Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 17 | #define LOG_TAG "AidlConversion" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #include <system/audio.h> |
| 20 | #include <utils/Log.h> |
| 21 | |
| 22 | #include "media/AidlConversion.h" |
| 23 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 24 | #include <media/ShmemCompat.h> |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 25 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 26 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 27 | // Utilities |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | using base::unexpected; |
| 32 | |
| 33 | namespace { |
| 34 | |
| 35 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 36 | // The code below establishes: |
| 37 | // IntegralTypeOf<T>, which works for either integral types (in which case it evaluates to T), or |
| 38 | // enum types (in which case it evaluates to std::underlying_type_T<T>). |
| 39 | |
| 40 | template<typename T, typename = std::enable_if_t<std::is_integral_v<T> || std::is_enum_v<T>>> |
| 41 | struct IntegralTypeOfStruct { |
| 42 | using Type = T; |
| 43 | }; |
| 44 | |
| 45 | template<typename T> |
| 46 | struct IntegralTypeOfStruct<T, std::enable_if_t<std::is_enum_v<T>>> { |
| 47 | using Type = std::underlying_type_t<T>; |
| 48 | }; |
| 49 | |
| 50 | template<typename T> |
| 51 | using IntegralTypeOf = typename IntegralTypeOfStruct<T>::Type; |
| 52 | |
| 53 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 54 | // Utilities for handling bitmasks. |
| 55 | |
| 56 | template<typename Enum> |
| 57 | Enum index2enum_index(int index) { |
| 58 | static_assert(std::is_enum_v<Enum> || std::is_integral_v<Enum>); |
| 59 | return static_cast<Enum>(index); |
| 60 | } |
| 61 | |
| 62 | template<typename Enum> |
| 63 | Enum index2enum_bitmask(int index) { |
| 64 | static_assert(std::is_enum_v<Enum> || std::is_integral_v<Enum>); |
| 65 | return static_cast<Enum>(1 << index); |
| 66 | } |
| 67 | |
| 68 | template<typename Mask, typename Enum> |
| 69 | Mask enumToMask_bitmask(Enum e) { |
| 70 | static_assert(std::is_enum_v<Enum> || std::is_integral_v<Enum>); |
| 71 | static_assert(std::is_enum_v<Mask> || std::is_integral_v<Mask>); |
| 72 | return static_cast<Mask>(e); |
| 73 | } |
| 74 | |
| 75 | template<typename Mask, typename Enum> |
| 76 | Mask enumToMask_index(Enum e) { |
| 77 | static_assert(std::is_enum_v<Enum> || std::is_integral_v<Enum>); |
| 78 | static_assert(std::is_enum_v<Mask> || std::is_integral_v<Mask>); |
| 79 | return static_cast<Mask>(static_cast<std::make_unsigned_t<IntegralTypeOf<Mask>>>(1) |
| 80 | << static_cast<int>(e)); |
| 81 | } |
| 82 | |
| 83 | template<typename DestMask, typename SrcMask, typename DestEnum, typename SrcEnum> |
| 84 | ConversionResult<DestMask> convertBitmask( |
| 85 | SrcMask src, const std::function<ConversionResult<DestEnum>(SrcEnum)>& enumConversion, |
| 86 | const std::function<SrcEnum(int)>& srcIndexToEnum, |
| 87 | const std::function<DestMask(DestEnum)>& destEnumToMask) { |
| 88 | using UnsignedDestMask = std::make_unsigned_t<IntegralTypeOf<DestMask>>; |
| 89 | using UnsignedSrcMask = std::make_unsigned_t<IntegralTypeOf<SrcMask>>; |
| 90 | |
| 91 | UnsignedDestMask dest = static_cast<UnsignedDestMask>(0); |
| 92 | UnsignedSrcMask usrc = static_cast<UnsignedSrcMask>(src); |
| 93 | |
| 94 | int srcBitIndex = 0; |
| 95 | while (usrc != 0) { |
| 96 | if (usrc & 1) { |
| 97 | SrcEnum srcEnum = srcIndexToEnum(srcBitIndex); |
| 98 | DestEnum destEnum = VALUE_OR_RETURN(enumConversion(srcEnum)); |
| 99 | DestMask destMask = destEnumToMask(destEnum); |
| 100 | dest |= destMask; |
| 101 | } |
| 102 | ++srcBitIndex; |
| 103 | usrc >>= 1; |
| 104 | } |
| 105 | return static_cast<DestMask>(dest); |
| 106 | } |
| 107 | |
| 108 | template<typename Mask, typename Enum> |
| 109 | bool bitmaskIsSet(Mask mask, Enum index) { |
| 110 | return (mask & enumToMask_index<Mask, Enum>(index)) != 0; |
| 111 | } |
| 112 | |
| 113 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 114 | // Utilities for working with AIDL unions. |
| 115 | // UNION_GET(obj, fieldname) returns a ConversionResult<T> containing either the strongly-typed |
| 116 | // value of the respective field, or BAD_VALUE if the union is not set to the requested field. |
| 117 | // UNION_SET(obj, fieldname, value) sets the requested field to the given value. |
| 118 | |
| 119 | template<typename T, typename T::Tag tag> |
| 120 | using UnionFieldType = std::decay_t<decltype(std::declval<T>().template get<tag>())>; |
| 121 | |
| 122 | template<typename T, typename T::Tag tag> |
| 123 | ConversionResult<UnionFieldType<T, tag>> unionGetField(const T& u) { |
| 124 | if (u.getTag() != tag) { |
| 125 | return unexpected(BAD_VALUE); |
| 126 | } |
| 127 | return u.template get<tag>(); |
| 128 | } |
| 129 | |
| 130 | #define UNION_GET(u, field) \ |
| 131 | unionGetField<std::decay_t<decltype(u)>, std::decay_t<decltype(u)>::Tag::field>(u) |
| 132 | |
| 133 | #define UNION_SET(u, field, value) \ |
| 134 | (u).set<std::decay_t<decltype(u)>::Tag::field>(value) |
| 135 | |
| 136 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 137 | |
| 138 | template<typename To, typename From> |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 139 | ConversionResult<To> convertReinterpret(From from) { |
| 140 | static_assert(sizeof(From) == sizeof(To)); |
| 141 | return static_cast<To>(from); |
| 142 | } |
| 143 | |
| 144 | enum class Direction { |
| 145 | INPUT, OUTPUT |
| 146 | }; |
| 147 | |
| 148 | ConversionResult<Direction> direction(media::AudioPortRole role, media::AudioPortType type) { |
| 149 | switch (type) { |
| 150 | case media::AudioPortType::DEVICE: |
| 151 | switch (role) { |
| 152 | case media::AudioPortRole::SOURCE: |
| 153 | return Direction::INPUT; |
| 154 | case media::AudioPortRole::SINK: |
| 155 | return Direction::OUTPUT; |
| 156 | default: |
| 157 | break; |
| 158 | } |
| 159 | break; |
| 160 | case media::AudioPortType::MIX: |
| 161 | switch (role) { |
| 162 | case media::AudioPortRole::SOURCE: |
| 163 | return Direction::OUTPUT; |
| 164 | case media::AudioPortRole::SINK: |
| 165 | return Direction::INPUT; |
| 166 | default: |
| 167 | break; |
| 168 | } |
| 169 | break; |
| 170 | default: |
| 171 | break; |
| 172 | } |
| 173 | return unexpected(BAD_VALUE); |
| 174 | } |
| 175 | |
| 176 | ConversionResult<Direction> direction(audio_port_role_t role, audio_port_type_t type) { |
| 177 | switch (type) { |
| 178 | case AUDIO_PORT_TYPE_DEVICE: |
| 179 | switch (role) { |
| 180 | case AUDIO_PORT_ROLE_SOURCE: |
| 181 | return Direction::INPUT; |
| 182 | case AUDIO_PORT_ROLE_SINK: |
| 183 | return Direction::OUTPUT; |
| 184 | default: |
| 185 | break; |
| 186 | } |
| 187 | break; |
| 188 | case AUDIO_PORT_TYPE_MIX: |
| 189 | switch (role) { |
| 190 | case AUDIO_PORT_ROLE_SOURCE: |
| 191 | return Direction::OUTPUT; |
| 192 | case AUDIO_PORT_ROLE_SINK: |
| 193 | return Direction::INPUT; |
| 194 | default: |
| 195 | break; |
| 196 | } |
| 197 | break; |
| 198 | default: |
| 199 | break; |
| 200 | } |
| 201 | return unexpected(BAD_VALUE); |
| 202 | } |
| 203 | |
| 204 | } // namespace |
| 205 | |
| 206 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 207 | // Converters |
| 208 | |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 209 | status_t aidl2legacy_string(std::string_view aidl, char* dest, size_t maxSize) { |
| 210 | if (aidl.size() > maxSize - 1) { |
| 211 | return BAD_VALUE; |
| 212 | } |
| 213 | aidl.copy(dest, aidl.size()); |
| 214 | dest[aidl.size()] = '\0'; |
| 215 | return OK; |
| 216 | } |
| 217 | |
| 218 | ConversionResult<std::string> legacy2aidl_string(const char* legacy, size_t maxSize) { |
| 219 | if (legacy == nullptr) { |
| 220 | return unexpected(BAD_VALUE); |
| 221 | } |
| 222 | if (strnlen(legacy, maxSize) == maxSize) { |
| 223 | // No null-terminator. |
| 224 | return unexpected(BAD_VALUE); |
| 225 | } |
| 226 | return std::string(legacy); |
| 227 | } |
| 228 | |
| 229 | ConversionResult<audio_module_handle_t> aidl2legacy_int32_t_audio_module_handle_t(int32_t aidl) { |
| 230 | return convertReinterpret<audio_module_handle_t>(aidl); |
| 231 | } |
| 232 | |
| 233 | ConversionResult<int32_t> legacy2aidl_audio_module_handle_t_int32_t(audio_module_handle_t legacy) { |
| 234 | return convertReinterpret<int32_t>(legacy); |
| 235 | } |
| 236 | |
| 237 | ConversionResult<audio_io_handle_t> aidl2legacy_int32_t_audio_io_handle_t(int32_t aidl) { |
| 238 | return convertReinterpret<audio_io_handle_t>(aidl); |
| 239 | } |
| 240 | |
| 241 | ConversionResult<int32_t> legacy2aidl_audio_io_handle_t_int32_t(audio_io_handle_t legacy) { |
| 242 | return convertReinterpret<int32_t>(legacy); |
| 243 | } |
| 244 | |
| 245 | ConversionResult<audio_port_handle_t> aidl2legacy_int32_t_audio_port_handle_t(int32_t aidl) { |
| 246 | return convertReinterpret<audio_port_handle_t>(aidl); |
| 247 | } |
| 248 | |
| 249 | ConversionResult<int32_t> legacy2aidl_audio_port_handle_t_int32_t(audio_port_handle_t legacy) { |
| 250 | return convertReinterpret<int32_t>(legacy); |
| 251 | } |
| 252 | |
| 253 | ConversionResult<audio_patch_handle_t> aidl2legacy_int32_t_audio_patch_handle_t(int32_t aidl) { |
| 254 | return convertReinterpret<audio_patch_handle_t>(aidl); |
| 255 | } |
| 256 | |
| 257 | ConversionResult<int32_t> legacy2aidl_audio_patch_handle_t_int32_t(audio_patch_handle_t legacy) { |
| 258 | return convertReinterpret<int32_t>(legacy); |
| 259 | } |
| 260 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 261 | ConversionResult<audio_unique_id_t> aidl2legacy_int32_t_audio_unique_id_t(int32_t aidl) { |
| 262 | return convertReinterpret<audio_unique_id_t>(aidl); |
| 263 | } |
| 264 | |
| 265 | ConversionResult<int32_t> legacy2aidl_audio_unique_id_t_int32_t(audio_unique_id_t legacy) { |
| 266 | return convertReinterpret<int32_t>(legacy); |
| 267 | } |
| 268 | |
| 269 | ConversionResult<pid_t> aidl2legacy_int32_t_pid_t(int32_t aidl) { |
| 270 | return convertReinterpret<pid_t>(aidl); |
| 271 | } |
| 272 | |
| 273 | ConversionResult<int32_t> legacy2aidl_pid_t_int32_t(pid_t legacy) { |
| 274 | return convertReinterpret<int32_t>(legacy); |
| 275 | } |
| 276 | |
| 277 | ConversionResult<uid_t> aidl2legacy_int32_t_uid_t(int32_t aidl) { |
| 278 | return convertReinterpret<uid_t>(aidl); |
| 279 | } |
| 280 | |
| 281 | ConversionResult<int32_t> legacy2aidl_uid_t_int32_t(uid_t legacy) { |
| 282 | return convertReinterpret<int32_t>(legacy); |
| 283 | } |
| 284 | |
| 285 | ConversionResult<String16> aidl2legacy_string_view_String16(std::string_view aidl) { |
| 286 | return String16(aidl.data(), aidl.size()); |
| 287 | } |
| 288 | |
| 289 | ConversionResult<std::string> legacy2aidl_String16_string(const String16& legacy) { |
| 290 | return std::string(String8(legacy).c_str()); |
| 291 | } |
| 292 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 293 | // The legacy enum is unnamed. Thus, we use int. |
| 294 | ConversionResult<int> aidl2legacy_AudioPortConfigType(media::AudioPortConfigType aidl) { |
| 295 | switch (aidl) { |
| 296 | case media::AudioPortConfigType::SAMPLE_RATE: |
| 297 | return AUDIO_PORT_CONFIG_SAMPLE_RATE; |
| 298 | case media::AudioPortConfigType::CHANNEL_MASK: |
| 299 | return AUDIO_PORT_CONFIG_CHANNEL_MASK; |
| 300 | case media::AudioPortConfigType::FORMAT: |
| 301 | return AUDIO_PORT_CONFIG_FORMAT; |
| 302 | case media::AudioPortConfigType::FLAGS: |
| 303 | return AUDIO_PORT_CONFIG_FLAGS; |
| 304 | default: |
| 305 | return unexpected(BAD_VALUE); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | // The legacy enum is unnamed. Thus, we use int. |
| 310 | ConversionResult<media::AudioPortConfigType> legacy2aidl_AudioPortConfigType(int legacy) { |
| 311 | switch (legacy) { |
| 312 | case AUDIO_PORT_CONFIG_SAMPLE_RATE: |
| 313 | return media::AudioPortConfigType::SAMPLE_RATE; |
| 314 | case AUDIO_PORT_CONFIG_CHANNEL_MASK: |
| 315 | return media::AudioPortConfigType::CHANNEL_MASK; |
| 316 | case AUDIO_PORT_CONFIG_FORMAT: |
| 317 | return media::AudioPortConfigType::FORMAT; |
| 318 | case AUDIO_PORT_CONFIG_FLAGS: |
| 319 | return media::AudioPortConfigType::FLAGS; |
| 320 | default: |
| 321 | return unexpected(BAD_VALUE); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | ConversionResult<unsigned int> aidl2legacy_int32_t_config_mask(int32_t aidl) { |
| 326 | return convertBitmask<unsigned int, int32_t, int, media::AudioPortConfigType>( |
| 327 | aidl, aidl2legacy_AudioPortConfigType, |
| 328 | // AudioPortConfigType enum is index-based. |
| 329 | index2enum_index<media::AudioPortConfigType>, |
| 330 | // AUDIO_PORT_CONFIG_* flags are mask-based. |
| 331 | enumToMask_bitmask<unsigned int, int>); |
| 332 | } |
| 333 | |
| 334 | ConversionResult<int32_t> legacy2aidl_config_mask_int32_t(unsigned int legacy) { |
| 335 | return convertBitmask<int32_t, unsigned int, media::AudioPortConfigType, int>( |
| 336 | legacy, legacy2aidl_AudioPortConfigType, |
| 337 | // AUDIO_PORT_CONFIG_* flags are mask-based. |
| 338 | index2enum_bitmask<unsigned>, |
| 339 | // AudioPortConfigType enum is index-based. |
| 340 | enumToMask_index<int32_t, media::AudioPortConfigType>); |
| 341 | } |
| 342 | |
| 343 | ConversionResult<audio_channel_mask_t> aidl2legacy_int32_t_audio_channel_mask_t(int32_t aidl) { |
| 344 | // TODO(ytai): should we convert bit-by-bit? |
| 345 | // One problem here is that the representation is both opaque and is different based on the |
| 346 | // context (input vs. output). Can determine based on type and role, as per useInChannelMask(). |
| 347 | return convertReinterpret<audio_channel_mask_t>(aidl); |
| 348 | } |
| 349 | |
| 350 | ConversionResult<int32_t> legacy2aidl_audio_channel_mask_t_int32_t(audio_channel_mask_t legacy) { |
| 351 | // TODO(ytai): should we convert bit-by-bit? |
| 352 | // One problem here is that the representation is both opaque and is different based on the |
| 353 | // context (input vs. output). Can determine based on type and role, as per useInChannelMask(). |
| 354 | return convertReinterpret<int32_t>(legacy); |
| 355 | } |
| 356 | |
| 357 | ConversionResult<audio_io_config_event> aidl2legacy_AudioIoConfigEvent_audio_io_config_event( |
| 358 | media::AudioIoConfigEvent aidl) { |
| 359 | switch (aidl) { |
| 360 | case media::AudioIoConfigEvent::OUTPUT_REGISTERED: |
| 361 | return AUDIO_OUTPUT_REGISTERED; |
| 362 | case media::AudioIoConfigEvent::OUTPUT_OPENED: |
| 363 | return AUDIO_OUTPUT_OPENED; |
| 364 | case media::AudioIoConfigEvent::OUTPUT_CLOSED: |
| 365 | return AUDIO_OUTPUT_CLOSED; |
| 366 | case media::AudioIoConfigEvent::OUTPUT_CONFIG_CHANGED: |
| 367 | return AUDIO_OUTPUT_CONFIG_CHANGED; |
| 368 | case media::AudioIoConfigEvent::INPUT_REGISTERED: |
| 369 | return AUDIO_INPUT_REGISTERED; |
| 370 | case media::AudioIoConfigEvent::INPUT_OPENED: |
| 371 | return AUDIO_INPUT_OPENED; |
| 372 | case media::AudioIoConfigEvent::INPUT_CLOSED: |
| 373 | return AUDIO_INPUT_CLOSED; |
| 374 | case media::AudioIoConfigEvent::INPUT_CONFIG_CHANGED: |
| 375 | return AUDIO_INPUT_CONFIG_CHANGED; |
| 376 | case media::AudioIoConfigEvent::CLIENT_STARTED: |
| 377 | return AUDIO_CLIENT_STARTED; |
| 378 | default: |
| 379 | return unexpected(BAD_VALUE); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | ConversionResult<media::AudioIoConfigEvent> legacy2aidl_audio_io_config_event_AudioIoConfigEvent( |
| 384 | audio_io_config_event legacy) { |
| 385 | switch (legacy) { |
| 386 | case AUDIO_OUTPUT_REGISTERED: |
| 387 | return media::AudioIoConfigEvent::OUTPUT_REGISTERED; |
| 388 | case AUDIO_OUTPUT_OPENED: |
| 389 | return media::AudioIoConfigEvent::OUTPUT_OPENED; |
| 390 | case AUDIO_OUTPUT_CLOSED: |
| 391 | return media::AudioIoConfigEvent::OUTPUT_CLOSED; |
| 392 | case AUDIO_OUTPUT_CONFIG_CHANGED: |
| 393 | return media::AudioIoConfigEvent::OUTPUT_CONFIG_CHANGED; |
| 394 | case AUDIO_INPUT_REGISTERED: |
| 395 | return media::AudioIoConfigEvent::INPUT_REGISTERED; |
| 396 | case AUDIO_INPUT_OPENED: |
| 397 | return media::AudioIoConfigEvent::INPUT_OPENED; |
| 398 | case AUDIO_INPUT_CLOSED: |
| 399 | return media::AudioIoConfigEvent::INPUT_CLOSED; |
| 400 | case AUDIO_INPUT_CONFIG_CHANGED: |
| 401 | return media::AudioIoConfigEvent::INPUT_CONFIG_CHANGED; |
| 402 | case AUDIO_CLIENT_STARTED: |
| 403 | return media::AudioIoConfigEvent::CLIENT_STARTED; |
| 404 | default: |
| 405 | return unexpected(BAD_VALUE); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | ConversionResult<audio_port_role_t> aidl2legacy_AudioPortRole_audio_port_role_t( |
| 410 | media::AudioPortRole aidl) { |
| 411 | switch (aidl) { |
| 412 | case media::AudioPortRole::NONE: |
| 413 | return AUDIO_PORT_ROLE_NONE; |
| 414 | case media::AudioPortRole::SOURCE: |
| 415 | return AUDIO_PORT_ROLE_SOURCE; |
| 416 | case media::AudioPortRole::SINK: |
| 417 | return AUDIO_PORT_ROLE_SINK; |
| 418 | default: |
| 419 | return unexpected(BAD_VALUE); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | ConversionResult<media::AudioPortRole> legacy2aidl_audio_port_role_t_AudioPortRole( |
| 424 | audio_port_role_t legacy) { |
| 425 | switch (legacy) { |
| 426 | case AUDIO_PORT_ROLE_NONE: |
| 427 | return media::AudioPortRole::NONE; |
| 428 | case AUDIO_PORT_ROLE_SOURCE: |
| 429 | return media::AudioPortRole::SOURCE; |
| 430 | case AUDIO_PORT_ROLE_SINK: |
| 431 | return media::AudioPortRole::SINK; |
| 432 | default: |
| 433 | return unexpected(BAD_VALUE); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | ConversionResult<audio_port_type_t> aidl2legacy_AudioPortType_audio_port_type_t( |
| 438 | media::AudioPortType aidl) { |
| 439 | switch (aidl) { |
| 440 | case media::AudioPortType::NONE: |
| 441 | return AUDIO_PORT_TYPE_NONE; |
| 442 | case media::AudioPortType::DEVICE: |
| 443 | return AUDIO_PORT_TYPE_DEVICE; |
| 444 | case media::AudioPortType::MIX: |
| 445 | return AUDIO_PORT_TYPE_MIX; |
| 446 | case media::AudioPortType::SESSION: |
| 447 | return AUDIO_PORT_TYPE_SESSION; |
| 448 | default: |
| 449 | return unexpected(BAD_VALUE); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | ConversionResult<media::AudioPortType> legacy2aidl_audio_port_type_t_AudioPortType( |
| 454 | audio_port_type_t legacy) { |
| 455 | switch (legacy) { |
| 456 | case AUDIO_PORT_TYPE_NONE: |
| 457 | return media::AudioPortType::NONE; |
| 458 | case AUDIO_PORT_TYPE_DEVICE: |
| 459 | return media::AudioPortType::DEVICE; |
| 460 | case AUDIO_PORT_TYPE_MIX: |
| 461 | return media::AudioPortType::MIX; |
| 462 | case AUDIO_PORT_TYPE_SESSION: |
| 463 | return media::AudioPortType::SESSION; |
| 464 | default: |
| 465 | return unexpected(BAD_VALUE); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | ConversionResult<audio_format_t> aidl2legacy_AudioFormat_audio_format_t( |
| 470 | media::audio::common::AudioFormat aidl) { |
| 471 | // This relies on AudioFormat being kept in sync with audio_format_t. |
| 472 | static_assert(sizeof(media::audio::common::AudioFormat) == sizeof(audio_format_t)); |
| 473 | return static_cast<audio_format_t>(aidl); |
| 474 | } |
| 475 | |
| 476 | ConversionResult<media::audio::common::AudioFormat> legacy2aidl_audio_format_t_AudioFormat( |
| 477 | audio_format_t legacy) { |
| 478 | // This relies on AudioFormat being kept in sync with audio_format_t. |
| 479 | static_assert(sizeof(media::audio::common::AudioFormat) == sizeof(audio_format_t)); |
| 480 | return static_cast<media::audio::common::AudioFormat>(legacy); |
| 481 | } |
| 482 | |
| 483 | ConversionResult<int> aidl2legacy_AudioGainMode_int(media::AudioGainMode aidl) { |
| 484 | switch (aidl) { |
| 485 | case media::AudioGainMode::JOINT: |
| 486 | return AUDIO_GAIN_MODE_JOINT; |
| 487 | case media::AudioGainMode::CHANNELS: |
| 488 | return AUDIO_GAIN_MODE_CHANNELS; |
| 489 | case media::AudioGainMode::RAMP: |
| 490 | return AUDIO_GAIN_MODE_RAMP; |
| 491 | default: |
| 492 | return unexpected(BAD_VALUE); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | ConversionResult<media::AudioGainMode> legacy2aidl_int_AudioGainMode(int legacy) { |
| 497 | switch (legacy) { |
| 498 | case AUDIO_GAIN_MODE_JOINT: |
| 499 | return media::AudioGainMode::JOINT; |
| 500 | case AUDIO_GAIN_MODE_CHANNELS: |
| 501 | return media::AudioGainMode::CHANNELS; |
| 502 | case AUDIO_GAIN_MODE_RAMP: |
| 503 | return media::AudioGainMode::RAMP; |
| 504 | default: |
| 505 | return unexpected(BAD_VALUE); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | ConversionResult<audio_gain_mode_t> aidl2legacy_int32_t_audio_gain_mode_t(int32_t aidl) { |
| 510 | return convertBitmask<audio_gain_mode_t, int32_t, int, media::AudioGainMode>( |
| 511 | aidl, aidl2legacy_AudioGainMode_int, |
| 512 | // AudioGainMode is index-based. |
| 513 | index2enum_index<media::AudioGainMode>, |
| 514 | // AUDIO_GAIN_MODE_* constants are mask-based. |
| 515 | enumToMask_bitmask<audio_gain_mode_t, int>); |
| 516 | } |
| 517 | |
| 518 | ConversionResult<int32_t> legacy2aidl_audio_gain_mode_t_int32_t(audio_gain_mode_t legacy) { |
| 519 | return convertBitmask<int32_t, audio_gain_mode_t, media::AudioGainMode, int>( |
| 520 | legacy, legacy2aidl_int_AudioGainMode, |
| 521 | // AUDIO_GAIN_MODE_* constants are mask-based. |
| 522 | index2enum_bitmask<int>, |
| 523 | // AudioGainMode is index-based. |
| 524 | enumToMask_index<int32_t, media::AudioGainMode>); |
| 525 | } |
| 526 | |
| 527 | ConversionResult<audio_devices_t> aidl2legacy_int32_t_audio_devices_t(int32_t aidl) { |
| 528 | // TODO(ytai): bitfield? |
| 529 | return convertReinterpret<audio_devices_t>(aidl); |
| 530 | } |
| 531 | |
| 532 | ConversionResult<int32_t> legacy2aidl_audio_devices_t_int32_t(audio_devices_t legacy) { |
| 533 | // TODO(ytai): bitfield? |
| 534 | return convertReinterpret<int32_t>(legacy); |
| 535 | } |
| 536 | |
| 537 | ConversionResult<audio_gain_config> aidl2legacy_AudioGainConfig_audio_gain_config( |
| 538 | const media::AudioGainConfig& aidl, media::AudioPortRole role, media::AudioPortType type) { |
| 539 | audio_gain_config legacy; |
| 540 | legacy.index = VALUE_OR_RETURN(convertIntegral<int>(aidl.index)); |
| 541 | legacy.mode = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_gain_mode_t(aidl.mode)); |
| 542 | legacy.channel_mask = |
| 543 | VALUE_OR_RETURN(aidl2legacy_int32_t_audio_channel_mask_t(aidl.channelMask)); |
| 544 | const bool isInput = VALUE_OR_RETURN(direction(role, type)) == Direction::INPUT; |
| 545 | const bool isJoint = bitmaskIsSet(aidl.mode, media::AudioGainMode::JOINT); |
| 546 | size_t numValues = isJoint ? 1 |
| 547 | : isInput ? audio_channel_count_from_in_mask(legacy.channel_mask) |
| 548 | : audio_channel_count_from_out_mask(legacy.channel_mask); |
| 549 | if (aidl.values.size() != numValues || aidl.values.size() > std::size(legacy.values)) { |
| 550 | return unexpected(BAD_VALUE); |
| 551 | } |
| 552 | for (size_t i = 0; i < numValues; ++i) { |
| 553 | legacy.values[i] = VALUE_OR_RETURN(convertIntegral<int>(aidl.values[i])); |
| 554 | } |
| 555 | legacy.ramp_duration_ms = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.rampDurationMs)); |
| 556 | return legacy; |
| 557 | } |
| 558 | |
| 559 | ConversionResult<media::AudioGainConfig> legacy2aidl_audio_gain_config_AudioGainConfig( |
| 560 | const audio_gain_config& legacy, audio_port_role_t role, audio_port_type_t type) { |
| 561 | media::AudioGainConfig aidl; |
| 562 | aidl.index = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.index)); |
| 563 | aidl.mode = VALUE_OR_RETURN(legacy2aidl_audio_gain_mode_t_int32_t(legacy.mode)); |
| 564 | aidl.channelMask = |
| 565 | VALUE_OR_RETURN(legacy2aidl_audio_channel_mask_t_int32_t(legacy.channel_mask)); |
| 566 | const bool isInput = VALUE_OR_RETURN(direction(role, type)) == Direction::INPUT; |
| 567 | const bool isJoint = (legacy.mode & AUDIO_GAIN_MODE_JOINT) != 0; |
| 568 | size_t numValues = isJoint ? 1 |
| 569 | : isInput ? audio_channel_count_from_in_mask(legacy.channel_mask) |
| 570 | : audio_channel_count_from_out_mask(legacy.channel_mask); |
| 571 | aidl.values.resize(numValues); |
| 572 | for (size_t i = 0; i < numValues; ++i) { |
| 573 | aidl.values[i] = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.values[i])); |
| 574 | } |
| 575 | aidl.rampDurationMs = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.ramp_duration_ms)); |
| 576 | return aidl; |
| 577 | } |
| 578 | |
| 579 | ConversionResult<audio_input_flags_t> aidl2legacy_AudioInputFlags_audio_input_flags_t( |
| 580 | media::AudioInputFlags aidl) { |
| 581 | switch (aidl) { |
| 582 | case media::AudioInputFlags::FAST: |
| 583 | return AUDIO_INPUT_FLAG_FAST; |
| 584 | case media::AudioInputFlags::HW_HOTWORD: |
| 585 | return AUDIO_INPUT_FLAG_HW_HOTWORD; |
| 586 | case media::AudioInputFlags::RAW: |
| 587 | return AUDIO_INPUT_FLAG_RAW; |
| 588 | case media::AudioInputFlags::SYNC: |
| 589 | return AUDIO_INPUT_FLAG_SYNC; |
| 590 | case media::AudioInputFlags::MMAP_NOIRQ: |
| 591 | return AUDIO_INPUT_FLAG_MMAP_NOIRQ; |
| 592 | case media::AudioInputFlags::VOIP_TX: |
| 593 | return AUDIO_INPUT_FLAG_VOIP_TX; |
| 594 | case media::AudioInputFlags::HW_AV_SYNC: |
| 595 | return AUDIO_INPUT_FLAG_HW_AV_SYNC; |
| 596 | case media::AudioInputFlags::DIRECT: |
| 597 | return AUDIO_INPUT_FLAG_DIRECT; |
| 598 | default: |
| 599 | return unexpected(BAD_VALUE); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | ConversionResult<media::AudioInputFlags> legacy2aidl_audio_input_flags_t_AudioInputFlags( |
| 604 | audio_input_flags_t legacy) { |
| 605 | switch (legacy) { |
| 606 | case AUDIO_INPUT_FLAG_FAST: |
| 607 | return media::AudioInputFlags::FAST; |
| 608 | case AUDIO_INPUT_FLAG_HW_HOTWORD: |
| 609 | return media::AudioInputFlags::HW_HOTWORD; |
| 610 | case AUDIO_INPUT_FLAG_RAW: |
| 611 | return media::AudioInputFlags::RAW; |
| 612 | case AUDIO_INPUT_FLAG_SYNC: |
| 613 | return media::AudioInputFlags::SYNC; |
| 614 | case AUDIO_INPUT_FLAG_MMAP_NOIRQ: |
| 615 | return media::AudioInputFlags::MMAP_NOIRQ; |
| 616 | case AUDIO_INPUT_FLAG_VOIP_TX: |
| 617 | return media::AudioInputFlags::VOIP_TX; |
| 618 | case AUDIO_INPUT_FLAG_HW_AV_SYNC: |
| 619 | return media::AudioInputFlags::HW_AV_SYNC; |
| 620 | case AUDIO_INPUT_FLAG_DIRECT: |
| 621 | return media::AudioInputFlags::DIRECT; |
| 622 | default: |
| 623 | return unexpected(BAD_VALUE); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | ConversionResult<audio_output_flags_t> aidl2legacy_AudioOutputFlags_audio_output_flags_t( |
| 628 | media::AudioOutputFlags aidl) { |
| 629 | switch (aidl) { |
| 630 | case media::AudioOutputFlags::DIRECT: |
| 631 | return AUDIO_OUTPUT_FLAG_DIRECT; |
| 632 | case media::AudioOutputFlags::PRIMARY: |
| 633 | return AUDIO_OUTPUT_FLAG_PRIMARY; |
| 634 | case media::AudioOutputFlags::FAST: |
| 635 | return AUDIO_OUTPUT_FLAG_FAST; |
| 636 | case media::AudioOutputFlags::DEEP_BUFFER: |
| 637 | return AUDIO_OUTPUT_FLAG_DEEP_BUFFER; |
| 638 | case media::AudioOutputFlags::COMPRESS_OFFLOAD: |
| 639 | return AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD; |
| 640 | case media::AudioOutputFlags::NON_BLOCKING: |
| 641 | return AUDIO_OUTPUT_FLAG_NON_BLOCKING; |
| 642 | case media::AudioOutputFlags::HW_AV_SYNC: |
| 643 | return AUDIO_OUTPUT_FLAG_HW_AV_SYNC; |
| 644 | case media::AudioOutputFlags::TTS: |
| 645 | return AUDIO_OUTPUT_FLAG_TTS; |
| 646 | case media::AudioOutputFlags::RAW: |
| 647 | return AUDIO_OUTPUT_FLAG_RAW; |
| 648 | case media::AudioOutputFlags::SYNC: |
| 649 | return AUDIO_OUTPUT_FLAG_SYNC; |
| 650 | case media::AudioOutputFlags::IEC958_NONAUDIO: |
| 651 | return AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO; |
| 652 | case media::AudioOutputFlags::DIRECT_PCM: |
| 653 | return AUDIO_OUTPUT_FLAG_DIRECT_PCM; |
| 654 | case media::AudioOutputFlags::MMAP_NOIRQ: |
| 655 | return AUDIO_OUTPUT_FLAG_MMAP_NOIRQ; |
| 656 | case media::AudioOutputFlags::VOIP_RX: |
| 657 | return AUDIO_OUTPUT_FLAG_VOIP_RX; |
| 658 | case media::AudioOutputFlags::INCALL_MUSIC: |
| 659 | return AUDIO_OUTPUT_FLAG_INCALL_MUSIC; |
| 660 | default: |
| 661 | return unexpected(BAD_VALUE); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | ConversionResult<media::AudioOutputFlags> legacy2aidl_audio_output_flags_t_AudioOutputFlags( |
| 666 | audio_output_flags_t legacy) { |
| 667 | switch (legacy) { |
| 668 | case AUDIO_OUTPUT_FLAG_DIRECT: |
| 669 | return media::AudioOutputFlags::DIRECT; |
| 670 | case AUDIO_OUTPUT_FLAG_PRIMARY: |
| 671 | return media::AudioOutputFlags::PRIMARY; |
| 672 | case AUDIO_OUTPUT_FLAG_FAST: |
| 673 | return media::AudioOutputFlags::FAST; |
| 674 | case AUDIO_OUTPUT_FLAG_DEEP_BUFFER: |
| 675 | return media::AudioOutputFlags::DEEP_BUFFER; |
| 676 | case AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD: |
| 677 | return media::AudioOutputFlags::COMPRESS_OFFLOAD; |
| 678 | case AUDIO_OUTPUT_FLAG_NON_BLOCKING: |
| 679 | return media::AudioOutputFlags::NON_BLOCKING; |
| 680 | case AUDIO_OUTPUT_FLAG_HW_AV_SYNC: |
| 681 | return media::AudioOutputFlags::HW_AV_SYNC; |
| 682 | case AUDIO_OUTPUT_FLAG_TTS: |
| 683 | return media::AudioOutputFlags::TTS; |
| 684 | case AUDIO_OUTPUT_FLAG_RAW: |
| 685 | return media::AudioOutputFlags::RAW; |
| 686 | case AUDIO_OUTPUT_FLAG_SYNC: |
| 687 | return media::AudioOutputFlags::SYNC; |
| 688 | case AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO: |
| 689 | return media::AudioOutputFlags::IEC958_NONAUDIO; |
| 690 | case AUDIO_OUTPUT_FLAG_DIRECT_PCM: |
| 691 | return media::AudioOutputFlags::DIRECT_PCM; |
| 692 | case AUDIO_OUTPUT_FLAG_MMAP_NOIRQ: |
| 693 | return media::AudioOutputFlags::MMAP_NOIRQ; |
| 694 | case AUDIO_OUTPUT_FLAG_VOIP_RX: |
| 695 | return media::AudioOutputFlags::VOIP_RX; |
| 696 | case AUDIO_OUTPUT_FLAG_INCALL_MUSIC: |
| 697 | return media::AudioOutputFlags::INCALL_MUSIC; |
| 698 | default: |
| 699 | return unexpected(BAD_VALUE); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | ConversionResult<audio_input_flags_t> aidl2legacy_audio_input_flags_mask(int32_t aidl) { |
| 704 | using LegacyMask = std::underlying_type_t<audio_input_flags_t>; |
| 705 | |
| 706 | LegacyMask converted = VALUE_OR_RETURN( |
| 707 | (convertBitmask<LegacyMask, int32_t, audio_input_flags_t, media::AudioInputFlags>( |
| 708 | aidl, aidl2legacy_AudioInputFlags_audio_input_flags_t, |
| 709 | index2enum_index<media::AudioInputFlags>, |
| 710 | enumToMask_bitmask<LegacyMask, audio_input_flags_t>))); |
| 711 | return static_cast<audio_input_flags_t>(converted); |
| 712 | } |
| 713 | |
| 714 | ConversionResult<int32_t> legacy2aidl_audio_input_flags_mask(audio_input_flags_t legacy) { |
| 715 | using LegacyMask = std::underlying_type_t<audio_input_flags_t>; |
| 716 | |
| 717 | LegacyMask legacyMask = static_cast<LegacyMask>(legacy); |
| 718 | return convertBitmask<int32_t, LegacyMask, media::AudioInputFlags, audio_input_flags_t>( |
| 719 | legacyMask, legacy2aidl_audio_input_flags_t_AudioInputFlags, |
| 720 | index2enum_bitmask<audio_input_flags_t>, |
| 721 | enumToMask_index<int32_t, media::AudioInputFlags>); |
| 722 | } |
| 723 | |
| 724 | ConversionResult<audio_output_flags_t> aidl2legacy_audio_output_flags_mask(int32_t aidl) { |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 725 | return convertBitmask<audio_output_flags_t, |
| 726 | int32_t, |
| 727 | audio_output_flags_t, |
| 728 | media::AudioOutputFlags>( |
| 729 | aidl, aidl2legacy_AudioOutputFlags_audio_output_flags_t, |
| 730 | index2enum_index<media::AudioOutputFlags>, |
| 731 | enumToMask_bitmask<audio_output_flags_t, audio_output_flags_t>); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | ConversionResult<int32_t> legacy2aidl_audio_output_flags_mask(audio_output_flags_t legacy) { |
| 735 | using LegacyMask = std::underlying_type_t<audio_output_flags_t>; |
| 736 | |
| 737 | LegacyMask legacyMask = static_cast<LegacyMask>(legacy); |
| 738 | return convertBitmask<int32_t, LegacyMask, media::AudioOutputFlags, audio_output_flags_t>( |
| 739 | legacyMask, legacy2aidl_audio_output_flags_t_AudioOutputFlags, |
| 740 | index2enum_bitmask<audio_output_flags_t>, |
| 741 | enumToMask_index<int32_t, media::AudioOutputFlags>); |
| 742 | } |
| 743 | |
| 744 | ConversionResult<audio_io_flags> aidl2legacy_AudioIoFlags_audio_io_flags( |
| 745 | const media::AudioIoFlags& aidl, media::AudioPortRole role, media::AudioPortType type) { |
| 746 | audio_io_flags legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 747 | Direction dir = VALUE_OR_RETURN(direction(role, type)); |
| 748 | switch (dir) { |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 749 | case Direction::INPUT: { |
| 750 | legacy.input = VALUE_OR_RETURN( |
| 751 | aidl2legacy_audio_input_flags_mask(VALUE_OR_RETURN(UNION_GET(aidl, input)))); |
| 752 | } |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 753 | break; |
| 754 | |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 755 | case Direction::OUTPUT: { |
| 756 | legacy.output = VALUE_OR_RETURN( |
| 757 | aidl2legacy_audio_output_flags_mask(VALUE_OR_RETURN(UNION_GET(aidl, output)))); |
| 758 | } |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 759 | break; |
| 760 | } |
| 761 | |
| 762 | return legacy; |
| 763 | } |
| 764 | |
| 765 | ConversionResult<media::AudioIoFlags> legacy2aidl_audio_io_flags_AudioIoFlags( |
| 766 | const audio_io_flags& legacy, audio_port_role_t role, audio_port_type_t type) { |
| 767 | media::AudioIoFlags aidl; |
| 768 | |
| 769 | Direction dir = VALUE_OR_RETURN(direction(role, type)); |
| 770 | switch (dir) { |
| 771 | case Direction::INPUT: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 772 | UNION_SET(aidl, input, |
| 773 | VALUE_OR_RETURN(legacy2aidl_audio_input_flags_mask(legacy.input))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 774 | break; |
| 775 | case Direction::OUTPUT: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 776 | UNION_SET(aidl, output, |
| 777 | VALUE_OR_RETURN(legacy2aidl_audio_output_flags_mask(legacy.output))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 778 | break; |
| 779 | } |
| 780 | return aidl; |
| 781 | } |
| 782 | |
| 783 | ConversionResult<audio_port_config_device_ext> aidl2legacy_AudioPortConfigDeviceExt( |
| 784 | const media::AudioPortConfigDeviceExt& aidl) { |
| 785 | audio_port_config_device_ext legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 786 | legacy.hw_module = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_module_handle_t(aidl.hwModule)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 787 | legacy.type = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_devices_t(aidl.type)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 788 | RETURN_IF_ERROR(aidl2legacy_string(aidl.address, legacy.address, AUDIO_DEVICE_MAX_ADDRESS_LEN)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 789 | return legacy; |
| 790 | } |
| 791 | |
| 792 | ConversionResult<media::AudioPortConfigDeviceExt> legacy2aidl_AudioPortConfigDeviceExt( |
| 793 | const audio_port_config_device_ext& legacy) { |
| 794 | media::AudioPortConfigDeviceExt aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 795 | aidl.hwModule = VALUE_OR_RETURN(legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 796 | aidl.type = VALUE_OR_RETURN(legacy2aidl_audio_devices_t_int32_t(legacy.type)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 797 | aidl.address = VALUE_OR_RETURN( |
| 798 | legacy2aidl_string(legacy.address, AUDIO_DEVICE_MAX_ADDRESS_LEN)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 799 | return aidl; |
| 800 | } |
| 801 | |
| 802 | ConversionResult<audio_stream_type_t> aidl2legacy_AudioStreamType_audio_stream_type_t( |
| 803 | media::AudioStreamType aidl) { |
| 804 | switch (aidl) { |
| 805 | case media::AudioStreamType::DEFAULT: |
| 806 | return AUDIO_STREAM_DEFAULT; |
| 807 | case media::AudioStreamType::VOICE_CALL: |
| 808 | return AUDIO_STREAM_VOICE_CALL; |
| 809 | case media::AudioStreamType::SYSTEM: |
| 810 | return AUDIO_STREAM_SYSTEM; |
| 811 | case media::AudioStreamType::RING: |
| 812 | return AUDIO_STREAM_RING; |
| 813 | case media::AudioStreamType::MUSIC: |
| 814 | return AUDIO_STREAM_MUSIC; |
| 815 | case media::AudioStreamType::ALARM: |
| 816 | return AUDIO_STREAM_ALARM; |
| 817 | case media::AudioStreamType::NOTIFICATION: |
| 818 | return AUDIO_STREAM_NOTIFICATION; |
| 819 | case media::AudioStreamType::BLUETOOTH_SCO: |
| 820 | return AUDIO_STREAM_BLUETOOTH_SCO; |
| 821 | case media::AudioStreamType::ENFORCED_AUDIBLE: |
| 822 | return AUDIO_STREAM_ENFORCED_AUDIBLE; |
| 823 | case media::AudioStreamType::DTMF: |
| 824 | return AUDIO_STREAM_DTMF; |
| 825 | case media::AudioStreamType::TTS: |
| 826 | return AUDIO_STREAM_TTS; |
| 827 | case media::AudioStreamType::ACCESSIBILITY: |
| 828 | return AUDIO_STREAM_ACCESSIBILITY; |
| 829 | case media::AudioStreamType::ASSISTANT: |
| 830 | return AUDIO_STREAM_ASSISTANT; |
| 831 | case media::AudioStreamType::REROUTING: |
| 832 | return AUDIO_STREAM_REROUTING; |
| 833 | case media::AudioStreamType::PATCH: |
| 834 | return AUDIO_STREAM_PATCH; |
| 835 | case media::AudioStreamType::CALL_ASSISTANT: |
| 836 | return AUDIO_STREAM_CALL_ASSISTANT; |
| 837 | default: |
| 838 | return unexpected(BAD_VALUE); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | ConversionResult<media::AudioStreamType> legacy2aidl_audio_stream_type_t_AudioStreamType( |
| 843 | audio_stream_type_t legacy) { |
| 844 | switch (legacy) { |
| 845 | case AUDIO_STREAM_DEFAULT: |
| 846 | return media::AudioStreamType::DEFAULT; |
| 847 | case AUDIO_STREAM_VOICE_CALL: |
| 848 | return media::AudioStreamType::VOICE_CALL; |
| 849 | case AUDIO_STREAM_SYSTEM: |
| 850 | return media::AudioStreamType::SYSTEM; |
| 851 | case AUDIO_STREAM_RING: |
| 852 | return media::AudioStreamType::RING; |
| 853 | case AUDIO_STREAM_MUSIC: |
| 854 | return media::AudioStreamType::MUSIC; |
| 855 | case AUDIO_STREAM_ALARM: |
| 856 | return media::AudioStreamType::ALARM; |
| 857 | case AUDIO_STREAM_NOTIFICATION: |
| 858 | return media::AudioStreamType::NOTIFICATION; |
| 859 | case AUDIO_STREAM_BLUETOOTH_SCO: |
| 860 | return media::AudioStreamType::BLUETOOTH_SCO; |
| 861 | case AUDIO_STREAM_ENFORCED_AUDIBLE: |
| 862 | return media::AudioStreamType::ENFORCED_AUDIBLE; |
| 863 | case AUDIO_STREAM_DTMF: |
| 864 | return media::AudioStreamType::DTMF; |
| 865 | case AUDIO_STREAM_TTS: |
| 866 | return media::AudioStreamType::TTS; |
| 867 | case AUDIO_STREAM_ACCESSIBILITY: |
| 868 | return media::AudioStreamType::ACCESSIBILITY; |
| 869 | case AUDIO_STREAM_ASSISTANT: |
| 870 | return media::AudioStreamType::ASSISTANT; |
| 871 | case AUDIO_STREAM_REROUTING: |
| 872 | return media::AudioStreamType::REROUTING; |
| 873 | case AUDIO_STREAM_PATCH: |
| 874 | return media::AudioStreamType::PATCH; |
| 875 | case AUDIO_STREAM_CALL_ASSISTANT: |
| 876 | return media::AudioStreamType::CALL_ASSISTANT; |
| 877 | default: |
| 878 | return unexpected(BAD_VALUE); |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | ConversionResult<audio_source_t> aidl2legacy_AudioSourceType_audio_source_t( |
| 883 | media::AudioSourceType aidl) { |
| 884 | switch (aidl) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 885 | case media::AudioSourceType::INVALID: |
| 886 | // This value does not have an enum |
| 887 | return AUDIO_SOURCE_INVALID; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 888 | case media::AudioSourceType::DEFAULT: |
| 889 | return AUDIO_SOURCE_DEFAULT; |
| 890 | case media::AudioSourceType::MIC: |
| 891 | return AUDIO_SOURCE_MIC; |
| 892 | case media::AudioSourceType::VOICE_UPLINK: |
| 893 | return AUDIO_SOURCE_VOICE_UPLINK; |
| 894 | case media::AudioSourceType::VOICE_DOWNLINK: |
| 895 | return AUDIO_SOURCE_VOICE_DOWNLINK; |
| 896 | case media::AudioSourceType::VOICE_CALL: |
| 897 | return AUDIO_SOURCE_VOICE_CALL; |
| 898 | case media::AudioSourceType::CAMCORDER: |
| 899 | return AUDIO_SOURCE_CAMCORDER; |
| 900 | case media::AudioSourceType::VOICE_RECOGNITION: |
| 901 | return AUDIO_SOURCE_VOICE_RECOGNITION; |
| 902 | case media::AudioSourceType::VOICE_COMMUNICATION: |
| 903 | return AUDIO_SOURCE_VOICE_COMMUNICATION; |
| 904 | case media::AudioSourceType::REMOTE_SUBMIX: |
| 905 | return AUDIO_SOURCE_REMOTE_SUBMIX; |
| 906 | case media::AudioSourceType::UNPROCESSED: |
| 907 | return AUDIO_SOURCE_UNPROCESSED; |
| 908 | case media::AudioSourceType::VOICE_PERFORMANCE: |
| 909 | return AUDIO_SOURCE_VOICE_PERFORMANCE; |
| 910 | case media::AudioSourceType::ECHO_REFERENCE: |
| 911 | return AUDIO_SOURCE_ECHO_REFERENCE; |
| 912 | case media::AudioSourceType::FM_TUNER: |
| 913 | return AUDIO_SOURCE_FM_TUNER; |
| 914 | case media::AudioSourceType::HOTWORD: |
| 915 | return AUDIO_SOURCE_HOTWORD; |
| 916 | default: |
| 917 | return unexpected(BAD_VALUE); |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | ConversionResult<media::AudioSourceType> legacy2aidl_audio_source_t_AudioSourceType( |
| 922 | audio_source_t legacy) { |
| 923 | switch (legacy) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 924 | case AUDIO_SOURCE_INVALID: |
| 925 | return media::AudioSourceType::INVALID; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 926 | case AUDIO_SOURCE_DEFAULT: |
| 927 | return media::AudioSourceType::DEFAULT; |
| 928 | case AUDIO_SOURCE_MIC: |
| 929 | return media::AudioSourceType::MIC; |
| 930 | case AUDIO_SOURCE_VOICE_UPLINK: |
| 931 | return media::AudioSourceType::VOICE_UPLINK; |
| 932 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 933 | return media::AudioSourceType::VOICE_DOWNLINK; |
| 934 | case AUDIO_SOURCE_VOICE_CALL: |
| 935 | return media::AudioSourceType::VOICE_CALL; |
| 936 | case AUDIO_SOURCE_CAMCORDER: |
| 937 | return media::AudioSourceType::CAMCORDER; |
| 938 | case AUDIO_SOURCE_VOICE_RECOGNITION: |
| 939 | return media::AudioSourceType::VOICE_RECOGNITION; |
| 940 | case AUDIO_SOURCE_VOICE_COMMUNICATION: |
| 941 | return media::AudioSourceType::VOICE_COMMUNICATION; |
| 942 | case AUDIO_SOURCE_REMOTE_SUBMIX: |
| 943 | return media::AudioSourceType::REMOTE_SUBMIX; |
| 944 | case AUDIO_SOURCE_UNPROCESSED: |
| 945 | return media::AudioSourceType::UNPROCESSED; |
| 946 | case AUDIO_SOURCE_VOICE_PERFORMANCE: |
| 947 | return media::AudioSourceType::VOICE_PERFORMANCE; |
| 948 | case AUDIO_SOURCE_ECHO_REFERENCE: |
| 949 | return media::AudioSourceType::ECHO_REFERENCE; |
| 950 | case AUDIO_SOURCE_FM_TUNER: |
| 951 | return media::AudioSourceType::FM_TUNER; |
| 952 | case AUDIO_SOURCE_HOTWORD: |
| 953 | return media::AudioSourceType::HOTWORD; |
| 954 | default: |
| 955 | return unexpected(BAD_VALUE); |
| 956 | } |
| 957 | } |
| 958 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 959 | ConversionResult<audio_session_t> aidl2legacy_int32_t_audio_session_t(int32_t aidl) { |
| 960 | return convertReinterpret<audio_session_t>(aidl); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 963 | ConversionResult<int32_t> legacy2aidl_audio_session_t_int32_t(audio_session_t legacy) { |
| 964 | return convertReinterpret<int32_t>(legacy); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | // This type is unnamed in the original definition, thus we name it here. |
| 968 | using audio_port_config_mix_ext_usecase = decltype(audio_port_config_mix_ext::usecase); |
| 969 | |
| 970 | ConversionResult<audio_port_config_mix_ext_usecase> aidl2legacy_AudioPortConfigMixExtUseCase( |
| 971 | const media::AudioPortConfigMixExtUseCase& aidl, media::AudioPortRole role) { |
| 972 | audio_port_config_mix_ext_usecase legacy; |
| 973 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 974 | switch (role) { |
| 975 | case media::AudioPortRole::NONE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 976 | // Just verify that the union is empty. |
| 977 | VALUE_OR_RETURN(UNION_GET(aidl, nothing)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 978 | break; |
| 979 | |
| 980 | case media::AudioPortRole::SOURCE: |
| 981 | // This is not a bug. A SOURCE role corresponds to the stream field. |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 982 | legacy.stream = VALUE_OR_RETURN(aidl2legacy_AudioStreamType_audio_stream_type_t( |
| 983 | VALUE_OR_RETURN(UNION_GET(aidl, stream)))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 984 | break; |
| 985 | |
| 986 | case media::AudioPortRole::SINK: |
| 987 | // This is not a bug. A SINK role corresponds to the source field. |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 988 | legacy.source = VALUE_OR_RETURN(aidl2legacy_AudioSourceType_audio_source_t( |
| 989 | VALUE_OR_RETURN(UNION_GET(aidl, source)))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 990 | break; |
| 991 | |
| 992 | default: |
| 993 | LOG_ALWAYS_FATAL("Shouldn't get here"); |
| 994 | } |
| 995 | return legacy; |
| 996 | } |
| 997 | |
| 998 | ConversionResult<media::AudioPortConfigMixExtUseCase> legacy2aidl_AudioPortConfigMixExtUseCase( |
| 999 | const audio_port_config_mix_ext_usecase& legacy, audio_port_role_t role) { |
| 1000 | media::AudioPortConfigMixExtUseCase aidl; |
| 1001 | |
| 1002 | switch (role) { |
| 1003 | case AUDIO_PORT_ROLE_NONE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1004 | UNION_SET(aidl, nothing, false); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1005 | break; |
| 1006 | case AUDIO_PORT_ROLE_SOURCE: |
| 1007 | // This is not a bug. A SOURCE role corresponds to the stream field. |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1008 | UNION_SET(aidl, stream, VALUE_OR_RETURN( |
| 1009 | legacy2aidl_audio_stream_type_t_AudioStreamType(legacy.stream))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1010 | break; |
| 1011 | case AUDIO_PORT_ROLE_SINK: |
| 1012 | // This is not a bug. A SINK role corresponds to the source field. |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1013 | UNION_SET(aidl, source, |
| 1014 | VALUE_OR_RETURN(legacy2aidl_audio_source_t_AudioSourceType(legacy.source))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1015 | break; |
| 1016 | default: |
| 1017 | LOG_ALWAYS_FATAL("Shouldn't get here"); |
| 1018 | } |
| 1019 | return aidl; |
| 1020 | } |
| 1021 | |
| 1022 | ConversionResult<audio_port_config_mix_ext> aidl2legacy_AudioPortConfigMixExt( |
| 1023 | const media::AudioPortConfigMixExt& aidl, media::AudioPortRole role) { |
| 1024 | audio_port_config_mix_ext legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1025 | legacy.hw_module = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_module_handle_t(aidl.hwModule)); |
| 1026 | legacy.handle = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.handle)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1027 | legacy.usecase = VALUE_OR_RETURN(aidl2legacy_AudioPortConfigMixExtUseCase(aidl.usecase, role)); |
| 1028 | return legacy; |
| 1029 | } |
| 1030 | |
| 1031 | ConversionResult<media::AudioPortConfigMixExt> legacy2aidl_AudioPortConfigMixExt( |
| 1032 | const audio_port_config_mix_ext& legacy, audio_port_role_t role) { |
| 1033 | media::AudioPortConfigMixExt aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1034 | aidl.hwModule = VALUE_OR_RETURN(legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
| 1035 | aidl.handle = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(legacy.handle)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1036 | aidl.usecase = VALUE_OR_RETURN(legacy2aidl_AudioPortConfigMixExtUseCase(legacy.usecase, role)); |
| 1037 | return aidl; |
| 1038 | } |
| 1039 | |
| 1040 | ConversionResult<audio_port_config_session_ext> aidl2legacy_AudioPortConfigSessionExt( |
| 1041 | const media::AudioPortConfigSessionExt& aidl) { |
| 1042 | audio_port_config_session_ext legacy; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1043 | legacy.session = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.session)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1044 | return legacy; |
| 1045 | } |
| 1046 | |
| 1047 | ConversionResult<media::AudioPortConfigSessionExt> legacy2aidl_AudioPortConfigSessionExt( |
| 1048 | const audio_port_config_session_ext& legacy) { |
| 1049 | media::AudioPortConfigSessionExt aidl; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1050 | aidl.session = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(legacy.session)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1051 | return aidl; |
| 1052 | } |
| 1053 | |
| 1054 | // This type is unnamed in the original definition, thus we name it here. |
| 1055 | using audio_port_config_ext = decltype(audio_port_config::ext); |
| 1056 | |
| 1057 | ConversionResult<audio_port_config_ext> aidl2legacy_AudioPortConfigExt( |
| 1058 | const media::AudioPortConfigExt& aidl, media::AudioPortType type, |
| 1059 | media::AudioPortRole role) { |
| 1060 | audio_port_config_ext legacy; |
| 1061 | // Our way of representing a union in AIDL is to have multiple vectors and require that at most |
| 1062 | // one of the them has size 1 and the rest are empty. |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1063 | switch (type) { |
| 1064 | case media::AudioPortType::NONE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1065 | // Just verify that the union is empty. |
| 1066 | VALUE_OR_RETURN(UNION_GET(aidl, nothing)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1067 | break; |
| 1068 | case media::AudioPortType::DEVICE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1069 | legacy.device = VALUE_OR_RETURN( |
| 1070 | aidl2legacy_AudioPortConfigDeviceExt(VALUE_OR_RETURN(UNION_GET(aidl, device)))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1071 | break; |
| 1072 | case media::AudioPortType::MIX: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1073 | legacy.mix = VALUE_OR_RETURN( |
| 1074 | aidl2legacy_AudioPortConfigMixExt(VALUE_OR_RETURN(UNION_GET(aidl, mix)), role)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1075 | break; |
| 1076 | case media::AudioPortType::SESSION: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1077 | legacy.session = VALUE_OR_RETURN(aidl2legacy_AudioPortConfigSessionExt( |
| 1078 | VALUE_OR_RETURN(UNION_GET(aidl, session)))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1079 | break; |
| 1080 | default: |
| 1081 | LOG_ALWAYS_FATAL("Shouldn't get here"); |
| 1082 | } |
| 1083 | return legacy; |
| 1084 | } |
| 1085 | |
| 1086 | ConversionResult<media::AudioPortConfigExt> legacy2aidl_AudioPortConfigExt( |
| 1087 | const audio_port_config_ext& legacy, audio_port_type_t type, audio_port_role_t role) { |
| 1088 | media::AudioPortConfigExt aidl; |
| 1089 | |
| 1090 | switch (type) { |
| 1091 | case AUDIO_PORT_TYPE_NONE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1092 | UNION_SET(aidl, nothing, false); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1093 | break; |
| 1094 | case AUDIO_PORT_TYPE_DEVICE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1095 | UNION_SET(aidl, device, |
| 1096 | VALUE_OR_RETURN(legacy2aidl_AudioPortConfigDeviceExt(legacy.device))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1097 | break; |
| 1098 | case AUDIO_PORT_TYPE_MIX: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1099 | UNION_SET(aidl, mix, |
| 1100 | VALUE_OR_RETURN(legacy2aidl_AudioPortConfigMixExt(legacy.mix, role))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1101 | break; |
| 1102 | case AUDIO_PORT_TYPE_SESSION: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1103 | UNION_SET(aidl, session, |
| 1104 | VALUE_OR_RETURN(legacy2aidl_AudioPortConfigSessionExt(legacy.session))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1105 | break; |
| 1106 | default: |
| 1107 | LOG_ALWAYS_FATAL("Shouldn't get here"); |
| 1108 | } |
| 1109 | return aidl; |
| 1110 | } |
| 1111 | |
| 1112 | ConversionResult<audio_port_config> aidl2legacy_AudioPortConfig_audio_port_config( |
| 1113 | const media::AudioPortConfig& aidl) { |
| 1114 | audio_port_config legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1115 | legacy.id = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.id)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1116 | legacy.role = VALUE_OR_RETURN(aidl2legacy_AudioPortRole_audio_port_role_t(aidl.role)); |
| 1117 | legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioPortType_audio_port_type_t(aidl.type)); |
| 1118 | legacy.config_mask = VALUE_OR_RETURN(aidl2legacy_int32_t_config_mask(aidl.configMask)); |
| 1119 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::SAMPLE_RATE)) { |
| 1120 | legacy.sample_rate = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.sampleRate)); |
| 1121 | } |
| 1122 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::CHANNEL_MASK)) { |
| 1123 | legacy.channel_mask = |
| 1124 | VALUE_OR_RETURN(aidl2legacy_int32_t_audio_channel_mask_t(aidl.channelMask)); |
| 1125 | } |
| 1126 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::FORMAT)) { |
| 1127 | legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
| 1128 | } |
| 1129 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::GAIN)) { |
| 1130 | legacy.gain = VALUE_OR_RETURN( |
| 1131 | aidl2legacy_AudioGainConfig_audio_gain_config(aidl.gain, aidl.role, aidl.type)); |
| 1132 | } |
| 1133 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::FLAGS)) { |
| 1134 | legacy.flags = VALUE_OR_RETURN( |
| 1135 | aidl2legacy_AudioIoFlags_audio_io_flags(aidl.flags, aidl.role, aidl.type)); |
| 1136 | } |
| 1137 | legacy.ext = VALUE_OR_RETURN(aidl2legacy_AudioPortConfigExt(aidl.ext, aidl.type, aidl.role)); |
| 1138 | return legacy; |
| 1139 | } |
| 1140 | |
| 1141 | ConversionResult<media::AudioPortConfig> legacy2aidl_audio_port_config_AudioPortConfig( |
| 1142 | const audio_port_config& legacy) { |
| 1143 | media::AudioPortConfig aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1144 | aidl.id = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy.id)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1145 | aidl.role = VALUE_OR_RETURN(legacy2aidl_audio_port_role_t_AudioPortRole(legacy.role)); |
| 1146 | aidl.type = VALUE_OR_RETURN(legacy2aidl_audio_port_type_t_AudioPortType(legacy.type)); |
| 1147 | aidl.configMask = VALUE_OR_RETURN(legacy2aidl_config_mask_int32_t(legacy.config_mask)); |
| 1148 | if (legacy.config_mask & AUDIO_PORT_CONFIG_SAMPLE_RATE) { |
| 1149 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.sample_rate)); |
| 1150 | } |
| 1151 | if (legacy.config_mask & AUDIO_PORT_CONFIG_CHANNEL_MASK) { |
| 1152 | aidl.channelMask = |
| 1153 | VALUE_OR_RETURN(legacy2aidl_audio_channel_mask_t_int32_t(legacy.channel_mask)); |
| 1154 | } |
| 1155 | if (legacy.config_mask & AUDIO_PORT_CONFIG_FORMAT) { |
| 1156 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
| 1157 | } |
| 1158 | if (legacy.config_mask & AUDIO_PORT_CONFIG_GAIN) { |
| 1159 | aidl.gain = VALUE_OR_RETURN(legacy2aidl_audio_gain_config_AudioGainConfig( |
| 1160 | legacy.gain, legacy.role, legacy.type)); |
| 1161 | } |
| 1162 | if (legacy.config_mask & AUDIO_PORT_CONFIG_FLAGS) { |
| 1163 | aidl.flags = VALUE_OR_RETURN( |
| 1164 | legacy2aidl_audio_io_flags_AudioIoFlags(legacy.flags, legacy.role, legacy.type)); |
| 1165 | } |
| 1166 | aidl.ext = |
| 1167 | VALUE_OR_RETURN(legacy2aidl_AudioPortConfigExt(legacy.ext, legacy.type, legacy.role)); |
| 1168 | return aidl; |
| 1169 | } |
| 1170 | |
| 1171 | ConversionResult<struct audio_patch> aidl2legacy_AudioPatch_audio_patch( |
| 1172 | const media::AudioPatch& aidl) { |
| 1173 | struct audio_patch legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1174 | legacy.id = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_patch_handle_t(aidl.id)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1175 | legacy.num_sinks = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.sinks.size())); |
| 1176 | if (legacy.num_sinks > AUDIO_PATCH_PORTS_MAX) { |
| 1177 | return unexpected(BAD_VALUE); |
| 1178 | } |
| 1179 | for (size_t i = 0; i < legacy.num_sinks; ++i) { |
| 1180 | legacy.sinks[i] = |
| 1181 | VALUE_OR_RETURN(aidl2legacy_AudioPortConfig_audio_port_config(aidl.sinks[i])); |
| 1182 | } |
| 1183 | legacy.num_sources = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.sources.size())); |
| 1184 | if (legacy.num_sources > AUDIO_PATCH_PORTS_MAX) { |
| 1185 | return unexpected(BAD_VALUE); |
| 1186 | } |
| 1187 | for (size_t i = 0; i < legacy.num_sources; ++i) { |
| 1188 | legacy.sources[i] = |
| 1189 | VALUE_OR_RETURN(aidl2legacy_AudioPortConfig_audio_port_config(aidl.sources[i])); |
| 1190 | } |
| 1191 | return legacy; |
| 1192 | } |
| 1193 | |
| 1194 | ConversionResult<media::AudioPatch> legacy2aidl_audio_patch_AudioPatch( |
| 1195 | const struct audio_patch& legacy) { |
| 1196 | media::AudioPatch aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1197 | aidl.id = VALUE_OR_RETURN(legacy2aidl_audio_patch_handle_t_int32_t(legacy.id)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1198 | |
| 1199 | if (legacy.num_sinks > AUDIO_PATCH_PORTS_MAX) { |
| 1200 | return unexpected(BAD_VALUE); |
| 1201 | } |
| 1202 | for (unsigned int i = 0; i < legacy.num_sinks; ++i) { |
| 1203 | aidl.sinks.push_back( |
| 1204 | VALUE_OR_RETURN(legacy2aidl_audio_port_config_AudioPortConfig(legacy.sinks[i]))); |
| 1205 | } |
| 1206 | if (legacy.num_sources > AUDIO_PATCH_PORTS_MAX) { |
| 1207 | return unexpected(BAD_VALUE); |
| 1208 | } |
| 1209 | for (unsigned int i = 0; i < legacy.num_sources; ++i) { |
| 1210 | aidl.sources.push_back( |
| 1211 | VALUE_OR_RETURN(legacy2aidl_audio_port_config_AudioPortConfig(legacy.sources[i]))); |
| 1212 | } |
| 1213 | return aidl; |
| 1214 | } |
| 1215 | |
| 1216 | ConversionResult<sp<AudioIoDescriptor>> aidl2legacy_AudioIoDescriptor_AudioIoDescriptor( |
| 1217 | const media::AudioIoDescriptor& aidl) { |
| 1218 | sp<AudioIoDescriptor> legacy(new AudioIoDescriptor()); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1219 | legacy->mIoHandle = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.ioHandle)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1220 | legacy->mPatch = VALUE_OR_RETURN(aidl2legacy_AudioPatch_audio_patch(aidl.patch)); |
| 1221 | legacy->mSamplingRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.samplingRate)); |
| 1222 | legacy->mFormat = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
| 1223 | legacy->mChannelMask = |
| 1224 | VALUE_OR_RETURN(aidl2legacy_int32_t_audio_channel_mask_t(aidl.channelMask)); |
| 1225 | legacy->mFrameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount)); |
| 1226 | legacy->mFrameCountHAL = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCountHAL)); |
| 1227 | legacy->mLatency = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.latency)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1228 | legacy->mPortId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1229 | return legacy; |
| 1230 | } |
| 1231 | |
| 1232 | ConversionResult<media::AudioIoDescriptor> legacy2aidl_AudioIoDescriptor_AudioIoDescriptor( |
| 1233 | const sp<AudioIoDescriptor>& legacy) { |
| 1234 | media::AudioIoDescriptor aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1235 | aidl.ioHandle = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(legacy->mIoHandle)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1236 | aidl.patch = VALUE_OR_RETURN(legacy2aidl_audio_patch_AudioPatch(legacy->mPatch)); |
| 1237 | aidl.samplingRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy->mSamplingRate)); |
| 1238 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy->mFormat)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1239 | aidl.channelMask = VALUE_OR_RETURN( |
| 1240 | legacy2aidl_audio_channel_mask_t_int32_t(legacy->mChannelMask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1241 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy->mFrameCount)); |
| 1242 | aidl.frameCountHAL = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy->mFrameCountHAL)); |
| 1243 | aidl.latency = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy->mLatency)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1244 | aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy->mPortId)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1245 | return aidl; |
| 1246 | } |
| 1247 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1248 | ConversionResult<AudioClient> aidl2legacy_AudioClient(const media::AudioClient& aidl) { |
| 1249 | AudioClient legacy; |
| 1250 | legacy.clientUid = VALUE_OR_RETURN(aidl2legacy_int32_t_uid_t(aidl.clientUid)); |
| 1251 | legacy.clientPid = VALUE_OR_RETURN(aidl2legacy_int32_t_pid_t(aidl.clientPid)); |
| 1252 | legacy.clientTid = VALUE_OR_RETURN(aidl2legacy_int32_t_pid_t(aidl.clientTid)); |
| 1253 | legacy.packageName = VALUE_OR_RETURN(aidl2legacy_string_view_String16(aidl.packageName)); |
| 1254 | return legacy; |
| 1255 | } |
| 1256 | |
| 1257 | ConversionResult<media::AudioClient> legacy2aidl_AudioClient(const AudioClient& legacy) { |
| 1258 | media::AudioClient aidl; |
| 1259 | aidl.clientUid = VALUE_OR_RETURN(legacy2aidl_uid_t_int32_t(legacy.clientUid)); |
| 1260 | aidl.clientPid = VALUE_OR_RETURN(legacy2aidl_pid_t_int32_t(legacy.clientPid)); |
| 1261 | aidl.clientTid = VALUE_OR_RETURN(legacy2aidl_pid_t_int32_t(legacy.clientTid)); |
| 1262 | aidl.packageName = VALUE_OR_RETURN(legacy2aidl_String16_string(legacy.packageName)); |
| 1263 | return aidl; |
| 1264 | } |
| 1265 | |
| 1266 | ConversionResult<audio_content_type_t> |
| 1267 | aidl2legacy_AudioContentType_audio_content_type_t(media::AudioContentType aidl) { |
| 1268 | switch (aidl) { |
| 1269 | case media::AudioContentType::UNKNOWN: |
| 1270 | return AUDIO_CONTENT_TYPE_UNKNOWN; |
| 1271 | case media::AudioContentType::SPEECH: |
| 1272 | return AUDIO_CONTENT_TYPE_SPEECH; |
| 1273 | case media::AudioContentType::MUSIC: |
| 1274 | return AUDIO_CONTENT_TYPE_MUSIC; |
| 1275 | case media::AudioContentType::MOVIE: |
| 1276 | return AUDIO_CONTENT_TYPE_MOVIE; |
| 1277 | case media::AudioContentType::SONIFICATION: |
| 1278 | return AUDIO_CONTENT_TYPE_SONIFICATION; |
| 1279 | } |
| 1280 | return unexpected(BAD_VALUE); |
| 1281 | } |
| 1282 | |
| 1283 | ConversionResult<media::AudioContentType> |
| 1284 | legacy2aidl_audio_content_type_t_AudioContentType(audio_content_type_t legacy) { |
| 1285 | switch (legacy) { |
| 1286 | case AUDIO_CONTENT_TYPE_UNKNOWN: |
| 1287 | return media::AudioContentType::UNKNOWN; |
| 1288 | case AUDIO_CONTENT_TYPE_SPEECH: |
| 1289 | return media::AudioContentType::SPEECH; |
| 1290 | case AUDIO_CONTENT_TYPE_MUSIC: |
| 1291 | return media::AudioContentType::MUSIC; |
| 1292 | case AUDIO_CONTENT_TYPE_MOVIE: |
| 1293 | return media::AudioContentType::MOVIE; |
| 1294 | case AUDIO_CONTENT_TYPE_SONIFICATION: |
| 1295 | return media::AudioContentType::SONIFICATION; |
| 1296 | } |
| 1297 | return unexpected(BAD_VALUE); |
| 1298 | } |
| 1299 | |
| 1300 | ConversionResult<audio_usage_t> |
| 1301 | aidl2legacy_AudioUsage_audio_usage_t(media::AudioUsage aidl) { |
| 1302 | switch (aidl) { |
| 1303 | case media::AudioUsage::UNKNOWN: |
| 1304 | return AUDIO_USAGE_UNKNOWN; |
| 1305 | case media::AudioUsage::MEDIA: |
| 1306 | return AUDIO_USAGE_MEDIA; |
| 1307 | case media::AudioUsage::VOICE_COMMUNICATION: |
| 1308 | return AUDIO_USAGE_VOICE_COMMUNICATION; |
| 1309 | case media::AudioUsage::VOICE_COMMUNICATION_SIGNALLING: |
| 1310 | return AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING; |
| 1311 | case media::AudioUsage::ALARM: |
| 1312 | return AUDIO_USAGE_ALARM; |
| 1313 | case media::AudioUsage::NOTIFICATION: |
| 1314 | return AUDIO_USAGE_NOTIFICATION; |
| 1315 | case media::AudioUsage::NOTIFICATION_TELEPHONY_RINGTONE: |
| 1316 | return AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE; |
| 1317 | case media::AudioUsage::NOTIFICATION_COMMUNICATION_REQUEST: |
| 1318 | return AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST; |
| 1319 | case media::AudioUsage::NOTIFICATION_COMMUNICATION_INSTANT: |
| 1320 | return AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT; |
| 1321 | case media::AudioUsage::NOTIFICATION_COMMUNICATION_DELAYED: |
| 1322 | return AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED; |
| 1323 | case media::AudioUsage::NOTIFICATION_EVENT: |
| 1324 | return AUDIO_USAGE_NOTIFICATION_EVENT; |
| 1325 | case media::AudioUsage::ASSISTANCE_ACCESSIBILITY: |
| 1326 | return AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY; |
| 1327 | case media::AudioUsage::ASSISTANCE_NAVIGATION_GUIDANCE: |
| 1328 | return AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE; |
| 1329 | case media::AudioUsage::ASSISTANCE_SONIFICATION: |
| 1330 | return AUDIO_USAGE_ASSISTANCE_SONIFICATION; |
| 1331 | case media::AudioUsage::GAME: |
| 1332 | return AUDIO_USAGE_GAME; |
| 1333 | case media::AudioUsage::VIRTUAL_SOURCE: |
| 1334 | return AUDIO_USAGE_VIRTUAL_SOURCE; |
| 1335 | case media::AudioUsage::ASSISTANT: |
| 1336 | return AUDIO_USAGE_ASSISTANT; |
| 1337 | case media::AudioUsage::CALL_ASSISTANT: |
| 1338 | return AUDIO_USAGE_CALL_ASSISTANT; |
| 1339 | case media::AudioUsage::EMERGENCY: |
| 1340 | return AUDIO_USAGE_EMERGENCY; |
| 1341 | case media::AudioUsage::SAFETY: |
| 1342 | return AUDIO_USAGE_SAFETY; |
| 1343 | case media::AudioUsage::VEHICLE_STATUS: |
| 1344 | return AUDIO_USAGE_VEHICLE_STATUS; |
| 1345 | case media::AudioUsage::ANNOUNCEMENT: |
| 1346 | return AUDIO_USAGE_ANNOUNCEMENT; |
| 1347 | } |
| 1348 | return unexpected(BAD_VALUE); |
| 1349 | } |
| 1350 | |
| 1351 | ConversionResult<media::AudioUsage> |
| 1352 | legacy2aidl_audio_usage_t_AudioUsage(audio_usage_t legacy) { |
| 1353 | switch (legacy) { |
| 1354 | case AUDIO_USAGE_UNKNOWN: |
| 1355 | return media::AudioUsage::UNKNOWN; |
| 1356 | case AUDIO_USAGE_MEDIA: |
| 1357 | return media::AudioUsage::MEDIA; |
| 1358 | case AUDIO_USAGE_VOICE_COMMUNICATION: |
| 1359 | return media::AudioUsage::VOICE_COMMUNICATION; |
| 1360 | case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING: |
| 1361 | return media::AudioUsage::VOICE_COMMUNICATION_SIGNALLING; |
| 1362 | case AUDIO_USAGE_ALARM: |
| 1363 | return media::AudioUsage::ALARM; |
| 1364 | case AUDIO_USAGE_NOTIFICATION: |
| 1365 | return media::AudioUsage::NOTIFICATION; |
| 1366 | case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE: |
| 1367 | return media::AudioUsage::NOTIFICATION_TELEPHONY_RINGTONE; |
| 1368 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST: |
| 1369 | return media::AudioUsage::NOTIFICATION_COMMUNICATION_REQUEST; |
| 1370 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT: |
| 1371 | return media::AudioUsage::NOTIFICATION_COMMUNICATION_INSTANT; |
| 1372 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED: |
| 1373 | return media::AudioUsage::NOTIFICATION_COMMUNICATION_DELAYED; |
| 1374 | case AUDIO_USAGE_NOTIFICATION_EVENT: |
| 1375 | return media::AudioUsage::NOTIFICATION_EVENT; |
| 1376 | case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY: |
| 1377 | return media::AudioUsage::ASSISTANCE_ACCESSIBILITY; |
| 1378 | case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE: |
| 1379 | return media::AudioUsage::ASSISTANCE_NAVIGATION_GUIDANCE; |
| 1380 | case AUDIO_USAGE_ASSISTANCE_SONIFICATION: |
| 1381 | return media::AudioUsage::ASSISTANCE_SONIFICATION; |
| 1382 | case AUDIO_USAGE_GAME: |
| 1383 | return media::AudioUsage::GAME; |
| 1384 | case AUDIO_USAGE_VIRTUAL_SOURCE: |
| 1385 | return media::AudioUsage::VIRTUAL_SOURCE; |
| 1386 | case AUDIO_USAGE_ASSISTANT: |
| 1387 | return media::AudioUsage::ASSISTANT; |
| 1388 | case AUDIO_USAGE_CALL_ASSISTANT: |
| 1389 | return media::AudioUsage::CALL_ASSISTANT; |
| 1390 | case AUDIO_USAGE_EMERGENCY: |
| 1391 | return media::AudioUsage::EMERGENCY; |
| 1392 | case AUDIO_USAGE_SAFETY: |
| 1393 | return media::AudioUsage::SAFETY; |
| 1394 | case AUDIO_USAGE_VEHICLE_STATUS: |
| 1395 | return media::AudioUsage::VEHICLE_STATUS; |
| 1396 | case AUDIO_USAGE_ANNOUNCEMENT: |
| 1397 | return media::AudioUsage::ANNOUNCEMENT; |
| 1398 | } |
| 1399 | return unexpected(BAD_VALUE); |
| 1400 | } |
| 1401 | |
| 1402 | ConversionResult<audio_flags_mask_t> |
| 1403 | aidl2legacy_AudioFlag_audio_flags_mask_t(media::AudioFlag aidl) { |
| 1404 | switch (aidl) { |
| 1405 | case media::AudioFlag::AUDIBILITY_ENFORCED: |
| 1406 | return AUDIO_FLAG_AUDIBILITY_ENFORCED; |
| 1407 | case media::AudioFlag::SECURE: |
| 1408 | return AUDIO_FLAG_SECURE; |
| 1409 | case media::AudioFlag::SCO: |
| 1410 | return AUDIO_FLAG_SCO; |
| 1411 | case media::AudioFlag::BEACON: |
| 1412 | return AUDIO_FLAG_BEACON; |
| 1413 | case media::AudioFlag::HW_AV_SYNC: |
| 1414 | return AUDIO_FLAG_HW_AV_SYNC; |
| 1415 | case media::AudioFlag::HW_HOTWORD: |
| 1416 | return AUDIO_FLAG_HW_HOTWORD; |
| 1417 | case media::AudioFlag::BYPASS_INTERRUPTION_POLICY: |
| 1418 | return AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY; |
| 1419 | case media::AudioFlag::BYPASS_MUTE: |
| 1420 | return AUDIO_FLAG_BYPASS_MUTE; |
| 1421 | case media::AudioFlag::LOW_LATENCY: |
| 1422 | return AUDIO_FLAG_LOW_LATENCY; |
| 1423 | case media::AudioFlag::DEEP_BUFFER: |
| 1424 | return AUDIO_FLAG_DEEP_BUFFER; |
| 1425 | case media::AudioFlag::NO_MEDIA_PROJECTION: |
| 1426 | return AUDIO_FLAG_NO_MEDIA_PROJECTION; |
| 1427 | case media::AudioFlag::MUTE_HAPTIC: |
| 1428 | return AUDIO_FLAG_MUTE_HAPTIC; |
| 1429 | case media::AudioFlag::NO_SYSTEM_CAPTURE: |
| 1430 | return AUDIO_FLAG_NO_SYSTEM_CAPTURE; |
| 1431 | case media::AudioFlag::CAPTURE_PRIVATE: |
| 1432 | return AUDIO_FLAG_CAPTURE_PRIVATE; |
| 1433 | } |
| 1434 | return unexpected(BAD_VALUE); |
| 1435 | } |
| 1436 | |
| 1437 | ConversionResult<media::AudioFlag> |
| 1438 | legacy2aidl_audio_flags_mask_t_AudioFlag(audio_flags_mask_t legacy) { |
| 1439 | switch (legacy) { |
| 1440 | case AUDIO_FLAG_NONE: |
| 1441 | return unexpected(BAD_VALUE); |
| 1442 | case AUDIO_FLAG_AUDIBILITY_ENFORCED: |
| 1443 | return media::AudioFlag::AUDIBILITY_ENFORCED; |
| 1444 | case AUDIO_FLAG_SECURE: |
| 1445 | return media::AudioFlag::SECURE; |
| 1446 | case AUDIO_FLAG_SCO: |
| 1447 | return media::AudioFlag::SCO; |
| 1448 | case AUDIO_FLAG_BEACON: |
| 1449 | return media::AudioFlag::BEACON; |
| 1450 | case AUDIO_FLAG_HW_AV_SYNC: |
| 1451 | return media::AudioFlag::HW_AV_SYNC; |
| 1452 | case AUDIO_FLAG_HW_HOTWORD: |
| 1453 | return media::AudioFlag::HW_HOTWORD; |
| 1454 | case AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY: |
| 1455 | return media::AudioFlag::BYPASS_INTERRUPTION_POLICY; |
| 1456 | case AUDIO_FLAG_BYPASS_MUTE: |
| 1457 | return media::AudioFlag::BYPASS_MUTE; |
| 1458 | case AUDIO_FLAG_LOW_LATENCY: |
| 1459 | return media::AudioFlag::LOW_LATENCY; |
| 1460 | case AUDIO_FLAG_DEEP_BUFFER: |
| 1461 | return media::AudioFlag::DEEP_BUFFER; |
| 1462 | case AUDIO_FLAG_NO_MEDIA_PROJECTION: |
| 1463 | return media::AudioFlag::NO_MEDIA_PROJECTION; |
| 1464 | case AUDIO_FLAG_MUTE_HAPTIC: |
| 1465 | return media::AudioFlag::MUTE_HAPTIC; |
| 1466 | case AUDIO_FLAG_NO_SYSTEM_CAPTURE: |
| 1467 | return media::AudioFlag::NO_SYSTEM_CAPTURE; |
| 1468 | case AUDIO_FLAG_CAPTURE_PRIVATE: |
| 1469 | return media::AudioFlag::CAPTURE_PRIVATE; |
| 1470 | } |
| 1471 | return unexpected(BAD_VALUE); |
| 1472 | } |
| 1473 | |
| 1474 | ConversionResult<audio_flags_mask_t> |
| 1475 | aidl2legacy_int32_t_audio_flags_mask_t_mask(int32_t aidl) { |
| 1476 | return convertBitmask<audio_flags_mask_t, int32_t, audio_flags_mask_t, media::AudioFlag>( |
| 1477 | aidl, aidl2legacy_AudioFlag_audio_flags_mask_t, index2enum_index<media::AudioFlag>, |
| 1478 | enumToMask_bitmask<audio_flags_mask_t, audio_flags_mask_t>); |
| 1479 | } |
| 1480 | |
| 1481 | ConversionResult<int32_t> |
| 1482 | legacy2aidl_audio_flags_mask_t_int32_t_mask(audio_flags_mask_t legacy) { |
| 1483 | return convertBitmask<int32_t, audio_flags_mask_t, media::AudioFlag, audio_flags_mask_t>( |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1484 | legacy, legacy2aidl_audio_flags_mask_t_AudioFlag, |
| 1485 | index2enum_bitmask<audio_flags_mask_t>, |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1486 | enumToMask_index<int32_t, media::AudioFlag>); |
| 1487 | } |
| 1488 | |
| 1489 | ConversionResult<audio_attributes_t> |
| 1490 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(const media::AudioAttributesInternal& aidl) { |
| 1491 | audio_attributes_t legacy; |
| 1492 | legacy.content_type = VALUE_OR_RETURN( |
| 1493 | aidl2legacy_AudioContentType_audio_content_type_t(aidl.contentType)); |
| 1494 | legacy.usage = VALUE_OR_RETURN(aidl2legacy_AudioUsage_audio_usage_t(aidl.usage)); |
| 1495 | legacy.source = VALUE_OR_RETURN(aidl2legacy_AudioSourceType_audio_source_t(aidl.source)); |
| 1496 | legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_flags_mask_t_mask(aidl.flags)); |
| 1497 | RETURN_IF_ERROR(aidl2legacy_string(aidl.tags, legacy.tags, sizeof(legacy.tags))); |
| 1498 | return legacy; |
| 1499 | } |
| 1500 | |
| 1501 | ConversionResult<media::AudioAttributesInternal> |
| 1502 | legacy2aidl_audio_attributes_t_AudioAttributesInternal(const audio_attributes_t& legacy) { |
| 1503 | media::AudioAttributesInternal aidl; |
| 1504 | aidl.contentType = VALUE_OR_RETURN( |
| 1505 | legacy2aidl_audio_content_type_t_AudioContentType(legacy.content_type)); |
| 1506 | aidl.usage = VALUE_OR_RETURN(legacy2aidl_audio_usage_t_AudioUsage(legacy.usage)); |
| 1507 | aidl.source = VALUE_OR_RETURN(legacy2aidl_audio_source_t_AudioSourceType(legacy.source)); |
| 1508 | aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_flags_mask_t_int32_t_mask(legacy.flags)); |
| 1509 | aidl.tags = VALUE_OR_RETURN(legacy2aidl_string(legacy.tags, sizeof(legacy.tags))); |
| 1510 | return aidl; |
| 1511 | } |
| 1512 | |
| 1513 | ConversionResult<audio_encapsulation_mode_t> |
| 1514 | aidl2legacy_audio_encapsulation_mode_t_AudioEncapsulationMode(media::AudioEncapsulationMode aidl) { |
| 1515 | switch (aidl) { |
| 1516 | case media::AudioEncapsulationMode::NONE: |
| 1517 | return AUDIO_ENCAPSULATION_MODE_NONE; |
| 1518 | case media::AudioEncapsulationMode::ELEMENTARY_STREAM: |
| 1519 | return AUDIO_ENCAPSULATION_MODE_ELEMENTARY_STREAM; |
| 1520 | case media::AudioEncapsulationMode::HANDLE: |
| 1521 | return AUDIO_ENCAPSULATION_MODE_HANDLE; |
| 1522 | } |
| 1523 | return unexpected(BAD_VALUE); |
| 1524 | } |
| 1525 | |
| 1526 | ConversionResult<media::AudioEncapsulationMode> |
| 1527 | legacy2aidl_AudioEncapsulationMode_audio_encapsulation_mode_t(audio_encapsulation_mode_t legacy) { |
| 1528 | switch (legacy) { |
| 1529 | case AUDIO_ENCAPSULATION_MODE_NONE: |
| 1530 | return media::AudioEncapsulationMode::NONE; |
| 1531 | case AUDIO_ENCAPSULATION_MODE_ELEMENTARY_STREAM: |
| 1532 | return media::AudioEncapsulationMode::ELEMENTARY_STREAM; |
| 1533 | case AUDIO_ENCAPSULATION_MODE_HANDLE: |
| 1534 | return media::AudioEncapsulationMode::HANDLE; |
| 1535 | } |
| 1536 | return unexpected(BAD_VALUE); |
| 1537 | } |
| 1538 | |
| 1539 | ConversionResult<audio_offload_info_t> |
| 1540 | aidl2legacy_AudioOffloadInfo_audio_offload_info_t(const media::AudioOffloadInfo& aidl) { |
| 1541 | audio_offload_info_t legacy; |
| 1542 | legacy.version = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.version)); |
| 1543 | legacy.size = sizeof(audio_offload_info_t); |
| 1544 | audio_config_base_t config = VALUE_OR_RETURN( |
| 1545 | aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.config)); |
| 1546 | legacy.sample_rate = config.sample_rate; |
| 1547 | legacy.channel_mask = config.channel_mask; |
| 1548 | legacy.format = config.format; |
| 1549 | legacy.stream_type = VALUE_OR_RETURN( |
| 1550 | aidl2legacy_AudioStreamType_audio_stream_type_t(aidl.streamType)); |
| 1551 | legacy.bit_rate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.bitRate)); |
| 1552 | legacy.duration_us = VALUE_OR_RETURN(convertIntegral<int64_t>(aidl.durationUs)); |
| 1553 | legacy.has_video = aidl.hasVideo; |
| 1554 | legacy.is_streaming = aidl.isStreaming; |
| 1555 | legacy.bit_width = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.bitWidth)); |
| 1556 | legacy.offload_buffer_size = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.offloadBufferSize)); |
| 1557 | legacy.usage = VALUE_OR_RETURN(aidl2legacy_AudioUsage_audio_usage_t(aidl.usage)); |
| 1558 | legacy.encapsulation_mode = VALUE_OR_RETURN( |
| 1559 | aidl2legacy_audio_encapsulation_mode_t_AudioEncapsulationMode(aidl.encapsulationMode)); |
| 1560 | legacy.content_id = VALUE_OR_RETURN(convertReinterpret<int32_t>(aidl.contentId)); |
| 1561 | legacy.sync_id = VALUE_OR_RETURN(convertReinterpret<int32_t>(aidl.syncId)); |
| 1562 | return legacy; |
| 1563 | } |
| 1564 | |
| 1565 | ConversionResult<media::AudioOffloadInfo> |
| 1566 | legacy2aidl_audio_offload_info_t_AudioOffloadInfo(const audio_offload_info_t& legacy) { |
| 1567 | media::AudioOffloadInfo aidl; |
| 1568 | // Version 0.1 fields. |
| 1569 | if (legacy.size < offsetof(audio_offload_info_t, usage) + sizeof(audio_offload_info_t::usage)) { |
| 1570 | return unexpected(BAD_VALUE); |
| 1571 | } |
| 1572 | aidl.version = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.version)); |
| 1573 | aidl.config.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.sample_rate)); |
| 1574 | aidl.config.channelMask = VALUE_OR_RETURN( |
| 1575 | legacy2aidl_audio_channel_mask_t_int32_t(legacy.channel_mask)); |
| 1576 | aidl.config.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
| 1577 | aidl.streamType = VALUE_OR_RETURN( |
| 1578 | legacy2aidl_audio_stream_type_t_AudioStreamType(legacy.stream_type)); |
| 1579 | aidl.bitRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.bit_rate)); |
| 1580 | aidl.durationUs = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy.duration_us)); |
| 1581 | aidl.hasVideo = legacy.has_video; |
| 1582 | aidl.isStreaming = legacy.is_streaming; |
| 1583 | aidl.bitWidth = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.bit_width)); |
| 1584 | aidl.offloadBufferSize = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.offload_buffer_size)); |
| 1585 | aidl.usage = VALUE_OR_RETURN(legacy2aidl_audio_usage_t_AudioUsage(legacy.usage)); |
| 1586 | |
| 1587 | // Version 0.2 fields. |
| 1588 | if (legacy.version >= AUDIO_OFFLOAD_INFO_VERSION_0_2) { |
| 1589 | if (legacy.size < |
| 1590 | offsetof(audio_offload_info_t, sync_id) + sizeof(audio_offload_info_t::sync_id)) { |
| 1591 | return unexpected(BAD_VALUE); |
| 1592 | } |
| 1593 | aidl.encapsulationMode = VALUE_OR_RETURN( |
| 1594 | legacy2aidl_AudioEncapsulationMode_audio_encapsulation_mode_t( |
| 1595 | legacy.encapsulation_mode)); |
| 1596 | aidl.contentId = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.content_id)); |
| 1597 | aidl.syncId = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.sync_id)); |
| 1598 | } |
| 1599 | return aidl; |
| 1600 | } |
| 1601 | |
| 1602 | ConversionResult<audio_config_t> |
| 1603 | aidl2legacy_AudioConfig_audio_config_t(const media::AudioConfig& aidl) { |
| 1604 | audio_config_t legacy; |
| 1605 | legacy.sample_rate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1606 | legacy.channel_mask = VALUE_OR_RETURN( |
| 1607 | aidl2legacy_int32_t_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1608 | legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1609 | legacy.offload_info = VALUE_OR_RETURN( |
| 1610 | aidl2legacy_AudioOffloadInfo_audio_offload_info_t(aidl.offloadInfo)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1611 | legacy.frame_count = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.frameCount)); |
| 1612 | return legacy; |
| 1613 | } |
| 1614 | |
| 1615 | ConversionResult<media::AudioConfig> |
| 1616 | legacy2aidl_audio_config_t_AudioConfig(const audio_config_t& legacy) { |
| 1617 | media::AudioConfig aidl; |
| 1618 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.sample_rate)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1619 | aidl.channelMask = VALUE_OR_RETURN( |
| 1620 | legacy2aidl_audio_channel_mask_t_int32_t(legacy.channel_mask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1621 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1622 | aidl.offloadInfo = VALUE_OR_RETURN( |
| 1623 | legacy2aidl_audio_offload_info_t_AudioOffloadInfo(legacy.offload_info)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1624 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy.frame_count)); |
| 1625 | return aidl; |
| 1626 | } |
| 1627 | |
| 1628 | ConversionResult<audio_config_base_t> |
| 1629 | aidl2legacy_AudioConfigBase_audio_config_base_t(const media::AudioConfigBase& aidl) { |
| 1630 | audio_config_base_t legacy; |
| 1631 | legacy.sample_rate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1632 | legacy.channel_mask = VALUE_OR_RETURN( |
| 1633 | aidl2legacy_int32_t_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1634 | legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
| 1635 | return legacy; |
| 1636 | } |
| 1637 | |
| 1638 | ConversionResult<media::AudioConfigBase> |
| 1639 | legacy2aidl_audio_config_base_t_AudioConfigBase(const audio_config_base_t& legacy) { |
| 1640 | media::AudioConfigBase aidl; |
| 1641 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.sample_rate)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1642 | aidl.channelMask = VALUE_OR_RETURN( |
| 1643 | legacy2aidl_audio_channel_mask_t_int32_t(legacy.channel_mask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1644 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
| 1645 | return aidl; |
| 1646 | } |
| 1647 | |
| 1648 | ConversionResult<sp<IMemory>> |
| 1649 | aidl2legacy_SharedFileRegion_IMemory(const media::SharedFileRegion& aidl) { |
| 1650 | sp<IMemory> legacy; |
| 1651 | if (!convertSharedFileRegionToIMemory(aidl, &legacy)) { |
| 1652 | return unexpected(BAD_VALUE); |
| 1653 | } |
| 1654 | return legacy; |
| 1655 | } |
| 1656 | |
| 1657 | ConversionResult<media::SharedFileRegion> |
| 1658 | legacy2aidl_IMemory_SharedFileRegion(const sp<IMemory>& legacy) { |
| 1659 | media::SharedFileRegion aidl; |
| 1660 | if (!convertIMemoryToSharedFileRegion(legacy, &aidl)) { |
| 1661 | return unexpected(BAD_VALUE); |
| 1662 | } |
| 1663 | return aidl; |
| 1664 | } |
| 1665 | |
| 1666 | ConversionResult<sp<IMemory>> |
| 1667 | aidl2legacy_NullableSharedFileRegion_IMemory(const std::optional<media::SharedFileRegion>& aidl) { |
| 1668 | sp<IMemory> legacy; |
| 1669 | if (!convertNullableSharedFileRegionToIMemory(aidl, &legacy)) { |
| 1670 | return unexpected(BAD_VALUE); |
| 1671 | } |
| 1672 | return legacy; |
| 1673 | } |
| 1674 | |
| 1675 | ConversionResult<std::optional<media::SharedFileRegion>> |
| 1676 | legacy2aidl_NullableIMemory_SharedFileRegion(const sp<IMemory>& legacy) { |
| 1677 | std::optional<media::SharedFileRegion> aidl; |
| 1678 | if (!convertNullableIMemoryToSharedFileRegion(legacy, &aidl)) { |
| 1679 | return unexpected(BAD_VALUE); |
| 1680 | } |
| 1681 | return aidl; |
| 1682 | } |
| 1683 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1684 | } // namespace android |