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 | |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 36 | using ::aidl::android::getParameterSpecificField; |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 37 | using ::aidl::android::aidl_utils::statusTFromBinderStatus; |
Shraddha Basantwani | 64db6d4 | 2023-02-01 16:24:19 +0530 | [diff] [blame] | 38 | using ::aidl::android::hardware::audio::effect::AutomaticGainControlV2; |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +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 | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 41 | using ::android::status_t; |
| 42 | using utils::EffectParamReader; |
| 43 | using utils::EffectParamWriter; |
| 44 | |
| 45 | status_t AidlConversionAgc2::setParameter(EffectParamReader& param) { |
| 46 | uint32_t type = 0, value = 0; |
| 47 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint32_t)) || |
| 48 | OK != param.readFromParameter(&type) || OK != param.readFromValue(&value)) { |
| 49 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 50 | return BAD_VALUE; |
| 51 | } |
| 52 | Parameter aidlParam; |
| 53 | switch (type) { |
| 54 | case AGC2_PARAM_FIXED_DIGITAL_GAIN: { |
| 55 | aidlParam = VALUE_OR_RETURN_STATUS( |
| 56 | aidl::android::legacy2aidl_uint32_fixedDigitalGain_Parameter_agc(value)); |
| 57 | break; |
| 58 | } |
| 59 | case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR: { |
| 60 | aidlParam = VALUE_OR_RETURN_STATUS( |
| 61 | aidl::android::legacy2aidl_uint32_levelEstimator_Parameter_agc(value)); |
| 62 | break; |
| 63 | } |
| 64 | case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN: { |
| 65 | aidlParam = VALUE_OR_RETURN_STATUS( |
| 66 | aidl::android::legacy2aidl_uint32_saturationMargin_Parameter_agc(value)); |
| 67 | break; |
| 68 | } |
| 69 | default: { |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 70 | // for vendor extension, copy data area to the DefaultExtension, parameter ignored |
| 71 | VendorExtension ext = VALUE_OR_RETURN_STATUS( |
| 72 | aidl::android::legacy2aidl_EffectParameterReader_Data_VendorExtension(param)); |
| 73 | aidlParam = MAKE_SPECIFIC_PARAMETER(AutomaticGainControlV2, automaticGainControlV2, |
| 74 | vendor, ext); |
| 75 | break; |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
| 79 | return statusTFromBinderStatus(mEffect->setParameter(aidlParam)); |
| 80 | } |
| 81 | |
| 82 | status_t AidlConversionAgc2::getParameter(EffectParamWriter& param) { |
| 83 | uint32_t type = 0, value = 0; |
| 84 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint32_t)) || |
| 85 | OK != param.readFromParameter(&type)) { |
| 86 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 87 | return BAD_VALUE; |
| 88 | } |
| 89 | Parameter aidlParam; |
| 90 | switch (type) { |
| 91 | case AGC2_PARAM_FIXED_DIGITAL_GAIN: { |
| 92 | Parameter::Id id = |
Shraddha Basantwani | 64db6d4 | 2023-02-01 16:24:19 +0530 | [diff] [blame] | 93 | MAKE_SPECIFIC_PARAMETER_ID(AutomaticGainControlV2, automaticGainControlV2Tag, |
| 94 | AutomaticGainControlV2::fixedDigitalGainMb); |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 95 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 96 | value = VALUE_OR_RETURN_STATUS( |
| 97 | aidl::android::aidl2legacy_Parameter_agc_uint32_fixedDigitalGain(aidlParam)); |
| 98 | break; |
| 99 | } |
| 100 | case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR: { |
| 101 | Parameter::Id id = |
Shraddha Basantwani | 64db6d4 | 2023-02-01 16:24:19 +0530 | [diff] [blame] | 102 | MAKE_SPECIFIC_PARAMETER_ID(AutomaticGainControlV2, automaticGainControlV2Tag, |
| 103 | AutomaticGainControlV2::levelEstimator); |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 104 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 105 | value = VALUE_OR_RETURN_STATUS( |
| 106 | aidl::android::aidl2legacy_Parameter_agc_uint32_levelEstimator(aidlParam)); |
| 107 | break; |
| 108 | } |
| 109 | case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN: { |
| 110 | Parameter::Id id = |
Shraddha Basantwani | 64db6d4 | 2023-02-01 16:24:19 +0530 | [diff] [blame] | 111 | MAKE_SPECIFIC_PARAMETER_ID(AutomaticGainControlV2, automaticGainControlV2Tag, |
| 112 | AutomaticGainControlV2::saturationMarginMb); |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 113 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 114 | value = VALUE_OR_RETURN_STATUS( |
| 115 | aidl::android::aidl2legacy_Parameter_agc_uint32_saturationMargin(aidlParam)); |
| 116 | break; |
| 117 | } |
| 118 | default: { |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 119 | VENDOR_EXTENSION_GET_AND_RETURN(AutomaticGainControlV2, automaticGainControlV2, param); |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
| 123 | return param.writeToValue(&value); |
| 124 | } |
| 125 | |
| 126 | } // namespace effect |
| 127 | } // namespace android |