blob: bd7ea46f367f3695a9ad2b00815f1632cd8ef9db [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 Kasten74105912014-07-03 12:28:53 -0700200 data.writeInt64(notificationFrames != NULL ? *notificationFrames : 0);
Glenn Kastend776ac62014-05-07 09:16:09 -0700201 cblk.clear();
202 buffers.clear();
Eric Laurent5841db72009-09-09 05:16:08 -0700203 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
204 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000205 ALOGE("openRecord error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700206 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700207 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800208 if (pFrameCount != NULL) {
209 *pFrameCount = frameCount;
210 }
Glenn Kasteneeca3262013-07-31 16:12:48 -0700211 lFlags = reply.readInt32();
212 if (flags != NULL) {
213 *flags = lFlags;
214 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700215 lSessionId = reply.readInt32();
216 if (sessionId != NULL) {
217 *sessionId = lSessionId;
218 }
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700219 size_t lNotificationFrames = (size_t) reply.readInt64();
220 if (notificationFrames != NULL) {
221 *notificationFrames = lNotificationFrames;
222 }
Eric Laurent5841db72009-09-09 05:16:08 -0700223 lStatus = reply.readInt32();
224 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700225 cblk = interface_cast<IMemory>(reply.readStrongBinder());
226 if (cblk != 0 && cblk->pointer() == NULL) {
227 cblk.clear();
228 }
229 buffers = interface_cast<IMemory>(reply.readStrongBinder());
230 if (buffers != 0 && buffers->pointer() == NULL) {
231 buffers.clear();
232 }
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700233 if (lStatus == NO_ERROR) {
234 if (record == 0) {
235 ALOGE("openRecord should have returned an IAudioRecord");
236 lStatus = UNKNOWN_ERROR;
Glenn Kastend776ac62014-05-07 09:16:09 -0700237 } else if (cblk == 0) {
238 ALOGE("openRecord should have returned a cblk");
239 lStatus = NO_MEMORY;
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700240 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700241 // buffers is permitted to be 0
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700242 } else {
Glenn Kastend776ac62014-05-07 09:16:09 -0700243 if (record != 0 || cblk != 0 || buffers != 0) {
244 ALOGE("openRecord returned an IAudioRecord, cblk, "
245 "or buffers but with status %d", lStatus);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700246 }
247 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700248 if (lStatus != NO_ERROR) {
249 record.clear();
250 cblk.clear();
251 buffers.clear();
252 }
Eric Laurent5841db72009-09-09 05:16:08 -0700253 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700254 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800255 *status = lStatus;
256 }
Eric Laurent5841db72009-09-09 05:16:08 -0700257 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800258 }
259
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800260 virtual uint32_t sampleRate(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800261 {
262 Parcel data, reply;
263 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800264 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800265 remote()->transact(SAMPLE_RATE, data, &reply);
266 return reply.readInt32();
267 }
268
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800269 virtual audio_format_t format(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800270 {
271 Parcel data, reply;
272 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800273 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800274 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800275 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800276 }
277
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800278 virtual size_t frameCount(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800279 {
280 Parcel data, reply;
281 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800282 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800283 remote()->transact(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800284 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800285 }
286
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800287 virtual uint32_t latency(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800288 {
289 Parcel data, reply;
290 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800291 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800292 remote()->transact(LATENCY, data, &reply);
293 return reply.readInt32();
294 }
295
296 virtual status_t setMasterVolume(float value)
297 {
298 Parcel data, reply;
299 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
300 data.writeFloat(value);
301 remote()->transact(SET_MASTER_VOLUME, data, &reply);
302 return reply.readInt32();
303 }
304
305 virtual status_t setMasterMute(bool muted)
306 {
307 Parcel data, reply;
308 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
309 data.writeInt32(muted);
310 remote()->transact(SET_MASTER_MUTE, data, &reply);
311 return reply.readInt32();
312 }
313
314 virtual float masterVolume() const
315 {
316 Parcel data, reply;
317 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
318 remote()->transact(MASTER_VOLUME, data, &reply);
319 return reply.readFloat();
320 }
321
322 virtual bool masterMute() const
323 {
324 Parcel data, reply;
325 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
326 remote()->transact(MASTER_MUTE, data, &reply);
327 return reply.readInt32();
328 }
329
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800330 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
331 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800332 {
333 Parcel data, reply;
334 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800335 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800336 data.writeFloat(value);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800337 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800338 remote()->transact(SET_STREAM_VOLUME, data, &reply);
339 return reply.readInt32();
340 }
341
Glenn Kastenfff6d712012-01-12 16:38:12 -0800342 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800343 {
344 Parcel data, reply;
345 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800346 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800347 data.writeInt32(muted);
348 remote()->transact(SET_STREAM_MUTE, data, &reply);
349 return reply.readInt32();
350 }
351
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800352 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800353 {
354 Parcel data, reply;
355 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800356 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800357 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800358 remote()->transact(STREAM_VOLUME, data, &reply);
359 return reply.readFloat();
360 }
361
Glenn Kastenfff6d712012-01-12 16:38:12 -0800362 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800363 {
364 Parcel data, reply;
365 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800366 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800367 remote()->transact(STREAM_MUTE, data, &reply);
368 return reply.readInt32();
369 }
370
Glenn Kastenf78aee72012-01-04 11:00:47 -0800371 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800372 {
373 Parcel data, reply;
374 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
375 data.writeInt32(mode);
376 remote()->transact(SET_MODE, data, &reply);
377 return reply.readInt32();
378 }
379
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800380 virtual status_t setMicMute(bool state)
381 {
382 Parcel data, reply;
383 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
384 data.writeInt32(state);
385 remote()->transact(SET_MIC_MUTE, data, &reply);
386 return reply.readInt32();
387 }
388
389 virtual bool getMicMute() const
390 {
391 Parcel data, reply;
392 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
393 remote()->transact(GET_MIC_MUTE, data, &reply);
394 return reply.readInt32();
395 }
396
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800397 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800398 {
399 Parcel data, reply;
400 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800401 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700402 data.writeString8(keyValuePairs);
403 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800404 return reply.readInt32();
405 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700406
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800407 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700408 {
409 Parcel data, reply;
410 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800411 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700412 data.writeString8(keys);
413 remote()->transact(GET_PARAMETERS, data, &reply);
414 return reply.readString8();
415 }
416
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800417 virtual void registerClient(const sp<IAudioFlingerClient>& client)
418 {
419 Parcel data, reply;
420 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
421 data.writeStrongBinder(client->asBinder());
422 remote()->transact(REGISTER_CLIENT, data, &reply);
423 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700424
Glenn Kastendd8104c2012-07-02 12:42:44 -0700425 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
426 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800427 {
428 Parcel data, reply;
429 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
430 data.writeInt32(sampleRate);
431 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700432 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800433 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800434 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800435 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700436
Eric Laurenta4c5a552012-03-29 10:12:40 -0700437 virtual audio_io_handle_t openOutput(audio_module_handle_t module,
438 audio_devices_t *pDevices,
439 uint32_t *pSamplingRate,
440 audio_format_t *pFormat,
441 audio_channel_mask_t *pChannelMask,
442 uint32_t *pLatencyMs,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000443 audio_output_flags_t flags,
444 const audio_offload_info_t *offloadInfo)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800445 {
446 Parcel data, reply;
Glenn Kasten45faf7e2014-01-17 10:23:01 -0800447 audio_devices_t devices = pDevices != NULL ? *pDevices : AUDIO_DEVICE_NONE;
Glenn Kasten7c5977f2013-07-02 14:17:22 -0700448 uint32_t samplingRate = pSamplingRate != NULL ? *pSamplingRate : 0;
449 audio_format_t format = pFormat != NULL ? *pFormat : AUDIO_FORMAT_DEFAULT;
450 audio_channel_mask_t channelMask = pChannelMask != NULL ?
451 *pChannelMask : (audio_channel_mask_t)0;
452 uint32_t latency = pLatencyMs != NULL ? *pLatencyMs : 0;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800453 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700454 data.writeInt32(module);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700455 data.writeInt32(devices);
456 data.writeInt32(samplingRate);
457 data.writeInt32(format);
Eric Laurenta4c5a552012-03-29 10:12:40 -0700458 data.writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700459 data.writeInt32(latency);
Glenn Kasten18868c52012-03-07 09:15:37 -0800460 data.writeInt32((int32_t) flags);
Glenn Kasten2301acc2014-01-17 10:21:00 -0800461 // hasOffloadInfo
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100462 if (offloadInfo == NULL) {
463 data.writeInt32(0);
464 } else {
465 data.writeInt32(1);
466 data.write(offloadInfo, sizeof(audio_offload_info_t));
467 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700468 remote()->transact(OPEN_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800469 audio_io_handle_t output = (audio_io_handle_t) reply.readInt32();
470 ALOGV("openOutput() returned output, %d", output);
Eric Laurenta4c5a552012-03-29 10:12:40 -0700471 devices = (audio_devices_t)reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700472 if (pDevices != NULL) {
473 *pDevices = devices;
474 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700475 samplingRate = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700476 if (pSamplingRate != NULL) {
477 *pSamplingRate = samplingRate;
478 }
Glenn Kasten58f30212012-01-12 12:27:51 -0800479 format = (audio_format_t) reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700480 if (pFormat != NULL) {
481 *pFormat = format;
482 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700483 channelMask = (audio_channel_mask_t)reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700484 if (pChannelMask != NULL) {
485 *pChannelMask = channelMask;
486 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700487 latency = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700488 if (pLatencyMs != NULL) {
489 *pLatencyMs = latency;
490 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700491 return output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800492 }
493
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800494 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
495 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800496 {
497 Parcel data, reply;
498 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800499 data.writeInt32((int32_t) output1);
500 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700501 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800502 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700503 }
504
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800505 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700506 {
507 Parcel data, reply;
508 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800509 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700510 remote()->transact(CLOSE_OUTPUT, data, &reply);
511 return reply.readInt32();
512 }
513
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800514 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700515 {
516 Parcel data, reply;
517 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800518 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700519 remote()->transact(SUSPEND_OUTPUT, data, &reply);
520 return reply.readInt32();
521 }
522
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800523 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700524 {
525 Parcel data, reply;
526 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800527 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700528 remote()->transact(RESTORE_OUTPUT, data, &reply);
529 return reply.readInt32();
530 }
531
Eric Laurenta4c5a552012-03-29 10:12:40 -0700532 virtual audio_io_handle_t openInput(audio_module_handle_t module,
533 audio_devices_t *pDevices,
534 uint32_t *pSamplingRate,
535 audio_format_t *pFormat,
Glenn Kastenec40d282014-07-15 15:31:26 -0700536 audio_channel_mask_t *pChannelMask,
537 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700538 {
539 Parcel data, reply;
Glenn Kasten45faf7e2014-01-17 10:23:01 -0800540 audio_devices_t devices = pDevices != NULL ? *pDevices : AUDIO_DEVICE_NONE;
Glenn Kasten7c5977f2013-07-02 14:17:22 -0700541 uint32_t samplingRate = pSamplingRate != NULL ? *pSamplingRate : 0;
542 audio_format_t format = pFormat != NULL ? *pFormat : AUDIO_FORMAT_DEFAULT;
543 audio_channel_mask_t channelMask = pChannelMask != NULL ?
544 *pChannelMask : (audio_channel_mask_t)0;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700545
546 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700547 data.writeInt32(module);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700548 data.writeInt32(devices);
549 data.writeInt32(samplingRate);
550 data.writeInt32(format);
Eric Laurenta4c5a552012-03-29 10:12:40 -0700551 data.writeInt32(channelMask);
Glenn Kastenec40d282014-07-15 15:31:26 -0700552 data.writeInt32(flags);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700553 remote()->transact(OPEN_INPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800554 audio_io_handle_t input = (audio_io_handle_t) reply.readInt32();
Eric Laurenta4c5a552012-03-29 10:12:40 -0700555 devices = (audio_devices_t)reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700556 if (pDevices != NULL) {
557 *pDevices = devices;
558 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700559 samplingRate = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700560 if (pSamplingRate != NULL) {
561 *pSamplingRate = samplingRate;
562 }
Glenn Kasten58f30212012-01-12 12:27:51 -0800563 format = (audio_format_t) reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700564 if (pFormat != NULL) {
565 *pFormat = format;
566 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700567 channelMask = (audio_channel_mask_t)reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700568 if (pChannelMask != NULL) {
569 *pChannelMask = channelMask;
570 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700571 return input;
572 }
573
Eric Laurentfa2877b2009-07-28 08:44:33 -0700574 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700575 {
576 Parcel data, reply;
577 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700578 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700579 remote()->transact(CLOSE_INPUT, data, &reply);
580 return reply.readInt32();
581 }
582
Glenn Kastend2304db2014-02-03 07:40:31 -0800583 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700584 {
585 Parcel data, reply;
586 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800587 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800588 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700589 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800590 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700591
592 virtual status_t setVoiceVolume(float volume)
593 {
594 Parcel data, reply;
595 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
596 data.writeFloat(volume);
597 remote()->transact(SET_VOICE_VOLUME, data, &reply);
598 return reply.readInt32();
599 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800600
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000601 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800602 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800603 {
604 Parcel data, reply;
605 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800606 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800607 remote()->transact(GET_RENDER_POSITION, data, &reply);
608 status_t status = reply.readInt32();
609 if (status == NO_ERROR) {
610 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700611 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800612 *halFrames = tmp;
613 }
614 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700615 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800616 *dspFrames = tmp;
617 }
618 }
619 return status;
620 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800621
Glenn Kasten5f972c02014-01-13 09:59:31 -0800622 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800623 {
624 Parcel data, reply;
625 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800626 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800627 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
628 if (status != NO_ERROR) {
629 return 0;
630 }
631 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800632 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700633
634 virtual int newAudioSessionId()
635 {
636 Parcel data, reply;
637 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
638 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
Glenn Kasten85d109a2014-01-17 10:25:08 -0800639 int id = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700640 if (status == NO_ERROR) {
641 id = reply.readInt32();
642 }
643 return id;
644 }
645
Marco Nelissend457c972014-02-11 08:47:07 -0800646 virtual void acquireAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700647 {
648 Parcel data, reply;
649 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
650 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800651 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700652 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
653 }
654
Marco Nelissend457c972014-02-11 08:47:07 -0800655 virtual void releaseAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700656 {
657 Parcel data, reply;
658 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
659 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800660 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700661 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
662 }
663
Glenn Kastenf587ba52012-01-26 16:25:10 -0800664 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700665 {
666 Parcel data, reply;
667 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
668 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
669 if (status != NO_ERROR) {
670 return status;
671 }
672 status = reply.readInt32();
673 if (status != NO_ERROR) {
674 return status;
675 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800676 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700677 *numEffects = (uint32_t)reply.readInt32();
678 }
679 return NO_ERROR;
680 }
681
Glenn Kastenf587ba52012-01-26 16:25:10 -0800682 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700683 {
684 if (pDescriptor == NULL) {
685 return BAD_VALUE;
686 }
687 Parcel data, reply;
688 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700689 data.writeInt32(index);
690 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700691 if (status != NO_ERROR) {
692 return status;
693 }
694 status = reply.readInt32();
695 if (status != NO_ERROR) {
696 return status;
697 }
698 reply.read(pDescriptor, sizeof(effect_descriptor_t));
699 return NO_ERROR;
700 }
701
Glenn Kasten5e92a782012-01-30 07:40:52 -0800702 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800703 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700704 {
705 if (pUuid == NULL || pDescriptor == NULL) {
706 return BAD_VALUE;
707 }
708 Parcel data, reply;
709 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
710 data.write(pUuid, sizeof(effect_uuid_t));
711 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
712 if (status != NO_ERROR) {
713 return status;
714 }
715 status = reply.readInt32();
716 if (status != NO_ERROR) {
717 return status;
718 }
719 reply.read(pDescriptor, sizeof(effect_descriptor_t));
720 return NO_ERROR;
721 }
722
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800723 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700724 effect_descriptor_t *pDesc,
725 const sp<IEffectClient>& client,
726 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800727 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700728 int sessionId,
729 status_t *status,
730 int *id,
731 int *enabled)
732 {
733 Parcel data, reply;
734 sp<IEffect> effect;
735
736 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700737 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700738 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700739 *status = BAD_VALUE;
740 }
741 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700742
743 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700744 data.write(pDesc, sizeof(effect_descriptor_t));
745 data.writeStrongBinder(client->asBinder());
746 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800747 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700748 data.writeInt32(sessionId);
749
750 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
751 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000752 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700753 } else {
754 lStatus = reply.readInt32();
755 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700756 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700757 *id = tmp;
758 }
759 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800760 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700761 *enabled = tmp;
762 }
763 effect = interface_cast<IEffect>(reply.readStrongBinder());
764 reply.read(pDesc, sizeof(effect_descriptor_t));
765 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700766 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700767 *status = lStatus;
768 }
769
770 return effect;
771 }
Eric Laurentde070132010-07-13 04:45:46 -0700772
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800773 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
774 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700775 {
776 Parcel data, reply;
777 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
778 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800779 data.writeInt32((int32_t) srcOutput);
780 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700781 remote()->transact(MOVE_EFFECTS, data, &reply);
782 return reply.readInt32();
783 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700784
785 virtual audio_module_handle_t loadHwModule(const char *name)
786 {
787 Parcel data, reply;
788 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
789 data.writeCString(name);
790 remote()->transact(LOAD_HW_MODULE, data, &reply);
791 return (audio_module_handle_t) reply.readInt32();
792 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700793
Glenn Kasten3b16c762012-11-14 08:44:39 -0800794 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700795 {
796 Parcel data, reply;
797 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
798 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
799 return reply.readInt32();
800 }
801
Glenn Kastene33054e2012-11-14 12:54:39 -0800802 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700803 {
804 Parcel data, reply;
805 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
806 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800807 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700808 }
809
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700810 virtual status_t setLowRamDevice(bool isLowRamDevice)
811 {
812 Parcel data, reply;
813 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
814 data.writeInt32((int) isLowRamDevice);
815 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
816 return reply.readInt32();
817 }
Eric Laurent4b123402014-04-11 09:22:20 -0700818 virtual status_t listAudioPorts(unsigned int *num_ports,
819 struct audio_port *ports)
820 {
821 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
822 return BAD_VALUE;
823 }
824 Parcel data, reply;
825 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
826 data.writeInt32(*num_ports);
827 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
828 if (status != NO_ERROR ||
829 (status = (status_t)reply.readInt32()) != NO_ERROR) {
830 return status;
831 }
832 *num_ports = (unsigned int)reply.readInt32();
833 reply.read(ports, *num_ports * sizeof(struct audio_port));
834 return status;
835 }
836 virtual status_t getAudioPort(struct audio_port *port)
837 {
838 if (port == NULL) {
839 return BAD_VALUE;
840 }
841 Parcel data, reply;
842 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
843 data.write(port, sizeof(struct audio_port));
844 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
845 if (status != NO_ERROR ||
846 (status = (status_t)reply.readInt32()) != NO_ERROR) {
847 return status;
848 }
849 reply.read(port, sizeof(struct audio_port));
850 return status;
851 }
852 virtual status_t createAudioPatch(const struct audio_patch *patch,
853 audio_patch_handle_t *handle)
854 {
855 if (patch == NULL || handle == NULL) {
856 return BAD_VALUE;
857 }
858 Parcel data, reply;
859 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
860 data.write(patch, sizeof(struct audio_patch));
861 data.write(handle, sizeof(audio_patch_handle_t));
862 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
863 if (status != NO_ERROR ||
864 (status = (status_t)reply.readInt32()) != NO_ERROR) {
865 return status;
866 }
867 reply.read(handle, sizeof(audio_patch_handle_t));
868 return status;
869 }
870 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
871 {
872 Parcel data, reply;
873 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
874 data.write(&handle, sizeof(audio_patch_handle_t));
875 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
876 if (status != NO_ERROR) {
877 status = (status_t)reply.readInt32();
878 }
879 return status;
880 }
881 virtual status_t listAudioPatches(unsigned int *num_patches,
882 struct audio_patch *patches)
883 {
884 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
885 return BAD_VALUE;
886 }
887 Parcel data, reply;
888 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
889 data.writeInt32(*num_patches);
890 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
891 if (status != NO_ERROR ||
892 (status = (status_t)reply.readInt32()) != NO_ERROR) {
893 return status;
894 }
895 *num_patches = (unsigned int)reply.readInt32();
896 reply.read(patches, *num_patches * sizeof(struct audio_patch));
897 return status;
898 }
899 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
900 {
901 if (config == NULL) {
902 return BAD_VALUE;
903 }
904 Parcel data, reply;
905 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
906 data.write(config, sizeof(struct audio_port_config));
907 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
908 if (status != NO_ERROR) {
909 status = (status_t)reply.readInt32();
910 }
911 return status;
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);
957 reply->writeStrongBinder(track->asBinder());
958 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();
Glenn Kastene03dd222014-01-28 11:04:39 -0800966 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800967 track_flags_t flags = (track_flags_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700968 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700969 int sessionId = data.readInt32();
Glenn Kasten74105912014-07-03 12:28:53 -0700970 size_t notificationFrames = data.readInt64();
Glenn Kastend776ac62014-05-07 09:16:09 -0700971 sp<IMemory> cblk;
972 sp<IMemory> buffers;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800973 status_t status;
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800974 sp<IAudioRecord> record = openRecord(input,
Glenn Kastend776ac62014-05-07 09:16:09 -0700975 sampleRate, format, channelMask, &frameCount, &flags, tid, &sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700976 &notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700977 cblk, buffers, &status);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700978 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700979 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700980 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700981 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700982 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800983 reply->writeInt32(status);
984 reply->writeStrongBinder(record->asBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700985 reply->writeStrongBinder(cblk->asBinder());
986 reply->writeStrongBinder(buffers->asBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800987 return NO_ERROR;
988 } break;
989 case SAMPLE_RATE: {
990 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800991 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800992 return NO_ERROR;
993 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800994 case FORMAT: {
995 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800996 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800997 return NO_ERROR;
998 } break;
999 case FRAME_COUNT: {
1000 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001001 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001002 return NO_ERROR;
1003 } break;
1004 case LATENCY: {
1005 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001006 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001007 return NO_ERROR;
1008 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001009 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001010 CHECK_INTERFACE(IAudioFlinger, data, reply);
1011 reply->writeInt32( setMasterVolume(data.readFloat()) );
1012 return NO_ERROR;
1013 } break;
1014 case SET_MASTER_MUTE: {
1015 CHECK_INTERFACE(IAudioFlinger, data, reply);
1016 reply->writeInt32( setMasterMute(data.readInt32()) );
1017 return NO_ERROR;
1018 } break;
1019 case MASTER_VOLUME: {
1020 CHECK_INTERFACE(IAudioFlinger, data, reply);
1021 reply->writeFloat( masterVolume() );
1022 return NO_ERROR;
1023 } break;
1024 case MASTER_MUTE: {
1025 CHECK_INTERFACE(IAudioFlinger, data, reply);
1026 reply->writeInt32( masterMute() );
1027 return NO_ERROR;
1028 } break;
1029 case SET_STREAM_VOLUME: {
1030 CHECK_INTERFACE(IAudioFlinger, data, reply);
1031 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001032 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001033 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001034 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001035 return NO_ERROR;
1036 } break;
1037 case SET_STREAM_MUTE: {
1038 CHECK_INTERFACE(IAudioFlinger, data, reply);
1039 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001040 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001041 return NO_ERROR;
1042 } break;
1043 case STREAM_VOLUME: {
1044 CHECK_INTERFACE(IAudioFlinger, data, reply);
1045 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001046 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001047 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001048 return NO_ERROR;
1049 } break;
1050 case STREAM_MUTE: {
1051 CHECK_INTERFACE(IAudioFlinger, data, reply);
1052 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001053 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001054 return NO_ERROR;
1055 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001056 case SET_MODE: {
1057 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001058 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001059 reply->writeInt32( setMode(mode) );
1060 return NO_ERROR;
1061 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001062 case SET_MIC_MUTE: {
1063 CHECK_INTERFACE(IAudioFlinger, data, reply);
1064 int state = data.readInt32();
1065 reply->writeInt32( setMicMute(state) );
1066 return NO_ERROR;
1067 } break;
1068 case GET_MIC_MUTE: {
1069 CHECK_INTERFACE(IAudioFlinger, data, reply);
1070 reply->writeInt32( getMicMute() );
1071 return NO_ERROR;
1072 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001073 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001074 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001075 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001076 String8 keyValuePairs(data.readString8());
1077 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001078 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001079 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001080 case GET_PARAMETERS: {
1081 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001082 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001083 String8 keys(data.readString8());
1084 reply->writeString8(getParameters(ioHandle, keys));
1085 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001086 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001087
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001088 case REGISTER_CLIENT: {
1089 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001090 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1091 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001092 registerClient(client);
1093 return NO_ERROR;
1094 } break;
1095 case GET_INPUTBUFFERSIZE: {
1096 CHECK_INTERFACE(IAudioFlinger, data, reply);
1097 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001098 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001099 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001100 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001101 return NO_ERROR;
1102 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001103 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001104 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001105 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
1106 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001107 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001108 audio_format_t format = (audio_format_t) data.readInt32();
Eric Laurenta4c5a552012-03-29 10:12:40 -07001109 audio_channel_mask_t channelMask = (audio_channel_mask_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001110 uint32_t latency = data.readInt32();
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001111 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001112 bool hasOffloadInfo = data.readInt32() != 0;
1113 audio_offload_info_t offloadInfo;
1114 if (hasOffloadInfo) {
1115 data.read(&offloadInfo, sizeof(audio_offload_info_t));
1116 }
Eric Laurenta4c5a552012-03-29 10:12:40 -07001117 audio_io_handle_t output = openOutput(module,
1118 &devices,
1119 &samplingRate,
1120 &format,
1121 &channelMask,
1122 &latency,
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +01001123 flags,
1124 hasOffloadInfo ? &offloadInfo : NULL);
Glenn Kasten70742962014-02-18 08:00:47 -08001125 ALOGV("OPEN_OUTPUT output, %d", output);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001126 reply->writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001127 reply->writeInt32(devices);
1128 reply->writeInt32(samplingRate);
1129 reply->writeInt32(format);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001130 reply->writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001131 reply->writeInt32(latency);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001132 return NO_ERROR;
1133 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001134 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001135 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001136 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1137 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1138 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001139 return NO_ERROR;
1140 } break;
1141 case CLOSE_OUTPUT: {
1142 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001143 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001144 return NO_ERROR;
1145 } break;
1146 case SUSPEND_OUTPUT: {
1147 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001148 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001149 return NO_ERROR;
1150 } break;
1151 case RESTORE_OUTPUT: {
1152 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001153 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001154 return NO_ERROR;
1155 } break;
1156 case OPEN_INPUT: {
1157 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001158 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
1159 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001160 uint32_t samplingRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001161 audio_format_t format = (audio_format_t) data.readInt32();
Eric Laurenta4c5a552012-03-29 10:12:40 -07001162 audio_channel_mask_t channelMask = (audio_channel_mask_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001163 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001164
Eric Laurenta4c5a552012-03-29 10:12:40 -07001165 audio_io_handle_t input = openInput(module,
1166 &devices,
1167 &samplingRate,
1168 &format,
Glenn Kastenec40d282014-07-15 15:31:26 -07001169 &channelMask,
1170 flags);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001171 reply->writeInt32((int32_t) input);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001172 reply->writeInt32(devices);
1173 reply->writeInt32(samplingRate);
1174 reply->writeInt32(format);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001175 reply->writeInt32(channelMask);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001176 return NO_ERROR;
1177 } break;
1178 case CLOSE_INPUT: {
1179 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001180 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001181 return NO_ERROR;
1182 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001183 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001184 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001185 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1186 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001187 return NO_ERROR;
1188 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001189 case SET_VOICE_VOLUME: {
1190 CHECK_INTERFACE(IAudioFlinger, data, reply);
1191 float volume = data.readFloat();
1192 reply->writeInt32( setVoiceVolume(volume) );
1193 return NO_ERROR;
1194 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001195 case GET_RENDER_POSITION: {
1196 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001197 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001198 uint32_t halFrames;
1199 uint32_t dspFrames;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001200 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1201 reply->writeInt32(status);
1202 if (status == NO_ERROR) {
1203 reply->writeInt32(halFrames);
1204 reply->writeInt32(dspFrames);
1205 }
1206 return NO_ERROR;
1207 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001208 case GET_INPUT_FRAMES_LOST: {
1209 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001210 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001211 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001212 return NO_ERROR;
1213 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001214 case NEW_AUDIO_SESSION_ID: {
1215 CHECK_INTERFACE(IAudioFlinger, data, reply);
1216 reply->writeInt32(newAudioSessionId());
1217 return NO_ERROR;
1218 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001219 case ACQUIRE_AUDIO_SESSION_ID: {
1220 CHECK_INTERFACE(IAudioFlinger, data, reply);
1221 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001222 int pid = data.readInt32();
1223 acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001224 return NO_ERROR;
1225 } break;
1226 case RELEASE_AUDIO_SESSION_ID: {
1227 CHECK_INTERFACE(IAudioFlinger, data, reply);
1228 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001229 int pid = data.readInt32();
1230 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001231 return NO_ERROR;
1232 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001233 case QUERY_NUM_EFFECTS: {
1234 CHECK_INTERFACE(IAudioFlinger, data, reply);
1235 uint32_t numEffects;
1236 status_t status = queryNumberEffects(&numEffects);
1237 reply->writeInt32(status);
1238 if (status == NO_ERROR) {
1239 reply->writeInt32((int32_t)numEffects);
1240 }
1241 return NO_ERROR;
1242 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001243 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001244 CHECK_INTERFACE(IAudioFlinger, data, reply);
1245 effect_descriptor_t desc;
Eric Laurentffe9c252010-06-23 17:38:20 -07001246 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001247 reply->writeInt32(status);
1248 if (status == NO_ERROR) {
1249 reply->write(&desc, sizeof(effect_descriptor_t));
1250 }
1251 return NO_ERROR;
1252 }
1253 case GET_EFFECT_DESCRIPTOR: {
1254 CHECK_INTERFACE(IAudioFlinger, data, reply);
1255 effect_uuid_t uuid;
1256 data.read(&uuid, sizeof(effect_uuid_t));
1257 effect_descriptor_t desc;
1258 status_t status = getEffectDescriptor(&uuid, &desc);
1259 reply->writeInt32(status);
1260 if (status == NO_ERROR) {
1261 reply->write(&desc, sizeof(effect_descriptor_t));
1262 }
1263 return NO_ERROR;
1264 }
1265 case CREATE_EFFECT: {
1266 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001267 effect_descriptor_t desc;
1268 data.read(&desc, sizeof(effect_descriptor_t));
1269 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1270 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001271 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -07001272 int sessionId = data.readInt32();
1273 status_t status;
1274 int id;
1275 int enabled;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001276
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001277 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001278 &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001279 reply->writeInt32(status);
1280 reply->writeInt32(id);
1281 reply->writeInt32(enabled);
1282 reply->writeStrongBinder(effect->asBinder());
1283 reply->write(&desc, sizeof(effect_descriptor_t));
1284 return NO_ERROR;
1285 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001286 case MOVE_EFFECTS: {
1287 CHECK_INTERFACE(IAudioFlinger, data, reply);
1288 int session = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001289 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1290 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001291 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1292 return NO_ERROR;
1293 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001294 case LOAD_HW_MODULE: {
1295 CHECK_INTERFACE(IAudioFlinger, data, reply);
1296 reply->writeInt32(loadHwModule(data.readCString()));
1297 return NO_ERROR;
1298 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001299 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1300 CHECK_INTERFACE(IAudioFlinger, data, reply);
1301 reply->writeInt32(getPrimaryOutputSamplingRate());
1302 return NO_ERROR;
1303 } break;
1304 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1305 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001306 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001307 return NO_ERROR;
1308 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001309 case SET_LOW_RAM_DEVICE: {
1310 CHECK_INTERFACE(IAudioFlinger, data, reply);
1311 bool isLowRamDevice = data.readInt32() != 0;
1312 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1313 return NO_ERROR;
1314 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001315 case LIST_AUDIO_PORTS: {
1316 CHECK_INTERFACE(IAudioFlinger, data, reply);
1317 unsigned int num_ports = data.readInt32();
1318 struct audio_port *ports =
1319 (struct audio_port *)calloc(num_ports,
1320 sizeof(struct audio_port));
1321 status_t status = listAudioPorts(&num_ports, ports);
1322 reply->writeInt32(status);
1323 if (status == NO_ERROR) {
1324 reply->writeInt32(num_ports);
1325 reply->write(&ports, num_ports * sizeof(struct audio_port));
1326 }
1327 free(ports);
1328 return NO_ERROR;
1329 } break;
1330 case GET_AUDIO_PORT: {
1331 CHECK_INTERFACE(IAudioFlinger, data, reply);
1332 struct audio_port port;
1333 data.read(&port, sizeof(struct audio_port));
1334 status_t status = getAudioPort(&port);
1335 reply->writeInt32(status);
1336 if (status == NO_ERROR) {
1337 reply->write(&port, sizeof(struct audio_port));
1338 }
1339 return NO_ERROR;
1340 } break;
1341 case CREATE_AUDIO_PATCH: {
1342 CHECK_INTERFACE(IAudioFlinger, data, reply);
1343 struct audio_patch patch;
1344 data.read(&patch, sizeof(struct audio_patch));
1345 audio_patch_handle_t handle;
1346 data.read(&handle, sizeof(audio_patch_handle_t));
1347 status_t status = createAudioPatch(&patch, &handle);
1348 reply->writeInt32(status);
1349 if (status == NO_ERROR) {
1350 reply->write(&handle, sizeof(audio_patch_handle_t));
1351 }
1352 return NO_ERROR;
1353 } break;
1354 case RELEASE_AUDIO_PATCH: {
1355 CHECK_INTERFACE(IAudioFlinger, data, reply);
1356 audio_patch_handle_t handle;
1357 data.read(&handle, sizeof(audio_patch_handle_t));
1358 status_t status = releaseAudioPatch(handle);
1359 reply->writeInt32(status);
1360 return NO_ERROR;
1361 } break;
1362 case LIST_AUDIO_PATCHES: {
1363 CHECK_INTERFACE(IAudioFlinger, data, reply);
1364 unsigned int num_patches = data.readInt32();
1365 struct audio_patch *patches =
1366 (struct audio_patch *)calloc(num_patches,
1367 sizeof(struct audio_patch));
1368 status_t status = listAudioPatches(&num_patches, patches);
1369 reply->writeInt32(status);
1370 if (status == NO_ERROR) {
1371 reply->writeInt32(num_patches);
1372 reply->write(&patches, num_patches * sizeof(struct audio_patch));
1373 }
1374 free(patches);
1375 return NO_ERROR;
1376 } break;
1377 case SET_AUDIO_PORT_CONFIG: {
1378 CHECK_INTERFACE(IAudioFlinger, data, reply);
1379 struct audio_port_config config;
1380 data.read(&config, sizeof(struct audio_port_config));
1381 status_t status = setAudioPortConfig(&config);
1382 reply->writeInt32(status);
1383 return NO_ERROR;
1384 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001385 default:
1386 return BBinder::onTransact(code, data, reply, flags);
1387 }
1388}
1389
1390// ----------------------------------------------------------------------------
1391
1392}; // namespace android