blob: d48532e11d99f21c9dfa8a2e728b4f908c86b5d7 [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,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700181 int *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700182 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700183 sp<IMemory>& cblk,
184 sp<IMemory>& buffers,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800185 status_t *status)
186 {
187 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700188 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800189 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800190 data.writeInt32((int32_t) input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800191 data.writeInt32(sampleRate);
192 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700193 data.writeInt32(channelMask);
Dianne Hackborneaa34702015-04-29 12:57:58 -0700194 data.writeString16(opPackageName);
Glenn Kasten74935e42013-12-19 08:56:45 -0800195 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800196 data.writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700197 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
198 data.writeInt32(lFlags);
Glenn Kasten1879fff2012-07-11 15:36:59 -0700199 data.writeInt32((int32_t) tid);
Glenn Kastenaea7ea02013-06-26 09:25:47 -0700200 int lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700201 if (sessionId != NULL) {
202 lSessionId = *sessionId;
203 }
204 data.writeInt32(lSessionId);
Glenn Kasten74105912014-07-03 12:28:53 -0700205 data.writeInt64(notificationFrames != NULL ? *notificationFrames : 0);
Glenn Kastend776ac62014-05-07 09:16:09 -0700206 cblk.clear();
207 buffers.clear();
Eric Laurent5841db72009-09-09 05:16:08 -0700208 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
209 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000210 ALOGE("openRecord error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700211 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700212 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800213 if (pFrameCount != NULL) {
214 *pFrameCount = frameCount;
215 }
Glenn Kasteneeca3262013-07-31 16:12:48 -0700216 lFlags = reply.readInt32();
217 if (flags != NULL) {
218 *flags = lFlags;
219 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700220 lSessionId = reply.readInt32();
221 if (sessionId != NULL) {
222 *sessionId = lSessionId;
223 }
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700224 size_t lNotificationFrames = (size_t) reply.readInt64();
225 if (notificationFrames != NULL) {
226 *notificationFrames = lNotificationFrames;
227 }
Eric Laurent5841db72009-09-09 05:16:08 -0700228 lStatus = reply.readInt32();
229 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700230 cblk = interface_cast<IMemory>(reply.readStrongBinder());
231 if (cblk != 0 && cblk->pointer() == NULL) {
232 cblk.clear();
233 }
234 buffers = interface_cast<IMemory>(reply.readStrongBinder());
235 if (buffers != 0 && buffers->pointer() == NULL) {
236 buffers.clear();
237 }
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700238 if (lStatus == NO_ERROR) {
239 if (record == 0) {
240 ALOGE("openRecord should have returned an IAudioRecord");
241 lStatus = UNKNOWN_ERROR;
Glenn Kastend776ac62014-05-07 09:16:09 -0700242 } else if (cblk == 0) {
243 ALOGE("openRecord should have returned a cblk");
244 lStatus = NO_MEMORY;
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700245 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700246 // buffers is permitted to be 0
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700247 } else {
Glenn Kastend776ac62014-05-07 09:16:09 -0700248 if (record != 0 || cblk != 0 || buffers != 0) {
249 ALOGE("openRecord returned an IAudioRecord, cblk, "
250 "or buffers but with status %d", lStatus);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700251 }
252 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700253 if (lStatus != NO_ERROR) {
254 record.clear();
255 cblk.clear();
256 buffers.clear();
257 }
Eric Laurent5841db72009-09-09 05:16:08 -0700258 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700259 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800260 *status = lStatus;
261 }
Eric Laurent5841db72009-09-09 05:16:08 -0700262 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800263 }
264
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800265 virtual uint32_t sampleRate(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800266 {
267 Parcel data, reply;
268 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800269 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800270 remote()->transact(SAMPLE_RATE, data, &reply);
271 return reply.readInt32();
272 }
273
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800274 virtual audio_format_t format(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800275 {
276 Parcel data, reply;
277 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800278 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800279 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800280 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800281 }
282
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800283 virtual size_t frameCount(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800284 {
285 Parcel data, reply;
286 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800287 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800288 remote()->transact(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800289 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800290 }
291
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800292 virtual uint32_t latency(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800293 {
294 Parcel data, reply;
295 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800296 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800297 remote()->transact(LATENCY, data, &reply);
298 return reply.readInt32();
299 }
300
301 virtual status_t setMasterVolume(float value)
302 {
303 Parcel data, reply;
304 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
305 data.writeFloat(value);
306 remote()->transact(SET_MASTER_VOLUME, data, &reply);
307 return reply.readInt32();
308 }
309
310 virtual status_t setMasterMute(bool muted)
311 {
312 Parcel data, reply;
313 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
314 data.writeInt32(muted);
315 remote()->transact(SET_MASTER_MUTE, data, &reply);
316 return reply.readInt32();
317 }
318
319 virtual float masterVolume() const
320 {
321 Parcel data, reply;
322 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
323 remote()->transact(MASTER_VOLUME, data, &reply);
324 return reply.readFloat();
325 }
326
327 virtual bool masterMute() const
328 {
329 Parcel data, reply;
330 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
331 remote()->transact(MASTER_MUTE, data, &reply);
332 return reply.readInt32();
333 }
334
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800335 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
336 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800337 {
338 Parcel data, reply;
339 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800340 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800341 data.writeFloat(value);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800342 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800343 remote()->transact(SET_STREAM_VOLUME, data, &reply);
344 return reply.readInt32();
345 }
346
Glenn Kastenfff6d712012-01-12 16:38:12 -0800347 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800348 {
349 Parcel data, reply;
350 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800351 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800352 data.writeInt32(muted);
353 remote()->transact(SET_STREAM_MUTE, data, &reply);
354 return reply.readInt32();
355 }
356
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800357 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800358 {
359 Parcel data, reply;
360 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800361 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800362 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800363 remote()->transact(STREAM_VOLUME, data, &reply);
364 return reply.readFloat();
365 }
366
Glenn Kastenfff6d712012-01-12 16:38:12 -0800367 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800368 {
369 Parcel data, reply;
370 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800371 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800372 remote()->transact(STREAM_MUTE, data, &reply);
373 return reply.readInt32();
374 }
375
Glenn Kastenf78aee72012-01-04 11:00:47 -0800376 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800377 {
378 Parcel data, reply;
379 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
380 data.writeInt32(mode);
381 remote()->transact(SET_MODE, data, &reply);
382 return reply.readInt32();
383 }
384
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800385 virtual status_t setMicMute(bool state)
386 {
387 Parcel data, reply;
388 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
389 data.writeInt32(state);
390 remote()->transact(SET_MIC_MUTE, data, &reply);
391 return reply.readInt32();
392 }
393
394 virtual bool getMicMute() const
395 {
396 Parcel data, reply;
397 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
398 remote()->transact(GET_MIC_MUTE, data, &reply);
399 return reply.readInt32();
400 }
401
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800402 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800403 {
404 Parcel data, reply;
405 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800406 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700407 data.writeString8(keyValuePairs);
408 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800409 return reply.readInt32();
410 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700411
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800412 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700413 {
414 Parcel data, reply;
415 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800416 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700417 data.writeString8(keys);
418 remote()->transact(GET_PARAMETERS, data, &reply);
419 return reply.readString8();
420 }
421
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800422 virtual void registerClient(const sp<IAudioFlingerClient>& client)
423 {
424 Parcel data, reply;
425 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800426 data.writeStrongBinder(IInterface::asBinder(client));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800427 remote()->transact(REGISTER_CLIENT, data, &reply);
428 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700429
Glenn Kastendd8104c2012-07-02 12:42:44 -0700430 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
431 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800432 {
433 Parcel data, reply;
434 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
435 data.writeInt32(sampleRate);
436 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700437 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800438 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800439 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800440 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700441
Eric Laurentcf2c0212014-07-25 16:20:43 -0700442 virtual status_t openOutput(audio_module_handle_t module,
443 audio_io_handle_t *output,
444 audio_config_t *config,
445 audio_devices_t *devices,
446 const String8& address,
447 uint32_t *latencyMs,
448 audio_output_flags_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800449 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700450 if (output == NULL || config == NULL || devices == NULL || latencyMs == NULL) {
451 return BAD_VALUE;
452 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800453 Parcel data, reply;
454 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700455 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700456 data.write(config, sizeof(audio_config_t));
457 data.writeInt32(*devices);
458 data.writeString8(address);
Glenn Kasten18868c52012-03-07 09:15:37 -0800459 data.writeInt32((int32_t) flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700460 status_t status = remote()->transact(OPEN_OUTPUT, data, &reply);
461 if (status != NO_ERROR) {
462 *output = AUDIO_IO_HANDLE_NONE;
463 return status;
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100464 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700465 status = (status_t)reply.readInt32();
466 if (status != NO_ERROR) {
467 *output = AUDIO_IO_HANDLE_NONE;
468 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700469 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700470 *output = (audio_io_handle_t)reply.readInt32();
471 ALOGV("openOutput() returned output, %d", *output);
472 reply.read(config, sizeof(audio_config_t));
473 *devices = (audio_devices_t)reply.readInt32();
474 *latencyMs = reply.readInt32();
475 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800476 }
477
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800478 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
479 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800480 {
481 Parcel data, reply;
482 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800483 data.writeInt32((int32_t) output1);
484 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700485 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800486 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700487 }
488
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800489 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700490 {
491 Parcel data, reply;
492 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800493 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700494 remote()->transact(CLOSE_OUTPUT, data, &reply);
495 return reply.readInt32();
496 }
497
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800498 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700499 {
500 Parcel data, reply;
501 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800502 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700503 remote()->transact(SUSPEND_OUTPUT, data, &reply);
504 return reply.readInt32();
505 }
506
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800507 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700508 {
509 Parcel data, reply;
510 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800511 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700512 remote()->transact(RESTORE_OUTPUT, data, &reply);
513 return reply.readInt32();
514 }
515
Eric Laurentcf2c0212014-07-25 16:20:43 -0700516 virtual status_t openInput(audio_module_handle_t module,
517 audio_io_handle_t *input,
518 audio_config_t *config,
519 audio_devices_t *device,
520 const String8& address,
521 audio_source_t source,
522 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700523 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700524 if (input == NULL || config == NULL || device == NULL) {
525 return BAD_VALUE;
526 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700527 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700528 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700529 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700530 data.writeInt32(*input);
531 data.write(config, sizeof(audio_config_t));
532 data.writeInt32(*device);
533 data.writeString8(address);
534 data.writeInt32(source);
Glenn Kastenec40d282014-07-15 15:31:26 -0700535 data.writeInt32(flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700536 status_t status = remote()->transact(OPEN_INPUT, data, &reply);
537 if (status != NO_ERROR) {
538 *input = AUDIO_IO_HANDLE_NONE;
539 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700540 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700541 status = (status_t)reply.readInt32();
542 if (status != NO_ERROR) {
543 *input = AUDIO_IO_HANDLE_NONE;
544 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700545 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700546 *input = (audio_io_handle_t)reply.readInt32();
547 reply.read(config, sizeof(audio_config_t));
548 *device = (audio_devices_t)reply.readInt32();
549 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700550 }
551
Eric Laurentfa2877b2009-07-28 08:44:33 -0700552 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700553 {
554 Parcel data, reply;
555 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700556 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700557 remote()->transact(CLOSE_INPUT, data, &reply);
558 return reply.readInt32();
559 }
560
Glenn Kastend2304db2014-02-03 07:40:31 -0800561 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700562 {
563 Parcel data, reply;
564 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800565 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800566 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700567 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800568 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700569
570 virtual status_t setVoiceVolume(float volume)
571 {
572 Parcel data, reply;
573 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
574 data.writeFloat(volume);
575 remote()->transact(SET_VOICE_VOLUME, data, &reply);
576 return reply.readInt32();
577 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800578
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000579 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800580 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800581 {
582 Parcel data, reply;
583 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800584 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800585 remote()->transact(GET_RENDER_POSITION, data, &reply);
586 status_t status = reply.readInt32();
587 if (status == NO_ERROR) {
588 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700589 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800590 *halFrames = tmp;
591 }
592 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700593 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800594 *dspFrames = tmp;
595 }
596 }
597 return status;
598 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800599
Glenn Kasten5f972c02014-01-13 09:59:31 -0800600 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800601 {
602 Parcel data, reply;
603 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800604 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800605 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
606 if (status != NO_ERROR) {
607 return 0;
608 }
609 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800610 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700611
Eric Laurentde3f8392014-07-27 18:38:22 -0700612 virtual audio_unique_id_t newAudioUniqueId()
Eric Laurentbe916aa2010-06-01 23:49:17 -0700613 {
614 Parcel data, reply;
615 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
616 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
Eric Laurentde3f8392014-07-27 18:38:22 -0700617 audio_unique_id_t id = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700618 if (status == NO_ERROR) {
619 id = reply.readInt32();
620 }
621 return id;
622 }
623
Marco Nelissend457c972014-02-11 08:47:07 -0800624 virtual void acquireAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700625 {
626 Parcel data, reply;
627 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
628 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800629 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700630 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
631 }
632
Marco Nelissend457c972014-02-11 08:47:07 -0800633 virtual void releaseAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700634 {
635 Parcel data, reply;
636 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
637 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800638 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700639 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
640 }
641
Glenn Kastenf587ba52012-01-26 16:25:10 -0800642 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700643 {
644 Parcel data, reply;
645 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
646 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
647 if (status != NO_ERROR) {
648 return status;
649 }
650 status = reply.readInt32();
651 if (status != NO_ERROR) {
652 return status;
653 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800654 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700655 *numEffects = (uint32_t)reply.readInt32();
656 }
657 return NO_ERROR;
658 }
659
Glenn Kastenf587ba52012-01-26 16:25:10 -0800660 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700661 {
662 if (pDescriptor == NULL) {
663 return BAD_VALUE;
664 }
665 Parcel data, reply;
666 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700667 data.writeInt32(index);
668 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700669 if (status != NO_ERROR) {
670 return status;
671 }
672 status = reply.readInt32();
673 if (status != NO_ERROR) {
674 return status;
675 }
676 reply.read(pDescriptor, sizeof(effect_descriptor_t));
677 return NO_ERROR;
678 }
679
Glenn Kasten5e92a782012-01-30 07:40:52 -0800680 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800681 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700682 {
683 if (pUuid == NULL || pDescriptor == NULL) {
684 return BAD_VALUE;
685 }
686 Parcel data, reply;
687 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
688 data.write(pUuid, sizeof(effect_uuid_t));
689 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
690 if (status != NO_ERROR) {
691 return status;
692 }
693 status = reply.readInt32();
694 if (status != NO_ERROR) {
695 return status;
696 }
697 reply.read(pDescriptor, sizeof(effect_descriptor_t));
698 return NO_ERROR;
699 }
700
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800701 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700702 effect_descriptor_t *pDesc,
703 const sp<IEffectClient>& client,
704 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800705 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700706 int sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700707 const String16& opPackageName,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700708 status_t *status,
709 int *id,
710 int *enabled)
711 {
712 Parcel data, reply;
713 sp<IEffect> effect;
714
715 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700716 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700717 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700718 *status = BAD_VALUE;
719 }
720 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700721
722 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700723 data.write(pDesc, sizeof(effect_descriptor_t));
Marco Nelissen06b46062014-11-14 07:58:25 -0800724 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700725 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800726 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700727 data.writeInt32(sessionId);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700728 data.writeString16(opPackageName);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700729
730 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
731 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000732 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700733 } else {
734 lStatus = reply.readInt32();
735 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700736 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700737 *id = tmp;
738 }
739 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800740 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700741 *enabled = tmp;
742 }
743 effect = interface_cast<IEffect>(reply.readStrongBinder());
744 reply.read(pDesc, sizeof(effect_descriptor_t));
745 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700746 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700747 *status = lStatus;
748 }
749
750 return effect;
751 }
Eric Laurentde070132010-07-13 04:45:46 -0700752
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800753 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
754 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700755 {
756 Parcel data, reply;
757 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
758 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800759 data.writeInt32((int32_t) srcOutput);
760 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700761 remote()->transact(MOVE_EFFECTS, data, &reply);
762 return reply.readInt32();
763 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700764
765 virtual audio_module_handle_t loadHwModule(const char *name)
766 {
767 Parcel data, reply;
768 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
769 data.writeCString(name);
770 remote()->transact(LOAD_HW_MODULE, data, &reply);
771 return (audio_module_handle_t) reply.readInt32();
772 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700773
Glenn Kasten3b16c762012-11-14 08:44:39 -0800774 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700775 {
776 Parcel data, reply;
777 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
778 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
779 return reply.readInt32();
780 }
781
Glenn Kastene33054e2012-11-14 12:54:39 -0800782 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700783 {
784 Parcel data, reply;
785 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
786 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800787 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700788 }
789
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700790 virtual status_t setLowRamDevice(bool isLowRamDevice)
791 {
792 Parcel data, reply;
793 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
794 data.writeInt32((int) isLowRamDevice);
795 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
796 return reply.readInt32();
797 }
Eric Laurent4b123402014-04-11 09:22:20 -0700798 virtual status_t listAudioPorts(unsigned int *num_ports,
799 struct audio_port *ports)
800 {
801 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
802 return BAD_VALUE;
803 }
804 Parcel data, reply;
805 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
806 data.writeInt32(*num_ports);
807 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
808 if (status != NO_ERROR ||
809 (status = (status_t)reply.readInt32()) != NO_ERROR) {
810 return status;
811 }
812 *num_ports = (unsigned int)reply.readInt32();
813 reply.read(ports, *num_ports * sizeof(struct audio_port));
814 return status;
815 }
816 virtual status_t getAudioPort(struct audio_port *port)
817 {
818 if (port == NULL) {
819 return BAD_VALUE;
820 }
821 Parcel data, reply;
822 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
823 data.write(port, sizeof(struct audio_port));
824 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
825 if (status != NO_ERROR ||
826 (status = (status_t)reply.readInt32()) != NO_ERROR) {
827 return status;
828 }
829 reply.read(port, sizeof(struct audio_port));
830 return status;
831 }
832 virtual status_t createAudioPatch(const struct audio_patch *patch,
833 audio_patch_handle_t *handle)
834 {
835 if (patch == NULL || handle == NULL) {
836 return BAD_VALUE;
837 }
838 Parcel data, reply;
839 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
840 data.write(patch, sizeof(struct audio_patch));
841 data.write(handle, sizeof(audio_patch_handle_t));
842 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
843 if (status != NO_ERROR ||
844 (status = (status_t)reply.readInt32()) != NO_ERROR) {
845 return status;
846 }
847 reply.read(handle, sizeof(audio_patch_handle_t));
848 return status;
849 }
850 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
851 {
852 Parcel data, reply;
853 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
854 data.write(&handle, sizeof(audio_patch_handle_t));
855 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
856 if (status != NO_ERROR) {
857 status = (status_t)reply.readInt32();
858 }
859 return status;
860 }
861 virtual status_t listAudioPatches(unsigned int *num_patches,
862 struct audio_patch *patches)
863 {
864 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
865 return BAD_VALUE;
866 }
867 Parcel data, reply;
868 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
869 data.writeInt32(*num_patches);
870 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
871 if (status != NO_ERROR ||
872 (status = (status_t)reply.readInt32()) != NO_ERROR) {
873 return status;
874 }
875 *num_patches = (unsigned int)reply.readInt32();
876 reply.read(patches, *num_patches * sizeof(struct audio_patch));
877 return status;
878 }
879 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
880 {
881 if (config == NULL) {
882 return BAD_VALUE;
883 }
884 Parcel data, reply;
885 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
886 data.write(config, sizeof(struct audio_port_config));
887 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
888 if (status != NO_ERROR) {
889 status = (status_t)reply.readInt32();
890 }
891 return status;
892 }
Eric Laurent93c3d412014-08-01 14:48:35 -0700893 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
894 {
895 Parcel data, reply;
896 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
897 data.writeInt32(sessionId);
898 status_t status = remote()->transact(GET_AUDIO_HW_SYNC, data, &reply);
899 if (status != NO_ERROR) {
900 return AUDIO_HW_SYNC_INVALID;
901 }
902 return (audio_hw_sync_t)reply.readInt32();
903 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800904};
905
906IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
907
908// ----------------------------------------------------------------------
909
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800910status_t BnAudioFlinger::onTransact(
911 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
912{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700913 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800914 case CREATE_TRACK: {
915 CHECK_INTERFACE(IAudioFlinger, data, reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800916 int streamType = data.readInt32();
917 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800918 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700919 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800920 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800921 track_flags_t flags = (track_flags_t) data.readInt32();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700922 bool haveSharedBuffer = data.readInt32() != 0;
923 sp<IMemory> buffer;
924 if (haveSharedBuffer) {
925 buffer = interface_cast<IMemory>(data.readStrongBinder());
926 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800927 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kasten3acbd052012-02-28 10:39:56 -0800928 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700929 int sessionId = data.readInt32();
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800930 int clientUid = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800931 status_t status;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700932 sp<IAudioTrack> track;
933 if ((haveSharedBuffer && (buffer == 0)) ||
934 ((buffer != 0) && (buffer->pointer() == NULL))) {
935 ALOGW("CREATE_TRACK: cannot retrieve shared memory");
936 status = DEAD_OBJECT;
937 } else {
938 track = createTrack(
939 (audio_stream_type_t) streamType, sampleRate, format,
Glenn Kasten74935e42013-12-19 08:56:45 -0800940 channelMask, &frameCount, &flags, buffer, output, tid,
Glenn Kastenc5a17422014-03-13 14:59:59 -0700941 &sessionId, clientUid, &status);
Glenn Kasten0cde0762014-01-16 15:06:36 -0800942 LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700943 }
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700944 reply->writeInt64(frameCount);
Glenn Kastene0b07172012-11-06 15:03:34 -0800945 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700946 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800947 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800948 reply->writeStrongBinder(IInterface::asBinder(track));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800949 return NO_ERROR;
950 } break;
951 case OPEN_RECORD: {
952 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800953 audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800954 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800955 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700956 audio_channel_mask_t channelMask = data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -0700957 const String16& opPackageName = data.readString16();
Glenn Kastene03dd222014-01-28 11:04:39 -0800958 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800959 track_flags_t flags = (track_flags_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700960 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700961 int sessionId = data.readInt32();
Glenn Kasten74105912014-07-03 12:28:53 -0700962 size_t notificationFrames = data.readInt64();
Glenn Kastend776ac62014-05-07 09:16:09 -0700963 sp<IMemory> cblk;
964 sp<IMemory> buffers;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800965 status_t status;
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800966 sp<IAudioRecord> record = openRecord(input,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700967 sampleRate, format, channelMask, opPackageName, &frameCount, &flags, tid,
968 &sessionId, &notificationFrames, cblk, buffers, &status);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700969 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700970 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700971 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700972 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700973 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800974 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800975 reply->writeStrongBinder(IInterface::asBinder(record));
976 reply->writeStrongBinder(IInterface::asBinder(cblk));
977 reply->writeStrongBinder(IInterface::asBinder(buffers));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800978 return NO_ERROR;
979 } break;
980 case SAMPLE_RATE: {
981 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800982 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800983 return NO_ERROR;
984 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800985 case FORMAT: {
986 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800987 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800988 return NO_ERROR;
989 } break;
990 case FRAME_COUNT: {
991 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800992 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800993 return NO_ERROR;
994 } break;
995 case LATENCY: {
996 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800997 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800998 return NO_ERROR;
999 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001000 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001001 CHECK_INTERFACE(IAudioFlinger, data, reply);
1002 reply->writeInt32( setMasterVolume(data.readFloat()) );
1003 return NO_ERROR;
1004 } break;
1005 case SET_MASTER_MUTE: {
1006 CHECK_INTERFACE(IAudioFlinger, data, reply);
1007 reply->writeInt32( setMasterMute(data.readInt32()) );
1008 return NO_ERROR;
1009 } break;
1010 case MASTER_VOLUME: {
1011 CHECK_INTERFACE(IAudioFlinger, data, reply);
1012 reply->writeFloat( masterVolume() );
1013 return NO_ERROR;
1014 } break;
1015 case MASTER_MUTE: {
1016 CHECK_INTERFACE(IAudioFlinger, data, reply);
1017 reply->writeInt32( masterMute() );
1018 return NO_ERROR;
1019 } break;
1020 case SET_STREAM_VOLUME: {
1021 CHECK_INTERFACE(IAudioFlinger, data, reply);
1022 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001023 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001024 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001025 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001026 return NO_ERROR;
1027 } break;
1028 case SET_STREAM_MUTE: {
1029 CHECK_INTERFACE(IAudioFlinger, data, reply);
1030 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001031 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001032 return NO_ERROR;
1033 } break;
1034 case STREAM_VOLUME: {
1035 CHECK_INTERFACE(IAudioFlinger, data, reply);
1036 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001037 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001038 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001039 return NO_ERROR;
1040 } break;
1041 case STREAM_MUTE: {
1042 CHECK_INTERFACE(IAudioFlinger, data, reply);
1043 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001044 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001045 return NO_ERROR;
1046 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001047 case SET_MODE: {
1048 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001049 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001050 reply->writeInt32( setMode(mode) );
1051 return NO_ERROR;
1052 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001053 case SET_MIC_MUTE: {
1054 CHECK_INTERFACE(IAudioFlinger, data, reply);
1055 int state = data.readInt32();
1056 reply->writeInt32( setMicMute(state) );
1057 return NO_ERROR;
1058 } break;
1059 case GET_MIC_MUTE: {
1060 CHECK_INTERFACE(IAudioFlinger, data, reply);
1061 reply->writeInt32( getMicMute() );
1062 return NO_ERROR;
1063 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001064 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001065 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001066 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001067 String8 keyValuePairs(data.readString8());
1068 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001069 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001070 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001071 case GET_PARAMETERS: {
1072 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001073 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001074 String8 keys(data.readString8());
1075 reply->writeString8(getParameters(ioHandle, keys));
1076 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001077 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001078
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001079 case REGISTER_CLIENT: {
1080 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001081 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1082 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001083 registerClient(client);
1084 return NO_ERROR;
1085 } break;
1086 case GET_INPUTBUFFERSIZE: {
1087 CHECK_INTERFACE(IAudioFlinger, data, reply);
1088 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001089 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001090 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001091 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001092 return NO_ERROR;
1093 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001094 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001095 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001096 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001097 audio_config_t config;
1098 data.read(&config, sizeof(audio_config_t));
Eric Laurenta4c5a552012-03-29 10:12:40 -07001099 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001100 String8 address(data.readString8());
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001101 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001102 uint32_t latencyMs;
1103 audio_io_handle_t output;
1104 status_t status = openOutput(module, &output, &config,
1105 &devices, address, &latencyMs, flags);
Glenn Kasten70742962014-02-18 08:00:47 -08001106 ALOGV("OPEN_OUTPUT output, %d", output);
Eric Laurentcf2c0212014-07-25 16:20:43 -07001107 reply->writeInt32((int32_t)status);
1108 if (status == NO_ERROR) {
1109 reply->writeInt32((int32_t)output);
1110 reply->write(&config, sizeof(audio_config_t));
1111 reply->writeInt32(devices);
1112 reply->writeInt32(latencyMs);
1113 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001114 return NO_ERROR;
1115 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001116 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001117 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001118 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1119 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1120 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001121 return NO_ERROR;
1122 } break;
1123 case CLOSE_OUTPUT: {
1124 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001125 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001126 return NO_ERROR;
1127 } break;
1128 case SUSPEND_OUTPUT: {
1129 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001130 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001131 return NO_ERROR;
1132 } break;
1133 case RESTORE_OUTPUT: {
1134 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001135 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001136 return NO_ERROR;
1137 } break;
1138 case OPEN_INPUT: {
1139 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001140 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001141 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
1142 audio_config_t config;
1143 data.read(&config, sizeof(audio_config_t));
1144 audio_devices_t device = (audio_devices_t)data.readInt32();
1145 String8 address(data.readString8());
1146 audio_source_t source = (audio_source_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001147 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001148
Eric Laurentcf2c0212014-07-25 16:20:43 -07001149 status_t status = openInput(module, &input, &config,
1150 &device, address, source, flags);
1151 reply->writeInt32((int32_t) status);
1152 if (status == NO_ERROR) {
1153 reply->writeInt32((int32_t) input);
1154 reply->write(&config, sizeof(audio_config_t));
1155 reply->writeInt32(device);
1156 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001157 return NO_ERROR;
1158 } break;
1159 case CLOSE_INPUT: {
1160 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001161 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001162 return NO_ERROR;
1163 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001164 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001165 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001166 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1167 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001168 return NO_ERROR;
1169 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001170 case SET_VOICE_VOLUME: {
1171 CHECK_INTERFACE(IAudioFlinger, data, reply);
1172 float volume = data.readFloat();
1173 reply->writeInt32( setVoiceVolume(volume) );
1174 return NO_ERROR;
1175 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001176 case GET_RENDER_POSITION: {
1177 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001178 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001179 uint32_t halFrames;
1180 uint32_t dspFrames;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001181 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1182 reply->writeInt32(status);
1183 if (status == NO_ERROR) {
1184 reply->writeInt32(halFrames);
1185 reply->writeInt32(dspFrames);
1186 }
1187 return NO_ERROR;
1188 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001189 case GET_INPUT_FRAMES_LOST: {
1190 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001191 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001192 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001193 return NO_ERROR;
1194 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001195 case NEW_AUDIO_SESSION_ID: {
1196 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentde3f8392014-07-27 18:38:22 -07001197 reply->writeInt32(newAudioUniqueId());
Eric Laurentbe916aa2010-06-01 23:49:17 -07001198 return NO_ERROR;
1199 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001200 case ACQUIRE_AUDIO_SESSION_ID: {
1201 CHECK_INTERFACE(IAudioFlinger, data, reply);
1202 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001203 int pid = data.readInt32();
1204 acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001205 return NO_ERROR;
1206 } break;
1207 case RELEASE_AUDIO_SESSION_ID: {
1208 CHECK_INTERFACE(IAudioFlinger, data, reply);
1209 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001210 int pid = data.readInt32();
1211 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001212 return NO_ERROR;
1213 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001214 case QUERY_NUM_EFFECTS: {
1215 CHECK_INTERFACE(IAudioFlinger, data, reply);
1216 uint32_t numEffects;
1217 status_t status = queryNumberEffects(&numEffects);
1218 reply->writeInt32(status);
1219 if (status == NO_ERROR) {
1220 reply->writeInt32((int32_t)numEffects);
1221 }
1222 return NO_ERROR;
1223 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001224 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001225 CHECK_INTERFACE(IAudioFlinger, data, reply);
1226 effect_descriptor_t desc;
Eric Laurentffe9c252010-06-23 17:38:20 -07001227 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001228 reply->writeInt32(status);
1229 if (status == NO_ERROR) {
1230 reply->write(&desc, sizeof(effect_descriptor_t));
1231 }
1232 return NO_ERROR;
1233 }
1234 case GET_EFFECT_DESCRIPTOR: {
1235 CHECK_INTERFACE(IAudioFlinger, data, reply);
1236 effect_uuid_t uuid;
1237 data.read(&uuid, sizeof(effect_uuid_t));
1238 effect_descriptor_t desc;
1239 status_t status = getEffectDescriptor(&uuid, &desc);
1240 reply->writeInt32(status);
1241 if (status == NO_ERROR) {
1242 reply->write(&desc, sizeof(effect_descriptor_t));
1243 }
1244 return NO_ERROR;
1245 }
1246 case CREATE_EFFECT: {
1247 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001248 effect_descriptor_t desc;
1249 data.read(&desc, sizeof(effect_descriptor_t));
1250 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1251 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001252 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -07001253 int sessionId = data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -07001254 const String16 opPackageName = data.readString16();
Eric Laurentbe916aa2010-06-01 23:49:17 -07001255 status_t status;
1256 int id;
1257 int enabled;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001258
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001259 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -07001260 opPackageName, &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001261 reply->writeInt32(status);
1262 reply->writeInt32(id);
1263 reply->writeInt32(enabled);
Marco Nelissen06b46062014-11-14 07:58:25 -08001264 reply->writeStrongBinder(IInterface::asBinder(effect));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001265 reply->write(&desc, sizeof(effect_descriptor_t));
1266 return NO_ERROR;
1267 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001268 case MOVE_EFFECTS: {
1269 CHECK_INTERFACE(IAudioFlinger, data, reply);
1270 int session = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001271 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1272 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001273 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1274 return NO_ERROR;
1275 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001276 case LOAD_HW_MODULE: {
1277 CHECK_INTERFACE(IAudioFlinger, data, reply);
1278 reply->writeInt32(loadHwModule(data.readCString()));
1279 return NO_ERROR;
1280 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001281 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1282 CHECK_INTERFACE(IAudioFlinger, data, reply);
1283 reply->writeInt32(getPrimaryOutputSamplingRate());
1284 return NO_ERROR;
1285 } break;
1286 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1287 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001288 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001289 return NO_ERROR;
1290 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001291 case SET_LOW_RAM_DEVICE: {
1292 CHECK_INTERFACE(IAudioFlinger, data, reply);
1293 bool isLowRamDevice = data.readInt32() != 0;
1294 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1295 return NO_ERROR;
1296 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001297 case LIST_AUDIO_PORTS: {
1298 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001299 unsigned int numPortsReq = data.readInt32();
1300 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1301 numPortsReq = MAX_ITEMS_PER_LIST;
1302 }
1303 unsigned int numPorts = numPortsReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001304 struct audio_port *ports =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001305 (struct audio_port *)calloc(numPortsReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001306 sizeof(struct audio_port));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001307 if (ports == NULL) {
1308 reply->writeInt32(NO_MEMORY);
1309 reply->writeInt32(0);
1310 return NO_ERROR;
1311 }
1312 status_t status = listAudioPorts(&numPorts, ports);
Eric Laurent4b123402014-04-11 09:22:20 -07001313 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001314 reply->writeInt32(numPorts);
Eric Laurent4b123402014-04-11 09:22:20 -07001315 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001316 if (numPortsReq > numPorts) {
1317 numPortsReq = numPorts;
1318 }
1319 reply->write(ports, numPortsReq * sizeof(struct audio_port));
Eric Laurent4b123402014-04-11 09:22:20 -07001320 }
1321 free(ports);
1322 return NO_ERROR;
1323 } break;
1324 case GET_AUDIO_PORT: {
1325 CHECK_INTERFACE(IAudioFlinger, data, reply);
1326 struct audio_port port;
1327 data.read(&port, sizeof(struct audio_port));
1328 status_t status = getAudioPort(&port);
1329 reply->writeInt32(status);
1330 if (status == NO_ERROR) {
1331 reply->write(&port, sizeof(struct audio_port));
1332 }
1333 return NO_ERROR;
1334 } break;
1335 case CREATE_AUDIO_PATCH: {
1336 CHECK_INTERFACE(IAudioFlinger, data, reply);
1337 struct audio_patch patch;
1338 data.read(&patch, sizeof(struct audio_patch));
1339 audio_patch_handle_t handle;
1340 data.read(&handle, sizeof(audio_patch_handle_t));
1341 status_t status = createAudioPatch(&patch, &handle);
1342 reply->writeInt32(status);
1343 if (status == NO_ERROR) {
1344 reply->write(&handle, sizeof(audio_patch_handle_t));
1345 }
1346 return NO_ERROR;
1347 } break;
1348 case RELEASE_AUDIO_PATCH: {
1349 CHECK_INTERFACE(IAudioFlinger, data, reply);
1350 audio_patch_handle_t handle;
1351 data.read(&handle, sizeof(audio_patch_handle_t));
1352 status_t status = releaseAudioPatch(handle);
1353 reply->writeInt32(status);
1354 return NO_ERROR;
1355 } break;
1356 case LIST_AUDIO_PATCHES: {
1357 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001358 unsigned int numPatchesReq = data.readInt32();
1359 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1360 numPatchesReq = MAX_ITEMS_PER_LIST;
1361 }
1362 unsigned int numPatches = numPatchesReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001363 struct audio_patch *patches =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001364 (struct audio_patch *)calloc(numPatchesReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001365 sizeof(struct audio_patch));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001366 if (patches == NULL) {
1367 reply->writeInt32(NO_MEMORY);
1368 reply->writeInt32(0);
1369 return NO_ERROR;
1370 }
1371 status_t status = listAudioPatches(&numPatches, patches);
Eric Laurent4b123402014-04-11 09:22:20 -07001372 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001373 reply->writeInt32(numPatches);
Eric Laurent4b123402014-04-11 09:22:20 -07001374 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001375 if (numPatchesReq > numPatches) {
1376 numPatchesReq = numPatches;
1377 }
1378 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
Eric Laurent4b123402014-04-11 09:22:20 -07001379 }
1380 free(patches);
1381 return NO_ERROR;
1382 } break;
1383 case SET_AUDIO_PORT_CONFIG: {
1384 CHECK_INTERFACE(IAudioFlinger, data, reply);
1385 struct audio_port_config config;
1386 data.read(&config, sizeof(struct audio_port_config));
1387 status_t status = setAudioPortConfig(&config);
1388 reply->writeInt32(status);
1389 return NO_ERROR;
1390 } break;
Eric Laurent93c3d412014-08-01 14:48:35 -07001391 case GET_AUDIO_HW_SYNC: {
1392 CHECK_INTERFACE(IAudioFlinger, data, reply);
1393 reply->writeInt32(getAudioHwSyncForSession((audio_session_t)data.readInt32()));
1394 return NO_ERROR;
1395 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001396 default:
1397 return BBinder::onTransact(code, data, reply, flags);
1398 }
1399}
1400
1401// ----------------------------------------------------------------------------
1402
Glenn Kasten40bc9062015-03-20 09:09:33 -07001403} // namespace android