blob: 0eff20528511efce9ea65cbf0fba46e51dbfbf8a [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Laurenta553c252009-07-17 12:17:14 -070019//#define LOG_NDEBUG 0
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020#include <utils/Log.h>
21
22#include <stdint.h>
23#include <sys/types.h>
24
Mathias Agopian07952722009-05-19 19:08:10 -070025#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-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 Project9066cfe2009-03-03 19:31:44 -080048 SET_MIC_MUTE,
49 GET_MIC_MUTE,
50 IS_MUSIC_ACTIVE,
Eric Laurenta553c252009-07-17 12:17:14 -070051 SET_PARAMETERS,
52 GET_PARAMETERS,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053 REGISTER_CLIENT,
54 GET_INPUTBUFFERSIZE,
Eric Laurenta553c252009-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 Laurent415f3e22009-10-21 08:14:22 -070062 SET_STREAM_OUTPUT,
63 SET_VOICE_VOLUME
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064};
65
66class BpAudioFlinger : public BpInterface<IAudioFlinger>
67{
68public:
69 BpAudioFlinger(const sp<IBinder>& impl)
70 : BpInterface<IAudioFlinger>(impl)
71 {
72 }
73
74 virtual sp<IAudioTrack> createTrack(
75 pid_t pid,
76 int streamType,
77 uint32_t sampleRate,
78 int format,
79 int channelCount,
80 int frameCount,
81 uint32_t flags,
82 const sp<IMemory>& sharedBuffer,
Eric Laurentddb78e72009-07-28 08:44:33 -070083 int output,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 status_t *status)
85 {
86 Parcel data, reply;
Eric Laurent8a77a992009-09-09 05:16:08 -070087 sp<IAudioTrack> track;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
89 data.writeInt32(pid);
90 data.writeInt32(streamType);
91 data.writeInt32(sampleRate);
92 data.writeInt32(format);
93 data.writeInt32(channelCount);
94 data.writeInt32(frameCount);
95 data.writeInt32(flags);
96 data.writeStrongBinder(sharedBuffer->asBinder());
Eric Laurentddb78e72009-07-28 08:44:33 -070097 data.writeInt32(output);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
99 if (lStatus != NO_ERROR) {
100 LOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent8a77a992009-09-09 05:16:08 -0700101 } else {
102 lStatus = reply.readInt32();
103 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 if (status) {
106 *status = lStatus;
107 }
Eric Laurent8a77a992009-09-09 05:16:08 -0700108 return track;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 }
110
111 virtual sp<IAudioRecord> openRecord(
112 pid_t pid,
Eric Laurentddb78e72009-07-28 08:44:33 -0700113 int input,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 uint32_t sampleRate,
115 int format,
116 int channelCount,
117 int frameCount,
118 uint32_t flags,
119 status_t *status)
120 {
121 Parcel data, reply;
Eric Laurent8a77a992009-09-09 05:16:08 -0700122 sp<IAudioRecord> record;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
124 data.writeInt32(pid);
Eric Laurentddb78e72009-07-28 08:44:33 -0700125 data.writeInt32(input);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 data.writeInt32(sampleRate);
127 data.writeInt32(format);
128 data.writeInt32(channelCount);
129 data.writeInt32(frameCount);
130 data.writeInt32(flags);
Eric Laurent8a77a992009-09-09 05:16:08 -0700131 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
132 if (lStatus != NO_ERROR) {
133 LOGE("openRecord error: %s", strerror(-lStatus));
134 } else {
135 lStatus = reply.readInt32();
136 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
137 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 if (status) {
139 *status = lStatus;
140 }
Eric Laurent8a77a992009-09-09 05:16:08 -0700141 return record;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 }
143
Eric Laurentddb78e72009-07-28 08:44:33 -0700144 virtual uint32_t sampleRate(int output) const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 {
146 Parcel data, reply;
147 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentddb78e72009-07-28 08:44:33 -0700148 data.writeInt32(output);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 remote()->transact(SAMPLE_RATE, data, &reply);
150 return reply.readInt32();
151 }
152
Eric Laurentddb78e72009-07-28 08:44:33 -0700153 virtual int channelCount(int output) const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 {
155 Parcel data, reply;
156 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentddb78e72009-07-28 08:44:33 -0700157 data.writeInt32(output);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 remote()->transact(CHANNEL_COUNT, data, &reply);
159 return reply.readInt32();
160 }
161
Eric Laurentddb78e72009-07-28 08:44:33 -0700162 virtual int format(int output) const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 {
164 Parcel data, reply;
165 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentddb78e72009-07-28 08:44:33 -0700166 data.writeInt32(output);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 remote()->transact(FORMAT, data, &reply);
168 return reply.readInt32();
169 }
170
Eric Laurentddb78e72009-07-28 08:44:33 -0700171 virtual size_t frameCount(int output) const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 {
173 Parcel data, reply;
174 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentddb78e72009-07-28 08:44:33 -0700175 data.writeInt32(output);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 remote()->transact(FRAME_COUNT, data, &reply);
177 return reply.readInt32();
178 }
179
Eric Laurentddb78e72009-07-28 08:44:33 -0700180 virtual uint32_t latency(int output) const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 {
182 Parcel data, reply;
183 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentddb78e72009-07-28 08:44:33 -0700184 data.writeInt32(output);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 remote()->transact(LATENCY, data, &reply);
186 return reply.readInt32();
187 }
188
189 virtual status_t setMasterVolume(float value)
190 {
191 Parcel data, reply;
192 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
193 data.writeFloat(value);
194 remote()->transact(SET_MASTER_VOLUME, data, &reply);
195 return reply.readInt32();
196 }
197
198 virtual status_t setMasterMute(bool muted)
199 {
200 Parcel data, reply;
201 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
202 data.writeInt32(muted);
203 remote()->transact(SET_MASTER_MUTE, data, &reply);
204 return reply.readInt32();
205 }
206
207 virtual float masterVolume() const
208 {
209 Parcel data, reply;
210 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
211 remote()->transact(MASTER_VOLUME, data, &reply);
212 return reply.readFloat();
213 }
214
215 virtual bool masterMute() const
216 {
217 Parcel data, reply;
218 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
219 remote()->transact(MASTER_MUTE, data, &reply);
220 return reply.readInt32();
221 }
222
Eric Laurentddb78e72009-07-28 08:44:33 -0700223 virtual status_t setStreamVolume(int stream, float value, int output)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 {
225 Parcel data, reply;
226 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
227 data.writeInt32(stream);
228 data.writeFloat(value);
Eric Laurentddb78e72009-07-28 08:44:33 -0700229 data.writeInt32(output);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 remote()->transact(SET_STREAM_VOLUME, data, &reply);
231 return reply.readInt32();
232 }
233
234 virtual status_t setStreamMute(int stream, bool muted)
235 {
236 Parcel data, reply;
237 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
238 data.writeInt32(stream);
239 data.writeInt32(muted);
240 remote()->transact(SET_STREAM_MUTE, data, &reply);
241 return reply.readInt32();
242 }
243
Eric Laurentddb78e72009-07-28 08:44:33 -0700244 virtual float streamVolume(int stream, int output) const
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 {
246 Parcel data, reply;
247 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
248 data.writeInt32(stream);
Eric Laurentddb78e72009-07-28 08:44:33 -0700249 data.writeInt32(output);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 remote()->transact(STREAM_VOLUME, data, &reply);
251 return reply.readFloat();
252 }
253
254 virtual bool streamMute(int stream) const
255 {
256 Parcel data, reply;
257 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
258 data.writeInt32(stream);
259 remote()->transact(STREAM_MUTE, data, &reply);
260 return reply.readInt32();
261 }
262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 virtual status_t setMode(int mode)
264 {
265 Parcel data, reply;
266 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
267 data.writeInt32(mode);
268 remote()->transact(SET_MODE, data, &reply);
269 return reply.readInt32();
270 }
271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 virtual status_t setMicMute(bool state)
273 {
274 Parcel data, reply;
275 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
276 data.writeInt32(state);
277 remote()->transact(SET_MIC_MUTE, data, &reply);
278 return reply.readInt32();
279 }
280
281 virtual bool getMicMute() const
282 {
283 Parcel data, reply;
284 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
285 remote()->transact(GET_MIC_MUTE, data, &reply);
286 return reply.readInt32();
287 }
288
289 virtual bool isMusicActive() const
290 {
291 Parcel data, reply;
292 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
293 remote()->transact(IS_MUSIC_ACTIVE, data, &reply);
294 return reply.readInt32();
295 }
296
Eric Laurentddb78e72009-07-28 08:44:33 -0700297 virtual status_t setParameters(int ioHandle, const String8& keyValuePairs)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 {
299 Parcel data, reply;
300 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentddb78e72009-07-28 08:44:33 -0700301 data.writeInt32(ioHandle);
Eric Laurenta553c252009-07-17 12:17:14 -0700302 data.writeString8(keyValuePairs);
303 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 return reply.readInt32();
305 }
Eric Laurenta553c252009-07-17 12:17:14 -0700306
Eric Laurentddb78e72009-07-28 08:44:33 -0700307 virtual String8 getParameters(int ioHandle, const String8& keys)
Eric Laurenta553c252009-07-17 12:17:14 -0700308 {
309 Parcel data, reply;
310 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentddb78e72009-07-28 08:44:33 -0700311 data.writeInt32(ioHandle);
Eric Laurenta553c252009-07-17 12:17:14 -0700312 data.writeString8(keys);
313 remote()->transact(GET_PARAMETERS, data, &reply);
314 return reply.readString8();
315 }
316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 virtual void registerClient(const sp<IAudioFlingerClient>& client)
318 {
319 Parcel data, reply;
320 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
321 data.writeStrongBinder(client->asBinder());
322 remote()->transact(REGISTER_CLIENT, data, &reply);
323 }
Eric Laurenta553c252009-07-17 12:17:14 -0700324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
326 {
327 Parcel data, reply;
328 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
329 data.writeInt32(sampleRate);
330 data.writeInt32(format);
331 data.writeInt32(channelCount);
332 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
333 return reply.readInt32();
334 }
Eric Laurenta553c252009-07-17 12:17:14 -0700335
Eric Laurentddb78e72009-07-28 08:44:33 -0700336 virtual int openOutput(uint32_t *pDevices,
Eric Laurenta553c252009-07-17 12:17:14 -0700337 uint32_t *pSamplingRate,
338 uint32_t *pFormat,
339 uint32_t *pChannels,
340 uint32_t *pLatencyMs,
341 uint32_t flags)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 {
343 Parcel data, reply;
Eric Laurenta553c252009-07-17 12:17:14 -0700344 uint32_t devices = pDevices ? *pDevices : 0;
345 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
346 uint32_t format = pFormat ? *pFormat : 0;
347 uint32_t channels = pChannels ? *pChannels : 0;
348 uint32_t latency = pLatencyMs ? *pLatencyMs : 0;
349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta553c252009-07-17 12:17:14 -0700351 data.writeInt32(devices);
352 data.writeInt32(samplingRate);
353 data.writeInt32(format);
354 data.writeInt32(channels);
355 data.writeInt32(latency);
356 data.writeInt32(flags);
357 remote()->transact(OPEN_OUTPUT, data, &reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700358 int output = reply.readInt32();
Eric Laurenta553c252009-07-17 12:17:14 -0700359 LOGV("openOutput() returned output, %p", output);
360 devices = reply.readInt32();
361 if (pDevices) *pDevices = devices;
362 samplingRate = reply.readInt32();
363 if (pSamplingRate) *pSamplingRate = samplingRate;
364 format = reply.readInt32();
365 if (pFormat) *pFormat = format;
366 channels = reply.readInt32();
367 if (pChannels) *pChannels = channels;
368 latency = reply.readInt32();
369 if (pLatencyMs) *pLatencyMs = latency;
370 return output;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 }
372
Eric Laurentddb78e72009-07-28 08:44:33 -0700373 virtual int openDuplicateOutput(int output1, int output2)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 {
375 Parcel data, reply;
376 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentddb78e72009-07-28 08:44:33 -0700377 data.writeInt32(output1);
378 data.writeInt32(output2);
Eric Laurenta553c252009-07-17 12:17:14 -0700379 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700380 return reply.readInt32();
Eric Laurenta553c252009-07-17 12:17:14 -0700381 }
382
Eric Laurentddb78e72009-07-28 08:44:33 -0700383 virtual status_t closeOutput(int output)
Eric Laurenta553c252009-07-17 12:17:14 -0700384 {
385 Parcel data, reply;
386 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentddb78e72009-07-28 08:44:33 -0700387 data.writeInt32(output);
Eric Laurenta553c252009-07-17 12:17:14 -0700388 remote()->transact(CLOSE_OUTPUT, data, &reply);
389 return reply.readInt32();
390 }
391
Eric Laurentddb78e72009-07-28 08:44:33 -0700392 virtual status_t suspendOutput(int output)
Eric Laurenta553c252009-07-17 12:17:14 -0700393 {
394 Parcel data, reply;
395 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentddb78e72009-07-28 08:44:33 -0700396 data.writeInt32(output);
Eric Laurenta553c252009-07-17 12:17:14 -0700397 remote()->transact(SUSPEND_OUTPUT, data, &reply);
398 return reply.readInt32();
399 }
400
Eric Laurentddb78e72009-07-28 08:44:33 -0700401 virtual status_t restoreOutput(int output)
Eric Laurenta553c252009-07-17 12:17:14 -0700402 {
403 Parcel data, reply;
404 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentddb78e72009-07-28 08:44:33 -0700405 data.writeInt32(output);
Eric Laurenta553c252009-07-17 12:17:14 -0700406 remote()->transact(RESTORE_OUTPUT, data, &reply);
407 return reply.readInt32();
408 }
409
Eric Laurentddb78e72009-07-28 08:44:33 -0700410 virtual int openInput(uint32_t *pDevices,
411 uint32_t *pSamplingRate,
412 uint32_t *pFormat,
413 uint32_t *pChannels,
414 uint32_t acoustics)
Eric Laurenta553c252009-07-17 12:17:14 -0700415 {
416 Parcel data, reply;
417 uint32_t devices = pDevices ? *pDevices : 0;
418 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
419 uint32_t format = pFormat ? *pFormat : 0;
420 uint32_t channels = pChannels ? *pChannels : 0;
421
422 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
423 data.writeInt32(devices);
424 data.writeInt32(samplingRate);
425 data.writeInt32(format);
426 data.writeInt32(channels);
427 data.writeInt32(acoustics);
428 remote()->transact(OPEN_INPUT, data, &reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700429 int input = reply.readInt32();
Eric Laurenta553c252009-07-17 12:17:14 -0700430 devices = reply.readInt32();
431 if (pDevices) *pDevices = devices;
432 samplingRate = reply.readInt32();
433 if (pSamplingRate) *pSamplingRate = samplingRate;
434 format = reply.readInt32();
435 if (pFormat) *pFormat = format;
436 channels = reply.readInt32();
437 if (pChannels) *pChannels = channels;
438 return input;
439 }
440
Eric Laurentddb78e72009-07-28 08:44:33 -0700441 virtual status_t closeInput(int input)
Eric Laurenta553c252009-07-17 12:17:14 -0700442 {
443 Parcel data, reply;
444 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentddb78e72009-07-28 08:44:33 -0700445 data.writeInt32(input);
Eric Laurenta553c252009-07-17 12:17:14 -0700446 remote()->transact(CLOSE_INPUT, data, &reply);
447 return reply.readInt32();
448 }
449
Eric Laurentddb78e72009-07-28 08:44:33 -0700450 virtual status_t setStreamOutput(uint32_t stream, int output)
Eric Laurenta553c252009-07-17 12:17:14 -0700451 {
452 Parcel data, reply;
453 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
454 data.writeInt32(stream);
Eric Laurentddb78e72009-07-28 08:44:33 -0700455 data.writeInt32(output);
Eric Laurenta553c252009-07-17 12:17:14 -0700456 remote()->transact(SET_STREAM_OUTPUT, data, &reply);
457 return reply.readInt32();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 }
Eric Laurent415f3e22009-10-21 08:14:22 -0700459
460 virtual status_t setVoiceVolume(float volume)
461 {
462 Parcel data, reply;
463 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
464 data.writeFloat(volume);
465 remote()->transact(SET_VOICE_VOLUME, data, &reply);
466 return reply.readInt32();
467 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468};
469
470IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
471
472// ----------------------------------------------------------------------
473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474status_t BnAudioFlinger::onTransact(
475 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
476{
477 switch(code) {
478 case CREATE_TRACK: {
479 CHECK_INTERFACE(IAudioFlinger, data, reply);
480 pid_t pid = data.readInt32();
481 int streamType = data.readInt32();
482 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 sp<IMemory> buffer = interface_cast<IMemory>(data.readStrongBinder());
Eric Laurentddb78e72009-07-28 08:44:33 -0700488 int output = data.readInt32();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 status_t status;
490 sp<IAudioTrack> track = createTrack(pid,
491 streamType, sampleRate, format,
Eric Laurenta553c252009-07-17 12:17:14 -0700492 channelCount, bufferCount, flags, buffer, output, &status);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 reply->writeInt32(status);
494 reply->writeStrongBinder(track->asBinder());
495 return NO_ERROR;
496 } break;
497 case OPEN_RECORD: {
498 CHECK_INTERFACE(IAudioFlinger, data, reply);
499 pid_t pid = data.readInt32();
Eric Laurentddb78e72009-07-28 08:44:33 -0700500 int input = data.readInt32();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 uint32_t sampleRate = data.readInt32();
502 int format = data.readInt32();
503 int channelCount = data.readInt32();
504 size_t bufferCount = data.readInt32();
505 uint32_t flags = data.readInt32();
506 status_t status;
Eric Laurenta553c252009-07-17 12:17:14 -0700507 sp<IAudioRecord> record = openRecord(pid, input,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 sampleRate, format, channelCount, bufferCount, flags, &status);
509 reply->writeInt32(status);
510 reply->writeStrongBinder(record->asBinder());
511 return NO_ERROR;
512 } break;
513 case SAMPLE_RATE: {
514 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700515 reply->writeInt32( sampleRate(data.readInt32()) );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 return NO_ERROR;
517 } break;
518 case CHANNEL_COUNT: {
519 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700520 reply->writeInt32( channelCount(data.readInt32()) );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800521 return NO_ERROR;
522 } break;
523 case FORMAT: {
524 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700525 reply->writeInt32( format(data.readInt32()) );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 return NO_ERROR;
527 } break;
528 case FRAME_COUNT: {
529 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700530 reply->writeInt32( frameCount(data.readInt32()) );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 return NO_ERROR;
532 } break;
533 case LATENCY: {
534 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700535 reply->writeInt32( latency(data.readInt32()) );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 return NO_ERROR;
537 } break;
538 case SET_MASTER_VOLUME: {
539 CHECK_INTERFACE(IAudioFlinger, data, reply);
540 reply->writeInt32( setMasterVolume(data.readFloat()) );
541 return NO_ERROR;
542 } break;
543 case SET_MASTER_MUTE: {
544 CHECK_INTERFACE(IAudioFlinger, data, reply);
545 reply->writeInt32( setMasterMute(data.readInt32()) );
546 return NO_ERROR;
547 } break;
548 case MASTER_VOLUME: {
549 CHECK_INTERFACE(IAudioFlinger, data, reply);
550 reply->writeFloat( masterVolume() );
551 return NO_ERROR;
552 } break;
553 case MASTER_MUTE: {
554 CHECK_INTERFACE(IAudioFlinger, data, reply);
555 reply->writeInt32( masterMute() );
556 return NO_ERROR;
557 } break;
558 case SET_STREAM_VOLUME: {
559 CHECK_INTERFACE(IAudioFlinger, data, reply);
560 int stream = data.readInt32();
Eric Laurenta553c252009-07-17 12:17:14 -0700561 float volume = data.readFloat();
Eric Laurentddb78e72009-07-28 08:44:33 -0700562 int output = data.readInt32();
Eric Laurenta553c252009-07-17 12:17:14 -0700563 reply->writeInt32( setStreamVolume(stream, volume, output) );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 return NO_ERROR;
565 } break;
566 case SET_STREAM_MUTE: {
567 CHECK_INTERFACE(IAudioFlinger, data, reply);
568 int stream = data.readInt32();
569 reply->writeInt32( setStreamMute(stream, data.readInt32()) );
570 return NO_ERROR;
571 } break;
572 case STREAM_VOLUME: {
573 CHECK_INTERFACE(IAudioFlinger, data, reply);
574 int stream = data.readInt32();
Eric Laurentddb78e72009-07-28 08:44:33 -0700575 int output = data.readInt32();
Eric Laurenta553c252009-07-17 12:17:14 -0700576 reply->writeFloat( streamVolume(stream, output) );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 return NO_ERROR;
578 } break;
579 case STREAM_MUTE: {
580 CHECK_INTERFACE(IAudioFlinger, data, reply);
581 int stream = data.readInt32();
582 reply->writeInt32( streamMute(stream) );
583 return NO_ERROR;
584 } break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 case SET_MODE: {
586 CHECK_INTERFACE(IAudioFlinger, data, reply);
587 int mode = data.readInt32();
588 reply->writeInt32( setMode(mode) );
589 return NO_ERROR;
590 } break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 case SET_MIC_MUTE: {
592 CHECK_INTERFACE(IAudioFlinger, data, reply);
593 int state = data.readInt32();
594 reply->writeInt32( setMicMute(state) );
595 return NO_ERROR;
596 } break;
597 case GET_MIC_MUTE: {
598 CHECK_INTERFACE(IAudioFlinger, data, reply);
599 reply->writeInt32( getMicMute() );
600 return NO_ERROR;
601 } break;
602 case IS_MUSIC_ACTIVE: {
603 CHECK_INTERFACE(IAudioFlinger, data, reply);
604 reply->writeInt32( isMusicActive() );
605 return NO_ERROR;
606 } break;
Eric Laurenta553c252009-07-17 12:17:14 -0700607 case SET_PARAMETERS: {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700609 int ioHandle = data.readInt32();
Eric Laurenta553c252009-07-17 12:17:14 -0700610 String8 keyValuePairs(data.readString8());
611 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 return NO_ERROR;
Eric Laurenta553c252009-07-17 12:17:14 -0700613 } break;
614 case GET_PARAMETERS: {
615 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700616 int ioHandle = data.readInt32();
Eric Laurenta553c252009-07-17 12:17:14 -0700617 String8 keys(data.readString8());
618 reply->writeString8(getParameters(ioHandle, keys));
619 return NO_ERROR;
620 } break;
621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 case REGISTER_CLIENT: {
623 CHECK_INTERFACE(IAudioFlinger, data, reply);
624 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(data.readStrongBinder());
625 registerClient(client);
626 return NO_ERROR;
627 } break;
628 case GET_INPUTBUFFERSIZE: {
629 CHECK_INTERFACE(IAudioFlinger, data, reply);
630 uint32_t sampleRate = data.readInt32();
631 int format = data.readInt32();
632 int channelCount = data.readInt32();
633 reply->writeInt32( getInputBufferSize(sampleRate, format, channelCount) );
634 return NO_ERROR;
635 } break;
Eric Laurenta553c252009-07-17 12:17:14 -0700636 case OPEN_OUTPUT: {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta553c252009-07-17 12:17:14 -0700638 uint32_t devices = data.readInt32();
639 uint32_t samplingRate = data.readInt32();
640 uint32_t format = data.readInt32();
641 uint32_t channels = data.readInt32();
642 uint32_t latency = data.readInt32();
643 uint32_t flags = data.readInt32();
Eric Laurentddb78e72009-07-28 08:44:33 -0700644 int output = openOutput(&devices,
Eric Laurenta553c252009-07-17 12:17:14 -0700645 &samplingRate,
646 &format,
647 &channels,
648 &latency,
649 flags);
650 LOGV("OPEN_OUTPUT output, %p", output);
Eric Laurentddb78e72009-07-28 08:44:33 -0700651 reply->writeInt32(output);
Eric Laurenta553c252009-07-17 12:17:14 -0700652 reply->writeInt32(devices);
653 reply->writeInt32(samplingRate);
654 reply->writeInt32(format);
655 reply->writeInt32(channels);
656 reply->writeInt32(latency);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 return NO_ERROR;
658 } break;
Eric Laurenta553c252009-07-17 12:17:14 -0700659 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700661 int output1 = data.readInt32();
662 int output2 = data.readInt32();
663 reply->writeInt32(openDuplicateOutput(output1, output2));
Eric Laurenta553c252009-07-17 12:17:14 -0700664 return NO_ERROR;
665 } break;
666 case CLOSE_OUTPUT: {
667 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700668 reply->writeInt32(closeOutput(data.readInt32()));
Eric Laurenta553c252009-07-17 12:17:14 -0700669 return NO_ERROR;
670 } break;
671 case SUSPEND_OUTPUT: {
672 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700673 reply->writeInt32(suspendOutput(data.readInt32()));
Eric Laurenta553c252009-07-17 12:17:14 -0700674 return NO_ERROR;
675 } break;
676 case RESTORE_OUTPUT: {
677 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700678 reply->writeInt32(restoreOutput(data.readInt32()));
Eric Laurenta553c252009-07-17 12:17:14 -0700679 return NO_ERROR;
680 } break;
681 case OPEN_INPUT: {
682 CHECK_INTERFACE(IAudioFlinger, data, reply);
683 uint32_t devices = data.readInt32();
684 uint32_t samplingRate = data.readInt32();
685 uint32_t format = data.readInt32();
686 uint32_t channels = data.readInt32();
687 uint32_t acoutics = data.readInt32();
688
Eric Laurentddb78e72009-07-28 08:44:33 -0700689 int input = openInput(&devices,
Eric Laurenta553c252009-07-17 12:17:14 -0700690 &samplingRate,
691 &format,
692 &channels,
693 acoutics);
Eric Laurentddb78e72009-07-28 08:44:33 -0700694 reply->writeInt32(input);
Eric Laurenta553c252009-07-17 12:17:14 -0700695 reply->writeInt32(devices);
696 reply->writeInt32(samplingRate);
697 reply->writeInt32(format);
698 reply->writeInt32(channels);
699 return NO_ERROR;
700 } break;
701 case CLOSE_INPUT: {
702 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentddb78e72009-07-28 08:44:33 -0700703 reply->writeInt32(closeInput(data.readInt32()));
Eric Laurenta553c252009-07-17 12:17:14 -0700704 return NO_ERROR;
705 } break;
706 case SET_STREAM_OUTPUT: {
707 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta553c252009-07-17 12:17:14 -0700708 uint32_t stream = data.readInt32();
Eric Laurentddb78e72009-07-28 08:44:33 -0700709 int output = data.readInt32();
Eric Laurenta553c252009-07-17 12:17:14 -0700710 reply->writeInt32(setStreamOutput(stream, output));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711 return NO_ERROR;
712 } break;
Eric Laurent415f3e22009-10-21 08:14:22 -0700713 case SET_VOICE_VOLUME: {
714 CHECK_INTERFACE(IAudioFlinger, data, reply);
715 float volume = data.readFloat();
716 reply->writeInt32( setVoiceVolume(volume) );
717 return NO_ERROR;
718 } break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719 default:
720 return BBinder::onTransact(code, data, reply, flags);
721 }
722}
723
724// ----------------------------------------------------------------------------
725
726}; // namespace android