blob: 8239b0e48192aba39a80d67ccbcbe397469c4271 [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 {
Glenn Kastencc1110d2012-03-19 12:07:35 -070048 TRACK_DEFAULT = 0, // client requests a default AudioTrack
49 TRACK_TIMED = 1, // client requests a TimedAudioTrack
50 TRACK_FAST = 2, // client requests a fast AudioTrack
Glenn Kastena075db42012-03-06 11:22:44 -080051 };
52 typedef uint32_t track_flags_t;
53
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080054 /* create an audio track and registers it with AudioFlinger.
55 * return null if the track cannot be created.
56 */
57 virtual sp<IAudioTrack> createTrack(
58 pid_t pid,
Glenn Kastenfff6d712012-01-12 16:38:12 -080059 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080060 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080061 audio_format_t format,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -070062 uint32_t channelMask,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080063 int frameCount,
Glenn Kastena075db42012-03-06 11:22:44 -080064 track_flags_t flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080065 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -080066 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -070067 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080068 status_t *status) = 0;
69
70 virtual sp<IAudioRecord> openRecord(
71 pid_t pid,
Glenn Kasten72ef00d2012-01-17 11:09:42 -080072 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080073 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080074 audio_format_t format,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -070075 uint32_t channelMask,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080076 int frameCount,
Glenn Kastena075db42012-03-06 11:22:44 -080077 track_flags_t flags,
Eric Laurentbe916aa2010-06-01 23:49:17 -070078 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080079 status_t *status) = 0;
80
81 /* query the audio hardware state. This state never changes,
82 * and therefore can be cached.
83 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -080084 virtual uint32_t sampleRate(audio_io_handle_t output) const = 0;
85 virtual int channelCount(audio_io_handle_t output) const = 0;
86 virtual audio_format_t format(audio_io_handle_t output) const = 0;
87 virtual size_t frameCount(audio_io_handle_t output) const = 0;
Glenn Kasten688aac72012-03-09 10:30:26 -080088
89 // return estimated latency in milliseconds
Glenn Kasten72ef00d2012-01-17 11:09:42 -080090 virtual uint32_t latency(audio_io_handle_t output) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080091
92 /* set/get the audio hardware state. This will probably be used by
93 * the preference panel, mostly.
94 */
95 virtual status_t setMasterVolume(float value) = 0;
96 virtual status_t setMasterMute(bool muted) = 0;
97
98 virtual float masterVolume() const = 0;
99 virtual bool masterMute() const = 0;
100
101 /* set/get stream type state. This will probably be used by
102 * the preference panel, mostly.
103 */
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800104 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
105 audio_io_handle_t output) = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800106 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800107
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800108 virtual float streamVolume(audio_stream_type_t stream,
109 audio_io_handle_t output) const = 0;
Glenn Kastenfff6d712012-01-12 16:38:12 -0800110 virtual bool streamMute(audio_stream_type_t stream) const = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800111
Eric Laurentc2f1f072009-07-17 12:17:14 -0700112 // set audio mode
Glenn Kastenf78aee72012-01-04 11:00:47 -0800113 virtual status_t setMode(audio_mode_t mode) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800114
115 // mic mute/state
116 virtual status_t setMicMute(bool state) = 0;
117 virtual bool getMicMute() const = 0;
118
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800119 virtual status_t setParameters(audio_io_handle_t ioHandle,
120 const String8& keyValuePairs) = 0;
121 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700122
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800123 // register a current process for audio output change notifications
124 virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700125
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800126 // retrieve the audio recording buffer size
Glenn Kastenf587ba52012-01-26 16:25:10 -0800127 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 -0800128
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800129 virtual audio_io_handle_t openOutput(uint32_t *pDevices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700130 uint32_t *pSamplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800131 audio_format_t *pFormat,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700132 uint32_t *pChannels,
133 uint32_t *pLatencyMs,
Glenn Kasten18868c52012-03-07 09:15:37 -0800134 audio_policy_output_flags_t flags) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800135 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
136 audio_io_handle_t output2) = 0;
137 virtual status_t closeOutput(audio_io_handle_t output) = 0;
138 virtual status_t suspendOutput(audio_io_handle_t output) = 0;
139 virtual status_t restoreOutput(audio_io_handle_t output) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700140
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800141 virtual audio_io_handle_t openInput(uint32_t *pDevices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700142 uint32_t *pSamplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800143 audio_format_t *pFormat,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700144 uint32_t *pChannels,
Glenn Kastende9719b2012-01-27 12:32:34 -0800145 audio_in_acoustics_t acoustics) = 0;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800146 virtual status_t closeInput(audio_io_handle_t input) = 0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700147
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800148 virtual status_t setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output) = 0;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700149
150 virtual status_t setVoiceVolume(float volume) = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800151
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800152 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
153 audio_io_handle_t output) const = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800154
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800155 virtual unsigned int getInputFramesLost(audio_io_handle_t ioHandle) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700156
157 virtual int newAudioSessionId() = 0;
158
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700159 virtual void acquireAudioSessionId(int audioSession) = 0;
160 virtual void releaseAudioSessionId(int audioSession) = 0;
161
Glenn Kastenf587ba52012-01-26 16:25:10 -0800162 virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700163
Glenn Kastenf587ba52012-01-26 16:25:10 -0800164 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700165
Glenn Kasten5e92a782012-01-30 07:40:52 -0800166 virtual status_t getEffectDescriptor(const effect_uuid_t *pEffectUUID,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800167 effect_descriptor_t *pDescriptor) const = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700168
169 virtual sp<IEffect> createEffect(pid_t pid,
170 effect_descriptor_t *pDesc,
171 const sp<IEffectClient>& client,
172 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800173 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700174 int sessionId,
175 status_t *status,
176 int *id,
177 int *enabled) = 0;
Eric Laurentde070132010-07-13 04:45:46 -0700178
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800179 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
180 audio_io_handle_t dstOutput) = 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800181};
182
183
184// ----------------------------------------------------------------------------
185
186class BnAudioFlinger : public BnInterface<IAudioFlinger>
187{
188public:
189 virtual status_t onTransact( uint32_t code,
190 const Parcel& data,
191 Parcel* reply,
192 uint32_t flags = 0);
193};
194
195// ----------------------------------------------------------------------------
196
197}; // namespace android
198
199#endif // ANDROID_IAUDIOFLINGER_H