1 /*
2 **
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"
19 //#define LOG_NDEBUG 0
20
21 #include <utils/Log.h>
22
23 #include <stdint.h>
24 #include <sys/types.h>
25 #include "IAudioFlinger.h"
26 #include <binder/IPCThreadState.h>
27 #include <binder/Parcel.h>
28 #include <system/thread_defs.h>
29
30 namespace android {
31
32 using aidl_utils::statusTFromBinderStatus;
33 using binder::Status;
34 using media::audio::common::AudioChannelLayout;
35 using media::audio::common::AudioFormatDescription;
36 using media::audio::common::AudioMMapPolicyInfo;
37 using media::audio::common::AudioMMapPolicyType;
38 using media::audio::common::AudioMode;
39 using media::audio::common::AudioStreamType;
40 using media::audio::common::AudioUuid;
41
42 #define MAX_ITEMS_PER_LIST 1024
43
44 #define VALUE_OR_RETURN_BINDER(x) \
45 ({ \
46 auto _tmp = (x); \
47 if (!_tmp.ok()) return Status::fromStatusT(_tmp.error()); \
48 std::move(_tmp.value()); \
49 })
50
51 #define RETURN_BINDER_IF_ERROR(x) \
52 { \
53 auto _tmp = (x); \
54 if (_tmp != OK) return Status::fromStatusT(_tmp); \
55 }
56
toAidl() const57 ConversionResult<media::CreateTrackRequest> IAudioFlinger::CreateTrackInput::toAidl() const {
58 media::CreateTrackRequest aidl;
59 aidl.attr = VALUE_OR_RETURN(legacy2aidl_audio_attributes_t_AudioAttributes(attr));
60 // Do not be mislead by 'Input'--this is an input to 'createTrack', which creates output tracks.
61 aidl.config = VALUE_OR_RETURN(legacy2aidl_audio_config_t_AudioConfig(
62 config, false /*isInput*/));
63 aidl.clientInfo = VALUE_OR_RETURN(legacy2aidl_AudioClient_AudioClient(clientInfo));
64 aidl.sharedBuffer = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(sharedBuffer));
65 aidl.notificationsPerBuffer = VALUE_OR_RETURN(convertIntegral<int32_t>(notificationsPerBuffer));
66 aidl.speed = speed;
67 aidl.audioTrackCallback = audioTrackCallback;
68 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_output_flags_t_int32_t_mask(flags));
69 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
70 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
71 aidl.selectedDeviceId = VALUE_OR_RETURN(
72 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
73 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
74 return aidl;
75 }
76
77 ConversionResult<IAudioFlinger::CreateTrackInput>
fromAidl(const media::CreateTrackRequest & aidl)78 IAudioFlinger::CreateTrackInput::fromAidl(const media::CreateTrackRequest& aidl) {
79 IAudioFlinger::CreateTrackInput legacy;
80 legacy.attr = VALUE_OR_RETURN(aidl2legacy_AudioAttributes_audio_attributes_t(aidl.attr));
81 // Do not be mislead by 'Input'--this is an input to 'createTrack', which creates output tracks.
82 legacy.config = VALUE_OR_RETURN(
83 aidl2legacy_AudioConfig_audio_config_t(aidl.config, false /*isInput*/));
84 legacy.clientInfo = VALUE_OR_RETURN(aidl2legacy_AudioClient_AudioClient(aidl.clientInfo));
85 legacy.sharedBuffer = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.sharedBuffer));
86 legacy.notificationsPerBuffer = VALUE_OR_RETURN(
87 convertIntegral<uint32_t>(aidl.notificationsPerBuffer));
88 legacy.speed = aidl.speed;
89 legacy.audioTrackCallback = aidl.audioTrackCallback;
90 legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_output_flags_t_mask(aidl.flags));
91 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
92 legacy.notificationFrameCount = VALUE_OR_RETURN(
93 convertIntegral<size_t>(aidl.notificationFrameCount));
94 legacy.selectedDeviceId = VALUE_OR_RETURN(
95 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
96 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
97 return legacy;
98 }
99
100 ConversionResult<media::CreateTrackResponse>
toAidl() const101 IAudioFlinger::CreateTrackOutput::toAidl() const {
102 media::CreateTrackResponse aidl;
103 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_output_flags_t_int32_t_mask(flags));
104 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
105 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
106 aidl.selectedDeviceId = VALUE_OR_RETURN(
107 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
108 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
109 aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate));
110 aidl.streamType = VALUE_OR_RETURN(
111 legacy2aidl_audio_stream_type_t_AudioStreamType(streamType));
112 aidl.afFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(afFrameCount));
113 aidl.afSampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(afSampleRate));
114 aidl.afLatencyMs = VALUE_OR_RETURN(convertIntegral<int32_t>(afLatencyMs));
115 aidl.afChannelMask = VALUE_OR_RETURN(
116 legacy2aidl_audio_channel_mask_t_AudioChannelLayout(afChannelMask, false /*isInput*/));
117 aidl.afFormat = VALUE_OR_RETURN(
118 legacy2aidl_audio_format_t_AudioFormatDescription(afFormat));
119 aidl.afTrackFlags = VALUE_OR_RETURN(
120 legacy2aidl_audio_output_flags_t_int32_t_mask(afTrackFlags));
121 aidl.outputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(outputId));
122 aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId));
123 aidl.audioTrack = audioTrack;
124 return aidl;
125 }
126
127 ConversionResult<IAudioFlinger::CreateTrackOutput>
fromAidl(const media::CreateTrackResponse & aidl)128 IAudioFlinger::CreateTrackOutput::fromAidl(
129 const media::CreateTrackResponse& aidl) {
130 IAudioFlinger::CreateTrackOutput legacy;
131 legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_output_flags_t_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 legacy.sampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate));
139 legacy.streamType = VALUE_OR_RETURN(
140 aidl2legacy_AudioStreamType_audio_stream_type_t(aidl.streamType));
141 legacy.afFrameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.afFrameCount));
142 legacy.afSampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.afSampleRate));
143 legacy.afLatencyMs = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.afLatencyMs));
144 legacy.afChannelMask = VALUE_OR_RETURN(
145 aidl2legacy_AudioChannelLayout_audio_channel_mask_t(aidl.afChannelMask,
146 false /*isInput*/));
147 legacy.afFormat = VALUE_OR_RETURN(
148 aidl2legacy_AudioFormatDescription_audio_format_t(aidl.afFormat));
149 legacy.afTrackFlags = VALUE_OR_RETURN(
150 aidl2legacy_int32_t_audio_output_flags_t_mask(aidl.afTrackFlags));
151 legacy.outputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.outputId));
152 legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId));
153 legacy.audioTrack = aidl.audioTrack;
154 return legacy;
155 }
156
157 ConversionResult<media::CreateRecordRequest>
toAidl() const158 IAudioFlinger::CreateRecordInput::toAidl() const {
159 media::CreateRecordRequest aidl;
160 aidl.attr = VALUE_OR_RETURN(legacy2aidl_audio_attributes_t_AudioAttributes(attr));
161 aidl.config = VALUE_OR_RETURN(
162 legacy2aidl_audio_config_base_t_AudioConfigBase(config, true /*isInput*/));
163 aidl.clientInfo = VALUE_OR_RETURN(legacy2aidl_AudioClient_AudioClient(clientInfo));
164 aidl.riid = VALUE_OR_RETURN(legacy2aidl_audio_unique_id_t_int32_t(riid));
165 aidl.maxSharedAudioHistoryMs = VALUE_OR_RETURN(
166 convertIntegral<int32_t>(maxSharedAudioHistoryMs));
167 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_input_flags_t_int32_t_mask(flags));
168 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
169 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
170 aidl.selectedDeviceId = VALUE_OR_RETURN(
171 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
172 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
173 return aidl;
174 }
175
176 ConversionResult<IAudioFlinger::CreateRecordInput>
fromAidl(const media::CreateRecordRequest & aidl)177 IAudioFlinger::CreateRecordInput::fromAidl(
178 const media::CreateRecordRequest& aidl) {
179 IAudioFlinger::CreateRecordInput legacy;
180 legacy.attr = VALUE_OR_RETURN(
181 aidl2legacy_AudioAttributes_audio_attributes_t(aidl.attr));
182 legacy.config = VALUE_OR_RETURN(
183 aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.config, true /*isInput*/));
184 legacy.clientInfo = VALUE_OR_RETURN(aidl2legacy_AudioClient_AudioClient(aidl.clientInfo));
185 legacy.riid = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_unique_id_t(aidl.riid));
186 legacy.maxSharedAudioHistoryMs = VALUE_OR_RETURN(
187 convertIntegral<int32_t>(aidl.maxSharedAudioHistoryMs));
188 legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_input_flags_t_mask(aidl.flags));
189 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
190 legacy.notificationFrameCount = VALUE_OR_RETURN(
191 convertIntegral<size_t>(aidl.notificationFrameCount));
192 legacy.selectedDeviceId = VALUE_OR_RETURN(
193 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
194 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
195 return legacy;
196 }
197
198 ConversionResult<media::CreateRecordResponse>
toAidl() const199 IAudioFlinger::CreateRecordOutput::toAidl() const {
200 media::CreateRecordResponse aidl;
201 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_input_flags_t_int32_t_mask(flags));
202 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
203 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
204 aidl.selectedDeviceId = VALUE_OR_RETURN(
205 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
206 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
207 aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate));
208 aidl.inputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(inputId));
209 aidl.cblk = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(cblk));
210 aidl.buffers = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(buffers));
211 aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId));
212 aidl.audioRecord = audioRecord;
213 aidl.serverConfig = VALUE_OR_RETURN(
214 legacy2aidl_audio_config_base_t_AudioConfigBase(serverConfig, true /*isInput*/));
215 aidl.halConfig = VALUE_OR_RETURN(
216 legacy2aidl_audio_config_base_t_AudioConfigBase(halConfig, true /*isInput*/));
217 return aidl;
218 }
219
220 ConversionResult<IAudioFlinger::CreateRecordOutput>
fromAidl(const media::CreateRecordResponse & aidl)221 IAudioFlinger::CreateRecordOutput::fromAidl(
222 const media::CreateRecordResponse& aidl) {
223 IAudioFlinger::CreateRecordOutput legacy;
224 legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_input_flags_t_mask(aidl.flags));
225 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
226 legacy.notificationFrameCount = VALUE_OR_RETURN(
227 convertIntegral<size_t>(aidl.notificationFrameCount));
228 legacy.selectedDeviceId = VALUE_OR_RETURN(
229 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
230 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
231 legacy.sampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate));
232 legacy.inputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.inputId));
233 legacy.cblk = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.cblk));
234 legacy.buffers = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.buffers));
235 legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId));
236 legacy.audioRecord = aidl.audioRecord;
237 legacy.serverConfig = VALUE_OR_RETURN(
238 aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.serverConfig, true /*isInput*/));
239 legacy.halConfig = VALUE_OR_RETURN(
240 aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.halConfig, true /*isInput*/));
241 return legacy;
242 }
243
244 ////////////////////////////////////////////////////////////////////////////////////////////////////
245 // AudioFlingerClientAdapter
246
AudioFlingerClientAdapter(const sp<media::IAudioFlingerService> delegate)247 AudioFlingerClientAdapter::AudioFlingerClientAdapter(
248 const sp<media::IAudioFlingerService> delegate) : mDelegate(delegate) {}
249
createTrack(const media::CreateTrackRequest & input,media::CreateTrackResponse & output)250 status_t AudioFlingerClientAdapter::createTrack(const media::CreateTrackRequest& input,
251 media::CreateTrackResponse& output) {
252 return statusTFromBinderStatus(mDelegate->createTrack(input, &output));
253 }
254
createRecord(const media::CreateRecordRequest & input,media::CreateRecordResponse & output)255 status_t AudioFlingerClientAdapter::createRecord(const media::CreateRecordRequest& input,
256 media::CreateRecordResponse& output) {
257 return statusTFromBinderStatus(mDelegate->createRecord(input, &output));
258 }
259
sampleRate(audio_io_handle_t ioHandle) const260 uint32_t AudioFlingerClientAdapter::sampleRate(audio_io_handle_t ioHandle) const {
261 auto result = [&]() -> ConversionResult<uint32_t> {
262 int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle));
263 int32_t aidlRet;
264 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->sampleRate(ioHandleAidl, &aidlRet)));
265 return convertIntegral<uint32_t>(aidlRet);
266 }();
267 // Failure is ignored.
268 return result.value_or(0);
269 }
270
format(audio_io_handle_t output) const271 audio_format_t AudioFlingerClientAdapter::format(audio_io_handle_t output) const {
272 auto result = [&]() -> ConversionResult<audio_format_t> {
273 int32_t outputAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(output));
274 AudioFormatDescription aidlRet;
275 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->format(outputAidl, &aidlRet)));
276 return aidl2legacy_AudioFormatDescription_audio_format_t(aidlRet);
277 }();
278 return result.value_or(AUDIO_FORMAT_INVALID);
279 }
280
frameCount(audio_io_handle_t ioHandle) const281 size_t AudioFlingerClientAdapter::frameCount(audio_io_handle_t ioHandle) const {
282 auto result = [&]() -> ConversionResult<size_t> {
283 int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle));
284 int64_t aidlRet;
285 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->frameCount(ioHandleAidl, &aidlRet)));
286 return convertIntegral<size_t>(aidlRet);
287 }();
288 // Failure is ignored.
289 return result.value_or(0);
290 }
291
latency(audio_io_handle_t output) const292 uint32_t AudioFlingerClientAdapter::latency(audio_io_handle_t output) const {
293 auto result = [&]() -> ConversionResult<uint32_t> {
294 int32_t outputAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(output));
295 int32_t aidlRet;
296 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->latency(outputAidl, &aidlRet)));
297 return convertIntegral<uint32_t>(aidlRet);
298 }();
299 // Failure is ignored.
300 return result.value_or(0);
301 }
302
setMasterVolume(float value)303 status_t AudioFlingerClientAdapter::setMasterVolume(float value) {
304 return statusTFromBinderStatus(mDelegate->setMasterVolume(value));
305 }
306
setMasterMute(bool muted)307 status_t AudioFlingerClientAdapter::setMasterMute(bool muted) {
308 return statusTFromBinderStatus(mDelegate->setMasterMute(muted));
309 }
310
masterVolume() const311 float AudioFlingerClientAdapter::masterVolume() const {
312 auto result = [&]() -> ConversionResult<float> {
313 float aidlRet;
314 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->masterVolume(&aidlRet)));
315 return aidlRet;
316 }();
317 // Failure is ignored.
318 return result.value_or(0.f);
319 }
320
masterMute() const321 bool AudioFlingerClientAdapter::masterMute() const {
322 auto result = [&]() -> ConversionResult<bool> {
323 bool aidlRet;
324 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->masterMute(&aidlRet)));
325 return aidlRet;
326 }();
327 // Failure is ignored.
328 return result.value_or(false);
329 }
330
setMasterBalance(float balance)331 status_t AudioFlingerClientAdapter::setMasterBalance(float balance) {
332 return statusTFromBinderStatus(mDelegate->setMasterBalance(balance));
333 }
334
getMasterBalance(float * balance) const335 status_t AudioFlingerClientAdapter::getMasterBalance(float* balance) const{
336 return statusTFromBinderStatus(mDelegate->getMasterBalance(balance));
337 }
338
setStreamVolume(audio_stream_type_t stream,float value,audio_io_handle_t output)339 status_t AudioFlingerClientAdapter::setStreamVolume(audio_stream_type_t stream, float value,
340 audio_io_handle_t output) {
341 AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS(
342 legacy2aidl_audio_stream_type_t_AudioStreamType(stream));
343 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
344 return statusTFromBinderStatus(mDelegate->setStreamVolume(streamAidl, value, outputAidl));
345 }
346
setStreamMute(audio_stream_type_t stream,bool muted)347 status_t AudioFlingerClientAdapter::setStreamMute(audio_stream_type_t stream, bool muted) {
348 AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS(
349 legacy2aidl_audio_stream_type_t_AudioStreamType(stream));
350 return statusTFromBinderStatus(mDelegate->setStreamMute(streamAidl, muted));
351 }
352
streamVolume(audio_stream_type_t stream,audio_io_handle_t output) const353 float AudioFlingerClientAdapter::streamVolume(audio_stream_type_t stream,
354 audio_io_handle_t output) const {
355 auto result = [&]() -> ConversionResult<float> {
356 AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS(
357 legacy2aidl_audio_stream_type_t_AudioStreamType(stream));
358 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
359 float aidlRet;
360 RETURN_IF_ERROR(statusTFromBinderStatus(
361 mDelegate->streamVolume(streamAidl, outputAidl, &aidlRet)));
362 return aidlRet;
363 }();
364 // Failure is ignored.
365 return result.value_or(0.f);
366 }
367
streamMute(audio_stream_type_t stream) const368 bool AudioFlingerClientAdapter::streamMute(audio_stream_type_t stream) const {
369 auto result = [&]() -> ConversionResult<bool> {
370 AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS(
371 legacy2aidl_audio_stream_type_t_AudioStreamType(stream));
372 bool aidlRet;
373 RETURN_IF_ERROR(statusTFromBinderStatus(
374 mDelegate->streamMute(streamAidl, &aidlRet)));
375 return aidlRet;
376 }();
377 // Failure is ignored.
378 return result.value_or(false);
379 }
380
setMode(audio_mode_t mode)381 status_t AudioFlingerClientAdapter::setMode(audio_mode_t mode) {
382 AudioMode modeAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_mode_t_AudioMode(mode));
383 return statusTFromBinderStatus(mDelegate->setMode(modeAidl));
384 }
385
setMicMute(bool state)386 status_t AudioFlingerClientAdapter::setMicMute(bool state) {
387 return statusTFromBinderStatus(mDelegate->setMicMute(state));
388 }
389
getMicMute() const390 bool AudioFlingerClientAdapter::getMicMute() const {
391 auto result = [&]() -> ConversionResult<bool> {
392 bool aidlRet;
393 RETURN_IF_ERROR(statusTFromBinderStatus(
394 mDelegate->getMicMute(&aidlRet)));
395 return aidlRet;
396 }();
397 // Failure is ignored.
398 return result.value_or(false);
399 }
400
setRecordSilenced(audio_port_handle_t portId,bool silenced)401 void AudioFlingerClientAdapter::setRecordSilenced(audio_port_handle_t portId, bool silenced) {
402 auto result = [&]() -> status_t {
403 int32_t portIdAidl = VALUE_OR_RETURN_STATUS(
404 legacy2aidl_audio_port_handle_t_int32_t(portId));
405 return statusTFromBinderStatus(mDelegate->setRecordSilenced(portIdAidl, silenced));
406 }();
407 // Failure is ignored.
408 (void) result;
409 }
410
setParameters(audio_io_handle_t ioHandle,const String8 & keyValuePairs)411 status_t AudioFlingerClientAdapter::setParameters(audio_io_handle_t ioHandle,
412 const String8& keyValuePairs) {
413 int32_t ioHandleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(ioHandle));
414 std::string keyValuePairsAidl = VALUE_OR_RETURN_STATUS(
415 legacy2aidl_String8_string(keyValuePairs));
416 return statusTFromBinderStatus(mDelegate->setParameters(ioHandleAidl, keyValuePairsAidl));
417 }
418
getParameters(audio_io_handle_t ioHandle,const String8 & keys) const419 String8 AudioFlingerClientAdapter::getParameters(audio_io_handle_t ioHandle, const String8& keys)
420 const {
421 auto result = [&]() -> ConversionResult<String8> {
422 int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle));
423 std::string keysAidl = VALUE_OR_RETURN(legacy2aidl_String8_string(keys));
424 std::string aidlRet;
425 RETURN_IF_ERROR(statusTFromBinderStatus(
426 mDelegate->getParameters(ioHandleAidl, keysAidl, &aidlRet)));
427 return aidl2legacy_string_view_String8(aidlRet);
428 }();
429 // Failure is ignored.
430 return result.value_or(String8());
431 }
432
registerClient(const sp<media::IAudioFlingerClient> & client)433 void AudioFlingerClientAdapter::registerClient(const sp<media::IAudioFlingerClient>& client) {
434 mDelegate->registerClient(client);
435 // Failure is ignored.
436 }
437
getInputBufferSize(uint32_t sampleRate,audio_format_t format,audio_channel_mask_t channelMask) const438 size_t AudioFlingerClientAdapter::getInputBufferSize(uint32_t sampleRate, audio_format_t format,
439 audio_channel_mask_t channelMask) const {
440 auto result = [&]() -> ConversionResult<size_t> {
441 int32_t sampleRateAidl = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate));
442 AudioFormatDescription formatAidl = VALUE_OR_RETURN(
443 legacy2aidl_audio_format_t_AudioFormatDescription(format));
444 AudioChannelLayout channelMaskAidl = VALUE_OR_RETURN(
445 legacy2aidl_audio_channel_mask_t_AudioChannelLayout(channelMask, true /*isInput*/));
446 int64_t aidlRet;
447 RETURN_IF_ERROR(statusTFromBinderStatus(
448 mDelegate->getInputBufferSize(sampleRateAidl, formatAidl, channelMaskAidl,
449 &aidlRet)));
450 return convertIntegral<size_t>(aidlRet);
451 }();
452 // Failure is ignored.
453 return result.value_or(0);
454 }
455
openOutput(const media::OpenOutputRequest & request,media::OpenOutputResponse * response)456 status_t AudioFlingerClientAdapter::openOutput(const media::OpenOutputRequest& request,
457 media::OpenOutputResponse* response) {
458 return statusTFromBinderStatus(mDelegate->openOutput(request, response));
459 }
460
openDuplicateOutput(audio_io_handle_t output1,audio_io_handle_t output2)461 audio_io_handle_t AudioFlingerClientAdapter::openDuplicateOutput(audio_io_handle_t output1,
462 audio_io_handle_t output2) {
463 auto result = [&]() -> ConversionResult<audio_io_handle_t> {
464 int32_t output1Aidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(output1));
465 int32_t output2Aidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(output2));
466 int32_t aidlRet;
467 RETURN_IF_ERROR(statusTFromBinderStatus(
468 mDelegate->openDuplicateOutput(output1Aidl, output2Aidl, &aidlRet)));
469 return aidl2legacy_int32_t_audio_io_handle_t(aidlRet);
470 }();
471 // Failure is ignored.
472 return result.value_or(0);
473 }
474
closeOutput(audio_io_handle_t output)475 status_t AudioFlingerClientAdapter::closeOutput(audio_io_handle_t output) {
476 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
477 return statusTFromBinderStatus(mDelegate->closeOutput(outputAidl));
478 }
479
suspendOutput(audio_io_handle_t output)480 status_t AudioFlingerClientAdapter::suspendOutput(audio_io_handle_t output) {
481 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
482 return statusTFromBinderStatus(mDelegate->suspendOutput(outputAidl));
483 }
484
restoreOutput(audio_io_handle_t output)485 status_t AudioFlingerClientAdapter::restoreOutput(audio_io_handle_t output) {
486 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
487 return statusTFromBinderStatus(mDelegate->restoreOutput(outputAidl));
488 }
489
openInput(const media::OpenInputRequest & request,media::OpenInputResponse * response)490 status_t AudioFlingerClientAdapter::openInput(const media::OpenInputRequest& request,
491 media::OpenInputResponse* response) {
492 return statusTFromBinderStatus(mDelegate->openInput(request, response));
493 }
494
closeInput(audio_io_handle_t input)495 status_t AudioFlingerClientAdapter::closeInput(audio_io_handle_t input) {
496 int32_t inputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(input));
497 return statusTFromBinderStatus(mDelegate->closeInput(inputAidl));
498 }
499
setVoiceVolume(float volume)500 status_t AudioFlingerClientAdapter::setVoiceVolume(float volume) {
501 return statusTFromBinderStatus(mDelegate->setVoiceVolume(volume));
502 }
503
getRenderPosition(uint32_t * halFrames,uint32_t * dspFrames,audio_io_handle_t output) const504 status_t AudioFlingerClientAdapter::getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames,
505 audio_io_handle_t output) const {
506 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
507 media::RenderPosition aidlRet;
508 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
509 mDelegate->getRenderPosition(outputAidl, &aidlRet)));
510 if (halFrames != nullptr) {
511 *halFrames = VALUE_OR_RETURN_STATUS(convertIntegral<uint32_t>(aidlRet.halFrames));
512 }
513 if (dspFrames != nullptr) {
514 *dspFrames = VALUE_OR_RETURN_STATUS(convertIntegral<uint32_t>(aidlRet.dspFrames));
515 }
516 return OK;
517 }
518
getInputFramesLost(audio_io_handle_t ioHandle) const519 uint32_t AudioFlingerClientAdapter::getInputFramesLost(audio_io_handle_t ioHandle) const {
520 auto result = [&]() -> ConversionResult<uint32_t> {
521 int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle));
522 int32_t aidlRet;
523 RETURN_IF_ERROR(statusTFromBinderStatus(
524 mDelegate->getInputFramesLost(ioHandleAidl, &aidlRet)));
525 return convertIntegral<uint32_t>(aidlRet);
526 }();
527 // Failure is ignored.
528 return result.value_or(0);
529 }
530
newAudioUniqueId(audio_unique_id_use_t use)531 audio_unique_id_t AudioFlingerClientAdapter::newAudioUniqueId(audio_unique_id_use_t use) {
532 auto result = [&]() -> ConversionResult<audio_unique_id_t> {
533 media::AudioUniqueIdUse useAidl = VALUE_OR_RETURN(
534 legacy2aidl_audio_unique_id_use_t_AudioUniqueIdUse(use));
535 int32_t aidlRet;
536 RETURN_IF_ERROR(statusTFromBinderStatus(
537 mDelegate->newAudioUniqueId(useAidl, &aidlRet)));
538 return aidl2legacy_int32_t_audio_unique_id_t(aidlRet);
539 }();
540 return result.value_or(AUDIO_UNIQUE_ID_ALLOCATE);
541 }
542
acquireAudioSessionId(audio_session_t audioSession,pid_t pid,uid_t uid)543 void AudioFlingerClientAdapter::acquireAudioSessionId(audio_session_t audioSession, pid_t pid,
544 uid_t uid) {
545 [&]() -> status_t {
546 int32_t audioSessionAidl = VALUE_OR_RETURN_STATUS(
547 legacy2aidl_audio_session_t_int32_t(audioSession));
548 int32_t pidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_pid_t_int32_t(pid));
549 int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_pid_t_int32_t(uid));
550 return statusTFromBinderStatus(
551 mDelegate->acquireAudioSessionId(audioSessionAidl, pidAidl, uidAidl));
552 }();
553 // Failure is ignored.
554 }
555
releaseAudioSessionId(audio_session_t audioSession,pid_t pid)556 void AudioFlingerClientAdapter::releaseAudioSessionId(audio_session_t audioSession, pid_t pid) {
557 [&]() -> status_t {
558 int32_t audioSessionAidl = VALUE_OR_RETURN_STATUS(
559 legacy2aidl_audio_session_t_int32_t(audioSession));
560 int32_t pidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_pid_t_int32_t(pid));
561 return statusTFromBinderStatus(
562 mDelegate->releaseAudioSessionId(audioSessionAidl, pidAidl));
563 }();
564 // Failure is ignored.
565 }
566
queryNumberEffects(uint32_t * numEffects) const567 status_t AudioFlingerClientAdapter::queryNumberEffects(uint32_t* numEffects) const {
568 int32_t aidlRet;
569 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
570 mDelegate->queryNumberEffects(&aidlRet)));
571 if (numEffects != nullptr) {
572 *numEffects = VALUE_OR_RETURN_STATUS(convertIntegral<uint32_t>(aidlRet));
573 }
574 return OK;
575 }
576
577 status_t
queryEffect(uint32_t index,effect_descriptor_t * pDescriptor) const578 AudioFlingerClientAdapter::queryEffect(uint32_t index, effect_descriptor_t* pDescriptor) const {
579 int32_t indexAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(index));
580 media::EffectDescriptor aidlRet;
581 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
582 mDelegate->queryEffect(indexAidl, &aidlRet)));
583 if (pDescriptor != nullptr) {
584 *pDescriptor = VALUE_OR_RETURN_STATUS(
585 aidl2legacy_EffectDescriptor_effect_descriptor_t(aidlRet));
586 }
587 return OK;
588 }
589
getEffectDescriptor(const effect_uuid_t * pEffectUUID,const effect_uuid_t * pTypeUUID,uint32_t preferredTypeFlag,effect_descriptor_t * pDescriptor) const590 status_t AudioFlingerClientAdapter::getEffectDescriptor(const effect_uuid_t* pEffectUUID,
591 const effect_uuid_t* pTypeUUID,
592 uint32_t preferredTypeFlag,
593 effect_descriptor_t* pDescriptor) const {
594 AudioUuid effectUuidAidl = VALUE_OR_RETURN_STATUS(
595 legacy2aidl_audio_uuid_t_AudioUuid(*pEffectUUID));
596 AudioUuid typeUuidAidl = VALUE_OR_RETURN_STATUS(
597 legacy2aidl_audio_uuid_t_AudioUuid(*pTypeUUID));
598 int32_t preferredTypeFlagAidl = VALUE_OR_RETURN_STATUS(
599 convertReinterpret<int32_t>(preferredTypeFlag));
600 media::EffectDescriptor aidlRet;
601 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
602 mDelegate->getEffectDescriptor(effectUuidAidl, typeUuidAidl, preferredTypeFlagAidl,
603 &aidlRet)));
604 if (pDescriptor != nullptr) {
605 *pDescriptor = VALUE_OR_RETURN_STATUS(
606 aidl2legacy_EffectDescriptor_effect_descriptor_t(aidlRet));
607 }
608 return OK;
609 }
610
createEffect(const media::CreateEffectRequest & request,media::CreateEffectResponse * response)611 status_t AudioFlingerClientAdapter::createEffect(const media::CreateEffectRequest& request,
612 media::CreateEffectResponse* response) {
613 return statusTFromBinderStatus(mDelegate->createEffect(request, response));
614 }
615
616 status_t
moveEffects(audio_session_t session,audio_io_handle_t srcOutput,audio_io_handle_t dstOutput)617 AudioFlingerClientAdapter::moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
618 audio_io_handle_t dstOutput) {
619 int32_t sessionAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(session));
620 int32_t srcOutputAidl = VALUE_OR_RETURN_STATUS(
621 legacy2aidl_audio_io_handle_t_int32_t(srcOutput));
622 int32_t dstOutputAidl = VALUE_OR_RETURN_STATUS(
623 legacy2aidl_audio_io_handle_t_int32_t(dstOutput));
624 return statusTFromBinderStatus(
625 mDelegate->moveEffects(sessionAidl, srcOutputAidl, dstOutputAidl));
626 }
627
setEffectSuspended(int effectId,audio_session_t sessionId,bool suspended)628 void AudioFlingerClientAdapter::setEffectSuspended(int effectId,
629 audio_session_t sessionId,
630 bool suspended) {
631 [&]() -> status_t {
632 int32_t effectIdAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(effectId));
633 int32_t sessionIdAidl = VALUE_OR_RETURN_STATUS(
634 legacy2aidl_audio_session_t_int32_t(sessionId));
635 return statusTFromBinderStatus(
636 mDelegate->setEffectSuspended(effectIdAidl, sessionIdAidl, suspended));
637 }();
638 // Failure is ignored.
639 }
640
loadHwModule(const char * name)641 audio_module_handle_t AudioFlingerClientAdapter::loadHwModule(const char* name) {
642 auto result = [&]() -> ConversionResult<audio_module_handle_t> {
643 std::string nameAidl(name);
644 int32_t aidlRet;
645 RETURN_IF_ERROR(statusTFromBinderStatus(
646 mDelegate->loadHwModule(nameAidl, &aidlRet)));
647 return aidl2legacy_int32_t_audio_module_handle_t(aidlRet);
648 }();
649 // Failure is ignored.
650 return result.value_or(0);
651 }
652
getPrimaryOutputSamplingRate() const653 uint32_t AudioFlingerClientAdapter::getPrimaryOutputSamplingRate() const {
654 auto result = [&]() -> ConversionResult<uint32_t> {
655 int32_t aidlRet;
656 RETURN_IF_ERROR(statusTFromBinderStatus(
657 mDelegate->getPrimaryOutputSamplingRate(&aidlRet)));
658 return convertIntegral<uint32_t>(aidlRet);
659 }();
660 // Failure is ignored.
661 return result.value_or(0);
662 }
663
getPrimaryOutputFrameCount() const664 size_t AudioFlingerClientAdapter::getPrimaryOutputFrameCount() const {
665 auto result = [&]() -> ConversionResult<size_t> {
666 int64_t aidlRet;
667 RETURN_IF_ERROR(statusTFromBinderStatus(
668 mDelegate->getPrimaryOutputFrameCount(&aidlRet)));
669 return convertIntegral<size_t>(aidlRet);
670 }();
671 // Failure is ignored.
672 return result.value_or(0);
673 }
674
setLowRamDevice(bool isLowRamDevice,int64_t totalMemory)675 status_t AudioFlingerClientAdapter::setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) {
676 return statusTFromBinderStatus(mDelegate->setLowRamDevice(isLowRamDevice, totalMemory));
677 }
678
getAudioPort(struct audio_port_v7 * port) const679 status_t AudioFlingerClientAdapter::getAudioPort(struct audio_port_v7* port) const {
680 media::AudioPortFw portAidl = VALUE_OR_RETURN_STATUS(
681 legacy2aidl_audio_port_v7_AudioPortFw(*port));
682 media::AudioPortFw aidlRet;
683 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
684 mDelegate->getAudioPort(portAidl, &aidlRet)));
685 *port = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioPortFw_audio_port_v7(aidlRet));
686 return OK;
687 }
688
createAudioPatch(const struct audio_patch * patch,audio_patch_handle_t * handle)689 status_t AudioFlingerClientAdapter::createAudioPatch(const struct audio_patch* patch,
690 audio_patch_handle_t* handle) {
691 media::AudioPatchFw patchAidl = VALUE_OR_RETURN_STATUS(
692 legacy2aidl_audio_patch_AudioPatchFw(*patch));
693 int32_t aidlRet = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(
694 AUDIO_PATCH_HANDLE_NONE));
695 if (handle != nullptr) {
696 aidlRet = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(*handle));
697 }
698 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
699 mDelegate->createAudioPatch(patchAidl, &aidlRet)));
700 if (handle != nullptr) {
701 *handle = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_patch_handle_t(aidlRet));
702 }
703 return OK;
704 }
705
releaseAudioPatch(audio_patch_handle_t handle)706 status_t AudioFlingerClientAdapter::releaseAudioPatch(audio_patch_handle_t handle) {
707 int32_t handleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(handle));
708 return statusTFromBinderStatus(mDelegate->releaseAudioPatch(handleAidl));
709 }
710
listAudioPatches(unsigned int * num_patches,struct audio_patch * patches) const711 status_t AudioFlingerClientAdapter::listAudioPatches(unsigned int* num_patches,
712 struct audio_patch* patches) const {
713 std::vector<media::AudioPatchFw> aidlRet;
714 int32_t maxPatches = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(*num_patches));
715 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
716 mDelegate->listAudioPatches(maxPatches, &aidlRet)));
717 *num_patches = VALUE_OR_RETURN_STATUS(convertIntegral<unsigned int>(aidlRet.size()));
718 return convertRange(aidlRet.begin(), aidlRet.end(), patches,
719 aidl2legacy_AudioPatchFw_audio_patch);
720 }
721
setAudioPortConfig(const struct audio_port_config * config)722 status_t AudioFlingerClientAdapter::setAudioPortConfig(const struct audio_port_config* config) {
723 media::AudioPortConfigFw configAidl = VALUE_OR_RETURN_STATUS(
724 legacy2aidl_audio_port_config_AudioPortConfigFw(*config));
725 return statusTFromBinderStatus(mDelegate->setAudioPortConfig(configAidl));
726 }
727
getAudioHwSyncForSession(audio_session_t sessionId)728 audio_hw_sync_t AudioFlingerClientAdapter::getAudioHwSyncForSession(audio_session_t sessionId) {
729 auto result = [&]() -> ConversionResult<audio_hw_sync_t> {
730 int32_t sessionIdAidl = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
731 int32_t aidlRet;
732 RETURN_IF_ERROR(statusTFromBinderStatus(
733 mDelegate->getAudioHwSyncForSession(sessionIdAidl, &aidlRet)));
734 return aidl2legacy_int32_t_audio_hw_sync_t(aidlRet);
735 }();
736 return result.value_or(AUDIO_HW_SYNC_INVALID);
737 }
738
systemReady()739 status_t AudioFlingerClientAdapter::systemReady() {
740 return statusTFromBinderStatus(mDelegate->systemReady());
741 }
742
audioPolicyReady()743 status_t AudioFlingerClientAdapter::audioPolicyReady() {
744 return statusTFromBinderStatus(mDelegate->audioPolicyReady());
745 }
746
frameCountHAL(audio_io_handle_t ioHandle) const747 size_t AudioFlingerClientAdapter::frameCountHAL(audio_io_handle_t ioHandle) const {
748 auto result = [&]() -> ConversionResult<size_t> {
749 int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle));
750 int64_t aidlRet;
751 RETURN_IF_ERROR(statusTFromBinderStatus(
752 mDelegate->frameCountHAL(ioHandleAidl, &aidlRet)));
753 return convertIntegral<size_t>(aidlRet);
754 }();
755 // Failure is ignored.
756 return result.value_or(0);
757 }
758
759 status_t
getMicrophones(std::vector<media::MicrophoneInfoFw> * microphones) const760 AudioFlingerClientAdapter::getMicrophones(
761 std::vector<media::MicrophoneInfoFw>* microphones) const {
762 std::vector<media::MicrophoneInfoFw> aidlRet;
763 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mDelegate->getMicrophones(&aidlRet)));
764 if (microphones != nullptr) {
765 *microphones = std::move(aidlRet);
766 }
767 return OK;
768 }
769
setAudioHalPids(const std::vector<pid_t> & pids)770 status_t AudioFlingerClientAdapter::setAudioHalPids(const std::vector<pid_t>& pids) {
771 std::vector<int32_t> pidsAidl = VALUE_OR_RETURN_STATUS(
772 convertContainer<std::vector<int32_t>>(pids, legacy2aidl_pid_t_int32_t));
773 return statusTFromBinderStatus(mDelegate->setAudioHalPids(pidsAidl));
774 }
775
setVibratorInfos(const std::vector<media::AudioVibratorInfo> & vibratorInfos)776 status_t AudioFlingerClientAdapter::setVibratorInfos(
777 const std::vector<media::AudioVibratorInfo>& vibratorInfos) {
778 return statusTFromBinderStatus(mDelegate->setVibratorInfos(vibratorInfos));
779 }
780
updateSecondaryOutputs(const TrackSecondaryOutputsMap & trackSecondaryOutputs)781 status_t AudioFlingerClientAdapter::updateSecondaryOutputs(
782 const TrackSecondaryOutputsMap& trackSecondaryOutputs) {
783 std::vector<media::TrackSecondaryOutputInfo> trackSecondaryOutputInfos =
784 VALUE_OR_RETURN_STATUS(
785 convertContainer<std::vector<media::TrackSecondaryOutputInfo>>(
786 trackSecondaryOutputs,
787 legacy2aidl_TrackSecondaryOutputInfoPair_TrackSecondaryOutputInfo));
788 return statusTFromBinderStatus(mDelegate->updateSecondaryOutputs(trackSecondaryOutputInfos));
789 }
790
getMmapPolicyInfos(AudioMMapPolicyType policyType,std::vector<AudioMMapPolicyInfo> * policyInfos)791 status_t AudioFlingerClientAdapter::getMmapPolicyInfos(
792 AudioMMapPolicyType policyType, std::vector<AudioMMapPolicyInfo> *policyInfos) {
793 return statusTFromBinderStatus(mDelegate->getMmapPolicyInfos(policyType, policyInfos));
794 }
795
getAAudioMixerBurstCount() const796 int32_t AudioFlingerClientAdapter::getAAudioMixerBurstCount() const {
797 auto result = [&]() -> ConversionResult<int32_t> {
798 int32_t aidlRet;
799 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->getAAudioMixerBurstCount(&aidlRet)));
800 return convertIntegral<int32_t>(aidlRet);
801 }();
802 // Failure is ignored.
803 return result.value_or(0);
804 }
805
getAAudioHardwareBurstMinUsec() const806 int32_t AudioFlingerClientAdapter::getAAudioHardwareBurstMinUsec() const {
807 auto result = [&]() -> ConversionResult<int32_t> {
808 int32_t aidlRet;
809 RETURN_IF_ERROR(statusTFromBinderStatus(
810 mDelegate->getAAudioHardwareBurstMinUsec(&aidlRet)));
811 return convertIntegral<int32_t>(aidlRet);
812 }();
813 // Failure is ignored.
814 return result.value_or(0);
815 }
816
setDeviceConnectedState(const struct audio_port_v7 * port,media::DeviceConnectedState state)817 status_t AudioFlingerClientAdapter::setDeviceConnectedState(
818 const struct audio_port_v7 *port, media::DeviceConnectedState state) {
819 media::AudioPortFw aidlPort = VALUE_OR_RETURN_STATUS(
820 legacy2aidl_audio_port_v7_AudioPortFw(*port));
821 return statusTFromBinderStatus(mDelegate->setDeviceConnectedState(aidlPort, state));
822 }
823
setSimulateDeviceConnections(bool enabled)824 status_t AudioFlingerClientAdapter::setSimulateDeviceConnections(bool enabled) {
825 return statusTFromBinderStatus(mDelegate->setSimulateDeviceConnections(enabled));
826 }
827
setRequestedLatencyMode(audio_io_handle_t output,audio_latency_mode_t mode)828 status_t AudioFlingerClientAdapter::setRequestedLatencyMode(
829 audio_io_handle_t output, audio_latency_mode_t mode) {
830 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
831 media::audio::common::AudioLatencyMode modeAidl = VALUE_OR_RETURN_STATUS(
832 legacy2aidl_audio_latency_mode_t_AudioLatencyMode(mode));
833 return statusTFromBinderStatus(mDelegate->setRequestedLatencyMode(outputAidl, modeAidl));
834 }
835
getSupportedLatencyModes(audio_io_handle_t output,std::vector<audio_latency_mode_t> * modes) const836 status_t AudioFlingerClientAdapter::getSupportedLatencyModes(
837 audio_io_handle_t output, std::vector<audio_latency_mode_t>* modes) const {
838 if (modes == nullptr) {
839 return BAD_VALUE;
840 }
841
842 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
843 std::vector<media::audio::common::AudioLatencyMode> modesAidl;
844
845 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
846 mDelegate->getSupportedLatencyModes(outputAidl, &modesAidl)));
847
848 *modes = VALUE_OR_RETURN_STATUS(
849 convertContainer<std::vector<audio_latency_mode_t>>(modesAidl,
850 aidl2legacy_AudioLatencyMode_audio_latency_mode_t));
851
852 return NO_ERROR;
853 }
854
setBluetoothVariableLatencyEnabled(bool enabled)855 status_t AudioFlingerClientAdapter::setBluetoothVariableLatencyEnabled(bool enabled) {
856 return statusTFromBinderStatus(mDelegate->setBluetoothVariableLatencyEnabled(enabled));
857 }
858
isBluetoothVariableLatencyEnabled(bool * enabled) const859 status_t AudioFlingerClientAdapter::isBluetoothVariableLatencyEnabled(bool* enabled) const {
860 if (enabled == nullptr) {
861 return BAD_VALUE;
862 }
863
864 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
865 mDelegate->isBluetoothVariableLatencyEnabled(enabled)));
866
867 return NO_ERROR;
868 }
869
supportsBluetoothVariableLatency(bool * support) const870 status_t AudioFlingerClientAdapter::supportsBluetoothVariableLatency(bool* support) const {
871 if (support == nullptr) {
872 return BAD_VALUE;
873 }
874
875 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
876 mDelegate->supportsBluetoothVariableLatency(support)));
877
878 return NO_ERROR;
879 }
880
getSoundDoseInterface(const sp<media::ISoundDoseCallback> & callback,sp<media::ISoundDose> * soundDose) const881 status_t AudioFlingerClientAdapter::getSoundDoseInterface(
882 const sp<media::ISoundDoseCallback> &callback,
883 sp<media::ISoundDose>* soundDose) const {
884 return statusTFromBinderStatus(mDelegate->getSoundDoseInterface(callback, soundDose));
885 }
886
invalidateTracks(const std::vector<audio_port_handle_t> & portIds)887 status_t AudioFlingerClientAdapter::invalidateTracks(
888 const std::vector<audio_port_handle_t>& portIds) {
889 std::vector<int32_t> portIdsAidl = VALUE_OR_RETURN_STATUS(
890 convertContainer<std::vector<int32_t>>(
891 portIds, legacy2aidl_audio_port_handle_t_int32_t));
892 return statusTFromBinderStatus(mDelegate->invalidateTracks(portIdsAidl));
893 }
894
getAudioPolicyConfig(media::AudioPolicyConfig * config)895 status_t AudioFlingerClientAdapter::getAudioPolicyConfig(media::AudioPolicyConfig *config) {
896 if (config == nullptr) {
897 return BAD_VALUE;
898 }
899
900 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mDelegate->getAudioPolicyConfig(config)));
901
902 return NO_ERROR;
903 }
904
getAudioMixPort(const struct audio_port_v7 * devicePort,struct audio_port_v7 * mixPort) const905 status_t AudioFlingerClientAdapter::getAudioMixPort(const struct audio_port_v7 *devicePort,
906 struct audio_port_v7 *mixPort) const {
907 if (devicePort == nullptr || mixPort == nullptr) {
908 return BAD_VALUE;
909 }
910 media::AudioPortFw devicePortAidl = VALUE_OR_RETURN_STATUS(
911 legacy2aidl_audio_port_v7_AudioPortFw(*devicePort));
912 media::AudioPortFw mixPortAidl = VALUE_OR_RETURN_STATUS(
913 legacy2aidl_audio_port_v7_AudioPortFw(*mixPort));
914 media::AudioPortFw aidlRet;
915 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
916 mDelegate->getAudioMixPort(devicePortAidl, mixPortAidl, &aidlRet)));
917 *mixPort = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioPortFw_audio_port_v7(aidlRet));
918 return OK;
919 }
920
setTracksInternalMute(const std::vector<media::TrackInternalMuteInfo> & tracksInternalMuted)921 status_t AudioFlingerClientAdapter::setTracksInternalMute(
922 const std::vector<media::TrackInternalMuteInfo>& tracksInternalMuted) {
923 return statusTFromBinderStatus(mDelegate->setTracksInternalMute(tracksInternalMuted));
924 }
925
resetReferencesForTest()926 status_t AudioFlingerClientAdapter::resetReferencesForTest() {
927 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mDelegate->resetReferencesForTest()));
928 return OK;
929 }
930
931 ////////////////////////////////////////////////////////////////////////////////////////////////////
932 // AudioFlingerServerAdapter
AudioFlingerServerAdapter(const sp<AudioFlingerServerAdapter::Delegate> & delegate)933 AudioFlingerServerAdapter::AudioFlingerServerAdapter(
934 const sp<AudioFlingerServerAdapter::Delegate>& delegate) : mDelegate(delegate) {
935 setMinSchedulerPolicy(SCHED_NORMAL, ANDROID_PRIORITY_AUDIO);
936 setInheritRt(true);
937 }
938
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)939 status_t AudioFlingerServerAdapter::onTransact(uint32_t code,
940 const Parcel& data,
941 Parcel* reply,
942 uint32_t flags) {
943 return mDelegate->onTransactWrapper(static_cast<Delegate::TransactionCode>(code),
944 data,
945 flags,
946 [&] {
947 return BnAudioFlingerService::onTransact(
948 code,
949 data,
950 reply,
951 flags);
952 });
953 }
954
dump(int fd,const Vector<String16> & args)955 status_t AudioFlingerServerAdapter::dump(int fd, const Vector<String16>& args) {
956 return mDelegate->dump(fd, args);
957 }
958
createTrack(const media::CreateTrackRequest & request,media::CreateTrackResponse * _aidl_return)959 Status AudioFlingerServerAdapter::createTrack(const media::CreateTrackRequest& request,
960 media::CreateTrackResponse* _aidl_return) {
961 return Status::fromStatusT(mDelegate->createTrack(request, *_aidl_return));
962 }
963
createRecord(const media::CreateRecordRequest & request,media::CreateRecordResponse * _aidl_return)964 Status AudioFlingerServerAdapter::createRecord(const media::CreateRecordRequest& request,
965 media::CreateRecordResponse* _aidl_return) {
966 return Status::fromStatusT(mDelegate->createRecord(request, *_aidl_return));
967 }
968
sampleRate(int32_t ioHandle,int32_t * _aidl_return)969 Status AudioFlingerServerAdapter::sampleRate(int32_t ioHandle, int32_t* _aidl_return) {
970 audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER(
971 aidl2legacy_int32_t_audio_io_handle_t(ioHandle));
972 *_aidl_return = VALUE_OR_RETURN_BINDER(
973 convertIntegral<int32_t>(mDelegate->sampleRate(ioHandleLegacy)));
974 return Status::ok();
975 }
976
format(int32_t output,AudioFormatDescription * _aidl_return)977 Status AudioFlingerServerAdapter::format(int32_t output,
978 AudioFormatDescription* _aidl_return) {
979 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
980 aidl2legacy_int32_t_audio_io_handle_t(output));
981 *_aidl_return = VALUE_OR_RETURN_BINDER(
982 legacy2aidl_audio_format_t_AudioFormatDescription(mDelegate->format(outputLegacy)));
983 return Status::ok();
984 }
985
frameCount(int32_t ioHandle,int64_t * _aidl_return)986 Status AudioFlingerServerAdapter::frameCount(int32_t ioHandle, int64_t* _aidl_return) {
987 audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER(
988 aidl2legacy_int32_t_audio_io_handle_t(ioHandle));
989 *_aidl_return = VALUE_OR_RETURN_BINDER(
990 convertIntegral<int64_t>(mDelegate->frameCount(ioHandleLegacy)));
991 return Status::ok();
992 }
993
latency(int32_t output,int32_t * _aidl_return)994 Status AudioFlingerServerAdapter::latency(int32_t output, int32_t* _aidl_return) {
995 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
996 aidl2legacy_int32_t_audio_io_handle_t(output));
997 *_aidl_return = VALUE_OR_RETURN_BINDER(
998 convertIntegral<int32_t>(mDelegate->latency(outputLegacy)));
999 return Status::ok();
1000 }
1001
setMasterVolume(float value)1002 Status AudioFlingerServerAdapter::setMasterVolume(float value) {
1003 return Status::fromStatusT(mDelegate->setMasterVolume(value));
1004 }
1005
setMasterMute(bool muted)1006 Status AudioFlingerServerAdapter::setMasterMute(bool muted) {
1007 return Status::fromStatusT(mDelegate->setMasterMute(muted));
1008 }
1009
masterVolume(float * _aidl_return)1010 Status AudioFlingerServerAdapter::masterVolume(float* _aidl_return) {
1011 *_aidl_return = mDelegate->masterVolume();
1012 return Status::ok();
1013 }
1014
masterMute(bool * _aidl_return)1015 Status AudioFlingerServerAdapter::masterMute(bool* _aidl_return) {
1016 *_aidl_return = mDelegate->masterMute();
1017 return Status::ok();
1018 }
1019
setMasterBalance(float balance)1020 Status AudioFlingerServerAdapter::setMasterBalance(float balance) {
1021 return Status::fromStatusT(mDelegate->setMasterBalance(balance));
1022 }
1023
getMasterBalance(float * _aidl_return)1024 Status AudioFlingerServerAdapter::getMasterBalance(float* _aidl_return) {
1025 return Status::fromStatusT(mDelegate->getMasterBalance(_aidl_return));
1026 }
1027
setStreamVolume(AudioStreamType stream,float value,int32_t output)1028 Status AudioFlingerServerAdapter::setStreamVolume(AudioStreamType stream, float value,
1029 int32_t output) {
1030 audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER(
1031 aidl2legacy_AudioStreamType_audio_stream_type_t(stream));
1032 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
1033 aidl2legacy_int32_t_audio_io_handle_t(output));
1034 return Status::fromStatusT(mDelegate->setStreamVolume(streamLegacy, value, outputLegacy));
1035 }
1036
setStreamMute(AudioStreamType stream,bool muted)1037 Status AudioFlingerServerAdapter::setStreamMute(AudioStreamType stream, bool muted) {
1038 audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER(
1039 aidl2legacy_AudioStreamType_audio_stream_type_t(stream));
1040 return Status::fromStatusT(mDelegate->setStreamMute(streamLegacy, muted));
1041 }
1042
streamVolume(AudioStreamType stream,int32_t output,float * _aidl_return)1043 Status AudioFlingerServerAdapter::streamVolume(AudioStreamType stream, int32_t output,
1044 float* _aidl_return) {
1045 audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER(
1046 aidl2legacy_AudioStreamType_audio_stream_type_t(stream));
1047 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
1048 aidl2legacy_int32_t_audio_io_handle_t(output));
1049 *_aidl_return = mDelegate->streamVolume(streamLegacy, outputLegacy);
1050 return Status::ok();
1051 }
1052
streamMute(AudioStreamType stream,bool * _aidl_return)1053 Status AudioFlingerServerAdapter::streamMute(AudioStreamType stream, bool* _aidl_return) {
1054 audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER(
1055 aidl2legacy_AudioStreamType_audio_stream_type_t(stream));
1056 *_aidl_return = mDelegate->streamMute(streamLegacy);
1057 return Status::ok();
1058 }
1059
setMode(AudioMode mode)1060 Status AudioFlingerServerAdapter::setMode(AudioMode mode) {
1061 audio_mode_t modeLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioMode_audio_mode_t(mode));
1062 return Status::fromStatusT(mDelegate->setMode(modeLegacy));
1063 }
1064
setMicMute(bool state)1065 Status AudioFlingerServerAdapter::setMicMute(bool state) {
1066 return Status::fromStatusT(mDelegate->setMicMute(state));
1067 }
1068
getMicMute(bool * _aidl_return)1069 Status AudioFlingerServerAdapter::getMicMute(bool* _aidl_return) {
1070 *_aidl_return = mDelegate->getMicMute();
1071 return Status::ok();
1072 }
1073
setRecordSilenced(int32_t portId,bool silenced)1074 Status AudioFlingerServerAdapter::setRecordSilenced(int32_t portId, bool silenced) {
1075 audio_port_handle_t portIdLegacy = VALUE_OR_RETURN_BINDER(
1076 aidl2legacy_int32_t_audio_port_handle_t(portId));
1077 mDelegate->setRecordSilenced(portIdLegacy, silenced);
1078 return Status::ok();
1079 }
1080
1081 Status
setParameters(int32_t ioHandle,const std::string & keyValuePairs)1082 AudioFlingerServerAdapter::setParameters(int32_t ioHandle, const std::string& keyValuePairs) {
1083 audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER(
1084 aidl2legacy_int32_t_audio_io_handle_t(ioHandle));
1085 String8 keyValuePairsLegacy = VALUE_OR_RETURN_BINDER(
1086 aidl2legacy_string_view_String8(keyValuePairs));
1087 return Status::fromStatusT(mDelegate->setParameters(ioHandleLegacy, keyValuePairsLegacy));
1088 }
1089
getParameters(int32_t ioHandle,const std::string & keys,std::string * _aidl_return)1090 Status AudioFlingerServerAdapter::getParameters(int32_t ioHandle, const std::string& keys,
1091 std::string* _aidl_return) {
1092 audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER(
1093 aidl2legacy_int32_t_audio_io_handle_t(ioHandle));
1094 String8 keysLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_string_view_String8(keys));
1095 *_aidl_return = VALUE_OR_RETURN_BINDER(
1096 legacy2aidl_String8_string(mDelegate->getParameters(ioHandleLegacy, keysLegacy)));
1097 return Status::ok();
1098 }
1099
registerClient(const sp<media::IAudioFlingerClient> & client)1100 Status AudioFlingerServerAdapter::registerClient(const sp<media::IAudioFlingerClient>& client) {
1101 mDelegate->registerClient(client);
1102 return Status::ok();
1103 }
1104
getInputBufferSize(int32_t sampleRate,const AudioFormatDescription & format,const AudioChannelLayout & channelMask,int64_t * _aidl_return)1105 Status AudioFlingerServerAdapter::getInputBufferSize(int32_t sampleRate,
1106 const AudioFormatDescription& format,
1107 const AudioChannelLayout& channelMask,
1108 int64_t* _aidl_return) {
1109 uint32_t sampleRateLegacy = VALUE_OR_RETURN_BINDER(convertIntegral<uint32_t>(sampleRate));
1110 audio_format_t formatLegacy = VALUE_OR_RETURN_BINDER(
1111 aidl2legacy_AudioFormatDescription_audio_format_t(format));
1112 audio_channel_mask_t channelMaskLegacy = VALUE_OR_RETURN_BINDER(
1113 aidl2legacy_AudioChannelLayout_audio_channel_mask_t(channelMask, true /*isInput*/));
1114 size_t size = mDelegate->getInputBufferSize(sampleRateLegacy, formatLegacy, channelMaskLegacy);
1115 *_aidl_return = VALUE_OR_RETURN_BINDER(convertIntegral<int64_t>(size));
1116 return Status::ok();
1117 }
1118
openOutput(const media::OpenOutputRequest & request,media::OpenOutputResponse * _aidl_return)1119 Status AudioFlingerServerAdapter::openOutput(const media::OpenOutputRequest& request,
1120 media::OpenOutputResponse* _aidl_return) {
1121 return Status::fromStatusT(mDelegate->openOutput(request, _aidl_return));
1122 }
1123
openDuplicateOutput(int32_t output1,int32_t output2,int32_t * _aidl_return)1124 Status AudioFlingerServerAdapter::openDuplicateOutput(int32_t output1, int32_t output2,
1125 int32_t* _aidl_return) {
1126 audio_io_handle_t output1Legacy = VALUE_OR_RETURN_BINDER(
1127 aidl2legacy_int32_t_audio_io_handle_t(output1));
1128 audio_io_handle_t output2Legacy = VALUE_OR_RETURN_BINDER(
1129 aidl2legacy_int32_t_audio_io_handle_t(output2));
1130 audio_io_handle_t result = mDelegate->openDuplicateOutput(output1Legacy, output2Legacy);
1131 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_io_handle_t_int32_t(result));
1132 return Status::ok();
1133 }
1134
closeOutput(int32_t output)1135 Status AudioFlingerServerAdapter::closeOutput(int32_t output) {
1136 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
1137 aidl2legacy_int32_t_audio_io_handle_t(output));
1138 return Status::fromStatusT(mDelegate->closeOutput(outputLegacy));
1139 }
1140
suspendOutput(int32_t output)1141 Status AudioFlingerServerAdapter::suspendOutput(int32_t output) {
1142 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
1143 aidl2legacy_int32_t_audio_io_handle_t(output));
1144 return Status::fromStatusT(mDelegate->suspendOutput(outputLegacy));
1145 }
1146
restoreOutput(int32_t output)1147 Status AudioFlingerServerAdapter::restoreOutput(int32_t output) {
1148 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
1149 aidl2legacy_int32_t_audio_io_handle_t(output));
1150 return Status::fromStatusT(mDelegate->restoreOutput(outputLegacy));
1151 }
1152
openInput(const media::OpenInputRequest & request,media::OpenInputResponse * _aidl_return)1153 Status AudioFlingerServerAdapter::openInput(const media::OpenInputRequest& request,
1154 media::OpenInputResponse* _aidl_return) {
1155 return Status::fromStatusT(mDelegate->openInput(request, _aidl_return));
1156 }
1157
closeInput(int32_t input)1158 Status AudioFlingerServerAdapter::closeInput(int32_t input) {
1159 audio_io_handle_t inputLegacy = VALUE_OR_RETURN_BINDER(
1160 aidl2legacy_int32_t_audio_io_handle_t(input));
1161 return Status::fromStatusT(mDelegate->closeInput(inputLegacy));
1162 }
1163
setVoiceVolume(float volume)1164 Status AudioFlingerServerAdapter::setVoiceVolume(float volume) {
1165 return Status::fromStatusT(mDelegate->setVoiceVolume(volume));
1166 }
1167
1168 Status
getRenderPosition(int32_t output,media::RenderPosition * _aidl_return)1169 AudioFlingerServerAdapter::getRenderPosition(int32_t output, media::RenderPosition* _aidl_return) {
1170 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
1171 aidl2legacy_int32_t_audio_io_handle_t(output));
1172 uint32_t halFramesLegacy;
1173 uint32_t dspFramesLegacy;
1174 RETURN_BINDER_IF_ERROR(
1175 mDelegate->getRenderPosition(&halFramesLegacy, &dspFramesLegacy, outputLegacy));
1176 _aidl_return->halFrames = VALUE_OR_RETURN_BINDER(convertIntegral<int32_t>(halFramesLegacy));
1177 _aidl_return->dspFrames = VALUE_OR_RETURN_BINDER(convertIntegral<int32_t>(dspFramesLegacy));
1178 return Status::ok();
1179 }
1180
getInputFramesLost(int32_t ioHandle,int32_t * _aidl_return)1181 Status AudioFlingerServerAdapter::getInputFramesLost(int32_t ioHandle, int32_t* _aidl_return) {
1182 audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER(
1183 aidl2legacy_int32_t_audio_io_handle_t(ioHandle));
1184 uint32_t result = mDelegate->getInputFramesLost(ioHandleLegacy);
1185 *_aidl_return = VALUE_OR_RETURN_BINDER(convertIntegral<int32_t>(result));
1186 return Status::ok();
1187 }
1188
1189 Status
newAudioUniqueId(media::AudioUniqueIdUse use,int32_t * _aidl_return)1190 AudioFlingerServerAdapter::newAudioUniqueId(media::AudioUniqueIdUse use, int32_t* _aidl_return) {
1191 audio_unique_id_use_t useLegacy = VALUE_OR_RETURN_BINDER(
1192 aidl2legacy_AudioUniqueIdUse_audio_unique_id_use_t(use));
1193 audio_unique_id_t result = mDelegate->newAudioUniqueId(useLegacy);
1194 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_unique_id_t_int32_t(result));
1195 return Status::ok();
1196 }
1197
1198 Status
acquireAudioSessionId(int32_t audioSession,int32_t pid,int32_t uid)1199 AudioFlingerServerAdapter::acquireAudioSessionId(int32_t audioSession, int32_t pid, int32_t uid) {
1200 audio_session_t audioSessionLegacy = VALUE_OR_RETURN_BINDER(
1201 aidl2legacy_int32_t_audio_session_t(audioSession));
1202 pid_t pidLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_int32_t_pid_t(pid));
1203 uid_t uidLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_int32_t_uid_t(uid));
1204 mDelegate->acquireAudioSessionId(audioSessionLegacy, pidLegacy, uidLegacy);
1205 return Status::ok();
1206 }
1207
releaseAudioSessionId(int32_t audioSession,int32_t pid)1208 Status AudioFlingerServerAdapter::releaseAudioSessionId(int32_t audioSession, int32_t pid) {
1209 audio_session_t audioSessionLegacy = VALUE_OR_RETURN_BINDER(
1210 aidl2legacy_int32_t_audio_session_t(audioSession));
1211 pid_t pidLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_int32_t_pid_t(pid));
1212 mDelegate->releaseAudioSessionId(audioSessionLegacy, pidLegacy);
1213 return Status::ok();
1214 }
1215
queryNumberEffects(int32_t * _aidl_return)1216 Status AudioFlingerServerAdapter::queryNumberEffects(int32_t* _aidl_return) {
1217 uint32_t result;
1218 RETURN_BINDER_IF_ERROR(mDelegate->queryNumberEffects(&result));
1219 *_aidl_return = VALUE_OR_RETURN_BINDER(convertIntegral<uint32_t>(result));
1220 return Status::ok();
1221 }
1222
1223 Status
queryEffect(int32_t index,media::EffectDescriptor * _aidl_return)1224 AudioFlingerServerAdapter::queryEffect(int32_t index, media::EffectDescriptor* _aidl_return) {
1225 uint32_t indexLegacy = VALUE_OR_RETURN_BINDER(convertIntegral<uint32_t>(index));
1226 effect_descriptor_t result;
1227 RETURN_BINDER_IF_ERROR(mDelegate->queryEffect(indexLegacy, &result));
1228 *_aidl_return = VALUE_OR_RETURN_BINDER(
1229 legacy2aidl_effect_descriptor_t_EffectDescriptor(result));
1230 return Status::ok();
1231 }
1232
getEffectDescriptor(const AudioUuid & effectUUID,const AudioUuid & typeUUID,int32_t preferredTypeFlag,media::EffectDescriptor * _aidl_return)1233 Status AudioFlingerServerAdapter::getEffectDescriptor(const AudioUuid& effectUUID,
1234 const AudioUuid& typeUUID,
1235 int32_t preferredTypeFlag,
1236 media::EffectDescriptor* _aidl_return) {
1237 effect_uuid_t effectUuidLegacy = VALUE_OR_RETURN_BINDER(
1238 aidl2legacy_AudioUuid_audio_uuid_t(effectUUID));
1239 effect_uuid_t typeUuidLegacy = VALUE_OR_RETURN_BINDER(
1240 aidl2legacy_AudioUuid_audio_uuid_t(typeUUID));
1241 uint32_t preferredTypeFlagLegacy = VALUE_OR_RETURN_BINDER(
1242 convertReinterpret<uint32_t>(preferredTypeFlag));
1243 effect_descriptor_t result;
1244 RETURN_BINDER_IF_ERROR(mDelegate->getEffectDescriptor(&effectUuidLegacy, &typeUuidLegacy,
1245 preferredTypeFlagLegacy, &result));
1246 *_aidl_return = VALUE_OR_RETURN_BINDER(
1247 legacy2aidl_effect_descriptor_t_EffectDescriptor(result));
1248 return Status::ok();
1249 }
1250
createEffect(const media::CreateEffectRequest & request,media::CreateEffectResponse * _aidl_return)1251 Status AudioFlingerServerAdapter::createEffect(const media::CreateEffectRequest& request,
1252 media::CreateEffectResponse* _aidl_return) {
1253 return Status::fromStatusT(mDelegate->createEffect(request, _aidl_return));
1254 }
1255
1256 Status
moveEffects(int32_t session,int32_t srcOutput,int32_t dstOutput)1257 AudioFlingerServerAdapter::moveEffects(int32_t session, int32_t srcOutput, int32_t dstOutput) {
1258 audio_session_t sessionLegacy = VALUE_OR_RETURN_BINDER(
1259 aidl2legacy_int32_t_audio_session_t(session));
1260 audio_io_handle_t srcOutputLegacy = VALUE_OR_RETURN_BINDER(
1261 aidl2legacy_int32_t_audio_io_handle_t(srcOutput));
1262 audio_io_handle_t dstOutputLegacy = VALUE_OR_RETURN_BINDER(
1263 aidl2legacy_int32_t_audio_io_handle_t(dstOutput));
1264 return Status::fromStatusT(
1265 mDelegate->moveEffects(sessionLegacy, srcOutputLegacy, dstOutputLegacy));
1266 }
1267
setEffectSuspended(int32_t effectId,int32_t sessionId,bool suspended)1268 Status AudioFlingerServerAdapter::setEffectSuspended(int32_t effectId, int32_t sessionId,
1269 bool suspended) {
1270 int effectIdLegacy = VALUE_OR_RETURN_BINDER(convertReinterpret<int>(effectId));
1271 audio_session_t sessionIdLegacy = VALUE_OR_RETURN_BINDER(
1272 aidl2legacy_int32_t_audio_session_t(sessionId));
1273 mDelegate->setEffectSuspended(effectIdLegacy, sessionIdLegacy, suspended);
1274 return Status::ok();
1275 }
1276
loadHwModule(const std::string & name,int32_t * _aidl_return)1277 Status AudioFlingerServerAdapter::loadHwModule(const std::string& name, int32_t* _aidl_return) {
1278 audio_module_handle_t result = mDelegate->loadHwModule(name.c_str());
1279 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_module_handle_t_int32_t(result));
1280 return Status::ok();
1281 }
1282
getPrimaryOutputSamplingRate(int32_t * _aidl_return)1283 Status AudioFlingerServerAdapter::getPrimaryOutputSamplingRate(int32_t* _aidl_return) {
1284 *_aidl_return = VALUE_OR_RETURN_BINDER(
1285 convertIntegral<int32_t>(mDelegate->getPrimaryOutputSamplingRate()));
1286 return Status::ok();
1287 }
1288
getPrimaryOutputFrameCount(int64_t * _aidl_return)1289 Status AudioFlingerServerAdapter::getPrimaryOutputFrameCount(int64_t* _aidl_return) {
1290 *_aidl_return = VALUE_OR_RETURN_BINDER(
1291 convertIntegral<int64_t>(mDelegate->getPrimaryOutputFrameCount()));
1292 return Status::ok();
1293
1294 }
1295
setLowRamDevice(bool isLowRamDevice,int64_t totalMemory)1296 Status AudioFlingerServerAdapter::setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) {
1297 return Status::fromStatusT(mDelegate->setLowRamDevice(isLowRamDevice, totalMemory));
1298 }
1299
getAudioPort(const media::AudioPortFw & port,media::AudioPortFw * _aidl_return)1300 Status AudioFlingerServerAdapter::getAudioPort(const media::AudioPortFw& port,
1301 media::AudioPortFw* _aidl_return) {
1302 audio_port_v7 portLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioPortFw_audio_port_v7(port));
1303 RETURN_BINDER_IF_ERROR(mDelegate->getAudioPort(&portLegacy));
1304 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_port_v7_AudioPortFw(portLegacy));
1305 return Status::ok();
1306 }
1307
createAudioPatch(const media::AudioPatchFw & patch,int32_t * _aidl_return)1308 Status AudioFlingerServerAdapter::createAudioPatch(const media::AudioPatchFw& patch,
1309 int32_t* _aidl_return) {
1310 audio_patch patchLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioPatchFw_audio_patch(patch));
1311 audio_patch_handle_t handleLegacy = VALUE_OR_RETURN_BINDER(
1312 aidl2legacy_int32_t_audio_patch_handle_t(*_aidl_return));
1313 RETURN_BINDER_IF_ERROR(mDelegate->createAudioPatch(&patchLegacy, &handleLegacy));
1314 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_patch_handle_t_int32_t(handleLegacy));
1315 return Status::ok();
1316 }
1317
releaseAudioPatch(int32_t handle)1318 Status AudioFlingerServerAdapter::releaseAudioPatch(int32_t handle) {
1319 audio_patch_handle_t handleLegacy = VALUE_OR_RETURN_BINDER(
1320 aidl2legacy_int32_t_audio_patch_handle_t(handle));
1321 return Status::fromStatusT(mDelegate->releaseAudioPatch(handleLegacy));
1322 }
1323
listAudioPatches(int32_t maxCount,std::vector<media::AudioPatchFw> * _aidl_return)1324 Status AudioFlingerServerAdapter::listAudioPatches(int32_t maxCount,
1325 std::vector<media::AudioPatchFw>* _aidl_return) {
1326 unsigned int count = VALUE_OR_RETURN_BINDER(convertIntegral<unsigned int>(maxCount));
1327 count = std::min(count, static_cast<unsigned int>(MAX_ITEMS_PER_LIST));
1328 std::unique_ptr<audio_patch[]> patchesLegacy(new audio_patch[count]);
1329 RETURN_BINDER_IF_ERROR(mDelegate->listAudioPatches(&count, patchesLegacy.get()));
1330 RETURN_BINDER_IF_ERROR(convertRange(&patchesLegacy[0],
1331 &patchesLegacy[count],
1332 std::back_inserter(*_aidl_return),
1333 legacy2aidl_audio_patch_AudioPatchFw));
1334 return Status::ok();
1335 }
1336
setAudioPortConfig(const media::AudioPortConfigFw & config)1337 Status AudioFlingerServerAdapter::setAudioPortConfig(const media::AudioPortConfigFw& config) {
1338 audio_port_config configLegacy = VALUE_OR_RETURN_BINDER(
1339 aidl2legacy_AudioPortConfigFw_audio_port_config(config));
1340 return Status::fromStatusT(mDelegate->setAudioPortConfig(&configLegacy));
1341 }
1342
getAudioHwSyncForSession(int32_t sessionId,int32_t * _aidl_return)1343 Status AudioFlingerServerAdapter::getAudioHwSyncForSession(int32_t sessionId,
1344 int32_t* _aidl_return) {
1345 audio_session_t sessionIdLegacy = VALUE_OR_RETURN_BINDER(
1346 aidl2legacy_int32_t_audio_session_t(sessionId));
1347 audio_hw_sync_t result = mDelegate->getAudioHwSyncForSession(sessionIdLegacy);
1348 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_hw_sync_t_int32_t(result));
1349 return Status::ok();
1350 }
1351
systemReady()1352 Status AudioFlingerServerAdapter::systemReady() {
1353 return Status::fromStatusT(mDelegate->systemReady());
1354 }
1355
audioPolicyReady()1356 Status AudioFlingerServerAdapter::audioPolicyReady() {
1357 mDelegate->audioPolicyReady();
1358 return Status::ok();
1359 }
1360
frameCountHAL(int32_t ioHandle,int64_t * _aidl_return)1361 Status AudioFlingerServerAdapter::frameCountHAL(int32_t ioHandle, int64_t* _aidl_return) {
1362 audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER(
1363 aidl2legacy_int32_t_audio_io_handle_t(ioHandle));
1364 size_t result = mDelegate->frameCountHAL(ioHandleLegacy);
1365 *_aidl_return = VALUE_OR_RETURN_BINDER(convertIntegral<int64_t>(result));
1366 return Status::ok();
1367 }
1368
getMicrophones(std::vector<media::MicrophoneInfoFw> * _aidl_return)1369 Status AudioFlingerServerAdapter::getMicrophones(
1370 std::vector<media::MicrophoneInfoFw>* _aidl_return) {
1371 RETURN_BINDER_IF_ERROR(mDelegate->getMicrophones(_aidl_return));
1372 return Status::ok();
1373 }
1374
setAudioHalPids(const std::vector<int32_t> & pids)1375 Status AudioFlingerServerAdapter::setAudioHalPids(const std::vector<int32_t>& pids) {
1376 std::vector<pid_t> pidsLegacy = VALUE_OR_RETURN_BINDER(
1377 convertContainer<std::vector<pid_t>>(pids, aidl2legacy_int32_t_pid_t));
1378 RETURN_BINDER_IF_ERROR(mDelegate->setAudioHalPids(pidsLegacy));
1379 return Status::ok();
1380 }
1381
setVibratorInfos(const std::vector<media::AudioVibratorInfo> & vibratorInfos)1382 Status AudioFlingerServerAdapter::setVibratorInfos(
1383 const std::vector<media::AudioVibratorInfo>& vibratorInfos) {
1384 return Status::fromStatusT(mDelegate->setVibratorInfos(vibratorInfos));
1385 }
1386
updateSecondaryOutputs(const std::vector<media::TrackSecondaryOutputInfo> & trackSecondaryOutputInfos)1387 Status AudioFlingerServerAdapter::updateSecondaryOutputs(
1388 const std::vector<media::TrackSecondaryOutputInfo>& trackSecondaryOutputInfos) {
1389 TrackSecondaryOutputsMap trackSecondaryOutputs =
1390 VALUE_OR_RETURN_BINDER(convertContainer<TrackSecondaryOutputsMap>(
1391 trackSecondaryOutputInfos,
1392 aidl2legacy_TrackSecondaryOutputInfo_TrackSecondaryOutputInfoPair));
1393 return Status::fromStatusT(mDelegate->updateSecondaryOutputs(trackSecondaryOutputs));
1394 }
1395
getMmapPolicyInfos(AudioMMapPolicyType policyType,std::vector<AudioMMapPolicyInfo> * _aidl_return)1396 Status AudioFlingerServerAdapter::getMmapPolicyInfos(
1397 AudioMMapPolicyType policyType, std::vector<AudioMMapPolicyInfo> *_aidl_return) {
1398 return Status::fromStatusT(mDelegate->getMmapPolicyInfos(policyType, _aidl_return));
1399 }
1400
getAAudioMixerBurstCount(int32_t * _aidl_return)1401 Status AudioFlingerServerAdapter::getAAudioMixerBurstCount(int32_t* _aidl_return) {
1402 *_aidl_return = VALUE_OR_RETURN_BINDER(
1403 convertIntegral<int32_t>(mDelegate->getAAudioMixerBurstCount()));
1404 return Status::ok();
1405 }
1406
getAAudioHardwareBurstMinUsec(int32_t * _aidl_return)1407 Status AudioFlingerServerAdapter::getAAudioHardwareBurstMinUsec(int32_t* _aidl_return) {
1408 *_aidl_return = VALUE_OR_RETURN_BINDER(
1409 convertIntegral<int32_t>(mDelegate->getAAudioHardwareBurstMinUsec()));
1410 return Status::ok();
1411 }
1412
setDeviceConnectedState(const media::AudioPortFw & port,media::DeviceConnectedState state)1413 Status AudioFlingerServerAdapter::setDeviceConnectedState(
1414 const media::AudioPortFw& port, media::DeviceConnectedState state) {
1415 audio_port_v7 portLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioPortFw_audio_port_v7(port));
1416 return Status::fromStatusT(mDelegate->setDeviceConnectedState(&portLegacy, state));
1417 }
1418
setSimulateDeviceConnections(bool enabled)1419 Status AudioFlingerServerAdapter::setSimulateDeviceConnections(bool enabled) {
1420 return Status::fromStatusT(mDelegate->setSimulateDeviceConnections(enabled));
1421 }
1422
setRequestedLatencyMode(int32_t output,media::audio::common::AudioLatencyMode modeAidl)1423 Status AudioFlingerServerAdapter::setRequestedLatencyMode(
1424 int32_t output, media::audio::common::AudioLatencyMode modeAidl) {
1425 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
1426 aidl2legacy_int32_t_audio_io_handle_t(output));
1427 audio_latency_mode_t modeLegacy = VALUE_OR_RETURN_BINDER(
1428 aidl2legacy_AudioLatencyMode_audio_latency_mode_t(modeAidl));
1429 return Status::fromStatusT(mDelegate->setRequestedLatencyMode(
1430 outputLegacy, modeLegacy));
1431 }
1432
getSupportedLatencyModes(int output,std::vector<media::audio::common::AudioLatencyMode> * _aidl_return)1433 Status AudioFlingerServerAdapter::getSupportedLatencyModes(
1434 int output, std::vector<media::audio::common::AudioLatencyMode>* _aidl_return) {
1435 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
1436 aidl2legacy_int32_t_audio_io_handle_t(output));
1437 std::vector<audio_latency_mode_t> modesLegacy;
1438
1439 RETURN_BINDER_IF_ERROR(mDelegate->getSupportedLatencyModes(outputLegacy, &modesLegacy));
1440
1441 *_aidl_return = VALUE_OR_RETURN_BINDER(
1442 convertContainer<std::vector<media::audio::common::AudioLatencyMode>>(
1443 modesLegacy, legacy2aidl_audio_latency_mode_t_AudioLatencyMode));
1444 return Status::ok();
1445 }
1446
setBluetoothVariableLatencyEnabled(bool enabled)1447 Status AudioFlingerServerAdapter::setBluetoothVariableLatencyEnabled(bool enabled) {
1448 return Status::fromStatusT(mDelegate->setBluetoothVariableLatencyEnabled(enabled));
1449 }
1450
isBluetoothVariableLatencyEnabled(bool * enabled)1451 Status AudioFlingerServerAdapter::isBluetoothVariableLatencyEnabled(bool *enabled) {
1452 return Status::fromStatusT(mDelegate->isBluetoothVariableLatencyEnabled(enabled));
1453 }
1454
supportsBluetoothVariableLatency(bool * support)1455 Status AudioFlingerServerAdapter::supportsBluetoothVariableLatency(bool *support) {
1456 return Status::fromStatusT(mDelegate->supportsBluetoothVariableLatency(support));
1457 }
1458
getSoundDoseInterface(const sp<media::ISoundDoseCallback> & callback,sp<media::ISoundDose> * soundDose)1459 Status AudioFlingerServerAdapter::getSoundDoseInterface(
1460 const sp<media::ISoundDoseCallback>& callback,
1461 sp<media::ISoundDose>* soundDose)
1462 {
1463 return Status::fromStatusT(mDelegate->getSoundDoseInterface(callback, soundDose));
1464 }
1465
invalidateTracks(const std::vector<int32_t> & portIds)1466 Status AudioFlingerServerAdapter::invalidateTracks(const std::vector<int32_t>& portIds) {
1467 std::vector<audio_port_handle_t> portIdsLegacy = VALUE_OR_RETURN_BINDER(
1468 convertContainer<std::vector<audio_port_handle_t>>(
1469 portIds, aidl2legacy_int32_t_audio_port_handle_t));
1470 RETURN_BINDER_IF_ERROR(mDelegate->invalidateTracks(portIdsLegacy));
1471 return Status::ok();
1472 }
1473
getAudioPolicyConfig(media::AudioPolicyConfig * _aidl_return)1474 Status AudioFlingerServerAdapter::getAudioPolicyConfig(media::AudioPolicyConfig* _aidl_return) {
1475 return Status::fromStatusT(mDelegate->getAudioPolicyConfig(_aidl_return));
1476 }
1477
getAudioMixPort(const media::AudioPortFw & devicePort,const media::AudioPortFw & mixPort,media::AudioPortFw * _aidl_return)1478 Status AudioFlingerServerAdapter::getAudioMixPort(const media::AudioPortFw &devicePort,
1479 const media::AudioPortFw &mixPort,
1480 media::AudioPortFw *_aidl_return) {
1481 audio_port_v7 devicePortLegacy = VALUE_OR_RETURN_BINDER(
1482 aidl2legacy_AudioPortFw_audio_port_v7(devicePort));
1483 audio_port_v7 mixPortLegacy = VALUE_OR_RETURN_BINDER(
1484 aidl2legacy_AudioPortFw_audio_port_v7(mixPort));
1485 RETURN_BINDER_IF_ERROR(mDelegate->getAudioMixPort(&devicePortLegacy, &mixPortLegacy));
1486 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_port_v7_AudioPortFw(mixPortLegacy));
1487 return Status::ok();
1488 }
1489
setTracksInternalMute(const std::vector<media::TrackInternalMuteInfo> & tracksInternalMute)1490 Status AudioFlingerServerAdapter::setTracksInternalMute(
1491 const std::vector<media::TrackInternalMuteInfo>& tracksInternalMute) {
1492 return Status::fromStatusT(mDelegate->setTracksInternalMute(tracksInternalMute));
1493 }
1494
resetReferencesForTest()1495 Status AudioFlingerServerAdapter::resetReferencesForTest() {
1496 RETURN_BINDER_IF_ERROR(mDelegate->resetReferencesForTest());
1497 return Status::ok();
1498 }
1499
1500 } // namespace android
1501