blob: ba8148f77ee5c0e783148ca3d338b564a6177c14 [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>
27#include <system/audio_effects/effect_bassboost.h>
28
29#include <utils/Log.h>
30
31#include "AidlConversionBassBoost.h"
32
33namespace android {
34namespace effect {
35
36using ::aidl::android::convertIntegral;
37using ::aidl::android::aidl_utils::statusTFromBinderStatus;
38using ::aidl::android::hardware::audio::effect::BassBoost;
39using ::aidl::android::hardware::audio::effect::Parameter;
40using ::android::status_t;
41using utils::EffectParamReader;
42using utils::EffectParamWriter;
43
44status_t AidlConversionBassBoost::setParameter(EffectParamReader& param) {
45 uint32_t type = 0;
46 uint16_t value = 0;
47 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) ||
48 OK != param.readFromParameter(&type) || OK != param.readFromValue(&value)) {
49 ALOGE("%s invalid param %s", __func__, param.toString().c_str());
50 return BAD_VALUE;
51 }
52 Parameter aidlParam;
53 switch (type) {
54 case BASSBOOST_PARAM_STRENGTH: {
55 aidlParam = VALUE_OR_RETURN_STATUS(
56 aidl::android::legacy2aidl_uint16_strengthPm_Parameter_BassBoost(value));
57 break;
58 }
59 case BASSBOOST_PARAM_STRENGTH_SUPPORTED: {
60 ALOGW("%s set BASSBOOST_PARAM_STRENGTH_SUPPORTED not supported", __func__);
61 return BAD_VALUE;
62 }
63 default: {
64 ALOGW("%s unknown param %s", __func__, param.toString().c_str());
65 return BAD_VALUE;
66 }
67 }
68
69 return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
70}
71
72status_t AidlConversionBassBoost::getParameter(EffectParamWriter& param) {
73 uint32_t type = 0, value = 0;
74 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint32_t)) ||
75 OK != param.readFromParameter(&type)) {
76 ALOGE("%s invalid param %s", __func__, param.toString().c_str());
77 param.setStatus(BAD_VALUE);
78 return BAD_VALUE;
79 }
80 Parameter aidlParam;
81 switch (type) {
82 case BASSBOOST_PARAM_STRENGTH: {
83 Parameter::Id id =
84 MAKE_SPECIFIC_PARAMETER_ID(BassBoost, bassBoostTag, BassBoost::strengthPm);
85 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam)));
86 value = VALUE_OR_RETURN_STATUS(
87 aidl::android::aidl2legacy_Parameter_BassBoost_uint16_strengthPm(aidlParam));
88 break;
89 }
90 case BASSBOOST_PARAM_STRENGTH_SUPPORTED: {
91 const auto& cap =
92 VALUE_OR_RETURN_STATUS(aidl::android::UNION_GET(mDesc.capability, bassBoost));
93 value = VALUE_OR_RETURN_STATUS(convertIntegral<uint32_t>(cap.strengthSupported));
94 break;
95 }
96 default: {
97 ALOGW("%s unknown param %s", __func__, param.toString().c_str());
98 return BAD_VALUE;
99 }
100 }
101
102 return param.writeToValue(&value);
103}
104
105} // namespace effect
106} // namespace android