/* * Copyright (C) 2018 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 "NoiseSuppressionEffect.h" #include #include "VersionUtils.h" namespace android { namespace hardware { namespace audio { namespace effect { namespace CPP_VERSION { namespace implementation { NoiseSuppressionEffect::NoiseSuppressionEffect(effect_handle_t handle) : mEffect(new Effect(true /*isInput*/, handle)) {} 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::CPP_VERSION::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(); } #if MAJOR_VERSION <= 6 Return NoiseSuppressionEffect::setAudioSource(AudioSource source) { return mEffect->setAudioSource(source); } Return NoiseSuppressionEffect::setDevice(AudioDeviceBitfield device) { return mEffect->setDevice(device); } Return NoiseSuppressionEffect::setInputDevice(AudioDeviceBitfield device) { return mEffect->setInputDevice(device); } #else Return NoiseSuppressionEffect::setAudioSource(const AudioSource& source) { return mEffect->setAudioSource(source); } Return NoiseSuppressionEffect::setDevice(const DeviceAddress& device) { return mEffect->setDevice(device); } Return NoiseSuppressionEffect::setInputDevice(const DeviceAddress& device) { return mEffect->setInputDevice(device); } #endif Return NoiseSuppressionEffect::setAndGetVolume(const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { return mEffect->setAndGetVolume(volumes, _hidl_cb); } Return NoiseSuppressionEffect::volumeChangeNotification(const hidl_vec& volumes) { return mEffect->volumeChangeNotification(volumes); } 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::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::offload(const EffectOffloadParameter& param) { return mEffect->offload(param); } Return NoiseSuppressionEffect::getDescriptor(getDescriptor_cb _hidl_cb) { return mEffect->getDescriptor(_hidl_cb); } Return NoiseSuppressionEffect::prepareForProcessing(prepareForProcessing_cb _hidl_cb) { return mEffect->prepareForProcessing(_hidl_cb); } Return NoiseSuppressionEffect::setProcessBuffers(const AudioBuffer& inBuffer, const AudioBuffer& outBuffer) { return mEffect->setProcessBuffers(inBuffer, outBuffer); } 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); } Return NoiseSuppressionEffect::close() { return mEffect->close(); } Return NoiseSuppressionEffect::debug(const hidl_handle& fd, const hidl_vec& options) { return mEffect->debug(fd, options); } // Methods from ::android::hardware::audio::effect::CPP_VERSION::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 CPP_VERSION } // namespace effect } // namespace audio } // namespace hardware } // namespace android