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

Side by Side Diff: webrtc/modules/audio_processing/voice_detection_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: 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/voice_detection_impl.h" 11 #include "webrtc/modules/audio_processing/voice_detection_impl.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 14
15 #include "webrtc/base/criticalsection.h"
15 #include "webrtc/common_audio/vad/include/webrtc_vad.h" 16 #include "webrtc/common_audio/vad/include/webrtc_vad.h"
16 #include "webrtc/modules/audio_processing/audio_buffer.h" 17 #include "webrtc/modules/audio_processing/audio_buffer.h"
17 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
18 18
19 namespace webrtc { 19 namespace webrtc {
20 20
21 typedef VadInst Handle; 21 typedef VadInst Handle;
22 22
23 namespace { 23 namespace {
24 int MapSetting(VoiceDetection::Likelihood likelihood) { 24 int MapSetting(VoiceDetection::Likelihood likelihood) {
25 switch (likelihood) { 25 switch (likelihood) {
26 case VoiceDetection::kVeryLowLikelihood: 26 case VoiceDetection::kVeryLowLikelihood:
27 return 3; 27 return 3;
28 case VoiceDetection::kLowLikelihood: 28 case VoiceDetection::kLowLikelihood:
29 return 2; 29 return 2;
30 case VoiceDetection::kModerateLikelihood: 30 case VoiceDetection::kModerateLikelihood:
31 return 1; 31 return 1;
32 case VoiceDetection::kHighLikelihood: 32 case VoiceDetection::kHighLikelihood:
33 return 0; 33 return 0;
34 } 34 }
35 assert(false); 35 assert(false);
36 return -1; 36 return -1;
37 } 37 }
38 } // namespace 38 } // namespace
39 39
40 VoiceDetectionImpl::VoiceDetectionImpl(const AudioProcessing* apm, 40 VoiceDetectionImpl::VoiceDetectionImpl(const AudioProcessing* apm,
41 CriticalSectionWrapper* crit, 41 rtc::CriticalSection* crit,
42 rtc::ThreadChecker* capture_thread) 42 rtc::ThreadChecker* capture_thread)
43 : ProcessingComponent(), 43 : ProcessingComponent(),
44 apm_(apm), 44 apm_(apm),
45 crit_(crit), 45 crit_(crit),
46 capture_thread_(capture_thread), 46 capture_thread_(capture_thread),
47 stream_has_voice_(false), 47 stream_has_voice_(false),
48 using_external_vad_(false), 48 using_external_vad_(false),
49 likelihood_(kLowLikelihood), 49 likelihood_(kLowLikelihood),
50 frame_size_ms_(10), 50 frame_size_ms_(10),
51 frame_size_samples_(0) {} 51 frame_size_samples_(0) {}
(...skipping 25 matching lines...) Expand all
77 stream_has_voice_ = true; 77 stream_has_voice_ = true;
78 audio->set_activity(AudioFrame::kVadActive); 78 audio->set_activity(AudioFrame::kVadActive);
79 } else { 79 } else {
80 return apm_->kUnspecifiedError; 80 return apm_->kUnspecifiedError;
81 } 81 }
82 82
83 return apm_->kNoError; 83 return apm_->kNoError;
84 } 84 }
85 85
86 int VoiceDetectionImpl::Enable(bool enable) { 86 int VoiceDetectionImpl::Enable(bool enable) {
87 CriticalSectionScoped crit_scoped(crit_); 87 rtc::CritScope cs(crit_);
88 return EnableComponent(enable); 88 return EnableComponent(enable);
89 } 89 }
90 90
91 bool VoiceDetectionImpl::is_enabled() const { 91 bool VoiceDetectionImpl::is_enabled() const {
92 rtc::CritScope cs(crit_);
92 return is_component_enabled(); 93 return is_component_enabled();
93 } 94 }
94 95
95 int VoiceDetectionImpl::set_stream_has_voice(bool has_voice) { 96 int VoiceDetectionImpl::set_stream_has_voice(bool has_voice) {
97 rtc::CritScope cs(crit_);
96 using_external_vad_ = true; 98 using_external_vad_ = true;
97 stream_has_voice_ = has_voice; 99 stream_has_voice_ = has_voice;
98 return apm_->kNoError; 100 return apm_->kNoError;
99 } 101 }
100 102
101 bool VoiceDetectionImpl::stream_has_voice() const { 103 bool VoiceDetectionImpl::stream_has_voice() const {
104 rtc::CritScope cs(crit_);
102 // TODO(ajm): enable this assertion? 105 // TODO(ajm): enable this assertion?
103 //assert(using_external_vad_ || is_component_enabled()); 106 //assert(using_external_vad_ || is_component_enabled());
104 return stream_has_voice_; 107 return stream_has_voice_;
105 } 108 }
106 109
107 int VoiceDetectionImpl::set_likelihood(VoiceDetection::Likelihood likelihood) { 110 int VoiceDetectionImpl::set_likelihood(VoiceDetection::Likelihood likelihood) {
108 CriticalSectionScoped crit_scoped(crit_); 111 rtc::CritScope cs(crit_);
109 if (MapSetting(likelihood) == -1) { 112 if (MapSetting(likelihood) == -1) {
110 return apm_->kBadParameterError; 113 return apm_->kBadParameterError;
111 } 114 }
112 115
113 likelihood_ = likelihood; 116 likelihood_ = likelihood;
114 return Configure(); 117 return Configure();
115 } 118 }
116 119
117 VoiceDetection::Likelihood VoiceDetectionImpl::likelihood() const { 120 VoiceDetection::Likelihood VoiceDetectionImpl::likelihood() const {
121 rtc::CritScope cs(crit_);
118 return likelihood_; 122 return likelihood_;
119 } 123 }
120 124
121 int VoiceDetectionImpl::set_frame_size_ms(int size) { 125 int VoiceDetectionImpl::set_frame_size_ms(int size) {
122 CriticalSectionScoped crit_scoped(crit_); 126 rtc::CritScope cs(crit_);
123 assert(size == 10); // TODO(ajm): remove when supported. 127 assert(size == 10); // TODO(ajm): remove when supported.
124 if (size != 10 && 128 if (size != 10 &&
125 size != 20 && 129 size != 20 &&
126 size != 30) { 130 size != 30) {
127 return apm_->kBadParameterError; 131 return apm_->kBadParameterError;
128 } 132 }
129 133
130 frame_size_ms_ = size; 134 frame_size_ms_ = size;
131 135
132 return Initialize(); 136 return Initialize();
133 } 137 }
134 138
135 int VoiceDetectionImpl::frame_size_ms() const { 139 int VoiceDetectionImpl::frame_size_ms() const {
140 rtc::CritScope cs(crit_);
136 return frame_size_ms_; 141 return frame_size_ms_;
137 } 142 }
138 143
139 int VoiceDetectionImpl::Initialize() { 144 int VoiceDetectionImpl::Initialize() {
140 int err = ProcessingComponent::Initialize(); 145 int err = ProcessingComponent::Initialize();
141 if (err != apm_->kNoError || !is_component_enabled()) { 146 if (err != apm_->kNoError || !is_component_enabled()) {
142 return err; 147 return err;
143 } 148 }
144 149
145 using_external_vad_ = false; 150 using_external_vad_ = false;
(...skipping 24 matching lines...) Expand all
170 int VoiceDetectionImpl::num_handles_required() const { 175 int VoiceDetectionImpl::num_handles_required() const {
171 return 1; 176 return 1;
172 } 177 }
173 178
174 int VoiceDetectionImpl::GetHandleError(void* handle) const { 179 int VoiceDetectionImpl::GetHandleError(void* handle) const {
175 // The VAD has no get_error() function. 180 // The VAD has no get_error() function.
176 assert(handle != NULL); 181 assert(handle != NULL);
177 return apm_->kUnspecifiedError; 182 return apm_->kUnspecifiedError;
178 } 183 }
179 } // namespace webrtc 184 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698