blob: fc39a46edcb5a86c7c3a50494417f4178addedd4 [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,
50 IS_MUSIC_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,
62 SET_STREAM_OUTPUT
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080063};
64
65class BpAudioFlinger : public BpInterface<IAudioFlinger>
66{
67public:
68 BpAudioFlinger(const sp<IBinder>& impl)
69 : BpInterface<IAudioFlinger>(impl)
70 {
71 }
72
73 virtual sp<IAudioTrack> createTrack(
74 pid_t pid,
75 int streamType,
76 uint32_t sampleRate,
77 int format,
78 int channelCount,
79 int frameCount,
80 uint32_t flags,
81 const sp<IMemory>& sharedBuffer,
Eric Laurentfa2877b2009-07-28 08:44:33 -070082 int output,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080083 status_t *status)
84 {
85 Parcel data, reply;
86 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
87 data.writeInt32(pid);
88 data.writeInt32(streamType);
89 data.writeInt32(sampleRate);
90 data.writeInt32(format);
91 data.writeInt32(channelCount);
92 data.writeInt32(frameCount);
93 data.writeInt32(flags);
94 data.writeStrongBinder(sharedBuffer->asBinder());
Eric Laurentfa2877b2009-07-28 08:44:33 -070095 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080096 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
97 if (lStatus != NO_ERROR) {
98 LOGE("createTrack error: %s", strerror(-lStatus));
99 }
100 lStatus = reply.readInt32();
101 if (status) {
102 *status = lStatus;
103 }
104 return interface_cast<IAudioTrack>(reply.readStrongBinder());
105 }
106
107 virtual sp<IAudioRecord> openRecord(
108 pid_t pid,
Eric Laurentfa2877b2009-07-28 08:44:33 -0700109 int input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800110 uint32_t sampleRate,
111 int format,
112 int channelCount,
113 int frameCount,
114 uint32_t flags,
115 status_t *status)
116 {
117 Parcel data, reply;
118 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
119 data.writeInt32(pid);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700120 data.writeInt32(input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800121 data.writeInt32(sampleRate);
122 data.writeInt32(format);
123 data.writeInt32(channelCount);
124 data.writeInt32(frameCount);
125 data.writeInt32(flags);
126 remote()->transact(OPEN_RECORD, data, &reply);
127 status_t lStatus = reply.readInt32();
128 if (status) {
129 *status = lStatus;
130 }
131 return interface_cast<IAudioRecord>(reply.readStrongBinder());
132 }
133
Eric Laurentfa2877b2009-07-28 08:44:33 -0700134 virtual uint32_t sampleRate(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800135 {
136 Parcel data, reply;
137 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700138 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800139 remote()->transact(SAMPLE_RATE, data, &reply);
140 return reply.readInt32();
141 }
142
Eric Laurentfa2877b2009-07-28 08:44:33 -0700143 virtual int channelCount(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800144 {
145 Parcel data, reply;
146 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700147 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800148 remote()->transact(CHANNEL_COUNT, data, &reply);
149 return reply.readInt32();
150 }
151
Eric Laurentfa2877b2009-07-28 08:44:33 -0700152 virtual int format(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800153 {
154 Parcel data, reply;
155 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700156 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800157 remote()->transact(FORMAT, data, &reply);
158 return reply.readInt32();
159 }
160
Eric Laurentfa2877b2009-07-28 08:44:33 -0700161 virtual size_t frameCount(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800162 {
163 Parcel data, reply;
164 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700165 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800166 remote()->transact(FRAME_COUNT, data, &reply);
167 return reply.readInt32();
168 }
169
Eric Laurentfa2877b2009-07-28 08:44:33 -0700170 virtual uint32_t latency(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800171 {
172 Parcel data, reply;
173 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700174 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800175 remote()->transact(LATENCY, data, &reply);
176 return reply.readInt32();
177 }
178
179 virtual status_t setMasterVolume(float value)
180 {
181 Parcel data, reply;
182 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
183 data.writeFloat(value);
184 remote()->transact(SET_MASTER_VOLUME, data, &reply);
185 return reply.readInt32();
186 }
187
188 virtual status_t setMasterMute(bool muted)
189 {
190 Parcel data, reply;
191 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
192 data.writeInt32(muted);
193 remote()->transact(SET_MASTER_MUTE, data, &reply);
194 return reply.readInt32();
195 }
196
197 virtual float masterVolume() const
198 {
199 Parcel data, reply;
200 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
201 remote()->transact(MASTER_VOLUME, data, &reply);
202 return reply.readFloat();
203 }
204
205 virtual bool masterMute() const
206 {
207 Parcel data, reply;
208 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
209 remote()->transact(MASTER_MUTE, data, &reply);
210 return reply.readInt32();
211 }
212
Eric Laurentfa2877b2009-07-28 08:44:33 -0700213 virtual status_t setStreamVolume(int stream, float value, int output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800214 {
215 Parcel data, reply;
216 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
217 data.writeInt32(stream);
218 data.writeFloat(value);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700219 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800220 remote()->transact(SET_STREAM_VOLUME, data, &reply);
221 return reply.readInt32();
222 }
223
224 virtual status_t setStreamMute(int stream, bool muted)
225 {
226 Parcel data, reply;
227 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
228 data.writeInt32(stream);
229 data.writeInt32(muted);
230 remote()->transact(SET_STREAM_MUTE, data, &reply);
231 return reply.readInt32();
232 }
233
Eric Laurentfa2877b2009-07-28 08:44:33 -0700234 virtual float streamVolume(int stream, int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800235 {
236 Parcel data, reply;
237 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
238 data.writeInt32(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700239 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800240 remote()->transact(STREAM_VOLUME, data, &reply);
241 return reply.readFloat();
242 }
243
244 virtual bool streamMute(int stream) const
245 {
246 Parcel data, reply;
247 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
248 data.writeInt32(stream);
249 remote()->transact(STREAM_MUTE, data, &reply);
250 return reply.readInt32();
251 }
252
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800253 virtual status_t setMode(int mode)
254 {
255 Parcel data, reply;
256 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
257 data.writeInt32(mode);
258 remote()->transact(SET_MODE, data, &reply);
259 return reply.readInt32();
260 }
261
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800262 virtual status_t setMicMute(bool state)
263 {
264 Parcel data, reply;
265 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
266 data.writeInt32(state);
267 remote()->transact(SET_MIC_MUTE, data, &reply);
268 return reply.readInt32();
269 }
270
271 virtual bool getMicMute() const
272 {
273 Parcel data, reply;
274 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
275 remote()->transact(GET_MIC_MUTE, data, &reply);
276 return reply.readInt32();
277 }
278
279 virtual bool isMusicActive() const
280 {
281 Parcel data, reply;
282 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
283 remote()->transact(IS_MUSIC_ACTIVE, data, &reply);
284 return reply.readInt32();
285 }
286
Eric Laurentfa2877b2009-07-28 08:44:33 -0700287 virtual status_t setParameters(int ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800288 {
289 Parcel data, reply;
290 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700291 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700292 data.writeString8(keyValuePairs);
293 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800294 return reply.readInt32();
295 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700296
Eric Laurentfa2877b2009-07-28 08:44:33 -0700297 virtual String8 getParameters(int ioHandle, const String8& keys)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700298 {
299 Parcel data, reply;
300 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700301 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700302 data.writeString8(keys);
303 remote()->transact(GET_PARAMETERS, data, &reply);
304 return reply.readString8();
305 }
306
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800307 virtual void registerClient(const sp<IAudioFlingerClient>& client)
308 {
309 Parcel data, reply;
310 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
311 data.writeStrongBinder(client->asBinder());
312 remote()->transact(REGISTER_CLIENT, data, &reply);
313 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700314
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800315 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
316 {
317 Parcel data, reply;
318 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
319 data.writeInt32(sampleRate);
320 data.writeInt32(format);
321 data.writeInt32(channelCount);
322 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
323 return reply.readInt32();
324 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700325
Eric Laurentfa2877b2009-07-28 08:44:33 -0700326 virtual int openOutput(uint32_t *pDevices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700327 uint32_t *pSamplingRate,
328 uint32_t *pFormat,
329 uint32_t *pChannels,
330 uint32_t *pLatencyMs,
331 uint32_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800332 {
333 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700334 uint32_t devices = pDevices ? *pDevices : 0;
335 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
336 uint32_t format = pFormat ? *pFormat : 0;
337 uint32_t channels = pChannels ? *pChannels : 0;
338 uint32_t latency = pLatencyMs ? *pLatencyMs : 0;
339
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800340 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700341 data.writeInt32(devices);
342 data.writeInt32(samplingRate);
343 data.writeInt32(format);
344 data.writeInt32(channels);
345 data.writeInt32(latency);
346 data.writeInt32(flags);
347 remote()->transact(OPEN_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700348 int output = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700349 LOGV("openOutput() returned output, %p", output);
350 devices = reply.readInt32();
351 if (pDevices) *pDevices = devices;
352 samplingRate = reply.readInt32();
353 if (pSamplingRate) *pSamplingRate = samplingRate;
354 format = reply.readInt32();
355 if (pFormat) *pFormat = format;
356 channels = reply.readInt32();
357 if (pChannels) *pChannels = channels;
358 latency = reply.readInt32();
359 if (pLatencyMs) *pLatencyMs = latency;
360 return output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800361 }
362
Eric Laurentfa2877b2009-07-28 08:44:33 -0700363 virtual int openDuplicateOutput(int output1, int output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800364 {
365 Parcel data, reply;
366 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700367 data.writeInt32(output1);
368 data.writeInt32(output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700369 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700370 return reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700371 }
372
Eric Laurentfa2877b2009-07-28 08:44:33 -0700373 virtual status_t closeOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700374 {
375 Parcel data, reply;
376 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700377 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700378 remote()->transact(CLOSE_OUTPUT, data, &reply);
379 return reply.readInt32();
380 }
381
Eric Laurentfa2877b2009-07-28 08:44:33 -0700382 virtual status_t suspendOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700383 {
384 Parcel data, reply;
385 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700386 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700387 remote()->transact(SUSPEND_OUTPUT, data, &reply);
388 return reply.readInt32();
389 }
390
Eric Laurentfa2877b2009-07-28 08:44:33 -0700391 virtual status_t restoreOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700392 {
393 Parcel data, reply;
394 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700395 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700396 remote()->transact(RESTORE_OUTPUT, data, &reply);
397 return reply.readInt32();
398 }
399
Eric Laurentfa2877b2009-07-28 08:44:33 -0700400 virtual int openInput(uint32_t *pDevices,
401 uint32_t *pSamplingRate,
402 uint32_t *pFormat,
403 uint32_t *pChannels,
404 uint32_t acoustics)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700405 {
406 Parcel data, reply;
407 uint32_t devices = pDevices ? *pDevices : 0;
408 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
409 uint32_t format = pFormat ? *pFormat : 0;
410 uint32_t channels = pChannels ? *pChannels : 0;
411
412 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
413 data.writeInt32(devices);
414 data.writeInt32(samplingRate);
415 data.writeInt32(format);
416 data.writeInt32(channels);
417 data.writeInt32(acoustics);
418 remote()->transact(OPEN_INPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700419 int input = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700420 devices = reply.readInt32();
421 if (pDevices) *pDevices = devices;
422 samplingRate = reply.readInt32();
423 if (pSamplingRate) *pSamplingRate = samplingRate;
424 format = reply.readInt32();
425 if (pFormat) *pFormat = format;
426 channels = reply.readInt32();
427 if (pChannels) *pChannels = channels;
428 return input;
429 }
430
Eric Laurentfa2877b2009-07-28 08:44:33 -0700431 virtual status_t closeInput(int input)
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(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700436 remote()->transact(CLOSE_INPUT, data, &reply);
437 return reply.readInt32();
438 }
439
Eric Laurentfa2877b2009-07-28 08:44:33 -0700440 virtual status_t setStreamOutput(uint32_t stream, int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700441 {
442 Parcel data, reply;
443 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
444 data.writeInt32(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700445 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700446 remote()->transact(SET_STREAM_OUTPUT, data, &reply);
447 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800448 }
449};
450
451IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
452
453// ----------------------------------------------------------------------
454
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800455status_t BnAudioFlinger::onTransact(
456 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
457{
458 switch(code) {
459 case CREATE_TRACK: {
460 CHECK_INTERFACE(IAudioFlinger, data, reply);
461 pid_t pid = data.readInt32();
462 int streamType = data.readInt32();
463 uint32_t sampleRate = data.readInt32();
464 int format = data.readInt32();
465 int channelCount = data.readInt32();
466 size_t bufferCount = data.readInt32();
467 uint32_t flags = data.readInt32();
468 sp<IMemory> buffer = interface_cast<IMemory>(data.readStrongBinder());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700469 int output = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800470 status_t status;
471 sp<IAudioTrack> track = createTrack(pid,
472 streamType, sampleRate, format,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700473 channelCount, bufferCount, flags, buffer, output, &status);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800474 reply->writeInt32(status);
475 reply->writeStrongBinder(track->asBinder());
476 return NO_ERROR;
477 } break;
478 case OPEN_RECORD: {
479 CHECK_INTERFACE(IAudioFlinger, data, reply);
480 pid_t pid = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700481 int input = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800482 uint32_t sampleRate = data.readInt32();
483 int format = data.readInt32();
484 int channelCount = data.readInt32();
485 size_t bufferCount = data.readInt32();
486 uint32_t flags = data.readInt32();
487 status_t status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700488 sp<IAudioRecord> record = openRecord(pid, input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800489 sampleRate, format, channelCount, bufferCount, flags, &status);
490 reply->writeInt32(status);
491 reply->writeStrongBinder(record->asBinder());
492 return NO_ERROR;
493 } break;
494 case SAMPLE_RATE: {
495 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700496 reply->writeInt32( sampleRate(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800497 return NO_ERROR;
498 } break;
499 case CHANNEL_COUNT: {
500 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700501 reply->writeInt32( channelCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800502 return NO_ERROR;
503 } break;
504 case FORMAT: {
505 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700506 reply->writeInt32( format(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800507 return NO_ERROR;
508 } break;
509 case FRAME_COUNT: {
510 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700511 reply->writeInt32( frameCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800512 return NO_ERROR;
513 } break;
514 case LATENCY: {
515 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700516 reply->writeInt32( latency(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800517 return NO_ERROR;
518 } break;
519 case SET_MASTER_VOLUME: {
520 CHECK_INTERFACE(IAudioFlinger, data, reply);
521 reply->writeInt32( setMasterVolume(data.readFloat()) );
522 return NO_ERROR;
523 } break;
524 case SET_MASTER_MUTE: {
525 CHECK_INTERFACE(IAudioFlinger, data, reply);
526 reply->writeInt32( setMasterMute(data.readInt32()) );
527 return NO_ERROR;
528 } break;
529 case MASTER_VOLUME: {
530 CHECK_INTERFACE(IAudioFlinger, data, reply);
531 reply->writeFloat( masterVolume() );
532 return NO_ERROR;
533 } break;
534 case MASTER_MUTE: {
535 CHECK_INTERFACE(IAudioFlinger, data, reply);
536 reply->writeInt32( masterMute() );
537 return NO_ERROR;
538 } break;
539 case SET_STREAM_VOLUME: {
540 CHECK_INTERFACE(IAudioFlinger, data, reply);
541 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700542 float volume = data.readFloat();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700543 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700544 reply->writeInt32( setStreamVolume(stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800545 return NO_ERROR;
546 } break;
547 case SET_STREAM_MUTE: {
548 CHECK_INTERFACE(IAudioFlinger, data, reply);
549 int stream = data.readInt32();
550 reply->writeInt32( setStreamMute(stream, data.readInt32()) );
551 return NO_ERROR;
552 } break;
553 case STREAM_VOLUME: {
554 CHECK_INTERFACE(IAudioFlinger, data, reply);
555 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700556 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700557 reply->writeFloat( streamVolume(stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800558 return NO_ERROR;
559 } break;
560 case STREAM_MUTE: {
561 CHECK_INTERFACE(IAudioFlinger, data, reply);
562 int stream = data.readInt32();
563 reply->writeInt32( streamMute(stream) );
564 return NO_ERROR;
565 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800566 case SET_MODE: {
567 CHECK_INTERFACE(IAudioFlinger, data, reply);
568 int mode = data.readInt32();
569 reply->writeInt32( setMode(mode) );
570 return NO_ERROR;
571 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800572 case SET_MIC_MUTE: {
573 CHECK_INTERFACE(IAudioFlinger, data, reply);
574 int state = data.readInt32();
575 reply->writeInt32( setMicMute(state) );
576 return NO_ERROR;
577 } break;
578 case GET_MIC_MUTE: {
579 CHECK_INTERFACE(IAudioFlinger, data, reply);
580 reply->writeInt32( getMicMute() );
581 return NO_ERROR;
582 } break;
583 case IS_MUSIC_ACTIVE: {
584 CHECK_INTERFACE(IAudioFlinger, data, reply);
585 reply->writeInt32( isMusicActive() );
586 return NO_ERROR;
587 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700588 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800589 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700590 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700591 String8 keyValuePairs(data.readString8());
592 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800593 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700594 } break;
595 case GET_PARAMETERS: {
596 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700597 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700598 String8 keys(data.readString8());
599 reply->writeString8(getParameters(ioHandle, keys));
600 return NO_ERROR;
601 } break;
602
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800603 case REGISTER_CLIENT: {
604 CHECK_INTERFACE(IAudioFlinger, data, reply);
605 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(data.readStrongBinder());
606 registerClient(client);
607 return NO_ERROR;
608 } break;
609 case GET_INPUTBUFFERSIZE: {
610 CHECK_INTERFACE(IAudioFlinger, data, reply);
611 uint32_t sampleRate = data.readInt32();
612 int format = data.readInt32();
613 int channelCount = data.readInt32();
614 reply->writeInt32( getInputBufferSize(sampleRate, format, channelCount) );
615 return NO_ERROR;
616 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700617 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800618 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700619 uint32_t devices = data.readInt32();
620 uint32_t samplingRate = data.readInt32();
621 uint32_t format = data.readInt32();
622 uint32_t channels = data.readInt32();
623 uint32_t latency = data.readInt32();
624 uint32_t flags = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700625 int output = openOutput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700626 &samplingRate,
627 &format,
628 &channels,
629 &latency,
630 flags);
631 LOGV("OPEN_OUTPUT output, %p", output);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700632 reply->writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700633 reply->writeInt32(devices);
634 reply->writeInt32(samplingRate);
635 reply->writeInt32(format);
636 reply->writeInt32(channels);
637 reply->writeInt32(latency);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800638 return NO_ERROR;
639 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700640 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800641 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700642 int output1 = data.readInt32();
643 int output2 = data.readInt32();
644 reply->writeInt32(openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700645 return NO_ERROR;
646 } break;
647 case CLOSE_OUTPUT: {
648 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700649 reply->writeInt32(closeOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700650 return NO_ERROR;
651 } break;
652 case SUSPEND_OUTPUT: {
653 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700654 reply->writeInt32(suspendOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700655 return NO_ERROR;
656 } break;
657 case RESTORE_OUTPUT: {
658 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700659 reply->writeInt32(restoreOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700660 return NO_ERROR;
661 } break;
662 case OPEN_INPUT: {
663 CHECK_INTERFACE(IAudioFlinger, data, reply);
664 uint32_t devices = data.readInt32();
665 uint32_t samplingRate = data.readInt32();
666 uint32_t format = data.readInt32();
667 uint32_t channels = data.readInt32();
668 uint32_t acoutics = data.readInt32();
669
Eric Laurentfa2877b2009-07-28 08:44:33 -0700670 int input = openInput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700671 &samplingRate,
672 &format,
673 &channels,
674 acoutics);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700675 reply->writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700676 reply->writeInt32(devices);
677 reply->writeInt32(samplingRate);
678 reply->writeInt32(format);
679 reply->writeInt32(channels);
680 return NO_ERROR;
681 } break;
682 case CLOSE_INPUT: {
683 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700684 reply->writeInt32(closeInput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700685 return NO_ERROR;
686 } break;
687 case SET_STREAM_OUTPUT: {
688 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700689 uint32_t stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700690 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700691 reply->writeInt32(setStreamOutput(stream, output));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800692 return NO_ERROR;
693 } break;
694 default:
695 return BBinder::onTransact(code, data, reply, flags);
696 }
697}
698
699// ----------------------------------------------------------------------------
700
701}; // namespace android