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