/* * 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 "Visualizer_HAL" #include "VisualizerEffect.h" #include #include #include "VersionUtils.h" namespace android { namespace hardware { namespace audio { namespace effect { namespace CPP_VERSION { 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::CPP_VERSION::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(AudioDeviceBitfield device) { return mEffect->setDevice(device); } Return VisualizerEffect::setAndGetVolume(const hidl_vec& volumes, setAndGetVolume_cb _hidl_cb) { return mEffect->setAndGetVolume(volumes, _hidl_cb); } Return VisualizerEffect::volumeChangeNotification(const hidl_vec& volumes) { return mEffect->volumeChangeNotification(volumes); } 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(AudioDeviceBitfield 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::prepareForProcessing(prepareForProcessing_cb _hidl_cb) { return mEffect->prepareForProcessing(_hidl_cb); } Return VisualizerEffect::setProcessBuffers(const AudioBuffer& inBuffer, const AudioBuffer& outBuffer) { return mEffect->setProcessBuffers(inBuffer, outBuffer); } 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); } Return VisualizerEffect::close() { return mEffect->close(); } Return VisualizerEffect::debug(const hidl_handle& fd, const hidl_vec& options) { return mEffect->debug(fd, options); } // Methods from ::android::hardware::audio::effect::CPP_VERSION::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 CPP_VERSION } // namespace effect } // namespace audio } // namespace hardware } // namespace android