blob: d722fe92b6ccc834e0ad78a5ef8913e30618ba22 [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
Eric Laurentf75c2fe2015-04-02 13:49:15 -070086#define MAX_ITEMS_PER_LIST 1024
87
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080088class BpAudioFlinger : public BpInterface<IAudioFlinger>
89{
90public:
91 BpAudioFlinger(const sp<IBinder>& impl)
92 : BpInterface<IAudioFlinger>(impl)
93 {
94 }
95
96 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080097 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080098 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080099 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -0700100 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -0800101 size_t *pFrameCount,
Glenn Kastene0b07172012-11-06 15:03:34 -0800102 track_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800103 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800104 audio_io_handle_t output,
Glenn Kasten3acbd052012-02-28 10:39:56 -0800105 pid_t tid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700106 int *sessionId,
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800107 int clientUid,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800108 status_t *status)
109 {
110 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700111 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800112 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800113 data.writeInt32((int32_t) streamType);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800114 data.writeInt32(sampleRate);
115 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700116 data.writeInt32(channelMask);
Glenn Kasten74935e42013-12-19 08:56:45 -0800117 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800118 data.writeInt64(frameCount);
Glenn Kastenb26e3e92012-11-14 08:32:08 -0800119 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
Glenn Kastene0b07172012-11-06 15:03:34 -0800120 data.writeInt32(lFlags);
Glenn Kasten2301acc2014-01-17 10:21:00 -0800121 // haveSharedBuffer
Eric Laurent3d00aa62013-09-24 09:53:27 -0700122 if (sharedBuffer != 0) {
123 data.writeInt32(true);
Marco Nelissen06b46062014-11-14 07:58:25 -0800124 data.writeStrongBinder(IInterface::asBinder(sharedBuffer));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700125 } else {
126 data.writeInt32(false);
127 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800128 data.writeInt32((int32_t) output);
Glenn Kasten3acbd052012-02-28 10:39:56 -0800129 data.writeInt32((int32_t) tid);
Glenn Kastenaea7ea02013-06-26 09:25:47 -0700130 int lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700131 if (sessionId != NULL) {
132 lSessionId = *sessionId;
133 }
134 data.writeInt32(lSessionId);
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800135 data.writeInt32(clientUid);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800136 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
137 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000138 ALOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700139 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700140 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800141 if (pFrameCount != NULL) {
142 *pFrameCount = frameCount;
143 }
Glenn Kastene0b07172012-11-06 15:03:34 -0800144 lFlags = reply.readInt32();
145 if (flags != NULL) {
146 *flags = lFlags;
147 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700148 lSessionId = reply.readInt32();
149 if (sessionId != NULL) {
150 *sessionId = lSessionId;
151 }
Eric Laurent5841db72009-09-09 05:16:08 -0700152 lStatus = reply.readInt32();
153 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
Glenn Kasten0cde0762014-01-16 15:06:36 -0800154 if (lStatus == NO_ERROR) {
155 if (track == 0) {
156 ALOGE("createTrack should have returned an IAudioTrack");
157 lStatus = UNKNOWN_ERROR;
158 }
159 } else {
160 if (track != 0) {
161 ALOGE("createTrack returned an IAudioTrack but with status %d", lStatus);
162 track.clear();
163 }
164 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800165 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700166 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800167 *status = lStatus;
168 }
Eric Laurent5841db72009-09-09 05:16:08 -0700169 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800170 }
171
172 virtual sp<IAudioRecord> openRecord(
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800173 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800174 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800175 audio_format_t format,
Glenn Kasten28b76b32012-07-03 17:24:41 -0700176 audio_channel_mask_t channelMask,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700177 const String16& opPackageName,
Glenn Kasten74935e42013-12-19 08:56:45 -0800178 size_t *pFrameCount,
Glenn Kasteneeca3262013-07-31 16:12:48 -0700179 track_flags_t *flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -0700180 pid_t tid,
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700181 int clientUid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700182 int *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700183 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700184 sp<IMemory>& cblk,
185 sp<IMemory>& buffers,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800186 status_t *status)
187 {
188 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700189 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800190 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800191 data.writeInt32((int32_t) input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800192 data.writeInt32(sampleRate);
193 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700194 data.writeInt32(channelMask);
Dianne Hackborneaa34702015-04-29 12:57:58 -0700195 data.writeString16(opPackageName);
Glenn Kasten74935e42013-12-19 08:56:45 -0800196 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800197 data.writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700198 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
199 data.writeInt32(lFlags);
Glenn Kasten1879fff2012-07-11 15:36:59 -0700200 data.writeInt32((int32_t) tid);
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700201 data.writeInt32((int32_t) clientUid);
Glenn Kastenaea7ea02013-06-26 09:25:47 -0700202 int lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700203 if (sessionId != NULL) {
204 lSessionId = *sessionId;
205 }
206 data.writeInt32(lSessionId);
Glenn Kasten74105912014-07-03 12:28:53 -0700207 data.writeInt64(notificationFrames != NULL ? *notificationFrames : 0);
Glenn Kastend776ac62014-05-07 09:16:09 -0700208 cblk.clear();
209 buffers.clear();
Eric Laurent5841db72009-09-09 05:16:08 -0700210 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
211 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000212 ALOGE("openRecord error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700213 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700214 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800215 if (pFrameCount != NULL) {
216 *pFrameCount = frameCount;
217 }
Glenn Kasteneeca3262013-07-31 16:12:48 -0700218 lFlags = reply.readInt32();
219 if (flags != NULL) {
220 *flags = lFlags;
221 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700222 lSessionId = reply.readInt32();
223 if (sessionId != NULL) {
224 *sessionId = lSessionId;
225 }
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700226 size_t lNotificationFrames = (size_t) reply.readInt64();
227 if (notificationFrames != NULL) {
228 *notificationFrames = lNotificationFrames;
229 }
Eric Laurent5841db72009-09-09 05:16:08 -0700230 lStatus = reply.readInt32();
231 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700232 cblk = interface_cast<IMemory>(reply.readStrongBinder());
233 if (cblk != 0 && cblk->pointer() == NULL) {
234 cblk.clear();
235 }
236 buffers = interface_cast<IMemory>(reply.readStrongBinder());
237 if (buffers != 0 && buffers->pointer() == NULL) {
238 buffers.clear();
239 }
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700240 if (lStatus == NO_ERROR) {
241 if (record == 0) {
242 ALOGE("openRecord should have returned an IAudioRecord");
243 lStatus = UNKNOWN_ERROR;
Glenn Kastend776ac62014-05-07 09:16:09 -0700244 } else if (cblk == 0) {
245 ALOGE("openRecord should have returned a cblk");
246 lStatus = NO_MEMORY;
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700247 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700248 // buffers is permitted to be 0
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700249 } else {
Glenn Kastend776ac62014-05-07 09:16:09 -0700250 if (record != 0 || cblk != 0 || buffers != 0) {
251 ALOGE("openRecord returned an IAudioRecord, cblk, "
252 "or buffers but with status %d", lStatus);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700253 }
254 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700255 if (lStatus != NO_ERROR) {
256 record.clear();
257 cblk.clear();
258 buffers.clear();
259 }
Eric Laurent5841db72009-09-09 05:16:08 -0700260 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700261 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800262 *status = lStatus;
263 }
Eric Laurent5841db72009-09-09 05:16:08 -0700264 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800265 }
266
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800267 virtual uint32_t sampleRate(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800268 {
269 Parcel data, reply;
270 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800271 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800272 remote()->transact(SAMPLE_RATE, data, &reply);
273 return reply.readInt32();
274 }
275
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800276 virtual audio_format_t format(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800277 {
278 Parcel data, reply;
279 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800280 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800281 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800282 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800283 }
284
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800285 virtual size_t frameCount(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800286 {
287 Parcel data, reply;
288 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800289 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800290 remote()->transact(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800291 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800292 }
293
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800294 virtual uint32_t latency(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800295 {
296 Parcel data, reply;
297 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800298 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800299 remote()->transact(LATENCY, data, &reply);
300 return reply.readInt32();
301 }
302
303 virtual status_t setMasterVolume(float value)
304 {
305 Parcel data, reply;
306 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
307 data.writeFloat(value);
308 remote()->transact(SET_MASTER_VOLUME, data, &reply);
309 return reply.readInt32();
310 }
311
312 virtual status_t setMasterMute(bool muted)
313 {
314 Parcel data, reply;
315 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
316 data.writeInt32(muted);
317 remote()->transact(SET_MASTER_MUTE, data, &reply);
318 return reply.readInt32();
319 }
320
321 virtual float masterVolume() const
322 {
323 Parcel data, reply;
324 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
325 remote()->transact(MASTER_VOLUME, data, &reply);
326 return reply.readFloat();
327 }
328
329 virtual bool masterMute() const
330 {
331 Parcel data, reply;
332 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
333 remote()->transact(MASTER_MUTE, data, &reply);
334 return reply.readInt32();
335 }
336
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800337 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
338 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800339 {
340 Parcel data, reply;
341 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800342 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800343 data.writeFloat(value);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800344 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800345 remote()->transact(SET_STREAM_VOLUME, data, &reply);
346 return reply.readInt32();
347 }
348
Glenn Kastenfff6d712012-01-12 16:38:12 -0800349 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800350 {
351 Parcel data, reply;
352 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800353 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800354 data.writeInt32(muted);
355 remote()->transact(SET_STREAM_MUTE, data, &reply);
356 return reply.readInt32();
357 }
358
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800359 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800360 {
361 Parcel data, reply;
362 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800363 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800364 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800365 remote()->transact(STREAM_VOLUME, data, &reply);
366 return reply.readFloat();
367 }
368
Glenn Kastenfff6d712012-01-12 16:38:12 -0800369 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800370 {
371 Parcel data, reply;
372 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800373 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800374 remote()->transact(STREAM_MUTE, data, &reply);
375 return reply.readInt32();
376 }
377
Glenn Kastenf78aee72012-01-04 11:00:47 -0800378 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800379 {
380 Parcel data, reply;
381 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
382 data.writeInt32(mode);
383 remote()->transact(SET_MODE, data, &reply);
384 return reply.readInt32();
385 }
386
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800387 virtual status_t setMicMute(bool state)
388 {
389 Parcel data, reply;
390 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
391 data.writeInt32(state);
392 remote()->transact(SET_MIC_MUTE, data, &reply);
393 return reply.readInt32();
394 }
395
396 virtual bool getMicMute() const
397 {
398 Parcel data, reply;
399 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
400 remote()->transact(GET_MIC_MUTE, data, &reply);
401 return reply.readInt32();
402 }
403
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800404 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800405 {
406 Parcel data, reply;
407 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800408 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700409 data.writeString8(keyValuePairs);
410 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800411 return reply.readInt32();
412 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700413
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800414 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700415 {
416 Parcel data, reply;
417 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800418 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700419 data.writeString8(keys);
420 remote()->transact(GET_PARAMETERS, data, &reply);
421 return reply.readString8();
422 }
423
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800424 virtual void registerClient(const sp<IAudioFlingerClient>& client)
425 {
426 Parcel data, reply;
427 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800428 data.writeStrongBinder(IInterface::asBinder(client));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800429 remote()->transact(REGISTER_CLIENT, data, &reply);
430 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700431
Glenn Kastendd8104c2012-07-02 12:42:44 -0700432 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
433 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800434 {
435 Parcel data, reply;
436 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
437 data.writeInt32(sampleRate);
438 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700439 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800440 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800441 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800442 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700443
Eric Laurentcf2c0212014-07-25 16:20:43 -0700444 virtual status_t openOutput(audio_module_handle_t module,
445 audio_io_handle_t *output,
446 audio_config_t *config,
447 audio_devices_t *devices,
448 const String8& address,
449 uint32_t *latencyMs,
450 audio_output_flags_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800451 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700452 if (output == NULL || config == NULL || devices == NULL || latencyMs == NULL) {
453 return BAD_VALUE;
454 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800455 Parcel data, reply;
456 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700457 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700458 data.write(config, sizeof(audio_config_t));
459 data.writeInt32(*devices);
460 data.writeString8(address);
Glenn Kasten18868c52012-03-07 09:15:37 -0800461 data.writeInt32((int32_t) flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700462 status_t status = remote()->transact(OPEN_OUTPUT, data, &reply);
463 if (status != NO_ERROR) {
464 *output = AUDIO_IO_HANDLE_NONE;
465 return status;
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100466 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700467 status = (status_t)reply.readInt32();
468 if (status != NO_ERROR) {
469 *output = AUDIO_IO_HANDLE_NONE;
470 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700471 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700472 *output = (audio_io_handle_t)reply.readInt32();
473 ALOGV("openOutput() returned output, %d", *output);
474 reply.read(config, sizeof(audio_config_t));
475 *devices = (audio_devices_t)reply.readInt32();
476 *latencyMs = reply.readInt32();
477 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800478 }
479
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800480 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
481 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800482 {
483 Parcel data, reply;
484 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800485 data.writeInt32((int32_t) output1);
486 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700487 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800488 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700489 }
490
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800491 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700492 {
493 Parcel data, reply;
494 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800495 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700496 remote()->transact(CLOSE_OUTPUT, data, &reply);
497 return reply.readInt32();
498 }
499
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800500 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700501 {
502 Parcel data, reply;
503 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800504 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700505 remote()->transact(SUSPEND_OUTPUT, data, &reply);
506 return reply.readInt32();
507 }
508
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800509 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700510 {
511 Parcel data, reply;
512 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800513 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700514 remote()->transact(RESTORE_OUTPUT, data, &reply);
515 return reply.readInt32();
516 }
517
Eric Laurentcf2c0212014-07-25 16:20:43 -0700518 virtual status_t openInput(audio_module_handle_t module,
519 audio_io_handle_t *input,
520 audio_config_t *config,
521 audio_devices_t *device,
522 const String8& address,
523 audio_source_t source,
524 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700525 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700526 if (input == NULL || config == NULL || device == NULL) {
527 return BAD_VALUE;
528 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700529 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700530 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700531 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700532 data.writeInt32(*input);
533 data.write(config, sizeof(audio_config_t));
534 data.writeInt32(*device);
535 data.writeString8(address);
536 data.writeInt32(source);
Glenn Kastenec40d282014-07-15 15:31:26 -0700537 data.writeInt32(flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700538 status_t status = remote()->transact(OPEN_INPUT, data, &reply);
539 if (status != NO_ERROR) {
540 *input = AUDIO_IO_HANDLE_NONE;
541 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700542 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700543 status = (status_t)reply.readInt32();
544 if (status != NO_ERROR) {
545 *input = AUDIO_IO_HANDLE_NONE;
546 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700547 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700548 *input = (audio_io_handle_t)reply.readInt32();
549 reply.read(config, sizeof(audio_config_t));
550 *device = (audio_devices_t)reply.readInt32();
551 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700552 }
553
Eric Laurentfa2877b2009-07-28 08:44:33 -0700554 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700555 {
556 Parcel data, reply;
557 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700558 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700559 remote()->transact(CLOSE_INPUT, data, &reply);
560 return reply.readInt32();
561 }
562
Glenn Kastend2304db2014-02-03 07:40:31 -0800563 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700564 {
565 Parcel data, reply;
566 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800567 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800568 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700569 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800570 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700571
572 virtual status_t setVoiceVolume(float volume)
573 {
574 Parcel data, reply;
575 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
576 data.writeFloat(volume);
577 remote()->transact(SET_VOICE_VOLUME, data, &reply);
578 return reply.readInt32();
579 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800580
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000581 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800582 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800583 {
584 Parcel data, reply;
585 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800586 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800587 remote()->transact(GET_RENDER_POSITION, data, &reply);
588 status_t status = reply.readInt32();
589 if (status == NO_ERROR) {
590 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700591 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800592 *halFrames = tmp;
593 }
594 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700595 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800596 *dspFrames = tmp;
597 }
598 }
599 return status;
600 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800601
Glenn Kasten5f972c02014-01-13 09:59:31 -0800602 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800603 {
604 Parcel data, reply;
605 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800606 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800607 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
608 if (status != NO_ERROR) {
609 return 0;
610 }
611 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800612 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700613
Eric Laurentde3f8392014-07-27 18:38:22 -0700614 virtual audio_unique_id_t newAudioUniqueId()
Eric Laurentbe916aa2010-06-01 23:49:17 -0700615 {
616 Parcel data, reply;
617 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
618 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
Eric Laurentde3f8392014-07-27 18:38:22 -0700619 audio_unique_id_t id = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700620 if (status == NO_ERROR) {
621 id = reply.readInt32();
622 }
623 return id;
624 }
625
Marco Nelissend457c972014-02-11 08:47:07 -0800626 virtual void acquireAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700627 {
628 Parcel data, reply;
629 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
630 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800631 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700632 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
633 }
634
Marco Nelissend457c972014-02-11 08:47:07 -0800635 virtual void releaseAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700636 {
637 Parcel data, reply;
638 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
639 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800640 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700641 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
642 }
643
Glenn Kastenf587ba52012-01-26 16:25:10 -0800644 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700645 {
646 Parcel data, reply;
647 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
648 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
649 if (status != NO_ERROR) {
650 return status;
651 }
652 status = reply.readInt32();
653 if (status != NO_ERROR) {
654 return status;
655 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800656 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700657 *numEffects = (uint32_t)reply.readInt32();
658 }
659 return NO_ERROR;
660 }
661
Glenn Kastenf587ba52012-01-26 16:25:10 -0800662 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700663 {
664 if (pDescriptor == NULL) {
665 return BAD_VALUE;
666 }
667 Parcel data, reply;
668 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700669 data.writeInt32(index);
670 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700671 if (status != NO_ERROR) {
672 return status;
673 }
674 status = reply.readInt32();
675 if (status != NO_ERROR) {
676 return status;
677 }
678 reply.read(pDescriptor, sizeof(effect_descriptor_t));
679 return NO_ERROR;
680 }
681
Glenn Kasten5e92a782012-01-30 07:40:52 -0800682 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800683 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700684 {
685 if (pUuid == NULL || pDescriptor == NULL) {
686 return BAD_VALUE;
687 }
688 Parcel data, reply;
689 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
690 data.write(pUuid, sizeof(effect_uuid_t));
691 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
692 if (status != NO_ERROR) {
693 return status;
694 }
695 status = reply.readInt32();
696 if (status != NO_ERROR) {
697 return status;
698 }
699 reply.read(pDescriptor, sizeof(effect_descriptor_t));
700 return NO_ERROR;
701 }
702
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800703 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700704 effect_descriptor_t *pDesc,
705 const sp<IEffectClient>& client,
706 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800707 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700708 int sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700709 const String16& opPackageName,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700710 status_t *status,
711 int *id,
712 int *enabled)
713 {
714 Parcel data, reply;
715 sp<IEffect> effect;
716
717 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700718 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700719 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700720 *status = BAD_VALUE;
721 }
722 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700723
724 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700725 data.write(pDesc, sizeof(effect_descriptor_t));
Marco Nelissen06b46062014-11-14 07:58:25 -0800726 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700727 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800728 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700729 data.writeInt32(sessionId);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700730 data.writeString16(opPackageName);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700731
732 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
733 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000734 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700735 } else {
736 lStatus = reply.readInt32();
737 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700738 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700739 *id = tmp;
740 }
741 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800742 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700743 *enabled = tmp;
744 }
745 effect = interface_cast<IEffect>(reply.readStrongBinder());
746 reply.read(pDesc, sizeof(effect_descriptor_t));
747 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700748 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700749 *status = lStatus;
750 }
751
752 return effect;
753 }
Eric Laurentde070132010-07-13 04:45:46 -0700754
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800755 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
756 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700757 {
758 Parcel data, reply;
759 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
760 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800761 data.writeInt32((int32_t) srcOutput);
762 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700763 remote()->transact(MOVE_EFFECTS, data, &reply);
764 return reply.readInt32();
765 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700766
767 virtual audio_module_handle_t loadHwModule(const char *name)
768 {
769 Parcel data, reply;
770 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
771 data.writeCString(name);
772 remote()->transact(LOAD_HW_MODULE, data, &reply);
773 return (audio_module_handle_t) reply.readInt32();
774 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700775
Glenn Kasten3b16c762012-11-14 08:44:39 -0800776 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700777 {
778 Parcel data, reply;
779 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
780 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
781 return reply.readInt32();
782 }
783
Glenn Kastene33054e2012-11-14 12:54:39 -0800784 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700785 {
786 Parcel data, reply;
787 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
788 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800789 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700790 }
791
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700792 virtual status_t setLowRamDevice(bool isLowRamDevice)
793 {
794 Parcel data, reply;
795 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
796 data.writeInt32((int) isLowRamDevice);
797 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
798 return reply.readInt32();
799 }
Eric Laurent4b123402014-04-11 09:22:20 -0700800 virtual status_t listAudioPorts(unsigned int *num_ports,
801 struct audio_port *ports)
802 {
803 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
804 return BAD_VALUE;
805 }
806 Parcel data, reply;
807 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
808 data.writeInt32(*num_ports);
809 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
810 if (status != NO_ERROR ||
811 (status = (status_t)reply.readInt32()) != NO_ERROR) {
812 return status;
813 }
814 *num_ports = (unsigned int)reply.readInt32();
815 reply.read(ports, *num_ports * sizeof(struct audio_port));
816 return status;
817 }
818 virtual status_t getAudioPort(struct audio_port *port)
819 {
820 if (port == NULL) {
821 return BAD_VALUE;
822 }
823 Parcel data, reply;
824 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
825 data.write(port, sizeof(struct audio_port));
826 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
827 if (status != NO_ERROR ||
828 (status = (status_t)reply.readInt32()) != NO_ERROR) {
829 return status;
830 }
831 reply.read(port, sizeof(struct audio_port));
832 return status;
833 }
834 virtual status_t createAudioPatch(const struct audio_patch *patch,
835 audio_patch_handle_t *handle)
836 {
837 if (patch == NULL || handle == NULL) {
838 return BAD_VALUE;
839 }
840 Parcel data, reply;
841 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
842 data.write(patch, sizeof(struct audio_patch));
843 data.write(handle, sizeof(audio_patch_handle_t));
844 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
845 if (status != NO_ERROR ||
846 (status = (status_t)reply.readInt32()) != NO_ERROR) {
847 return status;
848 }
849 reply.read(handle, sizeof(audio_patch_handle_t));
850 return status;
851 }
852 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
853 {
854 Parcel data, reply;
855 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
856 data.write(&handle, sizeof(audio_patch_handle_t));
857 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
858 if (status != NO_ERROR) {
859 status = (status_t)reply.readInt32();
860 }
861 return status;
862 }
863 virtual status_t listAudioPatches(unsigned int *num_patches,
864 struct audio_patch *patches)
865 {
866 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
867 return BAD_VALUE;
868 }
869 Parcel data, reply;
870 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
871 data.writeInt32(*num_patches);
872 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
873 if (status != NO_ERROR ||
874 (status = (status_t)reply.readInt32()) != NO_ERROR) {
875 return status;
876 }
877 *num_patches = (unsigned int)reply.readInt32();
878 reply.read(patches, *num_patches * sizeof(struct audio_patch));
879 return status;
880 }
881 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
882 {
883 if (config == NULL) {
884 return BAD_VALUE;
885 }
886 Parcel data, reply;
887 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
888 data.write(config, sizeof(struct audio_port_config));
889 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
890 if (status != NO_ERROR) {
891 status = (status_t)reply.readInt32();
892 }
893 return status;
894 }
Eric Laurent93c3d412014-08-01 14:48:35 -0700895 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
896 {
897 Parcel data, reply;
898 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
899 data.writeInt32(sessionId);
900 status_t status = remote()->transact(GET_AUDIO_HW_SYNC, data, &reply);
901 if (status != NO_ERROR) {
902 return AUDIO_HW_SYNC_INVALID;
903 }
904 return (audio_hw_sync_t)reply.readInt32();
905 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800906};
907
908IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
909
910// ----------------------------------------------------------------------
911
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800912status_t BnAudioFlinger::onTransact(
913 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
914{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700915 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800916 case CREATE_TRACK: {
917 CHECK_INTERFACE(IAudioFlinger, data, reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800918 int streamType = data.readInt32();
919 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800920 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700921 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800922 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800923 track_flags_t flags = (track_flags_t) data.readInt32();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700924 bool haveSharedBuffer = data.readInt32() != 0;
925 sp<IMemory> buffer;
926 if (haveSharedBuffer) {
927 buffer = interface_cast<IMemory>(data.readStrongBinder());
928 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800929 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kasten3acbd052012-02-28 10:39:56 -0800930 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700931 int sessionId = data.readInt32();
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800932 int clientUid = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800933 status_t status;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700934 sp<IAudioTrack> track;
935 if ((haveSharedBuffer && (buffer == 0)) ||
936 ((buffer != 0) && (buffer->pointer() == NULL))) {
937 ALOGW("CREATE_TRACK: cannot retrieve shared memory");
938 status = DEAD_OBJECT;
939 } else {
940 track = createTrack(
941 (audio_stream_type_t) streamType, sampleRate, format,
Glenn Kasten74935e42013-12-19 08:56:45 -0800942 channelMask, &frameCount, &flags, buffer, output, tid,
Glenn Kastenc5a17422014-03-13 14:59:59 -0700943 &sessionId, clientUid, &status);
Glenn Kasten0cde0762014-01-16 15:06:36 -0800944 LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700945 }
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700946 reply->writeInt64(frameCount);
Glenn Kastene0b07172012-11-06 15:03:34 -0800947 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700948 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800949 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800950 reply->writeStrongBinder(IInterface::asBinder(track));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800951 return NO_ERROR;
952 } break;
953 case OPEN_RECORD: {
954 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800955 audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800956 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800957 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700958 audio_channel_mask_t channelMask = data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -0700959 const String16& opPackageName = data.readString16();
Glenn Kastene03dd222014-01-28 11:04:39 -0800960 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800961 track_flags_t flags = (track_flags_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700962 pid_t tid = (pid_t) data.readInt32();
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700963 int clientUid = data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700964 int sessionId = data.readInt32();
Glenn Kasten74105912014-07-03 12:28:53 -0700965 size_t notificationFrames = data.readInt64();
Glenn Kastend776ac62014-05-07 09:16:09 -0700966 sp<IMemory> cblk;
967 sp<IMemory> buffers;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800968 status_t status;
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800969 sp<IAudioRecord> record = openRecord(input,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700970 sampleRate, format, channelMask, opPackageName, &frameCount, &flags, tid,
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700971 clientUid, &sessionId, &notificationFrames, cblk, buffers, &status);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700972 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700973 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700974 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700975 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700976 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800977 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800978 reply->writeStrongBinder(IInterface::asBinder(record));
979 reply->writeStrongBinder(IInterface::asBinder(cblk));
980 reply->writeStrongBinder(IInterface::asBinder(buffers));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800981 return NO_ERROR;
982 } break;
983 case SAMPLE_RATE: {
984 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800985 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800986 return NO_ERROR;
987 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800988 case FORMAT: {
989 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800990 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800991 return NO_ERROR;
992 } break;
993 case FRAME_COUNT: {
994 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800995 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800996 return NO_ERROR;
997 } break;
998 case LATENCY: {
999 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001000 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001001 return NO_ERROR;
1002 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001003 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001004 CHECK_INTERFACE(IAudioFlinger, data, reply);
1005 reply->writeInt32( setMasterVolume(data.readFloat()) );
1006 return NO_ERROR;
1007 } break;
1008 case SET_MASTER_MUTE: {
1009 CHECK_INTERFACE(IAudioFlinger, data, reply);
1010 reply->writeInt32( setMasterMute(data.readInt32()) );
1011 return NO_ERROR;
1012 } break;
1013 case MASTER_VOLUME: {
1014 CHECK_INTERFACE(IAudioFlinger, data, reply);
1015 reply->writeFloat( masterVolume() );
1016 return NO_ERROR;
1017 } break;
1018 case MASTER_MUTE: {
1019 CHECK_INTERFACE(IAudioFlinger, data, reply);
1020 reply->writeInt32( masterMute() );
1021 return NO_ERROR;
1022 } break;
1023 case SET_STREAM_VOLUME: {
1024 CHECK_INTERFACE(IAudioFlinger, data, reply);
1025 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001026 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001027 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001028 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001029 return NO_ERROR;
1030 } break;
1031 case SET_STREAM_MUTE: {
1032 CHECK_INTERFACE(IAudioFlinger, data, reply);
1033 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001034 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001035 return NO_ERROR;
1036 } break;
1037 case STREAM_VOLUME: {
1038 CHECK_INTERFACE(IAudioFlinger, data, reply);
1039 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001040 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001041 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001042 return NO_ERROR;
1043 } break;
1044 case STREAM_MUTE: {
1045 CHECK_INTERFACE(IAudioFlinger, data, reply);
1046 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001047 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001048 return NO_ERROR;
1049 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001050 case SET_MODE: {
1051 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001052 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001053 reply->writeInt32( setMode(mode) );
1054 return NO_ERROR;
1055 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001056 case SET_MIC_MUTE: {
1057 CHECK_INTERFACE(IAudioFlinger, data, reply);
1058 int state = data.readInt32();
1059 reply->writeInt32( setMicMute(state) );
1060 return NO_ERROR;
1061 } break;
1062 case GET_MIC_MUTE: {
1063 CHECK_INTERFACE(IAudioFlinger, data, reply);
1064 reply->writeInt32( getMicMute() );
1065 return NO_ERROR;
1066 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001067 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001068 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001069 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001070 String8 keyValuePairs(data.readString8());
1071 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001072 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001073 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001074 case GET_PARAMETERS: {
1075 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001076 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001077 String8 keys(data.readString8());
1078 reply->writeString8(getParameters(ioHandle, keys));
1079 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001080 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001081
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001082 case REGISTER_CLIENT: {
1083 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001084 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1085 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001086 registerClient(client);
1087 return NO_ERROR;
1088 } break;
1089 case GET_INPUTBUFFERSIZE: {
1090 CHECK_INTERFACE(IAudioFlinger, data, reply);
1091 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001092 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001093 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001094 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001095 return NO_ERROR;
1096 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001097 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001098 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001099 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001100 audio_config_t config;
1101 data.read(&config, sizeof(audio_config_t));
Eric Laurenta4c5a552012-03-29 10:12:40 -07001102 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001103 String8 address(data.readString8());
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001104 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001105 uint32_t latencyMs;
1106 audio_io_handle_t output;
1107 status_t status = openOutput(module, &output, &config,
1108 &devices, address, &latencyMs, flags);
Glenn Kasten70742962014-02-18 08:00:47 -08001109 ALOGV("OPEN_OUTPUT output, %d", output);
Eric Laurentcf2c0212014-07-25 16:20:43 -07001110 reply->writeInt32((int32_t)status);
1111 if (status == NO_ERROR) {
1112 reply->writeInt32((int32_t)output);
1113 reply->write(&config, sizeof(audio_config_t));
1114 reply->writeInt32(devices);
1115 reply->writeInt32(latencyMs);
1116 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001117 return NO_ERROR;
1118 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001119 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001120 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001121 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1122 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1123 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001124 return NO_ERROR;
1125 } break;
1126 case CLOSE_OUTPUT: {
1127 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001128 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001129 return NO_ERROR;
1130 } break;
1131 case SUSPEND_OUTPUT: {
1132 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001133 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001134 return NO_ERROR;
1135 } break;
1136 case RESTORE_OUTPUT: {
1137 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001138 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001139 return NO_ERROR;
1140 } break;
1141 case OPEN_INPUT: {
1142 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001143 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001144 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
1145 audio_config_t config;
1146 data.read(&config, sizeof(audio_config_t));
1147 audio_devices_t device = (audio_devices_t)data.readInt32();
1148 String8 address(data.readString8());
1149 audio_source_t source = (audio_source_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001150 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001151
Eric Laurentcf2c0212014-07-25 16:20:43 -07001152 status_t status = openInput(module, &input, &config,
1153 &device, address, source, flags);
1154 reply->writeInt32((int32_t) status);
1155 if (status == NO_ERROR) {
1156 reply->writeInt32((int32_t) input);
1157 reply->write(&config, sizeof(audio_config_t));
1158 reply->writeInt32(device);
1159 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001160 return NO_ERROR;
1161 } break;
1162 case CLOSE_INPUT: {
1163 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001164 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001165 return NO_ERROR;
1166 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001167 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001168 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001169 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1170 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001171 return NO_ERROR;
1172 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001173 case SET_VOICE_VOLUME: {
1174 CHECK_INTERFACE(IAudioFlinger, data, reply);
1175 float volume = data.readFloat();
1176 reply->writeInt32( setVoiceVolume(volume) );
1177 return NO_ERROR;
1178 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001179 case GET_RENDER_POSITION: {
1180 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001181 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001182 uint32_t halFrames;
1183 uint32_t dspFrames;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001184 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1185 reply->writeInt32(status);
1186 if (status == NO_ERROR) {
1187 reply->writeInt32(halFrames);
1188 reply->writeInt32(dspFrames);
1189 }
1190 return NO_ERROR;
1191 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001192 case GET_INPUT_FRAMES_LOST: {
1193 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001194 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001195 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001196 return NO_ERROR;
1197 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001198 case NEW_AUDIO_SESSION_ID: {
1199 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentde3f8392014-07-27 18:38:22 -07001200 reply->writeInt32(newAudioUniqueId());
Eric Laurentbe916aa2010-06-01 23:49:17 -07001201 return NO_ERROR;
1202 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001203 case ACQUIRE_AUDIO_SESSION_ID: {
1204 CHECK_INTERFACE(IAudioFlinger, data, reply);
1205 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001206 int pid = data.readInt32();
1207 acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001208 return NO_ERROR;
1209 } break;
1210 case RELEASE_AUDIO_SESSION_ID: {
1211 CHECK_INTERFACE(IAudioFlinger, data, reply);
1212 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001213 int pid = data.readInt32();
1214 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001215 return NO_ERROR;
1216 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001217 case QUERY_NUM_EFFECTS: {
1218 CHECK_INTERFACE(IAudioFlinger, data, reply);
1219 uint32_t numEffects;
1220 status_t status = queryNumberEffects(&numEffects);
1221 reply->writeInt32(status);
1222 if (status == NO_ERROR) {
1223 reply->writeInt32((int32_t)numEffects);
1224 }
1225 return NO_ERROR;
1226 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001227 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001228 CHECK_INTERFACE(IAudioFlinger, data, reply);
1229 effect_descriptor_t desc;
Eric Laurentffe9c252010-06-23 17:38:20 -07001230 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001231 reply->writeInt32(status);
1232 if (status == NO_ERROR) {
1233 reply->write(&desc, sizeof(effect_descriptor_t));
1234 }
1235 return NO_ERROR;
1236 }
1237 case GET_EFFECT_DESCRIPTOR: {
1238 CHECK_INTERFACE(IAudioFlinger, data, reply);
1239 effect_uuid_t uuid;
1240 data.read(&uuid, sizeof(effect_uuid_t));
1241 effect_descriptor_t desc;
1242 status_t status = getEffectDescriptor(&uuid, &desc);
1243 reply->writeInt32(status);
1244 if (status == NO_ERROR) {
1245 reply->write(&desc, sizeof(effect_descriptor_t));
1246 }
1247 return NO_ERROR;
1248 }
1249 case CREATE_EFFECT: {
1250 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001251 effect_descriptor_t desc;
1252 data.read(&desc, sizeof(effect_descriptor_t));
1253 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1254 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001255 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -07001256 int sessionId = data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -07001257 const String16 opPackageName = data.readString16();
Eric Laurentbe916aa2010-06-01 23:49:17 -07001258 status_t status;
1259 int id;
1260 int enabled;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001261
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001262 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -07001263 opPackageName, &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001264 reply->writeInt32(status);
1265 reply->writeInt32(id);
1266 reply->writeInt32(enabled);
Marco Nelissen06b46062014-11-14 07:58:25 -08001267 reply->writeStrongBinder(IInterface::asBinder(effect));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001268 reply->write(&desc, sizeof(effect_descriptor_t));
1269 return NO_ERROR;
1270 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001271 case MOVE_EFFECTS: {
1272 CHECK_INTERFACE(IAudioFlinger, data, reply);
1273 int session = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001274 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1275 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001276 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1277 return NO_ERROR;
1278 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001279 case LOAD_HW_MODULE: {
1280 CHECK_INTERFACE(IAudioFlinger, data, reply);
1281 reply->writeInt32(loadHwModule(data.readCString()));
1282 return NO_ERROR;
1283 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001284 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1285 CHECK_INTERFACE(IAudioFlinger, data, reply);
1286 reply->writeInt32(getPrimaryOutputSamplingRate());
1287 return NO_ERROR;
1288 } break;
1289 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1290 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001291 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001292 return NO_ERROR;
1293 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001294 case SET_LOW_RAM_DEVICE: {
1295 CHECK_INTERFACE(IAudioFlinger, data, reply);
1296 bool isLowRamDevice = data.readInt32() != 0;
1297 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1298 return NO_ERROR;
1299 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001300 case LIST_AUDIO_PORTS: {
1301 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001302 unsigned int numPortsReq = data.readInt32();
1303 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1304 numPortsReq = MAX_ITEMS_PER_LIST;
1305 }
1306 unsigned int numPorts = numPortsReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001307 struct audio_port *ports =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001308 (struct audio_port *)calloc(numPortsReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001309 sizeof(struct audio_port));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001310 if (ports == NULL) {
1311 reply->writeInt32(NO_MEMORY);
1312 reply->writeInt32(0);
1313 return NO_ERROR;
1314 }
1315 status_t status = listAudioPorts(&numPorts, ports);
Eric Laurent4b123402014-04-11 09:22:20 -07001316 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001317 reply->writeInt32(numPorts);
Eric Laurent4b123402014-04-11 09:22:20 -07001318 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001319 if (numPortsReq > numPorts) {
1320 numPortsReq = numPorts;
1321 }
1322 reply->write(ports, numPortsReq * sizeof(struct audio_port));
Eric Laurent4b123402014-04-11 09:22:20 -07001323 }
1324 free(ports);
1325 return NO_ERROR;
1326 } break;
1327 case GET_AUDIO_PORT: {
1328 CHECK_INTERFACE(IAudioFlinger, data, reply);
1329 struct audio_port port;
1330 data.read(&port, sizeof(struct audio_port));
1331 status_t status = getAudioPort(&port);
1332 reply->writeInt32(status);
1333 if (status == NO_ERROR) {
1334 reply->write(&port, sizeof(struct audio_port));
1335 }
1336 return NO_ERROR;
1337 } break;
1338 case CREATE_AUDIO_PATCH: {
1339 CHECK_INTERFACE(IAudioFlinger, data, reply);
1340 struct audio_patch patch;
1341 data.read(&patch, sizeof(struct audio_patch));
1342 audio_patch_handle_t handle;
1343 data.read(&handle, sizeof(audio_patch_handle_t));
1344 status_t status = createAudioPatch(&patch, &handle);
1345 reply->writeInt32(status);
1346 if (status == NO_ERROR) {
1347 reply->write(&handle, sizeof(audio_patch_handle_t));
1348 }
1349 return NO_ERROR;
1350 } break;
1351 case RELEASE_AUDIO_PATCH: {
1352 CHECK_INTERFACE(IAudioFlinger, data, reply);
1353 audio_patch_handle_t handle;
1354 data.read(&handle, sizeof(audio_patch_handle_t));
1355 status_t status = releaseAudioPatch(handle);
1356 reply->writeInt32(status);
1357 return NO_ERROR;
1358 } break;
1359 case LIST_AUDIO_PATCHES: {
1360 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001361 unsigned int numPatchesReq = data.readInt32();
1362 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1363 numPatchesReq = MAX_ITEMS_PER_LIST;
1364 }
1365 unsigned int numPatches = numPatchesReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001366 struct audio_patch *patches =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001367 (struct audio_patch *)calloc(numPatchesReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001368 sizeof(struct audio_patch));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001369 if (patches == NULL) {
1370 reply->writeInt32(NO_MEMORY);
1371 reply->writeInt32(0);
1372 return NO_ERROR;
1373 }
1374 status_t status = listAudioPatches(&numPatches, patches);
Eric Laurent4b123402014-04-11 09:22:20 -07001375 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001376 reply->writeInt32(numPatches);
Eric Laurent4b123402014-04-11 09:22:20 -07001377 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001378 if (numPatchesReq > numPatches) {
1379 numPatchesReq = numPatches;
1380 }
1381 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
Eric Laurent4b123402014-04-11 09:22:20 -07001382 }
1383 free(patches);
1384 return NO_ERROR;
1385 } break;
1386 case SET_AUDIO_PORT_CONFIG: {
1387 CHECK_INTERFACE(IAudioFlinger, data, reply);
1388 struct audio_port_config config;
1389 data.read(&config, sizeof(struct audio_port_config));
1390 status_t status = setAudioPortConfig(&config);
1391 reply->writeInt32(status);
1392 return NO_ERROR;
1393 } break;
Eric Laurent93c3d412014-08-01 14:48:35 -07001394 case GET_AUDIO_HW_SYNC: {
1395 CHECK_INTERFACE(IAudioFlinger, data, reply);
1396 reply->writeInt32(getAudioHwSyncForSession((audio_session_t)data.readInt32()));
1397 return NO_ERROR;
1398 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001399 default:
1400 return BBinder::onTransact(code, data, reply, flags);
1401 }
1402}
1403
1404// ----------------------------------------------------------------------------
1405
Glenn Kasten40bc9062015-03-20 09:09:33 -07001406} // namespace android