blob: 5331fce0522fa2c2cdc0e40560ada6c4201014eb [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 Laurentcf2c0212014-07-25 16:20:43 -0700437 virtual status_t openOutput(audio_module_handle_t module,
438 audio_io_handle_t *output,
439 audio_config_t *config,
440 audio_devices_t *devices,
441 const String8& address,
442 uint32_t *latencyMs,
443 audio_output_flags_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800444 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700445 if (output == NULL || config == NULL || devices == NULL || latencyMs == NULL) {
446 return BAD_VALUE;
447 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800448 Parcel data, reply;
449 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700450 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700451 data.write(config, sizeof(audio_config_t));
452 data.writeInt32(*devices);
453 data.writeString8(address);
Glenn Kasten18868c52012-03-07 09:15:37 -0800454 data.writeInt32((int32_t) flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700455 status_t status = remote()->transact(OPEN_OUTPUT, data, &reply);
456 if (status != NO_ERROR) {
457 *output = AUDIO_IO_HANDLE_NONE;
458 return status;
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100459 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700460 status = (status_t)reply.readInt32();
461 if (status != NO_ERROR) {
462 *output = AUDIO_IO_HANDLE_NONE;
463 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700464 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700465 *output = (audio_io_handle_t)reply.readInt32();
466 ALOGV("openOutput() returned output, %d", *output);
467 reply.read(config, sizeof(audio_config_t));
468 *devices = (audio_devices_t)reply.readInt32();
469 *latencyMs = reply.readInt32();
470 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800471 }
472
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800473 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
474 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800475 {
476 Parcel data, reply;
477 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800478 data.writeInt32((int32_t) output1);
479 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700480 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800481 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700482 }
483
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800484 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700485 {
486 Parcel data, reply;
487 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800488 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700489 remote()->transact(CLOSE_OUTPUT, data, &reply);
490 return reply.readInt32();
491 }
492
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800493 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700494 {
495 Parcel data, reply;
496 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800497 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700498 remote()->transact(SUSPEND_OUTPUT, data, &reply);
499 return reply.readInt32();
500 }
501
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800502 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700503 {
504 Parcel data, reply;
505 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800506 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700507 remote()->transact(RESTORE_OUTPUT, data, &reply);
508 return reply.readInt32();
509 }
510
Eric Laurentcf2c0212014-07-25 16:20:43 -0700511 virtual status_t openInput(audio_module_handle_t module,
512 audio_io_handle_t *input,
513 audio_config_t *config,
514 audio_devices_t *device,
515 const String8& address,
516 audio_source_t source,
517 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700518 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700519 if (input == NULL || config == NULL || device == NULL) {
520 return BAD_VALUE;
521 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700522 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700523 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700524 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700525 data.writeInt32(*input);
526 data.write(config, sizeof(audio_config_t));
527 data.writeInt32(*device);
528 data.writeString8(address);
529 data.writeInt32(source);
Glenn Kastenec40d282014-07-15 15:31:26 -0700530 data.writeInt32(flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700531 status_t status = remote()->transact(OPEN_INPUT, data, &reply);
532 if (status != NO_ERROR) {
533 *input = AUDIO_IO_HANDLE_NONE;
534 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700535 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700536 status = (status_t)reply.readInt32();
537 if (status != NO_ERROR) {
538 *input = AUDIO_IO_HANDLE_NONE;
539 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700540 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700541 *input = (audio_io_handle_t)reply.readInt32();
542 reply.read(config, sizeof(audio_config_t));
543 *device = (audio_devices_t)reply.readInt32();
544 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700545 }
546
Eric Laurentfa2877b2009-07-28 08:44:33 -0700547 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700548 {
549 Parcel data, reply;
550 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700551 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700552 remote()->transact(CLOSE_INPUT, data, &reply);
553 return reply.readInt32();
554 }
555
Glenn Kastend2304db2014-02-03 07:40:31 -0800556 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700557 {
558 Parcel data, reply;
559 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800560 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800561 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700562 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800563 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700564
565 virtual status_t setVoiceVolume(float volume)
566 {
567 Parcel data, reply;
568 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
569 data.writeFloat(volume);
570 remote()->transact(SET_VOICE_VOLUME, data, &reply);
571 return reply.readInt32();
572 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800573
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000574 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800575 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800576 {
577 Parcel data, reply;
578 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800579 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800580 remote()->transact(GET_RENDER_POSITION, data, &reply);
581 status_t status = reply.readInt32();
582 if (status == NO_ERROR) {
583 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700584 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800585 *halFrames = tmp;
586 }
587 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700588 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800589 *dspFrames = tmp;
590 }
591 }
592 return status;
593 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800594
Glenn Kasten5f972c02014-01-13 09:59:31 -0800595 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800596 {
597 Parcel data, reply;
598 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800599 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800600 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
601 if (status != NO_ERROR) {
602 return 0;
603 }
604 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800605 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700606
Eric Laurentde3f8392014-07-27 18:38:22 -0700607 virtual audio_unique_id_t newAudioUniqueId()
Eric Laurentbe916aa2010-06-01 23:49:17 -0700608 {
609 Parcel data, reply;
610 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
611 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
Eric Laurentde3f8392014-07-27 18:38:22 -0700612 audio_unique_id_t id = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700613 if (status == NO_ERROR) {
614 id = reply.readInt32();
615 }
616 return id;
617 }
618
Marco Nelissend457c972014-02-11 08:47:07 -0800619 virtual void acquireAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700620 {
621 Parcel data, reply;
622 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
623 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800624 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700625 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
626 }
627
Marco Nelissend457c972014-02-11 08:47:07 -0800628 virtual void releaseAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700629 {
630 Parcel data, reply;
631 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
632 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800633 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700634 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
635 }
636
Glenn Kastenf587ba52012-01-26 16:25:10 -0800637 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700638 {
639 Parcel data, reply;
640 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
641 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
642 if (status != NO_ERROR) {
643 return status;
644 }
645 status = reply.readInt32();
646 if (status != NO_ERROR) {
647 return status;
648 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800649 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700650 *numEffects = (uint32_t)reply.readInt32();
651 }
652 return NO_ERROR;
653 }
654
Glenn Kastenf587ba52012-01-26 16:25:10 -0800655 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700656 {
657 if (pDescriptor == NULL) {
658 return BAD_VALUE;
659 }
660 Parcel data, reply;
661 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700662 data.writeInt32(index);
663 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700664 if (status != NO_ERROR) {
665 return status;
666 }
667 status = reply.readInt32();
668 if (status != NO_ERROR) {
669 return status;
670 }
671 reply.read(pDescriptor, sizeof(effect_descriptor_t));
672 return NO_ERROR;
673 }
674
Glenn Kasten5e92a782012-01-30 07:40:52 -0800675 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800676 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700677 {
678 if (pUuid == NULL || pDescriptor == NULL) {
679 return BAD_VALUE;
680 }
681 Parcel data, reply;
682 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
683 data.write(pUuid, sizeof(effect_uuid_t));
684 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
685 if (status != NO_ERROR) {
686 return status;
687 }
688 status = reply.readInt32();
689 if (status != NO_ERROR) {
690 return status;
691 }
692 reply.read(pDescriptor, sizeof(effect_descriptor_t));
693 return NO_ERROR;
694 }
695
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800696 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700697 effect_descriptor_t *pDesc,
698 const sp<IEffectClient>& client,
699 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800700 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700701 int sessionId,
702 status_t *status,
703 int *id,
704 int *enabled)
705 {
706 Parcel data, reply;
707 sp<IEffect> effect;
708
709 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700710 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700711 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700712 *status = BAD_VALUE;
713 }
714 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700715
716 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700717 data.write(pDesc, sizeof(effect_descriptor_t));
718 data.writeStrongBinder(client->asBinder());
719 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800720 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700721 data.writeInt32(sessionId);
722
723 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
724 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000725 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700726 } else {
727 lStatus = reply.readInt32();
728 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700729 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700730 *id = tmp;
731 }
732 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800733 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700734 *enabled = tmp;
735 }
736 effect = interface_cast<IEffect>(reply.readStrongBinder());
737 reply.read(pDesc, sizeof(effect_descriptor_t));
738 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700739 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700740 *status = lStatus;
741 }
742
743 return effect;
744 }
Eric Laurentde070132010-07-13 04:45:46 -0700745
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800746 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
747 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700748 {
749 Parcel data, reply;
750 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
751 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800752 data.writeInt32((int32_t) srcOutput);
753 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700754 remote()->transact(MOVE_EFFECTS, data, &reply);
755 return reply.readInt32();
756 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700757
758 virtual audio_module_handle_t loadHwModule(const char *name)
759 {
760 Parcel data, reply;
761 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
762 data.writeCString(name);
763 remote()->transact(LOAD_HW_MODULE, data, &reply);
764 return (audio_module_handle_t) reply.readInt32();
765 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700766
Glenn Kasten3b16c762012-11-14 08:44:39 -0800767 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700768 {
769 Parcel data, reply;
770 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
771 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
772 return reply.readInt32();
773 }
774
Glenn Kastene33054e2012-11-14 12:54:39 -0800775 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700776 {
777 Parcel data, reply;
778 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
779 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800780 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700781 }
782
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700783 virtual status_t setLowRamDevice(bool isLowRamDevice)
784 {
785 Parcel data, reply;
786 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
787 data.writeInt32((int) isLowRamDevice);
788 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
789 return reply.readInt32();
790 }
Eric Laurent4b123402014-04-11 09:22:20 -0700791 virtual status_t listAudioPorts(unsigned int *num_ports,
792 struct audio_port *ports)
793 {
794 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
795 return BAD_VALUE;
796 }
797 Parcel data, reply;
798 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
799 data.writeInt32(*num_ports);
800 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
801 if (status != NO_ERROR ||
802 (status = (status_t)reply.readInt32()) != NO_ERROR) {
803 return status;
804 }
805 *num_ports = (unsigned int)reply.readInt32();
806 reply.read(ports, *num_ports * sizeof(struct audio_port));
807 return status;
808 }
809 virtual status_t getAudioPort(struct audio_port *port)
810 {
811 if (port == NULL) {
812 return BAD_VALUE;
813 }
814 Parcel data, reply;
815 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
816 data.write(port, sizeof(struct audio_port));
817 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
818 if (status != NO_ERROR ||
819 (status = (status_t)reply.readInt32()) != NO_ERROR) {
820 return status;
821 }
822 reply.read(port, sizeof(struct audio_port));
823 return status;
824 }
825 virtual status_t createAudioPatch(const struct audio_patch *patch,
826 audio_patch_handle_t *handle)
827 {
828 if (patch == NULL || handle == NULL) {
829 return BAD_VALUE;
830 }
831 Parcel data, reply;
832 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
833 data.write(patch, sizeof(struct audio_patch));
834 data.write(handle, sizeof(audio_patch_handle_t));
835 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
836 if (status != NO_ERROR ||
837 (status = (status_t)reply.readInt32()) != NO_ERROR) {
838 return status;
839 }
840 reply.read(handle, sizeof(audio_patch_handle_t));
841 return status;
842 }
843 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
844 {
845 Parcel data, reply;
846 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
847 data.write(&handle, sizeof(audio_patch_handle_t));
848 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
849 if (status != NO_ERROR) {
850 status = (status_t)reply.readInt32();
851 }
852 return status;
853 }
854 virtual status_t listAudioPatches(unsigned int *num_patches,
855 struct audio_patch *patches)
856 {
857 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
858 return BAD_VALUE;
859 }
860 Parcel data, reply;
861 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
862 data.writeInt32(*num_patches);
863 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
864 if (status != NO_ERROR ||
865 (status = (status_t)reply.readInt32()) != NO_ERROR) {
866 return status;
867 }
868 *num_patches = (unsigned int)reply.readInt32();
869 reply.read(patches, *num_patches * sizeof(struct audio_patch));
870 return status;
871 }
872 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
873 {
874 if (config == NULL) {
875 return BAD_VALUE;
876 }
877 Parcel data, reply;
878 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
879 data.write(config, sizeof(struct audio_port_config));
880 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
881 if (status != NO_ERROR) {
882 status = (status_t)reply.readInt32();
883 }
884 return status;
885 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800886};
887
888IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
889
890// ----------------------------------------------------------------------
891
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800892status_t BnAudioFlinger::onTransact(
893 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
894{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700895 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800896 case CREATE_TRACK: {
897 CHECK_INTERFACE(IAudioFlinger, data, reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800898 int streamType = data.readInt32();
899 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800900 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700901 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800902 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800903 track_flags_t flags = (track_flags_t) data.readInt32();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700904 bool haveSharedBuffer = data.readInt32() != 0;
905 sp<IMemory> buffer;
906 if (haveSharedBuffer) {
907 buffer = interface_cast<IMemory>(data.readStrongBinder());
908 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800909 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kasten3acbd052012-02-28 10:39:56 -0800910 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700911 int sessionId = data.readInt32();
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800912 int clientUid = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800913 status_t status;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700914 sp<IAudioTrack> track;
915 if ((haveSharedBuffer && (buffer == 0)) ||
916 ((buffer != 0) && (buffer->pointer() == NULL))) {
917 ALOGW("CREATE_TRACK: cannot retrieve shared memory");
918 status = DEAD_OBJECT;
919 } else {
920 track = createTrack(
921 (audio_stream_type_t) streamType, sampleRate, format,
Glenn Kasten74935e42013-12-19 08:56:45 -0800922 channelMask, &frameCount, &flags, buffer, output, tid,
Glenn Kastenc5a17422014-03-13 14:59:59 -0700923 &sessionId, clientUid, &status);
Glenn Kasten0cde0762014-01-16 15:06:36 -0800924 LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700925 }
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700926 reply->writeInt64(frameCount);
Glenn Kastene0b07172012-11-06 15:03:34 -0800927 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700928 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800929 reply->writeInt32(status);
930 reply->writeStrongBinder(track->asBinder());
931 return NO_ERROR;
932 } break;
933 case OPEN_RECORD: {
934 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800935 audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800936 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800937 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700938 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800939 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800940 track_flags_t flags = (track_flags_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700941 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700942 int sessionId = data.readInt32();
Glenn Kasten74105912014-07-03 12:28:53 -0700943 size_t notificationFrames = data.readInt64();
Glenn Kastend776ac62014-05-07 09:16:09 -0700944 sp<IMemory> cblk;
945 sp<IMemory> buffers;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800946 status_t status;
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800947 sp<IAudioRecord> record = openRecord(input,
Glenn Kastend776ac62014-05-07 09:16:09 -0700948 sampleRate, format, channelMask, &frameCount, &flags, tid, &sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700949 &notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700950 cblk, buffers, &status);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700951 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700952 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700953 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700954 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700955 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800956 reply->writeInt32(status);
957 reply->writeStrongBinder(record->asBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700958 reply->writeStrongBinder(cblk->asBinder());
959 reply->writeStrongBinder(buffers->asBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800960 return NO_ERROR;
961 } break;
962 case SAMPLE_RATE: {
963 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800964 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800965 return NO_ERROR;
966 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800967 case FORMAT: {
968 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800969 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800970 return NO_ERROR;
971 } break;
972 case FRAME_COUNT: {
973 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800974 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800975 return NO_ERROR;
976 } break;
977 case LATENCY: {
978 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800979 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800980 return NO_ERROR;
981 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700982 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800983 CHECK_INTERFACE(IAudioFlinger, data, reply);
984 reply->writeInt32( setMasterVolume(data.readFloat()) );
985 return NO_ERROR;
986 } break;
987 case SET_MASTER_MUTE: {
988 CHECK_INTERFACE(IAudioFlinger, data, reply);
989 reply->writeInt32( setMasterMute(data.readInt32()) );
990 return NO_ERROR;
991 } break;
992 case MASTER_VOLUME: {
993 CHECK_INTERFACE(IAudioFlinger, data, reply);
994 reply->writeFloat( masterVolume() );
995 return NO_ERROR;
996 } break;
997 case MASTER_MUTE: {
998 CHECK_INTERFACE(IAudioFlinger, data, reply);
999 reply->writeInt32( masterMute() );
1000 return NO_ERROR;
1001 } break;
1002 case SET_STREAM_VOLUME: {
1003 CHECK_INTERFACE(IAudioFlinger, data, reply);
1004 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001005 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001006 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001007 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001008 return NO_ERROR;
1009 } break;
1010 case SET_STREAM_MUTE: {
1011 CHECK_INTERFACE(IAudioFlinger, data, reply);
1012 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001013 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001014 return NO_ERROR;
1015 } break;
1016 case STREAM_VOLUME: {
1017 CHECK_INTERFACE(IAudioFlinger, data, reply);
1018 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001019 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001020 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001021 return NO_ERROR;
1022 } break;
1023 case STREAM_MUTE: {
1024 CHECK_INTERFACE(IAudioFlinger, data, reply);
1025 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001026 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001027 return NO_ERROR;
1028 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001029 case SET_MODE: {
1030 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001031 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001032 reply->writeInt32( setMode(mode) );
1033 return NO_ERROR;
1034 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001035 case SET_MIC_MUTE: {
1036 CHECK_INTERFACE(IAudioFlinger, data, reply);
1037 int state = data.readInt32();
1038 reply->writeInt32( setMicMute(state) );
1039 return NO_ERROR;
1040 } break;
1041 case GET_MIC_MUTE: {
1042 CHECK_INTERFACE(IAudioFlinger, data, reply);
1043 reply->writeInt32( getMicMute() );
1044 return NO_ERROR;
1045 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001046 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001047 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001048 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001049 String8 keyValuePairs(data.readString8());
1050 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001051 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001052 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001053 case GET_PARAMETERS: {
1054 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001055 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001056 String8 keys(data.readString8());
1057 reply->writeString8(getParameters(ioHandle, keys));
1058 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001059 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001060
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001061 case REGISTER_CLIENT: {
1062 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001063 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1064 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001065 registerClient(client);
1066 return NO_ERROR;
1067 } break;
1068 case GET_INPUTBUFFERSIZE: {
1069 CHECK_INTERFACE(IAudioFlinger, data, reply);
1070 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001071 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001072 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001073 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001074 return NO_ERROR;
1075 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001076 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001077 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001078 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001079 audio_config_t config;
1080 data.read(&config, sizeof(audio_config_t));
Eric Laurenta4c5a552012-03-29 10:12:40 -07001081 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001082 String8 address(data.readString8());
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001083 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001084 uint32_t latencyMs;
1085 audio_io_handle_t output;
1086 status_t status = openOutput(module, &output, &config,
1087 &devices, address, &latencyMs, flags);
Glenn Kasten70742962014-02-18 08:00:47 -08001088 ALOGV("OPEN_OUTPUT output, %d", output);
Eric Laurentcf2c0212014-07-25 16:20:43 -07001089 reply->writeInt32((int32_t)status);
1090 if (status == NO_ERROR) {
1091 reply->writeInt32((int32_t)output);
1092 reply->write(&config, sizeof(audio_config_t));
1093 reply->writeInt32(devices);
1094 reply->writeInt32(latencyMs);
1095 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001096 return NO_ERROR;
1097 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001098 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001099 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001100 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1101 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1102 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001103 return NO_ERROR;
1104 } break;
1105 case CLOSE_OUTPUT: {
1106 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001107 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001108 return NO_ERROR;
1109 } break;
1110 case SUSPEND_OUTPUT: {
1111 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001112 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001113 return NO_ERROR;
1114 } break;
1115 case RESTORE_OUTPUT: {
1116 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001117 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001118 return NO_ERROR;
1119 } break;
1120 case OPEN_INPUT: {
1121 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001122 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001123 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
1124 audio_config_t config;
1125 data.read(&config, sizeof(audio_config_t));
1126 audio_devices_t device = (audio_devices_t)data.readInt32();
1127 String8 address(data.readString8());
1128 audio_source_t source = (audio_source_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001129 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001130
Eric Laurentcf2c0212014-07-25 16:20:43 -07001131 status_t status = openInput(module, &input, &config,
1132 &device, address, source, flags);
1133 reply->writeInt32((int32_t) status);
1134 if (status == NO_ERROR) {
1135 reply->writeInt32((int32_t) input);
1136 reply->write(&config, sizeof(audio_config_t));
1137 reply->writeInt32(device);
1138 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001139 return NO_ERROR;
1140 } break;
1141 case CLOSE_INPUT: {
1142 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001143 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001144 return NO_ERROR;
1145 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001146 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001147 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001148 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1149 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001150 return NO_ERROR;
1151 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001152 case SET_VOICE_VOLUME: {
1153 CHECK_INTERFACE(IAudioFlinger, data, reply);
1154 float volume = data.readFloat();
1155 reply->writeInt32( setVoiceVolume(volume) );
1156 return NO_ERROR;
1157 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001158 case GET_RENDER_POSITION: {
1159 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001160 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001161 uint32_t halFrames;
1162 uint32_t dspFrames;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001163 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1164 reply->writeInt32(status);
1165 if (status == NO_ERROR) {
1166 reply->writeInt32(halFrames);
1167 reply->writeInt32(dspFrames);
1168 }
1169 return NO_ERROR;
1170 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001171 case GET_INPUT_FRAMES_LOST: {
1172 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001173 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001174 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001175 return NO_ERROR;
1176 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001177 case NEW_AUDIO_SESSION_ID: {
1178 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentde3f8392014-07-27 18:38:22 -07001179 reply->writeInt32(newAudioUniqueId());
Eric Laurentbe916aa2010-06-01 23:49:17 -07001180 return NO_ERROR;
1181 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001182 case ACQUIRE_AUDIO_SESSION_ID: {
1183 CHECK_INTERFACE(IAudioFlinger, data, reply);
1184 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001185 int pid = data.readInt32();
1186 acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001187 return NO_ERROR;
1188 } break;
1189 case RELEASE_AUDIO_SESSION_ID: {
1190 CHECK_INTERFACE(IAudioFlinger, data, reply);
1191 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001192 int pid = data.readInt32();
1193 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001194 return NO_ERROR;
1195 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001196 case QUERY_NUM_EFFECTS: {
1197 CHECK_INTERFACE(IAudioFlinger, data, reply);
1198 uint32_t numEffects;
1199 status_t status = queryNumberEffects(&numEffects);
1200 reply->writeInt32(status);
1201 if (status == NO_ERROR) {
1202 reply->writeInt32((int32_t)numEffects);
1203 }
1204 return NO_ERROR;
1205 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001206 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001207 CHECK_INTERFACE(IAudioFlinger, data, reply);
1208 effect_descriptor_t desc;
Eric Laurentffe9c252010-06-23 17:38:20 -07001209 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001210 reply->writeInt32(status);
1211 if (status == NO_ERROR) {
1212 reply->write(&desc, sizeof(effect_descriptor_t));
1213 }
1214 return NO_ERROR;
1215 }
1216 case GET_EFFECT_DESCRIPTOR: {
1217 CHECK_INTERFACE(IAudioFlinger, data, reply);
1218 effect_uuid_t uuid;
1219 data.read(&uuid, sizeof(effect_uuid_t));
1220 effect_descriptor_t desc;
1221 status_t status = getEffectDescriptor(&uuid, &desc);
1222 reply->writeInt32(status);
1223 if (status == NO_ERROR) {
1224 reply->write(&desc, sizeof(effect_descriptor_t));
1225 }
1226 return NO_ERROR;
1227 }
1228 case CREATE_EFFECT: {
1229 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001230 effect_descriptor_t desc;
1231 data.read(&desc, sizeof(effect_descriptor_t));
1232 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1233 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001234 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -07001235 int sessionId = data.readInt32();
1236 status_t status;
1237 int id;
1238 int enabled;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001239
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001240 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001241 &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001242 reply->writeInt32(status);
1243 reply->writeInt32(id);
1244 reply->writeInt32(enabled);
1245 reply->writeStrongBinder(effect->asBinder());
1246 reply->write(&desc, sizeof(effect_descriptor_t));
1247 return NO_ERROR;
1248 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001249 case MOVE_EFFECTS: {
1250 CHECK_INTERFACE(IAudioFlinger, data, reply);
1251 int session = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001252 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1253 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001254 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1255 return NO_ERROR;
1256 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001257 case LOAD_HW_MODULE: {
1258 CHECK_INTERFACE(IAudioFlinger, data, reply);
1259 reply->writeInt32(loadHwModule(data.readCString()));
1260 return NO_ERROR;
1261 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001262 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1263 CHECK_INTERFACE(IAudioFlinger, data, reply);
1264 reply->writeInt32(getPrimaryOutputSamplingRate());
1265 return NO_ERROR;
1266 } break;
1267 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1268 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001269 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001270 return NO_ERROR;
1271 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001272 case SET_LOW_RAM_DEVICE: {
1273 CHECK_INTERFACE(IAudioFlinger, data, reply);
1274 bool isLowRamDevice = data.readInt32() != 0;
1275 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1276 return NO_ERROR;
1277 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001278 case LIST_AUDIO_PORTS: {
1279 CHECK_INTERFACE(IAudioFlinger, data, reply);
1280 unsigned int num_ports = data.readInt32();
1281 struct audio_port *ports =
1282 (struct audio_port *)calloc(num_ports,
1283 sizeof(struct audio_port));
1284 status_t status = listAudioPorts(&num_ports, ports);
1285 reply->writeInt32(status);
1286 if (status == NO_ERROR) {
1287 reply->writeInt32(num_ports);
1288 reply->write(&ports, num_ports * sizeof(struct audio_port));
1289 }
1290 free(ports);
1291 return NO_ERROR;
1292 } break;
1293 case GET_AUDIO_PORT: {
1294 CHECK_INTERFACE(IAudioFlinger, data, reply);
1295 struct audio_port port;
1296 data.read(&port, sizeof(struct audio_port));
1297 status_t status = getAudioPort(&port);
1298 reply->writeInt32(status);
1299 if (status == NO_ERROR) {
1300 reply->write(&port, sizeof(struct audio_port));
1301 }
1302 return NO_ERROR;
1303 } break;
1304 case CREATE_AUDIO_PATCH: {
1305 CHECK_INTERFACE(IAudioFlinger, data, reply);
1306 struct audio_patch patch;
1307 data.read(&patch, sizeof(struct audio_patch));
1308 audio_patch_handle_t handle;
1309 data.read(&handle, sizeof(audio_patch_handle_t));
1310 status_t status = createAudioPatch(&patch, &handle);
1311 reply->writeInt32(status);
1312 if (status == NO_ERROR) {
1313 reply->write(&handle, sizeof(audio_patch_handle_t));
1314 }
1315 return NO_ERROR;
1316 } break;
1317 case RELEASE_AUDIO_PATCH: {
1318 CHECK_INTERFACE(IAudioFlinger, data, reply);
1319 audio_patch_handle_t handle;
1320 data.read(&handle, sizeof(audio_patch_handle_t));
1321 status_t status = releaseAudioPatch(handle);
1322 reply->writeInt32(status);
1323 return NO_ERROR;
1324 } break;
1325 case LIST_AUDIO_PATCHES: {
1326 CHECK_INTERFACE(IAudioFlinger, data, reply);
1327 unsigned int num_patches = data.readInt32();
1328 struct audio_patch *patches =
1329 (struct audio_patch *)calloc(num_patches,
1330 sizeof(struct audio_patch));
1331 status_t status = listAudioPatches(&num_patches, patches);
1332 reply->writeInt32(status);
1333 if (status == NO_ERROR) {
1334 reply->writeInt32(num_patches);
1335 reply->write(&patches, num_patches * sizeof(struct audio_patch));
1336 }
1337 free(patches);
1338 return NO_ERROR;
1339 } break;
1340 case SET_AUDIO_PORT_CONFIG: {
1341 CHECK_INTERFACE(IAudioFlinger, data, reply);
1342 struct audio_port_config config;
1343 data.read(&config, sizeof(struct audio_port_config));
1344 status_t status = setAudioPortConfig(&config);
1345 reply->writeInt32(status);
1346 return NO_ERROR;
1347 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001348 default:
1349 return BBinder::onTransact(code, data, reply, flags);
1350 }
1351}
1352
1353// ----------------------------------------------------------------------------
1354
1355}; // namespace android