blob: 3e9bf4be936a3aaa878054c7e781ba1bbecef648 [file] [log] [blame]
Shunkai Yao242521c2023-01-29 18:08:09 +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 "AidlConversionPresetReverb"
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_presetreverb.h>
28
29#include <utils/Log.h>
30
31#include "AidlConversionPresetReverb.h"
32
33namespace android {
34namespace effect {
35
36using ::aidl::android::convertIntegral;
37using ::aidl::android::getParameterSpecificField;
38using ::aidl::android::aidl_utils::statusTFromBinderStatus;
39using ::aidl::android::hardware::audio::effect::Parameter;
40using ::aidl::android::hardware::audio::effect::PresetReverb;
41using ::android::status_t;
42using utils::EffectParamReader;
43using utils::EffectParamWriter;
44
45status_t AidlConversionPresetReverb::setParameter(EffectParamReader& param) {
46 uint32_t type = 0;
47 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) ||
48 OK != param.readFromParameter(&type)) {
49 ALOGE("%s invalid param %s", __func__, param.toString().c_str());
50 return BAD_VALUE;
51 }
52 Parameter aidlParam;
53 if (type == REVERB_PARAM_PRESET) {
54 uint16_t value = 0;
55 if (OK != param.readFromValue(&value)) {
56 ALOGE("%s invalid preset value %s", __func__, param.toString().c_str());
57 return BAD_VALUE;
58 }
59 aidlParam = MAKE_SPECIFIC_PARAMETER(PresetReverb, presetReverb, preset,
60 static_cast<PresetReverb::Presets>(value));
61 } else {
62 // handle vendor extension
63 }
64
65 return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
66}
67
68status_t AidlConversionPresetReverb::getParameter(EffectParamWriter& param) {
69 uint32_t type = 0;
70 uint16_t value = 0;
71 ALOGE("%s enter %s", __func__, param.toString().c_str());
72 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) ||
73 OK != param.readFromParameter(&type)) {
74 ALOGE("%s invalid param %s", __func__, param.toString().c_str());
75 param.setStatus(BAD_VALUE);
76 return BAD_VALUE;
77 }
78 if (type == REVERB_PARAM_PRESET) {
79 Parameter aidlParam;
80 Parameter::Id id =
81 MAKE_SPECIFIC_PARAMETER_ID(PresetReverb, presetReverbTag, PresetReverb::preset);
82 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam)));
83 auto aidlPreset = VALUE_OR_RETURN_STATUS(
84 GET_PARAMETER_SPECIFIC_FIELD(aidlParam, PresetReverb, presetReverb,
85 PresetReverb::preset, PresetReverb::Presets));
86 value = static_cast<uint16_t>(aidlPreset);
87 } else {
88 // handle vendor extension
89 }
90 return param.writeToValue(&value);
91}
92
93} // namespace effect
94} // namespace android