blob: 642c37003898fae9ad036292452d8e7249d8eced [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>
Shunkai Yao242521c2023-01-29 18:08:09 +000026#include <system/audio_effects/effect_presetreverb.h>
27
28#include <utils/Log.h>
29
30#include "AidlConversionPresetReverb.h"
31
32namespace android {
33namespace effect {
34
35using ::aidl::android::convertIntegral;
36using ::aidl::android::getParameterSpecificField;
37using ::aidl::android::aidl_utils::statusTFromBinderStatus;
38using ::aidl::android::hardware::audio::effect::Parameter;
39using ::aidl::android::hardware::audio::effect::PresetReverb;
Shunkai Yaoda4a6402023-03-03 19:38:17 +000040using ::aidl::android::hardware::audio::effect::VendorExtension;
Shunkai Yao242521c2023-01-29 18:08:09 +000041using ::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 {
Shunkai Yaoda4a6402023-03-03 19:38:17 +000062 // for vendor extension, copy data area to the DefaultExtension, parameter ignored
63 VendorExtension ext = VALUE_OR_RETURN_STATUS(
Shunkai Yaodbd06942023-06-29 18:07:09 +000064 aidl::android::legacy2aidl_EffectParameterReader_VendorExtension(param));
Shunkai Yaoda4a6402023-03-03 19:38:17 +000065 aidlParam = MAKE_SPECIFIC_PARAMETER(PresetReverb, presetReverb, vendor, ext);
Shunkai Yao242521c2023-01-29 18:08:09 +000066 }
67
68 return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
69}
70
71status_t AidlConversionPresetReverb::getParameter(EffectParamWriter& param) {
72 uint32_t type = 0;
73 uint16_t value = 0;
Shunkai Yao242521c2023-01-29 18:08:09 +000074 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_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 if (type == REVERB_PARAM_PRESET) {
81 Parameter aidlParam;
82 Parameter::Id id =
83 MAKE_SPECIFIC_PARAMETER_ID(PresetReverb, presetReverbTag, PresetReverb::preset);
84 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam)));
85 auto aidlPreset = VALUE_OR_RETURN_STATUS(
86 GET_PARAMETER_SPECIFIC_FIELD(aidlParam, PresetReverb, presetReverb,
87 PresetReverb::preset, PresetReverb::Presets));
88 value = static_cast<uint16_t>(aidlPreset);
89 } else {
90 // handle vendor extension
Shunkai Yaoda4a6402023-03-03 19:38:17 +000091 VENDOR_EXTENSION_GET_AND_RETURN(PresetReverb, presetReverb, param);
Shunkai Yao242521c2023-01-29 18:08:09 +000092 }
93 return param.writeToValue(&value);
94}
95
96} // namespace effect
97} // namespace android