Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +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 "AidlConversionAgc2" |
| 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_agc2.h> |
| 28 | |
| 29 | #include <utils/Log.h> |
| 30 | |
| 31 | #include "AidlConversionAgc2.h" |
| 32 | |
| 33 | namespace android { |
| 34 | namespace effect { |
| 35 | |
| 36 | using ::aidl::android::aidl_utils::statusTFromBinderStatus; |
| 37 | using ::aidl::android::hardware::audio::effect::AutomaticGainControl; |
| 38 | using ::aidl::android::hardware::audio::effect::Parameter; |
| 39 | using ::android::status_t; |
| 40 | using utils::EffectParamReader; |
| 41 | using utils::EffectParamWriter; |
| 42 | |
| 43 | status_t AidlConversionAgc2::setParameter(EffectParamReader& param) { |
| 44 | uint32_t type = 0, value = 0; |
| 45 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint32_t)) || |
| 46 | OK != param.readFromParameter(&type) || OK != param.readFromValue(&value)) { |
| 47 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 48 | return BAD_VALUE; |
| 49 | } |
| 50 | Parameter aidlParam; |
| 51 | switch (type) { |
| 52 | case AGC2_PARAM_FIXED_DIGITAL_GAIN: { |
| 53 | aidlParam = VALUE_OR_RETURN_STATUS( |
| 54 | aidl::android::legacy2aidl_uint32_fixedDigitalGain_Parameter_agc(value)); |
| 55 | break; |
| 56 | } |
| 57 | case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR: { |
| 58 | aidlParam = VALUE_OR_RETURN_STATUS( |
| 59 | aidl::android::legacy2aidl_uint32_levelEstimator_Parameter_agc(value)); |
| 60 | break; |
| 61 | } |
| 62 | case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN: { |
| 63 | aidlParam = VALUE_OR_RETURN_STATUS( |
| 64 | aidl::android::legacy2aidl_uint32_saturationMargin_Parameter_agc(value)); |
| 65 | break; |
| 66 | } |
| 67 | default: { |
| 68 | ALOGW("%s unknown param %s", __func__, param.toString().c_str()); |
| 69 | return BAD_VALUE; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | return statusTFromBinderStatus(mEffect->setParameter(aidlParam)); |
| 74 | } |
| 75 | |
| 76 | status_t AidlConversionAgc2::getParameter(EffectParamWriter& param) { |
| 77 | uint32_t type = 0, value = 0; |
| 78 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint32_t)) || |
| 79 | OK != param.readFromParameter(&type)) { |
| 80 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 81 | return BAD_VALUE; |
| 82 | } |
| 83 | Parameter aidlParam; |
| 84 | switch (type) { |
| 85 | case AGC2_PARAM_FIXED_DIGITAL_GAIN: { |
| 86 | Parameter::Id id = |
| 87 | MAKE_SPECIFIC_PARAMETER_ID(AutomaticGainControl, automaticGainControlTag, |
| 88 | AutomaticGainControl::fixedDigitalGainMb); |
| 89 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 90 | value = VALUE_OR_RETURN_STATUS( |
| 91 | aidl::android::aidl2legacy_Parameter_agc_uint32_fixedDigitalGain(aidlParam)); |
| 92 | break; |
| 93 | } |
| 94 | case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR: { |
| 95 | Parameter::Id id = |
| 96 | MAKE_SPECIFIC_PARAMETER_ID(AutomaticGainControl, automaticGainControlTag, |
| 97 | AutomaticGainControl::levelEstimator); |
| 98 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 99 | value = VALUE_OR_RETURN_STATUS( |
| 100 | aidl::android::aidl2legacy_Parameter_agc_uint32_levelEstimator(aidlParam)); |
| 101 | break; |
| 102 | } |
| 103 | case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN: { |
| 104 | Parameter::Id id = |
| 105 | MAKE_SPECIFIC_PARAMETER_ID(AutomaticGainControl, automaticGainControlTag, |
| 106 | AutomaticGainControl::saturationMarginMb); |
| 107 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 108 | value = VALUE_OR_RETURN_STATUS( |
| 109 | aidl::android::aidl2legacy_Parameter_agc_uint32_saturationMargin(aidlParam)); |
| 110 | break; |
| 111 | } |
| 112 | default: { |
| 113 | ALOGW("%s unknown param %s", __func__, param.toString().c_str()); |
| 114 | return BAD_VALUE; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | return param.writeToValue(&value); |
| 119 | } |
| 120 | |
| 121 | } // namespace effect |
| 122 | } // namespace android |