blob: 31a18a4596ff76465f847265720c353a604b85dd [file] [log] [blame]
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001/*
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08002**
3** Copyright 2007, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioFlinger"
Eric Laurentc2f1f072009-07-17 12:17:14 -070019//#define LOG_NDEBUG 0
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080020#include <utils/Log.h>
21
22#include <stdint.h>
23#include <sys/types.h>
24
Mathias Agopian75624082009-05-19 19:08:10 -070025#include <binder/Parcel.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080026
27#include <media/IAudioFlinger.h>
28
29namespace android {
30
31enum {
32 CREATE_TRACK = IBinder::FIRST_CALL_TRANSACTION,
33 OPEN_RECORD,
34 SAMPLE_RATE,
Glenn Kasten5876f2f2012-11-30 10:52:16 -080035 RESERVED, // obsolete, was CHANNEL_COUNT
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080036 FORMAT,
37 FRAME_COUNT,
38 LATENCY,
39 SET_MASTER_VOLUME,
40 SET_MASTER_MUTE,
41 MASTER_VOLUME,
42 MASTER_MUTE,
43 SET_STREAM_VOLUME,
44 SET_STREAM_MUTE,
45 STREAM_VOLUME,
46 STREAM_MUTE,
47 SET_MODE,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080048 SET_MIC_MUTE,
49 GET_MIC_MUTE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070050 SET_PARAMETERS,
51 GET_PARAMETERS,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080052 REGISTER_CLIENT,
53 GET_INPUTBUFFERSIZE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070054 OPEN_OUTPUT,
55 OPEN_DUPLICATE_OUTPUT,
56 CLOSE_OUTPUT,
57 SUSPEND_OUTPUT,
58 RESTORE_OUTPUT,
59 OPEN_INPUT,
60 CLOSE_INPUT,
Glenn Kastend2304db2014-02-03 07:40:31 -080061 INVALIDATE_STREAM,
Eric Laurent342e9cf2010-01-19 17:37:09 -080062 SET_VOICE_VOLUME,
Eric Laurent05bca2f2010-02-26 02:47:27 -080063 GET_RENDER_POSITION,
Eric Laurentbe916aa2010-06-01 23:49:17 -070064 GET_INPUT_FRAMES_LOST,
65 NEW_AUDIO_SESSION_ID,
Marco Nelissen3a34bef2011-08-02 13:33:41 -070066 ACQUIRE_AUDIO_SESSION_ID,
67 RELEASE_AUDIO_SESSION_ID,
Eric Laurentbe916aa2010-06-01 23:49:17 -070068 QUERY_NUM_EFFECTS,
Eric Laurentffe9c252010-06-23 17:38:20 -070069 QUERY_EFFECT,
Eric Laurentbe916aa2010-06-01 23:49:17 -070070 GET_EFFECT_DESCRIPTOR,
Eric Laurentde070132010-07-13 04:45:46 -070071 CREATE_EFFECT,
Eric Laurenta4c5a552012-03-29 10:12:40 -070072 MOVE_EFFECTS,
Glenn Kastencc0f1cf2012-09-24 11:27:18 -070073 LOAD_HW_MODULE,
74 GET_PRIMARY_OUTPUT_SAMPLING_RATE,
75 GET_PRIMARY_OUTPUT_FRAME_COUNT,
Glenn Kasten4182c4e2013-07-15 14:45:07 -070076 SET_LOW_RAM_DEVICE,
Eric Laurent4b123402014-04-11 09:22:20 -070077 LIST_AUDIO_PORTS,
78 GET_AUDIO_PORT,
79 CREATE_AUDIO_PATCH,
80 RELEASE_AUDIO_PATCH,
81 LIST_AUDIO_PATCHES,
Eric Laurent93c3d412014-08-01 14:48:35 -070082 SET_AUDIO_PORT_CONFIG,
Eric Laurent72e3f392015-05-20 14:43:50 -070083 GET_AUDIO_HW_SYNC,
Glenn Kasten4a8308b2016-04-18 14:10:01 -070084 SYSTEM_READY,
85 FRAME_COUNT_HAL,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080086};
87
Eric Laurentf75c2fe2015-04-02 13:49:15 -070088#define MAX_ITEMS_PER_LIST 1024
89
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080090class BpAudioFlinger : public BpInterface<IAudioFlinger>
91{
92public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070093 explicit BpAudioFlinger(const sp<IBinder>& impl)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080094 : BpInterface<IAudioFlinger>(impl)
95 {
96 }
97
98 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080099 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800100 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800101 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -0700102 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -0800103 size_t *pFrameCount,
Eric Laurent05067782016-06-01 18:27:28 -0700104 audio_output_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800105 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800106 audio_io_handle_t output,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700107 pid_t pid,
Glenn Kasten3acbd052012-02-28 10:39:56 -0800108 pid_t tid,
Glenn Kastend848eb42016-03-08 13:42:11 -0800109 audio_session_t *sessionId,
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800110 int clientUid,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800111 status_t *status)
112 {
113 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700114 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800115 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800116 data.writeInt32((int32_t) streamType);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800117 data.writeInt32(sampleRate);
118 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700119 data.writeInt32(channelMask);
Glenn Kasten74935e42013-12-19 08:56:45 -0800120 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800121 data.writeInt64(frameCount);
Eric Laurent05067782016-06-01 18:27:28 -0700122 audio_output_flags_t lFlags = flags != NULL ? *flags : AUDIO_OUTPUT_FLAG_NONE;
Glenn Kastene0b07172012-11-06 15:03:34 -0800123 data.writeInt32(lFlags);
Glenn Kasten2301acc2014-01-17 10:21:00 -0800124 // haveSharedBuffer
Eric Laurent3d00aa62013-09-24 09:53:27 -0700125 if (sharedBuffer != 0) {
126 data.writeInt32(true);
Marco Nelissen06b46062014-11-14 07:58:25 -0800127 data.writeStrongBinder(IInterface::asBinder(sharedBuffer));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700128 } else {
129 data.writeInt32(false);
130 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800131 data.writeInt32((int32_t) output);
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700132 data.writeInt32((int32_t) pid);
Glenn Kasten3acbd052012-02-28 10:39:56 -0800133 data.writeInt32((int32_t) tid);
Glenn Kastend848eb42016-03-08 13:42:11 -0800134 audio_session_t lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700135 if (sessionId != NULL) {
136 lSessionId = *sessionId;
137 }
138 data.writeInt32(lSessionId);
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800139 data.writeInt32(clientUid);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800140 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
141 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000142 ALOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700143 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700144 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800145 if (pFrameCount != NULL) {
146 *pFrameCount = frameCount;
147 }
Eric Laurent05067782016-06-01 18:27:28 -0700148 lFlags = (audio_output_flags_t)reply.readInt32();
Glenn Kastene0b07172012-11-06 15:03:34 -0800149 if (flags != NULL) {
150 *flags = lFlags;
151 }
Glenn Kastend848eb42016-03-08 13:42:11 -0800152 lSessionId = (audio_session_t) reply.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700153 if (sessionId != NULL) {
154 *sessionId = lSessionId;
155 }
Eric Laurent5841db72009-09-09 05:16:08 -0700156 lStatus = reply.readInt32();
157 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
Glenn Kasten0cde0762014-01-16 15:06:36 -0800158 if (lStatus == NO_ERROR) {
159 if (track == 0) {
160 ALOGE("createTrack should have returned an IAudioTrack");
161 lStatus = UNKNOWN_ERROR;
162 }
163 } else {
164 if (track != 0) {
165 ALOGE("createTrack returned an IAudioTrack but with status %d", lStatus);
166 track.clear();
167 }
168 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800169 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700170 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800171 *status = lStatus;
172 }
Eric Laurent5841db72009-09-09 05:16:08 -0700173 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800174 }
175
176 virtual sp<IAudioRecord> openRecord(
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800177 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800178 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800179 audio_format_t format,
Glenn Kasten28b76b32012-07-03 17:24:41 -0700180 audio_channel_mask_t channelMask,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700181 const String16& opPackageName,
Glenn Kasten74935e42013-12-19 08:56:45 -0800182 size_t *pFrameCount,
Eric Laurent05067782016-06-01 18:27:28 -0700183 audio_input_flags_t *flags,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700184 pid_t pid,
Glenn Kasten1879fff2012-07-11 15:36:59 -0700185 pid_t tid,
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700186 int clientUid,
Glenn Kastend848eb42016-03-08 13:42:11 -0800187 audio_session_t *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700188 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700189 sp<IMemory>& cblk,
190 sp<IMemory>& buffers,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800191 status_t *status)
192 {
193 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700194 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800195 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800196 data.writeInt32((int32_t) input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800197 data.writeInt32(sampleRate);
198 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700199 data.writeInt32(channelMask);
Dianne Hackborneaa34702015-04-29 12:57:58 -0700200 data.writeString16(opPackageName);
Glenn Kasten74935e42013-12-19 08:56:45 -0800201 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800202 data.writeInt64(frameCount);
Eric Laurent05067782016-06-01 18:27:28 -0700203 audio_input_flags_t lFlags = flags != NULL ? *flags : AUDIO_INPUT_FLAG_NONE;
Glenn Kasteneeca3262013-07-31 16:12:48 -0700204 data.writeInt32(lFlags);
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700205 data.writeInt32((int32_t) pid);
Glenn Kasten1879fff2012-07-11 15:36:59 -0700206 data.writeInt32((int32_t) tid);
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700207 data.writeInt32((int32_t) clientUid);
Glenn Kastend848eb42016-03-08 13:42:11 -0800208 audio_session_t lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700209 if (sessionId != NULL) {
210 lSessionId = *sessionId;
211 }
212 data.writeInt32(lSessionId);
Glenn Kasten74105912014-07-03 12:28:53 -0700213 data.writeInt64(notificationFrames != NULL ? *notificationFrames : 0);
Glenn Kastend776ac62014-05-07 09:16:09 -0700214 cblk.clear();
215 buffers.clear();
Eric Laurent5841db72009-09-09 05:16:08 -0700216 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
217 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000218 ALOGE("openRecord error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700219 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700220 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800221 if (pFrameCount != NULL) {
222 *pFrameCount = frameCount;
223 }
Eric Laurent05067782016-06-01 18:27:28 -0700224 lFlags = (audio_input_flags_t)reply.readInt32();
Glenn Kasteneeca3262013-07-31 16:12:48 -0700225 if (flags != NULL) {
226 *flags = lFlags;
227 }
Glenn Kastend848eb42016-03-08 13:42:11 -0800228 lSessionId = (audio_session_t) reply.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700229 if (sessionId != NULL) {
230 *sessionId = lSessionId;
231 }
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700232 size_t lNotificationFrames = (size_t) reply.readInt64();
233 if (notificationFrames != NULL) {
234 *notificationFrames = lNotificationFrames;
235 }
Eric Laurent5841db72009-09-09 05:16:08 -0700236 lStatus = reply.readInt32();
237 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700238 cblk = interface_cast<IMemory>(reply.readStrongBinder());
239 if (cblk != 0 && cblk->pointer() == NULL) {
240 cblk.clear();
241 }
242 buffers = interface_cast<IMemory>(reply.readStrongBinder());
243 if (buffers != 0 && buffers->pointer() == NULL) {
244 buffers.clear();
245 }
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700246 if (lStatus == NO_ERROR) {
247 if (record == 0) {
248 ALOGE("openRecord should have returned an IAudioRecord");
249 lStatus = UNKNOWN_ERROR;
Glenn Kastend776ac62014-05-07 09:16:09 -0700250 } else if (cblk == 0) {
251 ALOGE("openRecord should have returned a cblk");
252 lStatus = NO_MEMORY;
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700253 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700254 // buffers is permitted to be 0
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700255 } else {
Glenn Kastend776ac62014-05-07 09:16:09 -0700256 if (record != 0 || cblk != 0 || buffers != 0) {
257 ALOGE("openRecord returned an IAudioRecord, cblk, "
258 "or buffers but with status %d", lStatus);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700259 }
260 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700261 if (lStatus != NO_ERROR) {
262 record.clear();
263 cblk.clear();
264 buffers.clear();
265 }
Eric Laurent5841db72009-09-09 05:16:08 -0700266 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700267 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800268 *status = lStatus;
269 }
Eric Laurent5841db72009-09-09 05:16:08 -0700270 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800271 }
272
Glenn Kasten2c073da2016-02-26 09:14:08 -0800273 virtual uint32_t sampleRate(audio_io_handle_t ioHandle) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800274 {
275 Parcel data, reply;
276 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten2c073da2016-02-26 09:14:08 -0800277 data.writeInt32((int32_t) ioHandle);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800278 remote()->transact(SAMPLE_RATE, data, &reply);
279 return reply.readInt32();
280 }
281
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700282 // RESERVED for channelCount()
283
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800284 virtual audio_format_t format(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800285 {
286 Parcel data, reply;
287 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800288 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800289 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800290 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800291 }
292
Glenn Kasten2c073da2016-02-26 09:14:08 -0800293 virtual size_t frameCount(audio_io_handle_t ioHandle) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800294 {
295 Parcel data, reply;
296 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten2c073da2016-02-26 09:14:08 -0800297 data.writeInt32((int32_t) ioHandle);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800298 remote()->transact(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800299 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800300 }
301
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800302 virtual uint32_t latency(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800303 {
304 Parcel data, reply;
305 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800306 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800307 remote()->transact(LATENCY, data, &reply);
308 return reply.readInt32();
309 }
310
311 virtual status_t setMasterVolume(float value)
312 {
313 Parcel data, reply;
314 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
315 data.writeFloat(value);
316 remote()->transact(SET_MASTER_VOLUME, data, &reply);
317 return reply.readInt32();
318 }
319
320 virtual status_t setMasterMute(bool muted)
321 {
322 Parcel data, reply;
323 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
324 data.writeInt32(muted);
325 remote()->transact(SET_MASTER_MUTE, data, &reply);
326 return reply.readInt32();
327 }
328
329 virtual float masterVolume() const
330 {
331 Parcel data, reply;
332 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
333 remote()->transact(MASTER_VOLUME, data, &reply);
334 return reply.readFloat();
335 }
336
337 virtual bool masterMute() const
338 {
339 Parcel data, reply;
340 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
341 remote()->transact(MASTER_MUTE, data, &reply);
342 return reply.readInt32();
343 }
344
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800345 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
346 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800347 {
348 Parcel data, reply;
349 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800350 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800351 data.writeFloat(value);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800352 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800353 remote()->transact(SET_STREAM_VOLUME, data, &reply);
354 return reply.readInt32();
355 }
356
Glenn Kastenfff6d712012-01-12 16:38:12 -0800357 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800358 {
359 Parcel data, reply;
360 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800361 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800362 data.writeInt32(muted);
363 remote()->transact(SET_STREAM_MUTE, data, &reply);
364 return reply.readInt32();
365 }
366
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800367 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800368 {
369 Parcel data, reply;
370 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800371 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800372 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800373 remote()->transact(STREAM_VOLUME, data, &reply);
374 return reply.readFloat();
375 }
376
Glenn Kastenfff6d712012-01-12 16:38:12 -0800377 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800378 {
379 Parcel data, reply;
380 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800381 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800382 remote()->transact(STREAM_MUTE, data, &reply);
383 return reply.readInt32();
384 }
385
Glenn Kastenf78aee72012-01-04 11:00:47 -0800386 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800387 {
388 Parcel data, reply;
389 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
390 data.writeInt32(mode);
391 remote()->transact(SET_MODE, data, &reply);
392 return reply.readInt32();
393 }
394
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800395 virtual status_t setMicMute(bool state)
396 {
397 Parcel data, reply;
398 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
399 data.writeInt32(state);
400 remote()->transact(SET_MIC_MUTE, data, &reply);
401 return reply.readInt32();
402 }
403
404 virtual bool getMicMute() const
405 {
406 Parcel data, reply;
407 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
408 remote()->transact(GET_MIC_MUTE, data, &reply);
409 return reply.readInt32();
410 }
411
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800412 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800413 {
414 Parcel data, reply;
415 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800416 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700417 data.writeString8(keyValuePairs);
418 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800419 return reply.readInt32();
420 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700421
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800422 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700423 {
424 Parcel data, reply;
425 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800426 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700427 data.writeString8(keys);
428 remote()->transact(GET_PARAMETERS, data, &reply);
429 return reply.readString8();
430 }
431
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800432 virtual void registerClient(const sp<IAudioFlingerClient>& client)
433 {
434 Parcel data, reply;
435 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800436 data.writeStrongBinder(IInterface::asBinder(client));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800437 remote()->transact(REGISTER_CLIENT, data, &reply);
438 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700439
Glenn Kastendd8104c2012-07-02 12:42:44 -0700440 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
441 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800442 {
443 Parcel data, reply;
444 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
445 data.writeInt32(sampleRate);
446 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700447 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800448 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800449 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800450 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700451
Eric Laurentcf2c0212014-07-25 16:20:43 -0700452 virtual status_t openOutput(audio_module_handle_t module,
453 audio_io_handle_t *output,
454 audio_config_t *config,
455 audio_devices_t *devices,
456 const String8& address,
457 uint32_t *latencyMs,
458 audio_output_flags_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800459 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700460 if (output == NULL || config == NULL || devices == NULL || latencyMs == NULL) {
461 return BAD_VALUE;
462 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800463 Parcel data, reply;
464 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700465 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700466 data.write(config, sizeof(audio_config_t));
467 data.writeInt32(*devices);
468 data.writeString8(address);
Glenn Kasten18868c52012-03-07 09:15:37 -0800469 data.writeInt32((int32_t) flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700470 status_t status = remote()->transact(OPEN_OUTPUT, data, &reply);
471 if (status != NO_ERROR) {
472 *output = AUDIO_IO_HANDLE_NONE;
473 return status;
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100474 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700475 status = (status_t)reply.readInt32();
476 if (status != NO_ERROR) {
477 *output = AUDIO_IO_HANDLE_NONE;
478 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700479 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700480 *output = (audio_io_handle_t)reply.readInt32();
481 ALOGV("openOutput() returned output, %d", *output);
482 reply.read(config, sizeof(audio_config_t));
483 *devices = (audio_devices_t)reply.readInt32();
484 *latencyMs = reply.readInt32();
485 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800486 }
487
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800488 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
489 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800490 {
491 Parcel data, reply;
492 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800493 data.writeInt32((int32_t) output1);
494 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700495 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800496 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700497 }
498
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800499 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700500 {
501 Parcel data, reply;
502 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800503 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700504 remote()->transact(CLOSE_OUTPUT, data, &reply);
505 return reply.readInt32();
506 }
507
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800508 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700509 {
510 Parcel data, reply;
511 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800512 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700513 remote()->transact(SUSPEND_OUTPUT, data, &reply);
514 return reply.readInt32();
515 }
516
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800517 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700518 {
519 Parcel data, reply;
520 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800521 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700522 remote()->transact(RESTORE_OUTPUT, data, &reply);
523 return reply.readInt32();
524 }
525
Eric Laurentcf2c0212014-07-25 16:20:43 -0700526 virtual status_t openInput(audio_module_handle_t module,
527 audio_io_handle_t *input,
528 audio_config_t *config,
529 audio_devices_t *device,
530 const String8& address,
531 audio_source_t source,
532 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700533 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700534 if (input == NULL || config == NULL || device == NULL) {
535 return BAD_VALUE;
536 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700537 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700538 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700539 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700540 data.writeInt32(*input);
541 data.write(config, sizeof(audio_config_t));
542 data.writeInt32(*device);
543 data.writeString8(address);
544 data.writeInt32(source);
Glenn Kastenec40d282014-07-15 15:31:26 -0700545 data.writeInt32(flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700546 status_t status = remote()->transact(OPEN_INPUT, data, &reply);
547 if (status != NO_ERROR) {
548 *input = AUDIO_IO_HANDLE_NONE;
549 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700550 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700551 status = (status_t)reply.readInt32();
552 if (status != NO_ERROR) {
553 *input = AUDIO_IO_HANDLE_NONE;
554 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700555 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700556 *input = (audio_io_handle_t)reply.readInt32();
557 reply.read(config, sizeof(audio_config_t));
558 *device = (audio_devices_t)reply.readInt32();
559 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700560 }
561
Eric Laurentfa2877b2009-07-28 08:44:33 -0700562 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700563 {
564 Parcel data, reply;
565 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700566 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700567 remote()->transact(CLOSE_INPUT, data, &reply);
568 return reply.readInt32();
569 }
570
Glenn Kastend2304db2014-02-03 07:40:31 -0800571 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700572 {
573 Parcel data, reply;
574 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800575 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800576 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700577 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800578 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700579
580 virtual status_t setVoiceVolume(float volume)
581 {
582 Parcel data, reply;
583 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
584 data.writeFloat(volume);
585 remote()->transact(SET_VOICE_VOLUME, data, &reply);
586 return reply.readInt32();
587 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800588
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000589 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800590 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800591 {
592 Parcel data, reply;
593 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800594 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800595 remote()->transact(GET_RENDER_POSITION, data, &reply);
596 status_t status = reply.readInt32();
597 if (status == NO_ERROR) {
598 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700599 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800600 *halFrames = tmp;
601 }
602 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700603 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800604 *dspFrames = tmp;
605 }
606 }
607 return status;
608 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800609
Glenn Kasten5f972c02014-01-13 09:59:31 -0800610 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800611 {
612 Parcel data, reply;
613 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800614 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800615 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
616 if (status != NO_ERROR) {
617 return 0;
618 }
619 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800620 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700621
Glenn Kasteneeecb982016-02-26 10:44:04 -0800622 virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use)
Eric Laurentbe916aa2010-06-01 23:49:17 -0700623 {
624 Parcel data, reply;
625 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasteneeecb982016-02-26 10:44:04 -0800626 data.writeInt32((int32_t) use);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700627 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
Eric Laurentde3f8392014-07-27 18:38:22 -0700628 audio_unique_id_t id = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700629 if (status == NO_ERROR) {
630 id = reply.readInt32();
631 }
632 return id;
633 }
634
Glenn Kastend848eb42016-03-08 13:42:11 -0800635 virtual void acquireAudioSessionId(audio_session_t audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700636 {
637 Parcel data, reply;
638 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
639 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800640 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700641 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
642 }
643
Glenn Kastend848eb42016-03-08 13:42:11 -0800644 virtual void releaseAudioSessionId(audio_session_t audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700645 {
646 Parcel data, reply;
647 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
648 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800649 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700650 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
651 }
652
Glenn Kastenf587ba52012-01-26 16:25:10 -0800653 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700654 {
655 Parcel data, reply;
656 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
657 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
658 if (status != NO_ERROR) {
659 return status;
660 }
661 status = reply.readInt32();
662 if (status != NO_ERROR) {
663 return status;
664 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800665 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700666 *numEffects = (uint32_t)reply.readInt32();
667 }
668 return NO_ERROR;
669 }
670
Glenn Kastenf587ba52012-01-26 16:25:10 -0800671 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700672 {
673 if (pDescriptor == NULL) {
674 return BAD_VALUE;
675 }
676 Parcel data, reply;
677 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700678 data.writeInt32(index);
679 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700680 if (status != NO_ERROR) {
681 return status;
682 }
683 status = reply.readInt32();
684 if (status != NO_ERROR) {
685 return status;
686 }
687 reply.read(pDescriptor, sizeof(effect_descriptor_t));
688 return NO_ERROR;
689 }
690
Glenn Kasten5e92a782012-01-30 07:40:52 -0800691 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800692 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700693 {
694 if (pUuid == NULL || pDescriptor == NULL) {
695 return BAD_VALUE;
696 }
697 Parcel data, reply;
698 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
699 data.write(pUuid, sizeof(effect_uuid_t));
700 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
701 if (status != NO_ERROR) {
702 return status;
703 }
704 status = reply.readInt32();
705 if (status != NO_ERROR) {
706 return status;
707 }
708 reply.read(pDescriptor, sizeof(effect_descriptor_t));
709 return NO_ERROR;
710 }
711
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800712 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700713 effect_descriptor_t *pDesc,
714 const sp<IEffectClient>& client,
715 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800716 audio_io_handle_t output,
Glenn Kastend848eb42016-03-08 13:42:11 -0800717 audio_session_t sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700718 const String16& opPackageName,
Eric Laurentb6436272016-12-07 19:24:50 -0800719 pid_t pid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700720 status_t *status,
721 int *id,
722 int *enabled)
723 {
724 Parcel data, reply;
725 sp<IEffect> effect;
726
727 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700728 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700729 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700730 *status = BAD_VALUE;
731 }
732 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700733
734 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700735 data.write(pDesc, sizeof(effect_descriptor_t));
Marco Nelissen06b46062014-11-14 07:58:25 -0800736 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700737 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800738 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700739 data.writeInt32(sessionId);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700740 data.writeString16(opPackageName);
Eric Laurentb6436272016-12-07 19:24:50 -0800741 data.writeInt32((int32_t) pid);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700742
743 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
744 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000745 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700746 } else {
747 lStatus = reply.readInt32();
748 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700749 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700750 *id = tmp;
751 }
752 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800753 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700754 *enabled = tmp;
755 }
756 effect = interface_cast<IEffect>(reply.readStrongBinder());
757 reply.read(pDesc, sizeof(effect_descriptor_t));
758 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700759 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700760 *status = lStatus;
761 }
762
763 return effect;
764 }
Eric Laurentde070132010-07-13 04:45:46 -0700765
Glenn Kastend848eb42016-03-08 13:42:11 -0800766 virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800767 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700768 {
769 Parcel data, reply;
770 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
771 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800772 data.writeInt32((int32_t) srcOutput);
773 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700774 remote()->transact(MOVE_EFFECTS, data, &reply);
775 return reply.readInt32();
776 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700777
778 virtual audio_module_handle_t loadHwModule(const char *name)
779 {
780 Parcel data, reply;
781 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
782 data.writeCString(name);
783 remote()->transact(LOAD_HW_MODULE, data, &reply);
784 return (audio_module_handle_t) reply.readInt32();
785 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700786
Glenn Kasten3b16c762012-11-14 08:44:39 -0800787 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700788 {
789 Parcel data, reply;
790 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
791 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
792 return reply.readInt32();
793 }
794
Glenn Kastene33054e2012-11-14 12:54:39 -0800795 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700796 {
797 Parcel data, reply;
798 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
799 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800800 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700801 }
802
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700803 virtual status_t setLowRamDevice(bool isLowRamDevice)
804 {
805 Parcel data, reply;
806 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
807 data.writeInt32((int) isLowRamDevice);
808 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
809 return reply.readInt32();
810 }
Eric Laurent4b123402014-04-11 09:22:20 -0700811 virtual status_t listAudioPorts(unsigned int *num_ports,
812 struct audio_port *ports)
813 {
814 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
815 return BAD_VALUE;
816 }
817 Parcel data, reply;
818 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
819 data.writeInt32(*num_ports);
820 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
821 if (status != NO_ERROR ||
822 (status = (status_t)reply.readInt32()) != NO_ERROR) {
823 return status;
824 }
825 *num_ports = (unsigned int)reply.readInt32();
826 reply.read(ports, *num_ports * sizeof(struct audio_port));
827 return status;
828 }
829 virtual status_t getAudioPort(struct audio_port *port)
830 {
831 if (port == NULL) {
832 return BAD_VALUE;
833 }
834 Parcel data, reply;
835 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
836 data.write(port, sizeof(struct audio_port));
837 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
838 if (status != NO_ERROR ||
839 (status = (status_t)reply.readInt32()) != NO_ERROR) {
840 return status;
841 }
842 reply.read(port, sizeof(struct audio_port));
843 return status;
844 }
845 virtual status_t createAudioPatch(const struct audio_patch *patch,
846 audio_patch_handle_t *handle)
847 {
848 if (patch == NULL || handle == NULL) {
849 return BAD_VALUE;
850 }
851 Parcel data, reply;
852 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
853 data.write(patch, sizeof(struct audio_patch));
854 data.write(handle, sizeof(audio_patch_handle_t));
855 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
856 if (status != NO_ERROR ||
857 (status = (status_t)reply.readInt32()) != NO_ERROR) {
858 return status;
859 }
860 reply.read(handle, sizeof(audio_patch_handle_t));
861 return status;
862 }
863 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
864 {
865 Parcel data, reply;
866 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
867 data.write(&handle, sizeof(audio_patch_handle_t));
868 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
869 if (status != NO_ERROR) {
870 status = (status_t)reply.readInt32();
871 }
872 return status;
873 }
874 virtual status_t listAudioPatches(unsigned int *num_patches,
875 struct audio_patch *patches)
876 {
877 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
878 return BAD_VALUE;
879 }
880 Parcel data, reply;
881 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
882 data.writeInt32(*num_patches);
883 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
884 if (status != NO_ERROR ||
885 (status = (status_t)reply.readInt32()) != NO_ERROR) {
886 return status;
887 }
888 *num_patches = (unsigned int)reply.readInt32();
889 reply.read(patches, *num_patches * sizeof(struct audio_patch));
890 return status;
891 }
892 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
893 {
894 if (config == NULL) {
895 return BAD_VALUE;
896 }
897 Parcel data, reply;
898 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
899 data.write(config, sizeof(struct audio_port_config));
900 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
901 if (status != NO_ERROR) {
902 status = (status_t)reply.readInt32();
903 }
904 return status;
905 }
Eric Laurent93c3d412014-08-01 14:48:35 -0700906 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
907 {
908 Parcel data, reply;
909 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
910 data.writeInt32(sessionId);
911 status_t status = remote()->transact(GET_AUDIO_HW_SYNC, data, &reply);
912 if (status != NO_ERROR) {
913 return AUDIO_HW_SYNC_INVALID;
914 }
915 return (audio_hw_sync_t)reply.readInt32();
916 }
Eric Laurent72e3f392015-05-20 14:43:50 -0700917 virtual status_t systemReady()
918 {
919 Parcel data, reply;
920 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
921 return remote()->transact(SYSTEM_READY, data, &reply, IBinder::FLAG_ONEWAY);
922 }
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700923 virtual size_t frameCountHAL(audio_io_handle_t ioHandle) const
924 {
925 Parcel data, reply;
926 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
927 data.writeInt32((int32_t) ioHandle);
928 status_t status = remote()->transact(FRAME_COUNT_HAL, data, &reply);
929 if (status != NO_ERROR) {
930 return 0;
931 }
932 return reply.readInt64();
933 }
934
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800935};
936
937IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
938
939// ----------------------------------------------------------------------
940
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800941status_t BnAudioFlinger::onTransact(
942 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
943{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700944 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800945 case CREATE_TRACK: {
946 CHECK_INTERFACE(IAudioFlinger, data, reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800947 int streamType = data.readInt32();
948 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800949 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700950 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800951 size_t frameCount = data.readInt64();
Eric Laurent05067782016-06-01 18:27:28 -0700952 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700953 bool haveSharedBuffer = data.readInt32() != 0;
954 sp<IMemory> buffer;
955 if (haveSharedBuffer) {
956 buffer = interface_cast<IMemory>(data.readStrongBinder());
957 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800958 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700959 pid_t pid = (pid_t) data.readInt32();
Glenn Kasten3acbd052012-02-28 10:39:56 -0800960 pid_t tid = (pid_t) data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -0800961 audio_session_t sessionId = (audio_session_t) data.readInt32();
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800962 int clientUid = data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -0700963 status_t status = NO_ERROR;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700964 sp<IAudioTrack> track;
965 if ((haveSharedBuffer && (buffer == 0)) ||
966 ((buffer != 0) && (buffer->pointer() == NULL))) {
967 ALOGW("CREATE_TRACK: cannot retrieve shared memory");
968 status = DEAD_OBJECT;
969 } else {
970 track = createTrack(
971 (audio_stream_type_t) streamType, sampleRate, format,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700972 channelMask, &frameCount, &flags, buffer, output, pid, tid,
Glenn Kastenc5a17422014-03-13 14:59:59 -0700973 &sessionId, clientUid, &status);
Glenn Kasten0cde0762014-01-16 15:06:36 -0800974 LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700975 }
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700976 reply->writeInt64(frameCount);
Glenn Kastene0b07172012-11-06 15:03:34 -0800977 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700978 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800979 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800980 reply->writeStrongBinder(IInterface::asBinder(track));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800981 return NO_ERROR;
982 } break;
983 case OPEN_RECORD: {
984 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800985 audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800986 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800987 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700988 audio_channel_mask_t channelMask = data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -0700989 const String16& opPackageName = data.readString16();
Glenn Kastene03dd222014-01-28 11:04:39 -0800990 size_t frameCount = data.readInt64();
Eric Laurent05067782016-06-01 18:27:28 -0700991 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700992 pid_t pid = (pid_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700993 pid_t tid = (pid_t) data.readInt32();
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700994 int clientUid = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -0800995 audio_session_t sessionId = (audio_session_t) data.readInt32();
Glenn Kasten74105912014-07-03 12:28:53 -0700996 size_t notificationFrames = data.readInt64();
Glenn Kastend776ac62014-05-07 09:16:09 -0700997 sp<IMemory> cblk;
998 sp<IMemory> buffers;
Wei Jia983dca32015-09-10 09:47:29 -0700999 status_t status = NO_ERROR;
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001000 sp<IAudioRecord> record = openRecord(input,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -07001001 sampleRate, format, channelMask, opPackageName, &frameCount, &flags,
1002 pid, tid, clientUid, &sessionId, &notificationFrames, cblk, buffers,
1003 &status);
Glenn Kastene93cf2c2013-09-24 11:52:37 -07001004 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -07001005 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -07001006 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001007 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -07001008 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001009 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -08001010 reply->writeStrongBinder(IInterface::asBinder(record));
1011 reply->writeStrongBinder(IInterface::asBinder(cblk));
1012 reply->writeStrongBinder(IInterface::asBinder(buffers));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001013 return NO_ERROR;
1014 } break;
1015 case SAMPLE_RATE: {
1016 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001017 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001018 return NO_ERROR;
1019 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001020
1021 // RESERVED for channelCount()
1022
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001023 case FORMAT: {
1024 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001025 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001026 return NO_ERROR;
1027 } break;
1028 case FRAME_COUNT: {
1029 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001030 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001031 return NO_ERROR;
1032 } break;
1033 case LATENCY: {
1034 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001035 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001036 return NO_ERROR;
1037 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001038 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001039 CHECK_INTERFACE(IAudioFlinger, data, reply);
1040 reply->writeInt32( setMasterVolume(data.readFloat()) );
1041 return NO_ERROR;
1042 } break;
1043 case SET_MASTER_MUTE: {
1044 CHECK_INTERFACE(IAudioFlinger, data, reply);
1045 reply->writeInt32( setMasterMute(data.readInt32()) );
1046 return NO_ERROR;
1047 } break;
1048 case MASTER_VOLUME: {
1049 CHECK_INTERFACE(IAudioFlinger, data, reply);
1050 reply->writeFloat( masterVolume() );
1051 return NO_ERROR;
1052 } break;
1053 case MASTER_MUTE: {
1054 CHECK_INTERFACE(IAudioFlinger, data, reply);
1055 reply->writeInt32( masterMute() );
1056 return NO_ERROR;
1057 } break;
1058 case SET_STREAM_VOLUME: {
1059 CHECK_INTERFACE(IAudioFlinger, data, reply);
1060 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001061 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001062 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001063 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001064 return NO_ERROR;
1065 } break;
1066 case SET_STREAM_MUTE: {
1067 CHECK_INTERFACE(IAudioFlinger, data, reply);
1068 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001069 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001070 return NO_ERROR;
1071 } break;
1072 case STREAM_VOLUME: {
1073 CHECK_INTERFACE(IAudioFlinger, data, reply);
1074 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001075 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001076 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001077 return NO_ERROR;
1078 } break;
1079 case STREAM_MUTE: {
1080 CHECK_INTERFACE(IAudioFlinger, data, reply);
1081 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001082 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001083 return NO_ERROR;
1084 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001085 case SET_MODE: {
1086 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001087 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001088 reply->writeInt32( setMode(mode) );
1089 return NO_ERROR;
1090 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001091 case SET_MIC_MUTE: {
1092 CHECK_INTERFACE(IAudioFlinger, data, reply);
1093 int state = data.readInt32();
1094 reply->writeInt32( setMicMute(state) );
1095 return NO_ERROR;
1096 } break;
1097 case GET_MIC_MUTE: {
1098 CHECK_INTERFACE(IAudioFlinger, data, reply);
1099 reply->writeInt32( getMicMute() );
1100 return NO_ERROR;
1101 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001102 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001103 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001104 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001105 String8 keyValuePairs(data.readString8());
1106 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001107 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001108 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001109 case GET_PARAMETERS: {
1110 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001111 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001112 String8 keys(data.readString8());
1113 reply->writeString8(getParameters(ioHandle, keys));
1114 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001115 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001116
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001117 case REGISTER_CLIENT: {
1118 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001119 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1120 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001121 registerClient(client);
1122 return NO_ERROR;
1123 } break;
1124 case GET_INPUTBUFFERSIZE: {
1125 CHECK_INTERFACE(IAudioFlinger, data, reply);
1126 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001127 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001128 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001129 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001130 return NO_ERROR;
1131 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001132 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001133 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001134 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001135 audio_config_t config = {};
1136 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1137 ALOGE("b/23905951");
1138 }
Eric Laurenta4c5a552012-03-29 10:12:40 -07001139 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001140 String8 address(data.readString8());
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001141 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001142 uint32_t latencyMs = 0;
Wei Jia4cac44b2015-09-16 15:01:16 -07001143 audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
Eric Laurentcf2c0212014-07-25 16:20:43 -07001144 status_t status = openOutput(module, &output, &config,
1145 &devices, address, &latencyMs, flags);
Glenn Kasten70742962014-02-18 08:00:47 -08001146 ALOGV("OPEN_OUTPUT output, %d", output);
Eric Laurentcf2c0212014-07-25 16:20:43 -07001147 reply->writeInt32((int32_t)status);
1148 if (status == NO_ERROR) {
1149 reply->writeInt32((int32_t)output);
1150 reply->write(&config, sizeof(audio_config_t));
1151 reply->writeInt32(devices);
1152 reply->writeInt32(latencyMs);
1153 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001154 return NO_ERROR;
1155 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001156 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001157 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001158 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1159 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1160 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001161 return NO_ERROR;
1162 } break;
1163 case CLOSE_OUTPUT: {
1164 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001165 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001166 return NO_ERROR;
1167 } break;
1168 case SUSPEND_OUTPUT: {
1169 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001170 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001171 return NO_ERROR;
1172 } break;
1173 case RESTORE_OUTPUT: {
1174 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001175 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001176 return NO_ERROR;
1177 } break;
1178 case OPEN_INPUT: {
1179 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001180 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001181 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001182 audio_config_t config = {};
1183 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1184 ALOGE("b/23905951");
1185 }
Eric Laurentcf2c0212014-07-25 16:20:43 -07001186 audio_devices_t device = (audio_devices_t)data.readInt32();
1187 String8 address(data.readString8());
1188 audio_source_t source = (audio_source_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001189 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001190
Eric Laurentcf2c0212014-07-25 16:20:43 -07001191 status_t status = openInput(module, &input, &config,
1192 &device, address, source, flags);
1193 reply->writeInt32((int32_t) status);
1194 if (status == NO_ERROR) {
1195 reply->writeInt32((int32_t) input);
1196 reply->write(&config, sizeof(audio_config_t));
1197 reply->writeInt32(device);
1198 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001199 return NO_ERROR;
1200 } break;
1201 case CLOSE_INPUT: {
1202 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001203 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001204 return NO_ERROR;
1205 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001206 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001207 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001208 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1209 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001210 return NO_ERROR;
1211 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001212 case SET_VOICE_VOLUME: {
1213 CHECK_INTERFACE(IAudioFlinger, data, reply);
1214 float volume = data.readFloat();
1215 reply->writeInt32( setVoiceVolume(volume) );
1216 return NO_ERROR;
1217 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001218 case GET_RENDER_POSITION: {
1219 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001220 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001221 uint32_t halFrames = 0;
1222 uint32_t dspFrames = 0;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001223 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1224 reply->writeInt32(status);
1225 if (status == NO_ERROR) {
1226 reply->writeInt32(halFrames);
1227 reply->writeInt32(dspFrames);
1228 }
1229 return NO_ERROR;
1230 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001231 case GET_INPUT_FRAMES_LOST: {
1232 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001233 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001234 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001235 return NO_ERROR;
1236 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001237 case NEW_AUDIO_SESSION_ID: {
1238 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasteneeecb982016-02-26 10:44:04 -08001239 reply->writeInt32(newAudioUniqueId((audio_unique_id_use_t) data.readInt32()));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001240 return NO_ERROR;
1241 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001242 case ACQUIRE_AUDIO_SESSION_ID: {
1243 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001244 audio_session_t audioSession = (audio_session_t) data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001245 int pid = data.readInt32();
1246 acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001247 return NO_ERROR;
1248 } break;
1249 case RELEASE_AUDIO_SESSION_ID: {
1250 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001251 audio_session_t audioSession = (audio_session_t) data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001252 int pid = data.readInt32();
1253 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001254 return NO_ERROR;
1255 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001256 case QUERY_NUM_EFFECTS: {
1257 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001258 uint32_t numEffects = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001259 status_t status = queryNumberEffects(&numEffects);
1260 reply->writeInt32(status);
1261 if (status == NO_ERROR) {
1262 reply->writeInt32((int32_t)numEffects);
1263 }
1264 return NO_ERROR;
1265 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001266 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001267 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001268 effect_descriptor_t desc = {};
Eric Laurentffe9c252010-06-23 17:38:20 -07001269 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001270 reply->writeInt32(status);
1271 if (status == NO_ERROR) {
1272 reply->write(&desc, sizeof(effect_descriptor_t));
1273 }
1274 return NO_ERROR;
1275 }
1276 case GET_EFFECT_DESCRIPTOR: {
1277 CHECK_INTERFACE(IAudioFlinger, data, reply);
1278 effect_uuid_t uuid;
1279 data.read(&uuid, sizeof(effect_uuid_t));
Wei Jia983dca32015-09-10 09:47:29 -07001280 effect_descriptor_t desc = {};
Eric Laurentbe916aa2010-06-01 23:49:17 -07001281 status_t status = getEffectDescriptor(&uuid, &desc);
1282 reply->writeInt32(status);
1283 if (status == NO_ERROR) {
1284 reply->write(&desc, sizeof(effect_descriptor_t));
1285 }
1286 return NO_ERROR;
1287 }
1288 case CREATE_EFFECT: {
1289 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001290 effect_descriptor_t desc = {};
1291 if (data.read(&desc, sizeof(effect_descriptor_t)) != NO_ERROR) {
1292 ALOGE("b/23905951");
1293 }
Eric Laurentbe916aa2010-06-01 23:49:17 -07001294 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1295 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001296 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001297 audio_session_t sessionId = (audio_session_t) data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -07001298 const String16 opPackageName = data.readString16();
Eric Laurentb6436272016-12-07 19:24:50 -08001299 pid_t pid = (pid_t)data.readInt32();
1300
Wei Jia983dca32015-09-10 09:47:29 -07001301 status_t status = NO_ERROR;
1302 int id = 0;
1303 int enabled = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001304
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001305 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Eric Laurentb6436272016-12-07 19:24:50 -08001306 opPackageName, pid, &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001307 reply->writeInt32(status);
1308 reply->writeInt32(id);
1309 reply->writeInt32(enabled);
Marco Nelissen06b46062014-11-14 07:58:25 -08001310 reply->writeStrongBinder(IInterface::asBinder(effect));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001311 reply->write(&desc, sizeof(effect_descriptor_t));
1312 return NO_ERROR;
1313 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001314 case MOVE_EFFECTS: {
1315 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001316 audio_session_t session = (audio_session_t) data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001317 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1318 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001319 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1320 return NO_ERROR;
1321 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001322 case LOAD_HW_MODULE: {
1323 CHECK_INTERFACE(IAudioFlinger, data, reply);
1324 reply->writeInt32(loadHwModule(data.readCString()));
1325 return NO_ERROR;
1326 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001327 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1328 CHECK_INTERFACE(IAudioFlinger, data, reply);
1329 reply->writeInt32(getPrimaryOutputSamplingRate());
1330 return NO_ERROR;
1331 } break;
1332 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1333 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001334 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001335 return NO_ERROR;
1336 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001337 case SET_LOW_RAM_DEVICE: {
1338 CHECK_INTERFACE(IAudioFlinger, data, reply);
1339 bool isLowRamDevice = data.readInt32() != 0;
1340 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1341 return NO_ERROR;
1342 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001343 case LIST_AUDIO_PORTS: {
1344 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001345 unsigned int numPortsReq = data.readInt32();
1346 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1347 numPortsReq = MAX_ITEMS_PER_LIST;
1348 }
1349 unsigned int numPorts = numPortsReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001350 struct audio_port *ports =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001351 (struct audio_port *)calloc(numPortsReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001352 sizeof(struct audio_port));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001353 if (ports == NULL) {
1354 reply->writeInt32(NO_MEMORY);
1355 reply->writeInt32(0);
1356 return NO_ERROR;
1357 }
1358 status_t status = listAudioPorts(&numPorts, ports);
Eric Laurent4b123402014-04-11 09:22:20 -07001359 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001360 reply->writeInt32(numPorts);
Eric Laurent4b123402014-04-11 09:22:20 -07001361 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001362 if (numPortsReq > numPorts) {
1363 numPortsReq = numPorts;
1364 }
1365 reply->write(ports, numPortsReq * sizeof(struct audio_port));
Eric Laurent4b123402014-04-11 09:22:20 -07001366 }
1367 free(ports);
1368 return NO_ERROR;
1369 } break;
1370 case GET_AUDIO_PORT: {
1371 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001372 struct audio_port port = {};
1373 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1374 ALOGE("b/23905951");
1375 }
Eric Laurent4b123402014-04-11 09:22:20 -07001376 status_t status = getAudioPort(&port);
1377 reply->writeInt32(status);
1378 if (status == NO_ERROR) {
1379 reply->write(&port, sizeof(struct audio_port));
1380 }
1381 return NO_ERROR;
1382 } break;
1383 case CREATE_AUDIO_PATCH: {
1384 CHECK_INTERFACE(IAudioFlinger, data, reply);
1385 struct audio_patch patch;
1386 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001387 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001388 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1389 ALOGE("b/23905951");
1390 }
Eric Laurent4b123402014-04-11 09:22:20 -07001391 status_t status = createAudioPatch(&patch, &handle);
1392 reply->writeInt32(status);
1393 if (status == NO_ERROR) {
1394 reply->write(&handle, sizeof(audio_patch_handle_t));
1395 }
1396 return NO_ERROR;
1397 } break;
1398 case RELEASE_AUDIO_PATCH: {
1399 CHECK_INTERFACE(IAudioFlinger, data, reply);
1400 audio_patch_handle_t handle;
1401 data.read(&handle, sizeof(audio_patch_handle_t));
1402 status_t status = releaseAudioPatch(handle);
1403 reply->writeInt32(status);
1404 return NO_ERROR;
1405 } break;
1406 case LIST_AUDIO_PATCHES: {
1407 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001408 unsigned int numPatchesReq = data.readInt32();
1409 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1410 numPatchesReq = MAX_ITEMS_PER_LIST;
1411 }
1412 unsigned int numPatches = numPatchesReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001413 struct audio_patch *patches =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001414 (struct audio_patch *)calloc(numPatchesReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001415 sizeof(struct audio_patch));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001416 if (patches == NULL) {
1417 reply->writeInt32(NO_MEMORY);
1418 reply->writeInt32(0);
1419 return NO_ERROR;
1420 }
1421 status_t status = listAudioPatches(&numPatches, patches);
Eric Laurent4b123402014-04-11 09:22:20 -07001422 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001423 reply->writeInt32(numPatches);
Eric Laurent4b123402014-04-11 09:22:20 -07001424 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001425 if (numPatchesReq > numPatches) {
1426 numPatchesReq = numPatches;
1427 }
1428 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
Eric Laurent4b123402014-04-11 09:22:20 -07001429 }
1430 free(patches);
1431 return NO_ERROR;
1432 } break;
1433 case SET_AUDIO_PORT_CONFIG: {
1434 CHECK_INTERFACE(IAudioFlinger, data, reply);
1435 struct audio_port_config config;
1436 data.read(&config, sizeof(struct audio_port_config));
1437 status_t status = setAudioPortConfig(&config);
1438 reply->writeInt32(status);
1439 return NO_ERROR;
1440 } break;
Eric Laurent93c3d412014-08-01 14:48:35 -07001441 case GET_AUDIO_HW_SYNC: {
1442 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001443 reply->writeInt32(getAudioHwSyncForSession((audio_session_t) data.readInt32()));
Eric Laurent93c3d412014-08-01 14:48:35 -07001444 return NO_ERROR;
1445 } break;
Eric Laurent72e3f392015-05-20 14:43:50 -07001446 case SYSTEM_READY: {
1447 CHECK_INTERFACE(IAudioFlinger, data, reply);
1448 systemReady();
1449 return NO_ERROR;
1450 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001451 case FRAME_COUNT_HAL: {
1452 CHECK_INTERFACE(IAudioFlinger, data, reply);
1453 reply->writeInt64( frameCountHAL((audio_io_handle_t) data.readInt32()) );
1454 return NO_ERROR;
1455 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001456 default:
1457 return BBinder::onTransact(code, data, reply, flags);
1458 }
1459}
1460
1461// ----------------------------------------------------------------------------
1462
Glenn Kasten40bc9062015-03-20 09:09:33 -07001463} // namespace android