blob: ca3a2a600f8ff0cb625f438c706041d59898ffc3 [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,
64 GET_RENDER_POSITION
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080065};
66
67class BpAudioFlinger : public BpInterface<IAudioFlinger>
68{
69public:
70 BpAudioFlinger(const sp<IBinder>& impl)
71 : BpInterface<IAudioFlinger>(impl)
72 {
73 }
74
75 virtual sp<IAudioTrack> createTrack(
76 pid_t pid,
77 int streamType,
78 uint32_t sampleRate,
79 int format,
80 int channelCount,
81 int frameCount,
82 uint32_t flags,
83 const sp<IMemory>& sharedBuffer,
Eric Laurentfa2877b2009-07-28 08:44:33 -070084 int output,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080085 status_t *status)
86 {
87 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -070088 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080089 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
90 data.writeInt32(pid);
91 data.writeInt32(streamType);
92 data.writeInt32(sampleRate);
93 data.writeInt32(format);
94 data.writeInt32(channelCount);
95 data.writeInt32(frameCount);
96 data.writeInt32(flags);
97 data.writeStrongBinder(sharedBuffer->asBinder());
Eric Laurentfa2877b2009-07-28 08:44:33 -070098 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080099 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
100 if (lStatus != NO_ERROR) {
101 LOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700102 } else {
103 lStatus = reply.readInt32();
104 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800105 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800106 if (status) {
107 *status = lStatus;
108 }
Eric Laurent5841db72009-09-09 05:16:08 -0700109 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800110 }
111
112 virtual sp<IAudioRecord> openRecord(
113 pid_t pid,
Eric Laurentfa2877b2009-07-28 08:44:33 -0700114 int input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800115 uint32_t sampleRate,
116 int format,
117 int channelCount,
118 int frameCount,
119 uint32_t flags,
120 status_t *status)
121 {
122 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700123 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800124 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
125 data.writeInt32(pid);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700126 data.writeInt32(input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800127 data.writeInt32(sampleRate);
128 data.writeInt32(format);
129 data.writeInt32(channelCount);
130 data.writeInt32(frameCount);
131 data.writeInt32(flags);
Eric Laurent5841db72009-09-09 05:16:08 -0700132 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
133 if (lStatus != NO_ERROR) {
134 LOGE("openRecord error: %s", strerror(-lStatus));
135 } else {
136 lStatus = reply.readInt32();
137 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
138 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800139 if (status) {
140 *status = lStatus;
141 }
Eric Laurent5841db72009-09-09 05:16:08 -0700142 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800143 }
144
Eric Laurentfa2877b2009-07-28 08:44:33 -0700145 virtual uint32_t sampleRate(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800146 {
147 Parcel data, reply;
148 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700149 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800150 remote()->transact(SAMPLE_RATE, data, &reply);
151 return reply.readInt32();
152 }
153
Eric Laurentfa2877b2009-07-28 08:44:33 -0700154 virtual int channelCount(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800155 {
156 Parcel data, reply;
157 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700158 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800159 remote()->transact(CHANNEL_COUNT, data, &reply);
160 return reply.readInt32();
161 }
162
Eric Laurentfa2877b2009-07-28 08:44:33 -0700163 virtual int format(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800164 {
165 Parcel data, reply;
166 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700167 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800168 remote()->transact(FORMAT, data, &reply);
169 return reply.readInt32();
170 }
171
Eric Laurentfa2877b2009-07-28 08:44:33 -0700172 virtual size_t frameCount(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800173 {
174 Parcel data, reply;
175 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700176 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800177 remote()->transact(FRAME_COUNT, data, &reply);
178 return reply.readInt32();
179 }
180
Eric Laurentfa2877b2009-07-28 08:44:33 -0700181 virtual uint32_t latency(int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800182 {
183 Parcel data, reply;
184 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700185 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800186 remote()->transact(LATENCY, data, &reply);
187 return reply.readInt32();
188 }
189
190 virtual status_t setMasterVolume(float value)
191 {
192 Parcel data, reply;
193 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
194 data.writeFloat(value);
195 remote()->transact(SET_MASTER_VOLUME, data, &reply);
196 return reply.readInt32();
197 }
198
199 virtual status_t setMasterMute(bool muted)
200 {
201 Parcel data, reply;
202 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
203 data.writeInt32(muted);
204 remote()->transact(SET_MASTER_MUTE, data, &reply);
205 return reply.readInt32();
206 }
207
208 virtual float masterVolume() const
209 {
210 Parcel data, reply;
211 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
212 remote()->transact(MASTER_VOLUME, data, &reply);
213 return reply.readFloat();
214 }
215
216 virtual bool masterMute() const
217 {
218 Parcel data, reply;
219 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
220 remote()->transact(MASTER_MUTE, data, &reply);
221 return reply.readInt32();
222 }
223
Eric Laurentfa2877b2009-07-28 08:44:33 -0700224 virtual status_t setStreamVolume(int stream, float value, int output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800225 {
226 Parcel data, reply;
227 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
228 data.writeInt32(stream);
229 data.writeFloat(value);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700230 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800231 remote()->transact(SET_STREAM_VOLUME, data, &reply);
232 return reply.readInt32();
233 }
234
235 virtual status_t setStreamMute(int stream, bool muted)
236 {
237 Parcel data, reply;
238 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
239 data.writeInt32(stream);
240 data.writeInt32(muted);
241 remote()->transact(SET_STREAM_MUTE, data, &reply);
242 return reply.readInt32();
243 }
244
Eric Laurentfa2877b2009-07-28 08:44:33 -0700245 virtual float streamVolume(int stream, int output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800246 {
247 Parcel data, reply;
248 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
249 data.writeInt32(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700250 data.writeInt32(output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800251 remote()->transact(STREAM_VOLUME, data, &reply);
252 return reply.readFloat();
253 }
254
255 virtual bool streamMute(int stream) const
256 {
257 Parcel data, reply;
258 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
259 data.writeInt32(stream);
260 remote()->transact(STREAM_MUTE, data, &reply);
261 return reply.readInt32();
262 }
263
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800264 virtual status_t setMode(int mode)
265 {
266 Parcel data, reply;
267 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
268 data.writeInt32(mode);
269 remote()->transact(SET_MODE, data, &reply);
270 return reply.readInt32();
271 }
272
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800273 virtual status_t setMicMute(bool state)
274 {
275 Parcel data, reply;
276 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
277 data.writeInt32(state);
278 remote()->transact(SET_MIC_MUTE, data, &reply);
279 return reply.readInt32();
280 }
281
282 virtual bool getMicMute() const
283 {
284 Parcel data, reply;
285 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
286 remote()->transact(GET_MIC_MUTE, data, &reply);
287 return reply.readInt32();
288 }
289
Eric Laurentb72a3962010-01-25 08:49:09 -0800290 virtual bool isStreamActive(int stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800291 {
292 Parcel data, reply;
293 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentb72a3962010-01-25 08:49:09 -0800294 data.writeInt32(stream);
295 remote()->transact(IS_STREAM_ACTIVE, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800296 return reply.readInt32();
297 }
298
Eric Laurentfa2877b2009-07-28 08:44:33 -0700299 virtual status_t setParameters(int ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800300 {
301 Parcel data, reply;
302 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700303 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700304 data.writeString8(keyValuePairs);
305 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800306 return reply.readInt32();
307 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700308
Eric Laurentfa2877b2009-07-28 08:44:33 -0700309 virtual String8 getParameters(int ioHandle, const String8& keys)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700310 {
311 Parcel data, reply;
312 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700313 data.writeInt32(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700314 data.writeString8(keys);
315 remote()->transact(GET_PARAMETERS, data, &reply);
316 return reply.readString8();
317 }
318
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800319 virtual void registerClient(const sp<IAudioFlingerClient>& client)
320 {
321 Parcel data, reply;
322 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
323 data.writeStrongBinder(client->asBinder());
324 remote()->transact(REGISTER_CLIENT, data, &reply);
325 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700326
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800327 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
328 {
329 Parcel data, reply;
330 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
331 data.writeInt32(sampleRate);
332 data.writeInt32(format);
333 data.writeInt32(channelCount);
334 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
335 return reply.readInt32();
336 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700337
Eric Laurentfa2877b2009-07-28 08:44:33 -0700338 virtual int openOutput(uint32_t *pDevices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700339 uint32_t *pSamplingRate,
340 uint32_t *pFormat,
341 uint32_t *pChannels,
342 uint32_t *pLatencyMs,
343 uint32_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800344 {
345 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700346 uint32_t devices = pDevices ? *pDevices : 0;
347 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
348 uint32_t format = pFormat ? *pFormat : 0;
349 uint32_t channels = pChannels ? *pChannels : 0;
350 uint32_t latency = pLatencyMs ? *pLatencyMs : 0;
351
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800352 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentc2f1f072009-07-17 12:17:14 -0700353 data.writeInt32(devices);
354 data.writeInt32(samplingRate);
355 data.writeInt32(format);
356 data.writeInt32(channels);
357 data.writeInt32(latency);
358 data.writeInt32(flags);
359 remote()->transact(OPEN_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700360 int output = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700361 LOGV("openOutput() returned output, %p", output);
362 devices = reply.readInt32();
363 if (pDevices) *pDevices = devices;
364 samplingRate = reply.readInt32();
365 if (pSamplingRate) *pSamplingRate = samplingRate;
366 format = reply.readInt32();
367 if (pFormat) *pFormat = format;
368 channels = reply.readInt32();
369 if (pChannels) *pChannels = channels;
370 latency = reply.readInt32();
371 if (pLatencyMs) *pLatencyMs = latency;
372 return output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800373 }
374
Eric Laurentfa2877b2009-07-28 08:44:33 -0700375 virtual int openDuplicateOutput(int output1, int output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800376 {
377 Parcel data, reply;
378 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700379 data.writeInt32(output1);
380 data.writeInt32(output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700381 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700382 return reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700383 }
384
Eric Laurentfa2877b2009-07-28 08:44:33 -0700385 virtual status_t closeOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700386 {
387 Parcel data, reply;
388 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700389 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700390 remote()->transact(CLOSE_OUTPUT, data, &reply);
391 return reply.readInt32();
392 }
393
Eric Laurentfa2877b2009-07-28 08:44:33 -0700394 virtual status_t suspendOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700395 {
396 Parcel data, reply;
397 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700398 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700399 remote()->transact(SUSPEND_OUTPUT, data, &reply);
400 return reply.readInt32();
401 }
402
Eric Laurentfa2877b2009-07-28 08:44:33 -0700403 virtual status_t restoreOutput(int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700404 {
405 Parcel data, reply;
406 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700407 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700408 remote()->transact(RESTORE_OUTPUT, data, &reply);
409 return reply.readInt32();
410 }
411
Eric Laurentfa2877b2009-07-28 08:44:33 -0700412 virtual int openInput(uint32_t *pDevices,
413 uint32_t *pSamplingRate,
414 uint32_t *pFormat,
415 uint32_t *pChannels,
416 uint32_t acoustics)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700417 {
418 Parcel data, reply;
419 uint32_t devices = pDevices ? *pDevices : 0;
420 uint32_t samplingRate = pSamplingRate ? *pSamplingRate : 0;
421 uint32_t format = pFormat ? *pFormat : 0;
422 uint32_t channels = pChannels ? *pChannels : 0;
423
424 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
425 data.writeInt32(devices);
426 data.writeInt32(samplingRate);
427 data.writeInt32(format);
428 data.writeInt32(channels);
429 data.writeInt32(acoustics);
430 remote()->transact(OPEN_INPUT, data, &reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700431 int input = reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700432 devices = reply.readInt32();
433 if (pDevices) *pDevices = devices;
434 samplingRate = reply.readInt32();
435 if (pSamplingRate) *pSamplingRate = samplingRate;
436 format = reply.readInt32();
437 if (pFormat) *pFormat = format;
438 channels = reply.readInt32();
439 if (pChannels) *pChannels = channels;
440 return input;
441 }
442
Eric Laurentfa2877b2009-07-28 08:44:33 -0700443 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700444 {
445 Parcel data, reply;
446 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700447 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700448 remote()->transact(CLOSE_INPUT, data, &reply);
449 return reply.readInt32();
450 }
451
Eric Laurentfa2877b2009-07-28 08:44:33 -0700452 virtual status_t setStreamOutput(uint32_t stream, int output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700453 {
454 Parcel data, reply;
455 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
456 data.writeInt32(stream);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700457 data.writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700458 remote()->transact(SET_STREAM_OUTPUT, data, &reply);
459 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800460 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700461
462 virtual status_t setVoiceVolume(float volume)
463 {
464 Parcel data, reply;
465 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
466 data.writeFloat(volume);
467 remote()->transact(SET_VOICE_VOLUME, data, &reply);
468 return reply.readInt32();
469 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800470
471 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int output)
472 {
473 Parcel data, reply;
474 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
475 data.writeInt32(output);
476 remote()->transact(GET_RENDER_POSITION, data, &reply);
477 status_t status = reply.readInt32();
478 if (status == NO_ERROR) {
479 uint32_t tmp = reply.readInt32();
480 if (halFrames) {
481 *halFrames = tmp;
482 }
483 tmp = reply.readInt32();
484 if (dspFrames) {
485 *dspFrames = tmp;
486 }
487 }
488 return status;
489 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800490};
491
492IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
493
494// ----------------------------------------------------------------------
495
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800496status_t BnAudioFlinger::onTransact(
497 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
498{
499 switch(code) {
500 case CREATE_TRACK: {
501 CHECK_INTERFACE(IAudioFlinger, data, reply);
502 pid_t pid = data.readInt32();
503 int streamType = data.readInt32();
504 uint32_t sampleRate = data.readInt32();
505 int format = data.readInt32();
506 int channelCount = data.readInt32();
507 size_t bufferCount = data.readInt32();
508 uint32_t flags = data.readInt32();
509 sp<IMemory> buffer = interface_cast<IMemory>(data.readStrongBinder());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700510 int output = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800511 status_t status;
512 sp<IAudioTrack> track = createTrack(pid,
513 streamType, sampleRate, format,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700514 channelCount, bufferCount, flags, buffer, output, &status);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800515 reply->writeInt32(status);
516 reply->writeStrongBinder(track->asBinder());
517 return NO_ERROR;
518 } break;
519 case OPEN_RECORD: {
520 CHECK_INTERFACE(IAudioFlinger, data, reply);
521 pid_t pid = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700522 int input = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800523 uint32_t sampleRate = data.readInt32();
524 int format = data.readInt32();
525 int channelCount = data.readInt32();
526 size_t bufferCount = data.readInt32();
527 uint32_t flags = data.readInt32();
528 status_t status;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700529 sp<IAudioRecord> record = openRecord(pid, input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800530 sampleRate, format, channelCount, bufferCount, flags, &status);
531 reply->writeInt32(status);
532 reply->writeStrongBinder(record->asBinder());
533 return NO_ERROR;
534 } break;
535 case SAMPLE_RATE: {
536 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700537 reply->writeInt32( sampleRate(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800538 return NO_ERROR;
539 } break;
540 case CHANNEL_COUNT: {
541 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700542 reply->writeInt32( channelCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800543 return NO_ERROR;
544 } break;
545 case FORMAT: {
546 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700547 reply->writeInt32( format(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800548 return NO_ERROR;
549 } break;
550 case FRAME_COUNT: {
551 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700552 reply->writeInt32( frameCount(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800553 return NO_ERROR;
554 } break;
555 case LATENCY: {
556 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700557 reply->writeInt32( latency(data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800558 return NO_ERROR;
559 } break;
560 case SET_MASTER_VOLUME: {
561 CHECK_INTERFACE(IAudioFlinger, data, reply);
562 reply->writeInt32( setMasterVolume(data.readFloat()) );
563 return NO_ERROR;
564 } break;
565 case SET_MASTER_MUTE: {
566 CHECK_INTERFACE(IAudioFlinger, data, reply);
567 reply->writeInt32( setMasterMute(data.readInt32()) );
568 return NO_ERROR;
569 } break;
570 case MASTER_VOLUME: {
571 CHECK_INTERFACE(IAudioFlinger, data, reply);
572 reply->writeFloat( masterVolume() );
573 return NO_ERROR;
574 } break;
575 case MASTER_MUTE: {
576 CHECK_INTERFACE(IAudioFlinger, data, reply);
577 reply->writeInt32( masterMute() );
578 return NO_ERROR;
579 } break;
580 case SET_STREAM_VOLUME: {
581 CHECK_INTERFACE(IAudioFlinger, data, reply);
582 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700583 float volume = data.readFloat();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700584 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700585 reply->writeInt32( setStreamVolume(stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800586 return NO_ERROR;
587 } break;
588 case SET_STREAM_MUTE: {
589 CHECK_INTERFACE(IAudioFlinger, data, reply);
590 int stream = data.readInt32();
591 reply->writeInt32( setStreamMute(stream, data.readInt32()) );
592 return NO_ERROR;
593 } break;
594 case STREAM_VOLUME: {
595 CHECK_INTERFACE(IAudioFlinger, data, reply);
596 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700597 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700598 reply->writeFloat( streamVolume(stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800599 return NO_ERROR;
600 } break;
601 case STREAM_MUTE: {
602 CHECK_INTERFACE(IAudioFlinger, data, reply);
603 int stream = data.readInt32();
604 reply->writeInt32( streamMute(stream) );
605 return NO_ERROR;
606 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800607 case SET_MODE: {
608 CHECK_INTERFACE(IAudioFlinger, data, reply);
609 int mode = data.readInt32();
610 reply->writeInt32( setMode(mode) );
611 return NO_ERROR;
612 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800613 case SET_MIC_MUTE: {
614 CHECK_INTERFACE(IAudioFlinger, data, reply);
615 int state = data.readInt32();
616 reply->writeInt32( setMicMute(state) );
617 return NO_ERROR;
618 } break;
619 case GET_MIC_MUTE: {
620 CHECK_INTERFACE(IAudioFlinger, data, reply);
621 reply->writeInt32( getMicMute() );
622 return NO_ERROR;
623 } break;
Eric Laurentb72a3962010-01-25 08:49:09 -0800624 case IS_STREAM_ACTIVE: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800625 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentb72a3962010-01-25 08:49:09 -0800626 int stream = data.readInt32();
627 reply->writeInt32( isStreamActive(stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800628 return NO_ERROR;
629 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700630 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800631 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700632 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700633 String8 keyValuePairs(data.readString8());
634 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800635 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700636 } break;
637 case GET_PARAMETERS: {
638 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700639 int ioHandle = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700640 String8 keys(data.readString8());
641 reply->writeString8(getParameters(ioHandle, keys));
642 return NO_ERROR;
643 } break;
644
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800645 case REGISTER_CLIENT: {
646 CHECK_INTERFACE(IAudioFlinger, data, reply);
647 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(data.readStrongBinder());
648 registerClient(client);
649 return NO_ERROR;
650 } break;
651 case GET_INPUTBUFFERSIZE: {
652 CHECK_INTERFACE(IAudioFlinger, data, reply);
653 uint32_t sampleRate = data.readInt32();
654 int format = data.readInt32();
655 int channelCount = data.readInt32();
656 reply->writeInt32( getInputBufferSize(sampleRate, format, channelCount) );
657 return NO_ERROR;
658 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700659 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800660 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700661 uint32_t devices = data.readInt32();
662 uint32_t samplingRate = data.readInt32();
663 uint32_t format = data.readInt32();
664 uint32_t channels = data.readInt32();
665 uint32_t latency = data.readInt32();
666 uint32_t flags = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700667 int output = openOutput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700668 &samplingRate,
669 &format,
670 &channels,
671 &latency,
672 flags);
673 LOGV("OPEN_OUTPUT output, %p", output);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700674 reply->writeInt32(output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700675 reply->writeInt32(devices);
676 reply->writeInt32(samplingRate);
677 reply->writeInt32(format);
678 reply->writeInt32(channels);
679 reply->writeInt32(latency);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800680 return NO_ERROR;
681 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700682 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800683 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700684 int output1 = data.readInt32();
685 int output2 = data.readInt32();
686 reply->writeInt32(openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700687 return NO_ERROR;
688 } break;
689 case CLOSE_OUTPUT: {
690 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700691 reply->writeInt32(closeOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700692 return NO_ERROR;
693 } break;
694 case SUSPEND_OUTPUT: {
695 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700696 reply->writeInt32(suspendOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700697 return NO_ERROR;
698 } break;
699 case RESTORE_OUTPUT: {
700 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700701 reply->writeInt32(restoreOutput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700702 return NO_ERROR;
703 } break;
704 case OPEN_INPUT: {
705 CHECK_INTERFACE(IAudioFlinger, data, reply);
706 uint32_t devices = data.readInt32();
707 uint32_t samplingRate = data.readInt32();
708 uint32_t format = data.readInt32();
709 uint32_t channels = data.readInt32();
710 uint32_t acoutics = data.readInt32();
711
Eric Laurentfa2877b2009-07-28 08:44:33 -0700712 int input = openInput(&devices,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700713 &samplingRate,
714 &format,
715 &channels,
716 acoutics);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700717 reply->writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700718 reply->writeInt32(devices);
719 reply->writeInt32(samplingRate);
720 reply->writeInt32(format);
721 reply->writeInt32(channels);
722 return NO_ERROR;
723 } break;
724 case CLOSE_INPUT: {
725 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentfa2877b2009-07-28 08:44:33 -0700726 reply->writeInt32(closeInput(data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -0700727 return NO_ERROR;
728 } break;
729 case SET_STREAM_OUTPUT: {
730 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700731 uint32_t stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700732 int output = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700733 reply->writeInt32(setStreamOutput(stream, output));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800734 return NO_ERROR;
735 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700736 case SET_VOICE_VOLUME: {
737 CHECK_INTERFACE(IAudioFlinger, data, reply);
738 float volume = data.readFloat();
739 reply->writeInt32( setVoiceVolume(volume) );
740 return NO_ERROR;
741 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -0800742 case GET_RENDER_POSITION: {
743 CHECK_INTERFACE(IAudioFlinger, data, reply);
744 int output = data.readInt32();
745 uint32_t halFrames;
746 uint32_t dspFrames;
747 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
748 reply->writeInt32(status);
749 if (status == NO_ERROR) {
750 reply->writeInt32(halFrames);
751 reply->writeInt32(dspFrames);
752 }
753 return NO_ERROR;
754 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800755 default:
756 return BBinder::onTransact(code, data, reply, flags);
757 }
758}
759
760// ----------------------------------------------------------------------------
761
762}; // namespace android