blob: 3a89e250d793e6f65a53ac12fc6c1466a1e42410 [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,
Eric Laurentffe9c252010-06-23 17:38:20 -070070 QUERY_EFFECT,
Eric Laurentbe916aa2010-06-01 23:49:17 -070071 GET_EFFECT_DESCRIPTOR,
Eric Laurentde070132010-07-13 04:45:46 -070072 CREATE_EFFECT,
73 MOVE_EFFECTS
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080074};
75
76class BpAudioFlinger : public BpInterface<IAudioFlinger>
77{
78public:
79 BpAudioFlinger(const sp<IBinder>& impl)
80 : BpInterface<IAudioFlinger>(impl)
81 {
82 }
83
84 virtual sp<IAudioTrack> createTrack(
85 pid_t pid,
86 int streamType,
87 uint32_t sampleRate,
88 int format,
89 int channelCount,
90 int frameCount,
91 uint32_t flags,
92 const sp<IMemory>& sharedBuffer,
Eric Laurentfa2877b2009-07-28 08:44:33 -070093 int output,
Eric Laurentbe916aa2010-06-01 23:49:17 -070094 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080095 status_t *status)
96 {
97 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -070098 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080099 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
100 data.writeInt32(pid);
101 data.writeInt32(streamType);
102 data.writeInt32(sampleRate);
103 data.writeInt32(format);
104 data.writeInt32(channelCount);
105 data.writeInt32(frameCount);
106 data.writeInt32(flags);
107 data.writeStrongBinder(sharedBuffer->asBinder());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700108 data.writeInt32(output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700109 int lSessionId = 0;
110 if (sessionId != NULL) {
111 lSessionId = *sessionId;
112 }
113 data.writeInt32(lSessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800114 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
115 if (lStatus != NO_ERROR) {
116 LOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700117 } else {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700118 lSessionId = reply.readInt32();
119 if (sessionId != NULL) {
120 *sessionId = lSessionId;
121 }
Eric Laurent5841db72009-09-09 05:16:08 -0700122 lStatus = reply.readInt32();
123 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800124 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800125 if (status) {
126 *status = lStatus;
127 }
Eric Laurent5841db72009-09-09 05:16:08 -0700128 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800129 }
130
131 virtual sp<IAudioRecord> openRecord(
132 pid_t pid,
Eric Laurentfa2877b2009-07-28 08:44:33 -0700133 int input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800134 uint32_t sampleRate,
135 int format,
136 int channelCount,
137 int frameCount,
138 uint32_t flags,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700139 int *sessionId,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800140 status_t *status)
141 {
142 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700143 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800144 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
145 data.writeInt32(pid);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700146 data.writeInt32(input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800147 data.writeInt32(sampleRate);
148 data.writeInt32(format);
149 data.writeInt32(channelCount);
150 data.writeInt32(frameCount);
151 data.writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700152 int lSessionId = 0;
153 if (sessionId != NULL) {
154 lSessionId = *sessionId;
155 }
156 data.writeInt32(lSessionId);
Eric Laurent5841db72009-09-09 05:16:08 -0700157 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
158 if (lStatus != NO_ERROR) {
159 LOGE("openRecord error: %s", strerror(-lStatus));
160 } else {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700161 lSessionId = reply.readInt32();
162 if (sessionId != NULL) {
163 *sessionId = lSessionId;
164 }
Eric Laurent5841db72009-09-09 05:16:08 -0700165 lStatus = reply.readInt32();
166 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
167 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800168 if (status) {
169 *status = lStatus;
170 }
Eric Laurent5841db72009-09-09 05:16:08 -0700171 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800172 }
173
Eric Laurentfa2877b2009-07-28 08:44:33 -0700174 virtual uint32_t sampleRate(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800175 {
176 Parcel data, reply;
177 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700178 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800179 remote()->transact(SAMPLE_RATE, data, &reply);
180 return reply.readInt32();
181 }
182
Eric Laurentfa2877b2009-07-28 08:44:33 -0700183 virtual int channelCount(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800184 {
185 Parcel data, reply;
186 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700187 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800188 remote()->transact(CHANNEL_COUNT, data, &reply);
189 return reply.readInt32();
190 }
191
Eric Laurentfa2877b2009-07-28 08:44:33 -0700192 virtual int format(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800193 {
194 Parcel data, reply;
195 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700196 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800197 remote()->transact(FORMAT, data, &reply);
198 return reply.readInt32();
199 }
200
Eric Laurentfa2877b2009-07-28 08:44:33 -0700201 virtual size_t frameCount(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800202 {
203 Parcel data, reply;
204 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700205 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800206 remote()->transact(FRAME_COUNT, data, &reply);
207 return reply.readInt32();
208 }
209
Eric Laurentfa2877b2009-07-28 08:44:33 -0700210 virtual uint32_t latency(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800211 {
212 Parcel data, reply;
213 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700214 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800215 remote()->transact(LATENCY, data, &reply);
216 return reply.readInt32();
217 }
218
219 virtual status_t setMasterVolume(float value)
220 {
221 Parcel data, reply;
222 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
223 data.writeFloat(value);
224 remote()->transact(SET_MASTER_VOLUME, data, &reply);
225 return reply.readInt32();
226 }
227
228 virtual status_t setMasterMute(bool muted)
229 {
230 Parcel data, reply;
231 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
232 data.writeInt32(muted);
233 remote()->transact(SET_MASTER_MUTE, data, &reply);
234 return reply.readInt32();
235 }
236
237 virtual float masterVolume() const
238 {
239 Parcel data, reply;
240 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
241 remote()->transact(MASTER_VOLUME, data, &reply);
242 return reply.readFloat();
243 }
244
245 virtual bool masterMute() const
246 {
247 Parcel data, reply;
248 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
249 remote()->transact(MASTER_MUTE, data, &reply);
250 return reply.readInt32();
251 }
252
Eric Laurentfa2877b2009-07-28 08:44:33 -0700253 virtual status_t setStreamVolume(int stream, float value, int output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800254 {
255 Parcel data, reply;
256 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
257 data.writeInt32(stream);
258 data.writeFloat(value);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700259 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800260 remote()->transact(SET_STREAM_VOLUME, data, &reply);
261 return reply.readInt32();
262 }
263
264 virtual status_t setStreamMute(int stream, bool muted)
265 {
266 Parcel data, reply;
267 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
268 data.writeInt32(stream);
269 data.writeInt32(muted);
270 remote()->transact(SET_STREAM_MUTE, data, &reply);
271 return reply.readInt32();
272 }
273
Eric Laurentfa2877b2009-07-28 08:44:33 -0700274 virtual float streamVolume(int stream, int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800275 {
276 Parcel data, reply;
277 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
278 data.writeInt32(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700279 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800280 remote()->transact(STREAM_VOLUME, data, &reply);
281 return reply.readFloat();
282 }
283
284 virtual bool streamMute(int stream) const
285 {
286 Parcel data, reply;
287 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
288 data.writeInt32(stream);
289 remote()->transact(STREAM_MUTE, data, &reply);
290 return reply.readInt32();
291 }
292
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800293 virtual status_t setMode(int mode)
294 {
295 Parcel data, reply;
296 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
297 data.writeInt32(mode);
298 remote()->transact(SET_MODE, data, &reply);
299 return reply.readInt32();
300 }
301
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800302 virtual status_t setMicMute(bool state)
303 {
304 Parcel data, reply;
305 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
306 data.writeInt32(state);
307 remote()->transact(SET_MIC_MUTE, data, &reply);
308 return reply.readInt32();
309 }
310
311 virtual bool getMicMute() const
312 {
313 Parcel data, reply;
314 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
315 remote()->transact(GET_MIC_MUTE, data, &reply);
316 return reply.readInt32();
317 }
318
Eric Laurentb72a3962010-01-25 08:49:09 -0800319 virtual bool isStreamActive(int stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800320 {
321 Parcel data, reply;
322 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentb72a3962010-01-25 08:49:09 -0800323 data.writeInt32(stream);
324 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800325 return reply.readInt32();
326 }
327
Eric Laurentfa2877b2009-07-28 08:44:33 -0700328 virtual status_t setParameters(int ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800329 {
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(keyValuePairs);
334 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800335 return reply.readInt32();
336 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700337
Eric Laurentfa2877b2009-07-28 08:44:33 -0700338 virtual String8 getParameters(int ioHandle, const String8& keys)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700339 {
340 Parcel data, reply;
341 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700342 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700343 data.writeString8(keys);
344 remote()->transact(GET_PARAMETERS, data, &reply);
345 return reply.readString8();
346 }
347
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800348 virtual void registerClient(const sp<IAudioFlingerClient>& client)
349 {
350 Parcel data, reply;
351 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
352 data.writeStrongBinder(client->asBinder());
353 remote()->transact(REGISTER_CLIENT, data, &reply);
354 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700355
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800356 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
357 {
358 Parcel data, reply;
359 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
360 data.writeInt32(sampleRate);
361 data.writeInt32(format);
362 data.writeInt32(channelCount);
363 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
364 return reply.readInt32();
365 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700366
Eric Laurentfa2877b2009-07-28 08:44:33 -0700367 virtual int openOutput(uint32_t *pDevices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700368 uint32_t *pSamplingRate,
369 uint32_t *pFormat,
370 uint32_t *pChannels,
371 uint32_t *pLatencyMs,
372 uint32_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800373 {
374 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700375 uint32_t devices = pDevices ? *pDevices : 0;
376 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
377 uint32_t format = pFormat ? *pFormat : 0;
378 uint32_t channels = pChannels ? *pChannels : 0;
379 uint32_t latency = pLatencyMs ? *pLatencyMs : 0;
380
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800381 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700382 data.writeInt32(devices);
383 data.writeInt32(samplingRate);
384 data.writeInt32(format);
385 data.writeInt32(channels);
386 data.writeInt32(latency);
387 data.writeInt32(flags);
388 remote()->transact(OPEN_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700389 int output = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700390 LOGV("openOutput() returned output, %p", output);
391 devices = reply.readInt32();
392 if (pDevices) *pDevices = devices;
393 samplingRate = reply.readInt32();
394 if (pSamplingRate) *pSamplingRate = samplingRate;
395 format = reply.readInt32();
396 if (pFormat) *pFormat = format;
397 channels = reply.readInt32();
398 if (pChannels) *pChannels = channels;
399 latency = reply.readInt32();
400 if (pLatencyMs) *pLatencyMs = latency;
401 return output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800402 }
403
Eric Laurentfa2877b2009-07-28 08:44:33 -0700404 virtual int openDuplicateOutput(int output1, int output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800405 {
406 Parcel data, reply;
407 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700408 data.writeInt32(output1);
409 data.writeInt32(output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700410 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700411 return reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700412 }
413
Eric Laurentfa2877b2009-07-28 08:44:33 -0700414 virtual status_t closeOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700415 {
416 Parcel data, reply;
417 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700418 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700419 remote()->transact(CLOSE_OUTPUT, data, &reply);
420 return reply.readInt32();
421 }
422
Eric Laurentfa2877b2009-07-28 08:44:33 -0700423 virtual status_t suspendOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700424 {
425 Parcel data, reply;
426 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700427 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700428 remote()->transact(SUSPEND_OUTPUT, data, &reply);
429 return reply.readInt32();
430 }
431
Eric Laurentfa2877b2009-07-28 08:44:33 -0700432 virtual status_t restoreOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700433 {
434 Parcel data, reply;
435 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700436 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700437 remote()->transact(RESTORE_OUTPUT, data, &reply);
438 return reply.readInt32();
439 }
440
Eric Laurentfa2877b2009-07-28 08:44:33 -0700441 virtual int openInput(uint32_t *pDevices,
442 uint32_t *pSamplingRate,
443 uint32_t *pFormat,
444 uint32_t *pChannels,
445 uint32_t acoustics)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700446 {
447 Parcel data, reply;
448 uint32_t devices = pDevices ? *pDevices : 0;
449 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
450 uint32_t format = pFormat ? *pFormat : 0;
451 uint32_t channels = pChannels ? *pChannels : 0;
452
453 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
454 data.writeInt32(devices);
455 data.writeInt32(samplingRate);
456 data.writeInt32(format);
457 data.writeInt32(channels);
458 data.writeInt32(acoustics);
459 remote()->transact(OPEN_INPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700460 int input = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700461 devices = reply.readInt32();
462 if (pDevices) *pDevices = devices;
463 samplingRate = reply.readInt32();
464 if (pSamplingRate) *pSamplingRate = samplingRate;
465 format = reply.readInt32();
466 if (pFormat) *pFormat = format;
467 channels = reply.readInt32();
468 if (pChannels) *pChannels = channels;
469 return input;
470 }
471
Eric Laurentfa2877b2009-07-28 08:44:33 -0700472 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700473 {
474 Parcel data, reply;
475 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700476 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700477 remote()->transact(CLOSE_INPUT, data, &reply);
478 return reply.readInt32();
479 }
480
Eric Laurentfa2877b2009-07-28 08:44:33 -0700481 virtual status_t setStreamOutput(uint32_t stream, int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700482 {
483 Parcel data, reply;
484 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
485 data.writeInt32(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700486 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700487 remote()->transact(SET_STREAM_OUTPUT, data, &reply);
488 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800489 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700490
491 virtual status_t setVoiceVolume(float volume)
492 {
493 Parcel data, reply;
494 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
495 data.writeFloat(volume);
496 remote()->transact(SET_VOICE_VOLUME, data, &reply);
497 return reply.readInt32();
498 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800499
500 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int output)
501 {
502 Parcel data, reply;
503 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
504 data.writeInt32(output);
505 remote()->transact(GET_RENDER_POSITION, data, &reply);
506 status_t status = reply.readInt32();
507 if (status == NO_ERROR) {
508 uint32_t tmp = reply.readInt32();
509 if (halFrames) {
510 *halFrames = tmp;
511 }
512 tmp = reply.readInt32();
513 if (dspFrames) {
514 *dspFrames = tmp;
515 }
516 }
517 return status;
518 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800519
520 virtual unsigned int getInputFramesLost(int ioHandle)
521 {
522 Parcel data, reply;
523 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
524 data.writeInt32(ioHandle);
525 remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
526 return reply.readInt32();
527 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700528
529 virtual int newAudioSessionId()
530 {
531 Parcel data, reply;
532 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
533 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
534 int id = 0;
535 if (status == NO_ERROR) {
536 id = reply.readInt32();
537 }
538 return id;
539 }
540
541 virtual status_t loadEffectLibrary(const char *libPath, int *handle)
542 {
543 if (libPath == NULL || handle == NULL) {
544 return BAD_VALUE;
545 }
546 *handle = 0;
547 Parcel data, reply;
548 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
549 data.writeCString(libPath);
550 status_t status = remote()->transact(LOAD_EFFECT_LIBRARY, data, &reply);
551 if (status == NO_ERROR) {
552 status = reply.readInt32();
553 if (status == NO_ERROR) {
554 *handle = reply.readInt32();
555 }
556 }
557 return status;
558 }
559
560 virtual status_t unloadEffectLibrary(int handle)
561 {
562 Parcel data, reply;
563 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
564 data.writeInt32(handle);
565 status_t status = remote()->transact(UNLOAD_EFFECT_LIBRARY, data, &reply);
566 if (status == NO_ERROR) {
567 status = reply.readInt32();
568 }
569 return status;
570 }
571
572 virtual status_t queryNumberEffects(uint32_t *numEffects)
573 {
574 Parcel data, reply;
575 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
576 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
577 if (status != NO_ERROR) {
578 return status;
579 }
580 status = reply.readInt32();
581 if (status != NO_ERROR) {
582 return status;
583 }
584 if (numEffects) {
585 *numEffects = (uint32_t)reply.readInt32();
586 }
587 return NO_ERROR;
588 }
589
Eric Laurentffe9c252010-06-23 17:38:20 -0700590 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor)
Eric Laurentbe916aa2010-06-01 23:49:17 -0700591 {
592 if (pDescriptor == NULL) {
593 return BAD_VALUE;
594 }
595 Parcel data, reply;
596 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700597 data.writeInt32(index);
598 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700599 if (status != NO_ERROR) {
600 return status;
601 }
602 status = reply.readInt32();
603 if (status != NO_ERROR) {
604 return status;
605 }
606 reply.read(pDescriptor, sizeof(effect_descriptor_t));
607 return NO_ERROR;
608 }
609
610 virtual status_t getEffectDescriptor(effect_uuid_t *pUuid, effect_descriptor_t *pDescriptor)
611 {
612 if (pUuid == NULL || pDescriptor == NULL) {
613 return BAD_VALUE;
614 }
615 Parcel data, reply;
616 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
617 data.write(pUuid, sizeof(effect_uuid_t));
618 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
619 if (status != NO_ERROR) {
620 return status;
621 }
622 status = reply.readInt32();
623 if (status != NO_ERROR) {
624 return status;
625 }
626 reply.read(pDescriptor, sizeof(effect_descriptor_t));
627 return NO_ERROR;
628 }
629
630 virtual sp<IEffect> createEffect(pid_t pid,
631 effect_descriptor_t *pDesc,
632 const sp<IEffectClient>& client,
633 int32_t priority,
634 int output,
635 int sessionId,
636 status_t *status,
637 int *id,
638 int *enabled)
639 {
640 Parcel data, reply;
641 sp<IEffect> effect;
642
643 if (pDesc == NULL) {
644 return effect;
645 if (status) {
646 *status = BAD_VALUE;
647 }
648 }
649
650 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
651 data.writeInt32(pid);
652 data.write(pDesc, sizeof(effect_descriptor_t));
653 data.writeStrongBinder(client->asBinder());
654 data.writeInt32(priority);
655 data.writeInt32(output);
656 data.writeInt32(sessionId);
657
658 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
659 if (lStatus != NO_ERROR) {
660 LOGE("createEffect error: %s", strerror(-lStatus));
661 } else {
662 lStatus = reply.readInt32();
663 int tmp = reply.readInt32();
664 if (id) {
665 *id = tmp;
666 }
667 tmp = reply.readInt32();
668 if (enabled) {
669 *enabled = tmp;
670 }
671 effect = interface_cast<IEffect>(reply.readStrongBinder());
672 reply.read(pDesc, sizeof(effect_descriptor_t));
673 }
674 if (status) {
675 *status = lStatus;
676 }
677
678 return effect;
679 }
Eric Laurentde070132010-07-13 04:45:46 -0700680
681 virtual status_t moveEffects(int session, int srcOutput, int dstOutput)
682 {
683 Parcel data, reply;
684 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
685 data.writeInt32(session);
686 data.writeInt32(srcOutput);
687 data.writeInt32(dstOutput);
688 remote()->transact(MOVE_EFFECTS, data, &reply);
689 return reply.readInt32();
690 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800691};
692
693IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
694
695// ----------------------------------------------------------------------
696
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800697status_t BnAudioFlinger::onTransact(
698 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
699{
700 switch(code) {
701 case CREATE_TRACK: {
702 CHECK_INTERFACE(IAudioFlinger, data, reply);
703 pid_t pid = data.readInt32();
704 int streamType = data.readInt32();
705 uint32_t sampleRate = data.readInt32();
706 int format = data.readInt32();
707 int channelCount = data.readInt32();
708 size_t bufferCount = data.readInt32();
709 uint32_t flags = data.readInt32();
710 sp<IMemory> buffer = interface_cast<IMemory>(data.readStrongBinder());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700711 int output = data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700712 int sessionId = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800713 status_t status;
714 sp<IAudioTrack> track = createTrack(pid,
715 streamType, sampleRate, format,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700716 channelCount, bufferCount, flags, buffer, output, &sessionId, &status);
717 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800718 reply->writeInt32(status);
719 reply->writeStrongBinder(track->asBinder());
720 return NO_ERROR;
721 } break;
722 case OPEN_RECORD: {
723 CHECK_INTERFACE(IAudioFlinger, data, reply);
724 pid_t pid = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700725 int input = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800726 uint32_t sampleRate = data.readInt32();
727 int format = data.readInt32();
728 int channelCount = data.readInt32();
729 size_t bufferCount = data.readInt32();
730 uint32_t flags = data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700731 int sessionId = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800732 status_t status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700733 sp<IAudioRecord> record = openRecord(pid, input,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700734 sampleRate, format, channelCount, bufferCount, flags, &sessionId, &status);
735 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800736 reply->writeInt32(status);
737 reply->writeStrongBinder(record->asBinder());
738 return NO_ERROR;
739 } break;
740 case SAMPLE_RATE: {
741 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700742 reply->writeInt32( sampleRate(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800743 return NO_ERROR;
744 } break;
745 case CHANNEL_COUNT: {
746 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700747 reply->writeInt32( channelCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800748 return NO_ERROR;
749 } break;
750 case FORMAT: {
751 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700752 reply->writeInt32( format(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800753 return NO_ERROR;
754 } break;
755 case FRAME_COUNT: {
756 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700757 reply->writeInt32( frameCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800758 return NO_ERROR;
759 } break;
760 case LATENCY: {
761 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700762 reply->writeInt32( latency(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800763 return NO_ERROR;
764 } break;
765 case SET_MASTER_VOLUME: {
766 CHECK_INTERFACE(IAudioFlinger, data, reply);
767 reply->writeInt32( setMasterVolume(data.readFloat()) );
768 return NO_ERROR;
769 } break;
770 case SET_MASTER_MUTE: {
771 CHECK_INTERFACE(IAudioFlinger, data, reply);
772 reply->writeInt32( setMasterMute(data.readInt32()) );
773 return NO_ERROR;
774 } break;
775 case MASTER_VOLUME: {
776 CHECK_INTERFACE(IAudioFlinger, data, reply);
777 reply->writeFloat( masterVolume() );
778 return NO_ERROR;
779 } break;
780 case MASTER_MUTE: {
781 CHECK_INTERFACE(IAudioFlinger, data, reply);
782 reply->writeInt32( masterMute() );
783 return NO_ERROR;
784 } break;
785 case SET_STREAM_VOLUME: {
786 CHECK_INTERFACE(IAudioFlinger, data, reply);
787 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700788 float volume = data.readFloat();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700789 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700790 reply->writeInt32( setStreamVolume(stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800791 return NO_ERROR;
792 } break;
793 case SET_STREAM_MUTE: {
794 CHECK_INTERFACE(IAudioFlinger, data, reply);
795 int stream = data.readInt32();
796 reply->writeInt32( setStreamMute(stream, data.readInt32()) );
797 return NO_ERROR;
798 } break;
799 case STREAM_VOLUME: {
800 CHECK_INTERFACE(IAudioFlinger, data, reply);
801 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700802 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700803 reply->writeFloat( streamVolume(stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800804 return NO_ERROR;
805 } break;
806 case STREAM_MUTE: {
807 CHECK_INTERFACE(IAudioFlinger, data, reply);
808 int stream = data.readInt32();
809 reply->writeInt32( streamMute(stream) );
810 return NO_ERROR;
811 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800812 case SET_MODE: {
813 CHECK_INTERFACE(IAudioFlinger, data, reply);
814 int mode = data.readInt32();
815 reply->writeInt32( setMode(mode) );
816 return NO_ERROR;
817 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800818 case SET_MIC_MUTE: {
819 CHECK_INTERFACE(IAudioFlinger, data, reply);
820 int state = data.readInt32();
821 reply->writeInt32( setMicMute(state) );
822 return NO_ERROR;
823 } break;
824 case GET_MIC_MUTE: {
825 CHECK_INTERFACE(IAudioFlinger, data, reply);
826 reply->writeInt32( getMicMute() );
827 return NO_ERROR;
828 } break;
Eric Laurentb72a3962010-01-25 08:49:09 -0800829 case IS_STREAM_ACTIVE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800830 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentb72a3962010-01-25 08:49:09 -0800831 int stream = data.readInt32();
832 reply->writeInt32( isStreamActive(stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800833 return NO_ERROR;
834 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700835 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800836 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700837 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700838 String8 keyValuePairs(data.readString8());
839 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800840 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700841 } break;
842 case GET_PARAMETERS: {
843 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700844 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700845 String8 keys(data.readString8());
846 reply->writeString8(getParameters(ioHandle, keys));
847 return NO_ERROR;
848 } break;
849
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800850 case REGISTER_CLIENT: {
851 CHECK_INTERFACE(IAudioFlinger, data, reply);
852 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(data.readStrongBinder());
853 registerClient(client);
854 return NO_ERROR;
855 } break;
856 case GET_INPUTBUFFERSIZE: {
857 CHECK_INTERFACE(IAudioFlinger, data, reply);
858 uint32_t sampleRate = data.readInt32();
859 int format = data.readInt32();
860 int channelCount = data.readInt32();
861 reply->writeInt32( getInputBufferSize(sampleRate, format, channelCount) );
862 return NO_ERROR;
863 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700864 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800865 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700866 uint32_t devices = data.readInt32();
867 uint32_t samplingRate = data.readInt32();
868 uint32_t format = data.readInt32();
869 uint32_t channels = data.readInt32();
870 uint32_t latency = data.readInt32();
871 uint32_t flags = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700872 int output = openOutput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700873 &samplingRate,
874 &format,
875 &channels,
876 &latency,
877 flags);
878 LOGV("OPEN_OUTPUT output, %p", output);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700879 reply->writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700880 reply->writeInt32(devices);
881 reply->writeInt32(samplingRate);
882 reply->writeInt32(format);
883 reply->writeInt32(channels);
884 reply->writeInt32(latency);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800885 return NO_ERROR;
886 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700887 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800888 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700889 int output1 = data.readInt32();
890 int output2 = data.readInt32();
891 reply->writeInt32(openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700892 return NO_ERROR;
893 } break;
894 case CLOSE_OUTPUT: {
895 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700896 reply->writeInt32(closeOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700897 return NO_ERROR;
898 } break;
899 case SUSPEND_OUTPUT: {
900 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700901 reply->writeInt32(suspendOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700902 return NO_ERROR;
903 } break;
904 case RESTORE_OUTPUT: {
905 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700906 reply->writeInt32(restoreOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700907 return NO_ERROR;
908 } break;
909 case OPEN_INPUT: {
910 CHECK_INTERFACE(IAudioFlinger, data, reply);
911 uint32_t devices = data.readInt32();
912 uint32_t samplingRate = data.readInt32();
913 uint32_t format = data.readInt32();
914 uint32_t channels = data.readInt32();
915 uint32_t acoutics = data.readInt32();
916
Eric Laurentfa2877b2009-07-28 08:44:33 -0700917 int input = openInput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700918 &samplingRate,
919 &format,
920 &channels,
921 acoutics);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700922 reply->writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700923 reply->writeInt32(devices);
924 reply->writeInt32(samplingRate);
925 reply->writeInt32(format);
926 reply->writeInt32(channels);
927 return NO_ERROR;
928 } break;
929 case CLOSE_INPUT: {
930 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700931 reply->writeInt32(closeInput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700932 return NO_ERROR;
933 } break;
934 case SET_STREAM_OUTPUT: {
935 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700936 uint32_t stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700937 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700938 reply->writeInt32(setStreamOutput(stream, output));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800939 return NO_ERROR;
940 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700941 case SET_VOICE_VOLUME: {
942 CHECK_INTERFACE(IAudioFlinger, data, reply);
943 float volume = data.readFloat();
944 reply->writeInt32( setVoiceVolume(volume) );
945 return NO_ERROR;
946 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -0800947 case GET_RENDER_POSITION: {
948 CHECK_INTERFACE(IAudioFlinger, data, reply);
949 int output = data.readInt32();
950 uint32_t halFrames;
951 uint32_t dspFrames;
952 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
953 reply->writeInt32(status);
954 if (status == NO_ERROR) {
955 reply->writeInt32(halFrames);
956 reply->writeInt32(dspFrames);
957 }
958 return NO_ERROR;
959 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800960 case GET_INPUT_FRAMES_LOST: {
961 CHECK_INTERFACE(IAudioFlinger, data, reply);
962 int ioHandle = data.readInt32();
963 reply->writeInt32(getInputFramesLost(ioHandle));
964 return NO_ERROR;
965 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700966 case NEW_AUDIO_SESSION_ID: {
967 CHECK_INTERFACE(IAudioFlinger, data, reply);
968 reply->writeInt32(newAudioSessionId());
969 return NO_ERROR;
970 } break;
971 case LOAD_EFFECT_LIBRARY: {
972 CHECK_INTERFACE(IAudioFlinger, data, reply);
973 int handle;
974 status_t status = loadEffectLibrary(data.readCString(), &handle);
975 reply->writeInt32(status);
976 if (status == NO_ERROR) {
977 reply->writeInt32(handle);
978 }
979 return NO_ERROR;
980 }
981 case UNLOAD_EFFECT_LIBRARY: {
982 CHECK_INTERFACE(IAudioFlinger, data, reply);
983 reply->writeInt32(unloadEffectLibrary(data.readInt32()));
984 return NO_ERROR;
985 }
986 case QUERY_NUM_EFFECTS: {
987 CHECK_INTERFACE(IAudioFlinger, data, reply);
988 uint32_t numEffects;
989 status_t status = queryNumberEffects(&numEffects);
990 reply->writeInt32(status);
991 if (status == NO_ERROR) {
992 reply->writeInt32((int32_t)numEffects);
993 }
994 return NO_ERROR;
995 }
Eric Laurentffe9c252010-06-23 17:38:20 -0700996 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700997 CHECK_INTERFACE(IAudioFlinger, data, reply);
998 effect_descriptor_t desc;
Eric Laurentffe9c252010-06-23 17:38:20 -0700999 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001000 reply->writeInt32(status);
1001 if (status == NO_ERROR) {
1002 reply->write(&desc, sizeof(effect_descriptor_t));
1003 }
1004 return NO_ERROR;
1005 }
1006 case GET_EFFECT_DESCRIPTOR: {
1007 CHECK_INTERFACE(IAudioFlinger, data, reply);
1008 effect_uuid_t uuid;
1009 data.read(&uuid, sizeof(effect_uuid_t));
1010 effect_descriptor_t desc;
1011 status_t status = getEffectDescriptor(&uuid, &desc);
1012 reply->writeInt32(status);
1013 if (status == NO_ERROR) {
1014 reply->write(&desc, sizeof(effect_descriptor_t));
1015 }
1016 return NO_ERROR;
1017 }
1018 case CREATE_EFFECT: {
1019 CHECK_INTERFACE(IAudioFlinger, data, reply);
1020 pid_t pid = data.readInt32();
1021 effect_descriptor_t desc;
1022 data.read(&desc, sizeof(effect_descriptor_t));
1023 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1024 int32_t priority = data.readInt32();
1025 int output = data.readInt32();
1026 int sessionId = data.readInt32();
1027 status_t status;
1028 int id;
1029 int enabled;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001030
Eric Laurentbe916aa2010-06-01 23:49:17 -07001031 sp<IEffect> effect = createEffect(pid, &desc, client, priority, output, sessionId, &status, &id, &enabled);
1032 reply->writeInt32(status);
1033 reply->writeInt32(id);
1034 reply->writeInt32(enabled);
1035 reply->writeStrongBinder(effect->asBinder());
1036 reply->write(&desc, sizeof(effect_descriptor_t));
1037 return NO_ERROR;
1038 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001039 case MOVE_EFFECTS: {
1040 CHECK_INTERFACE(IAudioFlinger, data, reply);
1041 int session = data.readInt32();
1042 int srcOutput = data.readInt32();
1043 int dstOutput = data.readInt32();
1044 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1045 return NO_ERROR;
1046 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001047 default:
1048 return BBinder::onTransact(code, data, reply, flags);
1049 }
1050}
1051
1052// ----------------------------------------------------------------------------
1053
1054}; // namespace android