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