Mikhail Naganov | 7cbf2f1 | 2016-10-27 20:05:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_Effect_H_ |
| 18 | #define HIDL_GENERATED_android_hardware_audio_effect_V2_0_Effect_H_ |
| 19 | |
| 20 | #include <vector> |
| 21 | |
| 22 | #include <android/hardware/audio/effect/2.0/IEffect.h> |
| 23 | #include <hidl/Status.h> |
| 24 | |
| 25 | #include <hidl/MQDescriptor.h> |
| 26 | |
| 27 | #include <hardware/audio_effect.h> |
| 28 | |
| 29 | namespace android { |
| 30 | namespace hardware { |
| 31 | namespace audio { |
| 32 | namespace effect { |
| 33 | namespace V2_0 { |
| 34 | namespace implementation { |
| 35 | |
| 36 | using ::android::hardware::audio::common::V2_0::AudioDevice; |
| 37 | using ::android::hardware::audio::common::V2_0::AudioMode; |
| 38 | using ::android::hardware::audio::common::V2_0::AudioSource; |
| 39 | using ::android::hardware::audio::common::V2_0::Uuid; |
| 40 | using ::android::hardware::audio::effect::V2_0::AudioBuffer; |
| 41 | using ::android::hardware::audio::effect::V2_0::EffectAuxChannelsConfig; |
| 42 | using ::android::hardware::audio::effect::V2_0::EffectConfig; |
| 43 | using ::android::hardware::audio::effect::V2_0::EffectDescriptor; |
| 44 | using ::android::hardware::audio::effect::V2_0::EffectFeature; |
| 45 | using ::android::hardware::audio::effect::V2_0::EffectOffloadParameter; |
| 46 | using ::android::hardware::audio::effect::V2_0::IEffect; |
| 47 | using ::android::hardware::audio::effect::V2_0::IEffectBufferProviderCallback; |
| 48 | using ::android::hardware::audio::effect::V2_0::Result; |
| 49 | using ::android::hardware::Return; |
| 50 | using ::android::hardware::Void; |
| 51 | using ::android::hardware::hidl_vec; |
| 52 | using ::android::hardware::hidl_string; |
| 53 | using ::android::sp; |
| 54 | |
| 55 | struct Effect : public IEffect { |
| 56 | explicit Effect(effect_handle_t handle); |
| 57 | |
| 58 | // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. |
| 59 | Return<Result> init() override; |
| 60 | Return<Result> setConfig( |
| 61 | const EffectConfig& config, |
| 62 | const sp<IEffectBufferProviderCallback>& inputBufferProvider, |
| 63 | const sp<IEffectBufferProviderCallback>& outputBufferProvider) override; |
| 64 | Return<Result> reset() override; |
| 65 | Return<Result> enable() override; |
| 66 | Return<Result> disable() override; |
| 67 | Return<Result> setDevice(AudioDevice device) override; |
| 68 | Return<void> setAndGetVolume( |
| 69 | const hidl_vec<uint32_t>& volumes, setAndGetVolume_cb _hidl_cb) override; |
| 70 | Return<Result> setAudioMode(AudioMode mode) override; |
| 71 | Return<Result> setConfigReverse( |
| 72 | const EffectConfig& config, |
| 73 | const sp<IEffectBufferProviderCallback>& inputBufferProvider, |
| 74 | const sp<IEffectBufferProviderCallback>& outputBufferProvider) override; |
| 75 | Return<Result> setInputDevice(AudioDevice device) override; |
| 76 | Return<void> getConfig(getConfig_cb _hidl_cb) override; |
| 77 | Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override; |
| 78 | Return<void> getSupportedAuxChannelsConfigs( |
| 79 | uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; |
| 80 | Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; |
| 81 | Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; |
| 82 | Return<Result> setAudioSource(AudioSource source) override; |
| 83 | Return<Result> offload(const EffectOffloadParameter& param) override; |
| 84 | Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override; |
| 85 | Return<void> process( |
| 86 | const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; |
| 87 | Return<void> processReverse( |
| 88 | const AudioBuffer& inBuffer, |
| 89 | uint32_t outFrameSize, |
| 90 | processReverse_cb _hidl_cb) override; |
| 91 | Return<void> command( |
| 92 | uint32_t commandId, |
| 93 | const hidl_vec<uint8_t>& data, |
| 94 | uint32_t resultMaxSize, |
| 95 | command_cb _hidl_cb) override; |
| 96 | Return<Result> setParameter( |
| 97 | const hidl_vec<uint8_t>& parameter, const hidl_vec<uint8_t>& value) override; |
| 98 | Return<void> getParameter( |
| 99 | const hidl_vec<uint8_t>& parameter, |
| 100 | uint32_t valueMaxSize, |
| 101 | getParameter_cb _hidl_cb) override; |
| 102 | Return<void> getSupportedConfigsForFeature( |
| 103 | uint32_t featureId, |
| 104 | uint32_t maxConfigs, |
| 105 | uint32_t configSize, |
| 106 | getSupportedConfigsForFeature_cb _hidl_cb) override; |
| 107 | Return<void> getCurrentConfigForFeature( |
| 108 | uint32_t featureId, |
| 109 | uint32_t configSize, |
| 110 | getCurrentConfigForFeature_cb _hidl_cb) override; |
| 111 | Return<Result> setCurrentConfigForFeature( |
| 112 | uint32_t featureId, const hidl_vec<uint8_t>& configData) override; |
| 113 | |
| 114 | // Utility methods for extending interfaces. |
| 115 | template<typename T> Return<void> getIntegerParam( |
| 116 | uint32_t paramId, std::function<void(Result retval, T paramValue)> cb) { |
| 117 | T value; |
| 118 | Result retval = getParameterImpl( |
| 119 | sizeof(uint32_t), ¶mId, |
| 120 | sizeof(T), |
| 121 | [&] (uint32_t valueSize, const void* valueData) { |
| 122 | if (valueSize > sizeof(T)) valueSize = sizeof(T); |
| 123 | memcpy(&value, valueData, valueSize); |
| 124 | }); |
| 125 | cb(retval, value); |
| 126 | return Void(); |
| 127 | } |
| 128 | |
| 129 | template<typename T> Result getParam(uint32_t paramId, T& paramValue) { |
| 130 | return getParameterImpl( |
| 131 | sizeof(uint32_t), ¶mId, |
| 132 | sizeof(T), |
| 133 | [&] (uint32_t valueSize, const void* valueData) { |
| 134 | if (valueSize > sizeof(T)) valueSize = sizeof(T); |
| 135 | memcpy(¶mValue, valueData, valueSize); |
| 136 | }); |
| 137 | } |
| 138 | |
| 139 | template<typename T> Result getParam(uint32_t paramId, uint32_t paramArg, T& paramValue) { |
| 140 | uint32_t params[2] = { paramId, paramArg }; |
| 141 | return getParameterImpl( |
| 142 | sizeof(params), params, |
| 143 | sizeof(T), |
| 144 | [&] (uint32_t valueSize, const void* valueData) { |
| 145 | if (valueSize > sizeof(T)) valueSize = sizeof(T); |
| 146 | memcpy(¶mValue, valueData, valueSize); |
| 147 | }); |
| 148 | } |
| 149 | |
| 150 | template<typename T> Result setParam(uint32_t paramId, const T& paramValue) { |
| 151 | return setParameterImpl(sizeof(uint32_t), ¶mId, sizeof(T), ¶mValue); |
| 152 | } |
| 153 | |
| 154 | template<typename T> Result setParam(uint32_t paramId, uint32_t paramArg, const T& paramValue) { |
| 155 | uint32_t params[2] = { paramId, paramArg }; |
| 156 | return setParameterImpl(sizeof(params), params, sizeof(T), ¶mValue); |
| 157 | } |
| 158 | |
| 159 | private: |
| 160 | friend struct VirtualizerEffect; // for getParameterImpl |
| 161 | friend struct VisualizerEffect; // to allow executing commands |
| 162 | |
| 163 | typedef int32_t (*ProcessFunction)( |
| 164 | effect_handle_t self, audio_buffer_t* inBuffer, audio_buffer_t* outBuffer); |
| 165 | using CommandSuccessCallback = std::function<void()>; |
| 166 | using GetConfigCallback = std::function<void(Result retval, const EffectConfig& config)>; |
| 167 | using GetCurrentConfigSuccessCallback = std::function<void(void* configData)>; |
| 168 | using GetParameterSuccessCallback = |
| 169 | std::function<void(uint32_t valueSize, const void* valueData)>; |
| 170 | using GetSupportedConfigsSuccessCallback = |
| 171 | std::function<void(uint32_t supportedConfigs, void* configsData)>; |
| 172 | using ProcessCallback = std::function<void(Result retval, const AudioBuffer& outBuffer)>; |
| 173 | |
| 174 | static const char *sContextResultOfCommand; |
| 175 | static const char *sContextCallToCommand; |
| 176 | static const char *sContextCallFunction; |
| 177 | |
| 178 | effect_handle_t mHandle; |
| 179 | |
| 180 | virtual ~Effect(); |
| 181 | |
| 182 | template<typename T> static size_t alignedSizeIn(size_t s); |
| 183 | template<typename T> static void hidlVecToHal( |
| 184 | const hidl_vec<T>& vec, uint32_t* halDataSize, void** halData); |
| 185 | static void effectAuxChannelsConfigFromHal( |
| 186 | const channel_config_t& halConfig, EffectAuxChannelsConfig* config); |
| 187 | static void effectAuxChannelsConfigToHal( |
| 188 | const EffectAuxChannelsConfig& config, channel_config_t* halConfig); |
| 189 | static void effectBufferConfigFromHal( |
| 190 | const buffer_config_t& halConfig, EffectBufferConfig* config); |
| 191 | static void effectBufferConfigToHal( |
| 192 | const EffectBufferConfig& config, buffer_config_t* halConfig); |
| 193 | static void effectConfigFromHal(const effect_config_t& halConfig, EffectConfig* config); |
| 194 | static void effectConfigToHal(const EffectConfig& config, effect_config_t* halConfig); |
| 195 | static void effectOffloadParamToHal( |
| 196 | const EffectOffloadParameter& offload, effect_offload_param_t* halOffload); |
| 197 | static std::vector<uint8_t> parameterToHal( |
| 198 | uint32_t paramSize, const void* paramData, uint32_t valueSize, const void** valueData); |
| 199 | |
| 200 | Result analyzeCommandStatus( |
| 201 | const char* commandName, const char* context, status_t status); |
| 202 | Result analyzeStatus( |
| 203 | const char* funcName, |
| 204 | const char* subFuncName, |
| 205 | const char* contextDescription, |
| 206 | status_t status); |
| 207 | void getConfigImpl(int commandCode, const char* commandName, GetConfigCallback cb); |
| 208 | Result getCurrentConfigImpl( |
| 209 | uint32_t featureId, uint32_t configSize, GetCurrentConfigSuccessCallback onSuccess); |
| 210 | Result getParameterImpl( |
| 211 | uint32_t paramSize, |
| 212 | const void* paramData, |
| 213 | uint32_t valueSize, |
| 214 | GetParameterSuccessCallback onSuccess); |
| 215 | Result getSupportedConfigsImpl( |
| 216 | uint32_t featureId, |
| 217 | uint32_t maxConfigs, |
| 218 | uint32_t configSize, |
| 219 | GetSupportedConfigsSuccessCallback onSuccess); |
| 220 | void processImpl( |
| 221 | ProcessFunction process, |
| 222 | const char* funcName, |
| 223 | const AudioBuffer& inBuffer, |
| 224 | uint32_t outFrameSize, |
| 225 | ProcessCallback cb); |
| 226 | Result sendCommand(int commandCode, const char* commandName); |
| 227 | Result sendCommand(int commandCode, const char* commandName, uint32_t size, void* data); |
| 228 | Result sendCommandReturningData( |
| 229 | int commandCode, const char* commandName, uint32_t* replySize, void* replyData); |
| 230 | Result sendCommandReturningData( |
| 231 | int commandCode, const char* commandName, |
| 232 | uint32_t size, void* data, |
| 233 | uint32_t* replySize, void* replyData); |
| 234 | Result sendCommandReturningStatus(int commandCode, const char* commandName); |
| 235 | Result sendCommandReturningStatus( |
| 236 | int commandCode, const char* commandName, uint32_t size, void* data); |
| 237 | Result sendCommandReturningStatusAndData( |
| 238 | int commandCode, const char* commandName, |
| 239 | uint32_t size, void* data, |
| 240 | uint32_t* replySize, void* replyData, |
| 241 | uint32_t minReplySize, |
| 242 | CommandSuccessCallback onSuccess); |
| 243 | Result setConfigImpl( |
| 244 | int commandCode, const char* commandName, |
| 245 | const EffectConfig& config, |
| 246 | const sp<IEffectBufferProviderCallback>& inputBufferProvider, |
| 247 | const sp<IEffectBufferProviderCallback>& outputBufferProvider); |
| 248 | Result setParameterImpl( |
| 249 | uint32_t paramSize, const void* paramData, uint32_t valueSize, const void* valueData); |
| 250 | }; |
| 251 | |
| 252 | } // namespace implementation |
| 253 | } // namespace V2_0 |
| 254 | } // namespace effect |
| 255 | } // namespace audio |
| 256 | } // namespace hardware |
| 257 | } // namespace android |
| 258 | |
| 259 | #endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_Effect_H_ |