1 /*
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 <system/audio_effects/effect_downmix.h>
27
28 #include <system/audio_effect.h>
29 #include <utils/Log.h>
30
31 #include "AidlConversionDownmix.h"
32
33 namespace android {
34 namespace effect {
35
36 using ::aidl::android::getParameterSpecificField;
37 using ::aidl::android::aidl_utils::statusTFromBinderStatus;
38 using ::aidl::android::hardware::audio::effect::Downmix;
39 using ::aidl::android::hardware::audio::effect::Parameter;
40 using ::aidl::android::hardware::audio::effect::VendorExtension;
41 using ::android::status_t;
42 using utils::EffectParamReader;
43 using utils::EffectParamWriter;
44
setParameter(EffectParamReader & param)45 status_t AidlConversionDownmix::setParameter(EffectParamReader& param) {
46 uint32_t type = 0;
47 int16_t value = 0;
48 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(int16_t)) ||
49 OK != param.readFromParameter(&type) || OK != param.readFromValue(&value)) {
50 ALOGE("%s invalid param %s", __func__, param.toString().c_str());
51 return BAD_VALUE;
52 }
53 Parameter aidlParam;
54 switch (type) {
55 case DOWNMIX_PARAM_TYPE: {
56 aidlParam = VALUE_OR_RETURN_STATUS(
57 aidl::android::legacy2aidl_int16_type_Parameter_Downmix(value));
58 break;
59 }
60 default: {
61 // for vendor extension, copy data area to the DefaultExtension, parameter ignored
62 VendorExtension ext = VALUE_OR_RETURN_STATUS(
63 aidl::android::legacy2aidl_EffectParameterReader_VendorExtension(param));
64 aidlParam = MAKE_SPECIFIC_PARAMETER(Downmix, downmix, vendor, ext);
65 }
66 }
67
68 return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
69 }
70
getParameter(EffectParamWriter & param)71 status_t AidlConversionDownmix::getParameter(EffectParamWriter& param) {
72 int16_t value = 0;
73 uint32_t type = 0;
74 if (!param.validateParamValueSize(sizeof(uint32_t), sizeof(uint16_t)) ||
75 OK != param.readFromParameter(&type)) {
76 param.setStatus(BAD_VALUE);
77 return BAD_VALUE;
78 }
79 Parameter aidlParam;
80 switch (type) {
81 case DOWNMIX_PARAM_TYPE: {
82 Parameter::Id id = MAKE_SPECIFIC_PARAMETER_ID(Downmix, downmixTag, Downmix::type);
83 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam)));
84 value = VALUE_OR_RETURN_STATUS(
85 aidl::android::aidl2legacy_Parameter_Downmix_int16_type(aidlParam));
86 break;
87 }
88 default: {
89 VENDOR_EXTENSION_GET_AND_RETURN(Downmix, downmix, param);
90 }
91 }
92
93 return param.writeToValue(&value);
94 }
95
96 } // namespace effect
97 } // namespace android
98