Shunkai Yao | 242521c | 2023-01-29 18:08:09 +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 | |
| 17 | #include <cstdint> |
| 18 | #include <cstring> |
| 19 | #include <optional> |
| 20 | #define LOG_TAG "AidlConversionLoudnessEnhancer" |
| 21 | //#define LOG_NDEBUG 0 |
| 22 | |
| 23 | #include <error/expected_utils.h> |
| 24 | #include <media/AidlConversionNdk.h> |
| 25 | #include <media/AidlConversionEffect.h> |
| 26 | #include <media/audiohal/AudioEffectUuid.h> |
| 27 | #include <system/audio_effects/effect_loudnessenhancer.h> |
| 28 | |
| 29 | #include <utils/Log.h> |
| 30 | |
| 31 | #include "AidlConversionLoudnessEnhancer.h" |
| 32 | |
| 33 | namespace android { |
| 34 | namespace effect { |
| 35 | |
| 36 | using ::aidl::android::aidl_utils::statusTFromBinderStatus; |
Shunkai Yao | 96a7c01 | 2023-02-10 00:00:48 +0000 | [diff] [blame] | 37 | using ::aidl::android::getParameterSpecificField; |
| 38 | using ::aidl::android::hardware::audio::effect::LoudnessEnhancer; |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 39 | using ::aidl::android::hardware::audio::effect::Parameter; |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 40 | using ::aidl::android::hardware::audio::effect::VendorExtension; |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 41 | using ::android::status_t; |
| 42 | using utils::EffectParamReader; |
| 43 | using utils::EffectParamWriter; |
| 44 | |
| 45 | status_t AidlConversionLoudnessEnhancer::setParameter(EffectParamReader& param) { |
| 46 | uint32_t type = 0; |
Shunkai Yao | 96a7c01 | 2023-02-10 00:00:48 +0000 | [diff] [blame] | 47 | int32_t gain = 0; |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 48 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) || |
Shunkai Yao | 96a7c01 | 2023-02-10 00:00:48 +0000 | [diff] [blame] | 49 | OK != param.readFromParameter(&type) || OK != param.readFromValue(&gain)) { |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 50 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 51 | return BAD_VALUE; |
| 52 | } |
| 53 | Parameter aidlParam; |
Shunkai Yao | 96a7c01 | 2023-02-10 00:00:48 +0000 | [diff] [blame] | 54 | switch (type) { |
| 55 | case LOUDNESS_ENHANCER_PARAM_TARGET_GAIN_MB: { |
| 56 | aidlParam = MAKE_SPECIFIC_PARAMETER(LoudnessEnhancer, loudnessEnhancer, gainMb, gain); |
| 57 | break; |
| 58 | } |
| 59 | default: { |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 60 | // for vendor extension, copy data area to the DefaultExtension, parameter ignored |
| 61 | VendorExtension ext = VALUE_OR_RETURN_STATUS( |
| 62 | aidl::android::legacy2aidl_EffectParameterReader_Data_VendorExtension(param)); |
| 63 | aidlParam = MAKE_SPECIFIC_PARAMETER(LoudnessEnhancer, loudnessEnhancer, vendor, ext); |
| 64 | break; |
Shunkai Yao | 96a7c01 | 2023-02-10 00:00:48 +0000 | [diff] [blame] | 65 | } |
| 66 | } |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 67 | return statusTFromBinderStatus(mEffect->setParameter(aidlParam)); |
| 68 | } |
| 69 | |
| 70 | status_t AidlConversionLoudnessEnhancer::getParameter(EffectParamWriter& param) { |
Shunkai Yao | 96a7c01 | 2023-02-10 00:00:48 +0000 | [diff] [blame] | 71 | uint32_t type = 0; |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 72 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint32_t)) || |
| 73 | OK != param.readFromParameter(&type)) { |
| 74 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 75 | param.setStatus(BAD_VALUE); |
| 76 | return BAD_VALUE; |
| 77 | } |
Shunkai Yao | 96a7c01 | 2023-02-10 00:00:48 +0000 | [diff] [blame] | 78 | switch (type) { |
| 79 | case LOUDNESS_ENHANCER_PARAM_TARGET_GAIN_MB: { |
| 80 | Parameter aidlParam; |
| 81 | Parameter::Id id = MAKE_SPECIFIC_PARAMETER_ID(LoudnessEnhancer, loudnessEnhancerTag, |
| 82 | LoudnessEnhancer::gainMb); |
| 83 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 84 | int32_t gain = VALUE_OR_RETURN_STATUS(GET_PARAMETER_SPECIFIC_FIELD( |
| 85 | aidlParam, LoudnessEnhancer, loudnessEnhancer, LoudnessEnhancer::gainMb, |
| 86 | std::decay_t<decltype(gain)>)); |
| 87 | return param.writeToValue(&gain); |
| 88 | } |
| 89 | default: { |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 90 | VENDOR_EXTENSION_GET_AND_RETURN(LoudnessEnhancer, loudnessEnhancer, param); |
Shunkai Yao | 96a7c01 | 2023-02-10 00:00:48 +0000 | [diff] [blame] | 91 | } |
| 92 | } |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | } // namespace effect |
| 96 | } // namespace android |