blob: 1cf2c73003ecf37efdb5a0bc70d78e4603de9ffa [file] [log] [blame]
Shunkai Yaodba8ba32023-01-27 17:02:21 +00001/*
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 Yao6b857c92023-02-13 17:44:52 +000027#include <system/audio_effects/aidl_effects_utils.h>
Shunkai Yaodba8ba32023-01-27 17:02:21 +000028#include <system/audio_effects/effect_bassboost.h>
29
30#include <utils/Log.h>
31
32#include "AidlConversionBassBoost.h"
33
34namespace android {
35namespace effect {
36
37using ::aidl::android::convertIntegral;
Shunkai Yaoda4a6402023-03-03 19:38:17 +000038using ::aidl::android::getParameterSpecificField;
Shunkai Yaodba8ba32023-01-27 17:02:21 +000039using ::aidl::android::aidl_utils::statusTFromBinderStatus;
40using ::aidl::android::hardware::audio::effect::BassBoost;
41using ::aidl::android::hardware::audio::effect::Parameter;
Shunkai Yao6b857c92023-02-13 17:44:52 +000042using ::aidl::android::hardware::audio::effect::Range;
Shunkai Yaoda4a6402023-03-03 19:38:17 +000043using ::aidl::android::hardware::audio::effect::VendorExtension;
Shunkai Yaodba8ba32023-01-27 17:02:21 +000044using ::android::status_t;
45using utils::EffectParamReader;
46using utils::EffectParamWriter;
47
48status_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 Yaoda4a6402023-03-03 19:38:17 +000068 // 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 Yaodba8ba32023-01-27 17:02:21 +000073 }
74 }
75
76 return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
77}
78
79status_t AidlConversionBassBoost::getParameter(EffectParamWriter& param) {
Shunkai Yao242521c2023-01-29 18:08:09 +000080 uint32_t type = 0;
81 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) ||
Shunkai Yaodba8ba32023-01-27 17:02:21 +000082 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 Yaob84e8792023-02-21 18:04:26 +000090 uint16_t value;
Shunkai Yaodba8ba32023-01-27 17:02:21 +000091 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 Yao242521c2023-01-29 18:08:09 +000096 return param.writeToValue(&value);
Shunkai Yaodba8ba32023-01-27 17:02:21 +000097 }
98 case BASSBOOST_PARAM_STRENGTH_SUPPORTED: {
Shunkai Yao6b857c92023-02-13 17:44:52 +000099 // an invalid range indicates not setting support for this parameter
Shunkai Yaob84e8792023-02-21 18:04:26 +0000100 uint32_t value =
Shunkai Yao6b857c92023-02-13 17:44:52 +0000101 ::aidl::android::hardware::audio::effect::isRangeValid<Range::Tag::bassBoost>(
102 BassBoost::strengthPm, mDesc.capability);
Shunkai Yao242521c2023-01-29 18:08:09 +0000103 return param.writeToValue(&value);
Shunkai Yaodba8ba32023-01-27 17:02:21 +0000104 }
105 default: {
Shunkai Yaoda4a6402023-03-03 19:38:17 +0000106 VENDOR_EXTENSION_GET_AND_RETURN(BassBoost, bassBoost, param);
Shunkai Yaodba8ba32023-01-27 17:02:21 +0000107 }
108 }
Shunkai Yaodba8ba32023-01-27 17:02:21 +0000109}
110
111} // namespace effect
112} // namespace android