blob: b532debe48ebf4288001956d8a7cf54912559f02 [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,
Eric Laurent72e3f392015-05-20 14:43:50 -070083 GET_AUDIO_HW_SYNC,
Glenn Kasten4a8308b2016-04-18 14:10:01 -070084 SYSTEM_READY,
85 FRAME_COUNT_HAL,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080086};
87
Eric Laurentf75c2fe2015-04-02 13:49:15 -070088#define MAX_ITEMS_PER_LIST 1024
89
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080090class BpAudioFlinger : public BpInterface<IAudioFlinger>
91{
92public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070093 explicit BpAudioFlinger(const sp<IBinder>& impl)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080094 : BpInterface<IAudioFlinger>(impl)
95 {
96 }
97
98 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080099 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800100 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800101 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -0700102 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -0800103 size_t *pFrameCount,
Eric Laurent05067782016-06-01 18:27:28 -0700104 audio_output_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800105 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800106 audio_io_handle_t output,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700107 pid_t pid,
Glenn Kasten3acbd052012-02-28 10:39:56 -0800108 pid_t tid,
Glenn Kastend848eb42016-03-08 13:42:11 -0800109 audio_session_t *sessionId,
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800110 int clientUid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800111 status_t *status,
112 audio_port_handle_t portId)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800113 {
114 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700115 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800116 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800117 data.writeInt32((int32_t) streamType);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800118 data.writeInt32(sampleRate);
119 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700120 data.writeInt32(channelMask);
Glenn Kasten74935e42013-12-19 08:56:45 -0800121 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800122 data.writeInt64(frameCount);
Eric Laurent05067782016-06-01 18:27:28 -0700123 audio_output_flags_t lFlags = flags != NULL ? *flags : AUDIO_OUTPUT_FLAG_NONE;
Glenn Kastene0b07172012-11-06 15:03:34 -0800124 data.writeInt32(lFlags);
Glenn Kasten2301acc2014-01-17 10:21:00 -0800125 // haveSharedBuffer
Eric Laurent3d00aa62013-09-24 09:53:27 -0700126 if (sharedBuffer != 0) {
127 data.writeInt32(true);
Marco Nelissen06b46062014-11-14 07:58:25 -0800128 data.writeStrongBinder(IInterface::asBinder(sharedBuffer));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700129 } else {
130 data.writeInt32(false);
131 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800132 data.writeInt32((int32_t) output);
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700133 data.writeInt32((int32_t) pid);
Glenn Kasten3acbd052012-02-28 10:39:56 -0800134 data.writeInt32((int32_t) tid);
Glenn Kastend848eb42016-03-08 13:42:11 -0800135 audio_session_t lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700136 if (sessionId != NULL) {
137 lSessionId = *sessionId;
138 }
139 data.writeInt32(lSessionId);
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800140 data.writeInt32(clientUid);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800141 data.writeInt32(portId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800142 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
143 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000144 ALOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700145 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700146 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800147 if (pFrameCount != NULL) {
148 *pFrameCount = frameCount;
149 }
Eric Laurent05067782016-06-01 18:27:28 -0700150 lFlags = (audio_output_flags_t)reply.readInt32();
Glenn Kastene0b07172012-11-06 15:03:34 -0800151 if (flags != NULL) {
152 *flags = lFlags;
153 }
Glenn Kastend848eb42016-03-08 13:42:11 -0800154 lSessionId = (audio_session_t) reply.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700155 if (sessionId != NULL) {
156 *sessionId = lSessionId;
157 }
Eric Laurent5841db72009-09-09 05:16:08 -0700158 lStatus = reply.readInt32();
159 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
Glenn Kasten0cde0762014-01-16 15:06:36 -0800160 if (lStatus == NO_ERROR) {
161 if (track == 0) {
162 ALOGE("createTrack should have returned an IAudioTrack");
163 lStatus = UNKNOWN_ERROR;
164 }
165 } else {
166 if (track != 0) {
167 ALOGE("createTrack returned an IAudioTrack but with status %d", lStatus);
168 track.clear();
169 }
170 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800171 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700172 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800173 *status = lStatus;
174 }
Eric Laurent5841db72009-09-09 05:16:08 -0700175 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800176 }
177
178 virtual sp<IAudioRecord> openRecord(
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800179 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800180 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800181 audio_format_t format,
Glenn Kasten28b76b32012-07-03 17:24:41 -0700182 audio_channel_mask_t channelMask,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700183 const String16& opPackageName,
Glenn Kasten74935e42013-12-19 08:56:45 -0800184 size_t *pFrameCount,
Eric Laurent05067782016-06-01 18:27:28 -0700185 audio_input_flags_t *flags,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700186 pid_t pid,
Glenn Kasten1879fff2012-07-11 15:36:59 -0700187 pid_t tid,
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700188 int clientUid,
Glenn Kastend848eb42016-03-08 13:42:11 -0800189 audio_session_t *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700190 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700191 sp<IMemory>& cblk,
192 sp<IMemory>& buffers,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800193 status_t *status,
194 audio_port_handle_t portId)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800195 {
196 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700197 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800198 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800199 data.writeInt32((int32_t) input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800200 data.writeInt32(sampleRate);
201 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700202 data.writeInt32(channelMask);
Dianne Hackborneaa34702015-04-29 12:57:58 -0700203 data.writeString16(opPackageName);
Glenn Kasten74935e42013-12-19 08:56:45 -0800204 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800205 data.writeInt64(frameCount);
Eric Laurent05067782016-06-01 18:27:28 -0700206 audio_input_flags_t lFlags = flags != NULL ? *flags : AUDIO_INPUT_FLAG_NONE;
Glenn Kasteneeca3262013-07-31 16:12:48 -0700207 data.writeInt32(lFlags);
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700208 data.writeInt32((int32_t) pid);
Glenn Kasten1879fff2012-07-11 15:36:59 -0700209 data.writeInt32((int32_t) tid);
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700210 data.writeInt32((int32_t) clientUid);
Glenn Kastend848eb42016-03-08 13:42:11 -0800211 audio_session_t lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700212 if (sessionId != NULL) {
213 lSessionId = *sessionId;
214 }
215 data.writeInt32(lSessionId);
Glenn Kasten74105912014-07-03 12:28:53 -0700216 data.writeInt64(notificationFrames != NULL ? *notificationFrames : 0);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800217 data.writeInt32(portId);
Glenn Kastend776ac62014-05-07 09:16:09 -0700218 cblk.clear();
219 buffers.clear();
Eric Laurent5841db72009-09-09 05:16:08 -0700220 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
221 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000222 ALOGE("openRecord error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700223 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700224 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800225 if (pFrameCount != NULL) {
226 *pFrameCount = frameCount;
227 }
Eric Laurent05067782016-06-01 18:27:28 -0700228 lFlags = (audio_input_flags_t)reply.readInt32();
Glenn Kasteneeca3262013-07-31 16:12:48 -0700229 if (flags != NULL) {
230 *flags = lFlags;
231 }
Glenn Kastend848eb42016-03-08 13:42:11 -0800232 lSessionId = (audio_session_t) reply.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700233 if (sessionId != NULL) {
234 *sessionId = lSessionId;
235 }
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700236 size_t lNotificationFrames = (size_t) reply.readInt64();
237 if (notificationFrames != NULL) {
238 *notificationFrames = lNotificationFrames;
239 }
Eric Laurent5841db72009-09-09 05:16:08 -0700240 lStatus = reply.readInt32();
241 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700242 cblk = interface_cast<IMemory>(reply.readStrongBinder());
243 if (cblk != 0 && cblk->pointer() == NULL) {
244 cblk.clear();
245 }
246 buffers = interface_cast<IMemory>(reply.readStrongBinder());
247 if (buffers != 0 && buffers->pointer() == NULL) {
248 buffers.clear();
249 }
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700250 if (lStatus == NO_ERROR) {
251 if (record == 0) {
252 ALOGE("openRecord should have returned an IAudioRecord");
253 lStatus = UNKNOWN_ERROR;
Glenn Kastend776ac62014-05-07 09:16:09 -0700254 } else if (cblk == 0) {
255 ALOGE("openRecord should have returned a cblk");
256 lStatus = NO_MEMORY;
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700257 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700258 // buffers is permitted to be 0
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700259 } else {
Glenn Kastend776ac62014-05-07 09:16:09 -0700260 if (record != 0 || cblk != 0 || buffers != 0) {
261 ALOGE("openRecord returned an IAudioRecord, cblk, "
262 "or buffers but with status %d", lStatus);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700263 }
264 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700265 if (lStatus != NO_ERROR) {
266 record.clear();
267 cblk.clear();
268 buffers.clear();
269 }
Eric Laurent5841db72009-09-09 05:16:08 -0700270 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700271 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800272 *status = lStatus;
273 }
Eric Laurent5841db72009-09-09 05:16:08 -0700274 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800275 }
276
Glenn Kasten2c073da2016-02-26 09:14:08 -0800277 virtual uint32_t sampleRate(audio_io_handle_t ioHandle) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800278 {
279 Parcel data, reply;
280 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten2c073da2016-02-26 09:14:08 -0800281 data.writeInt32((int32_t) ioHandle);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800282 remote()->transact(SAMPLE_RATE, data, &reply);
283 return reply.readInt32();
284 }
285
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700286 // RESERVED for channelCount()
287
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800288 virtual audio_format_t format(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800289 {
290 Parcel data, reply;
291 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800292 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800293 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800294 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800295 }
296
Glenn Kasten2c073da2016-02-26 09:14:08 -0800297 virtual size_t frameCount(audio_io_handle_t ioHandle) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800298 {
299 Parcel data, reply;
300 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten2c073da2016-02-26 09:14:08 -0800301 data.writeInt32((int32_t) ioHandle);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800302 remote()->transact(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800303 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800304 }
305
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800306 virtual uint32_t latency(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800307 {
308 Parcel data, reply;
309 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800310 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800311 remote()->transact(LATENCY, data, &reply);
312 return reply.readInt32();
313 }
314
315 virtual status_t setMasterVolume(float value)
316 {
317 Parcel data, reply;
318 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
319 data.writeFloat(value);
320 remote()->transact(SET_MASTER_VOLUME, data, &reply);
321 return reply.readInt32();
322 }
323
324 virtual status_t setMasterMute(bool muted)
325 {
326 Parcel data, reply;
327 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
328 data.writeInt32(muted);
329 remote()->transact(SET_MASTER_MUTE, data, &reply);
330 return reply.readInt32();
331 }
332
333 virtual float masterVolume() const
334 {
335 Parcel data, reply;
336 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
337 remote()->transact(MASTER_VOLUME, data, &reply);
338 return reply.readFloat();
339 }
340
341 virtual bool masterMute() const
342 {
343 Parcel data, reply;
344 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
345 remote()->transact(MASTER_MUTE, data, &reply);
346 return reply.readInt32();
347 }
348
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800349 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
350 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800351 {
352 Parcel data, reply;
353 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800354 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800355 data.writeFloat(value);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800356 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800357 remote()->transact(SET_STREAM_VOLUME, data, &reply);
358 return reply.readInt32();
359 }
360
Glenn Kastenfff6d712012-01-12 16:38:12 -0800361 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800362 {
363 Parcel data, reply;
364 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800365 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800366 data.writeInt32(muted);
367 remote()->transact(SET_STREAM_MUTE, data, &reply);
368 return reply.readInt32();
369 }
370
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800371 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800372 {
373 Parcel data, reply;
374 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800375 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800376 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800377 remote()->transact(STREAM_VOLUME, data, &reply);
378 return reply.readFloat();
379 }
380
Glenn Kastenfff6d712012-01-12 16:38:12 -0800381 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800382 {
383 Parcel data, reply;
384 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800385 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800386 remote()->transact(STREAM_MUTE, data, &reply);
387 return reply.readInt32();
388 }
389
Glenn Kastenf78aee72012-01-04 11:00:47 -0800390 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800391 {
392 Parcel data, reply;
393 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
394 data.writeInt32(mode);
395 remote()->transact(SET_MODE, data, &reply);
396 return reply.readInt32();
397 }
398
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800399 virtual status_t setMicMute(bool state)
400 {
401 Parcel data, reply;
402 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
403 data.writeInt32(state);
404 remote()->transact(SET_MIC_MUTE, data, &reply);
405 return reply.readInt32();
406 }
407
408 virtual bool getMicMute() const
409 {
410 Parcel data, reply;
411 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
412 remote()->transact(GET_MIC_MUTE, data, &reply);
413 return reply.readInt32();
414 }
415
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800416 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800417 {
418 Parcel data, reply;
419 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800420 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700421 data.writeString8(keyValuePairs);
422 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800423 return reply.readInt32();
424 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700425
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800426 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700427 {
428 Parcel data, reply;
429 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800430 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700431 data.writeString8(keys);
432 remote()->transact(GET_PARAMETERS, data, &reply);
433 return reply.readString8();
434 }
435
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800436 virtual void registerClient(const sp<IAudioFlingerClient>& client)
437 {
438 Parcel data, reply;
439 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800440 data.writeStrongBinder(IInterface::asBinder(client));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800441 remote()->transact(REGISTER_CLIENT, data, &reply);
442 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700443
Glenn Kastendd8104c2012-07-02 12:42:44 -0700444 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
445 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800446 {
447 Parcel data, reply;
448 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
449 data.writeInt32(sampleRate);
450 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700451 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800452 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800453 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800454 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700455
Eric Laurentcf2c0212014-07-25 16:20:43 -0700456 virtual status_t openOutput(audio_module_handle_t module,
457 audio_io_handle_t *output,
458 audio_config_t *config,
459 audio_devices_t *devices,
460 const String8& address,
461 uint32_t *latencyMs,
462 audio_output_flags_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800463 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700464 if (output == NULL || config == NULL || devices == NULL || latencyMs == NULL) {
465 return BAD_VALUE;
466 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800467 Parcel data, reply;
468 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700469 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700470 data.write(config, sizeof(audio_config_t));
471 data.writeInt32(*devices);
472 data.writeString8(address);
Glenn Kasten18868c52012-03-07 09:15:37 -0800473 data.writeInt32((int32_t) flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700474 status_t status = remote()->transact(OPEN_OUTPUT, data, &reply);
475 if (status != NO_ERROR) {
476 *output = AUDIO_IO_HANDLE_NONE;
477 return status;
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100478 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700479 status = (status_t)reply.readInt32();
480 if (status != NO_ERROR) {
481 *output = AUDIO_IO_HANDLE_NONE;
482 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700483 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700484 *output = (audio_io_handle_t)reply.readInt32();
485 ALOGV("openOutput() returned output, %d", *output);
486 reply.read(config, sizeof(audio_config_t));
487 *devices = (audio_devices_t)reply.readInt32();
488 *latencyMs = reply.readInt32();
489 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800490 }
491
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800492 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
493 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800494 {
495 Parcel data, reply;
496 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800497 data.writeInt32((int32_t) output1);
498 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700499 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800500 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700501 }
502
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800503 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700504 {
505 Parcel data, reply;
506 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800507 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700508 remote()->transact(CLOSE_OUTPUT, data, &reply);
509 return reply.readInt32();
510 }
511
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800512 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700513 {
514 Parcel data, reply;
515 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800516 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700517 remote()->transact(SUSPEND_OUTPUT, data, &reply);
518 return reply.readInt32();
519 }
520
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800521 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700522 {
523 Parcel data, reply;
524 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800525 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700526 remote()->transact(RESTORE_OUTPUT, data, &reply);
527 return reply.readInt32();
528 }
529
Eric Laurentcf2c0212014-07-25 16:20:43 -0700530 virtual status_t openInput(audio_module_handle_t module,
531 audio_io_handle_t *input,
532 audio_config_t *config,
533 audio_devices_t *device,
534 const String8& address,
535 audio_source_t source,
536 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700537 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700538 if (input == NULL || config == NULL || device == NULL) {
539 return BAD_VALUE;
540 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700541 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700542 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700543 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700544 data.writeInt32(*input);
545 data.write(config, sizeof(audio_config_t));
546 data.writeInt32(*device);
547 data.writeString8(address);
548 data.writeInt32(source);
Glenn Kastenec40d282014-07-15 15:31:26 -0700549 data.writeInt32(flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700550 status_t status = remote()->transact(OPEN_INPUT, data, &reply);
551 if (status != NO_ERROR) {
552 *input = AUDIO_IO_HANDLE_NONE;
553 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700554 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700555 status = (status_t)reply.readInt32();
556 if (status != NO_ERROR) {
557 *input = AUDIO_IO_HANDLE_NONE;
558 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700559 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700560 *input = (audio_io_handle_t)reply.readInt32();
561 reply.read(config, sizeof(audio_config_t));
562 *device = (audio_devices_t)reply.readInt32();
563 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700564 }
565
Eric Laurentfa2877b2009-07-28 08:44:33 -0700566 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700567 {
568 Parcel data, reply;
569 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700570 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700571 remote()->transact(CLOSE_INPUT, data, &reply);
572 return reply.readInt32();
573 }
574
Glenn Kastend2304db2014-02-03 07:40:31 -0800575 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700576 {
577 Parcel data, reply;
578 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800579 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800580 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700581 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800582 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700583
584 virtual status_t setVoiceVolume(float volume)
585 {
586 Parcel data, reply;
587 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
588 data.writeFloat(volume);
589 remote()->transact(SET_VOICE_VOLUME, data, &reply);
590 return reply.readInt32();
591 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800592
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000593 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800594 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800595 {
596 Parcel data, reply;
597 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800598 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800599 remote()->transact(GET_RENDER_POSITION, data, &reply);
600 status_t status = reply.readInt32();
601 if (status == NO_ERROR) {
602 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700603 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800604 *halFrames = tmp;
605 }
606 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700607 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800608 *dspFrames = tmp;
609 }
610 }
611 return status;
612 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800613
Glenn Kasten5f972c02014-01-13 09:59:31 -0800614 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800615 {
616 Parcel data, reply;
617 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800618 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800619 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
620 if (status != NO_ERROR) {
621 return 0;
622 }
623 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800624 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700625
Glenn Kasteneeecb982016-02-26 10:44:04 -0800626 virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use)
Eric Laurentbe916aa2010-06-01 23:49:17 -0700627 {
628 Parcel data, reply;
629 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasteneeecb982016-02-26 10:44:04 -0800630 data.writeInt32((int32_t) use);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700631 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
Eric Laurentde3f8392014-07-27 18:38:22 -0700632 audio_unique_id_t id = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700633 if (status == NO_ERROR) {
634 id = reply.readInt32();
635 }
636 return id;
637 }
638
Glenn Kastend848eb42016-03-08 13:42:11 -0800639 virtual void acquireAudioSessionId(audio_session_t audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700640 {
641 Parcel data, reply;
642 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
643 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800644 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700645 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
646 }
647
Glenn Kastend848eb42016-03-08 13:42:11 -0800648 virtual void releaseAudioSessionId(audio_session_t audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700649 {
650 Parcel data, reply;
651 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
652 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800653 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700654 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
655 }
656
Glenn Kastenf587ba52012-01-26 16:25:10 -0800657 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700658 {
659 Parcel data, reply;
660 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
661 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
662 if (status != NO_ERROR) {
663 return status;
664 }
665 status = reply.readInt32();
666 if (status != NO_ERROR) {
667 return status;
668 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800669 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700670 *numEffects = (uint32_t)reply.readInt32();
671 }
672 return NO_ERROR;
673 }
674
Glenn Kastenf587ba52012-01-26 16:25:10 -0800675 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700676 {
677 if (pDescriptor == NULL) {
678 return BAD_VALUE;
679 }
680 Parcel data, reply;
681 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700682 data.writeInt32(index);
683 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700684 if (status != NO_ERROR) {
685 return status;
686 }
687 status = reply.readInt32();
688 if (status != NO_ERROR) {
689 return status;
690 }
691 reply.read(pDescriptor, sizeof(effect_descriptor_t));
692 return NO_ERROR;
693 }
694
Glenn Kasten5e92a782012-01-30 07:40:52 -0800695 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800696 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700697 {
698 if (pUuid == NULL || pDescriptor == NULL) {
699 return BAD_VALUE;
700 }
701 Parcel data, reply;
702 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
703 data.write(pUuid, sizeof(effect_uuid_t));
704 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
705 if (status != NO_ERROR) {
706 return status;
707 }
708 status = reply.readInt32();
709 if (status != NO_ERROR) {
710 return status;
711 }
712 reply.read(pDescriptor, sizeof(effect_descriptor_t));
713 return NO_ERROR;
714 }
715
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800716 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700717 effect_descriptor_t *pDesc,
718 const sp<IEffectClient>& client,
719 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800720 audio_io_handle_t output,
Glenn Kastend848eb42016-03-08 13:42:11 -0800721 audio_session_t sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700722 const String16& opPackageName,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700723 status_t *status,
724 int *id,
725 int *enabled)
726 {
727 Parcel data, reply;
728 sp<IEffect> effect;
729
730 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700731 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700732 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700733 *status = BAD_VALUE;
734 }
735 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700736
737 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700738 data.write(pDesc, sizeof(effect_descriptor_t));
Marco Nelissen06b46062014-11-14 07:58:25 -0800739 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700740 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800741 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700742 data.writeInt32(sessionId);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700743 data.writeString16(opPackageName);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700744
745 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
746 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000747 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700748 } else {
749 lStatus = reply.readInt32();
750 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700751 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700752 *id = tmp;
753 }
754 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800755 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700756 *enabled = tmp;
757 }
758 effect = interface_cast<IEffect>(reply.readStrongBinder());
759 reply.read(pDesc, sizeof(effect_descriptor_t));
760 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700761 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700762 *status = lStatus;
763 }
764
765 return effect;
766 }
Eric Laurentde070132010-07-13 04:45:46 -0700767
Glenn Kastend848eb42016-03-08 13:42:11 -0800768 virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800769 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700770 {
771 Parcel data, reply;
772 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
773 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800774 data.writeInt32((int32_t) srcOutput);
775 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700776 remote()->transact(MOVE_EFFECTS, data, &reply);
777 return reply.readInt32();
778 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700779
780 virtual audio_module_handle_t loadHwModule(const char *name)
781 {
782 Parcel data, reply;
783 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
784 data.writeCString(name);
785 remote()->transact(LOAD_HW_MODULE, data, &reply);
786 return (audio_module_handle_t) reply.readInt32();
787 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700788
Glenn Kasten3b16c762012-11-14 08:44:39 -0800789 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700790 {
791 Parcel data, reply;
792 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
793 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
794 return reply.readInt32();
795 }
796
Glenn Kastene33054e2012-11-14 12:54:39 -0800797 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700798 {
799 Parcel data, reply;
800 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
801 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800802 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700803 }
804
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700805 virtual status_t setLowRamDevice(bool isLowRamDevice)
806 {
807 Parcel data, reply;
808 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
809 data.writeInt32((int) isLowRamDevice);
810 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
811 return reply.readInt32();
812 }
Eric Laurent4b123402014-04-11 09:22:20 -0700813 virtual status_t listAudioPorts(unsigned int *num_ports,
814 struct audio_port *ports)
815 {
816 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
817 return BAD_VALUE;
818 }
819 Parcel data, reply;
820 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
821 data.writeInt32(*num_ports);
822 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
823 if (status != NO_ERROR ||
824 (status = (status_t)reply.readInt32()) != NO_ERROR) {
825 return status;
826 }
827 *num_ports = (unsigned int)reply.readInt32();
828 reply.read(ports, *num_ports * sizeof(struct audio_port));
829 return status;
830 }
831 virtual status_t getAudioPort(struct audio_port *port)
832 {
833 if (port == NULL) {
834 return BAD_VALUE;
835 }
836 Parcel data, reply;
837 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
838 data.write(port, sizeof(struct audio_port));
839 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
840 if (status != NO_ERROR ||
841 (status = (status_t)reply.readInt32()) != NO_ERROR) {
842 return status;
843 }
844 reply.read(port, sizeof(struct audio_port));
845 return status;
846 }
847 virtual status_t createAudioPatch(const struct audio_patch *patch,
848 audio_patch_handle_t *handle)
849 {
850 if (patch == NULL || handle == NULL) {
851 return BAD_VALUE;
852 }
853 Parcel data, reply;
854 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
855 data.write(patch, sizeof(struct audio_patch));
856 data.write(handle, sizeof(audio_patch_handle_t));
857 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
858 if (status != NO_ERROR ||
859 (status = (status_t)reply.readInt32()) != NO_ERROR) {
860 return status;
861 }
862 reply.read(handle, sizeof(audio_patch_handle_t));
863 return status;
864 }
865 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
866 {
867 Parcel data, reply;
868 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
869 data.write(&handle, sizeof(audio_patch_handle_t));
870 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
871 if (status != NO_ERROR) {
872 status = (status_t)reply.readInt32();
873 }
874 return status;
875 }
876 virtual status_t listAudioPatches(unsigned int *num_patches,
877 struct audio_patch *patches)
878 {
879 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
880 return BAD_VALUE;
881 }
882 Parcel data, reply;
883 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
884 data.writeInt32(*num_patches);
885 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
886 if (status != NO_ERROR ||
887 (status = (status_t)reply.readInt32()) != NO_ERROR) {
888 return status;
889 }
890 *num_patches = (unsigned int)reply.readInt32();
891 reply.read(patches, *num_patches * sizeof(struct audio_patch));
892 return status;
893 }
894 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
895 {
896 if (config == NULL) {
897 return BAD_VALUE;
898 }
899 Parcel data, reply;
900 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
901 data.write(config, sizeof(struct audio_port_config));
902 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
903 if (status != NO_ERROR) {
904 status = (status_t)reply.readInt32();
905 }
906 return status;
907 }
Eric Laurent93c3d412014-08-01 14:48:35 -0700908 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
909 {
910 Parcel data, reply;
911 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
912 data.writeInt32(sessionId);
913 status_t status = remote()->transact(GET_AUDIO_HW_SYNC, data, &reply);
914 if (status != NO_ERROR) {
915 return AUDIO_HW_SYNC_INVALID;
916 }
917 return (audio_hw_sync_t)reply.readInt32();
918 }
Eric Laurent72e3f392015-05-20 14:43:50 -0700919 virtual status_t systemReady()
920 {
921 Parcel data, reply;
922 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
923 return remote()->transact(SYSTEM_READY, data, &reply, IBinder::FLAG_ONEWAY);
924 }
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700925 virtual size_t frameCountHAL(audio_io_handle_t ioHandle) const
926 {
927 Parcel data, reply;
928 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
929 data.writeInt32((int32_t) ioHandle);
930 status_t status = remote()->transact(FRAME_COUNT_HAL, data, &reply);
931 if (status != NO_ERROR) {
932 return 0;
933 }
934 return reply.readInt64();
935 }
936
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800937};
938
939IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
940
941// ----------------------------------------------------------------------
942
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800943status_t BnAudioFlinger::onTransact(
944 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
945{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700946 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800947 case CREATE_TRACK: {
948 CHECK_INTERFACE(IAudioFlinger, data, reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800949 int streamType = data.readInt32();
950 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800951 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700952 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800953 size_t frameCount = data.readInt64();
Eric Laurent05067782016-06-01 18:27:28 -0700954 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700955 bool haveSharedBuffer = data.readInt32() != 0;
956 sp<IMemory> buffer;
957 if (haveSharedBuffer) {
958 buffer = interface_cast<IMemory>(data.readStrongBinder());
959 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800960 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700961 pid_t pid = (pid_t) data.readInt32();
Glenn Kasten3acbd052012-02-28 10:39:56 -0800962 pid_t tid = (pid_t) data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -0800963 audio_session_t sessionId = (audio_session_t) data.readInt32();
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800964 int clientUid = data.readInt32();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800965 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -0700966 status_t status = NO_ERROR;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700967 sp<IAudioTrack> track;
968 if ((haveSharedBuffer && (buffer == 0)) ||
969 ((buffer != 0) && (buffer->pointer() == NULL))) {
970 ALOGW("CREATE_TRACK: cannot retrieve shared memory");
971 status = DEAD_OBJECT;
972 } else {
973 track = createTrack(
974 (audio_stream_type_t) streamType, sampleRate, format,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700975 channelMask, &frameCount, &flags, buffer, output, pid, tid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800976 &sessionId, clientUid, &status, portId);
Glenn Kasten0cde0762014-01-16 15:06:36 -0800977 LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700978 }
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700979 reply->writeInt64(frameCount);
Glenn Kastene0b07172012-11-06 15:03:34 -0800980 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700981 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800982 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800983 reply->writeStrongBinder(IInterface::asBinder(track));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800984 return NO_ERROR;
985 } break;
986 case OPEN_RECORD: {
987 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800988 audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800989 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800990 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700991 audio_channel_mask_t channelMask = data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -0700992 const String16& opPackageName = data.readString16();
Glenn Kastene03dd222014-01-28 11:04:39 -0800993 size_t frameCount = data.readInt64();
Eric Laurent05067782016-06-01 18:27:28 -0700994 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700995 pid_t pid = (pid_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700996 pid_t tid = (pid_t) data.readInt32();
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700997 int clientUid = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -0800998 audio_session_t sessionId = (audio_session_t) data.readInt32();
Glenn Kasten74105912014-07-03 12:28:53 -0700999 size_t notificationFrames = data.readInt64();
Eric Laurent20b9ef02016-12-05 11:03:16 -08001000 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
Glenn Kastend776ac62014-05-07 09:16:09 -07001001 sp<IMemory> cblk;
1002 sp<IMemory> buffers;
Wei Jia983dca32015-09-10 09:47:29 -07001003 status_t status = NO_ERROR;
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001004 sp<IAudioRecord> record = openRecord(input,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -07001005 sampleRate, format, channelMask, opPackageName, &frameCount, &flags,
1006 pid, tid, clientUid, &sessionId, &notificationFrames, cblk, buffers,
Eric Laurent20b9ef02016-12-05 11:03:16 -08001007 &status, portId);
Glenn Kastene93cf2c2013-09-24 11:52:37 -07001008 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -07001009 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -07001010 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001011 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -07001012 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001013 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -08001014 reply->writeStrongBinder(IInterface::asBinder(record));
1015 reply->writeStrongBinder(IInterface::asBinder(cblk));
1016 reply->writeStrongBinder(IInterface::asBinder(buffers));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001017 return NO_ERROR;
1018 } break;
1019 case SAMPLE_RATE: {
1020 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001021 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001022 return NO_ERROR;
1023 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001024
1025 // RESERVED for channelCount()
1026
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001027 case FORMAT: {
1028 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001029 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001030 return NO_ERROR;
1031 } break;
1032 case FRAME_COUNT: {
1033 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001034 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001035 return NO_ERROR;
1036 } break;
1037 case LATENCY: {
1038 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001039 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001040 return NO_ERROR;
1041 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001042 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001043 CHECK_INTERFACE(IAudioFlinger, data, reply);
1044 reply->writeInt32( setMasterVolume(data.readFloat()) );
1045 return NO_ERROR;
1046 } break;
1047 case SET_MASTER_MUTE: {
1048 CHECK_INTERFACE(IAudioFlinger, data, reply);
1049 reply->writeInt32( setMasterMute(data.readInt32()) );
1050 return NO_ERROR;
1051 } break;
1052 case MASTER_VOLUME: {
1053 CHECK_INTERFACE(IAudioFlinger, data, reply);
1054 reply->writeFloat( masterVolume() );
1055 return NO_ERROR;
1056 } break;
1057 case MASTER_MUTE: {
1058 CHECK_INTERFACE(IAudioFlinger, data, reply);
1059 reply->writeInt32( masterMute() );
1060 return NO_ERROR;
1061 } break;
1062 case SET_STREAM_VOLUME: {
1063 CHECK_INTERFACE(IAudioFlinger, data, reply);
1064 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001065 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001066 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001067 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001068 return NO_ERROR;
1069 } break;
1070 case SET_STREAM_MUTE: {
1071 CHECK_INTERFACE(IAudioFlinger, data, reply);
1072 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001073 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001074 return NO_ERROR;
1075 } break;
1076 case STREAM_VOLUME: {
1077 CHECK_INTERFACE(IAudioFlinger, data, reply);
1078 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001079 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001080 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001081 return NO_ERROR;
1082 } break;
1083 case STREAM_MUTE: {
1084 CHECK_INTERFACE(IAudioFlinger, data, reply);
1085 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001086 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001087 return NO_ERROR;
1088 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001089 case SET_MODE: {
1090 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001091 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001092 reply->writeInt32( setMode(mode) );
1093 return NO_ERROR;
1094 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001095 case SET_MIC_MUTE: {
1096 CHECK_INTERFACE(IAudioFlinger, data, reply);
1097 int state = data.readInt32();
1098 reply->writeInt32( setMicMute(state) );
1099 return NO_ERROR;
1100 } break;
1101 case GET_MIC_MUTE: {
1102 CHECK_INTERFACE(IAudioFlinger, data, reply);
1103 reply->writeInt32( getMicMute() );
1104 return NO_ERROR;
1105 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001106 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001107 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001108 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001109 String8 keyValuePairs(data.readString8());
1110 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001111 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001112 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001113 case GET_PARAMETERS: {
1114 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001115 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001116 String8 keys(data.readString8());
1117 reply->writeString8(getParameters(ioHandle, keys));
1118 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001119 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001120
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001121 case REGISTER_CLIENT: {
1122 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001123 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1124 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001125 registerClient(client);
1126 return NO_ERROR;
1127 } break;
1128 case GET_INPUTBUFFERSIZE: {
1129 CHECK_INTERFACE(IAudioFlinger, data, reply);
1130 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001131 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001132 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001133 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001134 return NO_ERROR;
1135 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001136 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001137 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001138 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001139 audio_config_t config = {};
1140 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1141 ALOGE("b/23905951");
1142 }
Eric Laurenta4c5a552012-03-29 10:12:40 -07001143 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001144 String8 address(data.readString8());
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001145 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001146 uint32_t latencyMs = 0;
Wei Jia4cac44b2015-09-16 15:01:16 -07001147 audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
Eric Laurentcf2c0212014-07-25 16:20:43 -07001148 status_t status = openOutput(module, &output, &config,
1149 &devices, address, &latencyMs, flags);
Glenn Kasten70742962014-02-18 08:00:47 -08001150 ALOGV("OPEN_OUTPUT output, %d", output);
Eric Laurentcf2c0212014-07-25 16:20:43 -07001151 reply->writeInt32((int32_t)status);
1152 if (status == NO_ERROR) {
1153 reply->writeInt32((int32_t)output);
1154 reply->write(&config, sizeof(audio_config_t));
1155 reply->writeInt32(devices);
1156 reply->writeInt32(latencyMs);
1157 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001158 return NO_ERROR;
1159 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001160 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001161 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001162 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1163 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1164 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001165 return NO_ERROR;
1166 } break;
1167 case CLOSE_OUTPUT: {
1168 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001169 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001170 return NO_ERROR;
1171 } break;
1172 case SUSPEND_OUTPUT: {
1173 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001174 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001175 return NO_ERROR;
1176 } break;
1177 case RESTORE_OUTPUT: {
1178 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001179 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001180 return NO_ERROR;
1181 } break;
1182 case OPEN_INPUT: {
1183 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001184 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001185 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001186 audio_config_t config = {};
1187 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1188 ALOGE("b/23905951");
1189 }
Eric Laurentcf2c0212014-07-25 16:20:43 -07001190 audio_devices_t device = (audio_devices_t)data.readInt32();
1191 String8 address(data.readString8());
1192 audio_source_t source = (audio_source_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001193 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001194
Eric Laurentcf2c0212014-07-25 16:20:43 -07001195 status_t status = openInput(module, &input, &config,
1196 &device, address, source, flags);
1197 reply->writeInt32((int32_t) status);
1198 if (status == NO_ERROR) {
1199 reply->writeInt32((int32_t) input);
1200 reply->write(&config, sizeof(audio_config_t));
1201 reply->writeInt32(device);
1202 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001203 return NO_ERROR;
1204 } break;
1205 case CLOSE_INPUT: {
1206 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001207 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001208 return NO_ERROR;
1209 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001210 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001211 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001212 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1213 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001214 return NO_ERROR;
1215 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001216 case SET_VOICE_VOLUME: {
1217 CHECK_INTERFACE(IAudioFlinger, data, reply);
1218 float volume = data.readFloat();
1219 reply->writeInt32( setVoiceVolume(volume) );
1220 return NO_ERROR;
1221 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001222 case GET_RENDER_POSITION: {
1223 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001224 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001225 uint32_t halFrames = 0;
1226 uint32_t dspFrames = 0;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001227 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1228 reply->writeInt32(status);
1229 if (status == NO_ERROR) {
1230 reply->writeInt32(halFrames);
1231 reply->writeInt32(dspFrames);
1232 }
1233 return NO_ERROR;
1234 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001235 case GET_INPUT_FRAMES_LOST: {
1236 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001237 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001238 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001239 return NO_ERROR;
1240 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001241 case NEW_AUDIO_SESSION_ID: {
1242 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasteneeecb982016-02-26 10:44:04 -08001243 reply->writeInt32(newAudioUniqueId((audio_unique_id_use_t) data.readInt32()));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001244 return NO_ERROR;
1245 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001246 case ACQUIRE_AUDIO_SESSION_ID: {
1247 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001248 audio_session_t audioSession = (audio_session_t) data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001249 int pid = data.readInt32();
1250 acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001251 return NO_ERROR;
1252 } break;
1253 case RELEASE_AUDIO_SESSION_ID: {
1254 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001255 audio_session_t audioSession = (audio_session_t) data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001256 int pid = data.readInt32();
1257 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001258 return NO_ERROR;
1259 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001260 case QUERY_NUM_EFFECTS: {
1261 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001262 uint32_t numEffects = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001263 status_t status = queryNumberEffects(&numEffects);
1264 reply->writeInt32(status);
1265 if (status == NO_ERROR) {
1266 reply->writeInt32((int32_t)numEffects);
1267 }
1268 return NO_ERROR;
1269 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001270 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001271 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001272 effect_descriptor_t desc = {};
Eric Laurentffe9c252010-06-23 17:38:20 -07001273 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001274 reply->writeInt32(status);
1275 if (status == NO_ERROR) {
1276 reply->write(&desc, sizeof(effect_descriptor_t));
1277 }
1278 return NO_ERROR;
1279 }
1280 case GET_EFFECT_DESCRIPTOR: {
1281 CHECK_INTERFACE(IAudioFlinger, data, reply);
1282 effect_uuid_t uuid;
1283 data.read(&uuid, sizeof(effect_uuid_t));
Wei Jia983dca32015-09-10 09:47:29 -07001284 effect_descriptor_t desc = {};
Eric Laurentbe916aa2010-06-01 23:49:17 -07001285 status_t status = getEffectDescriptor(&uuid, &desc);
1286 reply->writeInt32(status);
1287 if (status == NO_ERROR) {
1288 reply->write(&desc, sizeof(effect_descriptor_t));
1289 }
1290 return NO_ERROR;
1291 }
1292 case CREATE_EFFECT: {
1293 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001294 effect_descriptor_t desc = {};
1295 if (data.read(&desc, sizeof(effect_descriptor_t)) != NO_ERROR) {
1296 ALOGE("b/23905951");
1297 }
Eric Laurentbe916aa2010-06-01 23:49:17 -07001298 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1299 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001300 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001301 audio_session_t sessionId = (audio_session_t) data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -07001302 const String16 opPackageName = data.readString16();
Wei Jia983dca32015-09-10 09:47:29 -07001303 status_t status = NO_ERROR;
1304 int id = 0;
1305 int enabled = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001306
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001307 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -07001308 opPackageName, &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001309 reply->writeInt32(status);
1310 reply->writeInt32(id);
1311 reply->writeInt32(enabled);
Marco Nelissen06b46062014-11-14 07:58:25 -08001312 reply->writeStrongBinder(IInterface::asBinder(effect));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001313 reply->write(&desc, sizeof(effect_descriptor_t));
1314 return NO_ERROR;
1315 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001316 case MOVE_EFFECTS: {
1317 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001318 audio_session_t session = (audio_session_t) data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001319 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1320 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001321 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1322 return NO_ERROR;
1323 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001324 case LOAD_HW_MODULE: {
1325 CHECK_INTERFACE(IAudioFlinger, data, reply);
1326 reply->writeInt32(loadHwModule(data.readCString()));
1327 return NO_ERROR;
1328 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001329 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1330 CHECK_INTERFACE(IAudioFlinger, data, reply);
1331 reply->writeInt32(getPrimaryOutputSamplingRate());
1332 return NO_ERROR;
1333 } break;
1334 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1335 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001336 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001337 return NO_ERROR;
1338 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001339 case SET_LOW_RAM_DEVICE: {
1340 CHECK_INTERFACE(IAudioFlinger, data, reply);
1341 bool isLowRamDevice = data.readInt32() != 0;
1342 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1343 return NO_ERROR;
1344 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001345 case LIST_AUDIO_PORTS: {
1346 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001347 unsigned int numPortsReq = data.readInt32();
1348 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1349 numPortsReq = MAX_ITEMS_PER_LIST;
1350 }
1351 unsigned int numPorts = numPortsReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001352 struct audio_port *ports =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001353 (struct audio_port *)calloc(numPortsReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001354 sizeof(struct audio_port));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001355 if (ports == NULL) {
1356 reply->writeInt32(NO_MEMORY);
1357 reply->writeInt32(0);
1358 return NO_ERROR;
1359 }
1360 status_t status = listAudioPorts(&numPorts, ports);
Eric Laurent4b123402014-04-11 09:22:20 -07001361 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001362 reply->writeInt32(numPorts);
Eric Laurent4b123402014-04-11 09:22:20 -07001363 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001364 if (numPortsReq > numPorts) {
1365 numPortsReq = numPorts;
1366 }
1367 reply->write(ports, numPortsReq * sizeof(struct audio_port));
Eric Laurent4b123402014-04-11 09:22:20 -07001368 }
1369 free(ports);
1370 return NO_ERROR;
1371 } break;
1372 case GET_AUDIO_PORT: {
1373 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001374 struct audio_port port = {};
1375 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1376 ALOGE("b/23905951");
1377 }
Eric Laurent4b123402014-04-11 09:22:20 -07001378 status_t status = getAudioPort(&port);
1379 reply->writeInt32(status);
1380 if (status == NO_ERROR) {
1381 reply->write(&port, sizeof(struct audio_port));
1382 }
1383 return NO_ERROR;
1384 } break;
1385 case CREATE_AUDIO_PATCH: {
1386 CHECK_INTERFACE(IAudioFlinger, data, reply);
1387 struct audio_patch patch;
1388 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001389 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001390 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1391 ALOGE("b/23905951");
1392 }
Eric Laurent4b123402014-04-11 09:22:20 -07001393 status_t status = createAudioPatch(&patch, &handle);
1394 reply->writeInt32(status);
1395 if (status == NO_ERROR) {
1396 reply->write(&handle, sizeof(audio_patch_handle_t));
1397 }
1398 return NO_ERROR;
1399 } break;
1400 case RELEASE_AUDIO_PATCH: {
1401 CHECK_INTERFACE(IAudioFlinger, data, reply);
1402 audio_patch_handle_t handle;
1403 data.read(&handle, sizeof(audio_patch_handle_t));
1404 status_t status = releaseAudioPatch(handle);
1405 reply->writeInt32(status);
1406 return NO_ERROR;
1407 } break;
1408 case LIST_AUDIO_PATCHES: {
1409 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001410 unsigned int numPatchesReq = data.readInt32();
1411 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1412 numPatchesReq = MAX_ITEMS_PER_LIST;
1413 }
1414 unsigned int numPatches = numPatchesReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001415 struct audio_patch *patches =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001416 (struct audio_patch *)calloc(numPatchesReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001417 sizeof(struct audio_patch));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001418 if (patches == NULL) {
1419 reply->writeInt32(NO_MEMORY);
1420 reply->writeInt32(0);
1421 return NO_ERROR;
1422 }
1423 status_t status = listAudioPatches(&numPatches, patches);
Eric Laurent4b123402014-04-11 09:22:20 -07001424 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001425 reply->writeInt32(numPatches);
Eric Laurent4b123402014-04-11 09:22:20 -07001426 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001427 if (numPatchesReq > numPatches) {
1428 numPatchesReq = numPatches;
1429 }
1430 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
Eric Laurent4b123402014-04-11 09:22:20 -07001431 }
1432 free(patches);
1433 return NO_ERROR;
1434 } break;
1435 case SET_AUDIO_PORT_CONFIG: {
1436 CHECK_INTERFACE(IAudioFlinger, data, reply);
1437 struct audio_port_config config;
1438 data.read(&config, sizeof(struct audio_port_config));
1439 status_t status = setAudioPortConfig(&config);
1440 reply->writeInt32(status);
1441 return NO_ERROR;
1442 } break;
Eric Laurent93c3d412014-08-01 14:48:35 -07001443 case GET_AUDIO_HW_SYNC: {
1444 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001445 reply->writeInt32(getAudioHwSyncForSession((audio_session_t) data.readInt32()));
Eric Laurent93c3d412014-08-01 14:48:35 -07001446 return NO_ERROR;
1447 } break;
Eric Laurent72e3f392015-05-20 14:43:50 -07001448 case SYSTEM_READY: {
1449 CHECK_INTERFACE(IAudioFlinger, data, reply);
1450 systemReady();
1451 return NO_ERROR;
1452 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001453 case FRAME_COUNT_HAL: {
1454 CHECK_INTERFACE(IAudioFlinger, data, reply);
1455 reply->writeInt64( frameCountHAL((audio_io_handle_t) data.readInt32()) );
1456 return NO_ERROR;
1457 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001458 default:
1459 return BBinder::onTransact(code, data, reply, flags);
1460 }
1461}
1462
1463// ----------------------------------------------------------------------------
1464
Glenn Kasten40bc9062015-03-20 09:09:33 -07001465} // namespace android