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