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