blob: 5cf2bdbb16172af1bc0500a621e78e1331aeb4e5 [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
Steven Moreland25a9e552017-04-17 14:30:39 -070027#include "IAudioFlinger.h"
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080028
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,
Glenn Kasten9eae0362016-04-19 09:09:14 -070065 NEW_AUDIO_UNIQUE_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,
Glenn Kasten9eae0362016-04-19 09:09:14 -070083 GET_AUDIO_HW_SYNC_FOR_SESSION,
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
Eric Laurent21da6472017-11-09 16:29:26 -080098 virtual sp<IAudioTrack> createTrack(const CreateTrackInput& input,
99 CreateTrackOutput& output,
100 status_t *status)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800101 {
102 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700103 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800104 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurent21da6472017-11-09 16:29:26 -0800105
106 if (status == nullptr) {
107 return track;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700108 }
Eric Laurent21da6472017-11-09 16:29:26 -0800109
110 input.writeToParcel(&data);
111
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800112 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
113 if (lStatus != NO_ERROR) {
Eric Laurent21da6472017-11-09 16:29:26 -0800114 ALOGE("createTrack transaction error %d", lStatus);
115 *status = DEAD_OBJECT;
116 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800117 }
Eric Laurent21da6472017-11-09 16:29:26 -0800118 *status = reply.readInt32();
119 if (*status != NO_ERROR) {
120 ALOGE("createTrack returned error %d", *status);
121 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800122 }
Eric Laurent21da6472017-11-09 16:29:26 -0800123 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
124 if (track == 0) {
125 ALOGE("createTrack returned an NULL IAudioTrack with status OK");
126 *status = DEAD_OBJECT;
127 return track;
128 }
129 output.readFromParcel(&reply);
Eric Laurent5841db72009-09-09 05:16:08 -0700130 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800131 }
132
Ivan Lozanoff6900d2017-08-01 15:47:38 -0700133 virtual sp<media::IAudioRecord> openRecord(
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800134 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800135 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800136 audio_format_t format,
Glenn Kasten28b76b32012-07-03 17:24:41 -0700137 audio_channel_mask_t channelMask,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700138 const String16& opPackageName,
Glenn Kasten74935e42013-12-19 08:56:45 -0800139 size_t *pFrameCount,
Eric Laurent05067782016-06-01 18:27:28 -0700140 audio_input_flags_t *flags,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700141 pid_t pid,
Glenn Kasten1879fff2012-07-11 15:36:59 -0700142 pid_t tid,
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700143 int clientUid,
Glenn Kastend848eb42016-03-08 13:42:11 -0800144 audio_session_t *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700145 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700146 sp<IMemory>& cblk,
147 sp<IMemory>& buffers,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800148 status_t *status,
149 audio_port_handle_t portId)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800150 {
151 Parcel data, reply;
Ivan Lozanoff6900d2017-08-01 15:47:38 -0700152 sp<media::IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800153 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800154 data.writeInt32((int32_t) input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800155 data.writeInt32(sampleRate);
156 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700157 data.writeInt32(channelMask);
Dianne Hackborneaa34702015-04-29 12:57:58 -0700158 data.writeString16(opPackageName);
Glenn Kasten74935e42013-12-19 08:56:45 -0800159 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800160 data.writeInt64(frameCount);
Eric Laurent05067782016-06-01 18:27:28 -0700161 audio_input_flags_t lFlags = flags != NULL ? *flags : AUDIO_INPUT_FLAG_NONE;
Glenn Kasteneeca3262013-07-31 16:12:48 -0700162 data.writeInt32(lFlags);
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700163 data.writeInt32((int32_t) pid);
Glenn Kasten1879fff2012-07-11 15:36:59 -0700164 data.writeInt32((int32_t) tid);
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700165 data.writeInt32((int32_t) clientUid);
Glenn Kastend848eb42016-03-08 13:42:11 -0800166 audio_session_t lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700167 if (sessionId != NULL) {
168 lSessionId = *sessionId;
169 }
170 data.writeInt32(lSessionId);
Glenn Kasten74105912014-07-03 12:28:53 -0700171 data.writeInt64(notificationFrames != NULL ? *notificationFrames : 0);
Eric Laurent20b9ef02016-12-05 11:03:16 -0800172 data.writeInt32(portId);
Glenn Kastend776ac62014-05-07 09:16:09 -0700173 cblk.clear();
174 buffers.clear();
Eric Laurent5841db72009-09-09 05:16:08 -0700175 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
176 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000177 ALOGE("openRecord error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700178 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700179 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800180 if (pFrameCount != NULL) {
181 *pFrameCount = frameCount;
182 }
Eric Laurent05067782016-06-01 18:27:28 -0700183 lFlags = (audio_input_flags_t)reply.readInt32();
Glenn Kasteneeca3262013-07-31 16:12:48 -0700184 if (flags != NULL) {
185 *flags = lFlags;
186 }
Glenn Kastend848eb42016-03-08 13:42:11 -0800187 lSessionId = (audio_session_t) reply.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700188 if (sessionId != NULL) {
189 *sessionId = lSessionId;
190 }
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700191 size_t lNotificationFrames = (size_t) reply.readInt64();
192 if (notificationFrames != NULL) {
193 *notificationFrames = lNotificationFrames;
194 }
Eric Laurent5841db72009-09-09 05:16:08 -0700195 lStatus = reply.readInt32();
Ivan Lozanoff6900d2017-08-01 15:47:38 -0700196 record = interface_cast<media::IAudioRecord>(reply.readStrongBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700197 cblk = interface_cast<IMemory>(reply.readStrongBinder());
198 if (cblk != 0 && cblk->pointer() == NULL) {
199 cblk.clear();
200 }
201 buffers = interface_cast<IMemory>(reply.readStrongBinder());
202 if (buffers != 0 && buffers->pointer() == NULL) {
203 buffers.clear();
204 }
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700205 if (lStatus == NO_ERROR) {
206 if (record == 0) {
207 ALOGE("openRecord should have returned an IAudioRecord");
208 lStatus = UNKNOWN_ERROR;
Glenn Kastend776ac62014-05-07 09:16:09 -0700209 } else if (cblk == 0) {
210 ALOGE("openRecord should have returned a cblk");
211 lStatus = NO_MEMORY;
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700212 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700213 // buffers is permitted to be 0
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700214 } else {
Glenn Kastend776ac62014-05-07 09:16:09 -0700215 if (record != 0 || cblk != 0 || buffers != 0) {
216 ALOGE("openRecord returned an IAudioRecord, cblk, "
217 "or buffers but with status %d", lStatus);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700218 }
219 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700220 if (lStatus != NO_ERROR) {
221 record.clear();
222 cblk.clear();
223 buffers.clear();
224 }
Eric Laurent5841db72009-09-09 05:16:08 -0700225 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700226 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800227 *status = lStatus;
228 }
Eric Laurent5841db72009-09-09 05:16:08 -0700229 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800230 }
231
Glenn Kasten2c073da2016-02-26 09:14:08 -0800232 virtual uint32_t sampleRate(audio_io_handle_t ioHandle) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800233 {
234 Parcel data, reply;
235 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten2c073da2016-02-26 09:14:08 -0800236 data.writeInt32((int32_t) ioHandle);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800237 remote()->transact(SAMPLE_RATE, data, &reply);
238 return reply.readInt32();
239 }
240
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700241 // RESERVED for channelCount()
242
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800243 virtual audio_format_t format(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800244 {
245 Parcel data, reply;
246 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800247 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800248 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800249 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800250 }
251
Glenn Kasten2c073da2016-02-26 09:14:08 -0800252 virtual size_t frameCount(audio_io_handle_t ioHandle) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800253 {
254 Parcel data, reply;
255 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten2c073da2016-02-26 09:14:08 -0800256 data.writeInt32((int32_t) ioHandle);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800257 remote()->transact(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800258 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800259 }
260
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800261 virtual uint32_t latency(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800262 {
263 Parcel data, reply;
264 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800265 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800266 remote()->transact(LATENCY, data, &reply);
267 return reply.readInt32();
268 }
269
270 virtual status_t setMasterVolume(float value)
271 {
272 Parcel data, reply;
273 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
274 data.writeFloat(value);
275 remote()->transact(SET_MASTER_VOLUME, data, &reply);
276 return reply.readInt32();
277 }
278
279 virtual status_t setMasterMute(bool muted)
280 {
281 Parcel data, reply;
282 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
283 data.writeInt32(muted);
284 remote()->transact(SET_MASTER_MUTE, data, &reply);
285 return reply.readInt32();
286 }
287
288 virtual float masterVolume() const
289 {
290 Parcel data, reply;
291 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
292 remote()->transact(MASTER_VOLUME, data, &reply);
293 return reply.readFloat();
294 }
295
296 virtual bool masterMute() const
297 {
298 Parcel data, reply;
299 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
300 remote()->transact(MASTER_MUTE, data, &reply);
301 return reply.readInt32();
302 }
303
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800304 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
305 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800306 {
307 Parcel data, reply;
308 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800309 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800310 data.writeFloat(value);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800311 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800312 remote()->transact(SET_STREAM_VOLUME, data, &reply);
313 return reply.readInt32();
314 }
315
Glenn Kastenfff6d712012-01-12 16:38:12 -0800316 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800317 {
318 Parcel data, reply;
319 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800320 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800321 data.writeInt32(muted);
322 remote()->transact(SET_STREAM_MUTE, data, &reply);
323 return reply.readInt32();
324 }
325
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800326 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800327 {
328 Parcel data, reply;
329 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800330 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800331 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800332 remote()->transact(STREAM_VOLUME, data, &reply);
333 return reply.readFloat();
334 }
335
Glenn Kastenfff6d712012-01-12 16:38:12 -0800336 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800337 {
338 Parcel data, reply;
339 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800340 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800341 remote()->transact(STREAM_MUTE, data, &reply);
342 return reply.readInt32();
343 }
344
Glenn Kastenf78aee72012-01-04 11:00:47 -0800345 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800346 {
347 Parcel data, reply;
348 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
349 data.writeInt32(mode);
350 remote()->transact(SET_MODE, data, &reply);
351 return reply.readInt32();
352 }
353
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800354 virtual status_t setMicMute(bool state)
355 {
356 Parcel data, reply;
357 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
358 data.writeInt32(state);
359 remote()->transact(SET_MIC_MUTE, data, &reply);
360 return reply.readInt32();
361 }
362
363 virtual bool getMicMute() const
364 {
365 Parcel data, reply;
366 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
367 remote()->transact(GET_MIC_MUTE, data, &reply);
368 return reply.readInt32();
369 }
370
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800371 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800372 {
373 Parcel data, reply;
374 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800375 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700376 data.writeString8(keyValuePairs);
377 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800378 return reply.readInt32();
379 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700380
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800381 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700382 {
383 Parcel data, reply;
384 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800385 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700386 data.writeString8(keys);
387 remote()->transact(GET_PARAMETERS, data, &reply);
388 return reply.readString8();
389 }
390
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800391 virtual void registerClient(const sp<IAudioFlingerClient>& client)
392 {
393 Parcel data, reply;
394 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800395 data.writeStrongBinder(IInterface::asBinder(client));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800396 remote()->transact(REGISTER_CLIENT, data, &reply);
397 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700398
Glenn Kastendd8104c2012-07-02 12:42:44 -0700399 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
400 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800401 {
402 Parcel data, reply;
403 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
404 data.writeInt32(sampleRate);
405 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700406 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800407 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800408 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800409 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700410
Eric Laurentcf2c0212014-07-25 16:20:43 -0700411 virtual status_t openOutput(audio_module_handle_t module,
412 audio_io_handle_t *output,
413 audio_config_t *config,
414 audio_devices_t *devices,
415 const String8& address,
416 uint32_t *latencyMs,
417 audio_output_flags_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800418 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700419 if (output == NULL || config == NULL || devices == NULL || latencyMs == NULL) {
420 return BAD_VALUE;
421 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800422 Parcel data, reply;
423 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700424 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700425 data.write(config, sizeof(audio_config_t));
426 data.writeInt32(*devices);
427 data.writeString8(address);
Glenn Kasten18868c52012-03-07 09:15:37 -0800428 data.writeInt32((int32_t) flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700429 status_t status = remote()->transact(OPEN_OUTPUT, data, &reply);
430 if (status != NO_ERROR) {
431 *output = AUDIO_IO_HANDLE_NONE;
432 return status;
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100433 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700434 status = (status_t)reply.readInt32();
435 if (status != NO_ERROR) {
436 *output = AUDIO_IO_HANDLE_NONE;
437 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700438 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700439 *output = (audio_io_handle_t)reply.readInt32();
440 ALOGV("openOutput() returned output, %d", *output);
441 reply.read(config, sizeof(audio_config_t));
442 *devices = (audio_devices_t)reply.readInt32();
443 *latencyMs = reply.readInt32();
444 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800445 }
446
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800447 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
448 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800449 {
450 Parcel data, reply;
451 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800452 data.writeInt32((int32_t) output1);
453 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700454 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800455 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700456 }
457
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800458 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700459 {
460 Parcel data, reply;
461 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800462 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700463 remote()->transact(CLOSE_OUTPUT, data, &reply);
464 return reply.readInt32();
465 }
466
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800467 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700468 {
469 Parcel data, reply;
470 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800471 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700472 remote()->transact(SUSPEND_OUTPUT, data, &reply);
473 return reply.readInt32();
474 }
475
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800476 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700477 {
478 Parcel data, reply;
479 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800480 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700481 remote()->transact(RESTORE_OUTPUT, data, &reply);
482 return reply.readInt32();
483 }
484
Eric Laurentcf2c0212014-07-25 16:20:43 -0700485 virtual status_t openInput(audio_module_handle_t module,
486 audio_io_handle_t *input,
487 audio_config_t *config,
488 audio_devices_t *device,
489 const String8& address,
490 audio_source_t source,
491 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700492 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700493 if (input == NULL || config == NULL || device == NULL) {
494 return BAD_VALUE;
495 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700496 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700497 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700498 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700499 data.writeInt32(*input);
500 data.write(config, sizeof(audio_config_t));
501 data.writeInt32(*device);
502 data.writeString8(address);
503 data.writeInt32(source);
Glenn Kastenec40d282014-07-15 15:31:26 -0700504 data.writeInt32(flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700505 status_t status = remote()->transact(OPEN_INPUT, data, &reply);
506 if (status != NO_ERROR) {
507 *input = AUDIO_IO_HANDLE_NONE;
508 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700509 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700510 status = (status_t)reply.readInt32();
511 if (status != NO_ERROR) {
512 *input = AUDIO_IO_HANDLE_NONE;
513 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700514 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700515 *input = (audio_io_handle_t)reply.readInt32();
516 reply.read(config, sizeof(audio_config_t));
517 *device = (audio_devices_t)reply.readInt32();
518 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700519 }
520
Eric Laurentfa2877b2009-07-28 08:44:33 -0700521 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700522 {
523 Parcel data, reply;
524 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700525 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700526 remote()->transact(CLOSE_INPUT, data, &reply);
527 return reply.readInt32();
528 }
529
Glenn Kastend2304db2014-02-03 07:40:31 -0800530 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700531 {
532 Parcel data, reply;
533 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800534 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800535 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700536 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800537 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700538
539 virtual status_t setVoiceVolume(float volume)
540 {
541 Parcel data, reply;
542 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
543 data.writeFloat(volume);
544 remote()->transact(SET_VOICE_VOLUME, data, &reply);
545 return reply.readInt32();
546 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800547
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000548 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800549 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800550 {
551 Parcel data, reply;
552 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800553 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800554 remote()->transact(GET_RENDER_POSITION, data, &reply);
555 status_t status = reply.readInt32();
556 if (status == NO_ERROR) {
557 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700558 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800559 *halFrames = tmp;
560 }
561 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700562 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800563 *dspFrames = tmp;
564 }
565 }
566 return status;
567 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800568
Glenn Kasten5f972c02014-01-13 09:59:31 -0800569 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800570 {
571 Parcel data, reply;
572 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800573 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800574 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
575 if (status != NO_ERROR) {
576 return 0;
577 }
578 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800579 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700580
Glenn Kasteneeecb982016-02-26 10:44:04 -0800581 virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use)
Eric Laurentbe916aa2010-06-01 23:49:17 -0700582 {
583 Parcel data, reply;
584 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasteneeecb982016-02-26 10:44:04 -0800585 data.writeInt32((int32_t) use);
Glenn Kasten9eae0362016-04-19 09:09:14 -0700586 status_t status = remote()->transact(NEW_AUDIO_UNIQUE_ID, data, &reply);
587 audio_unique_id_t id = AUDIO_UNIQUE_ID_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700588 if (status == NO_ERROR) {
589 id = reply.readInt32();
590 }
591 return id;
592 }
593
Glenn Kastend848eb42016-03-08 13:42:11 -0800594 virtual void acquireAudioSessionId(audio_session_t audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700595 {
596 Parcel data, reply;
597 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
598 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800599 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700600 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
601 }
602
Glenn Kastend848eb42016-03-08 13:42:11 -0800603 virtual void releaseAudioSessionId(audio_session_t audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700604 {
605 Parcel data, reply;
606 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
607 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800608 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700609 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
610 }
611
Glenn Kastenf587ba52012-01-26 16:25:10 -0800612 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700613 {
614 Parcel data, reply;
615 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
616 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
617 if (status != NO_ERROR) {
618 return status;
619 }
620 status = reply.readInt32();
621 if (status != NO_ERROR) {
622 return status;
623 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800624 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700625 *numEffects = (uint32_t)reply.readInt32();
626 }
627 return NO_ERROR;
628 }
629
Glenn Kastenf587ba52012-01-26 16:25:10 -0800630 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700631 {
632 if (pDescriptor == NULL) {
633 return BAD_VALUE;
634 }
635 Parcel data, reply;
636 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700637 data.writeInt32(index);
638 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700639 if (status != NO_ERROR) {
640 return status;
641 }
642 status = reply.readInt32();
643 if (status != NO_ERROR) {
644 return status;
645 }
646 reply.read(pDescriptor, sizeof(effect_descriptor_t));
647 return NO_ERROR;
648 }
649
Glenn Kasten5e92a782012-01-30 07:40:52 -0800650 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800651 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700652 {
653 if (pUuid == NULL || pDescriptor == NULL) {
654 return BAD_VALUE;
655 }
656 Parcel data, reply;
657 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
658 data.write(pUuid, sizeof(effect_uuid_t));
659 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
660 if (status != NO_ERROR) {
661 return status;
662 }
663 status = reply.readInt32();
664 if (status != NO_ERROR) {
665 return status;
666 }
667 reply.read(pDescriptor, sizeof(effect_descriptor_t));
668 return NO_ERROR;
669 }
670
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800671 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700672 effect_descriptor_t *pDesc,
673 const sp<IEffectClient>& client,
674 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800675 audio_io_handle_t output,
Glenn Kastend848eb42016-03-08 13:42:11 -0800676 audio_session_t sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700677 const String16& opPackageName,
Eric Laurentb6436272016-12-07 19:24:50 -0800678 pid_t pid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700679 status_t *status,
680 int *id,
681 int *enabled)
682 {
683 Parcel data, reply;
684 sp<IEffect> effect;
685
686 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700687 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700688 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700689 *status = BAD_VALUE;
690 }
691 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700692
693 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700694 data.write(pDesc, sizeof(effect_descriptor_t));
Marco Nelissen06b46062014-11-14 07:58:25 -0800695 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700696 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800697 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700698 data.writeInt32(sessionId);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700699 data.writeString16(opPackageName);
Eric Laurentb6436272016-12-07 19:24:50 -0800700 data.writeInt32((int32_t) pid);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700701
702 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
703 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000704 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700705 } else {
706 lStatus = reply.readInt32();
707 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700708 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700709 *id = tmp;
710 }
711 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800712 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700713 *enabled = tmp;
714 }
715 effect = interface_cast<IEffect>(reply.readStrongBinder());
716 reply.read(pDesc, sizeof(effect_descriptor_t));
717 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700718 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700719 *status = lStatus;
720 }
721
722 return effect;
723 }
Eric Laurentde070132010-07-13 04:45:46 -0700724
Glenn Kastend848eb42016-03-08 13:42:11 -0800725 virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800726 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700727 {
728 Parcel data, reply;
729 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
730 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800731 data.writeInt32((int32_t) srcOutput);
732 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700733 remote()->transact(MOVE_EFFECTS, data, &reply);
734 return reply.readInt32();
735 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700736
737 virtual audio_module_handle_t loadHwModule(const char *name)
738 {
739 Parcel data, reply;
740 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
741 data.writeCString(name);
742 remote()->transact(LOAD_HW_MODULE, data, &reply);
743 return (audio_module_handle_t) reply.readInt32();
744 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700745
Glenn Kasten3b16c762012-11-14 08:44:39 -0800746 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700747 {
748 Parcel data, reply;
749 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
750 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
751 return reply.readInt32();
752 }
753
Glenn Kastene33054e2012-11-14 12:54:39 -0800754 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700755 {
756 Parcel data, reply;
757 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
758 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800759 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700760 }
761
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700762 virtual status_t setLowRamDevice(bool isLowRamDevice)
763 {
764 Parcel data, reply;
765 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
766 data.writeInt32((int) isLowRamDevice);
767 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
768 return reply.readInt32();
769 }
Eric Laurent4b123402014-04-11 09:22:20 -0700770 virtual status_t listAudioPorts(unsigned int *num_ports,
771 struct audio_port *ports)
772 {
773 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
774 return BAD_VALUE;
775 }
776 Parcel data, reply;
777 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
778 data.writeInt32(*num_ports);
779 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
780 if (status != NO_ERROR ||
781 (status = (status_t)reply.readInt32()) != NO_ERROR) {
782 return status;
783 }
784 *num_ports = (unsigned int)reply.readInt32();
785 reply.read(ports, *num_ports * sizeof(struct audio_port));
786 return status;
787 }
788 virtual status_t getAudioPort(struct audio_port *port)
789 {
790 if (port == NULL) {
791 return BAD_VALUE;
792 }
793 Parcel data, reply;
794 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
795 data.write(port, sizeof(struct audio_port));
796 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
797 if (status != NO_ERROR ||
798 (status = (status_t)reply.readInt32()) != NO_ERROR) {
799 return status;
800 }
801 reply.read(port, sizeof(struct audio_port));
802 return status;
803 }
804 virtual status_t createAudioPatch(const struct audio_patch *patch,
805 audio_patch_handle_t *handle)
806 {
807 if (patch == NULL || handle == NULL) {
808 return BAD_VALUE;
809 }
810 Parcel data, reply;
811 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
812 data.write(patch, sizeof(struct audio_patch));
813 data.write(handle, sizeof(audio_patch_handle_t));
814 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
815 if (status != NO_ERROR ||
816 (status = (status_t)reply.readInt32()) != NO_ERROR) {
817 return status;
818 }
819 reply.read(handle, sizeof(audio_patch_handle_t));
820 return status;
821 }
822 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
823 {
824 Parcel data, reply;
825 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
826 data.write(&handle, sizeof(audio_patch_handle_t));
827 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
828 if (status != NO_ERROR) {
829 status = (status_t)reply.readInt32();
830 }
831 return status;
832 }
833 virtual status_t listAudioPatches(unsigned int *num_patches,
834 struct audio_patch *patches)
835 {
836 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
837 return BAD_VALUE;
838 }
839 Parcel data, reply;
840 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
841 data.writeInt32(*num_patches);
842 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
843 if (status != NO_ERROR ||
844 (status = (status_t)reply.readInt32()) != NO_ERROR) {
845 return status;
846 }
847 *num_patches = (unsigned int)reply.readInt32();
848 reply.read(patches, *num_patches * sizeof(struct audio_patch));
849 return status;
850 }
851 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
852 {
853 if (config == NULL) {
854 return BAD_VALUE;
855 }
856 Parcel data, reply;
857 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
858 data.write(config, sizeof(struct audio_port_config));
859 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
860 if (status != NO_ERROR) {
861 status = (status_t)reply.readInt32();
862 }
863 return status;
864 }
Eric Laurent93c3d412014-08-01 14:48:35 -0700865 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
866 {
867 Parcel data, reply;
868 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
869 data.writeInt32(sessionId);
Glenn Kasten9eae0362016-04-19 09:09:14 -0700870 status_t status = remote()->transact(GET_AUDIO_HW_SYNC_FOR_SESSION, data, &reply);
Eric Laurent93c3d412014-08-01 14:48:35 -0700871 if (status != NO_ERROR) {
872 return AUDIO_HW_SYNC_INVALID;
873 }
874 return (audio_hw_sync_t)reply.readInt32();
875 }
Eric Laurent72e3f392015-05-20 14:43:50 -0700876 virtual status_t systemReady()
877 {
878 Parcel data, reply;
879 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
880 return remote()->transact(SYSTEM_READY, data, &reply, IBinder::FLAG_ONEWAY);
881 }
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700882 virtual size_t frameCountHAL(audio_io_handle_t ioHandle) const
883 {
884 Parcel data, reply;
885 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
886 data.writeInt32((int32_t) ioHandle);
887 status_t status = remote()->transact(FRAME_COUNT_HAL, data, &reply);
888 if (status != NO_ERROR) {
889 return 0;
890 }
891 return reply.readInt64();
892 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800893};
894
895IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
896
897// ----------------------------------------------------------------------
898
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800899status_t BnAudioFlinger::onTransact(
900 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
901{
Nicolas Rouletdcdfaec2017-02-14 10:18:39 -0800902 // Whitelist of relevant events to trigger log merging.
903 // Log merging should activate during audio activity of any kind. This are considered the
904 // most relevant events.
905 // TODO should select more wisely the items from the list
906 switch (code) {
907 case CREATE_TRACK:
908 case OPEN_RECORD:
909 case SET_MASTER_VOLUME:
910 case SET_MASTER_MUTE:
911 case SET_STREAM_VOLUME:
912 case SET_STREAM_MUTE:
913 case SET_MIC_MUTE:
914 case SET_PARAMETERS:
915 case OPEN_INPUT:
916 case SET_VOICE_VOLUME:
917 case CREATE_EFFECT:
918 case SYSTEM_READY: {
919 requestLogMerge();
920 break;
921 }
922 default:
923 break;
924 }
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700925 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800926 case CREATE_TRACK: {
927 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurent21da6472017-11-09 16:29:26 -0800928
929 CreateTrackInput input;
930 if (input.readFromParcel((Parcel*)&data) != NO_ERROR) {
931 reply->writeInt32(DEAD_OBJECT);
932 return NO_ERROR;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700933 }
Eric Laurent21da6472017-11-09 16:29:26 -0800934
935 status_t status;
936 CreateTrackOutput output;
937
938 sp<IAudioTrack> track= createTrack(input,
939 output,
940 &status);
941
942 LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800943 reply->writeInt32(status);
Eric Laurent21da6472017-11-09 16:29:26 -0800944 if (status != NO_ERROR) {
945 return NO_ERROR;
946 }
Marco Nelissen06b46062014-11-14 07:58:25 -0800947 reply->writeStrongBinder(IInterface::asBinder(track));
Eric Laurent21da6472017-11-09 16:29:26 -0800948 output.writeToParcel(reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800949 return NO_ERROR;
950 } break;
951 case OPEN_RECORD: {
952 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800953 audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800954 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800955 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700956 audio_channel_mask_t channelMask = data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -0700957 const String16& opPackageName = data.readString16();
Glenn Kastene03dd222014-01-28 11:04:39 -0800958 size_t frameCount = data.readInt64();
Eric Laurent05067782016-06-01 18:27:28 -0700959 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700960 pid_t pid = (pid_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700961 pid_t tid = (pid_t) data.readInt32();
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700962 int clientUid = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -0800963 audio_session_t sessionId = (audio_session_t) data.readInt32();
Glenn Kasten74105912014-07-03 12:28:53 -0700964 size_t notificationFrames = data.readInt64();
Eric Laurent20b9ef02016-12-05 11:03:16 -0800965 audio_port_handle_t portId = (audio_port_handle_t) data.readInt32();
Glenn Kastend776ac62014-05-07 09:16:09 -0700966 sp<IMemory> cblk;
967 sp<IMemory> buffers;
Wei Jia983dca32015-09-10 09:47:29 -0700968 status_t status = NO_ERROR;
Ivan Lozanoff6900d2017-08-01 15:47:38 -0700969 sp<media::IAudioRecord> record = openRecord(input,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700970 sampleRate, format, channelMask, opPackageName, &frameCount, &flags,
971 pid, tid, clientUid, &sessionId, &notificationFrames, cblk, buffers,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800972 &status, portId);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700973 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700974 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700975 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700976 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700977 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800978 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800979 reply->writeStrongBinder(IInterface::asBinder(record));
980 reply->writeStrongBinder(IInterface::asBinder(cblk));
981 reply->writeStrongBinder(IInterface::asBinder(buffers));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800982 return NO_ERROR;
983 } break;
984 case SAMPLE_RATE: {
985 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800986 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800987 return NO_ERROR;
988 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700989
990 // RESERVED for channelCount()
991
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800992 case FORMAT: {
993 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800994 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800995 return NO_ERROR;
996 } break;
997 case FRAME_COUNT: {
998 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800999 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001000 return NO_ERROR;
1001 } break;
1002 case LATENCY: {
1003 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001004 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001005 return NO_ERROR;
1006 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001007 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001008 CHECK_INTERFACE(IAudioFlinger, data, reply);
1009 reply->writeInt32( setMasterVolume(data.readFloat()) );
1010 return NO_ERROR;
1011 } break;
1012 case SET_MASTER_MUTE: {
1013 CHECK_INTERFACE(IAudioFlinger, data, reply);
1014 reply->writeInt32( setMasterMute(data.readInt32()) );
1015 return NO_ERROR;
1016 } break;
1017 case MASTER_VOLUME: {
1018 CHECK_INTERFACE(IAudioFlinger, data, reply);
1019 reply->writeFloat( masterVolume() );
1020 return NO_ERROR;
1021 } break;
1022 case MASTER_MUTE: {
1023 CHECK_INTERFACE(IAudioFlinger, data, reply);
1024 reply->writeInt32( masterMute() );
1025 return NO_ERROR;
1026 } break;
1027 case SET_STREAM_VOLUME: {
1028 CHECK_INTERFACE(IAudioFlinger, data, reply);
1029 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001030 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001031 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001032 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001033 return NO_ERROR;
1034 } break;
1035 case SET_STREAM_MUTE: {
1036 CHECK_INTERFACE(IAudioFlinger, data, reply);
1037 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001038 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001039 return NO_ERROR;
1040 } break;
1041 case STREAM_VOLUME: {
1042 CHECK_INTERFACE(IAudioFlinger, data, reply);
1043 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001044 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001045 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001046 return NO_ERROR;
1047 } break;
1048 case STREAM_MUTE: {
1049 CHECK_INTERFACE(IAudioFlinger, data, reply);
1050 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001051 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001052 return NO_ERROR;
1053 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001054 case SET_MODE: {
1055 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001056 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001057 reply->writeInt32( setMode(mode) );
1058 return NO_ERROR;
1059 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001060 case SET_MIC_MUTE: {
1061 CHECK_INTERFACE(IAudioFlinger, data, reply);
1062 int state = data.readInt32();
1063 reply->writeInt32( setMicMute(state) );
1064 return NO_ERROR;
1065 } break;
1066 case GET_MIC_MUTE: {
1067 CHECK_INTERFACE(IAudioFlinger, data, reply);
1068 reply->writeInt32( getMicMute() );
1069 return NO_ERROR;
1070 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001071 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001072 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001073 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001074 String8 keyValuePairs(data.readString8());
1075 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001076 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001077 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001078 case GET_PARAMETERS: {
1079 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001080 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001081 String8 keys(data.readString8());
1082 reply->writeString8(getParameters(ioHandle, keys));
1083 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001084 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001085
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001086 case REGISTER_CLIENT: {
1087 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001088 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1089 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001090 registerClient(client);
1091 return NO_ERROR;
1092 } break;
1093 case GET_INPUTBUFFERSIZE: {
1094 CHECK_INTERFACE(IAudioFlinger, data, reply);
1095 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001096 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001097 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001098 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001099 return NO_ERROR;
1100 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001101 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001102 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001103 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001104 audio_config_t config = {};
1105 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1106 ALOGE("b/23905951");
1107 }
Eric Laurenta4c5a552012-03-29 10:12:40 -07001108 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001109 String8 address(data.readString8());
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001110 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001111 uint32_t latencyMs = 0;
Wei Jia4cac44b2015-09-16 15:01:16 -07001112 audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
Eric Laurentcf2c0212014-07-25 16:20:43 -07001113 status_t status = openOutput(module, &output, &config,
1114 &devices, address, &latencyMs, flags);
Glenn Kasten70742962014-02-18 08:00:47 -08001115 ALOGV("OPEN_OUTPUT output, %d", output);
Eric Laurentcf2c0212014-07-25 16:20:43 -07001116 reply->writeInt32((int32_t)status);
1117 if (status == NO_ERROR) {
1118 reply->writeInt32((int32_t)output);
1119 reply->write(&config, sizeof(audio_config_t));
1120 reply->writeInt32(devices);
1121 reply->writeInt32(latencyMs);
1122 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001123 return NO_ERROR;
1124 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001125 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001126 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001127 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1128 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1129 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001130 return NO_ERROR;
1131 } break;
1132 case CLOSE_OUTPUT: {
1133 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001134 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001135 return NO_ERROR;
1136 } break;
1137 case SUSPEND_OUTPUT: {
1138 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001139 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001140 return NO_ERROR;
1141 } break;
1142 case RESTORE_OUTPUT: {
1143 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001144 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001145 return NO_ERROR;
1146 } break;
1147 case OPEN_INPUT: {
1148 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001149 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001150 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001151 audio_config_t config = {};
1152 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1153 ALOGE("b/23905951");
1154 }
Eric Laurentcf2c0212014-07-25 16:20:43 -07001155 audio_devices_t device = (audio_devices_t)data.readInt32();
1156 String8 address(data.readString8());
1157 audio_source_t source = (audio_source_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001158 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001159
Eric Laurentcf2c0212014-07-25 16:20:43 -07001160 status_t status = openInput(module, &input, &config,
1161 &device, address, source, flags);
1162 reply->writeInt32((int32_t) status);
1163 if (status == NO_ERROR) {
1164 reply->writeInt32((int32_t) input);
1165 reply->write(&config, sizeof(audio_config_t));
1166 reply->writeInt32(device);
1167 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001168 return NO_ERROR;
1169 } break;
1170 case CLOSE_INPUT: {
1171 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001172 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001173 return NO_ERROR;
1174 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001175 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001176 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001177 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1178 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001179 return NO_ERROR;
1180 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001181 case SET_VOICE_VOLUME: {
1182 CHECK_INTERFACE(IAudioFlinger, data, reply);
1183 float volume = data.readFloat();
1184 reply->writeInt32( setVoiceVolume(volume) );
1185 return NO_ERROR;
1186 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001187 case GET_RENDER_POSITION: {
1188 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001189 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001190 uint32_t halFrames = 0;
1191 uint32_t dspFrames = 0;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001192 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1193 reply->writeInt32(status);
1194 if (status == NO_ERROR) {
1195 reply->writeInt32(halFrames);
1196 reply->writeInt32(dspFrames);
1197 }
1198 return NO_ERROR;
1199 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001200 case GET_INPUT_FRAMES_LOST: {
1201 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001202 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001203 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001204 return NO_ERROR;
1205 } break;
Glenn Kasten9eae0362016-04-19 09:09:14 -07001206 case NEW_AUDIO_UNIQUE_ID: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001207 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasteneeecb982016-02-26 10:44:04 -08001208 reply->writeInt32(newAudioUniqueId((audio_unique_id_use_t) data.readInt32()));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001209 return NO_ERROR;
1210 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001211 case ACQUIRE_AUDIO_SESSION_ID: {
1212 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001213 audio_session_t audioSession = (audio_session_t) data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001214 int pid = data.readInt32();
1215 acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001216 return NO_ERROR;
1217 } break;
1218 case RELEASE_AUDIO_SESSION_ID: {
1219 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001220 audio_session_t audioSession = (audio_session_t) data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001221 int pid = data.readInt32();
1222 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001223 return NO_ERROR;
1224 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001225 case QUERY_NUM_EFFECTS: {
1226 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001227 uint32_t numEffects = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001228 status_t status = queryNumberEffects(&numEffects);
1229 reply->writeInt32(status);
1230 if (status == NO_ERROR) {
1231 reply->writeInt32((int32_t)numEffects);
1232 }
1233 return NO_ERROR;
1234 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001235 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001236 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001237 effect_descriptor_t desc = {};
Eric Laurentffe9c252010-06-23 17:38:20 -07001238 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001239 reply->writeInt32(status);
1240 if (status == NO_ERROR) {
1241 reply->write(&desc, sizeof(effect_descriptor_t));
1242 }
1243 return NO_ERROR;
1244 }
1245 case GET_EFFECT_DESCRIPTOR: {
1246 CHECK_INTERFACE(IAudioFlinger, data, reply);
1247 effect_uuid_t uuid;
1248 data.read(&uuid, sizeof(effect_uuid_t));
Wei Jia983dca32015-09-10 09:47:29 -07001249 effect_descriptor_t desc = {};
Eric Laurentbe916aa2010-06-01 23:49:17 -07001250 status_t status = getEffectDescriptor(&uuid, &desc);
1251 reply->writeInt32(status);
1252 if (status == NO_ERROR) {
1253 reply->write(&desc, sizeof(effect_descriptor_t));
1254 }
1255 return NO_ERROR;
1256 }
1257 case CREATE_EFFECT: {
1258 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001259 effect_descriptor_t desc = {};
1260 if (data.read(&desc, sizeof(effect_descriptor_t)) != NO_ERROR) {
1261 ALOGE("b/23905951");
1262 }
Eric Laurentbe916aa2010-06-01 23:49:17 -07001263 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1264 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001265 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001266 audio_session_t sessionId = (audio_session_t) data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -07001267 const String16 opPackageName = data.readString16();
Eric Laurentb6436272016-12-07 19:24:50 -08001268 pid_t pid = (pid_t)data.readInt32();
1269
Wei Jia983dca32015-09-10 09:47:29 -07001270 status_t status = NO_ERROR;
1271 int id = 0;
1272 int enabled = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001273
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001274 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Eric Laurentb6436272016-12-07 19:24:50 -08001275 opPackageName, pid, &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001276 reply->writeInt32(status);
1277 reply->writeInt32(id);
1278 reply->writeInt32(enabled);
Marco Nelissen06b46062014-11-14 07:58:25 -08001279 reply->writeStrongBinder(IInterface::asBinder(effect));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001280 reply->write(&desc, sizeof(effect_descriptor_t));
1281 return NO_ERROR;
1282 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001283 case MOVE_EFFECTS: {
1284 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001285 audio_session_t session = (audio_session_t) data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001286 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1287 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001288 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1289 return NO_ERROR;
1290 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001291 case LOAD_HW_MODULE: {
1292 CHECK_INTERFACE(IAudioFlinger, data, reply);
1293 reply->writeInt32(loadHwModule(data.readCString()));
1294 return NO_ERROR;
1295 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001296 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1297 CHECK_INTERFACE(IAudioFlinger, data, reply);
1298 reply->writeInt32(getPrimaryOutputSamplingRate());
1299 return NO_ERROR;
1300 } break;
1301 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1302 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001303 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001304 return NO_ERROR;
1305 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001306 case SET_LOW_RAM_DEVICE: {
1307 CHECK_INTERFACE(IAudioFlinger, data, reply);
1308 bool isLowRamDevice = data.readInt32() != 0;
1309 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1310 return NO_ERROR;
1311 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001312 case LIST_AUDIO_PORTS: {
1313 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001314 unsigned int numPortsReq = data.readInt32();
1315 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1316 numPortsReq = MAX_ITEMS_PER_LIST;
1317 }
1318 unsigned int numPorts = numPortsReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001319 struct audio_port *ports =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001320 (struct audio_port *)calloc(numPortsReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001321 sizeof(struct audio_port));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001322 if (ports == NULL) {
1323 reply->writeInt32(NO_MEMORY);
1324 reply->writeInt32(0);
1325 return NO_ERROR;
1326 }
1327 status_t status = listAudioPorts(&numPorts, ports);
Eric Laurent4b123402014-04-11 09:22:20 -07001328 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001329 reply->writeInt32(numPorts);
Eric Laurent4b123402014-04-11 09:22:20 -07001330 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001331 if (numPortsReq > numPorts) {
1332 numPortsReq = numPorts;
1333 }
1334 reply->write(ports, numPortsReq * sizeof(struct audio_port));
Eric Laurent4b123402014-04-11 09:22:20 -07001335 }
1336 free(ports);
1337 return NO_ERROR;
1338 } break;
1339 case GET_AUDIO_PORT: {
1340 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001341 struct audio_port port = {};
1342 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1343 ALOGE("b/23905951");
1344 }
Eric Laurent4b123402014-04-11 09:22:20 -07001345 status_t status = getAudioPort(&port);
1346 reply->writeInt32(status);
1347 if (status == NO_ERROR) {
1348 reply->write(&port, sizeof(struct audio_port));
1349 }
1350 return NO_ERROR;
1351 } break;
1352 case CREATE_AUDIO_PATCH: {
1353 CHECK_INTERFACE(IAudioFlinger, data, reply);
1354 struct audio_patch patch;
1355 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001356 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001357 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1358 ALOGE("b/23905951");
1359 }
Eric Laurent4b123402014-04-11 09:22:20 -07001360 status_t status = createAudioPatch(&patch, &handle);
1361 reply->writeInt32(status);
1362 if (status == NO_ERROR) {
1363 reply->write(&handle, sizeof(audio_patch_handle_t));
1364 }
1365 return NO_ERROR;
1366 } break;
1367 case RELEASE_AUDIO_PATCH: {
1368 CHECK_INTERFACE(IAudioFlinger, data, reply);
1369 audio_patch_handle_t handle;
1370 data.read(&handle, sizeof(audio_patch_handle_t));
1371 status_t status = releaseAudioPatch(handle);
1372 reply->writeInt32(status);
1373 return NO_ERROR;
1374 } break;
1375 case LIST_AUDIO_PATCHES: {
1376 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001377 unsigned int numPatchesReq = data.readInt32();
1378 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1379 numPatchesReq = MAX_ITEMS_PER_LIST;
1380 }
1381 unsigned int numPatches = numPatchesReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001382 struct audio_patch *patches =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001383 (struct audio_patch *)calloc(numPatchesReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001384 sizeof(struct audio_patch));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001385 if (patches == NULL) {
1386 reply->writeInt32(NO_MEMORY);
1387 reply->writeInt32(0);
1388 return NO_ERROR;
1389 }
1390 status_t status = listAudioPatches(&numPatches, patches);
Eric Laurent4b123402014-04-11 09:22:20 -07001391 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001392 reply->writeInt32(numPatches);
Eric Laurent4b123402014-04-11 09:22:20 -07001393 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001394 if (numPatchesReq > numPatches) {
1395 numPatchesReq = numPatches;
1396 }
1397 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
Eric Laurent4b123402014-04-11 09:22:20 -07001398 }
1399 free(patches);
1400 return NO_ERROR;
1401 } break;
1402 case SET_AUDIO_PORT_CONFIG: {
1403 CHECK_INTERFACE(IAudioFlinger, data, reply);
1404 struct audio_port_config config;
1405 data.read(&config, sizeof(struct audio_port_config));
1406 status_t status = setAudioPortConfig(&config);
1407 reply->writeInt32(status);
1408 return NO_ERROR;
1409 } break;
Glenn Kasten9eae0362016-04-19 09:09:14 -07001410 case GET_AUDIO_HW_SYNC_FOR_SESSION: {
Eric Laurent93c3d412014-08-01 14:48:35 -07001411 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001412 reply->writeInt32(getAudioHwSyncForSession((audio_session_t) data.readInt32()));
Eric Laurent93c3d412014-08-01 14:48:35 -07001413 return NO_ERROR;
1414 } break;
Eric Laurent72e3f392015-05-20 14:43:50 -07001415 case SYSTEM_READY: {
1416 CHECK_INTERFACE(IAudioFlinger, data, reply);
1417 systemReady();
1418 return NO_ERROR;
1419 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001420 case FRAME_COUNT_HAL: {
1421 CHECK_INTERFACE(IAudioFlinger, data, reply);
1422 reply->writeInt64( frameCountHAL((audio_io_handle_t) data.readInt32()) );
1423 return NO_ERROR;
1424 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001425 default:
1426 return BBinder::onTransact(code, data, reply, flags);
1427 }
1428}
1429
1430// ----------------------------------------------------------------------------
1431
Glenn Kasten40bc9062015-03-20 09:09:33 -07001432} // namespace android