1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "PolicyAidlConversion"
18 //#define LOG_NDEBUG 0
19 #include <utils/Log.h>
20
21 #include "media/PolicyAidlConversion.h"
22
23 #include "media/AidlConversion.h"
24
25 namespace android {
26
27 using base::unexpected;
28 using media::audio::common::AudioDeviceAddress;
29
30 ConversionResult<uint32_t>
aidl2legacy_AudioMixType_uint32_t(media::AudioMixType aidl)31 aidl2legacy_AudioMixType_uint32_t(media::AudioMixType aidl) {
32 switch (aidl) {
33 case media::AudioMixType::PLAYERS:
34 return MIX_TYPE_PLAYERS;
35 case media::AudioMixType::RECORDERS:
36 return MIX_TYPE_RECORDERS;
37 }
38 return unexpected(BAD_VALUE);
39 }
40
41 ConversionResult<media::AudioMixType>
legacy2aidl_uint32_t_AudioMixType(uint32_t legacy)42 legacy2aidl_uint32_t_AudioMixType(uint32_t legacy) {
43 switch (legacy) {
44 case MIX_TYPE_PLAYERS:
45 return media::AudioMixType::PLAYERS;
46 case MIX_TYPE_RECORDERS:
47 return media::AudioMixType::RECORDERS;
48 }
49 return unexpected(BAD_VALUE);
50 }
51
52 ConversionResult<uint32_t>
aidl2legacy_AudioMixCallbackFlag_uint32_t(media::AudioMixCallbackFlag aidl)53 aidl2legacy_AudioMixCallbackFlag_uint32_t(media::AudioMixCallbackFlag aidl) {
54 switch (aidl) {
55 case media::AudioMixCallbackFlag::NOTIFY_ACTIVITY:
56 return AudioMix::kCbFlagNotifyActivity;
57 }
58 return unexpected(BAD_VALUE);
59 }
60
61 ConversionResult<media::AudioMixCallbackFlag>
legacy2aidl_uint32_t_AudioMixCallbackFlag(uint32_t legacy)62 legacy2aidl_uint32_t_AudioMixCallbackFlag(uint32_t legacy) {
63 switch (legacy) {
64 case AudioMix::kCbFlagNotifyActivity:
65 return media::AudioMixCallbackFlag::NOTIFY_ACTIVITY;
66 }
67 return unexpected(BAD_VALUE);
68 }
69
70 ConversionResult<uint32_t>
aidl2legacy_AudioMixCallbackFlag_uint32_t_mask(int32_t aidl)71 aidl2legacy_AudioMixCallbackFlag_uint32_t_mask(int32_t aidl) {
72 return convertBitmask<uint32_t, int32_t, uint32_t, media::AudioMixCallbackFlag>(
73 aidl,
74 aidl2legacy_AudioMixCallbackFlag_uint32_t,
75 indexToEnum_index<media::AudioMixCallbackFlag>,
76 enumToMask_bitmask<uint32_t, uint32_t>);
77 }
78
79 ConversionResult<int32_t>
legacy2aidl_uint32_t_AudioMixCallbackFlag_mask(uint32_t legacy)80 legacy2aidl_uint32_t_AudioMixCallbackFlag_mask(uint32_t legacy) {
81 return convertBitmask<int32_t, uint32_t, media::AudioMixCallbackFlag, uint32_t>(
82 legacy,
83 legacy2aidl_uint32_t_AudioMixCallbackFlag,
84 indexToEnum_bitmask<uint32_t>,
85 enumToMask_index<int32_t, media::AudioMixCallbackFlag>);
86 }
87
88 ConversionResult<uint32_t>
aidl2legacy_AudioMixRouteFlag_uint32_t(media::AudioMixRouteFlag aidl)89 aidl2legacy_AudioMixRouteFlag_uint32_t(media::AudioMixRouteFlag aidl) {
90 switch (aidl) {
91 case media::AudioMixRouteFlag::RENDER:
92 return MIX_ROUTE_FLAG_RENDER;
93 case media::AudioMixRouteFlag::LOOP_BACK:
94 return MIX_ROUTE_FLAG_LOOP_BACK;
95 }
96 return unexpected(BAD_VALUE);
97 }
98
99 ConversionResult<media::AudioMixRouteFlag>
legacy2aidl_uint32_t_AudioMixRouteFlag(uint32_t legacy)100 legacy2aidl_uint32_t_AudioMixRouteFlag(uint32_t legacy) {
101 switch (legacy) {
102 case MIX_ROUTE_FLAG_RENDER:
103 return media::AudioMixRouteFlag::RENDER;
104 case MIX_ROUTE_FLAG_LOOP_BACK:
105 return media::AudioMixRouteFlag::LOOP_BACK;
106 }
107 return unexpected(BAD_VALUE);
108 }
109
110 ConversionResult<uint32_t>
aidl2legacy_AudioMixRouteFlag_uint32_t_mask(int32_t aidl)111 aidl2legacy_AudioMixRouteFlag_uint32_t_mask(int32_t aidl) {
112 return convertBitmask<uint32_t, int32_t, uint32_t, media::AudioMixRouteFlag>(
113 aidl,
114 aidl2legacy_AudioMixRouteFlag_uint32_t,
115 indexToEnum_index<media::AudioMixRouteFlag>,
116 enumToMask_bitmask<uint32_t, uint32_t>);
117 }
118
119 ConversionResult<int32_t>
legacy2aidl_uint32_t_AudioMixRouteFlag_mask(uint32_t legacy)120 legacy2aidl_uint32_t_AudioMixRouteFlag_mask(uint32_t legacy) {
121 return convertBitmask<int32_t, uint32_t, media::AudioMixRouteFlag, uint32_t>(
122 legacy,
123 legacy2aidl_uint32_t_AudioMixRouteFlag,
124 indexToEnum_bitmask<uint32_t>,
125 enumToMask_index<int32_t, media::AudioMixRouteFlag>);
126 }
127
128 // This type is unnamed in the original definition, thus we name it here.
129 using AudioMixMatchCriterionValue = decltype(AudioMixMatchCriterion::mValue);
130
131 ConversionResult<AudioMixMatchCriterionValue>
aidl2legacy_AudioMixMatchCriterionValue(const media::AudioMixMatchCriterionValue & aidl,uint32_t * rule)132 aidl2legacy_AudioMixMatchCriterionValue(
133 const media::AudioMixMatchCriterionValue& aidl,
134 uint32_t* rule) {
135 AudioMixMatchCriterionValue legacy;
136 *rule = 0;
137 switch (aidl.getTag()) {
138 case media::AudioMixMatchCriterionValue::usage:
139 legacy.mUsage = VALUE_OR_RETURN(
140 aidl2legacy_AudioUsage_audio_usage_t(UNION_GET(aidl, usage).value()));
141 *rule |= RULE_MATCH_ATTRIBUTE_USAGE;
142 return legacy;
143
144 case media::AudioMixMatchCriterionValue::source:
145 legacy.mSource = VALUE_OR_RETURN(
146 aidl2legacy_AudioSource_audio_source_t(UNION_GET(aidl, source).value()));
147 *rule |= RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET;
148 return legacy;
149
150 case media::AudioMixMatchCriterionValue::uid:
151 legacy.mUid = VALUE_OR_RETURN(
152 aidl2legacy_int32_t_uid_t(UNION_GET(aidl, uid).value()));
153 *rule |= RULE_MATCH_UID;
154 return legacy;
155
156 case media::AudioMixMatchCriterionValue::userId:
157 legacy.mUserId = VALUE_OR_RETURN(
158 convertIntegral<int>(UNION_GET(aidl, userId).value()));
159 *rule |= RULE_MATCH_USERID;
160 return legacy;
161 case media::AudioMixMatchCriterionValue::audioSessionId:
162 legacy.mAudioSessionId = VALUE_OR_RETURN(
163 aidl2legacy_int32_t_audio_session_t(UNION_GET(aidl, audioSessionId).value()));
164 *rule |= RULE_MATCH_AUDIO_SESSION_ID;
165 return legacy;
166 }
167 return unexpected(BAD_VALUE);
168 }
169
170 ConversionResult<media::AudioMixMatchCriterionValue>
legacy2aidl_AudioMixMatchCriterionValue(const AudioMixMatchCriterionValue & legacy,uint32_t rule)171 legacy2aidl_AudioMixMatchCriterionValue(
172 const AudioMixMatchCriterionValue& legacy,
173 uint32_t rule) {
174 media::AudioMixMatchCriterionValue aidl;
175 switch (rule) {
176 case RULE_MATCH_ATTRIBUTE_USAGE:
177 UNION_SET(aidl, usage,
178 VALUE_OR_RETURN(legacy2aidl_audio_usage_t_AudioUsage(legacy.mUsage)));
179 break;
180
181 case RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET:
182 UNION_SET(aidl, source,
183 VALUE_OR_RETURN(legacy2aidl_audio_source_t_AudioSource(legacy.mSource)));
184 break;
185
186 case RULE_MATCH_UID:
187 UNION_SET(aidl, uid, VALUE_OR_RETURN(legacy2aidl_uid_t_int32_t(legacy.mUid)));
188 break;
189
190 case RULE_MATCH_USERID:
191 UNION_SET(aidl, userId, VALUE_OR_RETURN(convertReinterpret<uint32_t>(legacy.mUserId)));
192 break;
193 case RULE_MATCH_AUDIO_SESSION_ID:
194 UNION_SET(aidl, audioSessionId,
195 VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(legacy.mAudioSessionId)));
196 break;
197 default:
198 return unexpected(BAD_VALUE);
199 }
200 return aidl;
201 }
202
203
204 ConversionResult<AudioMixMatchCriterion>
aidl2legacy_AudioMixMatchCriterion(const media::AudioMixMatchCriterion & aidl)205 aidl2legacy_AudioMixMatchCriterion(const media::AudioMixMatchCriterion& aidl) {
206 AudioMixMatchCriterion legacy;
207 legacy.mValue = VALUE_OR_RETURN(
208 aidl2legacy_AudioMixMatchCriterionValue(aidl.value, &legacy.mRule));
209 if (aidl.invert) {
210 legacy.mRule |= RULE_EXCLUSION_MASK;
211 }
212 return legacy;
213 }
214
215 ConversionResult<media::AudioMixMatchCriterion>
legacy2aidl_AudioMixMatchCriterion(const AudioMixMatchCriterion & legacy)216 legacy2aidl_AudioMixMatchCriterion(const AudioMixMatchCriterion& legacy) {
217 media::AudioMixMatchCriterion aidl;
218 uint32_t rule = legacy.mRule;
219 if (rule & RULE_EXCLUSION_MASK) {
220 aidl.invert = true;
221 rule &= ~RULE_EXCLUSION_MASK;
222 }
223 aidl.value = VALUE_OR_RETURN(legacy2aidl_AudioMixMatchCriterionValue(legacy.mValue, rule));
224 return aidl;
225 }
226
227 ConversionResult<AudioMix>
aidl2legacy_AudioMix(const media::AudioMix & aidl)228 aidl2legacy_AudioMix(const media::AudioMix& aidl) {
229 AudioMix legacy;
230 RETURN_IF_ERROR(convertRange(aidl.criteria.begin(), aidl.criteria.end(),
231 std::back_inserter(legacy.mCriteria),
232 aidl2legacy_AudioMixMatchCriterion));
233 legacy.mMixType = VALUE_OR_RETURN(aidl2legacy_AudioMixType_uint32_t(aidl.mixType));
234 // See 'convertAudioMixToNative' in 'android_media_AudioSystem.cpp' -- only
235 // an output mask is expected here.
236 legacy.mFormat = VALUE_OR_RETURN(aidl2legacy_AudioConfig_audio_config_t(
237 aidl.format, false /*isInput*/));
238 legacy.mRouteFlags = VALUE_OR_RETURN(
239 aidl2legacy_AudioMixRouteFlag_uint32_t_mask(aidl.routeFlags));
240 RETURN_IF_ERROR(aidl2legacy_AudioDevice_audio_device(
241 aidl.device, &legacy.mDeviceType, &legacy.mDeviceAddress));
242 legacy.mCbFlags = VALUE_OR_RETURN(aidl2legacy_AudioMixCallbackFlag_uint32_t_mask(aidl.cbFlags));
243 legacy.mAllowPrivilegedMediaPlaybackCapture = aidl.allowPrivilegedMediaPlaybackCapture;
244 legacy.mVoiceCommunicationCaptureAllowed = aidl.voiceCommunicationCaptureAllowed;
245 return legacy;
246 }
247
248 ConversionResult<media::AudioMix>
legacy2aidl_AudioMix(const AudioMix & legacy)249 legacy2aidl_AudioMix(const AudioMix& legacy) {
250 media::AudioMix aidl;
251 aidl.criteria = VALUE_OR_RETURN(
252 convertContainer<std::vector<media::AudioMixMatchCriterion>>(
253 legacy.mCriteria,
254 legacy2aidl_AudioMixMatchCriterion));
255 aidl.mixType = VALUE_OR_RETURN(legacy2aidl_uint32_t_AudioMixType(legacy.mMixType));
256 // See 'convertAudioMixToNative' in 'android_media_AudioSystem.cpp' -- only
257 // an output mask is expected here.
258 aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_config_t_AudioConfig(
259 legacy.mFormat, false /*isInput*/));
260 aidl.routeFlags = VALUE_OR_RETURN(
261 legacy2aidl_uint32_t_AudioMixRouteFlag_mask(legacy.mRouteFlags));
262 aidl.device = VALUE_OR_RETURN(
263 legacy2aidl_audio_device_AudioDevice(
264 legacy.mDeviceType, legacy.mDeviceAddress));
265 aidl.cbFlags = VALUE_OR_RETURN(legacy2aidl_uint32_t_AudioMixCallbackFlag_mask(legacy.mCbFlags));
266 aidl.allowPrivilegedMediaPlaybackCapture = legacy.mAllowPrivilegedMediaPlaybackCapture;
267 aidl.voiceCommunicationCaptureAllowed = legacy.mVoiceCommunicationCaptureAllowed;
268 return aidl;
269 }
270
271 ConversionResult<audio_policy_dev_state_t>
aidl2legacy_AudioPolicyDeviceState_audio_policy_dev_state_t(media::AudioPolicyDeviceState aidl)272 aidl2legacy_AudioPolicyDeviceState_audio_policy_dev_state_t(media::AudioPolicyDeviceState aidl) {
273 switch (aidl) {
274 case media::AudioPolicyDeviceState::UNAVAILABLE:
275 return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
276 case media::AudioPolicyDeviceState::AVAILABLE:
277 return AUDIO_POLICY_DEVICE_STATE_AVAILABLE;
278 }
279 return unexpected(BAD_VALUE);
280 }
281
282 ConversionResult<media::AudioPolicyDeviceState>
legacy2aidl_audio_policy_dev_state_t_AudioPolicyDeviceState(audio_policy_dev_state_t legacy)283 legacy2aidl_audio_policy_dev_state_t_AudioPolicyDeviceState(audio_policy_dev_state_t legacy) {
284 switch (legacy) {
285 case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE:
286 return media::AudioPolicyDeviceState::UNAVAILABLE;
287 case AUDIO_POLICY_DEVICE_STATE_AVAILABLE:
288 return media::AudioPolicyDeviceState::AVAILABLE;
289 case AUDIO_POLICY_DEVICE_STATE_CNT:
290 break;
291 }
292 return unexpected(BAD_VALUE);
293 }
294
295 ConversionResult<audio_policy_force_use_t>
aidl2legacy_AudioPolicyForceUse_audio_policy_force_use_t(media::AudioPolicyForceUse aidl)296 aidl2legacy_AudioPolicyForceUse_audio_policy_force_use_t(media::AudioPolicyForceUse aidl) {
297 switch (aidl) {
298 case media::AudioPolicyForceUse::COMMUNICATION:
299 return AUDIO_POLICY_FORCE_FOR_COMMUNICATION;
300 case media::AudioPolicyForceUse::MEDIA:
301 return AUDIO_POLICY_FORCE_FOR_MEDIA;
302 case media::AudioPolicyForceUse::RECORD:
303 return AUDIO_POLICY_FORCE_FOR_RECORD;
304 case media::AudioPolicyForceUse::DOCK:
305 return AUDIO_POLICY_FORCE_FOR_DOCK;
306 case media::AudioPolicyForceUse::SYSTEM:
307 return AUDIO_POLICY_FORCE_FOR_SYSTEM;
308 case media::AudioPolicyForceUse::HDMI_SYSTEM_AUDIO:
309 return AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO;
310 case media::AudioPolicyForceUse::ENCODED_SURROUND:
311 return AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND;
312 case media::AudioPolicyForceUse::VIBRATE_RINGING:
313 return AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING;
314 }
315 return unexpected(BAD_VALUE);
316 }
317
318 ConversionResult<media::AudioPolicyForceUse>
legacy2aidl_audio_policy_force_use_t_AudioPolicyForceUse(audio_policy_force_use_t legacy)319 legacy2aidl_audio_policy_force_use_t_AudioPolicyForceUse(audio_policy_force_use_t legacy) {
320 switch (legacy) {
321 case AUDIO_POLICY_FORCE_FOR_COMMUNICATION:
322 return media::AudioPolicyForceUse::COMMUNICATION;
323 case AUDIO_POLICY_FORCE_FOR_MEDIA:
324 return media::AudioPolicyForceUse::MEDIA;
325 case AUDIO_POLICY_FORCE_FOR_RECORD:
326 return media::AudioPolicyForceUse::RECORD;
327 case AUDIO_POLICY_FORCE_FOR_DOCK:
328 return media::AudioPolicyForceUse::DOCK;
329 case AUDIO_POLICY_FORCE_FOR_SYSTEM:
330 return media::AudioPolicyForceUse::SYSTEM;
331 case AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO:
332 return media::AudioPolicyForceUse::HDMI_SYSTEM_AUDIO;
333 case AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND:
334 return media::AudioPolicyForceUse::ENCODED_SURROUND;
335 case AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING:
336 return media::AudioPolicyForceUse::VIBRATE_RINGING;
337 case AUDIO_POLICY_FORCE_USE_CNT:
338 break;
339 }
340 return unexpected(BAD_VALUE);
341 }
342
343 ConversionResult<audio_policy_forced_cfg_t>
aidl2legacy_AudioPolicyForcedConfig_audio_policy_forced_cfg_t(media::AudioPolicyForcedConfig aidl)344 aidl2legacy_AudioPolicyForcedConfig_audio_policy_forced_cfg_t(media::AudioPolicyForcedConfig aidl) {
345 switch (aidl) {
346 case media::AudioPolicyForcedConfig::NONE:
347 return AUDIO_POLICY_FORCE_NONE;
348 case media::AudioPolicyForcedConfig::SPEAKER:
349 return AUDIO_POLICY_FORCE_SPEAKER;
350 case media::AudioPolicyForcedConfig::HEADPHONES:
351 return AUDIO_POLICY_FORCE_HEADPHONES;
352 case media::AudioPolicyForcedConfig::BT_SCO:
353 return AUDIO_POLICY_FORCE_BT_SCO;
354 case media::AudioPolicyForcedConfig::BT_A2DP:
355 return AUDIO_POLICY_FORCE_BT_A2DP;
356 case media::AudioPolicyForcedConfig::WIRED_ACCESSORY:
357 return AUDIO_POLICY_FORCE_WIRED_ACCESSORY;
358 case media::AudioPolicyForcedConfig::BT_CAR_DOCK:
359 return AUDIO_POLICY_FORCE_BT_CAR_DOCK;
360 case media::AudioPolicyForcedConfig::BT_DESK_DOCK:
361 return AUDIO_POLICY_FORCE_BT_DESK_DOCK;
362 case media::AudioPolicyForcedConfig::ANALOG_DOCK:
363 return AUDIO_POLICY_FORCE_ANALOG_DOCK;
364 case media::AudioPolicyForcedConfig::DIGITAL_DOCK:
365 return AUDIO_POLICY_FORCE_DIGITAL_DOCK;
366 case media::AudioPolicyForcedConfig::NO_BT_A2DP:
367 return AUDIO_POLICY_FORCE_NO_BT_A2DP;
368 case media::AudioPolicyForcedConfig::SYSTEM_ENFORCED:
369 return AUDIO_POLICY_FORCE_SYSTEM_ENFORCED;
370 case media::AudioPolicyForcedConfig::HDMI_SYSTEM_AUDIO_ENFORCED:
371 return AUDIO_POLICY_FORCE_HDMI_SYSTEM_AUDIO_ENFORCED;
372 case media::AudioPolicyForcedConfig::ENCODED_SURROUND_NEVER:
373 return AUDIO_POLICY_FORCE_ENCODED_SURROUND_NEVER;
374 case media::AudioPolicyForcedConfig::ENCODED_SURROUND_ALWAYS:
375 return AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS;
376 case media::AudioPolicyForcedConfig::ENCODED_SURROUND_MANUAL:
377 return AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL;
378 }
379 return unexpected(BAD_VALUE);
380 }
381
382 ConversionResult<media::AudioPolicyForcedConfig>
legacy2aidl_audio_policy_forced_cfg_t_AudioPolicyForcedConfig(audio_policy_forced_cfg_t legacy)383 legacy2aidl_audio_policy_forced_cfg_t_AudioPolicyForcedConfig(audio_policy_forced_cfg_t legacy) {
384 switch (legacy) {
385 case AUDIO_POLICY_FORCE_NONE:
386 return media::AudioPolicyForcedConfig::NONE;
387 case AUDIO_POLICY_FORCE_SPEAKER:
388 return media::AudioPolicyForcedConfig::SPEAKER;
389 case AUDIO_POLICY_FORCE_HEADPHONES:
390 return media::AudioPolicyForcedConfig::HEADPHONES;
391 case AUDIO_POLICY_FORCE_BT_SCO:
392 return media::AudioPolicyForcedConfig::BT_SCO;
393 case AUDIO_POLICY_FORCE_BT_A2DP:
394 return media::AudioPolicyForcedConfig::BT_A2DP;
395 case AUDIO_POLICY_FORCE_WIRED_ACCESSORY:
396 return media::AudioPolicyForcedConfig::WIRED_ACCESSORY;
397 case AUDIO_POLICY_FORCE_BT_CAR_DOCK:
398 return media::AudioPolicyForcedConfig::BT_CAR_DOCK;
399 case AUDIO_POLICY_FORCE_BT_DESK_DOCK:
400 return media::AudioPolicyForcedConfig::BT_DESK_DOCK;
401 case AUDIO_POLICY_FORCE_ANALOG_DOCK:
402 return media::AudioPolicyForcedConfig::ANALOG_DOCK;
403 case AUDIO_POLICY_FORCE_DIGITAL_DOCK:
404 return media::AudioPolicyForcedConfig::DIGITAL_DOCK;
405 case AUDIO_POLICY_FORCE_NO_BT_A2DP:
406 return media::AudioPolicyForcedConfig::NO_BT_A2DP;
407 case AUDIO_POLICY_FORCE_SYSTEM_ENFORCED:
408 return media::AudioPolicyForcedConfig::SYSTEM_ENFORCED;
409 case AUDIO_POLICY_FORCE_HDMI_SYSTEM_AUDIO_ENFORCED:
410 return media::AudioPolicyForcedConfig::HDMI_SYSTEM_AUDIO_ENFORCED;
411 case AUDIO_POLICY_FORCE_ENCODED_SURROUND_NEVER:
412 return media::AudioPolicyForcedConfig::ENCODED_SURROUND_NEVER;
413 case AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS:
414 return media::AudioPolicyForcedConfig::ENCODED_SURROUND_ALWAYS;
415 case AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL:
416 return media::AudioPolicyForcedConfig::ENCODED_SURROUND_MANUAL;
417 case AUDIO_POLICY_FORCE_CFG_CNT:
418 break;
419 }
420 return unexpected(BAD_VALUE);
421 }
422
423 ConversionResult<device_role_t>
aidl2legacy_DeviceRole_device_role_t(media::DeviceRole aidl)424 aidl2legacy_DeviceRole_device_role_t(media::DeviceRole aidl) {
425 switch (aidl) {
426 case media::DeviceRole::NONE:
427 return DEVICE_ROLE_NONE;
428 case media::DeviceRole::PREFERRED:
429 return DEVICE_ROLE_PREFERRED;
430 case media::DeviceRole::DISABLED:
431 return DEVICE_ROLE_DISABLED;
432 }
433 return unexpected(BAD_VALUE);
434 }
435
436 ConversionResult<media::DeviceRole>
legacy2aidl_device_role_t_DeviceRole(device_role_t legacy)437 legacy2aidl_device_role_t_DeviceRole(device_role_t legacy) {
438 switch (legacy) {
439 case DEVICE_ROLE_NONE:
440 return media::DeviceRole::NONE;
441 case DEVICE_ROLE_PREFERRED:
442 return media::DeviceRole::PREFERRED;
443 case DEVICE_ROLE_DISABLED:
444 return media::DeviceRole::DISABLED;
445 }
446 return unexpected(BAD_VALUE);
447 }
448
449 ConversionResult<audio_offload_mode_t>
aidl2legacy_AudioOffloadMode_audio_offload_mode_t(media::AudioOffloadMode aidl)450 aidl2legacy_AudioOffloadMode_audio_offload_mode_t(media::AudioOffloadMode aidl) {
451 switch (aidl) {
452 case media::AudioOffloadMode::NOT_SUPPORTED:
453 return AUDIO_OFFLOAD_NOT_SUPPORTED;
454 case media::AudioOffloadMode::SUPPORTED:
455 return AUDIO_OFFLOAD_SUPPORTED;
456 case media::AudioOffloadMode::GAPLESS_SUPPORTED:
457 return AUDIO_OFFLOAD_GAPLESS_SUPPORTED;
458 }
459 return unexpected(BAD_VALUE);
460 }
461
462 ConversionResult<media::AudioOffloadMode>
legacy2aidl_audio_offload_mode_t_AudioOffloadMode(audio_offload_mode_t legacy)463 legacy2aidl_audio_offload_mode_t_AudioOffloadMode(audio_offload_mode_t legacy) {
464 switch (legacy) {
465 case AUDIO_OFFLOAD_NOT_SUPPORTED:
466 return media::AudioOffloadMode::NOT_SUPPORTED;
467 case AUDIO_OFFLOAD_SUPPORTED:
468 return media::AudioOffloadMode::SUPPORTED;
469 case AUDIO_OFFLOAD_GAPLESS_SUPPORTED:
470 return media::AudioOffloadMode::GAPLESS_SUPPORTED;
471 }
472 return unexpected(BAD_VALUE);
473 }
474
475 ConversionResult<audio_mixer_behavior_t>
aidl2legacy_AudioMixerBehavior_audio_mixer_behavior_t(media::AudioMixerBehavior aidl)476 aidl2legacy_AudioMixerBehavior_audio_mixer_behavior_t(media::AudioMixerBehavior aidl) {
477 switch (aidl) {
478 case media::AudioMixerBehavior::DEFAULT:
479 return AUDIO_MIXER_BEHAVIOR_DEFAULT;
480 case media::AudioMixerBehavior::BIT_PERFECT:
481 return AUDIO_MIXER_BEHAVIOR_BIT_PERFECT;
482 case media::AudioMixerBehavior::INVALID:
483 return AUDIO_MIXER_BEHAVIOR_INVALID;
484 }
485 return unexpected(BAD_VALUE);
486 }
487 ConversionResult<media::AudioMixerBehavior>
legacy2aidl_audio_mixer_behavior_t_AudioMixerBehavior(audio_mixer_behavior_t legacy)488 legacy2aidl_audio_mixer_behavior_t_AudioMixerBehavior(audio_mixer_behavior_t legacy) {
489 switch (legacy) {
490 case AUDIO_MIXER_BEHAVIOR_DEFAULT:
491 return media::AudioMixerBehavior::DEFAULT;
492 case AUDIO_MIXER_BEHAVIOR_BIT_PERFECT:
493 return media::AudioMixerBehavior::BIT_PERFECT;
494 case AUDIO_MIXER_BEHAVIOR_INVALID:
495 return media::AudioMixerBehavior::INVALID;
496 }
497 return unexpected(BAD_VALUE);
498 }
499
500 ConversionResult<audio_mixer_attributes_t>
aidl2legacy_AudioMixerAttributesInternal_audio_mixer_attributes_t(const media::AudioMixerAttributesInternal & aidl)501 aidl2legacy_AudioMixerAttributesInternal_audio_mixer_attributes_t(
502 const media::AudioMixerAttributesInternal& aidl) {
503 audio_mixer_attributes_t legacy = AUDIO_MIXER_ATTRIBUTES_INITIALIZER;
504 legacy.config = VALUE_OR_RETURN(
505 aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.config, false /*isInput*/));
506 legacy.mixer_behavior = VALUE_OR_RETURN(
507 aidl2legacy_AudioMixerBehavior_audio_mixer_behavior_t(aidl.mixerBehavior));
508 return legacy;
509 }
510 ConversionResult<media::AudioMixerAttributesInternal>
legacy2aidl_audio_mixer_attributes_t_AudioMixerAttributesInternal(const audio_mixer_attributes & legacy)511 legacy2aidl_audio_mixer_attributes_t_AudioMixerAttributesInternal(
512 const audio_mixer_attributes& legacy) {
513 media::AudioMixerAttributesInternal aidl;
514 aidl.config = VALUE_OR_RETURN(
515 legacy2aidl_audio_config_base_t_AudioConfigBase(legacy.config, false /*isInput*/));
516 aidl.mixerBehavior = VALUE_OR_RETURN(
517 legacy2aidl_audio_mixer_behavior_t_AudioMixerBehavior(legacy.mixer_behavior));
518 return aidl;
519 }
520
521
522 } // namespace android
523