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

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

Issue 1424663003: Lock scheme #8: Introduced the new locking scheme (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@add_threadcheckers_CL
Patch Set: Major general updates, completing the locking scheme, and increasing readability Created 5 years, 1 month 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
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/noise_suppression_impl.h" 11 #include "webrtc/modules/audio_processing/noise_suppression_impl.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 14
15 #include "webrtc/base/criticalsection.h"
15 #include "webrtc/modules/audio_processing/audio_buffer.h" 16 #include "webrtc/modules/audio_processing/audio_buffer.h"
16 #if defined(WEBRTC_NS_FLOAT) 17 #if defined(WEBRTC_NS_FLOAT)
17 #include "webrtc/modules/audio_processing/ns/include/noise_suppression.h" 18 #include "webrtc/modules/audio_processing/ns/include/noise_suppression.h"
18 #elif defined(WEBRTC_NS_FIXED) 19 #elif defined(WEBRTC_NS_FIXED)
19 #include "webrtc/modules/audio_processing/ns/include/noise_suppression_x.h" 20 #include "webrtc/modules/audio_processing/ns/include/noise_suppression_x.h"
20 #endif 21 #endif
21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
22 22
23 23
24 namespace webrtc { 24 namespace webrtc {
25 25
26 #if defined(WEBRTC_NS_FLOAT) 26 #if defined(WEBRTC_NS_FLOAT)
27 typedef NsHandle Handle; 27 typedef NsHandle Handle;
28 #elif defined(WEBRTC_NS_FIXED) 28 #elif defined(WEBRTC_NS_FIXED)
29 typedef NsxHandle Handle; 29 typedef NsxHandle Handle;
30 #endif 30 #endif
31 31
32 namespace { 32 namespace {
33 int MapSetting(NoiseSuppression::Level level) { 33 int MapSetting(NoiseSuppression::Level level) {
34 switch (level) { 34 switch (level) {
35 case NoiseSuppression::kLow: 35 case NoiseSuppression::kLow:
36 return 0; 36 return 0;
37 case NoiseSuppression::kModerate: 37 case NoiseSuppression::kModerate:
38 return 1; 38 return 1;
39 case NoiseSuppression::kHigh: 39 case NoiseSuppression::kHigh:
40 return 2; 40 return 2;
41 case NoiseSuppression::kVeryHigh: 41 case NoiseSuppression::kVeryHigh:
42 return 3; 42 return 3;
43 } 43 }
44 assert(false); 44 assert(false);
45 return -1; 45 return -1;
46 } 46 }
47 } // namespace 47 } // namespace
48 48
49 NoiseSuppressionImpl::NoiseSuppressionImpl(const AudioProcessing* apm, 49 NoiseSuppressionImpl::NoiseSuppressionImpl(const AudioProcessing* apm,
50 CriticalSectionWrapper* crit) 50 rtc::CriticalSection* crit)
51 : ProcessingComponent(), apm_(apm), crit_(crit), level_(kModerate) {} 51 : ProcessingComponent(), apm_(apm), crit_(crit), level_(kModerate) {}
52 52
53 NoiseSuppressionImpl::~NoiseSuppressionImpl() {} 53 NoiseSuppressionImpl::~NoiseSuppressionImpl() {}
54 54
55 int NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { 55 int NoiseSuppressionImpl::AnalyzeCaptureAudio(AudioBuffer* audio) {
56 #if defined(WEBRTC_NS_FLOAT) 56 #if defined(WEBRTC_NS_FLOAT)
57 if (!is_component_enabled()) { 57 if (!is_component_enabled()) {
58 return apm_->kNoError; 58 return apm_->kNoError;
59 } 59 }
60 assert(audio->num_frames_per_band() <= 160); 60 assert(audio->num_frames_per_band() <= 160);
(...skipping 26 matching lines...) Expand all
87 WebRtcNsx_Process(my_handle, 87 WebRtcNsx_Process(my_handle,
88 audio->split_bands_const(i), 88 audio->split_bands_const(i),
89 audio->num_bands(), 89 audio->num_bands(),
90 audio->split_bands(i)); 90 audio->split_bands(i));
91 #endif 91 #endif
92 } 92 }
93 return apm_->kNoError; 93 return apm_->kNoError;
94 } 94 }
95 95
96 int NoiseSuppressionImpl::Enable(bool enable) { 96 int NoiseSuppressionImpl::Enable(bool enable) {
97 CriticalSectionScoped crit_scoped(crit_); 97 rtc::CritScope cs(crit_);
98 return EnableComponent(enable); 98 return EnableComponent(enable);
99 } 99 }
100 100
101 bool NoiseSuppressionImpl::is_enabled() const { 101 bool NoiseSuppressionImpl::is_enabled() const {
102 rtc::CritScope cs(crit_);
102 return is_component_enabled(); 103 return is_component_enabled();
103 } 104 }
104 105
105 int NoiseSuppressionImpl::set_level(Level level) { 106 int NoiseSuppressionImpl::set_level(Level level) {
106 CriticalSectionScoped crit_scoped(crit_); 107 rtc::CritScope cs(crit_);
107 if (MapSetting(level) == -1) { 108 if (MapSetting(level) == -1) {
108 return apm_->kBadParameterError; 109 return apm_->kBadParameterError;
109 } 110 }
110 111
111 level_ = level; 112 level_ = level;
112 return Configure(); 113 return Configure();
113 } 114 }
114 115
115 NoiseSuppression::Level NoiseSuppressionImpl::level() const { 116 NoiseSuppression::Level NoiseSuppressionImpl::level() const {
117 rtc::CritScope cs(crit_);
116 return level_; 118 return level_;
117 } 119 }
118 120
119 float NoiseSuppressionImpl::speech_probability() const { 121 float NoiseSuppressionImpl::speech_probability() const {
122 rtc::CritScope cs(crit_);
120 #if defined(WEBRTC_NS_FLOAT) 123 #if defined(WEBRTC_NS_FLOAT)
121 float probability_average = 0.0f; 124 float probability_average = 0.0f;
122 for (int i = 0; i < num_handles(); i++) { 125 for (int i = 0; i < num_handles(); i++) {
123 Handle* my_handle = static_cast<Handle*>(handle(i)); 126 Handle* my_handle = static_cast<Handle*>(handle(i));
124 probability_average += WebRtcNs_prior_speech_probability(my_handle); 127 probability_average += WebRtcNs_prior_speech_probability(my_handle);
125 } 128 }
126 return probability_average / num_handles(); 129 return probability_average / num_handles();
127 #elif defined(WEBRTC_NS_FIXED) 130 #elif defined(WEBRTC_NS_FIXED)
128 // Currently not available for the fixed point implementation. 131 // Currently not available for the fixed point implementation.
129 return apm_->kUnsupportedFunctionError; 132 return apm_->kUnsupportedFunctionError;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 int NoiseSuppressionImpl::num_handles_required() const { 172 int NoiseSuppressionImpl::num_handles_required() const {
170 return apm_->num_output_channels(); 173 return apm_->num_output_channels();
171 } 174 }
172 175
173 int NoiseSuppressionImpl::GetHandleError(void* handle) const { 176 int NoiseSuppressionImpl::GetHandleError(void* handle) const {
174 // The NS has no get_error() function. 177 // The NS has no get_error() function.
175 assert(handle != NULL); 178 assert(handle != NULL);
176 return apm_->kUnspecifiedError; 179 return apm_->kUnspecifiedError;
177 } 180 }
178 } // namespace webrtc 181 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698