blob: 18a933ffb4fb72e0fd9c324011f324c7fbf9afdd [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,
84 SYSTEM_READY
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080085};
86
Eric Laurentf75c2fe2015-04-02 13:49:15 -070087#define MAX_ITEMS_PER_LIST 1024
88
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080089class BpAudioFlinger : public BpInterface<IAudioFlinger>
90{
91public:
92 BpAudioFlinger(const sp<IBinder>& impl)
93 : BpInterface<IAudioFlinger>(impl)
94 {
95 }
96
97 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080098 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080099 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800100 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -0700101 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -0800102 size_t *pFrameCount,
Glenn Kastene0b07172012-11-06 15:03:34 -0800103 track_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800104 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800105 audio_io_handle_t output,
Glenn Kasten3acbd052012-02-28 10:39:56 -0800106 pid_t tid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700107 int *sessionId,
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800108 int clientUid,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800109 status_t *status)
110 {
111 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700112 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800113 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800114 data.writeInt32((int32_t) streamType);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800115 data.writeInt32(sampleRate);
116 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700117 data.writeInt32(channelMask);
Glenn Kasten74935e42013-12-19 08:56:45 -0800118 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800119 data.writeInt64(frameCount);
Glenn Kastenb26e3e92012-11-14 08:32:08 -0800120 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
Glenn Kastene0b07172012-11-06 15:03:34 -0800121 data.writeInt32(lFlags);
Glenn Kasten2301acc2014-01-17 10:21:00 -0800122 // haveSharedBuffer
Eric Laurent3d00aa62013-09-24 09:53:27 -0700123 if (sharedBuffer != 0) {
124 data.writeInt32(true);
Marco Nelissen06b46062014-11-14 07:58:25 -0800125 data.writeStrongBinder(IInterface::asBinder(sharedBuffer));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700126 } else {
127 data.writeInt32(false);
128 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800129 data.writeInt32((int32_t) output);
Glenn Kasten3acbd052012-02-28 10:39:56 -0800130 data.writeInt32((int32_t) tid);
Glenn Kastenaea7ea02013-06-26 09:25:47 -0700131 int lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700132 if (sessionId != NULL) {
133 lSessionId = *sessionId;
134 }
135 data.writeInt32(lSessionId);
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800136 data.writeInt32(clientUid);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800137 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
138 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000139 ALOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700140 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700141 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800142 if (pFrameCount != NULL) {
143 *pFrameCount = frameCount;
144 }
Glenn Kastene0b07172012-11-06 15:03:34 -0800145 lFlags = reply.readInt32();
146 if (flags != NULL) {
147 *flags = lFlags;
148 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700149 lSessionId = reply.readInt32();
150 if (sessionId != NULL) {
151 *sessionId = lSessionId;
152 }
Eric Laurent5841db72009-09-09 05:16:08 -0700153 lStatus = reply.readInt32();
154 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
Glenn Kasten0cde0762014-01-16 15:06:36 -0800155 if (lStatus == NO_ERROR) {
156 if (track == 0) {
157 ALOGE("createTrack should have returned an IAudioTrack");
158 lStatus = UNKNOWN_ERROR;
159 }
160 } else {
161 if (track != 0) {
162 ALOGE("createTrack returned an IAudioTrack but with status %d", lStatus);
163 track.clear();
164 }
165 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800166 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700167 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800168 *status = lStatus;
169 }
Eric Laurent5841db72009-09-09 05:16:08 -0700170 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800171 }
172
173 virtual sp<IAudioRecord> openRecord(
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800174 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800175 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800176 audio_format_t format,
Glenn Kasten28b76b32012-07-03 17:24:41 -0700177 audio_channel_mask_t channelMask,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700178 const String16& opPackageName,
Glenn Kasten74935e42013-12-19 08:56:45 -0800179 size_t *pFrameCount,
Glenn Kasteneeca3262013-07-31 16:12:48 -0700180 track_flags_t *flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -0700181 pid_t tid,
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700182 int clientUid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700183 int *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700184 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700185 sp<IMemory>& cblk,
186 sp<IMemory>& buffers,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800187 status_t *status)
188 {
189 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700190 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800191 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800192 data.writeInt32((int32_t) input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800193 data.writeInt32(sampleRate);
194 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700195 data.writeInt32(channelMask);
Dianne Hackborneaa34702015-04-29 12:57:58 -0700196 data.writeString16(opPackageName);
Glenn Kasten74935e42013-12-19 08:56:45 -0800197 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800198 data.writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700199 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
200 data.writeInt32(lFlags);
Glenn Kasten1879fff2012-07-11 15:36:59 -0700201 data.writeInt32((int32_t) tid);
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700202 data.writeInt32((int32_t) clientUid);
Glenn Kastenaea7ea02013-06-26 09:25:47 -0700203 int lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700204 if (sessionId != NULL) {
205 lSessionId = *sessionId;
206 }
207 data.writeInt32(lSessionId);
Glenn Kasten74105912014-07-03 12:28:53 -0700208 data.writeInt64(notificationFrames != NULL ? *notificationFrames : 0);
Glenn Kastend776ac62014-05-07 09:16:09 -0700209 cblk.clear();
210 buffers.clear();
Eric Laurent5841db72009-09-09 05:16:08 -0700211 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
212 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000213 ALOGE("openRecord error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700214 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700215 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800216 if (pFrameCount != NULL) {
217 *pFrameCount = frameCount;
218 }
Glenn Kasteneeca3262013-07-31 16:12:48 -0700219 lFlags = reply.readInt32();
220 if (flags != NULL) {
221 *flags = lFlags;
222 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700223 lSessionId = reply.readInt32();
224 if (sessionId != NULL) {
225 *sessionId = lSessionId;
226 }
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700227 size_t lNotificationFrames = (size_t) reply.readInt64();
228 if (notificationFrames != NULL) {
229 *notificationFrames = lNotificationFrames;
230 }
Eric Laurent5841db72009-09-09 05:16:08 -0700231 lStatus = reply.readInt32();
232 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700233 cblk = interface_cast<IMemory>(reply.readStrongBinder());
234 if (cblk != 0 && cblk->pointer() == NULL) {
235 cblk.clear();
236 }
237 buffers = interface_cast<IMemory>(reply.readStrongBinder());
238 if (buffers != 0 && buffers->pointer() == NULL) {
239 buffers.clear();
240 }
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700241 if (lStatus == NO_ERROR) {
242 if (record == 0) {
243 ALOGE("openRecord should have returned an IAudioRecord");
244 lStatus = UNKNOWN_ERROR;
Glenn Kastend776ac62014-05-07 09:16:09 -0700245 } else if (cblk == 0) {
246 ALOGE("openRecord should have returned a cblk");
247 lStatus = NO_MEMORY;
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700248 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700249 // buffers is permitted to be 0
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700250 } else {
Glenn Kastend776ac62014-05-07 09:16:09 -0700251 if (record != 0 || cblk != 0 || buffers != 0) {
252 ALOGE("openRecord returned an IAudioRecord, cblk, "
253 "or buffers but with status %d", lStatus);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700254 }
255 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700256 if (lStatus != NO_ERROR) {
257 record.clear();
258 cblk.clear();
259 buffers.clear();
260 }
Eric Laurent5841db72009-09-09 05:16:08 -0700261 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700262 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800263 *status = lStatus;
264 }
Eric Laurent5841db72009-09-09 05:16:08 -0700265 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800266 }
267
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800268 virtual uint32_t sampleRate(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800269 {
270 Parcel data, reply;
271 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800272 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800273 remote()->transact(SAMPLE_RATE, data, &reply);
274 return reply.readInt32();
275 }
276
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800277 virtual audio_format_t format(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800278 {
279 Parcel data, reply;
280 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800281 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800282 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800283 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800284 }
285
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800286 virtual size_t frameCount(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800287 {
288 Parcel data, reply;
289 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800290 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800291 remote()->transact(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800292 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800293 }
294
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800295 virtual uint32_t latency(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800296 {
297 Parcel data, reply;
298 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800299 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800300 remote()->transact(LATENCY, data, &reply);
301 return reply.readInt32();
302 }
303
304 virtual status_t setMasterVolume(float value)
305 {
306 Parcel data, reply;
307 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
308 data.writeFloat(value);
309 remote()->transact(SET_MASTER_VOLUME, data, &reply);
310 return reply.readInt32();
311 }
312
313 virtual status_t setMasterMute(bool muted)
314 {
315 Parcel data, reply;
316 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
317 data.writeInt32(muted);
318 remote()->transact(SET_MASTER_MUTE, data, &reply);
319 return reply.readInt32();
320 }
321
322 virtual float masterVolume() const
323 {
324 Parcel data, reply;
325 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
326 remote()->transact(MASTER_VOLUME, data, &reply);
327 return reply.readFloat();
328 }
329
330 virtual bool masterMute() const
331 {
332 Parcel data, reply;
333 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
334 remote()->transact(MASTER_MUTE, data, &reply);
335 return reply.readInt32();
336 }
337
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800338 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
339 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800340 {
341 Parcel data, reply;
342 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800343 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800344 data.writeFloat(value);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800345 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800346 remote()->transact(SET_STREAM_VOLUME, data, &reply);
347 return reply.readInt32();
348 }
349
Glenn Kastenfff6d712012-01-12 16:38:12 -0800350 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800351 {
352 Parcel data, reply;
353 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800354 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800355 data.writeInt32(muted);
356 remote()->transact(SET_STREAM_MUTE, data, &reply);
357 return reply.readInt32();
358 }
359
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800360 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800361 {
362 Parcel data, reply;
363 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800364 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800365 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800366 remote()->transact(STREAM_VOLUME, data, &reply);
367 return reply.readFloat();
368 }
369
Glenn Kastenfff6d712012-01-12 16:38:12 -0800370 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800371 {
372 Parcel data, reply;
373 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800374 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800375 remote()->transact(STREAM_MUTE, data, &reply);
376 return reply.readInt32();
377 }
378
Glenn Kastenf78aee72012-01-04 11:00:47 -0800379 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800380 {
381 Parcel data, reply;
382 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
383 data.writeInt32(mode);
384 remote()->transact(SET_MODE, data, &reply);
385 return reply.readInt32();
386 }
387
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800388 virtual status_t setMicMute(bool state)
389 {
390 Parcel data, reply;
391 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
392 data.writeInt32(state);
393 remote()->transact(SET_MIC_MUTE, data, &reply);
394 return reply.readInt32();
395 }
396
397 virtual bool getMicMute() const
398 {
399 Parcel data, reply;
400 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
401 remote()->transact(GET_MIC_MUTE, data, &reply);
402 return reply.readInt32();
403 }
404
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800405 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800406 {
407 Parcel data, reply;
408 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800409 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700410 data.writeString8(keyValuePairs);
411 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800412 return reply.readInt32();
413 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700414
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800415 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700416 {
417 Parcel data, reply;
418 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800419 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700420 data.writeString8(keys);
421 remote()->transact(GET_PARAMETERS, data, &reply);
422 return reply.readString8();
423 }
424
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800425 virtual void registerClient(const sp<IAudioFlingerClient>& client)
426 {
427 Parcel data, reply;
428 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800429 data.writeStrongBinder(IInterface::asBinder(client));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800430 remote()->transact(REGISTER_CLIENT, data, &reply);
431 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700432
Glenn Kastendd8104c2012-07-02 12:42:44 -0700433 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
434 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800435 {
436 Parcel data, reply;
437 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
438 data.writeInt32(sampleRate);
439 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700440 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800441 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800442 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800443 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700444
Eric Laurentcf2c0212014-07-25 16:20:43 -0700445 virtual status_t openOutput(audio_module_handle_t module,
446 audio_io_handle_t *output,
447 audio_config_t *config,
448 audio_devices_t *devices,
449 const String8& address,
450 uint32_t *latencyMs,
451 audio_output_flags_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800452 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700453 if (output == NULL || config == NULL || devices == NULL || latencyMs == NULL) {
454 return BAD_VALUE;
455 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800456 Parcel data, reply;
457 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700458 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700459 data.write(config, sizeof(audio_config_t));
460 data.writeInt32(*devices);
461 data.writeString8(address);
Glenn Kasten18868c52012-03-07 09:15:37 -0800462 data.writeInt32((int32_t) flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700463 status_t status = remote()->transact(OPEN_OUTPUT, data, &reply);
464 if (status != NO_ERROR) {
465 *output = AUDIO_IO_HANDLE_NONE;
466 return status;
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100467 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700468 status = (status_t)reply.readInt32();
469 if (status != NO_ERROR) {
470 *output = AUDIO_IO_HANDLE_NONE;
471 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700472 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700473 *output = (audio_io_handle_t)reply.readInt32();
474 ALOGV("openOutput() returned output, %d", *output);
475 reply.read(config, sizeof(audio_config_t));
476 *devices = (audio_devices_t)reply.readInt32();
477 *latencyMs = reply.readInt32();
478 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800479 }
480
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800481 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
482 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800483 {
484 Parcel data, reply;
485 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800486 data.writeInt32((int32_t) output1);
487 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700488 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800489 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700490 }
491
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800492 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700493 {
494 Parcel data, reply;
495 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800496 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700497 remote()->transact(CLOSE_OUTPUT, data, &reply);
498 return reply.readInt32();
499 }
500
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800501 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700502 {
503 Parcel data, reply;
504 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800505 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700506 remote()->transact(SUSPEND_OUTPUT, data, &reply);
507 return reply.readInt32();
508 }
509
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800510 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700511 {
512 Parcel data, reply;
513 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800514 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700515 remote()->transact(RESTORE_OUTPUT, data, &reply);
516 return reply.readInt32();
517 }
518
Eric Laurentcf2c0212014-07-25 16:20:43 -0700519 virtual status_t openInput(audio_module_handle_t module,
520 audio_io_handle_t *input,
521 audio_config_t *config,
522 audio_devices_t *device,
523 const String8& address,
524 audio_source_t source,
525 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700526 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700527 if (input == NULL || config == NULL || device == NULL) {
528 return BAD_VALUE;
529 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700530 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700531 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700532 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700533 data.writeInt32(*input);
534 data.write(config, sizeof(audio_config_t));
535 data.writeInt32(*device);
536 data.writeString8(address);
537 data.writeInt32(source);
Glenn Kastenec40d282014-07-15 15:31:26 -0700538 data.writeInt32(flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700539 status_t status = remote()->transact(OPEN_INPUT, data, &reply);
540 if (status != NO_ERROR) {
541 *input = AUDIO_IO_HANDLE_NONE;
542 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700543 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700544 status = (status_t)reply.readInt32();
545 if (status != NO_ERROR) {
546 *input = AUDIO_IO_HANDLE_NONE;
547 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700548 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700549 *input = (audio_io_handle_t)reply.readInt32();
550 reply.read(config, sizeof(audio_config_t));
551 *device = (audio_devices_t)reply.readInt32();
552 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700553 }
554
Eric Laurentfa2877b2009-07-28 08:44:33 -0700555 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700556 {
557 Parcel data, reply;
558 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700559 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700560 remote()->transact(CLOSE_INPUT, data, &reply);
561 return reply.readInt32();
562 }
563
Glenn Kastend2304db2014-02-03 07:40:31 -0800564 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700565 {
566 Parcel data, reply;
567 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800568 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800569 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700570 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800571 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700572
573 virtual status_t setVoiceVolume(float volume)
574 {
575 Parcel data, reply;
576 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
577 data.writeFloat(volume);
578 remote()->transact(SET_VOICE_VOLUME, data, &reply);
579 return reply.readInt32();
580 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800581
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000582 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800583 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800584 {
585 Parcel data, reply;
586 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800587 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800588 remote()->transact(GET_RENDER_POSITION, data, &reply);
589 status_t status = reply.readInt32();
590 if (status == NO_ERROR) {
591 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700592 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800593 *halFrames = tmp;
594 }
595 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700596 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800597 *dspFrames = tmp;
598 }
599 }
600 return status;
601 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800602
Glenn Kasten5f972c02014-01-13 09:59:31 -0800603 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800604 {
605 Parcel data, reply;
606 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800607 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800608 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
609 if (status != NO_ERROR) {
610 return 0;
611 }
612 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800613 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700614
Eric Laurentde3f8392014-07-27 18:38:22 -0700615 virtual audio_unique_id_t newAudioUniqueId()
Eric Laurentbe916aa2010-06-01 23:49:17 -0700616 {
617 Parcel data, reply;
618 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
619 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
Eric Laurentde3f8392014-07-27 18:38:22 -0700620 audio_unique_id_t id = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700621 if (status == NO_ERROR) {
622 id = reply.readInt32();
623 }
624 return id;
625 }
626
Marco Nelissend457c972014-02-11 08:47:07 -0800627 virtual void acquireAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700628 {
629 Parcel data, reply;
630 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
631 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800632 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700633 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
634 }
635
Marco Nelissend457c972014-02-11 08:47:07 -0800636 virtual void releaseAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700637 {
638 Parcel data, reply;
639 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
640 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800641 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700642 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
643 }
644
Glenn Kastenf587ba52012-01-26 16:25:10 -0800645 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700646 {
647 Parcel data, reply;
648 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
649 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
650 if (status != NO_ERROR) {
651 return status;
652 }
653 status = reply.readInt32();
654 if (status != NO_ERROR) {
655 return status;
656 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800657 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700658 *numEffects = (uint32_t)reply.readInt32();
659 }
660 return NO_ERROR;
661 }
662
Glenn Kastenf587ba52012-01-26 16:25:10 -0800663 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700664 {
665 if (pDescriptor == NULL) {
666 return BAD_VALUE;
667 }
668 Parcel data, reply;
669 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700670 data.writeInt32(index);
671 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700672 if (status != NO_ERROR) {
673 return status;
674 }
675 status = reply.readInt32();
676 if (status != NO_ERROR) {
677 return status;
678 }
679 reply.read(pDescriptor, sizeof(effect_descriptor_t));
680 return NO_ERROR;
681 }
682
Glenn Kasten5e92a782012-01-30 07:40:52 -0800683 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800684 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700685 {
686 if (pUuid == NULL || pDescriptor == NULL) {
687 return BAD_VALUE;
688 }
689 Parcel data, reply;
690 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
691 data.write(pUuid, sizeof(effect_uuid_t));
692 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
693 if (status != NO_ERROR) {
694 return status;
695 }
696 status = reply.readInt32();
697 if (status != NO_ERROR) {
698 return status;
699 }
700 reply.read(pDescriptor, sizeof(effect_descriptor_t));
701 return NO_ERROR;
702 }
703
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800704 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700705 effect_descriptor_t *pDesc,
706 const sp<IEffectClient>& client,
707 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800708 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700709 int sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700710 const String16& opPackageName,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700711 status_t *status,
712 int *id,
713 int *enabled)
714 {
715 Parcel data, reply;
716 sp<IEffect> effect;
717
718 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700719 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700720 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700721 *status = BAD_VALUE;
722 }
723 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700724
725 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700726 data.write(pDesc, sizeof(effect_descriptor_t));
Marco Nelissen06b46062014-11-14 07:58:25 -0800727 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700728 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800729 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700730 data.writeInt32(sessionId);
Svet Ganovbe71aa22015-04-28 12:06:02 -0700731 data.writeString16(opPackageName);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700732
733 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
734 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000735 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700736 } else {
737 lStatus = reply.readInt32();
738 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700739 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700740 *id = tmp;
741 }
742 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800743 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700744 *enabled = tmp;
745 }
746 effect = interface_cast<IEffect>(reply.readStrongBinder());
747 reply.read(pDesc, sizeof(effect_descriptor_t));
748 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700749 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700750 *status = lStatus;
751 }
752
753 return effect;
754 }
Eric Laurentde070132010-07-13 04:45:46 -0700755
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800756 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
757 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700758 {
759 Parcel data, reply;
760 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
761 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800762 data.writeInt32((int32_t) srcOutput);
763 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700764 remote()->transact(MOVE_EFFECTS, data, &reply);
765 return reply.readInt32();
766 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700767
768 virtual audio_module_handle_t loadHwModule(const char *name)
769 {
770 Parcel data, reply;
771 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
772 data.writeCString(name);
773 remote()->transact(LOAD_HW_MODULE, data, &reply);
774 return (audio_module_handle_t) reply.readInt32();
775 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700776
Glenn Kasten3b16c762012-11-14 08:44:39 -0800777 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700778 {
779 Parcel data, reply;
780 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
781 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
782 return reply.readInt32();
783 }
784
Glenn Kastene33054e2012-11-14 12:54:39 -0800785 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700786 {
787 Parcel data, reply;
788 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
789 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800790 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700791 }
792
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700793 virtual status_t setLowRamDevice(bool isLowRamDevice)
794 {
795 Parcel data, reply;
796 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
797 data.writeInt32((int) isLowRamDevice);
798 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
799 return reply.readInt32();
800 }
Eric Laurent4b123402014-04-11 09:22:20 -0700801 virtual status_t listAudioPorts(unsigned int *num_ports,
802 struct audio_port *ports)
803 {
804 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
805 return BAD_VALUE;
806 }
807 Parcel data, reply;
808 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
809 data.writeInt32(*num_ports);
810 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
811 if (status != NO_ERROR ||
812 (status = (status_t)reply.readInt32()) != NO_ERROR) {
813 return status;
814 }
815 *num_ports = (unsigned int)reply.readInt32();
816 reply.read(ports, *num_ports * sizeof(struct audio_port));
817 return status;
818 }
819 virtual status_t getAudioPort(struct audio_port *port)
820 {
821 if (port == NULL) {
822 return BAD_VALUE;
823 }
824 Parcel data, reply;
825 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
826 data.write(port, sizeof(struct audio_port));
827 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
828 if (status != NO_ERROR ||
829 (status = (status_t)reply.readInt32()) != NO_ERROR) {
830 return status;
831 }
832 reply.read(port, sizeof(struct audio_port));
833 return status;
834 }
835 virtual status_t createAudioPatch(const struct audio_patch *patch,
836 audio_patch_handle_t *handle)
837 {
838 if (patch == NULL || handle == NULL) {
839 return BAD_VALUE;
840 }
841 Parcel data, reply;
842 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
843 data.write(patch, sizeof(struct audio_patch));
844 data.write(handle, sizeof(audio_patch_handle_t));
845 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
846 if (status != NO_ERROR ||
847 (status = (status_t)reply.readInt32()) != NO_ERROR) {
848 return status;
849 }
850 reply.read(handle, sizeof(audio_patch_handle_t));
851 return status;
852 }
853 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
854 {
855 Parcel data, reply;
856 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
857 data.write(&handle, sizeof(audio_patch_handle_t));
858 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
859 if (status != NO_ERROR) {
860 status = (status_t)reply.readInt32();
861 }
862 return status;
863 }
864 virtual status_t listAudioPatches(unsigned int *num_patches,
865 struct audio_patch *patches)
866 {
867 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
868 return BAD_VALUE;
869 }
870 Parcel data, reply;
871 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
872 data.writeInt32(*num_patches);
873 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
874 if (status != NO_ERROR ||
875 (status = (status_t)reply.readInt32()) != NO_ERROR) {
876 return status;
877 }
878 *num_patches = (unsigned int)reply.readInt32();
879 reply.read(patches, *num_patches * sizeof(struct audio_patch));
880 return status;
881 }
882 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
883 {
884 if (config == NULL) {
885 return BAD_VALUE;
886 }
887 Parcel data, reply;
888 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
889 data.write(config, sizeof(struct audio_port_config));
890 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
891 if (status != NO_ERROR) {
892 status = (status_t)reply.readInt32();
893 }
894 return status;
895 }
Eric Laurent93c3d412014-08-01 14:48:35 -0700896 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
897 {
898 Parcel data, reply;
899 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
900 data.writeInt32(sessionId);
901 status_t status = remote()->transact(GET_AUDIO_HW_SYNC, data, &reply);
902 if (status != NO_ERROR) {
903 return AUDIO_HW_SYNC_INVALID;
904 }
905 return (audio_hw_sync_t)reply.readInt32();
906 }
Eric Laurent72e3f392015-05-20 14:43:50 -0700907 virtual status_t systemReady()
908 {
909 Parcel data, reply;
910 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
911 return remote()->transact(SYSTEM_READY, data, &reply, IBinder::FLAG_ONEWAY);
912 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800913};
914
915IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
916
917// ----------------------------------------------------------------------
918
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800919status_t BnAudioFlinger::onTransact(
920 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
921{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700922 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800923 case CREATE_TRACK: {
924 CHECK_INTERFACE(IAudioFlinger, data, reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800925 int streamType = data.readInt32();
926 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800927 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700928 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800929 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800930 track_flags_t flags = (track_flags_t) data.readInt32();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700931 bool haveSharedBuffer = data.readInt32() != 0;
932 sp<IMemory> buffer;
933 if (haveSharedBuffer) {
934 buffer = interface_cast<IMemory>(data.readStrongBinder());
935 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800936 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kasten3acbd052012-02-28 10:39:56 -0800937 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700938 int sessionId = data.readInt32();
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800939 int clientUid = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800940 status_t status;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700941 sp<IAudioTrack> track;
942 if ((haveSharedBuffer && (buffer == 0)) ||
943 ((buffer != 0) && (buffer->pointer() == NULL))) {
944 ALOGW("CREATE_TRACK: cannot retrieve shared memory");
945 status = DEAD_OBJECT;
946 } else {
947 track = createTrack(
948 (audio_stream_type_t) streamType, sampleRate, format,
Glenn Kasten74935e42013-12-19 08:56:45 -0800949 channelMask, &frameCount, &flags, buffer, output, tid,
Glenn Kastenc5a17422014-03-13 14:59:59 -0700950 &sessionId, clientUid, &status);
Glenn Kasten0cde0762014-01-16 15:06:36 -0800951 LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700952 }
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700953 reply->writeInt64(frameCount);
Glenn Kastene0b07172012-11-06 15:03:34 -0800954 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700955 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800956 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800957 reply->writeStrongBinder(IInterface::asBinder(track));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800958 return NO_ERROR;
959 } break;
960 case OPEN_RECORD: {
961 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800962 audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800963 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800964 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700965 audio_channel_mask_t channelMask = data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -0700966 const String16& opPackageName = data.readString16();
Glenn Kastene03dd222014-01-28 11:04:39 -0800967 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800968 track_flags_t flags = (track_flags_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700969 pid_t tid = (pid_t) data.readInt32();
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700970 int clientUid = data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700971 int sessionId = data.readInt32();
Glenn Kasten74105912014-07-03 12:28:53 -0700972 size_t notificationFrames = data.readInt64();
Glenn Kastend776ac62014-05-07 09:16:09 -0700973 sp<IMemory> cblk;
974 sp<IMemory> buffers;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800975 status_t status;
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800976 sp<IAudioRecord> record = openRecord(input,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700977 sampleRate, format, channelMask, opPackageName, &frameCount, &flags, tid,
Jean-Michel Trivi4cb66832015-05-01 18:34:17 -0700978 clientUid, &sessionId, &notificationFrames, cblk, buffers, &status);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700979 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700980 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700981 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700982 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700983 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800984 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800985 reply->writeStrongBinder(IInterface::asBinder(record));
986 reply->writeStrongBinder(IInterface::asBinder(cblk));
987 reply->writeStrongBinder(IInterface::asBinder(buffers));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800988 return NO_ERROR;
989 } break;
990 case SAMPLE_RATE: {
991 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800992 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800993 return NO_ERROR;
994 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800995 case FORMAT: {
996 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800997 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800998 return NO_ERROR;
999 } break;
1000 case FRAME_COUNT: {
1001 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001002 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001003 return NO_ERROR;
1004 } break;
1005 case LATENCY: {
1006 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001007 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001008 return NO_ERROR;
1009 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001010 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001011 CHECK_INTERFACE(IAudioFlinger, data, reply);
1012 reply->writeInt32( setMasterVolume(data.readFloat()) );
1013 return NO_ERROR;
1014 } break;
1015 case SET_MASTER_MUTE: {
1016 CHECK_INTERFACE(IAudioFlinger, data, reply);
1017 reply->writeInt32( setMasterMute(data.readInt32()) );
1018 return NO_ERROR;
1019 } break;
1020 case MASTER_VOLUME: {
1021 CHECK_INTERFACE(IAudioFlinger, data, reply);
1022 reply->writeFloat( masterVolume() );
1023 return NO_ERROR;
1024 } break;
1025 case MASTER_MUTE: {
1026 CHECK_INTERFACE(IAudioFlinger, data, reply);
1027 reply->writeInt32( masterMute() );
1028 return NO_ERROR;
1029 } break;
1030 case SET_STREAM_VOLUME: {
1031 CHECK_INTERFACE(IAudioFlinger, data, reply);
1032 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001033 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001034 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001035 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001036 return NO_ERROR;
1037 } break;
1038 case SET_STREAM_MUTE: {
1039 CHECK_INTERFACE(IAudioFlinger, data, reply);
1040 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001041 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001042 return NO_ERROR;
1043 } break;
1044 case STREAM_VOLUME: {
1045 CHECK_INTERFACE(IAudioFlinger, data, reply);
1046 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001047 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001048 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001049 return NO_ERROR;
1050 } break;
1051 case STREAM_MUTE: {
1052 CHECK_INTERFACE(IAudioFlinger, data, reply);
1053 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001054 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001055 return NO_ERROR;
1056 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001057 case SET_MODE: {
1058 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001059 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001060 reply->writeInt32( setMode(mode) );
1061 return NO_ERROR;
1062 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001063 case SET_MIC_MUTE: {
1064 CHECK_INTERFACE(IAudioFlinger, data, reply);
1065 int state = data.readInt32();
1066 reply->writeInt32( setMicMute(state) );
1067 return NO_ERROR;
1068 } break;
1069 case GET_MIC_MUTE: {
1070 CHECK_INTERFACE(IAudioFlinger, data, reply);
1071 reply->writeInt32( getMicMute() );
1072 return NO_ERROR;
1073 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001074 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001075 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001076 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001077 String8 keyValuePairs(data.readString8());
1078 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001079 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001080 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001081 case GET_PARAMETERS: {
1082 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001083 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001084 String8 keys(data.readString8());
1085 reply->writeString8(getParameters(ioHandle, keys));
1086 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001087 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001088
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001089 case REGISTER_CLIENT: {
1090 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001091 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1092 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001093 registerClient(client);
1094 return NO_ERROR;
1095 } break;
1096 case GET_INPUTBUFFERSIZE: {
1097 CHECK_INTERFACE(IAudioFlinger, data, reply);
1098 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001099 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001100 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001101 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001102 return NO_ERROR;
1103 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001104 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001105 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001106 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001107 audio_config_t config = {};
1108 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1109 ALOGE("b/23905951");
1110 }
Eric Laurenta4c5a552012-03-29 10:12:40 -07001111 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001112 String8 address(data.readString8());
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001113 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001114 uint32_t latencyMs;
1115 audio_io_handle_t output;
1116 status_t status = openOutput(module, &output, &config,
1117 &devices, address, &latencyMs, flags);
Glenn Kasten70742962014-02-18 08:00:47 -08001118 ALOGV("OPEN_OUTPUT output, %d", output);
Eric Laurentcf2c0212014-07-25 16:20:43 -07001119 reply->writeInt32((int32_t)status);
1120 if (status == NO_ERROR) {
1121 reply->writeInt32((int32_t)output);
1122 reply->write(&config, sizeof(audio_config_t));
1123 reply->writeInt32(devices);
1124 reply->writeInt32(latencyMs);
1125 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001126 return NO_ERROR;
1127 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001128 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001129 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001130 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1131 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1132 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001133 return NO_ERROR;
1134 } break;
1135 case CLOSE_OUTPUT: {
1136 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001137 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001138 return NO_ERROR;
1139 } break;
1140 case SUSPEND_OUTPUT: {
1141 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001142 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001143 return NO_ERROR;
1144 } break;
1145 case RESTORE_OUTPUT: {
1146 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001147 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001148 return NO_ERROR;
1149 } break;
1150 case OPEN_INPUT: {
1151 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001152 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001153 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001154 audio_config_t config = {};
1155 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1156 ALOGE("b/23905951");
1157 }
Eric Laurentcf2c0212014-07-25 16:20:43 -07001158 audio_devices_t device = (audio_devices_t)data.readInt32();
1159 String8 address(data.readString8());
1160 audio_source_t source = (audio_source_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001161 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001162
Eric Laurentcf2c0212014-07-25 16:20:43 -07001163 status_t status = openInput(module, &input, &config,
1164 &device, address, source, flags);
1165 reply->writeInt32((int32_t) status);
1166 if (status == NO_ERROR) {
1167 reply->writeInt32((int32_t) input);
1168 reply->write(&config, sizeof(audio_config_t));
1169 reply->writeInt32(device);
1170 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001171 return NO_ERROR;
1172 } break;
1173 case CLOSE_INPUT: {
1174 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001175 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001176 return NO_ERROR;
1177 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001178 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001179 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001180 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1181 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001182 return NO_ERROR;
1183 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001184 case SET_VOICE_VOLUME: {
1185 CHECK_INTERFACE(IAudioFlinger, data, reply);
1186 float volume = data.readFloat();
1187 reply->writeInt32( setVoiceVolume(volume) );
1188 return NO_ERROR;
1189 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001190 case GET_RENDER_POSITION: {
1191 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001192 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001193 uint32_t halFrames;
1194 uint32_t dspFrames;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001195 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1196 reply->writeInt32(status);
1197 if (status == NO_ERROR) {
1198 reply->writeInt32(halFrames);
1199 reply->writeInt32(dspFrames);
1200 }
1201 return NO_ERROR;
1202 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001203 case GET_INPUT_FRAMES_LOST: {
1204 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001205 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001206 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001207 return NO_ERROR;
1208 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001209 case NEW_AUDIO_SESSION_ID: {
1210 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentde3f8392014-07-27 18:38:22 -07001211 reply->writeInt32(newAudioUniqueId());
Eric Laurentbe916aa2010-06-01 23:49:17 -07001212 return NO_ERROR;
1213 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001214 case ACQUIRE_AUDIO_SESSION_ID: {
1215 CHECK_INTERFACE(IAudioFlinger, data, reply);
1216 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001217 int pid = data.readInt32();
1218 acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001219 return NO_ERROR;
1220 } break;
1221 case RELEASE_AUDIO_SESSION_ID: {
1222 CHECK_INTERFACE(IAudioFlinger, data, reply);
1223 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001224 int pid = data.readInt32();
1225 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001226 return NO_ERROR;
1227 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001228 case QUERY_NUM_EFFECTS: {
1229 CHECK_INTERFACE(IAudioFlinger, data, reply);
1230 uint32_t numEffects;
1231 status_t status = queryNumberEffects(&numEffects);
1232 reply->writeInt32(status);
1233 if (status == NO_ERROR) {
1234 reply->writeInt32((int32_t)numEffects);
1235 }
1236 return NO_ERROR;
1237 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001238 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001239 CHECK_INTERFACE(IAudioFlinger, data, reply);
1240 effect_descriptor_t desc;
Eric Laurentffe9c252010-06-23 17:38:20 -07001241 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001242 reply->writeInt32(status);
1243 if (status == NO_ERROR) {
1244 reply->write(&desc, sizeof(effect_descriptor_t));
1245 }
1246 return NO_ERROR;
1247 }
1248 case GET_EFFECT_DESCRIPTOR: {
1249 CHECK_INTERFACE(IAudioFlinger, data, reply);
1250 effect_uuid_t uuid;
1251 data.read(&uuid, sizeof(effect_uuid_t));
1252 effect_descriptor_t desc;
1253 status_t status = getEffectDescriptor(&uuid, &desc);
1254 reply->writeInt32(status);
1255 if (status == NO_ERROR) {
1256 reply->write(&desc, sizeof(effect_descriptor_t));
1257 }
1258 return NO_ERROR;
1259 }
1260 case CREATE_EFFECT: {
1261 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001262 effect_descriptor_t desc = {};
1263 if (data.read(&desc, sizeof(effect_descriptor_t)) != NO_ERROR) {
1264 ALOGE("b/23905951");
1265 }
Eric Laurentbe916aa2010-06-01 23:49:17 -07001266 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1267 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001268 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -07001269 int sessionId = data.readInt32();
Svet Ganovbe71aa22015-04-28 12:06:02 -07001270 const String16 opPackageName = data.readString16();
Eric Laurentbe916aa2010-06-01 23:49:17 -07001271 status_t status;
1272 int id;
1273 int enabled;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001274
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001275 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Svet Ganovbe71aa22015-04-28 12:06:02 -07001276 opPackageName, &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001277 reply->writeInt32(status);
1278 reply->writeInt32(id);
1279 reply->writeInt32(enabled);
Marco Nelissen06b46062014-11-14 07:58:25 -08001280 reply->writeStrongBinder(IInterface::asBinder(effect));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001281 reply->write(&desc, sizeof(effect_descriptor_t));
1282 return NO_ERROR;
1283 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001284 case MOVE_EFFECTS: {
1285 CHECK_INTERFACE(IAudioFlinger, data, reply);
1286 int session = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001287 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1288 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001289 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1290 return NO_ERROR;
1291 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001292 case LOAD_HW_MODULE: {
1293 CHECK_INTERFACE(IAudioFlinger, data, reply);
1294 reply->writeInt32(loadHwModule(data.readCString()));
1295 return NO_ERROR;
1296 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001297 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1298 CHECK_INTERFACE(IAudioFlinger, data, reply);
1299 reply->writeInt32(getPrimaryOutputSamplingRate());
1300 return NO_ERROR;
1301 } break;
1302 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1303 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001304 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001305 return NO_ERROR;
1306 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001307 case SET_LOW_RAM_DEVICE: {
1308 CHECK_INTERFACE(IAudioFlinger, data, reply);
1309 bool isLowRamDevice = data.readInt32() != 0;
1310 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1311 return NO_ERROR;
1312 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001313 case LIST_AUDIO_PORTS: {
1314 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001315 unsigned int numPortsReq = data.readInt32();
1316 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1317 numPortsReq = MAX_ITEMS_PER_LIST;
1318 }
1319 unsigned int numPorts = numPortsReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001320 struct audio_port *ports =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001321 (struct audio_port *)calloc(numPortsReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001322 sizeof(struct audio_port));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001323 if (ports == NULL) {
1324 reply->writeInt32(NO_MEMORY);
1325 reply->writeInt32(0);
1326 return NO_ERROR;
1327 }
1328 status_t status = listAudioPorts(&numPorts, ports);
Eric Laurent4b123402014-04-11 09:22:20 -07001329 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001330 reply->writeInt32(numPorts);
Eric Laurent4b123402014-04-11 09:22:20 -07001331 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001332 if (numPortsReq > numPorts) {
1333 numPortsReq = numPorts;
1334 }
1335 reply->write(ports, numPortsReq * sizeof(struct audio_port));
Eric Laurent4b123402014-04-11 09:22:20 -07001336 }
1337 free(ports);
1338 return NO_ERROR;
1339 } break;
1340 case GET_AUDIO_PORT: {
1341 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001342 struct audio_port port = {};
1343 if (data.read(&port, sizeof(struct audio_port)) != NO_ERROR) {
1344 ALOGE("b/23905951");
1345 }
Eric Laurent4b123402014-04-11 09:22:20 -07001346 status_t status = getAudioPort(&port);
1347 reply->writeInt32(status);
1348 if (status == NO_ERROR) {
1349 reply->write(&port, sizeof(struct audio_port));
1350 }
1351 return NO_ERROR;
1352 } break;
1353 case CREATE_AUDIO_PATCH: {
1354 CHECK_INTERFACE(IAudioFlinger, data, reply);
1355 struct audio_patch patch;
1356 data.read(&patch, sizeof(struct audio_patch));
Wei Jiae995e472015-09-09 09:48:34 -07001357 audio_patch_handle_t handle = {};
1358 if (data.read(&handle, sizeof(audio_patch_handle_t)) != NO_ERROR) {
1359 ALOGE("b/23905951");
1360 }
Eric Laurent4b123402014-04-11 09:22:20 -07001361 status_t status = createAudioPatch(&patch, &handle);
1362 reply->writeInt32(status);
1363 if (status == NO_ERROR) {
1364 reply->write(&handle, sizeof(audio_patch_handle_t));
1365 }
1366 return NO_ERROR;
1367 } break;
1368 case RELEASE_AUDIO_PATCH: {
1369 CHECK_INTERFACE(IAudioFlinger, data, reply);
1370 audio_patch_handle_t handle;
1371 data.read(&handle, sizeof(audio_patch_handle_t));
1372 status_t status = releaseAudioPatch(handle);
1373 reply->writeInt32(status);
1374 return NO_ERROR;
1375 } break;
1376 case LIST_AUDIO_PATCHES: {
1377 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001378 unsigned int numPatchesReq = data.readInt32();
1379 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1380 numPatchesReq = MAX_ITEMS_PER_LIST;
1381 }
1382 unsigned int numPatches = numPatchesReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001383 struct audio_patch *patches =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001384 (struct audio_patch *)calloc(numPatchesReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001385 sizeof(struct audio_patch));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001386 if (patches == NULL) {
1387 reply->writeInt32(NO_MEMORY);
1388 reply->writeInt32(0);
1389 return NO_ERROR;
1390 }
1391 status_t status = listAudioPatches(&numPatches, patches);
Eric Laurent4b123402014-04-11 09:22:20 -07001392 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001393 reply->writeInt32(numPatches);
Eric Laurent4b123402014-04-11 09:22:20 -07001394 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001395 if (numPatchesReq > numPatches) {
1396 numPatchesReq = numPatches;
1397 }
1398 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
Eric Laurent4b123402014-04-11 09:22:20 -07001399 }
1400 free(patches);
1401 return NO_ERROR;
1402 } break;
1403 case SET_AUDIO_PORT_CONFIG: {
1404 CHECK_INTERFACE(IAudioFlinger, data, reply);
1405 struct audio_port_config config;
1406 data.read(&config, sizeof(struct audio_port_config));
1407 status_t status = setAudioPortConfig(&config);
1408 reply->writeInt32(status);
1409 return NO_ERROR;
1410 } break;
Eric Laurent93c3d412014-08-01 14:48:35 -07001411 case GET_AUDIO_HW_SYNC: {
1412 CHECK_INTERFACE(IAudioFlinger, data, reply);
1413 reply->writeInt32(getAudioHwSyncForSession((audio_session_t)data.readInt32()));
1414 return NO_ERROR;
1415 } break;
Eric Laurent72e3f392015-05-20 14:43:50 -07001416 case SYSTEM_READY: {
1417 CHECK_INTERFACE(IAudioFlinger, data, reply);
1418 systemReady();
1419 return NO_ERROR;
1420 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001421 default:
1422 return BBinder::onTransact(code, data, reply, flags);
1423 }
1424}
1425
1426// ----------------------------------------------------------------------------
1427
Glenn Kasten40bc9062015-03-20 09:09:33 -07001428} // namespace android