Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(590)

Side by Side Diff: webrtc/modules/audio_processing/level_estimator_impl.cc

Issue 1523483002: Make LevelEstimation not a ProcessingComponent. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: one more reset Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/audio_processing/level_estimator_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
15 #include "webrtc/modules/audio_processing/rms_level.h" 14 #include "webrtc/modules/audio_processing/rms_level.h"
16 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 15 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
17 16
18 namespace webrtc { 17 namespace webrtc {
19 18
20 LevelEstimatorImpl::LevelEstimatorImpl(const AudioProcessing* apm, 19 LevelEstimatorImpl::LevelEstimatorImpl(rtc::CriticalSection* crit)
21 rtc::CriticalSection* crit) 20 : crit_(crit), rms_(new RMSLevel()) {
22 : ProcessingComponent(), crit_(crit) {
23 RTC_DCHECK(apm);
24 RTC_DCHECK(crit); 21 RTC_DCHECK(crit);
25 } 22 }
26 23
27 LevelEstimatorImpl::~LevelEstimatorImpl() {} 24 LevelEstimatorImpl::~LevelEstimatorImpl() {}
28 25
29 int LevelEstimatorImpl::ProcessStream(AudioBuffer* audio) { 26 void LevelEstimatorImpl::Initialize() {
30 rtc::CritScope cs(crit_); 27 rtc::CritScope cs(crit_);
28 rms_->Reset();
29 }
31 30
32 if (!is_component_enabled()) { 31 void LevelEstimatorImpl::ProcessStream(AudioBuffer* audio) {
33 return AudioProcessing::kNoError; 32 RTC_DCHECK(audio);
33 rtc::CritScope cs(crit_);
34 if (!enabled_) {
35 return;
34 } 36 }
35 37
36 RMSLevel* rms_level = static_cast<RMSLevel*>(handle(0)); 38 for (int i = 0; i < audio->num_channels(); i++) {
hlundin-webrtc 2015/12/15 10:07:57 Out of curiosity, why did you change from ++i to i
the sun 2015/12/15 12:08:45 I just did a side-by-side with another module and
37 for (int i = 0; i < audio->num_channels(); ++i) { 39 rms_->Process(audio->channels_const()[i], audio->num_frames());
38 rms_level->Process(audio->channels_const()[i],
39 audio->num_frames());
40 } 40 }
41
42 return AudioProcessing::kNoError;
43 } 41 }
44 42
45 int LevelEstimatorImpl::Enable(bool enable) { 43 int LevelEstimatorImpl::Enable(bool enable) {
46 rtc::CritScope cs(crit_); 44 rtc::CritScope cs(crit_);
47 return EnableComponent(enable); 45 if (enable && !enabled_) {
46 rms_->Reset();
47 }
48 enabled_ = enable;
49 return AudioProcessing::kNoError;
48 } 50 }
49 51
50 bool LevelEstimatorImpl::is_enabled() const { 52 bool LevelEstimatorImpl::is_enabled() const {
51 rtc::CritScope cs(crit_); 53 rtc::CritScope cs(crit_);
52 return is_component_enabled(); 54 return enabled_;
53 } 55 }
54 56
55 int LevelEstimatorImpl::RMS() { 57 int LevelEstimatorImpl::RMS() {
56 rtc::CritScope cs(crit_); 58 rtc::CritScope cs(crit_);
57 if (!is_component_enabled()) { 59 if (!enabled_) {
58 return AudioProcessing::kNotEnabledError; 60 return AudioProcessing::kNotEnabledError;;
hlundin-webrtc 2015/12/15 10:07:57 The number of semicolons is too high.
the sun 2015/12/15 12:08:45 Done.
59 } 61 }
60 62
61 RMSLevel* rms_level = static_cast<RMSLevel*>(handle(0)); 63 return rms_->RMS();
62 return rms_level->RMS();
63 } 64 }
64
65 // The ProcessingComponent implementation is pretty weird in this class since
66 // we have only a single instance of the trivial underlying component.
67 void* LevelEstimatorImpl::CreateHandle() const {
68 return new RMSLevel;
69 }
70
71 void LevelEstimatorImpl::DestroyHandle(void* handle) const {
72 delete static_cast<RMSLevel*>(handle);
73 }
74
75 int LevelEstimatorImpl::InitializeHandle(void* handle) const {
76 rtc::CritScope cs(crit_);
77 static_cast<RMSLevel*>(handle)->Reset();
78 return AudioProcessing::kNoError;
79 }
80
81 int LevelEstimatorImpl::ConfigureHandle(void* /*handle*/) const {
82 return AudioProcessing::kNoError;
83 }
84
85 int LevelEstimatorImpl::num_handles_required() const {
86 return 1;
87 }
88
89 int LevelEstimatorImpl::GetHandleError(void* /*handle*/) const {
90 return AudioProcessing::kUnspecifiedError;
91 }
92
93 } // namespace webrtc 65 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/level_estimator_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698