xref: /aosp_15_r20/frameworks/av/media/audioaidlconversion/include/media/AidlConversionEffect.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
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 #pragma once
18 
19 #include <android/binder_auto_utils.h>
20 #include <android/binder_manager.h>
21 #include <android/binder_process.h>
22 
23 /**
24  * Can only handle conversion between AIDL (NDK backend) and legacy type.
25  */
26 #include <hardware/audio_effect.h>
27 #include <media/AidlConversionUtil.h>
28 #include <system/audio_effect.h>
29 #include <system/audio_effects/audio_effects_utils.h>
30 
31 #include <aidl/android/hardware/audio/effect/IEffect.h>
32 
33 namespace aidl {
34 namespace android {
35 
36 template <typename P, typename T, typename P::Specific::Tag tag>
getParameterSpecific(const P & u)37 ConversionResult<T> getParameterSpecific(const P& u) {
38     const auto& spec = VALUE_OR_RETURN(UNION_GET(u, specific));
39     return unionGetField<typename P::Specific, tag>(spec);
40 }
41 
42 template <typename P, typename T, typename P::Specific::Tag tag, typename T::Tag field, typename F>
getParameterSpecificField(const P & u)43 ConversionResult<F> getParameterSpecificField(const P& u) {
44     const auto& spec =
45             VALUE_OR_RETURN((getParameterSpecific<std::decay_t<decltype(u)>, T, tag>(u)));
46     return VALUE_OR_RETURN((unionGetField<T, field>(spec)));
47 }
48 
49 #define GET_PARAMETER_SPECIFIC_FIELD(_u, _effect, _tag, _field, _fieldType)                      \
50     getParameterSpecificField<std::decay_t<decltype(_u)>, _effect,                               \
51                               aidl::android::hardware::audio::effect::Parameter::Specific::_tag, \
52                               _effect::_field, _fieldType>(_u)
53 
54 #define MAKE_SPECIFIC_PARAMETER(_spec, _tag, _field, _value)                                 \
55     UNION_MAKE(aidl::android::hardware::audio::effect::Parameter, specific,                  \
56                UNION_MAKE(aidl::android::hardware::audio::effect::Parameter::Specific, _tag, \
57                           UNION_MAKE(_spec, _field, _value)))
58 
59 #define MAKE_SPECIFIC_PARAMETER_ID(_spec, _tag, _field)                     \
60     UNION_MAKE(aidl::android::hardware::audio::effect::Parameter::Id, _tag, \
61                UNION_MAKE(_spec::Id, commonTag, _field))
62 
63 #define MAKE_EXTENSION_PARAMETER_ID(_effect, _tag, _field)                  \
64     UNION_MAKE(aidl::android::hardware::audio::effect::Parameter::Id, _tag, \
65                UNION_MAKE(_effect::Id, vendorExtensionTag, _field))
66 
67 #define VENDOR_EXTENSION_GET_AND_RETURN(_effect, _tag, _param)                                    \
68     {                                                                                             \
69         aidl::android::hardware::audio::effect::VendorExtension _extId = VALUE_OR_RETURN_STATUS(  \
70                 aidl::android::legacy2aidl_EffectParameterReader_VendorExtension(_param));        \
71         aidl::android::hardware::audio::effect::Parameter::Id _id =                               \
72                 MAKE_EXTENSION_PARAMETER_ID(_effect, _tag##Tag, _extId);                          \
73         aidl::android::hardware::audio::effect::Parameter _aidlParam;                             \
74         RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getParameter(_id, &_aidlParam))); \
75         return VALUE_OR_RETURN_STATUS(                                                            \
76                 aidl::android::aidl2legacy_Parameter_EffectParameterWriter(_aidlParam, _param));  \
77     }
78 
79 ConversionResult<uint32_t> aidl2legacy_Flags_Type_uint32(
80         ::aidl::android::hardware::audio::effect::Flags::Type type);
81 ConversionResult<uint32_t> aidl2legacy_Flags_Insert_uint32(
82         ::aidl::android::hardware::audio::effect::Flags::Insert insert);
83 ConversionResult<uint32_t> aidl2legacy_Flags_Volume_uint32(
84         ::aidl::android::hardware::audio::effect::Flags::Volume volume);
85 ConversionResult<uint32_t> aidl2legacy_Flags_HardwareAccelerator_uint32(
86         ::aidl::android::hardware::audio::effect::Flags::HardwareAccelerator hwAcceleratorMode);
87 ConversionResult<uint32_t> aidl2legacy_Flags_uint32(
88         const ::aidl::android::hardware::audio::effect::Flags aidl);
89 
90 ConversionResult<::aidl::android::hardware::audio::effect::Flags::Type>
91 legacy2aidl_uint32_Flags_Type(uint32_t legacy);
92 ConversionResult<::aidl::android::hardware::audio::effect::Flags::Insert>
93 legacy2aidl_uint32_Flags_Insert(uint32_t legacy);
94 ConversionResult<::aidl::android::hardware::audio::effect::Flags::Volume>
95 legacy2aidl_uint32_Flags_Volume(uint32_t legacy);
96 ConversionResult<::aidl::android::hardware::audio::effect::Flags::HardwareAccelerator>
97 legacy2aidl_uint32_Flags_HardwareAccelerator(uint32_t legacy);
98 ConversionResult<::aidl::android::hardware::audio::effect::Flags> legacy2aidl_uint32_Flags(
99         uint32_t hal);
100 
101 ConversionResult<effect_descriptor_t> aidl2legacy_Descriptor_effect_descriptor(
102         const ::aidl::android::hardware::audio::effect::Descriptor& aidl);
103 ConversionResult<::aidl::android::hardware::audio::effect::Descriptor>
104 legacy2aidl_effect_descriptor_Descriptor(const effect_descriptor_t& hal);
105 
106 ConversionResult<uint32_t> aidl2legacy_Parameter_aec_uint32_echoDelay(
107         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
108 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
109 legacy2aidl_uint32_echoDelay_Parameter_aec(uint32_t legacy);
110 
111 ConversionResult<uint32_t> aidl2legacy_Parameter_aec_uint32_mobileMode(
112         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
113 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
114 legacy2aidl_uint32_mobileMode_Parameter_aec(uint32_t legacy);
115 
116 ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_fixedDigitalGain(
117         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
118 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
119 legacy2aidl_uint32_fixedDigitalGain_Parameter_agc(uint32_t legacy);
120 
121 ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_levelEstimator(
122         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
123 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
124 legacy2aidl_uint32_levelEstimator_Parameter_agc(uint32_t legacy);
125 
126 ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_saturationMargin(
127         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
128 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
129 legacy2aidl_uint32_saturationMargin_Parameter_agc(uint32_t legacy);
130 
131 ConversionResult<uint16_t> aidl2legacy_Parameter_BassBoost_uint16_strengthPm(
132         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
133 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
134 legacy2aidl_uint16_strengthPm_Parameter_BassBoost(uint16_t legacy);
135 
136 ConversionResult<int16_t> aidl2legacy_Parameter_Downmix_int16_type(
137         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
138 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
139 legacy2aidl_int16_type_Parameter_Downmix(int16_t legacy);
140 
141 ConversionResult<::aidl::android::hardware::audio::effect::DynamicsProcessing::ResolutionPreference>
142 legacy2aidl_int32_DynamicsProcessing_ResolutionPreference(int32_t legacy);
143 ConversionResult<int32_t> aidl2legacy_DynamicsProcessing_ResolutionPreference_int32(
144         ::aidl::android::hardware::audio::effect::DynamicsProcessing::ResolutionPreference aidl);
145 
146 ConversionResult<uint32_t> aidl2legacy_Parameter_Visualizer_ScalingMode_uint32(
147         ::aidl::android::hardware::audio::effect::Visualizer::ScalingMode aidl);
148 ConversionResult<::aidl::android::hardware::audio::effect::Visualizer::ScalingMode>
149 legacy2aidl_Parameter_Visualizer_uint32_ScalingMode(uint32_t legacy);
150 
151 ConversionResult<uint32_t> aidl2legacy_Parameter_Visualizer_MeasurementMode_uint32(
152         ::aidl::android::hardware::audio::effect::Visualizer::MeasurementMode aidl);
153 ConversionResult<::aidl::android::hardware::audio::effect::Visualizer::MeasurementMode>
154 legacy2aidl_Parameter_Visualizer_uint32_MeasurementMode(uint32_t legacy);
155 
156 /**
157  * Read DefaultExtension from VendorExtension, and overwrite to the entire effect_param_t (both
158  * parameter and data area) with EffectParamWriter::overwrite.
159  */
160 ConversionResult<::android::status_t> aidl2legacy_VendorExtension_EffectParameterWriter_Data(
161         ::android::effect::utils::EffectParamWriter& param,
162         ::aidl::android::hardware::audio::effect::VendorExtension ext);
163 /**
164  * Copy the entire effect_param_t (both parameter and data area) to DefaultExtension::bytes, and
165  * write into VendorExtension.
166  */
167 ConversionResult<::aidl::android::hardware::audio::effect::VendorExtension>
168 legacy2aidl_EffectParameterReader_VendorExtension(
169         ::android::effect::utils::EffectParamReader& param);
170 
171 ConversionResult<::android::status_t> aidl2legacy_Parameter_EffectParameterWriter(
172         const ::aidl::android::hardware::audio::effect::Parameter& aidl,
173         ::android::effect::utils::EffectParamWriter& legacy);
174 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
175 legacy2aidl_EffectParameterReader_Parameter(
176         ::android::effect::utils::EffectParamReader& param);
177 }  // namespace android
178 }  // namespace aidl
179