blob: 786af536477958eb3448fad333ea95632bb62e5a [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
Eric Laurentb1cc36b2017-12-11 12:14:16 -080025#include <binder/IPCThreadState.h>
Mathias Agopian75624082009-05-19 19:08:10 -070026#include <binder/Parcel.h>
Steven Moreland25a9e552017-04-17 14:30:39 -070027#include "IAudioFlinger.h"
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080028
29namespace android {
30
Eric Laurentf75c2fe2015-04-02 13:49:15 -070031#define MAX_ITEMS_PER_LIST 1024
32
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -080033ConversionResult<media::CreateTrackRequest> IAudioFlinger::CreateTrackInput::toAidl() const {
34 media::CreateTrackRequest aidl;
35 aidl.attr = VALUE_OR_RETURN(legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr));
36 aidl.config = VALUE_OR_RETURN(legacy2aidl_audio_config_t_AudioConfig(config));
37 aidl.clientInfo = VALUE_OR_RETURN(legacy2aidl_AudioClient(clientInfo));
38 aidl.sharedBuffer = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(sharedBuffer));
39 aidl.notificationsPerBuffer = VALUE_OR_RETURN(convertIntegral<int32_t>(notificationsPerBuffer));
40 aidl.speed = speed;
41 aidl.audioTrackCallback = audioTrackCallback;
42 aidl.opPackageName = opPackageName;
43 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_output_flags_mask(flags));
44 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
45 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
46 aidl.selectedDeviceId = VALUE_OR_RETURN(
47 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
48 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
49 return aidl;
50}
51
52ConversionResult<IAudioFlinger::CreateTrackInput>
53IAudioFlinger::CreateTrackInput::fromAidl(const media::CreateTrackRequest& aidl) {
54 IAudioFlinger::CreateTrackInput legacy;
55 legacy.attr = VALUE_OR_RETURN(aidl2legacy_AudioAttributesInternal_audio_attributes_t(aidl.attr));
56 legacy.config = VALUE_OR_RETURN(aidl2legacy_AudioConfig_audio_config_t(aidl.config));
57 legacy.clientInfo = VALUE_OR_RETURN(aidl2legacy_AudioClient(aidl.clientInfo));
58 legacy.sharedBuffer = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.sharedBuffer));
59 legacy.notificationsPerBuffer = VALUE_OR_RETURN(
60 convertIntegral<uint32_t>(aidl.notificationsPerBuffer));
61 legacy.speed = aidl.speed;
62 legacy.audioTrackCallback = aidl.audioTrackCallback;
63 legacy.opPackageName = aidl.opPackageName;
64 legacy.flags = VALUE_OR_RETURN(aidl2legacy_audio_output_flags_mask(aidl.flags));
65 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
66 legacy.notificationFrameCount = VALUE_OR_RETURN(
67 convertIntegral<size_t>(aidl.notificationFrameCount));
68 legacy.selectedDeviceId = VALUE_OR_RETURN(
69 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
70 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
71 return legacy;
72}
73
74ConversionResult<media::CreateTrackResponse>
75IAudioFlinger::CreateTrackOutput::toAidl() const {
76 media::CreateTrackResponse aidl;
77 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_output_flags_mask(flags));
78 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
79 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
80 aidl.selectedDeviceId = VALUE_OR_RETURN(
81 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
82 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
83 aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate));
84 aidl.afFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(afFrameCount));
85 aidl.afSampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(afSampleRate));
86 aidl.afLatencyMs = VALUE_OR_RETURN(convertIntegral<int32_t>(afLatencyMs));
87 aidl.outputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(outputId));
88 aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId));
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -080089 aidl.audioTrack = audioTrack;
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -080090 return aidl;
91}
92
93ConversionResult<IAudioFlinger::CreateTrackOutput>
94IAudioFlinger::CreateTrackOutput::fromAidl(
95 const media::CreateTrackResponse& aidl) {
96 IAudioFlinger::CreateTrackOutput legacy;
97 legacy.flags = VALUE_OR_RETURN(aidl2legacy_audio_output_flags_mask(aidl.flags));
98 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
99 legacy.notificationFrameCount = VALUE_OR_RETURN(
100 convertIntegral<size_t>(aidl.notificationFrameCount));
101 legacy.selectedDeviceId = VALUE_OR_RETURN(
102 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
103 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
104 legacy.sampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate));
105 legacy.afFrameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.afFrameCount));
106 legacy.afSampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.afSampleRate));
107 legacy.afLatencyMs = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.afLatencyMs));
108 legacy.outputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.outputId));
109 legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId));
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800110 legacy.audioTrack = aidl.audioTrack;
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800111 return legacy;
112}
113
114ConversionResult<media::CreateRecordRequest>
115IAudioFlinger::CreateRecordInput::toAidl() const {
116 media::CreateRecordRequest aidl;
117 aidl.attr = VALUE_OR_RETURN(legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr));
118 aidl.config = VALUE_OR_RETURN(legacy2aidl_audio_config_base_t_AudioConfigBase(config));
119 aidl.clientInfo = VALUE_OR_RETURN(legacy2aidl_AudioClient(clientInfo));
120 aidl.opPackageName = VALUE_OR_RETURN(legacy2aidl_String16_string(opPackageName));
121 aidl.riid = VALUE_OR_RETURN(legacy2aidl_audio_unique_id_t_int32_t(riid));
122 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_input_flags_mask(flags));
123 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
124 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
125 aidl.selectedDeviceId = VALUE_OR_RETURN(
126 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
127 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
128 return aidl;
129}
130
131ConversionResult<IAudioFlinger::CreateRecordInput>
132IAudioFlinger::CreateRecordInput::fromAidl(
133 const media::CreateRecordRequest& aidl) {
134 IAudioFlinger::CreateRecordInput legacy;
135 legacy.attr = VALUE_OR_RETURN(aidl2legacy_AudioAttributesInternal_audio_attributes_t(aidl.attr));
136 legacy.config = VALUE_OR_RETURN(aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.config));
137 legacy.clientInfo = VALUE_OR_RETURN(aidl2legacy_AudioClient(aidl.clientInfo));
138 legacy.opPackageName = VALUE_OR_RETURN(aidl2legacy_string_view_String16(aidl.opPackageName));
139 legacy.riid = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_unique_id_t(aidl.riid));
140 legacy.flags = VALUE_OR_RETURN(aidl2legacy_audio_input_flags_mask(aidl.flags));
141 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
142 legacy.notificationFrameCount = VALUE_OR_RETURN(
143 convertIntegral<size_t>(aidl.notificationFrameCount));
144 legacy.selectedDeviceId = VALUE_OR_RETURN(
145 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
146 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
147 return legacy;
148}
149
150ConversionResult<media::CreateRecordResponse>
151IAudioFlinger::CreateRecordOutput::toAidl() const {
152 media::CreateRecordResponse aidl;
153 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_input_flags_mask(flags));
154 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
155 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
156 aidl.selectedDeviceId = VALUE_OR_RETURN(
157 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
158 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
159 aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate));
160 aidl.inputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(inputId));
161 aidl.cblk = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(cblk));
162 aidl.buffers = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(buffers));
163 aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId));
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800164 aidl.audioRecord = audioRecord;
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800165 return aidl;
166}
167
168ConversionResult<IAudioFlinger::CreateRecordOutput>
169IAudioFlinger::CreateRecordOutput::fromAidl(
170 const media::CreateRecordResponse& aidl) {
171 IAudioFlinger::CreateRecordOutput legacy;
172 legacy.flags = VALUE_OR_RETURN(aidl2legacy_audio_input_flags_mask(aidl.flags));
173 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
174 legacy.notificationFrameCount = VALUE_OR_RETURN(
175 convertIntegral<size_t>(aidl.notificationFrameCount));
176 legacy.selectedDeviceId = VALUE_OR_RETURN(
177 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
178 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
179 legacy.sampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate));
180 legacy.inputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.inputId));
181 legacy.cblk = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.cblk));
182 legacy.buffers = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.buffers));
183 legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId));
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800184 legacy.audioRecord = aidl.audioRecord;
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800185 return legacy;
186}
Eric Laurent42896a02019-09-27 15:40:33 -0700187
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800188class BpAudioFlinger : public BpInterface<IAudioFlinger>
189{
190public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -0700191 explicit BpAudioFlinger(const sp<IBinder>& impl)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800192 : BpInterface<IAudioFlinger>(impl)
193 {
194 }
195
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800196 virtual status_t createTrack(const media::CreateTrackRequest& input,
197 media::CreateTrackResponse& output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800198 {
199 Parcel data, reply;
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800200 status_t status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800201 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800202 data.writeParcelable(input);
Eric Laurent21da6472017-11-09 16:29:26 -0800203
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800204 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
205 if (lStatus != NO_ERROR) {
Eric Laurent21da6472017-11-09 16:29:26 -0800206 ALOGE("createTrack transaction error %d", lStatus);
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800207 return DEAD_OBJECT;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800208 }
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800209 status = reply.readInt32();
210 if (status != NO_ERROR) {
211 ALOGE("createTrack returned error %d", status);
212 return status;
Eric Laurent21da6472017-11-09 16:29:26 -0800213 }
214 output.readFromParcel(&reply);
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800215 if (output.audioTrack == 0) {
216 ALOGE("createTrack returned an NULL IAudioTrack with status OK");
217 return DEAD_OBJECT;
218 }
219 return OK;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800220 }
221
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800222 virtual status_t createRecord(const media::CreateRecordRequest& input,
223 media::CreateRecordResponse& output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800224 {
225 Parcel data, reply;
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800226 status_t status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800227 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentf14db3c2017-12-08 14:20:36 -0800228
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800229 data.writeParcelable(input);
Eric Laurentf14db3c2017-12-08 14:20:36 -0800230
231 status_t lStatus = remote()->transact(CREATE_RECORD, data, &reply);
Eric Laurent5841db72009-09-09 05:16:08 -0700232 if (lStatus != NO_ERROR) {
Eric Laurentf14db3c2017-12-08 14:20:36 -0800233 ALOGE("createRecord transaction error %d", lStatus);
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800234 return DEAD_OBJECT;
Eric Laurent5841db72009-09-09 05:16:08 -0700235 }
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800236 status = reply.readInt32();
237 if (status != NO_ERROR) {
238 ALOGE("createRecord returned error %d", status);
239 return status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800240 }
Eric Laurentf14db3c2017-12-08 14:20:36 -0800241
Eric Laurentf14db3c2017-12-08 14:20:36 -0800242 output.readFromParcel(&reply);
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800243 if (output.audioRecord == 0) {
244 ALOGE("createRecord returned a NULL IAudioRecord with status OK");
245 return DEAD_OBJECT;
246 }
247 return OK;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800248 }
249
Glenn Kasten2c073da2016-02-26 09:14:08 -0800250 virtual uint32_t sampleRate(audio_io_handle_t ioHandle) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800251 {
252 Parcel data, reply;
253 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten2c073da2016-02-26 09:14:08 -0800254 data.writeInt32((int32_t) ioHandle);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800255 remote()->transact(SAMPLE_RATE, data, &reply);
256 return reply.readInt32();
257 }
258
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700259 // RESERVED for channelCount()
260
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800261 virtual audio_format_t format(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800262 {
263 Parcel data, reply;
264 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800265 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800266 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800267 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800268 }
269
Glenn Kasten2c073da2016-02-26 09:14:08 -0800270 virtual size_t frameCount(audio_io_handle_t ioHandle) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800271 {
272 Parcel data, reply;
273 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten2c073da2016-02-26 09:14:08 -0800274 data.writeInt32((int32_t) ioHandle);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800275 remote()->transact(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800276 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800277 }
278
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800279 virtual uint32_t latency(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800280 {
281 Parcel data, reply;
282 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800283 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800284 remote()->transact(LATENCY, data, &reply);
285 return reply.readInt32();
286 }
287
288 virtual status_t setMasterVolume(float value)
289 {
290 Parcel data, reply;
291 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
292 data.writeFloat(value);
293 remote()->transact(SET_MASTER_VOLUME, data, &reply);
294 return reply.readInt32();
295 }
296
297 virtual status_t setMasterMute(bool muted)
298 {
299 Parcel data, reply;
300 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
301 data.writeInt32(muted);
302 remote()->transact(SET_MASTER_MUTE, data, &reply);
303 return reply.readInt32();
304 }
305
306 virtual float masterVolume() const
307 {
308 Parcel data, reply;
309 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
310 remote()->transact(MASTER_VOLUME, data, &reply);
311 return reply.readFloat();
312 }
313
314 virtual bool masterMute() const
315 {
316 Parcel data, reply;
317 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
318 remote()->transact(MASTER_MUTE, data, &reply);
319 return reply.readInt32();
320 }
321
Richard Folke Tullberg3fae0372017-01-13 09:04:25 +0100322 status_t setMasterBalance(float balance) override
323 {
324 Parcel data, reply;
325 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
326 data.writeFloat(balance);
327 status_t status = remote()->transact(SET_MASTER_BALANCE, data, &reply);
328 if (status != NO_ERROR) {
329 return status;
330 }
331 return reply.readInt32();
332 }
333
334 status_t getMasterBalance(float *balance) const override
335 {
336 Parcel data, reply;
337 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
338 status_t status = remote()->transact(GET_MASTER_BALANCE, data, &reply);
339 if (status != NO_ERROR) {
340 return status;
341 }
342 status = (status_t)reply.readInt32();
343 if (status != NO_ERROR) {
344 return status;
345 }
346 *balance = reply.readFloat();
347 return NO_ERROR;
348 }
349
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800350 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
351 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800352 {
353 Parcel data, reply;
354 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800355 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800356 data.writeFloat(value);
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(SET_STREAM_VOLUME, data, &reply);
359 return reply.readInt32();
360 }
361
Glenn Kastenfff6d712012-01-12 16:38:12 -0800362 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
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 data.writeInt32(muted);
368 remote()->transact(SET_STREAM_MUTE, data, &reply);
369 return reply.readInt32();
370 }
371
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800372 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800373 {
374 Parcel data, reply;
375 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800376 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800377 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800378 remote()->transact(STREAM_VOLUME, data, &reply);
379 return reply.readFloat();
380 }
381
Glenn Kastenfff6d712012-01-12 16:38:12 -0800382 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800383 {
384 Parcel data, reply;
385 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800386 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800387 remote()->transact(STREAM_MUTE, data, &reply);
388 return reply.readInt32();
389 }
390
Glenn Kastenf78aee72012-01-04 11:00:47 -0800391 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800392 {
393 Parcel data, reply;
394 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
395 data.writeInt32(mode);
396 remote()->transact(SET_MODE, data, &reply);
397 return reply.readInt32();
398 }
399
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800400 virtual status_t setMicMute(bool state)
401 {
402 Parcel data, reply;
403 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
404 data.writeInt32(state);
405 remote()->transact(SET_MIC_MUTE, data, &reply);
406 return reply.readInt32();
407 }
408
409 virtual bool getMicMute() const
410 {
411 Parcel data, reply;
412 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
413 remote()->transact(GET_MIC_MUTE, data, &reply);
414 return reply.readInt32();
415 }
416
Eric Laurent5ada82e2019-08-29 17:53:54 -0700417 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced)
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800418 {
419 Parcel data, reply;
420 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurent5ada82e2019-08-29 17:53:54 -0700421 data.writeInt32(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800422 data.writeInt32(silenced ? 1 : 0);
423 remote()->transact(SET_RECORD_SILENCED, data, &reply);
424 }
425
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800426 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800427 {
428 Parcel data, reply;
429 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800430 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700431 data.writeString8(keyValuePairs);
432 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800433 return reply.readInt32();
434 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700435
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800436 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700437 {
438 Parcel data, reply;
439 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800440 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700441 data.writeString8(keys);
442 remote()->transact(GET_PARAMETERS, data, &reply);
443 return reply.readString8();
444 }
445
Ytai Ben-Tsvi10dc0a62020-09-18 11:31:55 -0700446 virtual void registerClient(const sp<media::IAudioFlingerClient>& client)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800447 {
448 Parcel data, reply;
449 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800450 data.writeStrongBinder(IInterface::asBinder(client));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800451 remote()->transact(REGISTER_CLIENT, data, &reply);
452 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700453
Glenn Kastendd8104c2012-07-02 12:42:44 -0700454 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
455 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800456 {
457 Parcel data, reply;
458 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
459 data.writeInt32(sampleRate);
460 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700461 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800462 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800463 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800464 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700465
Ytai Ben-Tsvi50e016a2020-11-12 14:26:12 -0800466 virtual status_t openOutput(const media::OpenOutputRequest& request,
467 media::OpenOutputResponse* response)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800468 {
Ytai Ben-Tsvi50e016a2020-11-12 14:26:12 -0800469 status_t status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800470 Parcel data, reply;
Ytai Ben-Tsvi50e016a2020-11-12 14:26:12 -0800471 return data.writeParcelable(request)
472 ?: remote()->transact(OPEN_OUTPUT, data, &reply)
473 ?: data.readInt32(&status)
474 ?: status
475 ?: data.readParcelable(response);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800476 }
477
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800478 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
479 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800480 {
481 Parcel data, reply;
482 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800483 data.writeInt32((int32_t) output1);
484 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700485 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800486 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700487 }
488
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800489 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700490 {
491 Parcel data, reply;
492 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800493 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700494 remote()->transact(CLOSE_OUTPUT, data, &reply);
495 return reply.readInt32();
496 }
497
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800498 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700499 {
500 Parcel data, reply;
501 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800502 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700503 remote()->transact(SUSPEND_OUTPUT, data, &reply);
504 return reply.readInt32();
505 }
506
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800507 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700508 {
509 Parcel data, reply;
510 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800511 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700512 remote()->transact(RESTORE_OUTPUT, data, &reply);
513 return reply.readInt32();
514 }
515
Ytai Ben-Tsvi12a0b842020-11-05 13:47:32 -0800516 virtual status_t openInput(const media::OpenInputRequest& request,
517 media::OpenInputResponse* response)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700518 {
519 Parcel data, reply;
Ytai Ben-Tsvi12a0b842020-11-05 13:47:32 -0800520 status_t status;
521 return data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor())
522 ?: data.writeParcelable(request)
523 ?: remote()->transact(OPEN_INPUT, data, &reply)
524 ?: reply.readInt32(&status)
525 ?: status
526 ?: reply.readParcelable(response);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700527 }
528
Eric Laurentfa2877b2009-07-28 08:44:33 -0700529 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700530 {
531 Parcel data, reply;
532 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700533 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700534 remote()->transact(CLOSE_INPUT, data, &reply);
535 return reply.readInt32();
536 }
537
Glenn Kastend2304db2014-02-03 07:40:31 -0800538 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700539 {
540 Parcel data, reply;
541 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800542 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800543 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700544 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800545 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700546
547 virtual status_t setVoiceVolume(float volume)
548 {
549 Parcel data, reply;
550 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
551 data.writeFloat(volume);
552 remote()->transact(SET_VOICE_VOLUME, data, &reply);
553 return reply.readInt32();
554 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800555
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000556 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800557 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800558 {
559 Parcel data, reply;
560 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800561 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800562 remote()->transact(GET_RENDER_POSITION, data, &reply);
563 status_t status = reply.readInt32();
564 if (status == NO_ERROR) {
565 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700566 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800567 *halFrames = tmp;
568 }
569 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700570 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800571 *dspFrames = tmp;
572 }
573 }
574 return status;
575 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800576
Glenn Kasten5f972c02014-01-13 09:59:31 -0800577 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800578 {
579 Parcel data, reply;
580 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800581 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800582 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
583 if (status != NO_ERROR) {
584 return 0;
585 }
586 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800587 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700588
Glenn Kasteneeecb982016-02-26 10:44:04 -0800589 virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use)
Eric Laurentbe916aa2010-06-01 23:49:17 -0700590 {
591 Parcel data, reply;
592 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasteneeecb982016-02-26 10:44:04 -0800593 data.writeInt32((int32_t) use);
Glenn Kasten9eae0362016-04-19 09:09:14 -0700594 status_t status = remote()->transact(NEW_AUDIO_UNIQUE_ID, data, &reply);
595 audio_unique_id_t id = AUDIO_UNIQUE_ID_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700596 if (status == NO_ERROR) {
597 id = reply.readInt32();
598 }
599 return id;
600 }
601
Andy Hung8b0bfd92019-12-23 13:11:11 -0800602 void acquireAudioSessionId(audio_session_t audioSession, pid_t pid, uid_t uid) override
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700603 {
604 Parcel data, reply;
605 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
606 data.writeInt32(audioSession);
Andy Hung8b0bfd92019-12-23 13:11:11 -0800607 data.writeInt32((int32_t)pid);
608 data.writeInt32((int32_t)uid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700609 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
610 }
611
Glenn Kastend848eb42016-03-08 13:42:11 -0800612 virtual void releaseAudioSessionId(audio_session_t audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700613 {
614 Parcel data, reply;
615 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
616 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800617 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700618 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
619 }
620
Glenn Kastenf587ba52012-01-26 16:25:10 -0800621 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700622 {
623 Parcel data, reply;
624 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
625 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
626 if (status != NO_ERROR) {
627 return status;
628 }
629 status = reply.readInt32();
630 if (status != NO_ERROR) {
631 return status;
632 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800633 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700634 *numEffects = (uint32_t)reply.readInt32();
635 }
636 return NO_ERROR;
637 }
638
Glenn Kastenf587ba52012-01-26 16:25:10 -0800639 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700640 {
641 if (pDescriptor == NULL) {
642 return BAD_VALUE;
643 }
644 Parcel data, reply;
645 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700646 data.writeInt32(index);
647 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700648 if (status != NO_ERROR) {
649 return status;
650 }
651 status = reply.readInt32();
652 if (status != NO_ERROR) {
653 return status;
654 }
655 reply.read(pDescriptor, sizeof(effect_descriptor_t));
656 return NO_ERROR;
657 }
658
Glenn Kasten5e92a782012-01-30 07:40:52 -0800659 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -0700660 const effect_uuid_t *pType,
661 uint32_t preferredTypeFlag,
662 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700663 {
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -0700664 if (pUuid == NULL || pType == NULL || pDescriptor == NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700665 return BAD_VALUE;
666 }
667 Parcel data, reply;
668 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
669 data.write(pUuid, sizeof(effect_uuid_t));
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -0700670 data.write(pType, sizeof(effect_uuid_t));
671 data.writeUint32(preferredTypeFlag);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700672 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
673 if (status != NO_ERROR) {
674 return status;
675 }
676 status = reply.readInt32();
677 if (status != NO_ERROR) {
678 return status;
679 }
680 reply.read(pDescriptor, sizeof(effect_descriptor_t));
681 return NO_ERROR;
682 }
683
Ytai Ben-Tsvice182942020-11-04 14:48:01 -0800684 virtual status_t createEffect(const media::CreateEffectRequest& request,
685 media::CreateEffectResponse* response)
Eric Laurentbe916aa2010-06-01 23:49:17 -0700686 {
687 Parcel data, reply;
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700688 sp<media::IEffect> effect;
Ytai Ben-Tsvice182942020-11-04 14:48:01 -0800689 if (response == nullptr) {
690 return BAD_VALUE;
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700691 }
Ytai Ben-Tsvice182942020-11-04 14:48:01 -0800692 status_t status;
693 status_t lStatus = data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor())
694 ?: data.writeParcelable(request)
695 ?: remote()->transact(CREATE_EFFECT, data, &reply)
696 ?: reply.readInt32(&status)
697 ?: reply.readParcelable(response)
698 ?: status;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700699 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000700 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700701 }
Ytai Ben-Tsvice182942020-11-04 14:48:01 -0800702 return lStatus;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700703 }
Eric Laurentde070132010-07-13 04:45:46 -0700704
Glenn Kastend848eb42016-03-08 13:42:11 -0800705 virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800706 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700707 {
708 Parcel data, reply;
709 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
710 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800711 data.writeInt32((int32_t) srcOutput);
712 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700713 remote()->transact(MOVE_EFFECTS, data, &reply);
714 return reply.readInt32();
715 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700716
Eric Laurentb20cf7d2019-04-05 19:37:34 -0700717 virtual void setEffectSuspended(int effectId,
718 audio_session_t sessionId,
719 bool suspended)
720 {
721 Parcel data, reply;
722 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
723 data.writeInt32(effectId);
724 data.writeInt32(sessionId);
725 data.writeInt32(suspended ? 1 : 0);
726 remote()->transact(SET_EFFECT_SUSPENDED, data, &reply);
727 }
728
Eric Laurenta4c5a552012-03-29 10:12:40 -0700729 virtual audio_module_handle_t loadHwModule(const char *name)
730 {
731 Parcel data, reply;
732 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
733 data.writeCString(name);
734 remote()->transact(LOAD_HW_MODULE, data, &reply);
735 return (audio_module_handle_t) reply.readInt32();
736 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700737
Glenn Kasten3b16c762012-11-14 08:44:39 -0800738 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700739 {
740 Parcel data, reply;
741 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
742 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
743 return reply.readInt32();
744 }
745
Glenn Kastene33054e2012-11-14 12:54:39 -0800746 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700747 {
748 Parcel data, reply;
749 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
750 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800751 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700752 }
753
Andy Hung6f248bb2018-01-23 14:04:37 -0800754 virtual status_t setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) override
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700755 {
756 Parcel data, reply;
Andy Hung6f248bb2018-01-23 14:04:37 -0800757
758 static_assert(NO_ERROR == 0, "NO_ERROR must be 0");
759 return data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor())
760 ?: data.writeInt32((int) isLowRamDevice)
761 ?: data.writeInt64(totalMemory)
762 ?: remote()->transact(SET_LOW_RAM_DEVICE, data, &reply)
763 ?: reply.readInt32();
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700764 }
Andy Hung6f248bb2018-01-23 14:04:37 -0800765
Eric Laurent4b123402014-04-11 09:22:20 -0700766 virtual status_t listAudioPorts(unsigned int *num_ports,
767 struct audio_port *ports)
768 {
769 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
770 return BAD_VALUE;
771 }
772 Parcel data, reply;
773 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
774 data.writeInt32(*num_ports);
775 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
776 if (status != NO_ERROR ||
777 (status = (status_t)reply.readInt32()) != NO_ERROR) {
778 return status;
779 }
780 *num_ports = (unsigned int)reply.readInt32();
781 reply.read(ports, *num_ports * sizeof(struct audio_port));
782 return status;
783 }
jiabinb4fed192020-09-22 14:45:40 -0700784 virtual status_t getAudioPort(struct audio_port_v7 *port)
Eric Laurent4b123402014-04-11 09:22:20 -0700785 {
jiabinb4fed192020-09-22 14:45:40 -0700786 if (port == nullptr) {
Eric Laurent4b123402014-04-11 09:22:20 -0700787 return BAD_VALUE;
788 }
789 Parcel data, reply;
790 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
jiabinb4fed192020-09-22 14:45:40 -0700791 data.write(port, sizeof(struct audio_port_v7));
Eric Laurent4b123402014-04-11 09:22:20 -0700792 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
793 if (status != NO_ERROR ||
794 (status = (status_t)reply.readInt32()) != NO_ERROR) {
795 return status;
796 }
797 reply.read(port, sizeof(struct audio_port));
798 return status;
799 }
800 virtual status_t createAudioPatch(const struct audio_patch *patch,
801 audio_patch_handle_t *handle)
802 {
803 if (patch == NULL || handle == NULL) {
804 return BAD_VALUE;
805 }
806 Parcel data, reply;
807 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
808 data.write(patch, sizeof(struct audio_patch));
809 data.write(handle, sizeof(audio_patch_handle_t));
810 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
811 if (status != NO_ERROR ||
812 (status = (status_t)reply.readInt32()) != NO_ERROR) {
813 return status;
814 }
815 reply.read(handle, sizeof(audio_patch_handle_t));
816 return status;
817 }
818 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
819 {
820 Parcel data, reply;
821 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
822 data.write(&handle, sizeof(audio_patch_handle_t));
823 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
824 if (status != NO_ERROR) {
825 status = (status_t)reply.readInt32();
826 }
827 return status;
828 }
829 virtual status_t listAudioPatches(unsigned int *num_patches,
830 struct audio_patch *patches)
831 {
832 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
833 return BAD_VALUE;
834 }
835 Parcel data, reply;
836 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
837 data.writeInt32(*num_patches);
838 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
839 if (status != NO_ERROR ||
840 (status = (status_t)reply.readInt32()) != NO_ERROR) {
841 return status;
842 }
843 *num_patches = (unsigned int)reply.readInt32();
844 reply.read(patches, *num_patches * sizeof(struct audio_patch));
845 return status;
846 }
847 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
848 {
849 if (config == NULL) {
850 return BAD_VALUE;
851 }
852 Parcel data, reply;
853 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
854 data.write(config, sizeof(struct audio_port_config));
855 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
856 if (status != NO_ERROR) {
857 status = (status_t)reply.readInt32();
858 }
859 return status;
860 }
Eric Laurent93c3d412014-08-01 14:48:35 -0700861 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
862 {
863 Parcel data, reply;
864 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
865 data.writeInt32(sessionId);
Glenn Kasten9eae0362016-04-19 09:09:14 -0700866 status_t status = remote()->transact(GET_AUDIO_HW_SYNC_FOR_SESSION, data, &reply);
Eric Laurent93c3d412014-08-01 14:48:35 -0700867 if (status != NO_ERROR) {
868 return AUDIO_HW_SYNC_INVALID;
869 }
870 return (audio_hw_sync_t)reply.readInt32();
871 }
Eric Laurent72e3f392015-05-20 14:43:50 -0700872 virtual status_t systemReady()
873 {
874 Parcel data, reply;
875 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
876 return remote()->transact(SYSTEM_READY, data, &reply, IBinder::FLAG_ONEWAY);
877 }
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700878 virtual size_t frameCountHAL(audio_io_handle_t ioHandle) const
879 {
880 Parcel data, reply;
881 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
882 data.writeInt32((int32_t) ioHandle);
883 status_t status = remote()->transact(FRAME_COUNT_HAL, data, &reply);
884 if (status != NO_ERROR) {
885 return 0;
886 }
887 return reply.readInt64();
888 }
jiabin46a76fa2018-01-05 10:18:21 -0800889 virtual status_t getMicrophones(std::vector<media::MicrophoneInfo> *microphones)
890 {
891 Parcel data, reply;
892 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
jiabin9ff780e2018-03-19 18:19:52 -0700893 status_t status = remote()->transact(GET_MICROPHONES, data, &reply);
jiabin46a76fa2018-01-05 10:18:21 -0800894 if (status != NO_ERROR ||
895 (status = (status_t)reply.readInt32()) != NO_ERROR) {
896 return status;
897 }
898 status = reply.readParcelableVector(microphones);
899 return status;
900 }
Eric Laurent42896a02019-09-27 15:40:33 -0700901 virtual status_t setAudioHalPids(const std::vector<pid_t>& pids)
902 {
903 Parcel data, reply;
904 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
905 data.writeInt32(pids.size());
906 for (auto pid : pids) {
907 data.writeInt32(pid);
908 }
909 status_t status = remote()->transact(SET_AUDIO_HAL_PIDS, data, &reply);
910 if (status != NO_ERROR) {
911 return status;
912 }
913 return static_cast <status_t> (reply.readInt32());
914 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800915};
916
917IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
918
919// ----------------------------------------------------------------------
920
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800921status_t BnAudioFlinger::onTransact(
922 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
923{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700924 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800925 case CREATE_TRACK: {
926 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurent21da6472017-11-09 16:29:26 -0800927
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800928 media::CreateTrackRequest input;
929 if (data.readParcelable(&input) != NO_ERROR) {
Eric Laurent21da6472017-11-09 16:29:26 -0800930 reply->writeInt32(DEAD_OBJECT);
931 return NO_ERROR;
Eric Laurent3d00aa62013-09-24 09:53:27 -0700932 }
Eric Laurent21da6472017-11-09 16:29:26 -0800933
934 status_t status;
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800935 media::CreateTrackResponse output;
Eric Laurent21da6472017-11-09 16:29:26 -0800936
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800937 status = createTrack(input, output);
Eric Laurent21da6472017-11-09 16:29:26 -0800938
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800939 LOG_ALWAYS_FATAL_IF((output.audioTrack != 0) != (status == NO_ERROR));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800940 reply->writeInt32(status);
Eric Laurent21da6472017-11-09 16:29:26 -0800941 if (status != NO_ERROR) {
942 return NO_ERROR;
943 }
Eric Laurent21da6472017-11-09 16:29:26 -0800944 output.writeToParcel(reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800945 return NO_ERROR;
946 } break;
Eric Laurentf14db3c2017-12-08 14:20:36 -0800947 case CREATE_RECORD: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800948 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf14db3c2017-12-08 14:20:36 -0800949
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800950 media::CreateRecordRequest input;
951 if (data.readParcelable(&input) != NO_ERROR) {
Eric Laurentf14db3c2017-12-08 14:20:36 -0800952 reply->writeInt32(DEAD_OBJECT);
953 return NO_ERROR;
954 }
955
956 status_t status;
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800957 media::CreateRecordResponse output;
Eric Laurentf14db3c2017-12-08 14:20:36 -0800958
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800959 status = createRecord(input, output);
Eric Laurentf14db3c2017-12-08 14:20:36 -0800960
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800961 LOG_ALWAYS_FATAL_IF((output.audioRecord != 0) != (status == NO_ERROR));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800962 reply->writeInt32(status);
Eric Laurentf14db3c2017-12-08 14:20:36 -0800963 if (status != NO_ERROR) {
964 return NO_ERROR;
965 }
Eric Laurentf14db3c2017-12-08 14:20:36 -0800966 output.writeToParcel(reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800967 return NO_ERROR;
968 } break;
969 case SAMPLE_RATE: {
970 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800971 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800972 return NO_ERROR;
973 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700974
975 // RESERVED for channelCount()
976
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800977 case FORMAT: {
978 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800979 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800980 return NO_ERROR;
981 } break;
982 case FRAME_COUNT: {
983 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800984 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800985 return NO_ERROR;
986 } break;
987 case LATENCY: {
988 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800989 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800990 return NO_ERROR;
991 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700992 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800993 CHECK_INTERFACE(IAudioFlinger, data, reply);
994 reply->writeInt32( setMasterVolume(data.readFloat()) );
995 return NO_ERROR;
996 } break;
997 case SET_MASTER_MUTE: {
998 CHECK_INTERFACE(IAudioFlinger, data, reply);
999 reply->writeInt32( setMasterMute(data.readInt32()) );
1000 return NO_ERROR;
1001 } break;
1002 case MASTER_VOLUME: {
1003 CHECK_INTERFACE(IAudioFlinger, data, reply);
1004 reply->writeFloat( masterVolume() );
1005 return NO_ERROR;
1006 } break;
1007 case MASTER_MUTE: {
1008 CHECK_INTERFACE(IAudioFlinger, data, reply);
1009 reply->writeInt32( masterMute() );
1010 return NO_ERROR;
1011 } break;
Richard Folke Tullberg3fae0372017-01-13 09:04:25 +01001012 case SET_MASTER_BALANCE: {
1013 CHECK_INTERFACE(IAudioFlinger, data, reply);
1014 reply->writeInt32( setMasterBalance(data.readFloat()) );
1015 return NO_ERROR;
1016 } break;
1017 case GET_MASTER_BALANCE: {
1018 CHECK_INTERFACE(IAudioFlinger, data, reply);
1019 float f;
1020 const status_t status = getMasterBalance(&f);
1021 reply->writeInt32((int32_t)status);
1022 if (status == NO_ERROR) {
1023 (void)reply->writeFloat(f);
1024 }
1025 return NO_ERROR;
1026 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001027 case SET_STREAM_VOLUME: {
1028 CHECK_INTERFACE(IAudioFlinger, data, reply);
1029 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001030 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001031 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001032 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001033 return NO_ERROR;
1034 } break;
1035 case SET_STREAM_MUTE: {
1036 CHECK_INTERFACE(IAudioFlinger, data, reply);
1037 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001038 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001039 return NO_ERROR;
1040 } break;
1041 case STREAM_VOLUME: {
1042 CHECK_INTERFACE(IAudioFlinger, data, reply);
1043 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001044 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001045 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001046 return NO_ERROR;
1047 } break;
1048 case STREAM_MUTE: {
1049 CHECK_INTERFACE(IAudioFlinger, data, reply);
1050 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001051 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001052 return NO_ERROR;
1053 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001054 case SET_MODE: {
1055 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001056 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001057 reply->writeInt32( setMode(mode) );
1058 return NO_ERROR;
1059 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001060 case SET_MIC_MUTE: {
1061 CHECK_INTERFACE(IAudioFlinger, data, reply);
1062 int state = data.readInt32();
1063 reply->writeInt32( setMicMute(state) );
1064 return NO_ERROR;
1065 } break;
1066 case GET_MIC_MUTE: {
1067 CHECK_INTERFACE(IAudioFlinger, data, reply);
1068 reply->writeInt32( getMicMute() );
1069 return NO_ERROR;
1070 } break;
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001071 case SET_RECORD_SILENCED: {
1072 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurent5ada82e2019-08-29 17:53:54 -07001073 audio_port_handle_t portId = data.readInt32();
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001074 bool silenced = data.readInt32() == 1;
Eric Laurent5ada82e2019-08-29 17:53:54 -07001075 setRecordSilenced(portId, silenced);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001076 return NO_ERROR;
1077 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001078 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001079 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001080 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001081 String8 keyValuePairs(data.readString8());
1082 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001083 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001084 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001085 case GET_PARAMETERS: {
1086 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001087 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001088 String8 keys(data.readString8());
1089 reply->writeString8(getParameters(ioHandle, keys));
1090 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001091 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001092
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001093 case REGISTER_CLIENT: {
1094 CHECK_INTERFACE(IAudioFlinger, data, reply);
Ytai Ben-Tsvi10dc0a62020-09-18 11:31:55 -07001095 sp<media::IAudioFlingerClient> client = interface_cast<media::IAudioFlingerClient>(
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001096 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001097 registerClient(client);
1098 return NO_ERROR;
1099 } break;
1100 case GET_INPUTBUFFERSIZE: {
1101 CHECK_INTERFACE(IAudioFlinger, data, reply);
1102 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001103 audio_format_t format = (audio_format_t) data.readInt32();
Mikhail Naganov55773032020-10-01 15:08:13 -07001104 audio_channel_mask_t channelMask = (audio_channel_mask_t) data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001105 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001106 return NO_ERROR;
1107 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001108 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001109 CHECK_INTERFACE(IAudioFlinger, data, reply);
Ytai Ben-Tsvi50e016a2020-11-12 14:26:12 -08001110 status_t status;
1111 media::OpenOutputRequest request;
1112 media::OpenOutputResponse response;
1113 return data.readParcelable(&request)
1114 ?: (status = openOutput(request, &response), OK)
1115 ?: reply->writeInt32(status)
1116 ?: reply->writeParcelable(response);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001117 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001118 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001119 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001120 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1121 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1122 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001123 return NO_ERROR;
1124 } break;
1125 case CLOSE_OUTPUT: {
1126 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001127 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001128 return NO_ERROR;
1129 } break;
1130 case SUSPEND_OUTPUT: {
1131 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001132 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001133 return NO_ERROR;
1134 } break;
1135 case RESTORE_OUTPUT: {
1136 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001137 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001138 return NO_ERROR;
1139 } break;
1140 case OPEN_INPUT: {
1141 CHECK_INTERFACE(IAudioFlinger, data, reply);
Ytai Ben-Tsvi12a0b842020-11-05 13:47:32 -08001142 media::OpenInputRequest request;
1143 media::OpenInputResponse response;
1144 status_t status;
1145 return data.readParcelable(&request)
1146 ?: (status = openInput(request, &response), OK)
1147 ?: reply->writeInt32(status)
1148 ?: reply->writeParcelable(response);
Eric Laurentc2f1f072009-07-17 12:17:14 -07001149 } break;
1150 case CLOSE_INPUT: {
1151 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001152 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001153 return NO_ERROR;
1154 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001155 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001156 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001157 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1158 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001159 return NO_ERROR;
1160 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001161 case SET_VOICE_VOLUME: {
1162 CHECK_INTERFACE(IAudioFlinger, data, reply);
1163 float volume = data.readFloat();
1164 reply->writeInt32( setVoiceVolume(volume) );
1165 return NO_ERROR;
1166 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001167 case GET_RENDER_POSITION: {
1168 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001169 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001170 uint32_t halFrames = 0;
1171 uint32_t dspFrames = 0;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001172 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1173 reply->writeInt32(status);
1174 if (status == NO_ERROR) {
1175 reply->writeInt32(halFrames);
1176 reply->writeInt32(dspFrames);
1177 }
1178 return NO_ERROR;
1179 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001180 case GET_INPUT_FRAMES_LOST: {
1181 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001182 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001183 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001184 return NO_ERROR;
1185 } break;
Glenn Kasten9eae0362016-04-19 09:09:14 -07001186 case NEW_AUDIO_UNIQUE_ID: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001187 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasteneeecb982016-02-26 10:44:04 -08001188 reply->writeInt32(newAudioUniqueId((audio_unique_id_use_t) data.readInt32()));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001189 return NO_ERROR;
1190 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001191 case ACQUIRE_AUDIO_SESSION_ID: {
1192 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001193 audio_session_t audioSession = (audio_session_t) data.readInt32();
Andy Hung8b0bfd92019-12-23 13:11:11 -08001194 const pid_t pid = (pid_t)data.readInt32();
1195 const uid_t uid = (uid_t)data.readInt32();
1196 acquireAudioSessionId(audioSession, pid, uid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001197 return NO_ERROR;
1198 } break;
1199 case RELEASE_AUDIO_SESSION_ID: {
1200 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001201 audio_session_t audioSession = (audio_session_t) data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001202 int pid = data.readInt32();
1203 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001204 return NO_ERROR;
1205 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001206 case QUERY_NUM_EFFECTS: {
1207 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001208 uint32_t numEffects = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001209 status_t status = queryNumberEffects(&numEffects);
1210 reply->writeInt32(status);
1211 if (status == NO_ERROR) {
1212 reply->writeInt32((int32_t)numEffects);
1213 }
1214 return NO_ERROR;
1215 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001216 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001217 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001218 effect_descriptor_t desc = {};
Eric Laurentffe9c252010-06-23 17:38:20 -07001219 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001220 reply->writeInt32(status);
1221 if (status == NO_ERROR) {
1222 reply->write(&desc, sizeof(effect_descriptor_t));
1223 }
1224 return NO_ERROR;
1225 }
1226 case GET_EFFECT_DESCRIPTOR: {
1227 CHECK_INTERFACE(IAudioFlinger, data, reply);
Andy Hungf85d1292019-08-21 14:45:41 -07001228 effect_uuid_t uuid = {};
1229 if (data.read(&uuid, sizeof(effect_uuid_t)) != NO_ERROR) {
1230 android_errorWriteLog(0x534e4554, "139417189");
1231 }
1232 effect_uuid_t type = {};
1233 if (data.read(&type, sizeof(effect_uuid_t)) != NO_ERROR) {
1234 android_errorWriteLog(0x534e4554, "139417189");
1235 }
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -07001236 uint32_t preferredTypeFlag = data.readUint32();
Wei Jia983dca32015-09-10 09:47:29 -07001237 effect_descriptor_t desc = {};
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -07001238 status_t status = getEffectDescriptor(&uuid, &type, preferredTypeFlag, &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001239 reply->writeInt32(status);
1240 if (status == NO_ERROR) {
1241 reply->write(&desc, sizeof(effect_descriptor_t));
1242 }
1243 return NO_ERROR;
1244 }
1245 case CREATE_EFFECT: {
1246 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentb6436272016-12-07 19:24:50 -08001247
Ytai Ben-Tsvice182942020-11-04 14:48:01 -08001248 media::CreateEffectRequest request;
1249 media::CreateEffectResponse response;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001250
Ytai Ben-Tsvice182942020-11-04 14:48:01 -08001251 return data.readParcelable(&request)
1252 ?: reply->writeInt32(createEffect(request, &response))
1253 ?: reply->writeParcelable(response);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001254 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001255 case MOVE_EFFECTS: {
1256 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001257 audio_session_t session = (audio_session_t) data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001258 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1259 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001260 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1261 return NO_ERROR;
1262 } break;
Eric Laurentb20cf7d2019-04-05 19:37:34 -07001263 case SET_EFFECT_SUSPENDED: {
1264 CHECK_INTERFACE(IAudioFlinger, data, reply);
1265 int effectId = data.readInt32();
1266 audio_session_t sessionId = (audio_session_t) data.readInt32();
1267 bool suspended = data.readInt32() == 1;
1268 setEffectSuspended(effectId, sessionId, suspended);
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);
Andy Hung6f248bb2018-01-23 14:04:37 -08001288 int32_t isLowRamDevice;
1289 int64_t totalMemory;
1290 const status_t status =
1291 data.readInt32(&isLowRamDevice) ?:
1292 data.readInt64(&totalMemory) ?:
1293 setLowRamDevice(isLowRamDevice != 0, totalMemory);
1294 (void)reply->writeInt32(status);
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001295 return NO_ERROR;
1296 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001297 case LIST_AUDIO_PORTS: {
1298 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001299 unsigned int numPortsReq = data.readInt32();
1300 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1301 numPortsReq = MAX_ITEMS_PER_LIST;
1302 }
1303 unsigned int numPorts = numPortsReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001304 struct audio_port *ports =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001305 (struct audio_port *)calloc(numPortsReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001306 sizeof(struct audio_port));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001307 if (ports == NULL) {
1308 reply->writeInt32(NO_MEMORY);
1309 reply->writeInt32(0);
1310 return NO_ERROR;
1311 }
1312 status_t status = listAudioPorts(&numPorts, ports);
Eric Laurent4b123402014-04-11 09:22:20 -07001313 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001314 reply->writeInt32(numPorts);
Eric Laurent4b123402014-04-11 09:22:20 -07001315 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001316 if (numPortsReq > numPorts) {
1317 numPortsReq = numPorts;
1318 }
1319 reply->write(ports, numPortsReq * sizeof(struct audio_port));
Eric Laurent4b123402014-04-11 09:22:20 -07001320 }
1321 free(ports);
1322 return NO_ERROR;
1323 } break;
1324 case GET_AUDIO_PORT: {
1325 CHECK_INTERFACE(IAudioFlinger, data, reply);
jiabinb4fed192020-09-22 14:45:40 -07001326 struct audio_port_v7 port = {};
Eric Laurent4dacbc32020-10-07 13:48:21 -07001327 status_t status = data.read(&port, sizeof(struct audio_port));
1328 if (status != NO_ERROR) {
Wei Jiae995e472015-09-09 09:48:34 -07001329 ALOGE("b/23905951");
Eric Laurent4dacbc32020-10-07 13:48:21 -07001330 return status;
Wei Jiae995e472015-09-09 09:48:34 -07001331 }
Eric Laurent4b123402014-04-11 09:22:20 -07001332 reply->writeInt32(status);
1333 if (status == NO_ERROR) {
jiabinb4fed192020-09-22 14:45:40 -07001334 reply->write(&port, sizeof(struct audio_port_v7));
Eric Laurent4b123402014-04-11 09:22:20 -07001335 }
1336 return NO_ERROR;
1337 } break;
1338 case CREATE_AUDIO_PATCH: {
1339 CHECK_INTERFACE(IAudioFlinger, data, reply);
1340 struct audio_patch patch;
Eric Laurent4dacbc32020-10-07 13:48:21 -07001341 status_t status = data.read(&patch, sizeof(struct audio_patch));
1342 if (status != NO_ERROR) {
1343 return status;
Wei Jiae995e472015-09-09 09:48:34 -07001344 }
Eric Laurent4dacbc32020-10-07 13:48:21 -07001345 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
1346 status = data.read(&handle, sizeof(audio_patch_handle_t));
1347 if (status != NO_ERROR) {
1348 ALOGE("b/23905951");
1349 return status;
1350 }
Eric Laurent4b123402014-04-11 09:22:20 -07001351 reply->writeInt32(status);
1352 if (status == NO_ERROR) {
1353 reply->write(&handle, sizeof(audio_patch_handle_t));
1354 }
1355 return NO_ERROR;
1356 } break;
1357 case RELEASE_AUDIO_PATCH: {
1358 CHECK_INTERFACE(IAudioFlinger, data, reply);
1359 audio_patch_handle_t handle;
1360 data.read(&handle, sizeof(audio_patch_handle_t));
1361 status_t status = releaseAudioPatch(handle);
1362 reply->writeInt32(status);
1363 return NO_ERROR;
1364 } break;
1365 case LIST_AUDIO_PATCHES: {
1366 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001367 unsigned int numPatchesReq = data.readInt32();
1368 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1369 numPatchesReq = MAX_ITEMS_PER_LIST;
1370 }
1371 unsigned int numPatches = numPatchesReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001372 struct audio_patch *patches =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001373 (struct audio_patch *)calloc(numPatchesReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001374 sizeof(struct audio_patch));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001375 if (patches == NULL) {
1376 reply->writeInt32(NO_MEMORY);
1377 reply->writeInt32(0);
1378 return NO_ERROR;
1379 }
1380 status_t status = listAudioPatches(&numPatches, patches);
Eric Laurent4b123402014-04-11 09:22:20 -07001381 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001382 reply->writeInt32(numPatches);
Eric Laurent4b123402014-04-11 09:22:20 -07001383 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001384 if (numPatchesReq > numPatches) {
1385 numPatchesReq = numPatches;
1386 }
1387 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
Eric Laurent4b123402014-04-11 09:22:20 -07001388 }
1389 free(patches);
1390 return NO_ERROR;
1391 } break;
1392 case SET_AUDIO_PORT_CONFIG: {
1393 CHECK_INTERFACE(IAudioFlinger, data, reply);
1394 struct audio_port_config config;
Eric Laurent4dacbc32020-10-07 13:48:21 -07001395 status_t status = data.read(&config, sizeof(struct audio_port_config));
1396 if (status != NO_ERROR) {
1397 return status;
1398 }
Eric Laurent4b123402014-04-11 09:22:20 -07001399 reply->writeInt32(status);
1400 return NO_ERROR;
1401 } break;
Glenn Kasten9eae0362016-04-19 09:09:14 -07001402 case GET_AUDIO_HW_SYNC_FOR_SESSION: {
Eric Laurent93c3d412014-08-01 14:48:35 -07001403 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001404 reply->writeInt32(getAudioHwSyncForSession((audio_session_t) data.readInt32()));
Eric Laurent93c3d412014-08-01 14:48:35 -07001405 return NO_ERROR;
1406 } break;
Eric Laurent72e3f392015-05-20 14:43:50 -07001407 case SYSTEM_READY: {
1408 CHECK_INTERFACE(IAudioFlinger, data, reply);
1409 systemReady();
1410 return NO_ERROR;
1411 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001412 case FRAME_COUNT_HAL: {
1413 CHECK_INTERFACE(IAudioFlinger, data, reply);
1414 reply->writeInt64( frameCountHAL((audio_io_handle_t) data.readInt32()) );
1415 return NO_ERROR;
1416 } break;
jiabin9ff780e2018-03-19 18:19:52 -07001417 case GET_MICROPHONES: {
jiabin46a76fa2018-01-05 10:18:21 -08001418 CHECK_INTERFACE(IAudioFlinger, data, reply);
1419 std::vector<media::MicrophoneInfo> microphones;
1420 status_t status = getMicrophones(&microphones);
1421 reply->writeInt32(status);
1422 if (status == NO_ERROR) {
1423 reply->writeParcelableVector(microphones);
1424 }
1425 return NO_ERROR;
1426 }
Eric Laurent42896a02019-09-27 15:40:33 -07001427 case SET_AUDIO_HAL_PIDS: {
1428 CHECK_INTERFACE(IAudioFlinger, data, reply);
1429 std::vector<pid_t> pids;
1430 int32_t size;
1431 status_t status = data.readInt32(&size);
1432 if (status != NO_ERROR) {
1433 return status;
1434 }
1435 if (size < 0) {
1436 return BAD_VALUE;
1437 }
1438 if (size > MAX_ITEMS_PER_LIST) {
1439 size = MAX_ITEMS_PER_LIST;
1440 }
1441 for (int32_t i = 0; i < size; i++) {
1442 int32_t pid;
1443 status = data.readInt32(&pid);
1444 if (status != NO_ERROR) {
1445 return status;
1446 }
1447 pids.push_back(pid);
1448 }
1449 reply->writeInt32(setAudioHalPids(pids));
1450 return NO_ERROR;
1451 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001452 default:
1453 return BBinder::onTransact(code, data, reply, flags);
1454 }
1455}
1456
1457// ----------------------------------------------------------------------------
1458
Glenn Kasten40bc9062015-03-20 09:09:33 -07001459} // namespace android