blob: 2bae08e0a3992ab670bfdc20fb60254ccdfd2c39 [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 Laurente1315cf2011-05-17 19:16:02 -070032#include <hardware/audio_effect.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 // or-able bits shared by createTrack and openRecord, but not all combinations make sense
47 enum {
48 TRACK_DEFAULT = 0,
49 TRACK_TIMED = 1,
50 };
51 typedef uint32_t track_flags_t;
52
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080053 /* create an audio track and registers it with AudioFlinger.
54 * return null if the track cannot be created.
55 */
56 virtual sp<IAudioTrack> createTrack(
57 pid_t pid,
Glenn Kastenfff6d712012-01-12 16:38:12 -080058 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080059 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080060 audio_format_t format,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -070061 uint32_t channelMask,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080062 int frameCount,
Glenn Kastena075db42012-03-06 11:22:44 -080063 track_flags_t flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080064 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -080065 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -070066 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080067 status_t *status) = 0;
68
69 virtual sp<IAudioRecord> openRecord(
70 pid_t pid,
Glenn Kasten72ef00d2012-01-17 11:09:42 -080071 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080072 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080073 audio_format_t format,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -070074 uint32_t channelMask,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080075 int frameCount,
Glenn Kastena075db42012-03-06 11:22:44 -080076 track_flags_t flags,
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
80 /* query the audio hardware state. This state never changes,
81 * and therefore can be cached.
82 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -080083 virtual uint32_t sampleRate(audio_io_handle_t output) const = 0;
84 virtual int channelCount(audio_io_handle_t output) const = 0;
85 virtual audio_format_t format(audio_io_handle_t output) const = 0;
86 virtual size_t frameCount(audio_io_handle_t output) const = 0;
Glenn Kasten688aac72012-03-09 10:30:26 -080087
88 // return estimated latency in milliseconds
Glenn Kasten72ef00d2012-01-17 11:09:42 -080089 virtual uint32_t latency(audio_io_handle_t output) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080090
91 /* set/get the audio hardware state. This will probably be used by
92 * the preference panel, mostly.
93 */
94 virtual status_t setMasterVolume(float value) = 0;
95 virtual status_t setMasterMute(bool muted) = 0;
96
97 virtual float masterVolume() const = 0;
98 virtual bool masterMute() const = 0;
99
100 /* set/get stream type state. This will probably be used by
101 * the preference panel, mostly.
102 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800103 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
104 audio_io_handle_t output) = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800105 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800106
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800107 virtual float streamVolume(audio_stream_type_t stream,
108 audio_io_handle_t output) const = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800109 virtual bool streamMute(audio_stream_type_t stream) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800110
Eric Laurentc2f1f072009-07-17 12:17:14 -0700111 // set audio mode
Glenn Kastenf78aee72012-01-04 11:00:47 -0800112 virtual status_t setMode(audio_mode_t mode) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800113
114 // mic mute/state
115 virtual status_t setMicMute(bool state) = 0;
116 virtual bool getMicMute() const = 0;
117
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800118 virtual status_t setParameters(audio_io_handle_t ioHandle,
119 const String8& keyValuePairs) = 0;
120 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700121
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800122 // register a current process for audio output change notifications
123 virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700124
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800125 // retrieve the audio recording buffer size
Glenn Kastenf587ba52012-01-26 16:25:10 -0800126 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, int channelCount) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800127
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800128 virtual audio_io_handle_t openOutput(uint32_t *pDevices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700129 uint32_t *pSamplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800130 audio_format_t *pFormat,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700131 uint32_t *pChannels,
132 uint32_t *pLatencyMs,
Glenn Kasten18868c52012-03-07 09:15:37 -0800133 audio_policy_output_flags_t flags) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800134 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
135 audio_io_handle_t output2) = 0;
136 virtual status_t closeOutput(audio_io_handle_t output) = 0;
137 virtual status_t suspendOutput(audio_io_handle_t output) = 0;
138 virtual status_t restoreOutput(audio_io_handle_t output) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700139
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800140 virtual audio_io_handle_t openInput(uint32_t *pDevices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700141 uint32_t *pSamplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800142 audio_format_t *pFormat,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700143 uint32_t *pChannels,
Glenn Kastende9719b2012-01-27 12:32:34 -0800144 audio_in_acoustics_t acoustics) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800145 virtual status_t closeInput(audio_io_handle_t input) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700146
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800147 virtual status_t setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700148
149 virtual status_t setVoiceVolume(float volume) = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800150
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800151 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
152 audio_io_handle_t output) const = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800153
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800154 virtual unsigned int getInputFramesLost(audio_io_handle_t ioHandle) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700155
156 virtual int newAudioSessionId() = 0;
157
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700158 virtual void acquireAudioSessionId(int audioSession) = 0;
159 virtual void releaseAudioSessionId(int audioSession) = 0;
160
Glenn Kastenf587ba52012-01-26 16:25:10 -0800161 virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700162
Glenn Kastenf587ba52012-01-26 16:25:10 -0800163 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700164
Glenn Kasten5e92a782012-01-30 07:40:52 -0800165 virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800166 effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700167
168 virtual sp<IEffect> createEffect(pid_t pid,
169 effect_descriptor_t *pDesc,
170 const sp<IEffectClient>& client,
171 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800172 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700173 int sessionId,
174 status_t *status,
175 int *id,
176 int *enabled) = 0;
Eric Laurentde070132010-07-13 04:45:46 -0700177
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800178 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
179 audio_io_handle_t dstOutput) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800180};
181
182
183// ----------------------------------------------------------------------------
184
185class BnAudioFlinger : public BnInterface<IAudioFlinger>
186{
187public:
188 virtual status_t onTransact( uint32_t code,
189 const Parcel& data,
190 Parcel* reply,
191 uint32_t flags = 0);
192};
193
194// ----------------------------------------------------------------------------
195
196}; // namespace android
197
198#endif // ANDROID_IAUDIOFLINGER_H