Make LevelEstimation not a ProcessingComponent.

BUG=webrtc:5355

Review URL: https://codereview.webrtc.org/1523483002

Cr-Commit-Position: refs/heads/master@{#11033}
This commit is contained in:
solenberg
2015-12-15 11:39:38 -08:00
committed by Commit bot
parent 5e0218c66e
commit 949028fbf1
4 changed files with 50 additions and 77 deletions

View File

@ -150,14 +150,13 @@ struct AudioProcessingImpl::ApmPublicSubmodules {
: echo_cancellation(nullptr), : echo_cancellation(nullptr),
echo_control_mobile(nullptr), echo_control_mobile(nullptr),
gain_control(nullptr), gain_control(nullptr),
level_estimator(nullptr),
voice_detection(nullptr) {} voice_detection(nullptr) {}
// Accessed externally of APM without any lock acquired. // Accessed externally of APM without any lock acquired.
EchoCancellationImpl* echo_cancellation; EchoCancellationImpl* echo_cancellation;
EchoControlMobileImpl* echo_control_mobile; EchoControlMobileImpl* echo_control_mobile;
GainControlImpl* gain_control; GainControlImpl* gain_control;
rtc::scoped_ptr<HighPassFilterImpl> high_pass_filter; rtc::scoped_ptr<HighPassFilterImpl> high_pass_filter;
LevelEstimatorImpl* level_estimator; rtc::scoped_ptr<LevelEstimatorImpl> level_estimator;
rtc::scoped_ptr<NoiseSuppressionImpl> noise_suppression; rtc::scoped_ptr<NoiseSuppressionImpl> noise_suppression;
VoiceDetectionImpl* voice_detection; VoiceDetectionImpl* voice_detection;
rtc::scoped_ptr<GainControlForNewAgc> gain_control_for_new_agc; rtc::scoped_ptr<GainControlForNewAgc> gain_control_for_new_agc;
@ -243,8 +242,8 @@ AudioProcessingImpl::AudioProcessingImpl(const Config& config,
new GainControlImpl(this, &crit_capture_, &crit_capture_); new GainControlImpl(this, &crit_capture_, &crit_capture_);
public_submodules_->high_pass_filter.reset( public_submodules_->high_pass_filter.reset(
new HighPassFilterImpl(&crit_capture_)); new HighPassFilterImpl(&crit_capture_));
public_submodules_->level_estimator = public_submodules_->level_estimator.reset(
new LevelEstimatorImpl(this, &crit_capture_); new LevelEstimatorImpl(&crit_capture_));
public_submodules_->noise_suppression.reset( public_submodules_->noise_suppression.reset(
new NoiseSuppressionImpl(&crit_capture_)); new NoiseSuppressionImpl(&crit_capture_));
public_submodules_->voice_detection = public_submodules_->voice_detection =
@ -258,8 +257,6 @@ AudioProcessingImpl::AudioProcessingImpl(const Config& config,
public_submodules_->echo_control_mobile); public_submodules_->echo_control_mobile);
private_submodules_->component_list.push_back( private_submodules_->component_list.push_back(
public_submodules_->gain_control); public_submodules_->gain_control);
private_submodules_->component_list.push_back(
public_submodules_->level_estimator);
private_submodules_->component_list.push_back( private_submodules_->component_list.push_back(
public_submodules_->voice_detection); public_submodules_->voice_detection);
} }
@ -398,6 +395,7 @@ int AudioProcessingImpl::InitializeLocked() {
InitializeIntelligibility(); InitializeIntelligibility();
InitializeHighPassFilter(); InitializeHighPassFilter();
InitializeNoiseSuppression(); InitializeNoiseSuppression();
InitializeLevelEstimator();
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
if (debug_dump_.debug_file->Open()) { if (debug_dump_.debug_file->Open()) {
@ -804,7 +802,7 @@ int AudioProcessingImpl::ProcessStreamLocked() {
} }
// The level estimator operates on the recombined data. // The level estimator operates on the recombined data.
RETURN_ON_ERR(public_submodules_->level_estimator->ProcessStream(ca)); public_submodules_->level_estimator->ProcessStream(ca);
capture_.was_stream_delay_set = false; capture_.was_stream_delay_set = false;
return kNoError; return kNoError;
@ -1146,7 +1144,7 @@ HighPassFilter* AudioProcessingImpl::high_pass_filter() const {
LevelEstimator* AudioProcessingImpl::level_estimator() const { LevelEstimator* AudioProcessingImpl::level_estimator() const {
// Adding a lock here has no effect as it allows any access to the submodule // Adding a lock here has no effect as it allows any access to the submodule
// from the returned pointer. // from the returned pointer.
return public_submodules_->level_estimator; return public_submodules_->level_estimator.get();
} }
NoiseSuppression* AudioProcessingImpl::noise_suppression() const { NoiseSuppression* AudioProcessingImpl::noise_suppression() const {
@ -1178,6 +1176,9 @@ bool AudioProcessingImpl::is_data_processed() const {
if (public_submodules_->noise_suppression->is_enabled()) { if (public_submodules_->noise_suppression->is_enabled()) {
enabled_count++; enabled_count++;
} }
if (public_submodules_->level_estimator->is_enabled()) {
enabled_count++;
}
// Data is unchanged if no components are enabled, or if only // Data is unchanged if no components are enabled, or if only
// public_submodules_->level_estimator // public_submodules_->level_estimator
@ -1302,6 +1303,10 @@ void AudioProcessingImpl::InitializeNoiseSuppression() {
proc_sample_rate_hz()); proc_sample_rate_hz());
} }
void AudioProcessingImpl::InitializeLevelEstimator() {
public_submodules_->level_estimator->Initialize();
}
void AudioProcessingImpl::MaybeUpdateHistograms() { void AudioProcessingImpl::MaybeUpdateHistograms() {
static const int kMinDiffDelayMs = 60; static const int kMinDiffDelayMs = 60;

View File

@ -185,6 +185,8 @@ class AudioProcessingImpl : public AudioProcessing {
EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
void InitializeNoiseSuppression() void InitializeNoiseSuppression()
EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
void InitializeLevelEstimator()
EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
int InitializeLocked(const ProcessingConfig& config) int InitializeLocked(const ProcessingConfig& config)
EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_);

View File

@ -11,83 +11,55 @@
#include "webrtc/modules/audio_processing/level_estimator_impl.h" #include "webrtc/modules/audio_processing/level_estimator_impl.h"
#include "webrtc/modules/audio_processing/audio_buffer.h" #include "webrtc/modules/audio_processing/audio_buffer.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h"
#include "webrtc/modules/audio_processing/rms_level.h" #include "webrtc/modules/audio_processing/rms_level.h"
#include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
namespace webrtc { namespace webrtc {
LevelEstimatorImpl::LevelEstimatorImpl(const AudioProcessing* apm, LevelEstimatorImpl::LevelEstimatorImpl(rtc::CriticalSection* crit)
rtc::CriticalSection* crit) : crit_(crit), rms_(new RMSLevel()) {
: ProcessingComponent(), crit_(crit) {
RTC_DCHECK(apm);
RTC_DCHECK(crit); RTC_DCHECK(crit);
} }
LevelEstimatorImpl::~LevelEstimatorImpl() {} LevelEstimatorImpl::~LevelEstimatorImpl() {}
int LevelEstimatorImpl::ProcessStream(AudioBuffer* audio) { void LevelEstimatorImpl::Initialize() {
rtc::CritScope cs(crit_); rtc::CritScope cs(crit_);
rms_->Reset();
if (!is_component_enabled()) {
return AudioProcessing::kNoError;
} }
RMSLevel* rms_level = static_cast<RMSLevel*>(handle(0)); void LevelEstimatorImpl::ProcessStream(AudioBuffer* audio) {
for (int i = 0; i < audio->num_channels(); ++i) { RTC_DCHECK(audio);
rms_level->Process(audio->channels_const()[i], rtc::CritScope cs(crit_);
audio->num_frames()); if (!enabled_) {
return;
} }
return AudioProcessing::kNoError; for (int i = 0; i < audio->num_channels(); i++) {
rms_->Process(audio->channels_const()[i], audio->num_frames());
}
} }
int LevelEstimatorImpl::Enable(bool enable) { int LevelEstimatorImpl::Enable(bool enable) {
rtc::CritScope cs(crit_); rtc::CritScope cs(crit_);
return EnableComponent(enable); if (enable && !enabled_) {
rms_->Reset();
}
enabled_ = enable;
return AudioProcessing::kNoError;
} }
bool LevelEstimatorImpl::is_enabled() const { bool LevelEstimatorImpl::is_enabled() const {
rtc::CritScope cs(crit_); rtc::CritScope cs(crit_);
return is_component_enabled(); return enabled_;
} }
int LevelEstimatorImpl::RMS() { int LevelEstimatorImpl::RMS() {
rtc::CritScope cs(crit_); rtc::CritScope cs(crit_);
if (!is_component_enabled()) { if (!enabled_) {
return AudioProcessing::kNotEnabledError; return AudioProcessing::kNotEnabledError;
} }
RMSLevel* rms_level = static_cast<RMSLevel*>(handle(0)); return rms_->RMS();
return rms_level->RMS();
} }
// The ProcessingComponent implementation is pretty weird in this class since
// we have only a single instance of the trivial underlying component.
void* LevelEstimatorImpl::CreateHandle() const {
return new RMSLevel;
}
void LevelEstimatorImpl::DestroyHandle(void* handle) const {
delete static_cast<RMSLevel*>(handle);
}
int LevelEstimatorImpl::InitializeHandle(void* handle) const {
rtc::CritScope cs(crit_);
static_cast<RMSLevel*>(handle)->Reset();
return AudioProcessing::kNoError;
}
int LevelEstimatorImpl::ConfigureHandle(void* /*handle*/) const {
return AudioProcessing::kNoError;
}
int LevelEstimatorImpl::num_handles_required() const {
return 1;
}
int LevelEstimatorImpl::GetHandleError(void* /*handle*/) const {
return AudioProcessing::kUnspecifiedError;
}
} // namespace webrtc } // namespace webrtc

View File

@ -11,42 +11,36 @@
#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_IMPL_H_ #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_IMPL_H_
#define WEBRTC_MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_IMPL_H_ #define WEBRTC_MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_IMPL_H_
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/criticalsection.h" #include "webrtc/base/criticalsection.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/modules/audio_processing/include/audio_processing.h"
#include "webrtc/modules/audio_processing/processing_component.h"
#include "webrtc/modules/audio_processing/rms_level.h"
namespace webrtc { namespace webrtc {
class AudioBuffer; class AudioBuffer;
class RMSLevel;
class LevelEstimatorImpl : public LevelEstimator, class LevelEstimatorImpl : public LevelEstimator {
public ProcessingComponent {
public: public:
LevelEstimatorImpl(const AudioProcessing* apm, rtc::CriticalSection* crit); explicit LevelEstimatorImpl(rtc::CriticalSection* crit);
virtual ~LevelEstimatorImpl(); ~LevelEstimatorImpl() override;
int ProcessStream(AudioBuffer* audio); // TODO(peah): Fold into ctor, once public API is removed.
void Initialize();
void ProcessStream(AudioBuffer* audio);
// LevelEstimator implementation.
bool is_enabled() const override;
private:
// LevelEstimator implementation. // LevelEstimator implementation.
int Enable(bool enable) override; int Enable(bool enable) override;
bool is_enabled() const override;
int RMS() override; int RMS() override;
// ProcessingComponent implementation. private:
void* CreateHandle() const override; rtc::CriticalSection* const crit_ = nullptr;
int InitializeHandle(void* handle) const override; bool enabled_ GUARDED_BY(crit_) = false;
int ConfigureHandle(void* handle) const override; rtc::scoped_ptr<RMSLevel> rms_ GUARDED_BY(crit_);
void DestroyHandle(void* handle) const override; RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(LevelEstimatorImpl);
int num_handles_required() const override;
int GetHandleError(void* handle) const override;
rtc::CriticalSection* const crit_;
}; };
} // namespace webrtc } // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_IMPL_H_ #endif // WEBRTC_MODULES_AUDIO_PROCESSING_LEVEL_ESTIMATOR_IMPL_H_