blob: 4bd111ae6779950a52cc3bc2d6abd0373f8975cb [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
Glenn Kastena075db42012-03-06 11:22:44 -080053 };
54 typedef uint32_t track_flags_t;
55
Glenn Kastene93cf2c2013-09-24 11:52:37 -070056 // invariant on exit for all APIs that return an sp<>:
57 // (return value != 0) == (*status == NO_ERROR)
58
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080059 /* create an audio track and registers it with AudioFlinger.
60 * return null if the track cannot be created.
61 */
62 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080063 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080064 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080065 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -070066 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -080067 size_t *pFrameCount,
Glenn Kastene0b07172012-11-06 15:03:34 -080068 track_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080069 const sp<IMemory>& sharedBuffer,
Glenn Kastend631d962014-01-16 12:31:12 -080070 // On successful return, AudioFlinger takes over the handle
71 // reference and will release it when the track is destroyed.
72 // However on failure, the client is responsible for release.
Glenn Kasten72ef00d2012-01-17 11:09:42 -080073 audio_io_handle_t output,
Glenn Kasten3acbd052012-02-28 10:39:56 -080074 pid_t tid, // -1 means unused, otherwise must be valid non-0
Eric Laurentbe916aa2010-06-01 23:49:17 -070075 int *sessionId,
Glenn Kastend054c322013-07-12 12:59:20 -070076 // input: ignored
77 // output: server's description of IAudioTrack for display in logs.
78 // Don't attempt to parse, as the format could change.
79 String8& name,
Marco Nelissen462fd2f2013-01-14 14:12:05 -080080 int clientUid,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080081 status_t *status) = 0;
82
83 virtual sp<IAudioRecord> openRecord(
Glenn Kastend631d962014-01-16 12:31:12 -080084 // On successful return, AudioFlinger takes over the handle
85 // reference and will release it when the track is destroyed.
86 // However on failure, the client is responsible for release.
Glenn Kasten72ef00d2012-01-17 11:09:42 -080087 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080088 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080089 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -070090 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -080091 size_t *pFrameCount,
Glenn Kasteneeca3262013-07-31 16:12:48 -070092 track_flags_t *flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -070093 pid_t tid, // -1 means unused, otherwise must be valid non-0
Eric Laurentbe916aa2010-06-01 23:49:17 -070094 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080095 status_t *status) = 0;
96
97 /* query the audio hardware state. This state never changes,
98 * and therefore can be cached.
99 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800100 virtual uint32_t sampleRate(audio_io_handle_t output) const = 0;
Glenn Kastendd8104c2012-07-02 12:42:44 -0700101#if 0
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800102 virtual int channelCount(audio_io_handle_t output) const = 0;
Glenn Kastendd8104c2012-07-02 12:42:44 -0700103#endif
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800104 virtual audio_format_t format(audio_io_handle_t output) const = 0;
105 virtual size_t frameCount(audio_io_handle_t output) const = 0;
Glenn Kasten688aac72012-03-09 10:30:26 -0800106
107 // return estimated latency in milliseconds
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800108 virtual uint32_t latency(audio_io_handle_t output) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800109
110 /* set/get the audio hardware state. This will probably be used by
111 * the preference panel, mostly.
112 */
113 virtual status_t setMasterVolume(float value) = 0;
114 virtual status_t setMasterMute(bool muted) = 0;
115
116 virtual float masterVolume() const = 0;
117 virtual bool masterMute() const = 0;
118
119 /* set/get stream type state. This will probably be used by
120 * the preference panel, mostly.
121 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800122 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
123 audio_io_handle_t output) = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800124 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800125
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800126 virtual float streamVolume(audio_stream_type_t stream,
127 audio_io_handle_t output) const = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800128 virtual bool streamMute(audio_stream_type_t stream) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800129
Eric Laurentc2f1f072009-07-17 12:17:14 -0700130 // set audio mode
Glenn Kastenf78aee72012-01-04 11:00:47 -0800131 virtual status_t setMode(audio_mode_t mode) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800132
133 // mic mute/state
134 virtual status_t setMicMute(bool state) = 0;
135 virtual bool getMicMute() const = 0;
136
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800137 virtual status_t setParameters(audio_io_handle_t ioHandle,
138 const String8& keyValuePairs) = 0;
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700139 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys)
140 const = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700141
Glenn Kastenfb1fdc92013-07-10 17:03:19 -0700142 // Register an object to receive audio input/output change and track notifications.
143 // For a given calling pid, AudioFlinger disregards any registrations after the first.
144 // Thus the IAudioFlingerClient must be a singleton per process.
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800145 virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700146
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800147 // retrieve the audio recording buffer size
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 Laurenta4c5a552012-03-29 10:12:40 -0700151 virtual audio_io_handle_t openOutput(audio_module_handle_t module,
152 audio_devices_t *pDevices,
153 uint32_t *pSamplingRate,
154 audio_format_t *pFormat,
155 audio_channel_mask_t *pChannelMask,
156 uint32_t *pLatencyMs,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000157 audio_output_flags_t flags,
158 const audio_offload_info_t *offloadInfo = NULL) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800159 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
160 audio_io_handle_t output2) = 0;
161 virtual status_t closeOutput(audio_io_handle_t output) = 0;
162 virtual status_t suspendOutput(audio_io_handle_t output) = 0;
163 virtual status_t restoreOutput(audio_io_handle_t output) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700164
Eric Laurenta4c5a552012-03-29 10:12:40 -0700165 virtual audio_io_handle_t openInput(audio_module_handle_t module,
166 audio_devices_t *pDevices,
167 uint32_t *pSamplingRate,
168 audio_format_t *pFormat,
169 audio_channel_mask_t *pChannelMask) = 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 Kasten72ef00d2012-01-17 11:09:42 -0800172 virtual status_t setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output) = 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
Glenn Kastene33054e2012-11-14 12:54:39 -0800176 virtual status_t getRenderPosition(size_t *halFrames, size_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
181 virtual int newAudioSessionId() = 0;
182
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700183 virtual void acquireAudioSessionId(int audioSession) = 0;
184 virtual void releaseAudioSessionId(int audioSession) = 0;
185
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,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700199 int sessionId,
200 status_t *status,
201 int *id,
202 int *enabled) = 0;
Eric Laurentde070132010-07-13 04:45:46 -0700203
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800204 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
205 audio_io_handle_t dstOutput) = 0;
Eric Laurenta4c5a552012-03-29 10:12:40 -0700206
207 virtual audio_module_handle_t loadHwModule(const char *name) = 0;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700208
209 // helpers for android.media.AudioManager.getProperty(), see description there for meaning
210 // FIXME move these APIs to AudioPolicy to permit a more accurate implementation
211 // that looks on primary device for a stream with fast flag, primary flag, or first one.
Glenn Kasten3b16c762012-11-14 08:44:39 -0800212 virtual uint32_t getPrimaryOutputSamplingRate() = 0;
Glenn Kastene33054e2012-11-14 12:54:39 -0800213 virtual size_t getPrimaryOutputFrameCount() = 0;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700214
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700215 // Intended for AudioService to inform AudioFlinger of device's low RAM attribute,
216 // and should be called at most once. For a definition of what "low RAM" means, see
217 // android.app.ActivityManager.isLowRamDevice().
218 virtual status_t setLowRamDevice(bool isLowRamDevice) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800219};
220
221
222// ----------------------------------------------------------------------------
223
224class BnAudioFlinger : public BnInterface<IAudioFlinger>
225{
226public:
227 virtual status_t onTransact( uint32_t code,
228 const Parcel& data,
229 Parcel* reply,
230 uint32_t flags = 0);
231};
232
233// ----------------------------------------------------------------------------
234
235}; // namespace android
236
237#endif // ANDROID_IAUDIOFLINGER_H