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
29 ConversionResult<volume_group_t>
aidl2legacy_int32_t_volume_group_t(int32_t aidl)30 aidl2legacy_int32_t_volume_group_t(int32_t aidl) {
31 return convertReinterpret<volume_group_t>(aidl);
32 }
33
34 ConversionResult<int32_t>
legacy2aidl_volume_group_t_int32_t(volume_group_t legacy)35 legacy2aidl_volume_group_t_int32_t(volume_group_t legacy) {
36 return convertReinterpret<int32_t>(legacy);
37 }
38
39 ConversionResult<uint32_t>
aidl2legacy_AudioMixType_uint32_t(media::AudioMixType aidl)40 aidl2legacy_AudioMixType_uint32_t(media::AudioMixType aidl) {
41 switch (aidl) {
42 case media::AudioMixType::PLAYERS:
43 return MIX_TYPE_PLAYERS;
44 case media::AudioMixType::RECORDERS:
45 return MIX_TYPE_RECORDERS;
46 }
47 return unexpected(BAD_VALUE);
48 }
49
50 ConversionResult<media::AudioMixType>
legacy2aidl_uint32_t_AudioMixType(uint32_t legacy)51 legacy2aidl_uint32_t_AudioMixType(uint32_t legacy) {
52 switch (legacy) {
53 case MIX_TYPE_PLAYERS:
54 return media::AudioMixType::PLAYERS;
55 case MIX_TYPE_RECORDERS:
56 return media::AudioMixType::RECORDERS;
57 }
58 return unexpected(BAD_VALUE);
59 }
60
61 ConversionResult<uint32_t>
aidl2legacy_AudioMixCallbackFlag_uint32_t(media::AudioMixCallbackFlag aidl)62 aidl2legacy_AudioMixCallbackFlag_uint32_t(media::AudioMixCallbackFlag aidl) {
63 switch (aidl) {
64 case media::AudioMixCallbackFlag::NOTIFY_ACTIVITY:
65 return AudioMix::kCbFlagNotifyActivity;
66 }
67 return unexpected(BAD_VALUE);
68 }
69
70 ConversionResult<media::AudioMixCallbackFlag>
legacy2aidl_uint32_t_AudioMixCallbackFlag(uint32_t legacy)71 legacy2aidl_uint32_t_AudioMixCallbackFlag(uint32_t legacy) {
72 switch (legacy) {
73 case AudioMix::kCbFlagNotifyActivity:
74 return media::AudioMixCallbackFlag::NOTIFY_ACTIVITY;
75 }
76 return unexpected(BAD_VALUE);
77 }
78
79 ConversionResult<uint32_t>
aidl2legacy_AudioMixCallbackFlag_uint32_t_mask(int32_t aidl)80 aidl2legacy_AudioMixCallbackFlag_uint32_t_mask(int32_t aidl) {
81 return convertBitmask<uint32_t, int32_t, uint32_t, media::AudioMixCallbackFlag>(
82 aidl,
83 aidl2legacy_AudioMixCallbackFlag_uint32_t,
84 indexToEnum_index<media::AudioMixCallbackFlag>,
85 enumToMask_bitmask<uint32_t, uint32_t>);
86 }
87
88 ConversionResult<int32_t>
legacy2aidl_uint32_t_AudioMixCallbackFlag_mask(uint32_t legacy)89 legacy2aidl_uint32_t_AudioMixCallbackFlag_mask(uint32_t legacy) {
90 return convertBitmask<int32_t, uint32_t, media::AudioMixCallbackFlag, uint32_t>(
91 legacy,
92 legacy2aidl_uint32_t_AudioMixCallbackFlag,
93 indexToEnum_bitmask<uint32_t>,
94 enumToMask_index<int32_t, media::AudioMixCallbackFlag>);
95 }
96
97 ConversionResult<uint32_t>
aidl2legacy_AudioMixRouteFlag_uint32_t(media::AudioMixRouteFlag aidl)98 aidl2legacy_AudioMixRouteFlag_uint32_t(media::AudioMixRouteFlag aidl) {
99 switch (aidl) {
100 case media::AudioMixRouteFlag::RENDER:
101 return MIX_ROUTE_FLAG_RENDER;
102 case media::AudioMixRouteFlag::LOOP_BACK:
103 return MIX_ROUTE_FLAG_LOOP_BACK;
104 }
105 return unexpected(BAD_VALUE);
106 }
107
108 ConversionResult<media::AudioMixRouteFlag>
legacy2aidl_uint32_t_AudioMixRouteFlag(uint32_t legacy)109 legacy2aidl_uint32_t_AudioMixRouteFlag(uint32_t legacy) {
110 switch (legacy) {
111 case MIX_ROUTE_FLAG_RENDER:
112 return media::AudioMixRouteFlag::RENDER;
113 case MIX_ROUTE_FLAG_LOOP_BACK:
114 return media::AudioMixRouteFlag::LOOP_BACK;
115 }
116 return unexpected(BAD_VALUE);
117 }
118
119 ConversionResult<uint32_t>
aidl2legacy_AudioMixRouteFlag_uint32_t_mask(int32_t aidl)120 aidl2legacy_AudioMixRouteFlag_uint32_t_mask(int32_t aidl) {
121 return convertBitmask<uint32_t, int32_t, uint32_t, media::AudioMixRouteFlag>(
122 aidl,
123 aidl2legacy_AudioMixRouteFlag_uint32_t,
124 indexToEnum_index<media::AudioMixRouteFlag>,
125 enumToMask_bitmask<uint32_t, uint32_t>);
126 }
127
128 ConversionResult<int32_t>
legacy2aidl_uint32_t_AudioMixRouteFlag_mask(uint32_t legacy)129 legacy2aidl_uint32_t_AudioMixRouteFlag_mask(uint32_t legacy) {
130 return convertBitmask<int32_t, uint32_t, media::AudioMixRouteFlag, uint32_t>(
131 legacy,
132 legacy2aidl_uint32_t_AudioMixRouteFlag,
133 indexToEnum_bitmask<uint32_t>,
134 enumToMask_index<int32_t, media::AudioMixRouteFlag>);
135 }
136
137 // This type is unnamed in the original definition, thus we name it here.
138 using AudioMixMatchCriterionValue = decltype(AudioMixMatchCriterion::mValue);
139
140 ConversionResult<AudioMixMatchCriterionValue>
aidl2legacy_AudioMixMatchCriterionValue(const media::AudioMixMatchCriterionValue & aidl,uint32_t * rule)141 aidl2legacy_AudioMixMatchCriterionValue(
142 const media::AudioMixMatchCriterionValue& aidl,
143 uint32_t* rule) {
144 AudioMixMatchCriterionValue legacy;
145 *rule = 0;
146 switch (aidl.getTag()) {
147 case media::AudioMixMatchCriterionValue::usage:
148 legacy.mUsage = VALUE_OR_RETURN(
149 aidl2legacy_AudioUsage_audio_usage_t(UNION_GET(aidl, usage).value()));
150 *rule |= RULE_MATCH_ATTRIBUTE_USAGE;
151 return legacy;
152
153 case media::AudioMixMatchCriterionValue::source:
154 legacy.mSource = VALUE_OR_RETURN(
155 aidl2legacy_AudioSourceType_audio_source_t(UNION_GET(aidl, source).value()));
156 *rule |= RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET;
157 return legacy;
158
159 case media::AudioMixMatchCriterionValue::uid:
160 legacy.mUid = VALUE_OR_RETURN(
161 aidl2legacy_int32_t_uid_t(UNION_GET(aidl, uid).value()));
162 *rule |= RULE_MATCH_UID;
163 return legacy;
164
165 case media::AudioMixMatchCriterionValue::userId:
166 legacy.mUserId = VALUE_OR_RETURN(
167 convertIntegral<int>(UNION_GET(aidl, userId).value()));
168 *rule |= RULE_MATCH_USERID;
169 return legacy;
170 }
171 return unexpected(BAD_VALUE);
172 }
173
174 ConversionResult<media::AudioMixMatchCriterionValue>
legacy2aidl_AudioMixMatchCriterionValue(const AudioMixMatchCriterionValue & legacy,uint32_t rule)175 legacy2aidl_AudioMixMatchCriterionValue(
176 const AudioMixMatchCriterionValue& legacy,
177 uint32_t rule) {
178 media::AudioMixMatchCriterionValue aidl;
179 switch (rule) {
180 case RULE_MATCH_ATTRIBUTE_USAGE:
181 UNION_SET(aidl, usage,
182 VALUE_OR_RETURN(legacy2aidl_audio_usage_t_AudioUsage(legacy.mUsage)));
183 break;
184
185 case RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET:
186 UNION_SET(aidl, source,
187 VALUE_OR_RETURN(legacy2aidl_audio_source_t_AudioSourceType(legacy.mSource)));
188 break;
189
190 case RULE_MATCH_UID:
191 UNION_SET(aidl, uid, VALUE_OR_RETURN(legacy2aidl_uid_t_int32_t(legacy.mUid)));
192 break;
193
194 case RULE_MATCH_USERID:
195 UNION_SET(aidl, userId, VALUE_OR_RETURN(convertReinterpret<uint32_t>(legacy.mUserId)));
196 break;
197
198 default:
199 return unexpected(BAD_VALUE);
200 }
201 return aidl;
202 }
203
204
205 ConversionResult<AudioMixMatchCriterion>
aidl2legacy_AudioMixMatchCriterion(const media::AudioMixMatchCriterion & aidl)206 aidl2legacy_AudioMixMatchCriterion(const media::AudioMixMatchCriterion& aidl) {
207 AudioMixMatchCriterion legacy;
208 legacy.mValue = VALUE_OR_RETURN(
209 aidl2legacy_AudioMixMatchCriterionValue(aidl.value, &legacy.mRule));
210 if (aidl.invert) {
211 legacy.mRule |= RULE_EXCLUSION_MASK;
212 }
213 return legacy;
214 }
215
216 ConversionResult<media::AudioMixMatchCriterion>
legacy2aidl_AudioMixMatchCriterion(const AudioMixMatchCriterion & legacy)217 legacy2aidl_AudioMixMatchCriterion(const AudioMixMatchCriterion& legacy) {
218 media::AudioMixMatchCriterion aidl;
219 uint32_t rule = legacy.mRule;
220 if (rule & RULE_EXCLUSION_MASK) {
221 aidl.invert = true;
222 rule &= ~RULE_EXCLUSION_MASK;
223 }
224 aidl.value = VALUE_OR_RETURN(legacy2aidl_AudioMixMatchCriterionValue(legacy.mValue, rule));
225 return aidl;
226 }
227
228 ConversionResult<AudioMix>
aidl2legacy_AudioMix(const media::AudioMix & aidl)229 aidl2legacy_AudioMix(const media::AudioMix& aidl) {
230 AudioMix legacy;
231 RETURN_IF_ERROR(convertRange(aidl.criteria.begin(), aidl.criteria.end(),
232 std::back_inserter(legacy.mCriteria),
233 aidl2legacy_AudioMixMatchCriterion));
234 legacy.mMixType = VALUE_OR_RETURN(aidl2legacy_AudioMixType_uint32_t(aidl.mixType));
235 legacy.mFormat = VALUE_OR_RETURN(aidl2legacy_AudioConfig_audio_config_t(aidl.format));
236 legacy.mRouteFlags = VALUE_OR_RETURN(
237 aidl2legacy_AudioMixRouteFlag_uint32_t_mask(aidl.routeFlags));
238 legacy.mDeviceType = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_devices_t(aidl.device.type));
239 legacy.mDeviceAddress = VALUE_OR_RETURN(aidl2legacy_string_view_String8(aidl.device.address));
240 legacy.mCbFlags = VALUE_OR_RETURN(aidl2legacy_AudioMixCallbackFlag_uint32_t_mask(aidl.cbFlags));
241 legacy.mAllowPrivilegedMediaPlaybackCapture = aidl.allowPrivilegedMediaPlaybackCapture;
242 legacy.mVoiceCommunicationCaptureAllowed = aidl.voiceCommunicationCaptureAllowed;
243 return legacy;
244 }
245
246 ConversionResult<media::AudioMix>
legacy2aidl_AudioMix(const AudioMix & legacy)247 legacy2aidl_AudioMix(const AudioMix& legacy) {
248 media::AudioMix aidl;
249 aidl.criteria = VALUE_OR_RETURN(
250 convertContainer<std::vector<media::AudioMixMatchCriterion>>(
251 legacy.mCriteria,
252 legacy2aidl_AudioMixMatchCriterion));
253 aidl.mixType = VALUE_OR_RETURN(legacy2aidl_uint32_t_AudioMixType(legacy.mMixType));
254 aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_config_t_AudioConfig(legacy.mFormat));
255 aidl.routeFlags = VALUE_OR_RETURN(
256 legacy2aidl_uint32_t_AudioMixRouteFlag_mask(legacy.mRouteFlags));
257 aidl.device.type = VALUE_OR_RETURN(legacy2aidl_audio_devices_t_int32_t(legacy.mDeviceType));
258 aidl.device.address = VALUE_OR_RETURN(legacy2aidl_String8_string(legacy.mDeviceAddress));
259 aidl.cbFlags = VALUE_OR_RETURN(legacy2aidl_uint32_t_AudioMixCallbackFlag_mask(legacy.mCbFlags));
260 aidl.allowPrivilegedMediaPlaybackCapture = legacy.mAllowPrivilegedMediaPlaybackCapture;
261 aidl.voiceCommunicationCaptureAllowed = legacy.mVoiceCommunicationCaptureAllowed;
262 return aidl;
263 }
264
265 ConversionResult<audio_policy_dev_state_t>
aidl2legacy_AudioPolicyDeviceState_audio_policy_dev_state_t(media::AudioPolicyDeviceState aidl)266 aidl2legacy_AudioPolicyDeviceState_audio_policy_dev_state_t(media::AudioPolicyDeviceState aidl) {
267 switch (aidl) {
268 case media::AudioPolicyDeviceState::UNAVAILABLE:
269 return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
270 case media::AudioPolicyDeviceState::AVAILABLE:
271 return AUDIO_POLICY_DEVICE_STATE_AVAILABLE;
272 }
273 return unexpected(BAD_VALUE);
274 }
275
276 ConversionResult<media::AudioPolicyDeviceState>
legacy2aidl_audio_policy_dev_state_t_AudioPolicyDeviceState(audio_policy_dev_state_t legacy)277 legacy2aidl_audio_policy_dev_state_t_AudioPolicyDeviceState(audio_policy_dev_state_t legacy) {
278 switch (legacy) {
279 case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE:
280 return media::AudioPolicyDeviceState::UNAVAILABLE;
281 case AUDIO_POLICY_DEVICE_STATE_AVAILABLE:
282 return media::AudioPolicyDeviceState::AVAILABLE;
283 case AUDIO_POLICY_DEVICE_STATE_CNT:
284 break;
285 }
286 return unexpected(BAD_VALUE);
287 }
288
289 ConversionResult<audio_policy_force_use_t>
aidl2legacy_AudioPolicyForceUse_audio_policy_force_use_t(media::AudioPolicyForceUse aidl)290 aidl2legacy_AudioPolicyForceUse_audio_policy_force_use_t(media::AudioPolicyForceUse aidl) {
291 switch (aidl) {
292 case media::AudioPolicyForceUse::COMMUNICATION:
293 return AUDIO_POLICY_FORCE_FOR_COMMUNICATION;
294 case media::AudioPolicyForceUse::MEDIA:
295 return AUDIO_POLICY_FORCE_FOR_MEDIA;
296 case media::AudioPolicyForceUse::RECORD:
297 return AUDIO_POLICY_FORCE_FOR_RECORD;
298 case media::AudioPolicyForceUse::DOCK:
299 return AUDIO_POLICY_FORCE_FOR_DOCK;
300 case media::AudioPolicyForceUse::SYSTEM:
301 return AUDIO_POLICY_FORCE_FOR_SYSTEM;
302 case media::AudioPolicyForceUse::HDMI_SYSTEM_AUDIO:
303 return AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO;
304 case media::AudioPolicyForceUse::ENCODED_SURROUND:
305 return AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND;
306 case media::AudioPolicyForceUse::VIBRATE_RINGING:
307 return AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING;
308 }
309 return unexpected(BAD_VALUE);
310 }
311
312 ConversionResult<media::AudioPolicyForceUse>
legacy2aidl_audio_policy_force_use_t_AudioPolicyForceUse(audio_policy_force_use_t legacy)313 legacy2aidl_audio_policy_force_use_t_AudioPolicyForceUse(audio_policy_force_use_t legacy) {
314 switch (legacy) {
315 case AUDIO_POLICY_FORCE_FOR_COMMUNICATION:
316 return media::AudioPolicyForceUse::COMMUNICATION;
317 case AUDIO_POLICY_FORCE_FOR_MEDIA:
318 return media::AudioPolicyForceUse::MEDIA;
319 case AUDIO_POLICY_FORCE_FOR_RECORD:
320 return media::AudioPolicyForceUse::RECORD;
321 case AUDIO_POLICY_FORCE_FOR_DOCK:
322 return media::AudioPolicyForceUse::DOCK;
323 case AUDIO_POLICY_FORCE_FOR_SYSTEM:
324 return media::AudioPolicyForceUse::SYSTEM;
325 case AUDIO_POLICY_FORCE_FOR_HDMI_SYSTEM_AUDIO:
326 return media::AudioPolicyForceUse::HDMI_SYSTEM_AUDIO;
327 case AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND:
328 return media::AudioPolicyForceUse::ENCODED_SURROUND;
329 case AUDIO_POLICY_FORCE_FOR_VIBRATE_RINGING:
330 return media::AudioPolicyForceUse::VIBRATE_RINGING;
331 case AUDIO_POLICY_FORCE_USE_CNT:
332 break;
333 }
334 return unexpected(BAD_VALUE);
335 }
336
337 ConversionResult<audio_policy_forced_cfg_t>
aidl2legacy_AudioPolicyForcedConfig_audio_policy_forced_cfg_t(media::AudioPolicyForcedConfig aidl)338 aidl2legacy_AudioPolicyForcedConfig_audio_policy_forced_cfg_t(media::AudioPolicyForcedConfig aidl) {
339 switch (aidl) {
340 case media::AudioPolicyForcedConfig::NONE:
341 return AUDIO_POLICY_FORCE_NONE;
342 case media::AudioPolicyForcedConfig::SPEAKER:
343 return AUDIO_POLICY_FORCE_SPEAKER;
344 case media::AudioPolicyForcedConfig::HEADPHONES:
345 return AUDIO_POLICY_FORCE_HEADPHONES;
346 case media::AudioPolicyForcedConfig::BT_SCO:
347 return AUDIO_POLICY_FORCE_BT_SCO;
348 case media::AudioPolicyForcedConfig::BT_A2DP:
349 return AUDIO_POLICY_FORCE_BT_A2DP;
350 case media::AudioPolicyForcedConfig::WIRED_ACCESSORY:
351 return AUDIO_POLICY_FORCE_WIRED_ACCESSORY;
352 case media::AudioPolicyForcedConfig::BT_CAR_DOCK:
353 return AUDIO_POLICY_FORCE_BT_CAR_DOCK;
354 case media::AudioPolicyForcedConfig::BT_DESK_DOCK:
355 return AUDIO_POLICY_FORCE_BT_DESK_DOCK;
356 case media::AudioPolicyForcedConfig::ANALOG_DOCK:
357 return AUDIO_POLICY_FORCE_ANALOG_DOCK;
358 case media::AudioPolicyForcedConfig::DIGITAL_DOCK:
359 return AUDIO_POLICY_FORCE_DIGITAL_DOCK;
360 case media::AudioPolicyForcedConfig::NO_BT_A2DP:
361 return AUDIO_POLICY_FORCE_NO_BT_A2DP;
362 case media::AudioPolicyForcedConfig::SYSTEM_ENFORCED:
363 return AUDIO_POLICY_FORCE_SYSTEM_ENFORCED;
364 case media::AudioPolicyForcedConfig::HDMI_SYSTEM_AUDIO_ENFORCED:
365 return AUDIO_POLICY_FORCE_HDMI_SYSTEM_AUDIO_ENFORCED;
366 case media::AudioPolicyForcedConfig::ENCODED_SURROUND_NEVER:
367 return AUDIO_POLICY_FORCE_ENCODED_SURROUND_NEVER;
368 case media::AudioPolicyForcedConfig::ENCODED_SURROUND_ALWAYS:
369 return AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS;
370 case media::AudioPolicyForcedConfig::ENCODED_SURROUND_MANUAL:
371 return AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL;
372 }
373 return unexpected(BAD_VALUE);
374 }
375
376 ConversionResult<media::AudioPolicyForcedConfig>
legacy2aidl_audio_policy_forced_cfg_t_AudioPolicyForcedConfig(audio_policy_forced_cfg_t legacy)377 legacy2aidl_audio_policy_forced_cfg_t_AudioPolicyForcedConfig(audio_policy_forced_cfg_t legacy) {
378 switch (legacy) {
379 case AUDIO_POLICY_FORCE_NONE:
380 return media::AudioPolicyForcedConfig::NONE;
381 case AUDIO_POLICY_FORCE_SPEAKER:
382 return media::AudioPolicyForcedConfig::SPEAKER;
383 case AUDIO_POLICY_FORCE_HEADPHONES:
384 return media::AudioPolicyForcedConfig::HEADPHONES;
385 case AUDIO_POLICY_FORCE_BT_SCO:
386 return media::AudioPolicyForcedConfig::BT_SCO;
387 case AUDIO_POLICY_FORCE_BT_A2DP:
388 return media::AudioPolicyForcedConfig::BT_A2DP;
389 case AUDIO_POLICY_FORCE_WIRED_ACCESSORY:
390 return media::AudioPolicyForcedConfig::WIRED_ACCESSORY;
391 case AUDIO_POLICY_FORCE_BT_CAR_DOCK:
392 return media::AudioPolicyForcedConfig::BT_CAR_DOCK;
393 case AUDIO_POLICY_FORCE_BT_DESK_DOCK:
394 return media::AudioPolicyForcedConfig::BT_DESK_DOCK;
395 case AUDIO_POLICY_FORCE_ANALOG_DOCK:
396 return media::AudioPolicyForcedConfig::ANALOG_DOCK;
397 case AUDIO_POLICY_FORCE_DIGITAL_DOCK:
398 return media::AudioPolicyForcedConfig::DIGITAL_DOCK;
399 case AUDIO_POLICY_FORCE_NO_BT_A2DP:
400 return media::AudioPolicyForcedConfig::NO_BT_A2DP;
401 case AUDIO_POLICY_FORCE_SYSTEM_ENFORCED:
402 return media::AudioPolicyForcedConfig::SYSTEM_ENFORCED;
403 case AUDIO_POLICY_FORCE_HDMI_SYSTEM_AUDIO_ENFORCED:
404 return media::AudioPolicyForcedConfig::HDMI_SYSTEM_AUDIO_ENFORCED;
405 case AUDIO_POLICY_FORCE_ENCODED_SURROUND_NEVER:
406 return media::AudioPolicyForcedConfig::ENCODED_SURROUND_NEVER;
407 case AUDIO_POLICY_FORCE_ENCODED_SURROUND_ALWAYS:
408 return media::AudioPolicyForcedConfig::ENCODED_SURROUND_ALWAYS;
409 case AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL:
410 return media::AudioPolicyForcedConfig::ENCODED_SURROUND_MANUAL;
411 case AUDIO_POLICY_FORCE_CFG_CNT:
412 break;
413 }
414 return unexpected(BAD_VALUE);
415 }
416
417 ConversionResult<device_role_t>
aidl2legacy_DeviceRole_device_role_t(media::DeviceRole aidl)418 aidl2legacy_DeviceRole_device_role_t(media::DeviceRole aidl) {
419 switch (aidl) {
420 case media::DeviceRole::NONE:
421 return DEVICE_ROLE_NONE;
422 case media::DeviceRole::PREFERRED:
423 return DEVICE_ROLE_PREFERRED;
424 case media::DeviceRole::DISABLED:
425 return DEVICE_ROLE_DISABLED;
426 }
427 return unexpected(BAD_VALUE);
428 }
429
430 ConversionResult<media::DeviceRole>
legacy2aidl_device_role_t_DeviceRole(device_role_t legacy)431 legacy2aidl_device_role_t_DeviceRole(device_role_t legacy) {
432 switch (legacy) {
433 case DEVICE_ROLE_NONE:
434 return media::DeviceRole::NONE;
435 case DEVICE_ROLE_PREFERRED:
436 return media::DeviceRole::PREFERRED;
437 case DEVICE_ROLE_DISABLED:
438 return media::DeviceRole::DISABLED;
439 }
440 return unexpected(BAD_VALUE);
441 }
442
443 ConversionResult<audio_offload_mode_t>
aidl2legacy_AudioOffloadMode_audio_offload_mode_t(media::AudioOffloadMode aidl)444 aidl2legacy_AudioOffloadMode_audio_offload_mode_t(media::AudioOffloadMode aidl) {
445 switch (aidl) {
446 case media::AudioOffloadMode::NOT_SUPPORTED:
447 return AUDIO_OFFLOAD_NOT_SUPPORTED;
448 case media::AudioOffloadMode::SUPPORTED:
449 return AUDIO_OFFLOAD_SUPPORTED;
450 case media::AudioOffloadMode::GAPLESS_SUPPORTED:
451 return AUDIO_OFFLOAD_GAPLESS_SUPPORTED;
452 }
453 return unexpected(BAD_VALUE);
454 }
455
456 ConversionResult<media::AudioOffloadMode>
legacy2aidl_audio_offload_mode_t_AudioOffloadMode(audio_offload_mode_t legacy)457 legacy2aidl_audio_offload_mode_t_AudioOffloadMode(audio_offload_mode_t legacy) {
458 switch (legacy) {
459 case AUDIO_OFFLOAD_NOT_SUPPORTED:
460 return media::AudioOffloadMode::NOT_SUPPORTED;
461 case AUDIO_OFFLOAD_SUPPORTED:
462 return media::AudioOffloadMode::SUPPORTED;
463 case AUDIO_OFFLOAD_GAPLESS_SUPPORTED:
464 return media::AudioOffloadMode::GAPLESS_SUPPORTED;
465 }
466 return unexpected(BAD_VALUE);
467 }
468
469 } // namespace android
470