Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 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 | |
Shunkai Yao | 04b073a | 2023-02-17 06:17:12 +0000 | [diff] [blame] | 17 | #include <cstdint> |
| 18 | #include <inttypes.h> |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 19 | #include <utility> |
| 20 | |
| 21 | #define LOG_TAG "AidlConversionEffect" |
| 22 | //#define LOG_NDEBUG 0 |
| 23 | #include <utils/Log.h> |
| 24 | |
Shunkai Yao | 04b073a | 2023-02-17 06:17:12 +0000 | [diff] [blame] | 25 | #include <aidl/android/hardware/audio/effect/DefaultExtension.h> |
| 26 | #include <aidl/android/hardware/audio/effect/VendorExtension.h> |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 27 | #include <media/AidlConversionCppNdk.h> |
| 28 | #include <media/AidlConversionEffect.h> |
| 29 | |
| 30 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 31 | // AIDL NDK backend to legacy audio data structure conversion utilities. |
| 32 | |
| 33 | namespace aidl { |
| 34 | namespace android { |
| 35 | |
| 36 | using ::aidl::android::hardware::audio::effect::AcousticEchoCanceler; |
Shraddha Basantwani | 64db6d4 | 2023-02-01 16:24:19 +0530 | [diff] [blame] | 37 | using ::aidl::android::hardware::audio::effect::AutomaticGainControlV2; |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 38 | using ::aidl::android::hardware::audio::effect::BassBoost; |
Shunkai Yao | 04b073a | 2023-02-17 06:17:12 +0000 | [diff] [blame] | 39 | using ::aidl::android::hardware::audio::effect::DefaultExtension; |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 40 | using ::aidl::android::hardware::audio::effect::Descriptor; |
| 41 | using ::aidl::android::hardware::audio::effect::Downmix; |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 42 | using ::aidl::android::hardware::audio::effect::DynamicsProcessing; |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 43 | using ::aidl::android::hardware::audio::effect::Flags; |
| 44 | using ::aidl::android::hardware::audio::effect::Parameter; |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 45 | using ::aidl::android::hardware::audio::effect::PresetReverb; |
Shunkai Yao | 04b073a | 2023-02-17 06:17:12 +0000 | [diff] [blame] | 46 | using ::aidl::android::hardware::audio::effect::VendorExtension; |
| 47 | using ::aidl::android::hardware::audio::effect::Visualizer; |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 48 | using ::aidl::android::media::audio::common::AudioDeviceDescription; |
| 49 | |
| 50 | using ::android::BAD_VALUE; |
| 51 | using ::android::base::unexpected; |
Shunkai Yao | 04b073a | 2023-02-17 06:17:12 +0000 | [diff] [blame] | 52 | using ::android::effect::utils::EffectParamReader; |
| 53 | using ::android::effect::utils::EffectParamWriter; |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 54 | |
| 55 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 56 | // Converters |
| 57 | |
| 58 | ConversionResult<uint32_t> aidl2legacy_Flags_Type_uint32(Flags::Type type) { |
| 59 | switch (type) { |
| 60 | case Flags::Type::INSERT: |
| 61 | return EFFECT_FLAG_TYPE_INSERT; |
| 62 | case Flags::Type::AUXILIARY: |
| 63 | return EFFECT_FLAG_TYPE_AUXILIARY; |
| 64 | case Flags::Type::REPLACE: |
| 65 | return EFFECT_FLAG_TYPE_REPLACE; |
| 66 | case Flags::Type::PRE_PROC: |
| 67 | return EFFECT_FLAG_TYPE_PRE_PROC; |
| 68 | case Flags::Type::POST_PROC: |
| 69 | return EFFECT_FLAG_TYPE_POST_PROC; |
| 70 | } |
| 71 | return unexpected(BAD_VALUE); |
| 72 | } |
| 73 | |
| 74 | ConversionResult<Flags::Type> legacy2aidl_uint32_Flags_Type(uint32_t legacy) { |
| 75 | switch (legacy & EFFECT_FLAG_TYPE_MASK) { |
| 76 | case EFFECT_FLAG_TYPE_INSERT: |
| 77 | return Flags::Type::INSERT; |
| 78 | case EFFECT_FLAG_TYPE_AUXILIARY: |
| 79 | return Flags::Type::AUXILIARY; |
| 80 | case EFFECT_FLAG_TYPE_REPLACE: |
| 81 | return Flags::Type::REPLACE; |
| 82 | case EFFECT_FLAG_TYPE_PRE_PROC: |
| 83 | return Flags::Type::PRE_PROC; |
| 84 | case EFFECT_FLAG_TYPE_POST_PROC: |
| 85 | return Flags::Type::POST_PROC; |
| 86 | } |
| 87 | return unexpected(BAD_VALUE); |
| 88 | } |
| 89 | |
| 90 | ConversionResult<uint32_t> aidl2legacy_Flags_Insert_uint32(Flags::Insert insert) { |
| 91 | switch (insert) { |
| 92 | case Flags::Insert::ANY: |
| 93 | return EFFECT_FLAG_INSERT_ANY; |
| 94 | case Flags::Insert::FIRST: |
| 95 | return EFFECT_FLAG_INSERT_FIRST; |
| 96 | case Flags::Insert::LAST: |
| 97 | return EFFECT_FLAG_INSERT_LAST; |
| 98 | case Flags::Insert::EXCLUSIVE: |
| 99 | return EFFECT_FLAG_INSERT_EXCLUSIVE; |
| 100 | } |
| 101 | return unexpected(BAD_VALUE); |
| 102 | } |
| 103 | |
| 104 | ConversionResult<Flags::Insert> legacy2aidl_uint32_Flags_Insert(uint32_t legacy) { |
| 105 | switch (legacy & EFFECT_FLAG_INSERT_MASK) { |
| 106 | case EFFECT_FLAG_INSERT_ANY: |
| 107 | return Flags::Insert::ANY; |
| 108 | case EFFECT_FLAG_INSERT_FIRST: |
| 109 | return Flags::Insert::FIRST; |
| 110 | case EFFECT_FLAG_INSERT_LAST: |
| 111 | return Flags::Insert::LAST; |
| 112 | case EFFECT_FLAG_INSERT_EXCLUSIVE: |
| 113 | return Flags::Insert::EXCLUSIVE; |
| 114 | } |
| 115 | return unexpected(BAD_VALUE); |
| 116 | } |
| 117 | |
| 118 | ConversionResult<uint32_t> aidl2legacy_Flags_Volume_uint32(Flags::Volume volume) { |
| 119 | switch (volume) { |
| 120 | case Flags::Volume::NONE: |
| 121 | return 0; |
| 122 | case Flags::Volume::CTRL: |
| 123 | return EFFECT_FLAG_VOLUME_CTRL; |
| 124 | case Flags::Volume::IND: |
| 125 | return EFFECT_FLAG_VOLUME_IND; |
| 126 | case Flags::Volume::MONITOR: |
| 127 | return EFFECT_FLAG_VOLUME_MONITOR; |
| 128 | } |
| 129 | return unexpected(BAD_VALUE); |
| 130 | } |
| 131 | |
| 132 | ConversionResult<Flags::Volume> legacy2aidl_uint32_Flags_Volume(uint32_t legacy) { |
| 133 | switch (legacy & EFFECT_FLAG_VOLUME_MASK) { |
| 134 | case EFFECT_FLAG_VOLUME_CTRL: |
| 135 | return Flags::Volume::CTRL; |
| 136 | case EFFECT_FLAG_VOLUME_IND: |
| 137 | return Flags::Volume::IND; |
| 138 | case EFFECT_FLAG_VOLUME_MONITOR: |
| 139 | return Flags::Volume::MONITOR; |
| 140 | case EFFECT_FLAG_VOLUME_NONE: |
| 141 | return Flags::Volume::NONE; |
| 142 | } |
| 143 | return unexpected(BAD_VALUE); |
| 144 | } |
| 145 | |
| 146 | ConversionResult<uint32_t> aidl2legacy_Flags_uint32(Flags aidl) { |
| 147 | uint32_t legacy = 0; |
| 148 | legacy |= VALUE_OR_RETURN(aidl2legacy_Flags_Type_uint32(aidl.type)); |
| 149 | legacy |= VALUE_OR_RETURN(aidl2legacy_Flags_Insert_uint32(aidl.insert)); |
| 150 | legacy |= VALUE_OR_RETURN(aidl2legacy_Flags_Volume_uint32(aidl.volume)); |
| 151 | legacy |= VALUE_OR_RETURN(aidl2legacy_Flags_HardwareAccelerator_uint32(aidl.hwAcceleratorMode)); |
| 152 | |
| 153 | if (aidl.offloadIndication) { |
| 154 | legacy |= EFFECT_FLAG_OFFLOAD_SUPPORTED; |
| 155 | } |
| 156 | if (aidl.deviceIndication) { |
| 157 | legacy |= EFFECT_FLAG_DEVICE_IND; |
| 158 | } |
| 159 | if (aidl.audioModeIndication) { |
| 160 | legacy |= EFFECT_FLAG_AUDIO_MODE_IND; |
| 161 | } |
| 162 | if (aidl.audioSourceIndication) { |
| 163 | legacy |= EFFECT_FLAG_AUDIO_SOURCE_IND; |
| 164 | } |
Shunkai Yao | fba5c2d | 2023-02-02 22:50:00 +0000 | [diff] [blame] | 165 | if (aidl.bypass) { |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 166 | legacy |= EFFECT_FLAG_NO_PROCESS; |
| 167 | } |
| 168 | return legacy; |
| 169 | } |
| 170 | |
| 171 | ConversionResult<Flags> legacy2aidl_uint32_Flags(uint32_t legacy) { |
| 172 | Flags aidl; |
| 173 | |
| 174 | aidl.type = VALUE_OR_RETURN(legacy2aidl_uint32_Flags_Type(legacy)); |
| 175 | aidl.insert = VALUE_OR_RETURN(legacy2aidl_uint32_Flags_Insert(legacy)); |
| 176 | aidl.volume = VALUE_OR_RETURN(legacy2aidl_uint32_Flags_Volume(legacy)); |
| 177 | aidl.hwAcceleratorMode = VALUE_OR_RETURN(legacy2aidl_uint32_Flags_HardwareAccelerator(legacy)); |
| 178 | aidl.offloadIndication = (legacy & EFFECT_FLAG_OFFLOAD_SUPPORTED); |
| 179 | aidl.deviceIndication = (legacy & EFFECT_FLAG_DEVICE_IND); |
| 180 | aidl.audioModeIndication = (legacy & EFFECT_FLAG_AUDIO_MODE_IND); |
| 181 | aidl.audioSourceIndication = (legacy & EFFECT_FLAG_AUDIO_SOURCE_IND); |
Shunkai Yao | fba5c2d | 2023-02-02 22:50:00 +0000 | [diff] [blame] | 182 | aidl.bypass = (legacy & EFFECT_FLAG_NO_PROCESS); |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 183 | return aidl; |
| 184 | } |
| 185 | |
| 186 | ConversionResult<uint32_t> aidl2legacy_Flags_HardwareAccelerator_uint32( |
| 187 | Flags::HardwareAccelerator hwAcceleratorMode) { |
| 188 | switch (hwAcceleratorMode) { |
| 189 | case Flags::HardwareAccelerator::NONE: |
| 190 | return 0; |
| 191 | case Flags::HardwareAccelerator::SIMPLE: |
| 192 | return EFFECT_FLAG_HW_ACC_SIMPLE; |
| 193 | case Flags::HardwareAccelerator::TUNNEL: |
| 194 | return EFFECT_FLAG_HW_ACC_TUNNEL; |
| 195 | } |
| 196 | return unexpected(BAD_VALUE); |
| 197 | } |
| 198 | |
| 199 | ConversionResult<Flags::HardwareAccelerator> legacy2aidl_uint32_Flags_HardwareAccelerator( |
| 200 | uint32_t legacy) { |
| 201 | switch (legacy & EFFECT_FLAG_HW_ACC_MASK) { |
| 202 | case EFFECT_FLAG_HW_ACC_SIMPLE: |
| 203 | return Flags::HardwareAccelerator::SIMPLE; |
| 204 | case EFFECT_FLAG_HW_ACC_TUNNEL: |
| 205 | return Flags::HardwareAccelerator::TUNNEL; |
| 206 | case 0: |
| 207 | return Flags::HardwareAccelerator::NONE; |
| 208 | } |
| 209 | return unexpected(BAD_VALUE); |
| 210 | } |
| 211 | |
| 212 | ConversionResult<effect_descriptor_t> |
| 213 | aidl2legacy_Descriptor_effect_descriptor(const Descriptor& aidl) { |
| 214 | effect_descriptor_t legacy; |
| 215 | legacy.type = VALUE_OR_RETURN(aidl2legacy_AudioUuid_audio_uuid_t(aidl.common.id.type)); |
| 216 | legacy.uuid = VALUE_OR_RETURN(aidl2legacy_AudioUuid_audio_uuid_t(aidl.common.id.uuid)); |
| 217 | // legacy descriptor doesn't have proxy information |
| 218 | // proxy = VALUE_OR_RETURN(aidl2legacy_AudioUuid_audio_uuid_t(aidl.proxy)); |
| 219 | legacy.apiVersion = EFFECT_CONTROL_API_VERSION; |
| 220 | legacy.flags = VALUE_OR_RETURN(aidl2legacy_Flags_uint32(aidl.common.flags)); |
| 221 | legacy.cpuLoad = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.common.cpuLoad)); |
| 222 | legacy.memoryUsage = VALUE_OR_RETURN(convertIntegral<uint16_t>(aidl.common.memoryUsage)); |
| 223 | RETURN_IF_ERROR(aidl2legacy_string(aidl.common.name, legacy.name, sizeof(legacy.name))); |
| 224 | RETURN_IF_ERROR(aidl2legacy_string(aidl.common.implementor, legacy.implementor, |
| 225 | sizeof(legacy.implementor))); |
| 226 | return legacy; |
| 227 | } |
| 228 | |
| 229 | ConversionResult<Descriptor> |
| 230 | legacy2aidl_effect_descriptor_Descriptor(const effect_descriptor_t& legacy) { |
| 231 | Descriptor aidl; |
| 232 | aidl.common.id.type = VALUE_OR_RETURN(legacy2aidl_audio_uuid_t_AudioUuid(legacy.type)); |
| 233 | aidl.common.id.uuid = VALUE_OR_RETURN(legacy2aidl_audio_uuid_t_AudioUuid(legacy.uuid)); |
| 234 | // legacy descriptor doesn't have proxy information |
| 235 | // aidl.common.id.proxy |
| 236 | aidl.common.flags = VALUE_OR_RETURN(legacy2aidl_uint32_Flags(legacy.flags)); |
| 237 | aidl.common.cpuLoad = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.cpuLoad)); |
| 238 | aidl.common.memoryUsage = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.memoryUsage)); |
| 239 | aidl.common.name = VALUE_OR_RETURN(legacy2aidl_string(legacy.name, sizeof(legacy.name))); |
| 240 | aidl.common.implementor = |
| 241 | VALUE_OR_RETURN(legacy2aidl_string(legacy.implementor, sizeof(legacy.implementor))); |
| 242 | return aidl; |
| 243 | } |
| 244 | |
| 245 | ConversionResult<uint32_t> aidl2legacy_Parameter_aec_uint32_echoDelay(const Parameter& aidl) { |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 246 | int echoDelay = VALUE_OR_RETURN( |
| 247 | GET_PARAMETER_SPECIFIC_FIELD(aidl, AcousticEchoCanceler, acousticEchoCanceler, |
| 248 | AcousticEchoCanceler::echoDelayUs, int)); |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 249 | return VALUE_OR_RETURN(convertReinterpret<uint32_t>(echoDelay)); |
| 250 | } |
| 251 | |
| 252 | ConversionResult<Parameter> legacy2aidl_uint32_echoDelay_Parameter_aec(uint32_t legacy) { |
| 253 | int delay = VALUE_OR_RETURN(convertReinterpret<int32_t>(legacy)); |
| 254 | return MAKE_SPECIFIC_PARAMETER(AcousticEchoCanceler, acousticEchoCanceler, echoDelayUs, delay); |
| 255 | } |
| 256 | |
| 257 | ConversionResult<uint32_t> aidl2legacy_Parameter_aec_uint32_mobileMode(const Parameter& aidl) { |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 258 | bool mobileMode = VALUE_OR_RETURN( |
| 259 | GET_PARAMETER_SPECIFIC_FIELD(aidl, AcousticEchoCanceler, acousticEchoCanceler, |
| 260 | AcousticEchoCanceler::mobileMode, bool)); |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 261 | return VALUE_OR_RETURN(convertIntegral<uint32_t>(mobileMode)); |
| 262 | } |
| 263 | |
| 264 | ConversionResult<Parameter> legacy2aidl_uint32_mobileMode_Parameter_aec(uint32_t legacy) { |
| 265 | bool mode = VALUE_OR_RETURN(convertIntegral<bool>(legacy)); |
| 266 | return MAKE_SPECIFIC_PARAMETER(AcousticEchoCanceler, acousticEchoCanceler, mobileMode, mode); |
| 267 | } |
| 268 | |
| 269 | ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_fixedDigitalGain( |
| 270 | const Parameter& aidl) { |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 271 | int gain = VALUE_OR_RETURN( |
Shraddha Basantwani | 64db6d4 | 2023-02-01 16:24:19 +0530 | [diff] [blame] | 272 | GET_PARAMETER_SPECIFIC_FIELD(aidl, AutomaticGainControlV2, automaticGainControlV2, |
| 273 | AutomaticGainControlV2::fixedDigitalGainMb, int)); |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 274 | return VALUE_OR_RETURN(convertReinterpret<uint32_t>(gain)); |
| 275 | } |
| 276 | |
| 277 | ConversionResult<Parameter> legacy2aidl_uint32_fixedDigitalGain_Parameter_agc(uint32_t legacy) { |
| 278 | int gain = VALUE_OR_RETURN(convertReinterpret<int>(legacy)); |
Shraddha Basantwani | 64db6d4 | 2023-02-01 16:24:19 +0530 | [diff] [blame] | 279 | return MAKE_SPECIFIC_PARAMETER(AutomaticGainControlV2, automaticGainControlV2, |
| 280 | fixedDigitalGainMb, gain); |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_levelEstimator( |
| 284 | const Parameter& aidl) { |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 285 | const auto& le = VALUE_OR_RETURN(GET_PARAMETER_SPECIFIC_FIELD( |
Shraddha Basantwani | 64db6d4 | 2023-02-01 16:24:19 +0530 | [diff] [blame] | 286 | aidl, AutomaticGainControlV2, automaticGainControlV2, |
| 287 | AutomaticGainControlV2::levelEstimator, AutomaticGainControlV2::LevelEstimator)); |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 288 | return static_cast<uint32_t>(le); |
| 289 | } |
| 290 | |
| 291 | ConversionResult<Parameter> legacy2aidl_uint32_levelEstimator_Parameter_agc(uint32_t legacy) { |
Shraddha Basantwani | 64db6d4 | 2023-02-01 16:24:19 +0530 | [diff] [blame] | 292 | if (legacy > (uint32_t)AutomaticGainControlV2::LevelEstimator::PEAK) { |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 293 | return unexpected(BAD_VALUE); |
| 294 | } |
Shraddha Basantwani | 64db6d4 | 2023-02-01 16:24:19 +0530 | [diff] [blame] | 295 | AutomaticGainControlV2::LevelEstimator le = |
| 296 | static_cast<AutomaticGainControlV2::LevelEstimator>(legacy); |
| 297 | return MAKE_SPECIFIC_PARAMETER(AutomaticGainControlV2, automaticGainControlV2, levelEstimator, |
| 298 | le); |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_saturationMargin( |
| 302 | const Parameter& aidl) { |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 303 | int saturationMargin = VALUE_OR_RETURN( |
Shraddha Basantwani | 64db6d4 | 2023-02-01 16:24:19 +0530 | [diff] [blame] | 304 | GET_PARAMETER_SPECIFIC_FIELD(aidl, AutomaticGainControlV2, automaticGainControlV2, |
| 305 | AutomaticGainControlV2::saturationMarginMb, int)); |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 306 | return VALUE_OR_RETURN(convertIntegral<uint32_t>(saturationMargin)); |
| 307 | } |
| 308 | |
| 309 | ConversionResult<Parameter> legacy2aidl_uint32_saturationMargin_Parameter_agc(uint32_t legacy) { |
| 310 | int saturationMargin = VALUE_OR_RETURN(convertIntegral<int>(legacy)); |
Shraddha Basantwani | 64db6d4 | 2023-02-01 16:24:19 +0530 | [diff] [blame] | 311 | return MAKE_SPECIFIC_PARAMETER(AutomaticGainControlV2, automaticGainControlV2, |
| 312 | saturationMarginMb, saturationMargin); |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | ConversionResult<uint16_t> aidl2legacy_Parameter_BassBoost_uint16_strengthPm( |
| 316 | const Parameter& aidl) { |
| 317 | int strength = VALUE_OR_RETURN( |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 318 | GET_PARAMETER_SPECIFIC_FIELD(aidl, BassBoost, bassBoost, BassBoost::strengthPm, int)); |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 319 | return VALUE_OR_RETURN(convertIntegral<uint16_t>(strength)); |
| 320 | } |
| 321 | |
| 322 | ConversionResult<Parameter> legacy2aidl_uint16_strengthPm_Parameter_BassBoost(uint16_t legacy) { |
| 323 | int strength = VALUE_OR_RETURN(convertIntegral<int>(legacy)); |
| 324 | return MAKE_SPECIFIC_PARAMETER(BassBoost, bassBoost, strengthPm, strength); |
| 325 | } |
| 326 | |
| 327 | ConversionResult<int16_t> aidl2legacy_Parameter_Downmix_int16_type(const Parameter& aidl) { |
| 328 | Downmix::Type aidlType = VALUE_OR_RETURN( |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 329 | GET_PARAMETER_SPECIFIC_FIELD(aidl, Downmix, downmix, Downmix::type, Downmix::Type)); |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 330 | return VALUE_OR_RETURN(convertIntegral<int16_t>(static_cast<uint32_t>(aidlType))); |
| 331 | } |
| 332 | |
| 333 | ConversionResult<Parameter> legacy2aidl_int16_type_Parameter_Downmix(int16_t legacy) { |
| 334 | if (legacy > (uint32_t) Downmix::Type::FOLD) { |
| 335 | return unexpected(BAD_VALUE); |
| 336 | } |
| 337 | Downmix::Type aidlType = static_cast<Downmix::Type>(legacy); |
| 338 | return MAKE_SPECIFIC_PARAMETER(Downmix, downmix, type, aidlType); |
| 339 | } |
| 340 | |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 341 | ConversionResult<int16_t> aidl2legacy_DynamicsProcessing_ResolutionPreference_uint32_( |
| 342 | const Parameter& aidl) { |
| 343 | Downmix::Type aidlType = VALUE_OR_RETURN( |
| 344 | GET_PARAMETER_SPECIFIC_FIELD(aidl, Downmix, downmix, Downmix::type, Downmix::Type)); |
| 345 | return VALUE_OR_RETURN(convertIntegral<int16_t>(static_cast<uint32_t>(aidlType))); |
| 346 | } |
| 347 | |
| 348 | ConversionResult<DynamicsProcessing::ResolutionPreference> |
| 349 | legacy2aidl_int32_DynamicsProcessing_ResolutionPreference(int32_t legacy) { |
| 350 | if (legacy > (int32_t)DynamicsProcessing::ResolutionPreference::FAVOR_TIME_RESOLUTION) { |
| 351 | return unexpected(BAD_VALUE); |
| 352 | } |
| 353 | return static_cast<DynamicsProcessing::ResolutionPreference>(legacy); |
| 354 | } |
| 355 | |
| 356 | ConversionResult<int32_t> aidl2legacy_DynamicsProcessing_ResolutionPreference_int32( |
| 357 | DynamicsProcessing::ResolutionPreference aidl) { |
| 358 | return static_cast<int32_t>(aidl); |
| 359 | } |
| 360 | |
Shunkai Yao | 04b073a | 2023-02-17 06:17:12 +0000 | [diff] [blame] | 361 | ConversionResult<uint32_t> aidl2legacy_Parameter_Visualizer_ScalingMode_uint32( |
| 362 | Visualizer::ScalingMode aidl) { |
| 363 | switch (aidl) { |
| 364 | case Visualizer::ScalingMode::NORMALIZED: { |
| 365 | return 0; |
| 366 | } |
| 367 | case Visualizer::ScalingMode::AS_PLAYED: { |
| 368 | return 1; |
| 369 | } |
| 370 | } |
| 371 | return unexpected(BAD_VALUE); |
| 372 | } |
| 373 | |
| 374 | ConversionResult<Visualizer::ScalingMode> legacy2aidl_Parameter_Visualizer_uint32_ScalingMode( |
| 375 | uint32_t legacy) { |
| 376 | if (legacy == 0) { |
| 377 | return Visualizer::ScalingMode::NORMALIZED; |
| 378 | } else if (legacy == 1) { |
| 379 | return Visualizer::ScalingMode::AS_PLAYED; |
| 380 | } else { |
| 381 | return unexpected(BAD_VALUE); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | ConversionResult<uint32_t> aidl2legacy_Parameter_Visualizer_MeasurementMode_uint32( |
| 386 | Visualizer::MeasurementMode aidl) { |
| 387 | switch (aidl) { |
| 388 | case Visualizer::MeasurementMode::NONE: { |
| 389 | return 0; |
| 390 | } |
| 391 | case Visualizer::MeasurementMode::PEAK_RMS: { |
| 392 | return 1; |
| 393 | } |
| 394 | } |
| 395 | return unexpected(BAD_VALUE); |
| 396 | } |
| 397 | |
| 398 | ConversionResult<Visualizer::MeasurementMode> |
| 399 | legacy2aidl_Parameter_Visualizer_uint32_MeasurementMode(uint32_t legacy) { |
| 400 | if (legacy == 0) { |
| 401 | return Visualizer::MeasurementMode::NONE; |
| 402 | } else if (legacy == 1) { |
| 403 | return Visualizer::MeasurementMode::PEAK_RMS; |
| 404 | } else { |
| 405 | return unexpected(BAD_VALUE); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Copy the entire effect_param_t to DefaultExtension::bytes. |
| 411 | */ |
| 412 | ConversionResult<Parameter> legacy2aidl_EffectParameterReader_ParameterExtension( |
| 413 | EffectParamReader& param) { |
| 414 | size_t len = param.getTotalSize(); |
| 415 | DefaultExtension ext; |
| 416 | ext.bytes.resize(len); |
| 417 | std::memcpy(ext.bytes.data(), ¶m.getEffectParam(), len); |
| 418 | |
| 419 | VendorExtension effectParam; |
| 420 | effectParam.extension.setParcelable(ext); |
| 421 | return UNION_MAKE(Parameter, specific, |
| 422 | UNION_MAKE(Parameter::Specific, vendorEffect, effectParam)); |
| 423 | } |
| 424 | |
| 425 | ConversionResult<std::vector<uint8_t>> aidl2legacy_ParameterExtension_vector_uint8( |
| 426 | const Parameter& param) { |
| 427 | VendorExtension effectParam = VALUE_OR_RETURN( |
| 428 | (::aidl::android::getParameterSpecific<Parameter, VendorExtension, |
| 429 | Parameter::Specific::vendorEffect>(param))); |
| 430 | std::optional<DefaultExtension> ext; |
| 431 | if (STATUS_OK != effectParam.extension.getParcelable(&ext) || !ext.has_value()) { |
| 432 | return unexpected(BAD_VALUE); |
| 433 | } |
| 434 | return ext.value().bytes; |
| 435 | } |
| 436 | |
| 437 | ConversionResult<::android::status_t> aidl2legacy_ParameterExtension_EffectParameterWriter( |
| 438 | const ::aidl::android::hardware::audio::effect::Parameter& aidl, |
| 439 | EffectParamWriter& legacy) { |
| 440 | const std::vector<uint8_t>& extBytes = VALUE_OR_RETURN_STATUS( |
| 441 | ::aidl::android::aidl2legacy_ParameterExtension_vector_uint8(aidl)); |
| 442 | if (legacy.getTotalSize() < extBytes.size()) { |
| 443 | legacy.setStatus(BAD_VALUE); |
| 444 | return unexpected(BAD_VALUE); |
| 445 | } |
| 446 | |
| 447 | // create a reader wrapper and read the content to legacy EffectParamWriter |
| 448 | EffectParamReader reader(*(effect_param_t*)extBytes.data()); |
| 449 | if (STATUS_OK != legacy.writeToValue(reader.getValueAddress(), reader.getValueSize())) { |
| 450 | legacy.setStatus(BAD_VALUE); |
| 451 | return unexpected(BAD_VALUE); |
| 452 | } |
| 453 | return STATUS_OK; |
| 454 | } |
| 455 | |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 456 | } // namespace android |
| 457 | } // aidl |