blob: f6cf5ae1870c346e79b77fabdf7041538aa7f7fa [file] [log] [blame]
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001/*
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08002**
3** Copyright 2007, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioFlinger"
Eric Laurentc2f1f072009-07-17 12:17:14 -070019//#define LOG_NDEBUG 0
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080020#include <utils/Log.h>
21
22#include <stdint.h>
23#include <sys/types.h>
24
Mathias Agopian75624082009-05-19 19:08:10 -070025#include <binder/Parcel.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080026
27#include <media/IAudioFlinger.h>
28
29namespace android {
30
31enum {
32 CREATE_TRACK = IBinder::FIRST_CALL_TRANSACTION,
33 OPEN_RECORD,
34 SAMPLE_RATE,
35 CHANNEL_COUNT,
36 FORMAT,
37 FRAME_COUNT,
38 LATENCY,
39 SET_MASTER_VOLUME,
40 SET_MASTER_MUTE,
41 MASTER_VOLUME,
42 MASTER_MUTE,
43 SET_STREAM_VOLUME,
44 SET_STREAM_MUTE,
45 STREAM_VOLUME,
46 STREAM_MUTE,
47 SET_MODE,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080048 SET_MIC_MUTE,
49 GET_MIC_MUTE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070050 SET_PARAMETERS,
51 GET_PARAMETERS,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080052 REGISTER_CLIENT,
53 GET_INPUTBUFFERSIZE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070054 OPEN_OUTPUT,
55 OPEN_DUPLICATE_OUTPUT,
56 CLOSE_OUTPUT,
57 SUSPEND_OUTPUT,
58 RESTORE_OUTPUT,
59 OPEN_INPUT,
60 CLOSE_INPUT,
Eric Laurentf0ee6f42009-10-21 08:14:22 -070061 SET_STREAM_OUTPUT,
Eric Laurent342e9cf2010-01-19 17:37:09 -080062 SET_VOICE_VOLUME,
Eric Laurent05bca2f2010-02-26 02:47:27 -080063 GET_RENDER_POSITION,
Eric Laurentbe916aa2010-06-01 23:49:17 -070064 GET_INPUT_FRAMES_LOST,
65 NEW_AUDIO_SESSION_ID,
Marco Nelissen3a34bef2011-08-02 13:33:41 -070066 ACQUIRE_AUDIO_SESSION_ID,
67 RELEASE_AUDIO_SESSION_ID,
Eric Laurentbe916aa2010-06-01 23:49:17 -070068 QUERY_NUM_EFFECTS,
Eric Laurentffe9c252010-06-23 17:38:20 -070069 QUERY_EFFECT,
Eric Laurentbe916aa2010-06-01 23:49:17 -070070 GET_EFFECT_DESCRIPTOR,
Eric Laurentde070132010-07-13 04:45:46 -070071 CREATE_EFFECT,
72 MOVE_EFFECTS
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080073};
74
75class BpAudioFlinger : public BpInterface<IAudioFlinger>
76{
77public:
78 BpAudioFlinger(const sp<IBinder>& impl)
79 : BpInterface<IAudioFlinger>(impl)
80 {
81 }
82
83 virtual sp<IAudioTrack> createTrack(
84 pid_t pid,
Glenn Kastenfff6d712012-01-12 16:38:12 -080085 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080086 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080087 audio_format_t format,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -070088 uint32_t channelMask,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080089 int frameCount,
90 uint32_t flags,
91 const sp<IMemory>& sharedBuffer,
Eric Laurentfa2877b2009-07-28 08:44:33 -070092 int output,
Eric Laurentbe916aa2010-06-01 23:49:17 -070093 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080094 status_t *status)
95 {
96 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -070097 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080098 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
99 data.writeInt32(pid);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800100 data.writeInt32((int32_t) streamType);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800101 data.writeInt32(sampleRate);
102 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700103 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800104 data.writeInt32(frameCount);
105 data.writeInt32(flags);
106 data.writeStrongBinder(sharedBuffer->asBinder());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700107 data.writeInt32(output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700108 int lSessionId = 0;
109 if (sessionId != NULL) {
110 lSessionId = *sessionId;
111 }
112 data.writeInt32(lSessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800113 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
114 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000115 ALOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700116 } else {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700117 lSessionId = reply.readInt32();
118 if (sessionId != NULL) {
119 *sessionId = lSessionId;
120 }
Eric Laurent5841db72009-09-09 05:16:08 -0700121 lStatus = reply.readInt32();
122 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800123 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800124 if (status) {
125 *status = lStatus;
126 }
Eric Laurent5841db72009-09-09 05:16:08 -0700127 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800128 }
129
130 virtual sp<IAudioRecord> openRecord(
131 pid_t pid,
Eric Laurentfa2877b2009-07-28 08:44:33 -0700132 int input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800133 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800134 audio_format_t format,
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700135 uint32_t channelMask,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800136 int frameCount,
137 uint32_t flags,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700138 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800139 status_t *status)
140 {
141 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700142 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800143 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
144 data.writeInt32(pid);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700145 data.writeInt32(input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800146 data.writeInt32(sampleRate);
147 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700148 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800149 data.writeInt32(frameCount);
150 data.writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700151 int lSessionId = 0;
152 if (sessionId != NULL) {
153 lSessionId = *sessionId;
154 }
155 data.writeInt32(lSessionId);
Eric Laurent5841db72009-09-09 05:16:08 -0700156 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
157 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000158 ALOGE("openRecord error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700159 } else {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700160 lSessionId = reply.readInt32();
161 if (sessionId != NULL) {
162 *sessionId = lSessionId;
163 }
Eric Laurent5841db72009-09-09 05:16:08 -0700164 lStatus = reply.readInt32();
165 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
166 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800167 if (status) {
168 *status = lStatus;
169 }
Eric Laurent5841db72009-09-09 05:16:08 -0700170 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800171 }
172
Eric Laurentfa2877b2009-07-28 08:44:33 -0700173 virtual uint32_t sampleRate(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800174 {
175 Parcel data, reply;
176 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700177 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800178 remote()->transact(SAMPLE_RATE, data, &reply);
179 return reply.readInt32();
180 }
181
Eric Laurentfa2877b2009-07-28 08:44:33 -0700182 virtual int channelCount(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800183 {
184 Parcel data, reply;
185 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700186 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800187 remote()->transact(CHANNEL_COUNT, data, &reply);
188 return reply.readInt32();
189 }
190
Glenn Kasten58f30212012-01-12 12:27:51 -0800191 virtual audio_format_t format(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800192 {
193 Parcel data, reply;
194 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700195 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800196 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800197 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800198 }
199
Eric Laurentfa2877b2009-07-28 08:44:33 -0700200 virtual size_t frameCount(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800201 {
202 Parcel data, reply;
203 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700204 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800205 remote()->transact(FRAME_COUNT, data, &reply);
206 return reply.readInt32();
207 }
208
Eric Laurentfa2877b2009-07-28 08:44:33 -0700209 virtual uint32_t latency(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800210 {
211 Parcel data, reply;
212 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700213 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800214 remote()->transact(LATENCY, data, &reply);
215 return reply.readInt32();
216 }
217
218 virtual status_t setMasterVolume(float value)
219 {
220 Parcel data, reply;
221 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
222 data.writeFloat(value);
223 remote()->transact(SET_MASTER_VOLUME, data, &reply);
224 return reply.readInt32();
225 }
226
227 virtual status_t setMasterMute(bool muted)
228 {
229 Parcel data, reply;
230 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
231 data.writeInt32(muted);
232 remote()->transact(SET_MASTER_MUTE, data, &reply);
233 return reply.readInt32();
234 }
235
236 virtual float masterVolume() const
237 {
238 Parcel data, reply;
239 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
240 remote()->transact(MASTER_VOLUME, data, &reply);
241 return reply.readFloat();
242 }
243
244 virtual bool masterMute() const
245 {
246 Parcel data, reply;
247 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
248 remote()->transact(MASTER_MUTE, data, &reply);
249 return reply.readInt32();
250 }
251
Glenn Kastenfff6d712012-01-12 16:38:12 -0800252 virtual status_t setStreamVolume(audio_stream_type_t stream, float value, int output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800253 {
254 Parcel data, reply;
255 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800256 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800257 data.writeFloat(value);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700258 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800259 remote()->transact(SET_STREAM_VOLUME, data, &reply);
260 return reply.readInt32();
261 }
262
Glenn Kastenfff6d712012-01-12 16:38:12 -0800263 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800264 {
265 Parcel data, reply;
266 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800267 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800268 data.writeInt32(muted);
269 remote()->transact(SET_STREAM_MUTE, data, &reply);
270 return reply.readInt32();
271 }
272
Glenn Kastenfff6d712012-01-12 16:38:12 -0800273 virtual float streamVolume(audio_stream_type_t stream, int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800274 {
275 Parcel data, reply;
276 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800277 data.writeInt32((int32_t) stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700278 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800279 remote()->transact(STREAM_VOLUME, data, &reply);
280 return reply.readFloat();
281 }
282
Glenn Kastenfff6d712012-01-12 16:38:12 -0800283 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800284 {
285 Parcel data, reply;
286 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800287 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800288 remote()->transact(STREAM_MUTE, data, &reply);
289 return reply.readInt32();
290 }
291
Glenn Kastenf78aee72012-01-04 11:00:47 -0800292 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800293 {
294 Parcel data, reply;
295 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
296 data.writeInt32(mode);
297 remote()->transact(SET_MODE, data, &reply);
298 return reply.readInt32();
299 }
300
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800301 virtual status_t setMicMute(bool state)
302 {
303 Parcel data, reply;
304 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
305 data.writeInt32(state);
306 remote()->transact(SET_MIC_MUTE, data, &reply);
307 return reply.readInt32();
308 }
309
310 virtual bool getMicMute() const
311 {
312 Parcel data, reply;
313 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
314 remote()->transact(GET_MIC_MUTE, data, &reply);
315 return reply.readInt32();
316 }
317
Eric Laurentfa2877b2009-07-28 08:44:33 -0700318 virtual status_t setParameters(int ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800319 {
320 Parcel data, reply;
321 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700322 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700323 data.writeString8(keyValuePairs);
324 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800325 return reply.readInt32();
326 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700327
Glenn Kastenf587ba52012-01-26 16:25:10 -0800328 virtual String8 getParameters(int ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700329 {
330 Parcel data, reply;
331 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700332 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700333 data.writeString8(keys);
334 remote()->transact(GET_PARAMETERS, data, &reply);
335 return reply.readString8();
336 }
337
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800338 virtual void registerClient(const sp<IAudioFlingerClient>& client)
339 {
340 Parcel data, reply;
341 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
342 data.writeStrongBinder(client->asBinder());
343 remote()->transact(REGISTER_CLIENT, data, &reply);
344 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700345
Glenn Kastenf587ba52012-01-26 16:25:10 -0800346 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, int channelCount) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800347 {
348 Parcel data, reply;
349 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
350 data.writeInt32(sampleRate);
351 data.writeInt32(format);
352 data.writeInt32(channelCount);
353 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
354 return reply.readInt32();
355 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700356
Eric Laurentfa2877b2009-07-28 08:44:33 -0700357 virtual int openOutput(uint32_t *pDevices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700358 uint32_t *pSamplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800359 audio_format_t *pFormat,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700360 uint32_t *pChannels,
361 uint32_t *pLatencyMs,
362 uint32_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800363 {
364 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700365 uint32_t devices = pDevices ? *pDevices : 0;
366 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
Glenn Kasten58f30212012-01-12 12:27:51 -0800367 audio_format_t format = pFormat ? *pFormat : AUDIO_FORMAT_DEFAULT;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700368 uint32_t channels = pChannels ? *pChannels : 0;
369 uint32_t latency = pLatencyMs ? *pLatencyMs : 0;
370
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800371 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700372 data.writeInt32(devices);
373 data.writeInt32(samplingRate);
374 data.writeInt32(format);
375 data.writeInt32(channels);
376 data.writeInt32(latency);
377 data.writeInt32(flags);
378 remote()->transact(OPEN_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700379 int output = reply.readInt32();
Steve Block3856b092011-10-20 11:56:00 +0100380 ALOGV("openOutput() returned output, %p", output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700381 devices = reply.readInt32();
382 if (pDevices) *pDevices = devices;
383 samplingRate = reply.readInt32();
384 if (pSamplingRate) *pSamplingRate = samplingRate;
Glenn Kasten58f30212012-01-12 12:27:51 -0800385 format = (audio_format_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700386 if (pFormat) *pFormat = format;
387 channels = reply.readInt32();
388 if (pChannels) *pChannels = channels;
389 latency = reply.readInt32();
390 if (pLatencyMs) *pLatencyMs = latency;
391 return output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800392 }
393
Eric Laurentfa2877b2009-07-28 08:44:33 -0700394 virtual int openDuplicateOutput(int output1, int output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800395 {
396 Parcel data, reply;
397 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700398 data.writeInt32(output1);
399 data.writeInt32(output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700400 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700401 return reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700402 }
403
Eric Laurentfa2877b2009-07-28 08:44:33 -0700404 virtual status_t closeOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700405 {
406 Parcel data, reply;
407 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700408 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700409 remote()->transact(CLOSE_OUTPUT, data, &reply);
410 return reply.readInt32();
411 }
412
Eric Laurentfa2877b2009-07-28 08:44:33 -0700413 virtual status_t suspendOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700414 {
415 Parcel data, reply;
416 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700417 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700418 remote()->transact(SUSPEND_OUTPUT, data, &reply);
419 return reply.readInt32();
420 }
421
Eric Laurentfa2877b2009-07-28 08:44:33 -0700422 virtual status_t restoreOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700423 {
424 Parcel data, reply;
425 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700426 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700427 remote()->transact(RESTORE_OUTPUT, data, &reply);
428 return reply.readInt32();
429 }
430
Eric Laurentfa2877b2009-07-28 08:44:33 -0700431 virtual int openInput(uint32_t *pDevices,
432 uint32_t *pSamplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800433 audio_format_t *pFormat,
Eric Laurentfa2877b2009-07-28 08:44:33 -0700434 uint32_t *pChannels,
Glenn Kastende9719b2012-01-27 12:32:34 -0800435 audio_in_acoustics_t acoustics)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700436 {
437 Parcel data, reply;
438 uint32_t devices = pDevices ? *pDevices : 0;
439 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
Glenn Kasten58f30212012-01-12 12:27:51 -0800440 audio_format_t format = pFormat ? *pFormat : AUDIO_FORMAT_DEFAULT;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700441 uint32_t channels = pChannels ? *pChannels : 0;
442
443 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
444 data.writeInt32(devices);
445 data.writeInt32(samplingRate);
446 data.writeInt32(format);
447 data.writeInt32(channels);
Glenn Kastende9719b2012-01-27 12:32:34 -0800448 data.writeInt32((int32_t) acoustics);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700449 remote()->transact(OPEN_INPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700450 int input = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700451 devices = reply.readInt32();
452 if (pDevices) *pDevices = devices;
453 samplingRate = reply.readInt32();
454 if (pSamplingRate) *pSamplingRate = samplingRate;
Glenn Kasten58f30212012-01-12 12:27:51 -0800455 format = (audio_format_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700456 if (pFormat) *pFormat = format;
457 channels = reply.readInt32();
458 if (pChannels) *pChannels = channels;
459 return input;
460 }
461
Eric Laurentfa2877b2009-07-28 08:44:33 -0700462 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700463 {
464 Parcel data, reply;
465 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700466 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700467 remote()->transact(CLOSE_INPUT, data, &reply);
468 return reply.readInt32();
469 }
470
Glenn Kastenfff6d712012-01-12 16:38:12 -0800471 virtual status_t setStreamOutput(audio_stream_type_t stream, int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700472 {
473 Parcel data, reply;
474 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800475 data.writeInt32((int32_t) stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700476 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700477 remote()->transact(SET_STREAM_OUTPUT, data, &reply);
478 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800479 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700480
481 virtual status_t setVoiceVolume(float volume)
482 {
483 Parcel data, reply;
484 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
485 data.writeFloat(volume);
486 remote()->transact(SET_VOICE_VOLUME, data, &reply);
487 return reply.readInt32();
488 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800489
Glenn Kastenf587ba52012-01-26 16:25:10 -0800490 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800491 {
492 Parcel data, reply;
493 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
494 data.writeInt32(output);
495 remote()->transact(GET_RENDER_POSITION, data, &reply);
496 status_t status = reply.readInt32();
497 if (status == NO_ERROR) {
498 uint32_t tmp = reply.readInt32();
499 if (halFrames) {
500 *halFrames = tmp;
501 }
502 tmp = reply.readInt32();
503 if (dspFrames) {
504 *dspFrames = tmp;
505 }
506 }
507 return status;
508 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800509
Glenn Kastenf587ba52012-01-26 16:25:10 -0800510 virtual unsigned int getInputFramesLost(int ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800511 {
512 Parcel data, reply;
513 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
514 data.writeInt32(ioHandle);
515 remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
516 return reply.readInt32();
517 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700518
519 virtual int newAudioSessionId()
520 {
521 Parcel data, reply;
522 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
523 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
524 int id = 0;
525 if (status == NO_ERROR) {
526 id = reply.readInt32();
527 }
528 return id;
529 }
530
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700531 virtual void acquireAudioSessionId(int audioSession)
532 {
533 Parcel data, reply;
534 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
535 data.writeInt32(audioSession);
536 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
537 }
538
539 virtual void releaseAudioSessionId(int audioSession)
540 {
541 Parcel data, reply;
542 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
543 data.writeInt32(audioSession);
544 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
545 }
546
Glenn Kastenf587ba52012-01-26 16:25:10 -0800547 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700548 {
549 Parcel data, reply;
550 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
551 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
552 if (status != NO_ERROR) {
553 return status;
554 }
555 status = reply.readInt32();
556 if (status != NO_ERROR) {
557 return status;
558 }
559 if (numEffects) {
560 *numEffects = (uint32_t)reply.readInt32();
561 }
562 return NO_ERROR;
563 }
564
Glenn Kastenf587ba52012-01-26 16:25:10 -0800565 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700566 {
567 if (pDescriptor == NULL) {
568 return BAD_VALUE;
569 }
570 Parcel data, reply;
571 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700572 data.writeInt32(index);
573 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700574 if (status != NO_ERROR) {
575 return status;
576 }
577 status = reply.readInt32();
578 if (status != NO_ERROR) {
579 return status;
580 }
581 reply.read(pDescriptor, sizeof(effect_descriptor_t));
582 return NO_ERROR;
583 }
584
Glenn Kasten5e92a782012-01-30 07:40:52 -0800585 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800586 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700587 {
588 if (pUuid == NULL || pDescriptor == NULL) {
589 return BAD_VALUE;
590 }
591 Parcel data, reply;
592 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
593 data.write(pUuid, sizeof(effect_uuid_t));
594 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
595 if (status != NO_ERROR) {
596 return status;
597 }
598 status = reply.readInt32();
599 if (status != NO_ERROR) {
600 return status;
601 }
602 reply.read(pDescriptor, sizeof(effect_descriptor_t));
603 return NO_ERROR;
604 }
605
606 virtual sp<IEffect> createEffect(pid_t pid,
607 effect_descriptor_t *pDesc,
608 const sp<IEffectClient>& client,
609 int32_t priority,
610 int output,
611 int sessionId,
612 status_t *status,
613 int *id,
614 int *enabled)
615 {
616 Parcel data, reply;
617 sp<IEffect> effect;
618
619 if (pDesc == NULL) {
620 return effect;
621 if (status) {
622 *status = BAD_VALUE;
623 }
624 }
625
626 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
627 data.writeInt32(pid);
628 data.write(pDesc, sizeof(effect_descriptor_t));
629 data.writeStrongBinder(client->asBinder());
630 data.writeInt32(priority);
631 data.writeInt32(output);
632 data.writeInt32(sessionId);
633
634 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
635 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000636 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700637 } else {
638 lStatus = reply.readInt32();
639 int tmp = reply.readInt32();
640 if (id) {
641 *id = tmp;
642 }
643 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800644 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700645 *enabled = tmp;
646 }
647 effect = interface_cast<IEffect>(reply.readStrongBinder());
648 reply.read(pDesc, sizeof(effect_descriptor_t));
649 }
650 if (status) {
651 *status = lStatus;
652 }
653
654 return effect;
655 }
Eric Laurentde070132010-07-13 04:45:46 -0700656
657 virtual status_t moveEffects(int session, int srcOutput, int dstOutput)
658 {
659 Parcel data, reply;
660 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
661 data.writeInt32(session);
662 data.writeInt32(srcOutput);
663 data.writeInt32(dstOutput);
664 remote()->transact(MOVE_EFFECTS, data, &reply);
665 return reply.readInt32();
666 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800667};
668
669IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
670
671// ----------------------------------------------------------------------
672
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800673status_t BnAudioFlinger::onTransact(
674 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
675{
676 switch(code) {
677 case CREATE_TRACK: {
678 CHECK_INTERFACE(IAudioFlinger, data, reply);
679 pid_t pid = data.readInt32();
680 int streamType = data.readInt32();
681 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800682 audio_format_t format = (audio_format_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800683 int channelCount = data.readInt32();
684 size_t bufferCount = data.readInt32();
685 uint32_t flags = data.readInt32();
686 sp<IMemory> buffer = interface_cast<IMemory>(data.readStrongBinder());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700687 int output = data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700688 int sessionId = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800689 status_t status;
690 sp<IAudioTrack> track = createTrack(pid,
Glenn Kastenfff6d712012-01-12 16:38:12 -0800691 (audio_stream_type_t) streamType, sampleRate, format,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700692 channelCount, bufferCount, flags, buffer, output, &sessionId, &status);
693 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800694 reply->writeInt32(status);
695 reply->writeStrongBinder(track->asBinder());
696 return NO_ERROR;
697 } break;
698 case OPEN_RECORD: {
699 CHECK_INTERFACE(IAudioFlinger, data, reply);
700 pid_t pid = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700701 int input = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800702 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800703 audio_format_t format = (audio_format_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800704 int channelCount = data.readInt32();
705 size_t bufferCount = data.readInt32();
706 uint32_t flags = data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700707 int sessionId = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800708 status_t status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700709 sp<IAudioRecord> record = openRecord(pid, input,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700710 sampleRate, format, channelCount, bufferCount, flags, &sessionId, &status);
711 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800712 reply->writeInt32(status);
713 reply->writeStrongBinder(record->asBinder());
714 return NO_ERROR;
715 } break;
716 case SAMPLE_RATE: {
717 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700718 reply->writeInt32( sampleRate(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800719 return NO_ERROR;
720 } break;
721 case CHANNEL_COUNT: {
722 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700723 reply->writeInt32( channelCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800724 return NO_ERROR;
725 } break;
726 case FORMAT: {
727 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700728 reply->writeInt32( format(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800729 return NO_ERROR;
730 } break;
731 case FRAME_COUNT: {
732 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700733 reply->writeInt32( frameCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800734 return NO_ERROR;
735 } break;
736 case LATENCY: {
737 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700738 reply->writeInt32( latency(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800739 return NO_ERROR;
740 } break;
741 case SET_MASTER_VOLUME: {
742 CHECK_INTERFACE(IAudioFlinger, data, reply);
743 reply->writeInt32( setMasterVolume(data.readFloat()) );
744 return NO_ERROR;
745 } break;
746 case SET_MASTER_MUTE: {
747 CHECK_INTERFACE(IAudioFlinger, data, reply);
748 reply->writeInt32( setMasterMute(data.readInt32()) );
749 return NO_ERROR;
750 } break;
751 case MASTER_VOLUME: {
752 CHECK_INTERFACE(IAudioFlinger, data, reply);
753 reply->writeFloat( masterVolume() );
754 return NO_ERROR;
755 } break;
756 case MASTER_MUTE: {
757 CHECK_INTERFACE(IAudioFlinger, data, reply);
758 reply->writeInt32( masterMute() );
759 return NO_ERROR;
760 } break;
761 case SET_STREAM_VOLUME: {
762 CHECK_INTERFACE(IAudioFlinger, data, reply);
763 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700764 float volume = data.readFloat();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700765 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -0800766 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800767 return NO_ERROR;
768 } break;
769 case SET_STREAM_MUTE: {
770 CHECK_INTERFACE(IAudioFlinger, data, reply);
771 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -0800772 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800773 return NO_ERROR;
774 } break;
775 case STREAM_VOLUME: {
776 CHECK_INTERFACE(IAudioFlinger, data, reply);
777 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700778 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -0800779 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800780 return NO_ERROR;
781 } break;
782 case STREAM_MUTE: {
783 CHECK_INTERFACE(IAudioFlinger, data, reply);
784 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -0800785 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800786 return NO_ERROR;
787 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800788 case SET_MODE: {
789 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -0800790 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800791 reply->writeInt32( setMode(mode) );
792 return NO_ERROR;
793 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800794 case SET_MIC_MUTE: {
795 CHECK_INTERFACE(IAudioFlinger, data, reply);
796 int state = data.readInt32();
797 reply->writeInt32( setMicMute(state) );
798 return NO_ERROR;
799 } break;
800 case GET_MIC_MUTE: {
801 CHECK_INTERFACE(IAudioFlinger, data, reply);
802 reply->writeInt32( getMicMute() );
803 return NO_ERROR;
804 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700805 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800806 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700807 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700808 String8 keyValuePairs(data.readString8());
809 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800810 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700811 } break;
812 case GET_PARAMETERS: {
813 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700814 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700815 String8 keys(data.readString8());
816 reply->writeString8(getParameters(ioHandle, keys));
817 return NO_ERROR;
818 } break;
819
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800820 case REGISTER_CLIENT: {
821 CHECK_INTERFACE(IAudioFlinger, data, reply);
822 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(data.readStrongBinder());
823 registerClient(client);
824 return NO_ERROR;
825 } break;
826 case GET_INPUTBUFFERSIZE: {
827 CHECK_INTERFACE(IAudioFlinger, data, reply);
828 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800829 audio_format_t format = (audio_format_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800830 int channelCount = data.readInt32();
831 reply->writeInt32( getInputBufferSize(sampleRate, format, channelCount) );
832 return NO_ERROR;
833 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700834 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800835 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700836 uint32_t devices = data.readInt32();
837 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800838 audio_format_t format = (audio_format_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700839 uint32_t channels = data.readInt32();
840 uint32_t latency = data.readInt32();
841 uint32_t flags = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700842 int output = openOutput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700843 &samplingRate,
844 &format,
845 &channels,
846 &latency,
847 flags);
Steve Block3856b092011-10-20 11:56:00 +0100848 ALOGV("OPEN_OUTPUT output, %p", output);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700849 reply->writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700850 reply->writeInt32(devices);
851 reply->writeInt32(samplingRate);
852 reply->writeInt32(format);
853 reply->writeInt32(channels);
854 reply->writeInt32(latency);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800855 return NO_ERROR;
856 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700857 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800858 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700859 int output1 = data.readInt32();
860 int output2 = data.readInt32();
861 reply->writeInt32(openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700862 return NO_ERROR;
863 } break;
864 case CLOSE_OUTPUT: {
865 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700866 reply->writeInt32(closeOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700867 return NO_ERROR;
868 } break;
869 case SUSPEND_OUTPUT: {
870 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700871 reply->writeInt32(suspendOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700872 return NO_ERROR;
873 } break;
874 case RESTORE_OUTPUT: {
875 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700876 reply->writeInt32(restoreOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700877 return NO_ERROR;
878 } break;
879 case OPEN_INPUT: {
880 CHECK_INTERFACE(IAudioFlinger, data, reply);
881 uint32_t devices = data.readInt32();
882 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800883 audio_format_t format = (audio_format_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700884 uint32_t channels = data.readInt32();
Glenn Kastende9719b2012-01-27 12:32:34 -0800885 audio_in_acoustics_t acoustics = (audio_in_acoustics_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700886
Eric Laurentfa2877b2009-07-28 08:44:33 -0700887 int input = openInput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700888 &samplingRate,
889 &format,
890 &channels,
Glenn Kastende9719b2012-01-27 12:32:34 -0800891 acoustics);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700892 reply->writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700893 reply->writeInt32(devices);
894 reply->writeInt32(samplingRate);
895 reply->writeInt32(format);
896 reply->writeInt32(channels);
897 return NO_ERROR;
898 } break;
899 case CLOSE_INPUT: {
900 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700901 reply->writeInt32(closeInput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700902 return NO_ERROR;
903 } break;
904 case SET_STREAM_OUTPUT: {
905 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700906 uint32_t stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700907 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -0800908 reply->writeInt32(setStreamOutput((audio_stream_type_t) stream, output));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800909 return NO_ERROR;
910 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700911 case SET_VOICE_VOLUME: {
912 CHECK_INTERFACE(IAudioFlinger, data, reply);
913 float volume = data.readFloat();
914 reply->writeInt32( setVoiceVolume(volume) );
915 return NO_ERROR;
916 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -0800917 case GET_RENDER_POSITION: {
918 CHECK_INTERFACE(IAudioFlinger, data, reply);
919 int output = data.readInt32();
920 uint32_t halFrames;
921 uint32_t dspFrames;
922 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
923 reply->writeInt32(status);
924 if (status == NO_ERROR) {
925 reply->writeInt32(halFrames);
926 reply->writeInt32(dspFrames);
927 }
928 return NO_ERROR;
929 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800930 case GET_INPUT_FRAMES_LOST: {
931 CHECK_INTERFACE(IAudioFlinger, data, reply);
932 int ioHandle = data.readInt32();
933 reply->writeInt32(getInputFramesLost(ioHandle));
934 return NO_ERROR;
935 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700936 case NEW_AUDIO_SESSION_ID: {
937 CHECK_INTERFACE(IAudioFlinger, data, reply);
938 reply->writeInt32(newAudioSessionId());
939 return NO_ERROR;
940 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700941 case ACQUIRE_AUDIO_SESSION_ID: {
942 CHECK_INTERFACE(IAudioFlinger, data, reply);
943 int audioSession = data.readInt32();
944 acquireAudioSessionId(audioSession);
945 return NO_ERROR;
946 } break;
947 case RELEASE_AUDIO_SESSION_ID: {
948 CHECK_INTERFACE(IAudioFlinger, data, reply);
949 int audioSession = data.readInt32();
950 releaseAudioSessionId(audioSession);
951 return NO_ERROR;
952 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700953 case QUERY_NUM_EFFECTS: {
954 CHECK_INTERFACE(IAudioFlinger, data, reply);
955 uint32_t numEffects;
956 status_t status = queryNumberEffects(&numEffects);
957 reply->writeInt32(status);
958 if (status == NO_ERROR) {
959 reply->writeInt32((int32_t)numEffects);
960 }
961 return NO_ERROR;
962 }
Eric Laurentffe9c252010-06-23 17:38:20 -0700963 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700964 CHECK_INTERFACE(IAudioFlinger, data, reply);
965 effect_descriptor_t desc;
Eric Laurentffe9c252010-06-23 17:38:20 -0700966 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700967 reply->writeInt32(status);
968 if (status == NO_ERROR) {
969 reply->write(&desc, sizeof(effect_descriptor_t));
970 }
971 return NO_ERROR;
972 }
973 case GET_EFFECT_DESCRIPTOR: {
974 CHECK_INTERFACE(IAudioFlinger, data, reply);
975 effect_uuid_t uuid;
976 data.read(&uuid, sizeof(effect_uuid_t));
977 effect_descriptor_t desc;
978 status_t status = getEffectDescriptor(&uuid, &desc);
979 reply->writeInt32(status);
980 if (status == NO_ERROR) {
981 reply->write(&desc, sizeof(effect_descriptor_t));
982 }
983 return NO_ERROR;
984 }
985 case CREATE_EFFECT: {
986 CHECK_INTERFACE(IAudioFlinger, data, reply);
987 pid_t pid = data.readInt32();
988 effect_descriptor_t desc;
989 data.read(&desc, sizeof(effect_descriptor_t));
990 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
991 int32_t priority = data.readInt32();
992 int output = data.readInt32();
993 int sessionId = data.readInt32();
994 status_t status;
995 int id;
996 int enabled;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800997
Eric Laurentbe916aa2010-06-01 23:49:17 -0700998 sp<IEffect> effect = createEffect(pid, &desc, client, priority, output, sessionId, &status, &id, &enabled);
999 reply->writeInt32(status);
1000 reply->writeInt32(id);
1001 reply->writeInt32(enabled);
1002 reply->writeStrongBinder(effect->asBinder());
1003 reply->write(&desc, sizeof(effect_descriptor_t));
1004 return NO_ERROR;
1005 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001006 case MOVE_EFFECTS: {
1007 CHECK_INTERFACE(IAudioFlinger, data, reply);
1008 int session = data.readInt32();
1009 int srcOutput = data.readInt32();
1010 int dstOutput = data.readInt32();
1011 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1012 return NO_ERROR;
1013 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001014 default:
1015 return BBinder::onTransact(code, data, reply, flags);
1016 }
1017}
1018
1019// ----------------------------------------------------------------------------
1020
1021}; // namespace android