blob: abd7754a3c921dac1fd82fc5b9b86fa957907ffb [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
Alok Kediya601e9b52013-09-27 11:55:10 +05302 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
3 * Not a contribution.
4 * Copyright (C) 2007 The Android Open Source Project.
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08005 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef ANDROID_IAUDIOFLINGER_H
20#define ANDROID_IAUDIOFLINGER_H
21
22#include <stdint.h>
23#include <sys/types.h>
24#include <unistd.h>
25
26#include <utils/RefBase.h>
27#include <utils/Errors.h>
Mathias Agopian75624082009-05-19 19:08:10 -070028#include <binder/IInterface.h>
Alok Kediya601e9b52013-09-27 11:55:10 +053029#include <media/IDirectTrack.h>
30#include <media/IDirectTrackClient.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080031#include <media/IAudioTrack.h>
32#include <media/IAudioRecord.h>
33#include <media/IAudioFlingerClient.h>
Glenn Kasten72ef00d2012-01-17 11:09:42 -080034#include <system/audio.h>
Glenn Kasten18868c52012-03-07 09:15:37 -080035#include <system/audio_policy.h>
Eric Laurenta4c5a552012-03-29 10:12:40 -070036#include <hardware/audio_policy.h>
Eric Laurente1315cf2011-05-17 19:16:02 -070037#include <hardware/audio_effect.h>
Eric Laurentbe916aa2010-06-01 23:49:17 -070038#include <media/IEffect.h>
39#include <media/IEffectClient.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070040#include <utils/String8.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080041
42namespace android {
43
44// ----------------------------------------------------------------------------
45
46class IAudioFlinger : public IInterface
47{
48public:
49 DECLARE_META_INTERFACE(AudioFlinger);
50
Glenn Kastena075db42012-03-06 11:22:44 -080051 // or-able bits shared by createTrack and openRecord, but not all combinations make sense
52 enum {
Glenn Kastencc1110d2012-03-19 12:07:35 -070053 TRACK_DEFAULT = 0, // client requests a default AudioTrack
54 TRACK_TIMED = 1, // client requests a TimedAudioTrack
Glenn Kasten1879fff2012-07-11 15:36:59 -070055 TRACK_FAST = 2, // client requests a fast AudioTrack or AudioRecord
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000056 TRACK_OFFLOAD = 4, // client requests offload to hw codec
Alok Kediya601e9b52013-09-27 11:55:10 +053057 TRACK_VOICE_COMMUNICATION = 8, //client uses voice communication
Glenn Kastena075db42012-03-06 11:22:44 -080058 };
59 typedef uint32_t track_flags_t;
60
Glenn Kastene93cf2c2013-09-24 11:52:37 -070061 // invariant on exit for all APIs that return an sp<>:
62 // (return value != 0) == (*status == NO_ERROR)
63
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080064 /* create an audio track and registers it with AudioFlinger.
65 * return null if the track cannot be created.
66 */
67 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080068 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080069 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080070 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -070071 audio_channel_mask_t channelMask,
Glenn Kastene33054e2012-11-14 12:54:39 -080072 size_t frameCount,
Glenn Kastene0b07172012-11-06 15:03:34 -080073 track_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080074 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -080075 audio_io_handle_t output,
Glenn Kasten3acbd052012-02-28 10:39:56 -080076 pid_t tid, // -1 means unused, otherwise must be valid non-0
Eric Laurentbe916aa2010-06-01 23:49:17 -070077 int *sessionId,
Glenn Kastend054c322013-07-12 12:59:20 -070078 // input: ignored
79 // output: server's description of IAudioTrack for display in logs.
80 // Don't attempt to parse, as the format could change.
81 String8& name,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080082 status_t *status) = 0;
83
Alok Kediya601e9b52013-09-27 11:55:10 +053084 /* create a direct audio track and registers it with AudioFlinger.
85 * return null if the track cannot be created.
86 */
87 virtual sp<IDirectTrack> createDirectTrack(
88 pid_t pid,
89 uint32_t sampleRate,
90 audio_channel_mask_t channelMask,
91 audio_io_handle_t output,
92 int *sessionId,
93 IDirectTrackClient* client,
94 audio_stream_type_t streamType,
95 status_t *status) = 0;
96
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080097 virtual sp<IAudioRecord> openRecord(
Glenn Kasten72ef00d2012-01-17 11:09:42 -080098 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080099 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800100 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -0700101 audio_channel_mask_t channelMask,
Glenn Kastene33054e2012-11-14 12:54:39 -0800102 size_t frameCount,
Glenn Kasteneeca3262013-07-31 16:12:48 -0700103 track_flags_t *flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -0700104 pid_t tid, // -1 means unused, otherwise must be valid non-0
Eric Laurentbe916aa2010-06-01 23:49:17 -0700105 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800106 status_t *status) = 0;
107
108 /* query the audio hardware state. This state never changes,
109 * and therefore can be cached.
110 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800111 virtual uint32_t sampleRate(audio_io_handle_t output) const = 0;
Glenn Kastendd8104c2012-07-02 12:42:44 -0700112#if 0
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800113 virtual int channelCount(audio_io_handle_t output) const = 0;
Glenn Kastendd8104c2012-07-02 12:42:44 -0700114#endif
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800115 virtual audio_format_t format(audio_io_handle_t output) const = 0;
116 virtual size_t frameCount(audio_io_handle_t output) const = 0;
Glenn Kasten688aac72012-03-09 10:30:26 -0800117
118 // return estimated latency in milliseconds
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800119 virtual uint32_t latency(audio_io_handle_t output) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800120
121 /* set/get the audio hardware state. This will probably be used by
122 * the preference panel, mostly.
123 */
124 virtual status_t setMasterVolume(float value) = 0;
125 virtual status_t setMasterMute(bool muted) = 0;
126
127 virtual float masterVolume() const = 0;
128 virtual bool masterMute() const = 0;
129
130 /* set/get stream type state. This will probably be used by
131 * the preference panel, mostly.
132 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800133 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
134 audio_io_handle_t output) = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800135 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800136
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800137 virtual float streamVolume(audio_stream_type_t stream,
138 audio_io_handle_t output) const = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800139 virtual bool streamMute(audio_stream_type_t stream) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800140
Eric Laurentc2f1f072009-07-17 12:17:14 -0700141 // set audio mode
Glenn Kastenf78aee72012-01-04 11:00:47 -0800142 virtual status_t setMode(audio_mode_t mode) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800143
144 // mic mute/state
145 virtual status_t setMicMute(bool state) = 0;
146 virtual bool getMicMute() const = 0;
147
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800148 virtual status_t setParameters(audio_io_handle_t ioHandle,
149 const String8& keyValuePairs) = 0;
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700150 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys)
151 const = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700152
Glenn Kastenfb1fdc92013-07-10 17:03:19 -0700153 // Register an object to receive audio input/output change and track notifications.
154 // For a given calling pid, AudioFlinger disregards any registrations after the first.
155 // Thus the IAudioFlingerClient must be a singleton per process.
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800156 virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700157
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800158 // retrieve the audio recording buffer size
Glenn Kastendd8104c2012-07-02 12:42:44 -0700159 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
160 audio_channel_mask_t channelMask) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800161
Eric Laurenta4c5a552012-03-29 10:12:40 -0700162 virtual audio_io_handle_t openOutput(audio_module_handle_t module,
163 audio_devices_t *pDevices,
164 uint32_t *pSamplingRate,
165 audio_format_t *pFormat,
166 audio_channel_mask_t *pChannelMask,
167 uint32_t *pLatencyMs,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000168 audio_output_flags_t flags,
169 const audio_offload_info_t *offloadInfo = NULL) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800170 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
171 audio_io_handle_t output2) = 0;
172 virtual status_t closeOutput(audio_io_handle_t output) = 0;
173 virtual status_t suspendOutput(audio_io_handle_t output) = 0;
174 virtual status_t restoreOutput(audio_io_handle_t output) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700175
Eric Laurenta4c5a552012-03-29 10:12:40 -0700176 virtual audio_io_handle_t openInput(audio_module_handle_t module,
177 audio_devices_t *pDevices,
178 uint32_t *pSamplingRate,
179 audio_format_t *pFormat,
180 audio_channel_mask_t *pChannelMask) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800181 virtual status_t closeInput(audio_io_handle_t input) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700182
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800183 virtual status_t setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700184
185 virtual status_t setVoiceVolume(float volume) = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800186
Glenn Kastene33054e2012-11-14 12:54:39 -0800187 virtual status_t getRenderPosition(size_t *halFrames, size_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800188 audio_io_handle_t output) const = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800189
Glenn Kastene33054e2012-11-14 12:54:39 -0800190 virtual size_t getInputFramesLost(audio_io_handle_t ioHandle) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700191
192 virtual int newAudioSessionId() = 0;
193
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700194 virtual void acquireAudioSessionId(int audioSession) = 0;
195 virtual void releaseAudioSessionId(int audioSession) = 0;
196
Glenn Kastenf587ba52012-01-26 16:25:10 -0800197 virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700198
Glenn Kastenf587ba52012-01-26 16:25:10 -0800199 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700200
Glenn Kasten5e92a782012-01-30 07:40:52 -0800201 virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800202 effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700203
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800204 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700205 effect_descriptor_t *pDesc,
206 const sp<IEffectClient>& client,
207 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800208 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700209 int sessionId,
210 status_t *status,
211 int *id,
212 int *enabled) = 0;
Eric Laurentde070132010-07-13 04:45:46 -0700213
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800214 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
215 audio_io_handle_t dstOutput) = 0;
Eric Laurenta4c5a552012-03-29 10:12:40 -0700216
217 virtual audio_module_handle_t loadHwModule(const char *name) = 0;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700218
219 // helpers for android.media.AudioManager.getProperty(), see description there for meaning
220 // FIXME move these APIs to AudioPolicy to permit a more accurate implementation
221 // that looks on primary device for a stream with fast flag, primary flag, or first one.
Glenn Kasten3b16c762012-11-14 08:44:39 -0800222 virtual uint32_t getPrimaryOutputSamplingRate() = 0;
Glenn Kastene33054e2012-11-14 12:54:39 -0800223 virtual size_t getPrimaryOutputFrameCount() = 0;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700224
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700225 // Intended for AudioService to inform AudioFlinger of device's low RAM attribute,
226 // and should be called at most once. For a definition of what "low RAM" means, see
227 // android.app.ActivityManager.isLowRamDevice().
228 virtual status_t setLowRamDevice(bool isLowRamDevice) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800229};
230
231
232// ----------------------------------------------------------------------------
233
234class BnAudioFlinger : public BnInterface<IAudioFlinger>
235{
236public:
237 virtual status_t onTransact( uint32_t code,
238 const Parcel& data,
239 Parcel* reply,
240 uint32_t flags = 0);
241};
242
243// ----------------------------------------------------------------------------
244
245}; // namespace android
246
247#endif // ANDROID_IAUDIOFLINGER_H