blob: 38055f9ec75cb2ec70fc7fe7ef135c4d0eec5203 [file] [log] [blame]
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001/*
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08002**
3** Copyright 2007, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "IAudioFlinger"
Eric Laurentc2f1f072009-07-17 12:17:14 -070019//#define LOG_NDEBUG 0
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080020#include <utils/Log.h>
21
22#include <stdint.h>
23#include <sys/types.h>
24
Mathias Agopian75624082009-05-19 19:08:10 -070025#include <binder/Parcel.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080026
27#include <media/IAudioFlinger.h>
28
29namespace android {
30
31enum {
32 CREATE_TRACK = IBinder::FIRST_CALL_TRANSACTION,
33 OPEN_RECORD,
34 SAMPLE_RATE,
Glenn Kasten5876f2f2012-11-30 10:52:16 -080035 RESERVED, // obsolete, was CHANNEL_COUNT
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080036 FORMAT,
37 FRAME_COUNT,
38 LATENCY,
39 SET_MASTER_VOLUME,
40 SET_MASTER_MUTE,
41 MASTER_VOLUME,
42 MASTER_MUTE,
43 SET_STREAM_VOLUME,
44 SET_STREAM_MUTE,
45 STREAM_VOLUME,
46 STREAM_MUTE,
47 SET_MODE,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080048 SET_MIC_MUTE,
49 GET_MIC_MUTE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070050 SET_PARAMETERS,
51 GET_PARAMETERS,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080052 REGISTER_CLIENT,
53 GET_INPUTBUFFERSIZE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070054 OPEN_OUTPUT,
55 OPEN_DUPLICATE_OUTPUT,
56 CLOSE_OUTPUT,
57 SUSPEND_OUTPUT,
58 RESTORE_OUTPUT,
59 OPEN_INPUT,
60 CLOSE_INPUT,
Glenn Kastend2304db2014-02-03 07:40:31 -080061 INVALIDATE_STREAM,
Eric Laurent342e9cf2010-01-19 17:37:09 -080062 SET_VOICE_VOLUME,
Eric Laurent05bca2f2010-02-26 02:47:27 -080063 GET_RENDER_POSITION,
Eric Laurentbe916aa2010-06-01 23:49:17 -070064 GET_INPUT_FRAMES_LOST,
65 NEW_AUDIO_SESSION_ID,
Marco Nelissen3a34bef2011-08-02 13:33:41 -070066 ACQUIRE_AUDIO_SESSION_ID,
67 RELEASE_AUDIO_SESSION_ID,
Eric Laurentbe916aa2010-06-01 23:49:17 -070068 QUERY_NUM_EFFECTS,
Eric Laurentffe9c252010-06-23 17:38:20 -070069 QUERY_EFFECT,
Eric Laurentbe916aa2010-06-01 23:49:17 -070070 GET_EFFECT_DESCRIPTOR,
Eric Laurentde070132010-07-13 04:45:46 -070071 CREATE_EFFECT,
Eric Laurenta4c5a552012-03-29 10:12:40 -070072 MOVE_EFFECTS,
Glenn Kastencc0f1cf2012-09-24 11:27:18 -070073 LOAD_HW_MODULE,
74 GET_PRIMARY_OUTPUT_SAMPLING_RATE,
75 GET_PRIMARY_OUTPUT_FRAME_COUNT,
Glenn Kasten4182c4e2013-07-15 14:45:07 -070076 SET_LOW_RAM_DEVICE,
Eric Laurent4b123402014-04-11 09:22:20 -070077 LIST_AUDIO_PORTS,
78 GET_AUDIO_PORT,
79 CREATE_AUDIO_PATCH,
80 RELEASE_AUDIO_PATCH,
81 LIST_AUDIO_PATCHES,
Eric Laurent93c3d412014-08-01 14:48:35 -070082 SET_AUDIO_PORT_CONFIG,
83 GET_AUDIO_HW_SYNC
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080084};
85
Eric Laurentf75c2fe2015-04-02 13:49:15 -070086#define MAX_ITEMS_PER_LIST 1024
87
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080088class BpAudioFlinger : public BpInterface<IAudioFlinger>
89{
90public:
91 BpAudioFlinger(const sp<IBinder>& impl)
92 : BpInterface<IAudioFlinger>(impl)
93 {
94 }
95
96 virtual sp<IAudioTrack> createTrack(
Glenn Kastenfff6d712012-01-12 16:38:12 -080097 audio_stream_type_t streamType,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080098 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -080099 audio_format_t format,
Glenn Kastendd8104c2012-07-02 12:42:44 -0700100 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -0800101 size_t *pFrameCount,
Glenn Kastene0b07172012-11-06 15:03:34 -0800102 track_flags_t *flags,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800103 const sp<IMemory>& sharedBuffer,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800104 audio_io_handle_t output,
Glenn Kasten3acbd052012-02-28 10:39:56 -0800105 pid_t tid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700106 int *sessionId,
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800107 int clientUid,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800108 status_t *status)
109 {
110 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700111 sp<IAudioTrack> track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800112 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800113 data.writeInt32((int32_t) streamType);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800114 data.writeInt32(sampleRate);
115 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700116 data.writeInt32(channelMask);
Glenn Kasten74935e42013-12-19 08:56:45 -0800117 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800118 data.writeInt64(frameCount);
Glenn Kastenb26e3e92012-11-14 08:32:08 -0800119 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
Glenn Kastene0b07172012-11-06 15:03:34 -0800120 data.writeInt32(lFlags);
Glenn Kasten2301acc2014-01-17 10:21:00 -0800121 // haveSharedBuffer
Eric Laurent3d00aa62013-09-24 09:53:27 -0700122 if (sharedBuffer != 0) {
123 data.writeInt32(true);
Marco Nelissen06b46062014-11-14 07:58:25 -0800124 data.writeStrongBinder(IInterface::asBinder(sharedBuffer));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700125 } else {
126 data.writeInt32(false);
127 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800128 data.writeInt32((int32_t) output);
Glenn Kasten3acbd052012-02-28 10:39:56 -0800129 data.writeInt32((int32_t) tid);
Glenn Kastenaea7ea02013-06-26 09:25:47 -0700130 int lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700131 if (sessionId != NULL) {
132 lSessionId = *sessionId;
133 }
134 data.writeInt32(lSessionId);
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800135 data.writeInt32(clientUid);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800136 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
137 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000138 ALOGE("createTrack error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700139 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700140 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800141 if (pFrameCount != NULL) {
142 *pFrameCount = frameCount;
143 }
Glenn Kastene0b07172012-11-06 15:03:34 -0800144 lFlags = reply.readInt32();
145 if (flags != NULL) {
146 *flags = lFlags;
147 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700148 lSessionId = reply.readInt32();
149 if (sessionId != NULL) {
150 *sessionId = lSessionId;
151 }
Eric Laurent5841db72009-09-09 05:16:08 -0700152 lStatus = reply.readInt32();
153 track = interface_cast<IAudioTrack>(reply.readStrongBinder());
Glenn Kasten0cde0762014-01-16 15:06:36 -0800154 if (lStatus == NO_ERROR) {
155 if (track == 0) {
156 ALOGE("createTrack should have returned an IAudioTrack");
157 lStatus = UNKNOWN_ERROR;
158 }
159 } else {
160 if (track != 0) {
161 ALOGE("createTrack returned an IAudioTrack but with status %d", lStatus);
162 track.clear();
163 }
164 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800165 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700166 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800167 *status = lStatus;
168 }
Eric Laurent5841db72009-09-09 05:16:08 -0700169 return track;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800170 }
171
172 virtual sp<IAudioRecord> openRecord(
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800173 audio_io_handle_t input,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800174 uint32_t sampleRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800175 audio_format_t format,
Glenn Kasten28b76b32012-07-03 17:24:41 -0700176 audio_channel_mask_t channelMask,
Glenn Kasten74935e42013-12-19 08:56:45 -0800177 size_t *pFrameCount,
Glenn Kasteneeca3262013-07-31 16:12:48 -0700178 track_flags_t *flags,
Glenn Kasten1879fff2012-07-11 15:36:59 -0700179 pid_t tid,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700180 int *sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700181 size_t *notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700182 sp<IMemory>& cblk,
183 sp<IMemory>& buffers,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800184 status_t *status)
185 {
186 Parcel data, reply;
Eric Laurent5841db72009-09-09 05:16:08 -0700187 sp<IAudioRecord> record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800188 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800189 data.writeInt32((int32_t) input);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800190 data.writeInt32(sampleRate);
191 data.writeInt32(format);
Jean-Michel Trivi0d255b22011-05-24 15:53:33 -0700192 data.writeInt32(channelMask);
Glenn Kasten74935e42013-12-19 08:56:45 -0800193 size_t frameCount = pFrameCount != NULL ? *pFrameCount : 0;
Glenn Kastene03dd222014-01-28 11:04:39 -0800194 data.writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700195 track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
196 data.writeInt32(lFlags);
Glenn Kasten1879fff2012-07-11 15:36:59 -0700197 data.writeInt32((int32_t) tid);
Glenn Kastenaea7ea02013-06-26 09:25:47 -0700198 int lSessionId = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700199 if (sessionId != NULL) {
200 lSessionId = *sessionId;
201 }
202 data.writeInt32(lSessionId);
Glenn Kasten74105912014-07-03 12:28:53 -0700203 data.writeInt64(notificationFrames != NULL ? *notificationFrames : 0);
Glenn Kastend776ac62014-05-07 09:16:09 -0700204 cblk.clear();
205 buffers.clear();
Eric Laurent5841db72009-09-09 05:16:08 -0700206 status_t lStatus = remote()->transact(OPEN_RECORD, data, &reply);
207 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000208 ALOGE("openRecord error: %s", strerror(-lStatus));
Eric Laurent5841db72009-09-09 05:16:08 -0700209 } else {
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700210 frameCount = reply.readInt64();
Glenn Kasten74935e42013-12-19 08:56:45 -0800211 if (pFrameCount != NULL) {
212 *pFrameCount = frameCount;
213 }
Glenn Kasteneeca3262013-07-31 16:12:48 -0700214 lFlags = reply.readInt32();
215 if (flags != NULL) {
216 *flags = lFlags;
217 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700218 lSessionId = reply.readInt32();
219 if (sessionId != NULL) {
220 *sessionId = lSessionId;
221 }
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700222 size_t lNotificationFrames = (size_t) reply.readInt64();
223 if (notificationFrames != NULL) {
224 *notificationFrames = lNotificationFrames;
225 }
Eric Laurent5841db72009-09-09 05:16:08 -0700226 lStatus = reply.readInt32();
227 record = interface_cast<IAudioRecord>(reply.readStrongBinder());
Glenn Kastend776ac62014-05-07 09:16:09 -0700228 cblk = interface_cast<IMemory>(reply.readStrongBinder());
229 if (cblk != 0 && cblk->pointer() == NULL) {
230 cblk.clear();
231 }
232 buffers = interface_cast<IMemory>(reply.readStrongBinder());
233 if (buffers != 0 && buffers->pointer() == NULL) {
234 buffers.clear();
235 }
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700236 if (lStatus == NO_ERROR) {
237 if (record == 0) {
238 ALOGE("openRecord should have returned an IAudioRecord");
239 lStatus = UNKNOWN_ERROR;
Glenn Kastend776ac62014-05-07 09:16:09 -0700240 } else if (cblk == 0) {
241 ALOGE("openRecord should have returned a cblk");
242 lStatus = NO_MEMORY;
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700243 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700244 // buffers is permitted to be 0
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700245 } else {
Glenn Kastend776ac62014-05-07 09:16:09 -0700246 if (record != 0 || cblk != 0 || buffers != 0) {
247 ALOGE("openRecord returned an IAudioRecord, cblk, "
248 "or buffers but with status %d", lStatus);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700249 }
250 }
Glenn Kastend776ac62014-05-07 09:16:09 -0700251 if (lStatus != NO_ERROR) {
252 record.clear();
253 cblk.clear();
254 buffers.clear();
255 }
Eric Laurent5841db72009-09-09 05:16:08 -0700256 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700257 if (status != NULL) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800258 *status = lStatus;
259 }
Eric Laurent5841db72009-09-09 05:16:08 -0700260 return record;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800261 }
262
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800263 virtual uint32_t sampleRate(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800264 {
265 Parcel data, reply;
266 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800267 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800268 remote()->transact(SAMPLE_RATE, data, &reply);
269 return reply.readInt32();
270 }
271
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800272 virtual audio_format_t format(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800273 {
274 Parcel data, reply;
275 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800276 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800277 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800278 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800279 }
280
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800281 virtual size_t frameCount(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800282 {
283 Parcel data, reply;
284 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800285 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800286 remote()->transact(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800287 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800288 }
289
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800290 virtual uint32_t latency(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800291 {
292 Parcel data, reply;
293 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800294 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800295 remote()->transact(LATENCY, data, &reply);
296 return reply.readInt32();
297 }
298
299 virtual status_t setMasterVolume(float value)
300 {
301 Parcel data, reply;
302 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
303 data.writeFloat(value);
304 remote()->transact(SET_MASTER_VOLUME, data, &reply);
305 return reply.readInt32();
306 }
307
308 virtual status_t setMasterMute(bool muted)
309 {
310 Parcel data, reply;
311 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
312 data.writeInt32(muted);
313 remote()->transact(SET_MASTER_MUTE, data, &reply);
314 return reply.readInt32();
315 }
316
317 virtual float masterVolume() const
318 {
319 Parcel data, reply;
320 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
321 remote()->transact(MASTER_VOLUME, data, &reply);
322 return reply.readFloat();
323 }
324
325 virtual bool masterMute() const
326 {
327 Parcel data, reply;
328 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
329 remote()->transact(MASTER_MUTE, data, &reply);
330 return reply.readInt32();
331 }
332
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800333 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
334 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800335 {
336 Parcel data, reply;
337 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800338 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800339 data.writeFloat(value);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800340 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800341 remote()->transact(SET_STREAM_VOLUME, data, &reply);
342 return reply.readInt32();
343 }
344
Glenn Kastenfff6d712012-01-12 16:38:12 -0800345 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800346 {
347 Parcel data, reply;
348 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800349 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800350 data.writeInt32(muted);
351 remote()->transact(SET_STREAM_MUTE, data, &reply);
352 return reply.readInt32();
353 }
354
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800355 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800356 {
357 Parcel data, reply;
358 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800359 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800360 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800361 remote()->transact(STREAM_VOLUME, data, &reply);
362 return reply.readFloat();
363 }
364
Glenn Kastenfff6d712012-01-12 16:38:12 -0800365 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800366 {
367 Parcel data, reply;
368 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800369 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800370 remote()->transact(STREAM_MUTE, data, &reply);
371 return reply.readInt32();
372 }
373
Glenn Kastenf78aee72012-01-04 11:00:47 -0800374 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800375 {
376 Parcel data, reply;
377 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
378 data.writeInt32(mode);
379 remote()->transact(SET_MODE, data, &reply);
380 return reply.readInt32();
381 }
382
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800383 virtual status_t setMicMute(bool state)
384 {
385 Parcel data, reply;
386 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
387 data.writeInt32(state);
388 remote()->transact(SET_MIC_MUTE, data, &reply);
389 return reply.readInt32();
390 }
391
392 virtual bool getMicMute() const
393 {
394 Parcel data, reply;
395 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
396 remote()->transact(GET_MIC_MUTE, data, &reply);
397 return reply.readInt32();
398 }
399
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800400 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800401 {
402 Parcel data, reply;
403 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800404 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700405 data.writeString8(keyValuePairs);
406 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800407 return reply.readInt32();
408 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700409
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800410 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700411 {
412 Parcel data, reply;
413 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800414 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700415 data.writeString8(keys);
416 remote()->transact(GET_PARAMETERS, data, &reply);
417 return reply.readString8();
418 }
419
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800420 virtual void registerClient(const sp<IAudioFlingerClient>& client)
421 {
422 Parcel data, reply;
423 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800424 data.writeStrongBinder(IInterface::asBinder(client));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800425 remote()->transact(REGISTER_CLIENT, data, &reply);
426 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700427
Glenn Kastendd8104c2012-07-02 12:42:44 -0700428 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
429 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800430 {
431 Parcel data, reply;
432 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
433 data.writeInt32(sampleRate);
434 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700435 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800436 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800437 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800438 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700439
Eric Laurentcf2c0212014-07-25 16:20:43 -0700440 virtual status_t openOutput(audio_module_handle_t module,
441 audio_io_handle_t *output,
442 audio_config_t *config,
443 audio_devices_t *devices,
444 const String8& address,
445 uint32_t *latencyMs,
446 audio_output_flags_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800447 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700448 if (output == NULL || config == NULL || devices == NULL || latencyMs == NULL) {
449 return BAD_VALUE;
450 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800451 Parcel data, reply;
452 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700453 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700454 data.write(config, sizeof(audio_config_t));
455 data.writeInt32(*devices);
456 data.writeString8(address);
Glenn Kasten18868c52012-03-07 09:15:37 -0800457 data.writeInt32((int32_t) flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700458 status_t status = remote()->transact(OPEN_OUTPUT, data, &reply);
459 if (status != NO_ERROR) {
460 *output = AUDIO_IO_HANDLE_NONE;
461 return status;
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100462 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700463 status = (status_t)reply.readInt32();
464 if (status != NO_ERROR) {
465 *output = AUDIO_IO_HANDLE_NONE;
466 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700467 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700468 *output = (audio_io_handle_t)reply.readInt32();
469 ALOGV("openOutput() returned output, %d", *output);
470 reply.read(config, sizeof(audio_config_t));
471 *devices = (audio_devices_t)reply.readInt32();
472 *latencyMs = reply.readInt32();
473 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800474 }
475
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800476 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
477 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800478 {
479 Parcel data, reply;
480 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800481 data.writeInt32((int32_t) output1);
482 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700483 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800484 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700485 }
486
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800487 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700488 {
489 Parcel data, reply;
490 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800491 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700492 remote()->transact(CLOSE_OUTPUT, data, &reply);
493 return reply.readInt32();
494 }
495
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800496 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700497 {
498 Parcel data, reply;
499 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800500 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700501 remote()->transact(SUSPEND_OUTPUT, data, &reply);
502 return reply.readInt32();
503 }
504
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800505 virtual status_t restoreOutput(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(RESTORE_OUTPUT, data, &reply);
511 return reply.readInt32();
512 }
513
Eric Laurentcf2c0212014-07-25 16:20:43 -0700514 virtual status_t openInput(audio_module_handle_t module,
515 audio_io_handle_t *input,
516 audio_config_t *config,
517 audio_devices_t *device,
518 const String8& address,
519 audio_source_t source,
520 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700521 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700522 if (input == NULL || config == NULL || device == NULL) {
523 return BAD_VALUE;
524 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700525 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700526 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700527 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700528 data.writeInt32(*input);
529 data.write(config, sizeof(audio_config_t));
530 data.writeInt32(*device);
531 data.writeString8(address);
532 data.writeInt32(source);
Glenn Kastenec40d282014-07-15 15:31:26 -0700533 data.writeInt32(flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700534 status_t status = remote()->transact(OPEN_INPUT, data, &reply);
535 if (status != NO_ERROR) {
536 *input = AUDIO_IO_HANDLE_NONE;
537 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700538 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700539 status = (status_t)reply.readInt32();
540 if (status != NO_ERROR) {
541 *input = AUDIO_IO_HANDLE_NONE;
542 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700543 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700544 *input = (audio_io_handle_t)reply.readInt32();
545 reply.read(config, sizeof(audio_config_t));
546 *device = (audio_devices_t)reply.readInt32();
547 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700548 }
549
Eric Laurentfa2877b2009-07-28 08:44:33 -0700550 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700551 {
552 Parcel data, reply;
553 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700554 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700555 remote()->transact(CLOSE_INPUT, data, &reply);
556 return reply.readInt32();
557 }
558
Glenn Kastend2304db2014-02-03 07:40:31 -0800559 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700560 {
561 Parcel data, reply;
562 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800563 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800564 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700565 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800566 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700567
568 virtual status_t setVoiceVolume(float volume)
569 {
570 Parcel data, reply;
571 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
572 data.writeFloat(volume);
573 remote()->transact(SET_VOICE_VOLUME, data, &reply);
574 return reply.readInt32();
575 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800576
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000577 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800578 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800579 {
580 Parcel data, reply;
581 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800582 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800583 remote()->transact(GET_RENDER_POSITION, data, &reply);
584 status_t status = reply.readInt32();
585 if (status == NO_ERROR) {
586 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700587 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800588 *halFrames = tmp;
589 }
590 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700591 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800592 *dspFrames = tmp;
593 }
594 }
595 return status;
596 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800597
Glenn Kasten5f972c02014-01-13 09:59:31 -0800598 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800599 {
600 Parcel data, reply;
601 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800602 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800603 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
604 if (status != NO_ERROR) {
605 return 0;
606 }
607 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800608 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700609
Eric Laurentde3f8392014-07-27 18:38:22 -0700610 virtual audio_unique_id_t newAudioUniqueId()
Eric Laurentbe916aa2010-06-01 23:49:17 -0700611 {
612 Parcel data, reply;
613 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
614 status_t status = remote()->transact(NEW_AUDIO_SESSION_ID, data, &reply);
Eric Laurentde3f8392014-07-27 18:38:22 -0700615 audio_unique_id_t id = AUDIO_SESSION_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700616 if (status == NO_ERROR) {
617 id = reply.readInt32();
618 }
619 return id;
620 }
621
Marco Nelissend457c972014-02-11 08:47:07 -0800622 virtual void acquireAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700623 {
624 Parcel data, reply;
625 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
626 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800627 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700628 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
629 }
630
Marco Nelissend457c972014-02-11 08:47:07 -0800631 virtual void releaseAudioSessionId(int audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700632 {
633 Parcel data, reply;
634 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
635 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800636 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700637 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
638 }
639
Glenn Kastenf587ba52012-01-26 16:25:10 -0800640 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700641 {
642 Parcel data, reply;
643 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
644 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
645 if (status != NO_ERROR) {
646 return status;
647 }
648 status = reply.readInt32();
649 if (status != NO_ERROR) {
650 return status;
651 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800652 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700653 *numEffects = (uint32_t)reply.readInt32();
654 }
655 return NO_ERROR;
656 }
657
Glenn Kastenf587ba52012-01-26 16:25:10 -0800658 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700659 {
660 if (pDescriptor == NULL) {
661 return BAD_VALUE;
662 }
663 Parcel data, reply;
664 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700665 data.writeInt32(index);
666 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700667 if (status != NO_ERROR) {
668 return status;
669 }
670 status = reply.readInt32();
671 if (status != NO_ERROR) {
672 return status;
673 }
674 reply.read(pDescriptor, sizeof(effect_descriptor_t));
675 return NO_ERROR;
676 }
677
Glenn Kasten5e92a782012-01-30 07:40:52 -0800678 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Glenn Kastenf587ba52012-01-26 16:25:10 -0800679 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700680 {
681 if (pUuid == NULL || pDescriptor == NULL) {
682 return BAD_VALUE;
683 }
684 Parcel data, reply;
685 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
686 data.write(pUuid, sizeof(effect_uuid_t));
687 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
688 if (status != NO_ERROR) {
689 return status;
690 }
691 status = reply.readInt32();
692 if (status != NO_ERROR) {
693 return status;
694 }
695 reply.read(pDescriptor, sizeof(effect_descriptor_t));
696 return NO_ERROR;
697 }
698
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800699 virtual sp<IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700700 effect_descriptor_t *pDesc,
701 const sp<IEffectClient>& client,
702 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800703 audio_io_handle_t output,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700704 int sessionId,
705 status_t *status,
706 int *id,
707 int *enabled)
708 {
709 Parcel data, reply;
710 sp<IEffect> effect;
711
712 if (pDesc == NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700713 return effect;
Glenn Kasten507b2862013-07-31 16:12:13 -0700714 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700715 *status = BAD_VALUE;
716 }
717 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700718
719 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700720 data.write(pDesc, sizeof(effect_descriptor_t));
Marco Nelissen06b46062014-11-14 07:58:25 -0800721 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700722 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800723 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700724 data.writeInt32(sessionId);
725
726 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
727 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000728 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700729 } else {
730 lStatus = reply.readInt32();
731 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700732 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700733 *id = tmp;
734 }
735 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800736 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700737 *enabled = tmp;
738 }
739 effect = interface_cast<IEffect>(reply.readStrongBinder());
740 reply.read(pDesc, sizeof(effect_descriptor_t));
741 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700742 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700743 *status = lStatus;
744 }
745
746 return effect;
747 }
Eric Laurentde070132010-07-13 04:45:46 -0700748
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800749 virtual status_t moveEffects(int session, audio_io_handle_t srcOutput,
750 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700751 {
752 Parcel data, reply;
753 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
754 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800755 data.writeInt32((int32_t) srcOutput);
756 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700757 remote()->transact(MOVE_EFFECTS, data, &reply);
758 return reply.readInt32();
759 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700760
761 virtual audio_module_handle_t loadHwModule(const char *name)
762 {
763 Parcel data, reply;
764 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
765 data.writeCString(name);
766 remote()->transact(LOAD_HW_MODULE, data, &reply);
767 return (audio_module_handle_t) reply.readInt32();
768 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700769
Glenn Kasten3b16c762012-11-14 08:44:39 -0800770 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700771 {
772 Parcel data, reply;
773 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
774 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
775 return reply.readInt32();
776 }
777
Glenn Kastene33054e2012-11-14 12:54:39 -0800778 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700779 {
780 Parcel data, reply;
781 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
782 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800783 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700784 }
785
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700786 virtual status_t setLowRamDevice(bool isLowRamDevice)
787 {
788 Parcel data, reply;
789 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
790 data.writeInt32((int) isLowRamDevice);
791 remote()->transact(SET_LOW_RAM_DEVICE, data, &reply);
792 return reply.readInt32();
793 }
Eric Laurent4b123402014-04-11 09:22:20 -0700794 virtual status_t listAudioPorts(unsigned int *num_ports,
795 struct audio_port *ports)
796 {
797 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
798 return BAD_VALUE;
799 }
800 Parcel data, reply;
801 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
802 data.writeInt32(*num_ports);
803 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
804 if (status != NO_ERROR ||
805 (status = (status_t)reply.readInt32()) != NO_ERROR) {
806 return status;
807 }
808 *num_ports = (unsigned int)reply.readInt32();
809 reply.read(ports, *num_ports * sizeof(struct audio_port));
810 return status;
811 }
812 virtual status_t getAudioPort(struct audio_port *port)
813 {
814 if (port == NULL) {
815 return BAD_VALUE;
816 }
817 Parcel data, reply;
818 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
819 data.write(port, sizeof(struct audio_port));
820 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
821 if (status != NO_ERROR ||
822 (status = (status_t)reply.readInt32()) != NO_ERROR) {
823 return status;
824 }
825 reply.read(port, sizeof(struct audio_port));
826 return status;
827 }
828 virtual status_t createAudioPatch(const struct audio_patch *patch,
829 audio_patch_handle_t *handle)
830 {
831 if (patch == NULL || handle == NULL) {
832 return BAD_VALUE;
833 }
834 Parcel data, reply;
835 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
836 data.write(patch, sizeof(struct audio_patch));
837 data.write(handle, sizeof(audio_patch_handle_t));
838 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
839 if (status != NO_ERROR ||
840 (status = (status_t)reply.readInt32()) != NO_ERROR) {
841 return status;
842 }
843 reply.read(handle, sizeof(audio_patch_handle_t));
844 return status;
845 }
846 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
847 {
848 Parcel data, reply;
849 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
850 data.write(&handle, sizeof(audio_patch_handle_t));
851 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
852 if (status != NO_ERROR) {
853 status = (status_t)reply.readInt32();
854 }
855 return status;
856 }
857 virtual status_t listAudioPatches(unsigned int *num_patches,
858 struct audio_patch *patches)
859 {
860 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
861 return BAD_VALUE;
862 }
863 Parcel data, reply;
864 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
865 data.writeInt32(*num_patches);
866 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
867 if (status != NO_ERROR ||
868 (status = (status_t)reply.readInt32()) != NO_ERROR) {
869 return status;
870 }
871 *num_patches = (unsigned int)reply.readInt32();
872 reply.read(patches, *num_patches * sizeof(struct audio_patch));
873 return status;
874 }
875 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
876 {
877 if (config == NULL) {
878 return BAD_VALUE;
879 }
880 Parcel data, reply;
881 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
882 data.write(config, sizeof(struct audio_port_config));
883 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
884 if (status != NO_ERROR) {
885 status = (status_t)reply.readInt32();
886 }
887 return status;
888 }
Eric Laurent93c3d412014-08-01 14:48:35 -0700889 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
890 {
891 Parcel data, reply;
892 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
893 data.writeInt32(sessionId);
894 status_t status = remote()->transact(GET_AUDIO_HW_SYNC, data, &reply);
895 if (status != NO_ERROR) {
896 return AUDIO_HW_SYNC_INVALID;
897 }
898 return (audio_hw_sync_t)reply.readInt32();
899 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800900};
901
902IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
903
904// ----------------------------------------------------------------------
905
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800906status_t BnAudioFlinger::onTransact(
907 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
908{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700909 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800910 case CREATE_TRACK: {
911 CHECK_INTERFACE(IAudioFlinger, data, reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800912 int streamType = data.readInt32();
913 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800914 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700915 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800916 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800917 track_flags_t flags = (track_flags_t) data.readInt32();
Eric Laurent3d00aa62013-09-24 09:53:27 -0700918 bool haveSharedBuffer = data.readInt32() != 0;
919 sp<IMemory> buffer;
920 if (haveSharedBuffer) {
921 buffer = interface_cast<IMemory>(data.readStrongBinder());
922 }
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800923 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kasten3acbd052012-02-28 10:39:56 -0800924 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700925 int sessionId = data.readInt32();
Marco Nelissen462fd2f2013-01-14 14:12:05 -0800926 int clientUid = data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800927 status_t status;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700928 sp<IAudioTrack> track;
929 if ((haveSharedBuffer && (buffer == 0)) ||
930 ((buffer != 0) && (buffer->pointer() == NULL))) {
931 ALOGW("CREATE_TRACK: cannot retrieve shared memory");
932 status = DEAD_OBJECT;
933 } else {
934 track = createTrack(
935 (audio_stream_type_t) streamType, sampleRate, format,
Glenn Kasten74935e42013-12-19 08:56:45 -0800936 channelMask, &frameCount, &flags, buffer, output, tid,
Glenn Kastenc5a17422014-03-13 14:59:59 -0700937 &sessionId, clientUid, &status);
Glenn Kasten0cde0762014-01-16 15:06:36 -0800938 LOG_ALWAYS_FATAL_IF((track != 0) != (status == NO_ERROR));
Eric Laurent3d00aa62013-09-24 09:53:27 -0700939 }
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700940 reply->writeInt64(frameCount);
Glenn Kastene0b07172012-11-06 15:03:34 -0800941 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700942 reply->writeInt32(sessionId);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800943 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800944 reply->writeStrongBinder(IInterface::asBinder(track));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800945 return NO_ERROR;
946 } break;
947 case OPEN_RECORD: {
948 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800949 audio_io_handle_t input = (audio_io_handle_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800950 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -0800951 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -0700952 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -0800953 size_t frameCount = data.readInt64();
Glenn Kastena075db42012-03-06 11:22:44 -0800954 track_flags_t flags = (track_flags_t) data.readInt32();
Glenn Kasten1879fff2012-07-11 15:36:59 -0700955 pid_t tid = (pid_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700956 int sessionId = data.readInt32();
Glenn Kasten74105912014-07-03 12:28:53 -0700957 size_t notificationFrames = data.readInt64();
Glenn Kastend776ac62014-05-07 09:16:09 -0700958 sp<IMemory> cblk;
959 sp<IMemory> buffers;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800960 status_t status;
Glenn Kasten8d6cc842012-02-03 11:06:53 -0800961 sp<IAudioRecord> record = openRecord(input,
Glenn Kastend776ac62014-05-07 09:16:09 -0700962 sampleRate, format, channelMask, &frameCount, &flags, tid, &sessionId,
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700963 &notificationFrames,
Glenn Kastend776ac62014-05-07 09:16:09 -0700964 cblk, buffers, &status);
Glenn Kastene93cf2c2013-09-24 11:52:37 -0700965 LOG_ALWAYS_FATAL_IF((record != 0) != (status == NO_ERROR));
Glenn Kastenb53fc4e2014-05-02 08:03:58 -0700966 reply->writeInt64(frameCount);
Glenn Kasteneeca3262013-07-31 16:12:48 -0700967 reply->writeInt32(flags);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700968 reply->writeInt32(sessionId);
Glenn Kasten7df8c0b2014-07-03 12:23:29 -0700969 reply->writeInt64(notificationFrames);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800970 reply->writeInt32(status);
Marco Nelissen06b46062014-11-14 07:58:25 -0800971 reply->writeStrongBinder(IInterface::asBinder(record));
972 reply->writeStrongBinder(IInterface::asBinder(cblk));
973 reply->writeStrongBinder(IInterface::asBinder(buffers));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800974 return NO_ERROR;
975 } break;
976 case SAMPLE_RATE: {
977 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800978 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800979 return NO_ERROR;
980 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800981 case FORMAT: {
982 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800983 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800984 return NO_ERROR;
985 } break;
986 case FRAME_COUNT: {
987 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800988 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800989 return NO_ERROR;
990 } break;
991 case LATENCY: {
992 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800993 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800994 return NO_ERROR;
995 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700996 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800997 CHECK_INTERFACE(IAudioFlinger, data, reply);
998 reply->writeInt32( setMasterVolume(data.readFloat()) );
999 return NO_ERROR;
1000 } break;
1001 case SET_MASTER_MUTE: {
1002 CHECK_INTERFACE(IAudioFlinger, data, reply);
1003 reply->writeInt32( setMasterMute(data.readInt32()) );
1004 return NO_ERROR;
1005 } break;
1006 case MASTER_VOLUME: {
1007 CHECK_INTERFACE(IAudioFlinger, data, reply);
1008 reply->writeFloat( masterVolume() );
1009 return NO_ERROR;
1010 } break;
1011 case MASTER_MUTE: {
1012 CHECK_INTERFACE(IAudioFlinger, data, reply);
1013 reply->writeInt32( masterMute() );
1014 return NO_ERROR;
1015 } break;
1016 case SET_STREAM_VOLUME: {
1017 CHECK_INTERFACE(IAudioFlinger, data, reply);
1018 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001019 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001020 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001021 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001022 return NO_ERROR;
1023 } break;
1024 case SET_STREAM_MUTE: {
1025 CHECK_INTERFACE(IAudioFlinger, data, reply);
1026 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001027 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001028 return NO_ERROR;
1029 } break;
1030 case STREAM_VOLUME: {
1031 CHECK_INTERFACE(IAudioFlinger, data, reply);
1032 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001033 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001034 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001035 return NO_ERROR;
1036 } break;
1037 case STREAM_MUTE: {
1038 CHECK_INTERFACE(IAudioFlinger, data, reply);
1039 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001040 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001041 return NO_ERROR;
1042 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001043 case SET_MODE: {
1044 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001045 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001046 reply->writeInt32( setMode(mode) );
1047 return NO_ERROR;
1048 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001049 case SET_MIC_MUTE: {
1050 CHECK_INTERFACE(IAudioFlinger, data, reply);
1051 int state = data.readInt32();
1052 reply->writeInt32( setMicMute(state) );
1053 return NO_ERROR;
1054 } break;
1055 case GET_MIC_MUTE: {
1056 CHECK_INTERFACE(IAudioFlinger, data, reply);
1057 reply->writeInt32( getMicMute() );
1058 return NO_ERROR;
1059 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001060 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001061 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001062 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001063 String8 keyValuePairs(data.readString8());
1064 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001065 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001066 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001067 case GET_PARAMETERS: {
1068 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001069 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001070 String8 keys(data.readString8());
1071 reply->writeString8(getParameters(ioHandle, keys));
1072 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001073 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001074
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001075 case REGISTER_CLIENT: {
1076 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001077 sp<IAudioFlingerClient> client = interface_cast<IAudioFlingerClient>(
1078 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001079 registerClient(client);
1080 return NO_ERROR;
1081 } break;
1082 case GET_INPUTBUFFERSIZE: {
1083 CHECK_INTERFACE(IAudioFlinger, data, reply);
1084 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001085 audio_format_t format = (audio_format_t) data.readInt32();
Glenn Kastendd8104c2012-07-02 12:42:44 -07001086 audio_channel_mask_t channelMask = data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001087 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001088 return NO_ERROR;
1089 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001090 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001091 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001092 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001093 audio_config_t config;
1094 data.read(&config, sizeof(audio_config_t));
Eric Laurenta4c5a552012-03-29 10:12:40 -07001095 audio_devices_t devices = (audio_devices_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001096 String8 address(data.readString8());
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001097 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001098 uint32_t latencyMs;
1099 audio_io_handle_t output;
1100 status_t status = openOutput(module, &output, &config,
1101 &devices, address, &latencyMs, flags);
Glenn Kasten70742962014-02-18 08:00:47 -08001102 ALOGV("OPEN_OUTPUT output, %d", output);
Eric Laurentcf2c0212014-07-25 16:20:43 -07001103 reply->writeInt32((int32_t)status);
1104 if (status == NO_ERROR) {
1105 reply->writeInt32((int32_t)output);
1106 reply->write(&config, sizeof(audio_config_t));
1107 reply->writeInt32(devices);
1108 reply->writeInt32(latencyMs);
1109 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001110 return NO_ERROR;
1111 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001112 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001113 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001114 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1115 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1116 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001117 return NO_ERROR;
1118 } break;
1119 case CLOSE_OUTPUT: {
1120 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001121 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001122 return NO_ERROR;
1123 } break;
1124 case SUSPEND_OUTPUT: {
1125 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001126 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001127 return NO_ERROR;
1128 } break;
1129 case RESTORE_OUTPUT: {
1130 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001131 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001132 return NO_ERROR;
1133 } break;
1134 case OPEN_INPUT: {
1135 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001136 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001137 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
1138 audio_config_t config;
1139 data.read(&config, sizeof(audio_config_t));
1140 audio_devices_t device = (audio_devices_t)data.readInt32();
1141 String8 address(data.readString8());
1142 audio_source_t source = (audio_source_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001143 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001144
Eric Laurentcf2c0212014-07-25 16:20:43 -07001145 status_t status = openInput(module, &input, &config,
1146 &device, address, source, flags);
1147 reply->writeInt32((int32_t) status);
1148 if (status == NO_ERROR) {
1149 reply->writeInt32((int32_t) input);
1150 reply->write(&config, sizeof(audio_config_t));
1151 reply->writeInt32(device);
1152 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001153 return NO_ERROR;
1154 } break;
1155 case CLOSE_INPUT: {
1156 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001157 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001158 return NO_ERROR;
1159 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001160 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001161 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001162 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1163 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001164 return NO_ERROR;
1165 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001166 case SET_VOICE_VOLUME: {
1167 CHECK_INTERFACE(IAudioFlinger, data, reply);
1168 float volume = data.readFloat();
1169 reply->writeInt32( setVoiceVolume(volume) );
1170 return NO_ERROR;
1171 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001172 case GET_RENDER_POSITION: {
1173 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001174 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Kévin PETIT377b2ec2014-02-03 12:35:36 +00001175 uint32_t halFrames;
1176 uint32_t dspFrames;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001177 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1178 reply->writeInt32(status);
1179 if (status == NO_ERROR) {
1180 reply->writeInt32(halFrames);
1181 reply->writeInt32(dspFrames);
1182 }
1183 return NO_ERROR;
1184 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001185 case GET_INPUT_FRAMES_LOST: {
1186 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001187 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001188 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001189 return NO_ERROR;
1190 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001191 case NEW_AUDIO_SESSION_ID: {
1192 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentde3f8392014-07-27 18:38:22 -07001193 reply->writeInt32(newAudioUniqueId());
Eric Laurentbe916aa2010-06-01 23:49:17 -07001194 return NO_ERROR;
1195 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001196 case ACQUIRE_AUDIO_SESSION_ID: {
1197 CHECK_INTERFACE(IAudioFlinger, data, reply);
1198 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001199 int pid = data.readInt32();
1200 acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001201 return NO_ERROR;
1202 } break;
1203 case RELEASE_AUDIO_SESSION_ID: {
1204 CHECK_INTERFACE(IAudioFlinger, data, reply);
1205 int audioSession = data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001206 int pid = data.readInt32();
1207 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001208 return NO_ERROR;
1209 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001210 case QUERY_NUM_EFFECTS: {
1211 CHECK_INTERFACE(IAudioFlinger, data, reply);
1212 uint32_t numEffects;
1213 status_t status = queryNumberEffects(&numEffects);
1214 reply->writeInt32(status);
1215 if (status == NO_ERROR) {
1216 reply->writeInt32((int32_t)numEffects);
1217 }
1218 return NO_ERROR;
1219 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001220 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001221 CHECK_INTERFACE(IAudioFlinger, data, reply);
1222 effect_descriptor_t desc;
Eric Laurentffe9c252010-06-23 17:38:20 -07001223 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001224 reply->writeInt32(status);
1225 if (status == NO_ERROR) {
1226 reply->write(&desc, sizeof(effect_descriptor_t));
1227 }
1228 return NO_ERROR;
1229 }
1230 case GET_EFFECT_DESCRIPTOR: {
1231 CHECK_INTERFACE(IAudioFlinger, data, reply);
1232 effect_uuid_t uuid;
1233 data.read(&uuid, sizeof(effect_uuid_t));
1234 effect_descriptor_t desc;
1235 status_t status = getEffectDescriptor(&uuid, &desc);
1236 reply->writeInt32(status);
1237 if (status == NO_ERROR) {
1238 reply->write(&desc, sizeof(effect_descriptor_t));
1239 }
1240 return NO_ERROR;
1241 }
1242 case CREATE_EFFECT: {
1243 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001244 effect_descriptor_t desc;
1245 data.read(&desc, sizeof(effect_descriptor_t));
1246 sp<IEffectClient> client = interface_cast<IEffectClient>(data.readStrongBinder());
1247 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001248 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Eric Laurentbe916aa2010-06-01 23:49:17 -07001249 int sessionId = data.readInt32();
1250 status_t status;
1251 int id;
1252 int enabled;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001253
Glenn Kasten8d6cc842012-02-03 11:06:53 -08001254 sp<IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001255 &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001256 reply->writeInt32(status);
1257 reply->writeInt32(id);
1258 reply->writeInt32(enabled);
Marco Nelissen06b46062014-11-14 07:58:25 -08001259 reply->writeStrongBinder(IInterface::asBinder(effect));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001260 reply->write(&desc, sizeof(effect_descriptor_t));
1261 return NO_ERROR;
1262 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001263 case MOVE_EFFECTS: {
1264 CHECK_INTERFACE(IAudioFlinger, data, reply);
1265 int session = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001266 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1267 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001268 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1269 return NO_ERROR;
1270 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001271 case LOAD_HW_MODULE: {
1272 CHECK_INTERFACE(IAudioFlinger, data, reply);
1273 reply->writeInt32(loadHwModule(data.readCString()));
1274 return NO_ERROR;
1275 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001276 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1277 CHECK_INTERFACE(IAudioFlinger, data, reply);
1278 reply->writeInt32(getPrimaryOutputSamplingRate());
1279 return NO_ERROR;
1280 } break;
1281 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1282 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001283 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001284 return NO_ERROR;
1285 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001286 case SET_LOW_RAM_DEVICE: {
1287 CHECK_INTERFACE(IAudioFlinger, data, reply);
1288 bool isLowRamDevice = data.readInt32() != 0;
1289 reply->writeInt32(setLowRamDevice(isLowRamDevice));
1290 return NO_ERROR;
1291 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001292 case LIST_AUDIO_PORTS: {
1293 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001294 unsigned int numPortsReq = data.readInt32();
1295 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1296 numPortsReq = MAX_ITEMS_PER_LIST;
1297 }
1298 unsigned int numPorts = numPortsReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001299 struct audio_port *ports =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001300 (struct audio_port *)calloc(numPortsReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001301 sizeof(struct audio_port));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001302 if (ports == NULL) {
1303 reply->writeInt32(NO_MEMORY);
1304 reply->writeInt32(0);
1305 return NO_ERROR;
1306 }
1307 status_t status = listAudioPorts(&numPorts, ports);
Eric Laurent4b123402014-04-11 09:22:20 -07001308 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001309 reply->writeInt32(numPorts);
Eric Laurent4b123402014-04-11 09:22:20 -07001310 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001311 if (numPortsReq > numPorts) {
1312 numPortsReq = numPorts;
1313 }
1314 reply->write(ports, numPortsReq * sizeof(struct audio_port));
Eric Laurent4b123402014-04-11 09:22:20 -07001315 }
1316 free(ports);
1317 return NO_ERROR;
1318 } break;
1319 case GET_AUDIO_PORT: {
1320 CHECK_INTERFACE(IAudioFlinger, data, reply);
1321 struct audio_port port;
1322 data.read(&port, sizeof(struct audio_port));
1323 status_t status = getAudioPort(&port);
1324 reply->writeInt32(status);
1325 if (status == NO_ERROR) {
1326 reply->write(&port, sizeof(struct audio_port));
1327 }
1328 return NO_ERROR;
1329 } break;
1330 case CREATE_AUDIO_PATCH: {
1331 CHECK_INTERFACE(IAudioFlinger, data, reply);
1332 struct audio_patch patch;
1333 data.read(&patch, sizeof(struct audio_patch));
1334 audio_patch_handle_t handle;
1335 data.read(&handle, sizeof(audio_patch_handle_t));
1336 status_t status = createAudioPatch(&patch, &handle);
1337 reply->writeInt32(status);
1338 if (status == NO_ERROR) {
1339 reply->write(&handle, sizeof(audio_patch_handle_t));
1340 }
1341 return NO_ERROR;
1342 } break;
1343 case RELEASE_AUDIO_PATCH: {
1344 CHECK_INTERFACE(IAudioFlinger, data, reply);
1345 audio_patch_handle_t handle;
1346 data.read(&handle, sizeof(audio_patch_handle_t));
1347 status_t status = releaseAudioPatch(handle);
1348 reply->writeInt32(status);
1349 return NO_ERROR;
1350 } break;
1351 case LIST_AUDIO_PATCHES: {
1352 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001353 unsigned int numPatchesReq = data.readInt32();
1354 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1355 numPatchesReq = MAX_ITEMS_PER_LIST;
1356 }
1357 unsigned int numPatches = numPatchesReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001358 struct audio_patch *patches =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001359 (struct audio_patch *)calloc(numPatchesReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001360 sizeof(struct audio_patch));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001361 if (patches == NULL) {
1362 reply->writeInt32(NO_MEMORY);
1363 reply->writeInt32(0);
1364 return NO_ERROR;
1365 }
1366 status_t status = listAudioPatches(&numPatches, patches);
Eric Laurent4b123402014-04-11 09:22:20 -07001367 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001368 reply->writeInt32(numPatches);
Eric Laurent4b123402014-04-11 09:22:20 -07001369 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001370 if (numPatchesReq > numPatches) {
1371 numPatchesReq = numPatches;
1372 }
1373 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
Eric Laurent4b123402014-04-11 09:22:20 -07001374 }
1375 free(patches);
1376 return NO_ERROR;
1377 } break;
1378 case SET_AUDIO_PORT_CONFIG: {
1379 CHECK_INTERFACE(IAudioFlinger, data, reply);
1380 struct audio_port_config config;
1381 data.read(&config, sizeof(struct audio_port_config));
1382 status_t status = setAudioPortConfig(&config);
1383 reply->writeInt32(status);
1384 return NO_ERROR;
1385 } break;
Eric Laurent93c3d412014-08-01 14:48:35 -07001386 case GET_AUDIO_HW_SYNC: {
1387 CHECK_INTERFACE(IAudioFlinger, data, reply);
1388 reply->writeInt32(getAudioHwSyncForSession((audio_session_t)data.readInt32()));
1389 return NO_ERROR;
1390 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001391 default:
1392 return BBinder::onTransact(code, data, reply, flags);
1393 }
1394}
1395
1396// ----------------------------------------------------------------------------
1397
Glenn Kasten40bc9062015-03-20 09:09:33 -07001398} // namespace android