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