blob: 5cf42f7c4c12c61e99ccaa28d0afc3377ccdc9d6 [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,
82 SET_AUDIO_PORT_CONFIG
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080083};
84
85class BpAudioFlinger : public BpInterface<IAudioFlinger>
86{
87public:
88 BpAudioFlinger(const sp<IBinder>& impl)
89 : BpInterface<IAudioFlinger>(impl)
90 {
91 }
92
93 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080094 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080095 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080096 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -070097 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -080098 size_t *pFrameCount,
Glenn Kastene0b07172012-11-06 15:03:34 -080099 track_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800100 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800101 audio_io_handle_t output,
Glenn Kasten3acbd052012-02-28 10:39:56 -0800102 pid_t tid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700103 int *sessionId,
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800104 int clientUid,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800105 status_t *status)
106 {
107 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700108 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800109 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800110 data.writeInt32((int32_t) streamType);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800111 data.writeInt32(sampleRate);
112 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700113 data.writeInt32(channelMask);
Glenn Kasten74935e42013-12-19 08:56:45 -0800114 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800115 data.writeInt64(frameCount);
Glenn Kastenb26e3e92012-11-14 08:32:08 -0800116 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
Glenn Kastene0b07172012-11-06 15:03:34 -0800117 data.writeInt32(lFlags);
Glenn Kasten2301acc2014-01-17 10:21:00 -0800118 // haveSharedBuffer
Eric Laurent3d00aa62013-09-24 09:53:27 -0700119 if (sharedBuffer != 0) {
120 data.writeInt32(true);
121 data.writeStrongBinder(sharedBuffer->asBinder());
122 } else {
123 data.writeInt32(false);
124 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800125 data.writeInt32((int32_t) output);
Glenn Kasten3acbd052012-02-28 10:39:56 -0800126 data.writeInt32((int32_t) tid);
Glenn Kastenaea7ea02013-06-26 09:25:47 -0700127 int lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700128 if (sessionId != NULL) {
129 lSessionId = *sessionId;
130 }
131 data.writeInt32(lSessionId);
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800132 data.writeInt32(clientUid);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800133 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
134 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000135 ALOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700136 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700137 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800138 if (pFrameCount != NULL) {
139 *pFrameCount = frameCount;
140 }
Glenn Kastene0b07172012-11-06 15:03:34 -0800141 lFlags = reply.readInt32();
142 if (flags != NULL) {
143 *flags = lFlags;
144 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700145 lSessionId = reply.readInt32();
146 if (sessionId != NULL) {
147 *sessionId = lSessionId;
148 }
Eric Laurent5841db72009-09-09 05:16:08 -0700149 lStatus = reply.readInt32();
150 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
Glenn Kasten0cde0762014-01-16 15:06:36 -0800151 if (lStatus == NO_ERROR) {
152 if (track == 0) {
153 ALOGE("createTrack should have returned an IAudioTrack");
154 lStatus = UNKNOWN_ERROR;
155 }
156 } else {
157 if (track != 0) {
158 ALOGE("createTrack returned an IAudioTrack but with status %d", lStatus);
159 track.clear();
160 }
161 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800162 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700163 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800164 *status = lStatus;
165 }
Eric Laurent5841db72009-09-09 05:16:08 -0700166 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800167 }
168
169 virtual sp<IAudioRecord> openRecord(
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800170 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800171 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800172 audio_format_t format,
Glenn Kasten28b76b32012-07-03 17:24:41 -0700173 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -0800174 size_t *pFrameCount,
Glenn Kasteneeca3262013-07-31 16:12:48 -0700175 track_flags_t *flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -0700176 pid_t tid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700177 int *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700178 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700179 sp<IMemory>& cblk,
180 sp<IMemory>& buffers,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800181 status_t *status)
182 {
183 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700184 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800185 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800186 data.writeInt32((int32_t) input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800187 data.writeInt32(sampleRate);
188 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700189 data.writeInt32(channelMask);
Glenn Kasten74935e42013-12-19 08:56:45 -0800190 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800191 data.writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700192 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
193 data.writeInt32(lFlags);
Glenn Kasten1879fff2012-07-11 15:36:59 -0700194 data.writeInt32((int32_t) tid);
Glenn Kastenaea7ea02013-06-26 09:25:47 -0700195 int lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700196 if (sessionId != NULL) {
197 lSessionId = *sessionId;
198 }
199 data.writeInt32(lSessionId);
Glenn Kastend776ac62014-05-07 09:16:09 -0700200 cblk.clear();
201 buffers.clear();
Eric Laurent5841db72009-09-09 05:16:08 -0700202 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
203 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000204 ALOGE("openRecord error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700205 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700206 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800207 if (pFrameCount != NULL) {
208 *pFrameCount = frameCount;
209 }
Glenn Kasteneeca3262013-07-31 16:12:48 -0700210 lFlags = reply.readInt32();
211 if (flags != NULL) {
212 *flags = lFlags;
213 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700214 lSessionId = reply.readInt32();
215 if (sessionId != NULL) {
216 *sessionId = lSessionId;
217 }
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700218 size_t lNotificationFrames = (size_t) reply.readInt64();
219 if (notificationFrames != NULL) {
220 *notificationFrames = lNotificationFrames;
221 }
Eric Laurent5841db72009-09-09 05:16:08 -0700222 lStatus = reply.readInt32();
223 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700224 cblk = interface_cast<IMemory>(reply.readStrongBinder());
225 if (cblk != 0 && cblk->pointer() == NULL) {
226 cblk.clear();
227 }
228 buffers = interface_cast<IMemory>(reply.readStrongBinder());
229 if (buffers != 0 && buffers->pointer() == NULL) {
230 buffers.clear();
231 }
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700232 if (lStatus == NO_ERROR) {
233 if (record == 0) {
234 ALOGE("openRecord should have returned an IAudioRecord");
235 lStatus = UNKNOWN_ERROR;
Glenn Kastend776ac62014-05-07 09:16:09 -0700236 } else if (cblk == 0) {
237 ALOGE("openRecord should have returned a cblk");
238 lStatus = NO_MEMORY;
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700239 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700240 // buffers is permitted to be 0
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700241 } else {
Glenn Kastend776ac62014-05-07 09:16:09 -0700242 if (record != 0 || cblk != 0 || buffers != 0) {
243 ALOGE("openRecord returned an IAudioRecord, cblk, "
244 "or buffers but with status %d", lStatus);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700245 }
246 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700247 if (lStatus != NO_ERROR) {
248 record.clear();
249 cblk.clear();
250 buffers.clear();
251 }
Eric Laurent5841db72009-09-09 05:16:08 -0700252 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700253 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800254 *status = lStatus;
255 }
Eric Laurent5841db72009-09-09 05:16:08 -0700256 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800257 }
258
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800259 virtual uint32_t sampleRate(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800260 {
261 Parcel data, reply;
262 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800263 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800264 remote()->transact(SAMPLE_RATE, data, &reply);
265 return reply.readInt32();
266 }
267
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800268 virtual audio_format_t format(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(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800274 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800275 }
276
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800277 virtual size_t frameCount(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(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800283 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800284 }
285
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800286 virtual uint32_t latency(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(LATENCY, data, &reply);
292 return reply.readInt32();
293 }
294
295 virtual status_t setMasterVolume(float value)
296 {
297 Parcel data, reply;
298 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
299 data.writeFloat(value);
300 remote()->transact(SET_MASTER_VOLUME, data, &reply);
301 return reply.readInt32();
302 }
303
304 virtual status_t setMasterMute(bool muted)
305 {
306 Parcel data, reply;
307 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
308 data.writeInt32(muted);
309 remote()->transact(SET_MASTER_MUTE, data, &reply);
310 return reply.readInt32();
311 }
312
313 virtual float masterVolume() const
314 {
315 Parcel data, reply;
316 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
317 remote()->transact(MASTER_VOLUME, data, &reply);
318 return reply.readFloat();
319 }
320
321 virtual bool masterMute() const
322 {
323 Parcel data, reply;
324 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
325 remote()->transact(MASTER_MUTE, data, &reply);
326 return reply.readInt32();
327 }
328
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800329 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
330 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800331 {
332 Parcel data, reply;
333 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800334 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800335 data.writeFloat(value);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800336 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800337 remote()->transact(SET_STREAM_VOLUME, data, &reply);
338 return reply.readInt32();
339 }
340
Glenn Kastenfff6d712012-01-12 16:38:12 -0800341 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800342 {
343 Parcel data, reply;
344 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800345 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800346 data.writeInt32(muted);
347 remote()->transact(SET_STREAM_MUTE, data, &reply);
348 return reply.readInt32();
349 }
350
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800351 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800352 {
353 Parcel data, reply;
354 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800355 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800356 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800357 remote()->transact(STREAM_VOLUME, data, &reply);
358 return reply.readFloat();
359 }
360
Glenn Kastenfff6d712012-01-12 16:38:12 -0800361 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800362 {
363 Parcel data, reply;
364 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800365 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800366 remote()->transact(STREAM_MUTE, data, &reply);
367 return reply.readInt32();
368 }
369
Glenn Kastenf78aee72012-01-04 11:00:47 -0800370 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800371 {
372 Parcel data, reply;
373 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
374 data.writeInt32(mode);
375 remote()->transact(SET_MODE, data, &reply);
376 return reply.readInt32();
377 }
378
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800379 virtual status_t setMicMute(bool state)
380 {
381 Parcel data, reply;
382 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
383 data.writeInt32(state);
384 remote()->transact(SET_MIC_MUTE, data, &reply);
385 return reply.readInt32();
386 }
387
388 virtual bool getMicMute() const
389 {
390 Parcel data, reply;
391 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
392 remote()->transact(GET_MIC_MUTE, data, &reply);
393 return reply.readInt32();
394 }
395
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800396 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800397 {
398 Parcel data, reply;
399 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800400 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700401 data.writeString8(keyValuePairs);
402 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800403 return reply.readInt32();
404 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700405
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800406 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700407 {
408 Parcel data, reply;
409 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800410 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700411 data.writeString8(keys);
412 remote()->transact(GET_PARAMETERS, data, &reply);
413 return reply.readString8();
414 }
415
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800416 virtual void registerClient(const sp<IAudioFlingerClient>& client)
417 {
418 Parcel data, reply;
419 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
420 data.writeStrongBinder(client->asBinder());
421 remote()->transact(REGISTER_CLIENT, data, &reply);
422 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700423
Glenn Kastendd8104c2012-07-02 12:42:44 -0700424 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
425 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800426 {
427 Parcel data, reply;
428 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
429 data.writeInt32(sampleRate);
430 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700431 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800432 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800433 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800434 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700435
Eric Laurenta4c5a552012-03-29 10:12:40 -0700436 virtual audio_io_handle_t openOutput(audio_module_handle_t module,
437 audio_devices_t *pDevices,
438 uint32_t *pSamplingRate,
439 audio_format_t *pFormat,
440 audio_channel_mask_t *pChannelMask,
441 uint32_t *pLatencyMs,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000442 audio_output_flags_t flags,
443 const audio_offload_info_t *offloadInfo)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800444 {
445 Parcel data, reply;
Glenn Kasten45faf7e2014-01-17 10:23:01 -0800446 audio_devices_t devices = pDevices != NULL ? *pDevices : AUDIO_DEVICE_NONE;
Glenn Kasten7c5977f2013-07-02 14:17:22 -0700447 uint32_t samplingRate = pSamplingRate != NULL ? *pSamplingRate : 0;
448 audio_format_t format = pFormat != NULL ? *pFormat : AUDIO_FORMAT_DEFAULT;
449 audio_channel_mask_t channelMask = pChannelMask != NULL ?
450 *pChannelMask : (audio_channel_mask_t)0;
451 uint32_t latency = pLatencyMs != NULL ? *pLatencyMs : 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800452 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700453 data.writeInt32(module);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700454 data.writeInt32(devices);
455 data.writeInt32(samplingRate);
456 data.writeInt32(format);
Eric Laurenta4c5a552012-03-29 10:12:40 -0700457 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700458 data.writeInt32(latency);
Glenn Kasten18868c52012-03-07 09:15:37 -0800459 data.writeInt32((int32_t) flags);
Glenn Kasten2301acc2014-01-17 10:21:00 -0800460 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100461 if (offloadInfo == NULL) {
462 data.writeInt32(0);
463 } else {
464 data.writeInt32(1);
465 data.write(offloadInfo, sizeof(audio_offload_info_t));
466 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700467 remote()->transact(OPEN_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800468 audio_io_handle_t output = (audio_io_handle_t) reply.readInt32();
469 ALOGV("openOutput() returned output, %d", output);
Eric Laurenta4c5a552012-03-29 10:12:40 -0700470 devices = (audio_devices_t)reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700471 if (pDevices != NULL) {
472 *pDevices = devices;
473 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700474 samplingRate = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700475 if (pSamplingRate != NULL) {
476 *pSamplingRate = samplingRate;
477 }
Glenn Kasten58f30212012-01-12 12:27:51 -0800478 format = (audio_format_t) reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700479 if (pFormat != NULL) {
480 *pFormat = format;
481 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700482 channelMask = (audio_channel_mask_t)reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700483 if (pChannelMask != NULL) {
484 *pChannelMask = channelMask;
485 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700486 latency = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700487 if (pLatencyMs != NULL) {
488 *pLatencyMs = latency;
489 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700490 return output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800491 }
492
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800493 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
494 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800495 {
496 Parcel data, reply;
497 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800498 data.writeInt32((int32_t) output1);
499 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700500 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800501 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700502 }
503
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800504 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700505 {
506 Parcel data, reply;
507 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800508 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700509 remote()->transact(CLOSE_OUTPUT, data, &reply);
510 return reply.readInt32();
511 }
512
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800513 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700514 {
515 Parcel data, reply;
516 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800517 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700518 remote()->transact(SUSPEND_OUTPUT, data, &reply);
519 return reply.readInt32();
520 }
521
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800522 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700523 {
524 Parcel data, reply;
525 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800526 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700527 remote()->transact(RESTORE_OUTPUT, data, &reply);
528 return reply.readInt32();
529 }
530
Eric Laurenta4c5a552012-03-29 10:12:40 -0700531 virtual audio_io_handle_t openInput(audio_module_handle_t module,
532 audio_devices_t *pDevices,
533 uint32_t *pSamplingRate,
534 audio_format_t *pFormat,
535 audio_channel_mask_t *pChannelMask)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700536 {
537 Parcel data, reply;
Glenn Kasten45faf7e2014-01-17 10:23:01 -0800538 audio_devices_t devices = pDevices != NULL ? *pDevices : AUDIO_DEVICE_NONE;
Glenn Kasten7c5977f2013-07-02 14:17:22 -0700539 uint32_t samplingRate = pSamplingRate != NULL ? *pSamplingRate : 0;
540 audio_format_t format = pFormat != NULL ? *pFormat : AUDIO_FORMAT_DEFAULT;
541 audio_channel_mask_t channelMask = pChannelMask != NULL ?
542 *pChannelMask : (audio_channel_mask_t)0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700543
544 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700545 data.writeInt32(module);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700546 data.writeInt32(devices);
547 data.writeInt32(samplingRate);
548 data.writeInt32(format);
Eric Laurenta4c5a552012-03-29 10:12:40 -0700549 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700550 remote()->transact(OPEN_INPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800551 audio_io_handle_t input = (audio_io_handle_t) reply.readInt32();
Eric Laurenta4c5a552012-03-29 10:12:40 -0700552 devices = (audio_devices_t)reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700553 if (pDevices != NULL) {
554 *pDevices = devices;
555 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700556 samplingRate = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700557 if (pSamplingRate != NULL) {
558 *pSamplingRate = samplingRate;
559 }
Glenn Kasten58f30212012-01-12 12:27:51 -0800560 format = (audio_format_t) reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700561 if (pFormat != NULL) {
562 *pFormat = format;
563 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700564 channelMask = (audio_channel_mask_t)reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700565 if (pChannelMask != NULL) {
566 *pChannelMask = channelMask;
567 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700568 return input;
569 }
570
Eric Laurentfa2877b2009-07-28 08:44:33 -0700571 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700572 {
573 Parcel data, reply;
574 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700575 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700576 remote()->transact(CLOSE_INPUT, data, &reply);
577 return reply.readInt32();
578 }
579
Glenn Kastend2304db2014-02-03 07:40:31 -0800580 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700581 {
582 Parcel data, reply;
583 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800584 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800585 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700586 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800587 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700588
589 virtual status_t setVoiceVolume(float volume)
590 {
591 Parcel data, reply;
592 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
593 data.writeFloat(volume);
594 remote()->transact(SET_VOICE_VOLUME, data, &reply);
595 return reply.readInt32();
596 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800597
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000598 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800599 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800600 {
601 Parcel data, reply;
602 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800603 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800604 remote()->transact(GET_RENDER_POSITION, data, &reply);
605 status_t status = reply.readInt32();
606 if (status == NO_ERROR) {
607 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700608 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800609 *halFrames = tmp;
610 }
611 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700612 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800613 *dspFrames = tmp;
614 }
615 }
616 return status;
617 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800618
Glenn Kasten5f972c02014-01-13 09:59:31 -0800619 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800620 {
621 Parcel data, reply;
622 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800623 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800624 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
625 if (status != NO_ERROR) {
626 return 0;
627 }
628 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800629 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700630
631 virtual int newAudioSessionId()
632 {
633 Parcel data, reply;
634 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
635 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
Glenn Kasten85d109a2014-01-17 10:25:08 -0800636 int id = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700637 if (status == NO_ERROR) {
638 id = reply.readInt32();
639 }
640 return id;
641 }
642
Marco Nelissend457c972014-02-11 08:47:07 -0800643 virtual void acquireAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700644 {
645 Parcel data, reply;
646 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
647 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800648 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700649 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
650 }
651
Marco Nelissend457c972014-02-11 08:47:07 -0800652 virtual void releaseAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700653 {
654 Parcel data, reply;
655 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
656 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800657 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700658 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
659 }
660
Glenn Kastenf587ba52012-01-26 16:25:10 -0800661 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700662 {
663 Parcel data, reply;
664 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
665 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
666 if (status != NO_ERROR) {
667 return status;
668 }
669 status = reply.readInt32();
670 if (status != NO_ERROR) {
671 return status;
672 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800673 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700674 *numEffects = (uint32_t)reply.readInt32();
675 }
676 return NO_ERROR;
677 }
678
Glenn Kastenf587ba52012-01-26 16:25:10 -0800679 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700680 {
681 if (pDescriptor == NULL) {
682 return BAD_VALUE;
683 }
684 Parcel data, reply;
685 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700686 data.writeInt32(index);
687 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700688 if (status != NO_ERROR) {
689 return status;
690 }
691 status = reply.readInt32();
692 if (status != NO_ERROR) {
693 return status;
694 }
695 reply.read(pDescriptor, sizeof(effect_descriptor_t));
696 return NO_ERROR;
697 }
698
Glenn Kasten5e92a782012-01-30 07:40:52 -0800699 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800700 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700701 {
702 if (pUuid == NULL || pDescriptor == NULL) {
703 return BAD_VALUE;
704 }
705 Parcel data, reply;
706 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
707 data.write(pUuid, sizeof(effect_uuid_t));
708 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
709 if (status != NO_ERROR) {
710 return status;
711 }
712 status = reply.readInt32();
713 if (status != NO_ERROR) {
714 return status;
715 }
716 reply.read(pDescriptor, sizeof(effect_descriptor_t));
717 return NO_ERROR;
718 }
719
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800720 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700721 effect_descriptor_t *pDesc,
722 const sp<IEffectClient>& client,
723 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800724 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700725 int sessionId,
726 status_t *status,
727 int *id,
728 int *enabled)
729 {
730 Parcel data, reply;
731 sp<IEffect> effect;
732
733 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700734 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700735 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700736 *status = BAD_VALUE;
737 }
738 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700739
740 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700741 data.write(pDesc, sizeof(effect_descriptor_t));
742 data.writeStrongBinder(client->asBinder());
743 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800744 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700745 data.writeInt32(sessionId);
746
747 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
748 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000749 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700750 } else {
751 lStatus = reply.readInt32();
752 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700753 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700754 *id = tmp;
755 }
756 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800757 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700758 *enabled = tmp;
759 }
760 effect = interface_cast<IEffect>(reply.readStrongBinder());
761 reply.read(pDesc, sizeof(effect_descriptor_t));
762 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700763 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700764 *status = lStatus;
765 }
766
767 return effect;
768 }
Eric Laurentde070132010-07-13 04:45:46 -0700769
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800770 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
771 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700772 {
773 Parcel data, reply;
774 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
775 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800776 data.writeInt32((int32_t) srcOutput);
777 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700778 remote()->transact(MOVE_EFFECTS, data, &reply);
779 return reply.readInt32();
780 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700781
782 virtual audio_module_handle_t loadHwModule(const char *name)
783 {
784 Parcel data, reply;
785 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
786 data.writeCString(name);
787 remote()->transact(LOAD_HW_MODULE, data, &reply);
788 return (audio_module_handle_t) reply.readInt32();
789 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700790
Glenn Kasten3b16c762012-11-14 08:44:39 -0800791 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700792 {
793 Parcel data, reply;
794 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
795 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
796 return reply.readInt32();
797 }
798
Glenn Kastene33054e2012-11-14 12:54:39 -0800799 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700800 {
801 Parcel data, reply;
802 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
803 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800804 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700805 }
806
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700807 virtual status_t setLowRamDevice(bool isLowRamDevice)
808 {
809 Parcel data, reply;
810 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
811 data.writeInt32((int) isLowRamDevice);
812 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
813 return reply.readInt32();
814 }
Eric Laurent4b123402014-04-11 09:22:20 -0700815 virtual status_t listAudioPorts(unsigned int *num_ports,
816 struct audio_port *ports)
817 {
818 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
819 return BAD_VALUE;
820 }
821 Parcel data, reply;
822 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
823 data.writeInt32(*num_ports);
824 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
825 if (status != NO_ERROR ||
826 (status = (status_t)reply.readInt32()) != NO_ERROR) {
827 return status;
828 }
829 *num_ports = (unsigned int)reply.readInt32();
830 reply.read(ports, *num_ports * sizeof(struct audio_port));
831 return status;
832 }
833 virtual status_t getAudioPort(struct audio_port *port)
834 {
835 if (port == NULL) {
836 return BAD_VALUE;
837 }
838 Parcel data, reply;
839 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
840 data.write(port, sizeof(struct audio_port));
841 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
842 if (status != NO_ERROR ||
843 (status = (status_t)reply.readInt32()) != NO_ERROR) {
844 return status;
845 }
846 reply.read(port, sizeof(struct audio_port));
847 return status;
848 }
849 virtual status_t createAudioPatch(const struct audio_patch *patch,
850 audio_patch_handle_t *handle)
851 {
852 if (patch == NULL || handle == NULL) {
853 return BAD_VALUE;
854 }
855 Parcel data, reply;
856 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
857 data.write(patch, sizeof(struct audio_patch));
858 data.write(handle, sizeof(audio_patch_handle_t));
859 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
860 if (status != NO_ERROR ||
861 (status = (status_t)reply.readInt32()) != NO_ERROR) {
862 return status;
863 }
864 reply.read(handle, sizeof(audio_patch_handle_t));
865 return status;
866 }
867 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
868 {
869 Parcel data, reply;
870 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
871 data.write(&handle, sizeof(audio_patch_handle_t));
872 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
873 if (status != NO_ERROR) {
874 status = (status_t)reply.readInt32();
875 }
876 return status;
877 }
878 virtual status_t listAudioPatches(unsigned int *num_patches,
879 struct audio_patch *patches)
880 {
881 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
882 return BAD_VALUE;
883 }
884 Parcel data, reply;
885 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
886 data.writeInt32(*num_patches);
887 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
888 if (status != NO_ERROR ||
889 (status = (status_t)reply.readInt32()) != NO_ERROR) {
890 return status;
891 }
892 *num_patches = (unsigned int)reply.readInt32();
893 reply.read(patches, *num_patches * sizeof(struct audio_patch));
894 return status;
895 }
896 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
897 {
898 if (config == NULL) {
899 return BAD_VALUE;
900 }
901 Parcel data, reply;
902 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
903 data.write(config, sizeof(struct audio_port_config));
904 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
905 if (status != NO_ERROR) {
906 status = (status_t)reply.readInt32();
907 }
908 return status;
909 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800910};
911
912IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
913
914// ----------------------------------------------------------------------
915
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800916status_t BnAudioFlinger::onTransact(
917 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
918{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700919 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800920 case CREATE_TRACK: {
921 CHECK_INTERFACE(IAudioFlinger, data, reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800922 int streamType = data.readInt32();
923 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800924 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700925 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800926 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800927 track_flags_t flags = (track_flags_t) data.readInt32();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700928 bool haveSharedBuffer = data.readInt32() != 0;
929 sp<IMemory> buffer;
930 if (haveSharedBuffer) {
931 buffer = interface_cast<IMemory>(data.readStrongBinder());
932 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800933 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kasten3acbd052012-02-28 10:39:56 -0800934 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700935 int sessionId = data.readInt32();
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800936 int clientUid = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800937 status_t status;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700938 sp<IAudioTrack> track;
939 if ((haveSharedBuffer && (buffer == 0)) ||
940 ((buffer != 0) && (buffer->pointer() == NULL))) {
941 ALOGW("CREATE_TRACK: cannot retrieve shared memory");
942 status = DEAD_OBJECT;
943 } else {
944 track = createTrack(
945 (audio_stream_type_t) streamType, sampleRate, format,
Glenn Kasten74935e42013-12-19 08:56:45 -0800946 channelMask, &frameCount, &flags, buffer, output, tid,
Glenn Kastenc5a17422014-03-13 14:59:59 -0700947 &sessionId, clientUid, &status);
Glenn Kasten0cde0762014-01-16 15:06:36 -0800948 LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700949 }
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700950 reply->writeInt64(frameCount);
Glenn Kastene0b07172012-11-06 15:03:34 -0800951 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700952 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800953 reply->writeInt32(status);
954 reply->writeStrongBinder(track->asBinder());
955 return NO_ERROR;
956 } break;
957 case OPEN_RECORD: {
958 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800959 audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800960 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800961 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700962 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800963 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800964 track_flags_t flags = (track_flags_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700965 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700966 int sessionId = data.readInt32();
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700967 size_t notificationFrames = 0;
Glenn Kastend776ac62014-05-07 09:16:09 -0700968 sp<IMemory> cblk;
969 sp<IMemory> buffers;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800970 status_t status;
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800971 sp<IAudioRecord> record = openRecord(input,
Glenn Kastend776ac62014-05-07 09:16:09 -0700972 sampleRate, format, channelMask, &frameCount, &flags, tid, &sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700973 &notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700974 cblk, buffers, &status);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700975 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700976 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700977 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700978 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700979 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800980 reply->writeInt32(status);
981 reply->writeStrongBinder(record->asBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700982 reply->writeStrongBinder(cblk->asBinder());
983 reply->writeStrongBinder(buffers->asBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800984 return NO_ERROR;
985 } break;
986 case SAMPLE_RATE: {
987 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800988 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800989 return NO_ERROR;
990 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800991 case FORMAT: {
992 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800993 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800994 return NO_ERROR;
995 } break;
996 case FRAME_COUNT: {
997 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800998 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800999 return NO_ERROR;
1000 } break;
1001 case LATENCY: {
1002 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001003 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001004 return NO_ERROR;
1005 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001006 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001007 CHECK_INTERFACE(IAudioFlinger, data, reply);
1008 reply->writeInt32( setMasterVolume(data.readFloat()) );
1009 return NO_ERROR;
1010 } break;
1011 case SET_MASTER_MUTE: {
1012 CHECK_INTERFACE(IAudioFlinger, data, reply);
1013 reply->writeInt32( setMasterMute(data.readInt32()) );
1014 return NO_ERROR;
1015 } break;
1016 case MASTER_VOLUME: {
1017 CHECK_INTERFACE(IAudioFlinger, data, reply);
1018 reply->writeFloat( masterVolume() );
1019 return NO_ERROR;
1020 } break;
1021 case MASTER_MUTE: {
1022 CHECK_INTERFACE(IAudioFlinger, data, reply);
1023 reply->writeInt32( masterMute() );
1024 return NO_ERROR;
1025 } break;
1026 case SET_STREAM_VOLUME: {
1027 CHECK_INTERFACE(IAudioFlinger, data, reply);
1028 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001029 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001030 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001031 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001032 return NO_ERROR;
1033 } break;
1034 case SET_STREAM_MUTE: {
1035 CHECK_INTERFACE(IAudioFlinger, data, reply);
1036 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001037 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001038 return NO_ERROR;
1039 } break;
1040 case STREAM_VOLUME: {
1041 CHECK_INTERFACE(IAudioFlinger, data, reply);
1042 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001043 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001044 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001045 return NO_ERROR;
1046 } break;
1047 case STREAM_MUTE: {
1048 CHECK_INTERFACE(IAudioFlinger, data, reply);
1049 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001050 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001051 return NO_ERROR;
1052 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001053 case SET_MODE: {
1054 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001055 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001056 reply->writeInt32( setMode(mode) );
1057 return NO_ERROR;
1058 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001059 case SET_MIC_MUTE: {
1060 CHECK_INTERFACE(IAudioFlinger, data, reply);
1061 int state = data.readInt32();
1062 reply->writeInt32( setMicMute(state) );
1063 return NO_ERROR;
1064 } break;
1065 case GET_MIC_MUTE: {
1066 CHECK_INTERFACE(IAudioFlinger, data, reply);
1067 reply->writeInt32( getMicMute() );
1068 return NO_ERROR;
1069 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001070 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001071 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001072 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001073 String8 keyValuePairs(data.readString8());
1074 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001075 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001076 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001077 case GET_PARAMETERS: {
1078 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001079 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001080 String8 keys(data.readString8());
1081 reply->writeString8(getParameters(ioHandle, keys));
1082 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001083 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001084
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001085 case REGISTER_CLIENT: {
1086 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001087 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1088 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001089 registerClient(client);
1090 return NO_ERROR;
1091 } break;
1092 case GET_INPUTBUFFERSIZE: {
1093 CHECK_INTERFACE(IAudioFlinger, data, reply);
1094 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001095 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001096 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001097 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001098 return NO_ERROR;
1099 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001100 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001101 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001102 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
1103 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001104 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001105 audio_format_t format = (audio_format_t) data.readInt32();
Eric Laurenta4c5a552012-03-29 10:12:40 -07001106 audio_channel_mask_t channelMask = (audio_channel_mask_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001107 uint32_t latency = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001108 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001109 bool hasOffloadInfo = data.readInt32() != 0;
1110 audio_offload_info_t offloadInfo;
1111 if (hasOffloadInfo) {
1112 data.read(&offloadInfo, sizeof(audio_offload_info_t));
1113 }
Eric Laurenta4c5a552012-03-29 10:12:40 -07001114 audio_io_handle_t output = openOutput(module,
1115 &devices,
1116 &samplingRate,
1117 &format,
1118 &channelMask,
1119 &latency,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001120 flags,
1121 hasOffloadInfo ? &offloadInfo : NULL);
Glenn Kasten70742962014-02-18 08:00:47 -08001122 ALOGV("OPEN_OUTPUT output, %d", output);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001123 reply->writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001124 reply->writeInt32(devices);
1125 reply->writeInt32(samplingRate);
1126 reply->writeInt32(format);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001127 reply->writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001128 reply->writeInt32(latency);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001129 return NO_ERROR;
1130 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001131 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001132 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001133 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1134 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1135 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001136 return NO_ERROR;
1137 } break;
1138 case CLOSE_OUTPUT: {
1139 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001140 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001141 return NO_ERROR;
1142 } break;
1143 case SUSPEND_OUTPUT: {
1144 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001145 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001146 return NO_ERROR;
1147 } break;
1148 case RESTORE_OUTPUT: {
1149 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001150 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001151 return NO_ERROR;
1152 } break;
1153 case OPEN_INPUT: {
1154 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001155 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
1156 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001157 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001158 audio_format_t format = (audio_format_t) data.readInt32();
Eric Laurenta4c5a552012-03-29 10:12:40 -07001159 audio_channel_mask_t channelMask = (audio_channel_mask_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001160
Eric Laurenta4c5a552012-03-29 10:12:40 -07001161 audio_io_handle_t input = openInput(module,
1162 &devices,
1163 &samplingRate,
1164 &format,
1165 &channelMask);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001166 reply->writeInt32((int32_t) input);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001167 reply->writeInt32(devices);
1168 reply->writeInt32(samplingRate);
1169 reply->writeInt32(format);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001170 reply->writeInt32(channelMask);
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);
1211 reply->writeInt32(newAudioSessionId());
1212 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);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001262 effect_descriptor_t desc;
1263 data.read(&desc, sizeof(effect_descriptor_t));
1264 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1265 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001266 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -07001267 int sessionId = data.readInt32();
1268 status_t status;
1269 int id;
1270 int enabled;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001271
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001272 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001273 &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001274 reply->writeInt32(status);
1275 reply->writeInt32(id);
1276 reply->writeInt32(enabled);
1277 reply->writeStrongBinder(effect->asBinder());
1278 reply->write(&desc, sizeof(effect_descriptor_t));
1279 return NO_ERROR;
1280 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001281 case MOVE_EFFECTS: {
1282 CHECK_INTERFACE(IAudioFlinger, data, reply);
1283 int session = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001284 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1285 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001286 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1287 return NO_ERROR;
1288 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001289 case LOAD_HW_MODULE: {
1290 CHECK_INTERFACE(IAudioFlinger, data, reply);
1291 reply->writeInt32(loadHwModule(data.readCString()));
1292 return NO_ERROR;
1293 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001294 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1295 CHECK_INTERFACE(IAudioFlinger, data, reply);
1296 reply->writeInt32(getPrimaryOutputSamplingRate());
1297 return NO_ERROR;
1298 } break;
1299 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1300 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001301 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001302 return NO_ERROR;
1303 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001304 case SET_LOW_RAM_DEVICE: {
1305 CHECK_INTERFACE(IAudioFlinger, data, reply);
1306 bool isLowRamDevice = data.readInt32() != 0;
1307 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1308 return NO_ERROR;
1309 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001310 case LIST_AUDIO_PORTS: {
1311 CHECK_INTERFACE(IAudioFlinger, data, reply);
1312 unsigned int num_ports = data.readInt32();
1313 struct audio_port *ports =
1314 (struct audio_port *)calloc(num_ports,
1315 sizeof(struct audio_port));
1316 status_t status = listAudioPorts(&num_ports, ports);
1317 reply->writeInt32(status);
1318 if (status == NO_ERROR) {
1319 reply->writeInt32(num_ports);
1320 reply->write(&ports, num_ports * sizeof(struct audio_port));
1321 }
1322 free(ports);
1323 return NO_ERROR;
1324 } break;
1325 case GET_AUDIO_PORT: {
1326 CHECK_INTERFACE(IAudioFlinger, data, reply);
1327 struct audio_port port;
1328 data.read(&port, sizeof(struct audio_port));
1329 status_t status = getAudioPort(&port);
1330 reply->writeInt32(status);
1331 if (status == NO_ERROR) {
1332 reply->write(&port, sizeof(struct audio_port));
1333 }
1334 return NO_ERROR;
1335 } break;
1336 case CREATE_AUDIO_PATCH: {
1337 CHECK_INTERFACE(IAudioFlinger, data, reply);
1338 struct audio_patch patch;
1339 data.read(&patch, sizeof(struct audio_patch));
1340 audio_patch_handle_t handle;
1341 data.read(&handle, sizeof(audio_patch_handle_t));
1342 status_t status = createAudioPatch(&patch, &handle);
1343 reply->writeInt32(status);
1344 if (status == NO_ERROR) {
1345 reply->write(&handle, sizeof(audio_patch_handle_t));
1346 }
1347 return NO_ERROR;
1348 } break;
1349 case RELEASE_AUDIO_PATCH: {
1350 CHECK_INTERFACE(IAudioFlinger, data, reply);
1351 audio_patch_handle_t handle;
1352 data.read(&handle, sizeof(audio_patch_handle_t));
1353 status_t status = releaseAudioPatch(handle);
1354 reply->writeInt32(status);
1355 return NO_ERROR;
1356 } break;
1357 case LIST_AUDIO_PATCHES: {
1358 CHECK_INTERFACE(IAudioFlinger, data, reply);
1359 unsigned int num_patches = data.readInt32();
1360 struct audio_patch *patches =
1361 (struct audio_patch *)calloc(num_patches,
1362 sizeof(struct audio_patch));
1363 status_t status = listAudioPatches(&num_patches, patches);
1364 reply->writeInt32(status);
1365 if (status == NO_ERROR) {
1366 reply->writeInt32(num_patches);
1367 reply->write(&patches, num_patches * sizeof(struct audio_patch));
1368 }
1369 free(patches);
1370 return NO_ERROR;
1371 } break;
1372 case SET_AUDIO_PORT_CONFIG: {
1373 CHECK_INTERFACE(IAudioFlinger, data, reply);
1374 struct audio_port_config config;
1375 data.read(&config, sizeof(struct audio_port_config));
1376 status_t status = setAudioPortConfig(&config);
1377 reply->writeInt32(status);
1378 return NO_ERROR;
1379 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001380 default:
1381 return BBinder::onTransact(code, data, reply, flags);
1382 }
1383}
1384
1385// ----------------------------------------------------------------------------
1386
1387}; // namespace android