blob: 9727143d64daf998b06574f23b0138b0a325f9b9 [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_IAUDIOFLINGER_H
18#define ANDROID_IAUDIOFLINGER_H
19
20#include <stdint.h>
21#include <sys/types.h>
22#include <unistd.h>
23
24#include <utils/RefBase.h>
25#include <utils/Errors.h>
Mathias Agopian75624082009-05-19 19:08:10 -070026#include <binder/IInterface.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080027#include <media/IAudioTrack.h>
28#include <media/IAudioRecord.h>
29#include <media/IAudioFlingerClient.h>
Glenn Kasten72ef00d2012-01-17 11:09:42 -080030#include <system/audio.h>
Glenn Kasten18868c52012-03-07 09:15:37 -080031#include <system/audio_policy.h>
Eric Laurenta4c5a552012-03-29 10:12:40 -070032#include <hardware/audio_policy.h>
Eric Laurente1315cf2011-05-17 19:16:02 -070033#include <hardware/audio_effect.h>
Eric Laurentbe916aa2010-06-01 23:49:17 -070034#include <media/IEffect.h>
35#include <media/IEffectClient.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070036#include <utils/String8.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080037
38namespace android {
39
40// ----------------------------------------------------------------------------
41
42class IAudioFlinger : public IInterface
43{
44public:
45 DECLARE_META_INTERFACE(AudioFlinger);
46
Glenn Kastena075db42012-03-06 11:22:44 -080047 // or-able bits shared by createTrack and openRecord, but not all combinations make sense
48 enum {
Glenn Kastencc1110d2012-03-19 12:07:35 -070049 TRACK_DEFAULT = 0, // client requests a default AudioTrack
50 TRACK_TIMED = 1, // client requests a TimedAudioTrack
Glenn Kasten1879fff2012-07-11 15:36:59 -070051 TRACK_FAST = 2, // client requests a fast AudioTrack or AudioRecord
Glenn Kastena075db42012-03-06 11:22:44 -080052 };
53 typedef uint32_t track_flags_t;
54
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080055 /* create an audio track and registers it with AudioFlinger.
56 * return null if the track cannot be created.
57 */
58 virtual sp<IAudioTrack> createTrack(
59 pid_t pid,
Glenn Kastenfff6d712012-01-12 16:38:12 -080060 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080061 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080062 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -070063 audio_channel_mask_t channelMask,
Glenn Kastene33054e2012-11-14 12:54:39 -080064 size_t frameCount,
Glenn Kastene0b07172012-11-06 15:03:34 -080065 track_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080066 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -080067 audio_io_handle_t output,
Glenn Kasten3acbd052012-02-28 10:39:56 -080068 pid_t tid, // -1 means unused, otherwise must be valid non-0
Eric Laurentbe916aa2010-06-01 23:49:17 -070069 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080070 status_t *status) = 0;
71
72 virtual sp<IAudioRecord> openRecord(
73 pid_t pid,
Glenn Kasten72ef00d2012-01-17 11:09:42 -080074 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080075 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080076 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -070077 audio_channel_mask_t channelMask,
Glenn Kastene33054e2012-11-14 12:54:39 -080078 size_t frameCount,
Glenn Kastena075db42012-03-06 11:22:44 -080079 track_flags_t flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -070080 pid_t tid, // -1 means unused, otherwise must be valid non-0
Eric Laurentbe916aa2010-06-01 23:49:17 -070081 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080082 status_t *status) = 0;
83
84 /* query the audio hardware state. This state never changes,
85 * and therefore can be cached.
86 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -080087 virtual uint32_t sampleRate(audio_io_handle_t output) const = 0;
Glenn Kastendd8104c2012-07-02 12:42:44 -070088#if 0
Glenn Kasten72ef00d2012-01-17 11:09:42 -080089 virtual int channelCount(audio_io_handle_t output) const = 0;
Glenn Kastendd8104c2012-07-02 12:42:44 -070090#endif
Glenn Kasten72ef00d2012-01-17 11:09:42 -080091 virtual audio_format_t format(audio_io_handle_t output) const = 0;
92 virtual size_t frameCount(audio_io_handle_t output) const = 0;
Glenn Kasten688aac72012-03-09 10:30:26 -080093
94 // return estimated latency in milliseconds
Glenn Kasten72ef00d2012-01-17 11:09:42 -080095 virtual uint32_t latency(audio_io_handle_t output) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080096
97 /* set/get the audio hardware state. This will probably be used by
98 * the preference panel, mostly.
99 */
100 virtual status_t setMasterVolume(float value) = 0;
101 virtual status_t setMasterMute(bool muted) = 0;
102
103 virtual float masterVolume() const = 0;
104 virtual bool masterMute() const = 0;
105
106 /* set/get stream type state. This will probably be used by
107 * the preference panel, mostly.
108 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800109 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
110 audio_io_handle_t output) = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800111 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800112
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800113 virtual float streamVolume(audio_stream_type_t stream,
114 audio_io_handle_t output) const = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800115 virtual bool streamMute(audio_stream_type_t stream) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800116
Eric Laurentc2f1f072009-07-17 12:17:14 -0700117 // set audio mode
Glenn Kastenf78aee72012-01-04 11:00:47 -0800118 virtual status_t setMode(audio_mode_t mode) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800119
120 // mic mute/state
121 virtual status_t setMicMute(bool state) = 0;
122 virtual bool getMicMute() const = 0;
123
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800124 virtual status_t setParameters(audio_io_handle_t ioHandle,
125 const String8& keyValuePairs) = 0;
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700126 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys)
127 const = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700128
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800129 // register a current process for audio output change notifications
130 virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700131
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800132 // retrieve the audio recording buffer size
Glenn Kastendd8104c2012-07-02 12:42:44 -0700133 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
134 audio_channel_mask_t channelMask) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800135
Eric Laurenta4c5a552012-03-29 10:12:40 -0700136 virtual audio_io_handle_t openOutput(audio_module_handle_t module,
137 audio_devices_t *pDevices,
138 uint32_t *pSamplingRate,
139 audio_format_t *pFormat,
140 audio_channel_mask_t *pChannelMask,
141 uint32_t *pLatencyMs,
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700142 audio_output_flags_t flags) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800143 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
144 audio_io_handle_t output2) = 0;
145 virtual status_t closeOutput(audio_io_handle_t output) = 0;
146 virtual status_t suspendOutput(audio_io_handle_t output) = 0;
147 virtual status_t restoreOutput(audio_io_handle_t output) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700148
Eric Laurenta4c5a552012-03-29 10:12:40 -0700149 virtual audio_io_handle_t openInput(audio_module_handle_t module,
150 audio_devices_t *pDevices,
151 uint32_t *pSamplingRate,
152 audio_format_t *pFormat,
153 audio_channel_mask_t *pChannelMask) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800154 virtual status_t closeInput(audio_io_handle_t input) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700155
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800156 virtual status_t setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700157
158 virtual status_t setVoiceVolume(float volume) = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800159
Glenn Kastene33054e2012-11-14 12:54:39 -0800160 virtual status_t getRenderPosition(size_t *halFrames, size_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800161 audio_io_handle_t output) const = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800162
Glenn Kastene33054e2012-11-14 12:54:39 -0800163 virtual size_t getInputFramesLost(audio_io_handle_t ioHandle) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700164
165 virtual int newAudioSessionId() = 0;
166
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700167 virtual void acquireAudioSessionId(int audioSession) = 0;
168 virtual void releaseAudioSessionId(int audioSession) = 0;
169
Glenn Kastenf587ba52012-01-26 16:25:10 -0800170 virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700171
Glenn Kastenf587ba52012-01-26 16:25:10 -0800172 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700173
Glenn Kasten5e92a782012-01-30 07:40:52 -0800174 virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800175 effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700176
177 virtual sp<IEffect> createEffect(pid_t pid,
178 effect_descriptor_t *pDesc,
179 const sp<IEffectClient>& client,
180 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800181 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700182 int sessionId,
183 status_t *status,
184 int *id,
185 int *enabled) = 0;
Eric Laurentde070132010-07-13 04:45:46 -0700186
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800187 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
188 audio_io_handle_t dstOutput) = 0;
Eric Laurenta4c5a552012-03-29 10:12:40 -0700189
190 virtual audio_module_handle_t loadHwModule(const char *name) = 0;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700191
192 // helpers for android.media.AudioManager.getProperty(), see description there for meaning
193 // FIXME move these APIs to AudioPolicy to permit a more accurate implementation
194 // that looks on primary device for a stream with fast flag, primary flag, or first one.
Glenn Kasten3b16c762012-11-14 08:44:39 -0800195 virtual uint32_t getPrimaryOutputSamplingRate() = 0;
Glenn Kastene33054e2012-11-14 12:54:39 -0800196 virtual size_t getPrimaryOutputFrameCount() = 0;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700197
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800198};
199
200
201// ----------------------------------------------------------------------------
202
203class BnAudioFlinger : public BnInterface<IAudioFlinger>
204{
205public:
206 virtual status_t onTransact( uint32_t code,
207 const Parcel& data,
208 Parcel* reply,
209 uint32_t flags = 0);
210};
211
212// ----------------------------------------------------------------------------
213
214}; // namespace android
215
216#endif // ANDROID_IAUDIOFLINGER_H