blob: 9ec593fb04804596285d8ca6898e4a9667d48f8e [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;
38using ::aidl::android::aidl_utils::statusTFromBinderStatus;
39using ::aidl::android::hardware::audio::effect::BassBoost;
40using ::aidl::android::hardware::audio::effect::Parameter;
Shunkai Yao6b857c92023-02-13 17:44:52 +000041using ::aidl::android::hardware::audio::effect::Range;
Shunkai Yaodba8ba32023-01-27 17:02:21 +000042using ::android::status_t;
43using utils::EffectParamReader;
44using utils::EffectParamWriter;
45
46status_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
74status_t AidlConversionBassBoost::getParameter(EffectParamWriter& param) {
Shunkai Yao242521c2023-01-29 18:08:09 +000075 uint32_t type = 0;
76 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) ||
Shunkai Yaodba8ba32023-01-27 17:02:21 +000077 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 Yaob84e8792023-02-21 18:04:26 +000085 uint16_t value;
Shunkai Yaodba8ba32023-01-27 17:02:21 +000086 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 Yao242521c2023-01-29 18:08:09 +000091 return param.writeToValue(&value);
Shunkai Yaodba8ba32023-01-27 17:02:21 +000092 }
93 case BASSBOOST_PARAM_STRENGTH_SUPPORTED: {
Shunkai Yao6b857c92023-02-13 17:44:52 +000094 // an invalid range indicates not setting support for this parameter
Shunkai Yaob84e8792023-02-21 18:04:26 +000095 uint32_t value =
Shunkai Yao6b857c92023-02-13 17:44:52 +000096 ::aidl::android::hardware::audio::effect::isRangeValid<Range::Tag::bassBoost>(
97 BassBoost::strengthPm, mDesc.capability);
Shunkai Yao242521c2023-01-29 18:08:09 +000098 return param.writeToValue(&value);
Shunkai Yaodba8ba32023-01-27 17:02:21 +000099 }
100 default: {
101 ALOGW("%s unknown param %s", __func__, param.toString().c_str());
102 return BAD_VALUE;
103 }
104 }
Shunkai Yaodba8ba32023-01-27 17:02:21 +0000105}
106
107} // namespace effect
108} // namespace android