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 #include <type_traits>
21 #define LOG_TAG "AidlConversionVendorExtension"
22 //#define LOG_NDEBUG 0
23
24 #include <aidl/android/hardware/audio/effect/DefaultExtension.h>
25 #include <aidl/android/hardware/audio/effect/VendorExtension.h>
26 #include <error/expected_utils.h>
27 #include <media/AidlConversionNdk.h>
28 #include <media/AidlConversionEffect.h>
29
30 #include <utils/Log.h>
31
32 #include "AidlConversionVendorExtension.h"
33
34 namespace android {
35 namespace effect {
36
37 using ::aidl::android::aidl_utils::statusTFromBinderStatus;
38 using ::aidl::android::hardware::audio::effect::DefaultExtension;
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
45 /**
46 * For all effect types we currently don't support, add a default extension implementation to use
47 * std::vector<uint8_t> to pass through all data in the format of effect_param_t (the data we got
48 * from libaudioclient for now).
49 * This logic will be removed after we adopt to same AIDL parameter union AIDL in libaudioclient,
50 * after that framework doesn't need to do any AIDL conversion, and the vendor extension can be
51 * pass down in Parameter as is.
52 */
setParameter(EffectParamReader & param)53 status_t AidlConversionVendorExtension::setParameter(EffectParamReader& param) {
54 Parameter aidlParam = VALUE_OR_RETURN_STATUS(
55 ::aidl::android::legacy2aidl_EffectParameterReader_Parameter(param));
56 return statusTFromBinderStatus(mEffect->setParameter(aidlParam));
57 }
58
getParameter(EffectParamWriter & param)59 status_t AidlConversionVendorExtension::getParameter(EffectParamWriter& param) {
60 VendorExtension extId = VALUE_OR_RETURN_STATUS(
61 aidl::android::legacy2aidl_EffectParameterReader_VendorExtension(param));
62 Parameter::Id id = UNION_MAKE(Parameter::Id, vendorEffectTag, extId);
63 Parameter aidlParam;
64 RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(id, &aidlParam)));
65 // copy the AIDL extension data back to effect_param_t
66 return VALUE_OR_RETURN_STATUS(
67 ::aidl::android::aidl2legacy_Parameter_EffectParameterWriter(aidlParam, param));
68 }
69
70 } // namespace effect
71 } // namespace android
72