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 #include <utils/Log.h>
21
22 #include <stdint.h>
23 #include <sys/types.h>
24
25 #include <binder/IPCThreadState.h>
26 #include <binder/Parcel.h>
27 #include "IAudioFlinger.h"
28
29 namespace android {
30
31 using aidl_utils::statusTFromBinderStatus;
32 using binder::Status;
33
34 #define MAX_ITEMS_PER_LIST 1024
35
36 #define VALUE_OR_RETURN_BINDER(x) \
37 ({ \
38 auto _tmp = (x); \
39 if (!_tmp.ok()) return Status::fromStatusT(_tmp.error()); \
40 std::move(_tmp.value()); \
41 })
42
43 #define RETURN_STATUS_IF_ERROR(x) \
44 { \
45 auto _tmp = (x); \
46 if (_tmp != OK) return _tmp; \
47 }
48
49 #define RETURN_BINDER_IF_ERROR(x) \
50 { \
51 auto _tmp = (x); \
52 if (_tmp != OK) return Status::fromStatusT(_tmp); \
53 }
54
toAidl() const55 ConversionResult<media::CreateTrackRequest> IAudioFlinger::CreateTrackInput::toAidl() const {
56 media::CreateTrackRequest aidl;
57 aidl.attr = VALUE_OR_RETURN(legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr));
58 aidl.config = VALUE_OR_RETURN(legacy2aidl_audio_config_t_AudioConfig(config));
59 aidl.clientInfo = VALUE_OR_RETURN(legacy2aidl_AudioClient_AudioClient(clientInfo));
60 aidl.sharedBuffer = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(sharedBuffer));
61 aidl.notificationsPerBuffer = VALUE_OR_RETURN(convertIntegral<int32_t>(notificationsPerBuffer));
62 aidl.speed = speed;
63 aidl.audioTrackCallback = audioTrackCallback;
64 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_output_flags_t_int32_t_mask(flags));
65 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
66 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
67 aidl.selectedDeviceId = VALUE_OR_RETURN(
68 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
69 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
70 return aidl;
71 }
72
73 ConversionResult<IAudioFlinger::CreateTrackInput>
fromAidl(const media::CreateTrackRequest & aidl)74 IAudioFlinger::CreateTrackInput::fromAidl(const media::CreateTrackRequest& aidl) {
75 IAudioFlinger::CreateTrackInput legacy;
76 legacy.attr = VALUE_OR_RETURN(aidl2legacy_AudioAttributesInternal_audio_attributes_t(aidl.attr));
77 legacy.config = VALUE_OR_RETURN(aidl2legacy_AudioConfig_audio_config_t(aidl.config));
78 legacy.clientInfo = VALUE_OR_RETURN(aidl2legacy_AudioClient_AudioClient(aidl.clientInfo));
79 legacy.sharedBuffer = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.sharedBuffer));
80 legacy.notificationsPerBuffer = VALUE_OR_RETURN(
81 convertIntegral<uint32_t>(aidl.notificationsPerBuffer));
82 legacy.speed = aidl.speed;
83 legacy.audioTrackCallback = aidl.audioTrackCallback;
84 legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_output_flags_t_mask(aidl.flags));
85 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
86 legacy.notificationFrameCount = VALUE_OR_RETURN(
87 convertIntegral<size_t>(aidl.notificationFrameCount));
88 legacy.selectedDeviceId = VALUE_OR_RETURN(
89 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
90 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
91 return legacy;
92 }
93
94 ConversionResult<media::CreateTrackResponse>
toAidl() const95 IAudioFlinger::CreateTrackOutput::toAidl() const {
96 media::CreateTrackResponse aidl;
97 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_output_flags_t_int32_t_mask(flags));
98 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
99 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
100 aidl.selectedDeviceId = VALUE_OR_RETURN(
101 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
102 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
103 aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate));
104 aidl.streamType = VALUE_OR_RETURN(
105 legacy2aidl_audio_stream_type_t_AudioStreamType(streamType));
106 aidl.afFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(afFrameCount));
107 aidl.afSampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(afSampleRate));
108 aidl.afLatencyMs = VALUE_OR_RETURN(convertIntegral<int32_t>(afLatencyMs));
109 aidl.outputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(outputId));
110 aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId));
111 aidl.audioTrack = audioTrack;
112 return aidl;
113 }
114
115 ConversionResult<IAudioFlinger::CreateTrackOutput>
fromAidl(const media::CreateTrackResponse & aidl)116 IAudioFlinger::CreateTrackOutput::fromAidl(
117 const media::CreateTrackResponse& aidl) {
118 IAudioFlinger::CreateTrackOutput legacy;
119 legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_output_flags_t_mask(aidl.flags));
120 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
121 legacy.notificationFrameCount = VALUE_OR_RETURN(
122 convertIntegral<size_t>(aidl.notificationFrameCount));
123 legacy.selectedDeviceId = VALUE_OR_RETURN(
124 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
125 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
126 legacy.sampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate));
127 legacy.streamType = VALUE_OR_RETURN(
128 aidl2legacy_AudioStreamType_audio_stream_type_t(aidl.streamType));
129 legacy.afFrameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.afFrameCount));
130 legacy.afSampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.afSampleRate));
131 legacy.afLatencyMs = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.afLatencyMs));
132 legacy.outputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.outputId));
133 legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId));
134 legacy.audioTrack = aidl.audioTrack;
135 return legacy;
136 }
137
138 ConversionResult<media::CreateRecordRequest>
toAidl() const139 IAudioFlinger::CreateRecordInput::toAidl() const {
140 media::CreateRecordRequest aidl;
141 aidl.attr = VALUE_OR_RETURN(legacy2aidl_audio_attributes_t_AudioAttributesInternal(attr));
142 aidl.config = VALUE_OR_RETURN(legacy2aidl_audio_config_base_t_AudioConfigBase(config));
143 aidl.clientInfo = VALUE_OR_RETURN(legacy2aidl_AudioClient_AudioClient(clientInfo));
144 aidl.riid = VALUE_OR_RETURN(legacy2aidl_audio_unique_id_t_int32_t(riid));
145 aidl.maxSharedAudioHistoryMs = VALUE_OR_RETURN(
146 convertIntegral<int32_t>(maxSharedAudioHistoryMs));
147 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_input_flags_t_int32_t_mask(flags));
148 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
149 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
150 aidl.selectedDeviceId = VALUE_OR_RETURN(
151 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
152 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
153 return aidl;
154 }
155
156 ConversionResult<IAudioFlinger::CreateRecordInput>
fromAidl(const media::CreateRecordRequest & aidl)157 IAudioFlinger::CreateRecordInput::fromAidl(
158 const media::CreateRecordRequest& aidl) {
159 IAudioFlinger::CreateRecordInput legacy;
160 legacy.attr = VALUE_OR_RETURN(
161 aidl2legacy_AudioAttributesInternal_audio_attributes_t(aidl.attr));
162 legacy.config = VALUE_OR_RETURN(aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.config));
163 legacy.clientInfo = VALUE_OR_RETURN(aidl2legacy_AudioClient_AudioClient(aidl.clientInfo));
164 legacy.riid = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_unique_id_t(aidl.riid));
165 legacy.maxSharedAudioHistoryMs = VALUE_OR_RETURN(
166 convertIntegral<int32_t>(aidl.maxSharedAudioHistoryMs));
167 legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_input_flags_t_mask(aidl.flags));
168 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
169 legacy.notificationFrameCount = VALUE_OR_RETURN(
170 convertIntegral<size_t>(aidl.notificationFrameCount));
171 legacy.selectedDeviceId = VALUE_OR_RETURN(
172 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
173 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
174 return legacy;
175 }
176
177 ConversionResult<media::CreateRecordResponse>
toAidl() const178 IAudioFlinger::CreateRecordOutput::toAidl() const {
179 media::CreateRecordResponse aidl;
180 aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_input_flags_t_int32_t_mask(flags));
181 aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(frameCount));
182 aidl.notificationFrameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(notificationFrameCount));
183 aidl.selectedDeviceId = VALUE_OR_RETURN(
184 legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId));
185 aidl.sessionId = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
186 aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate));
187 aidl.inputId = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(inputId));
188 aidl.cblk = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(cblk));
189 aidl.buffers = VALUE_OR_RETURN(legacy2aidl_NullableIMemory_SharedFileRegion(buffers));
190 aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(portId));
191 aidl.audioRecord = audioRecord;
192 return aidl;
193 }
194
195 ConversionResult<IAudioFlinger::CreateRecordOutput>
fromAidl(const media::CreateRecordResponse & aidl)196 IAudioFlinger::CreateRecordOutput::fromAidl(
197 const media::CreateRecordResponse& aidl) {
198 IAudioFlinger::CreateRecordOutput legacy;
199 legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_input_flags_t_mask(aidl.flags));
200 legacy.frameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
201 legacy.notificationFrameCount = VALUE_OR_RETURN(
202 convertIntegral<size_t>(aidl.notificationFrameCount));
203 legacy.selectedDeviceId = VALUE_OR_RETURN(
204 aidl2legacy_int32_t_audio_port_handle_t(aidl.selectedDeviceId));
205 legacy.sessionId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.sessionId));
206 legacy.sampleRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate));
207 legacy.inputId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.inputId));
208 legacy.cblk = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.cblk));
209 legacy.buffers = VALUE_OR_RETURN(aidl2legacy_NullableSharedFileRegion_IMemory(aidl.buffers));
210 legacy.portId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId));
211 legacy.audioRecord = aidl.audioRecord;
212 return legacy;
213 }
214
215 ////////////////////////////////////////////////////////////////////////////////////////////////////
216 // AudioFlingerClientAdapter
217
AudioFlingerClientAdapter(const sp<media::IAudioFlingerService> delegate)218 AudioFlingerClientAdapter::AudioFlingerClientAdapter(
219 const sp<media::IAudioFlingerService> delegate) : mDelegate(delegate) {}
220
createTrack(const media::CreateTrackRequest & input,media::CreateTrackResponse & output)221 status_t AudioFlingerClientAdapter::createTrack(const media::CreateTrackRequest& input,
222 media::CreateTrackResponse& output) {
223 return statusTFromBinderStatus(mDelegate->createTrack(input, &output));
224 }
225
createRecord(const media::CreateRecordRequest & input,media::CreateRecordResponse & output)226 status_t AudioFlingerClientAdapter::createRecord(const media::CreateRecordRequest& input,
227 media::CreateRecordResponse& output) {
228 return statusTFromBinderStatus(mDelegate->createRecord(input, &output));
229 }
230
sampleRate(audio_io_handle_t ioHandle) const231 uint32_t AudioFlingerClientAdapter::sampleRate(audio_io_handle_t ioHandle) const {
232 auto result = [&]() -> ConversionResult<uint32_t> {
233 int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle));
234 int32_t aidlRet;
235 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->sampleRate(ioHandleAidl, &aidlRet)));
236 return convertIntegral<uint32_t>(aidlRet);
237 }();
238 // Failure is ignored.
239 return result.value_or(0);
240 }
241
format(audio_io_handle_t output) const242 audio_format_t AudioFlingerClientAdapter::format(audio_io_handle_t output) const {
243 auto result = [&]() -> ConversionResult<audio_format_t> {
244 int32_t outputAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(output));
245 media::audio::common::AudioFormat aidlRet;
246 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->format(outputAidl, &aidlRet)));
247 return aidl2legacy_AudioFormat_audio_format_t(aidlRet);
248 }();
249 return result.value_or(AUDIO_FORMAT_INVALID);
250 }
251
frameCount(audio_io_handle_t ioHandle) const252 size_t AudioFlingerClientAdapter::frameCount(audio_io_handle_t ioHandle) const {
253 auto result = [&]() -> ConversionResult<size_t> {
254 int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle));
255 int64_t aidlRet;
256 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->frameCount(ioHandleAidl, &aidlRet)));
257 return convertIntegral<size_t>(aidlRet);
258 }();
259 // Failure is ignored.
260 return result.value_or(0);
261 }
262
latency(audio_io_handle_t output) const263 uint32_t AudioFlingerClientAdapter::latency(audio_io_handle_t output) const {
264 auto result = [&]() -> ConversionResult<uint32_t> {
265 int32_t outputAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(output));
266 int32_t aidlRet;
267 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->latency(outputAidl, &aidlRet)));
268 return convertIntegral<uint32_t>(aidlRet);
269 }();
270 // Failure is ignored.
271 return result.value_or(0);
272 }
273
setMasterVolume(float value)274 status_t AudioFlingerClientAdapter::setMasterVolume(float value) {
275 return statusTFromBinderStatus(mDelegate->setMasterVolume(value));
276 }
277
setMasterMute(bool muted)278 status_t AudioFlingerClientAdapter::setMasterMute(bool muted) {
279 return statusTFromBinderStatus(mDelegate->setMasterMute(muted));
280 }
281
masterVolume() const282 float AudioFlingerClientAdapter::masterVolume() const {
283 auto result = [&]() -> ConversionResult<float> {
284 float aidlRet;
285 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->masterVolume(&aidlRet)));
286 return aidlRet;
287 }();
288 // Failure is ignored.
289 return result.value_or(0.f);
290 }
291
masterMute() const292 bool AudioFlingerClientAdapter::masterMute() const {
293 auto result = [&]() -> ConversionResult<bool> {
294 bool aidlRet;
295 RETURN_IF_ERROR(statusTFromBinderStatus(mDelegate->masterMute(&aidlRet)));
296 return aidlRet;
297 }();
298 // Failure is ignored.
299 return result.value_or(false);
300 }
301
setMasterBalance(float balance)302 status_t AudioFlingerClientAdapter::setMasterBalance(float balance) {
303 return statusTFromBinderStatus(mDelegate->setMasterBalance(balance));
304 }
305
getMasterBalance(float * balance) const306 status_t AudioFlingerClientAdapter::getMasterBalance(float* balance) const{
307 return statusTFromBinderStatus(mDelegate->getMasterBalance(balance));
308 }
309
setStreamVolume(audio_stream_type_t stream,float value,audio_io_handle_t output)310 status_t AudioFlingerClientAdapter::setStreamVolume(audio_stream_type_t stream, float value,
311 audio_io_handle_t output) {
312 media::AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS(
313 legacy2aidl_audio_stream_type_t_AudioStreamType(stream));
314 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
315 return statusTFromBinderStatus(mDelegate->setStreamVolume(streamAidl, value, outputAidl));
316 }
317
setStreamMute(audio_stream_type_t stream,bool muted)318 status_t AudioFlingerClientAdapter::setStreamMute(audio_stream_type_t stream, bool muted) {
319 media::AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS(
320 legacy2aidl_audio_stream_type_t_AudioStreamType(stream));
321 return statusTFromBinderStatus(mDelegate->setStreamMute(streamAidl, muted));
322 }
323
streamVolume(audio_stream_type_t stream,audio_io_handle_t output) const324 float AudioFlingerClientAdapter::streamVolume(audio_stream_type_t stream,
325 audio_io_handle_t output) const {
326 auto result = [&]() -> ConversionResult<float> {
327 media::AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS(
328 legacy2aidl_audio_stream_type_t_AudioStreamType(stream));
329 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
330 float aidlRet;
331 RETURN_IF_ERROR(statusTFromBinderStatus(
332 mDelegate->streamVolume(streamAidl, outputAidl, &aidlRet)));
333 return aidlRet;
334 }();
335 // Failure is ignored.
336 return result.value_or(0.f);
337 }
338
streamMute(audio_stream_type_t stream) const339 bool AudioFlingerClientAdapter::streamMute(audio_stream_type_t stream) const {
340 auto result = [&]() -> ConversionResult<bool> {
341 media::AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS(
342 legacy2aidl_audio_stream_type_t_AudioStreamType(stream));
343 bool aidlRet;
344 RETURN_IF_ERROR(statusTFromBinderStatus(
345 mDelegate->streamMute(streamAidl, &aidlRet)));
346 return aidlRet;
347 }();
348 // Failure is ignored.
349 return result.value_or(false);
350 }
351
setMode(audio_mode_t mode)352 status_t AudioFlingerClientAdapter::setMode(audio_mode_t mode) {
353 media::AudioMode modeAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_mode_t_AudioMode(mode));
354 return statusTFromBinderStatus(mDelegate->setMode(modeAidl));
355 }
356
setMicMute(bool state)357 status_t AudioFlingerClientAdapter::setMicMute(bool state) {
358 return statusTFromBinderStatus(mDelegate->setMicMute(state));
359 }
360
getMicMute() const361 bool AudioFlingerClientAdapter::getMicMute() const {
362 auto result = [&]() -> ConversionResult<bool> {
363 bool aidlRet;
364 RETURN_IF_ERROR(statusTFromBinderStatus(
365 mDelegate->getMicMute(&aidlRet)));
366 return aidlRet;
367 }();
368 // Failure is ignored.
369 return result.value_or(false);
370 }
371
setRecordSilenced(audio_port_handle_t portId,bool silenced)372 void AudioFlingerClientAdapter::setRecordSilenced(audio_port_handle_t portId, bool silenced) {
373 auto result = [&]() -> status_t {
374 int32_t portIdAidl = VALUE_OR_RETURN_STATUS(
375 legacy2aidl_audio_port_handle_t_int32_t(portId));
376 return statusTFromBinderStatus(mDelegate->setRecordSilenced(portIdAidl, silenced));
377 }();
378 // Failure is ignored.
379 (void) result;
380 }
381
setParameters(audio_io_handle_t ioHandle,const String8 & keyValuePairs)382 status_t AudioFlingerClientAdapter::setParameters(audio_io_handle_t ioHandle,
383 const String8& keyValuePairs) {
384 int32_t ioHandleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(ioHandle));
385 std::string keyValuePairsAidl = VALUE_OR_RETURN_STATUS(
386 legacy2aidl_String8_string(keyValuePairs));
387 return statusTFromBinderStatus(mDelegate->setParameters(ioHandleAidl, keyValuePairsAidl));
388 }
389
getParameters(audio_io_handle_t ioHandle,const String8 & keys) const390 String8 AudioFlingerClientAdapter::getParameters(audio_io_handle_t ioHandle, const String8& keys)
391 const {
392 auto result = [&]() -> ConversionResult<String8> {
393 int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle));
394 std::string keysAidl = VALUE_OR_RETURN(legacy2aidl_String8_string(keys));
395 std::string aidlRet;
396 RETURN_IF_ERROR(statusTFromBinderStatus(
397 mDelegate->getParameters(ioHandleAidl, keysAidl, &aidlRet)));
398 return aidl2legacy_string_view_String8(aidlRet);
399 }();
400 // Failure is ignored.
401 return result.value_or(String8());
402 }
403
registerClient(const sp<media::IAudioFlingerClient> & client)404 void AudioFlingerClientAdapter::registerClient(const sp<media::IAudioFlingerClient>& client) {
405 mDelegate->registerClient(client);
406 // Failure is ignored.
407 }
408
getInputBufferSize(uint32_t sampleRate,audio_format_t format,audio_channel_mask_t channelMask) const409 size_t AudioFlingerClientAdapter::getInputBufferSize(uint32_t sampleRate, audio_format_t format,
410 audio_channel_mask_t channelMask) const {
411 auto result = [&]() -> ConversionResult<size_t> {
412 int32_t sampleRateAidl = VALUE_OR_RETURN(convertIntegral<int32_t>(sampleRate));
413 media::audio::common::AudioFormat formatAidl = VALUE_OR_RETURN(
414 legacy2aidl_audio_format_t_AudioFormat(format));
415 int32_t channelMaskAidl = VALUE_OR_RETURN(
416 legacy2aidl_audio_channel_mask_t_int32_t(channelMask));
417 int64_t aidlRet;
418 RETURN_IF_ERROR(statusTFromBinderStatus(
419 mDelegate->getInputBufferSize(sampleRateAidl, formatAidl, channelMaskAidl,
420 &aidlRet)));
421 return convertIntegral<size_t>(aidlRet);
422 }();
423 // Failure is ignored.
424 return result.value_or(0);
425 }
426
openOutput(const media::OpenOutputRequest & request,media::OpenOutputResponse * response)427 status_t AudioFlingerClientAdapter::openOutput(const media::OpenOutputRequest& request,
428 media::OpenOutputResponse* response) {
429 return statusTFromBinderStatus(mDelegate->openOutput(request, response));
430 }
431
openDuplicateOutput(audio_io_handle_t output1,audio_io_handle_t output2)432 audio_io_handle_t AudioFlingerClientAdapter::openDuplicateOutput(audio_io_handle_t output1,
433 audio_io_handle_t output2) {
434 auto result = [&]() -> ConversionResult<audio_io_handle_t> {
435 int32_t output1Aidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(output1));
436 int32_t output2Aidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(output2));
437 int32_t aidlRet;
438 RETURN_IF_ERROR(statusTFromBinderStatus(
439 mDelegate->openDuplicateOutput(output1Aidl, output2Aidl, &aidlRet)));
440 return aidl2legacy_int32_t_audio_io_handle_t(aidlRet);
441 }();
442 // Failure is ignored.
443 return result.value_or(0);
444 }
445
closeOutput(audio_io_handle_t output)446 status_t AudioFlingerClientAdapter::closeOutput(audio_io_handle_t output) {
447 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
448 return statusTFromBinderStatus(mDelegate->closeOutput(outputAidl));
449 }
450
suspendOutput(audio_io_handle_t output)451 status_t AudioFlingerClientAdapter::suspendOutput(audio_io_handle_t output) {
452 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
453 return statusTFromBinderStatus(mDelegate->suspendOutput(outputAidl));
454 }
455
restoreOutput(audio_io_handle_t output)456 status_t AudioFlingerClientAdapter::restoreOutput(audio_io_handle_t output) {
457 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
458 return statusTFromBinderStatus(mDelegate->restoreOutput(outputAidl));
459 }
460
openInput(const media::OpenInputRequest & request,media::OpenInputResponse * response)461 status_t AudioFlingerClientAdapter::openInput(const media::OpenInputRequest& request,
462 media::OpenInputResponse* response) {
463 return statusTFromBinderStatus(mDelegate->openInput(request, response));
464 }
465
closeInput(audio_io_handle_t input)466 status_t AudioFlingerClientAdapter::closeInput(audio_io_handle_t input) {
467 int32_t inputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(input));
468 return statusTFromBinderStatus(mDelegate->closeInput(inputAidl));
469 }
470
invalidateStream(audio_stream_type_t stream)471 status_t AudioFlingerClientAdapter::invalidateStream(audio_stream_type_t stream) {
472 media::AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS(
473 legacy2aidl_audio_stream_type_t_AudioStreamType(stream));
474 return statusTFromBinderStatus(mDelegate->invalidateStream(streamAidl));
475 }
476
setVoiceVolume(float volume)477 status_t AudioFlingerClientAdapter::setVoiceVolume(float volume) {
478 return statusTFromBinderStatus(mDelegate->setVoiceVolume(volume));
479 }
480
getRenderPosition(uint32_t * halFrames,uint32_t * dspFrames,audio_io_handle_t output) const481 status_t AudioFlingerClientAdapter::getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames,
482 audio_io_handle_t output) const {
483 int32_t outputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(output));
484 media::RenderPosition aidlRet;
485 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
486 mDelegate->getRenderPosition(outputAidl, &aidlRet)));
487 if (halFrames != nullptr) {
488 *halFrames = VALUE_OR_RETURN_STATUS(convertIntegral<uint32_t>(aidlRet.halFrames));
489 }
490 if (dspFrames != nullptr) {
491 *dspFrames = VALUE_OR_RETURN_STATUS(convertIntegral<uint32_t>(aidlRet.dspFrames));
492 }
493 return OK;
494 }
495
getInputFramesLost(audio_io_handle_t ioHandle) const496 uint32_t AudioFlingerClientAdapter::getInputFramesLost(audio_io_handle_t ioHandle) const {
497 auto result = [&]() -> ConversionResult<uint32_t> {
498 int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle));
499 int32_t aidlRet;
500 RETURN_IF_ERROR(statusTFromBinderStatus(
501 mDelegate->getInputFramesLost(ioHandleAidl, &aidlRet)));
502 return convertIntegral<uint32_t>(aidlRet);
503 }();
504 // Failure is ignored.
505 return result.value_or(0);
506 }
507
newAudioUniqueId(audio_unique_id_use_t use)508 audio_unique_id_t AudioFlingerClientAdapter::newAudioUniqueId(audio_unique_id_use_t use) {
509 auto result = [&]() -> ConversionResult<audio_unique_id_t> {
510 media::AudioUniqueIdUse useAidl = VALUE_OR_RETURN(
511 legacy2aidl_audio_unique_id_use_t_AudioUniqueIdUse(use));
512 int32_t aidlRet;
513 RETURN_IF_ERROR(statusTFromBinderStatus(
514 mDelegate->newAudioUniqueId(useAidl, &aidlRet)));
515 return aidl2legacy_int32_t_audio_unique_id_t(aidlRet);
516 }();
517 return result.value_or(AUDIO_UNIQUE_ID_ALLOCATE);
518 }
519
acquireAudioSessionId(audio_session_t audioSession,pid_t pid,uid_t uid)520 void AudioFlingerClientAdapter::acquireAudioSessionId(audio_session_t audioSession, pid_t pid,
521 uid_t uid) {
522 [&]() -> status_t {
523 int32_t audioSessionAidl = VALUE_OR_RETURN_STATUS(
524 legacy2aidl_audio_session_t_int32_t(audioSession));
525 int32_t pidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_pid_t_int32_t(pid));
526 int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_pid_t_int32_t(uid));
527 return statusTFromBinderStatus(
528 mDelegate->acquireAudioSessionId(audioSessionAidl, pidAidl, uidAidl));
529 }();
530 // Failure is ignored.
531 }
532
releaseAudioSessionId(audio_session_t audioSession,pid_t pid)533 void AudioFlingerClientAdapter::releaseAudioSessionId(audio_session_t audioSession, pid_t pid) {
534 [&]() -> status_t {
535 int32_t audioSessionAidl = VALUE_OR_RETURN_STATUS(
536 legacy2aidl_audio_session_t_int32_t(audioSession));
537 int32_t pidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_pid_t_int32_t(pid));
538 return statusTFromBinderStatus(
539 mDelegate->releaseAudioSessionId(audioSessionAidl, pidAidl));
540 }();
541 // Failure is ignored.
542 }
543
queryNumberEffects(uint32_t * numEffects) const544 status_t AudioFlingerClientAdapter::queryNumberEffects(uint32_t* numEffects) const {
545 int32_t aidlRet;
546 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
547 mDelegate->queryNumberEffects(&aidlRet)));
548 if (numEffects != nullptr) {
549 *numEffects = VALUE_OR_RETURN_STATUS(convertIntegral<uint32_t>(aidlRet));
550 }
551 return OK;
552 }
553
554 status_t
queryEffect(uint32_t index,effect_descriptor_t * pDescriptor) const555 AudioFlingerClientAdapter::queryEffect(uint32_t index, effect_descriptor_t* pDescriptor) const {
556 int32_t indexAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(index));
557 media::EffectDescriptor aidlRet;
558 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
559 mDelegate->queryEffect(indexAidl, &aidlRet)));
560 if (pDescriptor != nullptr) {
561 *pDescriptor = VALUE_OR_RETURN_STATUS(
562 aidl2legacy_EffectDescriptor_effect_descriptor_t(aidlRet));
563 }
564 return OK;
565 }
566
getEffectDescriptor(const effect_uuid_t * pEffectUUID,const effect_uuid_t * pTypeUUID,uint32_t preferredTypeFlag,effect_descriptor_t * pDescriptor) const567 status_t AudioFlingerClientAdapter::getEffectDescriptor(const effect_uuid_t* pEffectUUID,
568 const effect_uuid_t* pTypeUUID,
569 uint32_t preferredTypeFlag,
570 effect_descriptor_t* pDescriptor) const {
571 media::AudioUuid effectUuidAidl = VALUE_OR_RETURN_STATUS(
572 legacy2aidl_audio_uuid_t_AudioUuid(*pEffectUUID));
573 media::AudioUuid typeUuidAidl = VALUE_OR_RETURN_STATUS(
574 legacy2aidl_audio_uuid_t_AudioUuid(*pTypeUUID));
575 int32_t preferredTypeFlagAidl = VALUE_OR_RETURN_STATUS(
576 convertReinterpret<int32_t>(preferredTypeFlag));
577 media::EffectDescriptor aidlRet;
578 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
579 mDelegate->getEffectDescriptor(effectUuidAidl, typeUuidAidl, preferredTypeFlagAidl,
580 &aidlRet)));
581 if (pDescriptor != nullptr) {
582 *pDescriptor = VALUE_OR_RETURN_STATUS(
583 aidl2legacy_EffectDescriptor_effect_descriptor_t(aidlRet));
584 }
585 return OK;
586 }
587
createEffect(const media::CreateEffectRequest & request,media::CreateEffectResponse * response)588 status_t AudioFlingerClientAdapter::createEffect(const media::CreateEffectRequest& request,
589 media::CreateEffectResponse* response) {
590 return statusTFromBinderStatus(mDelegate->createEffect(request, response));
591 }
592
593 status_t
moveEffects(audio_session_t session,audio_io_handle_t srcOutput,audio_io_handle_t dstOutput)594 AudioFlingerClientAdapter::moveEffects(audio_session_t session, audio_io_handle_t srcOutput,
595 audio_io_handle_t dstOutput) {
596 int32_t sessionAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(session));
597 int32_t srcOutputAidl = VALUE_OR_RETURN_STATUS(
598 legacy2aidl_audio_io_handle_t_int32_t(srcOutput));
599 int32_t dstOutputAidl = VALUE_OR_RETURN_STATUS(
600 legacy2aidl_audio_io_handle_t_int32_t(dstOutput));
601 return statusTFromBinderStatus(
602 mDelegate->moveEffects(sessionAidl, srcOutputAidl, dstOutputAidl));
603 }
604
setEffectSuspended(int effectId,audio_session_t sessionId,bool suspended)605 void AudioFlingerClientAdapter::setEffectSuspended(int effectId,
606 audio_session_t sessionId,
607 bool suspended) {
608 [&]() -> status_t {
609 int32_t effectIdAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(effectId));
610 int32_t sessionIdAidl = VALUE_OR_RETURN_STATUS(
611 legacy2aidl_audio_session_t_int32_t(sessionId));
612 return statusTFromBinderStatus(
613 mDelegate->setEffectSuspended(effectIdAidl, sessionIdAidl, suspended));
614 }();
615 // Failure is ignored.
616 }
617
loadHwModule(const char * name)618 audio_module_handle_t AudioFlingerClientAdapter::loadHwModule(const char* name) {
619 auto result = [&]() -> ConversionResult<audio_module_handle_t> {
620 std::string nameAidl(name);
621 int32_t aidlRet;
622 RETURN_IF_ERROR(statusTFromBinderStatus(
623 mDelegate->loadHwModule(nameAidl, &aidlRet)));
624 return aidl2legacy_int32_t_audio_module_handle_t(aidlRet);
625 }();
626 // Failure is ignored.
627 return result.value_or(0);
628 }
629
getPrimaryOutputSamplingRate()630 uint32_t AudioFlingerClientAdapter::getPrimaryOutputSamplingRate() {
631 auto result = [&]() -> ConversionResult<uint32_t> {
632 int32_t aidlRet;
633 RETURN_IF_ERROR(statusTFromBinderStatus(
634 mDelegate->getPrimaryOutputSamplingRate(&aidlRet)));
635 return convertIntegral<uint32_t>(aidlRet);
636 }();
637 // Failure is ignored.
638 return result.value_or(0);
639 }
640
getPrimaryOutputFrameCount()641 size_t AudioFlingerClientAdapter::getPrimaryOutputFrameCount() {
642 auto result = [&]() -> ConversionResult<size_t> {
643 int64_t aidlRet;
644 RETURN_IF_ERROR(statusTFromBinderStatus(
645 mDelegate->getPrimaryOutputFrameCount(&aidlRet)));
646 return convertIntegral<size_t>(aidlRet);
647 }();
648 // Failure is ignored.
649 return result.value_or(0);
650 }
651
setLowRamDevice(bool isLowRamDevice,int64_t totalMemory)652 status_t AudioFlingerClientAdapter::setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) {
653 return statusTFromBinderStatus(mDelegate->setLowRamDevice(isLowRamDevice, totalMemory));
654 }
655
getAudioPort(struct audio_port_v7 * port)656 status_t AudioFlingerClientAdapter::getAudioPort(struct audio_port_v7* port) {
657 media::AudioPort portAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_v7_AudioPort(*port));
658 media::AudioPort aidlRet;
659 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
660 mDelegate->getAudioPort(portAidl, &aidlRet)));
661 *port = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioPort_audio_port_v7(aidlRet));
662 return OK;
663 }
664
createAudioPatch(const struct audio_patch * patch,audio_patch_handle_t * handle)665 status_t AudioFlingerClientAdapter::createAudioPatch(const struct audio_patch* patch,
666 audio_patch_handle_t* handle) {
667 media::AudioPatch patchAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_AudioPatch(*patch));
668 int32_t aidlRet = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(
669 AUDIO_PATCH_HANDLE_NONE));
670 if (handle != nullptr) {
671 aidlRet = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(*handle));
672 }
673 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
674 mDelegate->createAudioPatch(patchAidl, &aidlRet)));
675 if (handle != nullptr) {
676 *handle = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_patch_handle_t(aidlRet));
677 }
678 return OK;
679 }
680
releaseAudioPatch(audio_patch_handle_t handle)681 status_t AudioFlingerClientAdapter::releaseAudioPatch(audio_patch_handle_t handle) {
682 int32_t handleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(handle));
683 return statusTFromBinderStatus(mDelegate->releaseAudioPatch(handleAidl));
684 }
685
listAudioPatches(unsigned int * num_patches,struct audio_patch * patches)686 status_t AudioFlingerClientAdapter::listAudioPatches(unsigned int* num_patches,
687 struct audio_patch* patches) {
688 std::vector<media::AudioPatch> aidlRet;
689 int32_t maxPatches = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(*num_patches));
690 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
691 mDelegate->listAudioPatches(maxPatches, &aidlRet)));
692 *num_patches = VALUE_OR_RETURN_STATUS(convertIntegral<unsigned int>(aidlRet.size()));
693 return convertRange(aidlRet.begin(), aidlRet.end(), patches,
694 aidl2legacy_AudioPatch_audio_patch);
695 }
696
setAudioPortConfig(const struct audio_port_config * config)697 status_t AudioFlingerClientAdapter::setAudioPortConfig(const struct audio_port_config* config) {
698 media::AudioPortConfig configAidl = VALUE_OR_RETURN_STATUS(
699 legacy2aidl_audio_port_config_AudioPortConfig(*config));
700 return statusTFromBinderStatus(mDelegate->setAudioPortConfig(configAidl));
701 }
702
getAudioHwSyncForSession(audio_session_t sessionId)703 audio_hw_sync_t AudioFlingerClientAdapter::getAudioHwSyncForSession(audio_session_t sessionId) {
704 auto result = [&]() -> ConversionResult<audio_hw_sync_t> {
705 int32_t sessionIdAidl = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(sessionId));
706 int32_t aidlRet;
707 RETURN_IF_ERROR(statusTFromBinderStatus(
708 mDelegate->getAudioHwSyncForSession(sessionIdAidl, &aidlRet)));
709 return aidl2legacy_int32_t_audio_hw_sync_t(aidlRet);
710 }();
711 return result.value_or(AUDIO_HW_SYNC_INVALID);
712 }
713
systemReady()714 status_t AudioFlingerClientAdapter::systemReady() {
715 return statusTFromBinderStatus(mDelegate->systemReady());
716 }
717
frameCountHAL(audio_io_handle_t ioHandle) const718 size_t AudioFlingerClientAdapter::frameCountHAL(audio_io_handle_t ioHandle) const {
719 auto result = [&]() -> ConversionResult<size_t> {
720 int32_t ioHandleAidl = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(ioHandle));
721 int64_t aidlRet;
722 RETURN_IF_ERROR(statusTFromBinderStatus(
723 mDelegate->frameCountHAL(ioHandleAidl, &aidlRet)));
724 return convertIntegral<size_t>(aidlRet);
725 }();
726 // Failure is ignored.
727 return result.value_or(0);
728 }
729
730 status_t
getMicrophones(std::vector<media::MicrophoneInfo> * microphones)731 AudioFlingerClientAdapter::getMicrophones(std::vector<media::MicrophoneInfo>* microphones) {
732 std::vector<media::MicrophoneInfoData> aidlRet;
733 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
734 mDelegate->getMicrophones(&aidlRet)));
735 if (microphones != nullptr) {
736 *microphones = VALUE_OR_RETURN_STATUS(
737 convertContainer<std::vector<media::MicrophoneInfo>>(aidlRet,
738 media::aidl2legacy_MicrophoneInfo));
739 }
740 return OK;
741 }
742
setAudioHalPids(const std::vector<pid_t> & pids)743 status_t AudioFlingerClientAdapter::setAudioHalPids(const std::vector<pid_t>& pids) {
744 std::vector<int32_t> pidsAidl = VALUE_OR_RETURN_STATUS(
745 convertContainer<std::vector<int32_t>>(pids, legacy2aidl_pid_t_int32_t));
746 return statusTFromBinderStatus(mDelegate->setAudioHalPids(pidsAidl));
747 }
748
setVibratorInfos(const std::vector<media::AudioVibratorInfo> & vibratorInfos)749 status_t AudioFlingerClientAdapter::setVibratorInfos(
750 const std::vector<media::AudioVibratorInfo>& vibratorInfos) {
751 return statusTFromBinderStatus(mDelegate->setVibratorInfos(vibratorInfos));
752 }
753
updateSecondaryOutputs(const TrackSecondaryOutputsMap & trackSecondaryOutputs)754 status_t AudioFlingerClientAdapter::updateSecondaryOutputs(
755 const TrackSecondaryOutputsMap& trackSecondaryOutputs) {
756 std::vector<media::TrackSecondaryOutputInfo> trackSecondaryOutputInfos =
757 VALUE_OR_RETURN_STATUS(
758 convertContainer<std::vector<media::TrackSecondaryOutputInfo>>(
759 trackSecondaryOutputs,
760 legacy2aidl_TrackSecondaryOutputInfoPair_TrackSecondaryOutputInfo));
761 return statusTFromBinderStatus(mDelegate->updateSecondaryOutputs(trackSecondaryOutputInfos));
762 }
763
764
765 ////////////////////////////////////////////////////////////////////////////////////////////////////
766 // AudioFlingerServerAdapter
AudioFlingerServerAdapter(const sp<AudioFlingerServerAdapter::Delegate> & delegate)767 AudioFlingerServerAdapter::AudioFlingerServerAdapter(
768 const sp<AudioFlingerServerAdapter::Delegate>& delegate) : mDelegate(delegate) {}
769
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)770 status_t AudioFlingerServerAdapter::onTransact(uint32_t code,
771 const Parcel& data,
772 Parcel* reply,
773 uint32_t flags) {
774 return mDelegate->onTransactWrapper(static_cast<Delegate::TransactionCode>(code),
775 data,
776 flags,
777 [&] {
778 return BnAudioFlingerService::onTransact(
779 code,
780 data,
781 reply,
782 flags);
783 });
784 }
785
dump(int fd,const Vector<String16> & args)786 status_t AudioFlingerServerAdapter::dump(int fd, const Vector<String16>& args) {
787 return mDelegate->dump(fd, args);
788 }
789
createTrack(const media::CreateTrackRequest & request,media::CreateTrackResponse * _aidl_return)790 Status AudioFlingerServerAdapter::createTrack(const media::CreateTrackRequest& request,
791 media::CreateTrackResponse* _aidl_return) {
792 return Status::fromStatusT(mDelegate->createTrack(request, *_aidl_return));
793 }
794
createRecord(const media::CreateRecordRequest & request,media::CreateRecordResponse * _aidl_return)795 Status AudioFlingerServerAdapter::createRecord(const media::CreateRecordRequest& request,
796 media::CreateRecordResponse* _aidl_return) {
797 return Status::fromStatusT(mDelegate->createRecord(request, *_aidl_return));
798 }
799
sampleRate(int32_t ioHandle,int32_t * _aidl_return)800 Status AudioFlingerServerAdapter::sampleRate(int32_t ioHandle, int32_t* _aidl_return) {
801 audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER(
802 aidl2legacy_int32_t_audio_io_handle_t(ioHandle));
803 *_aidl_return = VALUE_OR_RETURN_BINDER(
804 convertIntegral<int32_t>(mDelegate->sampleRate(ioHandleLegacy)));
805 return Status::ok();
806 }
807
format(int32_t output,media::audio::common::AudioFormat * _aidl_return)808 Status AudioFlingerServerAdapter::format(int32_t output,
809 media::audio::common::AudioFormat* _aidl_return) {
810 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
811 aidl2legacy_int32_t_audio_io_handle_t(output));
812 *_aidl_return = VALUE_OR_RETURN_BINDER(
813 legacy2aidl_audio_format_t_AudioFormat(mDelegate->format(outputLegacy)));
814 return Status::ok();
815 }
816
frameCount(int32_t ioHandle,int64_t * _aidl_return)817 Status AudioFlingerServerAdapter::frameCount(int32_t ioHandle, int64_t* _aidl_return) {
818 audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER(
819 aidl2legacy_int32_t_audio_io_handle_t(ioHandle));
820 *_aidl_return = VALUE_OR_RETURN_BINDER(
821 convertIntegral<int64_t>(mDelegate->frameCount(ioHandleLegacy)));
822 return Status::ok();
823 }
824
latency(int32_t output,int32_t * _aidl_return)825 Status AudioFlingerServerAdapter::latency(int32_t output, int32_t* _aidl_return) {
826 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
827 aidl2legacy_int32_t_audio_io_handle_t(output));
828 *_aidl_return = VALUE_OR_RETURN_BINDER(
829 convertIntegral<int32_t>(mDelegate->latency(outputLegacy)));
830 return Status::ok();
831 }
832
setMasterVolume(float value)833 Status AudioFlingerServerAdapter::setMasterVolume(float value) {
834 return Status::fromStatusT(mDelegate->setMasterVolume(value));
835 }
836
setMasterMute(bool muted)837 Status AudioFlingerServerAdapter::setMasterMute(bool muted) {
838 return Status::fromStatusT(mDelegate->setMasterMute(muted));
839 }
840
masterVolume(float * _aidl_return)841 Status AudioFlingerServerAdapter::masterVolume(float* _aidl_return) {
842 *_aidl_return = mDelegate->masterVolume();
843 return Status::ok();
844 }
845
masterMute(bool * _aidl_return)846 Status AudioFlingerServerAdapter::masterMute(bool* _aidl_return) {
847 *_aidl_return = mDelegate->masterMute();
848 return Status::ok();
849 }
850
setMasterBalance(float balance)851 Status AudioFlingerServerAdapter::setMasterBalance(float balance) {
852 return Status::fromStatusT(mDelegate->setMasterBalance(balance));
853 }
854
getMasterBalance(float * _aidl_return)855 Status AudioFlingerServerAdapter::getMasterBalance(float* _aidl_return) {
856 return Status::fromStatusT(mDelegate->getMasterBalance(_aidl_return));
857 }
858
setStreamVolume(media::AudioStreamType stream,float value,int32_t output)859 Status AudioFlingerServerAdapter::setStreamVolume(media::AudioStreamType stream, float value,
860 int32_t output) {
861 audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER(
862 aidl2legacy_AudioStreamType_audio_stream_type_t(stream));
863 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
864 aidl2legacy_int32_t_audio_io_handle_t(output));
865 return Status::fromStatusT(mDelegate->setStreamVolume(streamLegacy, value, outputLegacy));
866 }
867
setStreamMute(media::AudioStreamType stream,bool muted)868 Status AudioFlingerServerAdapter::setStreamMute(media::AudioStreamType stream, bool muted) {
869 audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER(
870 aidl2legacy_AudioStreamType_audio_stream_type_t(stream));
871 return Status::fromStatusT(mDelegate->setStreamMute(streamLegacy, muted));
872 }
873
streamVolume(media::AudioStreamType stream,int32_t output,float * _aidl_return)874 Status AudioFlingerServerAdapter::streamVolume(media::AudioStreamType stream, int32_t output,
875 float* _aidl_return) {
876 audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER(
877 aidl2legacy_AudioStreamType_audio_stream_type_t(stream));
878 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
879 aidl2legacy_int32_t_audio_io_handle_t(output));
880 *_aidl_return = mDelegate->streamVolume(streamLegacy, outputLegacy);
881 return Status::ok();
882 }
883
streamMute(media::AudioStreamType stream,bool * _aidl_return)884 Status AudioFlingerServerAdapter::streamMute(media::AudioStreamType stream, bool* _aidl_return) {
885 audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER(
886 aidl2legacy_AudioStreamType_audio_stream_type_t(stream));
887 *_aidl_return = mDelegate->streamMute(streamLegacy);
888 return Status::ok();
889 }
890
setMode(media::AudioMode mode)891 Status AudioFlingerServerAdapter::setMode(media::AudioMode mode) {
892 audio_mode_t modeLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioMode_audio_mode_t(mode));
893 return Status::fromStatusT(mDelegate->setMode(modeLegacy));
894 }
895
setMicMute(bool state)896 Status AudioFlingerServerAdapter::setMicMute(bool state) {
897 return Status::fromStatusT(mDelegate->setMicMute(state));
898 }
899
getMicMute(bool * _aidl_return)900 Status AudioFlingerServerAdapter::getMicMute(bool* _aidl_return) {
901 *_aidl_return = mDelegate->getMicMute();
902 return Status::ok();
903 }
904
setRecordSilenced(int32_t portId,bool silenced)905 Status AudioFlingerServerAdapter::setRecordSilenced(int32_t portId, bool silenced) {
906 audio_port_handle_t portIdLegacy = VALUE_OR_RETURN_BINDER(
907 aidl2legacy_int32_t_audio_port_handle_t(portId));
908 mDelegate->setRecordSilenced(portIdLegacy, silenced);
909 return Status::ok();
910 }
911
912 Status
setParameters(int32_t ioHandle,const std::string & keyValuePairs)913 AudioFlingerServerAdapter::setParameters(int32_t ioHandle, const std::string& keyValuePairs) {
914 audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER(
915 aidl2legacy_int32_t_audio_io_handle_t(ioHandle));
916 String8 keyValuePairsLegacy = VALUE_OR_RETURN_BINDER(
917 aidl2legacy_string_view_String8(keyValuePairs));
918 return Status::fromStatusT(mDelegate->setParameters(ioHandleLegacy, keyValuePairsLegacy));
919 }
920
getParameters(int32_t ioHandle,const std::string & keys,std::string * _aidl_return)921 Status AudioFlingerServerAdapter::getParameters(int32_t ioHandle, const std::string& keys,
922 std::string* _aidl_return) {
923 audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER(
924 aidl2legacy_int32_t_audio_io_handle_t(ioHandle));
925 String8 keysLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_string_view_String8(keys));
926 *_aidl_return = VALUE_OR_RETURN_BINDER(
927 legacy2aidl_String8_string(mDelegate->getParameters(ioHandleLegacy, keysLegacy)));
928 return Status::ok();
929 }
930
registerClient(const sp<media::IAudioFlingerClient> & client)931 Status AudioFlingerServerAdapter::registerClient(const sp<media::IAudioFlingerClient>& client) {
932 mDelegate->registerClient(client);
933 return Status::ok();
934 }
935
getInputBufferSize(int32_t sampleRate,media::audio::common::AudioFormat format,int32_t channelMask,int64_t * _aidl_return)936 Status AudioFlingerServerAdapter::getInputBufferSize(int32_t sampleRate,
937 media::audio::common::AudioFormat format,
938 int32_t channelMask, int64_t* _aidl_return) {
939 uint32_t sampleRateLegacy = VALUE_OR_RETURN_BINDER(convertIntegral<uint32_t>(sampleRate));
940 audio_format_t formatLegacy = VALUE_OR_RETURN_BINDER(
941 aidl2legacy_AudioFormat_audio_format_t(format));
942 audio_channel_mask_t channelMaskLegacy = VALUE_OR_RETURN_BINDER(
943 aidl2legacy_int32_t_audio_channel_mask_t(channelMask));
944 size_t size = mDelegate->getInputBufferSize(sampleRateLegacy, formatLegacy, channelMaskLegacy);
945 *_aidl_return = VALUE_OR_RETURN_BINDER(convertIntegral<int64_t>(size));
946 return Status::ok();
947 }
948
openOutput(const media::OpenOutputRequest & request,media::OpenOutputResponse * _aidl_return)949 Status AudioFlingerServerAdapter::openOutput(const media::OpenOutputRequest& request,
950 media::OpenOutputResponse* _aidl_return) {
951 return Status::fromStatusT(mDelegate->openOutput(request, _aidl_return));
952 }
953
openDuplicateOutput(int32_t output1,int32_t output2,int32_t * _aidl_return)954 Status AudioFlingerServerAdapter::openDuplicateOutput(int32_t output1, int32_t output2,
955 int32_t* _aidl_return) {
956 audio_io_handle_t output1Legacy = VALUE_OR_RETURN_BINDER(
957 aidl2legacy_int32_t_audio_io_handle_t(output1));
958 audio_io_handle_t output2Legacy = VALUE_OR_RETURN_BINDER(
959 aidl2legacy_int32_t_audio_io_handle_t(output2));
960 audio_io_handle_t result = mDelegate->openDuplicateOutput(output1Legacy, output2Legacy);
961 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_io_handle_t_int32_t(result));
962 return Status::ok();
963 }
964
closeOutput(int32_t output)965 Status AudioFlingerServerAdapter::closeOutput(int32_t output) {
966 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
967 aidl2legacy_int32_t_audio_io_handle_t(output));
968 return Status::fromStatusT(mDelegate->closeOutput(outputLegacy));
969 }
970
suspendOutput(int32_t output)971 Status AudioFlingerServerAdapter::suspendOutput(int32_t output) {
972 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
973 aidl2legacy_int32_t_audio_io_handle_t(output));
974 return Status::fromStatusT(mDelegate->suspendOutput(outputLegacy));
975 }
976
restoreOutput(int32_t output)977 Status AudioFlingerServerAdapter::restoreOutput(int32_t output) {
978 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
979 aidl2legacy_int32_t_audio_io_handle_t(output));
980 return Status::fromStatusT(mDelegate->restoreOutput(outputLegacy));
981 }
982
openInput(const media::OpenInputRequest & request,media::OpenInputResponse * _aidl_return)983 Status AudioFlingerServerAdapter::openInput(const media::OpenInputRequest& request,
984 media::OpenInputResponse* _aidl_return) {
985 return Status::fromStatusT(mDelegate->openInput(request, _aidl_return));
986 }
987
closeInput(int32_t input)988 Status AudioFlingerServerAdapter::closeInput(int32_t input) {
989 audio_io_handle_t inputLegacy = VALUE_OR_RETURN_BINDER(
990 aidl2legacy_int32_t_audio_io_handle_t(input));
991 return Status::fromStatusT(mDelegate->closeInput(inputLegacy));
992 }
993
invalidateStream(media::AudioStreamType stream)994 Status AudioFlingerServerAdapter::invalidateStream(media::AudioStreamType stream) {
995 audio_stream_type_t streamLegacy = VALUE_OR_RETURN_BINDER(
996 aidl2legacy_AudioStreamType_audio_stream_type_t(stream));
997 return Status::fromStatusT(mDelegate->invalidateStream(streamLegacy));
998 }
999
setVoiceVolume(float volume)1000 Status AudioFlingerServerAdapter::setVoiceVolume(float volume) {
1001 return Status::fromStatusT(mDelegate->setVoiceVolume(volume));
1002 }
1003
1004 Status
getRenderPosition(int32_t output,media::RenderPosition * _aidl_return)1005 AudioFlingerServerAdapter::getRenderPosition(int32_t output, media::RenderPosition* _aidl_return) {
1006 audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER(
1007 aidl2legacy_int32_t_audio_io_handle_t(output));
1008 uint32_t halFramesLegacy;
1009 uint32_t dspFramesLegacy;
1010 RETURN_BINDER_IF_ERROR(
1011 mDelegate->getRenderPosition(&halFramesLegacy, &dspFramesLegacy, outputLegacy));
1012 _aidl_return->halFrames = VALUE_OR_RETURN_BINDER(convertIntegral<int32_t>(halFramesLegacy));
1013 _aidl_return->dspFrames = VALUE_OR_RETURN_BINDER(convertIntegral<int32_t>(dspFramesLegacy));
1014 return Status::ok();
1015 }
1016
getInputFramesLost(int32_t ioHandle,int32_t * _aidl_return)1017 Status AudioFlingerServerAdapter::getInputFramesLost(int32_t ioHandle, int32_t* _aidl_return) {
1018 audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER(
1019 aidl2legacy_int32_t_audio_io_handle_t(ioHandle));
1020 uint32_t result = mDelegate->getInputFramesLost(ioHandleLegacy);
1021 *_aidl_return = VALUE_OR_RETURN_BINDER(convertIntegral<int32_t>(result));
1022 return Status::ok();
1023 }
1024
1025 Status
newAudioUniqueId(media::AudioUniqueIdUse use,int32_t * _aidl_return)1026 AudioFlingerServerAdapter::newAudioUniqueId(media::AudioUniqueIdUse use, int32_t* _aidl_return) {
1027 audio_unique_id_use_t useLegacy = VALUE_OR_RETURN_BINDER(
1028 aidl2legacy_AudioUniqueIdUse_audio_unique_id_use_t(use));
1029 audio_unique_id_t result = mDelegate->newAudioUniqueId(useLegacy);
1030 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_unique_id_t_int32_t(result));
1031 return Status::ok();
1032 }
1033
1034 Status
acquireAudioSessionId(int32_t audioSession,int32_t pid,int32_t uid)1035 AudioFlingerServerAdapter::acquireAudioSessionId(int32_t audioSession, int32_t pid, int32_t uid) {
1036 audio_session_t audioSessionLegacy = VALUE_OR_RETURN_BINDER(
1037 aidl2legacy_int32_t_audio_session_t(audioSession));
1038 pid_t pidLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_int32_t_pid_t(pid));
1039 uid_t uidLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_int32_t_uid_t(uid));
1040 mDelegate->acquireAudioSessionId(audioSessionLegacy, pidLegacy, uidLegacy);
1041 return Status::ok();
1042 }
1043
releaseAudioSessionId(int32_t audioSession,int32_t pid)1044 Status AudioFlingerServerAdapter::releaseAudioSessionId(int32_t audioSession, int32_t pid) {
1045 audio_session_t audioSessionLegacy = VALUE_OR_RETURN_BINDER(
1046 aidl2legacy_int32_t_audio_session_t(audioSession));
1047 pid_t pidLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_int32_t_pid_t(pid));
1048 mDelegate->releaseAudioSessionId(audioSessionLegacy, pidLegacy);
1049 return Status::ok();
1050 }
1051
queryNumberEffects(int32_t * _aidl_return)1052 Status AudioFlingerServerAdapter::queryNumberEffects(int32_t* _aidl_return) {
1053 uint32_t result;
1054 RETURN_BINDER_IF_ERROR(mDelegate->queryNumberEffects(&result));
1055 *_aidl_return = VALUE_OR_RETURN_BINDER(convertIntegral<uint32_t>(result));
1056 return Status::ok();
1057 }
1058
1059 Status
queryEffect(int32_t index,media::EffectDescriptor * _aidl_return)1060 AudioFlingerServerAdapter::queryEffect(int32_t index, media::EffectDescriptor* _aidl_return) {
1061 uint32_t indexLegacy = VALUE_OR_RETURN_BINDER(convertIntegral<uint32_t>(index));
1062 effect_descriptor_t result;
1063 RETURN_BINDER_IF_ERROR(mDelegate->queryEffect(indexLegacy, &result));
1064 *_aidl_return = VALUE_OR_RETURN_BINDER(
1065 legacy2aidl_effect_descriptor_t_EffectDescriptor(result));
1066 return Status::ok();
1067 }
1068
getEffectDescriptor(const media::AudioUuid & effectUUID,const media::AudioUuid & typeUUID,int32_t preferredTypeFlag,media::EffectDescriptor * _aidl_return)1069 Status AudioFlingerServerAdapter::getEffectDescriptor(const media::AudioUuid& effectUUID,
1070 const media::AudioUuid& typeUUID,
1071 int32_t preferredTypeFlag,
1072 media::EffectDescriptor* _aidl_return) {
1073 effect_uuid_t effectUuidLegacy = VALUE_OR_RETURN_BINDER(
1074 aidl2legacy_AudioUuid_audio_uuid_t(effectUUID));
1075 effect_uuid_t typeUuidLegacy = VALUE_OR_RETURN_BINDER(
1076 aidl2legacy_AudioUuid_audio_uuid_t(typeUUID));
1077 uint32_t preferredTypeFlagLegacy = VALUE_OR_RETURN_BINDER(
1078 convertReinterpret<uint32_t>(preferredTypeFlag));
1079 effect_descriptor_t result;
1080 RETURN_BINDER_IF_ERROR(mDelegate->getEffectDescriptor(&effectUuidLegacy, &typeUuidLegacy,
1081 preferredTypeFlagLegacy, &result));
1082 *_aidl_return = VALUE_OR_RETURN_BINDER(
1083 legacy2aidl_effect_descriptor_t_EffectDescriptor(result));
1084 return Status::ok();
1085 }
1086
createEffect(const media::CreateEffectRequest & request,media::CreateEffectResponse * _aidl_return)1087 Status AudioFlingerServerAdapter::createEffect(const media::CreateEffectRequest& request,
1088 media::CreateEffectResponse* _aidl_return) {
1089 return Status::fromStatusT(mDelegate->createEffect(request, _aidl_return));
1090 }
1091
1092 Status
moveEffects(int32_t session,int32_t srcOutput,int32_t dstOutput)1093 AudioFlingerServerAdapter::moveEffects(int32_t session, int32_t srcOutput, int32_t dstOutput) {
1094 audio_session_t sessionLegacy = VALUE_OR_RETURN_BINDER(
1095 aidl2legacy_int32_t_audio_session_t(session));
1096 audio_io_handle_t srcOutputLegacy = VALUE_OR_RETURN_BINDER(
1097 aidl2legacy_int32_t_audio_io_handle_t(srcOutput));
1098 audio_io_handle_t dstOutputLegacy = VALUE_OR_RETURN_BINDER(
1099 aidl2legacy_int32_t_audio_io_handle_t(dstOutput));
1100 return Status::fromStatusT(
1101 mDelegate->moveEffects(sessionLegacy, srcOutputLegacy, dstOutputLegacy));
1102 }
1103
setEffectSuspended(int32_t effectId,int32_t sessionId,bool suspended)1104 Status AudioFlingerServerAdapter::setEffectSuspended(int32_t effectId, int32_t sessionId,
1105 bool suspended) {
1106 int effectIdLegacy = VALUE_OR_RETURN_BINDER(convertReinterpret<int>(effectId));
1107 audio_session_t sessionIdLegacy = VALUE_OR_RETURN_BINDER(
1108 aidl2legacy_int32_t_audio_session_t(sessionId));
1109 mDelegate->setEffectSuspended(effectIdLegacy, sessionIdLegacy, suspended);
1110 return Status::ok();
1111 }
1112
loadHwModule(const std::string & name,int32_t * _aidl_return)1113 Status AudioFlingerServerAdapter::loadHwModule(const std::string& name, int32_t* _aidl_return) {
1114 audio_module_handle_t result = mDelegate->loadHwModule(name.c_str());
1115 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_module_handle_t_int32_t(result));
1116 return Status::ok();
1117 }
1118
getPrimaryOutputSamplingRate(int32_t * _aidl_return)1119 Status AudioFlingerServerAdapter::getPrimaryOutputSamplingRate(int32_t* _aidl_return) {
1120 *_aidl_return = VALUE_OR_RETURN_BINDER(
1121 convertIntegral<int32_t>(mDelegate->getPrimaryOutputSamplingRate()));
1122 return Status::ok();
1123 }
1124
getPrimaryOutputFrameCount(int64_t * _aidl_return)1125 Status AudioFlingerServerAdapter::getPrimaryOutputFrameCount(int64_t* _aidl_return) {
1126 *_aidl_return = VALUE_OR_RETURN_BINDER(
1127 convertIntegral<int64_t>(mDelegate->getPrimaryOutputFrameCount()));
1128 return Status::ok();
1129
1130 }
1131
setLowRamDevice(bool isLowRamDevice,int64_t totalMemory)1132 Status AudioFlingerServerAdapter::setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) {
1133 return Status::fromStatusT(mDelegate->setLowRamDevice(isLowRamDevice, totalMemory));
1134 }
1135
getAudioPort(const media::AudioPort & port,media::AudioPort * _aidl_return)1136 Status AudioFlingerServerAdapter::getAudioPort(const media::AudioPort& port,
1137 media::AudioPort* _aidl_return) {
1138 audio_port_v7 portLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioPort_audio_port_v7(port));
1139 RETURN_BINDER_IF_ERROR(mDelegate->getAudioPort(&portLegacy));
1140 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_port_v7_AudioPort(portLegacy));
1141 return Status::ok();
1142 }
1143
createAudioPatch(const media::AudioPatch & patch,int32_t * _aidl_return)1144 Status AudioFlingerServerAdapter::createAudioPatch(const media::AudioPatch& patch,
1145 int32_t* _aidl_return) {
1146 audio_patch patchLegacy = VALUE_OR_RETURN_BINDER(aidl2legacy_AudioPatch_audio_patch(patch));
1147 audio_patch_handle_t handleLegacy = VALUE_OR_RETURN_BINDER(
1148 aidl2legacy_int32_t_audio_patch_handle_t(*_aidl_return));
1149 RETURN_BINDER_IF_ERROR(mDelegate->createAudioPatch(&patchLegacy, &handleLegacy));
1150 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_patch_handle_t_int32_t(handleLegacy));
1151 return Status::ok();
1152 }
1153
releaseAudioPatch(int32_t handle)1154 Status AudioFlingerServerAdapter::releaseAudioPatch(int32_t handle) {
1155 audio_patch_handle_t handleLegacy = VALUE_OR_RETURN_BINDER(
1156 aidl2legacy_int32_t_audio_patch_handle_t(handle));
1157 return Status::fromStatusT(mDelegate->releaseAudioPatch(handleLegacy));
1158 }
1159
listAudioPatches(int32_t maxCount,std::vector<media::AudioPatch> * _aidl_return)1160 Status AudioFlingerServerAdapter::listAudioPatches(int32_t maxCount,
1161 std::vector<media::AudioPatch>* _aidl_return) {
1162 unsigned int count = VALUE_OR_RETURN_BINDER(convertIntegral<unsigned int>(maxCount));
1163 count = std::min(count, static_cast<unsigned int>(MAX_ITEMS_PER_LIST));
1164 std::unique_ptr<audio_patch[]> patchesLegacy(new audio_patch[count]);
1165 RETURN_BINDER_IF_ERROR(mDelegate->listAudioPatches(&count, patchesLegacy.get()));
1166 RETURN_BINDER_IF_ERROR(convertRange(&patchesLegacy[0],
1167 &patchesLegacy[count],
1168 std::back_inserter(*_aidl_return),
1169 legacy2aidl_audio_patch_AudioPatch));
1170 return Status::ok();
1171 }
1172
setAudioPortConfig(const media::AudioPortConfig & config)1173 Status AudioFlingerServerAdapter::setAudioPortConfig(const media::AudioPortConfig& config) {
1174 audio_port_config configLegacy = VALUE_OR_RETURN_BINDER(
1175 aidl2legacy_AudioPortConfig_audio_port_config(config));
1176 return Status::fromStatusT(mDelegate->setAudioPortConfig(&configLegacy));
1177 }
1178
getAudioHwSyncForSession(int32_t sessionId,int32_t * _aidl_return)1179 Status AudioFlingerServerAdapter::getAudioHwSyncForSession(int32_t sessionId,
1180 int32_t* _aidl_return) {
1181 audio_session_t sessionIdLegacy = VALUE_OR_RETURN_BINDER(
1182 aidl2legacy_int32_t_audio_session_t(sessionId));
1183 audio_hw_sync_t result = mDelegate->getAudioHwSyncForSession(sessionIdLegacy);
1184 *_aidl_return = VALUE_OR_RETURN_BINDER(legacy2aidl_audio_hw_sync_t_int32_t(result));
1185 return Status::ok();
1186 }
1187
systemReady()1188 Status AudioFlingerServerAdapter::systemReady() {
1189 return Status::fromStatusT(mDelegate->systemReady());
1190 }
1191
frameCountHAL(int32_t ioHandle,int64_t * _aidl_return)1192 Status AudioFlingerServerAdapter::frameCountHAL(int32_t ioHandle, int64_t* _aidl_return) {
1193 audio_io_handle_t ioHandleLegacy = VALUE_OR_RETURN_BINDER(
1194 aidl2legacy_int32_t_audio_io_handle_t(ioHandle));
1195 size_t result = mDelegate->frameCountHAL(ioHandleLegacy);
1196 *_aidl_return = VALUE_OR_RETURN_BINDER(convertIntegral<int64_t>(result));
1197 return Status::ok();
1198 }
1199
getMicrophones(std::vector<media::MicrophoneInfoData> * _aidl_return)1200 Status AudioFlingerServerAdapter::getMicrophones(
1201 std::vector<media::MicrophoneInfoData>* _aidl_return) {
1202 std::vector<media::MicrophoneInfo> resultLegacy;
1203 RETURN_BINDER_IF_ERROR(mDelegate->getMicrophones(&resultLegacy));
1204 *_aidl_return = VALUE_OR_RETURN_BINDER(convertContainer<std::vector<media::MicrophoneInfoData>>(
1205 resultLegacy, media::legacy2aidl_MicrophoneInfo));
1206 return Status::ok();
1207 }
1208
setAudioHalPids(const std::vector<int32_t> & pids)1209 Status AudioFlingerServerAdapter::setAudioHalPids(const std::vector<int32_t>& pids) {
1210 std::vector<pid_t> pidsLegacy = VALUE_OR_RETURN_BINDER(
1211 convertContainer<std::vector<pid_t>>(pids, aidl2legacy_int32_t_pid_t));
1212 RETURN_BINDER_IF_ERROR(mDelegate->setAudioHalPids(pidsLegacy));
1213 return Status::ok();
1214 }
1215
setVibratorInfos(const std::vector<media::AudioVibratorInfo> & vibratorInfos)1216 Status AudioFlingerServerAdapter::setVibratorInfos(
1217 const std::vector<media::AudioVibratorInfo>& vibratorInfos) {
1218 return Status::fromStatusT(mDelegate->setVibratorInfos(vibratorInfos));
1219 }
1220
updateSecondaryOutputs(const std::vector<media::TrackSecondaryOutputInfo> & trackSecondaryOutputInfos)1221 Status AudioFlingerServerAdapter::updateSecondaryOutputs(
1222 const std::vector<media::TrackSecondaryOutputInfo>& trackSecondaryOutputInfos) {
1223 TrackSecondaryOutputsMap trackSecondaryOutputs =
1224 VALUE_OR_RETURN_BINDER(convertContainer<TrackSecondaryOutputsMap>(
1225 trackSecondaryOutputInfos,
1226 aidl2legacy_TrackSecondaryOutputInfo_TrackSecondaryOutputInfoPair));
1227 return Status::fromStatusT(mDelegate->updateSecondaryOutputs(trackSecondaryOutputs));
1228 }
1229
1230 } // namespace android
1231