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