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