blob: aa7518802b42172546bf74db197e92eda4f7124c [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:
93 BpAudioFlinger(const sp<IBinder>& impl)
94 : 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,
Glenn Kastene0b07172012-11-06 15:03:34 -0800104 track_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,
Glenn Kasten3acbd052012-02-28 10:39:56 -0800107 pid_t tid,
Glenn Kastend848eb42016-03-08 13:42:11 -0800108 audio_session_t *sessionId,
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800109 int clientUid,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800110 status_t *status)
111 {
112 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700113 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800114 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800115 data.writeInt32((int32_t) streamType);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800116 data.writeInt32(sampleRate);
117 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700118 data.writeInt32(channelMask);
Glenn Kasten74935e42013-12-19 08:56:45 -0800119 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800120 data.writeInt64(frameCount);
Glenn Kastenb26e3e92012-11-14 08:32:08 -0800121 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
Glenn Kastene0b07172012-11-06 15:03:34 -0800122 data.writeInt32(lFlags);
Glenn Kasten2301acc2014-01-17 10:21:00 -0800123 // haveSharedBuffer
Eric Laurent3d00aa62013-09-24 09:53:27 -0700124 if (sharedBuffer != 0) {
125 data.writeInt32(true);
Marco Nelissen06b46062014-11-14 07:58:25 -0800126 data.writeStrongBinder(IInterface::asBinder(sharedBuffer));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700127 } else {
128 data.writeInt32(false);
129 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800130 data.writeInt32((int32_t) output);
Glenn Kasten3acbd052012-02-28 10:39:56 -0800131 data.writeInt32((int32_t) tid);
Glenn Kastend848eb42016-03-08 13:42:11 -0800132 audio_session_t lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700133 if (sessionId != NULL) {
134 lSessionId = *sessionId;
135 }
136 data.writeInt32(lSessionId);
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800137 data.writeInt32(clientUid);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800138 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
139 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000140 ALOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700141 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700142 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800143 if (pFrameCount != NULL) {
144 *pFrameCount = frameCount;
145 }
Glenn Kastene0b07172012-11-06 15:03:34 -0800146 lFlags = reply.readInt32();
147 if (flags != NULL) {
148 *flags = lFlags;
149 }
Glenn Kastend848eb42016-03-08 13:42:11 -0800150 lSessionId = (audio_session_t) reply.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700151 if (sessionId != NULL) {
152 *sessionId = lSessionId;
153 }
Eric Laurent5841db72009-09-09 05:16:08 -0700154 lStatus = reply.readInt32();
155 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
Glenn Kasten0cde0762014-01-16 15:06:36 -0800156 if (lStatus == NO_ERROR) {
157 if (track == 0) {
158 ALOGE("createTrack should have returned an IAudioTrack");
159 lStatus = UNKNOWN_ERROR;
160 }
161 } else {
162 if (track != 0) {
163 ALOGE("createTrack returned an IAudioTrack but with status %d", lStatus);
164 track.clear();
165 }
166 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800167 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700168 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800169 *status = lStatus;
170 }
Eric Laurent5841db72009-09-09 05:16:08 -0700171 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800172 }
173
174 virtual sp<IAudioRecord> openRecord(
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800175 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800176 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800177 audio_format_t format,
Glenn Kasten28b76b32012-07-03 17:24:41 -0700178 audio_channel_mask_t channelMask,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700179 const String16& opPackageName,
Glenn Kasten74935e42013-12-19 08:56:45 -0800180 size_t *pFrameCount,
Glenn Kasteneeca3262013-07-31 16:12:48 -0700181 track_flags_t *flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -0700182 pid_t tid,
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700183 int clientUid,
Glenn Kastend848eb42016-03-08 13:42:11 -0800184 audio_session_t *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700185 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700186 sp<IMemory>& cblk,
187 sp<IMemory>& buffers,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800188 status_t *status)
189 {
190 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700191 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800192 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800193 data.writeInt32((int32_t) input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800194 data.writeInt32(sampleRate);
195 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700196 data.writeInt32(channelMask);
Dianne Hackborneaa34702015-04-29 12:57:58 -0700197 data.writeString16(opPackageName);
Glenn Kasten74935e42013-12-19 08:56:45 -0800198 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800199 data.writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700200 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
201 data.writeInt32(lFlags);
Glenn Kasten1879fff2012-07-11 15:36:59 -0700202 data.writeInt32((int32_t) tid);
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700203 data.writeInt32((int32_t) clientUid);
Glenn Kastend848eb42016-03-08 13:42:11 -0800204 audio_session_t lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700205 if (sessionId != NULL) {
206 lSessionId = *sessionId;
207 }
208 data.writeInt32(lSessionId);
Glenn Kasten74105912014-07-03 12:28:53 -0700209 data.writeInt64(notificationFrames != NULL ? *notificationFrames : 0);
Glenn Kastend776ac62014-05-07 09:16:09 -0700210 cblk.clear();
211 buffers.clear();
Eric Laurent5841db72009-09-09 05:16:08 -0700212 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
213 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000214 ALOGE("openRecord error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700215 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700216 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800217 if (pFrameCount != NULL) {
218 *pFrameCount = frameCount;
219 }
Glenn Kasteneeca3262013-07-31 16:12:48 -0700220 lFlags = reply.readInt32();
221 if (flags != NULL) {
222 *flags = lFlags;
223 }
Glenn Kastend848eb42016-03-08 13:42:11 -0800224 lSessionId = (audio_session_t) reply.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700225 if (sessionId != NULL) {
226 *sessionId = lSessionId;
227 }
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700228 size_t lNotificationFrames = (size_t) reply.readInt64();
229 if (notificationFrames != NULL) {
230 *notificationFrames = lNotificationFrames;
231 }
Eric Laurent5841db72009-09-09 05:16:08 -0700232 lStatus = reply.readInt32();
233 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700234 cblk = interface_cast<IMemory>(reply.readStrongBinder());
235 if (cblk != 0 && cblk->pointer() == NULL) {
236 cblk.clear();
237 }
238 buffers = interface_cast<IMemory>(reply.readStrongBinder());
239 if (buffers != 0 && buffers->pointer() == NULL) {
240 buffers.clear();
241 }
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700242 if (lStatus == NO_ERROR) {
243 if (record == 0) {
244 ALOGE("openRecord should have returned an IAudioRecord");
245 lStatus = UNKNOWN_ERROR;
Glenn Kastend776ac62014-05-07 09:16:09 -0700246 } else if (cblk == 0) {
247 ALOGE("openRecord should have returned a cblk");
248 lStatus = NO_MEMORY;
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700249 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700250 // buffers is permitted to be 0
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700251 } else {
Glenn Kastend776ac62014-05-07 09:16:09 -0700252 if (record != 0 || cblk != 0 || buffers != 0) {
253 ALOGE("openRecord returned an IAudioRecord, cblk, "
254 "or buffers but with status %d", lStatus);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700255 }
256 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700257 if (lStatus != NO_ERROR) {
258 record.clear();
259 cblk.clear();
260 buffers.clear();
261 }
Eric Laurent5841db72009-09-09 05:16:08 -0700262 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700263 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800264 *status = lStatus;
265 }
Eric Laurent5841db72009-09-09 05:16:08 -0700266 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800267 }
268
Glenn Kasten2c073da2016-02-26 09:14:08 -0800269 virtual uint32_t sampleRate(audio_io_handle_t ioHandle) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800270 {
271 Parcel data, reply;
272 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten2c073da2016-02-26 09:14:08 -0800273 data.writeInt32((int32_t) ioHandle);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800274 remote()->transact(SAMPLE_RATE, data, &reply);
275 return reply.readInt32();
276 }
277
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700278 // RESERVED for channelCount()
279
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800280 virtual audio_format_t format(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800281 {
282 Parcel data, reply;
283 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800284 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800285 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800286 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800287 }
288
Glenn Kasten2c073da2016-02-26 09:14:08 -0800289 virtual size_t frameCount(audio_io_handle_t ioHandle) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800290 {
291 Parcel data, reply;
292 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten2c073da2016-02-26 09:14:08 -0800293 data.writeInt32((int32_t) ioHandle);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800294 remote()->transact(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800295 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800296 }
297
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800298 virtual uint32_t latency(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800299 {
300 Parcel data, reply;
301 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800302 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800303 remote()->transact(LATENCY, data, &reply);
304 return reply.readInt32();
305 }
306
307 virtual status_t setMasterVolume(float value)
308 {
309 Parcel data, reply;
310 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
311 data.writeFloat(value);
312 remote()->transact(SET_MASTER_VOLUME, data, &reply);
313 return reply.readInt32();
314 }
315
316 virtual status_t setMasterMute(bool muted)
317 {
318 Parcel data, reply;
319 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
320 data.writeInt32(muted);
321 remote()->transact(SET_MASTER_MUTE, data, &reply);
322 return reply.readInt32();
323 }
324
325 virtual float masterVolume() const
326 {
327 Parcel data, reply;
328 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
329 remote()->transact(MASTER_VOLUME, data, &reply);
330 return reply.readFloat();
331 }
332
333 virtual bool masterMute() const
334 {
335 Parcel data, reply;
336 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
337 remote()->transact(MASTER_MUTE, data, &reply);
338 return reply.readInt32();
339 }
340
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800341 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
342 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800343 {
344 Parcel data, reply;
345 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800346 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800347 data.writeFloat(value);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800348 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800349 remote()->transact(SET_STREAM_VOLUME, data, &reply);
350 return reply.readInt32();
351 }
352
Glenn Kastenfff6d712012-01-12 16:38:12 -0800353 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800354 {
355 Parcel data, reply;
356 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800357 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800358 data.writeInt32(muted);
359 remote()->transact(SET_STREAM_MUTE, data, &reply);
360 return reply.readInt32();
361 }
362
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800363 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800364 {
365 Parcel data, reply;
366 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800367 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800368 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800369 remote()->transact(STREAM_VOLUME, data, &reply);
370 return reply.readFloat();
371 }
372
Glenn Kastenfff6d712012-01-12 16:38:12 -0800373 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800374 {
375 Parcel data, reply;
376 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800377 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800378 remote()->transact(STREAM_MUTE, data, &reply);
379 return reply.readInt32();
380 }
381
Glenn Kastenf78aee72012-01-04 11:00:47 -0800382 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800383 {
384 Parcel data, reply;
385 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
386 data.writeInt32(mode);
387 remote()->transact(SET_MODE, data, &reply);
388 return reply.readInt32();
389 }
390
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800391 virtual status_t setMicMute(bool state)
392 {
393 Parcel data, reply;
394 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
395 data.writeInt32(state);
396 remote()->transact(SET_MIC_MUTE, data, &reply);
397 return reply.readInt32();
398 }
399
400 virtual bool getMicMute() const
401 {
402 Parcel data, reply;
403 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
404 remote()->transact(GET_MIC_MUTE, data, &reply);
405 return reply.readInt32();
406 }
407
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800408 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800409 {
410 Parcel data, reply;
411 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800412 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700413 data.writeString8(keyValuePairs);
414 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800415 return reply.readInt32();
416 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700417
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800418 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700419 {
420 Parcel data, reply;
421 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800422 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700423 data.writeString8(keys);
424 remote()->transact(GET_PARAMETERS, data, &reply);
425 return reply.readString8();
426 }
427
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800428 virtual void registerClient(const sp<IAudioFlingerClient>& client)
429 {
430 Parcel data, reply;
431 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800432 data.writeStrongBinder(IInterface::asBinder(client));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800433 remote()->transact(REGISTER_CLIENT, data, &reply);
434 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700435
Glenn Kastendd8104c2012-07-02 12:42:44 -0700436 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
437 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800438 {
439 Parcel data, reply;
440 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
441 data.writeInt32(sampleRate);
442 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700443 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800444 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800445 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800446 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700447
Eric Laurentcf2c0212014-07-25 16:20:43 -0700448 virtual status_t openOutput(audio_module_handle_t module,
449 audio_io_handle_t *output,
450 audio_config_t *config,
451 audio_devices_t *devices,
452 const String8& address,
453 uint32_t *latencyMs,
454 audio_output_flags_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800455 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700456 if (output == NULL || config == NULL || devices == NULL || latencyMs == NULL) {
457 return BAD_VALUE;
458 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800459 Parcel data, reply;
460 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700461 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700462 data.write(config, sizeof(audio_config_t));
463 data.writeInt32(*devices);
464 data.writeString8(address);
Glenn Kasten18868c52012-03-07 09:15:37 -0800465 data.writeInt32((int32_t) flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700466 status_t status = remote()->transact(OPEN_OUTPUT, data, &reply);
467 if (status != NO_ERROR) {
468 *output = AUDIO_IO_HANDLE_NONE;
469 return status;
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100470 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700471 status = (status_t)reply.readInt32();
472 if (status != NO_ERROR) {
473 *output = AUDIO_IO_HANDLE_NONE;
474 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700475 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700476 *output = (audio_io_handle_t)reply.readInt32();
477 ALOGV("openOutput() returned output, %d", *output);
478 reply.read(config, sizeof(audio_config_t));
479 *devices = (audio_devices_t)reply.readInt32();
480 *latencyMs = reply.readInt32();
481 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800482 }
483
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800484 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
485 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800486 {
487 Parcel data, reply;
488 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800489 data.writeInt32((int32_t) output1);
490 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700491 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800492 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700493 }
494
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800495 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700496 {
497 Parcel data, reply;
498 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800499 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700500 remote()->transact(CLOSE_OUTPUT, data, &reply);
501 return reply.readInt32();
502 }
503
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800504 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700505 {
506 Parcel data, reply;
507 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800508 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700509 remote()->transact(SUSPEND_OUTPUT, data, &reply);
510 return reply.readInt32();
511 }
512
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800513 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700514 {
515 Parcel data, reply;
516 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800517 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700518 remote()->transact(RESTORE_OUTPUT, data, &reply);
519 return reply.readInt32();
520 }
521
Eric Laurentcf2c0212014-07-25 16:20:43 -0700522 virtual status_t openInput(audio_module_handle_t module,
523 audio_io_handle_t *input,
524 audio_config_t *config,
525 audio_devices_t *device,
526 const String8& address,
527 audio_source_t source,
528 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700529 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700530 if (input == NULL || config == NULL || device == NULL) {
531 return BAD_VALUE;
532 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700533 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700534 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700535 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700536 data.writeInt32(*input);
537 data.write(config, sizeof(audio_config_t));
538 data.writeInt32(*device);
539 data.writeString8(address);
540 data.writeInt32(source);
Glenn Kastenec40d282014-07-15 15:31:26 -0700541 data.writeInt32(flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700542 status_t status = remote()->transact(OPEN_INPUT, data, &reply);
543 if (status != NO_ERROR) {
544 *input = AUDIO_IO_HANDLE_NONE;
545 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700546 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700547 status = (status_t)reply.readInt32();
548 if (status != NO_ERROR) {
549 *input = AUDIO_IO_HANDLE_NONE;
550 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700551 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700552 *input = (audio_io_handle_t)reply.readInt32();
553 reply.read(config, sizeof(audio_config_t));
554 *device = (audio_devices_t)reply.readInt32();
555 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700556 }
557
Eric Laurentfa2877b2009-07-28 08:44:33 -0700558 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700559 {
560 Parcel data, reply;
561 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700562 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700563 remote()->transact(CLOSE_INPUT, data, &reply);
564 return reply.readInt32();
565 }
566
Glenn Kastend2304db2014-02-03 07:40:31 -0800567 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700568 {
569 Parcel data, reply;
570 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800571 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800572 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700573 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800574 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700575
576 virtual status_t setVoiceVolume(float volume)
577 {
578 Parcel data, reply;
579 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
580 data.writeFloat(volume);
581 remote()->transact(SET_VOICE_VOLUME, data, &reply);
582 return reply.readInt32();
583 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800584
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000585 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800586 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800587 {
588 Parcel data, reply;
589 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800590 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800591 remote()->transact(GET_RENDER_POSITION, data, &reply);
592 status_t status = reply.readInt32();
593 if (status == NO_ERROR) {
594 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700595 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800596 *halFrames = tmp;
597 }
598 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700599 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800600 *dspFrames = tmp;
601 }
602 }
603 return status;
604 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800605
Glenn Kasten5f972c02014-01-13 09:59:31 -0800606 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800607 {
608 Parcel data, reply;
609 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800610 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800611 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
612 if (status != NO_ERROR) {
613 return 0;
614 }
615 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800616 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700617
Glenn Kasteneeecb982016-02-26 10:44:04 -0800618 virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use)
Eric Laurentbe916aa2010-06-01 23:49:17 -0700619 {
620 Parcel data, reply;
621 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasteneeecb982016-02-26 10:44:04 -0800622 data.writeInt32((int32_t) use);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700623 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
Eric Laurentde3f8392014-07-27 18:38:22 -0700624 audio_unique_id_t id = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700625 if (status == NO_ERROR) {
626 id = reply.readInt32();
627 }
628 return id;
629 }
630
Glenn Kastend848eb42016-03-08 13:42:11 -0800631 virtual void acquireAudioSessionId(audio_session_t audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700632 {
633 Parcel data, reply;
634 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
635 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800636 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700637 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
638 }
639
Glenn Kastend848eb42016-03-08 13:42:11 -0800640 virtual void releaseAudioSessionId(audio_session_t audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700641 {
642 Parcel data, reply;
643 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
644 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800645 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700646 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
647 }
648
Glenn Kastenf587ba52012-01-26 16:25:10 -0800649 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700650 {
651 Parcel data, reply;
652 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
653 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
654 if (status != NO_ERROR) {
655 return status;
656 }
657 status = reply.readInt32();
658 if (status != NO_ERROR) {
659 return status;
660 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800661 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700662 *numEffects = (uint32_t)reply.readInt32();
663 }
664 return NO_ERROR;
665 }
666
Glenn Kastenf587ba52012-01-26 16:25:10 -0800667 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700668 {
669 if (pDescriptor == NULL) {
670 return BAD_VALUE;
671 }
672 Parcel data, reply;
673 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700674 data.writeInt32(index);
675 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700676 if (status != NO_ERROR) {
677 return status;
678 }
679 status = reply.readInt32();
680 if (status != NO_ERROR) {
681 return status;
682 }
683 reply.read(pDescriptor, sizeof(effect_descriptor_t));
684 return NO_ERROR;
685 }
686
Glenn Kasten5e92a782012-01-30 07:40:52 -0800687 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800688 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700689 {
690 if (pUuid == NULL || pDescriptor == NULL) {
691 return BAD_VALUE;
692 }
693 Parcel data, reply;
694 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
695 data.write(pUuid, sizeof(effect_uuid_t));
696 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
697 if (status != NO_ERROR) {
698 return status;
699 }
700 status = reply.readInt32();
701 if (status != NO_ERROR) {
702 return status;
703 }
704 reply.read(pDescriptor, sizeof(effect_descriptor_t));
705 return NO_ERROR;
706 }
707
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800708 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700709 effect_descriptor_t *pDesc,
710 const sp<IEffectClient>& client,
711 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800712 audio_io_handle_t output,
Glenn Kastend848eb42016-03-08 13:42:11 -0800713 audio_session_t sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700714 const String16& opPackageName,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700715 status_t *status,
716 int *id,
717 int *enabled)
718 {
719 Parcel data, reply;
720 sp<IEffect> effect;
721
722 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700723 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700724 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700725 *status = BAD_VALUE;
726 }
727 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700728
729 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700730 data.write(pDesc, sizeof(effect_descriptor_t));
Marco Nelissen06b46062014-11-14 07:58:25 -0800731 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700732 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800733 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700734 data.writeInt32(sessionId);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700735 data.writeString16(opPackageName);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700736
737 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
738 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000739 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700740 } else {
741 lStatus = reply.readInt32();
742 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700743 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700744 *id = tmp;
745 }
746 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800747 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700748 *enabled = tmp;
749 }
750 effect = interface_cast<IEffect>(reply.readStrongBinder());
751 reply.read(pDesc, sizeof(effect_descriptor_t));
752 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700753 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700754 *status = lStatus;
755 }
756
757 return effect;
758 }
Eric Laurentde070132010-07-13 04:45:46 -0700759
Glenn Kastend848eb42016-03-08 13:42:11 -0800760 virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800761 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700762 {
763 Parcel data, reply;
764 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
765 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800766 data.writeInt32((int32_t) srcOutput);
767 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700768 remote()->transact(MOVE_EFFECTS, data, &reply);
769 return reply.readInt32();
770 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700771
772 virtual audio_module_handle_t loadHwModule(const char *name)
773 {
774 Parcel data, reply;
775 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
776 data.writeCString(name);
777 remote()->transact(LOAD_HW_MODULE, data, &reply);
778 return (audio_module_handle_t) reply.readInt32();
779 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700780
Glenn Kasten3b16c762012-11-14 08:44:39 -0800781 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700782 {
783 Parcel data, reply;
784 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
785 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
786 return reply.readInt32();
787 }
788
Glenn Kastene33054e2012-11-14 12:54:39 -0800789 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700790 {
791 Parcel data, reply;
792 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
793 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800794 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700795 }
796
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700797 virtual status_t setLowRamDevice(bool isLowRamDevice)
798 {
799 Parcel data, reply;
800 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
801 data.writeInt32((int) isLowRamDevice);
802 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
803 return reply.readInt32();
804 }
Eric Laurent4b123402014-04-11 09:22:20 -0700805 virtual status_t listAudioPorts(unsigned int *num_ports,
806 struct audio_port *ports)
807 {
808 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
809 return BAD_VALUE;
810 }
811 Parcel data, reply;
812 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
813 data.writeInt32(*num_ports);
814 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
815 if (status != NO_ERROR ||
816 (status = (status_t)reply.readInt32()) != NO_ERROR) {
817 return status;
818 }
819 *num_ports = (unsigned int)reply.readInt32();
820 reply.read(ports, *num_ports * sizeof(struct audio_port));
821 return status;
822 }
823 virtual status_t getAudioPort(struct audio_port *port)
824 {
825 if (port == NULL) {
826 return BAD_VALUE;
827 }
828 Parcel data, reply;
829 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
830 data.write(port, sizeof(struct audio_port));
831 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
832 if (status != NO_ERROR ||
833 (status = (status_t)reply.readInt32()) != NO_ERROR) {
834 return status;
835 }
836 reply.read(port, sizeof(struct audio_port));
837 return status;
838 }
839 virtual status_t createAudioPatch(const struct audio_patch *patch,
840 audio_patch_handle_t *handle)
841 {
842 if (patch == NULL || handle == NULL) {
843 return BAD_VALUE;
844 }
845 Parcel data, reply;
846 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
847 data.write(patch, sizeof(struct audio_patch));
848 data.write(handle, sizeof(audio_patch_handle_t));
849 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
850 if (status != NO_ERROR ||
851 (status = (status_t)reply.readInt32()) != NO_ERROR) {
852 return status;
853 }
854 reply.read(handle, sizeof(audio_patch_handle_t));
855 return status;
856 }
857 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
858 {
859 Parcel data, reply;
860 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
861 data.write(&handle, sizeof(audio_patch_handle_t));
862 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
863 if (status != NO_ERROR) {
864 status = (status_t)reply.readInt32();
865 }
866 return status;
867 }
868 virtual status_t listAudioPatches(unsigned int *num_patches,
869 struct audio_patch *patches)
870 {
871 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
872 return BAD_VALUE;
873 }
874 Parcel data, reply;
875 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
876 data.writeInt32(*num_patches);
877 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
878 if (status != NO_ERROR ||
879 (status = (status_t)reply.readInt32()) != NO_ERROR) {
880 return status;
881 }
882 *num_patches = (unsigned int)reply.readInt32();
883 reply.read(patches, *num_patches * sizeof(struct audio_patch));
884 return status;
885 }
886 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
887 {
888 if (config == NULL) {
889 return BAD_VALUE;
890 }
891 Parcel data, reply;
892 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
893 data.write(config, sizeof(struct audio_port_config));
894 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
895 if (status != NO_ERROR) {
896 status = (status_t)reply.readInt32();
897 }
898 return status;
899 }
Eric Laurent93c3d412014-08-01 14:48:35 -0700900 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
901 {
902 Parcel data, reply;
903 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
904 data.writeInt32(sessionId);
905 status_t status = remote()->transact(GET_AUDIO_HW_SYNC, data, &reply);
906 if (status != NO_ERROR) {
907 return AUDIO_HW_SYNC_INVALID;
908 }
909 return (audio_hw_sync_t)reply.readInt32();
910 }
Eric Laurent72e3f392015-05-20 14:43:50 -0700911 virtual status_t systemReady()
912 {
913 Parcel data, reply;
914 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
915 return remote()->transact(SYSTEM_READY, data, &reply, IBinder::FLAG_ONEWAY);
916 }
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700917 virtual size_t frameCountHAL(audio_io_handle_t ioHandle) const
918 {
919 Parcel data, reply;
920 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
921 data.writeInt32((int32_t) ioHandle);
922 status_t status = remote()->transact(FRAME_COUNT_HAL, data, &reply);
923 if (status != NO_ERROR) {
924 return 0;
925 }
926 return reply.readInt64();
927 }
928
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800929};
930
931IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
932
933// ----------------------------------------------------------------------
934
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800935status_t BnAudioFlinger::onTransact(
936 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
937{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700938 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800939 case CREATE_TRACK: {
940 CHECK_INTERFACE(IAudioFlinger, data, reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800941 int streamType = data.readInt32();
942 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800943 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700944 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800945 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800946 track_flags_t flags = (track_flags_t) data.readInt32();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700947 bool haveSharedBuffer = data.readInt32() != 0;
948 sp<IMemory> buffer;
949 if (haveSharedBuffer) {
950 buffer = interface_cast<IMemory>(data.readStrongBinder());
951 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800952 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kasten3acbd052012-02-28 10:39:56 -0800953 pid_t tid = (pid_t) data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -0800954 audio_session_t sessionId = (audio_session_t) data.readInt32();
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800955 int clientUid = data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -0700956 status_t status = NO_ERROR;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700957 sp<IAudioTrack> track;
958 if ((haveSharedBuffer && (buffer == 0)) ||
959 ((buffer != 0) && (buffer->pointer() == NULL))) {
960 ALOGW("CREATE_TRACK: cannot retrieve shared memory");
961 status = DEAD_OBJECT;
962 } else {
963 track = createTrack(
964 (audio_stream_type_t) streamType, sampleRate, format,
Glenn Kasten74935e42013-12-19 08:56:45 -0800965 channelMask, &frameCount, &flags, buffer, output, tid,
Glenn Kastenc5a17422014-03-13 14:59:59 -0700966 &sessionId, clientUid, &status);
Glenn Kasten0cde0762014-01-16 15:06:36 -0800967 LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700968 }
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700969 reply->writeInt64(frameCount);
Glenn Kastene0b07172012-11-06 15:03:34 -0800970 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700971 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800972 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800973 reply->writeStrongBinder(IInterface::asBinder(track));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800974 return NO_ERROR;
975 } break;
976 case OPEN_RECORD: {
977 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800978 audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800979 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800980 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700981 audio_channel_mask_t channelMask = data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -0700982 const String16& opPackageName = data.readString16();
Glenn Kastene03dd222014-01-28 11:04:39 -0800983 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800984 track_flags_t flags = (track_flags_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700985 pid_t tid = (pid_t) data.readInt32();
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700986 int clientUid = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -0800987 audio_session_t sessionId = (audio_session_t) data.readInt32();
Glenn Kasten74105912014-07-03 12:28:53 -0700988 size_t notificationFrames = data.readInt64();
Glenn Kastend776ac62014-05-07 09:16:09 -0700989 sp<IMemory> cblk;
990 sp<IMemory> buffers;
Wei Jia983dca32015-09-10 09:47:29 -0700991 status_t status = NO_ERROR;
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800992 sp<IAudioRecord> record = openRecord(input,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700993 sampleRate, format, channelMask, opPackageName, &frameCount, &flags, tid,
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700994 clientUid, &sessionId, &notificationFrames, cblk, buffers, &status);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700995 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700996 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700997 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700998 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700999 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001000 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -08001001 reply->writeStrongBinder(IInterface::asBinder(record));
1002 reply->writeStrongBinder(IInterface::asBinder(cblk));
1003 reply->writeStrongBinder(IInterface::asBinder(buffers));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001004 return NO_ERROR;
1005 } break;
1006 case SAMPLE_RATE: {
1007 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001008 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001009 return NO_ERROR;
1010 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001011
1012 // RESERVED for channelCount()
1013
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001014 case FORMAT: {
1015 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001016 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001017 return NO_ERROR;
1018 } break;
1019 case FRAME_COUNT: {
1020 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001021 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001022 return NO_ERROR;
1023 } break;
1024 case LATENCY: {
1025 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001026 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001027 return NO_ERROR;
1028 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001029 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001030 CHECK_INTERFACE(IAudioFlinger, data, reply);
1031 reply->writeInt32( setMasterVolume(data.readFloat()) );
1032 return NO_ERROR;
1033 } break;
1034 case SET_MASTER_MUTE: {
1035 CHECK_INTERFACE(IAudioFlinger, data, reply);
1036 reply->writeInt32( setMasterMute(data.readInt32()) );
1037 return NO_ERROR;
1038 } break;
1039 case MASTER_VOLUME: {
1040 CHECK_INTERFACE(IAudioFlinger, data, reply);
1041 reply->writeFloat( masterVolume() );
1042 return NO_ERROR;
1043 } break;
1044 case MASTER_MUTE: {
1045 CHECK_INTERFACE(IAudioFlinger, data, reply);
1046 reply->writeInt32( masterMute() );
1047 return NO_ERROR;
1048 } break;
1049 case SET_STREAM_VOLUME: {
1050 CHECK_INTERFACE(IAudioFlinger, data, reply);
1051 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001052 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001053 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001054 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001055 return NO_ERROR;
1056 } break;
1057 case SET_STREAM_MUTE: {
1058 CHECK_INTERFACE(IAudioFlinger, data, reply);
1059 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001060 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001061 return NO_ERROR;
1062 } break;
1063 case STREAM_VOLUME: {
1064 CHECK_INTERFACE(IAudioFlinger, data, reply);
1065 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001066 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001067 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001068 return NO_ERROR;
1069 } break;
1070 case STREAM_MUTE: {
1071 CHECK_INTERFACE(IAudioFlinger, data, reply);
1072 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001073 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001074 return NO_ERROR;
1075 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001076 case SET_MODE: {
1077 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001078 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001079 reply->writeInt32( setMode(mode) );
1080 return NO_ERROR;
1081 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001082 case SET_MIC_MUTE: {
1083 CHECK_INTERFACE(IAudioFlinger, data, reply);
1084 int state = data.readInt32();
1085 reply->writeInt32( setMicMute(state) );
1086 return NO_ERROR;
1087 } break;
1088 case GET_MIC_MUTE: {
1089 CHECK_INTERFACE(IAudioFlinger, data, reply);
1090 reply->writeInt32( getMicMute() );
1091 return NO_ERROR;
1092 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001093 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001094 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001095 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001096 String8 keyValuePairs(data.readString8());
1097 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001098 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001099 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001100 case GET_PARAMETERS: {
1101 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001102 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001103 String8 keys(data.readString8());
1104 reply->writeString8(getParameters(ioHandle, keys));
1105 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001106 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001107
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001108 case REGISTER_CLIENT: {
1109 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001110 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1111 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001112 registerClient(client);
1113 return NO_ERROR;
1114 } break;
1115 case GET_INPUTBUFFERSIZE: {
1116 CHECK_INTERFACE(IAudioFlinger, data, reply);
1117 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001118 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001119 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001120 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001121 return NO_ERROR;
1122 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001123 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001124 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001125 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001126 audio_config_t config = {};
1127 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1128 ALOGE("b/23905951");
1129 }
Eric Laurenta4c5a552012-03-29 10:12:40 -07001130 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001131 String8 address(data.readString8());
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001132 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001133 uint32_t latencyMs = 0;
Wei Jia4cac44b2015-09-16 15:01:16 -07001134 audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
Eric Laurentcf2c0212014-07-25 16:20:43 -07001135 status_t status = openOutput(module, &output, &config,
1136 &devices, address, &latencyMs, flags);
Glenn Kasten70742962014-02-18 08:00:47 -08001137 ALOGV("OPEN_OUTPUT output, %d", output);
Eric Laurentcf2c0212014-07-25 16:20:43 -07001138 reply->writeInt32((int32_t)status);
1139 if (status == NO_ERROR) {
1140 reply->writeInt32((int32_t)output);
1141 reply->write(&config, sizeof(audio_config_t));
1142 reply->writeInt32(devices);
1143 reply->writeInt32(latencyMs);
1144 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001145 return NO_ERROR;
1146 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001147 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001148 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001149 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1150 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1151 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001152 return NO_ERROR;
1153 } break;
1154 case CLOSE_OUTPUT: {
1155 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001156 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001157 return NO_ERROR;
1158 } break;
1159 case SUSPEND_OUTPUT: {
1160 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001161 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001162 return NO_ERROR;
1163 } break;
1164 case RESTORE_OUTPUT: {
1165 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001166 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001167 return NO_ERROR;
1168 } break;
1169 case OPEN_INPUT: {
1170 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001171 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001172 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001173 audio_config_t config = {};
1174 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1175 ALOGE("b/23905951");
1176 }
Eric Laurentcf2c0212014-07-25 16:20:43 -07001177 audio_devices_t device = (audio_devices_t)data.readInt32();
1178 String8 address(data.readString8());
1179 audio_source_t source = (audio_source_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001180 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001181
Eric Laurentcf2c0212014-07-25 16:20:43 -07001182 status_t status = openInput(module, &input, &config,
1183 &device, address, source, flags);
1184 reply->writeInt32((int32_t) status);
1185 if (status == NO_ERROR) {
1186 reply->writeInt32((int32_t) input);
1187 reply->write(&config, sizeof(audio_config_t));
1188 reply->writeInt32(device);
1189 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001190 return NO_ERROR;
1191 } break;
1192 case CLOSE_INPUT: {
1193 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001194 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001195 return NO_ERROR;
1196 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001197 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001198 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001199 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1200 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001201 return NO_ERROR;
1202 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001203 case SET_VOICE_VOLUME: {
1204 CHECK_INTERFACE(IAudioFlinger, data, reply);
1205 float volume = data.readFloat();
1206 reply->writeInt32( setVoiceVolume(volume) );
1207 return NO_ERROR;
1208 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001209 case GET_RENDER_POSITION: {
1210 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001211 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001212 uint32_t halFrames = 0;
1213 uint32_t dspFrames = 0;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001214 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1215 reply->writeInt32(status);
1216 if (status == NO_ERROR) {
1217 reply->writeInt32(halFrames);
1218 reply->writeInt32(dspFrames);
1219 }
1220 return NO_ERROR;
1221 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001222 case GET_INPUT_FRAMES_LOST: {
1223 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001224 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001225 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001226 return NO_ERROR;
1227 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001228 case NEW_AUDIO_SESSION_ID: {
1229 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasteneeecb982016-02-26 10:44:04 -08001230 reply->writeInt32(newAudioUniqueId((audio_unique_id_use_t) data.readInt32()));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001231 return NO_ERROR;
1232 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001233 case ACQUIRE_AUDIO_SESSION_ID: {
1234 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001235 audio_session_t audioSession = (audio_session_t) data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001236 int pid = data.readInt32();
1237 acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001238 return NO_ERROR;
1239 } break;
1240 case RELEASE_AUDIO_SESSION_ID: {
1241 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001242 audio_session_t audioSession = (audio_session_t) data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001243 int pid = data.readInt32();
1244 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001245 return NO_ERROR;
1246 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001247 case QUERY_NUM_EFFECTS: {
1248 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001249 uint32_t numEffects = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001250 status_t status = queryNumberEffects(&numEffects);
1251 reply->writeInt32(status);
1252 if (status == NO_ERROR) {
1253 reply->writeInt32((int32_t)numEffects);
1254 }
1255 return NO_ERROR;
1256 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001257 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001258 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001259 effect_descriptor_t desc = {};
Eric Laurentffe9c252010-06-23 17:38:20 -07001260 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001261 reply->writeInt32(status);
1262 if (status == NO_ERROR) {
1263 reply->write(&desc, sizeof(effect_descriptor_t));
1264 }
1265 return NO_ERROR;
1266 }
1267 case GET_EFFECT_DESCRIPTOR: {
1268 CHECK_INTERFACE(IAudioFlinger, data, reply);
1269 effect_uuid_t uuid;
1270 data.read(&uuid, sizeof(effect_uuid_t));
Wei Jia983dca32015-09-10 09:47:29 -07001271 effect_descriptor_t desc = {};
Eric Laurentbe916aa2010-06-01 23:49:17 -07001272 status_t status = getEffectDescriptor(&uuid, &desc);
1273 reply->writeInt32(status);
1274 if (status == NO_ERROR) {
1275 reply->write(&desc, sizeof(effect_descriptor_t));
1276 }
1277 return NO_ERROR;
1278 }
1279 case CREATE_EFFECT: {
1280 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001281 effect_descriptor_t desc = {};
1282 if (data.read(&desc, sizeof(effect_descriptor_t)) != NO_ERROR) {
1283 ALOGE("b/23905951");
1284 }
Eric Laurentbe916aa2010-06-01 23:49:17 -07001285 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1286 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001287 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001288 audio_session_t sessionId = (audio_session_t) data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -07001289 const String16 opPackageName = data.readString16();
Wei Jia983dca32015-09-10 09:47:29 -07001290 status_t status = NO_ERROR;
1291 int id = 0;
1292 int enabled = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001293
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001294 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -07001295 opPackageName, &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001296 reply->writeInt32(status);
1297 reply->writeInt32(id);
1298 reply->writeInt32(enabled);
Marco Nelissen06b46062014-11-14 07:58:25 -08001299 reply->writeStrongBinder(IInterface::asBinder(effect));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001300 reply->write(&desc, sizeof(effect_descriptor_t));
1301 return NO_ERROR;
1302 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001303 case MOVE_EFFECTS: {
1304 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001305 audio_session_t session = (audio_session_t) data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001306 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1307 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001308 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1309 return NO_ERROR;
1310 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001311 case LOAD_HW_MODULE: {
1312 CHECK_INTERFACE(IAudioFlinger, data, reply);
1313 reply->writeInt32(loadHwModule(data.readCString()));
1314 return NO_ERROR;
1315 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001316 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1317 CHECK_INTERFACE(IAudioFlinger, data, reply);
1318 reply->writeInt32(getPrimaryOutputSamplingRate());
1319 return NO_ERROR;
1320 } break;
1321 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1322 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001323 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001324 return NO_ERROR;
1325 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001326 case SET_LOW_RAM_DEVICE: {
1327 CHECK_INTERFACE(IAudioFlinger, data, reply);
1328 bool isLowRamDevice = data.readInt32() != 0;
1329 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1330 return NO_ERROR;
1331 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001332 case LIST_AUDIO_PORTS: {
1333 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001334 unsigned int numPortsReq = data.readInt32();
1335 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1336 numPortsReq = MAX_ITEMS_PER_LIST;
1337 }
1338 unsigned int numPorts = numPortsReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001339 struct audio_port *ports =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001340 (struct audio_port *)calloc(numPortsReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001341 sizeof(struct audio_port));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001342 if (ports == NULL) {
1343 reply->writeInt32(NO_MEMORY);
1344 reply->writeInt32(0);
1345 return NO_ERROR;
1346 }
1347 status_t status = listAudioPorts(&numPorts, ports);
Eric Laurent4b123402014-04-11 09:22:20 -07001348 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001349 reply->writeInt32(numPorts);
Eric Laurent4b123402014-04-11 09:22:20 -07001350 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001351 if (numPortsReq > numPorts) {
1352 numPortsReq = numPorts;
1353 }
1354 reply->write(ports, numPortsReq * sizeof(struct audio_port));
Eric Laurent4b123402014-04-11 09:22:20 -07001355 }
1356 free(ports);
1357 return NO_ERROR;
1358 } break;
1359 case GET_AUDIO_PORT: {
1360 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001361 struct audio_port port = {};
1362 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1363 ALOGE("b/23905951");
1364 }
Eric Laurent4b123402014-04-11 09:22:20 -07001365 status_t status = getAudioPort(&port);
1366 reply->writeInt32(status);
1367 if (status == NO_ERROR) {
1368 reply->write(&port, sizeof(struct audio_port));
1369 }
1370 return NO_ERROR;
1371 } break;
1372 case CREATE_AUDIO_PATCH: {
1373 CHECK_INTERFACE(IAudioFlinger, data, reply);
1374 struct audio_patch patch;
1375 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001376 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001377 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1378 ALOGE("b/23905951");
1379 }
Eric Laurent4b123402014-04-11 09:22:20 -07001380 status_t status = createAudioPatch(&patch, &handle);
1381 reply->writeInt32(status);
1382 if (status == NO_ERROR) {
1383 reply->write(&handle, sizeof(audio_patch_handle_t));
1384 }
1385 return NO_ERROR;
1386 } break;
1387 case RELEASE_AUDIO_PATCH: {
1388 CHECK_INTERFACE(IAudioFlinger, data, reply);
1389 audio_patch_handle_t handle;
1390 data.read(&handle, sizeof(audio_patch_handle_t));
1391 status_t status = releaseAudioPatch(handle);
1392 reply->writeInt32(status);
1393 return NO_ERROR;
1394 } break;
1395 case LIST_AUDIO_PATCHES: {
1396 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001397 unsigned int numPatchesReq = data.readInt32();
1398 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1399 numPatchesReq = MAX_ITEMS_PER_LIST;
1400 }
1401 unsigned int numPatches = numPatchesReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001402 struct audio_patch *patches =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001403 (struct audio_patch *)calloc(numPatchesReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001404 sizeof(struct audio_patch));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001405 if (patches == NULL) {
1406 reply->writeInt32(NO_MEMORY);
1407 reply->writeInt32(0);
1408 return NO_ERROR;
1409 }
1410 status_t status = listAudioPatches(&numPatches, patches);
Eric Laurent4b123402014-04-11 09:22:20 -07001411 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001412 reply->writeInt32(numPatches);
Eric Laurent4b123402014-04-11 09:22:20 -07001413 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001414 if (numPatchesReq > numPatches) {
1415 numPatchesReq = numPatches;
1416 }
1417 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
Eric Laurent4b123402014-04-11 09:22:20 -07001418 }
1419 free(patches);
1420 return NO_ERROR;
1421 } break;
1422 case SET_AUDIO_PORT_CONFIG: {
1423 CHECK_INTERFACE(IAudioFlinger, data, reply);
1424 struct audio_port_config config;
1425 data.read(&config, sizeof(struct audio_port_config));
1426 status_t status = setAudioPortConfig(&config);
1427 reply->writeInt32(status);
1428 return NO_ERROR;
1429 } break;
Eric Laurent93c3d412014-08-01 14:48:35 -07001430 case GET_AUDIO_HW_SYNC: {
1431 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001432 reply->writeInt32(getAudioHwSyncForSession((audio_session_t) data.readInt32()));
Eric Laurent93c3d412014-08-01 14:48:35 -07001433 return NO_ERROR;
1434 } break;
Eric Laurent72e3f392015-05-20 14:43:50 -07001435 case SYSTEM_READY: {
1436 CHECK_INTERFACE(IAudioFlinger, data, reply);
1437 systemReady();
1438 return NO_ERROR;
1439 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001440 case FRAME_COUNT_HAL: {
1441 CHECK_INTERFACE(IAudioFlinger, data, reply);
1442 reply->writeInt64( frameCountHAL((audio_io_handle_t) data.readInt32()) );
1443 return NO_ERROR;
1444 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001445 default:
1446 return BBinder::onTransact(code, data, reply, flags);
1447 }
1448}
1449
1450// ----------------------------------------------------------------------------
1451
Glenn Kasten40bc9062015-03-20 09:09:33 -07001452} // namespace android