blob: fc42979446ed0942f86dbf3122a1626fb9a862a4 [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,
63 SET_VOICE_VOLUME
The Android Open Source Project89fa4ad2009-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 Laurentfa2877b2009-07-28 08:44:33 -070083 int output,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080084 status_t *status)
85 {
86 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -070087 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-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 Laurentfa2877b2009-07-28 08:44:33 -070097 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-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 Laurent5841db72009-09-09 05:16:08 -0700101 } else {
102 lStatus = reply.readInt32();
103 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800104 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800105 if (status) {
106 *status = lStatus;
107 }
Eric Laurent5841db72009-09-09 05:16:08 -0700108 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800109 }
110
111 virtual sp<IAudioRecord> openRecord(
112 pid_t pid,
Eric Laurentfa2877b2009-07-28 08:44:33 -0700113 int input,
The Android Open Source Project89fa4ad2009-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 Laurent5841db72009-09-09 05:16:08 -0700122 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800123 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
124 data.writeInt32(pid);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700125 data.writeInt32(input);
The Android Open Source Project89fa4ad2009-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 Laurent5841db72009-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 Project89fa4ad2009-03-03 19:31:44 -0800138 if (status) {
139 *status = lStatus;
140 }
Eric Laurent5841db72009-09-09 05:16:08 -0700141 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800142 }
143
Eric Laurentfa2877b2009-07-28 08:44:33 -0700144 virtual uint32_t sampleRate(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800145 {
146 Parcel data, reply;
147 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700148 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800149 remote()->transact(SAMPLE_RATE, data, &reply);
150 return reply.readInt32();
151 }
152
Eric Laurentfa2877b2009-07-28 08:44:33 -0700153 virtual int channelCount(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800154 {
155 Parcel data, reply;
156 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700157 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800158 remote()->transact(CHANNEL_COUNT, data, &reply);
159 return reply.readInt32();
160 }
161
Eric Laurentfa2877b2009-07-28 08:44:33 -0700162 virtual int format(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800163 {
164 Parcel data, reply;
165 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700166 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800167 remote()->transact(FORMAT, data, &reply);
168 return reply.readInt32();
169 }
170
Eric Laurentfa2877b2009-07-28 08:44:33 -0700171 virtual size_t frameCount(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800172 {
173 Parcel data, reply;
174 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700175 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800176 remote()->transact(FRAME_COUNT, data, &reply);
177 return reply.readInt32();
178 }
179
Eric Laurentfa2877b2009-07-28 08:44:33 -0700180 virtual uint32_t latency(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800181 {
182 Parcel data, reply;
183 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700184 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-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 Laurentfa2877b2009-07-28 08:44:33 -0700223 virtual status_t setStreamVolume(int stream, float value, int output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800224 {
225 Parcel data, reply;
226 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
227 data.writeInt32(stream);
228 data.writeFloat(value);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700229 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-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 Laurentfa2877b2009-07-28 08:44:33 -0700244 virtual float streamVolume(int stream, int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800245 {
246 Parcel data, reply;
247 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
248 data.writeInt32(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700249 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-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 Project89fa4ad2009-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 Project89fa4ad2009-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
Eric Laurentb72a3962010-01-25 08:49:09 -0800289 virtual bool isStreamActive(int stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800290 {
291 Parcel data, reply;
292 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentb72a3962010-01-25 08:49:09 -0800293 data.writeInt32(stream);
294 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800295 return reply.readInt32();
296 }
297
Eric Laurentfa2877b2009-07-28 08:44:33 -0700298 virtual status_t setParameters(int ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800299 {
300 Parcel data, reply;
301 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700302 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700303 data.writeString8(keyValuePairs);
304 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800305 return reply.readInt32();
306 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700307
Eric Laurentfa2877b2009-07-28 08:44:33 -0700308 virtual String8 getParameters(int ioHandle, const String8& keys)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700309 {
310 Parcel data, reply;
311 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700312 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700313 data.writeString8(keys);
314 remote()->transact(GET_PARAMETERS, data, &reply);
315 return reply.readString8();
316 }
317
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800318 virtual void registerClient(const sp<IAudioFlingerClient>& client)
319 {
320 Parcel data, reply;
321 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
322 data.writeStrongBinder(client->asBinder());
323 remote()->transact(REGISTER_CLIENT, data, &reply);
324 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700325
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800326 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
327 {
328 Parcel data, reply;
329 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
330 data.writeInt32(sampleRate);
331 data.writeInt32(format);
332 data.writeInt32(channelCount);
333 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
334 return reply.readInt32();
335 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700336
Eric Laurentfa2877b2009-07-28 08:44:33 -0700337 virtual int openOutput(uint32_t *pDevices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700338 uint32_t *pSamplingRate,
339 uint32_t *pFormat,
340 uint32_t *pChannels,
341 uint32_t *pLatencyMs,
342 uint32_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800343 {
344 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700345 uint32_t devices = pDevices ? *pDevices : 0;
346 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
347 uint32_t format = pFormat ? *pFormat : 0;
348 uint32_t channels = pChannels ? *pChannels : 0;
349 uint32_t latency = pLatencyMs ? *pLatencyMs : 0;
350
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800351 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700352 data.writeInt32(devices);
353 data.writeInt32(samplingRate);
354 data.writeInt32(format);
355 data.writeInt32(channels);
356 data.writeInt32(latency);
357 data.writeInt32(flags);
358 remote()->transact(OPEN_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700359 int output = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700360 LOGV("openOutput() returned output, %p", output);
361 devices = reply.readInt32();
362 if (pDevices) *pDevices = devices;
363 samplingRate = reply.readInt32();
364 if (pSamplingRate) *pSamplingRate = samplingRate;
365 format = reply.readInt32();
366 if (pFormat) *pFormat = format;
367 channels = reply.readInt32();
368 if (pChannels) *pChannels = channels;
369 latency = reply.readInt32();
370 if (pLatencyMs) *pLatencyMs = latency;
371 return output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800372 }
373
Eric Laurentfa2877b2009-07-28 08:44:33 -0700374 virtual int openDuplicateOutput(int output1, int output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800375 {
376 Parcel data, reply;
377 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700378 data.writeInt32(output1);
379 data.writeInt32(output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700380 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700381 return reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700382 }
383
Eric Laurentfa2877b2009-07-28 08:44:33 -0700384 virtual status_t closeOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700385 {
386 Parcel data, reply;
387 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700388 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700389 remote()->transact(CLOSE_OUTPUT, data, &reply);
390 return reply.readInt32();
391 }
392
Eric Laurentfa2877b2009-07-28 08:44:33 -0700393 virtual status_t suspendOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700394 {
395 Parcel data, reply;
396 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700397 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700398 remote()->transact(SUSPEND_OUTPUT, data, &reply);
399 return reply.readInt32();
400 }
401
Eric Laurentfa2877b2009-07-28 08:44:33 -0700402 virtual status_t restoreOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700403 {
404 Parcel data, reply;
405 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700406 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700407 remote()->transact(RESTORE_OUTPUT, data, &reply);
408 return reply.readInt32();
409 }
410
Eric Laurentfa2877b2009-07-28 08:44:33 -0700411 virtual int openInput(uint32_t *pDevices,
412 uint32_t *pSamplingRate,
413 uint32_t *pFormat,
414 uint32_t *pChannels,
415 uint32_t acoustics)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700416 {
417 Parcel data, reply;
418 uint32_t devices = pDevices ? *pDevices : 0;
419 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
420 uint32_t format = pFormat ? *pFormat : 0;
421 uint32_t channels = pChannels ? *pChannels : 0;
422
423 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
424 data.writeInt32(devices);
425 data.writeInt32(samplingRate);
426 data.writeInt32(format);
427 data.writeInt32(channels);
428 data.writeInt32(acoustics);
429 remote()->transact(OPEN_INPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700430 int input = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700431 devices = reply.readInt32();
432 if (pDevices) *pDevices = devices;
433 samplingRate = reply.readInt32();
434 if (pSamplingRate) *pSamplingRate = samplingRate;
435 format = reply.readInt32();
436 if (pFormat) *pFormat = format;
437 channels = reply.readInt32();
438 if (pChannels) *pChannels = channels;
439 return input;
440 }
441
Eric Laurentfa2877b2009-07-28 08:44:33 -0700442 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700443 {
444 Parcel data, reply;
445 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700446 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700447 remote()->transact(CLOSE_INPUT, data, &reply);
448 return reply.readInt32();
449 }
450
Eric Laurentfa2877b2009-07-28 08:44:33 -0700451 virtual status_t setStreamOutput(uint32_t stream, int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700452 {
453 Parcel data, reply;
454 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
455 data.writeInt32(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700456 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700457 remote()->transact(SET_STREAM_OUTPUT, data, &reply);
458 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800459 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700460
461 virtual status_t setVoiceVolume(float volume)
462 {
463 Parcel data, reply;
464 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
465 data.writeFloat(volume);
466 remote()->transact(SET_VOICE_VOLUME, data, &reply);
467 return reply.readInt32();
468 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800469};
470
471IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
472
473// ----------------------------------------------------------------------
474
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800475status_t BnAudioFlinger::onTransact(
476 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
477{
478 switch(code) {
479 case CREATE_TRACK: {
480 CHECK_INTERFACE(IAudioFlinger, data, reply);
481 pid_t pid = data.readInt32();
482 int streamType = data.readInt32();
483 uint32_t sampleRate = data.readInt32();
484 int format = data.readInt32();
485 int channelCount = data.readInt32();
486 size_t bufferCount = data.readInt32();
487 uint32_t flags = data.readInt32();
488 sp<IMemory> buffer = interface_cast<IMemory>(data.readStrongBinder());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700489 int output = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800490 status_t status;
491 sp<IAudioTrack> track = createTrack(pid,
492 streamType, sampleRate, format,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700493 channelCount, bufferCount, flags, buffer, output, &status);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800494 reply->writeInt32(status);
495 reply->writeStrongBinder(track->asBinder());
496 return NO_ERROR;
497 } break;
498 case OPEN_RECORD: {
499 CHECK_INTERFACE(IAudioFlinger, data, reply);
500 pid_t pid = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700501 int input = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800502 uint32_t sampleRate = data.readInt32();
503 int format = data.readInt32();
504 int channelCount = data.readInt32();
505 size_t bufferCount = data.readInt32();
506 uint32_t flags = data.readInt32();
507 status_t status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700508 sp<IAudioRecord> record = openRecord(pid, input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800509 sampleRate, format, channelCount, bufferCount, flags, &status);
510 reply->writeInt32(status);
511 reply->writeStrongBinder(record->asBinder());
512 return NO_ERROR;
513 } break;
514 case SAMPLE_RATE: {
515 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700516 reply->writeInt32( sampleRate(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800517 return NO_ERROR;
518 } break;
519 case CHANNEL_COUNT: {
520 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700521 reply->writeInt32( channelCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800522 return NO_ERROR;
523 } break;
524 case FORMAT: {
525 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700526 reply->writeInt32( format(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800527 return NO_ERROR;
528 } break;
529 case FRAME_COUNT: {
530 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700531 reply->writeInt32( frameCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800532 return NO_ERROR;
533 } break;
534 case LATENCY: {
535 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700536 reply->writeInt32( latency(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800537 return NO_ERROR;
538 } break;
539 case SET_MASTER_VOLUME: {
540 CHECK_INTERFACE(IAudioFlinger, data, reply);
541 reply->writeInt32( setMasterVolume(data.readFloat()) );
542 return NO_ERROR;
543 } break;
544 case SET_MASTER_MUTE: {
545 CHECK_INTERFACE(IAudioFlinger, data, reply);
546 reply->writeInt32( setMasterMute(data.readInt32()) );
547 return NO_ERROR;
548 } break;
549 case MASTER_VOLUME: {
550 CHECK_INTERFACE(IAudioFlinger, data, reply);
551 reply->writeFloat( masterVolume() );
552 return NO_ERROR;
553 } break;
554 case MASTER_MUTE: {
555 CHECK_INTERFACE(IAudioFlinger, data, reply);
556 reply->writeInt32( masterMute() );
557 return NO_ERROR;
558 } break;
559 case SET_STREAM_VOLUME: {
560 CHECK_INTERFACE(IAudioFlinger, data, reply);
561 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700562 float volume = data.readFloat();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700563 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700564 reply->writeInt32( setStreamVolume(stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800565 return NO_ERROR;
566 } break;
567 case SET_STREAM_MUTE: {
568 CHECK_INTERFACE(IAudioFlinger, data, reply);
569 int stream = data.readInt32();
570 reply->writeInt32( setStreamMute(stream, data.readInt32()) );
571 return NO_ERROR;
572 } break;
573 case STREAM_VOLUME: {
574 CHECK_INTERFACE(IAudioFlinger, data, reply);
575 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700576 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700577 reply->writeFloat( streamVolume(stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800578 return NO_ERROR;
579 } break;
580 case STREAM_MUTE: {
581 CHECK_INTERFACE(IAudioFlinger, data, reply);
582 int stream = data.readInt32();
583 reply->writeInt32( streamMute(stream) );
584 return NO_ERROR;
585 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800586 case SET_MODE: {
587 CHECK_INTERFACE(IAudioFlinger, data, reply);
588 int mode = data.readInt32();
589 reply->writeInt32( setMode(mode) );
590 return NO_ERROR;
591 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800592 case SET_MIC_MUTE: {
593 CHECK_INTERFACE(IAudioFlinger, data, reply);
594 int state = data.readInt32();
595 reply->writeInt32( setMicMute(state) );
596 return NO_ERROR;
597 } break;
598 case GET_MIC_MUTE: {
599 CHECK_INTERFACE(IAudioFlinger, data, reply);
600 reply->writeInt32( getMicMute() );
601 return NO_ERROR;
602 } break;
Eric Laurentb72a3962010-01-25 08:49:09 -0800603 case IS_STREAM_ACTIVE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800604 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentb72a3962010-01-25 08:49:09 -0800605 int stream = data.readInt32();
606 reply->writeInt32( isStreamActive(stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800607 return NO_ERROR;
608 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700609 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800610 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700611 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700612 String8 keyValuePairs(data.readString8());
613 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800614 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700615 } break;
616 case GET_PARAMETERS: {
617 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700618 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700619 String8 keys(data.readString8());
620 reply->writeString8(getParameters(ioHandle, keys));
621 return NO_ERROR;
622 } break;
623
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800624 case REGISTER_CLIENT: {
625 CHECK_INTERFACE(IAudioFlinger, data, reply);
626 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(data.readStrongBinder());
627 registerClient(client);
628 return NO_ERROR;
629 } break;
630 case GET_INPUTBUFFERSIZE: {
631 CHECK_INTERFACE(IAudioFlinger, data, reply);
632 uint32_t sampleRate = data.readInt32();
633 int format = data.readInt32();
634 int channelCount = data.readInt32();
635 reply->writeInt32( getInputBufferSize(sampleRate, format, channelCount) );
636 return NO_ERROR;
637 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700638 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800639 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700640 uint32_t devices = data.readInt32();
641 uint32_t samplingRate = data.readInt32();
642 uint32_t format = data.readInt32();
643 uint32_t channels = data.readInt32();
644 uint32_t latency = data.readInt32();
645 uint32_t flags = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700646 int output = openOutput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700647 &samplingRate,
648 &format,
649 &channels,
650 &latency,
651 flags);
652 LOGV("OPEN_OUTPUT output, %p", output);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700653 reply->writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700654 reply->writeInt32(devices);
655 reply->writeInt32(samplingRate);
656 reply->writeInt32(format);
657 reply->writeInt32(channels);
658 reply->writeInt32(latency);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800659 return NO_ERROR;
660 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700661 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800662 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700663 int output1 = data.readInt32();
664 int output2 = data.readInt32();
665 reply->writeInt32(openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700666 return NO_ERROR;
667 } break;
668 case CLOSE_OUTPUT: {
669 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700670 reply->writeInt32(closeOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700671 return NO_ERROR;
672 } break;
673 case SUSPEND_OUTPUT: {
674 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700675 reply->writeInt32(suspendOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700676 return NO_ERROR;
677 } break;
678 case RESTORE_OUTPUT: {
679 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700680 reply->writeInt32(restoreOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700681 return NO_ERROR;
682 } break;
683 case OPEN_INPUT: {
684 CHECK_INTERFACE(IAudioFlinger, data, reply);
685 uint32_t devices = data.readInt32();
686 uint32_t samplingRate = data.readInt32();
687 uint32_t format = data.readInt32();
688 uint32_t channels = data.readInt32();
689 uint32_t acoutics = data.readInt32();
690
Eric Laurentfa2877b2009-07-28 08:44:33 -0700691 int input = openInput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700692 &samplingRate,
693 &format,
694 &channels,
695 acoutics);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700696 reply->writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700697 reply->writeInt32(devices);
698 reply->writeInt32(samplingRate);
699 reply->writeInt32(format);
700 reply->writeInt32(channels);
701 return NO_ERROR;
702 } break;
703 case CLOSE_INPUT: {
704 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700705 reply->writeInt32(closeInput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700706 return NO_ERROR;
707 } break;
708 case SET_STREAM_OUTPUT: {
709 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700710 uint32_t stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700711 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700712 reply->writeInt32(setStreamOutput(stream, output));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800713 return NO_ERROR;
714 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700715 case SET_VOICE_VOLUME: {
716 CHECK_INTERFACE(IAudioFlinger, data, reply);
717 float volume = data.readFloat();
718 reply->writeInt32( setVoiceVolume(volume) );
719 return NO_ERROR;
720 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800721 default:
722 return BBinder::onTransact(code, data, reply, flags);
723 }
724}
725
726// ----------------------------------------------------------------------------
727
728}; // namespace android