blob: 75fae77f43d482baba615ef7e073d84f993b4b4a [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>
Ethan Chen8d420ed2013-11-14 00:40:54 -080029#ifdef QCOM_HARDWARE
Alok Kediya601e9b52013-09-27 11:55:10 +053030#include <media/IDirectTrack.h>
31#include <media/IDirectTrackClient.h>
Ethan Chen8d420ed2013-11-14 00:40:54 -080032#endif
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080033#include <media/IAudioTrack.h>
34#include <media/IAudioRecord.h>
35#include <media/IAudioFlingerClient.h>
Glenn Kasten72ef00d2012-01-17 11:09:42 -080036#include <system/audio.h>
Glenn Kasten18868c52012-03-07 09:15:37 -080037#include <system/audio_policy.h>
Eric Laurenta4c5a552012-03-29 10:12:40 -070038#include <hardware/audio_policy.h>
Eric Laurente1315cf2011-05-17 19:16:02 -070039#include <hardware/audio_effect.h>
Eric Laurentbe916aa2010-06-01 23:49:17 -070040#include <media/IEffect.h>
41#include <media/IEffectClient.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070042#include <utils/String8.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080043
44namespace android {
45
46// ----------------------------------------------------------------------------
47
48class IAudioFlinger : public IInterface
49{
50public:
51 DECLARE_META_INTERFACE(AudioFlinger);
52
Glenn Kastena075db42012-03-06 11:22:44 -080053 // or-able bits shared by createTrack and openRecord, but not all combinations make sense
54 enum {
Glenn Kastencc1110d2012-03-19 12:07:35 -070055 TRACK_DEFAULT = 0, // client requests a default AudioTrack
56 TRACK_TIMED = 1, // client requests a TimedAudioTrack
Glenn Kasten1879fff2012-07-11 15:36:59 -070057 TRACK_FAST = 2, // client requests a fast AudioTrack or AudioRecord
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000058 TRACK_OFFLOAD = 4, // client requests offload to hw codec
Ethan Chen8d420ed2013-11-14 00:40:54 -080059#ifdef QCOM_HARDWARE
Alok Kediya601e9b52013-09-27 11:55:10 +053060 TRACK_VOICE_COMMUNICATION = 8, //client uses voice communication
Ethan Chen8d420ed2013-11-14 00:40:54 -080061#endif
Glenn Kastena075db42012-03-06 11:22:44 -080062 };
63 typedef uint32_t track_flags_t;
64
Glenn Kastene93cf2c2013-09-24 11:52:37 -070065 // invariant on exit for all APIs that return an sp<>:
66 // (return value != 0) == (*status == NO_ERROR)
67
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080068 /* create an audio track and registers it with AudioFlinger.
69 * return null if the track cannot be created.
70 */
71 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080072 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080073 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080074 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -070075 audio_channel_mask_t channelMask,
Glenn Kastene33054e2012-11-14 12:54:39 -080076 size_t frameCount,
Glenn Kastene0b07172012-11-06 15:03:34 -080077 track_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080078 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -080079 audio_io_handle_t output,
Glenn Kasten3acbd052012-02-28 10:39:56 -080080 pid_t tid, // -1 means unused, otherwise must be valid non-0
Eric Laurentbe916aa2010-06-01 23:49:17 -070081 int *sessionId,
Glenn Kastend054c322013-07-12 12:59:20 -070082 // input: ignored
83 // output: server's description of IAudioTrack for display in logs.
84 // Don't attempt to parse, as the format could change.
85 String8& name,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080086 status_t *status) = 0;
87
Ethan Chen8d420ed2013-11-14 00:40:54 -080088#ifdef QCOM_HARDWARE
Alok Kediya601e9b52013-09-27 11:55:10 +053089 /* create a direct audio track and registers it with AudioFlinger.
90 * return null if the track cannot be created.
91 */
92 virtual sp<IDirectTrack> createDirectTrack(
93 pid_t pid,
94 uint32_t sampleRate,
95 audio_channel_mask_t channelMask,
96 audio_io_handle_t output,
97 int *sessionId,
98 IDirectTrackClient* client,
99 audio_stream_type_t streamType,
100 status_t *status) = 0;
Ethan Chen8d420ed2013-11-14 00:40:54 -0800101#endif
Alok Kediya601e9b52013-09-27 11:55:10 +0530102
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800103 virtual sp<IAudioRecord> openRecord(
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800104 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800105 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800106 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -0700107 audio_channel_mask_t channelMask,
Glenn Kastene33054e2012-11-14 12:54:39 -0800108 size_t frameCount,
Glenn Kasteneeca3262013-07-31 16:12:48 -0700109 track_flags_t *flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -0700110 pid_t tid, // -1 means unused, otherwise must be valid non-0
Eric Laurentbe916aa2010-06-01 23:49:17 -0700111 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800112 status_t *status) = 0;
113
114 /* query the audio hardware state. This state never changes,
115 * and therefore can be cached.
116 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800117 virtual uint32_t sampleRate(audio_io_handle_t output) const = 0;
Glenn Kastendd8104c2012-07-02 12:42:44 -0700118#if 0
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800119 virtual int channelCount(audio_io_handle_t output) const = 0;
Glenn Kastendd8104c2012-07-02 12:42:44 -0700120#endif
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800121 virtual audio_format_t format(audio_io_handle_t output) const = 0;
122 virtual size_t frameCount(audio_io_handle_t output) const = 0;
Glenn Kasten688aac72012-03-09 10:30:26 -0800123
124 // return estimated latency in milliseconds
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800125 virtual uint32_t latency(audio_io_handle_t output) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800126
127 /* set/get the audio hardware state. This will probably be used by
128 * the preference panel, mostly.
129 */
130 virtual status_t setMasterVolume(float value) = 0;
131 virtual status_t setMasterMute(bool muted) = 0;
132
133 virtual float masterVolume() const = 0;
134 virtual bool masterMute() const = 0;
135
136 /* set/get stream type state. This will probably be used by
137 * the preference panel, mostly.
138 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800139 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
140 audio_io_handle_t output) = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800141 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800142
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800143 virtual float streamVolume(audio_stream_type_t stream,
144 audio_io_handle_t output) const = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800145 virtual bool streamMute(audio_stream_type_t stream) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800146
Eric Laurentc2f1f072009-07-17 12:17:14 -0700147 // set audio mode
Glenn Kastenf78aee72012-01-04 11:00:47 -0800148 virtual status_t setMode(audio_mode_t mode) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800149
150 // mic mute/state
151 virtual status_t setMicMute(bool state) = 0;
152 virtual bool getMicMute() const = 0;
153
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800154 virtual status_t setParameters(audio_io_handle_t ioHandle,
155 const String8& keyValuePairs) = 0;
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700156 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys)
157 const = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700158
Glenn Kastenfb1fdc92013-07-10 17:03:19 -0700159 // Register an object to receive audio input/output change and track notifications.
160 // For a given calling pid, AudioFlinger disregards any registrations after the first.
161 // Thus the IAudioFlingerClient must be a singleton per process.
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800162 virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700163
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800164 // retrieve the audio recording buffer size
Glenn Kastendd8104c2012-07-02 12:42:44 -0700165 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
166 audio_channel_mask_t channelMask) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800167
Eric Laurenta4c5a552012-03-29 10:12:40 -0700168 virtual audio_io_handle_t openOutput(audio_module_handle_t module,
169 audio_devices_t *pDevices,
170 uint32_t *pSamplingRate,
171 audio_format_t *pFormat,
172 audio_channel_mask_t *pChannelMask,
173 uint32_t *pLatencyMs,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000174 audio_output_flags_t flags,
175 const audio_offload_info_t *offloadInfo = NULL) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800176 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
177 audio_io_handle_t output2) = 0;
178 virtual status_t closeOutput(audio_io_handle_t output) = 0;
179 virtual status_t suspendOutput(audio_io_handle_t output) = 0;
180 virtual status_t restoreOutput(audio_io_handle_t output) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700181
Eric Laurenta4c5a552012-03-29 10:12:40 -0700182 virtual audio_io_handle_t openInput(audio_module_handle_t module,
183 audio_devices_t *pDevices,
184 uint32_t *pSamplingRate,
185 audio_format_t *pFormat,
186 audio_channel_mask_t *pChannelMask) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800187 virtual status_t closeInput(audio_io_handle_t input) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700188
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800189 virtual status_t setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700190
191 virtual status_t setVoiceVolume(float volume) = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800192
Glenn Kastene33054e2012-11-14 12:54:39 -0800193 virtual status_t getRenderPosition(size_t *halFrames, size_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800194 audio_io_handle_t output) const = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800195
Glenn Kastene33054e2012-11-14 12:54:39 -0800196 virtual size_t getInputFramesLost(audio_io_handle_t ioHandle) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700197
198 virtual int newAudioSessionId() = 0;
199
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700200 virtual void acquireAudioSessionId(int audioSession) = 0;
201 virtual void releaseAudioSessionId(int audioSession) = 0;
202
Glenn Kastenf587ba52012-01-26 16:25:10 -0800203 virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700204
Glenn Kastenf587ba52012-01-26 16:25:10 -0800205 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700206
Glenn Kasten5e92a782012-01-30 07:40:52 -0800207 virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800208 effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700209
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800210 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700211 effect_descriptor_t *pDesc,
212 const sp<IEffectClient>& client,
213 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800214 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700215 int sessionId,
216 status_t *status,
217 int *id,
218 int *enabled) = 0;
Eric Laurentde070132010-07-13 04:45:46 -0700219
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800220 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
221 audio_io_handle_t dstOutput) = 0;
Eric Laurenta4c5a552012-03-29 10:12:40 -0700222
223 virtual audio_module_handle_t loadHwModule(const char *name) = 0;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700224
225 // helpers for android.media.AudioManager.getProperty(), see description there for meaning
226 // FIXME move these APIs to AudioPolicy to permit a more accurate implementation
227 // that looks on primary device for a stream with fast flag, primary flag, or first one.
Glenn Kasten3b16c762012-11-14 08:44:39 -0800228 virtual uint32_t getPrimaryOutputSamplingRate() = 0;
Glenn Kastene33054e2012-11-14 12:54:39 -0800229 virtual size_t getPrimaryOutputFrameCount() = 0;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700230
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700231 // Intended for AudioService to inform AudioFlinger of device's low RAM attribute,
232 // and should be called at most once. For a definition of what "low RAM" means, see
233 // android.app.ActivityManager.isLowRamDevice().
234 virtual status_t setLowRamDevice(bool isLowRamDevice) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800235};
236
237
238// ----------------------------------------------------------------------------
239
240class BnAudioFlinger : public BnInterface<IAudioFlinger>
241{
242public:
243 virtual status_t onTransact( uint32_t code,
244 const Parcel& data,
245 Parcel* reply,
246 uint32_t flags = 0);
247};
248
249// ----------------------------------------------------------------------------
250
251}; // namespace android
252
253#endif // ANDROID_IAUDIOFLINGER_H