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 | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 282 | ConversionResult<audio_channel_mask_t> aidl2legacy_AudioChannelMask_audio_channel_mask_t( |
| 283 | media::AudioChannelMask aidl) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 284 | return convertReinterpret<audio_channel_mask_t>(aidl); |
| 285 | } |
| 286 | |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 287 | ConversionResult<media::AudioChannelMask> legacy2aidl_audio_channel_mask_t_AudioChannelMask( |
| 288 | audio_channel_mask_t legacy) { |
| 289 | return convertReinterpret<media::AudioChannelMask>(legacy); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | ConversionResult<audio_io_config_event> aidl2legacy_AudioIoConfigEvent_audio_io_config_event( |
| 293 | media::AudioIoConfigEvent aidl) { |
| 294 | switch (aidl) { |
| 295 | case media::AudioIoConfigEvent::OUTPUT_REGISTERED: |
| 296 | return AUDIO_OUTPUT_REGISTERED; |
| 297 | case media::AudioIoConfigEvent::OUTPUT_OPENED: |
| 298 | return AUDIO_OUTPUT_OPENED; |
| 299 | case media::AudioIoConfigEvent::OUTPUT_CLOSED: |
| 300 | return AUDIO_OUTPUT_CLOSED; |
| 301 | case media::AudioIoConfigEvent::OUTPUT_CONFIG_CHANGED: |
| 302 | return AUDIO_OUTPUT_CONFIG_CHANGED; |
| 303 | case media::AudioIoConfigEvent::INPUT_REGISTERED: |
| 304 | return AUDIO_INPUT_REGISTERED; |
| 305 | case media::AudioIoConfigEvent::INPUT_OPENED: |
| 306 | return AUDIO_INPUT_OPENED; |
| 307 | case media::AudioIoConfigEvent::INPUT_CLOSED: |
| 308 | return AUDIO_INPUT_CLOSED; |
| 309 | case media::AudioIoConfigEvent::INPUT_CONFIG_CHANGED: |
| 310 | return AUDIO_INPUT_CONFIG_CHANGED; |
| 311 | case media::AudioIoConfigEvent::CLIENT_STARTED: |
| 312 | return AUDIO_CLIENT_STARTED; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 313 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 314 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | ConversionResult<media::AudioIoConfigEvent> legacy2aidl_audio_io_config_event_AudioIoConfigEvent( |
| 318 | audio_io_config_event legacy) { |
| 319 | switch (legacy) { |
| 320 | case AUDIO_OUTPUT_REGISTERED: |
| 321 | return media::AudioIoConfigEvent::OUTPUT_REGISTERED; |
| 322 | case AUDIO_OUTPUT_OPENED: |
| 323 | return media::AudioIoConfigEvent::OUTPUT_OPENED; |
| 324 | case AUDIO_OUTPUT_CLOSED: |
| 325 | return media::AudioIoConfigEvent::OUTPUT_CLOSED; |
| 326 | case AUDIO_OUTPUT_CONFIG_CHANGED: |
| 327 | return media::AudioIoConfigEvent::OUTPUT_CONFIG_CHANGED; |
| 328 | case AUDIO_INPUT_REGISTERED: |
| 329 | return media::AudioIoConfigEvent::INPUT_REGISTERED; |
| 330 | case AUDIO_INPUT_OPENED: |
| 331 | return media::AudioIoConfigEvent::INPUT_OPENED; |
| 332 | case AUDIO_INPUT_CLOSED: |
| 333 | return media::AudioIoConfigEvent::INPUT_CLOSED; |
| 334 | case AUDIO_INPUT_CONFIG_CHANGED: |
| 335 | return media::AudioIoConfigEvent::INPUT_CONFIG_CHANGED; |
| 336 | case AUDIO_CLIENT_STARTED: |
| 337 | return media::AudioIoConfigEvent::CLIENT_STARTED; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 338 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 339 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | ConversionResult<audio_port_role_t> aidl2legacy_AudioPortRole_audio_port_role_t( |
| 343 | media::AudioPortRole aidl) { |
| 344 | switch (aidl) { |
| 345 | case media::AudioPortRole::NONE: |
| 346 | return AUDIO_PORT_ROLE_NONE; |
| 347 | case media::AudioPortRole::SOURCE: |
| 348 | return AUDIO_PORT_ROLE_SOURCE; |
| 349 | case media::AudioPortRole::SINK: |
| 350 | return AUDIO_PORT_ROLE_SINK; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 351 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 352 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | ConversionResult<media::AudioPortRole> legacy2aidl_audio_port_role_t_AudioPortRole( |
| 356 | audio_port_role_t legacy) { |
| 357 | switch (legacy) { |
| 358 | case AUDIO_PORT_ROLE_NONE: |
| 359 | return media::AudioPortRole::NONE; |
| 360 | case AUDIO_PORT_ROLE_SOURCE: |
| 361 | return media::AudioPortRole::SOURCE; |
| 362 | case AUDIO_PORT_ROLE_SINK: |
| 363 | return media::AudioPortRole::SINK; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 364 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 365 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | ConversionResult<audio_port_type_t> aidl2legacy_AudioPortType_audio_port_type_t( |
| 369 | media::AudioPortType aidl) { |
| 370 | switch (aidl) { |
| 371 | case media::AudioPortType::NONE: |
| 372 | return AUDIO_PORT_TYPE_NONE; |
| 373 | case media::AudioPortType::DEVICE: |
| 374 | return AUDIO_PORT_TYPE_DEVICE; |
| 375 | case media::AudioPortType::MIX: |
| 376 | return AUDIO_PORT_TYPE_MIX; |
| 377 | case media::AudioPortType::SESSION: |
| 378 | return AUDIO_PORT_TYPE_SESSION; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 379 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 380 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | ConversionResult<media::AudioPortType> legacy2aidl_audio_port_type_t_AudioPortType( |
| 384 | audio_port_type_t legacy) { |
| 385 | switch (legacy) { |
| 386 | case AUDIO_PORT_TYPE_NONE: |
| 387 | return media::AudioPortType::NONE; |
| 388 | case AUDIO_PORT_TYPE_DEVICE: |
| 389 | return media::AudioPortType::DEVICE; |
| 390 | case AUDIO_PORT_TYPE_MIX: |
| 391 | return media::AudioPortType::MIX; |
| 392 | case AUDIO_PORT_TYPE_SESSION: |
| 393 | return media::AudioPortType::SESSION; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 394 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 395 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | ConversionResult<audio_format_t> aidl2legacy_AudioFormat_audio_format_t( |
Mikhail Naganov | c10572e | 2021-05-21 17:42:02 -0700 | [diff] [blame] | 399 | media::AudioFormatSys aidl) { |
| 400 | // This relies on AudioFormatSys being kept in sync with audio_format_t. |
| 401 | static_assert(sizeof(media::AudioFormatSys) == sizeof(audio_format_t)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 402 | return static_cast<audio_format_t>(aidl); |
| 403 | } |
| 404 | |
Mikhail Naganov | c10572e | 2021-05-21 17:42:02 -0700 | [diff] [blame] | 405 | ConversionResult<media::AudioFormatSys> legacy2aidl_audio_format_t_AudioFormat( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 406 | audio_format_t legacy) { |
Mikhail Naganov | c10572e | 2021-05-21 17:42:02 -0700 | [diff] [blame] | 407 | // This relies on AudioFormatSys being kept in sync with audio_format_t. |
| 408 | static_assert(sizeof(media::AudioFormatSys) == sizeof(audio_format_t)); |
| 409 | return static_cast<media::AudioFormatSys>(legacy); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Mikhail Naganov | e128b8e | 2021-06-04 17:31:03 -0700 | [diff] [blame^] | 412 | namespace { |
| 413 | |
| 414 | namespace detail { |
| 415 | using AudioFormatPair = std::pair<audio_format_t, media::AudioFormatDescription>; |
| 416 | using AudioFormatPairs = std::vector<AudioFormatPair>; |
| 417 | } |
| 418 | |
| 419 | media::AudioFormatDescription make_AudioFormatDescription(media::AudioFormatType type) { |
| 420 | media::AudioFormatDescription result; |
| 421 | result.type = type; |
| 422 | return result; |
| 423 | } |
| 424 | |
| 425 | media::AudioFormatDescription make_AudioFormatDescription(media::PcmType pcm) { |
| 426 | auto result = make_AudioFormatDescription(media::AudioFormatType::PCM); |
| 427 | result.pcm = pcm; |
| 428 | return result; |
| 429 | } |
| 430 | |
| 431 | media::AudioFormatDescription make_AudioFormatDescription(const std::string& encoding) { |
| 432 | media::AudioFormatDescription result; |
| 433 | result.encoding = encoding; |
| 434 | return result; |
| 435 | } |
| 436 | |
| 437 | media::AudioFormatDescription make_AudioFormatDescription(media::PcmType transport, |
| 438 | const std::string& encoding) { |
| 439 | auto result = make_AudioFormatDescription(encoding); |
| 440 | result.pcm = transport; |
| 441 | return result; |
| 442 | } |
| 443 | |
| 444 | const detail::AudioFormatPairs& getAudioFormatPairs() { |
| 445 | static const detail::AudioFormatPairs pairs = {{ |
| 446 | { |
| 447 | AUDIO_FORMAT_INVALID, |
| 448 | make_AudioFormatDescription(media::AudioFormatType::SYS_RESERVED_INVALID) |
| 449 | }, |
| 450 | { |
| 451 | AUDIO_FORMAT_DEFAULT, media::AudioFormatDescription{} |
| 452 | }, |
| 453 | { |
| 454 | AUDIO_FORMAT_PCM_16_BIT, make_AudioFormatDescription(media::PcmType::INT_16_BIT) |
| 455 | }, |
| 456 | { |
| 457 | AUDIO_FORMAT_PCM_8_BIT, make_AudioFormatDescription(media::PcmType::UINT_8_BIT) |
| 458 | }, |
| 459 | { |
| 460 | AUDIO_FORMAT_PCM_32_BIT, make_AudioFormatDescription(media::PcmType::INT_32_BIT) |
| 461 | }, |
| 462 | { |
| 463 | AUDIO_FORMAT_PCM_8_24_BIT, make_AudioFormatDescription(media::PcmType::FIXED_Q_8_24) |
| 464 | }, |
| 465 | { |
| 466 | AUDIO_FORMAT_PCM_FLOAT, make_AudioFormatDescription(media::PcmType::FLOAT_32_BIT) |
| 467 | }, |
| 468 | { |
| 469 | AUDIO_FORMAT_PCM_24_BIT_PACKED, make_AudioFormatDescription(media::PcmType::INT_24_BIT) |
| 470 | }, |
| 471 | { |
| 472 | // See the comment in MediaDefs.h. |
| 473 | AUDIO_FORMAT_MP3, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_MPEG) |
| 474 | }, |
| 475 | { |
| 476 | AUDIO_FORMAT_AMR_NB, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AMR_NB) |
| 477 | }, |
| 478 | { |
| 479 | AUDIO_FORMAT_AMR_WB, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AMR_WB) |
| 480 | }, |
| 481 | { |
| 482 | // Note: in MediaDefs.cpp MEDIA_MIMETYPE_AUDIO_AAC = "audio/mp4a-latm". |
| 483 | AUDIO_FORMAT_AAC, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AAC_FORMAT) |
| 484 | }, |
| 485 | { |
| 486 | // Note: not in the IANA registry. |
| 487 | AUDIO_FORMAT_AAC_MAIN, make_AudioFormatDescription("audio/aac.main") |
| 488 | }, |
| 489 | { |
| 490 | // Note: not in the IANA registry. |
| 491 | AUDIO_FORMAT_AAC_LC, make_AudioFormatDescription("audio/aac.lc") |
| 492 | }, |
| 493 | { |
| 494 | // Note: not in the IANA registry. |
| 495 | AUDIO_FORMAT_AAC_SSR, make_AudioFormatDescription("audio/aac.ssr") |
| 496 | }, |
| 497 | { |
| 498 | // Note: not in the IANA registry. |
| 499 | AUDIO_FORMAT_AAC_LTP, make_AudioFormatDescription("audio/aac.ltp") |
| 500 | }, |
| 501 | { |
| 502 | // Note: not in the IANA registry. |
| 503 | AUDIO_FORMAT_AAC_HE_V1, make_AudioFormatDescription("audio/aac.he.v1") |
| 504 | }, |
| 505 | { |
| 506 | // Note: not in the IANA registry. |
| 507 | AUDIO_FORMAT_AAC_SCALABLE, make_AudioFormatDescription("audio/aac.scalable") |
| 508 | }, |
| 509 | { |
| 510 | // Note: not in the IANA registry. |
| 511 | AUDIO_FORMAT_AAC_ERLC, make_AudioFormatDescription("audio/aac.erlc") |
| 512 | }, |
| 513 | { |
| 514 | // Note: not in the IANA registry. |
| 515 | AUDIO_FORMAT_AAC_LD, make_AudioFormatDescription("audio/aac.ld") |
| 516 | }, |
| 517 | { |
| 518 | // Note: not in the IANA registry. |
| 519 | AUDIO_FORMAT_AAC_HE_V2, make_AudioFormatDescription("audio/aac.he.v2") |
| 520 | }, |
| 521 | { |
| 522 | // Note: not in the IANA registry. |
| 523 | AUDIO_FORMAT_AAC_ELD, make_AudioFormatDescription("audio/aac.eld") |
| 524 | }, |
| 525 | { |
| 526 | // Note: not in the IANA registry. |
| 527 | AUDIO_FORMAT_AAC_XHE, make_AudioFormatDescription("audio/aac.xhe") |
| 528 | }, |
| 529 | // AUDIO_FORMAT_HE_AAC_V1 and HE_AAC_V2 are removed since they were deprecated long time |
| 530 | // ago. |
| 531 | { |
| 532 | AUDIO_FORMAT_VORBIS, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_VORBIS) |
| 533 | }, |
| 534 | { |
| 535 | AUDIO_FORMAT_OPUS, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_OPUS) |
| 536 | }, |
| 537 | { |
| 538 | AUDIO_FORMAT_AC3, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AC3) |
| 539 | }, |
| 540 | { |
| 541 | AUDIO_FORMAT_E_AC3, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_EAC3) |
| 542 | }, |
| 543 | { |
| 544 | // Note: not in the IANA registry. |
| 545 | AUDIO_FORMAT_E_AC3_JOC, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_EAC3_JOC) |
| 546 | }, |
| 547 | { |
| 548 | AUDIO_FORMAT_DTS, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_DTS) |
| 549 | }, |
| 550 | { |
| 551 | AUDIO_FORMAT_DTS_HD, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_DTS_HD) |
| 552 | }, |
| 553 | // In the future, we would like to represent encapsulated bitstreams as |
| 554 | // nested AudioFormatDescriptions. The legacy 'AUDIO_FORMAT_IEC61937' type doesn't |
| 555 | // specify the format of the encapsulated bitstream. |
| 556 | { |
| 557 | // Note: not in the IANA registry. |
| 558 | AUDIO_FORMAT_IEC61937, |
| 559 | make_AudioFormatDescription(media::PcmType::INT_16_BIT, "audio/x-iec61937") |
| 560 | }, |
| 561 | { |
| 562 | // Note: not in the IANA registry. |
| 563 | AUDIO_FORMAT_DOLBY_TRUEHD, make_AudioFormatDescription("audio/vnd.dolby.truehd") |
| 564 | }, |
| 565 | { |
| 566 | AUDIO_FORMAT_EVRC, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_EVRC) |
| 567 | }, |
| 568 | { |
| 569 | AUDIO_FORMAT_EVRCB, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_EVRCB) |
| 570 | }, |
| 571 | { |
| 572 | AUDIO_FORMAT_EVRCWB, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_EVRCWB) |
| 573 | }, |
| 574 | { |
| 575 | AUDIO_FORMAT_EVRCNW, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_EVRCNW) |
| 576 | }, |
| 577 | { |
| 578 | // Note: not in the IANA registry. |
| 579 | AUDIO_FORMAT_AAC_ADIF, make_AudioFormatDescription("audio/aac.adif") |
| 580 | }, |
| 581 | { |
| 582 | // Note: not in the IANA registry. |
| 583 | AUDIO_FORMAT_WMA, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_WMA) |
| 584 | }, |
| 585 | { |
| 586 | // Note: not in the IANA registry. |
| 587 | AUDIO_FORMAT_WMA_PRO, make_AudioFormatDescription("audio/x-ms-wma.pro") |
| 588 | }, |
| 589 | { |
| 590 | AUDIO_FORMAT_AMR_WB_PLUS, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AMR_WB_PLUS) |
| 591 | }, |
| 592 | { |
| 593 | // Note: not in the IANA registry. |
| 594 | AUDIO_FORMAT_MP2, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_II) |
| 595 | }, |
| 596 | { |
| 597 | AUDIO_FORMAT_QCELP, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_QCELP) |
| 598 | }, |
| 599 | { |
| 600 | // Note: not in the IANA registry. |
| 601 | AUDIO_FORMAT_DSD, make_AudioFormatDescription("audio/vnd.sony.dsd") |
| 602 | }, |
| 603 | { |
| 604 | AUDIO_FORMAT_FLAC, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_FLAC) |
| 605 | }, |
| 606 | { |
| 607 | // Note: not in the IANA registry. |
| 608 | AUDIO_FORMAT_ALAC, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_ALAC) |
| 609 | }, |
| 610 | { |
| 611 | // Note: not in the IANA registry. |
| 612 | AUDIO_FORMAT_APE, make_AudioFormatDescription("audio/x-ape") |
| 613 | }, |
| 614 | { |
| 615 | // Note: not in the IANA registry. |
| 616 | AUDIO_FORMAT_AAC_ADTS, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AAC_ADTS) |
| 617 | }, |
| 618 | { |
| 619 | // Note: not in the IANA registry. |
| 620 | AUDIO_FORMAT_AAC_ADTS_MAIN, make_AudioFormatDescription("audio/aac-adts.main") |
| 621 | }, |
| 622 | { |
| 623 | // Note: not in the IANA registry. |
| 624 | AUDIO_FORMAT_AAC_ADTS_LC, make_AudioFormatDescription("audio/aac-adts.lc") |
| 625 | }, |
| 626 | { |
| 627 | // Note: not in the IANA registry. |
| 628 | AUDIO_FORMAT_AAC_ADTS_SSR, make_AudioFormatDescription("audio/aac-adts.ssr") |
| 629 | }, |
| 630 | { |
| 631 | // Note: not in the IANA registry. |
| 632 | AUDIO_FORMAT_AAC_ADTS_LTP, make_AudioFormatDescription("audio/aac-adts.ltp") |
| 633 | }, |
| 634 | { |
| 635 | // Note: not in the IANA registry. |
| 636 | AUDIO_FORMAT_AAC_ADTS_HE_V1, make_AudioFormatDescription("audio/aac-adts.he.v1") |
| 637 | }, |
| 638 | { |
| 639 | // Note: not in the IANA registry. |
| 640 | AUDIO_FORMAT_AAC_ADTS_SCALABLE, make_AudioFormatDescription("audio/aac-adts.scalable") |
| 641 | }, |
| 642 | { |
| 643 | // Note: not in the IANA registry. |
| 644 | AUDIO_FORMAT_AAC_ADTS_ERLC, make_AudioFormatDescription("audio/aac-adts.erlc") |
| 645 | }, |
| 646 | { |
| 647 | // Note: not in the IANA registry. |
| 648 | AUDIO_FORMAT_AAC_ADTS_LD, make_AudioFormatDescription("audio/aac-adts.ld") |
| 649 | }, |
| 650 | { |
| 651 | // Note: not in the IANA registry. |
| 652 | AUDIO_FORMAT_AAC_ADTS_HE_V2, make_AudioFormatDescription("audio/aac-adts.he.v2") |
| 653 | }, |
| 654 | { |
| 655 | // Note: not in the IANA registry. |
| 656 | AUDIO_FORMAT_AAC_ADTS_ELD, make_AudioFormatDescription("audio/aac-adts.eld") |
| 657 | }, |
| 658 | { |
| 659 | // Note: not in the IANA registry. |
| 660 | AUDIO_FORMAT_AAC_ADTS_XHE, make_AudioFormatDescription("audio/aac-adts.xhe") |
| 661 | }, |
| 662 | { |
| 663 | // Note: not in the IANA registry. "vnd.octel.sbc" is not BT SBC. |
| 664 | AUDIO_FORMAT_SBC, make_AudioFormatDescription("audio/x-sbc") |
| 665 | }, |
| 666 | { |
| 667 | AUDIO_FORMAT_APTX, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_APTX) |
| 668 | }, |
| 669 | { |
| 670 | // Note: not in the IANA registry. |
| 671 | AUDIO_FORMAT_APTX_HD, make_AudioFormatDescription("audio/vnd.qcom.aptx.hd") |
| 672 | }, |
| 673 | { |
| 674 | // Note: not in the IANA registry. Matches MediaDefs.cpp. |
| 675 | AUDIO_FORMAT_AC4, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AC4) |
| 676 | }, |
| 677 | { |
| 678 | // Note: not in the IANA registry. |
| 679 | AUDIO_FORMAT_LDAC, make_AudioFormatDescription("audio/vnd.sony.ldac") |
| 680 | }, |
| 681 | { |
| 682 | // Note: not in the IANA registry. |
| 683 | AUDIO_FORMAT_MAT, make_AudioFormatDescription("audio/vnd.dolby.mat") |
| 684 | }, |
| 685 | { |
| 686 | // Note: not in the IANA registry. |
| 687 | AUDIO_FORMAT_MAT_1_0, make_AudioFormatDescription("audio/vnd.dolby.mat.1.0") |
| 688 | }, |
| 689 | { |
| 690 | // Note: not in the IANA registry. |
| 691 | AUDIO_FORMAT_MAT_2_0, make_AudioFormatDescription("audio/vnd.dolby.mat.2.0") |
| 692 | }, |
| 693 | { |
| 694 | // Note: not in the IANA registry. |
| 695 | AUDIO_FORMAT_MAT_2_1, make_AudioFormatDescription("audio/vnd.dolby.mat.2.1") |
| 696 | }, |
| 697 | { |
| 698 | AUDIO_FORMAT_AAC_LATM, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_AAC) |
| 699 | }, |
| 700 | { |
| 701 | // Note: not in the IANA registry. |
| 702 | AUDIO_FORMAT_AAC_LATM_LC, make_AudioFormatDescription("audio/mp4a-latm.lc") |
| 703 | }, |
| 704 | { |
| 705 | // Note: not in the IANA registry. |
| 706 | AUDIO_FORMAT_AAC_LATM_HE_V1, make_AudioFormatDescription("audio/mp4a-latm.he.v1") |
| 707 | }, |
| 708 | { |
| 709 | // Note: not in the IANA registry. |
| 710 | AUDIO_FORMAT_AAC_LATM_HE_V2, make_AudioFormatDescription("audio/mp4a-latm.he.v2") |
| 711 | }, |
| 712 | { |
| 713 | // Note: not in the IANA registry. |
| 714 | AUDIO_FORMAT_CELT, make_AudioFormatDescription("audio/x-celt") |
| 715 | }, |
| 716 | { |
| 717 | // Note: not in the IANA registry. |
| 718 | AUDIO_FORMAT_APTX_ADAPTIVE, make_AudioFormatDescription("audio/vnd.qcom.aptx.adaptive") |
| 719 | }, |
| 720 | { |
| 721 | // Note: not in the IANA registry. |
| 722 | AUDIO_FORMAT_LHDC, make_AudioFormatDescription("audio/vnd.savitech.lhdc") |
| 723 | }, |
| 724 | { |
| 725 | // Note: not in the IANA registry. |
| 726 | AUDIO_FORMAT_LHDC_LL, make_AudioFormatDescription("audio/vnd.savitech.lhdc.ll") |
| 727 | }, |
| 728 | { |
| 729 | // Note: not in the IANA registry. |
| 730 | AUDIO_FORMAT_APTX_TWSP, make_AudioFormatDescription("audio/vnd.qcom.aptx.twsp") |
| 731 | }, |
| 732 | { |
| 733 | // Note: not in the IANA registry. |
| 734 | AUDIO_FORMAT_LC3, make_AudioFormatDescription("audio/x-lc3") |
| 735 | }, |
| 736 | { |
| 737 | // Note: not in the IANA registry. |
| 738 | AUDIO_FORMAT_MPEGH, make_AudioFormatDescription("audio/x-mpegh") |
| 739 | }, |
| 740 | { |
| 741 | // Note: not in the IANA registry. |
| 742 | AUDIO_FORMAT_MPEGH_BL_L3, make_AudioFormatDescription("audio/x-mpegh.bl.l3") |
| 743 | }, |
| 744 | { |
| 745 | // Note: not in the IANA registry. |
| 746 | AUDIO_FORMAT_MPEGH_BL_L4, make_AudioFormatDescription("audio/x-mpegh.bl.l4") |
| 747 | }, |
| 748 | { |
| 749 | // Note: not in the IANA registry. |
| 750 | AUDIO_FORMAT_MPEGH_LC_L3, make_AudioFormatDescription("audio/x-mpegh.lc.l3") |
| 751 | }, |
| 752 | { |
| 753 | // Note: not in the IANA registry. |
| 754 | AUDIO_FORMAT_MPEGH_LC_L4, make_AudioFormatDescription("audio/x-mpegh.lc.l4") |
| 755 | }, |
| 756 | { |
| 757 | // Note: not in the IANA registry. |
| 758 | AUDIO_FORMAT_IEC60958, |
| 759 | make_AudioFormatDescription(media::PcmType::INT_24_BIT, "audio/x-iec60958") |
| 760 | }, |
| 761 | { |
| 762 | AUDIO_FORMAT_DTS_UHD, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_DTS_UHD) |
| 763 | }, |
| 764 | { |
| 765 | AUDIO_FORMAT_DRA, make_AudioFormatDescription(MEDIA_MIMETYPE_AUDIO_DRA) |
| 766 | }, |
| 767 | }}; |
| 768 | return pairs; |
| 769 | } |
| 770 | |
| 771 | } // namespace |
| 772 | |
| 773 | ConversionResult<audio_format_t> aidl2legacy_AudioFormatDescription_audio_format_t( |
| 774 | const media::AudioFormatDescription& aidl) { |
| 775 | static const std::unordered_map<media::AudioFormatDescription, audio_format_t> m = |
| 776 | [](const detail::AudioFormatPairs& f) { |
| 777 | std::unordered_map<media::AudioFormatDescription, audio_format_t> r; |
| 778 | std::transform(f.begin(), f.end(), std::inserter(r, r.begin()), |
| 779 | [](const detail::AudioFormatPair& p) { |
| 780 | return std::make_pair(p.second, p.first); |
| 781 | }); |
| 782 | return r; |
| 783 | }(getAudioFormatPairs()); |
| 784 | if (auto it = m.find(aidl); it != m.end()) { |
| 785 | return it->second; |
| 786 | } else { |
| 787 | ALOGE("%s: no legacy audio_format_t found for %s", __func__, aidl.toString().c_str()); |
| 788 | return unexpected(BAD_VALUE); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | ConversionResult<media::AudioFormatDescription> legacy2aidl_audio_format_t_AudioFormatDescription( |
| 793 | audio_format_t legacy) { |
| 794 | static const std::unordered_map<audio_format_t, media::AudioFormatDescription> m = |
| 795 | [](const detail::AudioFormatPairs& f) { |
| 796 | return std::unordered_map<audio_format_t, media::AudioFormatDescription>( |
| 797 | f.begin(), f.end()); }(getAudioFormatPairs()); |
| 798 | if (auto it = m.find(legacy); it != m.end()) { |
| 799 | return it->second; |
| 800 | } else { |
| 801 | ALOGE("%s: no AudioFormatDescription found for legacy audio_format_t value 0x%x", |
| 802 | __func__, legacy); |
| 803 | return unexpected(BAD_VALUE); |
| 804 | } |
| 805 | } |
| 806 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 807 | 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] | 808 | switch (aidl) { |
| 809 | case media::AudioGainMode::JOINT: |
| 810 | return AUDIO_GAIN_MODE_JOINT; |
| 811 | case media::AudioGainMode::CHANNELS: |
| 812 | return AUDIO_GAIN_MODE_CHANNELS; |
| 813 | case media::AudioGainMode::RAMP: |
| 814 | return AUDIO_GAIN_MODE_RAMP; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 815 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 816 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 817 | } |
| 818 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 819 | 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] | 820 | switch (legacy) { |
| 821 | case AUDIO_GAIN_MODE_JOINT: |
| 822 | return media::AudioGainMode::JOINT; |
| 823 | case AUDIO_GAIN_MODE_CHANNELS: |
| 824 | return media::AudioGainMode::CHANNELS; |
| 825 | case AUDIO_GAIN_MODE_RAMP: |
| 826 | return media::AudioGainMode::RAMP; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 827 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 828 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 829 | } |
| 830 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 831 | ConversionResult<audio_gain_mode_t> aidl2legacy_int32_t_audio_gain_mode_t_mask(int32_t aidl) { |
| 832 | return convertBitmask<audio_gain_mode_t, int32_t, audio_gain_mode_t, media::AudioGainMode>( |
| 833 | aidl, aidl2legacy_AudioGainMode_audio_gain_mode_t, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 834 | // AudioGainMode is index-based. |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 835 | indexToEnum_index<media::AudioGainMode>, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 836 | // AUDIO_GAIN_MODE_* constants are mask-based. |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 837 | enumToMask_bitmask<audio_gain_mode_t, audio_gain_mode_t>); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 840 | 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] | 841 | return convertBitmask<int32_t, audio_gain_mode_t, media::AudioGainMode, audio_gain_mode_t>( |
| 842 | legacy, legacy2aidl_audio_gain_mode_t_AudioGainMode, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 843 | // AUDIO_GAIN_MODE_* constants are mask-based. |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 844 | indexToEnum_bitmask<audio_gain_mode_t>, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 845 | // AudioGainMode is index-based. |
| 846 | enumToMask_index<int32_t, media::AudioGainMode>); |
| 847 | } |
| 848 | |
| 849 | ConversionResult<audio_devices_t> aidl2legacy_int32_t_audio_devices_t(int32_t aidl) { |
| 850 | // TODO(ytai): bitfield? |
| 851 | return convertReinterpret<audio_devices_t>(aidl); |
| 852 | } |
| 853 | |
| 854 | ConversionResult<int32_t> legacy2aidl_audio_devices_t_int32_t(audio_devices_t legacy) { |
| 855 | // TODO(ytai): bitfield? |
| 856 | return convertReinterpret<int32_t>(legacy); |
| 857 | } |
| 858 | |
| 859 | ConversionResult<audio_gain_config> aidl2legacy_AudioGainConfig_audio_gain_config( |
| 860 | const media::AudioGainConfig& aidl, media::AudioPortRole role, media::AudioPortType type) { |
| 861 | audio_gain_config legacy; |
| 862 | legacy.index = VALUE_OR_RETURN(convertIntegral<int>(aidl.index)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 863 | 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] | 864 | legacy.channel_mask = |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 865 | VALUE_OR_RETURN(aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 866 | const bool isInput = VALUE_OR_RETURN(direction(role, type)) == Direction::INPUT; |
| 867 | const bool isJoint = bitmaskIsSet(aidl.mode, media::AudioGainMode::JOINT); |
| 868 | size_t numValues = isJoint ? 1 |
| 869 | : isInput ? audio_channel_count_from_in_mask(legacy.channel_mask) |
| 870 | : audio_channel_count_from_out_mask(legacy.channel_mask); |
| 871 | if (aidl.values.size() != numValues || aidl.values.size() > std::size(legacy.values)) { |
| 872 | return unexpected(BAD_VALUE); |
| 873 | } |
| 874 | for (size_t i = 0; i < numValues; ++i) { |
| 875 | legacy.values[i] = VALUE_OR_RETURN(convertIntegral<int>(aidl.values[i])); |
| 876 | } |
| 877 | legacy.ramp_duration_ms = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.rampDurationMs)); |
| 878 | return legacy; |
| 879 | } |
| 880 | |
| 881 | ConversionResult<media::AudioGainConfig> legacy2aidl_audio_gain_config_AudioGainConfig( |
| 882 | const audio_gain_config& legacy, audio_port_role_t role, audio_port_type_t type) { |
| 883 | media::AudioGainConfig aidl; |
| 884 | aidl.index = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.index)); |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 885 | 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] | 886 | aidl.channelMask = |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 887 | VALUE_OR_RETURN(legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy.channel_mask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 888 | const bool isInput = VALUE_OR_RETURN(direction(role, type)) == Direction::INPUT; |
| 889 | const bool isJoint = (legacy.mode & AUDIO_GAIN_MODE_JOINT) != 0; |
| 890 | size_t numValues = isJoint ? 1 |
| 891 | : isInput ? audio_channel_count_from_in_mask(legacy.channel_mask) |
| 892 | : audio_channel_count_from_out_mask(legacy.channel_mask); |
| 893 | aidl.values.resize(numValues); |
| 894 | for (size_t i = 0; i < numValues; ++i) { |
| 895 | aidl.values[i] = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.values[i])); |
| 896 | } |
| 897 | aidl.rampDurationMs = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.ramp_duration_ms)); |
| 898 | return aidl; |
| 899 | } |
| 900 | |
| 901 | ConversionResult<audio_input_flags_t> aidl2legacy_AudioInputFlags_audio_input_flags_t( |
| 902 | media::AudioInputFlags aidl) { |
| 903 | switch (aidl) { |
| 904 | case media::AudioInputFlags::FAST: |
| 905 | return AUDIO_INPUT_FLAG_FAST; |
| 906 | case media::AudioInputFlags::HW_HOTWORD: |
| 907 | return AUDIO_INPUT_FLAG_HW_HOTWORD; |
| 908 | case media::AudioInputFlags::RAW: |
| 909 | return AUDIO_INPUT_FLAG_RAW; |
| 910 | case media::AudioInputFlags::SYNC: |
| 911 | return AUDIO_INPUT_FLAG_SYNC; |
| 912 | case media::AudioInputFlags::MMAP_NOIRQ: |
| 913 | return AUDIO_INPUT_FLAG_MMAP_NOIRQ; |
| 914 | case media::AudioInputFlags::VOIP_TX: |
| 915 | return AUDIO_INPUT_FLAG_VOIP_TX; |
| 916 | case media::AudioInputFlags::HW_AV_SYNC: |
| 917 | return AUDIO_INPUT_FLAG_HW_AV_SYNC; |
| 918 | case media::AudioInputFlags::DIRECT: |
| 919 | return AUDIO_INPUT_FLAG_DIRECT; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 920 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 921 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | ConversionResult<media::AudioInputFlags> legacy2aidl_audio_input_flags_t_AudioInputFlags( |
| 925 | audio_input_flags_t legacy) { |
| 926 | switch (legacy) { |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 927 | case AUDIO_INPUT_FLAG_NONE: |
| 928 | break; // shouldn't get here. must be listed -Werror,-Wswitch |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 929 | case AUDIO_INPUT_FLAG_FAST: |
| 930 | return media::AudioInputFlags::FAST; |
| 931 | case AUDIO_INPUT_FLAG_HW_HOTWORD: |
| 932 | return media::AudioInputFlags::HW_HOTWORD; |
| 933 | case AUDIO_INPUT_FLAG_RAW: |
| 934 | return media::AudioInputFlags::RAW; |
| 935 | case AUDIO_INPUT_FLAG_SYNC: |
| 936 | return media::AudioInputFlags::SYNC; |
| 937 | case AUDIO_INPUT_FLAG_MMAP_NOIRQ: |
| 938 | return media::AudioInputFlags::MMAP_NOIRQ; |
| 939 | case AUDIO_INPUT_FLAG_VOIP_TX: |
| 940 | return media::AudioInputFlags::VOIP_TX; |
| 941 | case AUDIO_INPUT_FLAG_HW_AV_SYNC: |
| 942 | return media::AudioInputFlags::HW_AV_SYNC; |
| 943 | case AUDIO_INPUT_FLAG_DIRECT: |
| 944 | return media::AudioInputFlags::DIRECT; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 945 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 946 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | ConversionResult<audio_output_flags_t> aidl2legacy_AudioOutputFlags_audio_output_flags_t( |
| 950 | media::AudioOutputFlags aidl) { |
| 951 | switch (aidl) { |
| 952 | case media::AudioOutputFlags::DIRECT: |
| 953 | return AUDIO_OUTPUT_FLAG_DIRECT; |
| 954 | case media::AudioOutputFlags::PRIMARY: |
| 955 | return AUDIO_OUTPUT_FLAG_PRIMARY; |
| 956 | case media::AudioOutputFlags::FAST: |
| 957 | return AUDIO_OUTPUT_FLAG_FAST; |
| 958 | case media::AudioOutputFlags::DEEP_BUFFER: |
| 959 | return AUDIO_OUTPUT_FLAG_DEEP_BUFFER; |
| 960 | case media::AudioOutputFlags::COMPRESS_OFFLOAD: |
| 961 | return AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD; |
| 962 | case media::AudioOutputFlags::NON_BLOCKING: |
| 963 | return AUDIO_OUTPUT_FLAG_NON_BLOCKING; |
| 964 | case media::AudioOutputFlags::HW_AV_SYNC: |
| 965 | return AUDIO_OUTPUT_FLAG_HW_AV_SYNC; |
| 966 | case media::AudioOutputFlags::TTS: |
| 967 | return AUDIO_OUTPUT_FLAG_TTS; |
| 968 | case media::AudioOutputFlags::RAW: |
| 969 | return AUDIO_OUTPUT_FLAG_RAW; |
| 970 | case media::AudioOutputFlags::SYNC: |
| 971 | return AUDIO_OUTPUT_FLAG_SYNC; |
| 972 | case media::AudioOutputFlags::IEC958_NONAUDIO: |
| 973 | return AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO; |
| 974 | case media::AudioOutputFlags::DIRECT_PCM: |
| 975 | return AUDIO_OUTPUT_FLAG_DIRECT_PCM; |
| 976 | case media::AudioOutputFlags::MMAP_NOIRQ: |
| 977 | return AUDIO_OUTPUT_FLAG_MMAP_NOIRQ; |
| 978 | case media::AudioOutputFlags::VOIP_RX: |
| 979 | return AUDIO_OUTPUT_FLAG_VOIP_RX; |
| 980 | case media::AudioOutputFlags::INCALL_MUSIC: |
| 981 | return AUDIO_OUTPUT_FLAG_INCALL_MUSIC; |
Eric Laurent | 90fe31c | 2020-11-26 20:06:35 +0100 | [diff] [blame] | 982 | case media::AudioOutputFlags::GAPLESS_OFFLOAD: |
| 983 | return AUDIO_OUTPUT_FLAG_GAPLESS_OFFLOAD; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 984 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 985 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | ConversionResult<media::AudioOutputFlags> legacy2aidl_audio_output_flags_t_AudioOutputFlags( |
| 989 | audio_output_flags_t legacy) { |
| 990 | switch (legacy) { |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 991 | case AUDIO_OUTPUT_FLAG_NONE: |
| 992 | break; // shouldn't get here. must be listed -Werror,-Wswitch |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 993 | case AUDIO_OUTPUT_FLAG_DIRECT: |
| 994 | return media::AudioOutputFlags::DIRECT; |
| 995 | case AUDIO_OUTPUT_FLAG_PRIMARY: |
| 996 | return media::AudioOutputFlags::PRIMARY; |
| 997 | case AUDIO_OUTPUT_FLAG_FAST: |
| 998 | return media::AudioOutputFlags::FAST; |
| 999 | case AUDIO_OUTPUT_FLAG_DEEP_BUFFER: |
| 1000 | return media::AudioOutputFlags::DEEP_BUFFER; |
| 1001 | case AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD: |
| 1002 | return media::AudioOutputFlags::COMPRESS_OFFLOAD; |
| 1003 | case AUDIO_OUTPUT_FLAG_NON_BLOCKING: |
| 1004 | return media::AudioOutputFlags::NON_BLOCKING; |
| 1005 | case AUDIO_OUTPUT_FLAG_HW_AV_SYNC: |
| 1006 | return media::AudioOutputFlags::HW_AV_SYNC; |
| 1007 | case AUDIO_OUTPUT_FLAG_TTS: |
| 1008 | return media::AudioOutputFlags::TTS; |
| 1009 | case AUDIO_OUTPUT_FLAG_RAW: |
| 1010 | return media::AudioOutputFlags::RAW; |
| 1011 | case AUDIO_OUTPUT_FLAG_SYNC: |
| 1012 | return media::AudioOutputFlags::SYNC; |
| 1013 | case AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO: |
| 1014 | return media::AudioOutputFlags::IEC958_NONAUDIO; |
| 1015 | case AUDIO_OUTPUT_FLAG_DIRECT_PCM: |
| 1016 | return media::AudioOutputFlags::DIRECT_PCM; |
| 1017 | case AUDIO_OUTPUT_FLAG_MMAP_NOIRQ: |
| 1018 | return media::AudioOutputFlags::MMAP_NOIRQ; |
| 1019 | case AUDIO_OUTPUT_FLAG_VOIP_RX: |
| 1020 | return media::AudioOutputFlags::VOIP_RX; |
| 1021 | case AUDIO_OUTPUT_FLAG_INCALL_MUSIC: |
| 1022 | return media::AudioOutputFlags::INCALL_MUSIC; |
Eric Laurent | 90fe31c | 2020-11-26 20:06:35 +0100 | [diff] [blame] | 1023 | case AUDIO_OUTPUT_FLAG_GAPLESS_OFFLOAD: |
| 1024 | return media::AudioOutputFlags::GAPLESS_OFFLOAD; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1025 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1026 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1029 | ConversionResult<audio_input_flags_t> aidl2legacy_int32_t_audio_input_flags_t_mask( |
| 1030 | int32_t aidl) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1031 | using LegacyMask = std::underlying_type_t<audio_input_flags_t>; |
| 1032 | |
| 1033 | LegacyMask converted = VALUE_OR_RETURN( |
| 1034 | (convertBitmask<LegacyMask, int32_t, audio_input_flags_t, media::AudioInputFlags>( |
| 1035 | aidl, aidl2legacy_AudioInputFlags_audio_input_flags_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1036 | indexToEnum_index<media::AudioInputFlags>, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1037 | enumToMask_bitmask<LegacyMask, audio_input_flags_t>))); |
| 1038 | return static_cast<audio_input_flags_t>(converted); |
| 1039 | } |
| 1040 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1041 | ConversionResult<int32_t> legacy2aidl_audio_input_flags_t_int32_t_mask( |
| 1042 | audio_input_flags_t legacy) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1043 | using LegacyMask = std::underlying_type_t<audio_input_flags_t>; |
| 1044 | |
| 1045 | LegacyMask legacyMask = static_cast<LegacyMask>(legacy); |
| 1046 | return convertBitmask<int32_t, LegacyMask, media::AudioInputFlags, audio_input_flags_t>( |
| 1047 | legacyMask, legacy2aidl_audio_input_flags_t_AudioInputFlags, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1048 | indexToEnum_bitmask<audio_input_flags_t>, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1049 | enumToMask_index<int32_t, media::AudioInputFlags>); |
| 1050 | } |
| 1051 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1052 | ConversionResult<audio_output_flags_t> aidl2legacy_int32_t_audio_output_flags_t_mask( |
| 1053 | int32_t aidl) { |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1054 | return convertBitmask<audio_output_flags_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1055 | int32_t, |
| 1056 | audio_output_flags_t, |
| 1057 | media::AudioOutputFlags>( |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1058 | aidl, aidl2legacy_AudioOutputFlags_audio_output_flags_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1059 | indexToEnum_index<media::AudioOutputFlags>, |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1060 | enumToMask_bitmask<audio_output_flags_t, audio_output_flags_t>); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1063 | ConversionResult<int32_t> legacy2aidl_audio_output_flags_t_int32_t_mask( |
| 1064 | audio_output_flags_t legacy) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1065 | using LegacyMask = std::underlying_type_t<audio_output_flags_t>; |
| 1066 | |
| 1067 | LegacyMask legacyMask = static_cast<LegacyMask>(legacy); |
| 1068 | return convertBitmask<int32_t, LegacyMask, media::AudioOutputFlags, audio_output_flags_t>( |
| 1069 | legacyMask, legacy2aidl_audio_output_flags_t_AudioOutputFlags, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1070 | indexToEnum_bitmask<audio_output_flags_t>, |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1071 | enumToMask_index<int32_t, media::AudioOutputFlags>); |
| 1072 | } |
| 1073 | |
| 1074 | ConversionResult<audio_io_flags> aidl2legacy_AudioIoFlags_audio_io_flags( |
| 1075 | const media::AudioIoFlags& aidl, media::AudioPortRole role, media::AudioPortType type) { |
| 1076 | audio_io_flags legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1077 | Direction dir = VALUE_OR_RETURN(direction(role, type)); |
| 1078 | switch (dir) { |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1079 | case Direction::INPUT: { |
| 1080 | legacy.input = VALUE_OR_RETURN( |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1081 | aidl2legacy_int32_t_audio_input_flags_t_mask( |
| 1082 | VALUE_OR_RETURN(UNION_GET(aidl, input)))); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1083 | } |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1084 | break; |
| 1085 | |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1086 | case Direction::OUTPUT: { |
| 1087 | legacy.output = VALUE_OR_RETURN( |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1088 | aidl2legacy_int32_t_audio_output_flags_t_mask( |
| 1089 | VALUE_OR_RETURN(UNION_GET(aidl, output)))); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1090 | } |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1091 | break; |
| 1092 | } |
| 1093 | |
| 1094 | return legacy; |
| 1095 | } |
| 1096 | |
| 1097 | ConversionResult<media::AudioIoFlags> legacy2aidl_audio_io_flags_AudioIoFlags( |
| 1098 | const audio_io_flags& legacy, audio_port_role_t role, audio_port_type_t type) { |
| 1099 | media::AudioIoFlags aidl; |
| 1100 | |
| 1101 | Direction dir = VALUE_OR_RETURN(direction(role, type)); |
| 1102 | switch (dir) { |
| 1103 | case Direction::INPUT: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1104 | UNION_SET(aidl, input, |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1105 | VALUE_OR_RETURN(legacy2aidl_audio_input_flags_t_int32_t_mask( |
| 1106 | legacy.input))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1107 | break; |
| 1108 | case Direction::OUTPUT: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1109 | UNION_SET(aidl, output, |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1110 | VALUE_OR_RETURN(legacy2aidl_audio_output_flags_t_int32_t_mask( |
| 1111 | legacy.output))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1112 | break; |
| 1113 | } |
| 1114 | return aidl; |
| 1115 | } |
| 1116 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1117 | ConversionResult<audio_port_config_device_ext> |
| 1118 | aidl2legacy_AudioPortConfigDeviceExt_audio_port_config_device_ext( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1119 | const media::AudioPortConfigDeviceExt& aidl) { |
| 1120 | audio_port_config_device_ext legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1121 | legacy.hw_module = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_module_handle_t(aidl.hwModule)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1122 | legacy.type = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_devices_t(aidl.type)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1123 | 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] | 1124 | return legacy; |
| 1125 | } |
| 1126 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1127 | ConversionResult<media::AudioPortConfigDeviceExt> |
| 1128 | legacy2aidl_audio_port_config_device_ext_AudioPortConfigDeviceExt( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1129 | const audio_port_config_device_ext& legacy) { |
| 1130 | media::AudioPortConfigDeviceExt aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1131 | aidl.hwModule = VALUE_OR_RETURN(legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1132 | aidl.type = VALUE_OR_RETURN(legacy2aidl_audio_devices_t_int32_t(legacy.type)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1133 | aidl.address = VALUE_OR_RETURN( |
| 1134 | legacy2aidl_string(legacy.address, AUDIO_DEVICE_MAX_ADDRESS_LEN)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1135 | return aidl; |
| 1136 | } |
| 1137 | |
| 1138 | ConversionResult<audio_stream_type_t> aidl2legacy_AudioStreamType_audio_stream_type_t( |
| 1139 | media::AudioStreamType aidl) { |
| 1140 | switch (aidl) { |
| 1141 | case media::AudioStreamType::DEFAULT: |
| 1142 | return AUDIO_STREAM_DEFAULT; |
| 1143 | case media::AudioStreamType::VOICE_CALL: |
| 1144 | return AUDIO_STREAM_VOICE_CALL; |
| 1145 | case media::AudioStreamType::SYSTEM: |
| 1146 | return AUDIO_STREAM_SYSTEM; |
| 1147 | case media::AudioStreamType::RING: |
| 1148 | return AUDIO_STREAM_RING; |
| 1149 | case media::AudioStreamType::MUSIC: |
| 1150 | return AUDIO_STREAM_MUSIC; |
| 1151 | case media::AudioStreamType::ALARM: |
| 1152 | return AUDIO_STREAM_ALARM; |
| 1153 | case media::AudioStreamType::NOTIFICATION: |
| 1154 | return AUDIO_STREAM_NOTIFICATION; |
| 1155 | case media::AudioStreamType::BLUETOOTH_SCO: |
| 1156 | return AUDIO_STREAM_BLUETOOTH_SCO; |
| 1157 | case media::AudioStreamType::ENFORCED_AUDIBLE: |
| 1158 | return AUDIO_STREAM_ENFORCED_AUDIBLE; |
| 1159 | case media::AudioStreamType::DTMF: |
| 1160 | return AUDIO_STREAM_DTMF; |
| 1161 | case media::AudioStreamType::TTS: |
| 1162 | return AUDIO_STREAM_TTS; |
| 1163 | case media::AudioStreamType::ACCESSIBILITY: |
| 1164 | return AUDIO_STREAM_ACCESSIBILITY; |
| 1165 | case media::AudioStreamType::ASSISTANT: |
| 1166 | return AUDIO_STREAM_ASSISTANT; |
| 1167 | case media::AudioStreamType::REROUTING: |
| 1168 | return AUDIO_STREAM_REROUTING; |
| 1169 | case media::AudioStreamType::PATCH: |
| 1170 | return AUDIO_STREAM_PATCH; |
| 1171 | case media::AudioStreamType::CALL_ASSISTANT: |
| 1172 | return AUDIO_STREAM_CALL_ASSISTANT; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1173 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1174 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | ConversionResult<media::AudioStreamType> legacy2aidl_audio_stream_type_t_AudioStreamType( |
| 1178 | audio_stream_type_t legacy) { |
| 1179 | switch (legacy) { |
| 1180 | case AUDIO_STREAM_DEFAULT: |
| 1181 | return media::AudioStreamType::DEFAULT; |
| 1182 | case AUDIO_STREAM_VOICE_CALL: |
| 1183 | return media::AudioStreamType::VOICE_CALL; |
| 1184 | case AUDIO_STREAM_SYSTEM: |
| 1185 | return media::AudioStreamType::SYSTEM; |
| 1186 | case AUDIO_STREAM_RING: |
| 1187 | return media::AudioStreamType::RING; |
| 1188 | case AUDIO_STREAM_MUSIC: |
| 1189 | return media::AudioStreamType::MUSIC; |
| 1190 | case AUDIO_STREAM_ALARM: |
| 1191 | return media::AudioStreamType::ALARM; |
| 1192 | case AUDIO_STREAM_NOTIFICATION: |
| 1193 | return media::AudioStreamType::NOTIFICATION; |
| 1194 | case AUDIO_STREAM_BLUETOOTH_SCO: |
| 1195 | return media::AudioStreamType::BLUETOOTH_SCO; |
| 1196 | case AUDIO_STREAM_ENFORCED_AUDIBLE: |
| 1197 | return media::AudioStreamType::ENFORCED_AUDIBLE; |
| 1198 | case AUDIO_STREAM_DTMF: |
| 1199 | return media::AudioStreamType::DTMF; |
| 1200 | case AUDIO_STREAM_TTS: |
| 1201 | return media::AudioStreamType::TTS; |
| 1202 | case AUDIO_STREAM_ACCESSIBILITY: |
| 1203 | return media::AudioStreamType::ACCESSIBILITY; |
| 1204 | case AUDIO_STREAM_ASSISTANT: |
| 1205 | return media::AudioStreamType::ASSISTANT; |
| 1206 | case AUDIO_STREAM_REROUTING: |
| 1207 | return media::AudioStreamType::REROUTING; |
| 1208 | case AUDIO_STREAM_PATCH: |
| 1209 | return media::AudioStreamType::PATCH; |
| 1210 | case AUDIO_STREAM_CALL_ASSISTANT: |
| 1211 | return media::AudioStreamType::CALL_ASSISTANT; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1212 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1213 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | ConversionResult<audio_source_t> aidl2legacy_AudioSourceType_audio_source_t( |
| 1217 | media::AudioSourceType aidl) { |
| 1218 | switch (aidl) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1219 | case media::AudioSourceType::INVALID: |
| 1220 | // This value does not have an enum |
| 1221 | return AUDIO_SOURCE_INVALID; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1222 | case media::AudioSourceType::DEFAULT: |
| 1223 | return AUDIO_SOURCE_DEFAULT; |
| 1224 | case media::AudioSourceType::MIC: |
| 1225 | return AUDIO_SOURCE_MIC; |
| 1226 | case media::AudioSourceType::VOICE_UPLINK: |
| 1227 | return AUDIO_SOURCE_VOICE_UPLINK; |
| 1228 | case media::AudioSourceType::VOICE_DOWNLINK: |
| 1229 | return AUDIO_SOURCE_VOICE_DOWNLINK; |
| 1230 | case media::AudioSourceType::VOICE_CALL: |
| 1231 | return AUDIO_SOURCE_VOICE_CALL; |
| 1232 | case media::AudioSourceType::CAMCORDER: |
| 1233 | return AUDIO_SOURCE_CAMCORDER; |
| 1234 | case media::AudioSourceType::VOICE_RECOGNITION: |
| 1235 | return AUDIO_SOURCE_VOICE_RECOGNITION; |
| 1236 | case media::AudioSourceType::VOICE_COMMUNICATION: |
| 1237 | return AUDIO_SOURCE_VOICE_COMMUNICATION; |
| 1238 | case media::AudioSourceType::REMOTE_SUBMIX: |
| 1239 | return AUDIO_SOURCE_REMOTE_SUBMIX; |
| 1240 | case media::AudioSourceType::UNPROCESSED: |
| 1241 | return AUDIO_SOURCE_UNPROCESSED; |
| 1242 | case media::AudioSourceType::VOICE_PERFORMANCE: |
| 1243 | return AUDIO_SOURCE_VOICE_PERFORMANCE; |
| 1244 | case media::AudioSourceType::ECHO_REFERENCE: |
| 1245 | return AUDIO_SOURCE_ECHO_REFERENCE; |
| 1246 | case media::AudioSourceType::FM_TUNER: |
| 1247 | return AUDIO_SOURCE_FM_TUNER; |
| 1248 | case media::AudioSourceType::HOTWORD: |
| 1249 | return AUDIO_SOURCE_HOTWORD; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1250 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1251 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | ConversionResult<media::AudioSourceType> legacy2aidl_audio_source_t_AudioSourceType( |
| 1255 | audio_source_t legacy) { |
| 1256 | switch (legacy) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1257 | case AUDIO_SOURCE_INVALID: |
| 1258 | return media::AudioSourceType::INVALID; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1259 | case AUDIO_SOURCE_DEFAULT: |
| 1260 | return media::AudioSourceType::DEFAULT; |
| 1261 | case AUDIO_SOURCE_MIC: |
| 1262 | return media::AudioSourceType::MIC; |
| 1263 | case AUDIO_SOURCE_VOICE_UPLINK: |
| 1264 | return media::AudioSourceType::VOICE_UPLINK; |
| 1265 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 1266 | return media::AudioSourceType::VOICE_DOWNLINK; |
| 1267 | case AUDIO_SOURCE_VOICE_CALL: |
| 1268 | return media::AudioSourceType::VOICE_CALL; |
| 1269 | case AUDIO_SOURCE_CAMCORDER: |
| 1270 | return media::AudioSourceType::CAMCORDER; |
| 1271 | case AUDIO_SOURCE_VOICE_RECOGNITION: |
| 1272 | return media::AudioSourceType::VOICE_RECOGNITION; |
| 1273 | case AUDIO_SOURCE_VOICE_COMMUNICATION: |
| 1274 | return media::AudioSourceType::VOICE_COMMUNICATION; |
| 1275 | case AUDIO_SOURCE_REMOTE_SUBMIX: |
| 1276 | return media::AudioSourceType::REMOTE_SUBMIX; |
| 1277 | case AUDIO_SOURCE_UNPROCESSED: |
| 1278 | return media::AudioSourceType::UNPROCESSED; |
| 1279 | case AUDIO_SOURCE_VOICE_PERFORMANCE: |
| 1280 | return media::AudioSourceType::VOICE_PERFORMANCE; |
| 1281 | case AUDIO_SOURCE_ECHO_REFERENCE: |
| 1282 | return media::AudioSourceType::ECHO_REFERENCE; |
| 1283 | case AUDIO_SOURCE_FM_TUNER: |
| 1284 | return media::AudioSourceType::FM_TUNER; |
| 1285 | case AUDIO_SOURCE_HOTWORD: |
| 1286 | return media::AudioSourceType::HOTWORD; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1287 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1288 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1291 | ConversionResult<audio_session_t> aidl2legacy_int32_t_audio_session_t(int32_t aidl) { |
| 1292 | return convertReinterpret<audio_session_t>(aidl); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1295 | ConversionResult<int32_t> legacy2aidl_audio_session_t_int32_t(audio_session_t legacy) { |
| 1296 | return convertReinterpret<int32_t>(legacy); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | // This type is unnamed in the original definition, thus we name it here. |
| 1300 | using audio_port_config_mix_ext_usecase = decltype(audio_port_config_mix_ext::usecase); |
| 1301 | |
| 1302 | ConversionResult<audio_port_config_mix_ext_usecase> aidl2legacy_AudioPortConfigMixExtUseCase( |
| 1303 | const media::AudioPortConfigMixExtUseCase& aidl, media::AudioPortRole role) { |
| 1304 | audio_port_config_mix_ext_usecase legacy; |
| 1305 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1306 | switch (role) { |
| 1307 | case media::AudioPortRole::NONE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1308 | // Just verify that the union is empty. |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1309 | VALUE_OR_RETURN(UNION_GET(aidl, unspecified)); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1310 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1311 | |
| 1312 | case media::AudioPortRole::SOURCE: |
| 1313 | // 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] | 1314 | legacy.stream = VALUE_OR_RETURN(aidl2legacy_AudioStreamType_audio_stream_type_t( |
| 1315 | VALUE_OR_RETURN(UNION_GET(aidl, stream)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1316 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1317 | |
| 1318 | case media::AudioPortRole::SINK: |
| 1319 | // 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] | 1320 | legacy.source = VALUE_OR_RETURN(aidl2legacy_AudioSourceType_audio_source_t( |
| 1321 | VALUE_OR_RETURN(UNION_GET(aidl, source)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1322 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1323 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1324 | 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] | 1325 | } |
| 1326 | |
| 1327 | ConversionResult<media::AudioPortConfigMixExtUseCase> legacy2aidl_AudioPortConfigMixExtUseCase( |
| 1328 | const audio_port_config_mix_ext_usecase& legacy, audio_port_role_t role) { |
| 1329 | media::AudioPortConfigMixExtUseCase aidl; |
| 1330 | |
| 1331 | switch (role) { |
| 1332 | case AUDIO_PORT_ROLE_NONE: |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1333 | UNION_SET(aidl, unspecified, false); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1334 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1335 | case AUDIO_PORT_ROLE_SOURCE: |
| 1336 | // 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] | 1337 | UNION_SET(aidl, stream, VALUE_OR_RETURN( |
| 1338 | legacy2aidl_audio_stream_type_t_AudioStreamType(legacy.stream))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1339 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1340 | case AUDIO_PORT_ROLE_SINK: |
| 1341 | // 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] | 1342 | UNION_SET(aidl, source, |
| 1343 | VALUE_OR_RETURN(legacy2aidl_audio_source_t_AudioSourceType(legacy.source))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1344 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1345 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1346 | 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] | 1347 | } |
| 1348 | |
| 1349 | ConversionResult<audio_port_config_mix_ext> aidl2legacy_AudioPortConfigMixExt( |
| 1350 | const media::AudioPortConfigMixExt& aidl, media::AudioPortRole role) { |
| 1351 | audio_port_config_mix_ext legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1352 | legacy.hw_module = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_module_handle_t(aidl.hwModule)); |
| 1353 | 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] | 1354 | legacy.usecase = VALUE_OR_RETURN(aidl2legacy_AudioPortConfigMixExtUseCase(aidl.usecase, role)); |
| 1355 | return legacy; |
| 1356 | } |
| 1357 | |
| 1358 | ConversionResult<media::AudioPortConfigMixExt> legacy2aidl_AudioPortConfigMixExt( |
| 1359 | const audio_port_config_mix_ext& legacy, audio_port_role_t role) { |
| 1360 | media::AudioPortConfigMixExt aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1361 | aidl.hwModule = VALUE_OR_RETURN(legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
| 1362 | 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] | 1363 | aidl.usecase = VALUE_OR_RETURN(legacy2aidl_AudioPortConfigMixExtUseCase(legacy.usecase, role)); |
| 1364 | return aidl; |
| 1365 | } |
| 1366 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1367 | ConversionResult<audio_port_config_session_ext> |
| 1368 | aidl2legacy_AudioPortConfigSessionExt_audio_port_config_session_ext( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1369 | const media::AudioPortConfigSessionExt& aidl) { |
| 1370 | audio_port_config_session_ext legacy; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1371 | 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] | 1372 | return legacy; |
| 1373 | } |
| 1374 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1375 | ConversionResult<media::AudioPortConfigSessionExt> |
| 1376 | legacy2aidl_audio_port_config_session_ext_AudioPortConfigSessionExt( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1377 | const audio_port_config_session_ext& legacy) { |
| 1378 | media::AudioPortConfigSessionExt aidl; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1379 | 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] | 1380 | return aidl; |
| 1381 | } |
| 1382 | |
| 1383 | // This type is unnamed in the original definition, thus we name it here. |
| 1384 | using audio_port_config_ext = decltype(audio_port_config::ext); |
| 1385 | |
| 1386 | ConversionResult<audio_port_config_ext> aidl2legacy_AudioPortConfigExt( |
| 1387 | const media::AudioPortConfigExt& aidl, media::AudioPortType type, |
| 1388 | media::AudioPortRole role) { |
| 1389 | audio_port_config_ext legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1390 | switch (type) { |
| 1391 | case media::AudioPortType::NONE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1392 | // Just verify that the union is empty. |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1393 | VALUE_OR_RETURN(UNION_GET(aidl, unspecified)); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1394 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1395 | case media::AudioPortType::DEVICE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1396 | legacy.device = VALUE_OR_RETURN( |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1397 | aidl2legacy_AudioPortConfigDeviceExt_audio_port_config_device_ext( |
| 1398 | VALUE_OR_RETURN(UNION_GET(aidl, device)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1399 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1400 | case media::AudioPortType::MIX: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1401 | legacy.mix = VALUE_OR_RETURN( |
| 1402 | aidl2legacy_AudioPortConfigMixExt(VALUE_OR_RETURN(UNION_GET(aidl, mix)), role)); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1403 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1404 | case media::AudioPortType::SESSION: |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1405 | legacy.session = VALUE_OR_RETURN( |
| 1406 | aidl2legacy_AudioPortConfigSessionExt_audio_port_config_session_ext( |
| 1407 | VALUE_OR_RETURN(UNION_GET(aidl, session)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1408 | return legacy; |
| 1409 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1410 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1411 | 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] | 1412 | } |
| 1413 | |
| 1414 | ConversionResult<media::AudioPortConfigExt> legacy2aidl_AudioPortConfigExt( |
| 1415 | const audio_port_config_ext& legacy, audio_port_type_t type, audio_port_role_t role) { |
| 1416 | media::AudioPortConfigExt aidl; |
| 1417 | |
| 1418 | switch (type) { |
| 1419 | case AUDIO_PORT_TYPE_NONE: |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 1420 | UNION_SET(aidl, unspecified, false); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1421 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1422 | case AUDIO_PORT_TYPE_DEVICE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1423 | UNION_SET(aidl, device, |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1424 | VALUE_OR_RETURN( |
| 1425 | legacy2aidl_audio_port_config_device_ext_AudioPortConfigDeviceExt( |
| 1426 | legacy.device))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1427 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1428 | case AUDIO_PORT_TYPE_MIX: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1429 | UNION_SET(aidl, mix, |
| 1430 | VALUE_OR_RETURN(legacy2aidl_AudioPortConfigMixExt(legacy.mix, role))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1431 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1432 | case AUDIO_PORT_TYPE_SESSION: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1433 | UNION_SET(aidl, session, |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1434 | VALUE_OR_RETURN( |
| 1435 | legacy2aidl_audio_port_config_session_ext_AudioPortConfigSessionExt( |
| 1436 | legacy.session))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1437 | return aidl; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1438 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 1439 | 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] | 1440 | } |
| 1441 | |
| 1442 | ConversionResult<audio_port_config> aidl2legacy_AudioPortConfig_audio_port_config( |
| 1443 | const media::AudioPortConfig& aidl) { |
| 1444 | audio_port_config legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1445 | 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] | 1446 | legacy.role = VALUE_OR_RETURN(aidl2legacy_AudioPortRole_audio_port_role_t(aidl.role)); |
| 1447 | legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioPortType_audio_port_type_t(aidl.type)); |
| 1448 | legacy.config_mask = VALUE_OR_RETURN(aidl2legacy_int32_t_config_mask(aidl.configMask)); |
| 1449 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::SAMPLE_RATE)) { |
| 1450 | legacy.sample_rate = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.sampleRate)); |
| 1451 | } |
| 1452 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::CHANNEL_MASK)) { |
| 1453 | legacy.channel_mask = |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1454 | VALUE_OR_RETURN( |
| 1455 | aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1456 | } |
| 1457 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::FORMAT)) { |
| 1458 | legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
| 1459 | } |
| 1460 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::GAIN)) { |
| 1461 | legacy.gain = VALUE_OR_RETURN( |
| 1462 | aidl2legacy_AudioGainConfig_audio_gain_config(aidl.gain, aidl.role, aidl.type)); |
| 1463 | } |
| 1464 | if (bitmaskIsSet(aidl.configMask, media::AudioPortConfigType::FLAGS)) { |
| 1465 | legacy.flags = VALUE_OR_RETURN( |
| 1466 | aidl2legacy_AudioIoFlags_audio_io_flags(aidl.flags, aidl.role, aidl.type)); |
| 1467 | } |
| 1468 | legacy.ext = VALUE_OR_RETURN(aidl2legacy_AudioPortConfigExt(aidl.ext, aidl.type, aidl.role)); |
| 1469 | return legacy; |
| 1470 | } |
| 1471 | |
| 1472 | ConversionResult<media::AudioPortConfig> legacy2aidl_audio_port_config_AudioPortConfig( |
| 1473 | const audio_port_config& legacy) { |
| 1474 | media::AudioPortConfig aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1475 | 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] | 1476 | aidl.role = VALUE_OR_RETURN(legacy2aidl_audio_port_role_t_AudioPortRole(legacy.role)); |
| 1477 | aidl.type = VALUE_OR_RETURN(legacy2aidl_audio_port_type_t_AudioPortType(legacy.type)); |
| 1478 | aidl.configMask = VALUE_OR_RETURN(legacy2aidl_config_mask_int32_t(legacy.config_mask)); |
| 1479 | if (legacy.config_mask & AUDIO_PORT_CONFIG_SAMPLE_RATE) { |
| 1480 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.sample_rate)); |
| 1481 | } |
| 1482 | if (legacy.config_mask & AUDIO_PORT_CONFIG_CHANNEL_MASK) { |
| 1483 | aidl.channelMask = |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1484 | VALUE_OR_RETURN( |
| 1485 | legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy.channel_mask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1486 | } |
| 1487 | if (legacy.config_mask & AUDIO_PORT_CONFIG_FORMAT) { |
| 1488 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
| 1489 | } |
| 1490 | if (legacy.config_mask & AUDIO_PORT_CONFIG_GAIN) { |
| 1491 | aidl.gain = VALUE_OR_RETURN(legacy2aidl_audio_gain_config_AudioGainConfig( |
| 1492 | legacy.gain, legacy.role, legacy.type)); |
| 1493 | } |
| 1494 | if (legacy.config_mask & AUDIO_PORT_CONFIG_FLAGS) { |
| 1495 | aidl.flags = VALUE_OR_RETURN( |
| 1496 | legacy2aidl_audio_io_flags_AudioIoFlags(legacy.flags, legacy.role, legacy.type)); |
| 1497 | } |
| 1498 | aidl.ext = |
| 1499 | VALUE_OR_RETURN(legacy2aidl_AudioPortConfigExt(legacy.ext, legacy.type, legacy.role)); |
| 1500 | return aidl; |
| 1501 | } |
| 1502 | |
| 1503 | ConversionResult<struct audio_patch> aidl2legacy_AudioPatch_audio_patch( |
| 1504 | const media::AudioPatch& aidl) { |
| 1505 | struct audio_patch legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1506 | 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] | 1507 | legacy.num_sinks = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.sinks.size())); |
| 1508 | if (legacy.num_sinks > AUDIO_PATCH_PORTS_MAX) { |
| 1509 | return unexpected(BAD_VALUE); |
| 1510 | } |
| 1511 | for (size_t i = 0; i < legacy.num_sinks; ++i) { |
| 1512 | legacy.sinks[i] = |
| 1513 | VALUE_OR_RETURN(aidl2legacy_AudioPortConfig_audio_port_config(aidl.sinks[i])); |
| 1514 | } |
| 1515 | legacy.num_sources = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.sources.size())); |
| 1516 | if (legacy.num_sources > AUDIO_PATCH_PORTS_MAX) { |
| 1517 | return unexpected(BAD_VALUE); |
| 1518 | } |
| 1519 | for (size_t i = 0; i < legacy.num_sources; ++i) { |
| 1520 | legacy.sources[i] = |
| 1521 | VALUE_OR_RETURN(aidl2legacy_AudioPortConfig_audio_port_config(aidl.sources[i])); |
| 1522 | } |
| 1523 | return legacy; |
| 1524 | } |
| 1525 | |
| 1526 | ConversionResult<media::AudioPatch> legacy2aidl_audio_patch_AudioPatch( |
| 1527 | const struct audio_patch& legacy) { |
| 1528 | media::AudioPatch aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1529 | 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] | 1530 | |
| 1531 | if (legacy.num_sinks > AUDIO_PATCH_PORTS_MAX) { |
| 1532 | return unexpected(BAD_VALUE); |
| 1533 | } |
| 1534 | for (unsigned int i = 0; i < legacy.num_sinks; ++i) { |
| 1535 | aidl.sinks.push_back( |
| 1536 | VALUE_OR_RETURN(legacy2aidl_audio_port_config_AudioPortConfig(legacy.sinks[i]))); |
| 1537 | } |
| 1538 | if (legacy.num_sources > AUDIO_PATCH_PORTS_MAX) { |
| 1539 | return unexpected(BAD_VALUE); |
| 1540 | } |
| 1541 | for (unsigned int i = 0; i < legacy.num_sources; ++i) { |
| 1542 | aidl.sources.push_back( |
| 1543 | VALUE_OR_RETURN(legacy2aidl_audio_port_config_AudioPortConfig(legacy.sources[i]))); |
| 1544 | } |
| 1545 | return aidl; |
| 1546 | } |
| 1547 | |
| 1548 | ConversionResult<sp<AudioIoDescriptor>> aidl2legacy_AudioIoDescriptor_AudioIoDescriptor( |
| 1549 | const media::AudioIoDescriptor& aidl) { |
| 1550 | sp<AudioIoDescriptor> legacy(new AudioIoDescriptor()); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1551 | legacy->mIoHandle = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.ioHandle)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1552 | legacy->mPatch = VALUE_OR_RETURN(aidl2legacy_AudioPatch_audio_patch(aidl.patch)); |
| 1553 | legacy->mSamplingRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.samplingRate)); |
| 1554 | legacy->mFormat = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
| 1555 | legacy->mChannelMask = |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1556 | VALUE_OR_RETURN(aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1557 | legacy->mFrameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount)); |
| 1558 | legacy->mFrameCountHAL = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCountHAL)); |
| 1559 | legacy->mLatency = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.latency)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1560 | legacy->mPortId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1561 | return legacy; |
| 1562 | } |
| 1563 | |
| 1564 | ConversionResult<media::AudioIoDescriptor> legacy2aidl_AudioIoDescriptor_AudioIoDescriptor( |
| 1565 | const sp<AudioIoDescriptor>& legacy) { |
| 1566 | media::AudioIoDescriptor aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1567 | aidl.ioHandle = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(legacy->mIoHandle)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1568 | aidl.patch = VALUE_OR_RETURN(legacy2aidl_audio_patch_AudioPatch(legacy->mPatch)); |
| 1569 | aidl.samplingRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy->mSamplingRate)); |
| 1570 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy->mFormat)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1571 | aidl.channelMask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1572 | legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy->mChannelMask)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1573 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy->mFrameCount)); |
| 1574 | aidl.frameCountHAL = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy->mFrameCountHAL)); |
| 1575 | aidl.latency = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy->mLatency)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 1576 | aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy->mPortId)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1577 | return aidl; |
| 1578 | } |
| 1579 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1580 | ConversionResult<AudioClient> aidl2legacy_AudioClient_AudioClient( |
| 1581 | const media::AudioClient& aidl) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1582 | AudioClient legacy; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1583 | legacy.clientTid = VALUE_OR_RETURN(aidl2legacy_int32_t_pid_t(aidl.clientTid)); |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1584 | legacy.attributionSource = aidl.attributionSource; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1585 | return legacy; |
| 1586 | } |
| 1587 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 1588 | ConversionResult<media::AudioClient> legacy2aidl_AudioClient_AudioClient( |
| 1589 | const AudioClient& legacy) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1590 | media::AudioClient aidl; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1591 | aidl.clientTid = VALUE_OR_RETURN(legacy2aidl_pid_t_int32_t(legacy.clientTid)); |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1592 | aidl.attributionSource = legacy.attributionSource; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1593 | return aidl; |
| 1594 | } |
| 1595 | |
| 1596 | ConversionResult<audio_content_type_t> |
| 1597 | aidl2legacy_AudioContentType_audio_content_type_t(media::AudioContentType aidl) { |
| 1598 | switch (aidl) { |
| 1599 | case media::AudioContentType::UNKNOWN: |
| 1600 | return AUDIO_CONTENT_TYPE_UNKNOWN; |
| 1601 | case media::AudioContentType::SPEECH: |
| 1602 | return AUDIO_CONTENT_TYPE_SPEECH; |
| 1603 | case media::AudioContentType::MUSIC: |
| 1604 | return AUDIO_CONTENT_TYPE_MUSIC; |
| 1605 | case media::AudioContentType::MOVIE: |
| 1606 | return AUDIO_CONTENT_TYPE_MOVIE; |
| 1607 | case media::AudioContentType::SONIFICATION: |
| 1608 | return AUDIO_CONTENT_TYPE_SONIFICATION; |
| 1609 | } |
| 1610 | return unexpected(BAD_VALUE); |
| 1611 | } |
| 1612 | |
| 1613 | ConversionResult<media::AudioContentType> |
| 1614 | legacy2aidl_audio_content_type_t_AudioContentType(audio_content_type_t legacy) { |
| 1615 | switch (legacy) { |
| 1616 | case AUDIO_CONTENT_TYPE_UNKNOWN: |
| 1617 | return media::AudioContentType::UNKNOWN; |
| 1618 | case AUDIO_CONTENT_TYPE_SPEECH: |
| 1619 | return media::AudioContentType::SPEECH; |
| 1620 | case AUDIO_CONTENT_TYPE_MUSIC: |
| 1621 | return media::AudioContentType::MUSIC; |
| 1622 | case AUDIO_CONTENT_TYPE_MOVIE: |
| 1623 | return media::AudioContentType::MOVIE; |
| 1624 | case AUDIO_CONTENT_TYPE_SONIFICATION: |
| 1625 | return media::AudioContentType::SONIFICATION; |
| 1626 | } |
| 1627 | return unexpected(BAD_VALUE); |
| 1628 | } |
| 1629 | |
| 1630 | ConversionResult<audio_usage_t> |
| 1631 | aidl2legacy_AudioUsage_audio_usage_t(media::AudioUsage aidl) { |
| 1632 | switch (aidl) { |
| 1633 | case media::AudioUsage::UNKNOWN: |
| 1634 | return AUDIO_USAGE_UNKNOWN; |
| 1635 | case media::AudioUsage::MEDIA: |
| 1636 | return AUDIO_USAGE_MEDIA; |
| 1637 | case media::AudioUsage::VOICE_COMMUNICATION: |
| 1638 | return AUDIO_USAGE_VOICE_COMMUNICATION; |
| 1639 | case media::AudioUsage::VOICE_COMMUNICATION_SIGNALLING: |
| 1640 | return AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING; |
| 1641 | case media::AudioUsage::ALARM: |
| 1642 | return AUDIO_USAGE_ALARM; |
| 1643 | case media::AudioUsage::NOTIFICATION: |
| 1644 | return AUDIO_USAGE_NOTIFICATION; |
| 1645 | case media::AudioUsage::NOTIFICATION_TELEPHONY_RINGTONE: |
| 1646 | return AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE; |
| 1647 | case media::AudioUsage::NOTIFICATION_COMMUNICATION_REQUEST: |
| 1648 | return AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST; |
| 1649 | case media::AudioUsage::NOTIFICATION_COMMUNICATION_INSTANT: |
| 1650 | return AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT; |
| 1651 | case media::AudioUsage::NOTIFICATION_COMMUNICATION_DELAYED: |
| 1652 | return AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED; |
| 1653 | case media::AudioUsage::NOTIFICATION_EVENT: |
| 1654 | return AUDIO_USAGE_NOTIFICATION_EVENT; |
| 1655 | case media::AudioUsage::ASSISTANCE_ACCESSIBILITY: |
| 1656 | return AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY; |
| 1657 | case media::AudioUsage::ASSISTANCE_NAVIGATION_GUIDANCE: |
| 1658 | return AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE; |
| 1659 | case media::AudioUsage::ASSISTANCE_SONIFICATION: |
| 1660 | return AUDIO_USAGE_ASSISTANCE_SONIFICATION; |
| 1661 | case media::AudioUsage::GAME: |
| 1662 | return AUDIO_USAGE_GAME; |
| 1663 | case media::AudioUsage::VIRTUAL_SOURCE: |
| 1664 | return AUDIO_USAGE_VIRTUAL_SOURCE; |
| 1665 | case media::AudioUsage::ASSISTANT: |
| 1666 | return AUDIO_USAGE_ASSISTANT; |
| 1667 | case media::AudioUsage::CALL_ASSISTANT: |
| 1668 | return AUDIO_USAGE_CALL_ASSISTANT; |
| 1669 | case media::AudioUsage::EMERGENCY: |
| 1670 | return AUDIO_USAGE_EMERGENCY; |
| 1671 | case media::AudioUsage::SAFETY: |
| 1672 | return AUDIO_USAGE_SAFETY; |
| 1673 | case media::AudioUsage::VEHICLE_STATUS: |
| 1674 | return AUDIO_USAGE_VEHICLE_STATUS; |
| 1675 | case media::AudioUsage::ANNOUNCEMENT: |
| 1676 | return AUDIO_USAGE_ANNOUNCEMENT; |
| 1677 | } |
| 1678 | return unexpected(BAD_VALUE); |
| 1679 | } |
| 1680 | |
| 1681 | ConversionResult<media::AudioUsage> |
| 1682 | legacy2aidl_audio_usage_t_AudioUsage(audio_usage_t legacy) { |
| 1683 | switch (legacy) { |
| 1684 | case AUDIO_USAGE_UNKNOWN: |
| 1685 | return media::AudioUsage::UNKNOWN; |
| 1686 | case AUDIO_USAGE_MEDIA: |
| 1687 | return media::AudioUsage::MEDIA; |
| 1688 | case AUDIO_USAGE_VOICE_COMMUNICATION: |
| 1689 | return media::AudioUsage::VOICE_COMMUNICATION; |
| 1690 | case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING: |
| 1691 | return media::AudioUsage::VOICE_COMMUNICATION_SIGNALLING; |
| 1692 | case AUDIO_USAGE_ALARM: |
| 1693 | return media::AudioUsage::ALARM; |
| 1694 | case AUDIO_USAGE_NOTIFICATION: |
| 1695 | return media::AudioUsage::NOTIFICATION; |
| 1696 | case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE: |
| 1697 | return media::AudioUsage::NOTIFICATION_TELEPHONY_RINGTONE; |
| 1698 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST: |
| 1699 | return media::AudioUsage::NOTIFICATION_COMMUNICATION_REQUEST; |
| 1700 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT: |
| 1701 | return media::AudioUsage::NOTIFICATION_COMMUNICATION_INSTANT; |
| 1702 | case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED: |
| 1703 | return media::AudioUsage::NOTIFICATION_COMMUNICATION_DELAYED; |
| 1704 | case AUDIO_USAGE_NOTIFICATION_EVENT: |
| 1705 | return media::AudioUsage::NOTIFICATION_EVENT; |
| 1706 | case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY: |
| 1707 | return media::AudioUsage::ASSISTANCE_ACCESSIBILITY; |
| 1708 | case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE: |
| 1709 | return media::AudioUsage::ASSISTANCE_NAVIGATION_GUIDANCE; |
| 1710 | case AUDIO_USAGE_ASSISTANCE_SONIFICATION: |
| 1711 | return media::AudioUsage::ASSISTANCE_SONIFICATION; |
| 1712 | case AUDIO_USAGE_GAME: |
| 1713 | return media::AudioUsage::GAME; |
| 1714 | case AUDIO_USAGE_VIRTUAL_SOURCE: |
| 1715 | return media::AudioUsage::VIRTUAL_SOURCE; |
| 1716 | case AUDIO_USAGE_ASSISTANT: |
| 1717 | return media::AudioUsage::ASSISTANT; |
| 1718 | case AUDIO_USAGE_CALL_ASSISTANT: |
| 1719 | return media::AudioUsage::CALL_ASSISTANT; |
| 1720 | case AUDIO_USAGE_EMERGENCY: |
| 1721 | return media::AudioUsage::EMERGENCY; |
| 1722 | case AUDIO_USAGE_SAFETY: |
| 1723 | return media::AudioUsage::SAFETY; |
| 1724 | case AUDIO_USAGE_VEHICLE_STATUS: |
| 1725 | return media::AudioUsage::VEHICLE_STATUS; |
| 1726 | case AUDIO_USAGE_ANNOUNCEMENT: |
| 1727 | return media::AudioUsage::ANNOUNCEMENT; |
| 1728 | } |
| 1729 | return unexpected(BAD_VALUE); |
| 1730 | } |
| 1731 | |
| 1732 | ConversionResult<audio_flags_mask_t> |
| 1733 | aidl2legacy_AudioFlag_audio_flags_mask_t(media::AudioFlag aidl) { |
| 1734 | switch (aidl) { |
| 1735 | case media::AudioFlag::AUDIBILITY_ENFORCED: |
| 1736 | return AUDIO_FLAG_AUDIBILITY_ENFORCED; |
| 1737 | case media::AudioFlag::SECURE: |
| 1738 | return AUDIO_FLAG_SECURE; |
| 1739 | case media::AudioFlag::SCO: |
| 1740 | return AUDIO_FLAG_SCO; |
| 1741 | case media::AudioFlag::BEACON: |
| 1742 | return AUDIO_FLAG_BEACON; |
| 1743 | case media::AudioFlag::HW_AV_SYNC: |
| 1744 | return AUDIO_FLAG_HW_AV_SYNC; |
| 1745 | case media::AudioFlag::HW_HOTWORD: |
| 1746 | return AUDIO_FLAG_HW_HOTWORD; |
| 1747 | case media::AudioFlag::BYPASS_INTERRUPTION_POLICY: |
| 1748 | return AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY; |
| 1749 | case media::AudioFlag::BYPASS_MUTE: |
| 1750 | return AUDIO_FLAG_BYPASS_MUTE; |
| 1751 | case media::AudioFlag::LOW_LATENCY: |
| 1752 | return AUDIO_FLAG_LOW_LATENCY; |
| 1753 | case media::AudioFlag::DEEP_BUFFER: |
| 1754 | return AUDIO_FLAG_DEEP_BUFFER; |
| 1755 | case media::AudioFlag::NO_MEDIA_PROJECTION: |
| 1756 | return AUDIO_FLAG_NO_MEDIA_PROJECTION; |
| 1757 | case media::AudioFlag::MUTE_HAPTIC: |
| 1758 | return AUDIO_FLAG_MUTE_HAPTIC; |
| 1759 | case media::AudioFlag::NO_SYSTEM_CAPTURE: |
| 1760 | return AUDIO_FLAG_NO_SYSTEM_CAPTURE; |
| 1761 | case media::AudioFlag::CAPTURE_PRIVATE: |
| 1762 | return AUDIO_FLAG_CAPTURE_PRIVATE; |
| 1763 | } |
| 1764 | return unexpected(BAD_VALUE); |
| 1765 | } |
| 1766 | |
| 1767 | ConversionResult<media::AudioFlag> |
| 1768 | legacy2aidl_audio_flags_mask_t_AudioFlag(audio_flags_mask_t legacy) { |
| 1769 | switch (legacy) { |
| 1770 | case AUDIO_FLAG_NONE: |
| 1771 | return unexpected(BAD_VALUE); |
| 1772 | case AUDIO_FLAG_AUDIBILITY_ENFORCED: |
| 1773 | return media::AudioFlag::AUDIBILITY_ENFORCED; |
| 1774 | case AUDIO_FLAG_SECURE: |
| 1775 | return media::AudioFlag::SECURE; |
| 1776 | case AUDIO_FLAG_SCO: |
| 1777 | return media::AudioFlag::SCO; |
| 1778 | case AUDIO_FLAG_BEACON: |
| 1779 | return media::AudioFlag::BEACON; |
| 1780 | case AUDIO_FLAG_HW_AV_SYNC: |
| 1781 | return media::AudioFlag::HW_AV_SYNC; |
| 1782 | case AUDIO_FLAG_HW_HOTWORD: |
| 1783 | return media::AudioFlag::HW_HOTWORD; |
| 1784 | case AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY: |
| 1785 | return media::AudioFlag::BYPASS_INTERRUPTION_POLICY; |
| 1786 | case AUDIO_FLAG_BYPASS_MUTE: |
| 1787 | return media::AudioFlag::BYPASS_MUTE; |
| 1788 | case AUDIO_FLAG_LOW_LATENCY: |
| 1789 | return media::AudioFlag::LOW_LATENCY; |
| 1790 | case AUDIO_FLAG_DEEP_BUFFER: |
| 1791 | return media::AudioFlag::DEEP_BUFFER; |
| 1792 | case AUDIO_FLAG_NO_MEDIA_PROJECTION: |
| 1793 | return media::AudioFlag::NO_MEDIA_PROJECTION; |
| 1794 | case AUDIO_FLAG_MUTE_HAPTIC: |
| 1795 | return media::AudioFlag::MUTE_HAPTIC; |
| 1796 | case AUDIO_FLAG_NO_SYSTEM_CAPTURE: |
| 1797 | return media::AudioFlag::NO_SYSTEM_CAPTURE; |
| 1798 | case AUDIO_FLAG_CAPTURE_PRIVATE: |
| 1799 | return media::AudioFlag::CAPTURE_PRIVATE; |
| 1800 | } |
| 1801 | return unexpected(BAD_VALUE); |
| 1802 | } |
| 1803 | |
| 1804 | ConversionResult<audio_flags_mask_t> |
| 1805 | aidl2legacy_int32_t_audio_flags_mask_t_mask(int32_t aidl) { |
| 1806 | 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] | 1807 | aidl, aidl2legacy_AudioFlag_audio_flags_mask_t, indexToEnum_index<media::AudioFlag>, |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1808 | enumToMask_bitmask<audio_flags_mask_t, audio_flags_mask_t>); |
| 1809 | } |
| 1810 | |
| 1811 | ConversionResult<int32_t> |
| 1812 | legacy2aidl_audio_flags_mask_t_int32_t_mask(audio_flags_mask_t legacy) { |
| 1813 | 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] | 1814 | legacy, legacy2aidl_audio_flags_mask_t_AudioFlag, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 1815 | indexToEnum_bitmask<audio_flags_mask_t>, |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1816 | enumToMask_index<int32_t, media::AudioFlag>); |
| 1817 | } |
| 1818 | |
| 1819 | ConversionResult<audio_attributes_t> |
| 1820 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(const media::AudioAttributesInternal& aidl) { |
| 1821 | audio_attributes_t legacy; |
| 1822 | legacy.content_type = VALUE_OR_RETURN( |
| 1823 | aidl2legacy_AudioContentType_audio_content_type_t(aidl.contentType)); |
| 1824 | legacy.usage = VALUE_OR_RETURN(aidl2legacy_AudioUsage_audio_usage_t(aidl.usage)); |
| 1825 | legacy.source = VALUE_OR_RETURN(aidl2legacy_AudioSourceType_audio_source_t(aidl.source)); |
| 1826 | legacy.flags = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_flags_mask_t_mask(aidl.flags)); |
| 1827 | RETURN_IF_ERROR(aidl2legacy_string(aidl.tags, legacy.tags, sizeof(legacy.tags))); |
| 1828 | return legacy; |
| 1829 | } |
| 1830 | |
| 1831 | ConversionResult<media::AudioAttributesInternal> |
| 1832 | legacy2aidl_audio_attributes_t_AudioAttributesInternal(const audio_attributes_t& legacy) { |
| 1833 | media::AudioAttributesInternal aidl; |
| 1834 | aidl.contentType = VALUE_OR_RETURN( |
| 1835 | legacy2aidl_audio_content_type_t_AudioContentType(legacy.content_type)); |
| 1836 | aidl.usage = VALUE_OR_RETURN(legacy2aidl_audio_usage_t_AudioUsage(legacy.usage)); |
| 1837 | aidl.source = VALUE_OR_RETURN(legacy2aidl_audio_source_t_AudioSourceType(legacy.source)); |
| 1838 | aidl.flags = VALUE_OR_RETURN(legacy2aidl_audio_flags_mask_t_int32_t_mask(legacy.flags)); |
| 1839 | aidl.tags = VALUE_OR_RETURN(legacy2aidl_string(legacy.tags, sizeof(legacy.tags))); |
| 1840 | return aidl; |
| 1841 | } |
| 1842 | |
| 1843 | ConversionResult<audio_encapsulation_mode_t> |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 1844 | aidl2legacy_AudioEncapsulationMode_audio_encapsulation_mode_t(media::AudioEncapsulationMode aidl) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1845 | switch (aidl) { |
| 1846 | case media::AudioEncapsulationMode::NONE: |
| 1847 | return AUDIO_ENCAPSULATION_MODE_NONE; |
| 1848 | case media::AudioEncapsulationMode::ELEMENTARY_STREAM: |
| 1849 | return AUDIO_ENCAPSULATION_MODE_ELEMENTARY_STREAM; |
| 1850 | case media::AudioEncapsulationMode::HANDLE: |
| 1851 | return AUDIO_ENCAPSULATION_MODE_HANDLE; |
| 1852 | } |
| 1853 | return unexpected(BAD_VALUE); |
| 1854 | } |
| 1855 | |
| 1856 | ConversionResult<media::AudioEncapsulationMode> |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 1857 | legacy2aidl_audio_encapsulation_mode_t_AudioEncapsulationMode(audio_encapsulation_mode_t legacy) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1858 | switch (legacy) { |
| 1859 | case AUDIO_ENCAPSULATION_MODE_NONE: |
| 1860 | return media::AudioEncapsulationMode::NONE; |
| 1861 | case AUDIO_ENCAPSULATION_MODE_ELEMENTARY_STREAM: |
| 1862 | return media::AudioEncapsulationMode::ELEMENTARY_STREAM; |
| 1863 | case AUDIO_ENCAPSULATION_MODE_HANDLE: |
| 1864 | return media::AudioEncapsulationMode::HANDLE; |
| 1865 | } |
| 1866 | return unexpected(BAD_VALUE); |
| 1867 | } |
| 1868 | |
| 1869 | ConversionResult<audio_offload_info_t> |
| 1870 | aidl2legacy_AudioOffloadInfo_audio_offload_info_t(const media::AudioOffloadInfo& aidl) { |
| 1871 | audio_offload_info_t legacy; |
| 1872 | legacy.version = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.version)); |
| 1873 | legacy.size = sizeof(audio_offload_info_t); |
| 1874 | audio_config_base_t config = VALUE_OR_RETURN( |
| 1875 | aidl2legacy_AudioConfigBase_audio_config_base_t(aidl.config)); |
| 1876 | legacy.sample_rate = config.sample_rate; |
| 1877 | legacy.channel_mask = config.channel_mask; |
| 1878 | legacy.format = config.format; |
| 1879 | legacy.stream_type = VALUE_OR_RETURN( |
| 1880 | aidl2legacy_AudioStreamType_audio_stream_type_t(aidl.streamType)); |
| 1881 | legacy.bit_rate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.bitRate)); |
| 1882 | legacy.duration_us = VALUE_OR_RETURN(convertIntegral<int64_t>(aidl.durationUs)); |
| 1883 | legacy.has_video = aidl.hasVideo; |
| 1884 | legacy.is_streaming = aidl.isStreaming; |
| 1885 | legacy.bit_width = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.bitWidth)); |
| 1886 | legacy.offload_buffer_size = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.offloadBufferSize)); |
| 1887 | legacy.usage = VALUE_OR_RETURN(aidl2legacy_AudioUsage_audio_usage_t(aidl.usage)); |
| 1888 | legacy.encapsulation_mode = VALUE_OR_RETURN( |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 1889 | aidl2legacy_AudioEncapsulationMode_audio_encapsulation_mode_t(aidl.encapsulationMode)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1890 | legacy.content_id = VALUE_OR_RETURN(convertReinterpret<int32_t>(aidl.contentId)); |
| 1891 | legacy.sync_id = VALUE_OR_RETURN(convertReinterpret<int32_t>(aidl.syncId)); |
| 1892 | return legacy; |
| 1893 | } |
| 1894 | |
| 1895 | ConversionResult<media::AudioOffloadInfo> |
| 1896 | legacy2aidl_audio_offload_info_t_AudioOffloadInfo(const audio_offload_info_t& legacy) { |
| 1897 | media::AudioOffloadInfo aidl; |
| 1898 | // Version 0.1 fields. |
| 1899 | if (legacy.size < offsetof(audio_offload_info_t, usage) + sizeof(audio_offload_info_t::usage)) { |
| 1900 | return unexpected(BAD_VALUE); |
| 1901 | } |
| 1902 | aidl.version = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.version)); |
| 1903 | aidl.config.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.sample_rate)); |
| 1904 | aidl.config.channelMask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1905 | legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy.channel_mask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1906 | aidl.config.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
| 1907 | aidl.streamType = VALUE_OR_RETURN( |
| 1908 | legacy2aidl_audio_stream_type_t_AudioStreamType(legacy.stream_type)); |
| 1909 | aidl.bitRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.bit_rate)); |
| 1910 | aidl.durationUs = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy.duration_us)); |
| 1911 | aidl.hasVideo = legacy.has_video; |
| 1912 | aidl.isStreaming = legacy.is_streaming; |
| 1913 | aidl.bitWidth = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.bit_width)); |
| 1914 | aidl.offloadBufferSize = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.offload_buffer_size)); |
| 1915 | aidl.usage = VALUE_OR_RETURN(legacy2aidl_audio_usage_t_AudioUsage(legacy.usage)); |
| 1916 | |
| 1917 | // Version 0.2 fields. |
| 1918 | if (legacy.version >= AUDIO_OFFLOAD_INFO_VERSION_0_2) { |
| 1919 | if (legacy.size < |
| 1920 | offsetof(audio_offload_info_t, sync_id) + sizeof(audio_offload_info_t::sync_id)) { |
| 1921 | return unexpected(BAD_VALUE); |
| 1922 | } |
| 1923 | aidl.encapsulationMode = VALUE_OR_RETURN( |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 1924 | legacy2aidl_audio_encapsulation_mode_t_AudioEncapsulationMode( |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1925 | legacy.encapsulation_mode)); |
| 1926 | aidl.contentId = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.content_id)); |
| 1927 | aidl.syncId = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.sync_id)); |
| 1928 | } |
| 1929 | return aidl; |
| 1930 | } |
| 1931 | |
| 1932 | ConversionResult<audio_config_t> |
| 1933 | aidl2legacy_AudioConfig_audio_config_t(const media::AudioConfig& aidl) { |
| 1934 | audio_config_t legacy; |
| 1935 | legacy.sample_rate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1936 | legacy.channel_mask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1937 | aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1938 | legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1939 | legacy.offload_info = VALUE_OR_RETURN( |
| 1940 | aidl2legacy_AudioOffloadInfo_audio_offload_info_t(aidl.offloadInfo)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1941 | legacy.frame_count = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.frameCount)); |
| 1942 | return legacy; |
| 1943 | } |
| 1944 | |
| 1945 | ConversionResult<media::AudioConfig> |
| 1946 | legacy2aidl_audio_config_t_AudioConfig(const audio_config_t& legacy) { |
| 1947 | media::AudioConfig aidl; |
| 1948 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.sample_rate)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1949 | aidl.channelMask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1950 | legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy.channel_mask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1951 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1952 | aidl.offloadInfo = VALUE_OR_RETURN( |
| 1953 | legacy2aidl_audio_offload_info_t_AudioOffloadInfo(legacy.offload_info)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1954 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy.frame_count)); |
| 1955 | return aidl; |
| 1956 | } |
| 1957 | |
| 1958 | ConversionResult<audio_config_base_t> |
| 1959 | aidl2legacy_AudioConfigBase_audio_config_base_t(const media::AudioConfigBase& aidl) { |
| 1960 | audio_config_base_t legacy; |
| 1961 | legacy.sample_rate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1962 | legacy.channel_mask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1963 | aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1964 | legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
| 1965 | return legacy; |
| 1966 | } |
| 1967 | |
| 1968 | ConversionResult<media::AudioConfigBase> |
| 1969 | legacy2aidl_audio_config_base_t_AudioConfigBase(const audio_config_base_t& legacy) { |
| 1970 | media::AudioConfigBase aidl; |
| 1971 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.sample_rate)); |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 1972 | aidl.channelMask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 1973 | legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy.channel_mask)); |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 1974 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
| 1975 | return aidl; |
| 1976 | } |
| 1977 | |
| 1978 | ConversionResult<sp<IMemory>> |
| 1979 | aidl2legacy_SharedFileRegion_IMemory(const media::SharedFileRegion& aidl) { |
| 1980 | sp<IMemory> legacy; |
| 1981 | if (!convertSharedFileRegionToIMemory(aidl, &legacy)) { |
| 1982 | return unexpected(BAD_VALUE); |
| 1983 | } |
| 1984 | return legacy; |
| 1985 | } |
| 1986 | |
| 1987 | ConversionResult<media::SharedFileRegion> |
| 1988 | legacy2aidl_IMemory_SharedFileRegion(const sp<IMemory>& legacy) { |
| 1989 | media::SharedFileRegion aidl; |
| 1990 | if (!convertIMemoryToSharedFileRegion(legacy, &aidl)) { |
| 1991 | return unexpected(BAD_VALUE); |
| 1992 | } |
| 1993 | return aidl; |
| 1994 | } |
| 1995 | |
| 1996 | ConversionResult<sp<IMemory>> |
| 1997 | aidl2legacy_NullableSharedFileRegion_IMemory(const std::optional<media::SharedFileRegion>& aidl) { |
| 1998 | sp<IMemory> legacy; |
| 1999 | if (!convertNullableSharedFileRegionToIMemory(aidl, &legacy)) { |
| 2000 | return unexpected(BAD_VALUE); |
| 2001 | } |
| 2002 | return legacy; |
| 2003 | } |
| 2004 | |
| 2005 | ConversionResult<std::optional<media::SharedFileRegion>> |
| 2006 | legacy2aidl_NullableIMemory_SharedFileRegion(const sp<IMemory>& legacy) { |
| 2007 | std::optional<media::SharedFileRegion> aidl; |
| 2008 | if (!convertNullableIMemoryToSharedFileRegion(legacy, &aidl)) { |
| 2009 | return unexpected(BAD_VALUE); |
| 2010 | } |
| 2011 | return aidl; |
| 2012 | } |
| 2013 | |
Ytai Ben-Tsvi | bdc293a | 2020-11-02 17:01:38 -0800 | [diff] [blame] | 2014 | ConversionResult<AudioTimestamp> |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 2015 | aidl2legacy_AudioTimestampInternal_AudioTimestamp(const media::AudioTimestampInternal& aidl) { |
Ytai Ben-Tsvi | bdc293a | 2020-11-02 17:01:38 -0800 | [diff] [blame] | 2016 | AudioTimestamp legacy; |
| 2017 | legacy.mPosition = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.position)); |
| 2018 | legacy.mTime.tv_sec = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sec)); |
| 2019 | legacy.mTime.tv_nsec = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.nsec)); |
| 2020 | return legacy; |
| 2021 | } |
| 2022 | |
| 2023 | ConversionResult<media::AudioTimestampInternal> |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 2024 | legacy2aidl_AudioTimestamp_AudioTimestampInternal(const AudioTimestamp& legacy) { |
Ytai Ben-Tsvi | bdc293a | 2020-11-02 17:01:38 -0800 | [diff] [blame] | 2025 | media::AudioTimestampInternal aidl; |
| 2026 | aidl.position = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.mPosition)); |
| 2027 | aidl.sec = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy.mTime.tv_sec)); |
| 2028 | aidl.nsec = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.mTime.tv_nsec)); |
| 2029 | return aidl; |
| 2030 | } |
| 2031 | |
Ytai Ben-Tsvi | ce18294 | 2020-11-04 14:48:01 -0800 | [diff] [blame] | 2032 | ConversionResult<audio_uuid_t> |
| 2033 | aidl2legacy_AudioUuid_audio_uuid_t(const media::AudioUuid& aidl) { |
| 2034 | audio_uuid_t legacy; |
| 2035 | legacy.timeLow = VALUE_OR_RETURN(convertReinterpret<uint32_t>(aidl.timeLow)); |
| 2036 | legacy.timeMid = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.timeMid)); |
| 2037 | legacy.timeHiAndVersion = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.timeHiAndVersion)); |
| 2038 | legacy.clockSeq = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.clockSeq)); |
| 2039 | if (aidl.node.size() != std::size(legacy.node)) { |
| 2040 | return unexpected(BAD_VALUE); |
| 2041 | } |
| 2042 | std::copy(aidl.node.begin(), aidl.node.end(), legacy.node); |
| 2043 | return legacy; |
| 2044 | } |
| 2045 | |
| 2046 | ConversionResult<media::AudioUuid> |
| 2047 | legacy2aidl_audio_uuid_t_AudioUuid(const audio_uuid_t& legacy) { |
| 2048 | media::AudioUuid aidl; |
| 2049 | aidl.timeLow = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.timeLow)); |
| 2050 | aidl.timeMid = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.timeMid)); |
| 2051 | aidl.timeHiAndVersion = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.timeHiAndVersion)); |
| 2052 | aidl.clockSeq = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.clockSeq)); |
| 2053 | std::copy(legacy.node, legacy.node + std::size(legacy.node), std::back_inserter(aidl.node)); |
| 2054 | return aidl; |
| 2055 | } |
| 2056 | |
| 2057 | ConversionResult<effect_descriptor_t> |
| 2058 | aidl2legacy_EffectDescriptor_effect_descriptor_t(const media::EffectDescriptor& aidl) { |
| 2059 | effect_descriptor_t legacy; |
| 2060 | legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioUuid_audio_uuid_t(aidl.type)); |
| 2061 | legacy.uuid = VALUE_OR_RETURN(aidl2legacy_AudioUuid_audio_uuid_t(aidl.uuid)); |
| 2062 | legacy.apiVersion = VALUE_OR_RETURN(convertReinterpret<uint32_t>(aidl.apiVersion)); |
| 2063 | legacy.flags = VALUE_OR_RETURN(convertReinterpret<uint32_t>(aidl.flags)); |
| 2064 | legacy.cpuLoad = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.cpuLoad)); |
| 2065 | legacy.memoryUsage = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.memoryUsage)); |
| 2066 | RETURN_IF_ERROR(aidl2legacy_string(aidl.name, legacy.name, sizeof(legacy.name))); |
| 2067 | RETURN_IF_ERROR( |
| 2068 | aidl2legacy_string(aidl.implementor, legacy.implementor, sizeof(legacy.implementor))); |
| 2069 | return legacy; |
| 2070 | } |
| 2071 | |
| 2072 | ConversionResult<media::EffectDescriptor> |
| 2073 | legacy2aidl_effect_descriptor_t_EffectDescriptor(const effect_descriptor_t& legacy) { |
| 2074 | media::EffectDescriptor aidl; |
| 2075 | aidl.type = VALUE_OR_RETURN(legacy2aidl_audio_uuid_t_AudioUuid(legacy.type)); |
| 2076 | aidl.uuid = VALUE_OR_RETURN(legacy2aidl_audio_uuid_t_AudioUuid(legacy.uuid)); |
| 2077 | aidl.apiVersion = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.apiVersion)); |
| 2078 | aidl.flags = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.flags)); |
| 2079 | aidl.cpuLoad = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.cpuLoad)); |
| 2080 | aidl.memoryUsage = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.memoryUsage)); |
| 2081 | aidl.name = VALUE_OR_RETURN(legacy2aidl_string(legacy.name, sizeof(legacy.name))); |
| 2082 | aidl.implementor = VALUE_OR_RETURN( |
| 2083 | legacy2aidl_string(legacy.implementor, sizeof(legacy.implementor))); |
| 2084 | return aidl; |
| 2085 | } |
| 2086 | |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2087 | ConversionResult<audio_encapsulation_metadata_type_t> |
| 2088 | aidl2legacy_AudioEncapsulationMetadataType_audio_encapsulation_metadata_type_t( |
| 2089 | media::AudioEncapsulationMetadataType aidl) { |
| 2090 | switch (aidl) { |
| 2091 | case media::AudioEncapsulationMetadataType::NONE: |
| 2092 | return AUDIO_ENCAPSULATION_METADATA_TYPE_NONE; |
| 2093 | case media::AudioEncapsulationMetadataType::FRAMEWORK_TUNER: |
| 2094 | return AUDIO_ENCAPSULATION_METADATA_TYPE_FRAMEWORK_TUNER; |
| 2095 | case media::AudioEncapsulationMetadataType::DVB_AD_DESCRIPTOR: |
| 2096 | return AUDIO_ENCAPSULATION_METADATA_TYPE_DVB_AD_DESCRIPTOR; |
| 2097 | } |
| 2098 | return unexpected(BAD_VALUE); |
| 2099 | } |
| 2100 | |
| 2101 | ConversionResult<media::AudioEncapsulationMetadataType> |
| 2102 | legacy2aidl_audio_encapsulation_metadata_type_t_AudioEncapsulationMetadataType( |
| 2103 | audio_encapsulation_metadata_type_t legacy) { |
| 2104 | switch (legacy) { |
| 2105 | case AUDIO_ENCAPSULATION_METADATA_TYPE_NONE: |
| 2106 | return media::AudioEncapsulationMetadataType::NONE; |
| 2107 | case AUDIO_ENCAPSULATION_METADATA_TYPE_FRAMEWORK_TUNER: |
| 2108 | return media::AudioEncapsulationMetadataType::FRAMEWORK_TUNER; |
| 2109 | case AUDIO_ENCAPSULATION_METADATA_TYPE_DVB_AD_DESCRIPTOR: |
| 2110 | return media::AudioEncapsulationMetadataType::DVB_AD_DESCRIPTOR; |
| 2111 | } |
| 2112 | return unexpected(BAD_VALUE); |
| 2113 | } |
| 2114 | |
| 2115 | ConversionResult<uint32_t> |
| 2116 | aidl2legacy_AudioEncapsulationMode_mask(int32_t aidl) { |
| 2117 | return convertBitmask<uint32_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2118 | int32_t, |
| 2119 | audio_encapsulation_mode_t, |
| 2120 | media::AudioEncapsulationMode>( |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2121 | aidl, aidl2legacy_AudioEncapsulationMode_audio_encapsulation_mode_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2122 | indexToEnum_index<media::AudioEncapsulationMode>, |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2123 | enumToMask_index<uint32_t, audio_encapsulation_mode_t>); |
| 2124 | } |
| 2125 | |
| 2126 | ConversionResult<int32_t> |
| 2127 | legacy2aidl_AudioEncapsulationMode_mask(uint32_t legacy) { |
| 2128 | return convertBitmask<int32_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2129 | uint32_t, |
| 2130 | media::AudioEncapsulationMode, |
| 2131 | audio_encapsulation_mode_t>( |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2132 | legacy, legacy2aidl_audio_encapsulation_mode_t_AudioEncapsulationMode, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2133 | indexToEnum_index<audio_encapsulation_mode_t>, |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2134 | enumToMask_index<int32_t, media::AudioEncapsulationMode>); |
| 2135 | } |
| 2136 | |
| 2137 | ConversionResult<uint32_t> |
| 2138 | aidl2legacy_AudioEncapsulationMetadataType_mask(int32_t aidl) { |
| 2139 | return convertBitmask<uint32_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2140 | int32_t, |
| 2141 | audio_encapsulation_metadata_type_t, |
| 2142 | media::AudioEncapsulationMetadataType>( |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2143 | aidl, aidl2legacy_AudioEncapsulationMetadataType_audio_encapsulation_metadata_type_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2144 | indexToEnum_index<media::AudioEncapsulationMetadataType>, |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2145 | enumToMask_index<uint32_t, audio_encapsulation_metadata_type_t>); |
| 2146 | } |
| 2147 | |
| 2148 | ConversionResult<int32_t> |
| 2149 | legacy2aidl_AudioEncapsulationMetadataType_mask(uint32_t legacy) { |
| 2150 | return convertBitmask<int32_t, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2151 | uint32_t, |
| 2152 | media::AudioEncapsulationMetadataType, |
| 2153 | audio_encapsulation_metadata_type_t>( |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2154 | legacy, legacy2aidl_audio_encapsulation_metadata_type_t_AudioEncapsulationMetadataType, |
Ytai Ben-Tsvi | 08c7d9e | 2020-12-16 14:32:56 -0800 | [diff] [blame] | 2155 | indexToEnum_index<audio_encapsulation_metadata_type_t>, |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 2156 | enumToMask_index<int32_t, media::AudioEncapsulationMetadataType>); |
| 2157 | } |
| 2158 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2159 | ConversionResult<audio_mix_latency_class_t> |
| 2160 | aidl2legacy_AudioMixLatencyClass_audio_mix_latency_class_t( |
| 2161 | media::AudioMixLatencyClass aidl) { |
| 2162 | switch (aidl) { |
| 2163 | case media::AudioMixLatencyClass::LOW: |
| 2164 | return AUDIO_LATENCY_LOW; |
| 2165 | case media::AudioMixLatencyClass::NORMAL: |
| 2166 | return AUDIO_LATENCY_NORMAL; |
| 2167 | } |
| 2168 | return unexpected(BAD_VALUE); |
| 2169 | } |
| 2170 | |
| 2171 | ConversionResult<media::AudioMixLatencyClass> |
| 2172 | legacy2aidl_audio_mix_latency_class_t_AudioMixLatencyClass( |
| 2173 | audio_mix_latency_class_t legacy) { |
| 2174 | switch (legacy) { |
| 2175 | case AUDIO_LATENCY_LOW: |
| 2176 | return media::AudioMixLatencyClass::LOW; |
| 2177 | case AUDIO_LATENCY_NORMAL: |
| 2178 | return media::AudioMixLatencyClass::NORMAL; |
| 2179 | } |
| 2180 | return unexpected(BAD_VALUE); |
| 2181 | } |
| 2182 | |
| 2183 | ConversionResult<audio_port_device_ext> |
| 2184 | aidl2legacy_AudioPortDeviceExt_audio_port_device_ext(const media::AudioPortDeviceExt& aidl) { |
| 2185 | audio_port_device_ext legacy; |
| 2186 | legacy.hw_module = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_module_handle_t(aidl.hwModule)); |
| 2187 | legacy.type = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_devices_t(aidl.device.type)); |
| 2188 | RETURN_IF_ERROR( |
| 2189 | aidl2legacy_string(aidl.device.address, legacy.address, sizeof(legacy.address))); |
| 2190 | legacy.encapsulation_modes = VALUE_OR_RETURN( |
| 2191 | aidl2legacy_AudioEncapsulationMode_mask(aidl.encapsulationModes)); |
| 2192 | legacy.encapsulation_metadata_types = VALUE_OR_RETURN( |
| 2193 | aidl2legacy_AudioEncapsulationMetadataType_mask(aidl.encapsulationMetadataTypes)); |
| 2194 | return legacy; |
| 2195 | } |
| 2196 | |
| 2197 | ConversionResult<media::AudioPortDeviceExt> |
| 2198 | legacy2aidl_audio_port_device_ext_AudioPortDeviceExt(const audio_port_device_ext& legacy) { |
| 2199 | media::AudioPortDeviceExt aidl; |
| 2200 | aidl.hwModule = VALUE_OR_RETURN(legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
| 2201 | aidl.device.type = VALUE_OR_RETURN(legacy2aidl_audio_devices_t_int32_t(legacy.type)); |
| 2202 | aidl.device.address = VALUE_OR_RETURN( |
| 2203 | legacy2aidl_string(legacy.address, sizeof(legacy.address))); |
| 2204 | aidl.encapsulationModes = VALUE_OR_RETURN( |
| 2205 | legacy2aidl_AudioEncapsulationMode_mask(legacy.encapsulation_modes)); |
| 2206 | aidl.encapsulationMetadataTypes = VALUE_OR_RETURN( |
| 2207 | legacy2aidl_AudioEncapsulationMetadataType_mask(legacy.encapsulation_metadata_types)); |
| 2208 | return aidl; |
| 2209 | } |
| 2210 | |
| 2211 | ConversionResult<audio_port_mix_ext> |
| 2212 | aidl2legacy_AudioPortMixExt_audio_port_mix_ext(const media::AudioPortMixExt& aidl) { |
| 2213 | audio_port_mix_ext legacy; |
| 2214 | legacy.hw_module = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_module_handle_t(aidl.hwModule)); |
| 2215 | legacy.handle = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.handle)); |
| 2216 | legacy.latency_class = VALUE_OR_RETURN( |
| 2217 | aidl2legacy_AudioMixLatencyClass_audio_mix_latency_class_t(aidl.latencyClass)); |
| 2218 | return legacy; |
| 2219 | } |
| 2220 | |
| 2221 | ConversionResult<media::AudioPortMixExt> |
| 2222 | legacy2aidl_audio_port_mix_ext_AudioPortMixExt(const audio_port_mix_ext& legacy) { |
| 2223 | media::AudioPortMixExt aidl; |
| 2224 | aidl.hwModule = VALUE_OR_RETURN(legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
| 2225 | aidl.handle = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(legacy.handle)); |
| 2226 | aidl.latencyClass = VALUE_OR_RETURN( |
| 2227 | legacy2aidl_audio_mix_latency_class_t_AudioMixLatencyClass(legacy.latency_class)); |
| 2228 | return aidl; |
| 2229 | } |
| 2230 | |
| 2231 | ConversionResult<audio_port_session_ext> |
| 2232 | aidl2legacy_AudioPortSessionExt_audio_port_session_ext(const media::AudioPortSessionExt& aidl) { |
| 2233 | audio_port_session_ext legacy; |
| 2234 | legacy.session = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.session)); |
| 2235 | return legacy; |
| 2236 | } |
| 2237 | |
| 2238 | ConversionResult<media::AudioPortSessionExt> |
| 2239 | legacy2aidl_audio_port_session_ext_AudioPortSessionExt(const audio_port_session_ext& legacy) { |
| 2240 | media::AudioPortSessionExt aidl; |
| 2241 | aidl.session = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(legacy.session)); |
| 2242 | return aidl; |
| 2243 | } |
| 2244 | |
| 2245 | // This type is unnamed in the original definition, thus we name it here. |
| 2246 | using audio_port_v7_ext = decltype(audio_port_v7::ext); |
| 2247 | |
| 2248 | ConversionResult<audio_port_v7_ext> aidl2legacy_AudioPortExt( |
| 2249 | const media::AudioPortExt& aidl, media::AudioPortType type) { |
| 2250 | audio_port_v7_ext legacy; |
| 2251 | switch (type) { |
| 2252 | case media::AudioPortType::NONE: |
| 2253 | // Just verify that the union is empty. |
| 2254 | VALUE_OR_RETURN(UNION_GET(aidl, unspecified)); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2255 | return legacy; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2256 | case media::AudioPortType::DEVICE: |
| 2257 | legacy.device = VALUE_OR_RETURN( |
| 2258 | aidl2legacy_AudioPortDeviceExt_audio_port_device_ext( |
| 2259 | VALUE_OR_RETURN(UNION_GET(aidl, device)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2260 | return legacy; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2261 | case media::AudioPortType::MIX: |
| 2262 | legacy.mix = VALUE_OR_RETURN( |
| 2263 | aidl2legacy_AudioPortMixExt_audio_port_mix_ext( |
| 2264 | VALUE_OR_RETURN(UNION_GET(aidl, mix)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2265 | return legacy; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2266 | case media::AudioPortType::SESSION: |
| 2267 | legacy.session = VALUE_OR_RETURN(aidl2legacy_AudioPortSessionExt_audio_port_session_ext( |
| 2268 | VALUE_OR_RETURN(UNION_GET(aidl, session)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2269 | return legacy; |
| 2270 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2271 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2272 | 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] | 2273 | } |
| 2274 | |
| 2275 | ConversionResult<media::AudioPortExt> legacy2aidl_AudioPortExt( |
| 2276 | const audio_port_v7_ext& legacy, audio_port_type_t type) { |
| 2277 | media::AudioPortExt aidl; |
| 2278 | switch (type) { |
| 2279 | case AUDIO_PORT_TYPE_NONE: |
| 2280 | UNION_SET(aidl, unspecified, false); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2281 | return aidl; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2282 | case AUDIO_PORT_TYPE_DEVICE: |
| 2283 | UNION_SET(aidl, device, |
| 2284 | VALUE_OR_RETURN( |
| 2285 | legacy2aidl_audio_port_device_ext_AudioPortDeviceExt(legacy.device))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2286 | return aidl; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2287 | case AUDIO_PORT_TYPE_MIX: |
| 2288 | UNION_SET(aidl, mix, |
| 2289 | VALUE_OR_RETURN(legacy2aidl_audio_port_mix_ext_AudioPortMixExt(legacy.mix))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2290 | return aidl; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2291 | case AUDIO_PORT_TYPE_SESSION: |
| 2292 | UNION_SET(aidl, session, |
| 2293 | VALUE_OR_RETURN(legacy2aidl_audio_port_session_ext_AudioPortSessionExt( |
| 2294 | legacy.session))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2295 | return aidl; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2296 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 2297 | 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] | 2298 | } |
| 2299 | |
| 2300 | ConversionResult<audio_profile> |
| 2301 | aidl2legacy_AudioProfile_audio_profile(const media::AudioProfile& aidl) { |
| 2302 | audio_profile legacy; |
| 2303 | legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormat_audio_format_t(aidl.format)); |
| 2304 | |
| 2305 | if (aidl.samplingRates.size() > std::size(legacy.sample_rates)) { |
| 2306 | return unexpected(BAD_VALUE); |
| 2307 | } |
| 2308 | RETURN_IF_ERROR( |
| 2309 | convertRange(aidl.samplingRates.begin(), aidl.samplingRates.end(), legacy.sample_rates, |
| 2310 | convertIntegral<int32_t, unsigned int>)); |
| 2311 | legacy.num_sample_rates = aidl.samplingRates.size(); |
| 2312 | |
| 2313 | if (aidl.channelMasks.size() > std::size(legacy.channel_masks)) { |
| 2314 | return unexpected(BAD_VALUE); |
| 2315 | } |
| 2316 | RETURN_IF_ERROR( |
| 2317 | convertRange(aidl.channelMasks.begin(), aidl.channelMasks.end(), legacy.channel_masks, |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2318 | aidl2legacy_AudioChannelMask_audio_channel_mask_t)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2319 | legacy.num_channel_masks = aidl.channelMasks.size(); |
jiabin | 82e5693 | 2021-03-05 06:35:19 +0000 | [diff] [blame] | 2320 | |
| 2321 | legacy.encapsulation_type = VALUE_OR_RETURN( |
| 2322 | aidl2legacy_AudioEncapsulationType_audio_encapsulation_type_t(aidl.encapsulationType)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2323 | return legacy; |
| 2324 | } |
| 2325 | |
| 2326 | ConversionResult<media::AudioProfile> |
| 2327 | legacy2aidl_audio_profile_AudioProfile(const audio_profile& legacy) { |
| 2328 | media::AudioProfile aidl; |
| 2329 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormat(legacy.format)); |
| 2330 | |
| 2331 | if (legacy.num_sample_rates > std::size(legacy.sample_rates)) { |
| 2332 | return unexpected(BAD_VALUE); |
| 2333 | } |
| 2334 | RETURN_IF_ERROR( |
| 2335 | convertRange(legacy.sample_rates, legacy.sample_rates + legacy.num_sample_rates, |
| 2336 | std::back_inserter(aidl.samplingRates), |
| 2337 | convertIntegral<unsigned int, int32_t>)); |
| 2338 | |
| 2339 | if (legacy.num_channel_masks > std::size(legacy.channel_masks)) { |
| 2340 | return unexpected(BAD_VALUE); |
| 2341 | } |
| 2342 | RETURN_IF_ERROR( |
| 2343 | convertRange(legacy.channel_masks, legacy.channel_masks + legacy.num_channel_masks, |
| 2344 | std::back_inserter(aidl.channelMasks), |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2345 | legacy2aidl_audio_channel_mask_t_AudioChannelMask)); |
jiabin | 82e5693 | 2021-03-05 06:35:19 +0000 | [diff] [blame] | 2346 | |
| 2347 | aidl.encapsulationType = VALUE_OR_RETURN( |
| 2348 | legacy2aidl_audio_encapsulation_type_t_AudioEncapsulationType( |
| 2349 | legacy.encapsulation_type)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2350 | return aidl; |
| 2351 | } |
| 2352 | |
| 2353 | ConversionResult<audio_gain> |
| 2354 | aidl2legacy_AudioGain_audio_gain(const media::AudioGain& aidl) { |
| 2355 | audio_gain legacy; |
| 2356 | legacy.mode = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_gain_mode_t_mask(aidl.mode)); |
| 2357 | legacy.channel_mask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2358 | aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2359 | legacy.min_value = VALUE_OR_RETURN(convertIntegral<int>(aidl.minValue)); |
| 2360 | legacy.max_value = VALUE_OR_RETURN(convertIntegral<int>(aidl.maxValue)); |
| 2361 | legacy.default_value = VALUE_OR_RETURN(convertIntegral<int>(aidl.defaultValue)); |
| 2362 | legacy.step_value = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.stepValue)); |
| 2363 | legacy.min_ramp_ms = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.minRampMs)); |
| 2364 | legacy.max_ramp_ms = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.maxRampMs)); |
| 2365 | return legacy; |
| 2366 | } |
| 2367 | |
| 2368 | ConversionResult<media::AudioGain> |
| 2369 | legacy2aidl_audio_gain_AudioGain(const audio_gain& legacy) { |
| 2370 | media::AudioGain aidl; |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 2371 | aidl.mode = VALUE_OR_RETURN(legacy2aidl_audio_gain_mode_t_int32_t_mask(legacy.mode)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2372 | aidl.channelMask = VALUE_OR_RETURN( |
Mikhail Naganov | 2d8df4e | 2021-06-03 13:59:13 -0700 | [diff] [blame] | 2373 | legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy.channel_mask)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2374 | aidl.minValue = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.min_value)); |
| 2375 | aidl.maxValue = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.max_value)); |
| 2376 | aidl.defaultValue = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.default_value)); |
| 2377 | aidl.stepValue = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.step_value)); |
| 2378 | aidl.minRampMs = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.min_ramp_ms)); |
| 2379 | aidl.maxRampMs = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.max_ramp_ms)); |
| 2380 | return aidl; |
| 2381 | } |
| 2382 | |
| 2383 | ConversionResult<audio_port_v7> |
| 2384 | aidl2legacy_AudioPort_audio_port_v7(const media::AudioPort& aidl) { |
| 2385 | audio_port_v7 legacy; |
| 2386 | legacy.id = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.id)); |
| 2387 | legacy.role = VALUE_OR_RETURN(aidl2legacy_AudioPortRole_audio_port_role_t(aidl.role)); |
| 2388 | legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioPortType_audio_port_type_t(aidl.type)); |
| 2389 | RETURN_IF_ERROR(aidl2legacy_string(aidl.name, legacy.name, sizeof(legacy.name))); |
| 2390 | |
| 2391 | if (aidl.profiles.size() > std::size(legacy.audio_profiles)) { |
| 2392 | return unexpected(BAD_VALUE); |
| 2393 | } |
| 2394 | RETURN_IF_ERROR(convertRange(aidl.profiles.begin(), aidl.profiles.end(), legacy.audio_profiles, |
| 2395 | aidl2legacy_AudioProfile_audio_profile)); |
| 2396 | legacy.num_audio_profiles = aidl.profiles.size(); |
| 2397 | |
jiabin | 82e5693 | 2021-03-05 06:35:19 +0000 | [diff] [blame] | 2398 | if (aidl.extraAudioDescriptors.size() > std::size(legacy.extra_audio_descriptors)) { |
| 2399 | return unexpected(BAD_VALUE); |
| 2400 | } |
| 2401 | RETURN_IF_ERROR( |
| 2402 | convertRange(aidl.extraAudioDescriptors.begin(), aidl.extraAudioDescriptors.end(), |
| 2403 | legacy.extra_audio_descriptors, |
| 2404 | aidl2legacy_ExtraAudioDescriptor_audio_extra_audio_descriptor)); |
| 2405 | legacy.num_extra_audio_descriptors = aidl.extraAudioDescriptors.size(); |
| 2406 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2407 | if (aidl.gains.size() > std::size(legacy.gains)) { |
| 2408 | return unexpected(BAD_VALUE); |
| 2409 | } |
| 2410 | RETURN_IF_ERROR(convertRange(aidl.gains.begin(), aidl.gains.end(), legacy.gains, |
| 2411 | aidl2legacy_AudioGain_audio_gain)); |
| 2412 | legacy.num_gains = aidl.gains.size(); |
| 2413 | |
| 2414 | legacy.active_config = VALUE_OR_RETURN( |
| 2415 | aidl2legacy_AudioPortConfig_audio_port_config(aidl.activeConfig)); |
| 2416 | legacy.ext = VALUE_OR_RETURN(aidl2legacy_AudioPortExt(aidl.ext, aidl.type)); |
| 2417 | return legacy; |
| 2418 | } |
| 2419 | |
| 2420 | ConversionResult<media::AudioPort> |
| 2421 | legacy2aidl_audio_port_v7_AudioPort(const audio_port_v7& legacy) { |
| 2422 | media::AudioPort aidl; |
| 2423 | aidl.id = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy.id)); |
| 2424 | aidl.role = VALUE_OR_RETURN(legacy2aidl_audio_port_role_t_AudioPortRole(legacy.role)); |
| 2425 | aidl.type = VALUE_OR_RETURN(legacy2aidl_audio_port_type_t_AudioPortType(legacy.type)); |
| 2426 | aidl.name = VALUE_OR_RETURN(legacy2aidl_string(legacy.name, sizeof(legacy.name))); |
| 2427 | |
| 2428 | if (legacy.num_audio_profiles > std::size(legacy.audio_profiles)) { |
| 2429 | return unexpected(BAD_VALUE); |
| 2430 | } |
| 2431 | RETURN_IF_ERROR( |
| 2432 | convertRange(legacy.audio_profiles, legacy.audio_profiles + legacy.num_audio_profiles, |
| 2433 | std::back_inserter(aidl.profiles), |
| 2434 | legacy2aidl_audio_profile_AudioProfile)); |
| 2435 | |
jiabin | 82e5693 | 2021-03-05 06:35:19 +0000 | [diff] [blame] | 2436 | if (legacy.num_extra_audio_descriptors > std::size(legacy.extra_audio_descriptors)) { |
| 2437 | return unexpected(BAD_VALUE); |
| 2438 | } |
| 2439 | RETURN_IF_ERROR( |
| 2440 | convertRange(legacy.extra_audio_descriptors, |
| 2441 | legacy.extra_audio_descriptors + legacy.num_extra_audio_descriptors, |
| 2442 | std::back_inserter(aidl.extraAudioDescriptors), |
| 2443 | legacy2aidl_audio_extra_audio_descriptor_ExtraAudioDescriptor)); |
| 2444 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 2445 | if (legacy.num_gains > std::size(legacy.gains)) { |
| 2446 | return unexpected(BAD_VALUE); |
| 2447 | } |
| 2448 | RETURN_IF_ERROR( |
| 2449 | convertRange(legacy.gains, legacy.gains + legacy.num_gains, |
| 2450 | std::back_inserter(aidl.gains), |
| 2451 | legacy2aidl_audio_gain_AudioGain)); |
| 2452 | |
| 2453 | aidl.activeConfig = VALUE_OR_RETURN( |
| 2454 | legacy2aidl_audio_port_config_AudioPortConfig(legacy.active_config)); |
| 2455 | aidl.ext = VALUE_OR_RETURN(legacy2aidl_AudioPortExt(legacy.ext, legacy.type)); |
| 2456 | return aidl; |
| 2457 | } |
| 2458 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 2459 | ConversionResult<audio_mode_t> |
| 2460 | aidl2legacy_AudioMode_audio_mode_t(media::AudioMode aidl) { |
| 2461 | switch (aidl) { |
| 2462 | case media::AudioMode::INVALID: |
| 2463 | return AUDIO_MODE_INVALID; |
| 2464 | case media::AudioMode::CURRENT: |
| 2465 | return AUDIO_MODE_CURRENT; |
| 2466 | case media::AudioMode::NORMAL: |
| 2467 | return AUDIO_MODE_NORMAL; |
| 2468 | case media::AudioMode::RINGTONE: |
| 2469 | return AUDIO_MODE_RINGTONE; |
| 2470 | case media::AudioMode::IN_CALL: |
| 2471 | return AUDIO_MODE_IN_CALL; |
| 2472 | case media::AudioMode::IN_COMMUNICATION: |
| 2473 | return AUDIO_MODE_IN_COMMUNICATION; |
| 2474 | case media::AudioMode::CALL_SCREEN: |
| 2475 | return AUDIO_MODE_CALL_SCREEN; |
| 2476 | } |
| 2477 | return unexpected(BAD_VALUE); |
| 2478 | } |
| 2479 | |
| 2480 | ConversionResult<media::AudioMode> |
| 2481 | legacy2aidl_audio_mode_t_AudioMode(audio_mode_t legacy) { |
| 2482 | switch (legacy) { |
| 2483 | case AUDIO_MODE_INVALID: |
| 2484 | return media::AudioMode::INVALID; |
| 2485 | case AUDIO_MODE_CURRENT: |
| 2486 | return media::AudioMode::CURRENT; |
| 2487 | case AUDIO_MODE_NORMAL: |
| 2488 | return media::AudioMode::NORMAL; |
| 2489 | case AUDIO_MODE_RINGTONE: |
| 2490 | return media::AudioMode::RINGTONE; |
| 2491 | case AUDIO_MODE_IN_CALL: |
| 2492 | return media::AudioMode::IN_CALL; |
| 2493 | case AUDIO_MODE_IN_COMMUNICATION: |
| 2494 | return media::AudioMode::IN_COMMUNICATION; |
| 2495 | case AUDIO_MODE_CALL_SCREEN: |
| 2496 | return media::AudioMode::CALL_SCREEN; |
| 2497 | case AUDIO_MODE_CNT: |
| 2498 | break; |
| 2499 | } |
| 2500 | return unexpected(BAD_VALUE); |
| 2501 | } |
| 2502 | |
| 2503 | ConversionResult<audio_unique_id_use_t> |
| 2504 | aidl2legacy_AudioUniqueIdUse_audio_unique_id_use_t(media::AudioUniqueIdUse aidl) { |
| 2505 | switch (aidl) { |
| 2506 | case media::AudioUniqueIdUse::UNSPECIFIED: |
| 2507 | return AUDIO_UNIQUE_ID_USE_UNSPECIFIED; |
| 2508 | case media::AudioUniqueIdUse::SESSION: |
| 2509 | return AUDIO_UNIQUE_ID_USE_SESSION; |
| 2510 | case media::AudioUniqueIdUse::MODULE: |
| 2511 | return AUDIO_UNIQUE_ID_USE_MODULE; |
| 2512 | case media::AudioUniqueIdUse::EFFECT: |
| 2513 | return AUDIO_UNIQUE_ID_USE_EFFECT; |
| 2514 | case media::AudioUniqueIdUse::PATCH: |
| 2515 | return AUDIO_UNIQUE_ID_USE_PATCH; |
| 2516 | case media::AudioUniqueIdUse::OUTPUT: |
| 2517 | return AUDIO_UNIQUE_ID_USE_OUTPUT; |
| 2518 | case media::AudioUniqueIdUse::INPUT: |
| 2519 | return AUDIO_UNIQUE_ID_USE_INPUT; |
| 2520 | case media::AudioUniqueIdUse::CLIENT: |
| 2521 | return AUDIO_UNIQUE_ID_USE_CLIENT; |
| 2522 | } |
| 2523 | return unexpected(BAD_VALUE); |
| 2524 | } |
| 2525 | |
| 2526 | ConversionResult<media::AudioUniqueIdUse> |
| 2527 | legacy2aidl_audio_unique_id_use_t_AudioUniqueIdUse(audio_unique_id_use_t legacy) { |
| 2528 | switch (legacy) { |
| 2529 | case AUDIO_UNIQUE_ID_USE_UNSPECIFIED: |
| 2530 | return media::AudioUniqueIdUse::UNSPECIFIED; |
| 2531 | case AUDIO_UNIQUE_ID_USE_SESSION: |
| 2532 | return media::AudioUniqueIdUse::SESSION; |
| 2533 | case AUDIO_UNIQUE_ID_USE_MODULE: |
| 2534 | return media::AudioUniqueIdUse::MODULE; |
| 2535 | case AUDIO_UNIQUE_ID_USE_EFFECT: |
| 2536 | return media::AudioUniqueIdUse::EFFECT; |
| 2537 | case AUDIO_UNIQUE_ID_USE_PATCH: |
| 2538 | return media::AudioUniqueIdUse::PATCH; |
| 2539 | case AUDIO_UNIQUE_ID_USE_OUTPUT: |
| 2540 | return media::AudioUniqueIdUse::OUTPUT; |
| 2541 | case AUDIO_UNIQUE_ID_USE_INPUT: |
| 2542 | return media::AudioUniqueIdUse::INPUT; |
| 2543 | case AUDIO_UNIQUE_ID_USE_CLIENT: |
| 2544 | return media::AudioUniqueIdUse::CLIENT; |
| 2545 | case AUDIO_UNIQUE_ID_USE_MAX: |
| 2546 | break; |
| 2547 | } |
| 2548 | return unexpected(BAD_VALUE); |
| 2549 | } |
| 2550 | |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2551 | ConversionResult<volume_group_t> |
| 2552 | aidl2legacy_int32_t_volume_group_t(int32_t aidl) { |
| 2553 | return convertReinterpret<volume_group_t>(aidl); |
| 2554 | } |
| 2555 | |
| 2556 | ConversionResult<int32_t> |
| 2557 | legacy2aidl_volume_group_t_int32_t(volume_group_t legacy) { |
| 2558 | return convertReinterpret<int32_t>(legacy); |
| 2559 | } |
| 2560 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2561 | ConversionResult<product_strategy_t> |
| 2562 | aidl2legacy_int32_t_product_strategy_t(int32_t aidl) { |
| 2563 | return convertReinterpret<product_strategy_t>(aidl); |
| 2564 | } |
| 2565 | |
| 2566 | ConversionResult<int32_t> |
| 2567 | legacy2aidl_product_strategy_t_int32_t(product_strategy_t legacy) { |
| 2568 | return convertReinterpret<int32_t>(legacy); |
| 2569 | } |
| 2570 | |
Kuowei Li | d4adbdb | 2020-08-13 14:44:25 +0800 | [diff] [blame] | 2571 | ConversionResult<audio_dual_mono_mode_t> |
| 2572 | aidl2legacy_AudioDualMonoMode_audio_dual_mono_mode_t(media::AudioDualMonoMode aidl) { |
| 2573 | switch (aidl) { |
| 2574 | case media::AudioDualMonoMode::OFF: |
| 2575 | return AUDIO_DUAL_MONO_MODE_OFF; |
| 2576 | case media::AudioDualMonoMode::LR: |
| 2577 | return AUDIO_DUAL_MONO_MODE_LR; |
| 2578 | case media::AudioDualMonoMode::LL: |
| 2579 | return AUDIO_DUAL_MONO_MODE_LL; |
| 2580 | case media::AudioDualMonoMode::RR: |
| 2581 | return AUDIO_DUAL_MONO_MODE_RR; |
| 2582 | } |
| 2583 | return unexpected(BAD_VALUE); |
| 2584 | } |
| 2585 | |
| 2586 | ConversionResult<media::AudioDualMonoMode> |
| 2587 | legacy2aidl_audio_dual_mono_mode_t_AudioDualMonoMode(audio_dual_mono_mode_t legacy) { |
| 2588 | switch (legacy) { |
| 2589 | case AUDIO_DUAL_MONO_MODE_OFF: |
| 2590 | return media::AudioDualMonoMode::OFF; |
| 2591 | case AUDIO_DUAL_MONO_MODE_LR: |
| 2592 | return media::AudioDualMonoMode::LR; |
| 2593 | case AUDIO_DUAL_MONO_MODE_LL: |
| 2594 | return media::AudioDualMonoMode::LL; |
| 2595 | case AUDIO_DUAL_MONO_MODE_RR: |
| 2596 | return media::AudioDualMonoMode::RR; |
| 2597 | } |
| 2598 | return unexpected(BAD_VALUE); |
| 2599 | } |
| 2600 | |
| 2601 | ConversionResult<audio_timestretch_fallback_mode_t> |
| 2602 | aidl2legacy_int32_t_audio_timestretch_fallback_mode_t(int32_t aidl) { |
| 2603 | return convertReinterpret<audio_timestretch_fallback_mode_t>(aidl); |
| 2604 | } |
| 2605 | |
| 2606 | ConversionResult<int32_t> |
| 2607 | legacy2aidl_audio_timestretch_fallback_mode_t_int32_t(audio_timestretch_fallback_mode_t legacy) { |
| 2608 | return convertReinterpret<int32_t>(legacy); |
| 2609 | } |
| 2610 | |
| 2611 | ConversionResult<audio_timestretch_stretch_mode_t> |
| 2612 | aidl2legacy_int32_t_audio_timestretch_stretch_mode_t(int32_t aidl) { |
| 2613 | return convertReinterpret<audio_timestretch_stretch_mode_t>(aidl); |
| 2614 | } |
| 2615 | |
| 2616 | ConversionResult<int32_t> |
| 2617 | legacy2aidl_audio_timestretch_stretch_mode_t_int32_t(audio_timestretch_stretch_mode_t legacy) { |
| 2618 | return convertReinterpret<int32_t>(legacy); |
| 2619 | } |
| 2620 | |
| 2621 | ConversionResult<audio_playback_rate_t> |
| 2622 | aidl2legacy_AudioPlaybackRate_audio_playback_rate_t(const media::AudioPlaybackRate& aidl) { |
| 2623 | audio_playback_rate_t legacy; |
| 2624 | legacy.mSpeed = aidl.speed; |
| 2625 | legacy.mPitch = aidl.pitch; |
| 2626 | legacy.mFallbackMode = VALUE_OR_RETURN( |
| 2627 | aidl2legacy_int32_t_audio_timestretch_fallback_mode_t(aidl.fallbackMode)); |
| 2628 | legacy.mStretchMode = VALUE_OR_RETURN( |
| 2629 | aidl2legacy_int32_t_audio_timestretch_stretch_mode_t(aidl.stretchMode)); |
| 2630 | return legacy; |
| 2631 | } |
| 2632 | |
| 2633 | ConversionResult<media::AudioPlaybackRate> |
| 2634 | legacy2aidl_audio_playback_rate_t_AudioPlaybackRate(const audio_playback_rate_t& legacy) { |
| 2635 | media::AudioPlaybackRate aidl; |
| 2636 | aidl.speed = legacy.mSpeed; |
| 2637 | aidl.pitch = legacy.mPitch; |
| 2638 | aidl.fallbackMode = VALUE_OR_RETURN( |
| 2639 | legacy2aidl_audio_timestretch_fallback_mode_t_int32_t(legacy.mFallbackMode)); |
| 2640 | aidl.stretchMode = VALUE_OR_RETURN( |
| 2641 | legacy2aidl_audio_timestretch_stretch_mode_t_int32_t(legacy.mStretchMode)); |
| 2642 | return aidl; |
| 2643 | } |
| 2644 | |
jiabin | 82e5693 | 2021-03-05 06:35:19 +0000 | [diff] [blame] | 2645 | ConversionResult<audio_standard_t> |
| 2646 | aidl2legacy_AudioStandard_audio_standard_t(media::AudioStandard aidl) { |
| 2647 | switch (aidl) { |
| 2648 | case media::AudioStandard::NONE: |
| 2649 | return AUDIO_STANDARD_NONE; |
| 2650 | case media::AudioStandard::EDID: |
| 2651 | return AUDIO_STANDARD_EDID; |
| 2652 | } |
| 2653 | return unexpected(BAD_VALUE); |
| 2654 | } |
| 2655 | |
| 2656 | ConversionResult<media::AudioStandard> |
| 2657 | legacy2aidl_audio_standard_t_AudioStandard(audio_standard_t legacy) { |
| 2658 | switch (legacy) { |
| 2659 | case AUDIO_STANDARD_NONE: |
| 2660 | return media::AudioStandard::NONE; |
| 2661 | case AUDIO_STANDARD_EDID: |
| 2662 | return media::AudioStandard::EDID; |
| 2663 | } |
| 2664 | return unexpected(BAD_VALUE); |
| 2665 | } |
| 2666 | |
| 2667 | ConversionResult<audio_extra_audio_descriptor> |
| 2668 | aidl2legacy_ExtraAudioDescriptor_audio_extra_audio_descriptor( |
| 2669 | const media::ExtraAudioDescriptor& aidl) { |
| 2670 | audio_extra_audio_descriptor legacy; |
| 2671 | legacy.standard = VALUE_OR_RETURN(aidl2legacy_AudioStandard_audio_standard_t(aidl.standard)); |
| 2672 | if (aidl.audioDescriptor.size() > EXTRA_AUDIO_DESCRIPTOR_SIZE) { |
| 2673 | return unexpected(BAD_VALUE); |
| 2674 | } |
| 2675 | legacy.descriptor_length = aidl.audioDescriptor.size(); |
| 2676 | std::copy(aidl.audioDescriptor.begin(), aidl.audioDescriptor.end(), |
| 2677 | std::begin(legacy.descriptor)); |
| 2678 | legacy.encapsulation_type = |
| 2679 | VALUE_OR_RETURN(aidl2legacy_AudioEncapsulationType_audio_encapsulation_type_t( |
| 2680 | aidl.encapsulationType)); |
| 2681 | return legacy; |
| 2682 | } |
| 2683 | |
| 2684 | ConversionResult<media::ExtraAudioDescriptor> |
| 2685 | legacy2aidl_audio_extra_audio_descriptor_ExtraAudioDescriptor( |
| 2686 | const audio_extra_audio_descriptor& legacy) { |
| 2687 | media::ExtraAudioDescriptor aidl; |
| 2688 | aidl.standard = VALUE_OR_RETURN(legacy2aidl_audio_standard_t_AudioStandard(legacy.standard)); |
| 2689 | if (legacy.descriptor_length > EXTRA_AUDIO_DESCRIPTOR_SIZE) { |
| 2690 | return unexpected(BAD_VALUE); |
| 2691 | } |
| 2692 | aidl.audioDescriptor.resize(legacy.descriptor_length); |
| 2693 | std::copy(legacy.descriptor, legacy.descriptor + legacy.descriptor_length, |
| 2694 | aidl.audioDescriptor.begin()); |
| 2695 | aidl.encapsulationType = |
| 2696 | VALUE_OR_RETURN(legacy2aidl_audio_encapsulation_type_t_AudioEncapsulationType( |
| 2697 | legacy.encapsulation_type)); |
| 2698 | return aidl; |
| 2699 | } |
| 2700 | |
| 2701 | ConversionResult<audio_encapsulation_type_t> |
| 2702 | aidl2legacy_AudioEncapsulationType_audio_encapsulation_type_t( |
| 2703 | const media::AudioEncapsulationType& aidl) { |
| 2704 | switch (aidl) { |
| 2705 | case media::AudioEncapsulationType::NONE: |
| 2706 | return AUDIO_ENCAPSULATION_TYPE_NONE; |
| 2707 | case media::AudioEncapsulationType::IEC61937: |
| 2708 | return AUDIO_ENCAPSULATION_TYPE_IEC61937; |
| 2709 | } |
| 2710 | return unexpected(BAD_VALUE); |
| 2711 | } |
| 2712 | |
| 2713 | ConversionResult<media::AudioEncapsulationType> |
| 2714 | legacy2aidl_audio_encapsulation_type_t_AudioEncapsulationType( |
| 2715 | const audio_encapsulation_type_t & legacy) { |
| 2716 | switch (legacy) { |
| 2717 | case AUDIO_ENCAPSULATION_TYPE_NONE: |
| 2718 | return media::AudioEncapsulationType::NONE; |
| 2719 | case AUDIO_ENCAPSULATION_TYPE_IEC61937: |
| 2720 | return media::AudioEncapsulationType::IEC61937; |
| 2721 | } |
| 2722 | return unexpected(BAD_VALUE); |
| 2723 | } |
| 2724 | |
jiabin | 10a03f1 | 2021-05-07 23:46:28 +0000 | [diff] [blame] | 2725 | ConversionResult<TrackSecondaryOutputInfoPair> |
| 2726 | aidl2legacy_TrackSecondaryOutputInfo_TrackSecondaryOutputInfoPair( |
| 2727 | const media::TrackSecondaryOutputInfo& aidl) { |
| 2728 | TrackSecondaryOutputInfoPair trackSecondaryOutputInfoPair; |
| 2729 | trackSecondaryOutputInfoPair.first = |
| 2730 | VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
| 2731 | trackSecondaryOutputInfoPair.second = |
| 2732 | VALUE_OR_RETURN(convertContainer<std::vector<audio_port_handle_t>>( |
| 2733 | aidl.secondaryOutputIds, aidl2legacy_int32_t_audio_io_handle_t)); |
| 2734 | return trackSecondaryOutputInfoPair; |
| 2735 | } |
| 2736 | |
| 2737 | ConversionResult<media::TrackSecondaryOutputInfo> |
| 2738 | legacy2aidl_TrackSecondaryOutputInfoPair_TrackSecondaryOutputInfo( |
| 2739 | const TrackSecondaryOutputInfoPair& legacy) { |
| 2740 | media::TrackSecondaryOutputInfo trackSecondaryOutputInfo; |
| 2741 | trackSecondaryOutputInfo.portId = |
| 2742 | VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy.first)); |
| 2743 | trackSecondaryOutputInfo.secondaryOutputIds = |
| 2744 | VALUE_OR_RETURN(convertContainer<std::vector<int32_t>>( |
| 2745 | legacy.second, legacy2aidl_audio_io_handle_t_int32_t)); |
| 2746 | return trackSecondaryOutputInfo; |
| 2747 | } |
| 2748 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 2749 | } // namespace android |