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 "AidlConversionBassBoost" |
| 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> |
Shunkai Yao | 6b857c9 | 2023-02-13 17:44:52 +0000 | [diff] [blame] | 27 | #include <system/audio_effects/aidl_effects_utils.h> |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 28 | #include <system/audio_effects/effect_bassboost.h> |
| 29 | |
| 30 | #include <utils/Log.h> |
| 31 | |
| 32 | #include "AidlConversionBassBoost.h" |
| 33 | |
| 34 | namespace android { |
| 35 | namespace effect { |
| 36 | |
| 37 | using ::aidl::android::convertIntegral; |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 38 | using ::aidl::android::getParameterSpecificField; |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 39 | using ::aidl::android::aidl_utils::statusTFromBinderStatus; |
| 40 | using ::aidl::android::hardware::audio::effect::BassBoost; |
| 41 | using ::aidl::android::hardware::audio::effect::Parameter; |
Shunkai Yao | 6b857c9 | 2023-02-13 17:44:52 +0000 | [diff] [blame] | 42 | using ::aidl::android::hardware::audio::effect::Range; |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 43 | using ::aidl::android::hardware::audio::effect::VendorExtension; |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 44 | using ::android::status_t; |
| 45 | using utils::EffectParamReader; |
| 46 | using utils::EffectParamWriter; |
| 47 | |
| 48 | status_t AidlConversionBassBoost::setParameter(EffectParamReader& param) { |
| 49 | uint32_t type = 0; |
| 50 | uint16_t value = 0; |
| 51 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) || |
| 52 | OK != param.readFromParameter(&type) || OK != param.readFromValue(&value)) { |
| 53 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 54 | return BAD_VALUE; |
| 55 | } |
| 56 | Parameter aidlParam; |
| 57 | switch (type) { |
| 58 | case BASSBOOST_PARAM_STRENGTH: { |
| 59 | aidlParam = VALUE_OR_RETURN_STATUS( |
| 60 | aidl::android::legacy2aidl_uint16_strengthPm_Parameter_BassBoost(value)); |
| 61 | break; |
| 62 | } |
| 63 | case BASSBOOST_PARAM_STRENGTH_SUPPORTED: { |
| 64 | ALOGW("%s set BASSBOOST_PARAM_STRENGTH_SUPPORTED not supported", __func__); |
| 65 | return BAD_VALUE; |
| 66 | } |
| 67 | default: { |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 68 | // for vendor extension, copy data area to the DefaultExtension, parameter ignored |
| 69 | VendorExtension ext = VALUE_OR_RETURN_STATUS( |
| 70 | aidl::android::legacy2aidl_EffectParameterReader_Data_VendorExtension(param)); |
| 71 | aidlParam = MAKE_SPECIFIC_PARAMETER(BassBoost, bassBoost, vendor, ext); |
| 72 | break; |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | return statusTFromBinderStatus(mEffect->setParameter(aidlParam)); |
| 77 | } |
| 78 | |
| 79 | status_t AidlConversionBassBoost::getParameter(EffectParamWriter& param) { |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 80 | uint32_t type = 0; |
| 81 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) || |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 82 | OK != param.readFromParameter(&type)) { |
| 83 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 84 | param.setStatus(BAD_VALUE); |
| 85 | return BAD_VALUE; |
| 86 | } |
| 87 | Parameter aidlParam; |
| 88 | switch (type) { |
| 89 | case BASSBOOST_PARAM_STRENGTH: { |
Shunkai Yao | b84e879 | 2023-02-21 18:04:26 +0000 | [diff] [blame] | 90 | uint16_t value; |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 91 | Parameter::Id id = |
| 92 | MAKE_SPECIFIC_PARAMETER_ID(BassBoost, bassBoostTag, BassBoost::strengthPm); |
| 93 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 94 | value = VALUE_OR_RETURN_STATUS( |
| 95 | aidl::android::aidl2legacy_Parameter_BassBoost_uint16_strengthPm(aidlParam)); |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 96 | return param.writeToValue(&value); |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 97 | } |
| 98 | case BASSBOOST_PARAM_STRENGTH_SUPPORTED: { |
Shunkai Yao | 6b857c9 | 2023-02-13 17:44:52 +0000 | [diff] [blame] | 99 | // an invalid range indicates not setting support for this parameter |
Shunkai Yao | b84e879 | 2023-02-21 18:04:26 +0000 | [diff] [blame] | 100 | uint32_t value = |
Shunkai Yao | 6b857c9 | 2023-02-13 17:44:52 +0000 | [diff] [blame] | 101 | ::aidl::android::hardware::audio::effect::isRangeValid<Range::Tag::bassBoost>( |
| 102 | BassBoost::strengthPm, mDesc.capability); |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 103 | return param.writeToValue(&value); |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 104 | } |
| 105 | default: { |
Shunkai Yao | da4a640 | 2023-03-03 19:38:17 +0000 | [diff] [blame^] | 106 | VENDOR_EXTENSION_GET_AND_RETURN(BassBoost, bassBoost, param); |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 107 | } |
| 108 | } |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | } // namespace effect |
| 112 | } // namespace android |