blob: 396f87be03db3150c0cd5157605b046110a375f8 [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
Mingming Yin84f109b2012-12-27 17:43:05 -08002 * Copyright (C) 2007 The Android Open Source Project
Dorian Snyderf32d5702013-03-01 14:25:46 -08003 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Mingming Yin84f109b2012-12-27 17:43:05 -08004 *
vivek mehta2192bc92012-12-04 11:46:08 -08005 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
7 *
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08008 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#ifndef ANDROID_IAUDIOFLINGER_H
22#define ANDROID_IAUDIOFLINGER_H
23
24#include <stdint.h>
25#include <sys/types.h>
26#include <unistd.h>
27
28#include <utils/RefBase.h>
29#include <utils/Errors.h>
Mathias Agopian75624082009-05-19 19:08:10 -070030#include <binder/IInterface.h>
vivek mehta2192bc92012-12-04 11:46:08 -080031#ifdef QCOM_HARDWARE
32#include <media/IDirectTrack.h>
33#include <media/IDirectTrackClient.h>
34#endif
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080035#include <media/IAudioTrack.h>
36#include <media/IAudioRecord.h>
37#include <media/IAudioFlingerClient.h>
Glenn Kasten72ef00d2012-01-17 11:09:42 -080038#include <system/audio.h>
Glenn Kasten18868c52012-03-07 09:15:37 -080039#include <system/audio_policy.h>
Eric Laurenta4c5a552012-03-29 10:12:40 -070040#include <hardware/audio_policy.h>
Eric Laurente1315cf2011-05-17 19:16:02 -070041#include <hardware/audio_effect.h>
Eric Laurentbe916aa2010-06-01 23:49:17 -070042#include <media/IEffect.h>
43#include <media/IEffectClient.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070044#include <utils/String8.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080045
46namespace android {
47
48// ----------------------------------------------------------------------------
49
50class IAudioFlinger : public IInterface
51{
52public:
53 DECLARE_META_INTERFACE(AudioFlinger);
54
Glenn Kastena075db42012-03-06 11:22:44 -080055 // or-able bits shared by createTrack and openRecord, but not all combinations make sense
56 enum {
Glenn Kastencc1110d2012-03-19 12:07:35 -070057 TRACK_DEFAULT = 0, // client requests a default AudioTrack
58 TRACK_TIMED = 1, // client requests a TimedAudioTrack
Glenn Kasten1879fff2012-07-11 15:36:59 -070059 TRACK_FAST = 2, // client requests a fast AudioTrack or AudioRecord
Glenn Kastena075db42012-03-06 11:22:44 -080060 };
61 typedef uint32_t track_flags_t;
62
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080063 /* create an audio track and registers it with AudioFlinger.
64 * return null if the track cannot be created.
65 */
66 virtual sp<IAudioTrack> createTrack(
67 pid_t pid,
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,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080072 int frameCount,
Glenn Kastena075db42012-03-06 11:22:44 -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,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080078 status_t *status) = 0;
79
vivek mehta2192bc92012-12-04 11:46:08 -080080#ifdef QCOM_HARDWARE
81 /* create a direct audio track and registers it with AudioFlinger.
82 * return null if the track cannot be created.
83 */
84 virtual sp<IDirectTrack> createDirectTrack(
85 pid_t pid,
86 uint32_t sampleRate,
87 audio_channel_mask_t channelMask,
88 audio_io_handle_t output,
89 int *sessionId,
90 IDirectTrackClient* client,
91 audio_stream_type_t streamType,
92 status_t *status) = 0;
93#endif
94
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080095 virtual sp<IAudioRecord> openRecord(
96 pid_t pid,
Glenn Kasten72ef00d2012-01-17 11:09:42 -080097 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080098 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080099 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -0700100 audio_channel_mask_t channelMask,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800101 int frameCount,
Glenn Kastena075db42012-03-06 11:22:44 -0800102 track_flags_t flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -0700103 pid_t tid, // -1 means unused, otherwise must be valid non-0
Eric Laurentbe916aa2010-06-01 23:49:17 -0700104 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800105 status_t *status) = 0;
106
107 /* query the audio hardware state. This state never changes,
108 * and therefore can be cached.
109 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800110 virtual uint32_t sampleRate(audio_io_handle_t output) const = 0;
Glenn Kastendd8104c2012-07-02 12:42:44 -0700111#if 0
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800112 virtual int channelCount(audio_io_handle_t output) const = 0;
Glenn Kastendd8104c2012-07-02 12:42:44 -0700113#endif
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800114 virtual audio_format_t format(audio_io_handle_t output) const = 0;
115 virtual size_t frameCount(audio_io_handle_t output) const = 0;
Glenn Kasten688aac72012-03-09 10:30:26 -0800116
117 // return estimated latency in milliseconds
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800118 virtual uint32_t latency(audio_io_handle_t output) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800119
120 /* set/get the audio hardware state. This will probably be used by
121 * the preference panel, mostly.
122 */
123 virtual status_t setMasterVolume(float value) = 0;
124 virtual status_t setMasterMute(bool muted) = 0;
125
126 virtual float masterVolume() const = 0;
127 virtual bool masterMute() const = 0;
128
129 /* set/get stream type state. This will probably be used by
130 * the preference panel, mostly.
131 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800132 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
133 audio_io_handle_t output) = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800134 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800135
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800136 virtual float streamVolume(audio_stream_type_t stream,
137 audio_io_handle_t output) const = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800138 virtual bool streamMute(audio_stream_type_t stream) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800139
Eric Laurentc2f1f072009-07-17 12:17:14 -0700140 // set audio mode
Glenn Kastenf78aee72012-01-04 11:00:47 -0800141 virtual status_t setMode(audio_mode_t mode) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800142
143 // mic mute/state
144 virtual status_t setMicMute(bool state) = 0;
145 virtual bool getMicMute() const = 0;
146
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800147 virtual status_t setParameters(audio_io_handle_t ioHandle,
148 const String8& keyValuePairs) = 0;
149 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700150
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800151 // register a current process for audio output change notifications
152 virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700153
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800154 // retrieve the audio recording buffer size
Glenn Kastendd8104c2012-07-02 12:42:44 -0700155 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
156 audio_channel_mask_t channelMask) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800157
Eric Laurenta4c5a552012-03-29 10:12:40 -0700158 virtual audio_io_handle_t openOutput(audio_module_handle_t module,
159 audio_devices_t *pDevices,
160 uint32_t *pSamplingRate,
161 audio_format_t *pFormat,
162 audio_channel_mask_t *pChannelMask,
163 uint32_t *pLatencyMs,
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700164 audio_output_flags_t flags) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800165 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
166 audio_io_handle_t output2) = 0;
167 virtual status_t closeOutput(audio_io_handle_t output) = 0;
168 virtual status_t suspendOutput(audio_io_handle_t output) = 0;
169 virtual status_t restoreOutput(audio_io_handle_t output) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700170
Eric Laurenta4c5a552012-03-29 10:12:40 -0700171 virtual audio_io_handle_t openInput(audio_module_handle_t module,
172 audio_devices_t *pDevices,
173 uint32_t *pSamplingRate,
174 audio_format_t *pFormat,
175 audio_channel_mask_t *pChannelMask) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800176 virtual status_t closeInput(audio_io_handle_t input) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700177
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800178 virtual status_t setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700179
180 virtual status_t setVoiceVolume(float volume) = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800181
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800182 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
183 audio_io_handle_t output) const = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800184
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800185 virtual unsigned int getInputFramesLost(audio_io_handle_t ioHandle) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700186
187 virtual int newAudioSessionId() = 0;
188
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700189 virtual void acquireAudioSessionId(int audioSession) = 0;
190 virtual void releaseAudioSessionId(int audioSession) = 0;
191
Glenn Kastenf587ba52012-01-26 16:25:10 -0800192 virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700193
Glenn Kastenf587ba52012-01-26 16:25:10 -0800194 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700195
Glenn Kasten5e92a782012-01-30 07:40:52 -0800196 virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800197 effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700198
199 virtual sp<IEffect> createEffect(pid_t pid,
200 effect_descriptor_t *pDesc,
201 const sp<IEffectClient>& client,
202 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800203 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700204 int sessionId,
205 status_t *status,
206 int *id,
207 int *enabled) = 0;
Eric Laurentde070132010-07-13 04:45:46 -0700208
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800209 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
210 audio_io_handle_t dstOutput) = 0;
Eric Laurenta4c5a552012-03-29 10:12:40 -0700211
212 virtual audio_module_handle_t loadHwModule(const char *name) = 0;
Dorian Snyderf32d5702013-03-01 14:25:46 -0800213#ifdef QCOM_HARDWARE
214 virtual status_t deregisterClient(const sp<IAudioFlingerClient>& client) { return false; };
215#endif
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700216
217 // helpers for android.media.AudioManager.getProperty(), see description there for meaning
218 // FIXME move these APIs to AudioPolicy to permit a more accurate implementation
219 // that looks on primary device for a stream with fast flag, primary flag, or first one.
220 virtual int32_t getPrimaryOutputSamplingRate() = 0;
221 virtual int32_t getPrimaryOutputFrameCount() = 0;
Mingming Yin84f109b2012-12-27 17:43:05 -0800222#ifdef QCOM_FM_ENABLED
223 virtual status_t setFmVolume(float volume) = 0;
224#endif
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700225
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800226};
227
228
229// ----------------------------------------------------------------------------
230
231class BnAudioFlinger : public BnInterface<IAudioFlinger>
232{
233public:
234 virtual status_t onTransact( uint32_t code,
235 const Parcel& data,
236 Parcel* reply,
237 uint32_t flags = 0);
238};
239
240// ----------------------------------------------------------------------------
241
242}; // namespace android
243
244#endif // ANDROID_IAUDIOFLINGER_H