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 | |
Mikhail Naganov | e128b8e | 2021-06-04 17:31:03 -0700 | [diff] [blame] | 17 | #include <algorithm> |
| 18 | #include <unordered_map> |
| 19 | #include <utility> |
| 20 | #include <vector> |
| 21 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 22 | #define LOG_TAG "AidlConversion" |
| 23 | //#define LOG_NDEBUG 0 |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 24 | #include <utils/Log.h> |
| 25 | |
| 26 | #include "media/AidlConversion.h" |
| 27 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 28 | #include <media/ShmemCompat.h> |
Mikhail Naganov | e128b8e | 2021-06-04 17:31:03 -0700 | [diff] [blame] | 29 | #include <media/stagefright/foundation/MediaDefs.h> |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 30 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 31 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 32 | // Utilities |
| 33 | |
| 34 | namespace android { |
| 35 | |
| 36 | using base::unexpected; |
| 37 | |
| 38 | namespace { |
| 39 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 40 | enum class Direction { |
| 41 | INPUT, OUTPUT |
| 42 | }; |
| 43 | |
| 44 | ConversionResult<Direction> direction(media::AudioPortRole role, media::AudioPortType type) { |
| 45 | switch (type) { |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 46 | case media::AudioPortType::NONE: |
| 47 | case media::AudioPortType::SESSION: |
| 48 | break; // must be listed -Werror,-Wswitch |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 49 | case media::AudioPortType::DEVICE: |
| 50 | switch (role) { |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 51 | case media::AudioPortRole::NONE: |
| 52 | break; // must be listed -Werror,-Wswitch |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 53 | case media::AudioPortRole::SOURCE: |
| 54 | return Direction::INPUT; |
| 55 | case media::AudioPortRole::SINK: |
| 56 | return Direction::OUTPUT; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 57 | } |
| 58 | break; |
| 59 | case media::AudioPortType::MIX: |
| 60 | switch (role) { |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 61 | case media::AudioPortRole::NONE: |
| 62 | break; // must be listed -Werror,-Wswitch |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 63 | case media::AudioPortRole::SOURCE: |
| 64 | return Direction::OUTPUT; |
| 65 | case media::AudioPortRole::SINK: |
| 66 | return Direction::INPUT; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 67 | } |
| 68 | break; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 69 | } |
| 70 | return unexpected(BAD_VALUE); |
| 71 | } |
| 72 | |
| 73 | ConversionResult<Direction> direction(audio_port_role_t role, audio_port_type_t type) { |
| 74 | switch (type) { |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 75 | case AUDIO_PORT_TYPE_NONE: |
| 76 | case AUDIO_PORT_TYPE_SESSION: |
| 77 | break; // must be listed -Werror,-Wswitch |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 78 | case AUDIO_PORT_TYPE_DEVICE: |
| 79 | switch (role) { |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 80 | case AUDIO_PORT_ROLE_NONE: |
| 81 | break; // must be listed -Werror,-Wswitch |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 82 | case AUDIO_PORT_ROLE_SOURCE: |
| 83 | return Direction::INPUT; |
| 84 | case AUDIO_PORT_ROLE_SINK: |
| 85 | return Direction::OUTPUT; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 86 | } |
| 87 | break; |
| 88 | case AUDIO_PORT_TYPE_MIX: |
| 89 | switch (role) { |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 90 | case AUDIO_PORT_ROLE_NONE: |
| 91 | break; // must be listed -Werror,-Wswitch |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 92 | case AUDIO_PORT_ROLE_SOURCE: |
| 93 | return Direction::OUTPUT; |
| 94 | case AUDIO_PORT_ROLE_SINK: |
| 95 | return Direction::INPUT; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 96 | } |
| 97 | break; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 98 | } |
| 99 | return unexpected(BAD_VALUE); |
| 100 | } |
| 101 | |
| 102 | } // namespace |
| 103 | |
| 104 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 105 | // Converters |
| 106 | |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 107 | status_t aidl2legacy_string(std::string_view aidl, char* dest, size_t maxSize) { |
| 108 | if (aidl.size() > maxSize - 1) { |
| 109 | return BAD_VALUE; |
| 110 | } |
| 111 | aidl.copy(dest, aidl.size()); |
| 112 | dest[aidl.size()] = '\0'; |
| 113 | return OK; |
| 114 | } |
| 115 | |
| 116 | ConversionResult<std::string> legacy2aidl_string(const char* legacy, size_t maxSize) { |
| 117 | if (legacy == nullptr) { |
| 118 | return unexpected(BAD_VALUE); |
| 119 | } |
| 120 | if (strnlen(legacy, maxSize) == maxSize) { |
| 121 | // No null-terminator. |
| 122 | return unexpected(BAD_VALUE); |
| 123 | } |
| 124 | return std::string(legacy); |
| 125 | } |
| 126 | |
| 127 | ConversionResult<audio_module_handle_t> aidl2legacy_int32_t_audio_module_handle_t(int32_t aidl) { |
| 128 | return convertReinterpret<audio_module_handle_t>(aidl); |
| 129 | } |
| 130 | |
| 131 | ConversionResult<int32_t> legacy2aidl_audio_module_handle_t_int32_t(audio_module_handle_t legacy) { |
| 132 | return convertReinterpret<int32_t>(legacy); |
| 133 | } |
| 134 | |
| 135 | ConversionResult<audio_io_handle_t> aidl2legacy_int32_t_audio_io_handle_t(int32_t aidl) { |
| 136 | return convertReinterpret<audio_io_handle_t>(aidl); |
| 137 | } |
| 138 | |
| 139 | ConversionResult<int32_t> legacy2aidl_audio_io_handle_t_int32_t(audio_io_handle_t legacy) { |
| 140 | return convertReinterpret<int32_t>(legacy); |
| 141 | } |
| 142 | |
| 143 | ConversionResult<audio_port_handle_t> aidl2legacy_int32_t_audio_port_handle_t(int32_t aidl) { |
| 144 | return convertReinterpret<audio_port_handle_t>(aidl); |
| 145 | } |
| 146 | |
| 147 | ConversionResult<int32_t> legacy2aidl_audio_port_handle_t_int32_t(audio_port_handle_t legacy) { |
| 148 | return convertReinterpret<int32_t>(legacy); |
| 149 | } |
| 150 | |
| 151 | ConversionResult<audio_patch_handle_t> aidl2legacy_int32_t_audio_patch_handle_t(int32_t aidl) { |
| 152 | return convertReinterpret<audio_patch_handle_t>(aidl); |
| 153 | } |
| 154 | |
| 155 | ConversionResult<int32_t> legacy2aidl_audio_patch_handle_t_int32_t(audio_patch_handle_t legacy) { |
| 156 | return convertReinterpret<int32_t>(legacy); |
| 157 | } |
| 158 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 159 | ConversionResult<audio_unique_id_t> aidl2legacy_int32_t_audio_unique_id_t(int32_t aidl) { |
| 160 | return convertReinterpret<audio_unique_id_t>(aidl); |
| 161 | } |
| 162 | |
| 163 | ConversionResult<int32_t> legacy2aidl_audio_unique_id_t_int32_t(audio_unique_id_t legacy) { |
| 164 | return convertReinterpret<int32_t>(legacy); |
| 165 | } |
| 166 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 167 | ConversionResult<audio_hw_sync_t> aidl2legacy_int32_t_audio_hw_sync_t(int32_t aidl) { |
| 168 | return convertReinterpret<audio_hw_sync_t>(aidl); |
| 169 | } |
| 170 | |
| 171 | ConversionResult<int32_t> legacy2aidl_audio_hw_sync_t_int32_t(audio_hw_sync_t legacy) { |
| 172 | return convertReinterpret<int32_t>(legacy); |
| 173 | } |
| 174 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 175 | ConversionResult<pid_t> aidl2legacy_int32_t_pid_t(int32_t aidl) { |
| 176 | return convertReinterpret<pid_t>(aidl); |
| 177 | } |
| 178 | |
| 179 | ConversionResult<int32_t> legacy2aidl_pid_t_int32_t(pid_t legacy) { |
| 180 | return convertReinterpret<int32_t>(legacy); |
| 181 | } |
| 182 | |
| 183 | ConversionResult<uid_t> aidl2legacy_int32_t_uid_t(int32_t aidl) { |
| 184 | return convertReinterpret<uid_t>(aidl); |
| 185 | } |
| 186 | |
| 187 | ConversionResult<int32_t> legacy2aidl_uid_t_int32_t(uid_t legacy) { |
| 188 | return convertReinterpret<int32_t>(legacy); |
| 189 | } |
| 190 | |
| 191 | ConversionResult<String16> aidl2legacy_string_view_String16(std::string_view aidl) { |
| 192 | return String16(aidl.data(), aidl.size()); |
| 193 | } |
| 194 | |
| 195 | ConversionResult<std::string> legacy2aidl_String16_string(const String16& legacy) { |
| 196 | return std::string(String8(legacy).c_str()); |
| 197 | } |
| 198 | |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 199 | // TODO b/182392769: create an optional -> optional util |
| 200 | ConversionResult<std::optional<String16>> |
| 201 | aidl2legacy_optional_string_view_optional_String16(std::optional<std::string_view> aidl) { |
| 202 | if (!aidl.has_value()) { |
| 203 | return std::nullopt; |
| 204 | } |
| 205 | ConversionResult<String16> conversion = |
| 206 | VALUE_OR_RETURN(aidl2legacy_string_view_String16(aidl.value())); |
| 207 | return conversion.value(); |
| 208 | } |
| 209 | |
| 210 | ConversionResult<std::optional<std::string_view>> |
| 211 | legacy2aidl_optional_String16_optional_string(std::optional<String16> legacy) { |
| 212 | if (!legacy.has_value()) { |
| 213 | return std::nullopt; |
| 214 | } |
| 215 | ConversionResult<std::string> conversion = |
| 216 | VALUE_OR_RETURN(legacy2aidl_String16_string(legacy.value())); |
| 217 | return conversion.value(); |
| 218 | } |
| 219 | |
Ytai Ben-Tsvi | ce18294 | 2020-11-04 14:48:01 -0800 | [diff] [blame] | 220 | ConversionResult<String8> aidl2legacy_string_view_String8(std::string_view aidl) { |
| 221 | return String8(aidl.data(), aidl.size()); |
| 222 | } |
| 223 | |
| 224 | ConversionResult<std::string> legacy2aidl_String8_string(const String8& legacy) { |
| 225 | return std::string(legacy.c_str()); |
| 226 | } |
| 227 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 228 | // The legacy enum is unnamed. Thus, we use int32_t. |
| 229 | ConversionResult<int32_t> aidl2legacy_AudioPortConfigType_int32_t( |
| 230 | media::AudioPortConfigType aidl) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 231 | switch (aidl) { |
| 232 | case media::AudioPortConfigType::SAMPLE_RATE: |
| 233 | return AUDIO_PORT_CONFIG_SAMPLE_RATE; |
| 234 | case media::AudioPortConfigType::CHANNEL_MASK: |
| 235 | return AUDIO_PORT_CONFIG_CHANNEL_MASK; |
| 236 | case media::AudioPortConfigType::FORMAT: |
| 237 | return AUDIO_PORT_CONFIG_FORMAT; |
Hayden Gomes | 1117ea2 | 2020-11-20 11:06:37 -0800 | [diff] [blame] | 238 | case media::AudioPortConfigType::GAIN: |
| 239 | return AUDIO_PORT_CONFIG_GAIN; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 240 | case media::AudioPortConfigType::FLAGS: |
| 241 | return AUDIO_PORT_CONFIG_FLAGS; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 242 | } |
Hayden Gomes | 1117ea2 | 2020-11-20 11:06:37 -0800 | [diff] [blame] | 243 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 246 | // The legacy enum is unnamed. Thus, we use int32_t. |
| 247 | ConversionResult<media::AudioPortConfigType> legacy2aidl_int32_t_AudioPortConfigType( |
| 248 | int32_t legacy) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 249 | switch (legacy) { |
| 250 | case AUDIO_PORT_CONFIG_SAMPLE_RATE: |
| 251 | return media::AudioPortConfigType::SAMPLE_RATE; |
| 252 | case AUDIO_PORT_CONFIG_CHANNEL_MASK: |
| 253 | return media::AudioPortConfigType::CHANNEL_MASK; |
| 254 | case AUDIO_PORT_CONFIG_FORMAT: |
| 255 | return media::AudioPortConfigType::FORMAT; |
Hayden Gomes | 1117ea2 | 2020-11-20 11:06:37 -0800 | [diff] [blame] | 256 | case AUDIO_PORT_CONFIG_GAIN: |
| 257 | return media::AudioPortConfigType::GAIN; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 258 | case AUDIO_PORT_CONFIG_FLAGS: |
| 259 | return media::AudioPortConfigType::FLAGS; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 260 | } |
Hayden Gomes | 1117ea2 | 2020-11-20 11:06:37 -0800 | [diff] [blame] | 261 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | ConversionResult<unsigned int> aidl2legacy_int32_t_config_mask(int32_t aidl) { |
| 265 | return convertBitmask<unsigned int, int32_t, int, media::AudioPortConfigType>( |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 266 | aidl, aidl2legacy_AudioPortConfigType_int32_t, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 267 | // AudioPortConfigType enum is index-based. |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 268 | indexToEnum_index<media::AudioPortConfigType>, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 269 | // AUDIO_PORT_CONFIG_* flags are mask-based. |
| 270 | enumToMask_bitmask<unsigned int, int>); |
| 271 | } |
| 272 | |
| 273 | ConversionResult<int32_t> legacy2aidl_config_mask_int32_t(unsigned int legacy) { |
| 274 | return convertBitmask<int32_t, unsigned int, media::AudioPortConfigType, int>( |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 275 | legacy, legacy2aidl_int32_t_AudioPortConfigType, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 276 | // AUDIO_PORT_CONFIG_* flags are mask-based. |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 277 | indexToEnum_bitmask<unsigned>, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 278 | // AudioPortConfigType enum is index-based. |
| 279 | enumToMask_index<int32_t, media::AudioPortConfigType>); |
| 280 | } |
| 281 | |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 282 | ConversionResult<audio_channel_mask_t> aidl2legacy_AudioChannelMask_audio_channel_mask_t( |
| 283 | media::AudioChannelMask aidl) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 284 | return convertReinterpret<audio_channel_mask_t>(aidl); |
| 285 | } |
| 286 | |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 287 | ConversionResult<media::AudioChannelMask> legacy2aidl_audio_channel_mask_t_AudioChannelMask( |
| 288 | audio_channel_mask_t legacy) { |
| 289 | return convertReinterpret<media::AudioChannelMask>(legacy); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | ConversionResult<audio_io_config_event> aidl2legacy_AudioIoConfigEvent_audio_io_config_event( |
| 293 | media::AudioIoConfigEvent aidl) { |
| 294 | switch (aidl) { |
| 295 | case media::AudioIoConfigEvent::OUTPUT_REGISTERED: |
| 296 | return AUDIO_OUTPUT_REGISTERED; |
| 297 | case media::AudioIoConfigEvent::OUTPUT_OPENED: |
| 298 | return AUDIO_OUTPUT_OPENED; |
| 299 | case media::AudioIoConfigEvent::OUTPUT_CLOSED: |
| 300 | return AUDIO_OUTPUT_CLOSED; |
| 301 | case media::AudioIoConfigEvent::OUTPUT_CONFIG_CHANGED: |
| 302 | return AUDIO_OUTPUT_CONFIG_CHANGED; |
| 303 | case media::AudioIoConfigEvent::INPUT_REGISTERED: |
| 304 | return AUDIO_INPUT_REGISTERED; |
| 305 | case media::AudioIoConfigEvent::INPUT_OPENED: |
| 306 | return AUDIO_INPUT_OPENED; |
| 307 | case media::AudioIoConfigEvent::INPUT_CLOSED: |
| 308 | return AUDIO_INPUT_CLOSED; |
| 309 | case media::AudioIoConfigEvent::INPUT_CONFIG_CHANGED: |
| 310 | return AUDIO_INPUT_CONFIG_CHANGED; |
| 311 | case media::AudioIoConfigEvent::CLIENT_STARTED: |
| 312 | return AUDIO_CLIENT_STARTED; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 313 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 314 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | ConversionResult<media::AudioIoConfigEvent> legacy2aidl_audio_io_config_event_AudioIoConfigEvent( |
| 318 | audio_io_config_event legacy) { |
| 319 | switch (legacy) { |
| 320 | case AUDIO_OUTPUT_REGISTERED: |
| 321 | return media::AudioIoConfigEvent::OUTPUT_REGISTERED; |
| 322 | case AUDIO_OUTPUT_OPENED: |
| 323 | return media::AudioIoConfigEvent::OUTPUT_OPENED; |
| 324 | case AUDIO_OUTPUT_CLOSED: |
| 325 | return media::AudioIoConfigEvent::OUTPUT_CLOSED; |
| 326 | case AUDIO_OUTPUT_CONFIG_CHANGED: |
| 327 | return media::AudioIoConfigEvent::OUTPUT_CONFIG_CHANGED; |
| 328 | case AUDIO_INPUT_REGISTERED: |
| 329 | return media::AudioIoConfigEvent::INPUT_REGISTERED; |
| 330 | case AUDIO_INPUT_OPENED: |
| 331 | return media::AudioIoConfigEvent::INPUT_OPENED; |
| 332 | case AUDIO_INPUT_CLOSED: |
| 333 | return media::AudioIoConfigEvent::INPUT_CLOSED; |
| 334 | case AUDIO_INPUT_CONFIG_CHANGED: |
| 335 | return media::AudioIoConfigEvent::INPUT_CONFIG_CHANGED; |
| 336 | case AUDIO_CLIENT_STARTED: |
| 337 | return media::AudioIoConfigEvent::CLIENT_STARTED; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 338 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 339 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | ConversionResult<audio_port_role_t> aidl2legacy_AudioPortRole_audio_port_role_t( |
| 343 | media::AudioPortRole aidl) { |
| 344 | switch (aidl) { |
| 345 | case media::AudioPortRole::NONE: |
| 346 | return AUDIO_PORT_ROLE_NONE; |
| 347 | case media::AudioPortRole::SOURCE: |
| 348 | return AUDIO_PORT_ROLE_SOURCE; |
| 349 | case media::AudioPortRole::SINK: |
| 350 | return AUDIO_PORT_ROLE_SINK; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 351 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 352 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | ConversionResult<media::AudioPortRole> legacy2aidl_audio_port_role_t_AudioPortRole( |
| 356 | audio_port_role_t legacy) { |
| 357 | switch (legacy) { |
| 358 | case AUDIO_PORT_ROLE_NONE: |
| 359 | return media::AudioPortRole::NONE; |
| 360 | case AUDIO_PORT_ROLE_SOURCE: |
| 361 | return media::AudioPortRole::SOURCE; |
| 362 | case AUDIO_PORT_ROLE_SINK: |
| 363 | return media::AudioPortRole::SINK; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 364 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 365 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | ConversionResult<audio_port_type_t> aidl2legacy_AudioPortType_audio_port_type_t( |
| 369 | media::AudioPortType aidl) { |
| 370 | switch (aidl) { |
| 371 | case media::AudioPortType::NONE: |
| 372 | return AUDIO_PORT_TYPE_NONE; |
| 373 | case media::AudioPortType::DEVICE: |
| 374 | return AUDIO_PORT_TYPE_DEVICE; |
| 375 | case media::AudioPortType::MIX: |
| 376 | return AUDIO_PORT_TYPE_MIX; |
| 377 | case media::AudioPortType::SESSION: |
| 378 | return AUDIO_PORT_TYPE_SESSION; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 379 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 380 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | ConversionResult<media::AudioPortType> legacy2aidl_audio_port_type_t_AudioPortType( |
| 384 | audio_port_type_t legacy) { |
| 385 | switch (legacy) { |
| 386 | case AUDIO_PORT_TYPE_NONE: |
| 387 | return media::AudioPortType::NONE; |
| 388 | case AUDIO_PORT_TYPE_DEVICE: |
| 389 | return media::AudioPortType::DEVICE; |
| 390 | case AUDIO_PORT_TYPE_MIX: |
| 391 | return media::AudioPortType::MIX; |
| 392 | case AUDIO_PORT_TYPE_SESSION: |
| 393 | return media::AudioPortType::SESSION; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 394 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 395 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | ConversionResult<audio_format_t> aidl2legacy_AudioFormat_audio_format_t( |
Mikhail Naganov | c10572e | 2021-05-21 17:42:02 -0700 | [diff] [blame] | 399 | media::AudioFormatSys aidl) { |
| 400 | // This relies on AudioFormatSys being kept in sync with audio_format_t. |
| 401 | static_assert(sizeof(media::AudioFormatSys) == sizeof(audio_format_t)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 402 | return static_cast<audio_format_t>(aidl); |
| 403 | } |
| 404 | |
Mikhail Naganov | c10572e | 2021-05-21 17:42:02 -0700 | [diff] [blame] | 405 | ConversionResult<media::AudioFormatSys> legacy2aidl_audio_format_t_AudioFormat( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 406 | audio_format_t legacy) { |
Mikhail Naganov | c10572e | 2021-05-21 17:42:02 -0700 | [diff] [blame] | 407 | // This relies on AudioFormatSys being kept in sync with audio_format_t. |
| 408 | static_assert(sizeof(media::AudioFormatSys) == sizeof(audio_format_t)); |
| 409 | return static_cast<media::AudioFormatSys>(legacy); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Mikhail Naganov | e128b8e | 2021-06-04 17:31:03 -0700 | [diff] [blame] | 412 | namespace { |
| 413 | |
| 414 | namespace detail { |
Mikhail Naganov | cf2fa81 | 2021-06-25 09:03:37 -0700 | [diff] [blame^] | 415 | using AudioChannelPair = std::pair<audio_channel_mask_t, media::AudioChannelLayout>; |
| 416 | using AudioChannelPairs = std::vector<AudioChannelPair>; |
Mikhail Naganov | 09a7381 | 2021-06-17 18:00:55 -0700 | [diff] [blame] | 417 | using AudioDevicePair = std::pair<audio_devices_t, media::AudioDeviceDescription>; |
| 418 | using AudioDevicePairs = std::vector<AudioDevicePair>; |
Mikhail Naganov | e128b8e | 2021-06-04 17:31:03 -0700 | [diff] [blame] | 419 | using AudioFormatPair = std::pair<audio_format_t, media::AudioFormatDescription>; |
| 420 | using AudioFormatPairs = std::vector<AudioFormatPair>; |
| 421 | } |
| 422 | |
Mikhail Naganov | cf2fa81 | 2021-06-25 09:03:37 -0700 | [diff] [blame^] | 423 | const detail::AudioChannelPairs& getIndexAudioChannelPairs() { |
| 424 | static const detail::AudioChannelPairs pairs = { |
| 425 | #define DEFINE_INDEX_MASK(n) \ |
| 426 | { \ |
| 427 | AUDIO_CHANNEL_INDEX_MASK_##n, \ |
| 428 | media::AudioChannelLayout::make<media::AudioChannelLayout::Tag::indexMask>( \ |
| 429 | media::AudioChannelLayout::INDEX_MASK_##n) \ |
| 430 | } |
| 431 | |
| 432 | DEFINE_INDEX_MASK(1), |
| 433 | DEFINE_INDEX_MASK(2), |
| 434 | DEFINE_INDEX_MASK(3), |
| 435 | DEFINE_INDEX_MASK(4), |
| 436 | DEFINE_INDEX_MASK(5), |
| 437 | DEFINE_INDEX_MASK(6), |
| 438 | DEFINE_INDEX_MASK(7), |
| 439 | DEFINE_INDEX_MASK(8), |
| 440 | DEFINE_INDEX_MASK(9), |
| 441 | DEFINE_INDEX_MASK(10), |
| 442 | DEFINE_INDEX_MASK(11), |
| 443 | DEFINE_INDEX_MASK(12), |
| 444 | DEFINE_INDEX_MASK(13), |
| 445 | DEFINE_INDEX_MASK(14), |
| 446 | DEFINE_INDEX_MASK(15), |
| 447 | DEFINE_INDEX_MASK(16), |
| 448 | DEFINE_INDEX_MASK(17), |
| 449 | DEFINE_INDEX_MASK(18), |
| 450 | DEFINE_INDEX_MASK(19), |
| 451 | DEFINE_INDEX_MASK(20), |
| 452 | DEFINE_INDEX_MASK(21), |
| 453 | DEFINE_INDEX_MASK(22), |
| 454 | DEFINE_INDEX_MASK(23), |
| 455 | DEFINE_INDEX_MASK(24) |
| 456 | #undef DEFINE_INDEX_MASK |
| 457 | }; |
| 458 | return pairs; |
| 459 | } |
| 460 | |
| 461 | const detail::AudioChannelPairs& getInAudioChannelPairs() { |
| 462 | static const detail::AudioChannelPairs pairs = { |
| 463 | #define DEFINE_INPUT_LAYOUT(n) \ |
| 464 | { \ |
| 465 | AUDIO_CHANNEL_IN_##n, \ |
| 466 | media::AudioChannelLayout::make<media::AudioChannelLayout::Tag::layoutMask>( \ |
| 467 | media::AudioChannelLayout::LAYOUT_##n) \ |
| 468 | } |
| 469 | |
| 470 | DEFINE_INPUT_LAYOUT(MONO), |
| 471 | DEFINE_INPUT_LAYOUT(STEREO), |
| 472 | DEFINE_INPUT_LAYOUT(FRONT_BACK), |
| 473 | // AUDIO_CHANNEL_IN_6 not supported |
| 474 | DEFINE_INPUT_LAYOUT(2POINT0POINT2), |
| 475 | DEFINE_INPUT_LAYOUT(2POINT1POINT2), |
| 476 | DEFINE_INPUT_LAYOUT(3POINT0POINT2), |
| 477 | DEFINE_INPUT_LAYOUT(3POINT1POINT2), |
| 478 | DEFINE_INPUT_LAYOUT(5POINT1), |
| 479 | DEFINE_INPUT_LAYOUT(VOICE_UPLINK_MONO), |
| 480 | DEFINE_INPUT_LAYOUT(VOICE_DNLINK_MONO), |
| 481 | DEFINE_INPUT_LAYOUT(VOICE_CALL_MONO) |
| 482 | #undef DEFINE_INPUT_LAYOUT |
| 483 | }; |
| 484 | return pairs; |
| 485 | } |
| 486 | |
| 487 | const detail::AudioChannelPairs& getOutAudioChannelPairs() { |
| 488 | static const detail::AudioChannelPairs pairs = { |
| 489 | #define DEFINE_OUTPUT_LAYOUT(n) \ |
| 490 | { \ |
| 491 | AUDIO_CHANNEL_OUT_##n, \ |
| 492 | media::AudioChannelLayout::make<media::AudioChannelLayout::Tag::layoutMask>( \ |
| 493 | media::AudioChannelLayout::LAYOUT_##n) \ |
| 494 | } |
| 495 | |
| 496 | DEFINE_OUTPUT_LAYOUT(MONO), |
| 497 | DEFINE_OUTPUT_LAYOUT(STEREO), |
| 498 | DEFINE_OUTPUT_LAYOUT(2POINT1), |
| 499 | DEFINE_OUTPUT_LAYOUT(TRI), |
| 500 | DEFINE_OUTPUT_LAYOUT(TRI_BACK), |
| 501 | DEFINE_OUTPUT_LAYOUT(3POINT1), |
| 502 | DEFINE_OUTPUT_LAYOUT(2POINT0POINT2), |
| 503 | DEFINE_OUTPUT_LAYOUT(2POINT1POINT2), |
| 504 | DEFINE_OUTPUT_LAYOUT(3POINT0POINT2), |
| 505 | DEFINE_OUTPUT_LAYOUT(3POINT1POINT2), |
| 506 | DEFINE_OUTPUT_LAYOUT(QUAD), |
| 507 | DEFINE_OUTPUT_LAYOUT(QUAD_SIDE), |
| 508 | DEFINE_OUTPUT_LAYOUT(SURROUND), |
| 509 | DEFINE_OUTPUT_LAYOUT(PENTA), |
| 510 | DEFINE_OUTPUT_LAYOUT(5POINT1), |
| 511 | DEFINE_OUTPUT_LAYOUT(5POINT1_SIDE), |
| 512 | DEFINE_OUTPUT_LAYOUT(5POINT1POINT2), |
| 513 | DEFINE_OUTPUT_LAYOUT(5POINT1POINT4), |
| 514 | DEFINE_OUTPUT_LAYOUT(6POINT1), |
| 515 | DEFINE_OUTPUT_LAYOUT(7POINT1), |
| 516 | DEFINE_OUTPUT_LAYOUT(7POINT1POINT2), |
| 517 | DEFINE_OUTPUT_LAYOUT(7POINT1POINT4), |
| 518 | DEFINE_OUTPUT_LAYOUT(13POINT_360RA), |
| 519 | DEFINE_OUTPUT_LAYOUT(22POINT2), |
| 520 | DEFINE_OUTPUT_LAYOUT(MONO_HAPTIC_A), |
| 521 | DEFINE_OUTPUT_LAYOUT(STEREO_HAPTIC_A), |
| 522 | DEFINE_OUTPUT_LAYOUT(HAPTIC_AB), |
| 523 | DEFINE_OUTPUT_LAYOUT(MONO_HAPTIC_AB), |
| 524 | DEFINE_OUTPUT_LAYOUT(STEREO_HAPTIC_AB) |
| 525 | #undef DEFINE_OUTPUT_LAYOUT |
| 526 | }; |
| 527 | return pairs; |
| 528 | } |
| 529 | |
Mikhail Naganov | 09a7381 | 2021-06-17 18:00:55 -0700 | [diff] [blame] | 530 | media::AudioDeviceDescription make_AudioDeviceDescription(media::AudioDeviceType type, |
| 531 | const std::string& connection = "") { |
| 532 | media::AudioDeviceDescription result; |
| 533 | result.type = type; |
| 534 | result.connection = connection; |
| 535 | return result; |
| 536 | } |
| 537 | |
| 538 | void append_AudioDeviceDescription(detail::AudioDevicePairs& pairs, |
| 539 | audio_devices_t inputType, audio_devices_t outputType, |
| 540 | media::AudioDeviceType inType, media::AudioDeviceType outType, |
| 541 | const std::string& connection = "") { |
| 542 | pairs.push_back(std::make_pair(inputType, make_AudioDeviceDescription(inType, connection))); |
| 543 | pairs.push_back(std::make_pair(outputType, make_AudioDeviceDescription(outType, connection))); |
| 544 | } |
| 545 | |
| 546 | const detail::AudioDevicePairs& getAudioDevicePairs() { |
| 547 | static const detail::AudioDevicePairs pairs = []() { |
| 548 | detail::AudioDevicePairs pairs = {{ |
| 549 | { |
| 550 | AUDIO_DEVICE_NONE, media::AudioDeviceDescription{} |
| 551 | }, |
| 552 | { |
| 553 | AUDIO_DEVICE_OUT_EARPIECE, make_AudioDeviceDescription( |
| 554 | media::AudioDeviceType::OUT_SPEAKER_EARPIECE) |
| 555 | }, |
| 556 | { |
| 557 | AUDIO_DEVICE_OUT_SPEAKER, make_AudioDeviceDescription( |
| 558 | media::AudioDeviceType::OUT_SPEAKER) |
| 559 | }, |
| 560 | { |
| 561 | AUDIO_DEVICE_OUT_WIRED_HEADPHONE, make_AudioDeviceDescription( |
| 562 | media::AudioDeviceType::OUT_HEADPHONE, |
| 563 | media::AudioDeviceDescription::CONNECTION_ANALOG()) |
| 564 | }, |
| 565 | { |
| 566 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO, make_AudioDeviceDescription( |
| 567 | media::AudioDeviceType::OUT_DEVICE, |
| 568 | media::AudioDeviceDescription::CONNECTION_BT_SCO()) |
| 569 | }, |
| 570 | { |
| 571 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT, make_AudioDeviceDescription( |
| 572 | media::AudioDeviceType::OUT_CARKIT, |
| 573 | media::AudioDeviceDescription::CONNECTION_BT_SCO()) |
| 574 | }, |
| 575 | { |
| 576 | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, make_AudioDeviceDescription( |
| 577 | media::AudioDeviceType::OUT_HEADPHONE, |
| 578 | media::AudioDeviceDescription::CONNECTION_BT_A2DP()) |
| 579 | }, |
| 580 | { |
| 581 | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER, make_AudioDeviceDescription( |
| 582 | media::AudioDeviceType::OUT_SPEAKER, |
| 583 | media::AudioDeviceDescription::CONNECTION_BT_A2DP()) |
| 584 | }, |
| 585 | { |
| 586 | AUDIO_DEVICE_OUT_TELEPHONY_TX, make_AudioDeviceDescription( |
| 587 | media::AudioDeviceType::OUT_TELEPHONY_TX) |
| 588 | }, |
| 589 | { |
| 590 | AUDIO_DEVICE_OUT_AUX_LINE, make_AudioDeviceDescription( |
| 591 | media::AudioDeviceType::OUT_LINE_AUX) |
| 592 | }, |
| 593 | { |
| 594 | AUDIO_DEVICE_OUT_SPEAKER_SAFE, make_AudioDeviceDescription( |
| 595 | media::AudioDeviceType::OUT_SPEAKER_SAFE) |
| 596 | }, |
| 597 | { |
| 598 | AUDIO_DEVICE_OUT_HEARING_AID, make_AudioDeviceDescription( |
| 599 | media::AudioDeviceType::OUT_HEARING_AID, |
| 600 | media::AudioDeviceDescription::CONNECTION_WIRELESS()) |
| 601 | }, |
| 602 | { |
| 603 | AUDIO_DEVICE_OUT_ECHO_CANCELLER, make_AudioDeviceDescription( |
| 604 | media::AudioDeviceType::OUT_ECHO_CANCELLER) |
| 605 | }, |
| 606 | { |
| 607 | AUDIO_DEVICE_OUT_BLE_SPEAKER, make_AudioDeviceDescription( |
| 608 | media::AudioDeviceType::OUT_SPEAKER, |
| 609 | media::AudioDeviceDescription::CONNECTION_BT_LE()) |
| 610 | }, |
| 611 | // AUDIO_DEVICE_IN_AMBIENT and IN_COMMUNICATION are removed since they were deprecated. |
| 612 | { |
| 613 | AUDIO_DEVICE_IN_BUILTIN_MIC, make_AudioDeviceDescription( |
| 614 | media::AudioDeviceType::IN_MICROPHONE) |
| 615 | }, |
| 616 | { |
| 617 | AUDIO_DEVICE_IN_BACK_MIC, make_AudioDeviceDescription( |
| 618 | media::AudioDeviceType::IN_MICROPHONE_BACK) |
| 619 | }, |
| 620 | { |
| 621 | AUDIO_DEVICE_IN_TELEPHONY_RX, make_AudioDeviceDescription( |
| 622 | media::AudioDeviceType::IN_TELEPHONY_RX) |
| 623 | }, |
| 624 | { |
| 625 | AUDIO_DEVICE_IN_TV_TUNER, make_AudioDeviceDescription( |
| 626 | media::AudioDeviceType::IN_TV_TUNER) |
| 627 | }, |
| 628 | { |
| 629 | AUDIO_DEVICE_IN_LOOPBACK, make_AudioDeviceDescription( |
| 630 | media::AudioDeviceType::IN_LOOPBACK) |
| 631 | }, |
| 632 | { |
| 633 | AUDIO_DEVICE_IN_BLUETOOTH_BLE, make_AudioDeviceDescription( |
| 634 | media::AudioDeviceType::IN_DEVICE, |
| 635 | media::AudioDeviceDescription::CONNECTION_BT_LE()) |
| 636 | }, |
| 637 | { |
| 638 | AUDIO_DEVICE_IN_ECHO_REFERENCE, make_AudioDeviceDescription( |
| 639 | media::AudioDeviceType::IN_ECHO_REFERENCE) |
| 640 | } |
| 641 | }}; |
| 642 | append_AudioDeviceDescription(pairs, |
| 643 | AUDIO_DEVICE_IN_DEFAULT, AUDIO_DEVICE_OUT_DEFAULT, |
| 644 | media::AudioDeviceType::IN_DEFAULT, media::AudioDeviceType::OUT_DEFAULT); |
| 645 | append_AudioDeviceDescription(pairs, |
| 646 | AUDIO_DEVICE_IN_WIRED_HEADSET, AUDIO_DEVICE_OUT_WIRED_HEADSET, |
| 647 | media::AudioDeviceType::IN_HEADSET, media::AudioDeviceType::OUT_HEADSET, |
| 648 | media::AudioDeviceDescription::CONNECTION_ANALOG()); |
| 649 | append_AudioDeviceDescription(pairs, |
| 650 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET, |
| 651 | media::AudioDeviceType::IN_HEADSET, media::AudioDeviceType::OUT_HEADSET, |
| 652 | media::AudioDeviceDescription::CONNECTION_BT_SCO()); |
| 653 | append_AudioDeviceDescription(pairs, |
| 654 | AUDIO_DEVICE_IN_HDMI, AUDIO_DEVICE_OUT_HDMI, |
| 655 | media::AudioDeviceType::IN_DEVICE, media::AudioDeviceType::OUT_DEVICE, |
| 656 | media::AudioDeviceDescription::CONNECTION_HDMI()); |
| 657 | append_AudioDeviceDescription(pairs, |
| 658 | AUDIO_DEVICE_IN_REMOTE_SUBMIX, AUDIO_DEVICE_OUT_REMOTE_SUBMIX, |
| 659 | media::AudioDeviceType::IN_SUBMIX, media::AudioDeviceType::OUT_SUBMIX); |
| 660 | append_AudioDeviceDescription(pairs, |
| 661 | AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET, AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET, |
| 662 | media::AudioDeviceType::IN_HEADSET, media::AudioDeviceType::OUT_HEADSET, |
| 663 | media::AudioDeviceDescription::CONNECTION_ANALOG_DOCK()); |
| 664 | append_AudioDeviceDescription(pairs, |
| 665 | AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET, AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET, |
| 666 | media::AudioDeviceType::IN_HEADSET, media::AudioDeviceType::OUT_HEADSET, |
| 667 | media::AudioDeviceDescription::CONNECTION_DIGITAL_DOCK()); |
| 668 | append_AudioDeviceDescription(pairs, |
| 669 | AUDIO_DEVICE_IN_USB_ACCESSORY, AUDIO_DEVICE_OUT_USB_ACCESSORY, |
| 670 | media::AudioDeviceType::IN_ACCESSORY, media::AudioDeviceType::OUT_ACCESSORY, |
| 671 | media::AudioDeviceDescription::CONNECTION_USB()); |
| 672 | append_AudioDeviceDescription(pairs, |
| 673 | AUDIO_DEVICE_IN_USB_DEVICE, AUDIO_DEVICE_OUT_USB_DEVICE, |
| 674 | media::AudioDeviceType::IN_DEVICE, media::AudioDeviceType::OUT_DEVICE, |
| 675 | media::AudioDeviceDescription::CONNECTION_USB()); |
| 676 | append_AudioDeviceDescription(pairs, |
| 677 | AUDIO_DEVICE_IN_FM_TUNER, AUDIO_DEVICE_OUT_FM, |
| 678 | media::AudioDeviceType::IN_FM_TUNER, media::AudioDeviceType::OUT_FM); |
| 679 | append_AudioDeviceDescription(pairs, |
| 680 | AUDIO_DEVICE_IN_LINE, AUDIO_DEVICE_OUT_LINE, |
| 681 | media::AudioDeviceType::IN_DEVICE, media::AudioDeviceType::OUT_DEVICE, |
| 682 | media::AudioDeviceDescription::CONNECTION_ANALOG()); |
| 683 | append_AudioDeviceDescription(pairs, |
| 684 | AUDIO_DEVICE_IN_SPDIF, AUDIO_DEVICE_OUT_SPDIF, |
| 685 | media::AudioDeviceType::IN_DEVICE, media::AudioDeviceType::OUT_DEVICE, |
| 686 | media::AudioDeviceDescription::CONNECTION_SPDIF()); |
| 687 | append_AudioDeviceDescription(pairs, |
| 688 | AUDIO_DEVICE_IN_BLUETOOTH_A2DP, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP, |
| 689 | media::AudioDeviceType::IN_DEVICE, media::AudioDeviceType::OUT_DEVICE, |
| 690 | media::AudioDeviceDescription::CONNECTION_BT_A2DP()); |
| 691 | append_AudioDeviceDescription(pairs, |
| 692 | AUDIO_DEVICE_IN_IP, AUDIO_DEVICE_OUT_IP, |
| 693 | media::AudioDeviceType::IN_DEVICE, media::AudioDeviceType::OUT_DEVICE, |
| 694 | media::AudioDeviceDescription::CONNECTION_IP_V4()); |
| 695 | append_AudioDeviceDescription(pairs, |
| 696 | AUDIO_DEVICE_IN_BUS, AUDIO_DEVICE_OUT_BUS, |
| 697 | media::AudioDeviceType::IN_DEVICE, media::AudioDeviceType::OUT_DEVICE, |
| 698 | media::AudioDeviceDescription::CONNECTION_BUS()); |
| 699 | append_AudioDeviceDescription(pairs, |
| 700 | AUDIO_DEVICE_IN_PROXY, AUDIO_DEVICE_OUT_PROXY, |
| 701 | media::AudioDeviceType::IN_AFE_PROXY, media::AudioDeviceType::OUT_AFE_PROXY); |
| 702 | append_AudioDeviceDescription(pairs, |
| 703 | AUDIO_DEVICE_IN_USB_HEADSET, AUDIO_DEVICE_OUT_USB_HEADSET, |
| 704 | media::AudioDeviceType::IN_HEADSET, media::AudioDeviceType::OUT_HEADSET, |
| 705 | media::AudioDeviceDescription::CONNECTION_USB()); |
| 706 | append_AudioDeviceDescription(pairs, |
| 707 | AUDIO_DEVICE_IN_HDMI_ARC, AUDIO_DEVICE_OUT_HDMI_ARC, |
| 708 | media::AudioDeviceType::IN_DEVICE, media::AudioDeviceType::OUT_DEVICE, |
| 709 | media::AudioDeviceDescription::CONNECTION_HDMI_ARC()); |
| 710 | append_AudioDeviceDescription(pairs, |
| 711 | AUDIO_DEVICE_IN_HDMI_EARC, AUDIO_DEVICE_OUT_HDMI_EARC, |
| 712 | media::AudioDeviceType::IN_DEVICE, media::AudioDeviceType::OUT_DEVICE, |
| 713 | media::AudioDeviceDescription::CONNECTION_HDMI_EARC()); |
| 714 | append_AudioDeviceDescription(pairs, |
| 715 | AUDIO_DEVICE_IN_BLE_HEADSET, AUDIO_DEVICE_OUT_BLE_HEADSET, |
| 716 | media::AudioDeviceType::IN_HEADSET, media::AudioDeviceType::OUT_HEADSET, |
| 717 | media::AudioDeviceDescription::CONNECTION_BT_LE()); |
| 718 | return pairs; |
| 719 | }(); |
| 720 | return pairs; |
| 721 | } |
| 722 | |
Mikhail Naganov | e128b8e | 2021-06-04 17:31:03 -0700 | [diff] [blame] | 723 | media::AudioFormatDescription make_AudioFormatDescription(media::AudioFormatType type) { |
| 724 | media::AudioFormatDescription result; |
| 725 | result.type = type; |
| 726 | return result; |
| 727 | } |
| 728 | |
| 729 | media::AudioFormatDescription make_AudioFormatDescription(media::PcmType pcm) { |
| 730 | auto result = make_AudioFormatDescription(media::AudioFormatType::PCM); |
| 731 | result.pcm = pcm; |
| 732 | return result; |
| 733 | } |
| 734 | |
| 735 | media::AudioFormatDescription make_AudioFormatDescription(const std::string& encoding) { |
| 736 | media::AudioFormatDescription result; |
| 737 | result.encoding = encoding; |
| 738 | return result; |
| 739 | } |
| 740 | |
| 741 | media::AudioFormatDescription make_AudioFormatDescription(media::PcmType transport, |
| 742 | const std::string& encoding) { |
| 743 | auto result = make_AudioFormatDescription(encoding); |
| 744 | result.pcm = transport; |
| 745 | return result; |
| 746 | } |
| 747 | |
| 748 | const detail::AudioFormatPairs& getAudioFormatPairs() { |
| 749 | static const detail::AudioFormatPairs pairs = {{ |
| 750 | { |
| 751 | AUDIO_FORMAT_INVALID, |
| 752 | make_AudioFormatDescription(media::AudioFormatType::SYS_RESERVED_INVALID) |
| 753 | }, |
| 754 | { |
| 755 | AUDIO_FORMAT_DEFAULT, media::AudioFormatDescription{} |
| 756 | }, |
| 757 | { |
| 758 | AUDIO_FORMAT_PCM_16_BIT, make_AudioFormatDescription(media::PcmType::INT_16_BIT) |
| 759 | }, |
| 760 | { |
| 761 | AUDIO_FORMAT_PCM_8_BIT, make_AudioFormatDescription(media::PcmType::UINT_8_BIT) |
| 762 | }, |
| 763 | { |
| 764 | AUDIO_FORMAT_PCM_32_BIT, make_AudioFormatDescription(media::PcmType::INT_32_BIT) |
| 765 | }, |
| 766 | { |
| 767 | AUDIO_FORMAT_PCM_8_24_BIT, make_AudioFormatDescription(media::PcmType::FIXED_Q_8_24) |
| 768 | }, |
| 769 | { |
| 770 | AUDIO_FORMAT_PCM_FLOAT, make_AudioFormatDescription(media::PcmType::FLOAT_32_BIT) |
| 771 | }, |
| 772 | { |
| 773 | AUDIO_FORMAT_PCM_24_BIT_PACKED, make_AudioFormatDescription(media::PcmType::INT_24_BIT) |
| 774 | }, |
| 775 | { |
| 776 | // See the comment in MediaDefs.h. |
| 777 | AUDIO_FORMAT_MP3, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_MPEG) |
| 778 | }, |
| 779 | { |
| 780 | AUDIO_FORMAT_AMR_NB, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AMR_NB) |
| 781 | }, |
| 782 | { |
| 783 | AUDIO_FORMAT_AMR_WB, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AMR_WB) |
| 784 | }, |
| 785 | { |
| 786 | // Note: in MediaDefs.cpp MEDIA_MIMETYPE_AUDIO_AAC = "audio/mp4a-latm". |
| 787 | AUDIO_FORMAT_AAC, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AAC_FORMAT) |
| 788 | }, |
| 789 | { |
| 790 | // Note: not in the IANA registry. |
| 791 | AUDIO_FORMAT_AAC_MAIN, make_AudioFormatDescription("audio/aac.main") |
| 792 | }, |
| 793 | { |
| 794 | // Note: not in the IANA registry. |
| 795 | AUDIO_FORMAT_AAC_LC, make_AudioFormatDescription("audio/aac.lc") |
| 796 | }, |
| 797 | { |
| 798 | // Note: not in the IANA registry. |
| 799 | AUDIO_FORMAT_AAC_SSR, make_AudioFormatDescription("audio/aac.ssr") |
| 800 | }, |
| 801 | { |
| 802 | // Note: not in the IANA registry. |
| 803 | AUDIO_FORMAT_AAC_LTP, make_AudioFormatDescription("audio/aac.ltp") |
| 804 | }, |
| 805 | { |
| 806 | // Note: not in the IANA registry. |
| 807 | AUDIO_FORMAT_AAC_HE_V1, make_AudioFormatDescription("audio/aac.he.v1") |
| 808 | }, |
| 809 | { |
| 810 | // Note: not in the IANA registry. |
| 811 | AUDIO_FORMAT_AAC_SCALABLE, make_AudioFormatDescription("audio/aac.scalable") |
| 812 | }, |
| 813 | { |
| 814 | // Note: not in the IANA registry. |
| 815 | AUDIO_FORMAT_AAC_ERLC, make_AudioFormatDescription("audio/aac.erlc") |
| 816 | }, |
| 817 | { |
| 818 | // Note: not in the IANA registry. |
| 819 | AUDIO_FORMAT_AAC_LD, make_AudioFormatDescription("audio/aac.ld") |
| 820 | }, |
| 821 | { |
| 822 | // Note: not in the IANA registry. |
| 823 | AUDIO_FORMAT_AAC_HE_V2, make_AudioFormatDescription("audio/aac.he.v2") |
| 824 | }, |
| 825 | { |
| 826 | // Note: not in the IANA registry. |
| 827 | AUDIO_FORMAT_AAC_ELD, make_AudioFormatDescription("audio/aac.eld") |
| 828 | }, |
| 829 | { |
| 830 | // Note: not in the IANA registry. |
| 831 | AUDIO_FORMAT_AAC_XHE, make_AudioFormatDescription("audio/aac.xhe") |
| 832 | }, |
| 833 | // AUDIO_FORMAT_HE_AAC_V1 and HE_AAC_V2 are removed since they were deprecated long time |
| 834 | // ago. |
| 835 | { |
| 836 | AUDIO_FORMAT_VORBIS, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_VORBIS) |
| 837 | }, |
| 838 | { |
| 839 | AUDIO_FORMAT_OPUS, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_OPUS) |
| 840 | }, |
| 841 | { |
| 842 | AUDIO_FORMAT_AC3, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AC3) |
| 843 | }, |
| 844 | { |
| 845 | AUDIO_FORMAT_E_AC3, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_EAC3) |
| 846 | }, |
| 847 | { |
| 848 | // Note: not in the IANA registry. |
| 849 | AUDIO_FORMAT_E_AC3_JOC, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_EAC3_JOC) |
| 850 | }, |
| 851 | { |
| 852 | AUDIO_FORMAT_DTS, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_DTS) |
| 853 | }, |
| 854 | { |
| 855 | AUDIO_FORMAT_DTS_HD, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_DTS_HD) |
| 856 | }, |
| 857 | // In the future, we would like to represent encapsulated bitstreams as |
| 858 | // nested AudioFormatDescriptions. The legacy 'AUDIO_FORMAT_IEC61937' type doesn't |
| 859 | // specify the format of the encapsulated bitstream. |
| 860 | { |
| 861 | // Note: not in the IANA registry. |
| 862 | AUDIO_FORMAT_IEC61937, |
| 863 | make_AudioFormatDescription(media::PcmType::INT_16_BIT, "audio/x-iec61937") |
| 864 | }, |
| 865 | { |
| 866 | // Note: not in the IANA registry. |
| 867 | AUDIO_FORMAT_DOLBY_TRUEHD, make_AudioFormatDescription("audio/vnd.dolby.truehd") |
| 868 | }, |
| 869 | { |
| 870 | AUDIO_FORMAT_EVRC, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_EVRC) |
| 871 | }, |
| 872 | { |
| 873 | AUDIO_FORMAT_EVRCB, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_EVRCB) |
| 874 | }, |
| 875 | { |
| 876 | AUDIO_FORMAT_EVRCWB, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_EVRCWB) |
| 877 | }, |
| 878 | { |
| 879 | AUDIO_FORMAT_EVRCNW, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_EVRCNW) |
| 880 | }, |
| 881 | { |
| 882 | // Note: not in the IANA registry. |
| 883 | AUDIO_FORMAT_AAC_ADIF, make_AudioFormatDescription("audio/aac.adif") |
| 884 | }, |
| 885 | { |
| 886 | // Note: not in the IANA registry. |
| 887 | AUDIO_FORMAT_WMA, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_WMA) |
| 888 | }, |
| 889 | { |
| 890 | // Note: not in the IANA registry. |
| 891 | AUDIO_FORMAT_WMA_PRO, make_AudioFormatDescription("audio/x-ms-wma.pro") |
| 892 | }, |
| 893 | { |
| 894 | AUDIO_FORMAT_AMR_WB_PLUS, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AMR_WB_PLUS) |
| 895 | }, |
| 896 | { |
| 897 | // Note: not in the IANA registry. |
| 898 | AUDIO_FORMAT_MP2, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_II) |
| 899 | }, |
| 900 | { |
| 901 | AUDIO_FORMAT_QCELP, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_QCELP) |
| 902 | }, |
| 903 | { |
| 904 | // Note: not in the IANA registry. |
| 905 | AUDIO_FORMAT_DSD, make_AudioFormatDescription("audio/vnd.sony.dsd") |
| 906 | }, |
| 907 | { |
| 908 | AUDIO_FORMAT_FLAC, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_FLAC) |
| 909 | }, |
| 910 | { |
| 911 | // Note: not in the IANA registry. |
| 912 | AUDIO_FORMAT_ALAC, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_ALAC) |
| 913 | }, |
| 914 | { |
| 915 | // Note: not in the IANA registry. |
| 916 | AUDIO_FORMAT_APE, make_AudioFormatDescription("audio/x-ape") |
| 917 | }, |
| 918 | { |
| 919 | // Note: not in the IANA registry. |
| 920 | AUDIO_FORMAT_AAC_ADTS, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AAC_ADTS) |
| 921 | }, |
| 922 | { |
| 923 | // Note: not in the IANA registry. |
| 924 | AUDIO_FORMAT_AAC_ADTS_MAIN, make_AudioFormatDescription("audio/aac-adts.main") |
| 925 | }, |
| 926 | { |
| 927 | // Note: not in the IANA registry. |
| 928 | AUDIO_FORMAT_AAC_ADTS_LC, make_AudioFormatDescription("audio/aac-adts.lc") |
| 929 | }, |
| 930 | { |
| 931 | // Note: not in the IANA registry. |
| 932 | AUDIO_FORMAT_AAC_ADTS_SSR, make_AudioFormatDescription("audio/aac-adts.ssr") |
| 933 | }, |
| 934 | { |
| 935 | // Note: not in the IANA registry. |
| 936 | AUDIO_FORMAT_AAC_ADTS_LTP, make_AudioFormatDescription("audio/aac-adts.ltp") |
| 937 | }, |
| 938 | { |
| 939 | // Note: not in the IANA registry. |
| 940 | AUDIO_FORMAT_AAC_ADTS_HE_V1, make_AudioFormatDescription("audio/aac-adts.he.v1") |
| 941 | }, |
| 942 | { |
| 943 | // Note: not in the IANA registry. |
| 944 | AUDIO_FORMAT_AAC_ADTS_SCALABLE, make_AudioFormatDescription("audio/aac-adts.scalable") |
| 945 | }, |
| 946 | { |
| 947 | // Note: not in the IANA registry. |
| 948 | AUDIO_FORMAT_AAC_ADTS_ERLC, make_AudioFormatDescription("audio/aac-adts.erlc") |
| 949 | }, |
| 950 | { |
| 951 | // Note: not in the IANA registry. |
| 952 | AUDIO_FORMAT_AAC_ADTS_LD, make_AudioFormatDescription("audio/aac-adts.ld") |
| 953 | }, |
| 954 | { |
| 955 | // Note: not in the IANA registry. |
| 956 | AUDIO_FORMAT_AAC_ADTS_HE_V2, make_AudioFormatDescription("audio/aac-adts.he.v2") |
| 957 | }, |
| 958 | { |
| 959 | // Note: not in the IANA registry. |
| 960 | AUDIO_FORMAT_AAC_ADTS_ELD, make_AudioFormatDescription("audio/aac-adts.eld") |
| 961 | }, |
| 962 | { |
| 963 | // Note: not in the IANA registry. |
| 964 | AUDIO_FORMAT_AAC_ADTS_XHE, make_AudioFormatDescription("audio/aac-adts.xhe") |
| 965 | }, |
| 966 | { |
| 967 | // Note: not in the IANA registry. "vnd.octel.sbc" is not BT SBC. |
| 968 | AUDIO_FORMAT_SBC, make_AudioFormatDescription("audio/x-sbc") |
| 969 | }, |
| 970 | { |
| 971 | AUDIO_FORMAT_APTX, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_APTX) |
| 972 | }, |
| 973 | { |
| 974 | // Note: not in the IANA registry. |
| 975 | AUDIO_FORMAT_APTX_HD, make_AudioFormatDescription("audio/vnd.qcom.aptx.hd") |
| 976 | }, |
| 977 | { |
| 978 | // Note: not in the IANA registry. Matches MediaDefs.cpp. |
| 979 | AUDIO_FORMAT_AC4, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AC4) |
| 980 | }, |
| 981 | { |
| 982 | // Note: not in the IANA registry. |
| 983 | AUDIO_FORMAT_LDAC, make_AudioFormatDescription("audio/vnd.sony.ldac") |
| 984 | }, |
| 985 | { |
| 986 | // Note: not in the IANA registry. |
| 987 | AUDIO_FORMAT_MAT, make_AudioFormatDescription("audio/vnd.dolby.mat") |
| 988 | }, |
| 989 | { |
| 990 | // Note: not in the IANA registry. |
| 991 | AUDIO_FORMAT_MAT_1_0, make_AudioFormatDescription("audio/vnd.dolby.mat.1.0") |
| 992 | }, |
| 993 | { |
| 994 | // Note: not in the IANA registry. |
| 995 | AUDIO_FORMAT_MAT_2_0, make_AudioFormatDescription("audio/vnd.dolby.mat.2.0") |
| 996 | }, |
| 997 | { |
| 998 | // Note: not in the IANA registry. |
| 999 | AUDIO_FORMAT_MAT_2_1, make_AudioFormatDescription("audio/vnd.dolby.mat.2.1") |
| 1000 | }, |
| 1001 | { |
| 1002 | AUDIO_FORMAT_AAC_LATM, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AAC) |
| 1003 | }, |
| 1004 | { |
| 1005 | // Note: not in the IANA registry. |
| 1006 | AUDIO_FORMAT_AAC_LATM_LC, make_AudioFormatDescription("audio/mp4a-latm.lc") |
| 1007 | }, |
| 1008 | { |
| 1009 | // Note: not in the IANA registry. |
| 1010 | AUDIO_FORMAT_AAC_LATM_HE_V1, make_AudioFormatDescription("audio/mp4a-latm.he.v1") |
| 1011 | }, |
| 1012 | { |
| 1013 | // Note: not in the IANA registry. |
| 1014 | AUDIO_FORMAT_AAC_LATM_HE_V2, make_AudioFormatDescription("audio/mp4a-latm.he.v2") |
| 1015 | }, |
| 1016 | { |
| 1017 | // Note: not in the IANA registry. |
| 1018 | AUDIO_FORMAT_CELT, make_AudioFormatDescription("audio/x-celt") |
| 1019 | }, |
| 1020 | { |
| 1021 | // Note: not in the IANA registry. |
| 1022 | AUDIO_FORMAT_APTX_ADAPTIVE, make_AudioFormatDescription("audio/vnd.qcom.aptx.adaptive") |
| 1023 | }, |
| 1024 | { |
| 1025 | // Note: not in the IANA registry. |
| 1026 | AUDIO_FORMAT_LHDC, make_AudioFormatDescription("audio/vnd.savitech.lhdc") |
| 1027 | }, |
| 1028 | { |
| 1029 | // Note: not in the IANA registry. |
| 1030 | AUDIO_FORMAT_LHDC_LL, make_AudioFormatDescription("audio/vnd.savitech.lhdc.ll") |
| 1031 | }, |
| 1032 | { |
| 1033 | // Note: not in the IANA registry. |
| 1034 | AUDIO_FORMAT_APTX_TWSP, make_AudioFormatDescription("audio/vnd.qcom.aptx.twsp") |
| 1035 | }, |
| 1036 | { |
| 1037 | // Note: not in the IANA registry. |
| 1038 | AUDIO_FORMAT_LC3, make_AudioFormatDescription("audio/x-lc3") |
| 1039 | }, |
| 1040 | { |
| 1041 | // Note: not in the IANA registry. |
| 1042 | AUDIO_FORMAT_MPEGH, make_AudioFormatDescription("audio/x-mpegh") |
| 1043 | }, |
| 1044 | { |
| 1045 | // Note: not in the IANA registry. |
| 1046 | AUDIO_FORMAT_MPEGH_BL_L3, make_AudioFormatDescription("audio/x-mpegh.bl.l3") |
| 1047 | }, |
| 1048 | { |
| 1049 | // Note: not in the IANA registry. |
| 1050 | AUDIO_FORMAT_MPEGH_BL_L4, make_AudioFormatDescription("audio/x-mpegh.bl.l4") |
| 1051 | }, |
| 1052 | { |
| 1053 | // Note: not in the IANA registry. |
| 1054 | AUDIO_FORMAT_MPEGH_LC_L3, make_AudioFormatDescription("audio/x-mpegh.lc.l3") |
| 1055 | }, |
| 1056 | { |
| 1057 | // Note: not in the IANA registry. |
| 1058 | AUDIO_FORMAT_MPEGH_LC_L4, make_AudioFormatDescription("audio/x-mpegh.lc.l4") |
| 1059 | }, |
| 1060 | { |
| 1061 | // Note: not in the IANA registry. |
| 1062 | AUDIO_FORMAT_IEC60958, |
| 1063 | make_AudioFormatDescription(media::PcmType::INT_24_BIT, "audio/x-iec60958") |
| 1064 | }, |
| 1065 | { |
| 1066 | AUDIO_FORMAT_DTS_UHD, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_DTS_UHD) |
| 1067 | }, |
| 1068 | { |
| 1069 | AUDIO_FORMAT_DRA, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_DRA) |
| 1070 | }, |
| 1071 | }}; |
| 1072 | return pairs; |
| 1073 | } |
| 1074 | |
Mikhail Naganov | 09a7381 | 2021-06-17 18:00:55 -0700 | [diff] [blame] | 1075 | template<typename S, typename T> |
| 1076 | std::unordered_map<S, T> make_DirectMap(const std::vector<std::pair<S, T>>& v) { |
| 1077 | std::unordered_map<S, T> result(v.begin(), v.end()); |
| 1078 | LOG_ALWAYS_FATAL_IF(result.size() != v.size(), "Duplicate key elements detected"); |
| 1079 | return result; |
| 1080 | } |
| 1081 | |
| 1082 | template<typename S, typename T> |
| 1083 | std::unordered_map<T, S> make_ReverseMap(const std::vector<std::pair<S, T>>& v) { |
| 1084 | std::unordered_map<T, S> result; |
| 1085 | std::transform(v.begin(), v.end(), std::inserter(result, result.begin()), |
| 1086 | [](const std::pair<S, T>& p) { |
| 1087 | return std::make_pair(p.second, p.first); |
| 1088 | }); |
| 1089 | LOG_ALWAYS_FATAL_IF(result.size() != v.size(), "Duplicate key elements detected"); |
| 1090 | return result; |
| 1091 | } |
| 1092 | |
Mikhail Naganov | e128b8e | 2021-06-04 17:31:03 -0700 | [diff] [blame] | 1093 | } // namespace |
| 1094 | |
Mikhail Naganov | cf2fa81 | 2021-06-25 09:03:37 -0700 | [diff] [blame^] | 1095 | ConversionResult<audio_channel_mask_t> aidl2legacy_AudioChannelLayout_audio_channel_mask_t( |
| 1096 | const media::AudioChannelLayout& aidl, bool isOutput) { |
| 1097 | using ReverseMap = std::unordered_map<media::AudioChannelLayout, audio_channel_mask_t>; |
| 1098 | using Tag = media::AudioChannelLayout::Tag; |
| 1099 | static const ReverseMap mIdx = make_ReverseMap(getIndexAudioChannelPairs()); |
| 1100 | static const ReverseMap mIn = make_ReverseMap(getInAudioChannelPairs()); |
| 1101 | static const ReverseMap mOut = make_ReverseMap(getOutAudioChannelPairs()); |
| 1102 | |
| 1103 | auto convert = [](const media::AudioChannelLayout& aidl, const ReverseMap& m, |
| 1104 | const char* func, const char* type) -> ConversionResult<audio_channel_mask_t> { |
| 1105 | if (auto it = m.find(aidl); it != m.end()) { |
| 1106 | return it->second; |
| 1107 | } else { |
| 1108 | ALOGE("%s: no legacy %s audio_channel_mask_t found for %s", func, type, |
| 1109 | aidl.toString().c_str()); |
| 1110 | return unexpected(BAD_VALUE); |
| 1111 | } |
| 1112 | }; |
| 1113 | |
| 1114 | switch (aidl.getTag()) { |
| 1115 | case Tag::none: |
| 1116 | return AUDIO_CHANNEL_NONE; |
| 1117 | case Tag::invalid: |
| 1118 | return AUDIO_CHANNEL_INVALID; |
| 1119 | case Tag::indexMask: |
| 1120 | return convert(aidl, mIdx, __func__, "index"); |
| 1121 | case Tag::layoutMask: |
| 1122 | return convert(aidl, isOutput ? mOut : mIn, __func__, isOutput ? "output" : "input"); |
| 1123 | } |
| 1124 | ALOGE("%s: unexpected tag value %d", __func__, aidl.getTag()); |
| 1125 | return unexpected(BAD_VALUE); |
| 1126 | } |
| 1127 | |
| 1128 | ConversionResult<media::AudioChannelLayout> legacy2aidl_audio_channel_mask_t_AudioChannelLayout( |
| 1129 | audio_channel_mask_t legacy, bool isOutput) { |
| 1130 | using DirectMap = std::unordered_map<audio_channel_mask_t, media::AudioChannelLayout>; |
| 1131 | using Tag = media::AudioChannelLayout::Tag; |
| 1132 | static const DirectMap mIdx = make_DirectMap(getIndexAudioChannelPairs()); |
| 1133 | static const DirectMap mIn = make_DirectMap(getInAudioChannelPairs()); |
| 1134 | static const DirectMap mOut = make_DirectMap(getOutAudioChannelPairs()); |
| 1135 | |
| 1136 | auto convert = [](const audio_channel_mask_t legacy, const DirectMap& m, |
| 1137 | const char* func, const char* type) -> ConversionResult<media::AudioChannelLayout> { |
| 1138 | if (auto it = m.find(legacy); it != m.end()) { |
| 1139 | return it->second; |
| 1140 | } else { |
| 1141 | ALOGE("%s: no AudioChannelLayout found for legacy %s audio_channel_mask_t value 0x%x", |
| 1142 | func, type, legacy); |
| 1143 | return unexpected(BAD_VALUE); |
| 1144 | } |
| 1145 | }; |
| 1146 | |
| 1147 | if (legacy == AUDIO_CHANNEL_NONE) { |
| 1148 | return media::AudioChannelLayout{}; |
| 1149 | } else if (legacy == AUDIO_CHANNEL_INVALID) { |
| 1150 | return media::AudioChannelLayout::make<Tag::invalid>(0); |
| 1151 | } |
| 1152 | |
| 1153 | const audio_channel_representation_t repr = audio_channel_mask_get_representation(legacy); |
| 1154 | if (repr == AUDIO_CHANNEL_REPRESENTATION_INDEX) { |
| 1155 | return convert(legacy, mIdx, __func__, "index"); |
| 1156 | } else if (repr == AUDIO_CHANNEL_REPRESENTATION_POSITION) { |
| 1157 | return convert(legacy, isOutput ? mOut : mIn, __func__, isOutput ? "output" : "input"); |
| 1158 | } |
| 1159 | |
| 1160 | ALOGE("%s: unknown representation %d in audio_channel_mask_t value 0x%x", |
| 1161 | __func__, repr, legacy); |
| 1162 | return unexpected(BAD_VALUE); |
| 1163 | } |
| 1164 | |
Mikhail Naganov | 09a7381 | 2021-06-17 18:00:55 -0700 | [diff] [blame] | 1165 | ConversionResult<audio_devices_t> aidl2legacy_AudioDeviceDescription_audio_devices_t( |
| 1166 | const media::AudioDeviceDescription& aidl) { |
| 1167 | static const std::unordered_map<media::AudioDeviceDescription, audio_devices_t> m = |
| 1168 | make_ReverseMap(getAudioDevicePairs()); |
| 1169 | if (auto it = m.find(aidl); it != m.end()) { |
| 1170 | return it->second; |
| 1171 | } else { |
| 1172 | ALOGE("%s: no legacy audio_devices_t found for %s", __func__, aidl.toString().c_str()); |
| 1173 | return unexpected(BAD_VALUE); |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | ConversionResult<media::AudioDeviceDescription> legacy2aidl_audio_devices_t_AudioDeviceDescription( |
| 1178 | audio_devices_t legacy) { |
| 1179 | static const std::unordered_map<audio_devices_t, media::AudioDeviceDescription> m = |
| 1180 | make_DirectMap(getAudioDevicePairs()); |
| 1181 | if (auto it = m.find(legacy); it != m.end()) { |
| 1182 | return it->second; |
| 1183 | } else { |
| 1184 | ALOGE("%s: no AudioDeviceDescription found for legacy audio_devices_t value 0x%x", |
| 1185 | __func__, legacy); |
| 1186 | return unexpected(BAD_VALUE); |
| 1187 | } |
| 1188 | } |
| 1189 | |
Mikhail Naganov | e128b8e | 2021-06-04 17:31:03 -0700 | [diff] [blame] | 1190 | ConversionResult<audio_format_t> aidl2legacy_AudioFormatDescription_audio_format_t( |
| 1191 | const media::AudioFormatDescription& aidl) { |
| 1192 | static const std::unordered_map<media::AudioFormatDescription, audio_format_t> m = |
Mikhail Naganov | 09a7381 | 2021-06-17 18:00:55 -0700 | [diff] [blame] | 1193 | make_ReverseMap(getAudioFormatPairs()); |
Mikhail Naganov | e128b8e | 2021-06-04 17:31:03 -0700 | [diff] [blame] | 1194 | if (auto it = m.find(aidl); it != m.end()) { |
| 1195 | return it->second; |
| 1196 | } else { |
| 1197 | ALOGE("%s: no legacy audio_format_t found for %s", __func__, aidl.toString().c_str()); |
| 1198 | return unexpected(BAD_VALUE); |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | ConversionResult<media::AudioFormatDescription> legacy2aidl_audio_format_t_AudioFormatDescription( |
| 1203 | audio_format_t legacy) { |
| 1204 | static const std::unordered_map<audio_format_t, media::AudioFormatDescription> m = |
Mikhail Naganov | 09a7381 | 2021-06-17 18:00:55 -0700 | [diff] [blame] | 1205 | make_DirectMap(getAudioFormatPairs()); |
Mikhail Naganov | e128b8e | 2021-06-04 17:31:03 -0700 | [diff] [blame] | 1206 | if (auto it = m.find(legacy); it != m.end()) { |
| 1207 | return it->second; |
| 1208 | } else { |
| 1209 | ALOGE("%s: no AudioFormatDescription found for legacy audio_format_t value 0x%x", |
| 1210 | __func__, legacy); |
| 1211 | return unexpected(BAD_VALUE); |
| 1212 | } |
| 1213 | } |
| 1214 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1215 | ConversionResult<audio_gain_mode_t> aidl2legacy_AudioGainMode_audio_gain_mode_t(media::AudioGainMode aidl) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1216 | switch (aidl) { |
| 1217 | case media::AudioGainMode::JOINT: |
| 1218 | return AUDIO_GAIN_MODE_JOINT; |
| 1219 | case media::AudioGainMode::CHANNELS: |
| 1220 | return AUDIO_GAIN_MODE_CHANNELS; |
| 1221 | case media::AudioGainMode::RAMP: |
| 1222 | return AUDIO_GAIN_MODE_RAMP; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1223 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1224 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1227 | ConversionResult<media::AudioGainMode> legacy2aidl_audio_gain_mode_t_AudioGainMode(audio_gain_mode_t legacy) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1228 | switch (legacy) { |
| 1229 | case AUDIO_GAIN_MODE_JOINT: |
| 1230 | return media::AudioGainMode::JOINT; |
| 1231 | case AUDIO_GAIN_MODE_CHANNELS: |
| 1232 | return media::AudioGainMode::CHANNELS; |
| 1233 | case AUDIO_GAIN_MODE_RAMP: |
| 1234 | return media::AudioGainMode::RAMP; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1235 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1236 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1239 | ConversionResult<audio_gain_mode_t> aidl2legacy_int32_t_audio_gain_mode_t_mask(int32_t aidl) { |
| 1240 | return convertBitmask<audio_gain_mode_t, int32_t, audio_gain_mode_t, media::AudioGainMode>( |
| 1241 | aidl, aidl2legacy_AudioGainMode_audio_gain_mode_t, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1242 | // AudioGainMode is index-based. |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1243 | indexToEnum_index<media::AudioGainMode>, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1244 | // AUDIO_GAIN_MODE_* constants are mask-based. |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1245 | enumToMask_bitmask<audio_gain_mode_t, audio_gain_mode_t>); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1248 | ConversionResult<int32_t> legacy2aidl_audio_gain_mode_t_int32_t_mask(audio_gain_mode_t legacy) { |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1249 | return convertBitmask<int32_t, audio_gain_mode_t, media::AudioGainMode, audio_gain_mode_t>( |
| 1250 | legacy, legacy2aidl_audio_gain_mode_t_AudioGainMode, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1251 | // AUDIO_GAIN_MODE_* constants are mask-based. |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1252 | indexToEnum_bitmask<audio_gain_mode_t>, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1253 | // AudioGainMode is index-based. |
| 1254 | enumToMask_index<int32_t, media::AudioGainMode>); |
| 1255 | } |
| 1256 | |
| 1257 | ConversionResult<audio_devices_t> aidl2legacy_int32_t_audio_devices_t(int32_t aidl) { |
| 1258 | // TODO(ytai): bitfield? |
| 1259 | return convertReinterpret<audio_devices_t>(aidl); |
| 1260 | } |
| 1261 | |
| 1262 | ConversionResult<int32_t> legacy2aidl_audio_devices_t_int32_t(audio_devices_t legacy) { |
| 1263 | // TODO(ytai): bitfield? |
| 1264 | return convertReinterpret<int32_t>(legacy); |
| 1265 | } |
| 1266 | |
| 1267 | ConversionResult<audio_gain_config> aidl2legacy_AudioGainConfig_audio_gain_config( |
| 1268 | const media::AudioGainConfig& aidl, media::AudioPortRole role, media::AudioPortType type) { |
| 1269 | audio_gain_config legacy; |
| 1270 | legacy.index = VALUE_OR_RETURN(convertIntegral<int>(aidl.index)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1271 | legacy.mode = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_gain_mode_t_mask(aidl.mode)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1272 | legacy.channel_mask = |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1273 | VALUE_OR_RETURN(aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1274 | const bool isInput = VALUE_OR_RETURN(direction(role, type)) == Direction::INPUT; |
| 1275 | const bool isJoint = bitmaskIsSet(aidl.mode, media::AudioGainMode::JOINT); |
| 1276 | size_t numValues = isJoint ? 1 |
| 1277 | : isInput ? audio_channel_count_from_in_mask(legacy.channel_mask) |
| 1278 | : audio_channel_count_from_out_mask(legacy.channel_mask); |
| 1279 | if (aidl.values.size() != numValues || aidl.values.size() > std::size(legacy.values)) { |
| 1280 | return unexpected(BAD_VALUE); |
| 1281 | } |
| 1282 | for (size_t i = 0; i < numValues; ++i) { |
| 1283 | legacy.values[i] = VALUE_OR_RETURN(convertIntegral<int>(aidl.values[i])); |
| 1284 | } |
| 1285 | legacy.ramp_duration_ms = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.rampDurationMs)); |
| 1286 | return legacy; |
| 1287 | } |
| 1288 | |
| 1289 | ConversionResult<media::AudioGainConfig> legacy2aidl_audio_gain_config_AudioGainConfig( |
| 1290 | const audio_gain_config& legacy, audio_port_role_t role, audio_port_type_t type) { |
| 1291 | media::AudioGainConfig aidl; |
| 1292 | aidl.index = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.index)); |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1293 | aidl.mode = VALUE_OR_RETURN(legacy2aidl_audio_gain_mode_t_int32_t_mask(legacy.mode)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1294 | aidl.channelMask = |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1295 | VALUE_OR_RETURN(legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy.channel_mask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1296 | const bool isInput = VALUE_OR_RETURN(direction(role, type)) == Direction::INPUT; |
| 1297 | const bool isJoint = (legacy.mode & AUDIO_GAIN_MODE_JOINT) != 0; |
| 1298 | size_t numValues = isJoint ? 1 |
| 1299 | : isInput ? audio_channel_count_from_in_mask(legacy.channel_mask) |
| 1300 | : audio_channel_count_from_out_mask(legacy.channel_mask); |
| 1301 | aidl.values.resize(numValues); |
| 1302 | for (size_t i = 0; i < numValues; ++i) { |
| 1303 | aidl.values[i] = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.values[i])); |
| 1304 | } |
| 1305 | aidl.rampDurationMs = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.ramp_duration_ms)); |
| 1306 | return aidl; |
| 1307 | } |
| 1308 | |
| 1309 | ConversionResult<audio_input_flags_t> aidl2legacy_AudioInputFlags_audio_input_flags_t( |
| 1310 | media::AudioInputFlags aidl) { |
| 1311 | switch (aidl) { |
| 1312 | case media::AudioInputFlags::FAST: |
| 1313 | return AUDIO_INPUT_FLAG_FAST; |
| 1314 | case media::AudioInputFlags::HW_HOTWORD: |
| 1315 | return AUDIO_INPUT_FLAG_HW_HOTWORD; |
| 1316 | case media::AudioInputFlags::RAW: |
| 1317 | return AUDIO_INPUT_FLAG_RAW; |
| 1318 | case media::AudioInputFlags::SYNC: |
| 1319 | return AUDIO_INPUT_FLAG_SYNC; |
| 1320 | case media::AudioInputFlags::MMAP_NOIRQ: |
| 1321 | return AUDIO_INPUT_FLAG_MMAP_NOIRQ; |
| 1322 | case media::AudioInputFlags::VOIP_TX: |
| 1323 | return AUDIO_INPUT_FLAG_VOIP_TX; |
| 1324 | case media::AudioInputFlags::HW_AV_SYNC: |
| 1325 | return AUDIO_INPUT_FLAG_HW_AV_SYNC; |
| 1326 | case media::AudioInputFlags::DIRECT: |
| 1327 | return AUDIO_INPUT_FLAG_DIRECT; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1328 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1329 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | ConversionResult<media::AudioInputFlags> legacy2aidl_audio_input_flags_t_AudioInputFlags( |
| 1333 | audio_input_flags_t legacy) { |
| 1334 | switch (legacy) { |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1335 | case AUDIO_INPUT_FLAG_NONE: |
| 1336 | break; // shouldn't get here. must be listed -Werror,-Wswitch |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1337 | case AUDIO_INPUT_FLAG_FAST: |
| 1338 | return media::AudioInputFlags::FAST; |
| 1339 | case AUDIO_INPUT_FLAG_HW_HOTWORD: |
| 1340 | return media::AudioInputFlags::HW_HOTWORD; |
| 1341 | case AUDIO_INPUT_FLAG_RAW: |
| 1342 | return media::AudioInputFlags::RAW; |
| 1343 | case AUDIO_INPUT_FLAG_SYNC: |
| 1344 | return media::AudioInputFlags::SYNC; |
| 1345 | case AUDIO_INPUT_FLAG_MMAP_NOIRQ: |
| 1346 | return media::AudioInputFlags::MMAP_NOIRQ; |
| 1347 | case AUDIO_INPUT_FLAG_VOIP_TX: |
| 1348 | return media::AudioInputFlags::VOIP_TX; |
| 1349 | case AUDIO_INPUT_FLAG_HW_AV_SYNC: |
| 1350 | return media::AudioInputFlags::HW_AV_SYNC; |
| 1351 | case AUDIO_INPUT_FLAG_DIRECT: |
| 1352 | return media::AudioInputFlags::DIRECT; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1353 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1354 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | ConversionResult<audio_output_flags_t> aidl2legacy_AudioOutputFlags_audio_output_flags_t( |
| 1358 | media::AudioOutputFlags aidl) { |
| 1359 | switch (aidl) { |
| 1360 | case media::AudioOutputFlags::DIRECT: |
| 1361 | return AUDIO_OUTPUT_FLAG_DIRECT; |
| 1362 | case media::AudioOutputFlags::PRIMARY: |
| 1363 | return AUDIO_OUTPUT_FLAG_PRIMARY; |
| 1364 | case media::AudioOutputFlags::FAST: |
| 1365 | return AUDIO_OUTPUT_FLAG_FAST; |
| 1366 | case media::AudioOutputFlags::DEEP_BUFFER: |
| 1367 | return AUDIO_OUTPUT_FLAG_DEEP_BUFFER; |
| 1368 | case media::AudioOutputFlags::COMPRESS_OFFLOAD: |
| 1369 | return AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD; |
| 1370 | case media::AudioOutputFlags::NON_BLOCKING: |
| 1371 | return AUDIO_OUTPUT_FLAG_NON_BLOCKING; |
| 1372 | case media::AudioOutputFlags::HW_AV_SYNC: |
| 1373 | return AUDIO_OUTPUT_FLAG_HW_AV_SYNC; |
| 1374 | case media::AudioOutputFlags::TTS: |
| 1375 | return AUDIO_OUTPUT_FLAG_TTS; |
| 1376 | case media::AudioOutputFlags::RAW: |
| 1377 | return AUDIO_OUTPUT_FLAG_RAW; |
| 1378 | case media::AudioOutputFlags::SYNC: |
| 1379 | return AUDIO_OUTPUT_FLAG_SYNC; |
| 1380 | case media::AudioOutputFlags::IEC958_NONAUDIO: |
| 1381 | return AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO; |
| 1382 | case media::AudioOutputFlags::DIRECT_PCM: |
| 1383 | return AUDIO_OUTPUT_FLAG_DIRECT_PCM; |
| 1384 | case media::AudioOutputFlags::MMAP_NOIRQ: |
| 1385 | return AUDIO_OUTPUT_FLAG_MMAP_NOIRQ; |
| 1386 | case media::AudioOutputFlags::VOIP_RX: |
| 1387 | return AUDIO_OUTPUT_FLAG_VOIP_RX; |
| 1388 | case media::AudioOutputFlags::INCALL_MUSIC: |
| 1389 | return AUDIO_OUTPUT_FLAG_INCALL_MUSIC; |
Eric Laurent | 90fe31c | 2020-11-26 20:06:35 +0100 | [diff] [blame] | 1390 | case media::AudioOutputFlags::GAPLESS_OFFLOAD: |
| 1391 | return AUDIO_OUTPUT_FLAG_GAPLESS_OFFLOAD; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1392 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1393 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | ConversionResult<media::AudioOutputFlags> legacy2aidl_audio_output_flags_t_AudioOutputFlags( |
| 1397 | audio_output_flags_t legacy) { |
| 1398 | switch (legacy) { |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1399 | case AUDIO_OUTPUT_FLAG_NONE: |
| 1400 | break; // shouldn't get here. must be listed -Werror,-Wswitch |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1401 | case AUDIO_OUTPUT_FLAG_DIRECT: |
| 1402 | return media::AudioOutputFlags::DIRECT; |
| 1403 | case AUDIO_OUTPUT_FLAG_PRIMARY: |
| 1404 | return media::AudioOutputFlags::PRIMARY; |
| 1405 | case AUDIO_OUTPUT_FLAG_FAST: |
| 1406 | return media::AudioOutputFlags::FAST; |
| 1407 | case AUDIO_OUTPUT_FLAG_DEEP_BUFFER: |
| 1408 | return media::AudioOutputFlags::DEEP_BUFFER; |
| 1409 | case AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD: |
| 1410 | return media::AudioOutputFlags::COMPRESS_OFFLOAD; |
| 1411 | case AUDIO_OUTPUT_FLAG_NON_BLOCKING: |
| 1412 | return media::AudioOutputFlags::NON_BLOCKING; |
| 1413 | case AUDIO_OUTPUT_FLAG_HW_AV_SYNC: |
| 1414 | return media::AudioOutputFlags::HW_AV_SYNC; |
| 1415 | case AUDIO_OUTPUT_FLAG_TTS: |
| 1416 | return media::AudioOutputFlags::TTS; |
| 1417 | case AUDIO_OUTPUT_FLAG_RAW: |
| 1418 | return media::AudioOutputFlags::RAW; |
| 1419 | case AUDIO_OUTPUT_FLAG_SYNC: |
| 1420 | return media::AudioOutputFlags::SYNC; |
| 1421 | case AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO: |
| 1422 | return media::AudioOutputFlags::IEC958_NONAUDIO; |
| 1423 | case AUDIO_OUTPUT_FLAG_DIRECT_PCM: |
| 1424 | return media::AudioOutputFlags::DIRECT_PCM; |
| 1425 | case AUDIO_OUTPUT_FLAG_MMAP_NOIRQ: |
| 1426 | return media::AudioOutputFlags::MMAP_NOIRQ; |
| 1427 | case AUDIO_OUTPUT_FLAG_VOIP_RX: |
| 1428 | return media::AudioOutputFlags::VOIP_RX; |
| 1429 | case AUDIO_OUTPUT_FLAG_INCALL_MUSIC: |
| 1430 | return media::AudioOutputFlags::INCALL_MUSIC; |
Eric Laurent | 90fe31c | 2020-11-26 20:06:35 +0100 | [diff] [blame] | 1431 | case AUDIO_OUTPUT_FLAG_GAPLESS_OFFLOAD: |
| 1432 | return media::AudioOutputFlags::GAPLESS_OFFLOAD; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1433 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1434 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1437 | ConversionResult<audio_input_flags_t> aidl2legacy_int32_t_audio_input_flags_t_mask( |
| 1438 | int32_t aidl) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1439 | using LegacyMask = std::underlying_type_t<audio_input_flags_t>; |
| 1440 | |
| 1441 | LegacyMask converted = VALUE_OR_RETURN( |
| 1442 | (convertBitmask<LegacyMask, int32_t, audio_input_flags_t, media::AudioInputFlags>( |
| 1443 | aidl, aidl2legacy_AudioInputFlags_audio_input_flags_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1444 | indexToEnum_index<media::AudioInputFlags>, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1445 | enumToMask_bitmask<LegacyMask, audio_input_flags_t>))); |
| 1446 | return static_cast<audio_input_flags_t>(converted); |
| 1447 | } |
| 1448 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1449 | ConversionResult<int32_t> legacy2aidl_audio_input_flags_t_int32_t_mask( |
| 1450 | audio_input_flags_t legacy) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1451 | using LegacyMask = std::underlying_type_t<audio_input_flags_t>; |
| 1452 | |
| 1453 | LegacyMask legacyMask = static_cast<LegacyMask>(legacy); |
| 1454 | return convertBitmask<int32_t, LegacyMask, media::AudioInputFlags, audio_input_flags_t>( |
| 1455 | legacyMask, legacy2aidl_audio_input_flags_t_AudioInputFlags, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1456 | indexToEnum_bitmask<audio_input_flags_t>, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1457 | enumToMask_index<int32_t, media::AudioInputFlags>); |
| 1458 | } |
| 1459 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1460 | ConversionResult<audio_output_flags_t> aidl2legacy_int32_t_audio_output_flags_t_mask( |
| 1461 | int32_t aidl) { |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1462 | return convertBitmask<audio_output_flags_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1463 | int32_t, |
| 1464 | audio_output_flags_t, |
| 1465 | media::AudioOutputFlags>( |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1466 | aidl, aidl2legacy_AudioOutputFlags_audio_output_flags_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1467 | indexToEnum_index<media::AudioOutputFlags>, |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1468 | enumToMask_bitmask<audio_output_flags_t, audio_output_flags_t>); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1471 | ConversionResult<int32_t> legacy2aidl_audio_output_flags_t_int32_t_mask( |
| 1472 | audio_output_flags_t legacy) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1473 | using LegacyMask = std::underlying_type_t<audio_output_flags_t>; |
| 1474 | |
| 1475 | LegacyMask legacyMask = static_cast<LegacyMask>(legacy); |
| 1476 | return convertBitmask<int32_t, LegacyMask, media::AudioOutputFlags, audio_output_flags_t>( |
| 1477 | legacyMask, legacy2aidl_audio_output_flags_t_AudioOutputFlags, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1478 | indexToEnum_bitmask<audio_output_flags_t>, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1479 | enumToMask_index<int32_t, media::AudioOutputFlags>); |
| 1480 | } |
| 1481 | |
| 1482 | ConversionResult<audio_io_flags> aidl2legacy_AudioIoFlags_audio_io_flags( |
| 1483 | const media::AudioIoFlags& aidl, media::AudioPortRole role, media::AudioPortType type) { |
| 1484 | audio_io_flags legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1485 | Direction dir = VALUE_OR_RETURN(direction(role, type)); |
| 1486 | switch (dir) { |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1487 | case Direction::INPUT: { |
| 1488 | legacy.input = VALUE_OR_RETURN( |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1489 | aidl2legacy_int32_t_audio_input_flags_t_mask( |
| 1490 | VALUE_OR_RETURN(UNION_GET(aidl, input)))); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1491 | } |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1492 | break; |
| 1493 | |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1494 | case Direction::OUTPUT: { |
| 1495 | legacy.output = VALUE_OR_RETURN( |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1496 | aidl2legacy_int32_t_audio_output_flags_t_mask( |
| 1497 | VALUE_OR_RETURN(UNION_GET(aidl, output)))); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1498 | } |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1499 | break; |
| 1500 | } |
| 1501 | |
| 1502 | return legacy; |
| 1503 | } |
| 1504 | |
| 1505 | ConversionResult<media::AudioIoFlags> legacy2aidl_audio_io_flags_AudioIoFlags( |
| 1506 | const audio_io_flags& legacy, audio_port_role_t role, audio_port_type_t type) { |
| 1507 | media::AudioIoFlags aidl; |
| 1508 | |
| 1509 | Direction dir = VALUE_OR_RETURN(direction(role, type)); |
| 1510 | switch (dir) { |
| 1511 | case Direction::INPUT: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1512 | UNION_SET(aidl, input, |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1513 | VALUE_OR_RETURN(legacy2aidl_audio_input_flags_t_int32_t_mask( |
| 1514 | legacy.input))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1515 | break; |
| 1516 | case Direction::OUTPUT: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1517 | UNION_SET(aidl, output, |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1518 | VALUE_OR_RETURN(legacy2aidl_audio_output_flags_t_int32_t_mask( |
| 1519 | legacy.output))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1520 | break; |
| 1521 | } |
| 1522 | return aidl; |
| 1523 | } |
| 1524 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1525 | ConversionResult<audio_port_config_device_ext> |
| 1526 | aidl2legacy_AudioPortConfigDeviceExt_audio_port_config_device_ext( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1527 | const media::AudioPortConfigDeviceExt& aidl) { |
| 1528 | audio_port_config_device_ext legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1529 | 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] | 1530 | 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] | 1531 | 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] | 1532 | return legacy; |
| 1533 | } |
| 1534 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1535 | ConversionResult<media::AudioPortConfigDeviceExt> |
| 1536 | legacy2aidl_audio_port_config_device_ext_AudioPortConfigDeviceExt( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1537 | const audio_port_config_device_ext& legacy) { |
| 1538 | media::AudioPortConfigDeviceExt aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1539 | 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] | 1540 | 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] | 1541 | aidl.address = VALUE_OR_RETURN( |
| 1542 | legacy2aidl_string(legacy.address, AUDIO_DEVICE_MAX_ADDRESS_LEN)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1543 | return aidl; |
| 1544 | } |
| 1545 | |
| 1546 | ConversionResult<audio_stream_type_t> aidl2legacy_AudioStreamType_audio_stream_type_t( |
| 1547 | media::AudioStreamType aidl) { |
| 1548 | switch (aidl) { |
| 1549 | case media::AudioStreamType::DEFAULT: |
| 1550 | return AUDIO_STREAM_DEFAULT; |
| 1551 | case media::AudioStreamType::VOICE_CALL: |
| 1552 | return AUDIO_STREAM_VOICE_CALL; |
| 1553 | case media::AudioStreamType::SYSTEM: |
| 1554 | return AUDIO_STREAM_SYSTEM; |
| 1555 | case media::AudioStreamType::RING: |
| 1556 | return AUDIO_STREAM_RING; |
| 1557 | case media::AudioStreamType::MUSIC: |
| 1558 | return AUDIO_STREAM_MUSIC; |
| 1559 | case media::AudioStreamType::ALARM: |
| 1560 | return AUDIO_STREAM_ALARM; |
| 1561 | case media::AudioStreamType::NOTIFICATION: |
| 1562 | return AUDIO_STREAM_NOTIFICATION; |
| 1563 | case media::AudioStreamType::BLUETOOTH_SCO: |
| 1564 | return AUDIO_STREAM_BLUETOOTH_SCO; |
| 1565 | case media::AudioStreamType::ENFORCED_AUDIBLE: |
| 1566 | return AUDIO_STREAM_ENFORCED_AUDIBLE; |
| 1567 | case media::AudioStreamType::DTMF: |
| 1568 | return AUDIO_STREAM_DTMF; |
| 1569 | case media::AudioStreamType::TTS: |
| 1570 | return AUDIO_STREAM_TTS; |
| 1571 | case media::AudioStreamType::ACCESSIBILITY: |
| 1572 | return AUDIO_STREAM_ACCESSIBILITY; |
| 1573 | case media::AudioStreamType::ASSISTANT: |
| 1574 | return AUDIO_STREAM_ASSISTANT; |
| 1575 | case media::AudioStreamType::REROUTING: |
| 1576 | return AUDIO_STREAM_REROUTING; |
| 1577 | case media::AudioStreamType::PATCH: |
| 1578 | return AUDIO_STREAM_PATCH; |
| 1579 | case media::AudioStreamType::CALL_ASSISTANT: |
| 1580 | return AUDIO_STREAM_CALL_ASSISTANT; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1581 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1582 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | ConversionResult<media::AudioStreamType> legacy2aidl_audio_stream_type_t_AudioStreamType( |
| 1586 | audio_stream_type_t legacy) { |
| 1587 | switch (legacy) { |
| 1588 | case AUDIO_STREAM_DEFAULT: |
| 1589 | return media::AudioStreamType::DEFAULT; |
| 1590 | case AUDIO_STREAM_VOICE_CALL: |
| 1591 | return media::AudioStreamType::VOICE_CALL; |
| 1592 | case AUDIO_STREAM_SYSTEM: |
| 1593 | return media::AudioStreamType::SYSTEM; |
| 1594 | case AUDIO_STREAM_RING: |
| 1595 | return media::AudioStreamType::RING; |
| 1596 | case AUDIO_STREAM_MUSIC: |
| 1597 | return media::AudioStreamType::MUSIC; |
| 1598 | case AUDIO_STREAM_ALARM: |
| 1599 | return media::AudioStreamType::ALARM; |
| 1600 | case AUDIO_STREAM_NOTIFICATION: |
| 1601 | return media::AudioStreamType::NOTIFICATION; |
| 1602 | case AUDIO_STREAM_BLUETOOTH_SCO: |
| 1603 | return media::AudioStreamType::BLUETOOTH_SCO; |
| 1604 | case AUDIO_STREAM_ENFORCED_AUDIBLE: |
| 1605 | return media::AudioStreamType::ENFORCED_AUDIBLE; |
| 1606 | case AUDIO_STREAM_DTMF: |
| 1607 | return media::AudioStreamType::DTMF; |
| 1608 | case AUDIO_STREAM_TTS: |
| 1609 | return media::AudioStreamType::TTS; |
| 1610 | case AUDIO_STREAM_ACCESSIBILITY: |
| 1611 | return media::AudioStreamType::ACCESSIBILITY; |
| 1612 | case AUDIO_STREAM_ASSISTANT: |
| 1613 | return media::AudioStreamType::ASSISTANT; |
| 1614 | case AUDIO_STREAM_REROUTING: |
| 1615 | return media::AudioStreamType::REROUTING; |
| 1616 | case AUDIO_STREAM_PATCH: |
| 1617 | return media::AudioStreamType::PATCH; |
| 1618 | case AUDIO_STREAM_CALL_ASSISTANT: |
| 1619 | return media::AudioStreamType::CALL_ASSISTANT; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1620 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1621 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | ConversionResult<audio_source_t> aidl2legacy_AudioSourceType_audio_source_t( |
| 1625 | media::AudioSourceType aidl) { |
| 1626 | switch (aidl) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1627 | case media::AudioSourceType::INVALID: |
| 1628 | // This value does not have an enum |
| 1629 | return AUDIO_SOURCE_INVALID; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1630 | case media::AudioSourceType::DEFAULT: |
| 1631 | return AUDIO_SOURCE_DEFAULT; |
| 1632 | case media::AudioSourceType::MIC: |
| 1633 | return AUDIO_SOURCE_MIC; |
| 1634 | case media::AudioSourceType::VOICE_UPLINK: |
| 1635 | return AUDIO_SOURCE_VOICE_UPLINK; |
| 1636 | case media::AudioSourceType::VOICE_DOWNLINK: |
| 1637 | return AUDIO_SOURCE_VOICE_DOWNLINK; |
| 1638 | case media::AudioSourceType::VOICE_CALL: |
| 1639 | return AUDIO_SOURCE_VOICE_CALL; |
| 1640 | case media::AudioSourceType::CAMCORDER: |
| 1641 | return AUDIO_SOURCE_CAMCORDER; |
| 1642 | case media::AudioSourceType::VOICE_RECOGNITION: |
| 1643 | return AUDIO_SOURCE_VOICE_RECOGNITION; |
| 1644 | case media::AudioSourceType::VOICE_COMMUNICATION: |
| 1645 | return AUDIO_SOURCE_VOICE_COMMUNICATION; |
| 1646 | case media::AudioSourceType::REMOTE_SUBMIX: |
| 1647 | return AUDIO_SOURCE_REMOTE_SUBMIX; |
| 1648 | case media::AudioSourceType::UNPROCESSED: |
| 1649 | return AUDIO_SOURCE_UNPROCESSED; |
| 1650 | case media::AudioSourceType::VOICE_PERFORMANCE: |
| 1651 | return AUDIO_SOURCE_VOICE_PERFORMANCE; |
| 1652 | case media::AudioSourceType::ECHO_REFERENCE: |
| 1653 | return AUDIO_SOURCE_ECHO_REFERENCE; |
| 1654 | case media::AudioSourceType::FM_TUNER: |
| 1655 | return AUDIO_SOURCE_FM_TUNER; |
| 1656 | case media::AudioSourceType::HOTWORD: |
| 1657 | return AUDIO_SOURCE_HOTWORD; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1658 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1659 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | ConversionResult<media::AudioSourceType> legacy2aidl_audio_source_t_AudioSourceType( |
| 1663 | audio_source_t legacy) { |
| 1664 | switch (legacy) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1665 | case AUDIO_SOURCE_INVALID: |
| 1666 | return media::AudioSourceType::INVALID; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1667 | case AUDIO_SOURCE_DEFAULT: |
| 1668 | return media::AudioSourceType::DEFAULT; |
| 1669 | case AUDIO_SOURCE_MIC: |
| 1670 | return media::AudioSourceType::MIC; |
| 1671 | case AUDIO_SOURCE_VOICE_UPLINK: |
| 1672 | return media::AudioSourceType::VOICE_UPLINK; |
| 1673 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 1674 | return media::AudioSourceType::VOICE_DOWNLINK; |
| 1675 | case AUDIO_SOURCE_VOICE_CALL: |
| 1676 | return media::AudioSourceType::VOICE_CALL; |
| 1677 | case AUDIO_SOURCE_CAMCORDER: |
| 1678 | return media::AudioSourceType::CAMCORDER; |
| 1679 | case AUDIO_SOURCE_VOICE_RECOGNITION: |
| 1680 | return media::AudioSourceType::VOICE_RECOGNITION; |
| 1681 | case AUDIO_SOURCE_VOICE_COMMUNICATION: |
| 1682 | return media::AudioSourceType::VOICE_COMMUNICATION; |
| 1683 | case AUDIO_SOURCE_REMOTE_SUBMIX: |
| 1684 | return media::AudioSourceType::REMOTE_SUBMIX; |
| 1685 | case AUDIO_SOURCE_UNPROCESSED: |
| 1686 | return media::AudioSourceType::UNPROCESSED; |
| 1687 | case AUDIO_SOURCE_VOICE_PERFORMANCE: |
| 1688 | return media::AudioSourceType::VOICE_PERFORMANCE; |
| 1689 | case AUDIO_SOURCE_ECHO_REFERENCE: |
| 1690 | return media::AudioSourceType::ECHO_REFERENCE; |
| 1691 | case AUDIO_SOURCE_FM_TUNER: |
| 1692 | return media::AudioSourceType::FM_TUNER; |
| 1693 | case AUDIO_SOURCE_HOTWORD: |
| 1694 | return media::AudioSourceType::HOTWORD; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1695 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1696 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1699 | ConversionResult<audio_session_t> aidl2legacy_int32_t_audio_session_t(int32_t aidl) { |
| 1700 | return convertReinterpret<audio_session_t>(aidl); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1703 | ConversionResult<int32_t> legacy2aidl_audio_session_t_int32_t(audio_session_t legacy) { |
| 1704 | return convertReinterpret<int32_t>(legacy); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | // This type is unnamed in the original definition, thus we name it here. |
| 1708 | using audio_port_config_mix_ext_usecase = decltype(audio_port_config_mix_ext::usecase); |
| 1709 | |
| 1710 | ConversionResult<audio_port_config_mix_ext_usecase> aidl2legacy_AudioPortConfigMixExtUseCase( |
| 1711 | const media::AudioPortConfigMixExtUseCase& aidl, media::AudioPortRole role) { |
| 1712 | audio_port_config_mix_ext_usecase legacy; |
| 1713 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1714 | switch (role) { |
| 1715 | case media::AudioPortRole::NONE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1716 | // Just verify that the union is empty. |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1717 | VALUE_OR_RETURN(UNION_GET(aidl, unspecified)); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1718 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1719 | |
| 1720 | case media::AudioPortRole::SOURCE: |
| 1721 | // 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] | 1722 | legacy.stream = VALUE_OR_RETURN(aidl2legacy_AudioStreamType_audio_stream_type_t( |
| 1723 | VALUE_OR_RETURN(UNION_GET(aidl, stream)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1724 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1725 | |
| 1726 | case media::AudioPortRole::SINK: |
| 1727 | // 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] | 1728 | legacy.source = VALUE_OR_RETURN(aidl2legacy_AudioSourceType_audio_source_t( |
| 1729 | VALUE_OR_RETURN(UNION_GET(aidl, source)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1730 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1731 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1732 | LOG_ALWAYS_FATAL("Shouldn't get here"); // with -Werror,-Wswitch may compile-time fail |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | ConversionResult<media::AudioPortConfigMixExtUseCase> legacy2aidl_AudioPortConfigMixExtUseCase( |
| 1736 | const audio_port_config_mix_ext_usecase& legacy, audio_port_role_t role) { |
| 1737 | media::AudioPortConfigMixExtUseCase aidl; |
| 1738 | |
| 1739 | switch (role) { |
| 1740 | case AUDIO_PORT_ROLE_NONE: |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1741 | UNION_SET(aidl, unspecified, false); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1742 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1743 | case AUDIO_PORT_ROLE_SOURCE: |
| 1744 | // 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] | 1745 | UNION_SET(aidl, stream, VALUE_OR_RETURN( |
| 1746 | legacy2aidl_audio_stream_type_t_AudioStreamType(legacy.stream))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1747 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1748 | case AUDIO_PORT_ROLE_SINK: |
| 1749 | // 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] | 1750 | UNION_SET(aidl, source, |
| 1751 | VALUE_OR_RETURN(legacy2aidl_audio_source_t_AudioSourceType(legacy.source))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1752 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1753 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1754 | LOG_ALWAYS_FATAL("Shouldn't get here"); // with -Werror,-Wswitch may compile-time fail |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | ConversionResult<audio_port_config_mix_ext> aidl2legacy_AudioPortConfigMixExt( |
| 1758 | const media::AudioPortConfigMixExt& aidl, media::AudioPortRole role) { |
| 1759 | audio_port_config_mix_ext legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1760 | legacy.hw_module = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_module_handle_t(aidl.hwModule)); |
| 1761 | 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] | 1762 | legacy.usecase = VALUE_OR_RETURN(aidl2legacy_AudioPortConfigMixExtUseCase(aidl.usecase, role)); |
| 1763 | return legacy; |
| 1764 | } |
| 1765 | |
| 1766 | ConversionResult<media::AudioPortConfigMixExt> legacy2aidl_AudioPortConfigMixExt( |
| 1767 | const audio_port_config_mix_ext& legacy, audio_port_role_t role) { |
| 1768 | media::AudioPortConfigMixExt aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1769 | aidl.hwModule = VALUE_OR_RETURN(legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
| 1770 | 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] | 1771 | aidl.usecase = VALUE_OR_RETURN(legacy2aidl_AudioPortConfigMixExtUseCase(legacy.usecase, role)); |
| 1772 | return aidl; |
| 1773 | } |
| 1774 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1775 | ConversionResult<audio_port_config_session_ext> |
| 1776 | aidl2legacy_AudioPortConfigSessionExt_audio_port_config_session_ext( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1777 | const media::AudioPortConfigSessionExt& aidl) { |
| 1778 | audio_port_config_session_ext legacy; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1779 | 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] | 1780 | return legacy; |
| 1781 | } |
| 1782 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1783 | ConversionResult<media::AudioPortConfigSessionExt> |
| 1784 | legacy2aidl_audio_port_config_session_ext_AudioPortConfigSessionExt( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1785 | const audio_port_config_session_ext& legacy) { |
| 1786 | media::AudioPortConfigSessionExt aidl; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1787 | 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] | 1788 | return aidl; |
| 1789 | } |
| 1790 | |
| 1791 | // This type is unnamed in the original definition, thus we name it here. |
| 1792 | using audio_port_config_ext = decltype(audio_port_config::ext); |
| 1793 | |
| 1794 | ConversionResult<audio_port_config_ext> aidl2legacy_AudioPortConfigExt( |
| 1795 | const media::AudioPortConfigExt& aidl, media::AudioPortType type, |
| 1796 | media::AudioPortRole role) { |
| 1797 | audio_port_config_ext legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1798 | switch (type) { |
| 1799 | case media::AudioPortType::NONE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1800 | // Just verify that the union is empty. |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1801 | VALUE_OR_RETURN(UNION_GET(aidl, unspecified)); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1802 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1803 | case media::AudioPortType::DEVICE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1804 | legacy.device = VALUE_OR_RETURN( |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1805 | aidl2legacy_AudioPortConfigDeviceExt_audio_port_config_device_ext( |
| 1806 | VALUE_OR_RETURN(UNION_GET(aidl, device)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1807 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1808 | case media::AudioPortType::MIX: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1809 | legacy.mix = VALUE_OR_RETURN( |
| 1810 | aidl2legacy_AudioPortConfigMixExt(VALUE_OR_RETURN(UNION_GET(aidl, mix)), role)); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1811 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1812 | case media::AudioPortType::SESSION: |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1813 | legacy.session = VALUE_OR_RETURN( |
| 1814 | aidl2legacy_AudioPortConfigSessionExt_audio_port_config_session_ext( |
| 1815 | VALUE_OR_RETURN(UNION_GET(aidl, session)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1816 | return legacy; |
| 1817 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1818 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1819 | LOG_ALWAYS_FATAL("Shouldn't get here"); // with -Werror,-Wswitch may compile-time fail |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | ConversionResult<media::AudioPortConfigExt> legacy2aidl_AudioPortConfigExt( |
| 1823 | const audio_port_config_ext& legacy, audio_port_type_t type, audio_port_role_t role) { |
| 1824 | media::AudioPortConfigExt aidl; |
| 1825 | |
| 1826 | switch (type) { |
| 1827 | case AUDIO_PORT_TYPE_NONE: |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1828 | UNION_SET(aidl, unspecified, false); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1829 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1830 | case AUDIO_PORT_TYPE_DEVICE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1831 | UNION_SET(aidl, device, |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1832 | VALUE_OR_RETURN( |
| 1833 | legacy2aidl_audio_port_config_device_ext_AudioPortConfigDeviceExt( |
| 1834 | legacy.device))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1835 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1836 | case AUDIO_PORT_TYPE_MIX: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1837 | UNION_SET(aidl, mix, |
| 1838 | VALUE_OR_RETURN(legacy2aidl_AudioPortConfigMixExt(legacy.mix, role))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1839 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1840 | case AUDIO_PORT_TYPE_SESSION: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1841 | UNION_SET(aidl, session, |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1842 | VALUE_OR_RETURN( |
| 1843 | legacy2aidl_audio_port_config_session_ext_AudioPortConfigSessionExt( |
| 1844 | legacy.session))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1845 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1846 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1847 | LOG_ALWAYS_FATAL("Shouldn't get here"); // with -Werror,-Wswitch may compile-time fail |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | ConversionResult<audio_port_config> aidl2legacy_AudioPortConfig_audio_port_config( |
| 1851 | const media::AudioPortConfig& aidl) { |
| 1852 | audio_port_config legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1853 | 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] | 1854 | legacy.role = VALUE_OR_RETURN(aidl2legacy_AudioPortRole_audio_port_role_t(aidl.role)); |
| 1855 | legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioPortType_audio_port_type_t(aidl.type)); |
| 1856 | legacy.config_mask = VALUE_OR_RETURN(aidl2legacy_int32_t_config_mask(aidl.configMask)); |
| 1857 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::SAMPLE_RATE)) { |
| 1858 | legacy.sample_rate = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.sampleRate)); |
| 1859 | } |
| 1860 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::CHANNEL_MASK)) { |
| 1861 | legacy.channel_mask = |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1862 | VALUE_OR_RETURN( |
| 1863 | aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1864 | } |
| 1865 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::FORMAT)) { |
| 1866 | legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
| 1867 | } |
| 1868 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::GAIN)) { |
| 1869 | legacy.gain = VALUE_OR_RETURN( |
| 1870 | aidl2legacy_AudioGainConfig_audio_gain_config(aidl.gain, aidl.role, aidl.type)); |
| 1871 | } |
| 1872 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::FLAGS)) { |
| 1873 | legacy.flags = VALUE_OR_RETURN( |
| 1874 | aidl2legacy_AudioIoFlags_audio_io_flags(aidl.flags, aidl.role, aidl.type)); |
| 1875 | } |
| 1876 | legacy.ext = VALUE_OR_RETURN(aidl2legacy_AudioPortConfigExt(aidl.ext, aidl.type, aidl.role)); |
| 1877 | return legacy; |
| 1878 | } |
| 1879 | |
| 1880 | ConversionResult<media::AudioPortConfig> legacy2aidl_audio_port_config_AudioPortConfig( |
| 1881 | const audio_port_config& legacy) { |
| 1882 | media::AudioPortConfig aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1883 | 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] | 1884 | aidl.role = VALUE_OR_RETURN(legacy2aidl_audio_port_role_t_AudioPortRole(legacy.role)); |
| 1885 | aidl.type = VALUE_OR_RETURN(legacy2aidl_audio_port_type_t_AudioPortType(legacy.type)); |
| 1886 | aidl.configMask = VALUE_OR_RETURN(legacy2aidl_config_mask_int32_t(legacy.config_mask)); |
| 1887 | if (legacy.config_mask & AUDIO_PORT_CONFIG_SAMPLE_RATE) { |
| 1888 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.sample_rate)); |
| 1889 | } |
| 1890 | if (legacy.config_mask & AUDIO_PORT_CONFIG_CHANNEL_MASK) { |
| 1891 | aidl.channelMask = |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1892 | VALUE_OR_RETURN( |
| 1893 | legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy.channel_mask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1894 | } |
| 1895 | if (legacy.config_mask & AUDIO_PORT_CONFIG_FORMAT) { |
| 1896 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
| 1897 | } |
| 1898 | if (legacy.config_mask & AUDIO_PORT_CONFIG_GAIN) { |
| 1899 | aidl.gain = VALUE_OR_RETURN(legacy2aidl_audio_gain_config_AudioGainConfig( |
| 1900 | legacy.gain, legacy.role, legacy.type)); |
| 1901 | } |
| 1902 | if (legacy.config_mask & AUDIO_PORT_CONFIG_FLAGS) { |
| 1903 | aidl.flags = VALUE_OR_RETURN( |
| 1904 | legacy2aidl_audio_io_flags_AudioIoFlags(legacy.flags, legacy.role, legacy.type)); |
| 1905 | } |
| 1906 | aidl.ext = |
| 1907 | VALUE_OR_RETURN(legacy2aidl_AudioPortConfigExt(legacy.ext, legacy.type, legacy.role)); |
| 1908 | return aidl; |
| 1909 | } |
| 1910 | |
| 1911 | ConversionResult<struct audio_patch> aidl2legacy_AudioPatch_audio_patch( |
| 1912 | const media::AudioPatch& aidl) { |
| 1913 | struct audio_patch legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1914 | 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] | 1915 | legacy.num_sinks = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.sinks.size())); |
| 1916 | if (legacy.num_sinks > AUDIO_PATCH_PORTS_MAX) { |
| 1917 | return unexpected(BAD_VALUE); |
| 1918 | } |
| 1919 | for (size_t i = 0; i < legacy.num_sinks; ++i) { |
| 1920 | legacy.sinks[i] = |
| 1921 | VALUE_OR_RETURN(aidl2legacy_AudioPortConfig_audio_port_config(aidl.sinks[i])); |
| 1922 | } |
| 1923 | legacy.num_sources = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.sources.size())); |
| 1924 | if (legacy.num_sources > AUDIO_PATCH_PORTS_MAX) { |
| 1925 | return unexpected(BAD_VALUE); |
| 1926 | } |
| 1927 | for (size_t i = 0; i < legacy.num_sources; ++i) { |
| 1928 | legacy.sources[i] = |
| 1929 | VALUE_OR_RETURN(aidl2legacy_AudioPortConfig_audio_port_config(aidl.sources[i])); |
| 1930 | } |
| 1931 | return legacy; |
| 1932 | } |
| 1933 | |
| 1934 | ConversionResult<media::AudioPatch> legacy2aidl_audio_patch_AudioPatch( |
| 1935 | const struct audio_patch& legacy) { |
| 1936 | media::AudioPatch aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1937 | 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] | 1938 | |
| 1939 | if (legacy.num_sinks > AUDIO_PATCH_PORTS_MAX) { |
| 1940 | return unexpected(BAD_VALUE); |
| 1941 | } |
| 1942 | for (unsigned int i = 0; i < legacy.num_sinks; ++i) { |
| 1943 | aidl.sinks.push_back( |
| 1944 | VALUE_OR_RETURN(legacy2aidl_audio_port_config_AudioPortConfig(legacy.sinks[i]))); |
| 1945 | } |
| 1946 | if (legacy.num_sources > AUDIO_PATCH_PORTS_MAX) { |
| 1947 | return unexpected(BAD_VALUE); |
| 1948 | } |
| 1949 | for (unsigned int i = 0; i < legacy.num_sources; ++i) { |
| 1950 | aidl.sources.push_back( |
| 1951 | VALUE_OR_RETURN(legacy2aidl_audio_port_config_AudioPortConfig(legacy.sources[i]))); |
| 1952 | } |
| 1953 | return aidl; |
| 1954 | } |
| 1955 | |
| 1956 | ConversionResult<sp<AudioIoDescriptor>> aidl2legacy_AudioIoDescriptor_AudioIoDescriptor( |
| 1957 | const media::AudioIoDescriptor& aidl) { |
| 1958 | sp<AudioIoDescriptor> legacy(new AudioIoDescriptor()); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1959 | 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] | 1960 | legacy->mPatch = VALUE_OR_RETURN(aidl2legacy_AudioPatch_audio_patch(aidl.patch)); |
| 1961 | legacy->mSamplingRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.samplingRate)); |
| 1962 | legacy->mFormat = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
| 1963 | legacy->mChannelMask = |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1964 | VALUE_OR_RETURN(aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1965 | legacy->mFrameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount)); |
| 1966 | legacy->mFrameCountHAL = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCountHAL)); |
| 1967 | legacy->mLatency = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.latency)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1968 | 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] | 1969 | return legacy; |
| 1970 | } |
| 1971 | |
| 1972 | ConversionResult<media::AudioIoDescriptor> legacy2aidl_AudioIoDescriptor_AudioIoDescriptor( |
| 1973 | const sp<AudioIoDescriptor>& legacy) { |
| 1974 | media::AudioIoDescriptor aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1975 | 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] | 1976 | aidl.patch = VALUE_OR_RETURN(legacy2aidl_audio_patch_AudioPatch(legacy->mPatch)); |
| 1977 | aidl.samplingRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy->mSamplingRate)); |
| 1978 | 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] | 1979 | aidl.channelMask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1980 | legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy->mChannelMask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1981 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy->mFrameCount)); |
| 1982 | aidl.frameCountHAL = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy->mFrameCountHAL)); |
| 1983 | aidl.latency = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy->mLatency)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1984 | 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] | 1985 | return aidl; |
| 1986 | } |
| 1987 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1988 | ConversionResult<AudioClient> aidl2legacy_AudioClient_AudioClient( |
| 1989 | const media::AudioClient& aidl) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1990 | AudioClient legacy; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1991 | legacy.clientTid = VALUE_OR_RETURN(aidl2legacy_int32_t_pid_t(aidl.clientTid)); |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1992 | legacy.attributionSource = aidl.attributionSource; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1993 | return legacy; |
| 1994 | } |
| 1995 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1996 | ConversionResult<media::AudioClient> legacy2aidl_AudioClient_AudioClient( |
| 1997 | const AudioClient& legacy) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1998 | media::AudioClient aidl; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1999 | aidl.clientTid = VALUE_OR_RETURN(legacy2aidl_pid_t_int32_t(legacy.clientTid)); |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 2000 | aidl.attributionSource = legacy.attributionSource; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2001 | return aidl; |
| 2002 | } |
| 2003 | |
| 2004 | ConversionResult<audio_content_type_t> |
| 2005 | aidl2legacy_AudioContentType_audio_content_type_t(media::AudioContentType aidl) { |
| 2006 | switch (aidl) { |
| 2007 | case media::AudioContentType::UNKNOWN: |
| 2008 | return AUDIO_CONTENT_TYPE_UNKNOWN; |
| 2009 | case media::AudioContentType::SPEECH: |
| 2010 | return AUDIO_CONTENT_TYPE_SPEECH; |
| 2011 | case media::AudioContentType::MUSIC: |
| 2012 | return AUDIO_CONTENT_TYPE_MUSIC; |
| 2013 | case media::AudioContentType::MOVIE: |
| 2014 | return AUDIO_CONTENT_TYPE_MOVIE; |
| 2015 | case media::AudioContentType::SONIFICATION: |
| 2016 | return AUDIO_CONTENT_TYPE_SONIFICATION; |
| 2017 | } |
| 2018 | return unexpected(BAD_VALUE); |
| 2019 | } |
| 2020 | |
| 2021 | ConversionResult<media::AudioContentType> |
| 2022 | legacy2aidl_audio_content_type_t_AudioContentType(audio_content_type_t legacy) { |
| 2023 | switch (legacy) { |
| 2024 | case AUDIO_CONTENT_TYPE_UNKNOWN: |
| 2025 | return media::AudioContentType::UNKNOWN; |
| 2026 | case AUDIO_CONTENT_TYPE_SPEECH: |
| 2027 | return media::AudioContentType::SPEECH; |
| 2028 | case AUDIO_CONTENT_TYPE_MUSIC: |
| 2029 | return media::AudioContentType::MUSIC; |
| 2030 | case AUDIO_CONTENT_TYPE_MOVIE: |
| 2031 | return media::AudioContentType::MOVIE; |
| 2032 | case AUDIO_CONTENT_TYPE_SONIFICATION: |
| 2033 | return media::AudioContentType::SONIFICATION; |
| 2034 | } |
| 2035 | return unexpected(BAD_VALUE); |
| 2036 | } |
| 2037 | |
| 2038 | ConversionResult<audio_usage_t> |
| 2039 | aidl2legacy_AudioUsage_audio_usage_t(media::AudioUsage aidl) { |
| 2040 | switch (aidl) { |
| 2041 | case media::AudioUsage::UNKNOWN: |
| 2042 | return AUDIO_USAGE_UNKNOWN; |
| 2043 | case media::AudioUsage::MEDIA: |
| 2044 | return AUDIO_USAGE_MEDIA; |
| 2045 | case media::AudioUsage::VOICE_COMMUNICATION: |
| 2046 | return AUDIO_USAGE_VOICE_COMMUNICATION; |
| 2047 | case media::AudioUsage::VOICE_COMMUNICATION_SIGNALLING: |
| 2048 | return AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING; |
| 2049 | case media::AudioUsage::ALARM: |
| 2050 | return AUDIO_USAGE_ALARM; |
| 2051 | case media::AudioUsage::NOTIFICATION: |
| 2052 | return AUDIO_USAGE_NOTIFICATION; |
| 2053 | case media::AudioUsage::NOTIFICATION_TELEPHONY_RINGTONE: |
| 2054 | return AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE; |
| 2055 | case media::AudioUsage::NOTIFICATION_COMMUNICATION_REQUEST: |
| 2056 | return AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST; |
| 2057 | case media::AudioUsage::NOTIFICATION_COMMUNICATION_INSTANT: |
| 2058 | return AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT; |
| 2059 | case media::AudioUsage::NOTIFICATION_COMMUNICATION_DELAYED: |
| 2060 | return AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED; |
| 2061 | case media::AudioUsage::NOTIFICATION_EVENT: |
| 2062 | return AUDIO_USAGE_NOTIFICATION_EVENT; |
| 2063 | case media::AudioUsage::ASSISTANCE_ACCESSIBILITY: |
| 2064 | return AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY; |
| 2065 | case media::AudioUsage::ASSISTANCE_NAVIGATION_GUIDANCE: |
| 2066 | return AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE; |
| 2067 | case media::AudioUsage::ASSISTANCE_SONIFICATION: |
| 2068 | return AUDIO_USAGE_ASSISTANCE_SONIFICATION; |
| 2069 | case media::AudioUsage::GAME: |
| 2070 | return AUDIO_USAGE_GAME; |
| 2071 | case media::AudioUsage::VIRTUAL_SOURCE: |
| 2072 | return AUDIO_USAGE_VIRTUAL_SOURCE; |
| 2073 | case media::AudioUsage::ASSISTANT: |
| 2074 | return AUDIO_USAGE_ASSISTANT; |
| 2075 | case media::AudioUsage::CALL_ASSISTANT: |
| 2076 | return AUDIO_USAGE_CALL_ASSISTANT; |
| 2077 | case media::AudioUsage::EMERGENCY: |
| 2078 | return AUDIO_USAGE_EMERGENCY; |
| 2079 | case media::AudioUsage::SAFETY: |
| 2080 | return AUDIO_USAGE_SAFETY; |
| 2081 | case media::AudioUsage::VEHICLE_STATUS: |
| 2082 | return AUDIO_USAGE_VEHICLE_STATUS; |
| 2083 | case media::AudioUsage::ANNOUNCEMENT: |
| 2084 | return AUDIO_USAGE_ANNOUNCEMENT; |
| 2085 | } |
| 2086 | return unexpected(BAD_VALUE); |
| 2087 | } |
| 2088 | |
| 2089 | ConversionResult<media::AudioUsage> |
| 2090 | legacy2aidl_audio_usage_t_AudioUsage(audio_usage_t legacy) { |
| 2091 | switch (legacy) { |
| 2092 | case AUDIO_USAGE_UNKNOWN: |
| 2093 | return media::AudioUsage::UNKNOWN; |
| 2094 | case AUDIO_USAGE_MEDIA: |
| 2095 | return media::AudioUsage::MEDIA; |
| 2096 | case AUDIO_USAGE_VOICE_COMMUNICATION: |
| 2097 | return media::AudioUsage::VOICE_COMMUNICATION; |
| 2098 | case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING: |
| 2099 | return media::AudioUsage::VOICE_COMMUNICATION_SIGNALLING; |
| 2100 | case AUDIO_USAGE_ALARM: |
| 2101 | return media::AudioUsage::ALARM; |
| 2102 | case AUDIO_USAGE_NOTIFICATION: |
| 2103 | return media::AudioUsage::NOTIFICATION; |
| 2104 | case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE: |
| 2105 | return media::AudioUsage::NOTIFICATION_TELEPHONY_RINGTONE; |
| 2106 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST: |
| 2107 | return media::AudioUsage::NOTIFICATION_COMMUNICATION_REQUEST; |
| 2108 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT: |
| 2109 | return media::AudioUsage::NOTIFICATION_COMMUNICATION_INSTANT; |
| 2110 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED: |
| 2111 | return media::AudioUsage::NOTIFICATION_COMMUNICATION_DELAYED; |
| 2112 | case AUDIO_USAGE_NOTIFICATION_EVENT: |
| 2113 | return media::AudioUsage::NOTIFICATION_EVENT; |
| 2114 | case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY: |
| 2115 | return media::AudioUsage::ASSISTANCE_ACCESSIBILITY; |
| 2116 | case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE: |
| 2117 | return media::AudioUsage::ASSISTANCE_NAVIGATION_GUIDANCE; |
| 2118 | case AUDIO_USAGE_ASSISTANCE_SONIFICATION: |
| 2119 | return media::AudioUsage::ASSISTANCE_SONIFICATION; |
| 2120 | case AUDIO_USAGE_GAME: |
| 2121 | return media::AudioUsage::GAME; |
| 2122 | case AUDIO_USAGE_VIRTUAL_SOURCE: |
| 2123 | return media::AudioUsage::VIRTUAL_SOURCE; |
| 2124 | case AUDIO_USAGE_ASSISTANT: |
| 2125 | return media::AudioUsage::ASSISTANT; |
| 2126 | case AUDIO_USAGE_CALL_ASSISTANT: |
| 2127 | return media::AudioUsage::CALL_ASSISTANT; |
| 2128 | case AUDIO_USAGE_EMERGENCY: |
| 2129 | return media::AudioUsage::EMERGENCY; |
| 2130 | case AUDIO_USAGE_SAFETY: |
| 2131 | return media::AudioUsage::SAFETY; |
| 2132 | case AUDIO_USAGE_VEHICLE_STATUS: |
| 2133 | return media::AudioUsage::VEHICLE_STATUS; |
| 2134 | case AUDIO_USAGE_ANNOUNCEMENT: |
| 2135 | return media::AudioUsage::ANNOUNCEMENT; |
| 2136 | } |
| 2137 | return unexpected(BAD_VALUE); |
| 2138 | } |
| 2139 | |
| 2140 | ConversionResult<audio_flags_mask_t> |
| 2141 | aidl2legacy_AudioFlag_audio_flags_mask_t(media::AudioFlag aidl) { |
| 2142 | switch (aidl) { |
| 2143 | case media::AudioFlag::AUDIBILITY_ENFORCED: |
| 2144 | return AUDIO_FLAG_AUDIBILITY_ENFORCED; |
| 2145 | case media::AudioFlag::SECURE: |
| 2146 | return AUDIO_FLAG_SECURE; |
| 2147 | case media::AudioFlag::SCO: |
| 2148 | return AUDIO_FLAG_SCO; |
| 2149 | case media::AudioFlag::BEACON: |
| 2150 | return AUDIO_FLAG_BEACON; |
| 2151 | case media::AudioFlag::HW_AV_SYNC: |
| 2152 | return AUDIO_FLAG_HW_AV_SYNC; |
| 2153 | case media::AudioFlag::HW_HOTWORD: |
| 2154 | return AUDIO_FLAG_HW_HOTWORD; |
| 2155 | case media::AudioFlag::BYPASS_INTERRUPTION_POLICY: |
| 2156 | return AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY; |
| 2157 | case media::AudioFlag::BYPASS_MUTE: |
| 2158 | return AUDIO_FLAG_BYPASS_MUTE; |
| 2159 | case media::AudioFlag::LOW_LATENCY: |
| 2160 | return AUDIO_FLAG_LOW_LATENCY; |
| 2161 | case media::AudioFlag::DEEP_BUFFER: |
| 2162 | return AUDIO_FLAG_DEEP_BUFFER; |
| 2163 | case media::AudioFlag::NO_MEDIA_PROJECTION: |
| 2164 | return AUDIO_FLAG_NO_MEDIA_PROJECTION; |
| 2165 | case media::AudioFlag::MUTE_HAPTIC: |
| 2166 | return AUDIO_FLAG_MUTE_HAPTIC; |
| 2167 | case media::AudioFlag::NO_SYSTEM_CAPTURE: |
| 2168 | return AUDIO_FLAG_NO_SYSTEM_CAPTURE; |
| 2169 | case media::AudioFlag::CAPTURE_PRIVATE: |
| 2170 | return AUDIO_FLAG_CAPTURE_PRIVATE; |
| 2171 | } |
| 2172 | return unexpected(BAD_VALUE); |
| 2173 | } |
| 2174 | |
| 2175 | ConversionResult<media::AudioFlag> |
| 2176 | legacy2aidl_audio_flags_mask_t_AudioFlag(audio_flags_mask_t legacy) { |
| 2177 | switch (legacy) { |
| 2178 | case AUDIO_FLAG_NONE: |
| 2179 | return unexpected(BAD_VALUE); |
| 2180 | case AUDIO_FLAG_AUDIBILITY_ENFORCED: |
| 2181 | return media::AudioFlag::AUDIBILITY_ENFORCED; |
| 2182 | case AUDIO_FLAG_SECURE: |
| 2183 | return media::AudioFlag::SECURE; |
| 2184 | case AUDIO_FLAG_SCO: |
| 2185 | return media::AudioFlag::SCO; |
| 2186 | case AUDIO_FLAG_BEACON: |
| 2187 | return media::AudioFlag::BEACON; |
| 2188 | case AUDIO_FLAG_HW_AV_SYNC: |
| 2189 | return media::AudioFlag::HW_AV_SYNC; |
| 2190 | case AUDIO_FLAG_HW_HOTWORD: |
| 2191 | return media::AudioFlag::HW_HOTWORD; |
| 2192 | case AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY: |
| 2193 | return media::AudioFlag::BYPASS_INTERRUPTION_POLICY; |
| 2194 | case AUDIO_FLAG_BYPASS_MUTE: |
| 2195 | return media::AudioFlag::BYPASS_MUTE; |
| 2196 | case AUDIO_FLAG_LOW_LATENCY: |
| 2197 | return media::AudioFlag::LOW_LATENCY; |
| 2198 | case AUDIO_FLAG_DEEP_BUFFER: |
| 2199 | return media::AudioFlag::DEEP_BUFFER; |
| 2200 | case AUDIO_FLAG_NO_MEDIA_PROJECTION: |
| 2201 | return media::AudioFlag::NO_MEDIA_PROJECTION; |
| 2202 | case AUDIO_FLAG_MUTE_HAPTIC: |
| 2203 | return media::AudioFlag::MUTE_HAPTIC; |
| 2204 | case AUDIO_FLAG_NO_SYSTEM_CAPTURE: |
| 2205 | return media::AudioFlag::NO_SYSTEM_CAPTURE; |
| 2206 | case AUDIO_FLAG_CAPTURE_PRIVATE: |
| 2207 | return media::AudioFlag::CAPTURE_PRIVATE; |
| 2208 | } |
| 2209 | return unexpected(BAD_VALUE); |
| 2210 | } |
| 2211 | |
| 2212 | ConversionResult<audio_flags_mask_t> |
| 2213 | aidl2legacy_int32_t_audio_flags_mask_t_mask(int32_t aidl) { |
| 2214 | return convertBitmask<audio_flags_mask_t, int32_t, audio_flags_mask_t, media::AudioFlag>( |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2215 | aidl, aidl2legacy_AudioFlag_audio_flags_mask_t, indexToEnum_index<media::AudioFlag>, |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2216 | enumToMask_bitmask<audio_flags_mask_t, audio_flags_mask_t>); |
| 2217 | } |
| 2218 | |
| 2219 | ConversionResult<int32_t> |
| 2220 | legacy2aidl_audio_flags_mask_t_int32_t_mask(audio_flags_mask_t legacy) { |
| 2221 | 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] | 2222 | legacy, legacy2aidl_audio_flags_mask_t_AudioFlag, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2223 | indexToEnum_bitmask<audio_flags_mask_t>, |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2224 | enumToMask_index<int32_t, media::AudioFlag>); |
| 2225 | } |
| 2226 | |
| 2227 | ConversionResult<audio_attributes_t> |
| 2228 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(const media::AudioAttributesInternal& aidl) { |
| 2229 | audio_attributes_t legacy; |
| 2230 | legacy.content_type = VALUE_OR_RETURN( |
| 2231 | aidl2legacy_AudioContentType_audio_content_type_t(aidl.contentType)); |
| 2232 | legacy.usage = VALUE_OR_RETURN(aidl2legacy_AudioUsage_audio_usage_t(aidl.usage)); |
| 2233 | legacy.source = VALUE_OR_RETURN(aidl2legacy_AudioSourceType_audio_source_t(aidl.source)); |
| 2234 | legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_flags_mask_t_mask(aidl.flags)); |
| 2235 | RETURN_IF_ERROR(aidl2legacy_string(aidl.tags, legacy.tags, sizeof(legacy.tags))); |
| 2236 | return legacy; |
| 2237 | } |
| 2238 | |
| 2239 | ConversionResult<media::AudioAttributesInternal> |
| 2240 | legacy2aidl_audio_attributes_t_AudioAttributesInternal(const audio_attributes_t& legacy) { |
| 2241 | media::AudioAttributesInternal aidl; |
| 2242 | aidl.contentType = VALUE_OR_RETURN( |
| 2243 | legacy2aidl_audio_content_type_t_AudioContentType(legacy.content_type)); |
| 2244 | aidl.usage = VALUE_OR_RETURN(legacy2aidl_audio_usage_t_AudioUsage(legacy.usage)); |
| 2245 | aidl.source = VALUE_OR_RETURN(legacy2aidl_audio_source_t_AudioSourceType(legacy.source)); |
| 2246 | aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_flags_mask_t_int32_t_mask(legacy.flags)); |
| 2247 | aidl.tags = VALUE_OR_RETURN(legacy2aidl_string(legacy.tags, sizeof(legacy.tags))); |
| 2248 | return aidl; |
| 2249 | } |
| 2250 | |
| 2251 | ConversionResult<audio_encapsulation_mode_t> |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2252 | aidl2legacy_AudioEncapsulationMode_audio_encapsulation_mode_t(media::AudioEncapsulationMode aidl) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2253 | switch (aidl) { |
| 2254 | case media::AudioEncapsulationMode::NONE: |
| 2255 | return AUDIO_ENCAPSULATION_MODE_NONE; |
| 2256 | case media::AudioEncapsulationMode::ELEMENTARY_STREAM: |
| 2257 | return AUDIO_ENCAPSULATION_MODE_ELEMENTARY_STREAM; |
| 2258 | case media::AudioEncapsulationMode::HANDLE: |
| 2259 | return AUDIO_ENCAPSULATION_MODE_HANDLE; |
| 2260 | } |
| 2261 | return unexpected(BAD_VALUE); |
| 2262 | } |
| 2263 | |
| 2264 | ConversionResult<media::AudioEncapsulationMode> |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2265 | legacy2aidl_audio_encapsulation_mode_t_AudioEncapsulationMode(audio_encapsulation_mode_t legacy) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2266 | switch (legacy) { |
| 2267 | case AUDIO_ENCAPSULATION_MODE_NONE: |
| 2268 | return media::AudioEncapsulationMode::NONE; |
| 2269 | case AUDIO_ENCAPSULATION_MODE_ELEMENTARY_STREAM: |
| 2270 | return media::AudioEncapsulationMode::ELEMENTARY_STREAM; |
| 2271 | case AUDIO_ENCAPSULATION_MODE_HANDLE: |
| 2272 | return media::AudioEncapsulationMode::HANDLE; |
| 2273 | } |
| 2274 | return unexpected(BAD_VALUE); |
| 2275 | } |
| 2276 | |
| 2277 | ConversionResult<audio_offload_info_t> |
| 2278 | aidl2legacy_AudioOffloadInfo_audio_offload_info_t(const media::AudioOffloadInfo& aidl) { |
| 2279 | audio_offload_info_t legacy; |
| 2280 | legacy.version = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.version)); |
| 2281 | legacy.size = sizeof(audio_offload_info_t); |
| 2282 | audio_config_base_t config = VALUE_OR_RETURN( |
| 2283 | aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.config)); |
| 2284 | legacy.sample_rate = config.sample_rate; |
| 2285 | legacy.channel_mask = config.channel_mask; |
| 2286 | legacy.format = config.format; |
| 2287 | legacy.stream_type = VALUE_OR_RETURN( |
| 2288 | aidl2legacy_AudioStreamType_audio_stream_type_t(aidl.streamType)); |
| 2289 | legacy.bit_rate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.bitRate)); |
| 2290 | legacy.duration_us = VALUE_OR_RETURN(convertIntegral<int64_t>(aidl.durationUs)); |
| 2291 | legacy.has_video = aidl.hasVideo; |
| 2292 | legacy.is_streaming = aidl.isStreaming; |
| 2293 | legacy.bit_width = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.bitWidth)); |
| 2294 | legacy.offload_buffer_size = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.offloadBufferSize)); |
| 2295 | legacy.usage = VALUE_OR_RETURN(aidl2legacy_AudioUsage_audio_usage_t(aidl.usage)); |
| 2296 | legacy.encapsulation_mode = VALUE_OR_RETURN( |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2297 | aidl2legacy_AudioEncapsulationMode_audio_encapsulation_mode_t(aidl.encapsulationMode)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2298 | legacy.content_id = VALUE_OR_RETURN(convertReinterpret<int32_t>(aidl.contentId)); |
| 2299 | legacy.sync_id = VALUE_OR_RETURN(convertReinterpret<int32_t>(aidl.syncId)); |
| 2300 | return legacy; |
| 2301 | } |
| 2302 | |
| 2303 | ConversionResult<media::AudioOffloadInfo> |
| 2304 | legacy2aidl_audio_offload_info_t_AudioOffloadInfo(const audio_offload_info_t& legacy) { |
| 2305 | media::AudioOffloadInfo aidl; |
| 2306 | // Version 0.1 fields. |
| 2307 | if (legacy.size < offsetof(audio_offload_info_t, usage) + sizeof(audio_offload_info_t::usage)) { |
| 2308 | return unexpected(BAD_VALUE); |
| 2309 | } |
| 2310 | aidl.version = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.version)); |
| 2311 | aidl.config.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.sample_rate)); |
| 2312 | aidl.config.channelMask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2313 | legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy.channel_mask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2314 | aidl.config.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
| 2315 | aidl.streamType = VALUE_OR_RETURN( |
| 2316 | legacy2aidl_audio_stream_type_t_AudioStreamType(legacy.stream_type)); |
| 2317 | aidl.bitRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.bit_rate)); |
| 2318 | aidl.durationUs = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy.duration_us)); |
| 2319 | aidl.hasVideo = legacy.has_video; |
| 2320 | aidl.isStreaming = legacy.is_streaming; |
| 2321 | aidl.bitWidth = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.bit_width)); |
| 2322 | aidl.offloadBufferSize = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.offload_buffer_size)); |
| 2323 | aidl.usage = VALUE_OR_RETURN(legacy2aidl_audio_usage_t_AudioUsage(legacy.usage)); |
| 2324 | |
| 2325 | // Version 0.2 fields. |
| 2326 | if (legacy.version >= AUDIO_OFFLOAD_INFO_VERSION_0_2) { |
| 2327 | if (legacy.size < |
| 2328 | offsetof(audio_offload_info_t, sync_id) + sizeof(audio_offload_info_t::sync_id)) { |
| 2329 | return unexpected(BAD_VALUE); |
| 2330 | } |
| 2331 | aidl.encapsulationMode = VALUE_OR_RETURN( |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2332 | legacy2aidl_audio_encapsulation_mode_t_AudioEncapsulationMode( |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2333 | legacy.encapsulation_mode)); |
| 2334 | aidl.contentId = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.content_id)); |
| 2335 | aidl.syncId = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.sync_id)); |
| 2336 | } |
| 2337 | return aidl; |
| 2338 | } |
| 2339 | |
| 2340 | ConversionResult<audio_config_t> |
| 2341 | aidl2legacy_AudioConfig_audio_config_t(const media::AudioConfig& aidl) { |
| 2342 | audio_config_t legacy; |
| 2343 | legacy.sample_rate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 2344 | legacy.channel_mask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2345 | aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2346 | 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] | 2347 | legacy.offload_info = VALUE_OR_RETURN( |
| 2348 | aidl2legacy_AudioOffloadInfo_audio_offload_info_t(aidl.offloadInfo)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2349 | legacy.frame_count = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.frameCount)); |
| 2350 | return legacy; |
| 2351 | } |
| 2352 | |
| 2353 | ConversionResult<media::AudioConfig> |
| 2354 | legacy2aidl_audio_config_t_AudioConfig(const audio_config_t& legacy) { |
| 2355 | media::AudioConfig aidl; |
| 2356 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.sample_rate)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 2357 | aidl.channelMask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2358 | legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy.channel_mask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2359 | 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] | 2360 | aidl.offloadInfo = VALUE_OR_RETURN( |
| 2361 | legacy2aidl_audio_offload_info_t_AudioOffloadInfo(legacy.offload_info)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2362 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy.frame_count)); |
| 2363 | return aidl; |
| 2364 | } |
| 2365 | |
| 2366 | ConversionResult<audio_config_base_t> |
| 2367 | aidl2legacy_AudioConfigBase_audio_config_base_t(const media::AudioConfigBase& aidl) { |
| 2368 | audio_config_base_t legacy; |
| 2369 | legacy.sample_rate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 2370 | legacy.channel_mask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2371 | aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2372 | legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
| 2373 | return legacy; |
| 2374 | } |
| 2375 | |
| 2376 | ConversionResult<media::AudioConfigBase> |
| 2377 | legacy2aidl_audio_config_base_t_AudioConfigBase(const audio_config_base_t& legacy) { |
| 2378 | media::AudioConfigBase aidl; |
| 2379 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.sample_rate)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 2380 | aidl.channelMask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2381 | legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy.channel_mask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 2382 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
| 2383 | return aidl; |
| 2384 | } |
| 2385 | |
| 2386 | ConversionResult<sp<IMemory>> |
| 2387 | aidl2legacy_SharedFileRegion_IMemory(const media::SharedFileRegion& aidl) { |
| 2388 | sp<IMemory> legacy; |
| 2389 | if (!convertSharedFileRegionToIMemory(aidl, &legacy)) { |
| 2390 | return unexpected(BAD_VALUE); |
| 2391 | } |
| 2392 | return legacy; |
| 2393 | } |
| 2394 | |
| 2395 | ConversionResult<media::SharedFileRegion> |
| 2396 | legacy2aidl_IMemory_SharedFileRegion(const sp<IMemory>& legacy) { |
| 2397 | media::SharedFileRegion aidl; |
| 2398 | if (!convertIMemoryToSharedFileRegion(legacy, &aidl)) { |
| 2399 | return unexpected(BAD_VALUE); |
| 2400 | } |
| 2401 | return aidl; |
| 2402 | } |
| 2403 | |
| 2404 | ConversionResult<sp<IMemory>> |
| 2405 | aidl2legacy_NullableSharedFileRegion_IMemory(const std::optional<media::SharedFileRegion>& aidl) { |
| 2406 | sp<IMemory> legacy; |
| 2407 | if (!convertNullableSharedFileRegionToIMemory(aidl, &legacy)) { |
| 2408 | return unexpected(BAD_VALUE); |
| 2409 | } |
| 2410 | return legacy; |
| 2411 | } |
| 2412 | |
| 2413 | ConversionResult<std::optional<media::SharedFileRegion>> |
| 2414 | legacy2aidl_NullableIMemory_SharedFileRegion(const sp<IMemory>& legacy) { |
| 2415 | std::optional<media::SharedFileRegion> aidl; |
| 2416 | if (!convertNullableIMemoryToSharedFileRegion(legacy, &aidl)) { |
| 2417 | return unexpected(BAD_VALUE); |
| 2418 | } |
| 2419 | return aidl; |
| 2420 | } |
| 2421 | |
Ytai Ben-Tsvi | bdc293a | 2020-11-02 17:01:38 -0800 | [diff] [blame] | 2422 | ConversionResult<AudioTimestamp> |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 2423 | aidl2legacy_AudioTimestampInternal_AudioTimestamp(const media::AudioTimestampInternal& aidl) { |
Ytai Ben-Tsvi | bdc293a | 2020-11-02 17:01:38 -0800 | [diff] [blame] | 2424 | AudioTimestamp legacy; |
| 2425 | legacy.mPosition = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.position)); |
| 2426 | legacy.mTime.tv_sec = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sec)); |
| 2427 | legacy.mTime.tv_nsec = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.nsec)); |
| 2428 | return legacy; |
| 2429 | } |
| 2430 | |
| 2431 | ConversionResult<media::AudioTimestampInternal> |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 2432 | legacy2aidl_AudioTimestamp_AudioTimestampInternal(const AudioTimestamp& legacy) { |
Ytai Ben-Tsvi | bdc293a | 2020-11-02 17:01:38 -0800 | [diff] [blame] | 2433 | media::AudioTimestampInternal aidl; |
| 2434 | aidl.position = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.mPosition)); |
| 2435 | aidl.sec = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy.mTime.tv_sec)); |
| 2436 | aidl.nsec = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.mTime.tv_nsec)); |
| 2437 | return aidl; |
| 2438 | } |
| 2439 | |
Ytai Ben-Tsvi | ce18294 | 2020-11-04 14:48:01 -0800 | [diff] [blame] | 2440 | ConversionResult<audio_uuid_t> |
| 2441 | aidl2legacy_AudioUuid_audio_uuid_t(const media::AudioUuid& aidl) { |
| 2442 | audio_uuid_t legacy; |
| 2443 | legacy.timeLow = VALUE_OR_RETURN(convertReinterpret<uint32_t>(aidl.timeLow)); |
| 2444 | legacy.timeMid = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.timeMid)); |
| 2445 | legacy.timeHiAndVersion = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.timeHiAndVersion)); |
| 2446 | legacy.clockSeq = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.clockSeq)); |
| 2447 | if (aidl.node.size() != std::size(legacy.node)) { |
| 2448 | return unexpected(BAD_VALUE); |
| 2449 | } |
| 2450 | std::copy(aidl.node.begin(), aidl.node.end(), legacy.node); |
| 2451 | return legacy; |
| 2452 | } |
| 2453 | |
| 2454 | ConversionResult<media::AudioUuid> |
| 2455 | legacy2aidl_audio_uuid_t_AudioUuid(const audio_uuid_t& legacy) { |
| 2456 | media::AudioUuid aidl; |
| 2457 | aidl.timeLow = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.timeLow)); |
| 2458 | aidl.timeMid = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.timeMid)); |
| 2459 | aidl.timeHiAndVersion = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.timeHiAndVersion)); |
| 2460 | aidl.clockSeq = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.clockSeq)); |
| 2461 | std::copy(legacy.node, legacy.node + std::size(legacy.node), std::back_inserter(aidl.node)); |
| 2462 | return aidl; |
| 2463 | } |
| 2464 | |
| 2465 | ConversionResult<effect_descriptor_t> |
| 2466 | aidl2legacy_EffectDescriptor_effect_descriptor_t(const media::EffectDescriptor& aidl) { |
| 2467 | effect_descriptor_t legacy; |
| 2468 | legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioUuid_audio_uuid_t(aidl.type)); |
| 2469 | legacy.uuid = VALUE_OR_RETURN(aidl2legacy_AudioUuid_audio_uuid_t(aidl.uuid)); |
| 2470 | legacy.apiVersion = VALUE_OR_RETURN(convertReinterpret<uint32_t>(aidl.apiVersion)); |
| 2471 | legacy.flags = VALUE_OR_RETURN(convertReinterpret<uint32_t>(aidl.flags)); |
| 2472 | legacy.cpuLoad = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.cpuLoad)); |
| 2473 | legacy.memoryUsage = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.memoryUsage)); |
| 2474 | RETURN_IF_ERROR(aidl2legacy_string(aidl.name, legacy.name, sizeof(legacy.name))); |
| 2475 | RETURN_IF_ERROR( |
| 2476 | aidl2legacy_string(aidl.implementor, legacy.implementor, sizeof(legacy.implementor))); |
| 2477 | return legacy; |
| 2478 | } |
| 2479 | |
| 2480 | ConversionResult<media::EffectDescriptor> |
| 2481 | legacy2aidl_effect_descriptor_t_EffectDescriptor(const effect_descriptor_t& legacy) { |
| 2482 | media::EffectDescriptor aidl; |
| 2483 | aidl.type = VALUE_OR_RETURN(legacy2aidl_audio_uuid_t_AudioUuid(legacy.type)); |
| 2484 | aidl.uuid = VALUE_OR_RETURN(legacy2aidl_audio_uuid_t_AudioUuid(legacy.uuid)); |
| 2485 | aidl.apiVersion = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.apiVersion)); |
| 2486 | aidl.flags = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.flags)); |
| 2487 | aidl.cpuLoad = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.cpuLoad)); |
| 2488 | aidl.memoryUsage = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.memoryUsage)); |
| 2489 | aidl.name = VALUE_OR_RETURN(legacy2aidl_string(legacy.name, sizeof(legacy.name))); |
| 2490 | aidl.implementor = VALUE_OR_RETURN( |
| 2491 | legacy2aidl_string(legacy.implementor, sizeof(legacy.implementor))); |
| 2492 | return aidl; |
| 2493 | } |
| 2494 | |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2495 | ConversionResult<audio_encapsulation_metadata_type_t> |
| 2496 | aidl2legacy_AudioEncapsulationMetadataType_audio_encapsulation_metadata_type_t( |
| 2497 | media::AudioEncapsulationMetadataType aidl) { |
| 2498 | switch (aidl) { |
| 2499 | case media::AudioEncapsulationMetadataType::NONE: |
| 2500 | return AUDIO_ENCAPSULATION_METADATA_TYPE_NONE; |
| 2501 | case media::AudioEncapsulationMetadataType::FRAMEWORK_TUNER: |
| 2502 | return AUDIO_ENCAPSULATION_METADATA_TYPE_FRAMEWORK_TUNER; |
| 2503 | case media::AudioEncapsulationMetadataType::DVB_AD_DESCRIPTOR: |
| 2504 | return AUDIO_ENCAPSULATION_METADATA_TYPE_DVB_AD_DESCRIPTOR; |
| 2505 | } |
| 2506 | return unexpected(BAD_VALUE); |
| 2507 | } |
| 2508 | |
| 2509 | ConversionResult<media::AudioEncapsulationMetadataType> |
| 2510 | legacy2aidl_audio_encapsulation_metadata_type_t_AudioEncapsulationMetadataType( |
| 2511 | audio_encapsulation_metadata_type_t legacy) { |
| 2512 | switch (legacy) { |
| 2513 | case AUDIO_ENCAPSULATION_METADATA_TYPE_NONE: |
| 2514 | return media::AudioEncapsulationMetadataType::NONE; |
| 2515 | case AUDIO_ENCAPSULATION_METADATA_TYPE_FRAMEWORK_TUNER: |
| 2516 | return media::AudioEncapsulationMetadataType::FRAMEWORK_TUNER; |
| 2517 | case AUDIO_ENCAPSULATION_METADATA_TYPE_DVB_AD_DESCRIPTOR: |
| 2518 | return media::AudioEncapsulationMetadataType::DVB_AD_DESCRIPTOR; |
| 2519 | } |
| 2520 | return unexpected(BAD_VALUE); |
| 2521 | } |
| 2522 | |
| 2523 | ConversionResult<uint32_t> |
| 2524 | aidl2legacy_AudioEncapsulationMode_mask(int32_t aidl) { |
| 2525 | return convertBitmask<uint32_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2526 | int32_t, |
| 2527 | audio_encapsulation_mode_t, |
| 2528 | media::AudioEncapsulationMode>( |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2529 | aidl, aidl2legacy_AudioEncapsulationMode_audio_encapsulation_mode_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2530 | indexToEnum_index<media::AudioEncapsulationMode>, |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2531 | enumToMask_index<uint32_t, audio_encapsulation_mode_t>); |
| 2532 | } |
| 2533 | |
| 2534 | ConversionResult<int32_t> |
| 2535 | legacy2aidl_AudioEncapsulationMode_mask(uint32_t legacy) { |
| 2536 | return convertBitmask<int32_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2537 | uint32_t, |
| 2538 | media::AudioEncapsulationMode, |
| 2539 | audio_encapsulation_mode_t>( |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2540 | legacy, legacy2aidl_audio_encapsulation_mode_t_AudioEncapsulationMode, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2541 | indexToEnum_index<audio_encapsulation_mode_t>, |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2542 | enumToMask_index<int32_t, media::AudioEncapsulationMode>); |
| 2543 | } |
| 2544 | |
| 2545 | ConversionResult<uint32_t> |
| 2546 | aidl2legacy_AudioEncapsulationMetadataType_mask(int32_t aidl) { |
| 2547 | return convertBitmask<uint32_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2548 | int32_t, |
| 2549 | audio_encapsulation_metadata_type_t, |
| 2550 | media::AudioEncapsulationMetadataType>( |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2551 | aidl, aidl2legacy_AudioEncapsulationMetadataType_audio_encapsulation_metadata_type_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2552 | indexToEnum_index<media::AudioEncapsulationMetadataType>, |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2553 | enumToMask_index<uint32_t, audio_encapsulation_metadata_type_t>); |
| 2554 | } |
| 2555 | |
| 2556 | ConversionResult<int32_t> |
| 2557 | legacy2aidl_AudioEncapsulationMetadataType_mask(uint32_t legacy) { |
| 2558 | return convertBitmask<int32_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2559 | uint32_t, |
| 2560 | media::AudioEncapsulationMetadataType, |
| 2561 | audio_encapsulation_metadata_type_t>( |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2562 | legacy, legacy2aidl_audio_encapsulation_metadata_type_t_AudioEncapsulationMetadataType, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2563 | indexToEnum_index<audio_encapsulation_metadata_type_t>, |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2564 | enumToMask_index<int32_t, media::AudioEncapsulationMetadataType>); |
| 2565 | } |
| 2566 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2567 | ConversionResult<audio_mix_latency_class_t> |
| 2568 | aidl2legacy_AudioMixLatencyClass_audio_mix_latency_class_t( |
| 2569 | media::AudioMixLatencyClass aidl) { |
| 2570 | switch (aidl) { |
| 2571 | case media::AudioMixLatencyClass::LOW: |
| 2572 | return AUDIO_LATENCY_LOW; |
| 2573 | case media::AudioMixLatencyClass::NORMAL: |
| 2574 | return AUDIO_LATENCY_NORMAL; |
| 2575 | } |
| 2576 | return unexpected(BAD_VALUE); |
| 2577 | } |
| 2578 | |
| 2579 | ConversionResult<media::AudioMixLatencyClass> |
| 2580 | legacy2aidl_audio_mix_latency_class_t_AudioMixLatencyClass( |
| 2581 | audio_mix_latency_class_t legacy) { |
| 2582 | switch (legacy) { |
| 2583 | case AUDIO_LATENCY_LOW: |
| 2584 | return media::AudioMixLatencyClass::LOW; |
| 2585 | case AUDIO_LATENCY_NORMAL: |
| 2586 | return media::AudioMixLatencyClass::NORMAL; |
| 2587 | } |
| 2588 | return unexpected(BAD_VALUE); |
| 2589 | } |
| 2590 | |
| 2591 | ConversionResult<audio_port_device_ext> |
| 2592 | aidl2legacy_AudioPortDeviceExt_audio_port_device_ext(const media::AudioPortDeviceExt& aidl) { |
| 2593 | audio_port_device_ext legacy; |
| 2594 | legacy.hw_module = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_module_handle_t(aidl.hwModule)); |
| 2595 | legacy.type = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_devices_t(aidl.device.type)); |
| 2596 | RETURN_IF_ERROR( |
| 2597 | aidl2legacy_string(aidl.device.address, legacy.address, sizeof(legacy.address))); |
| 2598 | legacy.encapsulation_modes = VALUE_OR_RETURN( |
| 2599 | aidl2legacy_AudioEncapsulationMode_mask(aidl.encapsulationModes)); |
| 2600 | legacy.encapsulation_metadata_types = VALUE_OR_RETURN( |
| 2601 | aidl2legacy_AudioEncapsulationMetadataType_mask(aidl.encapsulationMetadataTypes)); |
| 2602 | return legacy; |
| 2603 | } |
| 2604 | |
| 2605 | ConversionResult<media::AudioPortDeviceExt> |
| 2606 | legacy2aidl_audio_port_device_ext_AudioPortDeviceExt(const audio_port_device_ext& legacy) { |
| 2607 | media::AudioPortDeviceExt aidl; |
| 2608 | aidl.hwModule = VALUE_OR_RETURN(legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
| 2609 | aidl.device.type = VALUE_OR_RETURN(legacy2aidl_audio_devices_t_int32_t(legacy.type)); |
| 2610 | aidl.device.address = VALUE_OR_RETURN( |
| 2611 | legacy2aidl_string(legacy.address, sizeof(legacy.address))); |
| 2612 | aidl.encapsulationModes = VALUE_OR_RETURN( |
| 2613 | legacy2aidl_AudioEncapsulationMode_mask(legacy.encapsulation_modes)); |
| 2614 | aidl.encapsulationMetadataTypes = VALUE_OR_RETURN( |
| 2615 | legacy2aidl_AudioEncapsulationMetadataType_mask(legacy.encapsulation_metadata_types)); |
| 2616 | return aidl; |
| 2617 | } |
| 2618 | |
| 2619 | ConversionResult<audio_port_mix_ext> |
| 2620 | aidl2legacy_AudioPortMixExt_audio_port_mix_ext(const media::AudioPortMixExt& aidl) { |
| 2621 | audio_port_mix_ext legacy; |
| 2622 | legacy.hw_module = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_module_handle_t(aidl.hwModule)); |
| 2623 | legacy.handle = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.handle)); |
| 2624 | legacy.latency_class = VALUE_OR_RETURN( |
| 2625 | aidl2legacy_AudioMixLatencyClass_audio_mix_latency_class_t(aidl.latencyClass)); |
| 2626 | return legacy; |
| 2627 | } |
| 2628 | |
| 2629 | ConversionResult<media::AudioPortMixExt> |
| 2630 | legacy2aidl_audio_port_mix_ext_AudioPortMixExt(const audio_port_mix_ext& legacy) { |
| 2631 | media::AudioPortMixExt aidl; |
| 2632 | aidl.hwModule = VALUE_OR_RETURN(legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
| 2633 | aidl.handle = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(legacy.handle)); |
| 2634 | aidl.latencyClass = VALUE_OR_RETURN( |
| 2635 | legacy2aidl_audio_mix_latency_class_t_AudioMixLatencyClass(legacy.latency_class)); |
| 2636 | return aidl; |
| 2637 | } |
| 2638 | |
| 2639 | ConversionResult<audio_port_session_ext> |
| 2640 | aidl2legacy_AudioPortSessionExt_audio_port_session_ext(const media::AudioPortSessionExt& aidl) { |
| 2641 | audio_port_session_ext legacy; |
| 2642 | legacy.session = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.session)); |
| 2643 | return legacy; |
| 2644 | } |
| 2645 | |
| 2646 | ConversionResult<media::AudioPortSessionExt> |
| 2647 | legacy2aidl_audio_port_session_ext_AudioPortSessionExt(const audio_port_session_ext& legacy) { |
| 2648 | media::AudioPortSessionExt aidl; |
| 2649 | aidl.session = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(legacy.session)); |
| 2650 | return aidl; |
| 2651 | } |
| 2652 | |
| 2653 | // This type is unnamed in the original definition, thus we name it here. |
| 2654 | using audio_port_v7_ext = decltype(audio_port_v7::ext); |
| 2655 | |
| 2656 | ConversionResult<audio_port_v7_ext> aidl2legacy_AudioPortExt( |
| 2657 | const media::AudioPortExt& aidl, media::AudioPortType type) { |
| 2658 | audio_port_v7_ext legacy; |
| 2659 | switch (type) { |
| 2660 | case media::AudioPortType::NONE: |
| 2661 | // Just verify that the union is empty. |
| 2662 | VALUE_OR_RETURN(UNION_GET(aidl, unspecified)); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2663 | return legacy; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2664 | case media::AudioPortType::DEVICE: |
| 2665 | legacy.device = VALUE_OR_RETURN( |
| 2666 | aidl2legacy_AudioPortDeviceExt_audio_port_device_ext( |
| 2667 | VALUE_OR_RETURN(UNION_GET(aidl, device)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2668 | return legacy; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2669 | case media::AudioPortType::MIX: |
| 2670 | legacy.mix = VALUE_OR_RETURN( |
| 2671 | aidl2legacy_AudioPortMixExt_audio_port_mix_ext( |
| 2672 | VALUE_OR_RETURN(UNION_GET(aidl, mix)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2673 | return legacy; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2674 | case media::AudioPortType::SESSION: |
| 2675 | legacy.session = VALUE_OR_RETURN(aidl2legacy_AudioPortSessionExt_audio_port_session_ext( |
| 2676 | VALUE_OR_RETURN(UNION_GET(aidl, session)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2677 | return legacy; |
| 2678 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2679 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2680 | LOG_ALWAYS_FATAL("Shouldn't get here"); // with -Werror,-Wswitch may compile-time fail |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | ConversionResult<media::AudioPortExt> legacy2aidl_AudioPortExt( |
| 2684 | const audio_port_v7_ext& legacy, audio_port_type_t type) { |
| 2685 | media::AudioPortExt aidl; |
| 2686 | switch (type) { |
| 2687 | case AUDIO_PORT_TYPE_NONE: |
| 2688 | UNION_SET(aidl, unspecified, false); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2689 | return aidl; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2690 | case AUDIO_PORT_TYPE_DEVICE: |
| 2691 | UNION_SET(aidl, device, |
| 2692 | VALUE_OR_RETURN( |
| 2693 | legacy2aidl_audio_port_device_ext_AudioPortDeviceExt(legacy.device))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2694 | return aidl; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2695 | case AUDIO_PORT_TYPE_MIX: |
| 2696 | UNION_SET(aidl, mix, |
| 2697 | VALUE_OR_RETURN(legacy2aidl_audio_port_mix_ext_AudioPortMixExt(legacy.mix))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2698 | return aidl; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2699 | case AUDIO_PORT_TYPE_SESSION: |
| 2700 | UNION_SET(aidl, session, |
| 2701 | VALUE_OR_RETURN(legacy2aidl_audio_port_session_ext_AudioPortSessionExt( |
| 2702 | legacy.session))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2703 | return aidl; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2704 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2705 | LOG_ALWAYS_FATAL("Shouldn't get here"); // with -Werror,-Wswitch may compile-time fail |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | ConversionResult<audio_profile> |
| 2709 | aidl2legacy_AudioProfile_audio_profile(const media::AudioProfile& aidl) { |
| 2710 | audio_profile legacy; |
| 2711 | legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
| 2712 | |
| 2713 | if (aidl.samplingRates.size() > std::size(legacy.sample_rates)) { |
| 2714 | return unexpected(BAD_VALUE); |
| 2715 | } |
| 2716 | RETURN_IF_ERROR( |
| 2717 | convertRange(aidl.samplingRates.begin(), aidl.samplingRates.end(), legacy.sample_rates, |
| 2718 | convertIntegral<int32_t, unsigned int>)); |
| 2719 | legacy.num_sample_rates = aidl.samplingRates.size(); |
| 2720 | |
| 2721 | if (aidl.channelMasks.size() > std::size(legacy.channel_masks)) { |
| 2722 | return unexpected(BAD_VALUE); |
| 2723 | } |
| 2724 | RETURN_IF_ERROR( |
| 2725 | convertRange(aidl.channelMasks.begin(), aidl.channelMasks.end(), legacy.channel_masks, |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2726 | aidl2legacy_AudioChannelMask_audio_channel_mask_t)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2727 | legacy.num_channel_masks = aidl.channelMasks.size(); |
jiabin | 82e5693 | 2021-03-05 06:35:19 +0000 | [diff] [blame] | 2728 | |
| 2729 | legacy.encapsulation_type = VALUE_OR_RETURN( |
| 2730 | aidl2legacy_AudioEncapsulationType_audio_encapsulation_type_t(aidl.encapsulationType)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2731 | return legacy; |
| 2732 | } |
| 2733 | |
| 2734 | ConversionResult<media::AudioProfile> |
| 2735 | legacy2aidl_audio_profile_AudioProfile(const audio_profile& legacy) { |
| 2736 | media::AudioProfile aidl; |
| 2737 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
| 2738 | |
| 2739 | if (legacy.num_sample_rates > std::size(legacy.sample_rates)) { |
| 2740 | return unexpected(BAD_VALUE); |
| 2741 | } |
| 2742 | RETURN_IF_ERROR( |
| 2743 | convertRange(legacy.sample_rates, legacy.sample_rates + legacy.num_sample_rates, |
| 2744 | std::back_inserter(aidl.samplingRates), |
| 2745 | convertIntegral<unsigned int, int32_t>)); |
| 2746 | |
| 2747 | if (legacy.num_channel_masks > std::size(legacy.channel_masks)) { |
| 2748 | return unexpected(BAD_VALUE); |
| 2749 | } |
| 2750 | RETURN_IF_ERROR( |
| 2751 | convertRange(legacy.channel_masks, legacy.channel_masks + legacy.num_channel_masks, |
| 2752 | std::back_inserter(aidl.channelMasks), |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2753 | legacy2aidl_audio_channel_mask_t_AudioChannelMask)); |
jiabin | 82e5693 | 2021-03-05 06:35:19 +0000 | [diff] [blame] | 2754 | |
| 2755 | aidl.encapsulationType = VALUE_OR_RETURN( |
| 2756 | legacy2aidl_audio_encapsulation_type_t_AudioEncapsulationType( |
| 2757 | legacy.encapsulation_type)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2758 | return aidl; |
| 2759 | } |
| 2760 | |
| 2761 | ConversionResult<audio_gain> |
| 2762 | aidl2legacy_AudioGain_audio_gain(const media::AudioGain& aidl) { |
| 2763 | audio_gain legacy; |
| 2764 | legacy.mode = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_gain_mode_t_mask(aidl.mode)); |
| 2765 | legacy.channel_mask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2766 | aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2767 | legacy.min_value = VALUE_OR_RETURN(convertIntegral<int>(aidl.minValue)); |
| 2768 | legacy.max_value = VALUE_OR_RETURN(convertIntegral<int>(aidl.maxValue)); |
| 2769 | legacy.default_value = VALUE_OR_RETURN(convertIntegral<int>(aidl.defaultValue)); |
| 2770 | legacy.step_value = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.stepValue)); |
| 2771 | legacy.min_ramp_ms = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.minRampMs)); |
| 2772 | legacy.max_ramp_ms = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.maxRampMs)); |
| 2773 | return legacy; |
| 2774 | } |
| 2775 | |
| 2776 | ConversionResult<media::AudioGain> |
| 2777 | legacy2aidl_audio_gain_AudioGain(const audio_gain& legacy) { |
| 2778 | media::AudioGain aidl; |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 2779 | aidl.mode = VALUE_OR_RETURN(legacy2aidl_audio_gain_mode_t_int32_t_mask(legacy.mode)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2780 | aidl.channelMask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2781 | legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy.channel_mask)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2782 | aidl.minValue = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.min_value)); |
| 2783 | aidl.maxValue = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.max_value)); |
| 2784 | aidl.defaultValue = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.default_value)); |
| 2785 | aidl.stepValue = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.step_value)); |
| 2786 | aidl.minRampMs = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.min_ramp_ms)); |
| 2787 | aidl.maxRampMs = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.max_ramp_ms)); |
| 2788 | return aidl; |
| 2789 | } |
| 2790 | |
| 2791 | ConversionResult<audio_port_v7> |
| 2792 | aidl2legacy_AudioPort_audio_port_v7(const media::AudioPort& aidl) { |
| 2793 | audio_port_v7 legacy; |
| 2794 | legacy.id = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.id)); |
| 2795 | legacy.role = VALUE_OR_RETURN(aidl2legacy_AudioPortRole_audio_port_role_t(aidl.role)); |
| 2796 | legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioPortType_audio_port_type_t(aidl.type)); |
| 2797 | RETURN_IF_ERROR(aidl2legacy_string(aidl.name, legacy.name, sizeof(legacy.name))); |
| 2798 | |
| 2799 | if (aidl.profiles.size() > std::size(legacy.audio_profiles)) { |
| 2800 | return unexpected(BAD_VALUE); |
| 2801 | } |
| 2802 | RETURN_IF_ERROR(convertRange(aidl.profiles.begin(), aidl.profiles.end(), legacy.audio_profiles, |
| 2803 | aidl2legacy_AudioProfile_audio_profile)); |
| 2804 | legacy.num_audio_profiles = aidl.profiles.size(); |
| 2805 | |
jiabin | 82e5693 | 2021-03-05 06:35:19 +0000 | [diff] [blame] | 2806 | if (aidl.extraAudioDescriptors.size() > std::size(legacy.extra_audio_descriptors)) { |
| 2807 | return unexpected(BAD_VALUE); |
| 2808 | } |
| 2809 | RETURN_IF_ERROR( |
| 2810 | convertRange(aidl.extraAudioDescriptors.begin(), aidl.extraAudioDescriptors.end(), |
| 2811 | legacy.extra_audio_descriptors, |
| 2812 | aidl2legacy_ExtraAudioDescriptor_audio_extra_audio_descriptor)); |
| 2813 | legacy.num_extra_audio_descriptors = aidl.extraAudioDescriptors.size(); |
| 2814 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2815 | if (aidl.gains.size() > std::size(legacy.gains)) { |
| 2816 | return unexpected(BAD_VALUE); |
| 2817 | } |
| 2818 | RETURN_IF_ERROR(convertRange(aidl.gains.begin(), aidl.gains.end(), legacy.gains, |
| 2819 | aidl2legacy_AudioGain_audio_gain)); |
| 2820 | legacy.num_gains = aidl.gains.size(); |
| 2821 | |
| 2822 | legacy.active_config = VALUE_OR_RETURN( |
| 2823 | aidl2legacy_AudioPortConfig_audio_port_config(aidl.activeConfig)); |
| 2824 | legacy.ext = VALUE_OR_RETURN(aidl2legacy_AudioPortExt(aidl.ext, aidl.type)); |
| 2825 | return legacy; |
| 2826 | } |
| 2827 | |
| 2828 | ConversionResult<media::AudioPort> |
| 2829 | legacy2aidl_audio_port_v7_AudioPort(const audio_port_v7& legacy) { |
| 2830 | media::AudioPort aidl; |
| 2831 | aidl.id = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy.id)); |
| 2832 | aidl.role = VALUE_OR_RETURN(legacy2aidl_audio_port_role_t_AudioPortRole(legacy.role)); |
| 2833 | aidl.type = VALUE_OR_RETURN(legacy2aidl_audio_port_type_t_AudioPortType(legacy.type)); |
| 2834 | aidl.name = VALUE_OR_RETURN(legacy2aidl_string(legacy.name, sizeof(legacy.name))); |
| 2835 | |
| 2836 | if (legacy.num_audio_profiles > std::size(legacy.audio_profiles)) { |
| 2837 | return unexpected(BAD_VALUE); |
| 2838 | } |
| 2839 | RETURN_IF_ERROR( |
| 2840 | convertRange(legacy.audio_profiles, legacy.audio_profiles + legacy.num_audio_profiles, |
| 2841 | std::back_inserter(aidl.profiles), |
| 2842 | legacy2aidl_audio_profile_AudioProfile)); |
| 2843 | |
jiabin | 82e5693 | 2021-03-05 06:35:19 +0000 | [diff] [blame] | 2844 | if (legacy.num_extra_audio_descriptors > std::size(legacy.extra_audio_descriptors)) { |
| 2845 | return unexpected(BAD_VALUE); |
| 2846 | } |
| 2847 | RETURN_IF_ERROR( |
| 2848 | convertRange(legacy.extra_audio_descriptors, |
| 2849 | legacy.extra_audio_descriptors + legacy.num_extra_audio_descriptors, |
| 2850 | std::back_inserter(aidl.extraAudioDescriptors), |
| 2851 | legacy2aidl_audio_extra_audio_descriptor_ExtraAudioDescriptor)); |
| 2852 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2853 | if (legacy.num_gains > std::size(legacy.gains)) { |
| 2854 | return unexpected(BAD_VALUE); |
| 2855 | } |
| 2856 | RETURN_IF_ERROR( |
| 2857 | convertRange(legacy.gains, legacy.gains + legacy.num_gains, |
| 2858 | std::back_inserter(aidl.gains), |
| 2859 | legacy2aidl_audio_gain_AudioGain)); |
| 2860 | |
| 2861 | aidl.activeConfig = VALUE_OR_RETURN( |
| 2862 | legacy2aidl_audio_port_config_AudioPortConfig(legacy.active_config)); |
| 2863 | aidl.ext = VALUE_OR_RETURN(legacy2aidl_AudioPortExt(legacy.ext, legacy.type)); |
| 2864 | return aidl; |
| 2865 | } |
| 2866 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 2867 | ConversionResult<audio_mode_t> |
| 2868 | aidl2legacy_AudioMode_audio_mode_t(media::AudioMode aidl) { |
| 2869 | switch (aidl) { |
| 2870 | case media::AudioMode::INVALID: |
| 2871 | return AUDIO_MODE_INVALID; |
| 2872 | case media::AudioMode::CURRENT: |
| 2873 | return AUDIO_MODE_CURRENT; |
| 2874 | case media::AudioMode::NORMAL: |
| 2875 | return AUDIO_MODE_NORMAL; |
| 2876 | case media::AudioMode::RINGTONE: |
| 2877 | return AUDIO_MODE_RINGTONE; |
| 2878 | case media::AudioMode::IN_CALL: |
| 2879 | return AUDIO_MODE_IN_CALL; |
| 2880 | case media::AudioMode::IN_COMMUNICATION: |
| 2881 | return AUDIO_MODE_IN_COMMUNICATION; |
| 2882 | case media::AudioMode::CALL_SCREEN: |
| 2883 | return AUDIO_MODE_CALL_SCREEN; |
| 2884 | } |
| 2885 | return unexpected(BAD_VALUE); |
| 2886 | } |
| 2887 | |
| 2888 | ConversionResult<media::AudioMode> |
| 2889 | legacy2aidl_audio_mode_t_AudioMode(audio_mode_t legacy) { |
| 2890 | switch (legacy) { |
| 2891 | case AUDIO_MODE_INVALID: |
| 2892 | return media::AudioMode::INVALID; |
| 2893 | case AUDIO_MODE_CURRENT: |
| 2894 | return media::AudioMode::CURRENT; |
| 2895 | case AUDIO_MODE_NORMAL: |
| 2896 | return media::AudioMode::NORMAL; |
| 2897 | case AUDIO_MODE_RINGTONE: |
| 2898 | return media::AudioMode::RINGTONE; |
| 2899 | case AUDIO_MODE_IN_CALL: |
| 2900 | return media::AudioMode::IN_CALL; |
| 2901 | case AUDIO_MODE_IN_COMMUNICATION: |
| 2902 | return media::AudioMode::IN_COMMUNICATION; |
| 2903 | case AUDIO_MODE_CALL_SCREEN: |
| 2904 | return media::AudioMode::CALL_SCREEN; |
| 2905 | case AUDIO_MODE_CNT: |
| 2906 | break; |
| 2907 | } |
| 2908 | return unexpected(BAD_VALUE); |
| 2909 | } |
| 2910 | |
| 2911 | ConversionResult<audio_unique_id_use_t> |
| 2912 | aidl2legacy_AudioUniqueIdUse_audio_unique_id_use_t(media::AudioUniqueIdUse aidl) { |
| 2913 | switch (aidl) { |
| 2914 | case media::AudioUniqueIdUse::UNSPECIFIED: |
| 2915 | return AUDIO_UNIQUE_ID_USE_UNSPECIFIED; |
| 2916 | case media::AudioUniqueIdUse::SESSION: |
| 2917 | return AUDIO_UNIQUE_ID_USE_SESSION; |
| 2918 | case media::AudioUniqueIdUse::MODULE: |
| 2919 | return AUDIO_UNIQUE_ID_USE_MODULE; |
| 2920 | case media::AudioUniqueIdUse::EFFECT: |
| 2921 | return AUDIO_UNIQUE_ID_USE_EFFECT; |
| 2922 | case media::AudioUniqueIdUse::PATCH: |
| 2923 | return AUDIO_UNIQUE_ID_USE_PATCH; |
| 2924 | case media::AudioUniqueIdUse::OUTPUT: |
| 2925 | return AUDIO_UNIQUE_ID_USE_OUTPUT; |
| 2926 | case media::AudioUniqueIdUse::INPUT: |
| 2927 | return AUDIO_UNIQUE_ID_USE_INPUT; |
| 2928 | case media::AudioUniqueIdUse::CLIENT: |
| 2929 | return AUDIO_UNIQUE_ID_USE_CLIENT; |
| 2930 | } |
| 2931 | return unexpected(BAD_VALUE); |
| 2932 | } |
| 2933 | |
| 2934 | ConversionResult<media::AudioUniqueIdUse> |
| 2935 | legacy2aidl_audio_unique_id_use_t_AudioUniqueIdUse(audio_unique_id_use_t legacy) { |
| 2936 | switch (legacy) { |
| 2937 | case AUDIO_UNIQUE_ID_USE_UNSPECIFIED: |
| 2938 | return media::AudioUniqueIdUse::UNSPECIFIED; |
| 2939 | case AUDIO_UNIQUE_ID_USE_SESSION: |
| 2940 | return media::AudioUniqueIdUse::SESSION; |
| 2941 | case AUDIO_UNIQUE_ID_USE_MODULE: |
| 2942 | return media::AudioUniqueIdUse::MODULE; |
| 2943 | case AUDIO_UNIQUE_ID_USE_EFFECT: |
| 2944 | return media::AudioUniqueIdUse::EFFECT; |
| 2945 | case AUDIO_UNIQUE_ID_USE_PATCH: |
| 2946 | return media::AudioUniqueIdUse::PATCH; |
| 2947 | case AUDIO_UNIQUE_ID_USE_OUTPUT: |
| 2948 | return media::AudioUniqueIdUse::OUTPUT; |
| 2949 | case AUDIO_UNIQUE_ID_USE_INPUT: |
| 2950 | return media::AudioUniqueIdUse::INPUT; |
| 2951 | case AUDIO_UNIQUE_ID_USE_CLIENT: |
| 2952 | return media::AudioUniqueIdUse::CLIENT; |
| 2953 | case AUDIO_UNIQUE_ID_USE_MAX: |
| 2954 | break; |
| 2955 | } |
| 2956 | return unexpected(BAD_VALUE); |
| 2957 | } |
| 2958 | |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2959 | ConversionResult<volume_group_t> |
| 2960 | aidl2legacy_int32_t_volume_group_t(int32_t aidl) { |
| 2961 | return convertReinterpret<volume_group_t>(aidl); |
| 2962 | } |
| 2963 | |
| 2964 | ConversionResult<int32_t> |
| 2965 | legacy2aidl_volume_group_t_int32_t(volume_group_t legacy) { |
| 2966 | return convertReinterpret<int32_t>(legacy); |
| 2967 | } |
| 2968 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2969 | ConversionResult<product_strategy_t> |
| 2970 | aidl2legacy_int32_t_product_strategy_t(int32_t aidl) { |
| 2971 | return convertReinterpret<product_strategy_t>(aidl); |
| 2972 | } |
| 2973 | |
| 2974 | ConversionResult<int32_t> |
| 2975 | legacy2aidl_product_strategy_t_int32_t(product_strategy_t legacy) { |
| 2976 | return convertReinterpret<int32_t>(legacy); |
| 2977 | } |
| 2978 | |
Kuowei Li | d4adbdb | 2020-08-13 14:44:25 +0800 | [diff] [blame] | 2979 | ConversionResult<audio_dual_mono_mode_t> |
| 2980 | aidl2legacy_AudioDualMonoMode_audio_dual_mono_mode_t(media::AudioDualMonoMode aidl) { |
| 2981 | switch (aidl) { |
| 2982 | case media::AudioDualMonoMode::OFF: |
| 2983 | return AUDIO_DUAL_MONO_MODE_OFF; |
| 2984 | case media::AudioDualMonoMode::LR: |
| 2985 | return AUDIO_DUAL_MONO_MODE_LR; |
| 2986 | case media::AudioDualMonoMode::LL: |
| 2987 | return AUDIO_DUAL_MONO_MODE_LL; |
| 2988 | case media::AudioDualMonoMode::RR: |
| 2989 | return AUDIO_DUAL_MONO_MODE_RR; |
| 2990 | } |
| 2991 | return unexpected(BAD_VALUE); |
| 2992 | } |
| 2993 | |
| 2994 | ConversionResult<media::AudioDualMonoMode> |
| 2995 | legacy2aidl_audio_dual_mono_mode_t_AudioDualMonoMode(audio_dual_mono_mode_t legacy) { |
| 2996 | switch (legacy) { |
| 2997 | case AUDIO_DUAL_MONO_MODE_OFF: |
| 2998 | return media::AudioDualMonoMode::OFF; |
| 2999 | case AUDIO_DUAL_MONO_MODE_LR: |
| 3000 | return media::AudioDualMonoMode::LR; |
| 3001 | case AUDIO_DUAL_MONO_MODE_LL: |
| 3002 | return media::AudioDualMonoMode::LL; |
| 3003 | case AUDIO_DUAL_MONO_MODE_RR: |
| 3004 | return media::AudioDualMonoMode::RR; |
| 3005 | } |
| 3006 | return unexpected(BAD_VALUE); |
| 3007 | } |
| 3008 | |
| 3009 | ConversionResult<audio_timestretch_fallback_mode_t> |
| 3010 | aidl2legacy_int32_t_audio_timestretch_fallback_mode_t(int32_t aidl) { |
| 3011 | return convertReinterpret<audio_timestretch_fallback_mode_t>(aidl); |
| 3012 | } |
| 3013 | |
| 3014 | ConversionResult<int32_t> |
| 3015 | legacy2aidl_audio_timestretch_fallback_mode_t_int32_t(audio_timestretch_fallback_mode_t legacy) { |
| 3016 | return convertReinterpret<int32_t>(legacy); |
| 3017 | } |
| 3018 | |
| 3019 | ConversionResult<audio_timestretch_stretch_mode_t> |
| 3020 | aidl2legacy_int32_t_audio_timestretch_stretch_mode_t(int32_t aidl) { |
| 3021 | return convertReinterpret<audio_timestretch_stretch_mode_t>(aidl); |
| 3022 | } |
| 3023 | |
| 3024 | ConversionResult<int32_t> |
| 3025 | legacy2aidl_audio_timestretch_stretch_mode_t_int32_t(audio_timestretch_stretch_mode_t legacy) { |
| 3026 | return convertReinterpret<int32_t>(legacy); |
| 3027 | } |
| 3028 | |
| 3029 | ConversionResult<audio_playback_rate_t> |
| 3030 | aidl2legacy_AudioPlaybackRate_audio_playback_rate_t(const media::AudioPlaybackRate& aidl) { |
| 3031 | audio_playback_rate_t legacy; |
| 3032 | legacy.mSpeed = aidl.speed; |
| 3033 | legacy.mPitch = aidl.pitch; |
| 3034 | legacy.mFallbackMode = VALUE_OR_RETURN( |
| 3035 | aidl2legacy_int32_t_audio_timestretch_fallback_mode_t(aidl.fallbackMode)); |
| 3036 | legacy.mStretchMode = VALUE_OR_RETURN( |
| 3037 | aidl2legacy_int32_t_audio_timestretch_stretch_mode_t(aidl.stretchMode)); |
| 3038 | return legacy; |
| 3039 | } |
| 3040 | |
| 3041 | ConversionResult<media::AudioPlaybackRate> |
| 3042 | legacy2aidl_audio_playback_rate_t_AudioPlaybackRate(const audio_playback_rate_t& legacy) { |
| 3043 | media::AudioPlaybackRate aidl; |
| 3044 | aidl.speed = legacy.mSpeed; |
| 3045 | aidl.pitch = legacy.mPitch; |
| 3046 | aidl.fallbackMode = VALUE_OR_RETURN( |
| 3047 | legacy2aidl_audio_timestretch_fallback_mode_t_int32_t(legacy.mFallbackMode)); |
| 3048 | aidl.stretchMode = VALUE_OR_RETURN( |
| 3049 | legacy2aidl_audio_timestretch_stretch_mode_t_int32_t(legacy.mStretchMode)); |
| 3050 | return aidl; |
| 3051 | } |
| 3052 | |
jiabin | 82e5693 | 2021-03-05 06:35:19 +0000 | [diff] [blame] | 3053 | ConversionResult<audio_standard_t> |
| 3054 | aidl2legacy_AudioStandard_audio_standard_t(media::AudioStandard aidl) { |
| 3055 | switch (aidl) { |
| 3056 | case media::AudioStandard::NONE: |
| 3057 | return AUDIO_STANDARD_NONE; |
| 3058 | case media::AudioStandard::EDID: |
| 3059 | return AUDIO_STANDARD_EDID; |
| 3060 | } |
| 3061 | return unexpected(BAD_VALUE); |
| 3062 | } |
| 3063 | |
| 3064 | ConversionResult<media::AudioStandard> |
| 3065 | legacy2aidl_audio_standard_t_AudioStandard(audio_standard_t legacy) { |
| 3066 | switch (legacy) { |
| 3067 | case AUDIO_STANDARD_NONE: |
| 3068 | return media::AudioStandard::NONE; |
| 3069 | case AUDIO_STANDARD_EDID: |
| 3070 | return media::AudioStandard::EDID; |
| 3071 | } |
| 3072 | return unexpected(BAD_VALUE); |
| 3073 | } |
| 3074 | |
| 3075 | ConversionResult<audio_extra_audio_descriptor> |
| 3076 | aidl2legacy_ExtraAudioDescriptor_audio_extra_audio_descriptor( |
| 3077 | const media::ExtraAudioDescriptor& aidl) { |
| 3078 | audio_extra_audio_descriptor legacy; |
| 3079 | legacy.standard = VALUE_OR_RETURN(aidl2legacy_AudioStandard_audio_standard_t(aidl.standard)); |
| 3080 | if (aidl.audioDescriptor.size() > EXTRA_AUDIO_DESCRIPTOR_SIZE) { |
| 3081 | return unexpected(BAD_VALUE); |
| 3082 | } |
| 3083 | legacy.descriptor_length = aidl.audioDescriptor.size(); |
| 3084 | std::copy(aidl.audioDescriptor.begin(), aidl.audioDescriptor.end(), |
| 3085 | std::begin(legacy.descriptor)); |
| 3086 | legacy.encapsulation_type = |
| 3087 | VALUE_OR_RETURN(aidl2legacy_AudioEncapsulationType_audio_encapsulation_type_t( |
| 3088 | aidl.encapsulationType)); |
| 3089 | return legacy; |
| 3090 | } |
| 3091 | |
| 3092 | ConversionResult<media::ExtraAudioDescriptor> |
| 3093 | legacy2aidl_audio_extra_audio_descriptor_ExtraAudioDescriptor( |
| 3094 | const audio_extra_audio_descriptor& legacy) { |
| 3095 | media::ExtraAudioDescriptor aidl; |
| 3096 | aidl.standard = VALUE_OR_RETURN(legacy2aidl_audio_standard_t_AudioStandard(legacy.standard)); |
| 3097 | if (legacy.descriptor_length > EXTRA_AUDIO_DESCRIPTOR_SIZE) { |
| 3098 | return unexpected(BAD_VALUE); |
| 3099 | } |
| 3100 | aidl.audioDescriptor.resize(legacy.descriptor_length); |
| 3101 | std::copy(legacy.descriptor, legacy.descriptor + legacy.descriptor_length, |
| 3102 | aidl.audioDescriptor.begin()); |
| 3103 | aidl.encapsulationType = |
| 3104 | VALUE_OR_RETURN(legacy2aidl_audio_encapsulation_type_t_AudioEncapsulationType( |
| 3105 | legacy.encapsulation_type)); |
| 3106 | return aidl; |
| 3107 | } |
| 3108 | |
| 3109 | ConversionResult<audio_encapsulation_type_t> |
| 3110 | aidl2legacy_AudioEncapsulationType_audio_encapsulation_type_t( |
| 3111 | const media::AudioEncapsulationType& aidl) { |
| 3112 | switch (aidl) { |
| 3113 | case media::AudioEncapsulationType::NONE: |
| 3114 | return AUDIO_ENCAPSULATION_TYPE_NONE; |
| 3115 | case media::AudioEncapsulationType::IEC61937: |
| 3116 | return AUDIO_ENCAPSULATION_TYPE_IEC61937; |
| 3117 | } |
| 3118 | return unexpected(BAD_VALUE); |
| 3119 | } |
| 3120 | |
| 3121 | ConversionResult<media::AudioEncapsulationType> |
| 3122 | legacy2aidl_audio_encapsulation_type_t_AudioEncapsulationType( |
| 3123 | const audio_encapsulation_type_t & legacy) { |
| 3124 | switch (legacy) { |
| 3125 | case AUDIO_ENCAPSULATION_TYPE_NONE: |
| 3126 | return media::AudioEncapsulationType::NONE; |
| 3127 | case AUDIO_ENCAPSULATION_TYPE_IEC61937: |
| 3128 | return media::AudioEncapsulationType::IEC61937; |
| 3129 | } |
| 3130 | return unexpected(BAD_VALUE); |
| 3131 | } |
| 3132 | |
jiabin | 10a03f1 | 2021-05-07 23:46:28 +0000 | [diff] [blame] | 3133 | ConversionResult<TrackSecondaryOutputInfoPair> |
| 3134 | aidl2legacy_TrackSecondaryOutputInfo_TrackSecondaryOutputInfoPair( |
| 3135 | const media::TrackSecondaryOutputInfo& aidl) { |
| 3136 | TrackSecondaryOutputInfoPair trackSecondaryOutputInfoPair; |
| 3137 | trackSecondaryOutputInfoPair.first = |
| 3138 | VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
| 3139 | trackSecondaryOutputInfoPair.second = |
| 3140 | VALUE_OR_RETURN(convertContainer<std::vector<audio_port_handle_t>>( |
| 3141 | aidl.secondaryOutputIds, aidl2legacy_int32_t_audio_io_handle_t)); |
| 3142 | return trackSecondaryOutputInfoPair; |
| 3143 | } |
| 3144 | |
| 3145 | ConversionResult<media::TrackSecondaryOutputInfo> |
| 3146 | legacy2aidl_TrackSecondaryOutputInfoPair_TrackSecondaryOutputInfo( |
| 3147 | const TrackSecondaryOutputInfoPair& legacy) { |
| 3148 | media::TrackSecondaryOutputInfo trackSecondaryOutputInfo; |
| 3149 | trackSecondaryOutputInfo.portId = |
| 3150 | VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy.first)); |
| 3151 | trackSecondaryOutputInfo.secondaryOutputIds = |
| 3152 | VALUE_OR_RETURN(convertContainer<std::vector<int32_t>>( |
| 3153 | legacy.second, legacy2aidl_audio_io_handle_t_int32_t)); |
| 3154 | return trackSecondaryOutputInfo; |
| 3155 | } |
| 3156 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 3157 | } // namespace android |