blob: 17cedf72aa0b875826904547705cffb6efd43303 [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 "AidlConversionDownmix"
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_downmix.h>
28
29#include <system/audio_effect.h>
30#include <utils/Log.h>
31
32#include "AidlConversionDownmix.h"
33
34namespace android {
35namespace effect {
36
37using ::aidl::android::aidl_utils::statusTFromBinderStatus;
38using ::aidl::android::hardware::audio::effect::Downmix;
39using ::aidl::android::hardware::audio::effect::Parameter;
40using ::android::status_t;
41using utils::EffectParamReader;
42using utils::EffectParamWriter;
43
44status_t AidlConversionDownmix::setParameter(EffectParamReader& param) {
45 uint32_t type = 0;
46 int16_t value = 0;
47 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(int16_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 DOWNMIX_PARAM_TYPE: {
55 aidlParam = VALUE_OR_RETURN_STATUS(
56 aidl::android::legacy2aidl_int16_type_Parameter_Downmix(value));
57 break;
58 }
59 default: {
60 ALOGW("%s unknown param %s", __func__, param.toString().c_str());
61 return BAD_VALUE;
62 }
63 }
64
65 return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
66}
67
68status_t AidlConversionDownmix::getParameter(EffectParamWriter& param) {
69 int16_t value = 0;
70 uint32_t type = 0;
71 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) ||
72 OK != param.readFromParameter(&type)) {
73 param.setStatus(BAD_VALUE);
74 return BAD_VALUE;
75 }
76 Parameter aidlParam;
77 switch (type) {
78 case DOWNMIX_PARAM_TYPE: {
79 Parameter::Id id = MAKE_SPECIFIC_PARAMETER_ID(Downmix, downmixTag, Downmix::type);
80 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam)));
81 value = VALUE_OR_RETURN_STATUS(
82 aidl::android::aidl2legacy_Parameter_Downmix_int16_type(aidlParam));
83 break;
84 }
85 default: {
86 ALOGW("%s unknown param %s", __func__, param.toString().c_str());
87 return BAD_VALUE;
88 }
89 }
90
91 return param.writeToValue(&value);
92}
93
94} // namespace effect
95} // namespace android