platform_hardware_interfaces/audio/effect/2.0/default/DownmixEffect.cpp
Mikhail Naganov f4f2ff3974 audiohal: Fix volume changes handling
Some legacy implementations of the effects HAL use the condition
of the reply buffer being NULL as an indication that they shouldn't
apply attenuation to the input audio data. Therefore, separate
methods are needed to distinguish the use cases of delegating the
volume control to the effect, and just informing the effect of the
volume changes.

A new method added to IEffect: volumeChangeNotification that implements
the second use case. The contract of setAndGetVolume method has been
updated to indicate that it is only called in the first use case.

Also updated the wrapper for a generic IEffect commands to pass NULL
pointers to the command and reply buffers in case when the size
of the input or output data is 0, to preserve compatibility with
direct calls from the framework.

Bug: 34368451
Test: volume control works when both Bass Boost and Equalizer are
      enabled in the NXP implementation of the effects

Change-Id: I3c9a5bbdff561802bc94080c51703385a8903282
2017-01-19 12:52:27 -08:00

194 lines
6 KiB
C++

/*
* 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 <system/audio_effects/effect_downmix.h>
#include <android/log.h>
#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<Result> DownmixEffect::init() {
return mEffect->init();
}
Return<Result> DownmixEffect::setConfig(
const EffectConfig& config,
const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider);
}
Return<Result> DownmixEffect::reset() {
return mEffect->reset();
}
Return<Result> DownmixEffect::enable() {
return mEffect->enable();
}
Return<Result> DownmixEffect::disable() {
return mEffect->disable();
}
Return<Result> DownmixEffect::setDevice(AudioDevice device) {
return mEffect->setDevice(device);
}
Return<void> DownmixEffect::setAndGetVolume(
const hidl_vec<uint32_t>& volumes, setAndGetVolume_cb _hidl_cb) {
return mEffect->setAndGetVolume(volumes, _hidl_cb);
}
Return<Result> DownmixEffect::volumeChangeNotification(
const hidl_vec<uint32_t>& volumes) {
return mEffect->volumeChangeNotification(volumes);
}
Return<Result> DownmixEffect::setAudioMode(AudioMode mode) {
return mEffect->setAudioMode(mode);
}
Return<Result> DownmixEffect::setConfigReverse(
const EffectConfig& config,
const sp<IEffectBufferProviderCallback>& inputBufferProvider,
const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
}
Return<Result> DownmixEffect::setInputDevice(AudioDevice device) {
return mEffect->setInputDevice(device);
}
Return<void> DownmixEffect::getConfig(getConfig_cb _hidl_cb) {
return mEffect->getConfig(_hidl_cb);
}
Return<void> DownmixEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) {
return mEffect->getConfigReverse(_hidl_cb);
}
Return<void> DownmixEffect::getSupportedAuxChannelsConfigs(
uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) {
return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb);
}
Return<void> DownmixEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) {
return mEffect->getAuxChannelsConfig(_hidl_cb);
}
Return<Result> DownmixEffect::setAuxChannelsConfig(
const EffectAuxChannelsConfig& config) {
return mEffect->setAuxChannelsConfig(config);
}
Return<Result> DownmixEffect::setAudioSource(AudioSource source) {
return mEffect->setAudioSource(source);
}
Return<Result> DownmixEffect::offload(const EffectOffloadParameter& param) {
return mEffect->offload(param);
}
Return<void> DownmixEffect::getDescriptor(getDescriptor_cb _hidl_cb) {
return mEffect->getDescriptor(_hidl_cb);
}
Return<void> DownmixEffect::prepareForProcessing(
prepareForProcessing_cb _hidl_cb) {
return mEffect->prepareForProcessing(_hidl_cb);
}
Return<Result> DownmixEffect::setProcessBuffers(
const AudioBuffer& inBuffer, const AudioBuffer& outBuffer) {
return mEffect->setProcessBuffers(inBuffer, outBuffer);
}
Return<void> DownmixEffect::command(
uint32_t commandId,
const hidl_vec<uint8_t>& data,
uint32_t resultMaxSize,
command_cb _hidl_cb) {
return mEffect->command(commandId, data, resultMaxSize, _hidl_cb);
}
Return<Result> DownmixEffect::setParameter(
const hidl_vec<uint8_t>& parameter, const hidl_vec<uint8_t>& value) {
return mEffect->setParameter(parameter, value);
}
Return<void> DownmixEffect::getParameter(
const hidl_vec<uint8_t>& parameter,
uint32_t valueMaxSize,
getParameter_cb _hidl_cb) {
return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb);
}
Return<void> DownmixEffect::getSupportedConfigsForFeature(
uint32_t featureId,
uint32_t maxConfigs,
uint32_t configSize,
getSupportedConfigsForFeature_cb _hidl_cb) {
return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb);
}
Return<void> DownmixEffect::getCurrentConfigForFeature(
uint32_t featureId,
uint32_t configSize,
getCurrentConfigForFeature_cb _hidl_cb) {
return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb);
}
Return<Result> DownmixEffect::setCurrentConfigForFeature(
uint32_t featureId, const hidl_vec<uint8_t>& configData) {
return mEffect->setCurrentConfigForFeature(featureId, configData);
}
Return<Result> DownmixEffect::close() {
return mEffect->close();
}
// Methods from ::android::hardware::audio::effect::V2_0::IDownmixEffect follow.
Return<Result> DownmixEffect::setType(IDownmixEffect::Type preset) {
return mEffect->setParam(DOWNMIX_PARAM_TYPE, static_cast<downmix_type_t>(preset));
}
Return<void> 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