• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         aidl::android::hardware::audio::effect::VendorExtension _ext =                            \
76                 VALUE_OR_RETURN_STATUS(GET_PARAMETER_SPECIFIC_FIELD(                              \
77                         _aidlParam, _effect, _tag, _effect::vendor, VendorExtension));            \
78         return VALUE_OR_RETURN_STATUS(                                                            \
79                 aidl::android::aidl2legacy_Parameter_EffectParameterWriter(_aidlParam, _param));  \
80     }
81 
82 ConversionResult<uint32_t> aidl2legacy_Flags_Type_uint32(
83         ::aidl::android::hardware::audio::effect::Flags::Type type);
84 ConversionResult<uint32_t> aidl2legacy_Flags_Insert_uint32(
85         ::aidl::android::hardware::audio::effect::Flags::Insert insert);
86 ConversionResult<uint32_t> aidl2legacy_Flags_Volume_uint32(
87         ::aidl::android::hardware::audio::effect::Flags::Volume volume);
88 ConversionResult<uint32_t> aidl2legacy_Flags_HardwareAccelerator_uint32(
89         ::aidl::android::hardware::audio::effect::Flags::HardwareAccelerator hwAcceleratorMode);
90 ConversionResult<uint32_t> aidl2legacy_Flags_uint32(
91         const ::aidl::android::hardware::audio::effect::Flags aidl);
92 
93 ConversionResult<::aidl::android::hardware::audio::effect::Flags::Type>
94 legacy2aidl_uint32_Flags_Type(uint32_t legacy);
95 ConversionResult<::aidl::android::hardware::audio::effect::Flags::Insert>
96 legacy2aidl_uint32_Flags_Insert(uint32_t legacy);
97 ConversionResult<::aidl::android::hardware::audio::effect::Flags::Volume>
98 legacy2aidl_uint32_Flags_Volume(uint32_t legacy);
99 ConversionResult<::aidl::android::hardware::audio::effect::Flags::HardwareAccelerator>
100 legacy2aidl_uint32_Flags_HardwareAccelerator(uint32_t legacy);
101 ConversionResult<::aidl::android::hardware::audio::effect::Flags> legacy2aidl_uint32_Flags(
102         uint32_t hal);
103 
104 ConversionResult<effect_descriptor_t> aidl2legacy_Descriptor_effect_descriptor(
105         const ::aidl::android::hardware::audio::effect::Descriptor& aidl);
106 ConversionResult<::aidl::android::hardware::audio::effect::Descriptor>
107 legacy2aidl_effect_descriptor_Descriptor(const effect_descriptor_t& hal);
108 
109 ConversionResult<uint32_t> aidl2legacy_Parameter_aec_uint32_echoDelay(
110         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
111 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
112 legacy2aidl_uint32_echoDelay_Parameter_aec(uint32_t legacy);
113 
114 ConversionResult<uint32_t> aidl2legacy_Parameter_aec_uint32_mobileMode(
115         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
116 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
117 legacy2aidl_uint32_mobileMode_Parameter_aec(uint32_t legacy);
118 
119 ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_fixedDigitalGain(
120         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
121 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
122 legacy2aidl_uint32_fixedDigitalGain_Parameter_agc(uint32_t legacy);
123 
124 ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_levelEstimator(
125         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
126 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
127 legacy2aidl_uint32_levelEstimator_Parameter_agc(uint32_t legacy);
128 
129 ConversionResult<uint32_t> aidl2legacy_Parameter_agc_uint32_saturationMargin(
130         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
131 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
132 legacy2aidl_uint32_saturationMargin_Parameter_agc(uint32_t legacy);
133 
134 ConversionResult<uint16_t> aidl2legacy_Parameter_BassBoost_uint16_strengthPm(
135         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
136 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
137 legacy2aidl_uint16_strengthPm_Parameter_BassBoost(uint16_t legacy);
138 
139 ConversionResult<int16_t> aidl2legacy_Parameter_Downmix_int16_type(
140         const ::aidl::android::hardware::audio::effect::Parameter& aidl);
141 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
142 legacy2aidl_int16_type_Parameter_Downmix(int16_t legacy);
143 
144 ConversionResult<::aidl::android::hardware::audio::effect::DynamicsProcessing::ResolutionPreference>
145 legacy2aidl_int32_DynamicsProcessing_ResolutionPreference(int32_t legacy);
146 ConversionResult<int32_t> aidl2legacy_DynamicsProcessing_ResolutionPreference_int32(
147         ::aidl::android::hardware::audio::effect::DynamicsProcessing::ResolutionPreference aidl);
148 
149 ConversionResult<uint32_t> aidl2legacy_Parameter_Visualizer_ScalingMode_uint32(
150         ::aidl::android::hardware::audio::effect::Visualizer::ScalingMode aidl);
151 ConversionResult<::aidl::android::hardware::audio::effect::Visualizer::ScalingMode>
152 legacy2aidl_Parameter_Visualizer_uint32_ScalingMode(uint32_t legacy);
153 
154 ConversionResult<uint32_t> aidl2legacy_Parameter_Visualizer_MeasurementMode_uint32(
155         ::aidl::android::hardware::audio::effect::Visualizer::MeasurementMode aidl);
156 ConversionResult<::aidl::android::hardware::audio::effect::Visualizer::MeasurementMode>
157 legacy2aidl_Parameter_Visualizer_uint32_MeasurementMode(uint32_t legacy);
158 
159 /**
160  * Read DefaultExtension from VendorExtension, and overwrite to the entire effect_param_t (both
161  * parameter and data area) with EffectParamWriter::overwrite.
162  */
163 ConversionResult<::android::status_t> aidl2legacy_VendorExtension_EffectParameterWriter_Data(
164         ::android::effect::utils::EffectParamWriter& param,
165         ::aidl::android::hardware::audio::effect::VendorExtension ext);
166 /**
167  * Copy the entire effect_param_t (both parameter and data area) to DefaultExtension::bytes, and
168  * write into VendorExtension.
169  */
170 ConversionResult<::aidl::android::hardware::audio::effect::VendorExtension>
171 legacy2aidl_EffectParameterReader_VendorExtension(
172         ::android::effect::utils::EffectParamReader& param);
173 
174 ConversionResult<::android::status_t> aidl2legacy_Parameter_EffectParameterWriter(
175         const ::aidl::android::hardware::audio::effect::Parameter& aidl,
176         ::android::effect::utils::EffectParamWriter& legacy);
177 ConversionResult<::aidl::android::hardware::audio::effect::Parameter>
178 legacy2aidl_EffectParameterReader_Parameter(
179         ::android::effect::utils::EffectParamReader& param);
180 }  // namespace android
181 }  // namespace aidl
182