Index: webrtc/modules/audio_processing/level_estimator_impl.cc |
diff --git a/webrtc/modules/audio_processing/level_estimator_impl.cc b/webrtc/modules/audio_processing/level_estimator_impl.cc |
index 52f6697a57e44c79765d53ee0ff0d82375ecfb8f..aa676a870f838d74246ecc72ced301ac7d870001 100644 |
--- a/webrtc/modules/audio_processing/level_estimator_impl.cc |
+++ b/webrtc/modules/audio_processing/level_estimator_impl.cc |
@@ -11,83 +11,55 @@ |
#include "webrtc/modules/audio_processing/level_estimator_impl.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/system_wrappers/include/critical_section_wrapper.h" |
namespace webrtc { |
-LevelEstimatorImpl::LevelEstimatorImpl(const AudioProcessing* apm, |
- rtc::CriticalSection* crit) |
- : ProcessingComponent(), crit_(crit) { |
- RTC_DCHECK(apm); |
+LevelEstimatorImpl::LevelEstimatorImpl(rtc::CriticalSection* crit) |
+ : crit_(crit), rms_(new RMSLevel()) { |
RTC_DCHECK(crit); |
} |
LevelEstimatorImpl::~LevelEstimatorImpl() {} |
-int LevelEstimatorImpl::ProcessStream(AudioBuffer* audio) { |
+void LevelEstimatorImpl::Initialize() { |
rtc::CritScope cs(crit_); |
+ rms_->Reset(); |
+} |
- if (!is_component_enabled()) { |
- return AudioProcessing::kNoError; |
+void LevelEstimatorImpl::ProcessStream(AudioBuffer* audio) { |
+ RTC_DCHECK(audio); |
+ rtc::CritScope cs(crit_); |
+ if (!enabled_) { |
+ return; |
} |
- RMSLevel* rms_level = static_cast<RMSLevel*>(handle(0)); |
- for (int i = 0; i < audio->num_channels(); ++i) { |
- rms_level->Process(audio->channels_const()[i], |
- audio->num_frames()); |
+ for (int i = 0; i < audio->num_channels(); i++) { |
+ rms_->Process(audio->channels_const()[i], audio->num_frames()); |
} |
- |
- return AudioProcessing::kNoError; |
} |
int LevelEstimatorImpl::Enable(bool enable) { |
rtc::CritScope cs(crit_); |
- return EnableComponent(enable); |
+ if (enable && !enabled_) { |
+ rms_->Reset(); |
+ } |
+ enabled_ = enable; |
+ return AudioProcessing::kNoError; |
} |
bool LevelEstimatorImpl::is_enabled() const { |
rtc::CritScope cs(crit_); |
- return is_component_enabled(); |
+ return enabled_; |
} |
int LevelEstimatorImpl::RMS() { |
rtc::CritScope cs(crit_); |
- if (!is_component_enabled()) { |
+ if (!enabled_) { |
return AudioProcessing::kNotEnabledError; |
} |
- RMSLevel* rms_level = static_cast<RMSLevel*>(handle(0)); |
- 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; |
+ return rms_->RMS(); |
} |
- |
-int LevelEstimatorImpl::num_handles_required() const { |
- return 1; |
-} |
- |
-int LevelEstimatorImpl::GetHandleError(void* /*handle*/) const { |
- return AudioProcessing::kUnspecifiedError; |
-} |
- |
} // namespace webrtc |