blob: f04c1187ffbde3f064c478332e419b3db9d821af [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;
Shunkai Yaoda4a6402023-03-03 19:38:17 +000041using ::aidl::android::hardware::audio::effect::VendorExtension;
Shunkai Yao242521c2023-01-29 18:08:09 +000042using ::android::status_t;
43using utils::EffectParamReader;
44using utils::EffectParamWriter;
45
46status_t AidlConversionPresetReverb::setParameter(EffectParamReader& param) {
47 uint32_t type = 0;
48 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) ||
49 OK != param.readFromParameter(&type)) {
50 ALOGE("%s invalid param %s", __func__, param.toString().c_str());
51 return BAD_VALUE;
52 }
53 Parameter aidlParam;
54 if (type == REVERB_PARAM_PRESET) {
55 uint16_t value = 0;
56 if (OK != param.readFromValue(&value)) {
57 ALOGE("%s invalid preset value %s", __func__, param.toString().c_str());
58 return BAD_VALUE;
59 }
60 aidlParam = MAKE_SPECIFIC_PARAMETER(PresetReverb, presetReverb, preset,
61 static_cast<PresetReverb::Presets>(value));
62 } else {
Shunkai Yaoda4a6402023-03-03 19:38:17 +000063 // for vendor extension, copy data area to the DefaultExtension, parameter ignored
64 VendorExtension ext = VALUE_OR_RETURN_STATUS(
65 aidl::android::legacy2aidl_EffectParameterReader_Data_VendorExtension(param));
66 aidlParam = MAKE_SPECIFIC_PARAMETER(PresetReverb, presetReverb, vendor, ext);
Shunkai Yao242521c2023-01-29 18:08:09 +000067 }
68
69 return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
70}
71
72status_t AidlConversionPresetReverb::getParameter(EffectParamWriter& param) {
73 uint32_t type = 0;
74 uint16_t value = 0;
75 ALOGE("%s enter %s", __func__, param.toString().c_str());
76 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) ||
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 if (type == REVERB_PARAM_PRESET) {
83 Parameter aidlParam;
84 Parameter::Id id =
85 MAKE_SPECIFIC_PARAMETER_ID(PresetReverb, presetReverbTag, PresetReverb::preset);
86 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam)));
87 auto aidlPreset = VALUE_OR_RETURN_STATUS(
88 GET_PARAMETER_SPECIFIC_FIELD(aidlParam, PresetReverb, presetReverb,
89 PresetReverb::preset, PresetReverb::Presets));
90 value = static_cast<uint16_t>(aidlPreset);
91 } else {
92 // handle vendor extension
Shunkai Yaoda4a6402023-03-03 19:38:17 +000093 VENDOR_EXTENSION_GET_AND_RETURN(PresetReverb, presetReverb, param);
Shunkai Yao242521c2023-01-29 18:08:09 +000094 }
95 return param.writeToValue(&value);
96}
97
98} // namespace effect
99} // namespace android