blob: 92e65e482eb1acb867595fe204306a4e004e22a1 [file] [log] [blame]
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001/*
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08002**
3** Copyright 2007, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioFlinger"
Eric Laurentc2f1f072009-07-17 12:17:14 -070019//#define LOG_NDEBUG 0
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080020#include <utils/Log.h>
21
22#include <stdint.h>
23#include <sys/types.h>
24
Mathias Agopian75624082009-05-19 19:08:10 -070025#include <binder/Parcel.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080026
27#include <media/IAudioFlinger.h>
28
29namespace android {
30
31enum {
32 CREATE_TRACK = IBinder::FIRST_CALL_TRANSACTION,
33 OPEN_RECORD,
34 SAMPLE_RATE,
Glenn Kasten5876f2f2012-11-30 10:52:16 -080035 RESERVED, // obsolete, was CHANNEL_COUNT
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080036 FORMAT,
37 FRAME_COUNT,
38 LATENCY,
39 SET_MASTER_VOLUME,
40 SET_MASTER_MUTE,
41 MASTER_VOLUME,
42 MASTER_MUTE,
43 SET_STREAM_VOLUME,
44 SET_STREAM_MUTE,
45 STREAM_VOLUME,
46 STREAM_MUTE,
47 SET_MODE,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080048 SET_MIC_MUTE,
49 GET_MIC_MUTE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070050 SET_PARAMETERS,
51 GET_PARAMETERS,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080052 REGISTER_CLIENT,
53 GET_INPUTBUFFERSIZE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070054 OPEN_OUTPUT,
55 OPEN_DUPLICATE_OUTPUT,
56 CLOSE_OUTPUT,
57 SUSPEND_OUTPUT,
58 RESTORE_OUTPUT,
59 OPEN_INPUT,
60 CLOSE_INPUT,
Glenn Kastend2304db2014-02-03 07:40:31 -080061 INVALIDATE_STREAM,
Eric Laurent342e9cf2010-01-19 17:37:09 -080062 SET_VOICE_VOLUME,
Eric Laurent05bca2f2010-02-26 02:47:27 -080063 GET_RENDER_POSITION,
Eric Laurentbe916aa2010-06-01 23:49:17 -070064 GET_INPUT_FRAMES_LOST,
65 NEW_AUDIO_SESSION_ID,
Marco Nelissen3a34bef2011-08-02 13:33:41 -070066 ACQUIRE_AUDIO_SESSION_ID,
67 RELEASE_AUDIO_SESSION_ID,
Eric Laurentbe916aa2010-06-01 23:49:17 -070068 QUERY_NUM_EFFECTS,
Eric Laurentffe9c252010-06-23 17:38:20 -070069 QUERY_EFFECT,
Eric Laurentbe916aa2010-06-01 23:49:17 -070070 GET_EFFECT_DESCRIPTOR,
Eric Laurentde070132010-07-13 04:45:46 -070071 CREATE_EFFECT,
Eric Laurenta4c5a552012-03-29 10:12:40 -070072 MOVE_EFFECTS,
Glenn Kastencc0f1cf2012-09-24 11:27:18 -070073 LOAD_HW_MODULE,
74 GET_PRIMARY_OUTPUT_SAMPLING_RATE,
75 GET_PRIMARY_OUTPUT_FRAME_COUNT,
Glenn Kasten4182c4e2013-07-15 14:45:07 -070076 SET_LOW_RAM_DEVICE,
Eric Laurent4b123402014-04-11 09:22:20 -070077 LIST_AUDIO_PORTS,
78 GET_AUDIO_PORT,
79 CREATE_AUDIO_PATCH,
80 RELEASE_AUDIO_PATCH,
81 LIST_AUDIO_PATCHES,
Eric Laurent93c3d412014-08-01 14:48:35 -070082 SET_AUDIO_PORT_CONFIG,
Eric Laurent72e3f392015-05-20 14:43:50 -070083 GET_AUDIO_HW_SYNC,
Glenn Kasten4a8308b2016-04-18 14:10:01 -070084 SYSTEM_READY,
85 FRAME_COUNT_HAL,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080086};
87
Eric Laurentf75c2fe2015-04-02 13:49:15 -070088#define MAX_ITEMS_PER_LIST 1024
89
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080090class BpAudioFlinger : public BpInterface<IAudioFlinger>
91{
92public:
93 BpAudioFlinger(const sp<IBinder>& impl)
94 : BpInterface<IAudioFlinger>(impl)
95 {
96 }
97
98 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080099 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800100 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800101 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -0700102 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -0800103 size_t *pFrameCount,
Glenn Kastene0b07172012-11-06 15:03:34 -0800104 track_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800105 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800106 audio_io_handle_t output,
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);
Glenn Kastenb26e3e92012-11-14 08:32:08 -0800122 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
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 }
Glenn Kastene0b07172012-11-06 15:03:34 -0800148 lFlags = reply.readInt32();
149 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,
Glenn Kasteneeca3262013-07-31 16:12:48 -0700183 track_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);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700203 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
204 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 }
Glenn Kasteneeca3262013-07-31 16:12:48 -0700224 lFlags = reply.readInt32();
225 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 Laurentbe916aa2010-06-01 23:49:17 -0700719 status_t *status,
720 int *id,
721 int *enabled)
722 {
723 Parcel data, reply;
724 sp<IEffect> effect;
725
726 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700727 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700728 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700729 *status = BAD_VALUE;
730 }
731 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700732
733 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700734 data.write(pDesc, sizeof(effect_descriptor_t));
Marco Nelissen06b46062014-11-14 07:58:25 -0800735 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700736 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800737 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700738 data.writeInt32(sessionId);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700739 data.writeString16(opPackageName);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700740
741 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
742 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000743 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700744 } else {
745 lStatus = reply.readInt32();
746 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700747 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700748 *id = tmp;
749 }
750 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800751 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700752 *enabled = tmp;
753 }
754 effect = interface_cast<IEffect>(reply.readStrongBinder());
755 reply.read(pDesc, sizeof(effect_descriptor_t));
756 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700757 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700758 *status = lStatus;
759 }
760
761 return effect;
762 }
Eric Laurentde070132010-07-13 04:45:46 -0700763
Glenn Kastend848eb42016-03-08 13:42:11 -0800764 virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800765 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700766 {
767 Parcel data, reply;
768 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
769 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800770 data.writeInt32((int32_t) srcOutput);
771 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700772 remote()->transact(MOVE_EFFECTS, data, &reply);
773 return reply.readInt32();
774 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700775
776 virtual audio_module_handle_t loadHwModule(const char *name)
777 {
778 Parcel data, reply;
779 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
780 data.writeCString(name);
781 remote()->transact(LOAD_HW_MODULE, data, &reply);
782 return (audio_module_handle_t) reply.readInt32();
783 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700784
Glenn Kasten3b16c762012-11-14 08:44:39 -0800785 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700786 {
787 Parcel data, reply;
788 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
789 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
790 return reply.readInt32();
791 }
792
Glenn Kastene33054e2012-11-14 12:54:39 -0800793 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700794 {
795 Parcel data, reply;
796 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
797 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800798 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700799 }
800
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700801 virtual status_t setLowRamDevice(bool isLowRamDevice)
802 {
803 Parcel data, reply;
804 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
805 data.writeInt32((int) isLowRamDevice);
806 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
807 return reply.readInt32();
808 }
Eric Laurent4b123402014-04-11 09:22:20 -0700809 virtual status_t listAudioPorts(unsigned int *num_ports,
810 struct audio_port *ports)
811 {
812 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
813 return BAD_VALUE;
814 }
815 Parcel data, reply;
816 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
817 data.writeInt32(*num_ports);
818 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
819 if (status != NO_ERROR ||
820 (status = (status_t)reply.readInt32()) != NO_ERROR) {
821 return status;
822 }
823 *num_ports = (unsigned int)reply.readInt32();
824 reply.read(ports, *num_ports * sizeof(struct audio_port));
825 return status;
826 }
827 virtual status_t getAudioPort(struct audio_port *port)
828 {
829 if (port == NULL) {
830 return BAD_VALUE;
831 }
832 Parcel data, reply;
833 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
834 data.write(port, sizeof(struct audio_port));
835 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
836 if (status != NO_ERROR ||
837 (status = (status_t)reply.readInt32()) != NO_ERROR) {
838 return status;
839 }
840 reply.read(port, sizeof(struct audio_port));
841 return status;
842 }
843 virtual status_t createAudioPatch(const struct audio_patch *patch,
844 audio_patch_handle_t *handle)
845 {
846 if (patch == NULL || handle == NULL) {
847 return BAD_VALUE;
848 }
849 Parcel data, reply;
850 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
851 data.write(patch, sizeof(struct audio_patch));
852 data.write(handle, sizeof(audio_patch_handle_t));
853 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
854 if (status != NO_ERROR ||
855 (status = (status_t)reply.readInt32()) != NO_ERROR) {
856 return status;
857 }
858 reply.read(handle, sizeof(audio_patch_handle_t));
859 return status;
860 }
861 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
862 {
863 Parcel data, reply;
864 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
865 data.write(&handle, sizeof(audio_patch_handle_t));
866 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
867 if (status != NO_ERROR) {
868 status = (status_t)reply.readInt32();
869 }
870 return status;
871 }
872 virtual status_t listAudioPatches(unsigned int *num_patches,
873 struct audio_patch *patches)
874 {
875 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
876 return BAD_VALUE;
877 }
878 Parcel data, reply;
879 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
880 data.writeInt32(*num_patches);
881 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
882 if (status != NO_ERROR ||
883 (status = (status_t)reply.readInt32()) != NO_ERROR) {
884 return status;
885 }
886 *num_patches = (unsigned int)reply.readInt32();
887 reply.read(patches, *num_patches * sizeof(struct audio_patch));
888 return status;
889 }
890 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
891 {
892 if (config == NULL) {
893 return BAD_VALUE;
894 }
895 Parcel data, reply;
896 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
897 data.write(config, sizeof(struct audio_port_config));
898 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
899 if (status != NO_ERROR) {
900 status = (status_t)reply.readInt32();
901 }
902 return status;
903 }
Eric Laurent93c3d412014-08-01 14:48:35 -0700904 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
905 {
906 Parcel data, reply;
907 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
908 data.writeInt32(sessionId);
909 status_t status = remote()->transact(GET_AUDIO_HW_SYNC, data, &reply);
910 if (status != NO_ERROR) {
911 return AUDIO_HW_SYNC_INVALID;
912 }
913 return (audio_hw_sync_t)reply.readInt32();
914 }
Eric Laurent72e3f392015-05-20 14:43:50 -0700915 virtual status_t systemReady()
916 {
917 Parcel data, reply;
918 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
919 return remote()->transact(SYSTEM_READY, data, &reply, IBinder::FLAG_ONEWAY);
920 }
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700921 virtual size_t frameCountHAL(audio_io_handle_t ioHandle) const
922 {
923 Parcel data, reply;
924 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
925 data.writeInt32((int32_t) ioHandle);
926 status_t status = remote()->transact(FRAME_COUNT_HAL, data, &reply);
927 if (status != NO_ERROR) {
928 return 0;
929 }
930 return reply.readInt64();
931 }
932
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800933};
934
935IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
936
937// ----------------------------------------------------------------------
938
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800939status_t BnAudioFlinger::onTransact(
940 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
941{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700942 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800943 case CREATE_TRACK: {
944 CHECK_INTERFACE(IAudioFlinger, data, reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800945 int streamType = data.readInt32();
946 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800947 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700948 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800949 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800950 track_flags_t flags = (track_flags_t) data.readInt32();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700951 bool haveSharedBuffer = data.readInt32() != 0;
952 sp<IMemory> buffer;
953 if (haveSharedBuffer) {
954 buffer = interface_cast<IMemory>(data.readStrongBinder());
955 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800956 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700957 pid_t pid = (pid_t) data.readInt32();
Glenn Kasten3acbd052012-02-28 10:39:56 -0800958 pid_t tid = (pid_t) data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -0800959 audio_session_t sessionId = (audio_session_t) data.readInt32();
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800960 int clientUid = data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -0700961 status_t status = NO_ERROR;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700962 sp<IAudioTrack> track;
963 if ((haveSharedBuffer && (buffer == 0)) ||
964 ((buffer != 0) && (buffer->pointer() == NULL))) {
965 ALOGW("CREATE_TRACK: cannot retrieve shared memory");
966 status = DEAD_OBJECT;
967 } else {
968 track = createTrack(
969 (audio_stream_type_t) streamType, sampleRate, format,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700970 channelMask, &frameCount, &flags, buffer, output, pid, tid,
Glenn Kastenc5a17422014-03-13 14:59:59 -0700971 &sessionId, clientUid, &status);
Glenn Kasten0cde0762014-01-16 15:06:36 -0800972 LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700973 }
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700974 reply->writeInt64(frameCount);
Glenn Kastene0b07172012-11-06 15:03:34 -0800975 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700976 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800977 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800978 reply->writeStrongBinder(IInterface::asBinder(track));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800979 return NO_ERROR;
980 } break;
981 case OPEN_RECORD: {
982 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800983 audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800984 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800985 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700986 audio_channel_mask_t channelMask = data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -0700987 const String16& opPackageName = data.readString16();
Glenn Kastene03dd222014-01-28 11:04:39 -0800988 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800989 track_flags_t flags = (track_flags_t) data.readInt32();
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700990 pid_t pid = (pid_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700991 pid_t tid = (pid_t) data.readInt32();
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700992 int clientUid = data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -0800993 audio_session_t sessionId = (audio_session_t) data.readInt32();
Glenn Kasten74105912014-07-03 12:28:53 -0700994 size_t notificationFrames = data.readInt64();
Glenn Kastend776ac62014-05-07 09:16:09 -0700995 sp<IMemory> cblk;
996 sp<IMemory> buffers;
Wei Jia983dca32015-09-10 09:47:29 -0700997 status_t status = NO_ERROR;
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800998 sp<IAudioRecord> record = openRecord(input,
Haynes Mathew George9ea77cd2016-04-06 17:07:48 -0700999 sampleRate, format, channelMask, opPackageName, &frameCount, &flags,
1000 pid, tid, clientUid, &sessionId, &notificationFrames, cblk, buffers,
1001 &status);
Glenn Kastene93cf2c2013-09-24 11:52:37 -07001002 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -07001003 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -07001004 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001005 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -07001006 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001007 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -08001008 reply->writeStrongBinder(IInterface::asBinder(record));
1009 reply->writeStrongBinder(IInterface::asBinder(cblk));
1010 reply->writeStrongBinder(IInterface::asBinder(buffers));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001011 return NO_ERROR;
1012 } break;
1013 case SAMPLE_RATE: {
1014 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001015 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001016 return NO_ERROR;
1017 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001018
1019 // RESERVED for channelCount()
1020
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001021 case FORMAT: {
1022 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001023 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001024 return NO_ERROR;
1025 } break;
1026 case FRAME_COUNT: {
1027 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001028 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001029 return NO_ERROR;
1030 } break;
1031 case LATENCY: {
1032 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001033 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001034 return NO_ERROR;
1035 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001036 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001037 CHECK_INTERFACE(IAudioFlinger, data, reply);
1038 reply->writeInt32( setMasterVolume(data.readFloat()) );
1039 return NO_ERROR;
1040 } break;
1041 case SET_MASTER_MUTE: {
1042 CHECK_INTERFACE(IAudioFlinger, data, reply);
1043 reply->writeInt32( setMasterMute(data.readInt32()) );
1044 return NO_ERROR;
1045 } break;
1046 case MASTER_VOLUME: {
1047 CHECK_INTERFACE(IAudioFlinger, data, reply);
1048 reply->writeFloat( masterVolume() );
1049 return NO_ERROR;
1050 } break;
1051 case MASTER_MUTE: {
1052 CHECK_INTERFACE(IAudioFlinger, data, reply);
1053 reply->writeInt32( masterMute() );
1054 return NO_ERROR;
1055 } break;
1056 case SET_STREAM_VOLUME: {
1057 CHECK_INTERFACE(IAudioFlinger, data, reply);
1058 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001059 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001060 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001061 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001062 return NO_ERROR;
1063 } break;
1064 case SET_STREAM_MUTE: {
1065 CHECK_INTERFACE(IAudioFlinger, data, reply);
1066 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001067 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001068 return NO_ERROR;
1069 } break;
1070 case STREAM_VOLUME: {
1071 CHECK_INTERFACE(IAudioFlinger, data, reply);
1072 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001073 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001074 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001075 return NO_ERROR;
1076 } break;
1077 case STREAM_MUTE: {
1078 CHECK_INTERFACE(IAudioFlinger, data, reply);
1079 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001080 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001081 return NO_ERROR;
1082 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001083 case SET_MODE: {
1084 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001085 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001086 reply->writeInt32( setMode(mode) );
1087 return NO_ERROR;
1088 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001089 case SET_MIC_MUTE: {
1090 CHECK_INTERFACE(IAudioFlinger, data, reply);
1091 int state = data.readInt32();
1092 reply->writeInt32( setMicMute(state) );
1093 return NO_ERROR;
1094 } break;
1095 case GET_MIC_MUTE: {
1096 CHECK_INTERFACE(IAudioFlinger, data, reply);
1097 reply->writeInt32( getMicMute() );
1098 return NO_ERROR;
1099 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001100 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001101 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001102 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001103 String8 keyValuePairs(data.readString8());
1104 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001105 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001106 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001107 case GET_PARAMETERS: {
1108 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001109 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001110 String8 keys(data.readString8());
1111 reply->writeString8(getParameters(ioHandle, keys));
1112 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001113 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001114
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001115 case REGISTER_CLIENT: {
1116 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001117 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1118 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001119 registerClient(client);
1120 return NO_ERROR;
1121 } break;
1122 case GET_INPUTBUFFERSIZE: {
1123 CHECK_INTERFACE(IAudioFlinger, data, reply);
1124 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001125 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001126 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001127 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001128 return NO_ERROR;
1129 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001130 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001131 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001132 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001133 audio_config_t config = {};
1134 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1135 ALOGE("b/23905951");
1136 }
Eric Laurenta4c5a552012-03-29 10:12:40 -07001137 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001138 String8 address(data.readString8());
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001139 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001140 uint32_t latencyMs = 0;
Wei Jia4cac44b2015-09-16 15:01:16 -07001141 audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
Eric Laurentcf2c0212014-07-25 16:20:43 -07001142 status_t status = openOutput(module, &output, &config,
1143 &devices, address, &latencyMs, flags);
Glenn Kasten70742962014-02-18 08:00:47 -08001144 ALOGV("OPEN_OUTPUT output, %d", output);
Eric Laurentcf2c0212014-07-25 16:20:43 -07001145 reply->writeInt32((int32_t)status);
1146 if (status == NO_ERROR) {
1147 reply->writeInt32((int32_t)output);
1148 reply->write(&config, sizeof(audio_config_t));
1149 reply->writeInt32(devices);
1150 reply->writeInt32(latencyMs);
1151 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001152 return NO_ERROR;
1153 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001154 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001155 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001156 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1157 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1158 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001159 return NO_ERROR;
1160 } break;
1161 case CLOSE_OUTPUT: {
1162 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001163 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001164 return NO_ERROR;
1165 } break;
1166 case SUSPEND_OUTPUT: {
1167 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001168 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001169 return NO_ERROR;
1170 } break;
1171 case RESTORE_OUTPUT: {
1172 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001173 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001174 return NO_ERROR;
1175 } break;
1176 case OPEN_INPUT: {
1177 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001178 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001179 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001180 audio_config_t config = {};
1181 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1182 ALOGE("b/23905951");
1183 }
Eric Laurentcf2c0212014-07-25 16:20:43 -07001184 audio_devices_t device = (audio_devices_t)data.readInt32();
1185 String8 address(data.readString8());
1186 audio_source_t source = (audio_source_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001187 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001188
Eric Laurentcf2c0212014-07-25 16:20:43 -07001189 status_t status = openInput(module, &input, &config,
1190 &device, address, source, flags);
1191 reply->writeInt32((int32_t) status);
1192 if (status == NO_ERROR) {
1193 reply->writeInt32((int32_t) input);
1194 reply->write(&config, sizeof(audio_config_t));
1195 reply->writeInt32(device);
1196 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001197 return NO_ERROR;
1198 } break;
1199 case CLOSE_INPUT: {
1200 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001201 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001202 return NO_ERROR;
1203 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001204 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001205 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001206 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1207 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001208 return NO_ERROR;
1209 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001210 case SET_VOICE_VOLUME: {
1211 CHECK_INTERFACE(IAudioFlinger, data, reply);
1212 float volume = data.readFloat();
1213 reply->writeInt32( setVoiceVolume(volume) );
1214 return NO_ERROR;
1215 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001216 case GET_RENDER_POSITION: {
1217 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001218 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001219 uint32_t halFrames = 0;
1220 uint32_t dspFrames = 0;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001221 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1222 reply->writeInt32(status);
1223 if (status == NO_ERROR) {
1224 reply->writeInt32(halFrames);
1225 reply->writeInt32(dspFrames);
1226 }
1227 return NO_ERROR;
1228 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001229 case GET_INPUT_FRAMES_LOST: {
1230 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001231 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001232 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001233 return NO_ERROR;
1234 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001235 case NEW_AUDIO_SESSION_ID: {
1236 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasteneeecb982016-02-26 10:44:04 -08001237 reply->writeInt32(newAudioUniqueId((audio_unique_id_use_t) data.readInt32()));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001238 return NO_ERROR;
1239 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001240 case ACQUIRE_AUDIO_SESSION_ID: {
1241 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001242 audio_session_t audioSession = (audio_session_t) data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001243 int pid = data.readInt32();
1244 acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001245 return NO_ERROR;
1246 } break;
1247 case RELEASE_AUDIO_SESSION_ID: {
1248 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001249 audio_session_t audioSession = (audio_session_t) data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001250 int pid = data.readInt32();
1251 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001252 return NO_ERROR;
1253 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001254 case QUERY_NUM_EFFECTS: {
1255 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001256 uint32_t numEffects = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001257 status_t status = queryNumberEffects(&numEffects);
1258 reply->writeInt32(status);
1259 if (status == NO_ERROR) {
1260 reply->writeInt32((int32_t)numEffects);
1261 }
1262 return NO_ERROR;
1263 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001264 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001265 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001266 effect_descriptor_t desc = {};
Eric Laurentffe9c252010-06-23 17:38:20 -07001267 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001268 reply->writeInt32(status);
1269 if (status == NO_ERROR) {
1270 reply->write(&desc, sizeof(effect_descriptor_t));
1271 }
1272 return NO_ERROR;
1273 }
1274 case GET_EFFECT_DESCRIPTOR: {
1275 CHECK_INTERFACE(IAudioFlinger, data, reply);
1276 effect_uuid_t uuid;
1277 data.read(&uuid, sizeof(effect_uuid_t));
Wei Jia983dca32015-09-10 09:47:29 -07001278 effect_descriptor_t desc = {};
Eric Laurentbe916aa2010-06-01 23:49:17 -07001279 status_t status = getEffectDescriptor(&uuid, &desc);
1280 reply->writeInt32(status);
1281 if (status == NO_ERROR) {
1282 reply->write(&desc, sizeof(effect_descriptor_t));
1283 }
1284 return NO_ERROR;
1285 }
1286 case CREATE_EFFECT: {
1287 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001288 effect_descriptor_t desc = {};
1289 if (data.read(&desc, sizeof(effect_descriptor_t)) != NO_ERROR) {
1290 ALOGE("b/23905951");
1291 }
Eric Laurentbe916aa2010-06-01 23:49:17 -07001292 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1293 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001294 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001295 audio_session_t sessionId = (audio_session_t) data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -07001296 const String16 opPackageName = data.readString16();
Wei Jia983dca32015-09-10 09:47:29 -07001297 status_t status = NO_ERROR;
1298 int id = 0;
1299 int enabled = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001300
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001301 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -07001302 opPackageName, &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001303 reply->writeInt32(status);
1304 reply->writeInt32(id);
1305 reply->writeInt32(enabled);
Marco Nelissen06b46062014-11-14 07:58:25 -08001306 reply->writeStrongBinder(IInterface::asBinder(effect));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001307 reply->write(&desc, sizeof(effect_descriptor_t));
1308 return NO_ERROR;
1309 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001310 case MOVE_EFFECTS: {
1311 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001312 audio_session_t session = (audio_session_t) data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001313 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1314 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001315 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1316 return NO_ERROR;
1317 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001318 case LOAD_HW_MODULE: {
1319 CHECK_INTERFACE(IAudioFlinger, data, reply);
1320 reply->writeInt32(loadHwModule(data.readCString()));
1321 return NO_ERROR;
1322 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001323 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1324 CHECK_INTERFACE(IAudioFlinger, data, reply);
1325 reply->writeInt32(getPrimaryOutputSamplingRate());
1326 return NO_ERROR;
1327 } break;
1328 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1329 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001330 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001331 return NO_ERROR;
1332 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001333 case SET_LOW_RAM_DEVICE: {
1334 CHECK_INTERFACE(IAudioFlinger, data, reply);
1335 bool isLowRamDevice = data.readInt32() != 0;
1336 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1337 return NO_ERROR;
1338 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001339 case LIST_AUDIO_PORTS: {
1340 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001341 unsigned int numPortsReq = data.readInt32();
1342 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1343 numPortsReq = MAX_ITEMS_PER_LIST;
1344 }
1345 unsigned int numPorts = numPortsReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001346 struct audio_port *ports =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001347 (struct audio_port *)calloc(numPortsReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001348 sizeof(struct audio_port));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001349 if (ports == NULL) {
1350 reply->writeInt32(NO_MEMORY);
1351 reply->writeInt32(0);
1352 return NO_ERROR;
1353 }
1354 status_t status = listAudioPorts(&numPorts, ports);
Eric Laurent4b123402014-04-11 09:22:20 -07001355 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001356 reply->writeInt32(numPorts);
Eric Laurent4b123402014-04-11 09:22:20 -07001357 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001358 if (numPortsReq > numPorts) {
1359 numPortsReq = numPorts;
1360 }
1361 reply->write(ports, numPortsReq * sizeof(struct audio_port));
Eric Laurent4b123402014-04-11 09:22:20 -07001362 }
1363 free(ports);
1364 return NO_ERROR;
1365 } break;
1366 case GET_AUDIO_PORT: {
1367 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001368 struct audio_port port = {};
1369 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1370 ALOGE("b/23905951");
1371 }
Eric Laurent4b123402014-04-11 09:22:20 -07001372 status_t status = getAudioPort(&port);
1373 reply->writeInt32(status);
1374 if (status == NO_ERROR) {
1375 reply->write(&port, sizeof(struct audio_port));
1376 }
1377 return NO_ERROR;
1378 } break;
1379 case CREATE_AUDIO_PATCH: {
1380 CHECK_INTERFACE(IAudioFlinger, data, reply);
1381 struct audio_patch patch;
1382 data.read(&patch, sizeof(struct audio_patch));
Glenn Kastena13cde92016-03-28 15:26:02 -07001383 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
Wei Jiae995e472015-09-09 09:48:34 -07001384 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1385 ALOGE("b/23905951");
1386 }
Eric Laurent4b123402014-04-11 09:22:20 -07001387 status_t status = createAudioPatch(&patch, &handle);
1388 reply->writeInt32(status);
1389 if (status == NO_ERROR) {
1390 reply->write(&handle, sizeof(audio_patch_handle_t));
1391 }
1392 return NO_ERROR;
1393 } break;
1394 case RELEASE_AUDIO_PATCH: {
1395 CHECK_INTERFACE(IAudioFlinger, data, reply);
1396 audio_patch_handle_t handle;
1397 data.read(&handle, sizeof(audio_patch_handle_t));
1398 status_t status = releaseAudioPatch(handle);
1399 reply->writeInt32(status);
1400 return NO_ERROR;
1401 } break;
1402 case LIST_AUDIO_PATCHES: {
1403 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001404 unsigned int numPatchesReq = data.readInt32();
1405 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1406 numPatchesReq = MAX_ITEMS_PER_LIST;
1407 }
1408 unsigned int numPatches = numPatchesReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001409 struct audio_patch *patches =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001410 (struct audio_patch *)calloc(numPatchesReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001411 sizeof(struct audio_patch));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001412 if (patches == NULL) {
1413 reply->writeInt32(NO_MEMORY);
1414 reply->writeInt32(0);
1415 return NO_ERROR;
1416 }
1417 status_t status = listAudioPatches(&numPatches, patches);
Eric Laurent4b123402014-04-11 09:22:20 -07001418 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001419 reply->writeInt32(numPatches);
Eric Laurent4b123402014-04-11 09:22:20 -07001420 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001421 if (numPatchesReq > numPatches) {
1422 numPatchesReq = numPatches;
1423 }
1424 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
Eric Laurent4b123402014-04-11 09:22:20 -07001425 }
1426 free(patches);
1427 return NO_ERROR;
1428 } break;
1429 case SET_AUDIO_PORT_CONFIG: {
1430 CHECK_INTERFACE(IAudioFlinger, data, reply);
1431 struct audio_port_config config;
1432 data.read(&config, sizeof(struct audio_port_config));
1433 status_t status = setAudioPortConfig(&config);
1434 reply->writeInt32(status);
1435 return NO_ERROR;
1436 } break;
Eric Laurent93c3d412014-08-01 14:48:35 -07001437 case GET_AUDIO_HW_SYNC: {
1438 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001439 reply->writeInt32(getAudioHwSyncForSession((audio_session_t) data.readInt32()));
Eric Laurent93c3d412014-08-01 14:48:35 -07001440 return NO_ERROR;
1441 } break;
Eric Laurent72e3f392015-05-20 14:43:50 -07001442 case SYSTEM_READY: {
1443 CHECK_INTERFACE(IAudioFlinger, data, reply);
1444 systemReady();
1445 return NO_ERROR;
1446 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001447 case FRAME_COUNT_HAL: {
1448 CHECK_INTERFACE(IAudioFlinger, data, reply);
1449 reply->writeInt64( frameCountHAL((audio_io_handle_t) data.readInt32()) );
1450 return NO_ERROR;
1451 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001452 default:
1453 return BBinder::onTransact(code, data, reply, flags);
1454 }
1455}
1456
1457// ----------------------------------------------------------------------------
1458
Glenn Kasten40bc9062015-03-20 09:09:33 -07001459} // namespace android