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 "AidlConversionNoiseSuppression" |
| 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_ns.h> |
| 28 | |
| 29 | #include <utils/Log.h> |
| 30 | |
| 31 | #include "AidlConversionNoiseSuppression.h" |
| 32 | |
| 33 | namespace android { |
| 34 | namespace effect { |
| 35 | |
Shunkai Yao | f6a5b17 | 2023-02-14 06:26:06 +0000 | [diff] [blame] | 36 | using ::aidl::android::getParameterSpecificField; |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 37 | using ::aidl::android::aidl_utils::statusTFromBinderStatus; |
Shunkai Yao | f6a5b17 | 2023-02-14 06:26:06 +0000 | [diff] [blame] | 38 | using ::aidl::android::hardware::audio::effect::NoiseSuppression; |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 39 | using ::aidl::android::hardware::audio::effect::Parameter; |
| 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 AidlConversionNoiseSuppression::setParameter(EffectParamReader& param) { |
Shunkai Yao | f6a5b17 | 2023-02-14 06:26:06 +0000 | [diff] [blame] | 46 | uint32_t type = 0, value = 0; |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 47 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_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; |
Shunkai Yao | f6a5b17 | 2023-02-14 06:26:06 +0000 | [diff] [blame] | 53 | switch (type) { |
| 54 | case NS_PARAM_LEVEL: { |
| 55 | aidlParam = MAKE_SPECIFIC_PARAMETER(NoiseSuppression, noiseSuppression, level, |
| 56 | static_cast<NoiseSuppression::Level>(value)); |
| 57 | break; |
| 58 | } |
| 59 | case NS_PARAM_TYPE: { |
| 60 | aidlParam = MAKE_SPECIFIC_PARAMETER(NoiseSuppression, noiseSuppression, type, |
| 61 | static_cast<NoiseSuppression::Type>(value)); |
| 62 | break; |
| 63 | } |
| 64 | default: { |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 65 | // for vendor extension, copy data area to the DefaultExtension, parameter ignored |
| 66 | VendorExtension ext = VALUE_OR_RETURN_STATUS( |
| 67 | aidl::android::legacy2aidl_EffectParameterReader_Data_VendorExtension(param)); |
| 68 | aidlParam = MAKE_SPECIFIC_PARAMETER(NoiseSuppression, noiseSuppression, vendor, ext); |
| 69 | break; |
Shunkai Yao | f6a5b17 | 2023-02-14 06:26:06 +0000 | [diff] [blame] | 70 | } |
| 71 | } |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 72 | return statusTFromBinderStatus(mEffect->setParameter(aidlParam)); |
| 73 | } |
| 74 | |
| 75 | status_t AidlConversionNoiseSuppression::getParameter(EffectParamWriter& param) { |
Shunkai Yao | f6a5b17 | 2023-02-14 06:26:06 +0000 | [diff] [blame] | 76 | uint32_t paramType = 0, value = 0; |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 77 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint32_t)) || |
Shunkai Yao | f6a5b17 | 2023-02-14 06:26:06 +0000 | [diff] [blame] | 78 | OK != param.readFromParameter(¶mType)) { |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 79 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 80 | param.setStatus(BAD_VALUE); |
| 81 | return BAD_VALUE; |
| 82 | } |
Shunkai Yao | f6a5b17 | 2023-02-14 06:26:06 +0000 | [diff] [blame] | 83 | Parameter aidlParam; |
| 84 | switch (paramType) { |
| 85 | case NS_PARAM_LEVEL: { |
| 86 | Parameter::Id id = MAKE_SPECIFIC_PARAMETER_ID(NoiseSuppression, noiseSuppressionTag, |
| 87 | NoiseSuppression::level); |
| 88 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 89 | NoiseSuppression::Level level = VALUE_OR_RETURN_STATUS( |
| 90 | GET_PARAMETER_SPECIFIC_FIELD(aidlParam, NoiseSuppression, noiseSuppression, |
| 91 | NoiseSuppression::level, NoiseSuppression::Level)); |
| 92 | value = static_cast<uint32_t>(level); |
| 93 | break; |
| 94 | } |
| 95 | case NS_PARAM_TYPE: { |
| 96 | Parameter::Id id = MAKE_SPECIFIC_PARAMETER_ID(NoiseSuppression, noiseSuppressionTag, |
| 97 | NoiseSuppression::type); |
| 98 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 99 | NoiseSuppression::Type nsType = VALUE_OR_RETURN_STATUS( |
| 100 | GET_PARAMETER_SPECIFIC_FIELD(aidlParam, NoiseSuppression, noiseSuppression, |
| 101 | NoiseSuppression::type, NoiseSuppression::Type)); |
| 102 | value = static_cast<uint32_t>(nsType); |
| 103 | break; |
| 104 | } |
| 105 | default: { |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 106 | VENDOR_EXTENSION_GET_AND_RETURN(NoiseSuppression, noiseSuppression, param); |
Shunkai Yao | f6a5b17 | 2023-02-14 06:26:06 +0000 | [diff] [blame] | 107 | } |
| 108 | } |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 109 | return param.writeToValue(&value); |
| 110 | } |
| 111 | |
| 112 | } // namespace effect |
| 113 | } // namespace android |