blob: 6f038eae3a1f50b2a706f58362fb1b1fc478aaff [file] [log] [blame]
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001/*
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08002**
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,
Glenn Kasten5876f2f2012-11-30 10:52:16 -080035 RESERVED, // obsolete, was CHANNEL_COUNT
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080036 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 Laurentc2f1f072009-07-17 12:17:14 -070050 SET_PARAMETERS,
51 GET_PARAMETERS,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080052 REGISTER_CLIENT,
53 GET_INPUTBUFFERSIZE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070054 OPEN_OUTPUT,
55 OPEN_DUPLICATE_OUTPUT,
56 CLOSE_OUTPUT,
57 SUSPEND_OUTPUT,
58 RESTORE_OUTPUT,
59 OPEN_INPUT,
60 CLOSE_INPUT,
Glenn Kastend2304db2014-02-03 07:40:31 -080061 INVALIDATE_STREAM,
Eric Laurent342e9cf2010-01-19 17:37:09 -080062 SET_VOICE_VOLUME,
Eric Laurent05bca2f2010-02-26 02:47:27 -080063 GET_RENDER_POSITION,
Eric Laurentbe916aa2010-06-01 23:49:17 -070064 GET_INPUT_FRAMES_LOST,
65 NEW_AUDIO_SESSION_ID,
Marco Nelissen3a34bef2011-08-02 13:33:41 -070066 ACQUIRE_AUDIO_SESSION_ID,
67 RELEASE_AUDIO_SESSION_ID,
Eric Laurentbe916aa2010-06-01 23:49:17 -070068 QUERY_NUM_EFFECTS,
Eric Laurentffe9c252010-06-23 17:38:20 -070069 QUERY_EFFECT,
Eric Laurentbe916aa2010-06-01 23:49:17 -070070 GET_EFFECT_DESCRIPTOR,
Eric Laurentde070132010-07-13 04:45:46 -070071 CREATE_EFFECT,
Eric Laurenta4c5a552012-03-29 10:12:40 -070072 MOVE_EFFECTS,
Glenn Kastencc0f1cf2012-09-24 11:27:18 -070073 LOAD_HW_MODULE,
74 GET_PRIMARY_OUTPUT_SAMPLING_RATE,
75 GET_PRIMARY_OUTPUT_FRAME_COUNT,
Glenn Kasten4182c4e2013-07-15 14:45:07 -070076 SET_LOW_RAM_DEVICE,
Eric Laurent4b123402014-04-11 09:22:20 -070077 LIST_AUDIO_PORTS,
78 GET_AUDIO_PORT,
79 CREATE_AUDIO_PATCH,
80 RELEASE_AUDIO_PATCH,
81 LIST_AUDIO_PATCHES,
Eric Laurent93c3d412014-08-01 14:48:35 -070082 SET_AUDIO_PORT_CONFIG,
83 GET_AUDIO_HW_SYNC
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080084};
85
86class BpAudioFlinger : public BpInterface<IAudioFlinger>
87{
88public:
89 BpAudioFlinger(const sp<IBinder>& impl)
90 : BpInterface<IAudioFlinger>(impl)
91 {
92 }
93
94 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080095 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080096 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080097 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -070098 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -080099 size_t *pFrameCount,
Glenn Kastene0b07172012-11-06 15:03:34 -0800100 track_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800101 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800102 audio_io_handle_t output,
Glenn Kasten3acbd052012-02-28 10:39:56 -0800103 pid_t tid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700104 int *sessionId,
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800105 int clientUid,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800106 status_t *status)
107 {
108 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700109 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800110 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800111 data.writeInt32((int32_t) streamType);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800112 data.writeInt32(sampleRate);
113 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700114 data.writeInt32(channelMask);
Glenn Kasten74935e42013-12-19 08:56:45 -0800115 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800116 data.writeInt64(frameCount);
Glenn Kastenb26e3e92012-11-14 08:32:08 -0800117 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
Glenn Kastene0b07172012-11-06 15:03:34 -0800118 data.writeInt32(lFlags);
Glenn Kasten2301acc2014-01-17 10:21:00 -0800119 // haveSharedBuffer
Eric Laurent3d00aa62013-09-24 09:53:27 -0700120 if (sharedBuffer != 0) {
121 data.writeInt32(true);
Marco Nelissen06b46062014-11-14 07:58:25 -0800122 data.writeStrongBinder(IInterface::asBinder(sharedBuffer));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700123 } else {
124 data.writeInt32(false);
125 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800126 data.writeInt32((int32_t) output);
Glenn Kasten3acbd052012-02-28 10:39:56 -0800127 data.writeInt32((int32_t) tid);
Glenn Kastenaea7ea02013-06-26 09:25:47 -0700128 int lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700129 if (sessionId != NULL) {
130 lSessionId = *sessionId;
131 }
132 data.writeInt32(lSessionId);
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800133 data.writeInt32(clientUid);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800134 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
135 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000136 ALOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700137 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700138 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800139 if (pFrameCount != NULL) {
140 *pFrameCount = frameCount;
141 }
Glenn Kastene0b07172012-11-06 15:03:34 -0800142 lFlags = reply.readInt32();
143 if (flags != NULL) {
144 *flags = lFlags;
145 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700146 lSessionId = reply.readInt32();
147 if (sessionId != NULL) {
148 *sessionId = lSessionId;
149 }
Eric Laurent5841db72009-09-09 05:16:08 -0700150 lStatus = reply.readInt32();
151 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
Glenn Kasten0cde0762014-01-16 15:06:36 -0800152 if (lStatus == NO_ERROR) {
153 if (track == 0) {
154 ALOGE("createTrack should have returned an IAudioTrack");
155 lStatus = UNKNOWN_ERROR;
156 }
157 } else {
158 if (track != 0) {
159 ALOGE("createTrack returned an IAudioTrack but with status %d", lStatus);
160 track.clear();
161 }
162 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800163 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700164 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800165 *status = lStatus;
166 }
Eric Laurent5841db72009-09-09 05:16:08 -0700167 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800168 }
169
170 virtual sp<IAudioRecord> openRecord(
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800171 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800172 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800173 audio_format_t format,
Glenn Kasten28b76b32012-07-03 17:24:41 -0700174 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -0800175 size_t *pFrameCount,
Glenn Kasteneeca3262013-07-31 16:12:48 -0700176 track_flags_t *flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -0700177 pid_t tid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700178 int *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700179 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700180 sp<IMemory>& cblk,
181 sp<IMemory>& buffers,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800182 status_t *status)
183 {
184 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700185 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800186 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800187 data.writeInt32((int32_t) input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800188 data.writeInt32(sampleRate);
189 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700190 data.writeInt32(channelMask);
Glenn Kasten74935e42013-12-19 08:56:45 -0800191 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800192 data.writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700193 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
194 data.writeInt32(lFlags);
Glenn Kasten1879fff2012-07-11 15:36:59 -0700195 data.writeInt32((int32_t) tid);
Glenn Kastenaea7ea02013-06-26 09:25:47 -0700196 int lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700197 if (sessionId != NULL) {
198 lSessionId = *sessionId;
199 }
200 data.writeInt32(lSessionId);
Glenn Kasten74105912014-07-03 12:28:53 -0700201 data.writeInt64(notificationFrames != NULL ? *notificationFrames : 0);
Glenn Kastend776ac62014-05-07 09:16:09 -0700202 cblk.clear();
203 buffers.clear();
Eric Laurent5841db72009-09-09 05:16:08 -0700204 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
205 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000206 ALOGE("openRecord error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700207 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700208 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800209 if (pFrameCount != NULL) {
210 *pFrameCount = frameCount;
211 }
Glenn Kasteneeca3262013-07-31 16:12:48 -0700212 lFlags = reply.readInt32();
213 if (flags != NULL) {
214 *flags = lFlags;
215 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700216 lSessionId = reply.readInt32();
217 if (sessionId != NULL) {
218 *sessionId = lSessionId;
219 }
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700220 size_t lNotificationFrames = (size_t) reply.readInt64();
221 if (notificationFrames != NULL) {
222 *notificationFrames = lNotificationFrames;
223 }
Eric Laurent5841db72009-09-09 05:16:08 -0700224 lStatus = reply.readInt32();
225 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700226 cblk = interface_cast<IMemory>(reply.readStrongBinder());
227 if (cblk != 0 && cblk->pointer() == NULL) {
228 cblk.clear();
229 }
230 buffers = interface_cast<IMemory>(reply.readStrongBinder());
231 if (buffers != 0 && buffers->pointer() == NULL) {
232 buffers.clear();
233 }
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700234 if (lStatus == NO_ERROR) {
235 if (record == 0) {
236 ALOGE("openRecord should have returned an IAudioRecord");
237 lStatus = UNKNOWN_ERROR;
Glenn Kastend776ac62014-05-07 09:16:09 -0700238 } else if (cblk == 0) {
239 ALOGE("openRecord should have returned a cblk");
240 lStatus = NO_MEMORY;
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700241 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700242 // buffers is permitted to be 0
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700243 } else {
Glenn Kastend776ac62014-05-07 09:16:09 -0700244 if (record != 0 || cblk != 0 || buffers != 0) {
245 ALOGE("openRecord returned an IAudioRecord, cblk, "
246 "or buffers but with status %d", lStatus);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700247 }
248 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700249 if (lStatus != NO_ERROR) {
250 record.clear();
251 cblk.clear();
252 buffers.clear();
253 }
Eric Laurent5841db72009-09-09 05:16:08 -0700254 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700255 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800256 *status = lStatus;
257 }
Eric Laurent5841db72009-09-09 05:16:08 -0700258 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800259 }
260
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800261 virtual uint32_t sampleRate(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800262 {
263 Parcel data, reply;
264 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800265 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800266 remote()->transact(SAMPLE_RATE, data, &reply);
267 return reply.readInt32();
268 }
269
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800270 virtual audio_format_t format(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800271 {
272 Parcel data, reply;
273 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800274 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800275 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800276 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800277 }
278
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800279 virtual size_t frameCount(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800280 {
281 Parcel data, reply;
282 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800283 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800284 remote()->transact(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800285 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800286 }
287
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800288 virtual uint32_t latency(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800289 {
290 Parcel data, reply;
291 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800292 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800293 remote()->transact(LATENCY, data, &reply);
294 return reply.readInt32();
295 }
296
297 virtual status_t setMasterVolume(float value)
298 {
299 Parcel data, reply;
300 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
301 data.writeFloat(value);
302 remote()->transact(SET_MASTER_VOLUME, data, &reply);
303 return reply.readInt32();
304 }
305
306 virtual status_t setMasterMute(bool muted)
307 {
308 Parcel data, reply;
309 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
310 data.writeInt32(muted);
311 remote()->transact(SET_MASTER_MUTE, data, &reply);
312 return reply.readInt32();
313 }
314
315 virtual float masterVolume() const
316 {
317 Parcel data, reply;
318 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
319 remote()->transact(MASTER_VOLUME, data, &reply);
320 return reply.readFloat();
321 }
322
323 virtual bool masterMute() const
324 {
325 Parcel data, reply;
326 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
327 remote()->transact(MASTER_MUTE, data, &reply);
328 return reply.readInt32();
329 }
330
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800331 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
332 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800333 {
334 Parcel data, reply;
335 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800336 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800337 data.writeFloat(value);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800338 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800339 remote()->transact(SET_STREAM_VOLUME, data, &reply);
340 return reply.readInt32();
341 }
342
Glenn Kastenfff6d712012-01-12 16:38:12 -0800343 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800344 {
345 Parcel data, reply;
346 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800347 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800348 data.writeInt32(muted);
349 remote()->transact(SET_STREAM_MUTE, data, &reply);
350 return reply.readInt32();
351 }
352
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800353 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800354 {
355 Parcel data, reply;
356 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800357 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800358 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800359 remote()->transact(STREAM_VOLUME, data, &reply);
360 return reply.readFloat();
361 }
362
Glenn Kastenfff6d712012-01-12 16:38:12 -0800363 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800364 {
365 Parcel data, reply;
366 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800367 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800368 remote()->transact(STREAM_MUTE, data, &reply);
369 return reply.readInt32();
370 }
371
Glenn Kastenf78aee72012-01-04 11:00:47 -0800372 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800373 {
374 Parcel data, reply;
375 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
376 data.writeInt32(mode);
377 remote()->transact(SET_MODE, data, &reply);
378 return reply.readInt32();
379 }
380
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800381 virtual status_t setMicMute(bool state)
382 {
383 Parcel data, reply;
384 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
385 data.writeInt32(state);
386 remote()->transact(SET_MIC_MUTE, data, &reply);
387 return reply.readInt32();
388 }
389
390 virtual bool getMicMute() const
391 {
392 Parcel data, reply;
393 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
394 remote()->transact(GET_MIC_MUTE, data, &reply);
395 return reply.readInt32();
396 }
397
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800398 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800399 {
400 Parcel data, reply;
401 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800402 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700403 data.writeString8(keyValuePairs);
404 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800405 return reply.readInt32();
406 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700407
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800408 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700409 {
410 Parcel data, reply;
411 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800412 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700413 data.writeString8(keys);
414 remote()->transact(GET_PARAMETERS, data, &reply);
415 return reply.readString8();
416 }
417
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800418 virtual void registerClient(const sp<IAudioFlingerClient>& client)
419 {
420 Parcel data, reply;
421 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800422 data.writeStrongBinder(IInterface::asBinder(client));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800423 remote()->transact(REGISTER_CLIENT, data, &reply);
424 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700425
Glenn Kastendd8104c2012-07-02 12:42:44 -0700426 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
427 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800428 {
429 Parcel data, reply;
430 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
431 data.writeInt32(sampleRate);
432 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700433 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800434 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800435 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800436 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700437
Eric Laurentcf2c0212014-07-25 16:20:43 -0700438 virtual status_t openOutput(audio_module_handle_t module,
439 audio_io_handle_t *output,
440 audio_config_t *config,
441 audio_devices_t *devices,
442 const String8& address,
443 uint32_t *latencyMs,
444 audio_output_flags_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800445 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700446 if (output == NULL || config == NULL || devices == NULL || latencyMs == NULL) {
447 return BAD_VALUE;
448 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800449 Parcel data, reply;
450 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700451 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700452 data.write(config, sizeof(audio_config_t));
453 data.writeInt32(*devices);
454 data.writeString8(address);
Glenn Kasten18868c52012-03-07 09:15:37 -0800455 data.writeInt32((int32_t) flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700456 status_t status = remote()->transact(OPEN_OUTPUT, data, &reply);
457 if (status != NO_ERROR) {
458 *output = AUDIO_IO_HANDLE_NONE;
459 return status;
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100460 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700461 status = (status_t)reply.readInt32();
462 if (status != NO_ERROR) {
463 *output = AUDIO_IO_HANDLE_NONE;
464 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700465 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700466 *output = (audio_io_handle_t)reply.readInt32();
467 ALOGV("openOutput() returned output, %d", *output);
468 reply.read(config, sizeof(audio_config_t));
469 *devices = (audio_devices_t)reply.readInt32();
470 *latencyMs = reply.readInt32();
471 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800472 }
473
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800474 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
475 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800476 {
477 Parcel data, reply;
478 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800479 data.writeInt32((int32_t) output1);
480 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700481 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800482 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700483 }
484
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800485 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700486 {
487 Parcel data, reply;
488 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800489 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700490 remote()->transact(CLOSE_OUTPUT, data, &reply);
491 return reply.readInt32();
492 }
493
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800494 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700495 {
496 Parcel data, reply;
497 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800498 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700499 remote()->transact(SUSPEND_OUTPUT, data, &reply);
500 return reply.readInt32();
501 }
502
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800503 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700504 {
505 Parcel data, reply;
506 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800507 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700508 remote()->transact(RESTORE_OUTPUT, data, &reply);
509 return reply.readInt32();
510 }
511
Eric Laurentcf2c0212014-07-25 16:20:43 -0700512 virtual status_t openInput(audio_module_handle_t module,
513 audio_io_handle_t *input,
514 audio_config_t *config,
515 audio_devices_t *device,
516 const String8& address,
517 audio_source_t source,
518 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700519 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700520 if (input == NULL || config == NULL || device == NULL) {
521 return BAD_VALUE;
522 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700523 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700524 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700525 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700526 data.writeInt32(*input);
527 data.write(config, sizeof(audio_config_t));
528 data.writeInt32(*device);
529 data.writeString8(address);
530 data.writeInt32(source);
Glenn Kastenec40d282014-07-15 15:31:26 -0700531 data.writeInt32(flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700532 status_t status = remote()->transact(OPEN_INPUT, data, &reply);
533 if (status != NO_ERROR) {
534 *input = AUDIO_IO_HANDLE_NONE;
535 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700536 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700537 status = (status_t)reply.readInt32();
538 if (status != NO_ERROR) {
539 *input = AUDIO_IO_HANDLE_NONE;
540 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700541 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700542 *input = (audio_io_handle_t)reply.readInt32();
543 reply.read(config, sizeof(audio_config_t));
544 *device = (audio_devices_t)reply.readInt32();
545 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700546 }
547
Eric Laurentfa2877b2009-07-28 08:44:33 -0700548 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700549 {
550 Parcel data, reply;
551 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700552 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700553 remote()->transact(CLOSE_INPUT, data, &reply);
554 return reply.readInt32();
555 }
556
Glenn Kastend2304db2014-02-03 07:40:31 -0800557 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700558 {
559 Parcel data, reply;
560 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800561 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800562 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700563 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800564 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700565
566 virtual status_t setVoiceVolume(float volume)
567 {
568 Parcel data, reply;
569 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
570 data.writeFloat(volume);
571 remote()->transact(SET_VOICE_VOLUME, data, &reply);
572 return reply.readInt32();
573 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800574
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000575 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800576 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800577 {
578 Parcel data, reply;
579 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800580 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800581 remote()->transact(GET_RENDER_POSITION, data, &reply);
582 status_t status = reply.readInt32();
583 if (status == NO_ERROR) {
584 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700585 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800586 *halFrames = tmp;
587 }
588 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700589 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800590 *dspFrames = tmp;
591 }
592 }
593 return status;
594 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800595
Glenn Kasten5f972c02014-01-13 09:59:31 -0800596 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800597 {
598 Parcel data, reply;
599 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800600 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800601 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
602 if (status != NO_ERROR) {
603 return 0;
604 }
605 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800606 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700607
Eric Laurentde3f8392014-07-27 18:38:22 -0700608 virtual audio_unique_id_t newAudioUniqueId()
Eric Laurentbe916aa2010-06-01 23:49:17 -0700609 {
610 Parcel data, reply;
611 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
612 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
Eric Laurentde3f8392014-07-27 18:38:22 -0700613 audio_unique_id_t id = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700614 if (status == NO_ERROR) {
615 id = reply.readInt32();
616 }
617 return id;
618 }
619
Marco Nelissend457c972014-02-11 08:47:07 -0800620 virtual void acquireAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700621 {
622 Parcel data, reply;
623 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
624 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800625 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700626 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
627 }
628
Marco Nelissend457c972014-02-11 08:47:07 -0800629 virtual void releaseAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700630 {
631 Parcel data, reply;
632 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
633 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800634 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700635 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
636 }
637
Glenn Kastenf587ba52012-01-26 16:25:10 -0800638 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700639 {
640 Parcel data, reply;
641 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
642 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
643 if (status != NO_ERROR) {
644 return status;
645 }
646 status = reply.readInt32();
647 if (status != NO_ERROR) {
648 return status;
649 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800650 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700651 *numEffects = (uint32_t)reply.readInt32();
652 }
653 return NO_ERROR;
654 }
655
Glenn Kastenf587ba52012-01-26 16:25:10 -0800656 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700657 {
658 if (pDescriptor == NULL) {
659 return BAD_VALUE;
660 }
661 Parcel data, reply;
662 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700663 data.writeInt32(index);
664 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700665 if (status != NO_ERROR) {
666 return status;
667 }
668 status = reply.readInt32();
669 if (status != NO_ERROR) {
670 return status;
671 }
672 reply.read(pDescriptor, sizeof(effect_descriptor_t));
673 return NO_ERROR;
674 }
675
Glenn Kasten5e92a782012-01-30 07:40:52 -0800676 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800677 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700678 {
679 if (pUuid == NULL || pDescriptor == NULL) {
680 return BAD_VALUE;
681 }
682 Parcel data, reply;
683 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
684 data.write(pUuid, sizeof(effect_uuid_t));
685 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
686 if (status != NO_ERROR) {
687 return status;
688 }
689 status = reply.readInt32();
690 if (status != NO_ERROR) {
691 return status;
692 }
693 reply.read(pDescriptor, sizeof(effect_descriptor_t));
694 return NO_ERROR;
695 }
696
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800697 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700698 effect_descriptor_t *pDesc,
699 const sp<IEffectClient>& client,
700 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800701 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700702 int sessionId,
703 status_t *status,
704 int *id,
705 int *enabled)
706 {
707 Parcel data, reply;
708 sp<IEffect> effect;
709
710 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700711 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700712 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700713 *status = BAD_VALUE;
714 }
715 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700716
717 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700718 data.write(pDesc, sizeof(effect_descriptor_t));
Marco Nelissen06b46062014-11-14 07:58:25 -0800719 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700720 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800721 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700722 data.writeInt32(sessionId);
723
724 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
725 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000726 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700727 } else {
728 lStatus = reply.readInt32();
729 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700730 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700731 *id = tmp;
732 }
733 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800734 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700735 *enabled = tmp;
736 }
737 effect = interface_cast<IEffect>(reply.readStrongBinder());
738 reply.read(pDesc, sizeof(effect_descriptor_t));
739 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700740 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700741 *status = lStatus;
742 }
743
744 return effect;
745 }
Eric Laurentde070132010-07-13 04:45:46 -0700746
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800747 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
748 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700749 {
750 Parcel data, reply;
751 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
752 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800753 data.writeInt32((int32_t) srcOutput);
754 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700755 remote()->transact(MOVE_EFFECTS, data, &reply);
756 return reply.readInt32();
757 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700758
759 virtual audio_module_handle_t loadHwModule(const char *name)
760 {
761 Parcel data, reply;
762 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
763 data.writeCString(name);
764 remote()->transact(LOAD_HW_MODULE, data, &reply);
765 return (audio_module_handle_t) reply.readInt32();
766 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700767
Glenn Kasten3b16c762012-11-14 08:44:39 -0800768 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700769 {
770 Parcel data, reply;
771 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
772 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
773 return reply.readInt32();
774 }
775
Glenn Kastene33054e2012-11-14 12:54:39 -0800776 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700777 {
778 Parcel data, reply;
779 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
780 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800781 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700782 }
783
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700784 virtual status_t setLowRamDevice(bool isLowRamDevice)
785 {
786 Parcel data, reply;
787 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
788 data.writeInt32((int) isLowRamDevice);
789 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
790 return reply.readInt32();
791 }
Eric Laurent4b123402014-04-11 09:22:20 -0700792 virtual status_t listAudioPorts(unsigned int *num_ports,
793 struct audio_port *ports)
794 {
795 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
796 return BAD_VALUE;
797 }
798 Parcel data, reply;
799 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
800 data.writeInt32(*num_ports);
801 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
802 if (status != NO_ERROR ||
803 (status = (status_t)reply.readInt32()) != NO_ERROR) {
804 return status;
805 }
806 *num_ports = (unsigned int)reply.readInt32();
807 reply.read(ports, *num_ports * sizeof(struct audio_port));
808 return status;
809 }
810 virtual status_t getAudioPort(struct audio_port *port)
811 {
812 if (port == NULL) {
813 return BAD_VALUE;
814 }
815 Parcel data, reply;
816 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
817 data.write(port, sizeof(struct audio_port));
818 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
819 if (status != NO_ERROR ||
820 (status = (status_t)reply.readInt32()) != NO_ERROR) {
821 return status;
822 }
823 reply.read(port, sizeof(struct audio_port));
824 return status;
825 }
826 virtual status_t createAudioPatch(const struct audio_patch *patch,
827 audio_patch_handle_t *handle)
828 {
829 if (patch == NULL || handle == NULL) {
830 return BAD_VALUE;
831 }
832 Parcel data, reply;
833 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
834 data.write(patch, sizeof(struct audio_patch));
835 data.write(handle, sizeof(audio_patch_handle_t));
836 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
837 if (status != NO_ERROR ||
838 (status = (status_t)reply.readInt32()) != NO_ERROR) {
839 return status;
840 }
841 reply.read(handle, sizeof(audio_patch_handle_t));
842 return status;
843 }
844 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
845 {
846 Parcel data, reply;
847 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
848 data.write(&handle, sizeof(audio_patch_handle_t));
849 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
850 if (status != NO_ERROR) {
851 status = (status_t)reply.readInt32();
852 }
853 return status;
854 }
855 virtual status_t listAudioPatches(unsigned int *num_patches,
856 struct audio_patch *patches)
857 {
858 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
859 return BAD_VALUE;
860 }
861 Parcel data, reply;
862 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
863 data.writeInt32(*num_patches);
864 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
865 if (status != NO_ERROR ||
866 (status = (status_t)reply.readInt32()) != NO_ERROR) {
867 return status;
868 }
869 *num_patches = (unsigned int)reply.readInt32();
870 reply.read(patches, *num_patches * sizeof(struct audio_patch));
871 return status;
872 }
873 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
874 {
875 if (config == NULL) {
876 return BAD_VALUE;
877 }
878 Parcel data, reply;
879 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
880 data.write(config, sizeof(struct audio_port_config));
881 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
882 if (status != NO_ERROR) {
883 status = (status_t)reply.readInt32();
884 }
885 return status;
886 }
Eric Laurent93c3d412014-08-01 14:48:35 -0700887 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
888 {
889 Parcel data, reply;
890 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
891 data.writeInt32(sessionId);
892 status_t status = remote()->transact(GET_AUDIO_HW_SYNC, data, &reply);
893 if (status != NO_ERROR) {
894 return AUDIO_HW_SYNC_INVALID;
895 }
896 return (audio_hw_sync_t)reply.readInt32();
897 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800898};
899
900IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
901
902// ----------------------------------------------------------------------
903
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800904status_t BnAudioFlinger::onTransact(
905 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
906{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700907 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800908 case CREATE_TRACK: {
909 CHECK_INTERFACE(IAudioFlinger, data, reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800910 int streamType = data.readInt32();
911 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800912 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700913 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800914 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800915 track_flags_t flags = (track_flags_t) data.readInt32();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700916 bool haveSharedBuffer = data.readInt32() != 0;
917 sp<IMemory> buffer;
918 if (haveSharedBuffer) {
919 buffer = interface_cast<IMemory>(data.readStrongBinder());
920 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800921 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kasten3acbd052012-02-28 10:39:56 -0800922 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700923 int sessionId = data.readInt32();
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800924 int clientUid = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800925 status_t status;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700926 sp<IAudioTrack> track;
927 if ((haveSharedBuffer && (buffer == 0)) ||
928 ((buffer != 0) && (buffer->pointer() == NULL))) {
929 ALOGW("CREATE_TRACK: cannot retrieve shared memory");
930 status = DEAD_OBJECT;
931 } else {
932 track = createTrack(
933 (audio_stream_type_t) streamType, sampleRate, format,
Glenn Kasten74935e42013-12-19 08:56:45 -0800934 channelMask, &frameCount, &flags, buffer, output, tid,
Glenn Kastenc5a17422014-03-13 14:59:59 -0700935 &sessionId, clientUid, &status);
Glenn Kasten0cde0762014-01-16 15:06:36 -0800936 LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700937 }
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700938 reply->writeInt64(frameCount);
Glenn Kastene0b07172012-11-06 15:03:34 -0800939 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700940 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800941 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800942 reply->writeStrongBinder(IInterface::asBinder(track));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800943 return NO_ERROR;
944 } break;
945 case OPEN_RECORD: {
946 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800947 audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800948 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800949 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700950 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800951 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800952 track_flags_t flags = (track_flags_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700953 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700954 int sessionId = data.readInt32();
Glenn Kasten74105912014-07-03 12:28:53 -0700955 size_t notificationFrames = data.readInt64();
Glenn Kastend776ac62014-05-07 09:16:09 -0700956 sp<IMemory> cblk;
957 sp<IMemory> buffers;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800958 status_t status;
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800959 sp<IAudioRecord> record = openRecord(input,
Glenn Kastend776ac62014-05-07 09:16:09 -0700960 sampleRate, format, channelMask, &frameCount, &flags, tid, &sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700961 &notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700962 cblk, buffers, &status);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700963 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700964 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700965 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700966 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700967 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800968 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800969 reply->writeStrongBinder(IInterface::asBinder(record));
970 reply->writeStrongBinder(IInterface::asBinder(cblk));
971 reply->writeStrongBinder(IInterface::asBinder(buffers));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800972 return NO_ERROR;
973 } break;
974 case SAMPLE_RATE: {
975 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800976 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800977 return NO_ERROR;
978 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800979 case FORMAT: {
980 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800981 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800982 return NO_ERROR;
983 } break;
984 case FRAME_COUNT: {
985 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800986 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800987 return NO_ERROR;
988 } break;
989 case LATENCY: {
990 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800991 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800992 return NO_ERROR;
993 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700994 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800995 CHECK_INTERFACE(IAudioFlinger, data, reply);
996 reply->writeInt32( setMasterVolume(data.readFloat()) );
997 return NO_ERROR;
998 } break;
999 case SET_MASTER_MUTE: {
1000 CHECK_INTERFACE(IAudioFlinger, data, reply);
1001 reply->writeInt32( setMasterMute(data.readInt32()) );
1002 return NO_ERROR;
1003 } break;
1004 case MASTER_VOLUME: {
1005 CHECK_INTERFACE(IAudioFlinger, data, reply);
1006 reply->writeFloat( masterVolume() );
1007 return NO_ERROR;
1008 } break;
1009 case MASTER_MUTE: {
1010 CHECK_INTERFACE(IAudioFlinger, data, reply);
1011 reply->writeInt32( masterMute() );
1012 return NO_ERROR;
1013 } break;
1014 case SET_STREAM_VOLUME: {
1015 CHECK_INTERFACE(IAudioFlinger, data, reply);
1016 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001017 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001018 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001019 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001020 return NO_ERROR;
1021 } break;
1022 case SET_STREAM_MUTE: {
1023 CHECK_INTERFACE(IAudioFlinger, data, reply);
1024 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001025 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001026 return NO_ERROR;
1027 } break;
1028 case STREAM_VOLUME: {
1029 CHECK_INTERFACE(IAudioFlinger, data, reply);
1030 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001031 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001032 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001033 return NO_ERROR;
1034 } break;
1035 case STREAM_MUTE: {
1036 CHECK_INTERFACE(IAudioFlinger, data, reply);
1037 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001038 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001039 return NO_ERROR;
1040 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001041 case SET_MODE: {
1042 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001043 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001044 reply->writeInt32( setMode(mode) );
1045 return NO_ERROR;
1046 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001047 case SET_MIC_MUTE: {
1048 CHECK_INTERFACE(IAudioFlinger, data, reply);
1049 int state = data.readInt32();
1050 reply->writeInt32( setMicMute(state) );
1051 return NO_ERROR;
1052 } break;
1053 case GET_MIC_MUTE: {
1054 CHECK_INTERFACE(IAudioFlinger, data, reply);
1055 reply->writeInt32( getMicMute() );
1056 return NO_ERROR;
1057 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001058 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001059 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001060 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001061 String8 keyValuePairs(data.readString8());
1062 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001063 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001064 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001065 case GET_PARAMETERS: {
1066 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001067 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001068 String8 keys(data.readString8());
1069 reply->writeString8(getParameters(ioHandle, keys));
1070 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001071 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001072
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001073 case REGISTER_CLIENT: {
1074 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001075 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1076 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001077 registerClient(client);
1078 return NO_ERROR;
1079 } break;
1080 case GET_INPUTBUFFERSIZE: {
1081 CHECK_INTERFACE(IAudioFlinger, data, reply);
1082 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001083 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001084 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001085 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001086 return NO_ERROR;
1087 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001088 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001089 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001090 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001091 audio_config_t config;
1092 data.read(&config, sizeof(audio_config_t));
Eric Laurenta4c5a552012-03-29 10:12:40 -07001093 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001094 String8 address(data.readString8());
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001095 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001096 uint32_t latencyMs;
1097 audio_io_handle_t output;
1098 status_t status = openOutput(module, &output, &config,
1099 &devices, address, &latencyMs, flags);
Glenn Kasten70742962014-02-18 08:00:47 -08001100 ALOGV("OPEN_OUTPUT output, %d", output);
Eric Laurentcf2c0212014-07-25 16:20:43 -07001101 reply->writeInt32((int32_t)status);
1102 if (status == NO_ERROR) {
1103 reply->writeInt32((int32_t)output);
1104 reply->write(&config, sizeof(audio_config_t));
1105 reply->writeInt32(devices);
1106 reply->writeInt32(latencyMs);
1107 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001108 return NO_ERROR;
1109 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001110 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001111 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001112 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1113 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1114 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001115 return NO_ERROR;
1116 } break;
1117 case CLOSE_OUTPUT: {
1118 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001119 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001120 return NO_ERROR;
1121 } break;
1122 case SUSPEND_OUTPUT: {
1123 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001124 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001125 return NO_ERROR;
1126 } break;
1127 case RESTORE_OUTPUT: {
1128 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001129 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001130 return NO_ERROR;
1131 } break;
1132 case OPEN_INPUT: {
1133 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001134 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001135 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
1136 audio_config_t config;
1137 data.read(&config, sizeof(audio_config_t));
1138 audio_devices_t device = (audio_devices_t)data.readInt32();
1139 String8 address(data.readString8());
1140 audio_source_t source = (audio_source_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001141 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001142
Eric Laurentcf2c0212014-07-25 16:20:43 -07001143 status_t status = openInput(module, &input, &config,
1144 &device, address, source, flags);
1145 reply->writeInt32((int32_t) status);
1146 if (status == NO_ERROR) {
1147 reply->writeInt32((int32_t) input);
1148 reply->write(&config, sizeof(audio_config_t));
1149 reply->writeInt32(device);
1150 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001151 return NO_ERROR;
1152 } break;
1153 case CLOSE_INPUT: {
1154 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001155 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001156 return NO_ERROR;
1157 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001158 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001159 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001160 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1161 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001162 return NO_ERROR;
1163 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001164 case SET_VOICE_VOLUME: {
1165 CHECK_INTERFACE(IAudioFlinger, data, reply);
1166 float volume = data.readFloat();
1167 reply->writeInt32( setVoiceVolume(volume) );
1168 return NO_ERROR;
1169 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001170 case GET_RENDER_POSITION: {
1171 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001172 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001173 uint32_t halFrames;
1174 uint32_t dspFrames;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001175 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1176 reply->writeInt32(status);
1177 if (status == NO_ERROR) {
1178 reply->writeInt32(halFrames);
1179 reply->writeInt32(dspFrames);
1180 }
1181 return NO_ERROR;
1182 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001183 case GET_INPUT_FRAMES_LOST: {
1184 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001185 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001186 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001187 return NO_ERROR;
1188 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001189 case NEW_AUDIO_SESSION_ID: {
1190 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentde3f8392014-07-27 18:38:22 -07001191 reply->writeInt32(newAudioUniqueId());
Eric Laurentbe916aa2010-06-01 23:49:17 -07001192 return NO_ERROR;
1193 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001194 case ACQUIRE_AUDIO_SESSION_ID: {
1195 CHECK_INTERFACE(IAudioFlinger, data, reply);
1196 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001197 int pid = data.readInt32();
1198 acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001199 return NO_ERROR;
1200 } break;
1201 case RELEASE_AUDIO_SESSION_ID: {
1202 CHECK_INTERFACE(IAudioFlinger, data, reply);
1203 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001204 int pid = data.readInt32();
1205 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001206 return NO_ERROR;
1207 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001208 case QUERY_NUM_EFFECTS: {
1209 CHECK_INTERFACE(IAudioFlinger, data, reply);
1210 uint32_t numEffects;
1211 status_t status = queryNumberEffects(&numEffects);
1212 reply->writeInt32(status);
1213 if (status == NO_ERROR) {
1214 reply->writeInt32((int32_t)numEffects);
1215 }
1216 return NO_ERROR;
1217 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001218 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001219 CHECK_INTERFACE(IAudioFlinger, data, reply);
1220 effect_descriptor_t desc;
Eric Laurentffe9c252010-06-23 17:38:20 -07001221 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001222 reply->writeInt32(status);
1223 if (status == NO_ERROR) {
1224 reply->write(&desc, sizeof(effect_descriptor_t));
1225 }
1226 return NO_ERROR;
1227 }
1228 case GET_EFFECT_DESCRIPTOR: {
1229 CHECK_INTERFACE(IAudioFlinger, data, reply);
1230 effect_uuid_t uuid;
1231 data.read(&uuid, sizeof(effect_uuid_t));
1232 effect_descriptor_t desc;
1233 status_t status = getEffectDescriptor(&uuid, &desc);
1234 reply->writeInt32(status);
1235 if (status == NO_ERROR) {
1236 reply->write(&desc, sizeof(effect_descriptor_t));
1237 }
1238 return NO_ERROR;
1239 }
1240 case CREATE_EFFECT: {
1241 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001242 effect_descriptor_t desc;
1243 data.read(&desc, sizeof(effect_descriptor_t));
1244 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1245 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001246 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -07001247 int sessionId = data.readInt32();
1248 status_t status;
1249 int id;
1250 int enabled;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001251
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001252 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001253 &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001254 reply->writeInt32(status);
1255 reply->writeInt32(id);
1256 reply->writeInt32(enabled);
Marco Nelissen06b46062014-11-14 07:58:25 -08001257 reply->writeStrongBinder(IInterface::asBinder(effect));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001258 reply->write(&desc, sizeof(effect_descriptor_t));
1259 return NO_ERROR;
1260 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001261 case MOVE_EFFECTS: {
1262 CHECK_INTERFACE(IAudioFlinger, data, reply);
1263 int session = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001264 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1265 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001266 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1267 return NO_ERROR;
1268 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001269 case LOAD_HW_MODULE: {
1270 CHECK_INTERFACE(IAudioFlinger, data, reply);
1271 reply->writeInt32(loadHwModule(data.readCString()));
1272 return NO_ERROR;
1273 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001274 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1275 CHECK_INTERFACE(IAudioFlinger, data, reply);
1276 reply->writeInt32(getPrimaryOutputSamplingRate());
1277 return NO_ERROR;
1278 } break;
1279 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1280 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001281 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001282 return NO_ERROR;
1283 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001284 case SET_LOW_RAM_DEVICE: {
1285 CHECK_INTERFACE(IAudioFlinger, data, reply);
1286 bool isLowRamDevice = data.readInt32() != 0;
1287 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1288 return NO_ERROR;
1289 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001290 case LIST_AUDIO_PORTS: {
1291 CHECK_INTERFACE(IAudioFlinger, data, reply);
1292 unsigned int num_ports = data.readInt32();
1293 struct audio_port *ports =
1294 (struct audio_port *)calloc(num_ports,
1295 sizeof(struct audio_port));
1296 status_t status = listAudioPorts(&num_ports, ports);
1297 reply->writeInt32(status);
1298 if (status == NO_ERROR) {
1299 reply->writeInt32(num_ports);
1300 reply->write(&ports, num_ports * sizeof(struct audio_port));
1301 }
1302 free(ports);
1303 return NO_ERROR;
1304 } break;
1305 case GET_AUDIO_PORT: {
1306 CHECK_INTERFACE(IAudioFlinger, data, reply);
1307 struct audio_port port;
1308 data.read(&port, sizeof(struct audio_port));
1309 status_t status = getAudioPort(&port);
1310 reply->writeInt32(status);
1311 if (status == NO_ERROR) {
1312 reply->write(&port, sizeof(struct audio_port));
1313 }
1314 return NO_ERROR;
1315 } break;
1316 case CREATE_AUDIO_PATCH: {
1317 CHECK_INTERFACE(IAudioFlinger, data, reply);
1318 struct audio_patch patch;
1319 data.read(&patch, sizeof(struct audio_patch));
1320 audio_patch_handle_t handle;
1321 data.read(&handle, sizeof(audio_patch_handle_t));
1322 status_t status = createAudioPatch(&patch, &handle);
1323 reply->writeInt32(status);
1324 if (status == NO_ERROR) {
1325 reply->write(&handle, sizeof(audio_patch_handle_t));
1326 }
1327 return NO_ERROR;
1328 } break;
1329 case RELEASE_AUDIO_PATCH: {
1330 CHECK_INTERFACE(IAudioFlinger, data, reply);
1331 audio_patch_handle_t handle;
1332 data.read(&handle, sizeof(audio_patch_handle_t));
1333 status_t status = releaseAudioPatch(handle);
1334 reply->writeInt32(status);
1335 return NO_ERROR;
1336 } break;
1337 case LIST_AUDIO_PATCHES: {
1338 CHECK_INTERFACE(IAudioFlinger, data, reply);
1339 unsigned int num_patches = data.readInt32();
1340 struct audio_patch *patches =
1341 (struct audio_patch *)calloc(num_patches,
1342 sizeof(struct audio_patch));
1343 status_t status = listAudioPatches(&num_patches, patches);
1344 reply->writeInt32(status);
1345 if (status == NO_ERROR) {
1346 reply->writeInt32(num_patches);
1347 reply->write(&patches, num_patches * sizeof(struct audio_patch));
1348 }
1349 free(patches);
1350 return NO_ERROR;
1351 } break;
1352 case SET_AUDIO_PORT_CONFIG: {
1353 CHECK_INTERFACE(IAudioFlinger, data, reply);
1354 struct audio_port_config config;
1355 data.read(&config, sizeof(struct audio_port_config));
1356 status_t status = setAudioPortConfig(&config);
1357 reply->writeInt32(status);
1358 return NO_ERROR;
1359 } break;
Eric Laurent93c3d412014-08-01 14:48:35 -07001360 case GET_AUDIO_HW_SYNC: {
1361 CHECK_INTERFACE(IAudioFlinger, data, reply);
1362 reply->writeInt32(getAudioHwSyncForSession((audio_session_t)data.readInt32()));
1363 return NO_ERROR;
1364 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001365 default:
1366 return BBinder::onTransact(code, data, reply, flags);
1367 }
1368}
1369
1370// ----------------------------------------------------------------------------
1371
Glenn Kasten40bc9062015-03-20 09:09:33 -07001372} // namespace android