From 7cbf2f1fb15a2a7d9b8b61ca81ad93fa9ddcaea3 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Thu, 27 Oct 2016 20:05:35 -0700 Subject: [PATCH] Implement audio effects HAL delegating to legacy HAL Changes made to the .hal definition: - added missing generated Result for methods implemented via legacy "command" function; - fixed Aux Channels feature definition; - added "size" parameter for reply data in cases where the wrapper needs to allocate a reply buffer; - added method for generic support of feature configs; - added new Result type; - use arrays instead of strings in effect descriptor to ease conversion from / to legacy HAL; - added missing method to the Preset Reverb interface; - fixed names of the Visualizer enums to avoid clashes with defines from the legacy HAL file. The implementation isn't hooked up to the server yet. Need to implement devices and streams first. Bug: 30222631 Change-Id: I75bb42f19ac3303759e918b6d6a91646b1555f8c Test: make --- audio/effect/2.0/IEffect.hal | 148 ++++- .../effect/2.0/IEnvironmentalReverbEffect.hal | 10 + audio/effect/2.0/IVisualizerEffect.hal | 14 +- .../default/AcousticEchoCancelerEffect.cpp | 184 ++++++ .../2.0/default/AcousticEchoCancelerEffect.h | 118 ++++ audio/effect/2.0/default/Android.mk | 31 + .../default/AutomaticGainControlEffect.cpp | 230 +++++++ .../2.0/default/AutomaticGainControlEffect.h | 134 ++++ audio/effect/2.0/default/BassBoostEffect.cpp | 188 ++++++ audio/effect/2.0/default/BassBoostEffect.h | 119 ++++ audio/effect/2.0/default/Conversions.cpp | 78 +++ audio/effect/2.0/default/Conversions.h | 48 ++ audio/effect/2.0/default/DownmixEffect.cpp | 187 ++++++ audio/effect/2.0/default/DownmixEffect.h | 118 ++++ audio/effect/2.0/default/Effect.cpp | 613 ++++++++++++++++++ audio/effect/2.0/default/Effect.h | 259 ++++++++ audio/effect/2.0/default/EffectsFactory.cpp | 197 ++++++ audio/effect/2.0/default/EffectsFactory.h | 66 ++ .../2.0/default/EnvironmentalReverbEffect.cpp | 310 +++++++++ .../2.0/default/EnvironmentalReverbEffect.h | 160 +++++ audio/effect/2.0/default/EqualizerEffect.cpp | 286 ++++++++ audio/effect/2.0/default/EqualizerEffect.h | 150 +++++ .../2.0/default/LoudnessEnhancerEffect.cpp | 187 ++++++ .../2.0/default/LoudnessEnhancerEffect.h | 128 ++++ .../2.0/default/NoiseSuppressionEffect.cpp | 228 +++++++ .../2.0/default/NoiseSuppressionEffect.h | 142 ++++ .../effect/2.0/default/PresetReverbEffect.cpp | 188 ++++++ audio/effect/2.0/default/PresetReverbEffect.h | 128 ++++ .../effect/2.0/default/VirtualizerEffect.cpp | 242 +++++++ audio/effect/2.0/default/VirtualizerEffect.h | 139 ++++ audio/effect/2.0/default/VisualizerEffect.cpp | 262 ++++++++ audio/effect/2.0/default/VisualizerEffect.h | 138 ++++ audio/effect/2.0/types.hal | 13 +- 33 files changed, 5405 insertions(+), 38 deletions(-) create mode 100644 audio/effect/2.0/default/AcousticEchoCancelerEffect.cpp create mode 100644 audio/effect/2.0/default/AcousticEchoCancelerEffect.h create mode 100644 audio/effect/2.0/default/Android.mk create mode 100644 audio/effect/2.0/default/AutomaticGainControlEffect.cpp create mode 100644 audio/effect/2.0/default/AutomaticGainControlEffect.h create mode 100644 audio/effect/2.0/default/BassBoostEffect.cpp create mode 100644 audio/effect/2.0/default/BassBoostEffect.h create mode 100644 audio/effect/2.0/default/Conversions.cpp create mode 100644 audio/effect/2.0/default/Conversions.h create mode 100644 audio/effect/2.0/default/DownmixEffect.cpp create mode 100644 audio/effect/2.0/default/DownmixEffect.h create mode 100644 audio/effect/2.0/default/Effect.cpp create mode 100644 audio/effect/2.0/default/Effect.h create mode 100644 audio/effect/2.0/default/EffectsFactory.cpp create mode 100644 audio/effect/2.0/default/EffectsFactory.h create mode 100644 audio/effect/2.0/default/EnvironmentalReverbEffect.cpp create mode 100644 audio/effect/2.0/default/EnvironmentalReverbEffect.h create mode 100644 audio/effect/2.0/default/EqualizerEffect.cpp create mode 100644 audio/effect/2.0/default/EqualizerEffect.h create mode 100644 audio/effect/2.0/default/LoudnessEnhancerEffect.cpp create mode 100644 audio/effect/2.0/default/LoudnessEnhancerEffect.h create mode 100644 audio/effect/2.0/default/NoiseSuppressionEffect.cpp create mode 100644 audio/effect/2.0/default/NoiseSuppressionEffect.h create mode 100644 audio/effect/2.0/default/PresetReverbEffect.cpp create mode 100644 audio/effect/2.0/default/PresetReverbEffect.h create mode 100644 audio/effect/2.0/default/VirtualizerEffect.cpp create mode 100644 audio/effect/2.0/default/VirtualizerEffect.h create mode 100644 audio/effect/2.0/default/VisualizerEffect.cpp create mode 100644 audio/effect/2.0/default/VisualizerEffect.h diff --git a/audio/effect/2.0/IEffect.hal b/audio/effect/2.0/IEffect.hal index f1cc79506d..615a460eb8 100644 --- a/audio/effect/2.0/IEffect.hal +++ b/audio/effect/2.0/IEffect.hal @@ -48,9 +48,11 @@ interface IEffect { /* * Reset the effect engine. Keep configuration but resets state and buffer * content. + * + * @return retval operation completion status. */ @callflow(next={"*"}) - reset(); + reset() generates (Result retval); /* * Enable processing. @@ -74,9 +76,10 @@ interface IEffect { * descriptor to receive this command when the device changes. * * @param device output device specification. + * @return retval operation completion status. */ @callflow(next={"*"}) - setDevice(AudioDevice device); + setDevice(AudioDevice device) generates (Result retval); /* * Set and get volume. Used by audio framework to delegate volume control to @@ -94,9 +97,11 @@ interface IEffect { * @return result updated volume values. It is OK to receive an empty vector * as a result in which case the effect framework has * delegated volume control to another effect. + * @return retval operation completion status. */ @callflow(next={"*"}) - setAndGetVolume(vec volumes) generates (vec result); + setAndGetVolume(vec volumes) + generates (Result retval, vec result); /* * Set the audio mode. The effect implementation must set @@ -104,9 +109,10 @@ interface IEffect { * when the audio mode changes. * * @param mode desired audio mode. + * @return retval operation completion status. */ @callflow(next={"*"}) - setAudioMode(AudioMode mode); + setAudioMode(AudioMode mode) generates (Result retval); /* * Apply new audio parameters configurations for input and output buffers of @@ -130,58 +136,63 @@ interface IEffect { * receive this command when the device changes. * * @param device input device specification. + * @return retval operation completion status. */ @callflow(next={"*"}) - setInputDevice(AudioDevice device); + setInputDevice(AudioDevice device) generates (Result retval); /* * Read audio parameters configurations for input and output buffers. * + * @return retval operation completion status. * @return config configuration descriptor. */ @callflow(next={"*"}) - getConfig() generates (EffectConfig config); + getConfig() generates (Result retval, EffectConfig config); /* * Read audio parameters configurations for input and output buffers of * reverse stream. * + * @return retval operation completion status. * @return config configuration descriptor. */ @callflow(next={"*"}) - getConfigReverse() generates (EffectConfig config); + getConfigReverse() generates (Result retval, EffectConfig config); /* - * Queries for supported configurations for a particular feature (e.g. get - * the supported combinations of main and auxiliary channels for a noise - * suppressor). The command parameter is a list of the feature identifiers. + * Queries for supported combinations of main and auxiliary channels + * (e.g. for a multi-microphone noise suppressor). * + * @param maxConfigs maximum number of the combinations to return. * @return retval absence of the feature support is indicated using - * NOT_SUPPORTED code. + * NOT_SUPPORTED code. RESULT_TOO_BIG is returned if + * the number of supported combinations exceeds 'maxConfigs'. * @return result list of configuration descriptors. */ @callflow(next={"*"}) - getFeatureSupportedConfigs(vec features) - generates (Result retval, vec result); + getSupportedAuxChannelsConfigs(uint32_t maxConfigs) + generates (Result retval, vec result); /* - * Retrieves current configuration for a given feature. + * Retrieves the current configuration of main and auxiliary channels. * * @return retval absence of the feature support is indicated using * NOT_SUPPORTED code. * @return result configuration descriptor. */ @callflow(next={"*"}) - getFeatureConfig(EffectFeature feature) - generates (Result retval, EffectFeatureConfig result); + getAuxChannelsConfig() + generates (Result retval, EffectAuxChannelsConfig result); /* - * Sets current configuration for a given feature. + * Sets the current configuration of main and auxiliary channels. * - * @return retval operation completion status. + * @return retval operation completion status; absence of the feature + * support is indicated using NOT_SUPPORTED code. */ @callflow(next={"*"}) - setFeatureConfig(EffectFeatureConfig featureConfig) + setAuxChannelsConfig(EffectAuxChannelsConfig config) generates (Result retval); /* @@ -189,9 +200,10 @@ interface IEffect { * recognition...). * * @param source source descriptor. + * @return retval operation completion status. */ @callflow(next={"*"}) - setAudioSource(AudioSource source); + setAudioSource(AudioSource source) generates (Result retval); /* * This command indicates if the playback thread the effect is attached to @@ -207,10 +219,11 @@ interface IEffect { /* * Returns the effect descriptor. * + * @return retval operation completion status. * @return descriptor effect descriptor. */ @callflow(next={"*"}) - getDescriptor() generates (EffectDescriptor descriptor); + getDescriptor() generates (Result retval, EffectDescriptor descriptor); /* * Effect process function. Takes input samples as specified (count and @@ -223,13 +236,18 @@ interface IEffect { * off the effect gracefully and when done indicate that it is OK to stop * calling the 'process' function by returning the INVALID_STATE status. * + * Output audio buffer must contain no more frames than the input audio + * buffer. Since the effect may transform input channels into a different + * amount of channels, the caller provides the output frame size. + * * @param inBuffer input audio buffer. + * @param outFrameSize output frame size in bytes. * @return retval operation completion status. * @return outBuffer output audio buffer. */ // TODO(mnaganov): replace with FMQ version. @callflow(next={"*"}) - process(AudioBuffer inBuffer) + process(AudioBuffer inBuffer, uint32_t outFrameSize) generates (Result retval, AudioBuffer outBuffer); /* @@ -238,13 +256,18 @@ interface IEffect { * reference stream, this function MUST return NOT_SUPPORTED. For example, * this function would typically implemented by an Echo Canceler. * + * Output audio buffer must contain no more frames than the input audio + * buffer. Since the effect may transform input channels into a different + * amount of channels, the caller provides the output frame size. + * * @param inBuffer input audio buffer. + * @param outFrameSize output frame size in bytes. * @return retval operation completion status. * @return outBuffer output audio buffer. */ // TODO(mnaganov): replace with FMQ version. @callflow(next={"*"}) - processReverse(AudioBuffer inBuffer) + processReverse(AudioBuffer inBuffer, uint32_t outFrameSize) generates (Result retval, AudioBuffer outBuffer); /* @@ -261,10 +284,11 @@ interface IEffect { * * @param commandId the ID of the command. * @param data command data. + * @param resultMaxSize maximum size in bytes of the result; can be 0. * @return status command completion status. * @return result result data. */ - command(uint32_t commandId, vec data) + command(uint32_t commandId, vec data, uint32_t resultMaxSize) generates (int32_t status, vec result); /* @@ -302,10 +326,84 @@ interface IEffect { * implemented in software. * * @param parameter identifying data of the parameter. + * @param valueMaxSize maximum size in bytes of the value. * @return retval operation completion status. * @return result the value of the parameter. */ @callflow(next={"*"}) - getParameter(vec parameter) + getParameter(vec parameter, uint32_t valueMaxSize) generates (Result retval, vec value); + + /* + * Get supported configs for a vendor-specific feature. The configs returned + * are not interpreted by Android Framework and are passed as-is between the + * application and the effect. + * + * The effect must use INVALID_ARGUMENTS return code if the feature ID is + * unknown. If the effect does not support getting vendor-specific feature + * configs, it must return NOT_SUPPORTED. If the feature is supported but + * the total number of supported configurations exceeds the maximum number + * indicated by the caller, the method must return RESULT_TOO_BIG. + * + * Use this method only if the effect is provided by a third party, and + * there is no interface defined for it. This method only works for effects + * implemented in software. + * + * @param featureId feature identifier. + * @param maxConfigs maximum number of configs to return. + * @param configSize size of each config in bytes. + * @return retval operation completion status. + * @return configsCount number of configs returned. + * @return configsData data for all the configs returned. + */ + @callflow(next={"*"}) + getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize) generates ( + Result retval, + uint32_t configsCount, + vec configsData); + + /* + * Get the current config for a vendor-specific feature. The config returned + * is not interpreted by Android Framework and is passed as-is between the + * application and the effect. + * + * The effect must use INVALID_ARGUMENTS return code if the feature ID is + * unknown. If the effect does not support getting vendor-specific + * feature configs, it must return NOT_SUPPORTED. + * + * Use this method only if the effect is provided by a third party, and + * there is no interface defined for it. This method only works for effects + * implemented in software. + * + * @param featureId feature identifier. + * @param configSize size of the config in bytes. + * @return retval operation completion status. + * @return configData config data. + */ + @callflow(next={"*"}) + getCurrentConfigForFeature(uint32_t featureId, uint32_t configSize) + generates (Result retval, vec configData); + + /* + * Set the current config for a vendor-specific feature. The config data + * is not interpreted by Android Framework and is passed as-is between the + * application and the effect. + * + * The effect must use INVALID_ARGUMENTS return code if the feature ID is + * unknown. If the effect does not support getting vendor-specific + * feature configs, it must return NOT_SUPPORTED. + * + * Use this method only if the effect is provided by a third party, and + * there is no interface defined for it. This method only works for effects + * implemented in software. + * + * @param featureId feature identifier. + * @param configData config data. + * @return retval operation completion status. + */ + setCurrentConfigForFeature(uint32_t featureId, vec configData) + generates (Result retval); }; diff --git a/audio/effect/2.0/IEnvironmentalReverbEffect.hal b/audio/effect/2.0/IEnvironmentalReverbEffect.hal index bd7aeeba29..d9b1ee6050 100644 --- a/audio/effect/2.0/IEnvironmentalReverbEffect.hal +++ b/audio/effect/2.0/IEnvironmentalReverbEffect.hal @@ -123,6 +123,16 @@ interface IEnvironmentalReverbEffect extends IEffect { */ getReverbLevel() generates (Result retval, int16_t reverbLevel); + /* + * Sets the reverb delay of the room. + */ + setReverbDelay(uint32_t reverDelay) generates (Result retval); + + /* + * Gets the reverb delay of the room. + */ + getReverbDelay() generates (Result retval, uint32_t reverbDelay); + /* * Sets room diffusion. */ diff --git a/audio/effect/2.0/IVisualizerEffect.hal b/audio/effect/2.0/IVisualizerEffect.hal index 2a7ddb8b44..70dabf9e58 100644 --- a/audio/effect/2.0/IVisualizerEffect.hal +++ b/audio/effect/2.0/IVisualizerEffect.hal @@ -36,10 +36,10 @@ interface IVisualizerEffect extends IEffect { getCaptureSize() generates (Result retval, uint16_t captureSize); enum ScalingMode { - // Keep in sync with + // Keep in sync with SCALING_MODE_... in // frameworks/base/media/java/android/media/audiofx/Visualizer.java - SCALING_MODE_NORMALIZED = 0, - SCALING_MODE_AS_PLAYED = 1 + NORMALIZED = 0, + AS_PLAYED = 1 }; /* @@ -63,10 +63,10 @@ interface IVisualizerEffect extends IEffect { getLatency() generates (Result retval, uint32_t latencyMs); enum MeasurementMode { - // Keep in sync with + // Keep in sync with MEASUREMENT_MODE_... in // frameworks/base/media/java/android/media/audiofx/Visualizer.java - MEASUREMENT_MODE_NONE = 0x0, - MEASUREMENT_MODE_PEAK_RMS = 0x1 + NONE = 0x0, + PEAK_RMS = 0x1 }; /* @@ -97,7 +97,7 @@ interface IVisualizerEffect extends IEffect { int32_t peakMb; // millibels int32_t rmsMb; // millibels } peakAndRms; - }; + } value; }; /* * Retrieves the lastest measurements. The measurements to be made diff --git a/audio/effect/2.0/default/AcousticEchoCancelerEffect.cpp b/audio/effect/2.0/default/AcousticEchoCancelerEffect.cpp new file mode 100644 index 0000000000..c2f50f9106 --- /dev/null +++ b/audio/effect/2.0/default/AcousticEchoCancelerEffect.cpp @@ -0,0 +1,184 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "AEC_Effect_HAL" +#include +#include + +#include "AcousticEchoCancelerEffect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +AcousticEchoCancelerEffect::AcousticEchoCancelerEffect(effect_handle_t handle) + : mEffect(new Effect(handle)) { +} + +AcousticEchoCancelerEffect::~AcousticEchoCancelerEffect() {} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. +Return AcousticEchoCancelerEffect::init() { + return mEffect->init(); +} + +Return AcousticEchoCancelerEffect::setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); +} + +Return AcousticEchoCancelerEffect::reset() { + return mEffect->reset(); +} + +Return AcousticEchoCancelerEffect::enable() { + return mEffect->enable(); +} + +Return AcousticEchoCancelerEffect::disable() { + return mEffect->disable(); +} + +Return AcousticEchoCancelerEffect::setDevice(AudioDevice device) { + return mEffect->setDevice(device); +} + +Return AcousticEchoCancelerEffect::setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { + return mEffect->setAndGetVolume(volumes, _hidl_cb); +} + +Return AcousticEchoCancelerEffect::setAudioMode(AudioMode mode) { + return mEffect->setAudioMode(mode); +} + +Return AcousticEchoCancelerEffect::setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); +} + +Return AcousticEchoCancelerEffect::setInputDevice(AudioDevice device) { + return mEffect->setInputDevice(device); +} + +Return AcousticEchoCancelerEffect::getConfig(getConfig_cb _hidl_cb) { + return mEffect->getConfig(_hidl_cb); +} + +Return AcousticEchoCancelerEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + return mEffect->getConfigReverse(_hidl_cb); +} + +Return AcousticEchoCancelerEffect::getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); +} + +Return AcousticEchoCancelerEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + return mEffect->getAuxChannelsConfig(_hidl_cb); +} + +Return AcousticEchoCancelerEffect::setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) { + return mEffect->setAuxChannelsConfig(config); +} + +Return AcousticEchoCancelerEffect::setAudioSource(AudioSource source) { + return mEffect->setAudioSource(source); +} + +Return AcousticEchoCancelerEffect::offload(const EffectOffloadParameter& param) { + return mEffect->offload(param); +} + +Return AcousticEchoCancelerEffect::getDescriptor(getDescriptor_cb _hidl_cb) { + return mEffect->getDescriptor(_hidl_cb); +} + +Return AcousticEchoCancelerEffect::process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) { + return mEffect->process(inBuffer, outFrameSize, _hidl_cb); +} + +Return AcousticEchoCancelerEffect::processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) { + return mEffect->processReverse(inBuffer, outFrameSize, _hidl_cb); +} + +Return AcousticEchoCancelerEffect::command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); +} + +Return AcousticEchoCancelerEffect::setParameter( + const hidl_vec& parameter, const hidl_vec& value) { + return mEffect->setParameter(parameter, value); +} + +Return AcousticEchoCancelerEffect::getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); +} + +Return AcousticEchoCancelerEffect::getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); +} + +Return AcousticEchoCancelerEffect::getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); +} + +Return AcousticEchoCancelerEffect::setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) { + return mEffect->setCurrentConfigForFeature(featureId, configData); +} + +// Methods from ::android::hardware::audio::effect::V2_0::IAcousticEchoCancelerEffect follow. +Return AcousticEchoCancelerEffect::setEchoDelay(uint32_t echoDelayMs) { + return mEffect->setParam(AEC_PARAM_ECHO_DELAY, echoDelayMs); +} + +Return AcousticEchoCancelerEffect::getEchoDelay(getEchoDelay_cb _hidl_cb) { + return mEffect->getIntegerParam(AEC_PARAM_ECHO_DELAY, _hidl_cb); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/AcousticEchoCancelerEffect.h b/audio/effect/2.0/default/AcousticEchoCancelerEffect.h new file mode 100644 index 0000000000..cebc2d4769 --- /dev/null +++ b/audio/effect/2.0/default/AcousticEchoCancelerEffect.h @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_AcousticEchoCancelerEffect_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_AcousticEchoCancelerEffect_H_ + +#include +#include + +#include + +#include "Effect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::effect::V2_0::IAcousticEchoCancelerEffect; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct AcousticEchoCancelerEffect : public IAcousticEchoCancelerEffect { + explicit AcousticEchoCancelerEffect(effect_handle_t handle); + + // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. + Return init() override; + Return setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return reset() override; + Return enable() override; + Return disable() override; + Return setDevice(AudioDevice device) override; + Return setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) override; + Return setAudioMode(AudioMode mode) override; + Return setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return setInputDevice(AudioDevice device) override; + Return getConfig(getConfig_cb _hidl_cb) override; + Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + Return getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; + Return setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; + Return setAudioSource(AudioSource source) override; + Return offload(const EffectOffloadParameter& param) override; + Return getDescriptor(getDescriptor_cb _hidl_cb) override; + Return process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; + Return processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) override; + Return command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override; + Return setParameter( + const hidl_vec& parameter, const hidl_vec& value) override; + Return getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + Return getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + Return getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + Return setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) override; + + // Methods from ::android::hardware::audio::effect::V2_0::IAcousticEchoCancelerEffect follow. + Return setEchoDelay(uint32_t echoDelayMs) override; + Return getEchoDelay(getEchoDelay_cb _hidl_cb) override; + + private: + sp mEffect; + + virtual ~AcousticEchoCancelerEffect(); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_AcousticEchoCancelerEffect_H_ diff --git a/audio/effect/2.0/default/Android.mk b/audio/effect/2.0/default/Android.mk new file mode 100644 index 0000000000..13106f3a4d --- /dev/null +++ b/audio/effect/2.0/default/Android.mk @@ -0,0 +1,31 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := android.hardware.audio.effect@2.0-impl +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_SRC_FILES := \ + AcousticEchoCancelerEffect.cpp \ + AutomaticGainControlEffect.cpp \ + BassBoostEffect.cpp \ + Conversions.cpp \ + DownmixEffect.cpp \ + Effect.cpp \ + EffectsFactory.cpp \ + EnvironmentalReverbEffect.cpp \ + EqualizerEffect.cpp \ + LoudnessEnhancerEffect.cpp \ + NoiseSuppressionEffect.cpp \ + PresetReverbEffect.cpp \ + VirtualizerEffect.cpp \ + VisualizerEffect.cpp \ + +LOCAL_SHARED_LIBRARIES := \ + libhidl \ + libhwbinder \ + libutils \ + libeffects \ + liblog \ + android.hardware.audio.common@2.0 \ + android.hardware.audio.effect@2.0 \ + +include $(BUILD_SHARED_LIBRARY) diff --git a/audio/effect/2.0/default/AutomaticGainControlEffect.cpp b/audio/effect/2.0/default/AutomaticGainControlEffect.cpp new file mode 100644 index 0000000000..34cbe97f9a --- /dev/null +++ b/audio/effect/2.0/default/AutomaticGainControlEffect.cpp @@ -0,0 +1,230 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "AGC_Effect_HAL" +#include + +#include "AutomaticGainControlEffect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +AutomaticGainControlEffect::AutomaticGainControlEffect(effect_handle_t handle) + : mEffect(new Effect(handle)) { +} + +AutomaticGainControlEffect::~AutomaticGainControlEffect() {} + +void AutomaticGainControlEffect::propertiesFromHal( + const t_agc_settings& halProperties, + IAutomaticGainControlEffect::AllProperties* properties) { + properties->targetLevelMb = halProperties.targetLevel; + properties->compGainMb = halProperties.compGain; + properties->limiterEnabled = halProperties.limiterEnabled; +} + +void AutomaticGainControlEffect::propertiesToHal( + const IAutomaticGainControlEffect::AllProperties& properties, + t_agc_settings* halProperties) { + halProperties->targetLevel = properties.targetLevelMb; + halProperties->compGain = properties.compGainMb; + halProperties->limiterEnabled = properties.limiterEnabled; +} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. +Return AutomaticGainControlEffect::init() { + return mEffect->init(); +} + +Return AutomaticGainControlEffect::setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); +} + +Return AutomaticGainControlEffect::reset() { + return mEffect->reset(); +} + +Return AutomaticGainControlEffect::enable() { + return mEffect->enable(); +} + +Return AutomaticGainControlEffect::disable() { + return mEffect->disable(); +} + +Return AutomaticGainControlEffect::setDevice(AudioDevice device) { + return mEffect->setDevice(device); +} + +Return AutomaticGainControlEffect::setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { + return mEffect->setAndGetVolume(volumes, _hidl_cb); +} + +Return AutomaticGainControlEffect::setAudioMode(AudioMode mode) { + return mEffect->setAudioMode(mode); +} + +Return AutomaticGainControlEffect::setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); +} + +Return AutomaticGainControlEffect::setInputDevice(AudioDevice device) { + return mEffect->setInputDevice(device); +} + +Return AutomaticGainControlEffect::getConfig(getConfig_cb _hidl_cb) { + return mEffect->getConfig(_hidl_cb); +} + +Return AutomaticGainControlEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + return mEffect->getConfigReverse(_hidl_cb); +} + +Return AutomaticGainControlEffect::getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); +} + +Return AutomaticGainControlEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + return mEffect->getAuxChannelsConfig(_hidl_cb); +} + +Return AutomaticGainControlEffect::setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) { + return mEffect->setAuxChannelsConfig(config); +} + +Return AutomaticGainControlEffect::setAudioSource(AudioSource source) { + return mEffect->setAudioSource(source); +} + +Return AutomaticGainControlEffect::offload(const EffectOffloadParameter& param) { + return mEffect->offload(param); +} + +Return AutomaticGainControlEffect::getDescriptor(getDescriptor_cb _hidl_cb) { + return mEffect->getDescriptor(_hidl_cb); +} + +Return AutomaticGainControlEffect::process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) { + return mEffect->process(inBuffer, outFrameSize, _hidl_cb); +} + +Return AutomaticGainControlEffect::processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) { + return mEffect->processReverse(inBuffer, outFrameSize, _hidl_cb); +} + +Return AutomaticGainControlEffect::command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); +} + +Return AutomaticGainControlEffect::setParameter( + const hidl_vec& parameter, const hidl_vec& value) { + return mEffect->setParameter(parameter, value); +} + +Return AutomaticGainControlEffect::getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); +} + +Return AutomaticGainControlEffect::getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); +} + +Return AutomaticGainControlEffect::getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); +} + +Return AutomaticGainControlEffect::setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) { + return mEffect->setCurrentConfigForFeature(featureId, configData); +} + +// Methods from ::android::hardware::audio::effect::V2_0::IAutomaticGainControlEffect follow. +Return AutomaticGainControlEffect::setTargetLevel(int16_t targetLevelMb) { + return mEffect->setParam(AGC_PARAM_TARGET_LEVEL, targetLevelMb); +} + +Return AutomaticGainControlEffect::getTargetLevel(getTargetLevel_cb _hidl_cb) { + return mEffect->getIntegerParam(AGC_PARAM_TARGET_LEVEL, _hidl_cb); +} + +Return AutomaticGainControlEffect::setCompGain(int16_t compGainMb) { + return mEffect->setParam(AGC_PARAM_COMP_GAIN, compGainMb); +} + +Return AutomaticGainControlEffect::getCompGain(getCompGain_cb _hidl_cb) { + return mEffect->getIntegerParam(AGC_PARAM_COMP_GAIN, _hidl_cb); +} + +Return AutomaticGainControlEffect::setLimiterEnabled(bool enabled) { + return mEffect->setParam(AGC_PARAM_LIMITER_ENA, enabled); +} + +Return AutomaticGainControlEffect::isLimiterEnabled(isLimiterEnabled_cb _hidl_cb) { + return mEffect->getIntegerParam(AGC_PARAM_LIMITER_ENA, _hidl_cb); +} + +Return AutomaticGainControlEffect::setAllProperties(const IAutomaticGainControlEffect::AllProperties& properties) { + t_agc_settings halProperties; + propertiesToHal(properties, &halProperties); + return mEffect->setParam(AGC_PARAM_PROPERTIES, halProperties); +} + +Return AutomaticGainControlEffect::getAllProperties(getAllProperties_cb _hidl_cb) { + t_agc_settings halProperties; + Result retval = mEffect->getParam(AGC_PARAM_PROPERTIES, halProperties); + AllProperties properties; + propertiesFromHal(halProperties, &properties); + _hidl_cb(retval, properties); + return Void(); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/AutomaticGainControlEffect.h b/audio/effect/2.0/default/AutomaticGainControlEffect.h new file mode 100644 index 0000000000..f4b228c80d --- /dev/null +++ b/audio/effect/2.0/default/AutomaticGainControlEffect.h @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_AutomaticGainControlEffect_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_AutomaticGainControlEffect_H_ + +#include + +#include +#include + +#include + +#include "Effect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::effect::V2_0::IAutomaticGainControlEffect; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct AutomaticGainControlEffect : public IAutomaticGainControlEffect { + explicit AutomaticGainControlEffect(effect_handle_t handle); + + // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. + Return init() override; + Return setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return reset() override; + Return enable() override; + Return disable() override; + Return setDevice(AudioDevice device) override; + Return setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) override; + Return setAudioMode(AudioMode mode) override; + Return setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return setInputDevice(AudioDevice device) override; + Return getConfig(getConfig_cb _hidl_cb) override; + Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + Return getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; + Return setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; + Return setAudioSource(AudioSource source) override; + Return offload(const EffectOffloadParameter& param) override; + Return getDescriptor(getDescriptor_cb _hidl_cb) override; + Return process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; + Return processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) override; + Return command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override; + Return setParameter( + const hidl_vec& parameter, const hidl_vec& value) override; + Return getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + Return getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + Return getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + Return setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) override; + + // Methods from ::android::hardware::audio::effect::V2_0::IAutomaticGainControlEffect follow. + Return setTargetLevel(int16_t targetLevelMb) override; + Return getTargetLevel(getTargetLevel_cb _hidl_cb) override; + Return setCompGain(int16_t compGainMb) override; + Return getCompGain(getCompGain_cb _hidl_cb) override; + Return setLimiterEnabled(bool enabled) override; + Return isLimiterEnabled(isLimiterEnabled_cb _hidl_cb) override; + Return setAllProperties( + const IAutomaticGainControlEffect::AllProperties& properties) override; + Return getAllProperties(getAllProperties_cb _hidl_cb) override; + + private: + sp mEffect; + + virtual ~AutomaticGainControlEffect(); + + void propertiesFromHal( + const t_agc_settings& halProperties, + IAutomaticGainControlEffect::AllProperties* properties); + void propertiesToHal( + const IAutomaticGainControlEffect::AllProperties& properties, + t_agc_settings* halProperties); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_AutomaticGainControlEffect_H_ diff --git a/audio/effect/2.0/default/BassBoostEffect.cpp b/audio/effect/2.0/default/BassBoostEffect.cpp new file mode 100644 index 0000000000..1b12f76eaa --- /dev/null +++ b/audio/effect/2.0/default/BassBoostEffect.cpp @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "BassBoost_HAL" +#include +#include + +#include "BassBoostEffect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +BassBoostEffect::BassBoostEffect(effect_handle_t handle) + : mEffect(new Effect(handle)) { +} + +BassBoostEffect::~BassBoostEffect() {} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. +Return BassBoostEffect::init() { + return mEffect->init(); +} + +Return BassBoostEffect::setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); +} + +Return BassBoostEffect::reset() { + return mEffect->reset(); +} + +Return BassBoostEffect::enable() { + return mEffect->enable(); +} + +Return BassBoostEffect::disable() { + return mEffect->disable(); +} + +Return BassBoostEffect::setDevice(AudioDevice device) { + return mEffect->setDevice(device); +} + +Return BassBoostEffect::setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { + return mEffect->setAndGetVolume(volumes, _hidl_cb); +} + +Return BassBoostEffect::setAudioMode(AudioMode mode) { + return mEffect->setAudioMode(mode); +} + +Return BassBoostEffect::setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); +} + +Return BassBoostEffect::setInputDevice(AudioDevice device) { + return mEffect->setInputDevice(device); +} + +Return BassBoostEffect::getConfig(getConfig_cb _hidl_cb) { + return mEffect->getConfig(_hidl_cb); +} + +Return BassBoostEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + return mEffect->getConfigReverse(_hidl_cb); +} + +Return BassBoostEffect::getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); +} + +Return BassBoostEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + return mEffect->getAuxChannelsConfig(_hidl_cb); +} + +Return BassBoostEffect::setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) { + return mEffect->setAuxChannelsConfig(config); +} + +Return BassBoostEffect::setAudioSource(AudioSource source) { + return mEffect->setAudioSource(source); +} + +Return BassBoostEffect::offload(const EffectOffloadParameter& param) { + return mEffect->offload(param); +} + +Return BassBoostEffect::getDescriptor(getDescriptor_cb _hidl_cb) { + return mEffect->getDescriptor(_hidl_cb); +} + +Return BassBoostEffect::process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) { + return mEffect->process(inBuffer, outFrameSize, _hidl_cb); +} + +Return BassBoostEffect::processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) { + return mEffect->processReverse(inBuffer, outFrameSize, _hidl_cb); +} + +Return BassBoostEffect::command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); +} + +Return BassBoostEffect::setParameter( + const hidl_vec& parameter, const hidl_vec& value) { + return mEffect->setParameter(parameter, value); +} + +Return BassBoostEffect::getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); +} + +Return BassBoostEffect::getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); +} + +Return BassBoostEffect::getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); +} + +Return BassBoostEffect::setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) { + return mEffect->setCurrentConfigForFeature(featureId, configData); +} + +// Methods from ::android::hardware::audio::effect::V2_0::IBassBoostEffect follow. +Return BassBoostEffect::isStrengthSupported(isStrengthSupported_cb _hidl_cb) { + return mEffect->getIntegerParam(BASSBOOST_PARAM_STRENGTH_SUPPORTED, _hidl_cb); +} + +Return BassBoostEffect::setStrength(uint16_t strength) { + return mEffect->setParam(BASSBOOST_PARAM_STRENGTH, strength); +} + +Return BassBoostEffect::getStrength(getStrength_cb _hidl_cb) { + return mEffect->getIntegerParam(BASSBOOST_PARAM_STRENGTH, _hidl_cb); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/BassBoostEffect.h b/audio/effect/2.0/default/BassBoostEffect.h new file mode 100644 index 0000000000..23377e156d --- /dev/null +++ b/audio/effect/2.0/default/BassBoostEffect.h @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_BassBoostEffect_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_BassBoostEffect_H_ + +#include +#include + +#include + +#include "Effect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::effect::V2_0::IBassBoostEffect; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct BassBoostEffect : public IBassBoostEffect { + explicit BassBoostEffect(effect_handle_t handle); + + // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. + Return init() override; + Return setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return reset() override; + Return enable() override; + Return disable() override; + Return setDevice(AudioDevice device) override; + Return setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) override; + Return setAudioMode(AudioMode mode) override; + Return setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return setInputDevice(AudioDevice device) override; + Return getConfig(getConfig_cb _hidl_cb) override; + Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + Return getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; + Return setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; + Return setAudioSource(AudioSource source) override; + Return offload(const EffectOffloadParameter& param) override; + Return getDescriptor(getDescriptor_cb _hidl_cb) override; + Return process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; + Return processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) override; + Return command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override; + Return setParameter( + const hidl_vec& parameter, const hidl_vec& value) override; + Return getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + Return getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + Return getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + Return setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) override; + + // Methods from ::android::hardware::audio::effect::V2_0::IBassBoostEffect follow. + Return isStrengthSupported(isStrengthSupported_cb _hidl_cb) override; + Return setStrength(uint16_t strength) override; + Return getStrength(getStrength_cb _hidl_cb) override; + + private: + sp mEffect; + + virtual ~BassBoostEffect(); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_BassBoostEffect_H_ diff --git a/audio/effect/2.0/default/Conversions.cpp b/audio/effect/2.0/default/Conversions.cpp new file mode 100644 index 0000000000..ef2374cd80 --- /dev/null +++ b/audio/effect/2.0/default/Conversions.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "Conversions.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +void effectDescriptorFromHal( + const effect_descriptor_t& halDescriptor, EffectDescriptor* descriptor) { + uuidFromHal(halDescriptor.type, &descriptor->type); + uuidFromHal(halDescriptor.uuid, &descriptor->uuid); + descriptor->flags = EffectFlags(halDescriptor.flags); + descriptor->cpuLoad = halDescriptor.cpuLoad; + descriptor->memoryUsage = halDescriptor.memoryUsage; + memcpy(descriptor->name.data(), halDescriptor.name, descriptor->name.size()); + memcpy(descriptor->implementor.data(), + halDescriptor.implementor, descriptor->implementor.size()); +} + +void uuidFromHal(const effect_uuid_t& halUuid, Uuid* uuid) { + uuid->timeLow = halUuid.timeLow; + uuid->timeMid = halUuid.timeMid; + uuid->versionAndTimeHigh = halUuid.timeHiAndVersion; + uuid->variantAndClockSeqHigh = halUuid.clockSeq; + memcpy(uuid->node.data(), halUuid.node, uuid->node.size()); +} + +void uuidToHal(const Uuid& uuid, effect_uuid_t* halUuid) { + halUuid->timeLow = uuid.timeLow; + halUuid->timeMid = uuid.timeMid; + halUuid->timeHiAndVersion = uuid.versionAndTimeHigh; + halUuid->clockSeq = uuid.variantAndClockSeqHigh; + memcpy(halUuid->node, uuid.node.data(), uuid.node.size()); +} + +std::string uuidToString(const effect_uuid_t& halUuid) { + char str[64]; + snprintf(str, sizeof(str), "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x", + halUuid.timeLow, + halUuid.timeMid, + halUuid.timeHiAndVersion, + halUuid.clockSeq, + halUuid.node[0], + halUuid.node[1], + halUuid.node[2], + halUuid.node[3], + halUuid.node[4], + halUuid.node[5]); + return str; +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/Conversions.h b/audio/effect/2.0/default/Conversions.h new file mode 100644 index 0000000000..5348ae6686 --- /dev/null +++ b/audio/effect/2.0/default/Conversions.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef android_hardware_audio_effect_V2_0_Conversions_H_ +#define android_hardware_audio_effect_V2_0_Conversions_H_ + +#include + +#include +#include + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::common::V2_0::Uuid; +using ::android::hardware::audio::effect::V2_0::EffectDescriptor; + +void effectDescriptorFromHal( + const effect_descriptor_t& halDescriptor, EffectDescriptor* descriptor); +void uuidFromHal(const effect_uuid_t& halUuid, Uuid* uuid); +void uuidToHal(const Uuid& uuid, effect_uuid_t* halUuid); +std::string uuidToString(const effect_uuid_t& halUuid); + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // android_hardware_audio_effect_V2_0_Conversions_H_ diff --git a/audio/effect/2.0/default/DownmixEffect.cpp b/audio/effect/2.0/default/DownmixEffect.cpp new file mode 100644 index 0000000000..4c0a0bf25b --- /dev/null +++ b/audio/effect/2.0/default/DownmixEffect.cpp @@ -0,0 +1,187 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "Downmix_HAL" +#include +#include + +#include "DownmixEffect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +DownmixEffect::DownmixEffect(effect_handle_t handle) + : mEffect(new Effect(handle)) { +} + +DownmixEffect::~DownmixEffect() {} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. +Return DownmixEffect::init() { + return mEffect->init(); +} + +Return DownmixEffect::setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); +} + +Return DownmixEffect::reset() { + return mEffect->reset(); +} + +Return DownmixEffect::enable() { + return mEffect->enable(); +} + +Return DownmixEffect::disable() { + return mEffect->disable(); +} + +Return DownmixEffect::setDevice(AudioDevice device) { + return mEffect->setDevice(device); +} + +Return DownmixEffect::setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { + return mEffect->setAndGetVolume(volumes, _hidl_cb); +} + +Return DownmixEffect::setAudioMode(AudioMode mode) { + return mEffect->setAudioMode(mode); +} + +Return DownmixEffect::setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); +} + +Return DownmixEffect::setInputDevice(AudioDevice device) { + return mEffect->setInputDevice(device); +} + +Return DownmixEffect::getConfig(getConfig_cb _hidl_cb) { + return mEffect->getConfig(_hidl_cb); +} + +Return DownmixEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + return mEffect->getConfigReverse(_hidl_cb); +} + +Return DownmixEffect::getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); +} + +Return DownmixEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + return mEffect->getAuxChannelsConfig(_hidl_cb); +} + +Return DownmixEffect::setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) { + return mEffect->setAuxChannelsConfig(config); +} + +Return DownmixEffect::setAudioSource(AudioSource source) { + return mEffect->setAudioSource(source); +} + +Return DownmixEffect::offload(const EffectOffloadParameter& param) { + return mEffect->offload(param); +} + +Return DownmixEffect::getDescriptor(getDescriptor_cb _hidl_cb) { + return mEffect->getDescriptor(_hidl_cb); +} + +Return DownmixEffect::process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) { + return mEffect->process(inBuffer, outFrameSize, _hidl_cb); +} + +Return DownmixEffect::processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) { + return mEffect->processReverse(inBuffer, outFrameSize, _hidl_cb); +} + +Return DownmixEffect::command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); +} + +Return DownmixEffect::setParameter( + const hidl_vec& parameter, const hidl_vec& value) { + return mEffect->setParameter(parameter, value); +} + +Return DownmixEffect::getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); +} + +Return DownmixEffect::getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); +} + +Return DownmixEffect::getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); +} + +Return DownmixEffect::setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) { + return mEffect->setCurrentConfigForFeature(featureId, configData); +} + +// Methods from ::android::hardware::audio::effect::V2_0::IDownmixEffect follow. +Return DownmixEffect::setType(IDownmixEffect::Type preset) { + return mEffect->setParam(DOWNMIX_PARAM_TYPE, static_cast(preset)); +} + +Return DownmixEffect::getType(getType_cb _hidl_cb) { + downmix_type_t halPreset = DOWNMIX_TYPE_INVALID; + Result retval = mEffect->getParam(DOWNMIX_PARAM_TYPE, halPreset); + _hidl_cb(retval, Type(halPreset)); + return Void(); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/DownmixEffect.h b/audio/effect/2.0/default/DownmixEffect.h new file mode 100644 index 0000000000..5ed4ffdf59 --- /dev/null +++ b/audio/effect/2.0/default/DownmixEffect.h @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_DownmixEffect_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_DownmixEffect_H_ + +#include +#include + +#include + +#include "Effect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::effect::V2_0::IDownmixEffect; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct DownmixEffect : public IDownmixEffect { + explicit DownmixEffect(effect_handle_t handle); + + // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. + Return init() override; + Return setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return reset() override; + Return enable() override; + Return disable() override; + Return setDevice(AudioDevice device) override; + Return setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) override; + Return setAudioMode(AudioMode mode) override; + Return setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return setInputDevice(AudioDevice device) override; + Return getConfig(getConfig_cb _hidl_cb) override; + Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + Return getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; + Return setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; + Return setAudioSource(AudioSource source) override; + Return offload(const EffectOffloadParameter& param) override; + Return getDescriptor(getDescriptor_cb _hidl_cb) override; + Return process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; + Return processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) override; + Return command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override; + Return setParameter( + const hidl_vec& parameter, const hidl_vec& value) override; + Return getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + Return getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + Return getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + Return setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) override; + + // Methods from ::android::hardware::audio::effect::V2_0::IDownmixEffect follow. + Return setType(IDownmixEffect::Type preset) override; + Return getType(getType_cb _hidl_cb) override; + + private: + sp mEffect; + + virtual ~DownmixEffect(); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_DownmixEffect_H_ diff --git a/audio/effect/2.0/default/Effect.cpp b/audio/effect/2.0/default/Effect.cpp new file mode 100644 index 0000000000..8ab0749871 --- /dev/null +++ b/audio/effect/2.0/default/Effect.cpp @@ -0,0 +1,613 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#define LOG_TAG "EffectHAL" +#include +#include + +#include "Conversions.h" +#include "Effect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::common::V2_0::AudioChannelMask; +using ::android::hardware::audio::common::V2_0::AudioFormat; + +// static +const char *Effect::sContextResultOfCommand = "returned status"; +const char *Effect::sContextCallToCommand = "error"; +const char *Effect::sContextCallFunction = sContextCallToCommand; + +Effect::Effect(effect_handle_t handle) : mHandle(handle) { +} + +Effect::~Effect() { + int status = EffectRelease(mHandle); + ALOGW_IF(status, "Error releasing effect %p: %s", mHandle, strerror(-status)); + mHandle = 0; +} + +// static +template size_t Effect::alignedSizeIn(size_t s) { + return (s + sizeof(T) - 1) / sizeof(T); +} + +// static +template void Effect::hidlVecToHal( + const hidl_vec& vec, uint32_t* halDataSize, void** halData) { + *halDataSize = static_cast(vec.size() * sizeof(T)); + *halData = static_cast(const_cast(&vec[0])); +} + +// static +void Effect::effectAuxChannelsConfigFromHal( + const channel_config_t& halConfig, EffectAuxChannelsConfig* config) { + config->mainChannels = AudioChannelMask(halConfig.main_channels); + config->auxChannels = AudioChannelMask(halConfig.aux_channels); +} + +// static +void Effect::effectAuxChannelsConfigToHal( + const EffectAuxChannelsConfig& config, channel_config_t* halConfig) { + halConfig->main_channels = static_cast(config.mainChannels); + halConfig->aux_channels = static_cast(config.auxChannels); +} + +// static +void Effect::effectBufferConfigFromHal( + const buffer_config_t& halConfig, EffectBufferConfig* config) { + // TODO(mnaganov): Use FMQ instead of AudioBuffer. + (void)halConfig.buffer.frameCount; + (void)halConfig.buffer.raw; + config->samplingRateHz = halConfig.samplingRate; + config->channels = AudioChannelMask(halConfig.channels); + config->format = AudioFormat(halConfig.format); + config->accessMode = EffectBufferAccess(halConfig.accessMode); + config->mask = EffectConfigParameters(halConfig.mask); +} + +// static +void Effect::effectBufferConfigToHal(const EffectBufferConfig& config, buffer_config_t* halConfig) { + // TODO(mnaganov): Use FMQ instead of AudioBuffer. + halConfig->buffer.frameCount = 0; + halConfig->buffer.raw = NULL; + halConfig->samplingRate = config.samplingRateHz; + halConfig->channels = static_cast(config.channels); + // TODO(mnaganov): As the calling code does not use BP for now, implement later. + halConfig->bufferProvider.cookie = NULL; + halConfig->bufferProvider.getBuffer = NULL; + halConfig->bufferProvider.releaseBuffer = NULL; + halConfig->format = static_cast(config.format); + halConfig->accessMode = static_cast(config.accessMode); + halConfig->mask = static_cast(config.mask); +} + +// static +void Effect::effectConfigFromHal(const effect_config_t& halConfig, EffectConfig* config) { + effectBufferConfigFromHal(halConfig.inputCfg, &config->inputCfg); + effectBufferConfigFromHal(halConfig.outputCfg, &config->outputCfg); +} + +// static +void Effect::effectConfigToHal(const EffectConfig& config, effect_config_t* halConfig) { + effectBufferConfigToHal(config.inputCfg, &halConfig->inputCfg); + effectBufferConfigToHal(config.outputCfg, &halConfig->outputCfg); +} + +// static +void Effect::effectOffloadParamToHal( + const EffectOffloadParameter& offload, effect_offload_param_t* halOffload) { + halOffload->isOffload = offload.isOffload; + halOffload->ioHandle = offload.ioHandle; +} + +// static +std::vector Effect::parameterToHal( + uint32_t paramSize, + const void* paramData, + uint32_t valueSize, + const void** valueData) { + size_t valueOffsetFromData = alignedSizeIn(paramSize) * sizeof(uint32_t); + size_t halParamBufferSize = sizeof(effect_param_t) + valueOffsetFromData + valueSize; + std::vector halParamBuffer(halParamBufferSize, 0); + effect_param_t *halParam = reinterpret_cast(&halParamBuffer[0]); + halParam->psize = paramSize; + halParam->vsize = valueSize; + memcpy(halParam->data, paramData, paramSize); + if (valueData) { + if (*valueData) { + // Value data is provided. + memcpy(halParam->data + valueOffsetFromData, *valueData, valueSize); + } else { + // The caller needs the pointer to the value data location. + *valueData = halParam->data + valueOffsetFromData; + } + } + return halParamBuffer; +} + +Result Effect::analyzeCommandStatus(const char* commandName, const char* context, status_t status) { + return analyzeStatus("command", commandName, context, status); +} + +Result Effect::analyzeStatus( + const char* funcName, + const char* subFuncName, + const char* contextDescription, + status_t status) { + if (status != OK) { + ALOGW("Effect %p %s %s %s: %s", + mHandle, funcName, subFuncName, contextDescription, strerror(-status)); + } + switch (status) { + case OK: return Result::OK; + case -EINVAL: return Result::INVALID_ARGUMENTS; + case -ENODATA: return Result::INVALID_STATE; + case -ENODEV: return Result::NOT_INITIALIZED; + case -ENOMEM: return Result::RESULT_TOO_BIG; + case -ENOSYS: return Result::NOT_SUPPORTED; + default: return Result::INVALID_STATE; + } +} + +void Effect::getConfigImpl(int commandCode, const char* commandName, GetConfigCallback cb) { + uint32_t halResultSize = sizeof(effect_config_t); + effect_config_t halConfig; + status_t status = (*mHandle)->command( + mHandle, commandCode, 0, NULL, &halResultSize, &halConfig); + EffectConfig config; + if (status == OK) { + effectConfigFromHal(halConfig, &config); + } + cb(analyzeCommandStatus(commandName, sContextCallToCommand, status), config); +} + +Result Effect::getCurrentConfigImpl( + uint32_t featureId, uint32_t configSize, GetCurrentConfigSuccessCallback onSuccess) { + uint32_t halCmd = featureId; + uint32_t halResult[alignedSizeIn(sizeof(uint32_t) + configSize)]; + memset(halResult, 0, sizeof(halResult)); + uint32_t halResultSize = 0; + return sendCommandReturningStatusAndData( + EFFECT_CMD_GET_FEATURE_CONFIG, "GET_FEATURE_CONFIG", + sizeof(uint32_t), &halCmd, + &halResultSize, halResult, + sizeof(uint32_t), + [&]{ onSuccess(&halResult[1]); }); +} + +Result Effect::getParameterImpl( + uint32_t paramSize, + const void* paramData, + uint32_t valueSize, + GetParameterSuccessCallback onSuccess) { + // As it is unknown what method HAL uses for copying the provided parameter data, + // it is safer to make sure that input and output buffers do not overlap. + std::vector halCmdBuffer = + parameterToHal(paramSize, paramData, valueSize, nullptr); + const void *valueData = nullptr; + std::vector halParamBuffer = + parameterToHal(paramSize, paramData, valueSize, &valueData); + uint32_t halParamBufferSize = halParamBuffer.size(); + + return sendCommandReturningStatusAndData( + EFFECT_CMD_GET_PARAM, "GET_PARAM", + halCmdBuffer.size(), &halCmdBuffer[0], + &halParamBufferSize, &halParamBuffer[0], + sizeof(effect_param_t), + [&]{ + effect_param_t *halParam = reinterpret_cast(&halParamBuffer[0]); + onSuccess(halParam->vsize, valueData); + }); +} + +Result Effect::getSupportedConfigsImpl( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + GetSupportedConfigsSuccessCallback onSuccess) { + uint32_t halCmd[2] = { featureId, maxConfigs }; + uint32_t halResultSize = 2 * sizeof(uint32_t) + maxConfigs * sizeof(configSize); + uint8_t halResult[halResultSize]; + memset(&halResult[0], 0, halResultSize); + return sendCommandReturningStatusAndData( + EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS, "GET_FEATURE_SUPPORTED_CONFIGS", + sizeof(halCmd), halCmd, + &halResultSize, &halResult[0], + 2 * sizeof(uint32_t), + [&]{ + uint32_t *halResult32 = reinterpret_cast(&halResult[0]); + uint32_t supportedConfigs = *(++halResult32); // skip status field + if (supportedConfigs > maxConfigs) supportedConfigs = maxConfigs; + onSuccess(supportedConfigs, ++halResult32); + }); +} + +void Effect::processImpl( + ProcessFunction process, + const char* funcName, + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + ProcessCallback cb) { + audio_buffer_t halInBuffer; + halInBuffer.frameCount = inBuffer.frameCount; + halInBuffer.u8 = const_cast(&inBuffer.data[0]); + audio_buffer_t halOutBuffer; + halOutBuffer.frameCount = halInBuffer.frameCount; + // TODO(mnaganov): Consider stashing the buffer to avoid reallocating it every time. + std::unique_ptr halOutBufferData( + new uint8_t[halOutBuffer.frameCount * outFrameSize]); + halOutBuffer.u8 = &halOutBufferData[0]; + status_t status = process(mHandle, &halInBuffer, &halOutBuffer); + Result retval = analyzeStatus(funcName, "", sContextCallFunction, status); + AudioBuffer outBuffer; + if (status == OK) { + outBuffer.frameCount = halOutBuffer.frameCount; + outBuffer.data.setToExternal(halOutBuffer.u8, halOutBuffer.frameCount * outFrameSize); + } else { + outBuffer.frameCount = 0; + } + cb(retval, outBuffer); +} + +Result Effect::sendCommand(int commandCode, const char* commandName) { + return sendCommand(commandCode, commandName, 0, NULL); +} + +Result Effect::sendCommand( + int commandCode, const char* commandName, uint32_t size, void* data) { + status_t status = (*mHandle)->command(mHandle, commandCode, size, data, 0, NULL); + return analyzeCommandStatus(commandName, sContextCallToCommand, status); +} + +Result Effect::sendCommandReturningData( + int commandCode, const char* commandName, + uint32_t* replySize, void* replyData) { + return sendCommandReturningData(commandCode, commandName, 0, NULL, replySize, replyData); +} + +Result Effect::sendCommandReturningData( + int commandCode, const char* commandName, + uint32_t size, void* data, + uint32_t* replySize, void* replyData) { + uint32_t expectedReplySize = *replySize; + status_t status = (*mHandle)->command(mHandle, commandCode, size, data, replySize, replyData); + if (status == OK && *replySize != expectedReplySize) { + status = -ENODATA; + } + return analyzeCommandStatus(commandName, sContextCallToCommand, status); +} + +Result Effect::sendCommandReturningStatus(int commandCode, const char* commandName) { + return sendCommandReturningStatus(commandCode, commandName, 0, NULL); +} + +Result Effect::sendCommandReturningStatus( + int commandCode, const char* commandName, uint32_t size, void* data) { + uint32_t replyCmdStatus; + uint32_t replySize = sizeof(uint32_t); + return sendCommandReturningStatusAndData( + commandCode, commandName, size, data, &replySize, &replyCmdStatus, replySize, []{}); +} + +Result Effect::sendCommandReturningStatusAndData( + int commandCode, const char* commandName, + uint32_t size, void* data, + uint32_t* replySize, void* replyData, + uint32_t minReplySize, + CommandSuccessCallback onSuccess) { + status_t status = + (*mHandle)->command(mHandle, commandCode, size, data, replySize, replyData); + Result retval; + if (status == OK && minReplySize >= sizeof(uint32_t) && *replySize >= minReplySize) { + uint32_t commandStatus = *reinterpret_cast(replyData); + retval = analyzeCommandStatus(commandName, sContextResultOfCommand, commandStatus); + if (commandStatus == OK) { + onSuccess(); + } + } else { + retval = analyzeCommandStatus(commandName, sContextCallToCommand, status); + } + return retval; +} + +Result Effect::setConfigImpl( + int commandCode, const char* commandName, + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + effect_config_t halConfig; + effectConfigToHal(config, &halConfig); + if (inputBufferProvider != 0) { + LOG_FATAL("Using input buffer provider is not supported"); + } + if (outputBufferProvider != 0) { + LOG_FATAL("Using output buffer provider is not supported"); + } + return sendCommandReturningStatus( + commandCode, commandName, sizeof(effect_config_t), &halConfig); +} + + +Result Effect::setParameterImpl( + uint32_t paramSize, const void* paramData, uint32_t valueSize, const void* valueData) { + std::vector halParamBuffer = parameterToHal( + paramSize, paramData, valueSize, &valueData); + return sendCommandReturningStatus( + EFFECT_CMD_SET_PARAM, "SET_PARAM", halParamBuffer.size(), &halParamBuffer[0]); +} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. +Return Effect::init() { + return sendCommandReturningStatus(EFFECT_CMD_INIT, "INIT"); +} + +Return Effect::setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return setConfigImpl( + EFFECT_CMD_SET_CONFIG, "SET_CONFIG", config, inputBufferProvider, outputBufferProvider); +} + +Return Effect::reset() { + return sendCommand(EFFECT_CMD_RESET, "RESET"); +} + +Return Effect::enable() { + return sendCommandReturningStatus(EFFECT_CMD_ENABLE, "ENABLE"); +} + +Return Effect::disable() { + return sendCommandReturningStatus(EFFECT_CMD_DISABLE, "DISABLE"); +} + +Return Effect::setDevice(AudioDevice device) { + uint32_t halDevice = static_cast(device); + return sendCommand(EFFECT_CMD_SET_DEVICE, "SET_DEVICE", sizeof(uint32_t), &halDevice); +} + +Return Effect::setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { + uint32_t halDataSize; + void *halData; + hidlVecToHal(volumes, &halDataSize, &halData); + uint32_t halResultSize = halDataSize; + uint32_t halResult[volumes.size()]; + Result retval = sendCommandReturningData( + EFFECT_CMD_SET_VOLUME, "SET_VOLUME", halDataSize, halData, &halResultSize, halResult); + hidl_vec result; + if (retval == Result::OK) { + result.setToExternal(&halResult[0], halResultSize); + } + _hidl_cb(retval, result); + return Void(); +} + +Return Effect::setAudioMode(AudioMode mode) { + uint32_t halMode = static_cast(mode); + return sendCommand( + EFFECT_CMD_SET_AUDIO_MODE, "SET_AUDIO_MODE", sizeof(uint32_t), &halMode); +} + +Return Effect::setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return setConfigImpl(EFFECT_CMD_SET_CONFIG_REVERSE, "SET_CONFIG_REVERSE", + config, inputBufferProvider, outputBufferProvider); +} + +Return Effect::setInputDevice(AudioDevice device) { + uint32_t halDevice = static_cast(device); + return sendCommand( + EFFECT_CMD_SET_INPUT_DEVICE, "SET_INPUT_DEVICE", sizeof(uint32_t), &halDevice); +} + +Return Effect::getConfig(getConfig_cb _hidl_cb) { + getConfigImpl(EFFECT_CMD_GET_CONFIG, "GET_CONFIG", _hidl_cb); + return Void(); +} + +Return Effect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + getConfigImpl(EFFECT_CMD_GET_CONFIG_REVERSE, "GET_CONFIG_REVERSE", _hidl_cb); + return Void(); +} + +Return Effect::getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) { + hidl_vec result; + Result retval = getSupportedConfigsImpl( + EFFECT_FEATURE_AUX_CHANNELS, + maxConfigs, + sizeof(channel_config_t), + [&] (uint32_t supportedConfigs, void* configsData) { + result.resize(supportedConfigs); + channel_config_t *config = reinterpret_cast(configsData); + for (size_t i = 0; i < result.size(); ++i) { + effectAuxChannelsConfigFromHal(*config++, &result[i]); + } + }); + _hidl_cb(retval, result); + return Void(); +} + +Return Effect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + uint32_t halCmd = EFFECT_FEATURE_AUX_CHANNELS; + uint32_t halResult[alignedSizeIn(sizeof(uint32_t) + sizeof(channel_config_t))]; + memset(halResult, 0, sizeof(halResult)); + uint32_t halResultSize = 0; + EffectAuxChannelsConfig result; + Result retval = getCurrentConfigImpl( + EFFECT_FEATURE_AUX_CHANNELS, + sizeof(channel_config_t), + [&] (void* configData) { + effectAuxChannelsConfigFromHal( + *reinterpret_cast(configData), &result); + }); + _hidl_cb(retval, result); + return Void(); +} + +Return Effect::setAuxChannelsConfig(const EffectAuxChannelsConfig& config) { + uint32_t halCmd[alignedSizeIn(sizeof(uint32_t) + sizeof(channel_config_t))]; + halCmd[0] = EFFECT_FEATURE_AUX_CHANNELS; + effectAuxChannelsConfigToHal(config, reinterpret_cast(&halCmd[1])); + return sendCommandReturningStatus(EFFECT_CMD_SET_FEATURE_CONFIG, + "SET_FEATURE_CONFIG AUX_CHANNELS", sizeof(halCmd), halCmd); +} + +Return Effect::setAudioSource(AudioSource source) { + uint32_t halSource = static_cast(source); + return sendCommand( + EFFECT_CMD_SET_AUDIO_SOURCE, "SET_AUDIO_SOURCE", sizeof(uint32_t), &halSource); +} + +Return Effect::offload(const EffectOffloadParameter& param) { + effect_offload_param_t halParam; + effectOffloadParamToHal(param, &halParam); + return sendCommandReturningStatus( + EFFECT_CMD_OFFLOAD, "OFFLOAD", sizeof(effect_offload_param_t), &halParam); +} + +Return Effect::getDescriptor(getDescriptor_cb _hidl_cb) { + effect_descriptor_t halDescriptor; + memset(&halDescriptor, 0, sizeof(effect_descriptor_t)); + status_t status = (*mHandle)->get_descriptor(mHandle, &halDescriptor); + EffectDescriptor descriptor; + if (status == OK) { + effectDescriptorFromHal(halDescriptor, &descriptor); + } + _hidl_cb(analyzeStatus("get_descriptor", "", sContextCallFunction, status), descriptor); + return Void(); +} + +Return Effect::process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) { + processImpl((*mHandle)->process, "process", inBuffer, outFrameSize, _hidl_cb); + return Void(); +} + +Return Effect::processReverse( + const AudioBuffer& inBuffer, uint32_t outFrameSize, processReverse_cb _hidl_cb) { + if ((*mHandle)->process_reverse != NULL) { + processImpl( + (*mHandle)->process_reverse, "process_reverse", inBuffer, outFrameSize, _hidl_cb); + } else { + _hidl_cb(Result::NOT_SUPPORTED, AudioBuffer()); + } + return Void(); +} + +Return Effect::command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) { + uint32_t halDataSize; + void *halData; + hidlVecToHal(data, &halDataSize, &halData); + uint32_t halResultSize = resultMaxSize; + std::unique_ptr halResult(new uint8_t[halResultSize]); + memset(&halResult[0], 0, halResultSize); + status_t status = (*mHandle)->command( + mHandle, commandId, halDataSize, halData, &halResultSize, &halResult[0]); + hidl_vec result; + if (status == OK) { + result.setToExternal(&halResult[0], halResultSize); + } + _hidl_cb(status, result); + return Void(); +} + +Return Effect::setParameter( + const hidl_vec& parameter, const hidl_vec& value) { + return setParameterImpl(parameter.size(), ¶meter[0], value.size(), &value[0]); +} + +Return Effect::getParameter( + const hidl_vec& parameter, uint32_t valueMaxSize, getParameter_cb _hidl_cb) { + hidl_vec value; + Result retval = getParameterImpl( + parameter.size(), + ¶meter[0], + valueMaxSize, + [&] (uint32_t valueSize, const void* valueData) { + value.setToExternal( + reinterpret_cast(const_cast(valueData)), valueSize); + }); + _hidl_cb(retval, value); + return Void(); +} + +Return Effect::getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + uint32_t configCount = 0; + hidl_vec result; + Result retval = getSupportedConfigsImpl( + featureId, + maxConfigs, + configSize, + [&] (uint32_t supportedConfigs, void* configsData) { + configCount = supportedConfigs; + result.resize(configCount * configSize); + memcpy(&result[0], configsData, result.size()); + }); + _hidl_cb(retval, configCount, result); + return Void(); +} + +Return Effect::getCurrentConfigForFeature( + uint32_t featureId, uint32_t configSize, getCurrentConfigForFeature_cb _hidl_cb) { + hidl_vec result; + Result retval = getCurrentConfigImpl( + featureId, + configSize, + [&] (void* configData) { + result.resize(configSize); + memcpy(&result[0], configData, result.size()); + }); + _hidl_cb(retval, result); + return Void(); +} + +Return Effect::setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) { + uint32_t halCmd[alignedSizeIn(sizeof(uint32_t) + configData.size())]; + memset(halCmd, 0, sizeof(halCmd)); + halCmd[0] = featureId; + memcpy(&halCmd[1], &configData[0], configData.size()); + return sendCommandReturningStatus( + EFFECT_CMD_SET_FEATURE_CONFIG, "SET_FEATURE_CONFIG", sizeof(halCmd), halCmd); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/Effect.h b/audio/effect/2.0/default/Effect.h new file mode 100644 index 0000000000..e27a7e4c6e --- /dev/null +++ b/audio/effect/2.0/default/Effect.h @@ -0,0 +1,259 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_Effect_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_Effect_H_ + +#include + +#include +#include + +#include + +#include + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::common::V2_0::AudioDevice; +using ::android::hardware::audio::common::V2_0::AudioMode; +using ::android::hardware::audio::common::V2_0::AudioSource; +using ::android::hardware::audio::common::V2_0::Uuid; +using ::android::hardware::audio::effect::V2_0::AudioBuffer; +using ::android::hardware::audio::effect::V2_0::EffectAuxChannelsConfig; +using ::android::hardware::audio::effect::V2_0::EffectConfig; +using ::android::hardware::audio::effect::V2_0::EffectDescriptor; +using ::android::hardware::audio::effect::V2_0::EffectFeature; +using ::android::hardware::audio::effect::V2_0::EffectOffloadParameter; +using ::android::hardware::audio::effect::V2_0::IEffect; +using ::android::hardware::audio::effect::V2_0::IEffectBufferProviderCallback; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct Effect : public IEffect { + explicit Effect(effect_handle_t handle); + + // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. + Return init() override; + Return setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return reset() override; + Return enable() override; + Return disable() override; + Return setDevice(AudioDevice device) override; + Return setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) override; + Return setAudioMode(AudioMode mode) override; + Return setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return setInputDevice(AudioDevice device) override; + Return getConfig(getConfig_cb _hidl_cb) override; + Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + Return getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; + Return setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; + Return setAudioSource(AudioSource source) override; + Return offload(const EffectOffloadParameter& param) override; + Return getDescriptor(getDescriptor_cb _hidl_cb) override; + Return process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; + Return processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) override; + Return command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override; + Return setParameter( + const hidl_vec& parameter, const hidl_vec& value) override; + Return getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + Return getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + Return getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + Return setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) override; + + // Utility methods for extending interfaces. + template Return getIntegerParam( + uint32_t paramId, std::function cb) { + T value; + Result retval = getParameterImpl( + sizeof(uint32_t), ¶mId, + sizeof(T), + [&] (uint32_t valueSize, const void* valueData) { + if (valueSize > sizeof(T)) valueSize = sizeof(T); + memcpy(&value, valueData, valueSize); + }); + cb(retval, value); + return Void(); + } + + template Result getParam(uint32_t paramId, T& paramValue) { + return getParameterImpl( + sizeof(uint32_t), ¶mId, + sizeof(T), + [&] (uint32_t valueSize, const void* valueData) { + if (valueSize > sizeof(T)) valueSize = sizeof(T); + memcpy(¶mValue, valueData, valueSize); + }); + } + + template Result getParam(uint32_t paramId, uint32_t paramArg, T& paramValue) { + uint32_t params[2] = { paramId, paramArg }; + return getParameterImpl( + sizeof(params), params, + sizeof(T), + [&] (uint32_t valueSize, const void* valueData) { + if (valueSize > sizeof(T)) valueSize = sizeof(T); + memcpy(¶mValue, valueData, valueSize); + }); + } + + template Result setParam(uint32_t paramId, const T& paramValue) { + return setParameterImpl(sizeof(uint32_t), ¶mId, sizeof(T), ¶mValue); + } + + template Result setParam(uint32_t paramId, uint32_t paramArg, const T& paramValue) { + uint32_t params[2] = { paramId, paramArg }; + return setParameterImpl(sizeof(params), params, sizeof(T), ¶mValue); + } + + private: + friend struct VirtualizerEffect; // for getParameterImpl + friend struct VisualizerEffect; // to allow executing commands + + typedef int32_t (*ProcessFunction)( + effect_handle_t self, audio_buffer_t* inBuffer, audio_buffer_t* outBuffer); + using CommandSuccessCallback = std::function; + using GetConfigCallback = std::function; + using GetCurrentConfigSuccessCallback = std::function; + using GetParameterSuccessCallback = + std::function; + using GetSupportedConfigsSuccessCallback = + std::function; + using ProcessCallback = std::function; + + static const char *sContextResultOfCommand; + static const char *sContextCallToCommand; + static const char *sContextCallFunction; + + effect_handle_t mHandle; + + virtual ~Effect(); + + template static size_t alignedSizeIn(size_t s); + template static void hidlVecToHal( + const hidl_vec& vec, uint32_t* halDataSize, void** halData); + static void effectAuxChannelsConfigFromHal( + const channel_config_t& halConfig, EffectAuxChannelsConfig* config); + static void effectAuxChannelsConfigToHal( + const EffectAuxChannelsConfig& config, channel_config_t* halConfig); + static void effectBufferConfigFromHal( + const buffer_config_t& halConfig, EffectBufferConfig* config); + static void effectBufferConfigToHal( + const EffectBufferConfig& config, buffer_config_t* halConfig); + static void effectConfigFromHal(const effect_config_t& halConfig, EffectConfig* config); + static void effectConfigToHal(const EffectConfig& config, effect_config_t* halConfig); + static void effectOffloadParamToHal( + const EffectOffloadParameter& offload, effect_offload_param_t* halOffload); + static std::vector parameterToHal( + uint32_t paramSize, const void* paramData, uint32_t valueSize, const void** valueData); + + Result analyzeCommandStatus( + const char* commandName, const char* context, status_t status); + Result analyzeStatus( + const char* funcName, + const char* subFuncName, + const char* contextDescription, + status_t status); + void getConfigImpl(int commandCode, const char* commandName, GetConfigCallback cb); + Result getCurrentConfigImpl( + uint32_t featureId, uint32_t configSize, GetCurrentConfigSuccessCallback onSuccess); + Result getParameterImpl( + uint32_t paramSize, + const void* paramData, + uint32_t valueSize, + GetParameterSuccessCallback onSuccess); + Result getSupportedConfigsImpl( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + GetSupportedConfigsSuccessCallback onSuccess); + void processImpl( + ProcessFunction process, + const char* funcName, + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + ProcessCallback cb); + Result sendCommand(int commandCode, const char* commandName); + Result sendCommand(int commandCode, const char* commandName, uint32_t size, void* data); + Result sendCommandReturningData( + int commandCode, const char* commandName, uint32_t* replySize, void* replyData); + Result sendCommandReturningData( + int commandCode, const char* commandName, + uint32_t size, void* data, + uint32_t* replySize, void* replyData); + Result sendCommandReturningStatus(int commandCode, const char* commandName); + Result sendCommandReturningStatus( + int commandCode, const char* commandName, uint32_t size, void* data); + Result sendCommandReturningStatusAndData( + int commandCode, const char* commandName, + uint32_t size, void* data, + uint32_t* replySize, void* replyData, + uint32_t minReplySize, + CommandSuccessCallback onSuccess); + Result setConfigImpl( + int commandCode, const char* commandName, + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider); + Result setParameterImpl( + uint32_t paramSize, const void* paramData, uint32_t valueSize, const void* valueData); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_Effect_H_ diff --git a/audio/effect/2.0/default/EffectsFactory.cpp b/audio/effect/2.0/default/EffectsFactory.cpp new file mode 100644 index 0000000000..f7c5d628b0 --- /dev/null +++ b/audio/effect/2.0/default/EffectsFactory.cpp @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "EffectFactoryHAL" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "AcousticEchoCancelerEffect.h" +#include "AutomaticGainControlEffect.h" +#include "BassBoostEffect.h" +#include "Conversions.h" +#include "EffectsFactory.h" +#include "DownmixEffect.h" +#include "Effect.h" +#include "EnvironmentalReverbEffect.h" +#include "EqualizerEffect.h" +#include "LoudnessEnhancerEffect.h" +#include "NoiseSuppressionEffect.h" +#include "PresetReverbEffect.h" +#include "VirtualizerEffect.h" +#include "VisualizerEffect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +// static +sp EffectsFactory::dispatchEffectInstanceCreation( + const effect_descriptor_t& halDescriptor, effect_handle_t handle) { + const effect_uuid_t *halUuid = &halDescriptor.type; + if (memcmp(halUuid, FX_IID_AEC, sizeof(effect_uuid_t)) == 0) { + return new AcousticEchoCancelerEffect(handle); + } else if (memcmp(halUuid, FX_IID_AGC, sizeof(effect_uuid_t)) == 0) { + return new AutomaticGainControlEffect(handle); + } else if (memcmp(halUuid, SL_IID_BASSBOOST, sizeof(effect_uuid_t)) == 0) { + return new BassBoostEffect(handle); + } else if (memcmp(halUuid, EFFECT_UIID_DOWNMIX, sizeof(effect_uuid_t)) == 0) { + return new DownmixEffect(handle); + } else if (memcmp(halUuid, SL_IID_ENVIRONMENTALREVERB, sizeof(effect_uuid_t)) == 0) { + return new EnvironmentalReverbEffect(handle); + } else if (memcmp(halUuid, SL_IID_EQUALIZER, sizeof(effect_uuid_t)) == 0) { + return new EqualizerEffect(handle); + } else if (memcmp(halUuid, FX_IID_LOUDNESS_ENHANCER, sizeof(effect_uuid_t)) == 0) { + return new LoudnessEnhancerEffect(handle); + } else if (memcmp(halUuid, FX_IID_NS, sizeof(effect_uuid_t)) == 0) { + return new NoiseSuppressionEffect(handle); + } else if (memcmp(halUuid, SL_IID_PRESETREVERB, sizeof(effect_uuid_t)) == 0) { + return new PresetReverbEffect(handle); + } else if (memcmp(halUuid, SL_IID_VIRTUALIZER, sizeof(effect_uuid_t)) == 0) { + return new VirtualizerEffect(handle); + } else if (memcmp(halUuid, SL_IID_VISUALIZATION, sizeof(effect_uuid_t)) == 0) { + return new VisualizerEffect(handle); + } + return new Effect(handle); +} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffectsFactory follow. +Return EffectsFactory::getAllDescriptors(getAllDescriptors_cb _hidl_cb) { + Result retval(Result::OK); + hidl_vec result; + uint32_t numEffects; + status_t status; + +restart: + numEffects = 0; + status = EffectQueryNumberEffects(&numEffects); + if (status != OK) { + retval = Result::NOT_INITIALIZED; + ALOGW("Error querying number of effects: %s", strerror(-status)); + goto exit; + } + result.resize(numEffects); + for (uint32_t i = 0; i < numEffects; ++i) { + effect_descriptor_t halDescriptor; + status = EffectQueryEffect(i, &halDescriptor); + if (status == OK) { + effectDescriptorFromHal(halDescriptor, &result[i]); + } else { + ALOGW("Error querying effect at position %d / %d: %s", + i, numEffects, strerror(-status)); + switch (status) { + case -ENOSYS: { + // Effect list has changed. + goto restart; + } + case -ENOENT: { + // No more effects available. + result.resize(i); + } + default: { + result.resize(0); + retval = Result::NOT_INITIALIZED; + } + } + break; + } + } + +exit: + _hidl_cb(retval, result); + return Void(); +} + +Return EffectsFactory::getDescriptor(const Uuid& uid, getDescriptor_cb _hidl_cb) { + effect_uuid_t halUuid; + uuidToHal(uid, &halUuid); + effect_descriptor_t halDescriptor; + status_t status = EffectGetDescriptor(&halUuid, &halDescriptor); + EffectDescriptor descriptor; + effectDescriptorFromHal(halDescriptor, &descriptor); + Result retval(Result::OK); + if (status != OK) { + ALOGW("Error querying effect descriptor for %s: %s", + uuidToString(halUuid).c_str(), strerror(-status)); + if (status == -ENOENT) { + retval = Result::INVALID_ARGUMENTS; + } else { + retval = Result::NOT_INITIALIZED; + } + } + _hidl_cb(retval, descriptor); + return Void(); +} + +Return EffectsFactory::createEffect( + const Uuid& uid, int32_t session, int32_t ioHandle, createEffect_cb _hidl_cb) { + effect_uuid_t halUuid; + uuidToHal(uid, &halUuid); + effect_handle_t handle; + Result retval(Result::OK); + status_t status = EffectCreate(&halUuid, session, ioHandle, &handle); + sp effect; + if (status == OK) { + effect_descriptor_t halDescriptor; + memset(&halDescriptor, 0, sizeof(effect_descriptor_t)); + status = (*handle)->get_descriptor(handle, &halDescriptor); + if (status == OK) { + effect = dispatchEffectInstanceCreation(halDescriptor, handle); + } + } + if (status != OK) { + ALOGW("Error creating effect %s: %s", uuidToString(halUuid).c_str(), strerror(-status)); + if (status == -ENOENT) { + retval = Result::INVALID_ARGUMENTS; + } else { + retval = Result::NOT_INITIALIZED; + } + } + _hidl_cb(retval, effect); + return Void(); +} + +Return EffectsFactory::debugDump(const native_handle_t* fd) { + if (fd->numFds == 1) { + EffectDumpEffects(fd->data[0]); + } + return Void(); +} + + +IEffectsFactory* HIDL_FETCH_IEffectsFactory(const char* /* name */) { + return new EffectsFactory(); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/EffectsFactory.h b/audio/effect/2.0/default/EffectsFactory.h new file mode 100644 index 0000000000..229356f170 --- /dev/null +++ b/audio/effect/2.0/default/EffectsFactory.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_EffectsFactory_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_EffectsFactory_H_ + +#include + +#include +#include + +#include +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::common::V2_0::Uuid; +using ::android::hardware::audio::effect::V2_0::EffectDescriptor; +using ::android::hardware::audio::effect::V2_0::IEffect; +using ::android::hardware::audio::effect::V2_0::IEffectsFactory; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct EffectsFactory : public IEffectsFactory { + // Methods from ::android::hardware::audio::effect::V2_0::IEffectsFactory follow. + Return getAllDescriptors(getAllDescriptors_cb _hidl_cb) override; + Return getDescriptor(const Uuid& uid, getDescriptor_cb _hidl_cb) override; + Return createEffect( + const Uuid& uid, int32_t session, int32_t ioHandle, createEffect_cb _hidl_cb) override; + Return debugDump(const native_handle_t* fd) override; + + private: + static sp dispatchEffectInstanceCreation( + const effect_descriptor_t& halDescriptor, effect_handle_t handle); +}; + +extern "C" IEffectsFactory* HIDL_FETCH_IEffectsFactory(const char* name); + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_EffectsFactory_H_ diff --git a/audio/effect/2.0/default/EnvironmentalReverbEffect.cpp b/audio/effect/2.0/default/EnvironmentalReverbEffect.cpp new file mode 100644 index 0000000000..4485be4c5c --- /dev/null +++ b/audio/effect/2.0/default/EnvironmentalReverbEffect.cpp @@ -0,0 +1,310 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "EnvReverb_HAL" +#include + +#include "EnvironmentalReverbEffect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +EnvironmentalReverbEffect::EnvironmentalReverbEffect(effect_handle_t handle) + : mEffect(new Effect(handle)) { +} + +EnvironmentalReverbEffect::~EnvironmentalReverbEffect() {} + +void EnvironmentalReverbEffect::propertiesFromHal( + const t_reverb_settings& halProperties, + IEnvironmentalReverbEffect::AllProperties* properties) { + properties->roomLevel = halProperties.roomLevel; + properties->roomHfLevel = halProperties.roomHFLevel; + properties->decayTime = halProperties.decayTime; + properties->decayHfRatio = halProperties.decayHFRatio; + properties->reflectionsLevel = halProperties.reflectionsLevel; + properties->reflectionsDelay = halProperties.reflectionsDelay; + properties->reverbLevel = halProperties.reverbLevel; + properties->reverbDelay = halProperties.reverbDelay; + properties->diffusion = halProperties.diffusion; + properties->density = halProperties.density; +} + +void EnvironmentalReverbEffect::propertiesToHal( + const IEnvironmentalReverbEffect::AllProperties& properties, + t_reverb_settings* halProperties) { + halProperties->roomLevel = properties.roomLevel; + halProperties->roomHFLevel = properties.roomHfLevel; + halProperties->decayTime = properties.decayTime; + halProperties->decayHFRatio = properties.decayHfRatio; + halProperties->reflectionsLevel = properties.reflectionsLevel; + halProperties->reflectionsDelay = properties.reflectionsDelay; + halProperties->reverbLevel = properties.reverbLevel; + halProperties->reverbDelay = properties.reverbDelay; + halProperties->diffusion = properties.diffusion; + halProperties->density = properties.density; +} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. +Return EnvironmentalReverbEffect::init() { + return mEffect->init(); +} + +Return EnvironmentalReverbEffect::setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); +} + +Return EnvironmentalReverbEffect::reset() { + return mEffect->reset(); +} + +Return EnvironmentalReverbEffect::enable() { + return mEffect->enable(); +} + +Return EnvironmentalReverbEffect::disable() { + return mEffect->disable(); +} + +Return EnvironmentalReverbEffect::setDevice(AudioDevice device) { + return mEffect->setDevice(device); +} + +Return EnvironmentalReverbEffect::setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { + return mEffect->setAndGetVolume(volumes, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setAudioMode(AudioMode mode) { + return mEffect->setAudioMode(mode); +} + +Return EnvironmentalReverbEffect::setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); +} + +Return EnvironmentalReverbEffect::setInputDevice(AudioDevice device) { + return mEffect->setInputDevice(device); +} + +Return EnvironmentalReverbEffect::getConfig(getConfig_cb _hidl_cb) { + return mEffect->getConfig(_hidl_cb); +} + +Return EnvironmentalReverbEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + return mEffect->getConfigReverse(_hidl_cb); +} + +Return EnvironmentalReverbEffect::getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); +} + +Return EnvironmentalReverbEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + return mEffect->getAuxChannelsConfig(_hidl_cb); +} + +Return EnvironmentalReverbEffect::setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) { + return mEffect->setAuxChannelsConfig(config); +} + +Return EnvironmentalReverbEffect::setAudioSource(AudioSource source) { + return mEffect->setAudioSource(source); +} + +Return EnvironmentalReverbEffect::offload(const EffectOffloadParameter& param) { + return mEffect->offload(param); +} + +Return EnvironmentalReverbEffect::getDescriptor(getDescriptor_cb _hidl_cb) { + return mEffect->getDescriptor(_hidl_cb); +} + +Return EnvironmentalReverbEffect::process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) { + return mEffect->process(inBuffer, outFrameSize, _hidl_cb); +} + +Return EnvironmentalReverbEffect::processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) { + return mEffect->processReverse(inBuffer, outFrameSize, _hidl_cb); +} + +Return EnvironmentalReverbEffect::command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setParameter( + const hidl_vec& parameter, const hidl_vec& value) { + return mEffect->setParameter(parameter, value); +} + +Return EnvironmentalReverbEffect::getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); +} + +Return EnvironmentalReverbEffect::getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); +} + +Return EnvironmentalReverbEffect::getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) { + return mEffect->setCurrentConfigForFeature(featureId, configData); +} + + +// Methods from ::android::hardware::audio::effect::V2_0::IEnvironmentalReverbEffect follow. +Return EnvironmentalReverbEffect::setBypass(bool bypass) { + return mEffect->setParam(REVERB_PARAM_BYPASS, bypass); +} + +Return EnvironmentalReverbEffect::getBypass(getBypass_cb _hidl_cb) { + return mEffect->getIntegerParam(REVERB_PARAM_BYPASS, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setRoomLevel(int16_t roomLevel) { + return mEffect->setParam(REVERB_PARAM_ROOM_LEVEL, roomLevel); +} + +Return EnvironmentalReverbEffect::getRoomLevel(getRoomLevel_cb _hidl_cb) { + return mEffect->getIntegerParam(REVERB_PARAM_ROOM_LEVEL, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setRoomHfLevel(int16_t roomHfLevel) { + return mEffect->setParam(REVERB_PARAM_ROOM_HF_LEVEL, roomHfLevel); +} + +Return EnvironmentalReverbEffect::getRoomHfLevel(getRoomHfLevel_cb _hidl_cb) { + return mEffect->getIntegerParam(REVERB_PARAM_ROOM_HF_LEVEL, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setDecayTime(uint32_t decayTime) { + return mEffect->setParam(REVERB_PARAM_DECAY_TIME, decayTime); +} + +Return EnvironmentalReverbEffect::getDecayTime(getDecayTime_cb _hidl_cb) { + return mEffect->getIntegerParam(REVERB_PARAM_DECAY_TIME, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setDecayHfRatio(int16_t decayHfRatio) { + return mEffect->setParam(REVERB_PARAM_DECAY_HF_RATIO, decayHfRatio); +} + +Return EnvironmentalReverbEffect::getDecayHfRatio(getDecayHfRatio_cb _hidl_cb) { + return mEffect->getIntegerParam(REVERB_PARAM_DECAY_HF_RATIO, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setReflectionsLevel(int16_t reflectionsLevel) { + return mEffect->setParam(REVERB_PARAM_REFLECTIONS_LEVEL, reflectionsLevel); +} + +Return EnvironmentalReverbEffect::getReflectionsLevel(getReflectionsLevel_cb _hidl_cb) { + return mEffect->getIntegerParam(REVERB_PARAM_REFLECTIONS_LEVEL, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setReflectionsDelay(uint32_t reflectionsDelay) { + return mEffect->setParam(REVERB_PARAM_REFLECTIONS_DELAY, reflectionsDelay); +} + +Return EnvironmentalReverbEffect::getReflectionsDelay(getReflectionsDelay_cb _hidl_cb) { + return mEffect->getIntegerParam(REVERB_PARAM_REFLECTIONS_DELAY, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setReverbLevel(int16_t reverbLevel) { + return mEffect->setParam(REVERB_PARAM_REVERB_LEVEL, reverbLevel); +} + +Return EnvironmentalReverbEffect::getReverbLevel(getReverbLevel_cb _hidl_cb) { + return mEffect->getIntegerParam(REVERB_PARAM_REVERB_LEVEL, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setReverbDelay(uint32_t reverbDelay) { + return mEffect->setParam(REVERB_PARAM_REVERB_DELAY, reverbDelay); +} + +Return EnvironmentalReverbEffect::getReverbDelay(getReverbDelay_cb _hidl_cb) { + return mEffect->getIntegerParam(REVERB_PARAM_REVERB_DELAY, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setDiffusion(int16_t diffusion) { + return mEffect->setParam(REVERB_PARAM_DIFFUSION, diffusion); +} + +Return EnvironmentalReverbEffect::getDiffusion(getDiffusion_cb _hidl_cb) { + return mEffect->getIntegerParam(REVERB_PARAM_DIFFUSION, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setDensity(int16_t density) { + return mEffect->setParam(REVERB_PARAM_DENSITY, density); +} + +Return EnvironmentalReverbEffect::getDensity(getDensity_cb _hidl_cb) { + return mEffect->getIntegerParam(REVERB_PARAM_DENSITY, _hidl_cb); +} + +Return EnvironmentalReverbEffect::setAllProperties( + const IEnvironmentalReverbEffect::AllProperties& properties) { + t_reverb_settings halProperties; + propertiesToHal(properties, &halProperties); + return mEffect->setParam(REVERB_PARAM_PROPERTIES, halProperties); +} + +Return EnvironmentalReverbEffect::getAllProperties(getAllProperties_cb _hidl_cb) { + t_reverb_settings halProperties; + Result retval = mEffect->getParam(REVERB_PARAM_PROPERTIES, halProperties); + AllProperties properties; + propertiesFromHal(halProperties, &properties); + _hidl_cb(retval, properties); + return Void(); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/EnvironmentalReverbEffect.h b/audio/effect/2.0/default/EnvironmentalReverbEffect.h new file mode 100644 index 0000000000..c97c51c17f --- /dev/null +++ b/audio/effect/2.0/default/EnvironmentalReverbEffect.h @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_EnvironmentalReverbEffect_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_EnvironmentalReverbEffect_H_ + +#include + +#include +#include + +#include + +#include "Effect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::common::V2_0::AudioDevice; +using ::android::hardware::audio::common::V2_0::AudioMode; +using ::android::hardware::audio::common::V2_0::AudioSource; +using ::android::hardware::audio::effect::V2_0::AudioBuffer; +using ::android::hardware::audio::effect::V2_0::EffectAuxChannelsConfig; +using ::android::hardware::audio::effect::V2_0::EffectConfig; +using ::android::hardware::audio::effect::V2_0::EffectDescriptor; +using ::android::hardware::audio::effect::V2_0::EffectOffloadParameter; +using ::android::hardware::audio::effect::V2_0::IEffect; +using ::android::hardware::audio::effect::V2_0::IEffectBufferProviderCallback; +using ::android::hardware::audio::effect::V2_0::IEnvironmentalReverbEffect; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct EnvironmentalReverbEffect : public IEnvironmentalReverbEffect { + explicit EnvironmentalReverbEffect(effect_handle_t handle); + + // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. + Return init() override; + Return setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return reset() override; + Return enable() override; + Return disable() override; + Return setDevice(AudioDevice device) override; + Return setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) override; + Return setAudioMode(AudioMode mode) override; + Return setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return setInputDevice(AudioDevice device) override; + Return getConfig(getConfig_cb _hidl_cb) override; + Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + Return getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; + Return setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; + Return setAudioSource(AudioSource source) override; + Return offload(const EffectOffloadParameter& param) override; + Return getDescriptor(getDescriptor_cb _hidl_cb) override; + Return process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; + Return processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) override; + Return command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override; + Return setParameter( + const hidl_vec& parameter, const hidl_vec& value) override; + Return getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + Return getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + Return getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + Return setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) override; + + // Methods from ::android::hardware::audio::effect::V2_0::IEnvironmentalReverbEffect follow. + Return setBypass(bool bypass) override; + Return getBypass(getBypass_cb _hidl_cb) override; + Return setRoomLevel(int16_t roomLevel) override; + Return getRoomLevel(getRoomLevel_cb _hidl_cb) override; + Return setRoomHfLevel(int16_t roomHfLevel) override; + Return getRoomHfLevel(getRoomHfLevel_cb _hidl_cb) override; + Return setDecayTime(uint32_t decayTime) override; + Return getDecayTime(getDecayTime_cb _hidl_cb) override; + Return setDecayHfRatio(int16_t decayHfRatio) override; + Return getDecayHfRatio(getDecayHfRatio_cb _hidl_cb) override; + Return setReflectionsLevel(int16_t reflectionsLevel) override; + Return getReflectionsLevel(getReflectionsLevel_cb _hidl_cb) override; + Return setReflectionsDelay(uint32_t reflectionsDelay) override; + Return getReflectionsDelay(getReflectionsDelay_cb _hidl_cb) override; + Return setReverbLevel(int16_t reverbLevel) override; + Return getReverbLevel(getReverbLevel_cb _hidl_cb) override; + Return setReverbDelay(uint32_t reverbDelay) override; + Return getReverbDelay(getReverbDelay_cb _hidl_cb) override; + Return setDiffusion(int16_t diffusion) override; + Return getDiffusion(getDiffusion_cb _hidl_cb) override; + Return setDensity(int16_t density) override; + Return getDensity(getDensity_cb _hidl_cb) override; + Return setAllProperties( + const IEnvironmentalReverbEffect::AllProperties& properties) override; + Return getAllProperties(getAllProperties_cb _hidl_cb) override; + + private: + sp mEffect; + + virtual ~EnvironmentalReverbEffect(); + + void propertiesFromHal( + const t_reverb_settings& halProperties, + IEnvironmentalReverbEffect::AllProperties* properties); + void propertiesToHal( + const IEnvironmentalReverbEffect::AllProperties& properties, + t_reverb_settings* halProperties); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_EnvironmentalReverbEffect_H_ diff --git a/audio/effect/2.0/default/EqualizerEffect.cpp b/audio/effect/2.0/default/EqualizerEffect.cpp new file mode 100644 index 0000000000..9e20b8adec --- /dev/null +++ b/audio/effect/2.0/default/EqualizerEffect.cpp @@ -0,0 +1,286 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define LOG_TAG "Equalizer_HAL" +#include + +#include "EqualizerEffect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +EqualizerEffect::EqualizerEffect(effect_handle_t handle) + : mEffect(new Effect(handle)) { +} + +EqualizerEffect::~EqualizerEffect() {} + +void EqualizerEffect::propertiesFromHal( + t_equalizer_settings& halProperties, + IEqualizerEffect::AllProperties* properties) { + properties->curPreset = halProperties.curPreset; + properties->bandLevels.setToExternal(&halProperties.bandLevels[0], halProperties.numBands); +} + +std::vector EqualizerEffect::propertiesToHal( + const IEqualizerEffect::AllProperties& properties, + t_equalizer_settings** halProperties) { + size_t bandsSize = properties.bandLevels.size() * sizeof(uint16_t); + std::vector halBuffer(sizeof(t_equalizer_settings) + bandsSize, 0); + *halProperties = reinterpret_cast(&halBuffer[0]); + (*halProperties)->curPreset = properties.curPreset; + (*halProperties)->numBands = properties.bandLevels.size(); + memcpy((*halProperties)->bandLevels, &properties.bandLevels[0], bandsSize); + return halBuffer; +} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. +Return EqualizerEffect::init() { + return mEffect->init(); +} + +Return EqualizerEffect::setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); +} + +Return EqualizerEffect::reset() { + return mEffect->reset(); +} + +Return EqualizerEffect::enable() { + return mEffect->enable(); +} + +Return EqualizerEffect::disable() { + return mEffect->disable(); +} + +Return EqualizerEffect::setDevice(AudioDevice device) { + return mEffect->setDevice(device); +} + +Return EqualizerEffect::setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { + return mEffect->setAndGetVolume(volumes, _hidl_cb); +} + +Return EqualizerEffect::setAudioMode(AudioMode mode) { + return mEffect->setAudioMode(mode); +} + +Return EqualizerEffect::setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); +} + +Return EqualizerEffect::setInputDevice(AudioDevice device) { + return mEffect->setInputDevice(device); +} + +Return EqualizerEffect::getConfig(getConfig_cb _hidl_cb) { + return mEffect->getConfig(_hidl_cb); +} + +Return EqualizerEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + return mEffect->getConfigReverse(_hidl_cb); +} + +Return EqualizerEffect::getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); +} + +Return EqualizerEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + return mEffect->getAuxChannelsConfig(_hidl_cb); +} + +Return EqualizerEffect::setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) { + return mEffect->setAuxChannelsConfig(config); +} + +Return EqualizerEffect::setAudioSource(AudioSource source) { + return mEffect->setAudioSource(source); +} + +Return EqualizerEffect::offload(const EffectOffloadParameter& param) { + return mEffect->offload(param); +} + +Return EqualizerEffect::getDescriptor(getDescriptor_cb _hidl_cb) { + return mEffect->getDescriptor(_hidl_cb); +} + +Return EqualizerEffect::process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) { + return mEffect->process(inBuffer, outFrameSize, _hidl_cb); +} + +Return EqualizerEffect::processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) { + return mEffect->processReverse(inBuffer, outFrameSize, _hidl_cb); +} + +Return EqualizerEffect::command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); +} + +Return EqualizerEffect::setParameter( + const hidl_vec& parameter, const hidl_vec& value) { + return mEffect->setParameter(parameter, value); +} + +Return EqualizerEffect::getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); +} + +Return EqualizerEffect::getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); +} + +Return EqualizerEffect::getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); +} + +Return EqualizerEffect::setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) { + return mEffect->setCurrentConfigForFeature(featureId, configData); +} + + +// Methods from ::android::hardware::audio::effect::V2_0::IEqualizerEffect follow. +Return EqualizerEffect::getNumBands(getNumBands_cb _hidl_cb) { + return mEffect->getIntegerParam(EQ_PARAM_NUM_BANDS, _hidl_cb); +} + +Return EqualizerEffect::getLevelRange(getLevelRange_cb _hidl_cb) { + uint16_t halLevels[2] = { 0, 0 }; + Result retval = mEffect->getParam(EQ_PARAM_LEVEL_RANGE, halLevels); + _hidl_cb(retval, halLevels[0], halLevels[1]); + return Void(); +} + +Return EqualizerEffect::setBandLevel(uint16_t band, uint16_t level) { + return mEffect->setParam(EQ_PARAM_BAND_LEVEL, band, level); +} + +Return EqualizerEffect::getBandLevel(uint16_t band, getBandLevel_cb _hidl_cb) { + uint16_t halLevel = 0; + Result retval = mEffect->getParam(EQ_PARAM_BAND_LEVEL, band, halLevel); + _hidl_cb(retval, halLevel); + return Void(); +} + +Return EqualizerEffect::getBandCenterFrequency( + uint16_t band, getBandCenterFrequency_cb _hidl_cb) { + uint32_t halFreq = 0; + Result retval = mEffect->getParam(EQ_PARAM_CENTER_FREQ, band, halFreq); + _hidl_cb(retval, halFreq); + return Void(); +} + +Return EqualizerEffect::getBandFrequencyRange( + uint16_t band, getBandFrequencyRange_cb _hidl_cb) { + uint32_t halFreqs[2] = { 0, 0 }; + Result retval = mEffect->getParam(EQ_PARAM_BAND_FREQ_RANGE, band, halFreqs); + _hidl_cb(retval, halFreqs[0], halFreqs[1]); + return Void(); +} + +Return EqualizerEffect::getBandForFrequency(uint32_t freq, getBandForFrequency_cb _hidl_cb) { + uint16_t halBand = 0; + Result retval = mEffect->getParam(EQ_PARAM_GET_BAND, freq, halBand); + _hidl_cb(retval, halBand); + return Void(); +} + +Return EqualizerEffect::getPresetNames(getPresetNames_cb _hidl_cb) { + uint16_t halPresetCount = 0; + Result retval = mEffect->getParam(EQ_PARAM_GET_NUM_OF_PRESETS, halPresetCount); + hidl_vec presetNames; + if (retval == Result::OK) { + presetNames.resize(halPresetCount); + for (uint16_t i = 0; i < halPresetCount; ++i) { + char halPresetName[EFFECT_STRING_LEN_MAX]; + retval = mEffect->getParam(EQ_PARAM_GET_PRESET_NAME, i, halPresetName); + if (retval == Result::OK) { + presetNames[i] = halPresetName; + } else { + presetNames.resize(i); + } + } + } + _hidl_cb(retval, presetNames); + return Void(); +} + +Return EqualizerEffect::setCurrentPreset(uint16_t preset) { + return mEffect->setParam(EQ_PARAM_CUR_PRESET, preset); +} + +Return EqualizerEffect::getCurrentPreset(getCurrentPreset_cb _hidl_cb) { + return mEffect->getIntegerParam(EQ_PARAM_CUR_PRESET, _hidl_cb); +} + +Return EqualizerEffect::setAllProperties( + const IEqualizerEffect::AllProperties& properties) { + t_equalizer_settings *halPropertiesPtr = nullptr; + std::vector halBuffer = propertiesToHal(properties, &halPropertiesPtr); + return mEffect->setParam(EQ_PARAM_PROPERTIES, *halPropertiesPtr); +} + +Return EqualizerEffect::getAllProperties(getAllProperties_cb _hidl_cb) { + t_equalizer_settings halProperties; + Result retval = mEffect->getParam(EQ_PARAM_PROPERTIES, halProperties); + AllProperties properties; + propertiesFromHal(halProperties, &properties); + _hidl_cb(retval, properties); + return Void(); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/EqualizerEffect.h b/audio/effect/2.0/default/EqualizerEffect.h new file mode 100644 index 0000000000..5665e9c572 --- /dev/null +++ b/audio/effect/2.0/default/EqualizerEffect.h @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_EqualizerEffect_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_EqualizerEffect_H_ + +#include + +#include + +#include +#include + +#include + +#include "Effect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::common::V2_0::AudioDevice; +using ::android::hardware::audio::common::V2_0::AudioMode; +using ::android::hardware::audio::common::V2_0::AudioSource; +using ::android::hardware::audio::effect::V2_0::AudioBuffer; +using ::android::hardware::audio::effect::V2_0::EffectAuxChannelsConfig; +using ::android::hardware::audio::effect::V2_0::EffectConfig; +using ::android::hardware::audio::effect::V2_0::EffectDescriptor; +using ::android::hardware::audio::effect::V2_0::EffectOffloadParameter; +using ::android::hardware::audio::effect::V2_0::IEffect; +using ::android::hardware::audio::effect::V2_0::IEffectBufferProviderCallback; +using ::android::hardware::audio::effect::V2_0::IEqualizerEffect; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct EqualizerEffect : public IEqualizerEffect { + explicit EqualizerEffect(effect_handle_t handle); + + // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. + Return init() override; + Return setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return reset() override; + Return enable() override; + Return disable() override; + Return setDevice(AudioDevice device) override; + Return setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) override; + Return setAudioMode(AudioMode mode) override; + Return setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return setInputDevice(AudioDevice device) override; + Return getConfig(getConfig_cb _hidl_cb) override; + Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + Return getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; + Return setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; + Return setAudioSource(AudioSource source) override; + Return offload(const EffectOffloadParameter& param) override; + Return getDescriptor(getDescriptor_cb _hidl_cb) override; + Return process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; + Return processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) override; + Return command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override; + Return setParameter( + const hidl_vec& parameter, const hidl_vec& value) override; + Return getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + Return getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + Return getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + Return setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) override; + + // Methods from ::android::hardware::audio::effect::V2_0::IEqualizerEffect follow. + Return getNumBands(getNumBands_cb _hidl_cb) override; + Return getLevelRange(getLevelRange_cb _hidl_cb) override; + Return setBandLevel(uint16_t band, uint16_t level) override; + Return getBandLevel(uint16_t band, getBandLevel_cb _hidl_cb) override; + Return getBandCenterFrequency( + uint16_t band, getBandCenterFrequency_cb _hidl_cb) override; + Return getBandFrequencyRange(uint16_t band, getBandFrequencyRange_cb _hidl_cb) override; + Return getBandForFrequency(uint32_t freq, getBandForFrequency_cb _hidl_cb) override; + Return getPresetNames(getPresetNames_cb _hidl_cb) override; + Return setCurrentPreset(uint16_t preset) override; + Return getCurrentPreset(getCurrentPreset_cb _hidl_cb) override; + Return setAllProperties(const IEqualizerEffect::AllProperties& properties) override; + Return getAllProperties(getAllProperties_cb _hidl_cb) override; + + private: + sp mEffect; + + virtual ~EqualizerEffect(); + + void propertiesFromHal( + t_equalizer_settings& halProperties, + IEqualizerEffect::AllProperties* properties); + std::vector propertiesToHal( + const IEqualizerEffect::AllProperties& properties, + t_equalizer_settings** halProperties); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_EqualizerEffect_H_ diff --git a/audio/effect/2.0/default/LoudnessEnhancerEffect.cpp b/audio/effect/2.0/default/LoudnessEnhancerEffect.cpp new file mode 100644 index 0000000000..1e724e04d8 --- /dev/null +++ b/audio/effect/2.0/default/LoudnessEnhancerEffect.cpp @@ -0,0 +1,187 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define LOG_TAG "LoudnessEnhancer_HAL" +#include +#include + +#include "LoudnessEnhancerEffect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +LoudnessEnhancerEffect::LoudnessEnhancerEffect(effect_handle_t handle) + : mEffect(new Effect(handle)) { +} + +LoudnessEnhancerEffect::~LoudnessEnhancerEffect() {} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. +Return LoudnessEnhancerEffect::init() { + return mEffect->init(); +} + +Return LoudnessEnhancerEffect::setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); +} + +Return LoudnessEnhancerEffect::reset() { + return mEffect->reset(); +} + +Return LoudnessEnhancerEffect::enable() { + return mEffect->enable(); +} + +Return LoudnessEnhancerEffect::disable() { + return mEffect->disable(); +} + +Return LoudnessEnhancerEffect::setDevice(AudioDevice device) { + return mEffect->setDevice(device); +} + +Return LoudnessEnhancerEffect::setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { + return mEffect->setAndGetVolume(volumes, _hidl_cb); +} + +Return LoudnessEnhancerEffect::setAudioMode(AudioMode mode) { + return mEffect->setAudioMode(mode); +} + +Return LoudnessEnhancerEffect::setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); +} + +Return LoudnessEnhancerEffect::setInputDevice(AudioDevice device) { + return mEffect->setInputDevice(device); +} + +Return LoudnessEnhancerEffect::getConfig(getConfig_cb _hidl_cb) { + return mEffect->getConfig(_hidl_cb); +} + +Return LoudnessEnhancerEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + return mEffect->getConfigReverse(_hidl_cb); +} + +Return LoudnessEnhancerEffect::getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); +} + +Return LoudnessEnhancerEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + return mEffect->getAuxChannelsConfig(_hidl_cb); +} + +Return LoudnessEnhancerEffect::setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) { + return mEffect->setAuxChannelsConfig(config); +} + +Return LoudnessEnhancerEffect::setAudioSource(AudioSource source) { + return mEffect->setAudioSource(source); +} + +Return LoudnessEnhancerEffect::offload(const EffectOffloadParameter& param) { + return mEffect->offload(param); +} + +Return LoudnessEnhancerEffect::getDescriptor(getDescriptor_cb _hidl_cb) { + return mEffect->getDescriptor(_hidl_cb); +} + +Return LoudnessEnhancerEffect::process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) { + return mEffect->process(inBuffer, outFrameSize, _hidl_cb); +} + +Return LoudnessEnhancerEffect::processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) { + return mEffect->processReverse(inBuffer, outFrameSize, _hidl_cb); +} + +Return LoudnessEnhancerEffect::command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); +} + +Return LoudnessEnhancerEffect::setParameter( + const hidl_vec& parameter, const hidl_vec& value) { + return mEffect->setParameter(parameter, value); +} + +Return LoudnessEnhancerEffect::getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); +} + +Return LoudnessEnhancerEffect::getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); +} + +Return LoudnessEnhancerEffect::getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); +} + +Return LoudnessEnhancerEffect::setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) { + return mEffect->setCurrentConfigForFeature(featureId, configData); +} + + +// Methods from ::android::hardware::audio::effect::V2_0::ILoudnessEnhancerEffect follow. +Return LoudnessEnhancerEffect::setTargetGain(int32_t targetGainMb) { + return mEffect->setParam(LOUDNESS_ENHANCER_DEFAULT_TARGET_GAIN_MB, targetGainMb); +} + +Return LoudnessEnhancerEffect::getTargetGain(getTargetGain_cb _hidl_cb) { + return mEffect->getIntegerParam(LOUDNESS_ENHANCER_DEFAULT_TARGET_GAIN_MB, _hidl_cb); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/LoudnessEnhancerEffect.h b/audio/effect/2.0/default/LoudnessEnhancerEffect.h new file mode 100644 index 0000000000..e68b038416 --- /dev/null +++ b/audio/effect/2.0/default/LoudnessEnhancerEffect.h @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_LoudnessEnhancerEffect_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_LoudnessEnhancerEffect_H_ + +#include +#include + +#include + +#include "Effect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::common::V2_0::AudioDevice; +using ::android::hardware::audio::common::V2_0::AudioMode; +using ::android::hardware::audio::common::V2_0::AudioSource; +using ::android::hardware::audio::effect::V2_0::AudioBuffer; +using ::android::hardware::audio::effect::V2_0::EffectAuxChannelsConfig; +using ::android::hardware::audio::effect::V2_0::EffectConfig; +using ::android::hardware::audio::effect::V2_0::EffectDescriptor; +using ::android::hardware::audio::effect::V2_0::EffectOffloadParameter; +using ::android::hardware::audio::effect::V2_0::IEffect; +using ::android::hardware::audio::effect::V2_0::IEffectBufferProviderCallback; +using ::android::hardware::audio::effect::V2_0::ILoudnessEnhancerEffect; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct LoudnessEnhancerEffect : public ILoudnessEnhancerEffect { + explicit LoudnessEnhancerEffect(effect_handle_t handle); + + // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. + Return init() override; + Return setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return reset() override; + Return enable() override; + Return disable() override; + Return setDevice(AudioDevice device) override; + Return setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) override; + Return setAudioMode(AudioMode mode) override; + Return setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return setInputDevice(AudioDevice device) override; + Return getConfig(getConfig_cb _hidl_cb) override; + Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + Return getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; + Return setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; + Return setAudioSource(AudioSource source) override; + Return offload(const EffectOffloadParameter& param) override; + Return getDescriptor(getDescriptor_cb _hidl_cb) override; + Return process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; + Return processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) override; + Return command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override; + Return setParameter( + const hidl_vec& parameter, const hidl_vec& value) override; + Return getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + Return getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + Return getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + Return setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) override; + + // Methods from ::android::hardware::audio::effect::V2_0::ILoudnessEnhancerEffect follow. + Return setTargetGain(int32_t targetGainMb) override; + Return getTargetGain(getTargetGain_cb _hidl_cb) override; + + private: + sp mEffect; + + virtual ~LoudnessEnhancerEffect(); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_LoudnessEnhancerEffect_H_ diff --git a/audio/effect/2.0/default/NoiseSuppressionEffect.cpp b/audio/effect/2.0/default/NoiseSuppressionEffect.cpp new file mode 100644 index 0000000000..5c392df8c7 --- /dev/null +++ b/audio/effect/2.0/default/NoiseSuppressionEffect.cpp @@ -0,0 +1,228 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "NS_Effect_HAL" +#include + +#include "NoiseSuppressionEffect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +NoiseSuppressionEffect::NoiseSuppressionEffect(effect_handle_t handle) + : mEffect(new Effect(handle)) { +} + +NoiseSuppressionEffect::~NoiseSuppressionEffect() {} + +void NoiseSuppressionEffect::propertiesFromHal( + const t_ns_settings& halProperties, + INoiseSuppressionEffect::AllProperties* properties) { + properties->level = Level(halProperties.level); + properties->type = Type(halProperties.type); +} + +void NoiseSuppressionEffect::propertiesToHal( + const INoiseSuppressionEffect::AllProperties& properties, + t_ns_settings* halProperties) { + halProperties->level = static_cast(properties.level); + halProperties->type = static_cast(properties.type); +} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. +Return NoiseSuppressionEffect::init() { + return mEffect->init(); +} + +Return NoiseSuppressionEffect::setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); +} + +Return NoiseSuppressionEffect::reset() { + return mEffect->reset(); +} + +Return NoiseSuppressionEffect::enable() { + return mEffect->enable(); +} + +Return NoiseSuppressionEffect::disable() { + return mEffect->disable(); +} + +Return NoiseSuppressionEffect::setDevice(AudioDevice device) { + return mEffect->setDevice(device); +} + +Return NoiseSuppressionEffect::setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { + return mEffect->setAndGetVolume(volumes, _hidl_cb); +} + +Return NoiseSuppressionEffect::setAudioMode(AudioMode mode) { + return mEffect->setAudioMode(mode); +} + +Return NoiseSuppressionEffect::setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); +} + +Return NoiseSuppressionEffect::setInputDevice(AudioDevice device) { + return mEffect->setInputDevice(device); +} + +Return NoiseSuppressionEffect::getConfig(getConfig_cb _hidl_cb) { + return mEffect->getConfig(_hidl_cb); +} + +Return NoiseSuppressionEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + return mEffect->getConfigReverse(_hidl_cb); +} + +Return NoiseSuppressionEffect::getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); +} + +Return NoiseSuppressionEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + return mEffect->getAuxChannelsConfig(_hidl_cb); +} + +Return NoiseSuppressionEffect::setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) { + return mEffect->setAuxChannelsConfig(config); +} + +Return NoiseSuppressionEffect::setAudioSource(AudioSource source) { + return mEffect->setAudioSource(source); +} + +Return NoiseSuppressionEffect::offload(const EffectOffloadParameter& param) { + return mEffect->offload(param); +} + +Return NoiseSuppressionEffect::getDescriptor(getDescriptor_cb _hidl_cb) { + return mEffect->getDescriptor(_hidl_cb); +} + +Return NoiseSuppressionEffect::process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) { + return mEffect->process(inBuffer, outFrameSize, _hidl_cb); +} + +Return NoiseSuppressionEffect::processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) { + return mEffect->processReverse(inBuffer, outFrameSize, _hidl_cb); +} + +Return NoiseSuppressionEffect::command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); +} + +Return NoiseSuppressionEffect::setParameter( + const hidl_vec& parameter, const hidl_vec& value) { + return mEffect->setParameter(parameter, value); +} + +Return NoiseSuppressionEffect::getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); +} + +Return NoiseSuppressionEffect::getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); +} + +Return NoiseSuppressionEffect::getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); +} + +Return NoiseSuppressionEffect::setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) { + return mEffect->setCurrentConfigForFeature(featureId, configData); +} + + +// Methods from ::android::hardware::audio::effect::V2_0::INoiseSuppressionEffect follow. +Return NoiseSuppressionEffect::setSuppressionLevel(INoiseSuppressionEffect::Level level) { + return mEffect->setParam(NS_PARAM_LEVEL, static_cast(level)); +} + +Return NoiseSuppressionEffect::getSuppressionLevel(getSuppressionLevel_cb _hidl_cb) { + int32_t halLevel = 0; + Result retval = mEffect->getParam(NS_PARAM_LEVEL, halLevel); + _hidl_cb(retval, Level(halLevel)); + return Void(); +} + +Return NoiseSuppressionEffect::setSuppressionType(INoiseSuppressionEffect::Type type) { + return mEffect->setParam(NS_PARAM_TYPE, static_cast(type)); +} + +Return NoiseSuppressionEffect::getSuppressionType(getSuppressionType_cb _hidl_cb) { + int32_t halType = 0; + Result retval = mEffect->getParam(NS_PARAM_TYPE, halType); + _hidl_cb(retval, Type(halType)); + return Void(); +} + +Return NoiseSuppressionEffect::setAllProperties( + const INoiseSuppressionEffect::AllProperties& properties) { + t_ns_settings halProperties; + propertiesToHal(properties, &halProperties); + return mEffect->setParam(NS_PARAM_PROPERTIES, halProperties); +} + +Return NoiseSuppressionEffect::getAllProperties(getAllProperties_cb _hidl_cb) { + t_ns_settings halProperties; + Result retval = mEffect->getParam(NS_PARAM_PROPERTIES, halProperties); + AllProperties properties; + propertiesFromHal(halProperties, &properties); + _hidl_cb(retval, properties); + return Void(); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/NoiseSuppressionEffect.h b/audio/effect/2.0/default/NoiseSuppressionEffect.h new file mode 100644 index 0000000000..83e513e679 --- /dev/null +++ b/audio/effect/2.0/default/NoiseSuppressionEffect.h @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_NoiseSuppressionEffect_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_NoiseSuppressionEffect_H_ + +#include + +#include +#include + +#include + +#include "Effect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::common::V2_0::AudioDevice; +using ::android::hardware::audio::common::V2_0::AudioMode; +using ::android::hardware::audio::common::V2_0::AudioSource; +using ::android::hardware::audio::effect::V2_0::AudioBuffer; +using ::android::hardware::audio::effect::V2_0::EffectAuxChannelsConfig; +using ::android::hardware::audio::effect::V2_0::EffectConfig; +using ::android::hardware::audio::effect::V2_0::EffectDescriptor; +using ::android::hardware::audio::effect::V2_0::EffectOffloadParameter; +using ::android::hardware::audio::effect::V2_0::IEffect; +using ::android::hardware::audio::effect::V2_0::IEffectBufferProviderCallback; +using ::android::hardware::audio::effect::V2_0::INoiseSuppressionEffect; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct NoiseSuppressionEffect : public INoiseSuppressionEffect { + explicit NoiseSuppressionEffect(effect_handle_t handle); + + // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. + Return init() override; + Return setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return reset() override; + Return enable() override; + Return disable() override; + Return setDevice(AudioDevice device) override; + Return setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) override; + Return setAudioMode(AudioMode mode) override; + Return setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return setInputDevice(AudioDevice device) override; + Return getConfig(getConfig_cb _hidl_cb) override; + Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + Return getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; + Return setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; + Return setAudioSource(AudioSource source) override; + Return offload(const EffectOffloadParameter& param) override; + Return getDescriptor(getDescriptor_cb _hidl_cb) override; + Return process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; + Return processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) override; + Return command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override; + Return setParameter( + const hidl_vec& parameter, const hidl_vec& value) override; + Return getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + Return getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + Return getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + Return setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) override; + + // Methods from ::android::hardware::audio::effect::V2_0::INoiseSuppressionEffect follow. + Return setSuppressionLevel(INoiseSuppressionEffect::Level level) override; + Return getSuppressionLevel(getSuppressionLevel_cb _hidl_cb) override; + Return setSuppressionType(INoiseSuppressionEffect::Type type) override; + Return getSuppressionType(getSuppressionType_cb _hidl_cb) override; + Return setAllProperties( + const INoiseSuppressionEffect::AllProperties& properties) override; + Return getAllProperties(getAllProperties_cb _hidl_cb) override; + + private: + sp mEffect; + + virtual ~NoiseSuppressionEffect(); + + void propertiesFromHal( + const t_ns_settings& halProperties, + INoiseSuppressionEffect::AllProperties* properties); + void propertiesToHal( + const INoiseSuppressionEffect::AllProperties& properties, + t_ns_settings* halProperties); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_NoiseSuppressionEffect_H_ diff --git a/audio/effect/2.0/default/PresetReverbEffect.cpp b/audio/effect/2.0/default/PresetReverbEffect.cpp new file mode 100644 index 0000000000..988bc510dd --- /dev/null +++ b/audio/effect/2.0/default/PresetReverbEffect.cpp @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "PresetReverb_HAL" +#include +#include + +#include "PresetReverbEffect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +PresetReverbEffect::PresetReverbEffect(effect_handle_t handle) + : mEffect(new Effect(handle)) { +} + +PresetReverbEffect::~PresetReverbEffect() {} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. +Return PresetReverbEffect::init() { + return mEffect->init(); +} + +Return PresetReverbEffect::setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); +} + +Return PresetReverbEffect::reset() { + return mEffect->reset(); +} + +Return PresetReverbEffect::enable() { + return mEffect->enable(); +} + +Return PresetReverbEffect::disable() { + return mEffect->disable(); +} + +Return PresetReverbEffect::setDevice(AudioDevice device) { + return mEffect->setDevice(device); +} + +Return PresetReverbEffect::setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { + return mEffect->setAndGetVolume(volumes, _hidl_cb); +} + +Return PresetReverbEffect::setAudioMode(AudioMode mode) { + return mEffect->setAudioMode(mode); +} + +Return PresetReverbEffect::setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); +} + +Return PresetReverbEffect::setInputDevice(AudioDevice device) { + return mEffect->setInputDevice(device); +} + +Return PresetReverbEffect::getConfig(getConfig_cb _hidl_cb) { + return mEffect->getConfig(_hidl_cb); +} + +Return PresetReverbEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + return mEffect->getConfigReverse(_hidl_cb); +} + +Return PresetReverbEffect::getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); +} + +Return PresetReverbEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + return mEffect->getAuxChannelsConfig(_hidl_cb); +} + +Return PresetReverbEffect::setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) { + return mEffect->setAuxChannelsConfig(config); +} + +Return PresetReverbEffect::setAudioSource(AudioSource source) { + return mEffect->setAudioSource(source); +} + +Return PresetReverbEffect::offload(const EffectOffloadParameter& param) { + return mEffect->offload(param); +} + +Return PresetReverbEffect::getDescriptor(getDescriptor_cb _hidl_cb) { + return mEffect->getDescriptor(_hidl_cb); +} + +Return PresetReverbEffect::process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) { + return mEffect->process(inBuffer, outFrameSize, _hidl_cb); +} + +Return PresetReverbEffect::processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) { + return mEffect->processReverse(inBuffer, outFrameSize, _hidl_cb); +} + +Return PresetReverbEffect::command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); +} + +Return PresetReverbEffect::setParameter( + const hidl_vec& parameter, const hidl_vec& value) { + return mEffect->setParameter(parameter, value); +} + +Return PresetReverbEffect::getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); +} + +Return PresetReverbEffect::getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); +} + +Return PresetReverbEffect::getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); +} + +Return PresetReverbEffect::setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) { + return mEffect->setCurrentConfigForFeature(featureId, configData); +} + + +// Methods from ::android::hardware::audio::effect::V2_0::IPresetReverbEffect follow. +Return PresetReverbEffect::setPreset(IPresetReverbEffect::Preset preset) { + return mEffect->setParam(REVERB_PARAM_PRESET, static_cast(preset)); +} + +Return PresetReverbEffect::getPreset(getPreset_cb _hidl_cb) { + t_reverb_presets halPreset = REVERB_PRESET_NONE; + Result retval = mEffect->getParam(REVERB_PARAM_PRESET, halPreset); + _hidl_cb(retval, Preset(halPreset)); + return Void(); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/PresetReverbEffect.h b/audio/effect/2.0/default/PresetReverbEffect.h new file mode 100644 index 0000000000..3d98102e31 --- /dev/null +++ b/audio/effect/2.0/default/PresetReverbEffect.h @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_PresetReverbEffect_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_PresetReverbEffect_H_ + +#include +#include + +#include + +#include "Effect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::common::V2_0::AudioDevice; +using ::android::hardware::audio::common::V2_0::AudioMode; +using ::android::hardware::audio::common::V2_0::AudioSource; +using ::android::hardware::audio::effect::V2_0::AudioBuffer; +using ::android::hardware::audio::effect::V2_0::EffectAuxChannelsConfig; +using ::android::hardware::audio::effect::V2_0::EffectConfig; +using ::android::hardware::audio::effect::V2_0::EffectDescriptor; +using ::android::hardware::audio::effect::V2_0::EffectOffloadParameter; +using ::android::hardware::audio::effect::V2_0::IEffect; +using ::android::hardware::audio::effect::V2_0::IEffectBufferProviderCallback; +using ::android::hardware::audio::effect::V2_0::IPresetReverbEffect; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct PresetReverbEffect : public IPresetReverbEffect { + explicit PresetReverbEffect(effect_handle_t handle); + + // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. + Return init() override; + Return setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return reset() override; + Return enable() override; + Return disable() override; + Return setDevice(AudioDevice device) override; + Return setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) override; + Return setAudioMode(AudioMode mode) override; + Return setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return setInputDevice(AudioDevice device) override; + Return getConfig(getConfig_cb _hidl_cb) override; + Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + Return getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; + Return setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; + Return setAudioSource(AudioSource source) override; + Return offload(const EffectOffloadParameter& param) override; + Return getDescriptor(getDescriptor_cb _hidl_cb) override; + Return process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; + Return processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) override; + Return command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override; + Return setParameter( + const hidl_vec& parameter, const hidl_vec& value) override; + Return getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + Return getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + Return getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + Return setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) override; + + // Methods from ::android::hardware::audio::effect::V2_0::IPresetReverbEffect follow. + Return setPreset(IPresetReverbEffect::Preset preset) override; + Return getPreset(getPreset_cb _hidl_cb) override; + + private: + sp mEffect; + + virtual ~PresetReverbEffect(); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_PresetReverbEffect_H_ diff --git a/audio/effect/2.0/default/VirtualizerEffect.cpp b/audio/effect/2.0/default/VirtualizerEffect.cpp new file mode 100644 index 0000000000..af5252bcb9 --- /dev/null +++ b/audio/effect/2.0/default/VirtualizerEffect.cpp @@ -0,0 +1,242 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define LOG_TAG "Virtualizer_HAL" +#include +#include + +#include "VirtualizerEffect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +VirtualizerEffect::VirtualizerEffect(effect_handle_t handle) + : mEffect(new Effect(handle)) { +} + +VirtualizerEffect::~VirtualizerEffect() {} + +void VirtualizerEffect::speakerAnglesFromHal( + const int32_t* halAngles, uint32_t channelCount, hidl_vec& speakerAngles) { + speakerAngles.resize(channelCount); + for (uint32_t i = 0; i < channelCount; ++i) { + speakerAngles[i].mask = AudioChannelMask(*halAngles++); + speakerAngles[i].azimuth = *halAngles++; + speakerAngles[i].elevation = *halAngles++; + } +} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. +Return VirtualizerEffect::init() { + return mEffect->init(); +} + +Return VirtualizerEffect::setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); +} + +Return VirtualizerEffect::reset() { + return mEffect->reset(); +} + +Return VirtualizerEffect::enable() { + return mEffect->enable(); +} + +Return VirtualizerEffect::disable() { + return mEffect->disable(); +} + +Return VirtualizerEffect::setDevice(AudioDevice device) { + return mEffect->setDevice(device); +} + +Return VirtualizerEffect::setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { + return mEffect->setAndGetVolume(volumes, _hidl_cb); +} + +Return VirtualizerEffect::setAudioMode(AudioMode mode) { + return mEffect->setAudioMode(mode); +} + +Return VirtualizerEffect::setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); +} + +Return VirtualizerEffect::setInputDevice(AudioDevice device) { + return mEffect->setInputDevice(device); +} + +Return VirtualizerEffect::getConfig(getConfig_cb _hidl_cb) { + return mEffect->getConfig(_hidl_cb); +} + +Return VirtualizerEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + return mEffect->getConfigReverse(_hidl_cb); +} + +Return VirtualizerEffect::getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); +} + +Return VirtualizerEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + return mEffect->getAuxChannelsConfig(_hidl_cb); +} + +Return VirtualizerEffect::setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) { + return mEffect->setAuxChannelsConfig(config); +} + +Return VirtualizerEffect::setAudioSource(AudioSource source) { + return mEffect->setAudioSource(source); +} + +Return VirtualizerEffect::offload(const EffectOffloadParameter& param) { + return mEffect->offload(param); +} + +Return VirtualizerEffect::getDescriptor(getDescriptor_cb _hidl_cb) { + return mEffect->getDescriptor(_hidl_cb); +} + +Return VirtualizerEffect::process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) { + return mEffect->process(inBuffer, outFrameSize, _hidl_cb); +} + +Return VirtualizerEffect::processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) { + return mEffect->processReverse(inBuffer, outFrameSize, _hidl_cb); +} + +Return VirtualizerEffect::command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); +} + +Return VirtualizerEffect::setParameter( + const hidl_vec& parameter, const hidl_vec& value) { + return mEffect->setParameter(parameter, value); +} + +Return VirtualizerEffect::getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); +} + +Return VirtualizerEffect::getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); +} + +Return VirtualizerEffect::getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); +} + +Return VirtualizerEffect::setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) { + return mEffect->setCurrentConfigForFeature(featureId, configData); +} + + +// Methods from ::android::hardware::audio::effect::V2_0::IVirtualizerEffect follow. +Return VirtualizerEffect::isStrengthSupported() { + bool halSupported = false; + mEffect->getParam(VIRTUALIZER_PARAM_STRENGTH_SUPPORTED, halSupported); + return halSupported; +} + +Return VirtualizerEffect::setStrength(uint16_t strength) { + return mEffect->setParam(VIRTUALIZER_PARAM_STRENGTH, strength); +} + +Return VirtualizerEffect::getStrength(getStrength_cb _hidl_cb) { + return mEffect->getIntegerParam(VIRTUALIZER_PARAM_STRENGTH, _hidl_cb); +} + +Return VirtualizerEffect::getVirtualSpeakerAngles( + AudioChannelMask mask, AudioDevice device, getVirtualSpeakerAngles_cb _hidl_cb) { + uint32_t channelCount = audio_channel_count_from_out_mask( + static_cast(mask)); + size_t halSpeakerAnglesSize = sizeof(int32_t) * 3 * channelCount; + uint32_t halParam[3] = { + VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES, + static_cast(mask), + static_cast(device) + }; + hidl_vec speakerAngles; + Result retval = mEffect->getParameterImpl( + sizeof(halParam), halParam, + halSpeakerAnglesSize, + [&] (uint32_t valueSize, const void* valueData) { + if (valueSize > halSpeakerAnglesSize) { + valueSize = halSpeakerAnglesSize; + } else if (valueSize < halSpeakerAnglesSize) { + channelCount = valueSize / (sizeof(int32_t) * 3); + } + speakerAnglesFromHal( + reinterpret_cast(valueData), channelCount, speakerAngles); + }); + _hidl_cb(retval, speakerAngles); + return Void(); +} + +Return VirtualizerEffect::forceVirtualizationMode(AudioDevice device) { + return mEffect->setParam( + VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE, static_cast(device)); +} + +Return VirtualizerEffect::getVirtualizationMode(getVirtualizationMode_cb _hidl_cb) { + uint32_t halMode = 0; + Result retval = mEffect->getParam(VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE, halMode); + _hidl_cb(retval, AudioDevice(halMode)); + return Void(); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/VirtualizerEffect.h b/audio/effect/2.0/default/VirtualizerEffect.h new file mode 100644 index 0000000000..2731c4e273 --- /dev/null +++ b/audio/effect/2.0/default/VirtualizerEffect.h @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_VirtualizerEffect_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_VirtualizerEffect_H_ + +#include +#include + +#include + +#include "Effect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::common::V2_0::AudioChannelMask; +using ::android::hardware::audio::common::V2_0::AudioDevice; +using ::android::hardware::audio::common::V2_0::AudioMode; +using ::android::hardware::audio::common::V2_0::AudioSource; +using ::android::hardware::audio::effect::V2_0::AudioBuffer; +using ::android::hardware::audio::effect::V2_0::EffectAuxChannelsConfig; +using ::android::hardware::audio::effect::V2_0::EffectConfig; +using ::android::hardware::audio::effect::V2_0::EffectDescriptor; +using ::android::hardware::audio::effect::V2_0::EffectOffloadParameter; +using ::android::hardware::audio::effect::V2_0::IEffect; +using ::android::hardware::audio::effect::V2_0::IEffectBufferProviderCallback; +using ::android::hardware::audio::effect::V2_0::IVirtualizerEffect; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct VirtualizerEffect : public IVirtualizerEffect { + explicit VirtualizerEffect(effect_handle_t handle); + + // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. + Return init() override; + Return setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return reset() override; + Return enable() override; + Return disable() override; + Return setDevice(AudioDevice device) override; + Return setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) override; + Return setAudioMode(AudioMode mode) override; + Return setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return setInputDevice(AudioDevice device) override; + Return getConfig(getConfig_cb _hidl_cb) override; + Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + Return getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; + Return setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; + Return setAudioSource(AudioSource source) override; + Return offload(const EffectOffloadParameter& param) override; + Return getDescriptor(getDescriptor_cb _hidl_cb) override; + Return process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; + Return processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) override; + Return command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override; + Return setParameter( + const hidl_vec& parameter, const hidl_vec& value) override; + Return getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + Return getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + Return getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + Return setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) override; + + // Methods from ::android::hardware::audio::effect::V2_0::IVirtualizerEffect follow. + Return isStrengthSupported() override; + Return setStrength(uint16_t strength) override; + Return getStrength(getStrength_cb _hidl_cb) override; + Return getVirtualSpeakerAngles( + AudioChannelMask mask, + AudioDevice device, + getVirtualSpeakerAngles_cb _hidl_cb) override; + Return forceVirtualizationMode(AudioDevice device) override; + Return getVirtualizationMode(getVirtualizationMode_cb _hidl_cb) override; + + private: + sp mEffect; + + virtual ~VirtualizerEffect(); + + void speakerAnglesFromHal( + const int32_t* halAngles, uint32_t channelCount, hidl_vec& speakerAngles); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_VirtualizerEffect_H_ diff --git a/audio/effect/2.0/default/VisualizerEffect.cpp b/audio/effect/2.0/default/VisualizerEffect.cpp new file mode 100644 index 0000000000..a1f92a6ec8 --- /dev/null +++ b/audio/effect/2.0/default/VisualizerEffect.cpp @@ -0,0 +1,262 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "Visualizer_HAL" +#include +#include + +#include "VisualizerEffect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +VisualizerEffect::VisualizerEffect(effect_handle_t handle) + : mEffect(new Effect(handle)), mCaptureSize(0), mMeasurementMode(MeasurementMode::NONE) { +} + +VisualizerEffect::~VisualizerEffect() {} + +// Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. +Return VisualizerEffect::init() { + return mEffect->init(); +} + +Return VisualizerEffect::setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider); +} + +Return VisualizerEffect::reset() { + return mEffect->reset(); +} + +Return VisualizerEffect::enable() { + return mEffect->enable(); +} + +Return VisualizerEffect::disable() { + return mEffect->disable(); +} + +Return VisualizerEffect::setDevice(AudioDevice device) { + return mEffect->setDevice(device); +} + +Return VisualizerEffect::setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { + return mEffect->setAndGetVolume(volumes, _hidl_cb); +} + +Return VisualizerEffect::setAudioMode(AudioMode mode) { + return mEffect->setAudioMode(mode); +} + +Return VisualizerEffect::setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) { + return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider); +} + +Return VisualizerEffect::setInputDevice(AudioDevice device) { + return mEffect->setInputDevice(device); +} + +Return VisualizerEffect::getConfig(getConfig_cb _hidl_cb) { + return mEffect->getConfig(_hidl_cb); +} + +Return VisualizerEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) { + return mEffect->getConfigReverse(_hidl_cb); +} + +Return VisualizerEffect::getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) { + return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb); +} + +Return VisualizerEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) { + return mEffect->getAuxChannelsConfig(_hidl_cb); +} + +Return VisualizerEffect::setAuxChannelsConfig( + const EffectAuxChannelsConfig& config) { + return mEffect->setAuxChannelsConfig(config); +} + +Return VisualizerEffect::setAudioSource(AudioSource source) { + return mEffect->setAudioSource(source); +} + +Return VisualizerEffect::offload(const EffectOffloadParameter& param) { + return mEffect->offload(param); +} + +Return VisualizerEffect::getDescriptor(getDescriptor_cb _hidl_cb) { + return mEffect->getDescriptor(_hidl_cb); +} + +Return VisualizerEffect::process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) { + return mEffect->process(inBuffer, outFrameSize, _hidl_cb); +} + +Return VisualizerEffect::processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) { + return mEffect->processReverse(inBuffer, outFrameSize, _hidl_cb); +} + +Return VisualizerEffect::command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) { + return mEffect->command(commandId, data, resultMaxSize, _hidl_cb); +} + +Return VisualizerEffect::setParameter( + const hidl_vec& parameter, const hidl_vec& value) { + return mEffect->setParameter(parameter, value); +} + +Return VisualizerEffect::getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) { + return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb); +} + +Return VisualizerEffect::getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) { + return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb); +} + +Return VisualizerEffect::getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) { + return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb); +} + +Return VisualizerEffect::setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) { + return mEffect->setCurrentConfigForFeature(featureId, configData); +} + + +// Methods from ::android::hardware::audio::effect::V2_0::IVisualizerEffect follow. +Return VisualizerEffect::setCaptureSize(uint16_t captureSize) { + Result retval = mEffect->setParam(VISUALIZER_PARAM_CAPTURE_SIZE, captureSize); + if (retval == Result::OK) { + mCaptureSize = captureSize; + } + return retval; +} + +Return VisualizerEffect::getCaptureSize(getCaptureSize_cb _hidl_cb) { + return mEffect->getIntegerParam(VISUALIZER_PARAM_CAPTURE_SIZE, _hidl_cb); +} + +Return VisualizerEffect::setScalingMode(IVisualizerEffect::ScalingMode scalingMode) { + return mEffect->setParam(VISUALIZER_PARAM_SCALING_MODE, static_cast(scalingMode)); +} + +Return VisualizerEffect::getScalingMode(getScalingMode_cb _hidl_cb) { + int32_t halMode; + Result retval = mEffect->getParam(VISUALIZER_PARAM_SCALING_MODE, halMode); + _hidl_cb(retval, ScalingMode(halMode)); + return Void(); +} + +Return VisualizerEffect::setLatency(uint32_t latencyMs) { + return mEffect->setParam(VISUALIZER_PARAM_LATENCY, latencyMs); +} + +Return VisualizerEffect::getLatency(getLatency_cb _hidl_cb) { + return mEffect->getIntegerParam(VISUALIZER_PARAM_LATENCY, _hidl_cb); +} + +Return VisualizerEffect::setMeasurementMode( + IVisualizerEffect::MeasurementMode measurementMode) { + Result retval = mEffect->setParam( + VISUALIZER_PARAM_MEASUREMENT_MODE, static_cast(measurementMode)); + if (retval == Result::OK) { + mMeasurementMode = measurementMode; + } + return retval; +} + +Return VisualizerEffect::getMeasurementMode(getMeasurementMode_cb _hidl_cb) { + int32_t halMode; + Result retval = mEffect->getParam(VISUALIZER_PARAM_MEASUREMENT_MODE, halMode); + _hidl_cb(retval, MeasurementMode(halMode)); + return Void(); +} + +Return VisualizerEffect::capture(capture_cb _hidl_cb) { + if (mCaptureSize == 0) { + _hidl_cb(Result::NOT_INITIALIZED, hidl_vec()); + return Void(); + } + uint32_t halCaptureSize = mCaptureSize; + uint8_t halCapture[mCaptureSize]; + Result retval = mEffect->sendCommandReturningData( + VISUALIZER_CMD_CAPTURE, "VISUALIZER_CAPTURE", &halCaptureSize, halCapture); + hidl_vec capture; + if (retval == Result::OK) { + capture.setToExternal(&halCapture[0], halCaptureSize); + } + _hidl_cb(retval, capture); + return Void(); +} + +Return VisualizerEffect::measure(measure_cb _hidl_cb) { + if (mMeasurementMode == MeasurementMode::NONE) { + _hidl_cb(Result::NOT_INITIALIZED, Measurement()); + return Void(); + } + int32_t halMeasurement[MEASUREMENT_COUNT]; + uint32_t halMeasurementSize = sizeof(halMeasurement); + Result retval = mEffect->sendCommandReturningData( + VISUALIZER_CMD_MEASURE, "VISUALIZER_MEASURE", &halMeasurementSize, halMeasurement); + Measurement measurement = { .mode = MeasurementMode::PEAK_RMS }; + measurement.value.peakAndRms.peakMb = 0; + measurement.value.peakAndRms.rmsMb = 0; + if (retval == Result::OK) { + measurement.value.peakAndRms.peakMb = halMeasurement[MEASUREMENT_IDX_PEAK]; + measurement.value.peakAndRms.rmsMb = halMeasurement[MEASUREMENT_IDX_RMS]; + } + _hidl_cb(retval, measurement); + return Void(); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android diff --git a/audio/effect/2.0/default/VisualizerEffect.h b/audio/effect/2.0/default/VisualizerEffect.h new file mode 100644 index 0000000000..505b16fe0a --- /dev/null +++ b/audio/effect/2.0/default/VisualizerEffect.h @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIDL_GENERATED_android_hardware_audio_effect_V2_0_VisualizerEffect_H_ +#define HIDL_GENERATED_android_hardware_audio_effect_V2_0_VisualizerEffect_H_ + +#include +#include + +#include + +#include "Effect.h" + +namespace android { +namespace hardware { +namespace audio { +namespace effect { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::audio::common::V2_0::AudioDevice; +using ::android::hardware::audio::common::V2_0::AudioMode; +using ::android::hardware::audio::common::V2_0::AudioSource; +using ::android::hardware::audio::effect::V2_0::AudioBuffer; +using ::android::hardware::audio::effect::V2_0::EffectAuxChannelsConfig; +using ::android::hardware::audio::effect::V2_0::EffectConfig; +using ::android::hardware::audio::effect::V2_0::EffectDescriptor; +using ::android::hardware::audio::effect::V2_0::EffectOffloadParameter; +using ::android::hardware::audio::effect::V2_0::IEffect; +using ::android::hardware::audio::effect::V2_0::IEffectBufferProviderCallback; +using ::android::hardware::audio::effect::V2_0::IVisualizerEffect; +using ::android::hardware::audio::effect::V2_0::Result; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::sp; + +struct VisualizerEffect : public IVisualizerEffect { + explicit VisualizerEffect(effect_handle_t handle); + + // Methods from ::android::hardware::audio::effect::V2_0::IEffect follow. + Return init() override; + Return setConfig( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return reset() override; + Return enable() override; + Return disable() override; + Return setDevice(AudioDevice device) override; + Return setAndGetVolume( + const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) override; + Return setAudioMode(AudioMode mode) override; + Return setConfigReverse( + const EffectConfig& config, + const sp& inputBufferProvider, + const sp& outputBufferProvider) override; + Return setInputDevice(AudioDevice device) override; + Return getConfig(getConfig_cb _hidl_cb) override; + Return getConfigReverse(getConfigReverse_cb _hidl_cb) override; + Return getSupportedAuxChannelsConfigs( + uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override; + Return getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override; + Return setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override; + Return setAudioSource(AudioSource source) override; + Return offload(const EffectOffloadParameter& param) override; + Return getDescriptor(getDescriptor_cb _hidl_cb) override; + Return process( + const AudioBuffer& inBuffer, uint32_t outFrameSize, process_cb _hidl_cb) override; + Return processReverse( + const AudioBuffer& inBuffer, + uint32_t outFrameSize, + processReverse_cb _hidl_cb) override; + Return command( + uint32_t commandId, + const hidl_vec& data, + uint32_t resultMaxSize, + command_cb _hidl_cb) override; + Return setParameter( + const hidl_vec& parameter, const hidl_vec& value) override; + Return getParameter( + const hidl_vec& parameter, + uint32_t valueMaxSize, + getParameter_cb _hidl_cb) override; + Return getSupportedConfigsForFeature( + uint32_t featureId, + uint32_t maxConfigs, + uint32_t configSize, + getSupportedConfigsForFeature_cb _hidl_cb) override; + Return getCurrentConfigForFeature( + uint32_t featureId, + uint32_t configSize, + getCurrentConfigForFeature_cb _hidl_cb) override; + Return setCurrentConfigForFeature( + uint32_t featureId, const hidl_vec& configData) override; + + // Methods from ::android::hardware::audio::effect::V2_0::IVisualizerEffect follow. + Return setCaptureSize(uint16_t captureSize) override; + Return getCaptureSize(getCaptureSize_cb _hidl_cb) override; + Return setScalingMode(IVisualizerEffect::ScalingMode scalingMode) override; + Return getScalingMode(getScalingMode_cb _hidl_cb) override; + Return setLatency(uint32_t latencyMs) override; + Return getLatency(getLatency_cb _hidl_cb) override; + Return setMeasurementMode(IVisualizerEffect::MeasurementMode measurementMode) override; + Return getMeasurementMode(getMeasurementMode_cb _hidl_cb) override; + Return capture(capture_cb _hidl_cb) override; + Return measure(measure_cb _hidl_cb) override; + + private: + sp mEffect; + uint16_t mCaptureSize; + MeasurementMode mMeasurementMode; + + virtual ~VisualizerEffect(); +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace effect +} // namespace audio +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_android_hardware_audio_effect_V2_0_VisualizerEffect_H_ diff --git a/audio/effect/2.0/types.hal b/audio/effect/2.0/types.hal index 82f6766af9..35015b27ec 100644 --- a/audio/effect/2.0/types.hal +++ b/audio/effect/2.0/types.hal @@ -23,7 +23,8 @@ enum Result { NOT_INITIALIZED, INVALID_ARGUMENTS, INVALID_STATE, - NOT_SUPPORTED + NOT_SUPPORTED, + RESULT_TOO_BIG }; /* @@ -207,8 +208,8 @@ struct EffectDescriptor { // as estimated on an ARM9E core (ARMv5TE) with 0 WS uint16_t memoryUsage; // data memory usage expressed in KB and includes // only dynamically allocated memory - string name; // human readable effect name - string implementor; // human readable effect implementor name + uint8_t[64] name; // human readable effect name + uint8_t[64] implementor; // human readable effect implementor name }; /* @@ -272,9 +273,9 @@ enum EffectFeature { CNT }; -struct EffectFeatureConfig { - EffectFeature feature; - EffectConfig config; +struct EffectAuxChannelsConfig { + AudioChannelMask mainChannels; // channel mask for main channels + AudioChannelMask auxChannels; // channel mask for auxiliary channels }; struct EffectOffloadParameter {