| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/audio_processing/level_estimator_impl.h" | 11 #include "webrtc/modules/audio_processing/level_estimator_impl.h" |
| 12 | 12 |
| 13 #include "webrtc/modules/audio_processing/audio_buffer.h" | 13 #include "webrtc/modules/audio_processing/audio_buffer.h" |
| 14 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 14 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 15 #include "webrtc/modules/audio_processing/rms_level.h" | 15 #include "webrtc/modules/audio_processing/rms_level.h" |
| 16 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 16 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 17 | 17 |
| 18 namespace webrtc { | 18 namespace webrtc { |
| 19 | 19 |
| 20 LevelEstimatorImpl::LevelEstimatorImpl(const AudioProcessing* apm, | 20 LevelEstimatorImpl::LevelEstimatorImpl(const AudioProcessing* apm, |
| 21 CriticalSectionWrapper* crit) | 21 rtc::CriticalSection* crit) |
| 22 : ProcessingComponent(), | 22 : ProcessingComponent(), crit_(crit) { |
| 23 crit_(crit) {} | 23 RTC_DCHECK(apm); |
| 24 RTC_DCHECK(crit); |
| 25 } |
| 24 | 26 |
| 25 LevelEstimatorImpl::~LevelEstimatorImpl() {} | 27 LevelEstimatorImpl::~LevelEstimatorImpl() {} |
| 26 | 28 |
| 27 int LevelEstimatorImpl::ProcessStream(AudioBuffer* audio) { | 29 int LevelEstimatorImpl::ProcessStream(AudioBuffer* audio) { |
| 30 rtc::CritScope cs(crit_); |
| 31 |
| 28 if (!is_component_enabled()) { | 32 if (!is_component_enabled()) { |
| 29 return AudioProcessing::kNoError; | 33 return AudioProcessing::kNoError; |
| 30 } | 34 } |
| 31 | 35 |
| 32 RMSLevel* rms_level = static_cast<RMSLevel*>(handle(0)); | 36 RMSLevel* rms_level = static_cast<RMSLevel*>(handle(0)); |
| 33 for (int i = 0; i < audio->num_channels(); ++i) { | 37 for (int i = 0; i < audio->num_channels(); ++i) { |
| 34 rms_level->Process(audio->channels_const()[i], | 38 rms_level->Process(audio->channels_const()[i], |
| 35 audio->num_frames()); | 39 audio->num_frames()); |
| 36 } | 40 } |
| 37 | 41 |
| 38 return AudioProcessing::kNoError; | 42 return AudioProcessing::kNoError; |
| 39 } | 43 } |
| 40 | 44 |
| 41 int LevelEstimatorImpl::Enable(bool enable) { | 45 int LevelEstimatorImpl::Enable(bool enable) { |
| 42 CriticalSectionScoped crit_scoped(crit_); | 46 rtc::CritScope cs(crit_); |
| 43 return EnableComponent(enable); | 47 return EnableComponent(enable); |
| 44 } | 48 } |
| 45 | 49 |
| 46 bool LevelEstimatorImpl::is_enabled() const { | 50 bool LevelEstimatorImpl::is_enabled() const { |
| 51 rtc::CritScope cs(crit_); |
| 47 return is_component_enabled(); | 52 return is_component_enabled(); |
| 48 } | 53 } |
| 49 | 54 |
| 50 int LevelEstimatorImpl::RMS() { | 55 int LevelEstimatorImpl::RMS() { |
| 56 rtc::CritScope cs(crit_); |
| 51 if (!is_component_enabled()) { | 57 if (!is_component_enabled()) { |
| 52 return AudioProcessing::kNotEnabledError; | 58 return AudioProcessing::kNotEnabledError; |
| 53 } | 59 } |
| 54 | 60 |
| 55 RMSLevel* rms_level = static_cast<RMSLevel*>(handle(0)); | 61 RMSLevel* rms_level = static_cast<RMSLevel*>(handle(0)); |
| 56 return rms_level->RMS(); | 62 return rms_level->RMS(); |
| 57 } | 63 } |
| 58 | 64 |
| 59 // The ProcessingComponent implementation is pretty weird in this class since | 65 // The ProcessingComponent implementation is pretty weird in this class since |
| 60 // we have only a single instance of the trivial underlying component. | 66 // we have only a single instance of the trivial underlying component. |
| 61 void* LevelEstimatorImpl::CreateHandle() const { | 67 void* LevelEstimatorImpl::CreateHandle() const { |
| 62 return new RMSLevel; | 68 return new RMSLevel; |
| 63 } | 69 } |
| 64 | 70 |
| 65 void LevelEstimatorImpl::DestroyHandle(void* handle) const { | 71 void LevelEstimatorImpl::DestroyHandle(void* handle) const { |
| 66 delete static_cast<RMSLevel*>(handle); | 72 delete static_cast<RMSLevel*>(handle); |
| 67 } | 73 } |
| 68 | 74 |
| 69 int LevelEstimatorImpl::InitializeHandle(void* handle) const { | 75 int LevelEstimatorImpl::InitializeHandle(void* handle) const { |
| 76 rtc::CritScope cs(crit_); |
| 70 static_cast<RMSLevel*>(handle)->Reset(); | 77 static_cast<RMSLevel*>(handle)->Reset(); |
| 71 return AudioProcessing::kNoError; | 78 return AudioProcessing::kNoError; |
| 72 } | 79 } |
| 73 | 80 |
| 74 int LevelEstimatorImpl::ConfigureHandle(void* /*handle*/) const { | 81 int LevelEstimatorImpl::ConfigureHandle(void* /*handle*/) const { |
| 75 return AudioProcessing::kNoError; | 82 return AudioProcessing::kNoError; |
| 76 } | 83 } |
| 77 | 84 |
| 78 int LevelEstimatorImpl::num_handles_required() const { | 85 int LevelEstimatorImpl::num_handles_required() const { |
| 79 return 1; | 86 return 1; |
| 80 } | 87 } |
| 81 | 88 |
| 82 int LevelEstimatorImpl::GetHandleError(void* /*handle*/) const { | 89 int LevelEstimatorImpl::GetHandleError(void* /*handle*/) const { |
| 83 return AudioProcessing::kUnspecifiedError; | 90 return AudioProcessing::kUnspecifiedError; |
| 84 } | 91 } |
| 85 | 92 |
| 86 } // namespace webrtc | 93 } // namespace webrtc |
| OLD | NEW |