blob: 7bee37b8589116ce933f2e3eb454eaf1818ff3fd [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
Shunkai Yaoda4a6402023-03-03 19:38:17 +000037using ::aidl::android::getParameterSpecificField;
Shunkai Yaodba8ba32023-01-27 17:02:21 +000038using ::aidl::android::aidl_utils::statusTFromBinderStatus;
39using ::aidl::android::hardware::audio::effect::Downmix;
40using ::aidl::android::hardware::audio::effect::Parameter;
Shunkai Yaoda4a6402023-03-03 19:38:17 +000041using ::aidl::android::hardware::audio::effect::VendorExtension;
Shunkai Yaodba8ba32023-01-27 17:02:21 +000042using ::android::status_t;
43using utils::EffectParamReader;
44using utils::EffectParamWriter;
45
46status_t AidlConversionDownmix::setParameter(EffectParamReader& param) {
47 uint32_t type = 0;
48 int16_t value = 0;
49 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(int16_t)) ||
50 OK != param.readFromParameter(&type) || OK != param.readFromValue(&value)) {
51 ALOGE("%s invalid param %s", __func__, param.toString().c_str());
52 return BAD_VALUE;
53 }
54 Parameter aidlParam;
55 switch (type) {
56 case DOWNMIX_PARAM_TYPE: {
57 aidlParam = VALUE_OR_RETURN_STATUS(
58 aidl::android::legacy2aidl_int16_type_Parameter_Downmix(value));
59 break;
60 }
61 default: {
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(
64 aidl::android::legacy2aidl_EffectParameterReader_Data_VendorExtension(param));
65 aidlParam = MAKE_SPECIFIC_PARAMETER(Downmix, downmix, vendor, ext);
Shunkai Yaodba8ba32023-01-27 17:02:21 +000066 }
67 }
68
69 return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
70}
71
72status_t AidlConversionDownmix::getParameter(EffectParamWriter& param) {
73 int16_t value = 0;
74 uint32_t type = 0;
75 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) ||
76 OK != param.readFromParameter(&type)) {
77 param.setStatus(BAD_VALUE);
78 return BAD_VALUE;
79 }
80 Parameter aidlParam;
81 switch (type) {
82 case DOWNMIX_PARAM_TYPE: {
83 Parameter::Id id = MAKE_SPECIFIC_PARAMETER_ID(Downmix, downmixTag, Downmix::type);
84 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam)));
85 value = VALUE_OR_RETURN_STATUS(
86 aidl::android::aidl2legacy_Parameter_Downmix_int16_type(aidlParam));
87 break;
88 }
89 default: {
Shunkai Yaoda4a6402023-03-03 19:38:17 +000090 VENDOR_EXTENSION_GET_AND_RETURN(Downmix, downmix, param);
Shunkai Yaodba8ba32023-01-27 17:02:21 +000091 }
92 }
93
94 return param.writeToValue(&value);
95}
96
97} // namespace effect
98} // namespace android