Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Mikhail Naganov | e128b8e | 2021-06-04 17:31:03 -0700 | [diff] [blame] | 17 | #include <algorithm> |
| 18 | #include <unordered_map> |
| 19 | #include <utility> |
| 20 | #include <vector> |
| 21 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 22 | #define LOG_TAG "AidlConversion" |
| 23 | //#define LOG_NDEBUG 0 |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 24 | #include <utils/Log.h> |
| 25 | |
| 26 | #include "media/AidlConversion.h" |
| 27 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 28 | #include <media/ShmemCompat.h> |
Mikhail Naganov | e128b8e | 2021-06-04 17:31:03 -0700 | [diff] [blame] | 29 | #include <media/stagefright/foundation/MediaDefs.h> |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 30 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 31 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 32 | // Utilities |
| 33 | |
| 34 | namespace android { |
| 35 | |
| 36 | using base::unexpected; |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 37 | using media::audio::common::AudioChannelLayout; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 38 | using media::audio::common::AudioConfig; |
| 39 | using media::audio::common::AudioConfigBase; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 40 | using media::audio::common::AudioContentType; |
Mikhail Naganov | 932cb96 | 2021-09-16 01:05:27 +0000 | [diff] [blame] | 41 | using media::audio::common::AudioDevice; |
| 42 | using media::audio::common::AudioDeviceAddress; |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 43 | using media::audio::common::AudioDeviceDescription; |
| 44 | using media::audio::common::AudioDeviceType; |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 45 | using media::audio::common::AudioFormatDescription; |
| 46 | using media::audio::common::AudioFormatType; |
Mikhail Naganov | 7d0b36b | 2021-09-22 23:58:41 +0000 | [diff] [blame] | 47 | using media::audio::common::AudioGain; |
| 48 | using media::audio::common::AudioGainConfig; |
| 49 | using media::audio::common::AudioGainMode; |
Mikhail Naganov | 1050612 | 2021-10-19 10:14:23 -0700 | [diff] [blame] | 50 | using media::audio::common::AudioInputFlags; |
| 51 | using media::audio::common::AudioIoFlags; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 52 | using media::audio::common::AudioMode; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 53 | using media::audio::common::AudioOffloadInfo; |
Mikhail Naganov | 1050612 | 2021-10-19 10:14:23 -0700 | [diff] [blame] | 54 | using media::audio::common::AudioOutputFlags; |
| 55 | using media::audio::common::AudioPortDeviceExt; |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 56 | using media::audio::common::AudioPortExt; |
| 57 | using media::audio::common::AudioPortMixExt; |
| 58 | using media::audio::common::AudioPortMixExtUseCase; |
Mikhail Naganov | 89818ba | 2021-09-21 20:37:13 +0000 | [diff] [blame] | 59 | using media::audio::common::AudioProfile; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 60 | using media::audio::common::AudioSource; |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 61 | using media::audio::common::AudioStandard; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 62 | using media::audio::common::AudioStreamType; |
| 63 | using media::audio::common::AudioUsage; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 64 | using media::audio::common::AudioUuid; |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 65 | using media::audio::common::ExtraAudioDescriptor; |
| 66 | using media::audio::common::Int; |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 67 | using media::audio::common::PcmType; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 68 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 69 | ConversionResult<audio_port_role_t> aidl2legacy_AudioPortRole_audio_port_role_t( |
| 70 | media::AudioPortRole aidl) { |
| 71 | switch (aidl) { |
| 72 | case media::AudioPortRole::NONE: |
| 73 | return AUDIO_PORT_ROLE_NONE; |
| 74 | case media::AudioPortRole::SOURCE: |
| 75 | return AUDIO_PORT_ROLE_SOURCE; |
| 76 | case media::AudioPortRole::SINK: |
| 77 | return AUDIO_PORT_ROLE_SINK; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 78 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 79 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | ConversionResult<media::AudioPortRole> legacy2aidl_audio_port_role_t_AudioPortRole( |
| 83 | audio_port_role_t legacy) { |
| 84 | switch (legacy) { |
| 85 | case AUDIO_PORT_ROLE_NONE: |
| 86 | return media::AudioPortRole::NONE; |
| 87 | case AUDIO_PORT_ROLE_SOURCE: |
| 88 | return media::AudioPortRole::SOURCE; |
| 89 | case AUDIO_PORT_ROLE_SINK: |
| 90 | return media::AudioPortRole::SINK; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 91 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 92 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | ConversionResult<audio_port_type_t> aidl2legacy_AudioPortType_audio_port_type_t( |
| 96 | media::AudioPortType aidl) { |
| 97 | switch (aidl) { |
| 98 | case media::AudioPortType::NONE: |
| 99 | return AUDIO_PORT_TYPE_NONE; |
| 100 | case media::AudioPortType::DEVICE: |
| 101 | return AUDIO_PORT_TYPE_DEVICE; |
| 102 | case media::AudioPortType::MIX: |
| 103 | return AUDIO_PORT_TYPE_MIX; |
| 104 | case media::AudioPortType::SESSION: |
| 105 | return AUDIO_PORT_TYPE_SESSION; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 106 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 107 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | ConversionResult<media::AudioPortType> legacy2aidl_audio_port_type_t_AudioPortType( |
| 111 | audio_port_type_t legacy) { |
| 112 | switch (legacy) { |
| 113 | case AUDIO_PORT_TYPE_NONE: |
| 114 | return media::AudioPortType::NONE; |
| 115 | case AUDIO_PORT_TYPE_DEVICE: |
| 116 | return media::AudioPortType::DEVICE; |
| 117 | case AUDIO_PORT_TYPE_MIX: |
| 118 | return media::AudioPortType::MIX; |
| 119 | case AUDIO_PORT_TYPE_SESSION: |
| 120 | return media::AudioPortType::SESSION; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 121 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 122 | return unexpected(BAD_VALUE); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 125 | ConversionResult<AudioPortDirection> portDirection( |
| 126 | media::AudioPortRole role, media::AudioPortType type) { |
| 127 | audio_port_role_t legacyRole = VALUE_OR_RETURN( |
| 128 | aidl2legacy_AudioPortRole_audio_port_role_t(role)); |
| 129 | audio_port_type_t legacyType = VALUE_OR_RETURN( |
| 130 | aidl2legacy_AudioPortType_audio_port_type_t(type)); |
| 131 | return portDirection(legacyRole, legacyType); |
| 132 | } |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 133 | |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 134 | ConversionResult<audio_io_config_event_t> aidl2legacy_AudioIoConfigEvent_audio_io_config_event_t( |
| 135 | media::AudioIoConfigEvent aidl) { |
| 136 | switch (aidl) { |
| 137 | case media::AudioIoConfigEvent::OUTPUT_REGISTERED: |
| 138 | return AUDIO_OUTPUT_REGISTERED; |
| 139 | case media::AudioIoConfigEvent::OUTPUT_OPENED: |
| 140 | return AUDIO_OUTPUT_OPENED; |
| 141 | case media::AudioIoConfigEvent::OUTPUT_CLOSED: |
| 142 | return AUDIO_OUTPUT_CLOSED; |
| 143 | case media::AudioIoConfigEvent::OUTPUT_CONFIG_CHANGED: |
| 144 | return AUDIO_OUTPUT_CONFIG_CHANGED; |
| 145 | case media::AudioIoConfigEvent::INPUT_REGISTERED: |
| 146 | return AUDIO_INPUT_REGISTERED; |
| 147 | case media::AudioIoConfigEvent::INPUT_OPENED: |
| 148 | return AUDIO_INPUT_OPENED; |
| 149 | case media::AudioIoConfigEvent::INPUT_CLOSED: |
| 150 | return AUDIO_INPUT_CLOSED; |
| 151 | case media::AudioIoConfigEvent::INPUT_CONFIG_CHANGED: |
| 152 | return AUDIO_INPUT_CONFIG_CHANGED; |
| 153 | case media::AudioIoConfigEvent::CLIENT_STARTED: |
| 154 | return AUDIO_CLIENT_STARTED; |
| 155 | } |
| 156 | return unexpected(BAD_VALUE); |
| 157 | } |
| 158 | |
| 159 | ConversionResult<media::AudioIoConfigEvent> legacy2aidl_audio_io_config_event_t_AudioIoConfigEvent( |
| 160 | audio_io_config_event_t legacy) { |
| 161 | switch (legacy) { |
| 162 | case AUDIO_OUTPUT_REGISTERED: |
| 163 | return media::AudioIoConfigEvent::OUTPUT_REGISTERED; |
| 164 | case AUDIO_OUTPUT_OPENED: |
| 165 | return media::AudioIoConfigEvent::OUTPUT_OPENED; |
| 166 | case AUDIO_OUTPUT_CLOSED: |
| 167 | return media::AudioIoConfigEvent::OUTPUT_CLOSED; |
| 168 | case AUDIO_OUTPUT_CONFIG_CHANGED: |
| 169 | return media::AudioIoConfigEvent::OUTPUT_CONFIG_CHANGED; |
| 170 | case AUDIO_INPUT_REGISTERED: |
| 171 | return media::AudioIoConfigEvent::INPUT_REGISTERED; |
| 172 | case AUDIO_INPUT_OPENED: |
| 173 | return media::AudioIoConfigEvent::INPUT_OPENED; |
| 174 | case AUDIO_INPUT_CLOSED: |
| 175 | return media::AudioIoConfigEvent::INPUT_CLOSED; |
| 176 | case AUDIO_INPUT_CONFIG_CHANGED: |
| 177 | return media::AudioIoConfigEvent::INPUT_CONFIG_CHANGED; |
| 178 | case AUDIO_CLIENT_STARTED: |
| 179 | return media::AudioIoConfigEvent::CLIENT_STARTED; |
| 180 | } |
| 181 | return unexpected(BAD_VALUE); |
| 182 | } |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 183 | ConversionResult<audio_port_config_mix_ext_usecase> aidl2legacy_AudioPortMixExtUseCase( |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 184 | const AudioPortMixExtUseCase& aidl, media::AudioPortRole role) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 185 | switch (role) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 186 | case media::AudioPortRole::NONE: { |
| 187 | audio_port_config_mix_ext_usecase legacy; |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 188 | // Just verify that the union is empty. |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 189 | VALUE_OR_RETURN(UNION_GET(aidl, unspecified)); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 190 | return legacy; |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 191 | } |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 192 | case media::AudioPortRole::SOURCE: |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 193 | return aidl2legacy_AudioPortMixExtUseCase_audio_port_config_mix_ext_usecase( |
| 194 | aidl, false /*isInput*/); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 195 | case media::AudioPortRole::SINK: |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 196 | return aidl2legacy_AudioPortMixExtUseCase_audio_port_config_mix_ext_usecase( |
| 197 | aidl, true /*isInput*/); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 198 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 199 | 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] | 200 | } |
| 201 | |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 202 | ConversionResult<AudioPortMixExtUseCase> legacy2aidl_AudioPortMixExtUseCase( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 203 | const audio_port_config_mix_ext_usecase& legacy, audio_port_role_t role) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 204 | switch (role) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 205 | case AUDIO_PORT_ROLE_NONE: { |
| 206 | AudioPortMixExtUseCase aidl; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 207 | UNION_SET(aidl, unspecified, false); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 208 | return aidl; |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 209 | } |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 210 | case AUDIO_PORT_ROLE_SOURCE: |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 211 | return legacy2aidl_audio_port_config_mix_ext_usecase_AudioPortMixExtUseCase( |
| 212 | legacy, false /*isInput*/); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 213 | case AUDIO_PORT_ROLE_SINK: |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 214 | return legacy2aidl_audio_port_config_mix_ext_usecase_AudioPortMixExtUseCase( |
| 215 | legacy, true /*isInput*/); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 216 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 217 | 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] | 218 | } |
| 219 | |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 220 | ConversionResult<audio_port_config_mix_ext> aidl2legacy_AudioPortMixExt( |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 221 | const AudioPortMixExt& aidl, media::AudioPortRole role, |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 222 | const media::AudioPortMixExtSys& aidlMixExt) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 223 | // Not using HAL-level 'aidl2legacy_AudioPortMixExt' as it does not support |
| 224 | // 'media::AudioPortRole::NONE'. |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 225 | audio_port_config_mix_ext legacy; |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 226 | legacy.hw_module = VALUE_OR_RETURN( |
| 227 | aidl2legacy_int32_t_audio_module_handle_t(aidlMixExt.hwModule)); |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 228 | legacy.handle = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.handle)); |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 229 | legacy.usecase = VALUE_OR_RETURN(aidl2legacy_AudioPortMixExtUseCase(aidl.usecase, role)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 230 | return legacy; |
| 231 | } |
| 232 | |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 233 | status_t legacy2aidl_AudioPortMixExt( |
| 234 | const audio_port_config_mix_ext& legacy, audio_port_role_t role, |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 235 | AudioPortMixExt* aidl, media::AudioPortMixExtSys* aidlMixExt) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 236 | // Not using HAL-level 'legacy2aidl_AudioPortMixExt' as it does not support |
| 237 | // 'AUDIO_PORT_ROLE_NONE'. |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 238 | aidlMixExt->hwModule = VALUE_OR_RETURN_STATUS( |
| 239 | legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
| 240 | aidl->handle = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(legacy.handle)); |
| 241 | aidl->usecase = VALUE_OR_RETURN_STATUS( |
| 242 | legacy2aidl_AudioPortMixExtUseCase(legacy.usecase, role)); |
| 243 | return OK; |
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 | ConversionResult<audio_port_config_session_ext> |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 247 | aidl2legacy_int32_t_audio_port_config_session_ext(int32_t aidl) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 248 | audio_port_config_session_ext legacy; |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 249 | legacy.session = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 250 | return legacy; |
| 251 | } |
| 252 | |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 253 | ConversionResult<int32_t> |
| 254 | legacy2aidl_audio_port_config_session_ext_int32_t( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 255 | const audio_port_config_session_ext& legacy) { |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 256 | return legacy2aidl_audio_session_t_int32_t(legacy.session); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 259 | ConversionResult<audio_port_config_device_ext> |
| 260 | aidl2legacy_AudioPortDeviceExt_audio_port_config_device_ext( |
| 261 | const AudioPortDeviceExt& aidl, const media::AudioPortDeviceExtSys& aidlDeviceExt) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 262 | audio_port_config_device_ext legacy = VALUE_OR_RETURN( |
| 263 | aidl2legacy_AudioPortDeviceExt_audio_port_config_device_ext(aidl)); |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 264 | legacy.hw_module = VALUE_OR_RETURN( |
| 265 | aidl2legacy_int32_t_audio_module_handle_t(aidlDeviceExt.hwModule)); |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 266 | return legacy; |
| 267 | } |
| 268 | |
| 269 | status_t legacy2aidl_audio_port_config_device_ext_AudioPortDeviceExt( |
| 270 | const audio_port_config_device_ext& legacy, |
| 271 | AudioPortDeviceExt* aidl, media::AudioPortDeviceExtSys* aidlDeviceExt) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 272 | *aidl = VALUE_OR_RETURN_STATUS( |
| 273 | legacy2aidl_audio_port_config_device_ext_AudioPortDeviceExt(legacy)); |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 274 | aidlDeviceExt->hwModule = VALUE_OR_RETURN_STATUS( |
| 275 | legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 276 | return OK; |
| 277 | } |
| 278 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 279 | // This type is unnamed in the original definition, thus we name it here. |
| 280 | using audio_port_config_ext = decltype(audio_port_config::ext); |
| 281 | |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 282 | ConversionResult<audio_port_config_ext> aidl2legacy_AudioPortExt_audio_port_config_ext( |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 283 | const AudioPortExt& aidl, media::AudioPortType type, |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 284 | media::AudioPortRole role, const media::AudioPortExtSys& aidlSys) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 285 | // Not using HAL-level 'aidl2legacy_AudioPortExt_audio_port_config_ext' as it does not support |
| 286 | // 'media::AudioPortType::SESSION'. |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 287 | audio_port_config_ext legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 288 | switch (type) { |
| 289 | case media::AudioPortType::NONE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 290 | // Just verify that the union is empty. |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 291 | VALUE_OR_RETURN(UNION_GET(aidl, unspecified)); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 292 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 293 | case media::AudioPortType::DEVICE: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 294 | legacy.device = VALUE_OR_RETURN( |
Mikhail Naganov | 1050612 | 2021-10-19 10:14:23 -0700 | [diff] [blame] | 295 | aidl2legacy_AudioPortDeviceExt_audio_port_config_device_ext( |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 296 | VALUE_OR_RETURN(UNION_GET(aidl, device)), |
| 297 | VALUE_OR_RETURN(UNION_GET(aidlSys, device)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 298 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 299 | case media::AudioPortType::MIX: |
Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 300 | legacy.mix = VALUE_OR_RETURN( |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 301 | aidl2legacy_AudioPortMixExt( |
| 302 | VALUE_OR_RETURN(UNION_GET(aidl, mix)), role, |
| 303 | VALUE_OR_RETURN(UNION_GET(aidlSys, mix)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 304 | return legacy; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 305 | case media::AudioPortType::SESSION: |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 306 | legacy.session = VALUE_OR_RETURN( |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 307 | aidl2legacy_int32_t_audio_port_config_session_ext( |
Mikhail Naganov | e4bf423 | 2022-03-11 02:05:58 +0000 | [diff] [blame] | 308 | VALUE_OR_RETURN(UNION_GET(aidlSys, session)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 309 | return legacy; |
| 310 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 311 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 312 | 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] | 313 | } |
| 314 | |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 315 | status_t legacy2aidl_AudioPortExt( |
| 316 | const audio_port_config_ext& legacy, audio_port_type_t type, audio_port_role_t role, |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 317 | AudioPortExt* aidl, media::AudioPortExtSys* aidlSys) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 318 | // Not using HAL-level 'aidl2legacy_AudioPortExt_audio_port_config_ext' as it does not support |
| 319 | // 'AUDIO_PORT_TYPE_SESSION'. |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 320 | switch (type) { |
| 321 | case AUDIO_PORT_TYPE_NONE: |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 322 | UNION_SET(*aidl, unspecified, false); |
| 323 | UNION_SET(*aidlSys, unspecified, false); |
| 324 | return OK; |
| 325 | case AUDIO_PORT_TYPE_DEVICE: { |
Mikhail Naganov | 1050612 | 2021-10-19 10:14:23 -0700 | [diff] [blame] | 326 | AudioPortDeviceExt device; |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 327 | media::AudioPortDeviceExtSys deviceSys; |
| 328 | RETURN_STATUS_IF_ERROR( |
Mikhail Naganov | 1050612 | 2021-10-19 10:14:23 -0700 | [diff] [blame] | 329 | legacy2aidl_audio_port_config_device_ext_AudioPortDeviceExt( |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 330 | legacy.device, &device, &deviceSys)); |
| 331 | UNION_SET(*aidl, device, device); |
| 332 | UNION_SET(*aidlSys, device, deviceSys); |
| 333 | return OK; |
| 334 | } |
| 335 | case AUDIO_PORT_TYPE_MIX: { |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 336 | AudioPortMixExt mix; |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 337 | media::AudioPortMixExtSys mixSys; |
| 338 | RETURN_STATUS_IF_ERROR(legacy2aidl_AudioPortMixExt(legacy.mix, role, &mix, &mixSys)); |
| 339 | UNION_SET(*aidl, mix, mix); |
| 340 | UNION_SET(*aidlSys, mix, mixSys); |
| 341 | return OK; |
| 342 | } |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 343 | case AUDIO_PORT_TYPE_SESSION: |
Mikhail Naganov | e4bf423 | 2022-03-11 02:05:58 +0000 | [diff] [blame] | 344 | UNION_SET(*aidl, unspecified, false); |
| 345 | UNION_SET(*aidlSys, session, VALUE_OR_RETURN_STATUS( |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 346 | legacy2aidl_audio_port_config_session_ext_int32_t(legacy.session))); |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 347 | return OK; |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 348 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 349 | 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] | 350 | } |
| 351 | |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 352 | ConversionResult<audio_port_config> aidl2legacy_AudioPortConfigFw_audio_port_config( |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 353 | const media::AudioPortConfigFw& aidl, int32_t* aidlPortId) { |
| 354 | const bool isInput = VALUE_OR_RETURN( |
| 355 | portDirection(aidl.sys.role, aidl.sys.type)) == AudioPortDirection::INPUT; |
| 356 | audio_port_config legacy; |
| 357 | int32_t aidlPortIdHolder; |
| 358 | RETURN_IF_ERROR(aidl2legacy_AudioPortConfig_audio_port_config( |
| 359 | aidl.hal, isInput, &legacy, &aidlPortIdHolder)); |
| 360 | if (aidlPortId != nullptr) *aidlPortId = aidlPortIdHolder; |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 361 | legacy.role = VALUE_OR_RETURN(aidl2legacy_AudioPortRole_audio_port_role_t(aidl.sys.role)); |
| 362 | legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioPortType_audio_port_type_t(aidl.sys.type)); |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 363 | legacy.ext = VALUE_OR_RETURN( |
| 364 | aidl2legacy_AudioPortExt_audio_port_config_ext( |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 365 | aidl.hal.ext, aidl.sys.type, aidl.sys.role, aidl.sys.ext)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 366 | return legacy; |
| 367 | } |
| 368 | |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 369 | ConversionResult<media::AudioPortConfigFw> legacy2aidl_audio_port_config_AudioPortConfigFw( |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 370 | const audio_port_config& legacy, int32_t portId) { |
| 371 | const bool isInput = VALUE_OR_RETURN( |
| 372 | portDirection(legacy.role, legacy.type)) == AudioPortDirection::INPUT; |
Atneya Nair | b8de69b | 2022-12-18 17:26:26 -0800 | [diff] [blame] | 373 | media::AudioPortConfigFw aidl; |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 374 | aidl.hal = VALUE_OR_RETURN( |
| 375 | legacy2aidl_audio_port_config_AudioPortConfig(legacy, isInput, portId)); |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 376 | aidl.sys.role = VALUE_OR_RETURN(legacy2aidl_audio_port_role_t_AudioPortRole(legacy.role)); |
| 377 | aidl.sys.type = VALUE_OR_RETURN(legacy2aidl_audio_port_type_t_AudioPortType(legacy.type)); |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 378 | RETURN_IF_ERROR(legacy2aidl_AudioPortExt(legacy.ext, legacy.type, legacy.role, |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 379 | &aidl.hal.ext, &aidl.sys.ext)); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 380 | return aidl; |
| 381 | } |
| 382 | |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 383 | ConversionResult<struct audio_patch> aidl2legacy_AudioPatchFw_audio_patch( |
Atneya Nair | b6c50a3 | 2022-12-18 16:14:18 -0800 | [diff] [blame] | 384 | const media::AudioPatchFw& aidl) { |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 385 | struct audio_patch legacy; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 386 | 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] | 387 | legacy.num_sinks = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.sinks.size())); |
| 388 | if (legacy.num_sinks > AUDIO_PATCH_PORTS_MAX) { |
| 389 | return unexpected(BAD_VALUE); |
| 390 | } |
| 391 | for (size_t i = 0; i < legacy.num_sinks; ++i) { |
| 392 | legacy.sinks[i] = |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 393 | VALUE_OR_RETURN(aidl2legacy_AudioPortConfigFw_audio_port_config(aidl.sinks[i])); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 394 | } |
| 395 | legacy.num_sources = VALUE_OR_RETURN(convertIntegral<unsigned int>(aidl.sources.size())); |
| 396 | if (legacy.num_sources > AUDIO_PATCH_PORTS_MAX) { |
| 397 | return unexpected(BAD_VALUE); |
| 398 | } |
| 399 | for (size_t i = 0; i < legacy.num_sources; ++i) { |
| 400 | legacy.sources[i] = |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 401 | VALUE_OR_RETURN(aidl2legacy_AudioPortConfigFw_audio_port_config(aidl.sources[i])); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 402 | } |
| 403 | return legacy; |
| 404 | } |
| 405 | |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 406 | ConversionResult<media::AudioPatchFw> legacy2aidl_audio_patch_AudioPatchFw( |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 407 | const struct audio_patch& legacy) { |
Atneya Nair | b6c50a3 | 2022-12-18 16:14:18 -0800 | [diff] [blame] | 408 | media::AudioPatchFw aidl; |
Ytai Ben-Tsvi | 49298c5 | 2020-10-15 10:56:48 -0700 | [diff] [blame] | 409 | 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] | 410 | |
| 411 | if (legacy.num_sinks > AUDIO_PATCH_PORTS_MAX) { |
| 412 | return unexpected(BAD_VALUE); |
| 413 | } |
| 414 | for (unsigned int i = 0; i < legacy.num_sinks; ++i) { |
| 415 | aidl.sinks.push_back( |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 416 | VALUE_OR_RETURN(legacy2aidl_audio_port_config_AudioPortConfigFw(legacy.sinks[i]))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 417 | } |
| 418 | if (legacy.num_sources > AUDIO_PATCH_PORTS_MAX) { |
| 419 | return unexpected(BAD_VALUE); |
| 420 | } |
| 421 | for (unsigned int i = 0; i < legacy.num_sources; ++i) { |
| 422 | aidl.sources.push_back( |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 423 | VALUE_OR_RETURN(legacy2aidl_audio_port_config_AudioPortConfigFw(legacy.sources[i]))); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 424 | } |
| 425 | return aidl; |
| 426 | } |
| 427 | |
| 428 | ConversionResult<sp<AudioIoDescriptor>> aidl2legacy_AudioIoDescriptor_AudioIoDescriptor( |
| 429 | const media::AudioIoDescriptor& aidl) { |
Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 430 | const audio_io_handle_t io_handle = VALUE_OR_RETURN( |
| 431 | aidl2legacy_int32_t_audio_io_handle_t(aidl.ioHandle)); |
| 432 | const struct audio_patch patch = VALUE_OR_RETURN( |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 433 | aidl2legacy_AudioPatchFw_audio_patch(aidl.patch)); |
Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 434 | const bool isInput = aidl.isInput; |
| 435 | const uint32_t sampling_rate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.samplingRate)); |
| 436 | const audio_format_t format = VALUE_OR_RETURN( |
Mikhail Naganov | b60bd1b | 2021-07-15 17:31:43 -0700 | [diff] [blame] | 437 | aidl2legacy_AudioFormatDescription_audio_format_t(aidl.format)); |
Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 438 | const audio_channel_mask_t channel_mask = VALUE_OR_RETURN( |
Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 439 | aidl2legacy_AudioChannelLayout_audio_channel_mask_t(aidl.channelMask, isInput)); |
Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 440 | const size_t frame_count = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount)); |
| 441 | const size_t frame_count_hal = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCountHAL)); |
| 442 | const uint32_t latency = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.latency)); |
| 443 | const audio_port_handle_t port_id = VALUE_OR_RETURN( |
| 444 | aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
| 445 | return sp<AudioIoDescriptor>::make(io_handle, patch, isInput, sampling_rate, format, |
| 446 | channel_mask, frame_count, frame_count_hal, latency, port_id); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | ConversionResult<media::AudioIoDescriptor> legacy2aidl_AudioIoDescriptor_AudioIoDescriptor( |
| 450 | const sp<AudioIoDescriptor>& legacy) { |
| 451 | media::AudioIoDescriptor aidl; |
Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 452 | aidl.ioHandle = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(legacy->getIoHandle())); |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 453 | aidl.patch = VALUE_OR_RETURN(legacy2aidl_audio_patch_AudioPatchFw(legacy->getPatch())); |
Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 454 | aidl.isInput = legacy->getIsInput(); |
| 455 | aidl.samplingRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy->getSamplingRate())); |
Mikhail Naganov | b60bd1b | 2021-07-15 17:31:43 -0700 | [diff] [blame] | 456 | aidl.format = VALUE_OR_RETURN( |
Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 457 | legacy2aidl_audio_format_t_AudioFormatDescription(legacy->getFormat())); |
Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 458 | aidl.channelMask = VALUE_OR_RETURN(legacy2aidl_audio_channel_mask_t_AudioChannelLayout( |
| 459 | legacy->getChannelMask(), legacy->getIsInput())); |
Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 460 | aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy->getFrameCount())); |
| 461 | aidl.frameCountHAL = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy->getFrameCountHAL())); |
| 462 | aidl.latency = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy->getLatency())); |
| 463 | aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy->getPortId())); |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 464 | return aidl; |
| 465 | } |
| 466 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 467 | ConversionResult<AudioClient> aidl2legacy_AudioClient_AudioClient( |
| 468 | const media::AudioClient& aidl) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 469 | AudioClient legacy; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 470 | legacy.clientTid = VALUE_OR_RETURN(aidl2legacy_int32_t_pid_t(aidl.clientTid)); |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 471 | legacy.attributionSource = aidl.attributionSource; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 472 | return legacy; |
| 473 | } |
| 474 | |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 475 | ConversionResult<media::AudioClient> legacy2aidl_AudioClient_AudioClient( |
| 476 | const AudioClient& legacy) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 477 | media::AudioClient aidl; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 478 | aidl.clientTid = VALUE_OR_RETURN(legacy2aidl_pid_t_int32_t(legacy.clientTid)); |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 479 | aidl.attributionSource = legacy.attributionSource; |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 480 | return aidl; |
| 481 | } |
| 482 | |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 483 | ConversionResult<sp<IMemory>> |
| 484 | aidl2legacy_SharedFileRegion_IMemory(const media::SharedFileRegion& aidl) { |
| 485 | sp<IMemory> legacy; |
| 486 | if (!convertSharedFileRegionToIMemory(aidl, &legacy)) { |
| 487 | return unexpected(BAD_VALUE); |
| 488 | } |
| 489 | return legacy; |
| 490 | } |
| 491 | |
| 492 | ConversionResult<media::SharedFileRegion> |
| 493 | legacy2aidl_IMemory_SharedFileRegion(const sp<IMemory>& legacy) { |
| 494 | media::SharedFileRegion aidl; |
| 495 | if (!convertIMemoryToSharedFileRegion(legacy, &aidl)) { |
| 496 | return unexpected(BAD_VALUE); |
| 497 | } |
| 498 | return aidl; |
| 499 | } |
| 500 | |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 501 | ConversionResult<sp<IMemory>> aidl2legacy_NullableSharedFileRegion_IMemory( |
| 502 | const std::optional<media::SharedFileRegion>& aidl) { |
Ytai Ben-Tsvi | 4dfeb62 | 2020-11-02 12:47:30 -0800 | [diff] [blame] | 503 | sp<IMemory> legacy; |
| 504 | if (!convertNullableSharedFileRegionToIMemory(aidl, &legacy)) { |
| 505 | return unexpected(BAD_VALUE); |
| 506 | } |
| 507 | return legacy; |
| 508 | } |
| 509 | |
| 510 | ConversionResult<std::optional<media::SharedFileRegion>> |
| 511 | legacy2aidl_NullableIMemory_SharedFileRegion(const sp<IMemory>& legacy) { |
| 512 | std::optional<media::SharedFileRegion> aidl; |
| 513 | if (!convertNullableIMemoryToSharedFileRegion(legacy, &aidl)) { |
| 514 | return unexpected(BAD_VALUE); |
| 515 | } |
| 516 | return aidl; |
| 517 | } |
| 518 | |
Ytai Ben-Tsvi | bdc293a | 2020-11-02 17:01:38 -0800 | [diff] [blame] | 519 | ConversionResult<AudioTimestamp> |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 520 | aidl2legacy_AudioTimestampInternal_AudioTimestamp(const media::AudioTimestampInternal& aidl) { |
Ytai Ben-Tsvi | bdc293a | 2020-11-02 17:01:38 -0800 | [diff] [blame] | 521 | AudioTimestamp legacy; |
| 522 | legacy.mPosition = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.position)); |
| 523 | legacy.mTime.tv_sec = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sec)); |
| 524 | legacy.mTime.tv_nsec = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.nsec)); |
| 525 | return legacy; |
| 526 | } |
| 527 | |
| 528 | ConversionResult<media::AudioTimestampInternal> |
Andy Hung | 973638a | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 529 | legacy2aidl_AudioTimestamp_AudioTimestampInternal(const AudioTimestamp& legacy) { |
Ytai Ben-Tsvi | bdc293a | 2020-11-02 17:01:38 -0800 | [diff] [blame] | 530 | media::AudioTimestampInternal aidl; |
Mikhail Naganov | c5f378e | 2023-06-22 15:18:57 +0000 | [diff] [blame] | 531 | aidl.position = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy.mPosition)); |
Ytai Ben-Tsvi | bdc293a | 2020-11-02 17:01:38 -0800 | [diff] [blame] | 532 | aidl.sec = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy.mTime.tv_sec)); |
| 533 | aidl.nsec = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.mTime.tv_nsec)); |
| 534 | return aidl; |
| 535 | } |
| 536 | |
Ytai Ben-Tsvi | ce18294 | 2020-11-04 14:48:01 -0800 | [diff] [blame] | 537 | ConversionResult<effect_descriptor_t> |
| 538 | aidl2legacy_EffectDescriptor_effect_descriptor_t(const media::EffectDescriptor& aidl) { |
| 539 | effect_descriptor_t legacy; |
| 540 | legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioUuid_audio_uuid_t(aidl.type)); |
| 541 | legacy.uuid = VALUE_OR_RETURN(aidl2legacy_AudioUuid_audio_uuid_t(aidl.uuid)); |
| 542 | legacy.apiVersion = VALUE_OR_RETURN(convertReinterpret<uint32_t>(aidl.apiVersion)); |
| 543 | legacy.flags = VALUE_OR_RETURN(convertReinterpret<uint32_t>(aidl.flags)); |
| 544 | legacy.cpuLoad = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.cpuLoad)); |
| 545 | legacy.memoryUsage = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.memoryUsage)); |
| 546 | RETURN_IF_ERROR(aidl2legacy_string(aidl.name, legacy.name, sizeof(legacy.name))); |
| 547 | RETURN_IF_ERROR( |
| 548 | aidl2legacy_string(aidl.implementor, legacy.implementor, sizeof(legacy.implementor))); |
| 549 | return legacy; |
| 550 | } |
| 551 | |
| 552 | ConversionResult<media::EffectDescriptor> |
| 553 | legacy2aidl_effect_descriptor_t_EffectDescriptor(const effect_descriptor_t& legacy) { |
| 554 | media::EffectDescriptor aidl; |
| 555 | aidl.type = VALUE_OR_RETURN(legacy2aidl_audio_uuid_t_AudioUuid(legacy.type)); |
| 556 | aidl.uuid = VALUE_OR_RETURN(legacy2aidl_audio_uuid_t_AudioUuid(legacy.uuid)); |
| 557 | aidl.apiVersion = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.apiVersion)); |
| 558 | aidl.flags = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy.flags)); |
| 559 | aidl.cpuLoad = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.cpuLoad)); |
| 560 | aidl.memoryUsage = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.memoryUsage)); |
| 561 | aidl.name = VALUE_OR_RETURN(legacy2aidl_string(legacy.name, sizeof(legacy.name))); |
| 562 | aidl.implementor = VALUE_OR_RETURN( |
| 563 | legacy2aidl_string(legacy.implementor, sizeof(legacy.implementor))); |
| 564 | return aidl; |
| 565 | } |
| 566 | |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 567 | ConversionResult<audio_port_mix_ext> |
| 568 | aidl2legacy_AudioPortMixExt_audio_port_mix_ext( |
| 569 | const AudioPortMixExt& aidl, const media::AudioPortMixExtSys& aidlSys) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 570 | audio_port_mix_ext legacy = VALUE_OR_RETURN( |
| 571 | aidl2legacy_AudioPortMixExt_audio_port_mix_ext(aidl)); |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 572 | legacy.hw_module = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_module_handle_t(aidlSys.hwModule)); |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 573 | return legacy; |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 576 | status_t |
| 577 | legacy2aidl_audio_port_mix_ext_AudioPortMixExt(const audio_port_mix_ext& legacy, |
| 578 | AudioPortMixExt* aidl, media::AudioPortMixExtSys* aidlMixExt) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 579 | *aidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_mix_ext_AudioPortMixExt(legacy)); |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 580 | aidlMixExt->hwModule = VALUE_OR_RETURN_STATUS( |
| 581 | legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 582 | return OK; |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 583 | } |
| 584 | |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 585 | ConversionResult<audio_port_session_ext> |
| 586 | aidl2legacy_int32_t_audio_port_session_ext(int32_t aidl) { |
| 587 | audio_port_session_ext legacy; |
| 588 | legacy.session = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl)); |
| 589 | return legacy; |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | ConversionResult<int32_t> |
Shunkai Yao | 4b574cf | 2022-12-14 04:27:19 +0000 | [diff] [blame] | 593 | legacy2aidl_audio_port_session_ext_int32_t(const audio_port_session_ext& legacy) { |
| 594 | return legacy2aidl_audio_session_t_int32_t(legacy.session); |
Ytai Ben-Tsvi | 50e016a | 2020-11-12 14:26:12 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 597 | ConversionResult<audio_port_device_ext> |
Mikhail Naganov | 1050612 | 2021-10-19 10:14:23 -0700 | [diff] [blame] | 598 | aidl2legacy_AudioPortDeviceExt_audio_port_device_ext( |
| 599 | const AudioPortDeviceExt& aidl, const media::AudioPortDeviceExtSys& aidlSys) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 600 | audio_port_device_ext legacy = VALUE_OR_RETURN( |
| 601 | aidl2legacy_AudioPortDeviceExt_audio_port_device_ext(aidl)); |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 602 | legacy.hw_module = VALUE_OR_RETURN( |
| 603 | aidl2legacy_int32_t_audio_module_handle_t(aidlSys.hwModule)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 604 | return legacy; |
| 605 | } |
| 606 | |
Mikhail Naganov | 1050612 | 2021-10-19 10:14:23 -0700 | [diff] [blame] | 607 | status_t legacy2aidl_audio_port_device_ext_AudioPortDeviceExt( |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 608 | const audio_port_device_ext& legacy, |
Mikhail Naganov | 1050612 | 2021-10-19 10:14:23 -0700 | [diff] [blame] | 609 | AudioPortDeviceExt* aidl, media::AudioPortDeviceExtSys* aidlDeviceExt) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 610 | *aidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_device_ext_AudioPortDeviceExt(legacy)); |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 611 | aidlDeviceExt->hwModule = VALUE_OR_RETURN_STATUS( |
| 612 | legacy2aidl_audio_module_handle_t_int32_t(legacy.hw_module)); |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 613 | return OK; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 614 | } |
| 615 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 616 | // This type is unnamed in the original definition, thus we name it here. |
| 617 | using audio_port_v7_ext = decltype(audio_port_v7::ext); |
| 618 | |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 619 | ConversionResult<audio_port_v7_ext> aidl2legacy_AudioPortExt_audio_port_v7_ext( |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 620 | const AudioPortExt& aidl, media::AudioPortType type, |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 621 | const media::AudioPortExtSys& aidlSys) { |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 622 | audio_port_v7_ext legacy; |
| 623 | switch (type) { |
| 624 | case media::AudioPortType::NONE: |
| 625 | // Just verify that the union is empty. |
| 626 | VALUE_OR_RETURN(UNION_GET(aidl, unspecified)); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 627 | return legacy; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 628 | case media::AudioPortType::DEVICE: |
| 629 | legacy.device = VALUE_OR_RETURN( |
Mikhail Naganov | 1050612 | 2021-10-19 10:14:23 -0700 | [diff] [blame] | 630 | aidl2legacy_AudioPortDeviceExt_audio_port_device_ext( |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 631 | VALUE_OR_RETURN(UNION_GET(aidl, device)), |
| 632 | VALUE_OR_RETURN(UNION_GET(aidlSys, device)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 633 | return legacy; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 634 | case media::AudioPortType::MIX: |
| 635 | legacy.mix = VALUE_OR_RETURN( |
| 636 | aidl2legacy_AudioPortMixExt_audio_port_mix_ext( |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 637 | VALUE_OR_RETURN(UNION_GET(aidl, mix)), |
| 638 | VALUE_OR_RETURN(UNION_GET(aidlSys, mix)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 639 | return legacy; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 640 | case media::AudioPortType::SESSION: |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 641 | legacy.session = VALUE_OR_RETURN( |
| 642 | aidl2legacy_int32_t_audio_port_session_ext( |
Mikhail Naganov | e4bf423 | 2022-03-11 02:05:58 +0000 | [diff] [blame] | 643 | VALUE_OR_RETURN(UNION_GET(aidlSys, session)))); |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 644 | return legacy; |
| 645 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 646 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 647 | 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] | 648 | } |
| 649 | |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 650 | status_t legacy2aidl_AudioPortExt( |
| 651 | const audio_port_v7_ext& legacy, audio_port_type_t type, |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 652 | AudioPortExt* aidl, media::AudioPortExtSys* aidlSys) { |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 653 | switch (type) { |
| 654 | case AUDIO_PORT_TYPE_NONE: |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 655 | UNION_SET(*aidl, unspecified, false); |
| 656 | UNION_SET(*aidlSys, unspecified, false); |
| 657 | return OK; |
| 658 | case AUDIO_PORT_TYPE_DEVICE: { |
Mikhail Naganov | 1050612 | 2021-10-19 10:14:23 -0700 | [diff] [blame] | 659 | AudioPortDeviceExt device; |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 660 | media::AudioPortDeviceExtSys deviceSys; |
| 661 | RETURN_STATUS_IF_ERROR( |
Mikhail Naganov | 1050612 | 2021-10-19 10:14:23 -0700 | [diff] [blame] | 662 | legacy2aidl_audio_port_device_ext_AudioPortDeviceExt( |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 663 | legacy.device, &device, &deviceSys)); |
| 664 | UNION_SET(*aidl, device, device); |
| 665 | UNION_SET(*aidlSys, device, deviceSys); |
| 666 | return OK; |
| 667 | } |
| 668 | case AUDIO_PORT_TYPE_MIX: { |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 669 | AudioPortMixExt mix; |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 670 | media::AudioPortMixExtSys mixSys; |
| 671 | RETURN_STATUS_IF_ERROR( |
| 672 | legacy2aidl_audio_port_mix_ext_AudioPortMixExt( |
| 673 | legacy.mix, &mix, &mixSys)); |
| 674 | UNION_SET(*aidl, mix, mix); |
| 675 | UNION_SET(*aidlSys, mix, mixSys); |
| 676 | return OK; |
| 677 | } |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 678 | case AUDIO_PORT_TYPE_SESSION: |
Mikhail Naganov | e4bf423 | 2022-03-11 02:05:58 +0000 | [diff] [blame] | 679 | UNION_SET(*aidl, unspecified, false); |
| 680 | UNION_SET(*aidlSys, session, VALUE_OR_RETURN_STATUS( |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 681 | legacy2aidl_audio_port_session_ext_int32_t(legacy.session))); |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 682 | return OK; |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 683 | } |
Andy Hung | 3f69c16 | 2020-12-09 12:08:48 -0800 | [diff] [blame] | 684 | 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] | 685 | } |
| 686 | |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 687 | ConversionResult<audio_port_v7> |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 688 | aidl2legacy_AudioPortFw_audio_port_v7(const media::AudioPortFw& aidl) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 689 | const bool isInput = VALUE_OR_RETURN( |
| 690 | portDirection(aidl.sys.role, aidl.sys.type)) == AudioPortDirection::INPUT; |
| 691 | audio_port_v7 legacy = VALUE_OR_RETURN(aidl2legacy_AudioPort_audio_port_v7(aidl.hal, isInput)); |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 692 | legacy.role = VALUE_OR_RETURN(aidl2legacy_AudioPortRole_audio_port_role_t(aidl.sys.role)); |
| 693 | legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioPortType_audio_port_type_t(aidl.sys.type)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 694 | |
| 695 | legacy.active_config = VALUE_OR_RETURN( |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 696 | aidl2legacy_AudioPortConfigFw_audio_port_config(aidl.sys.activeConfig)); |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 697 | legacy.ext = VALUE_OR_RETURN( |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 698 | aidl2legacy_AudioPortExt_audio_port_v7_ext(aidl.hal.ext, aidl.sys.type, aidl.sys.ext)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 699 | return legacy; |
| 700 | } |
| 701 | |
Atneya Nair | c18e9a1 | 2022-12-18 16:45:15 -0800 | [diff] [blame] | 702 | ConversionResult<media::AudioPortFw> |
Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 703 | legacy2aidl_audio_port_v7_AudioPortFw(const audio_port_v7& legacy) { |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 704 | const bool isInput = VALUE_OR_RETURN( |
| 705 | portDirection(legacy.role, legacy.type)) == AudioPortDirection::INPUT; |
Atneya Nair | c18e9a1 | 2022-12-18 16:45:15 -0800 | [diff] [blame] | 706 | media::AudioPortFw aidl; |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 707 | aidl.hal = VALUE_OR_RETURN(legacy2aidl_audio_port_v7_AudioPort(legacy, isInput)); |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 708 | aidl.sys.role = VALUE_OR_RETURN(legacy2aidl_audio_port_role_t_AudioPortRole(legacy.role)); |
| 709 | aidl.sys.type = VALUE_OR_RETURN(legacy2aidl_audio_port_type_t_AudioPortType(legacy.type)); |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 710 | // These get filled by the call to 'legacy2aidl_AudioPortExt' below. |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 711 | aidl.sys.profiles.resize(legacy.num_audio_profiles); |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 712 | aidl.sys.gains.resize(legacy.num_gains); |
Mikhail Naganov | 6313e57 | 2021-12-04 01:46:55 +0000 | [diff] [blame] | 713 | aidl.sys.activeConfig = VALUE_OR_RETURN( |
Mikhail Naganov | 72cd068 | 2023-01-17 17:58:26 -0800 | [diff] [blame] | 714 | legacy2aidl_audio_port_config_AudioPortConfigFw(legacy.active_config, legacy.id)); |
Mikhail Naganov | 6313e57 | 2021-12-04 01:46:55 +0000 | [diff] [blame] | 715 | aidl.sys.activeConfig.hal.portId = aidl.hal.id; |
Mikhail Naganov | ceb8bf9 | 2021-09-23 21:29:39 +0000 | [diff] [blame] | 716 | RETURN_IF_ERROR( |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 717 | legacy2aidl_AudioPortExt(legacy.ext, legacy.type, &aidl.hal.ext, &aidl.sys.ext)); |
Ytai Ben-Tsvi | 0cf9265 | 2020-11-23 13:23:00 -0800 | [diff] [blame] | 718 | return aidl; |
| 719 | } |
| 720 | |
Ytai Ben-Tsvi | 50b8ccb | 2020-11-24 13:47:54 -0800 | [diff] [blame] | 721 | ConversionResult<audio_unique_id_use_t> |
| 722 | aidl2legacy_AudioUniqueIdUse_audio_unique_id_use_t(media::AudioUniqueIdUse aidl) { |
| 723 | switch (aidl) { |
| 724 | case media::AudioUniqueIdUse::UNSPECIFIED: |
| 725 | return AUDIO_UNIQUE_ID_USE_UNSPECIFIED; |
| 726 | case media::AudioUniqueIdUse::SESSION: |
| 727 | return AUDIO_UNIQUE_ID_USE_SESSION; |
| 728 | case media::AudioUniqueIdUse::MODULE: |
| 729 | return AUDIO_UNIQUE_ID_USE_MODULE; |
| 730 | case media::AudioUniqueIdUse::EFFECT: |
| 731 | return AUDIO_UNIQUE_ID_USE_EFFECT; |
| 732 | case media::AudioUniqueIdUse::PATCH: |
| 733 | return AUDIO_UNIQUE_ID_USE_PATCH; |
| 734 | case media::AudioUniqueIdUse::OUTPUT: |
| 735 | return AUDIO_UNIQUE_ID_USE_OUTPUT; |
| 736 | case media::AudioUniqueIdUse::INPUT: |
| 737 | return AUDIO_UNIQUE_ID_USE_INPUT; |
| 738 | case media::AudioUniqueIdUse::CLIENT: |
| 739 | return AUDIO_UNIQUE_ID_USE_CLIENT; |
| 740 | } |
| 741 | return unexpected(BAD_VALUE); |
| 742 | } |
| 743 | |
| 744 | ConversionResult<media::AudioUniqueIdUse> |
| 745 | legacy2aidl_audio_unique_id_use_t_AudioUniqueIdUse(audio_unique_id_use_t legacy) { |
| 746 | switch (legacy) { |
| 747 | case AUDIO_UNIQUE_ID_USE_UNSPECIFIED: |
| 748 | return media::AudioUniqueIdUse::UNSPECIFIED; |
| 749 | case AUDIO_UNIQUE_ID_USE_SESSION: |
| 750 | return media::AudioUniqueIdUse::SESSION; |
| 751 | case AUDIO_UNIQUE_ID_USE_MODULE: |
| 752 | return media::AudioUniqueIdUse::MODULE; |
| 753 | case AUDIO_UNIQUE_ID_USE_EFFECT: |
| 754 | return media::AudioUniqueIdUse::EFFECT; |
| 755 | case AUDIO_UNIQUE_ID_USE_PATCH: |
| 756 | return media::AudioUniqueIdUse::PATCH; |
| 757 | case AUDIO_UNIQUE_ID_USE_OUTPUT: |
| 758 | return media::AudioUniqueIdUse::OUTPUT; |
| 759 | case AUDIO_UNIQUE_ID_USE_INPUT: |
| 760 | return media::AudioUniqueIdUse::INPUT; |
| 761 | case AUDIO_UNIQUE_ID_USE_CLIENT: |
| 762 | return media::AudioUniqueIdUse::CLIENT; |
| 763 | case AUDIO_UNIQUE_ID_USE_MAX: |
| 764 | break; |
| 765 | } |
| 766 | return unexpected(BAD_VALUE); |
| 767 | } |
| 768 | |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 769 | ConversionResult<volume_group_t> |
| 770 | aidl2legacy_int32_t_volume_group_t(int32_t aidl) { |
| 771 | return convertReinterpret<volume_group_t>(aidl); |
| 772 | } |
| 773 | |
| 774 | ConversionResult<int32_t> |
| 775 | legacy2aidl_volume_group_t_int32_t(volume_group_t legacy) { |
| 776 | return convertReinterpret<int32_t>(legacy); |
| 777 | } |
| 778 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 779 | ConversionResult<product_strategy_t> |
| 780 | aidl2legacy_int32_t_product_strategy_t(int32_t aidl) { |
| 781 | return convertReinterpret<product_strategy_t>(aidl); |
| 782 | } |
| 783 | |
| 784 | ConversionResult<int32_t> |
| 785 | legacy2aidl_product_strategy_t_int32_t(product_strategy_t legacy) { |
| 786 | return convertReinterpret<int32_t>(legacy); |
| 787 | } |
| 788 | |
jiabin | 10a03f1 | 2021-05-07 23:46:28 +0000 | [diff] [blame] | 789 | ConversionResult<TrackSecondaryOutputInfoPair> |
| 790 | aidl2legacy_TrackSecondaryOutputInfo_TrackSecondaryOutputInfoPair( |
| 791 | const media::TrackSecondaryOutputInfo& aidl) { |
| 792 | TrackSecondaryOutputInfoPair trackSecondaryOutputInfoPair; |
| 793 | trackSecondaryOutputInfoPair.first = |
| 794 | VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
| 795 | trackSecondaryOutputInfoPair.second = |
| 796 | VALUE_OR_RETURN(convertContainer<std::vector<audio_port_handle_t>>( |
| 797 | aidl.secondaryOutputIds, aidl2legacy_int32_t_audio_io_handle_t)); |
| 798 | return trackSecondaryOutputInfoPair; |
| 799 | } |
| 800 | |
| 801 | ConversionResult<media::TrackSecondaryOutputInfo> |
| 802 | legacy2aidl_TrackSecondaryOutputInfoPair_TrackSecondaryOutputInfo( |
| 803 | const TrackSecondaryOutputInfoPair& legacy) { |
| 804 | media::TrackSecondaryOutputInfo trackSecondaryOutputInfo; |
| 805 | trackSecondaryOutputInfo.portId = |
| 806 | VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy.first)); |
| 807 | trackSecondaryOutputInfo.secondaryOutputIds = |
| 808 | VALUE_OR_RETURN(convertContainer<std::vector<int32_t>>( |
| 809 | legacy.second, legacy2aidl_audio_io_handle_t_int32_t)); |
| 810 | return trackSecondaryOutputInfo; |
| 811 | } |
| 812 | |
jiabin | 2b9d5a1 | 2021-12-10 01:06:29 +0000 | [diff] [blame] | 813 | ConversionResult<audio_direct_mode_t> |
| 814 | aidl2legacy_AudioDirectMode_audio_direct_mode_t(media::AudioDirectMode aidl) { |
| 815 | switch (aidl) { |
| 816 | case media::AudioDirectMode::NONE: |
| 817 | return AUDIO_DIRECT_NOT_SUPPORTED; |
| 818 | case media::AudioDirectMode::OFFLOAD: |
| 819 | return AUDIO_DIRECT_OFFLOAD_SUPPORTED; |
| 820 | case media::AudioDirectMode::OFFLOAD_GAPLESS: |
| 821 | return AUDIO_DIRECT_OFFLOAD_GAPLESS_SUPPORTED; |
| 822 | case media::AudioDirectMode::BITSTREAM: |
| 823 | return AUDIO_DIRECT_BITSTREAM_SUPPORTED; |
| 824 | } |
| 825 | return unexpected(BAD_VALUE); |
| 826 | } |
| 827 | ConversionResult<media::AudioDirectMode> |
| 828 | legacy2aidl_audio_direct_mode_t_AudioDirectMode(audio_direct_mode_t legacy) { |
| 829 | switch (legacy) { |
| 830 | case AUDIO_DIRECT_NOT_SUPPORTED: |
| 831 | return media::AudioDirectMode::NONE; |
| 832 | case AUDIO_DIRECT_OFFLOAD_SUPPORTED: |
| 833 | return media::AudioDirectMode::OFFLOAD; |
| 834 | case AUDIO_DIRECT_OFFLOAD_GAPLESS_SUPPORTED: |
| 835 | return media::AudioDirectMode::OFFLOAD_GAPLESS; |
| 836 | case AUDIO_DIRECT_BITSTREAM_SUPPORTED: |
| 837 | return media::AudioDirectMode::BITSTREAM; |
| 838 | } |
| 839 | return unexpected(BAD_VALUE); |
| 840 | } |
| 841 | |
| 842 | ConversionResult<audio_direct_mode_t> aidl2legacy_int32_t_audio_direct_mode_t_mask(int32_t aidl) { |
| 843 | using LegacyMask = std::underlying_type_t<audio_direct_mode_t>; |
| 844 | |
| 845 | LegacyMask converted = VALUE_OR_RETURN( |
| 846 | (convertBitmask<LegacyMask, int32_t, audio_direct_mode_t, media::AudioDirectMode>( |
| 847 | aidl, aidl2legacy_AudioDirectMode_audio_direct_mode_t, |
| 848 | indexToEnum_index<media::AudioDirectMode>, |
| 849 | enumToMask_bitmask<LegacyMask, audio_direct_mode_t>))); |
| 850 | return static_cast<audio_direct_mode_t>(converted); |
| 851 | } |
| 852 | ConversionResult<int32_t> legacy2aidl_audio_direct_mode_t_int32_t_mask(audio_direct_mode_t legacy) { |
| 853 | using LegacyMask = std::underlying_type_t<audio_direct_mode_t>; |
| 854 | |
| 855 | LegacyMask legacyMask = static_cast<LegacyMask>(legacy); |
| 856 | return convertBitmask<int32_t, LegacyMask, media::AudioDirectMode, audio_direct_mode_t>( |
| 857 | legacyMask, legacy2aidl_audio_direct_mode_t_AudioDirectMode, |
| 858 | indexToEnum_bitmask<audio_direct_mode_t>, |
| 859 | enumToMask_index<int32_t, media::AudioDirectMode>); |
| 860 | } |
Mikhail Naganov | 2a6a301 | 2023-02-13 11:45:03 -0800 | [diff] [blame] | 861 | |
| 862 | ConversionResult<audio_microphone_characteristic_t> |
| 863 | aidl2legacy_MicrophoneInfoFw_audio_microphone_characteristic_t( |
| 864 | const media::MicrophoneInfoFw& aidl) { |
| 865 | audio_microphone_characteristic_t legacy = |
| 866 | VALUE_OR_RETURN(aidl2legacy_MicrophoneInfos_audio_microphone_characteristic_t( |
| 867 | aidl.info, aidl.dynamic)); |
| 868 | legacy.id = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
| 869 | return legacy; |
| 870 | } |
| 871 | ConversionResult<media::MicrophoneInfoFw> |
| 872 | legacy2aidl_audio_microphone_characteristic_t_MicrophoneInfoFw( |
| 873 | const audio_microphone_characteristic_t& legacy) { |
| 874 | media::MicrophoneInfoFw aidl; |
| 875 | RETURN_IF_ERROR(legacy2aidl_audio_microphone_characteristic_t_MicrophoneInfos( |
| 876 | legacy, &aidl.info, &aidl.dynamic)); |
| 877 | aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy.id)); |
| 878 | return aidl; |
| 879 | } |
| 880 | |
Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 881 | } // namespace android |