blob: b5c65476503a7256756560e3dc2fa79d2edec357 [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>
Eric Laurent4dacbc32020-10-07 13:48:21 -070027#include <media/AudioSanitizer.h>
Eric Laurent14dc3cb2020-09-16 18:42:23 -070028#include <media/IAudioPolicyService.h>
Andy Hung4ef19fa2018-05-15 19:35:29 -070029#include <mediautils/ServiceUtilities.h>
Marco Nelissencf90b492019-09-26 11:20:54 -070030#include <mediautils/TimeCheck.h>
Steven Moreland25a9e552017-04-17 14:30:39 -070031#include "IAudioFlinger.h"
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080032
33namespace android {
34
35enum {
36 CREATE_TRACK = IBinder::FIRST_CALL_TRANSACTION,
Eric Laurentf14db3c2017-12-08 14:20:36 -080037 CREATE_RECORD,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080038 SAMPLE_RATE,
Glenn Kasten5876f2f2012-11-30 10:52:16 -080039 RESERVED, // obsolete, was CHANNEL_COUNT
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080040 FORMAT,
41 FRAME_COUNT,
42 LATENCY,
43 SET_MASTER_VOLUME,
44 SET_MASTER_MUTE,
45 MASTER_VOLUME,
46 MASTER_MUTE,
47 SET_STREAM_VOLUME,
48 SET_STREAM_MUTE,
49 STREAM_VOLUME,
50 STREAM_MUTE,
51 SET_MODE,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080052 SET_MIC_MUTE,
53 GET_MIC_MUTE,
Svet Ganovf4ddfef2018-01-16 07:37:58 -080054 SET_RECORD_SILENCED,
Eric Laurentc2f1f072009-07-17 12:17:14 -070055 SET_PARAMETERS,
56 GET_PARAMETERS,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080057 REGISTER_CLIENT,
58 GET_INPUTBUFFERSIZE,
Eric Laurentc2f1f072009-07-17 12:17:14 -070059 OPEN_OUTPUT,
60 OPEN_DUPLICATE_OUTPUT,
61 CLOSE_OUTPUT,
62 SUSPEND_OUTPUT,
63 RESTORE_OUTPUT,
64 OPEN_INPUT,
65 CLOSE_INPUT,
Glenn Kastend2304db2014-02-03 07:40:31 -080066 INVALIDATE_STREAM,
Eric Laurent342e9cf2010-01-19 17:37:09 -080067 SET_VOICE_VOLUME,
Eric Laurent05bca2f2010-02-26 02:47:27 -080068 GET_RENDER_POSITION,
Eric Laurentbe916aa2010-06-01 23:49:17 -070069 GET_INPUT_FRAMES_LOST,
Glenn Kasten9eae0362016-04-19 09:09:14 -070070 NEW_AUDIO_UNIQUE_ID,
Marco Nelissen3a34bef2011-08-02 13:33:41 -070071 ACQUIRE_AUDIO_SESSION_ID,
72 RELEASE_AUDIO_SESSION_ID,
Eric Laurentbe916aa2010-06-01 23:49:17 -070073 QUERY_NUM_EFFECTS,
Eric Laurentffe9c252010-06-23 17:38:20 -070074 QUERY_EFFECT,
Eric Laurentbe916aa2010-06-01 23:49:17 -070075 GET_EFFECT_DESCRIPTOR,
Eric Laurentde070132010-07-13 04:45:46 -070076 CREATE_EFFECT,
Eric Laurenta4c5a552012-03-29 10:12:40 -070077 MOVE_EFFECTS,
Glenn Kastencc0f1cf2012-09-24 11:27:18 -070078 LOAD_HW_MODULE,
79 GET_PRIMARY_OUTPUT_SAMPLING_RATE,
80 GET_PRIMARY_OUTPUT_FRAME_COUNT,
Glenn Kasten4182c4e2013-07-15 14:45:07 -070081 SET_LOW_RAM_DEVICE,
Eric Laurent4b123402014-04-11 09:22:20 -070082 LIST_AUDIO_PORTS,
83 GET_AUDIO_PORT,
84 CREATE_AUDIO_PATCH,
85 RELEASE_AUDIO_PATCH,
86 LIST_AUDIO_PATCHES,
Eric Laurent93c3d412014-08-01 14:48:35 -070087 SET_AUDIO_PORT_CONFIG,
Glenn Kasten9eae0362016-04-19 09:09:14 -070088 GET_AUDIO_HW_SYNC_FOR_SESSION,
Glenn Kasten4a8308b2016-04-18 14:10:01 -070089 SYSTEM_READY,
90 FRAME_COUNT_HAL,
jiabin9ff780e2018-03-19 18:19:52 -070091 GET_MICROPHONES,
Richard Folke Tullberg3fae0372017-01-13 09:04:25 +010092 SET_MASTER_BALANCE,
93 GET_MASTER_BALANCE,
Eric Laurentb20cf7d2019-04-05 19:37:34 -070094 SET_EFFECT_SUSPENDED,
Eric Laurent42896a02019-09-27 15:40:33 -070095 SET_AUDIO_HAL_PIDS
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080096};
97
Eric Laurentf75c2fe2015-04-02 13:49:15 -070098#define MAX_ITEMS_PER_LIST 1024
99
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800100ConversionResult<media::CreateTrackRequest> IAudioFlinger::CreateTrackInput::toAidl() const {
101 media::CreateTrackRequest aidl;
102 aidl.attr = VALUE_OR_RETURN(legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr));
103 aidl.config = VALUE_OR_RETURN(legacy2aidl_audio_config_t_AudioConfig(config));
104 aidl.clientInfo = VALUE_OR_RETURN(legacy2aidl_AudioClient(clientInfo));
105 aidl.sharedBuffer = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(sharedBuffer));
106 aidl.notificationsPerBuffer = VALUE_OR_RETURN(convertIntegral<int32_t>(notificationsPerBuffer));
107 aidl.speed = speed;
108 aidl.audioTrackCallback = audioTrackCallback;
109 aidl.opPackageName = opPackageName;
110 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_output_flags_mask(flags));
111 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
112 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
113 aidl.selectedDeviceId = VALUE_OR_RETURN(
114 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
115 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
116 return aidl;
117}
118
119ConversionResult<IAudioFlinger::CreateTrackInput>
120IAudioFlinger::CreateTrackInput::fromAidl(const media::CreateTrackRequest& aidl) {
121 IAudioFlinger::CreateTrackInput legacy;
122 legacy.attr = VALUE_OR_RETURN(aidl2legacy_AudioAttributesInternal_audio_attributes_t(aidl.attr));
123 legacy.config = VALUE_OR_RETURN(aidl2legacy_AudioConfig_audio_config_t(aidl.config));
124 legacy.clientInfo = VALUE_OR_RETURN(aidl2legacy_AudioClient(aidl.clientInfo));
125 legacy.sharedBuffer = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.sharedBuffer));
126 legacy.notificationsPerBuffer = VALUE_OR_RETURN(
127 convertIntegral<uint32_t>(aidl.notificationsPerBuffer));
128 legacy.speed = aidl.speed;
129 legacy.audioTrackCallback = aidl.audioTrackCallback;
130 legacy.opPackageName = aidl.opPackageName;
131 legacy.flags = VALUE_OR_RETURN(aidl2legacy_audio_output_flags_mask(aidl.flags));
132 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
133 legacy.notificationFrameCount = VALUE_OR_RETURN(
134 convertIntegral<size_t>(aidl.notificationFrameCount));
135 legacy.selectedDeviceId = VALUE_OR_RETURN(
136 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
137 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
138 return legacy;
139}
140
141ConversionResult<media::CreateTrackResponse>
142IAudioFlinger::CreateTrackOutput::toAidl() const {
143 media::CreateTrackResponse aidl;
144 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_output_flags_mask(flags));
145 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
146 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
147 aidl.selectedDeviceId = VALUE_OR_RETURN(
148 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
149 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
150 aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate));
151 aidl.afFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(afFrameCount));
152 aidl.afSampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(afSampleRate));
153 aidl.afLatencyMs = VALUE_OR_RETURN(convertIntegral<int32_t>(afLatencyMs));
154 aidl.outputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(outputId));
155 aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId));
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800156 aidl.audioTrack = audioTrack;
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800157 return aidl;
158}
159
160ConversionResult<IAudioFlinger::CreateTrackOutput>
161IAudioFlinger::CreateTrackOutput::fromAidl(
162 const media::CreateTrackResponse& aidl) {
163 IAudioFlinger::CreateTrackOutput legacy;
164 legacy.flags = VALUE_OR_RETURN(aidl2legacy_audio_output_flags_mask(aidl.flags));
165 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
166 legacy.notificationFrameCount = VALUE_OR_RETURN(
167 convertIntegral<size_t>(aidl.notificationFrameCount));
168 legacy.selectedDeviceId = VALUE_OR_RETURN(
169 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
170 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
171 legacy.sampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate));
172 legacy.afFrameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.afFrameCount));
173 legacy.afSampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.afSampleRate));
174 legacy.afLatencyMs = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.afLatencyMs));
175 legacy.outputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.outputId));
176 legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId));
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800177 legacy.audioTrack = aidl.audioTrack;
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800178 return legacy;
179}
180
181ConversionResult<media::CreateRecordRequest>
182IAudioFlinger::CreateRecordInput::toAidl() const {
183 media::CreateRecordRequest aidl;
184 aidl.attr = VALUE_OR_RETURN(legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr));
185 aidl.config = VALUE_OR_RETURN(legacy2aidl_audio_config_base_t_AudioConfigBase(config));
186 aidl.clientInfo = VALUE_OR_RETURN(legacy2aidl_AudioClient(clientInfo));
187 aidl.opPackageName = VALUE_OR_RETURN(legacy2aidl_String16_string(opPackageName));
188 aidl.riid = VALUE_OR_RETURN(legacy2aidl_audio_unique_id_t_int32_t(riid));
189 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_input_flags_mask(flags));
190 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
191 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
192 aidl.selectedDeviceId = VALUE_OR_RETURN(
193 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
194 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
195 return aidl;
196}
197
198ConversionResult<IAudioFlinger::CreateRecordInput>
199IAudioFlinger::CreateRecordInput::fromAidl(
200 const media::CreateRecordRequest& aidl) {
201 IAudioFlinger::CreateRecordInput legacy;
202 legacy.attr = VALUE_OR_RETURN(aidl2legacy_AudioAttributesInternal_audio_attributes_t(aidl.attr));
203 legacy.config = VALUE_OR_RETURN(aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.config));
204 legacy.clientInfo = VALUE_OR_RETURN(aidl2legacy_AudioClient(aidl.clientInfo));
205 legacy.opPackageName = VALUE_OR_RETURN(aidl2legacy_string_view_String16(aidl.opPackageName));
206 legacy.riid = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_unique_id_t(aidl.riid));
207 legacy.flags = VALUE_OR_RETURN(aidl2legacy_audio_input_flags_mask(aidl.flags));
208 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
209 legacy.notificationFrameCount = VALUE_OR_RETURN(
210 convertIntegral<size_t>(aidl.notificationFrameCount));
211 legacy.selectedDeviceId = VALUE_OR_RETURN(
212 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
213 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
214 return legacy;
215}
216
217ConversionResult<media::CreateRecordResponse>
218IAudioFlinger::CreateRecordOutput::toAidl() const {
219 media::CreateRecordResponse aidl;
220 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_input_flags_mask(flags));
221 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
222 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
223 aidl.selectedDeviceId = VALUE_OR_RETURN(
224 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
225 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
226 aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate));
227 aidl.inputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(inputId));
228 aidl.cblk = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(cblk));
229 aidl.buffers = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(buffers));
230 aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId));
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800231 aidl.audioRecord = audioRecord;
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800232 return aidl;
233}
234
235ConversionResult<IAudioFlinger::CreateRecordOutput>
236IAudioFlinger::CreateRecordOutput::fromAidl(
237 const media::CreateRecordResponse& aidl) {
238 IAudioFlinger::CreateRecordOutput legacy;
239 legacy.flags = VALUE_OR_RETURN(aidl2legacy_audio_input_flags_mask(aidl.flags));
240 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
241 legacy.notificationFrameCount = VALUE_OR_RETURN(
242 convertIntegral<size_t>(aidl.notificationFrameCount));
243 legacy.selectedDeviceId = VALUE_OR_RETURN(
244 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
245 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
246 legacy.sampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate));
247 legacy.inputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.inputId));
248 legacy.cblk = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.cblk));
249 legacy.buffers = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.buffers));
250 legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId));
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800251 legacy.audioRecord = aidl.audioRecord;
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800252 return legacy;
253}
Eric Laurent42896a02019-09-27 15:40:33 -0700254
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800255class BpAudioFlinger : public BpInterface<IAudioFlinger>
256{
257public:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -0700258 explicit BpAudioFlinger(const sp<IBinder>& impl)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800259 : BpInterface<IAudioFlinger>(impl)
260 {
261 }
262
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800263 virtual status_t createTrack(const media::CreateTrackRequest& input,
264 media::CreateTrackResponse& output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800265 {
266 Parcel data, reply;
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800267 status_t status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800268 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800269 data.writeParcelable(input);
Eric Laurent21da6472017-11-09 16:29:26 -0800270
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800271 status_t lStatus = remote()->transact(CREATE_TRACK, data, &reply);
272 if (lStatus != NO_ERROR) {
Eric Laurent21da6472017-11-09 16:29:26 -0800273 ALOGE("createTrack transaction error %d", lStatus);
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800274 return DEAD_OBJECT;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800275 }
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800276 status = reply.readInt32();
277 if (status != NO_ERROR) {
278 ALOGE("createTrack returned error %d", status);
279 return status;
Eric Laurent21da6472017-11-09 16:29:26 -0800280 }
281 output.readFromParcel(&reply);
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800282 if (output.audioTrack == 0) {
283 ALOGE("createTrack returned an NULL IAudioTrack with status OK");
284 return DEAD_OBJECT;
285 }
286 return OK;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800287 }
288
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800289 virtual status_t createRecord(const media::CreateRecordRequest& input,
290 media::CreateRecordResponse& output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800291 {
292 Parcel data, reply;
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800293 status_t status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800294 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentf14db3c2017-12-08 14:20:36 -0800295
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -0800296 data.writeParcelable(input);
Eric Laurentf14db3c2017-12-08 14:20:36 -0800297
298 status_t lStatus = remote()->transact(CREATE_RECORD, data, &reply);
Eric Laurent5841db72009-09-09 05:16:08 -0700299 if (lStatus != NO_ERROR) {
Eric Laurentf14db3c2017-12-08 14:20:36 -0800300 ALOGE("createRecord transaction error %d", lStatus);
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800301 return DEAD_OBJECT;
Eric Laurent5841db72009-09-09 05:16:08 -0700302 }
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800303 status = reply.readInt32();
304 if (status != NO_ERROR) {
305 ALOGE("createRecord returned error %d", status);
306 return status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800307 }
Eric Laurentf14db3c2017-12-08 14:20:36 -0800308
Eric Laurentf14db3c2017-12-08 14:20:36 -0800309 output.readFromParcel(&reply);
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -0800310 if (output.audioRecord == 0) {
311 ALOGE("createRecord returned a NULL IAudioRecord with status OK");
312 return DEAD_OBJECT;
313 }
314 return OK;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800315 }
316
Glenn Kasten2c073da2016-02-26 09:14:08 -0800317 virtual uint32_t sampleRate(audio_io_handle_t ioHandle) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800318 {
319 Parcel data, reply;
320 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten2c073da2016-02-26 09:14:08 -0800321 data.writeInt32((int32_t) ioHandle);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800322 remote()->transact(SAMPLE_RATE, data, &reply);
323 return reply.readInt32();
324 }
325
Glenn Kasten4a8308b2016-04-18 14:10:01 -0700326 // RESERVED for channelCount()
327
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800328 virtual audio_format_t format(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800329 {
330 Parcel data, reply;
331 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800332 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800333 remote()->transact(FORMAT, data, &reply);
Glenn Kasten58f30212012-01-12 12:27:51 -0800334 return (audio_format_t) reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800335 }
336
Glenn Kasten2c073da2016-02-26 09:14:08 -0800337 virtual size_t frameCount(audio_io_handle_t ioHandle) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800338 {
339 Parcel data, reply;
340 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten2c073da2016-02-26 09:14:08 -0800341 data.writeInt32((int32_t) ioHandle);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800342 remote()->transact(FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800343 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800344 }
345
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800346 virtual uint32_t latency(audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800347 {
348 Parcel data, reply;
349 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800350 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800351 remote()->transact(LATENCY, data, &reply);
352 return reply.readInt32();
353 }
354
355 virtual status_t setMasterVolume(float value)
356 {
357 Parcel data, reply;
358 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
359 data.writeFloat(value);
360 remote()->transact(SET_MASTER_VOLUME, data, &reply);
361 return reply.readInt32();
362 }
363
364 virtual status_t setMasterMute(bool muted)
365 {
366 Parcel data, reply;
367 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
368 data.writeInt32(muted);
369 remote()->transact(SET_MASTER_MUTE, data, &reply);
370 return reply.readInt32();
371 }
372
373 virtual float masterVolume() const
374 {
375 Parcel data, reply;
376 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
377 remote()->transact(MASTER_VOLUME, data, &reply);
378 return reply.readFloat();
379 }
380
381 virtual bool masterMute() const
382 {
383 Parcel data, reply;
384 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
385 remote()->transact(MASTER_MUTE, data, &reply);
386 return reply.readInt32();
387 }
388
Richard Folke Tullberg3fae0372017-01-13 09:04:25 +0100389 status_t setMasterBalance(float balance) override
390 {
391 Parcel data, reply;
392 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
393 data.writeFloat(balance);
394 status_t status = remote()->transact(SET_MASTER_BALANCE, data, &reply);
395 if (status != NO_ERROR) {
396 return status;
397 }
398 return reply.readInt32();
399 }
400
401 status_t getMasterBalance(float *balance) const override
402 {
403 Parcel data, reply;
404 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
405 status_t status = remote()->transact(GET_MASTER_BALANCE, data, &reply);
406 if (status != NO_ERROR) {
407 return status;
408 }
409 status = (status_t)reply.readInt32();
410 if (status != NO_ERROR) {
411 return status;
412 }
413 *balance = reply.readFloat();
414 return NO_ERROR;
415 }
416
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800417 virtual status_t setStreamVolume(audio_stream_type_t stream, float value,
418 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800419 {
420 Parcel data, reply;
421 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800422 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800423 data.writeFloat(value);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800424 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800425 remote()->transact(SET_STREAM_VOLUME, data, &reply);
426 return reply.readInt32();
427 }
428
Glenn Kastenfff6d712012-01-12 16:38:12 -0800429 virtual status_t setStreamMute(audio_stream_type_t stream, bool muted)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800430 {
431 Parcel data, reply;
432 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800433 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800434 data.writeInt32(muted);
435 remote()->transact(SET_STREAM_MUTE, data, &reply);
436 return reply.readInt32();
437 }
438
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800439 virtual float streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800440 {
441 Parcel data, reply;
442 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800443 data.writeInt32((int32_t) stream);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800444 data.writeInt32((int32_t) output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800445 remote()->transact(STREAM_VOLUME, data, &reply);
446 return reply.readFloat();
447 }
448
Glenn Kastenfff6d712012-01-12 16:38:12 -0800449 virtual bool streamMute(audio_stream_type_t stream) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800450 {
451 Parcel data, reply;
452 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800453 data.writeInt32((int32_t) stream);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800454 remote()->transact(STREAM_MUTE, data, &reply);
455 return reply.readInt32();
456 }
457
Glenn Kastenf78aee72012-01-04 11:00:47 -0800458 virtual status_t setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800459 {
460 Parcel data, reply;
461 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
462 data.writeInt32(mode);
463 remote()->transact(SET_MODE, data, &reply);
464 return reply.readInt32();
465 }
466
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800467 virtual status_t setMicMute(bool state)
468 {
469 Parcel data, reply;
470 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
471 data.writeInt32(state);
472 remote()->transact(SET_MIC_MUTE, data, &reply);
473 return reply.readInt32();
474 }
475
476 virtual bool getMicMute() const
477 {
478 Parcel data, reply;
479 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
480 remote()->transact(GET_MIC_MUTE, data, &reply);
481 return reply.readInt32();
482 }
483
Eric Laurent5ada82e2019-08-29 17:53:54 -0700484 virtual void setRecordSilenced(audio_port_handle_t portId, bool silenced)
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800485 {
486 Parcel data, reply;
487 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurent5ada82e2019-08-29 17:53:54 -0700488 data.writeInt32(portId);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800489 data.writeInt32(silenced ? 1 : 0);
490 remote()->transact(SET_RECORD_SILENCED, data, &reply);
491 }
492
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800493 virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800494 {
495 Parcel data, reply;
496 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800497 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700498 data.writeString8(keyValuePairs);
499 remote()->transact(SET_PARAMETERS, data, &reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800500 return reply.readInt32();
501 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700502
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800503 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const
Eric Laurentc2f1f072009-07-17 12:17:14 -0700504 {
505 Parcel data, reply;
506 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800507 data.writeInt32((int32_t) ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700508 data.writeString8(keys);
509 remote()->transact(GET_PARAMETERS, data, &reply);
510 return reply.readString8();
511 }
512
Ytai Ben-Tsvi10dc0a62020-09-18 11:31:55 -0700513 virtual void registerClient(const sp<media::IAudioFlingerClient>& client)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800514 {
515 Parcel data, reply;
516 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800517 data.writeStrongBinder(IInterface::asBinder(client));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800518 remote()->transact(REGISTER_CLIENT, data, &reply);
519 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700520
Glenn Kastendd8104c2012-07-02 12:42:44 -0700521 virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
522 audio_channel_mask_t channelMask) const
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800523 {
524 Parcel data, reply;
525 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
526 data.writeInt32(sampleRate);
527 data.writeInt32(format);
Glenn Kastendd8104c2012-07-02 12:42:44 -0700528 data.writeInt32(channelMask);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800529 remote()->transact(GET_INPUTBUFFERSIZE, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800530 return reply.readInt64();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800531 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700532
Eric Laurentcf2c0212014-07-25 16:20:43 -0700533 virtual status_t openOutput(audio_module_handle_t module,
534 audio_io_handle_t *output,
535 audio_config_t *config,
jiabin43810402019-10-24 14:58:31 -0700536 const sp<DeviceDescriptorBase>& device,
Eric Laurentcf2c0212014-07-25 16:20:43 -0700537 uint32_t *latencyMs,
538 audio_output_flags_t flags)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800539 {
jiabin43810402019-10-24 14:58:31 -0700540 if (output == nullptr || config == nullptr || device == nullptr || latencyMs == nullptr) {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700541 return BAD_VALUE;
542 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800543 Parcel data, reply;
544 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700545 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700546 data.write(config, sizeof(audio_config_t));
jiabin43810402019-10-24 14:58:31 -0700547 data.writeParcelable(*device);
Glenn Kasten18868c52012-03-07 09:15:37 -0800548 data.writeInt32((int32_t) flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700549 status_t status = remote()->transact(OPEN_OUTPUT, data, &reply);
550 if (status != NO_ERROR) {
551 *output = AUDIO_IO_HANDLE_NONE;
552 return status;
Richard Fitzgeraldb1a270d2013-05-14 12:12:21 +0100553 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700554 status = (status_t)reply.readInt32();
555 if (status != NO_ERROR) {
556 *output = AUDIO_IO_HANDLE_NONE;
557 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700558 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700559 *output = (audio_io_handle_t)reply.readInt32();
560 ALOGV("openOutput() returned output, %d", *output);
561 reply.read(config, sizeof(audio_config_t));
Eric Laurentcf2c0212014-07-25 16:20:43 -0700562 *latencyMs = reply.readInt32();
563 return NO_ERROR;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800564 }
565
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800566 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
567 audio_io_handle_t output2)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800568 {
569 Parcel data, reply;
570 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800571 data.writeInt32((int32_t) output1);
572 data.writeInt32((int32_t) output2);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700573 remote()->transact(OPEN_DUPLICATE_OUTPUT, data, &reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800574 return (audio_io_handle_t) reply.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700575 }
576
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800577 virtual status_t closeOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700578 {
579 Parcel data, reply;
580 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800581 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700582 remote()->transact(CLOSE_OUTPUT, data, &reply);
583 return reply.readInt32();
584 }
585
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800586 virtual status_t suspendOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700587 {
588 Parcel data, reply;
589 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800590 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700591 remote()->transact(SUSPEND_OUTPUT, data, &reply);
592 return reply.readInt32();
593 }
594
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800595 virtual status_t restoreOutput(audio_io_handle_t output)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700596 {
597 Parcel data, reply;
598 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800599 data.writeInt32((int32_t) output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700600 remote()->transact(RESTORE_OUTPUT, data, &reply);
601 return reply.readInt32();
602 }
603
Eric Laurentcf2c0212014-07-25 16:20:43 -0700604 virtual status_t openInput(audio_module_handle_t module,
605 audio_io_handle_t *input,
606 audio_config_t *config,
607 audio_devices_t *device,
608 const String8& address,
609 audio_source_t source,
610 audio_input_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700611 {
Eric Laurentcf2c0212014-07-25 16:20:43 -0700612 if (input == NULL || config == NULL || device == NULL) {
613 return BAD_VALUE;
614 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700615 Parcel data, reply;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700616 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurenta4c5a552012-03-29 10:12:40 -0700617 data.writeInt32(module);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700618 data.writeInt32(*input);
619 data.write(config, sizeof(audio_config_t));
620 data.writeInt32(*device);
621 data.writeString8(address);
622 data.writeInt32(source);
Glenn Kastenec40d282014-07-15 15:31:26 -0700623 data.writeInt32(flags);
Eric Laurentcf2c0212014-07-25 16:20:43 -0700624 status_t status = remote()->transact(OPEN_INPUT, data, &reply);
625 if (status != NO_ERROR) {
626 *input = AUDIO_IO_HANDLE_NONE;
627 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700628 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700629 status = (status_t)reply.readInt32();
630 if (status != NO_ERROR) {
631 *input = AUDIO_IO_HANDLE_NONE;
632 return status;
Glenn Kasten507b2862013-07-31 16:12:13 -0700633 }
Eric Laurentcf2c0212014-07-25 16:20:43 -0700634 *input = (audio_io_handle_t)reply.readInt32();
635 reply.read(config, sizeof(audio_config_t));
636 *device = (audio_devices_t)reply.readInt32();
637 return NO_ERROR;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700638 }
639
Eric Laurentfa2877b2009-07-28 08:44:33 -0700640 virtual status_t closeInput(int input)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700641 {
642 Parcel data, reply;
643 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentfa2877b2009-07-28 08:44:33 -0700644 data.writeInt32(input);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700645 remote()->transact(CLOSE_INPUT, data, &reply);
646 return reply.readInt32();
647 }
648
Glenn Kastend2304db2014-02-03 07:40:31 -0800649 virtual status_t invalidateStream(audio_stream_type_t stream)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700650 {
651 Parcel data, reply;
652 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kastenfff6d712012-01-12 16:38:12 -0800653 data.writeInt32((int32_t) stream);
Glenn Kastend2304db2014-02-03 07:40:31 -0800654 remote()->transact(INVALIDATE_STREAM, data, &reply);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700655 return reply.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800656 }
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700657
658 virtual status_t setVoiceVolume(float volume)
659 {
660 Parcel data, reply;
661 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
662 data.writeFloat(volume);
663 remote()->transact(SET_VOICE_VOLUME, data, &reply);
664 return reply.readInt32();
665 }
Eric Laurent342e9cf2010-01-19 17:37:09 -0800666
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000667 virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800668 audio_io_handle_t output) const
Eric Laurent342e9cf2010-01-19 17:37:09 -0800669 {
670 Parcel data, reply;
671 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800672 data.writeInt32((int32_t) output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800673 remote()->transact(GET_RENDER_POSITION, data, &reply);
674 status_t status = reply.readInt32();
675 if (status == NO_ERROR) {
676 uint32_t tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700677 if (halFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800678 *halFrames = tmp;
679 }
680 tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700681 if (dspFrames != NULL) {
Eric Laurent342e9cf2010-01-19 17:37:09 -0800682 *dspFrames = tmp;
683 }
684 }
685 return status;
686 }
Eric Laurent05bca2f2010-02-26 02:47:27 -0800687
Glenn Kasten5f972c02014-01-13 09:59:31 -0800688 virtual uint32_t getInputFramesLost(audio_io_handle_t ioHandle) const
Eric Laurent05bca2f2010-02-26 02:47:27 -0800689 {
690 Parcel data, reply;
691 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800692 data.writeInt32((int32_t) ioHandle);
Glenn Kasten5f972c02014-01-13 09:59:31 -0800693 status_t status = remote()->transact(GET_INPUT_FRAMES_LOST, data, &reply);
694 if (status != NO_ERROR) {
695 return 0;
696 }
697 return (uint32_t) reply.readInt32();
Eric Laurent05bca2f2010-02-26 02:47:27 -0800698 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700699
Glenn Kasteneeecb982016-02-26 10:44:04 -0800700 virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use)
Eric Laurentbe916aa2010-06-01 23:49:17 -0700701 {
702 Parcel data, reply;
703 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Glenn Kasteneeecb982016-02-26 10:44:04 -0800704 data.writeInt32((int32_t) use);
Glenn Kasten9eae0362016-04-19 09:09:14 -0700705 status_t status = remote()->transact(NEW_AUDIO_UNIQUE_ID, data, &reply);
706 audio_unique_id_t id = AUDIO_UNIQUE_ID_ALLOCATE;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700707 if (status == NO_ERROR) {
708 id = reply.readInt32();
709 }
710 return id;
711 }
712
Andy Hung8b0bfd92019-12-23 13:11:11 -0800713 void acquireAudioSessionId(audio_session_t audioSession, pid_t pid, uid_t uid) override
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700714 {
715 Parcel data, reply;
716 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
717 data.writeInt32(audioSession);
Andy Hung8b0bfd92019-12-23 13:11:11 -0800718 data.writeInt32((int32_t)pid);
719 data.writeInt32((int32_t)uid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700720 remote()->transact(ACQUIRE_AUDIO_SESSION_ID, data, &reply);
721 }
722
Glenn Kastend848eb42016-03-08 13:42:11 -0800723 virtual void releaseAudioSessionId(audio_session_t audioSession, int pid)
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700724 {
725 Parcel data, reply;
726 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
727 data.writeInt32(audioSession);
Marco Nelissend457c972014-02-11 08:47:07 -0800728 data.writeInt32(pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700729 remote()->transact(RELEASE_AUDIO_SESSION_ID, data, &reply);
730 }
731
Glenn Kastenf587ba52012-01-26 16:25:10 -0800732 virtual status_t queryNumberEffects(uint32_t *numEffects) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700733 {
734 Parcel data, reply;
735 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
736 status_t status = remote()->transact(QUERY_NUM_EFFECTS, data, &reply);
737 if (status != NO_ERROR) {
738 return status;
739 }
740 status = reply.readInt32();
741 if (status != NO_ERROR) {
742 return status;
743 }
Glenn Kasten9d1f02d2012-02-08 17:47:58 -0800744 if (numEffects != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700745 *numEffects = (uint32_t)reply.readInt32();
746 }
747 return NO_ERROR;
748 }
749
Glenn Kastenf587ba52012-01-26 16:25:10 -0800750 virtual status_t queryEffect(uint32_t index, effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700751 {
752 if (pDescriptor == NULL) {
753 return BAD_VALUE;
754 }
755 Parcel data, reply;
756 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentffe9c252010-06-23 17:38:20 -0700757 data.writeInt32(index);
758 status_t status = remote()->transact(QUERY_EFFECT, data, &reply);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700759 if (status != NO_ERROR) {
760 return status;
761 }
762 status = reply.readInt32();
763 if (status != NO_ERROR) {
764 return status;
765 }
766 reply.read(pDescriptor, sizeof(effect_descriptor_t));
767 return NO_ERROR;
768 }
769
Glenn Kasten5e92a782012-01-30 07:40:52 -0800770 virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -0700771 const effect_uuid_t *pType,
772 uint32_t preferredTypeFlag,
773 effect_descriptor_t *pDescriptor) const
Eric Laurentbe916aa2010-06-01 23:49:17 -0700774 {
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -0700775 if (pUuid == NULL || pType == NULL || pDescriptor == NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700776 return BAD_VALUE;
777 }
778 Parcel data, reply;
779 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
780 data.write(pUuid, sizeof(effect_uuid_t));
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -0700781 data.write(pType, sizeof(effect_uuid_t));
782 data.writeUint32(preferredTypeFlag);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700783 status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
784 if (status != NO_ERROR) {
785 return status;
786 }
787 status = reply.readInt32();
788 if (status != NO_ERROR) {
789 return status;
790 }
791 reply.read(pDescriptor, sizeof(effect_descriptor_t));
792 return NO_ERROR;
793 }
794
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700795 virtual sp<media::IEffect> createEffect(
Eric Laurentbe916aa2010-06-01 23:49:17 -0700796 effect_descriptor_t *pDesc,
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700797 const sp<media::IEffectClient>& client,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700798 int32_t priority,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800799 audio_io_handle_t output,
Glenn Kastend848eb42016-03-08 13:42:11 -0800800 audio_session_t sessionId,
Eric Laurent94876032019-11-13 12:45:28 -0800801 const AudioDeviceTypeAddr& device,
Svet Ganovbe71aa22015-04-28 12:06:02 -0700802 const String16& opPackageName,
Eric Laurentb6436272016-12-07 19:24:50 -0800803 pid_t pid,
Eric Laurent2fe0acd2020-03-13 14:30:46 -0700804 bool probe,
Eric Laurentbe916aa2010-06-01 23:49:17 -0700805 status_t *status,
806 int *id,
807 int *enabled)
808 {
809 Parcel data, reply;
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700810 sp<media::IEffect> effect;
Eric Laurentbe916aa2010-06-01 23:49:17 -0700811 if (pDesc == NULL) {
Glenn Kasten507b2862013-07-31 16:12:13 -0700812 if (status != NULL) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700813 *status = BAD_VALUE;
814 }
Eric Laurent94876032019-11-13 12:45:28 -0800815 return nullptr;
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700816 }
Eric Laurentbe916aa2010-06-01 23:49:17 -0700817
818 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700819 data.write(pDesc, sizeof(effect_descriptor_t));
Marco Nelissen06b46062014-11-14 07:58:25 -0800820 data.writeStrongBinder(IInterface::asBinder(client));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700821 data.writeInt32(priority);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800822 data.writeInt32((int32_t) output);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700823 data.writeInt32(sessionId);
Eric Laurent94876032019-11-13 12:45:28 -0800824 if (data.writeParcelable(device) != NO_ERROR) {
825 if (status != NULL) {
826 *status = NO_INIT;
827 }
828 return nullptr;
829 }
Svet Ganovbe71aa22015-04-28 12:06:02 -0700830 data.writeString16(opPackageName);
Eric Laurentb6436272016-12-07 19:24:50 -0800831 data.writeInt32((int32_t) pid);
Eric Laurent2fe0acd2020-03-13 14:30:46 -0700832 data.writeInt32(probe ? 1 : 0);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700833
834 status_t lStatus = remote()->transact(CREATE_EFFECT, data, &reply);
835 if (lStatus != NO_ERROR) {
Steve Block29357bc2012-01-06 19:20:56 +0000836 ALOGE("createEffect error: %s", strerror(-lStatus));
Eric Laurentbe916aa2010-06-01 23:49:17 -0700837 } else {
838 lStatus = reply.readInt32();
839 int tmp = reply.readInt32();
Glenn Kasten507b2862013-07-31 16:12:13 -0700840 if (id != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700841 *id = tmp;
842 }
843 tmp = reply.readInt32();
Glenn Kastena0d68332012-01-27 16:47:15 -0800844 if (enabled != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700845 *enabled = tmp;
846 }
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -0700847 effect = interface_cast<media::IEffect>(reply.readStrongBinder());
Eric Laurentbe916aa2010-06-01 23:49:17 -0700848 reply.read(pDesc, sizeof(effect_descriptor_t));
849 }
Glenn Kasten507b2862013-07-31 16:12:13 -0700850 if (status != NULL) {
Eric Laurentbe916aa2010-06-01 23:49:17 -0700851 *status = lStatus;
852 }
853
854 return effect;
855 }
Eric Laurentde070132010-07-13 04:45:46 -0700856
Glenn Kastend848eb42016-03-08 13:42:11 -0800857 virtual status_t moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800858 audio_io_handle_t dstOutput)
Eric Laurentde070132010-07-13 04:45:46 -0700859 {
860 Parcel data, reply;
861 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
862 data.writeInt32(session);
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800863 data.writeInt32((int32_t) srcOutput);
864 data.writeInt32((int32_t) dstOutput);
Eric Laurentde070132010-07-13 04:45:46 -0700865 remote()->transact(MOVE_EFFECTS, data, &reply);
866 return reply.readInt32();
867 }
Eric Laurenta4c5a552012-03-29 10:12:40 -0700868
Eric Laurentb20cf7d2019-04-05 19:37:34 -0700869 virtual void setEffectSuspended(int effectId,
870 audio_session_t sessionId,
871 bool suspended)
872 {
873 Parcel data, reply;
874 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
875 data.writeInt32(effectId);
876 data.writeInt32(sessionId);
877 data.writeInt32(suspended ? 1 : 0);
878 remote()->transact(SET_EFFECT_SUSPENDED, data, &reply);
879 }
880
Eric Laurenta4c5a552012-03-29 10:12:40 -0700881 virtual audio_module_handle_t loadHwModule(const char *name)
882 {
883 Parcel data, reply;
884 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
885 data.writeCString(name);
886 remote()->transact(LOAD_HW_MODULE, data, &reply);
887 return (audio_module_handle_t) reply.readInt32();
888 }
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700889
Glenn Kasten3b16c762012-11-14 08:44:39 -0800890 virtual uint32_t getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700891 {
892 Parcel data, reply;
893 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
894 remote()->transact(GET_PRIMARY_OUTPUT_SAMPLING_RATE, data, &reply);
895 return reply.readInt32();
896 }
897
Glenn Kastene33054e2012-11-14 12:54:39 -0800898 virtual size_t getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700899 {
900 Parcel data, reply;
901 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
902 remote()->transact(GET_PRIMARY_OUTPUT_FRAME_COUNT, data, &reply);
Glenn Kastene03dd222014-01-28 11:04:39 -0800903 return reply.readInt64();
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700904 }
905
Andy Hung6f248bb2018-01-23 14:04:37 -0800906 virtual status_t setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) override
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700907 {
908 Parcel data, reply;
Andy Hung6f248bb2018-01-23 14:04:37 -0800909
910 static_assert(NO_ERROR == 0, "NO_ERROR must be 0");
911 return data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor())
912 ?: data.writeInt32((int) isLowRamDevice)
913 ?: data.writeInt64(totalMemory)
914 ?: remote()->transact(SET_LOW_RAM_DEVICE, data, &reply)
915 ?: reply.readInt32();
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700916 }
Andy Hung6f248bb2018-01-23 14:04:37 -0800917
Eric Laurent4b123402014-04-11 09:22:20 -0700918 virtual status_t listAudioPorts(unsigned int *num_ports,
919 struct audio_port *ports)
920 {
921 if (num_ports == NULL || *num_ports == 0 || ports == NULL) {
922 return BAD_VALUE;
923 }
924 Parcel data, reply;
925 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
926 data.writeInt32(*num_ports);
927 status_t status = remote()->transact(LIST_AUDIO_PORTS, data, &reply);
928 if (status != NO_ERROR ||
929 (status = (status_t)reply.readInt32()) != NO_ERROR) {
930 return status;
931 }
932 *num_ports = (unsigned int)reply.readInt32();
933 reply.read(ports, *num_ports * sizeof(struct audio_port));
934 return status;
935 }
jiabinb4fed192020-09-22 14:45:40 -0700936 virtual status_t getAudioPort(struct audio_port_v7 *port)
Eric Laurent4b123402014-04-11 09:22:20 -0700937 {
jiabinb4fed192020-09-22 14:45:40 -0700938 if (port == nullptr) {
Eric Laurent4b123402014-04-11 09:22:20 -0700939 return BAD_VALUE;
940 }
941 Parcel data, reply;
942 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
jiabinb4fed192020-09-22 14:45:40 -0700943 data.write(port, sizeof(struct audio_port_v7));
Eric Laurent4b123402014-04-11 09:22:20 -0700944 status_t status = remote()->transact(GET_AUDIO_PORT, data, &reply);
945 if (status != NO_ERROR ||
946 (status = (status_t)reply.readInt32()) != NO_ERROR) {
947 return status;
948 }
949 reply.read(port, sizeof(struct audio_port));
950 return status;
951 }
952 virtual status_t createAudioPatch(const struct audio_patch *patch,
953 audio_patch_handle_t *handle)
954 {
955 if (patch == NULL || handle == NULL) {
956 return BAD_VALUE;
957 }
958 Parcel data, reply;
959 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
960 data.write(patch, sizeof(struct audio_patch));
961 data.write(handle, sizeof(audio_patch_handle_t));
962 status_t status = remote()->transact(CREATE_AUDIO_PATCH, data, &reply);
963 if (status != NO_ERROR ||
964 (status = (status_t)reply.readInt32()) != NO_ERROR) {
965 return status;
966 }
967 reply.read(handle, sizeof(audio_patch_handle_t));
968 return status;
969 }
970 virtual status_t releaseAudioPatch(audio_patch_handle_t handle)
971 {
972 Parcel data, reply;
973 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
974 data.write(&handle, sizeof(audio_patch_handle_t));
975 status_t status = remote()->transact(RELEASE_AUDIO_PATCH, data, &reply);
976 if (status != NO_ERROR) {
977 status = (status_t)reply.readInt32();
978 }
979 return status;
980 }
981 virtual status_t listAudioPatches(unsigned int *num_patches,
982 struct audio_patch *patches)
983 {
984 if (num_patches == NULL || *num_patches == 0 || patches == NULL) {
985 return BAD_VALUE;
986 }
987 Parcel data, reply;
988 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
989 data.writeInt32(*num_patches);
990 status_t status = remote()->transact(LIST_AUDIO_PATCHES, data, &reply);
991 if (status != NO_ERROR ||
992 (status = (status_t)reply.readInt32()) != NO_ERROR) {
993 return status;
994 }
995 *num_patches = (unsigned int)reply.readInt32();
996 reply.read(patches, *num_patches * sizeof(struct audio_patch));
997 return status;
998 }
999 virtual status_t setAudioPortConfig(const struct audio_port_config *config)
1000 {
1001 if (config == NULL) {
1002 return BAD_VALUE;
1003 }
1004 Parcel data, reply;
1005 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
1006 data.write(config, sizeof(struct audio_port_config));
1007 status_t status = remote()->transact(SET_AUDIO_PORT_CONFIG, data, &reply);
1008 if (status != NO_ERROR) {
1009 status = (status_t)reply.readInt32();
1010 }
1011 return status;
1012 }
Eric Laurent93c3d412014-08-01 14:48:35 -07001013 virtual audio_hw_sync_t getAudioHwSyncForSession(audio_session_t sessionId)
1014 {
1015 Parcel data, reply;
1016 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
1017 data.writeInt32(sessionId);
Glenn Kasten9eae0362016-04-19 09:09:14 -07001018 status_t status = remote()->transact(GET_AUDIO_HW_SYNC_FOR_SESSION, data, &reply);
Eric Laurent93c3d412014-08-01 14:48:35 -07001019 if (status != NO_ERROR) {
1020 return AUDIO_HW_SYNC_INVALID;
1021 }
1022 return (audio_hw_sync_t)reply.readInt32();
1023 }
Eric Laurent72e3f392015-05-20 14:43:50 -07001024 virtual status_t systemReady()
1025 {
1026 Parcel data, reply;
1027 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
1028 return remote()->transact(SYSTEM_READY, data, &reply, IBinder::FLAG_ONEWAY);
1029 }
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001030 virtual size_t frameCountHAL(audio_io_handle_t ioHandle) const
1031 {
1032 Parcel data, reply;
1033 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
1034 data.writeInt32((int32_t) ioHandle);
1035 status_t status = remote()->transact(FRAME_COUNT_HAL, data, &reply);
1036 if (status != NO_ERROR) {
1037 return 0;
1038 }
1039 return reply.readInt64();
1040 }
jiabin46a76fa2018-01-05 10:18:21 -08001041 virtual status_t getMicrophones(std::vector<media::MicrophoneInfo> *microphones)
1042 {
1043 Parcel data, reply;
1044 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
jiabin9ff780e2018-03-19 18:19:52 -07001045 status_t status = remote()->transact(GET_MICROPHONES, data, &reply);
jiabin46a76fa2018-01-05 10:18:21 -08001046 if (status != NO_ERROR ||
1047 (status = (status_t)reply.readInt32()) != NO_ERROR) {
1048 return status;
1049 }
1050 status = reply.readParcelableVector(microphones);
1051 return status;
1052 }
Eric Laurent42896a02019-09-27 15:40:33 -07001053 virtual status_t setAudioHalPids(const std::vector<pid_t>& pids)
1054 {
1055 Parcel data, reply;
1056 data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
1057 data.writeInt32(pids.size());
1058 for (auto pid : pids) {
1059 data.writeInt32(pid);
1060 }
1061 status_t status = remote()->transact(SET_AUDIO_HAL_PIDS, data, &reply);
1062 if (status != NO_ERROR) {
1063 return status;
1064 }
1065 return static_cast <status_t> (reply.readInt32());
1066 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001067};
1068
1069IMPLEMENT_META_INTERFACE(AudioFlinger, "android.media.IAudioFlinger");
1070
1071// ----------------------------------------------------------------------
1072
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001073status_t BnAudioFlinger::onTransact(
1074 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
1075{
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001076 // make sure transactions reserved to AudioPolicyManager do not come from other processes
1077 switch (code) {
1078 case SET_STREAM_VOLUME:
1079 case SET_STREAM_MUTE:
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001080 case OPEN_OUTPUT:
1081 case OPEN_DUPLICATE_OUTPUT:
1082 case CLOSE_OUTPUT:
1083 case SUSPEND_OUTPUT:
1084 case RESTORE_OUTPUT:
1085 case OPEN_INPUT:
1086 case CLOSE_INPUT:
1087 case INVALIDATE_STREAM:
1088 case SET_VOICE_VOLUME:
1089 case MOVE_EFFECTS:
Eric Laurentb20cf7d2019-04-05 19:37:34 -07001090 case SET_EFFECT_SUSPENDED:
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001091 case LOAD_HW_MODULE:
1092 case LIST_AUDIO_PORTS:
1093 case GET_AUDIO_PORT:
1094 case CREATE_AUDIO_PATCH:
1095 case RELEASE_AUDIO_PATCH:
1096 case LIST_AUDIO_PATCHES:
1097 case SET_AUDIO_PORT_CONFIG:
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001098 case SET_RECORD_SILENCED:
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001099 ALOGW("%s: transaction %d received from PID %d",
1100 __func__, code, IPCThreadState::self()->getCallingPid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001101 // return status only for non void methods
1102 switch (code) {
1103 case SET_RECORD_SILENCED:
Eric Laurentb20cf7d2019-04-05 19:37:34 -07001104 case SET_EFFECT_SUSPENDED:
Eric Laurentef92bff2018-04-26 10:44:50 -07001105 break;
1106 default:
1107 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1108 break;
1109 }
1110 return OK;
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001111 default:
1112 break;
1113 }
1114
Eric Laurent4980df22018-01-26 18:04:09 -08001115 // make sure the following transactions come from system components
1116 switch (code) {
1117 case SET_MASTER_VOLUME:
1118 case SET_MASTER_MUTE:
1119 case SET_MODE:
1120 case SET_MIC_MUTE:
1121 case SET_LOW_RAM_DEVICE:
Eric Laurent42896a02019-09-27 15:40:33 -07001122 case SYSTEM_READY:
1123 case SET_AUDIO_HAL_PIDS: {
Andy Hung4ef19fa2018-05-15 19:35:29 -07001124 if (!isServiceUid(IPCThreadState::self()->getCallingUid())) {
Eric Laurent4980df22018-01-26 18:04:09 -08001125 ALOGW("%s: transaction %d received from PID %d unauthorized UID %d",
1126 __func__, code, IPCThreadState::self()->getCallingPid(),
1127 IPCThreadState::self()->getCallingUid());
Eric Laurentef92bff2018-04-26 10:44:50 -07001128 // return status only for non void methods
1129 switch (code) {
1130 case SYSTEM_READY:
1131 break;
1132 default:
1133 reply->writeInt32(static_cast<int32_t> (INVALID_OPERATION));
1134 break;
1135 }
1136 return OK;
Eric Laurent4980df22018-01-26 18:04:09 -08001137 }
Eric Laurent96c7eed2018-03-26 17:57:01 -07001138 } break;
Eric Laurent4980df22018-01-26 18:04:09 -08001139 default:
1140 break;
1141 }
1142
Glenn Kasten67f95702020-06-22 16:42:52 -07001143 // List of relevant events that trigger log merging.
Nicolas Rouletdcdfaec2017-02-14 10:18:39 -08001144 // Log merging should activate during audio activity of any kind. This are considered the
1145 // most relevant events.
1146 // TODO should select more wisely the items from the list
1147 switch (code) {
1148 case CREATE_TRACK:
Eric Laurentf14db3c2017-12-08 14:20:36 -08001149 case CREATE_RECORD:
Nicolas Rouletdcdfaec2017-02-14 10:18:39 -08001150 case SET_MASTER_VOLUME:
1151 case SET_MASTER_MUTE:
Nicolas Rouletdcdfaec2017-02-14 10:18:39 -08001152 case SET_MIC_MUTE:
1153 case SET_PARAMETERS:
Nicolas Rouletdcdfaec2017-02-14 10:18:39 -08001154 case CREATE_EFFECT:
1155 case SYSTEM_READY: {
1156 requestLogMerge();
1157 break;
1158 }
1159 default:
1160 break;
1161 }
Eric Laurentb1cc36b2017-12-11 12:14:16 -08001162
Eric Laurent39b09b52018-06-29 12:24:40 -07001163 std::string tag("IAudioFlinger command " + std::to_string(code));
1164 TimeCheck check(tag.c_str());
Eric Laurent3528c932018-02-23 17:17:22 -08001165
Eric Laurent14dc3cb2020-09-16 18:42:23 -07001166 // Make sure we connect to Audio Policy Service before calling into AudioFlinger:
1167 // - AudioFlinger can call into Audio Policy Service with its global mutex held
1168 // - If this is the first time Audio Policy Service is queried from inside audioserver process
1169 // this will trigger Audio Policy Manager initialization.
1170 // - Audio Policy Manager initialization calls into AudioFlinger which will try to lock
1171 // its global mutex and a deadlock will occur.
1172 if (IPCThreadState::self()->getCallingPid() != getpid()) {
1173 AudioSystem::get_audio_policy_service();
1174 }
1175
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001176 switch (code) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001177 case CREATE_TRACK: {
1178 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurent21da6472017-11-09 16:29:26 -08001179
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -08001180 media::CreateTrackRequest input;
1181 if (data.readParcelable(&input) != NO_ERROR) {
Eric Laurent21da6472017-11-09 16:29:26 -08001182 reply->writeInt32(DEAD_OBJECT);
1183 return NO_ERROR;
Eric Laurent3d00aa62013-09-24 09:53:27 -07001184 }
Eric Laurent21da6472017-11-09 16:29:26 -08001185
1186 status_t status;
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -08001187 media::CreateTrackResponse output;
Eric Laurent21da6472017-11-09 16:29:26 -08001188
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -08001189 status = createTrack(input, output);
Eric Laurent21da6472017-11-09 16:29:26 -08001190
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -08001191 LOG_ALWAYS_FATAL_IF((output.audioTrack != 0) != (status == NO_ERROR));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001192 reply->writeInt32(status);
Eric Laurent21da6472017-11-09 16:29:26 -08001193 if (status != NO_ERROR) {
1194 return NO_ERROR;
1195 }
Eric Laurent21da6472017-11-09 16:29:26 -08001196 output.writeToParcel(reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001197 return NO_ERROR;
1198 } break;
Eric Laurentf14db3c2017-12-08 14:20:36 -08001199 case CREATE_RECORD: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001200 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf14db3c2017-12-08 14:20:36 -08001201
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -08001202 media::CreateRecordRequest input;
1203 if (data.readParcelable(&input) != NO_ERROR) {
Eric Laurentf14db3c2017-12-08 14:20:36 -08001204 reply->writeInt32(DEAD_OBJECT);
1205 return NO_ERROR;
1206 }
1207
1208 status_t status;
Ytai Ben-Tsvi4dfeb622020-11-02 12:47:30 -08001209 media::CreateRecordResponse output;
Eric Laurentf14db3c2017-12-08 14:20:36 -08001210
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -08001211 status = createRecord(input, output);
Eric Laurentf14db3c2017-12-08 14:20:36 -08001212
Ytai Ben-Tsvi16d87612020-11-03 16:32:36 -08001213 LOG_ALWAYS_FATAL_IF((output.audioRecord != 0) != (status == NO_ERROR));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001214 reply->writeInt32(status);
Eric Laurentf14db3c2017-12-08 14:20:36 -08001215 if (status != NO_ERROR) {
1216 return NO_ERROR;
1217 }
Eric Laurentf14db3c2017-12-08 14:20:36 -08001218 output.writeToParcel(reply);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001219 return NO_ERROR;
1220 } break;
1221 case SAMPLE_RATE: {
1222 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001223 reply->writeInt32( sampleRate((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001224 return NO_ERROR;
1225 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001226
1227 // RESERVED for channelCount()
1228
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001229 case FORMAT: {
1230 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001231 reply->writeInt32( format((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001232 return NO_ERROR;
1233 } break;
1234 case FRAME_COUNT: {
1235 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001236 reply->writeInt64( frameCount((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001237 return NO_ERROR;
1238 } break;
1239 case LATENCY: {
1240 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001241 reply->writeInt32( latency((audio_io_handle_t) data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001242 return NO_ERROR;
1243 } break;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001244 case SET_MASTER_VOLUME: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001245 CHECK_INTERFACE(IAudioFlinger, data, reply);
1246 reply->writeInt32( setMasterVolume(data.readFloat()) );
1247 return NO_ERROR;
1248 } break;
1249 case SET_MASTER_MUTE: {
1250 CHECK_INTERFACE(IAudioFlinger, data, reply);
1251 reply->writeInt32( setMasterMute(data.readInt32()) );
1252 return NO_ERROR;
1253 } break;
1254 case MASTER_VOLUME: {
1255 CHECK_INTERFACE(IAudioFlinger, data, reply);
1256 reply->writeFloat( masterVolume() );
1257 return NO_ERROR;
1258 } break;
1259 case MASTER_MUTE: {
1260 CHECK_INTERFACE(IAudioFlinger, data, reply);
1261 reply->writeInt32( masterMute() );
1262 return NO_ERROR;
1263 } break;
Richard Folke Tullberg3fae0372017-01-13 09:04:25 +01001264 case SET_MASTER_BALANCE: {
1265 CHECK_INTERFACE(IAudioFlinger, data, reply);
1266 reply->writeInt32( setMasterBalance(data.readFloat()) );
1267 return NO_ERROR;
1268 } break;
1269 case GET_MASTER_BALANCE: {
1270 CHECK_INTERFACE(IAudioFlinger, data, reply);
1271 float f;
1272 const status_t status = getMasterBalance(&f);
1273 reply->writeInt32((int32_t)status);
1274 if (status == NO_ERROR) {
1275 (void)reply->writeFloat(f);
1276 }
1277 return NO_ERROR;
1278 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001279 case SET_STREAM_VOLUME: {
1280 CHECK_INTERFACE(IAudioFlinger, data, reply);
1281 int stream = data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001282 float volume = data.readFloat();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001283 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001284 reply->writeInt32( setStreamVolume((audio_stream_type_t) stream, volume, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001285 return NO_ERROR;
1286 } break;
1287 case SET_STREAM_MUTE: {
1288 CHECK_INTERFACE(IAudioFlinger, data, reply);
1289 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001290 reply->writeInt32( setStreamMute((audio_stream_type_t) stream, data.readInt32()) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001291 return NO_ERROR;
1292 } break;
1293 case STREAM_VOLUME: {
1294 CHECK_INTERFACE(IAudioFlinger, data, reply);
1295 int stream = data.readInt32();
Eric Laurentfa2877b2009-07-28 08:44:33 -07001296 int output = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001297 reply->writeFloat( streamVolume((audio_stream_type_t) stream, output) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001298 return NO_ERROR;
1299 } break;
1300 case STREAM_MUTE: {
1301 CHECK_INTERFACE(IAudioFlinger, data, reply);
1302 int stream = data.readInt32();
Glenn Kastenfff6d712012-01-12 16:38:12 -08001303 reply->writeInt32( streamMute((audio_stream_type_t) stream) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001304 return NO_ERROR;
1305 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001306 case SET_MODE: {
1307 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastenf78aee72012-01-04 11:00:47 -08001308 audio_mode_t mode = (audio_mode_t) data.readInt32();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001309 reply->writeInt32( setMode(mode) );
1310 return NO_ERROR;
1311 } break;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001312 case SET_MIC_MUTE: {
1313 CHECK_INTERFACE(IAudioFlinger, data, reply);
1314 int state = data.readInt32();
1315 reply->writeInt32( setMicMute(state) );
1316 return NO_ERROR;
1317 } break;
1318 case GET_MIC_MUTE: {
1319 CHECK_INTERFACE(IAudioFlinger, data, reply);
1320 reply->writeInt32( getMicMute() );
1321 return NO_ERROR;
1322 } break;
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001323 case SET_RECORD_SILENCED: {
1324 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurent5ada82e2019-08-29 17:53:54 -07001325 audio_port_handle_t portId = data.readInt32();
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001326 bool silenced = data.readInt32() == 1;
Eric Laurent5ada82e2019-08-29 17:53:54 -07001327 setRecordSilenced(portId, silenced);
Svet Ganovf4ddfef2018-01-16 07:37:58 -08001328 return NO_ERROR;
1329 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001330 case SET_PARAMETERS: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001331 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001332 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001333 String8 keyValuePairs(data.readString8());
1334 reply->writeInt32(setParameters(ioHandle, keyValuePairs));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001335 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001336 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001337 case GET_PARAMETERS: {
1338 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001339 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001340 String8 keys(data.readString8());
1341 reply->writeString8(getParameters(ioHandle, keys));
1342 return NO_ERROR;
Glenn Kastene53b9ea2012-03-12 16:29:55 -07001343 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001344
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001345 case REGISTER_CLIENT: {
1346 CHECK_INTERFACE(IAudioFlinger, data, reply);
Ytai Ben-Tsvi10dc0a62020-09-18 11:31:55 -07001347 sp<media::IAudioFlingerClient> client = interface_cast<media::IAudioFlingerClient>(
Glenn Kasten85ab62c2012-11-01 11:11:38 -07001348 data.readStrongBinder());
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001349 registerClient(client);
1350 return NO_ERROR;
1351 } break;
1352 case GET_INPUTBUFFERSIZE: {
1353 CHECK_INTERFACE(IAudioFlinger, data, reply);
1354 uint32_t sampleRate = data.readInt32();
Glenn Kasten58f30212012-01-12 12:27:51 -08001355 audio_format_t format = (audio_format_t) data.readInt32();
Mikhail Naganov55773032020-10-01 15:08:13 -07001356 audio_channel_mask_t channelMask = (audio_channel_mask_t) data.readInt32();
Glenn Kastene03dd222014-01-28 11:04:39 -08001357 reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001358 return NO_ERROR;
1359 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001360 case OPEN_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001361 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001362 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001363 audio_config_t config = {};
1364 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1365 ALOGE("b/23905951");
1366 }
jiabin43810402019-10-24 14:58:31 -07001367 sp<DeviceDescriptorBase> device = new DeviceDescriptorBase(AUDIO_DEVICE_NONE);
1368 status_t status = NO_ERROR;
1369 if ((status = data.readParcelable(device.get())) != NO_ERROR) {
1370 reply->writeInt32((int32_t)status);
1371 return NO_ERROR;
1372 }
Eric Laurent0ca3cf92012-04-18 09:24:29 -07001373 audio_output_flags_t flags = (audio_output_flags_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001374 uint32_t latencyMs = 0;
Wei Jia4cac44b2015-09-16 15:01:16 -07001375 audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
jiabin43810402019-10-24 14:58:31 -07001376 status = openOutput(module, &output, &config, device, &latencyMs, flags);
Glenn Kasten70742962014-02-18 08:00:47 -08001377 ALOGV("OPEN_OUTPUT output, %d", output);
Eric Laurentcf2c0212014-07-25 16:20:43 -07001378 reply->writeInt32((int32_t)status);
1379 if (status == NO_ERROR) {
1380 reply->writeInt32((int32_t)output);
1381 reply->write(&config, sizeof(audio_config_t));
Eric Laurentcf2c0212014-07-25 16:20:43 -07001382 reply->writeInt32(latencyMs);
1383 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001384 return NO_ERROR;
1385 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -07001386 case OPEN_DUPLICATE_OUTPUT: {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001387 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001388 audio_io_handle_t output1 = (audio_io_handle_t) data.readInt32();
1389 audio_io_handle_t output2 = (audio_io_handle_t) data.readInt32();
1390 reply->writeInt32((int32_t) openDuplicateOutput(output1, output2));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001391 return NO_ERROR;
1392 } break;
1393 case CLOSE_OUTPUT: {
1394 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001395 reply->writeInt32(closeOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001396 return NO_ERROR;
1397 } break;
1398 case SUSPEND_OUTPUT: {
1399 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001400 reply->writeInt32(suspendOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001401 return NO_ERROR;
1402 } break;
1403 case RESTORE_OUTPUT: {
1404 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001405 reply->writeInt32(restoreOutput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001406 return NO_ERROR;
1407 } break;
1408 case OPEN_INPUT: {
1409 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurenta4c5a552012-03-29 10:12:40 -07001410 audio_module_handle_t module = (audio_module_handle_t)data.readInt32();
Eric Laurentcf2c0212014-07-25 16:20:43 -07001411 audio_io_handle_t input = (audio_io_handle_t)data.readInt32();
Wei Jiae995e472015-09-09 09:48:34 -07001412 audio_config_t config = {};
1413 if (data.read(&config, sizeof(audio_config_t)) != NO_ERROR) {
1414 ALOGE("b/23905951");
1415 }
Eric Laurentcf2c0212014-07-25 16:20:43 -07001416 audio_devices_t device = (audio_devices_t)data.readInt32();
1417 String8 address(data.readString8());
1418 audio_source_t source = (audio_source_t)data.readInt32();
Glenn Kastenec40d282014-07-15 15:31:26 -07001419 audio_input_flags_t flags = (audio_input_flags_t) data.readInt32();
Eric Laurentc2f1f072009-07-17 12:17:14 -07001420
Eric Laurentcf2c0212014-07-25 16:20:43 -07001421 status_t status = openInput(module, &input, &config,
1422 &device, address, source, flags);
1423 reply->writeInt32((int32_t) status);
1424 if (status == NO_ERROR) {
1425 reply->writeInt32((int32_t) input);
1426 reply->write(&config, sizeof(audio_config_t));
1427 reply->writeInt32(device);
1428 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001429 return NO_ERROR;
1430 } break;
1431 case CLOSE_INPUT: {
1432 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001433 reply->writeInt32(closeInput((audio_io_handle_t) data.readInt32()));
Eric Laurentc2f1f072009-07-17 12:17:14 -07001434 return NO_ERROR;
1435 } break;
Glenn Kastend2304db2014-02-03 07:40:31 -08001436 case INVALIDATE_STREAM: {
Eric Laurentc2f1f072009-07-17 12:17:14 -07001437 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend2304db2014-02-03 07:40:31 -08001438 audio_stream_type_t stream = (audio_stream_type_t) data.readInt32();
1439 reply->writeInt32(invalidateStream(stream));
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001440 return NO_ERROR;
1441 } break;
Eric Laurentf0ee6f42009-10-21 08:14:22 -07001442 case SET_VOICE_VOLUME: {
1443 CHECK_INTERFACE(IAudioFlinger, data, reply);
1444 float volume = data.readFloat();
1445 reply->writeInt32( setVoiceVolume(volume) );
1446 return NO_ERROR;
1447 } break;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001448 case GET_RENDER_POSITION: {
1449 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001450 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Wei Jia983dca32015-09-10 09:47:29 -07001451 uint32_t halFrames = 0;
1452 uint32_t dspFrames = 0;
Eric Laurent342e9cf2010-01-19 17:37:09 -08001453 status_t status = getRenderPosition(&halFrames, &dspFrames, output);
1454 reply->writeInt32(status);
1455 if (status == NO_ERROR) {
1456 reply->writeInt32(halFrames);
1457 reply->writeInt32(dspFrames);
1458 }
1459 return NO_ERROR;
1460 }
Eric Laurent05bca2f2010-02-26 02:47:27 -08001461 case GET_INPUT_FRAMES_LOST: {
1462 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001463 audio_io_handle_t ioHandle = (audio_io_handle_t) data.readInt32();
Glenn Kasten5f972c02014-01-13 09:59:31 -08001464 reply->writeInt32((int32_t) getInputFramesLost(ioHandle));
Eric Laurent05bca2f2010-02-26 02:47:27 -08001465 return NO_ERROR;
1466 } break;
Glenn Kasten9eae0362016-04-19 09:09:14 -07001467 case NEW_AUDIO_UNIQUE_ID: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001468 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kasteneeecb982016-02-26 10:44:04 -08001469 reply->writeInt32(newAudioUniqueId((audio_unique_id_use_t) data.readInt32()));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001470 return NO_ERROR;
1471 } break;
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001472 case ACQUIRE_AUDIO_SESSION_ID: {
1473 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001474 audio_session_t audioSession = (audio_session_t) data.readInt32();
Andy Hung8b0bfd92019-12-23 13:11:11 -08001475 const pid_t pid = (pid_t)data.readInt32();
1476 const uid_t uid = (uid_t)data.readInt32();
1477 acquireAudioSessionId(audioSession, pid, uid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001478 return NO_ERROR;
1479 } break;
1480 case RELEASE_AUDIO_SESSION_ID: {
1481 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001482 audio_session_t audioSession = (audio_session_t) data.readInt32();
Marco Nelissend457c972014-02-11 08:47:07 -08001483 int pid = data.readInt32();
1484 releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -07001485 return NO_ERROR;
1486 } break;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001487 case QUERY_NUM_EFFECTS: {
1488 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001489 uint32_t numEffects = 0;
Eric Laurentbe916aa2010-06-01 23:49:17 -07001490 status_t status = queryNumberEffects(&numEffects);
1491 reply->writeInt32(status);
1492 if (status == NO_ERROR) {
1493 reply->writeInt32((int32_t)numEffects);
1494 }
1495 return NO_ERROR;
1496 }
Eric Laurentffe9c252010-06-23 17:38:20 -07001497 case QUERY_EFFECT: {
Eric Laurentbe916aa2010-06-01 23:49:17 -07001498 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jia983dca32015-09-10 09:47:29 -07001499 effect_descriptor_t desc = {};
Eric Laurentffe9c252010-06-23 17:38:20 -07001500 status_t status = queryEffect(data.readInt32(), &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001501 reply->writeInt32(status);
1502 if (status == NO_ERROR) {
1503 reply->write(&desc, sizeof(effect_descriptor_t));
1504 }
1505 return NO_ERROR;
1506 }
1507 case GET_EFFECT_DESCRIPTOR: {
1508 CHECK_INTERFACE(IAudioFlinger, data, reply);
Andy Hungf85d1292019-08-21 14:45:41 -07001509 effect_uuid_t uuid = {};
1510 if (data.read(&uuid, sizeof(effect_uuid_t)) != NO_ERROR) {
1511 android_errorWriteLog(0x534e4554, "139417189");
1512 }
1513 effect_uuid_t type = {};
1514 if (data.read(&type, sizeof(effect_uuid_t)) != NO_ERROR) {
1515 android_errorWriteLog(0x534e4554, "139417189");
1516 }
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -07001517 uint32_t preferredTypeFlag = data.readUint32();
Wei Jia983dca32015-09-10 09:47:29 -07001518 effect_descriptor_t desc = {};
Ari Hausman-Cohen2046ec72018-04-24 14:00:55 -07001519 status_t status = getEffectDescriptor(&uuid, &type, preferredTypeFlag, &desc);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001520 reply->writeInt32(status);
1521 if (status == NO_ERROR) {
1522 reply->write(&desc, sizeof(effect_descriptor_t));
1523 }
1524 return NO_ERROR;
1525 }
1526 case CREATE_EFFECT: {
1527 CHECK_INTERFACE(IAudioFlinger, data, reply);
Wei Jiae995e472015-09-09 09:48:34 -07001528 effect_descriptor_t desc = {};
1529 if (data.read(&desc, sizeof(effect_descriptor_t)) != NO_ERROR) {
1530 ALOGE("b/23905951");
1531 }
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -07001532 sp<media::IEffectClient> client =
1533 interface_cast<media::IEffectClient>(data.readStrongBinder());
Eric Laurentbe916aa2010-06-01 23:49:17 -07001534 int32_t priority = data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001535 audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
Glenn Kastend848eb42016-03-08 13:42:11 -08001536 audio_session_t sessionId = (audio_session_t) data.readInt32();
Eric Laurent94876032019-11-13 12:45:28 -08001537 AudioDeviceTypeAddr device;
1538 status_t status = NO_ERROR;
1539 if ((status = data.readParcelable(&device)) != NO_ERROR) {
1540 return status;
1541 }
Svet Ganovbe71aa22015-04-28 12:06:02 -07001542 const String16 opPackageName = data.readString16();
Eric Laurentb6436272016-12-07 19:24:50 -08001543 pid_t pid = (pid_t)data.readInt32();
Eric Laurent2fe0acd2020-03-13 14:30:46 -07001544 bool probe = data.readInt32() == 1;
Eric Laurentb6436272016-12-07 19:24:50 -08001545
Wei Jia983dca32015-09-10 09:47:29 -07001546 int id = 0;
1547 int enabled = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -08001548
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -07001549 sp<media::IEffect> effect = createEffect(&desc, client, priority, output, sessionId,
1550 device, opPackageName, pid, probe, &status, &id, &enabled);
Eric Laurentbe916aa2010-06-01 23:49:17 -07001551 reply->writeInt32(status);
1552 reply->writeInt32(id);
1553 reply->writeInt32(enabled);
Marco Nelissen06b46062014-11-14 07:58:25 -08001554 reply->writeStrongBinder(IInterface::asBinder(effect));
Eric Laurentbe916aa2010-06-01 23:49:17 -07001555 reply->write(&desc, sizeof(effect_descriptor_t));
1556 return NO_ERROR;
1557 } break;
Eric Laurentde070132010-07-13 04:45:46 -07001558 case MOVE_EFFECTS: {
1559 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001560 audio_session_t session = (audio_session_t) data.readInt32();
Glenn Kasten72ef00d2012-01-17 11:09:42 -08001561 audio_io_handle_t srcOutput = (audio_io_handle_t) data.readInt32();
1562 audio_io_handle_t dstOutput = (audio_io_handle_t) data.readInt32();
Eric Laurentde070132010-07-13 04:45:46 -07001563 reply->writeInt32(moveEffects(session, srcOutput, dstOutput));
1564 return NO_ERROR;
1565 } break;
Eric Laurentb20cf7d2019-04-05 19:37:34 -07001566 case SET_EFFECT_SUSPENDED: {
1567 CHECK_INTERFACE(IAudioFlinger, data, reply);
1568 int effectId = data.readInt32();
1569 audio_session_t sessionId = (audio_session_t) data.readInt32();
1570 bool suspended = data.readInt32() == 1;
1571 setEffectSuspended(effectId, sessionId, suspended);
1572 return NO_ERROR;
1573 } break;
Eric Laurenta4c5a552012-03-29 10:12:40 -07001574 case LOAD_HW_MODULE: {
1575 CHECK_INTERFACE(IAudioFlinger, data, reply);
1576 reply->writeInt32(loadHwModule(data.readCString()));
1577 return NO_ERROR;
1578 } break;
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001579 case GET_PRIMARY_OUTPUT_SAMPLING_RATE: {
1580 CHECK_INTERFACE(IAudioFlinger, data, reply);
1581 reply->writeInt32(getPrimaryOutputSamplingRate());
1582 return NO_ERROR;
1583 } break;
1584 case GET_PRIMARY_OUTPUT_FRAME_COUNT: {
1585 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastene03dd222014-01-28 11:04:39 -08001586 reply->writeInt64(getPrimaryOutputFrameCount());
Glenn Kastencc0f1cf2012-09-24 11:27:18 -07001587 return NO_ERROR;
1588 } break;
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001589 case SET_LOW_RAM_DEVICE: {
1590 CHECK_INTERFACE(IAudioFlinger, data, reply);
Andy Hung6f248bb2018-01-23 14:04:37 -08001591 int32_t isLowRamDevice;
1592 int64_t totalMemory;
1593 const status_t status =
1594 data.readInt32(&isLowRamDevice) ?:
1595 data.readInt64(&totalMemory) ?:
1596 setLowRamDevice(isLowRamDevice != 0, totalMemory);
1597 (void)reply->writeInt32(status);
Glenn Kasten4182c4e2013-07-15 14:45:07 -07001598 return NO_ERROR;
1599 } break;
Eric Laurent4b123402014-04-11 09:22:20 -07001600 case LIST_AUDIO_PORTS: {
1601 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001602 unsigned int numPortsReq = data.readInt32();
1603 if (numPortsReq > MAX_ITEMS_PER_LIST) {
1604 numPortsReq = MAX_ITEMS_PER_LIST;
1605 }
1606 unsigned int numPorts = numPortsReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001607 struct audio_port *ports =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001608 (struct audio_port *)calloc(numPortsReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001609 sizeof(struct audio_port));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001610 if (ports == NULL) {
1611 reply->writeInt32(NO_MEMORY);
1612 reply->writeInt32(0);
1613 return NO_ERROR;
1614 }
1615 status_t status = listAudioPorts(&numPorts, ports);
Eric Laurent4b123402014-04-11 09:22:20 -07001616 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001617 reply->writeInt32(numPorts);
Eric Laurent4b123402014-04-11 09:22:20 -07001618 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001619 if (numPortsReq > numPorts) {
1620 numPortsReq = numPorts;
1621 }
1622 reply->write(ports, numPortsReq * sizeof(struct audio_port));
Eric Laurent4b123402014-04-11 09:22:20 -07001623 }
1624 free(ports);
1625 return NO_ERROR;
1626 } break;
1627 case GET_AUDIO_PORT: {
1628 CHECK_INTERFACE(IAudioFlinger, data, reply);
jiabinb4fed192020-09-22 14:45:40 -07001629 struct audio_port_v7 port = {};
Eric Laurent4dacbc32020-10-07 13:48:21 -07001630 status_t status = data.read(&port, sizeof(struct audio_port));
1631 if (status != NO_ERROR) {
Wei Jiae995e472015-09-09 09:48:34 -07001632 ALOGE("b/23905951");
Eric Laurent4dacbc32020-10-07 13:48:21 -07001633 return status;
Wei Jiae995e472015-09-09 09:48:34 -07001634 }
Eric Laurent4dacbc32020-10-07 13:48:21 -07001635 status = AudioSanitizer::sanitizeAudioPort(&port);
1636 if (status == NO_ERROR) {
1637 status = getAudioPort(&port);
1638 }
Eric Laurent4b123402014-04-11 09:22:20 -07001639 reply->writeInt32(status);
1640 if (status == NO_ERROR) {
jiabinb4fed192020-09-22 14:45:40 -07001641 reply->write(&port, sizeof(struct audio_port_v7));
Eric Laurent4b123402014-04-11 09:22:20 -07001642 }
1643 return NO_ERROR;
1644 } break;
1645 case CREATE_AUDIO_PATCH: {
1646 CHECK_INTERFACE(IAudioFlinger, data, reply);
1647 struct audio_patch patch;
Eric Laurent4dacbc32020-10-07 13:48:21 -07001648 status_t status = data.read(&patch, sizeof(struct audio_patch));
1649 if (status != NO_ERROR) {
1650 return status;
Wei Jiae995e472015-09-09 09:48:34 -07001651 }
Eric Laurent4dacbc32020-10-07 13:48:21 -07001652 audio_patch_handle_t handle = AUDIO_PATCH_HANDLE_NONE;
1653 status = data.read(&handle, sizeof(audio_patch_handle_t));
1654 if (status != NO_ERROR) {
1655 ALOGE("b/23905951");
1656 return status;
1657 }
1658 status = AudioSanitizer::sanitizeAudioPatch(&patch);
1659 if (status == NO_ERROR) {
1660 status = createAudioPatch(&patch, &handle);
1661 }
Eric Laurent4b123402014-04-11 09:22:20 -07001662 reply->writeInt32(status);
1663 if (status == NO_ERROR) {
1664 reply->write(&handle, sizeof(audio_patch_handle_t));
1665 }
1666 return NO_ERROR;
1667 } break;
1668 case RELEASE_AUDIO_PATCH: {
1669 CHECK_INTERFACE(IAudioFlinger, data, reply);
1670 audio_patch_handle_t handle;
1671 data.read(&handle, sizeof(audio_patch_handle_t));
1672 status_t status = releaseAudioPatch(handle);
1673 reply->writeInt32(status);
1674 return NO_ERROR;
1675 } break;
1676 case LIST_AUDIO_PATCHES: {
1677 CHECK_INTERFACE(IAudioFlinger, data, reply);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001678 unsigned int numPatchesReq = data.readInt32();
1679 if (numPatchesReq > MAX_ITEMS_PER_LIST) {
1680 numPatchesReq = MAX_ITEMS_PER_LIST;
1681 }
1682 unsigned int numPatches = numPatchesReq;
Eric Laurent4b123402014-04-11 09:22:20 -07001683 struct audio_patch *patches =
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001684 (struct audio_patch *)calloc(numPatchesReq,
Eric Laurent4b123402014-04-11 09:22:20 -07001685 sizeof(struct audio_patch));
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001686 if (patches == NULL) {
1687 reply->writeInt32(NO_MEMORY);
1688 reply->writeInt32(0);
1689 return NO_ERROR;
1690 }
1691 status_t status = listAudioPatches(&numPatches, patches);
Eric Laurent4b123402014-04-11 09:22:20 -07001692 reply->writeInt32(status);
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001693 reply->writeInt32(numPatches);
Eric Laurent4b123402014-04-11 09:22:20 -07001694 if (status == NO_ERROR) {
Eric Laurentf75c2fe2015-04-02 13:49:15 -07001695 if (numPatchesReq > numPatches) {
1696 numPatchesReq = numPatches;
1697 }
1698 reply->write(patches, numPatchesReq * sizeof(struct audio_patch));
Eric Laurent4b123402014-04-11 09:22:20 -07001699 }
1700 free(patches);
1701 return NO_ERROR;
1702 } break;
1703 case SET_AUDIO_PORT_CONFIG: {
1704 CHECK_INTERFACE(IAudioFlinger, data, reply);
1705 struct audio_port_config config;
Eric Laurent4dacbc32020-10-07 13:48:21 -07001706 status_t status = data.read(&config, sizeof(struct audio_port_config));
1707 if (status != NO_ERROR) {
1708 return status;
1709 }
1710 status = AudioSanitizer::sanitizeAudioPortConfig(&config);
1711 if (status == NO_ERROR) {
1712 status = setAudioPortConfig(&config);
1713 }
Eric Laurent4b123402014-04-11 09:22:20 -07001714 reply->writeInt32(status);
1715 return NO_ERROR;
1716 } break;
Glenn Kasten9eae0362016-04-19 09:09:14 -07001717 case GET_AUDIO_HW_SYNC_FOR_SESSION: {
Eric Laurent93c3d412014-08-01 14:48:35 -07001718 CHECK_INTERFACE(IAudioFlinger, data, reply);
Glenn Kastend848eb42016-03-08 13:42:11 -08001719 reply->writeInt32(getAudioHwSyncForSession((audio_session_t) data.readInt32()));
Eric Laurent93c3d412014-08-01 14:48:35 -07001720 return NO_ERROR;
1721 } break;
Eric Laurent72e3f392015-05-20 14:43:50 -07001722 case SYSTEM_READY: {
1723 CHECK_INTERFACE(IAudioFlinger, data, reply);
1724 systemReady();
1725 return NO_ERROR;
1726 } break;
Glenn Kasten4a8308b2016-04-18 14:10:01 -07001727 case FRAME_COUNT_HAL: {
1728 CHECK_INTERFACE(IAudioFlinger, data, reply);
1729 reply->writeInt64( frameCountHAL((audio_io_handle_t) data.readInt32()) );
1730 return NO_ERROR;
1731 } break;
jiabin9ff780e2018-03-19 18:19:52 -07001732 case GET_MICROPHONES: {
jiabin46a76fa2018-01-05 10:18:21 -08001733 CHECK_INTERFACE(IAudioFlinger, data, reply);
1734 std::vector<media::MicrophoneInfo> microphones;
1735 status_t status = getMicrophones(&microphones);
1736 reply->writeInt32(status);
1737 if (status == NO_ERROR) {
1738 reply->writeParcelableVector(microphones);
1739 }
1740 return NO_ERROR;
1741 }
Eric Laurent42896a02019-09-27 15:40:33 -07001742 case SET_AUDIO_HAL_PIDS: {
1743 CHECK_INTERFACE(IAudioFlinger, data, reply);
1744 std::vector<pid_t> pids;
1745 int32_t size;
1746 status_t status = data.readInt32(&size);
1747 if (status != NO_ERROR) {
1748 return status;
1749 }
1750 if (size < 0) {
1751 return BAD_VALUE;
1752 }
1753 if (size > MAX_ITEMS_PER_LIST) {
1754 size = MAX_ITEMS_PER_LIST;
1755 }
1756 for (int32_t i = 0; i < size; i++) {
1757 int32_t pid;
1758 status = data.readInt32(&pid);
1759 if (status != NO_ERROR) {
1760 return status;
1761 }
1762 pids.push_back(pid);
1763 }
1764 reply->writeInt32(setAudioHalPids(pids));
1765 return NO_ERROR;
1766 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001767 default:
1768 return BBinder::onTransact(code, data, reply, flags);
1769 }
1770}
1771
1772// ----------------------------------------------------------------------------
1773
Glenn Kasten40bc9062015-03-20 09:09:33 -07001774} // namespace android