blob: f927a80f83c3c0421e5e4a48d4d854b7de0a13b5 [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
Richard Fitzgeraldad3af332013-03-25 16:54:37 +000052 TRACK_OFFLOAD = 4, // client requests offload to hw codec
Eric Laurentab5cdba2014-06-09 17:22:27 -070053 TRACK_DIRECT = 8, // client requests a direct output
Glenn Kastena075db42012-03-06 11:22:44 -080054 };
55 typedef uint32_t track_flags_t;
56
Glenn Kastene93cf2c2013-09-24 11:52:37 -070057 // invariant on exit for all APIs that return an sp<>:
58 // (return value != 0) == (*status == NO_ERROR)
59
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080060 /* create an audio track and registers it with AudioFlinger.
61 * return null if the track cannot be created.
62 */
63 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080064 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080065 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080066 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -070067 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -080068 size_t *pFrameCount,
Glenn Kastene0b07172012-11-06 15:03:34 -080069 track_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080070 const sp<IMemory>& sharedBuffer,
Glenn Kastend631d962014-01-16 12:31:12 -080071 // On successful return, AudioFlinger takes over the handle
72 // reference and will release it when the track is destroyed.
73 // However on failure, the client is responsible for release.
Glenn Kasten72ef00d2012-01-17 11:09:42 -080074 audio_io_handle_t output,
Glenn Kasten3acbd052012-02-28 10:39:56 -080075 pid_t tid, // -1 means unused, otherwise must be valid non-0
Eric Laurentbe916aa2010-06-01 23:49:17 -070076 int *sessionId,
Marco Nelissen462fd2f2013-01-14 14:12:05 -080077 int clientUid,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080078 status_t *status) = 0;
79
80 virtual sp<IAudioRecord> openRecord(
Glenn Kastend631d962014-01-16 12:31:12 -080081 // On successful return, AudioFlinger takes over the handle
82 // reference and will release it when the track is destroyed.
83 // However on failure, the client is responsible for release.
Glenn Kasten72ef00d2012-01-17 11:09:42 -080084 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080085 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080086 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -070087 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -080088 size_t *pFrameCount,
Glenn Kasteneeca3262013-07-31 16:12:48 -070089 track_flags_t *flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -070090 pid_t tid, // -1 means unused, otherwise must be valid non-0
Eric Laurentbe916aa2010-06-01 23:49:17 -070091 int *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -070092 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -070093 sp<IMemory>& cblk,
94 sp<IMemory>& buffers, // return value 0 means it follows cblk
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080095 status_t *status) = 0;
96
Glenn Kastenf59497b2015-01-26 16:35:47 -080097 // FIXME Surprisingly, sampleRate/format/frameCount/latency don't work for input handles
98
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080099 /* query the audio hardware state. This state never changes,
100 * and therefore can be cached.
101 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800102 virtual uint32_t sampleRate(audio_io_handle_t output) const = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800103 virtual audio_format_t format(audio_io_handle_t output) const = 0;
104 virtual size_t frameCount(audio_io_handle_t output) const = 0;
Glenn Kasten688aac72012-03-09 10:30:26 -0800105
106 // return estimated latency in milliseconds
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800107 virtual uint32_t latency(audio_io_handle_t output) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800108
109 /* set/get the audio hardware state. This will probably be used by
110 * the preference panel, mostly.
111 */
112 virtual status_t setMasterVolume(float value) = 0;
113 virtual status_t setMasterMute(bool muted) = 0;
114
115 virtual float masterVolume() const = 0;
116 virtual bool masterMute() const = 0;
117
118 /* set/get stream type state. This will probably be used by
119 * the preference panel, mostly.
120 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800121 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
122 audio_io_handle_t output) = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800123 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800124
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800125 virtual float streamVolume(audio_stream_type_t stream,
126 audio_io_handle_t output) const = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800127 virtual bool streamMute(audio_stream_type_t stream) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800128
Eric Laurentc2f1f072009-07-17 12:17:14 -0700129 // set audio mode
Glenn Kastenf78aee72012-01-04 11:00:47 -0800130 virtual status_t setMode(audio_mode_t mode) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800131
132 // mic mute/state
133 virtual status_t setMicMute(bool state) = 0;
134 virtual bool getMicMute() const = 0;
135
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800136 virtual status_t setParameters(audio_io_handle_t ioHandle,
137 const String8& keyValuePairs) = 0;
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700138 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys)
139 const = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700140
Glenn Kastenfb1fdc92013-07-10 17:03:19 -0700141 // Register an object to receive audio input/output change and track notifications.
142 // For a given calling pid, AudioFlinger disregards any registrations after the first.
143 // Thus the IAudioFlingerClient must be a singleton per process.
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800144 virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700145
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800146 // retrieve the audio recording buffer size
Glenn Kastenf5e837e2014-07-03 10:17:10 -0700147 // FIXME This API assumes a route, and so should be deprecated.
Glenn Kastendd8104c2012-07-02 12:42:44 -0700148 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
149 audio_channel_mask_t channelMask) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800150
Eric Laurentcf2c0212014-07-25 16:20:43 -0700151 virtual status_t openOutput(audio_module_handle_t module,
152 audio_io_handle_t *output,
153 audio_config_t *config,
154 audio_devices_t *devices,
155 const String8& address,
156 uint32_t *latencyMs,
157 audio_output_flags_t flags) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800158 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
159 audio_io_handle_t output2) = 0;
160 virtual status_t closeOutput(audio_io_handle_t output) = 0;
161 virtual status_t suspendOutput(audio_io_handle_t output) = 0;
162 virtual status_t restoreOutput(audio_io_handle_t output) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700163
Eric Laurentcf2c0212014-07-25 16:20:43 -0700164 virtual status_t openInput(audio_module_handle_t module,
165 audio_io_handle_t *input,
166 audio_config_t *config,
167 audio_devices_t *device,
168 const String8& address,
169 audio_source_t source,
170 audio_input_flags_t flags) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800171 virtual status_t closeInput(audio_io_handle_t input) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700172
Glenn Kastend2304db2014-02-03 07:40:31 -0800173 virtual status_t invalidateStream(audio_stream_type_t stream) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700174
175 virtual status_t setVoiceVolume(float volume) = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800176
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000177 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800178 audio_io_handle_t output) const = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800179
Glenn Kasten5f972c02014-01-13 09:59:31 -0800180 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700181
Eric Laurentde3f8392014-07-27 18:38:22 -0700182 virtual audio_unique_id_t newAudioUniqueId() = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700183
Marco Nelissend457c972014-02-11 08:47:07 -0800184 virtual void acquireAudioSessionId(int audioSession, pid_t pid) = 0;
185 virtual void releaseAudioSessionId(int audioSession, pid_t pid) = 0;
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700186
Glenn Kastenf587ba52012-01-26 16:25:10 -0800187 virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700188
Glenn Kastenf587ba52012-01-26 16:25:10 -0800189 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700190
Glenn Kasten5e92a782012-01-30 07:40:52 -0800191 virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800192 effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700193
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800194 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700195 effect_descriptor_t *pDesc,
196 const sp<IEffectClient>& client,
197 int32_t priority,
Glenn Kastend631d962014-01-16 12:31:12 -0800198 // AudioFlinger doesn't take over handle reference from client
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800199 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700200 int sessionId,
201 status_t *status,
202 int *id,
203 int *enabled) = 0;
Eric Laurentde070132010-07-13 04:45:46 -0700204
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800205 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
206 audio_io_handle_t dstOutput) = 0;
Eric Laurenta4c5a552012-03-29 10:12:40 -0700207
208 virtual audio_module_handle_t loadHwModule(const char *name) = 0;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700209
210 // helpers for android.media.AudioManager.getProperty(), see description there for meaning
211 // FIXME move these APIs to AudioPolicy to permit a more accurate implementation
212 // that looks on primary device for a stream with fast flag, primary flag, or first one.
Glenn Kasten3b16c762012-11-14 08:44:39 -0800213 virtual uint32_t getPrimaryOutputSamplingRate() = 0;
Glenn Kastene33054e2012-11-14 12:54:39 -0800214 virtual size_t getPrimaryOutputFrameCount() = 0;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700215
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700216 // Intended for AudioService to inform AudioFlinger of device's low RAM attribute,
217 // and should be called at most once. For a definition of what "low RAM" means, see
218 // android.app.ActivityManager.isLowRamDevice().
219 virtual status_t setLowRamDevice(bool isLowRamDevice) = 0;
Eric Laurent4b123402014-04-11 09:22:20 -0700220
221 /* List available audio ports and their attributes */
222 virtual status_t listAudioPorts(unsigned int *num_ports,
223 struct audio_port *ports) = 0;
224
225 /* Get attributes for a given audio port */
226 virtual status_t getAudioPort(struct audio_port *port) = 0;
227
228 /* Create an audio patch between several source and sink ports */
229 virtual status_t createAudioPatch(const struct audio_patch *patch,
230 audio_patch_handle_t *handle) = 0;
231
232 /* Release an audio patch */
233 virtual status_t releaseAudioPatch(audio_patch_handle_t handle) = 0;
234
235 /* List existing audio patches */
236 virtual status_t listAudioPatches(unsigned int *num_patches,
237 struct audio_patch *patches) = 0;
238 /* Set audio port configuration */
239 virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0;
240
Eric Laurent93c3d412014-08-01 14:48:35 -0700241 /* Get the HW synchronization source used for an audio session */
242 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800243};
244
245
246// ----------------------------------------------------------------------------
247
248class BnAudioFlinger : public BnInterface<IAudioFlinger>
249{
250public:
251 virtual status_t onTransact( uint32_t code,
252 const Parcel& data,
253 Parcel* reply,
254 uint32_t flags = 0);
255};
256
257// ----------------------------------------------------------------------------
258
259}; // namespace android
260
261#endif // ANDROID_IAUDIOFLINGER_H