blob: 47bcc12422ea4835d4ed124ce0ed7fde768b6b8d [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/* //device/extlibs/pv/android/IAudioflinger.cpp
2**
3** Copyright 2007, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioFlinger"
Eric Laurentc2f1f072009-07-17 12:17:14 -070019//#define LOG_NDEBUG 0
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080020#include <utils/Log.h>
21
22#include <stdint.h>
23#include <sys/types.h>
24
Mathias Agopian75624082009-05-19 19:08:10 -070025#include <binder/Parcel.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080026
27#include <media/IAudioFlinger.h>
28
29namespace android {
30
31enum {
32 CREATE_TRACK = IBinder::FIRST_CALL_TRANSACTION,
33 OPEN_RECORD,
34 SAMPLE_RATE,
35 CHANNEL_COUNT,
36 FORMAT,
37 FRAME_COUNT,
38 LATENCY,
39 SET_MASTER_VOLUME,
40 SET_MASTER_MUTE,
41 MASTER_VOLUME,
42 MASTER_MUTE,
43 SET_STREAM_VOLUME,
44 SET_STREAM_MUTE,
45 STREAM_VOLUME,
46 STREAM_MUTE,
47 SET_MODE,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080048 SET_MIC_MUTE,
49 GET_MIC_MUTE,
Eric Laurentb72a3962010-01-25 08:49:09 -080050 IS_STREAM_ACTIVE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070051 SET_PARAMETERS,
52 GET_PARAMETERS,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080053 REGISTER_CLIENT,
54 GET_INPUTBUFFERSIZE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070055 OPEN_OUTPUT,
56 OPEN_DUPLICATE_OUTPUT,
57 CLOSE_OUTPUT,
58 SUSPEND_OUTPUT,
59 RESTORE_OUTPUT,
60 OPEN_INPUT,
61 CLOSE_INPUT,
Eric Laurentf0ee6f42009-10-21 08:14:22 -070062 SET_STREAM_OUTPUT,
Eric Laurent342e9cf2010-01-19 17:37:09 -080063 SET_VOICE_VOLUME,
Eric Laurent05bca2f2010-02-26 02:47:27 -080064 GET_RENDER_POSITION,
65 GET_INPUT_FRAMES_LOST
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080066};
67
68class BpAudioFlinger : public BpInterface<IAudioFlinger>
69{
70public:
71 BpAudioFlinger(const sp<IBinder>& impl)
72 : BpInterface<IAudioFlinger>(impl)
73 {
74 }
75
76 virtual sp<IAudioTrack> createTrack(
77 pid_t pid,
78 int streamType,
79 uint32_t sampleRate,
80 int format,
81 int channelCount,
82 int frameCount,
83 uint32_t flags,
84 const sp<IMemory>& sharedBuffer,
Eric Laurentfa2877b2009-07-28 08:44:33 -070085 int output,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080086 status_t *status)
87 {
88 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -070089 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080090 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
91 data.writeInt32(pid);
92 data.writeInt32(streamType);
93 data.writeInt32(sampleRate);
94 data.writeInt32(format);
95 data.writeInt32(channelCount);
96 data.writeInt32(frameCount);
97 data.writeInt32(flags);
98 data.writeStrongBinder(sharedBuffer->asBinder());
Eric Laurentfa2877b2009-07-28 08:44:33 -070099 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800100 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
101 if (lStatus != NO_ERROR) {
102 LOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700103 } else {
104 lStatus = reply.readInt32();
105 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800106 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800107 if (status) {
108 *status = lStatus;
109 }
Eric Laurent5841db72009-09-09 05:16:08 -0700110 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800111 }
112
113 virtual sp<IAudioRecord> openRecord(
114 pid_t pid,
Eric Laurentfa2877b2009-07-28 08:44:33 -0700115 int input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800116 uint32_t sampleRate,
117 int format,
118 int channelCount,
119 int frameCount,
120 uint32_t flags,
121 status_t *status)
122 {
123 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700124 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800125 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
126 data.writeInt32(pid);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700127 data.writeInt32(input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800128 data.writeInt32(sampleRate);
129 data.writeInt32(format);
130 data.writeInt32(channelCount);
131 data.writeInt32(frameCount);
132 data.writeInt32(flags);
Eric Laurent5841db72009-09-09 05:16:08 -0700133 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
134 if (lStatus != NO_ERROR) {
135 LOGE("openRecord error: %s", strerror(-lStatus));
136 } else {
137 lStatus = reply.readInt32();
138 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
139 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800140 if (status) {
141 *status = lStatus;
142 }
Eric Laurent5841db72009-09-09 05:16:08 -0700143 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800144 }
145
Eric Laurentfa2877b2009-07-28 08:44:33 -0700146 virtual uint32_t sampleRate(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800147 {
148 Parcel data, reply;
149 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700150 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800151 remote()->transact(SAMPLE_RATE, data, &reply);
152 return reply.readInt32();
153 }
154
Eric Laurentfa2877b2009-07-28 08:44:33 -0700155 virtual int channelCount(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800156 {
157 Parcel data, reply;
158 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700159 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800160 remote()->transact(CHANNEL_COUNT, data, &reply);
161 return reply.readInt32();
162 }
163
Eric Laurentfa2877b2009-07-28 08:44:33 -0700164 virtual int format(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800165 {
166 Parcel data, reply;
167 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700168 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800169 remote()->transact(FORMAT, data, &reply);
170 return reply.readInt32();
171 }
172
Eric Laurentfa2877b2009-07-28 08:44:33 -0700173 virtual size_t frameCount(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800174 {
175 Parcel data, reply;
176 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700177 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800178 remote()->transact(FRAME_COUNT, data, &reply);
179 return reply.readInt32();
180 }
181
Eric Laurentfa2877b2009-07-28 08:44:33 -0700182 virtual uint32_t latency(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800183 {
184 Parcel data, reply;
185 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700186 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800187 remote()->transact(LATENCY, data, &reply);
188 return reply.readInt32();
189 }
190
191 virtual status_t setMasterVolume(float value)
192 {
193 Parcel data, reply;
194 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
195 data.writeFloat(value);
196 remote()->transact(SET_MASTER_VOLUME, data, &reply);
197 return reply.readInt32();
198 }
199
200 virtual status_t setMasterMute(bool muted)
201 {
202 Parcel data, reply;
203 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
204 data.writeInt32(muted);
205 remote()->transact(SET_MASTER_MUTE, data, &reply);
206 return reply.readInt32();
207 }
208
209 virtual float masterVolume() const
210 {
211 Parcel data, reply;
212 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
213 remote()->transact(MASTER_VOLUME, data, &reply);
214 return reply.readFloat();
215 }
216
217 virtual bool masterMute() const
218 {
219 Parcel data, reply;
220 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
221 remote()->transact(MASTER_MUTE, data, &reply);
222 return reply.readInt32();
223 }
224
Eric Laurentfa2877b2009-07-28 08:44:33 -0700225 virtual status_t setStreamVolume(int stream, float value, int output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800226 {
227 Parcel data, reply;
228 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
229 data.writeInt32(stream);
230 data.writeFloat(value);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700231 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800232 remote()->transact(SET_STREAM_VOLUME, data, &reply);
233 return reply.readInt32();
234 }
235
236 virtual status_t setStreamMute(int stream, bool muted)
237 {
238 Parcel data, reply;
239 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
240 data.writeInt32(stream);
241 data.writeInt32(muted);
242 remote()->transact(SET_STREAM_MUTE, data, &reply);
243 return reply.readInt32();
244 }
245
Eric Laurentfa2877b2009-07-28 08:44:33 -0700246 virtual float streamVolume(int stream, int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800247 {
248 Parcel data, reply;
249 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
250 data.writeInt32(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700251 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800252 remote()->transact(STREAM_VOLUME, data, &reply);
253 return reply.readFloat();
254 }
255
256 virtual bool streamMute(int stream) const
257 {
258 Parcel data, reply;
259 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
260 data.writeInt32(stream);
261 remote()->transact(STREAM_MUTE, data, &reply);
262 return reply.readInt32();
263 }
264
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800265 virtual status_t setMode(int mode)
266 {
267 Parcel data, reply;
268 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
269 data.writeInt32(mode);
270 remote()->transact(SET_MODE, data, &reply);
271 return reply.readInt32();
272 }
273
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800274 virtual status_t setMicMute(bool state)
275 {
276 Parcel data, reply;
277 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
278 data.writeInt32(state);
279 remote()->transact(SET_MIC_MUTE, data, &reply);
280 return reply.readInt32();
281 }
282
283 virtual bool getMicMute() const
284 {
285 Parcel data, reply;
286 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
287 remote()->transact(GET_MIC_MUTE, data, &reply);
288 return reply.readInt32();
289 }
290
Eric Laurentb72a3962010-01-25 08:49:09 -0800291 virtual bool isStreamActive(int stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800292 {
293 Parcel data, reply;
294 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentb72a3962010-01-25 08:49:09 -0800295 data.writeInt32(stream);
296 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800297 return reply.readInt32();
298 }
299
Eric Laurentfa2877b2009-07-28 08:44:33 -0700300 virtual status_t setParameters(int ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800301 {
302 Parcel data, reply;
303 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700304 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700305 data.writeString8(keyValuePairs);
306 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800307 return reply.readInt32();
308 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700309
Eric Laurentfa2877b2009-07-28 08:44:33 -0700310 virtual String8 getParameters(int ioHandle, const String8& keys)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700311 {
312 Parcel data, reply;
313 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700314 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700315 data.writeString8(keys);
316 remote()->transact(GET_PARAMETERS, data, &reply);
317 return reply.readString8();
318 }
319
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800320 virtual void registerClient(const sp<IAudioFlingerClient>& client)
321 {
322 Parcel data, reply;
323 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
324 data.writeStrongBinder(client->asBinder());
325 remote()->transact(REGISTER_CLIENT, data, &reply);
326 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700327
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800328 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
329 {
330 Parcel data, reply;
331 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
332 data.writeInt32(sampleRate);
333 data.writeInt32(format);
334 data.writeInt32(channelCount);
335 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
336 return reply.readInt32();
337 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700338
Eric Laurentfa2877b2009-07-28 08:44:33 -0700339 virtual int openOutput(uint32_t *pDevices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700340 uint32_t *pSamplingRate,
341 uint32_t *pFormat,
342 uint32_t *pChannels,
343 uint32_t *pLatencyMs,
344 uint32_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800345 {
346 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700347 uint32_t devices = pDevices ? *pDevices : 0;
348 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
349 uint32_t format = pFormat ? *pFormat : 0;
350 uint32_t channels = pChannels ? *pChannels : 0;
351 uint32_t latency = pLatencyMs ? *pLatencyMs : 0;
352
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800353 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700354 data.writeInt32(devices);
355 data.writeInt32(samplingRate);
356 data.writeInt32(format);
357 data.writeInt32(channels);
358 data.writeInt32(latency);
359 data.writeInt32(flags);
360 remote()->transact(OPEN_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700361 int output = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700362 LOGV("openOutput() returned output, %p", output);
363 devices = reply.readInt32();
364 if (pDevices) *pDevices = devices;
365 samplingRate = reply.readInt32();
366 if (pSamplingRate) *pSamplingRate = samplingRate;
367 format = reply.readInt32();
368 if (pFormat) *pFormat = format;
369 channels = reply.readInt32();
370 if (pChannels) *pChannels = channels;
371 latency = reply.readInt32();
372 if (pLatencyMs) *pLatencyMs = latency;
373 return output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800374 }
375
Eric Laurentfa2877b2009-07-28 08:44:33 -0700376 virtual int openDuplicateOutput(int output1, int output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800377 {
378 Parcel data, reply;
379 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700380 data.writeInt32(output1);
381 data.writeInt32(output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700382 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700383 return reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700384 }
385
Eric Laurentfa2877b2009-07-28 08:44:33 -0700386 virtual status_t closeOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700387 {
388 Parcel data, reply;
389 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700390 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700391 remote()->transact(CLOSE_OUTPUT, data, &reply);
392 return reply.readInt32();
393 }
394
Eric Laurentfa2877b2009-07-28 08:44:33 -0700395 virtual status_t suspendOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700396 {
397 Parcel data, reply;
398 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700399 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700400 remote()->transact(SUSPEND_OUTPUT, data, &reply);
401 return reply.readInt32();
402 }
403
Eric Laurentfa2877b2009-07-28 08:44:33 -0700404 virtual status_t restoreOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700405 {
406 Parcel data, reply;
407 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700408 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700409 remote()->transact(RESTORE_OUTPUT, data, &reply);
410 return reply.readInt32();
411 }
412
Eric Laurentfa2877b2009-07-28 08:44:33 -0700413 virtual int openInput(uint32_t *pDevices,
414 uint32_t *pSamplingRate,
415 uint32_t *pFormat,
416 uint32_t *pChannels,
417 uint32_t acoustics)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700418 {
419 Parcel data, reply;
420 uint32_t devices = pDevices ? *pDevices : 0;
421 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
422 uint32_t format = pFormat ? *pFormat : 0;
423 uint32_t channels = pChannels ? *pChannels : 0;
424
425 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
426 data.writeInt32(devices);
427 data.writeInt32(samplingRate);
428 data.writeInt32(format);
429 data.writeInt32(channels);
430 data.writeInt32(acoustics);
431 remote()->transact(OPEN_INPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700432 int input = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700433 devices = reply.readInt32();
434 if (pDevices) *pDevices = devices;
435 samplingRate = reply.readInt32();
436 if (pSamplingRate) *pSamplingRate = samplingRate;
437 format = reply.readInt32();
438 if (pFormat) *pFormat = format;
439 channels = reply.readInt32();
440 if (pChannels) *pChannels = channels;
441 return input;
442 }
443
Eric Laurentfa2877b2009-07-28 08:44:33 -0700444 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700445 {
446 Parcel data, reply;
447 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700448 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700449 remote()->transact(CLOSE_INPUT, data, &reply);
450 return reply.readInt32();
451 }
452
Eric Laurentfa2877b2009-07-28 08:44:33 -0700453 virtual status_t setStreamOutput(uint32_t stream, int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700454 {
455 Parcel data, reply;
456 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
457 data.writeInt32(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700458 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700459 remote()->transact(SET_STREAM_OUTPUT, data, &reply);
460 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800461 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700462
463 virtual status_t setVoiceVolume(float volume)
464 {
465 Parcel data, reply;
466 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
467 data.writeFloat(volume);
468 remote()->transact(SET_VOICE_VOLUME, data, &reply);
469 return reply.readInt32();
470 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800471
472 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int output)
473 {
474 Parcel data, reply;
475 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
476 data.writeInt32(output);
477 remote()->transact(GET_RENDER_POSITION, data, &reply);
478 status_t status = reply.readInt32();
479 if (status == NO_ERROR) {
480 uint32_t tmp = reply.readInt32();
481 if (halFrames) {
482 *halFrames = tmp;
483 }
484 tmp = reply.readInt32();
485 if (dspFrames) {
486 *dspFrames = tmp;
487 }
488 }
489 return status;
490 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800491
492 virtual unsigned int getInputFramesLost(int ioHandle)
493 {
494 Parcel data, reply;
495 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
496 data.writeInt32(ioHandle);
497 remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
498 return reply.readInt32();
499 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800500};
501
502IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
503
504// ----------------------------------------------------------------------
505
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800506status_t BnAudioFlinger::onTransact(
507 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
508{
509 switch(code) {
510 case CREATE_TRACK: {
511 CHECK_INTERFACE(IAudioFlinger, data, reply);
512 pid_t pid = data.readInt32();
513 int streamType = data.readInt32();
514 uint32_t sampleRate = data.readInt32();
515 int format = data.readInt32();
516 int channelCount = data.readInt32();
517 size_t bufferCount = data.readInt32();
518 uint32_t flags = data.readInt32();
519 sp<IMemory> buffer = interface_cast<IMemory>(data.readStrongBinder());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700520 int output = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800521 status_t status;
522 sp<IAudioTrack> track = createTrack(pid,
523 streamType, sampleRate, format,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700524 channelCount, bufferCount, flags, buffer, output, &status);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800525 reply->writeInt32(status);
526 reply->writeStrongBinder(track->asBinder());
527 return NO_ERROR;
528 } break;
529 case OPEN_RECORD: {
530 CHECK_INTERFACE(IAudioFlinger, data, reply);
531 pid_t pid = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700532 int input = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800533 uint32_t sampleRate = data.readInt32();
534 int format = data.readInt32();
535 int channelCount = data.readInt32();
536 size_t bufferCount = data.readInt32();
537 uint32_t flags = data.readInt32();
538 status_t status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700539 sp<IAudioRecord> record = openRecord(pid, input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800540 sampleRate, format, channelCount, bufferCount, flags, &status);
541 reply->writeInt32(status);
542 reply->writeStrongBinder(record->asBinder());
543 return NO_ERROR;
544 } break;
545 case SAMPLE_RATE: {
546 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700547 reply->writeInt32( sampleRate(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800548 return NO_ERROR;
549 } break;
550 case CHANNEL_COUNT: {
551 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700552 reply->writeInt32( channelCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800553 return NO_ERROR;
554 } break;
555 case FORMAT: {
556 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700557 reply->writeInt32( format(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800558 return NO_ERROR;
559 } break;
560 case FRAME_COUNT: {
561 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700562 reply->writeInt32( frameCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800563 return NO_ERROR;
564 } break;
565 case LATENCY: {
566 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700567 reply->writeInt32( latency(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800568 return NO_ERROR;
569 } break;
570 case SET_MASTER_VOLUME: {
571 CHECK_INTERFACE(IAudioFlinger, data, reply);
572 reply->writeInt32( setMasterVolume(data.readFloat()) );
573 return NO_ERROR;
574 } break;
575 case SET_MASTER_MUTE: {
576 CHECK_INTERFACE(IAudioFlinger, data, reply);
577 reply->writeInt32( setMasterMute(data.readInt32()) );
578 return NO_ERROR;
579 } break;
580 case MASTER_VOLUME: {
581 CHECK_INTERFACE(IAudioFlinger, data, reply);
582 reply->writeFloat( masterVolume() );
583 return NO_ERROR;
584 } break;
585 case MASTER_MUTE: {
586 CHECK_INTERFACE(IAudioFlinger, data, reply);
587 reply->writeInt32( masterMute() );
588 return NO_ERROR;
589 } break;
590 case SET_STREAM_VOLUME: {
591 CHECK_INTERFACE(IAudioFlinger, data, reply);
592 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700593 float volume = data.readFloat();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700594 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700595 reply->writeInt32( setStreamVolume(stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800596 return NO_ERROR;
597 } break;
598 case SET_STREAM_MUTE: {
599 CHECK_INTERFACE(IAudioFlinger, data, reply);
600 int stream = data.readInt32();
601 reply->writeInt32( setStreamMute(stream, data.readInt32()) );
602 return NO_ERROR;
603 } break;
604 case STREAM_VOLUME: {
605 CHECK_INTERFACE(IAudioFlinger, data, reply);
606 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700607 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700608 reply->writeFloat( streamVolume(stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800609 return NO_ERROR;
610 } break;
611 case STREAM_MUTE: {
612 CHECK_INTERFACE(IAudioFlinger, data, reply);
613 int stream = data.readInt32();
614 reply->writeInt32( streamMute(stream) );
615 return NO_ERROR;
616 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800617 case SET_MODE: {
618 CHECK_INTERFACE(IAudioFlinger, data, reply);
619 int mode = data.readInt32();
620 reply->writeInt32( setMode(mode) );
621 return NO_ERROR;
622 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800623 case SET_MIC_MUTE: {
624 CHECK_INTERFACE(IAudioFlinger, data, reply);
625 int state = data.readInt32();
626 reply->writeInt32( setMicMute(state) );
627 return NO_ERROR;
628 } break;
629 case GET_MIC_MUTE: {
630 CHECK_INTERFACE(IAudioFlinger, data, reply);
631 reply->writeInt32( getMicMute() );
632 return NO_ERROR;
633 } break;
Eric Laurentb72a3962010-01-25 08:49:09 -0800634 case IS_STREAM_ACTIVE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800635 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentb72a3962010-01-25 08:49:09 -0800636 int stream = data.readInt32();
637 reply->writeInt32( isStreamActive(stream) );
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 SET_PARAMETERS: {
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 ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700643 String8 keyValuePairs(data.readString8());
644 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800645 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700646 } break;
647 case GET_PARAMETERS: {
648 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700649 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700650 String8 keys(data.readString8());
651 reply->writeString8(getParameters(ioHandle, keys));
652 return NO_ERROR;
653 } break;
654
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800655 case REGISTER_CLIENT: {
656 CHECK_INTERFACE(IAudioFlinger, data, reply);
657 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(data.readStrongBinder());
658 registerClient(client);
659 return NO_ERROR;
660 } break;
661 case GET_INPUTBUFFERSIZE: {
662 CHECK_INTERFACE(IAudioFlinger, data, reply);
663 uint32_t sampleRate = data.readInt32();
664 int format = data.readInt32();
665 int channelCount = data.readInt32();
666 reply->writeInt32( getInputBufferSize(sampleRate, format, channelCount) );
667 return NO_ERROR;
668 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700669 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800670 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700671 uint32_t devices = data.readInt32();
672 uint32_t samplingRate = data.readInt32();
673 uint32_t format = data.readInt32();
674 uint32_t channels = data.readInt32();
675 uint32_t latency = data.readInt32();
676 uint32_t flags = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700677 int output = openOutput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700678 &samplingRate,
679 &format,
680 &channels,
681 &latency,
682 flags);
683 LOGV("OPEN_OUTPUT output, %p", output);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700684 reply->writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700685 reply->writeInt32(devices);
686 reply->writeInt32(samplingRate);
687 reply->writeInt32(format);
688 reply->writeInt32(channels);
689 reply->writeInt32(latency);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800690 return NO_ERROR;
691 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700692 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800693 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700694 int output1 = data.readInt32();
695 int output2 = data.readInt32();
696 reply->writeInt32(openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700697 return NO_ERROR;
698 } break;
699 case CLOSE_OUTPUT: {
700 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700701 reply->writeInt32(closeOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700702 return NO_ERROR;
703 } break;
704 case SUSPEND_OUTPUT: {
705 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700706 reply->writeInt32(suspendOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700707 return NO_ERROR;
708 } break;
709 case RESTORE_OUTPUT: {
710 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700711 reply->writeInt32(restoreOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700712 return NO_ERROR;
713 } break;
714 case OPEN_INPUT: {
715 CHECK_INTERFACE(IAudioFlinger, data, reply);
716 uint32_t devices = data.readInt32();
717 uint32_t samplingRate = data.readInt32();
718 uint32_t format = data.readInt32();
719 uint32_t channels = data.readInt32();
720 uint32_t acoutics = data.readInt32();
721
Eric Laurentfa2877b2009-07-28 08:44:33 -0700722 int input = openInput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700723 &samplingRate,
724 &format,
725 &channels,
726 acoutics);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700727 reply->writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700728 reply->writeInt32(devices);
729 reply->writeInt32(samplingRate);
730 reply->writeInt32(format);
731 reply->writeInt32(channels);
732 return NO_ERROR;
733 } break;
734 case CLOSE_INPUT: {
735 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700736 reply->writeInt32(closeInput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700737 return NO_ERROR;
738 } break;
739 case SET_STREAM_OUTPUT: {
740 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700741 uint32_t stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700742 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700743 reply->writeInt32(setStreamOutput(stream, output));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800744 return NO_ERROR;
745 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700746 case SET_VOICE_VOLUME: {
747 CHECK_INTERFACE(IAudioFlinger, data, reply);
748 float volume = data.readFloat();
749 reply->writeInt32( setVoiceVolume(volume) );
750 return NO_ERROR;
751 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -0800752 case GET_RENDER_POSITION: {
753 CHECK_INTERFACE(IAudioFlinger, data, reply);
754 int output = data.readInt32();
755 uint32_t halFrames;
756 uint32_t dspFrames;
757 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
758 reply->writeInt32(status);
759 if (status == NO_ERROR) {
760 reply->writeInt32(halFrames);
761 reply->writeInt32(dspFrames);
762 }
763 return NO_ERROR;
764 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800765 case GET_INPUT_FRAMES_LOST: {
766 CHECK_INTERFACE(IAudioFlinger, data, reply);
767 int ioHandle = data.readInt32();
768 reply->writeInt32(getInputFramesLost(ioHandle));
769 return NO_ERROR;
770 } break;
771
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800772 default:
773 return BBinder::onTransact(code, data, reply, flags);
774 }
775}
776
777// ----------------------------------------------------------------------------
778
779}; // namespace android