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/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/include/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 : ProcessingComponent(), | 42 : ProcessingComponent(), |
43 apm_(apm), | 43 apm_(apm), |
44 crit_(crit), | 44 crit_(crit), |
45 stream_has_voice_(false), | 45 stream_has_voice_(false), |
46 using_external_vad_(false), | 46 using_external_vad_(false), |
47 likelihood_(kLowLikelihood), | 47 likelihood_(kLowLikelihood), |
48 frame_size_ms_(10), | 48 frame_size_ms_(10), |
49 frame_size_samples_(0) {} | 49 frame_size_samples_(0) {} |
50 | 50 |
51 VoiceDetectionImpl::~VoiceDetectionImpl() {} | 51 VoiceDetectionImpl::~VoiceDetectionImpl() {} |
(...skipping 22 matching lines...) Expand all Loading... |
74 stream_has_voice_ = true; | 74 stream_has_voice_ = true; |
75 audio->set_activity(AudioFrame::kVadActive); | 75 audio->set_activity(AudioFrame::kVadActive); |
76 } else { | 76 } else { |
77 return apm_->kUnspecifiedError; | 77 return apm_->kUnspecifiedError; |
78 } | 78 } |
79 | 79 |
80 return apm_->kNoError; | 80 return apm_->kNoError; |
81 } | 81 } |
82 | 82 |
83 int VoiceDetectionImpl::Enable(bool enable) { | 83 int VoiceDetectionImpl::Enable(bool enable) { |
84 CriticalSectionScoped crit_scoped(crit_); | 84 rtc::CritScope cs(crit_); |
85 return EnableComponent(enable); | 85 return EnableComponent(enable); |
86 } | 86 } |
87 | 87 |
88 bool VoiceDetectionImpl::is_enabled() const { | 88 bool VoiceDetectionImpl::is_enabled() const { |
| 89 rtc::CritScope cs(crit_); |
89 return is_component_enabled(); | 90 return is_component_enabled(); |
90 } | 91 } |
91 | 92 |
92 int VoiceDetectionImpl::set_stream_has_voice(bool has_voice) { | 93 int VoiceDetectionImpl::set_stream_has_voice(bool has_voice) { |
| 94 rtc::CritScope cs(crit_); |
93 using_external_vad_ = true; | 95 using_external_vad_ = true; |
94 stream_has_voice_ = has_voice; | 96 stream_has_voice_ = has_voice; |
95 return apm_->kNoError; | 97 return apm_->kNoError; |
96 } | 98 } |
97 | 99 |
98 bool VoiceDetectionImpl::stream_has_voice() const { | 100 bool VoiceDetectionImpl::stream_has_voice() const { |
| 101 rtc::CritScope cs(crit_); |
99 // TODO(ajm): enable this assertion? | 102 // TODO(ajm): enable this assertion? |
100 //assert(using_external_vad_ || is_component_enabled()); | 103 //assert(using_external_vad_ || is_component_enabled()); |
101 return stream_has_voice_; | 104 return stream_has_voice_; |
102 } | 105 } |
103 | 106 |
104 int VoiceDetectionImpl::set_likelihood(VoiceDetection::Likelihood likelihood) { | 107 int VoiceDetectionImpl::set_likelihood(VoiceDetection::Likelihood likelihood) { |
105 CriticalSectionScoped crit_scoped(crit_); | 108 rtc::CritScope cs(crit_); |
106 if (MapSetting(likelihood) == -1) { | 109 if (MapSetting(likelihood) == -1) { |
107 return apm_->kBadParameterError; | 110 return apm_->kBadParameterError; |
108 } | 111 } |
109 | 112 |
110 likelihood_ = likelihood; | 113 likelihood_ = likelihood; |
111 return Configure(); | 114 return Configure(); |
112 } | 115 } |
113 | 116 |
114 VoiceDetection::Likelihood VoiceDetectionImpl::likelihood() const { | 117 VoiceDetection::Likelihood VoiceDetectionImpl::likelihood() const { |
| 118 rtc::CritScope cs(crit_); |
115 return likelihood_; | 119 return likelihood_; |
116 } | 120 } |
117 | 121 |
118 int VoiceDetectionImpl::set_frame_size_ms(int size) { | 122 int VoiceDetectionImpl::set_frame_size_ms(int size) { |
119 CriticalSectionScoped crit_scoped(crit_); | 123 rtc::CritScope cs(crit_); |
120 assert(size == 10); // TODO(ajm): remove when supported. | 124 assert(size == 10); // TODO(ajm): remove when supported. |
121 if (size != 10 && | 125 if (size != 10 && |
122 size != 20 && | 126 size != 20 && |
123 size != 30) { | 127 size != 30) { |
124 return apm_->kBadParameterError; | 128 return apm_->kBadParameterError; |
125 } | 129 } |
126 | 130 |
127 frame_size_ms_ = size; | 131 frame_size_ms_ = size; |
128 | 132 |
129 return Initialize(); | 133 return Initialize(); |
130 } | 134 } |
131 | 135 |
132 int VoiceDetectionImpl::frame_size_ms() const { | 136 int VoiceDetectionImpl::frame_size_ms() const { |
| 137 rtc::CritScope cs(crit_); |
133 return frame_size_ms_; | 138 return frame_size_ms_; |
134 } | 139 } |
135 | 140 |
136 int VoiceDetectionImpl::Initialize() { | 141 int VoiceDetectionImpl::Initialize() { |
137 int err = ProcessingComponent::Initialize(); | 142 int err = ProcessingComponent::Initialize(); |
138 if (err != apm_->kNoError || !is_component_enabled()) { | 143 if (err != apm_->kNoError || !is_component_enabled()) { |
139 return err; | 144 return err; |
140 } | 145 } |
141 | 146 |
142 using_external_vad_ = false; | 147 using_external_vad_ = false; |
(...skipping 24 matching lines...) Expand all Loading... |
167 int VoiceDetectionImpl::num_handles_required() const { | 172 int VoiceDetectionImpl::num_handles_required() const { |
168 return 1; | 173 return 1; |
169 } | 174 } |
170 | 175 |
171 int VoiceDetectionImpl::GetHandleError(void* handle) const { | 176 int VoiceDetectionImpl::GetHandleError(void* handle) const { |
172 // The VAD has no get_error() function. | 177 // The VAD has no get_error() function. |
173 assert(handle != NULL); | 178 assert(handle != NULL); |
174 return apm_->kUnspecifiedError; | 179 return apm_->kUnspecifiedError; |
175 } | 180 } |
176 } // namespace webrtc | 181 } // namespace webrtc |
OLD | NEW |