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 "AidlConversionAec" |
| 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_aec.h> |
| 28 | |
| 29 | #include <utils/Log.h> |
| 30 | |
| 31 | #include "AidlConversionAec.h" |
| 32 | |
| 33 | namespace android { |
| 34 | namespace effect { |
| 35 | |
| 36 | using ::aidl::android::aidl_utils::statusTFromBinderStatus; |
| 37 | using ::aidl::android::hardware::audio::effect::AcousticEchoCanceler; |
| 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 AidlConversionAec::setParameter(EffectParamReader& param) { |
| 44 | uint32_t type, value = 0; |
| 45 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint32_t)) || |
| 46 | OK != param.readFromParameter(&type) || |
| 47 | OK != param.readFromValue(&value)) { |
| 48 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 49 | return BAD_VALUE; |
| 50 | } |
| 51 | |
| 52 | Parameter aidlParam; |
| 53 | switch (type) { |
| 54 | case AEC_PARAM_ECHO_DELAY: |
| 55 | FALLTHROUGH_INTENDED; |
| 56 | case AEC_PARAM_PROPERTIES: { |
| 57 | aidlParam = VALUE_OR_RETURN_STATUS( |
| 58 | aidl::android::legacy2aidl_uint32_echoDelay_Parameter_aec(value)); |
| 59 | break; |
| 60 | } |
| 61 | case AEC_PARAM_MOBILE_MODE: { |
| 62 | aidlParam = VALUE_OR_RETURN_STATUS( |
| 63 | aidl::android::legacy2aidl_uint32_mobileMode_Parameter_aec(value)); |
| 64 | break; |
| 65 | } |
| 66 | default: { |
| 67 | ALOGW("%s unknown param %s", __func__, param.toString().c_str()); |
| 68 | return BAD_VALUE; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | return statusTFromBinderStatus(mEffect->setParameter(aidlParam)); |
| 73 | } |
| 74 | |
| 75 | status_t AidlConversionAec::getParameter(EffectParamWriter& param) { |
| 76 | uint32_t type = 0, value = 0; |
| 77 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint32_t)) || |
| 78 | OK != param.readFromParameter(&type)) { |
| 79 | param.setStatus(BAD_VALUE); |
| 80 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 81 | return BAD_VALUE; |
| 82 | } |
| 83 | Parameter aidlParam; |
| 84 | switch (type) { |
| 85 | case AEC_PARAM_ECHO_DELAY: |
| 86 | FALLTHROUGH_INTENDED; |
| 87 | case AEC_PARAM_PROPERTIES: { |
| 88 | Parameter::Id id = |
| 89 | MAKE_SPECIFIC_PARAMETER_ID(AcousticEchoCanceler, acousticEchoCancelerTag, |
| 90 | AcousticEchoCanceler::echoDelayUs); |
| 91 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 92 | value = VALUE_OR_RETURN_STATUS( |
| 93 | aidl::android::aidl2legacy_Parameter_aec_uint32_echoDelay(aidlParam)); |
| 94 | break; |
| 95 | } |
| 96 | case AEC_PARAM_MOBILE_MODE: { |
| 97 | Parameter::Id id = |
| 98 | MAKE_SPECIFIC_PARAMETER_ID(AcousticEchoCanceler, acousticEchoCancelerTag, |
| 99 | AcousticEchoCanceler::mobileMode); |
| 100 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 101 | value = VALUE_OR_RETURN_STATUS( |
| 102 | aidl::android::aidl2legacy_Parameter_aec_uint32_mobileMode(aidlParam)); |
| 103 | break; |
| 104 | } |
| 105 | default: |
| 106 | ALOGW("%s unknown param %s", __func__, param.toString().c_str()); |
| 107 | return BAD_VALUE; |
| 108 | } |
| 109 | return param.writeToValue(&value); |
| 110 | } |
| 111 | |
| 112 | } // namespace effect |
| 113 | } // namespace android |