blob: 8c5e61a026dbaee3143e5805dc132e0d9f98e725 [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>
Mikhail Naganov00260b52016-10-13 12:54:24 -070031#include <system/audio_effect.h>
Glenn Kasten18868c52012-03-07 09:15:37 -080032#include <system/audio_policy.h>
Eric Laurentbe916aa2010-06-01 23:49:17 -070033#include <media/IEffect.h>
34#include <media/IEffectClient.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070035#include <utils/String8.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080036
37namespace android {
38
39// ----------------------------------------------------------------------------
40
41class IAudioFlinger : public IInterface
42{
43public:
44 DECLARE_META_INTERFACE(AudioFlinger);
45
Glenn Kastena075db42012-03-06 11:22:44 -080046
Glenn Kastene93cf2c2013-09-24 11:52:37 -070047 // invariant on exit for all APIs that return an sp<>:
48 // (return value != 0) == (*status == NO_ERROR)
49
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080050 /* create an audio track and registers it with AudioFlinger.
51 * return null if the track cannot be created.
52 */
53 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080054 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080055 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080056 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -070057 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -080058 size_t *pFrameCount,
Eric Laurent05067782016-06-01 18:27:28 -070059 audio_output_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080060 const sp<IMemory>& sharedBuffer,
Glenn Kastend631d962014-01-16 12:31:12 -080061 // On successful return, AudioFlinger takes over the handle
62 // reference and will release it when the track is destroyed.
63 // However on failure, the client is responsible for release.
Glenn Kasten72ef00d2012-01-17 11:09:42 -080064 audio_io_handle_t output,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -070065 pid_t pid,
Glenn Kasten3acbd052012-02-28 10:39:56 -080066 pid_t tid, // -1 means unused, otherwise must be valid non-0
Glenn Kastend848eb42016-03-08 13:42:11 -080067 audio_session_t *sessionId,
Marco Nelissen462fd2f2013-01-14 14:12:05 -080068 int clientUid,
Eric Laurent20b9ef02016-12-05 11:03:16 -080069 status_t *status,
70 audio_port_handle_t portId) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080071
72 virtual sp<IAudioRecord> openRecord(
Glenn Kastend631d962014-01-16 12:31:12 -080073 // On successful return, AudioFlinger takes over the handle
74 // reference and will release it when the track is destroyed.
75 // However on failure, the client is responsible for release.
Glenn Kasten72ef00d2012-01-17 11:09:42 -080076 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080077 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080078 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -070079 audio_channel_mask_t channelMask,
Svet Ganovbe71aa22015-04-28 12:06:02 -070080 const String16& callingPackage,
Glenn Kasten74935e42013-12-19 08:56:45 -080081 size_t *pFrameCount,
Eric Laurent05067782016-06-01 18:27:28 -070082 audio_input_flags_t *flags,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -070083 pid_t pid,
Glenn Kasten1879fff2012-07-11 15:36:59 -070084 pid_t tid, // -1 means unused, otherwise must be valid non-0
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -070085 int clientUid,
Glenn Kastend848eb42016-03-08 13:42:11 -080086 audio_session_t *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -070087 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -070088 sp<IMemory>& cblk,
89 sp<IMemory>& buffers, // return value 0 means it follows cblk
Eric Laurent20b9ef02016-12-05 11:03:16 -080090 status_t *status,
91 audio_port_handle_t portId) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080092
Glenn Kasten2c073da2016-02-26 09:14:08 -080093 // FIXME Surprisingly, format/latency don't work for input handles
Glenn Kastenf59497b2015-01-26 16:35:47 -080094
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080095 /* query the audio hardware state. This state never changes,
96 * and therefore can be cached.
97 */
Glenn Kasten2c073da2016-02-26 09:14:08 -080098 virtual uint32_t sampleRate(audio_io_handle_t ioHandle) const = 0;
Glenn Kasten4a8308b2016-04-18 14:10:01 -070099
100 // reserved; formerly channelCount()
101
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800102 virtual audio_format_t format(audio_io_handle_t output) const = 0;
Glenn Kasten2c073da2016-02-26 09:14:08 -0800103 virtual size_t frameCount(audio_io_handle_t ioHandle) const = 0;
Glenn Kasten688aac72012-03-09 10:30:26 -0800104
105 // return estimated latency in milliseconds
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800106 virtual uint32_t latency(audio_io_handle_t output) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800107
108 /* set/get the audio hardware state. This will probably be used by
109 * the preference panel, mostly.
110 */
111 virtual status_t setMasterVolume(float value) = 0;
112 virtual status_t setMasterMute(bool muted) = 0;
113
114 virtual float masterVolume() const = 0;
115 virtual bool masterMute() const = 0;
116
117 /* set/get stream type state. This will probably be used by
118 * the preference panel, mostly.
119 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800120 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
121 audio_io_handle_t output) = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800122 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800123
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800124 virtual float streamVolume(audio_stream_type_t stream,
125 audio_io_handle_t output) const = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800126 virtual bool streamMute(audio_stream_type_t stream) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800127
Eric Laurentc2f1f072009-07-17 12:17:14 -0700128 // set audio mode
Glenn Kastenf78aee72012-01-04 11:00:47 -0800129 virtual status_t setMode(audio_mode_t mode) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800130
131 // mic mute/state
132 virtual status_t setMicMute(bool state) = 0;
133 virtual bool getMicMute() const = 0;
134
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800135 virtual status_t setParameters(audio_io_handle_t ioHandle,
136 const String8& keyValuePairs) = 0;
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700137 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys)
138 const = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700139
Glenn Kastenfb1fdc92013-07-10 17:03:19 -0700140 // Register an object to receive audio input/output change and track notifications.
141 // For a given calling pid, AudioFlinger disregards any registrations after the first.
142 // Thus the IAudioFlingerClient must be a singleton per process.
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800143 virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700144
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800145 // retrieve the audio recording buffer size
Glenn Kastenf5e837e2014-07-03 10:17:10 -0700146 // FIXME This API assumes a route, and so should be deprecated.
Glenn Kastendd8104c2012-07-02 12:42:44 -0700147 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
148 audio_channel_mask_t channelMask) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800149
Eric Laurentcf2c0212014-07-25 16:20:43 -0700150 virtual status_t openOutput(audio_module_handle_t module,
151 audio_io_handle_t *output,
152 audio_config_t *config,
153 audio_devices_t *devices,
154 const String8& address,
155 uint32_t *latencyMs,
156 audio_output_flags_t flags) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800157 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
158 audio_io_handle_t output2) = 0;
159 virtual status_t closeOutput(audio_io_handle_t output) = 0;
160 virtual status_t suspendOutput(audio_io_handle_t output) = 0;
161 virtual status_t restoreOutput(audio_io_handle_t output) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700162
Eric Laurentcf2c0212014-07-25 16:20:43 -0700163 virtual status_t openInput(audio_module_handle_t module,
164 audio_io_handle_t *input,
165 audio_config_t *config,
166 audio_devices_t *device,
167 const String8& address,
168 audio_source_t source,
169 audio_input_flags_t flags) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800170 virtual status_t closeInput(audio_io_handle_t input) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700171
Glenn Kastend2304db2014-02-03 07:40:31 -0800172 virtual status_t invalidateStream(audio_stream_type_t stream) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700173
174 virtual status_t setVoiceVolume(float volume) = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800175
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000176 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800177 audio_io_handle_t output) const = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800178
Glenn Kasten5f972c02014-01-13 09:59:31 -0800179 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700180
Glenn Kasteneeecb982016-02-26 10:44:04 -0800181 virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use) = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700182
Glenn Kastend848eb42016-03-08 13:42:11 -0800183 virtual void acquireAudioSessionId(audio_session_t audioSession, pid_t pid) = 0;
184 virtual void releaseAudioSessionId(audio_session_t audioSession, pid_t pid) = 0;
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700185
Glenn Kastenf587ba52012-01-26 16:25:10 -0800186 virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700187
Glenn Kastenf587ba52012-01-26 16:25:10 -0800188 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700189
Glenn Kasten5e92a782012-01-30 07:40:52 -0800190 virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800191 effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700192
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800193 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700194 effect_descriptor_t *pDesc,
195 const sp<IEffectClient>& client,
196 int32_t priority,
Glenn Kastend631d962014-01-16 12:31:12 -0800197 // AudioFlinger doesn't take over handle reference from client
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800198 audio_io_handle_t output,
Glenn Kastend848eb42016-03-08 13:42:11 -0800199 audio_session_t sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700200 const String16& callingPackage,
Eric Laurentb6436272016-12-07 19:24:50 -0800201 pid_t pid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700202 status_t *status,
203 int *id,
204 int *enabled) = 0;
Eric Laurentde070132010-07-13 04:45:46 -0700205
Glenn Kastend848eb42016-03-08 13:42:11 -0800206 virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800207 audio_io_handle_t dstOutput) = 0;
Eric Laurenta4c5a552012-03-29 10:12:40 -0700208
209 virtual audio_module_handle_t loadHwModule(const char *name) = 0;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700210
211 // helpers for android.media.AudioManager.getProperty(), see description there for meaning
212 // FIXME move these APIs to AudioPolicy to permit a more accurate implementation
213 // that looks on primary device for a stream with fast flag, primary flag, or first one.
Glenn Kasten3b16c762012-11-14 08:44:39 -0800214 virtual uint32_t getPrimaryOutputSamplingRate() = 0;
Glenn Kastene33054e2012-11-14 12:54:39 -0800215 virtual size_t getPrimaryOutputFrameCount() = 0;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700216
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700217 // Intended for AudioService to inform AudioFlinger of device's low RAM attribute,
218 // and should be called at most once. For a definition of what "low RAM" means, see
219 // android.app.ActivityManager.isLowRamDevice().
220 virtual status_t setLowRamDevice(bool isLowRamDevice) = 0;
Eric Laurent4b123402014-04-11 09:22:20 -0700221
222 /* List available audio ports and their attributes */
223 virtual status_t listAudioPorts(unsigned int *num_ports,
224 struct audio_port *ports) = 0;
225
226 /* Get attributes for a given audio port */
227 virtual status_t getAudioPort(struct audio_port *port) = 0;
228
229 /* Create an audio patch between several source and sink ports */
230 virtual status_t createAudioPatch(const struct audio_patch *patch,
231 audio_patch_handle_t *handle) = 0;
232
233 /* Release an audio patch */
234 virtual status_t releaseAudioPatch(audio_patch_handle_t handle) = 0;
235
236 /* List existing audio patches */
237 virtual status_t listAudioPatches(unsigned int *num_patches,
238 struct audio_patch *patches) = 0;
239 /* Set audio port configuration */
240 virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0;
241
Eric Laurent93c3d412014-08-01 14:48:35 -0700242 /* Get the HW synchronization source used for an audio session */
243 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId) = 0;
Eric Laurent72e3f392015-05-20 14:43:50 -0700244
245 /* Indicate JAVA services are ready (scheduling, power management ...) */
246 virtual status_t systemReady() = 0;
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700247
248 // Returns the number of frames per audio HAL buffer.
249 virtual size_t frameCountHAL(audio_io_handle_t ioHandle) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800250};
251
252
253// ----------------------------------------------------------------------------
254
255class BnAudioFlinger : public BnInterface<IAudioFlinger>
256{
257public:
258 virtual status_t onTransact( uint32_t code,
259 const Parcel& data,
260 Parcel* reply,
261 uint32_t flags = 0);
262};
263
264// ----------------------------------------------------------------------------
265
266}; // namespace android
267
268#endif // ANDROID_IAUDIOFLINGER_H