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; |
| 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 | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 42 | using ::android::status_t; |
| 43 | using utils::EffectParamReader; |
| 44 | using utils::EffectParamWriter; |
| 45 | |
| 46 | status_t AidlConversionBassBoost::setParameter(EffectParamReader& param) { |
| 47 | uint32_t type = 0; |
| 48 | uint16_t value = 0; |
| 49 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) || |
| 50 | OK != param.readFromParameter(&type) || OK != param.readFromValue(&value)) { |
| 51 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 52 | return BAD_VALUE; |
| 53 | } |
| 54 | Parameter aidlParam; |
| 55 | switch (type) { |
| 56 | case BASSBOOST_PARAM_STRENGTH: { |
| 57 | aidlParam = VALUE_OR_RETURN_STATUS( |
| 58 | aidl::android::legacy2aidl_uint16_strengthPm_Parameter_BassBoost(value)); |
| 59 | break; |
| 60 | } |
| 61 | case BASSBOOST_PARAM_STRENGTH_SUPPORTED: { |
| 62 | ALOGW("%s set BASSBOOST_PARAM_STRENGTH_SUPPORTED not supported", __func__); |
| 63 | return BAD_VALUE; |
| 64 | } |
| 65 | default: { |
| 66 | ALOGW("%s unknown param %s", __func__, param.toString().c_str()); |
| 67 | return BAD_VALUE; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return statusTFromBinderStatus(mEffect->setParameter(aidlParam)); |
| 72 | } |
| 73 | |
| 74 | status_t AidlConversionBassBoost::getParameter(EffectParamWriter& param) { |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 75 | uint32_t type = 0; |
| 76 | if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) || |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 77 | OK != param.readFromParameter(&type)) { |
| 78 | ALOGE("%s invalid param %s", __func__, param.toString().c_str()); |
| 79 | param.setStatus(BAD_VALUE); |
| 80 | return BAD_VALUE; |
| 81 | } |
| 82 | Parameter aidlParam; |
| 83 | switch (type) { |
| 84 | case BASSBOOST_PARAM_STRENGTH: { |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 85 | uint32_t value; |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 86 | Parameter::Id id = |
| 87 | MAKE_SPECIFIC_PARAMETER_ID(BassBoost, bassBoostTag, BassBoost::strengthPm); |
| 88 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam))); |
| 89 | value = VALUE_OR_RETURN_STATUS( |
| 90 | aidl::android::aidl2legacy_Parameter_BassBoost_uint16_strengthPm(aidlParam)); |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 91 | return param.writeToValue(&value); |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 92 | } |
| 93 | case BASSBOOST_PARAM_STRENGTH_SUPPORTED: { |
Shunkai Yao | 6b857c9 | 2023-02-13 17:44:52 +0000 | [diff] [blame] | 94 | // an invalid range indicates not setting support for this parameter |
| 95 | uint16_t value = |
| 96 | ::aidl::android::hardware::audio::effect::isRangeValid<Range::Tag::bassBoost>( |
| 97 | BassBoost::strengthPm, mDesc.capability); |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 98 | return param.writeToValue(&value); |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 99 | } |
| 100 | default: { |
| 101 | ALOGW("%s unknown param %s", __func__, param.toString().c_str()); |
| 102 | return BAD_VALUE; |
| 103 | } |
| 104 | } |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | } // namespace effect |
| 108 | } // namespace android |