blob: f2a8db390c302333c89ad08c5f47fa83242ab5ce [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/* //device/extlibs/pv/android/IAudioflinger.cpp
2**
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 Laurentb72a3962010-01-25 08:49:09 -080050 IS_STREAM_ACTIVE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070051 SET_PARAMETERS,
52 GET_PARAMETERS,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080053 REGISTER_CLIENT,
54 GET_INPUTBUFFERSIZE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070055 OPEN_OUTPUT,
56 OPEN_DUPLICATE_OUTPUT,
57 CLOSE_OUTPUT,
58 SUSPEND_OUTPUT,
59 RESTORE_OUTPUT,
60 OPEN_INPUT,
61 CLOSE_INPUT,
Eric Laurentf0ee6f42009-10-21 08:14:22 -070062 SET_STREAM_OUTPUT,
Eric Laurent342e9cf2010-01-19 17:37:09 -080063 SET_VOICE_VOLUME,
Eric Laurent05bca2f2010-02-26 02:47:27 -080064 GET_RENDER_POSITION,
Eric Laurentbe916aa2010-06-01 23:49:17 -070065 GET_INPUT_FRAMES_LOST,
66 NEW_AUDIO_SESSION_ID,
67 LOAD_EFFECT_LIBRARY,
68 UNLOAD_EFFECT_LIBRARY,
69 QUERY_NUM_EFFECTS,
70 QUERY_NEXT_EFFECT,
71 GET_EFFECT_DESCRIPTOR,
72 CREATE_EFFECT
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,
85 int streamType,
86 uint32_t sampleRate,
87 int format,
88 int channelCount,
89 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);
100 data.writeInt32(streamType);
101 data.writeInt32(sampleRate);
102 data.writeInt32(format);
103 data.writeInt32(channelCount);
104 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) {
115 LOGE("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,
134 int format,
135 int channelCount,
136 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);
148 data.writeInt32(channelCount);
149 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) {
158 LOGE("openRecord error: %s", strerror(-lStatus));
159 } 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
Eric Laurentfa2877b2009-07-28 08:44:33 -0700191 virtual int 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);
197 return reply.readInt32();
198 }
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
Eric Laurentfa2877b2009-07-28 08:44:33 -0700252 virtual status_t setStreamVolume(int 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());
256 data.writeInt32(stream);
257 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
263 virtual status_t setStreamMute(int stream, bool muted)
264 {
265 Parcel data, reply;
266 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
267 data.writeInt32(stream);
268 data.writeInt32(muted);
269 remote()->transact(SET_STREAM_MUTE, data, &reply);
270 return reply.readInt32();
271 }
272
Eric Laurentfa2877b2009-07-28 08:44:33 -0700273 virtual float streamVolume(int stream, int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800274 {
275 Parcel data, reply;
276 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
277 data.writeInt32(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
283 virtual bool streamMute(int stream) const
284 {
285 Parcel data, reply;
286 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
287 data.writeInt32(stream);
288 remote()->transact(STREAM_MUTE, data, &reply);
289 return reply.readInt32();
290 }
291
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800292 virtual status_t setMode(int mode)
293 {
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 Laurentb72a3962010-01-25 08:49:09 -0800318 virtual bool isStreamActive(int stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800319 {
320 Parcel data, reply;
321 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentb72a3962010-01-25 08:49:09 -0800322 data.writeInt32(stream);
323 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800324 return reply.readInt32();
325 }
326
Eric Laurentfa2877b2009-07-28 08:44:33 -0700327 virtual status_t setParameters(int ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800328 {
329 Parcel data, reply;
330 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700331 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700332 data.writeString8(keyValuePairs);
333 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800334 return reply.readInt32();
335 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700336
Eric Laurentfa2877b2009-07-28 08:44:33 -0700337 virtual String8 getParameters(int ioHandle, const String8& keys)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700338 {
339 Parcel data, reply;
340 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700341 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700342 data.writeString8(keys);
343 remote()->transact(GET_PARAMETERS, data, &reply);
344 return reply.readString8();
345 }
346
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800347 virtual void registerClient(const sp<IAudioFlingerClient>& client)
348 {
349 Parcel data, reply;
350 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
351 data.writeStrongBinder(client->asBinder());
352 remote()->transact(REGISTER_CLIENT, data, &reply);
353 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700354
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800355 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
356 {
357 Parcel data, reply;
358 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
359 data.writeInt32(sampleRate);
360 data.writeInt32(format);
361 data.writeInt32(channelCount);
362 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
363 return reply.readInt32();
364 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700365
Eric Laurentfa2877b2009-07-28 08:44:33 -0700366 virtual int openOutput(uint32_t *pDevices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700367 uint32_t *pSamplingRate,
368 uint32_t *pFormat,
369 uint32_t *pChannels,
370 uint32_t *pLatencyMs,
371 uint32_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800372 {
373 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700374 uint32_t devices = pDevices ? *pDevices : 0;
375 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
376 uint32_t format = pFormat ? *pFormat : 0;
377 uint32_t channels = pChannels ? *pChannels : 0;
378 uint32_t latency = pLatencyMs ? *pLatencyMs : 0;
379
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800380 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700381 data.writeInt32(devices);
382 data.writeInt32(samplingRate);
383 data.writeInt32(format);
384 data.writeInt32(channels);
385 data.writeInt32(latency);
386 data.writeInt32(flags);
387 remote()->transact(OPEN_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700388 int output = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700389 LOGV("openOutput() returned output, %p", output);
390 devices = reply.readInt32();
391 if (pDevices) *pDevices = devices;
392 samplingRate = reply.readInt32();
393 if (pSamplingRate) *pSamplingRate = samplingRate;
394 format = reply.readInt32();
395 if (pFormat) *pFormat = format;
396 channels = reply.readInt32();
397 if (pChannels) *pChannels = channels;
398 latency = reply.readInt32();
399 if (pLatencyMs) *pLatencyMs = latency;
400 return output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800401 }
402
Eric Laurentfa2877b2009-07-28 08:44:33 -0700403 virtual int openDuplicateOutput(int output1, int output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800404 {
405 Parcel data, reply;
406 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700407 data.writeInt32(output1);
408 data.writeInt32(output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700409 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700410 return reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700411 }
412
Eric Laurentfa2877b2009-07-28 08:44:33 -0700413 virtual status_t closeOutput(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(CLOSE_OUTPUT, data, &reply);
419 return reply.readInt32();
420 }
421
Eric Laurentfa2877b2009-07-28 08:44:33 -0700422 virtual status_t suspendOutput(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(SUSPEND_OUTPUT, data, &reply);
428 return reply.readInt32();
429 }
430
Eric Laurentfa2877b2009-07-28 08:44:33 -0700431 virtual status_t restoreOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700432 {
433 Parcel data, reply;
434 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700435 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700436 remote()->transact(RESTORE_OUTPUT, data, &reply);
437 return reply.readInt32();
438 }
439
Eric Laurentfa2877b2009-07-28 08:44:33 -0700440 virtual int openInput(uint32_t *pDevices,
441 uint32_t *pSamplingRate,
442 uint32_t *pFormat,
443 uint32_t *pChannels,
444 uint32_t acoustics)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700445 {
446 Parcel data, reply;
447 uint32_t devices = pDevices ? *pDevices : 0;
448 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
449 uint32_t format = pFormat ? *pFormat : 0;
450 uint32_t channels = pChannels ? *pChannels : 0;
451
452 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
453 data.writeInt32(devices);
454 data.writeInt32(samplingRate);
455 data.writeInt32(format);
456 data.writeInt32(channels);
457 data.writeInt32(acoustics);
458 remote()->transact(OPEN_INPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700459 int input = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700460 devices = reply.readInt32();
461 if (pDevices) *pDevices = devices;
462 samplingRate = reply.readInt32();
463 if (pSamplingRate) *pSamplingRate = samplingRate;
464 format = reply.readInt32();
465 if (pFormat) *pFormat = format;
466 channels = reply.readInt32();
467 if (pChannels) *pChannels = channels;
468 return input;
469 }
470
Eric Laurentfa2877b2009-07-28 08:44:33 -0700471 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700472 {
473 Parcel data, reply;
474 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700475 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700476 remote()->transact(CLOSE_INPUT, data, &reply);
477 return reply.readInt32();
478 }
479
Eric Laurentfa2877b2009-07-28 08:44:33 -0700480 virtual status_t setStreamOutput(uint32_t stream, int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700481 {
482 Parcel data, reply;
483 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
484 data.writeInt32(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700485 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700486 remote()->transact(SET_STREAM_OUTPUT, data, &reply);
487 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800488 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700489
490 virtual status_t setVoiceVolume(float volume)
491 {
492 Parcel data, reply;
493 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
494 data.writeFloat(volume);
495 remote()->transact(SET_VOICE_VOLUME, data, &reply);
496 return reply.readInt32();
497 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800498
499 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int output)
500 {
501 Parcel data, reply;
502 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
503 data.writeInt32(output);
504 remote()->transact(GET_RENDER_POSITION, data, &reply);
505 status_t status = reply.readInt32();
506 if (status == NO_ERROR) {
507 uint32_t tmp = reply.readInt32();
508 if (halFrames) {
509 *halFrames = tmp;
510 }
511 tmp = reply.readInt32();
512 if (dspFrames) {
513 *dspFrames = tmp;
514 }
515 }
516 return status;
517 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800518
519 virtual unsigned int getInputFramesLost(int ioHandle)
520 {
521 Parcel data, reply;
522 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
523 data.writeInt32(ioHandle);
524 remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
525 return reply.readInt32();
526 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700527
528 virtual int newAudioSessionId()
529 {
530 Parcel data, reply;
531 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
532 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
533 int id = 0;
534 if (status == NO_ERROR) {
535 id = reply.readInt32();
536 }
537 return id;
538 }
539
540 virtual status_t loadEffectLibrary(const char *libPath, int *handle)
541 {
542 if (libPath == NULL || handle == NULL) {
543 return BAD_VALUE;
544 }
545 *handle = 0;
546 Parcel data, reply;
547 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
548 data.writeCString(libPath);
549 status_t status = remote()->transact(LOAD_EFFECT_LIBRARY, data, &reply);
550 if (status == NO_ERROR) {
551 status = reply.readInt32();
552 if (status == NO_ERROR) {
553 *handle = reply.readInt32();
554 }
555 }
556 return status;
557 }
558
559 virtual status_t unloadEffectLibrary(int handle)
560 {
561 Parcel data, reply;
562 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
563 data.writeInt32(handle);
564 status_t status = remote()->transact(UNLOAD_EFFECT_LIBRARY, data, &reply);
565 if (status == NO_ERROR) {
566 status = reply.readInt32();
567 }
568 return status;
569 }
570
571 virtual status_t queryNumberEffects(uint32_t *numEffects)
572 {
573 Parcel data, reply;
574 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
575 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
576 if (status != NO_ERROR) {
577 return status;
578 }
579 status = reply.readInt32();
580 if (status != NO_ERROR) {
581 return status;
582 }
583 if (numEffects) {
584 *numEffects = (uint32_t)reply.readInt32();
585 }
586 return NO_ERROR;
587 }
588
589 virtual status_t queryNextEffect(effect_descriptor_t *pDescriptor)
590 {
591 if (pDescriptor == NULL) {
592 return BAD_VALUE;
593 }
594 Parcel data, reply;
595 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
596 status_t status = remote()->transact(QUERY_NEXT_EFFECT, data, &reply);
597 if (status != NO_ERROR) {
598 return status;
599 }
600 status = reply.readInt32();
601 if (status != NO_ERROR) {
602 return status;
603 }
604 reply.read(pDescriptor, sizeof(effect_descriptor_t));
605 return NO_ERROR;
606 }
607
608 virtual status_t getEffectDescriptor(effect_uuid_t *pUuid, effect_descriptor_t *pDescriptor)
609 {
610 if (pUuid == NULL || pDescriptor == NULL) {
611 return BAD_VALUE;
612 }
613 Parcel data, reply;
614 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
615 data.write(pUuid, sizeof(effect_uuid_t));
616 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
617 if (status != NO_ERROR) {
618 return status;
619 }
620 status = reply.readInt32();
621 if (status != NO_ERROR) {
622 return status;
623 }
624 reply.read(pDescriptor, sizeof(effect_descriptor_t));
625 return NO_ERROR;
626 }
627
628 virtual sp<IEffect> createEffect(pid_t pid,
629 effect_descriptor_t *pDesc,
630 const sp<IEffectClient>& client,
631 int32_t priority,
632 int output,
633 int sessionId,
634 status_t *status,
635 int *id,
636 int *enabled)
637 {
638 Parcel data, reply;
639 sp<IEffect> effect;
640
641 if (pDesc == NULL) {
642 return effect;
643 if (status) {
644 *status = BAD_VALUE;
645 }
646 }
647
648 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
649 data.writeInt32(pid);
650 data.write(pDesc, sizeof(effect_descriptor_t));
651 data.writeStrongBinder(client->asBinder());
652 data.writeInt32(priority);
653 data.writeInt32(output);
654 data.writeInt32(sessionId);
655
656 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
657 if (lStatus != NO_ERROR) {
658 LOGE("createEffect error: %s", strerror(-lStatus));
659 } else {
660 lStatus = reply.readInt32();
661 int tmp = reply.readInt32();
662 if (id) {
663 *id = tmp;
664 }
665 tmp = reply.readInt32();
666 if (enabled) {
667 *enabled = tmp;
668 }
669 effect = interface_cast<IEffect>(reply.readStrongBinder());
670 reply.read(pDesc, sizeof(effect_descriptor_t));
671 }
672 if (status) {
673 *status = lStatus;
674 }
675
676 return effect;
677 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800678};
679
680IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
681
682// ----------------------------------------------------------------------
683
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800684status_t BnAudioFlinger::onTransact(
685 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
686{
687 switch(code) {
688 case CREATE_TRACK: {
689 CHECK_INTERFACE(IAudioFlinger, data, reply);
690 pid_t pid = data.readInt32();
691 int streamType = data.readInt32();
692 uint32_t sampleRate = data.readInt32();
693 int format = data.readInt32();
694 int channelCount = data.readInt32();
695 size_t bufferCount = data.readInt32();
696 uint32_t flags = data.readInt32();
697 sp<IMemory> buffer = interface_cast<IMemory>(data.readStrongBinder());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700698 int output = data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700699 int sessionId = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800700 status_t status;
701 sp<IAudioTrack> track = createTrack(pid,
702 streamType, sampleRate, format,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700703 channelCount, bufferCount, flags, buffer, output, &sessionId, &status);
704 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800705 reply->writeInt32(status);
706 reply->writeStrongBinder(track->asBinder());
707 return NO_ERROR;
708 } break;
709 case OPEN_RECORD: {
710 CHECK_INTERFACE(IAudioFlinger, data, reply);
711 pid_t pid = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700712 int input = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800713 uint32_t sampleRate = data.readInt32();
714 int format = data.readInt32();
715 int channelCount = data.readInt32();
716 size_t bufferCount = data.readInt32();
717 uint32_t flags = data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700718 int sessionId = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800719 status_t status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700720 sp<IAudioRecord> record = openRecord(pid, input,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700721 sampleRate, format, channelCount, bufferCount, flags, &sessionId, &status);
722 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800723 reply->writeInt32(status);
724 reply->writeStrongBinder(record->asBinder());
725 return NO_ERROR;
726 } break;
727 case SAMPLE_RATE: {
728 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700729 reply->writeInt32( sampleRate(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800730 return NO_ERROR;
731 } break;
732 case CHANNEL_COUNT: {
733 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700734 reply->writeInt32( channelCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800735 return NO_ERROR;
736 } break;
737 case FORMAT: {
738 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700739 reply->writeInt32( format(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800740 return NO_ERROR;
741 } break;
742 case FRAME_COUNT: {
743 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700744 reply->writeInt32( frameCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800745 return NO_ERROR;
746 } break;
747 case LATENCY: {
748 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700749 reply->writeInt32( latency(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800750 return NO_ERROR;
751 } break;
752 case SET_MASTER_VOLUME: {
753 CHECK_INTERFACE(IAudioFlinger, data, reply);
754 reply->writeInt32( setMasterVolume(data.readFloat()) );
755 return NO_ERROR;
756 } break;
757 case SET_MASTER_MUTE: {
758 CHECK_INTERFACE(IAudioFlinger, data, reply);
759 reply->writeInt32( setMasterMute(data.readInt32()) );
760 return NO_ERROR;
761 } break;
762 case MASTER_VOLUME: {
763 CHECK_INTERFACE(IAudioFlinger, data, reply);
764 reply->writeFloat( masterVolume() );
765 return NO_ERROR;
766 } break;
767 case MASTER_MUTE: {
768 CHECK_INTERFACE(IAudioFlinger, data, reply);
769 reply->writeInt32( masterMute() );
770 return NO_ERROR;
771 } break;
772 case SET_STREAM_VOLUME: {
773 CHECK_INTERFACE(IAudioFlinger, data, reply);
774 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700775 float volume = data.readFloat();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700776 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700777 reply->writeInt32( setStreamVolume(stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800778 return NO_ERROR;
779 } break;
780 case SET_STREAM_MUTE: {
781 CHECK_INTERFACE(IAudioFlinger, data, reply);
782 int stream = data.readInt32();
783 reply->writeInt32( setStreamMute(stream, data.readInt32()) );
784 return NO_ERROR;
785 } break;
786 case STREAM_VOLUME: {
787 CHECK_INTERFACE(IAudioFlinger, data, reply);
788 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700789 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700790 reply->writeFloat( streamVolume(stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800791 return NO_ERROR;
792 } break;
793 case STREAM_MUTE: {
794 CHECK_INTERFACE(IAudioFlinger, data, reply);
795 int stream = data.readInt32();
796 reply->writeInt32( streamMute(stream) );
797 return NO_ERROR;
798 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800799 case SET_MODE: {
800 CHECK_INTERFACE(IAudioFlinger, data, reply);
801 int mode = data.readInt32();
802 reply->writeInt32( setMode(mode) );
803 return NO_ERROR;
804 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800805 case SET_MIC_MUTE: {
806 CHECK_INTERFACE(IAudioFlinger, data, reply);
807 int state = data.readInt32();
808 reply->writeInt32( setMicMute(state) );
809 return NO_ERROR;
810 } break;
811 case GET_MIC_MUTE: {
812 CHECK_INTERFACE(IAudioFlinger, data, reply);
813 reply->writeInt32( getMicMute() );
814 return NO_ERROR;
815 } break;
Eric Laurentb72a3962010-01-25 08:49:09 -0800816 case IS_STREAM_ACTIVE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800817 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentb72a3962010-01-25 08:49:09 -0800818 int stream = data.readInt32();
819 reply->writeInt32( isStreamActive(stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800820 return NO_ERROR;
821 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700822 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800823 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700824 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700825 String8 keyValuePairs(data.readString8());
826 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800827 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700828 } break;
829 case GET_PARAMETERS: {
830 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700831 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700832 String8 keys(data.readString8());
833 reply->writeString8(getParameters(ioHandle, keys));
834 return NO_ERROR;
835 } break;
836
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800837 case REGISTER_CLIENT: {
838 CHECK_INTERFACE(IAudioFlinger, data, reply);
839 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(data.readStrongBinder());
840 registerClient(client);
841 return NO_ERROR;
842 } break;
843 case GET_INPUTBUFFERSIZE: {
844 CHECK_INTERFACE(IAudioFlinger, data, reply);
845 uint32_t sampleRate = data.readInt32();
846 int format = data.readInt32();
847 int channelCount = data.readInt32();
848 reply->writeInt32( getInputBufferSize(sampleRate, format, channelCount) );
849 return NO_ERROR;
850 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700851 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800852 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700853 uint32_t devices = data.readInt32();
854 uint32_t samplingRate = data.readInt32();
855 uint32_t format = data.readInt32();
856 uint32_t channels = data.readInt32();
857 uint32_t latency = data.readInt32();
858 uint32_t flags = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700859 int output = openOutput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700860 &samplingRate,
861 &format,
862 &channels,
863 &latency,
864 flags);
865 LOGV("OPEN_OUTPUT output, %p", output);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700866 reply->writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700867 reply->writeInt32(devices);
868 reply->writeInt32(samplingRate);
869 reply->writeInt32(format);
870 reply->writeInt32(channels);
871 reply->writeInt32(latency);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800872 return NO_ERROR;
873 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700874 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800875 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700876 int output1 = data.readInt32();
877 int output2 = data.readInt32();
878 reply->writeInt32(openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700879 return NO_ERROR;
880 } break;
881 case CLOSE_OUTPUT: {
882 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700883 reply->writeInt32(closeOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700884 return NO_ERROR;
885 } break;
886 case SUSPEND_OUTPUT: {
887 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700888 reply->writeInt32(suspendOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700889 return NO_ERROR;
890 } break;
891 case RESTORE_OUTPUT: {
892 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700893 reply->writeInt32(restoreOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700894 return NO_ERROR;
895 } break;
896 case OPEN_INPUT: {
897 CHECK_INTERFACE(IAudioFlinger, data, reply);
898 uint32_t devices = data.readInt32();
899 uint32_t samplingRate = data.readInt32();
900 uint32_t format = data.readInt32();
901 uint32_t channels = data.readInt32();
902 uint32_t acoutics = data.readInt32();
903
Eric Laurentfa2877b2009-07-28 08:44:33 -0700904 int input = openInput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700905 &samplingRate,
906 &format,
907 &channels,
908 acoutics);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700909 reply->writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700910 reply->writeInt32(devices);
911 reply->writeInt32(samplingRate);
912 reply->writeInt32(format);
913 reply->writeInt32(channels);
914 return NO_ERROR;
915 } break;
916 case CLOSE_INPUT: {
917 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700918 reply->writeInt32(closeInput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700919 return NO_ERROR;
920 } break;
921 case SET_STREAM_OUTPUT: {
922 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700923 uint32_t stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700924 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700925 reply->writeInt32(setStreamOutput(stream, output));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800926 return NO_ERROR;
927 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700928 case SET_VOICE_VOLUME: {
929 CHECK_INTERFACE(IAudioFlinger, data, reply);
930 float volume = data.readFloat();
931 reply->writeInt32( setVoiceVolume(volume) );
932 return NO_ERROR;
933 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -0800934 case GET_RENDER_POSITION: {
935 CHECK_INTERFACE(IAudioFlinger, data, reply);
936 int output = data.readInt32();
937 uint32_t halFrames;
938 uint32_t dspFrames;
939 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
940 reply->writeInt32(status);
941 if (status == NO_ERROR) {
942 reply->writeInt32(halFrames);
943 reply->writeInt32(dspFrames);
944 }
945 return NO_ERROR;
946 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800947 case GET_INPUT_FRAMES_LOST: {
948 CHECK_INTERFACE(IAudioFlinger, data, reply);
949 int ioHandle = data.readInt32();
950 reply->writeInt32(getInputFramesLost(ioHandle));
951 return NO_ERROR;
952 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700953 case NEW_AUDIO_SESSION_ID: {
954 CHECK_INTERFACE(IAudioFlinger, data, reply);
955 reply->writeInt32(newAudioSessionId());
956 return NO_ERROR;
957 } break;
958 case LOAD_EFFECT_LIBRARY: {
959 CHECK_INTERFACE(IAudioFlinger, data, reply);
960 int handle;
961 status_t status = loadEffectLibrary(data.readCString(), &handle);
962 reply->writeInt32(status);
963 if (status == NO_ERROR) {
964 reply->writeInt32(handle);
965 }
966 return NO_ERROR;
967 }
968 case UNLOAD_EFFECT_LIBRARY: {
969 CHECK_INTERFACE(IAudioFlinger, data, reply);
970 reply->writeInt32(unloadEffectLibrary(data.readInt32()));
971 return NO_ERROR;
972 }
973 case QUERY_NUM_EFFECTS: {
974 CHECK_INTERFACE(IAudioFlinger, data, reply);
975 uint32_t numEffects;
976 status_t status = queryNumberEffects(&numEffects);
977 reply->writeInt32(status);
978 if (status == NO_ERROR) {
979 reply->writeInt32((int32_t)numEffects);
980 }
981 return NO_ERROR;
982 }
983 case QUERY_NEXT_EFFECT: {
984 CHECK_INTERFACE(IAudioFlinger, data, reply);
985 effect_descriptor_t desc;
986 status_t status = queryNextEffect(&desc);
987 reply->writeInt32(status);
988 if (status == NO_ERROR) {
989 reply->write(&desc, sizeof(effect_descriptor_t));
990 }
991 return NO_ERROR;
992 }
993 case GET_EFFECT_DESCRIPTOR: {
994 CHECK_INTERFACE(IAudioFlinger, data, reply);
995 effect_uuid_t uuid;
996 data.read(&uuid, sizeof(effect_uuid_t));
997 effect_descriptor_t desc;
998 status_t status = getEffectDescriptor(&uuid, &desc);
999 reply->writeInt32(status);
1000 if (status == NO_ERROR) {
1001 reply->write(&desc, sizeof(effect_descriptor_t));
1002 }
1003 return NO_ERROR;
1004 }
1005 case CREATE_EFFECT: {
1006 CHECK_INTERFACE(IAudioFlinger, data, reply);
1007 pid_t pid = data.readInt32();
1008 effect_descriptor_t desc;
1009 data.read(&desc, sizeof(effect_descriptor_t));
1010 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1011 int32_t priority = data.readInt32();
1012 int output = data.readInt32();
1013 int sessionId = data.readInt32();
1014 status_t status;
1015 int id;
1016 int enabled;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001017
Eric Laurentbe916aa2010-06-01 23:49:17 -07001018 sp<IEffect> effect = createEffect(pid, &desc, client, priority, output, sessionId, &status, &id, &enabled);
1019 reply->writeInt32(status);
1020 reply->writeInt32(id);
1021 reply->writeInt32(enabled);
1022 reply->writeStrongBinder(effect->asBinder());
1023 reply->write(&desc, sizeof(effect_descriptor_t));
1024 return NO_ERROR;
1025 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001026 default:
1027 return BBinder::onTransact(code, data, reply, flags);
1028 }
1029}
1030
1031// ----------------------------------------------------------------------------
1032
1033}; // namespace android