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

Side by Side Diff: webrtc/modules/audio_processing/echo_control_mobile_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/echo_control_mobile_impl.h" 11 #include "webrtc/modules/audio_processing/echo_control_mobile_impl.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <string.h> 14 #include <string.h>
15 15
16 #include "webrtc/base/criticalsection.h"
16 #include "webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h" 17 #include "webrtc/modules/audio_processing/aecm/include/echo_control_mobile.h"
17 #include "webrtc/modules/audio_processing/audio_buffer.h" 18 #include "webrtc/modules/audio_processing/audio_buffer.h"
18 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
19 #include "webrtc/system_wrappers/interface/logging.h" 19 #include "webrtc/system_wrappers/interface/logging.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 22
23 typedef void Handle; 23 typedef void Handle;
24 24
25 namespace { 25 namespace {
26 int16_t MapSetting(EchoControlMobile::RoutingMode mode) { 26 int16_t MapSetting(EchoControlMobile::RoutingMode mode) {
27 switch (mode) { 27 switch (mode) {
28 case EchoControlMobile::kQuietEarpieceOrHeadset: 28 case EchoControlMobile::kQuietEarpieceOrHeadset:
(...skipping 30 matching lines...) Expand all
59 } // namespace 59 } // namespace
60 60
61 const size_t EchoControlMobileImpl::kAllowedValuesOfSamplesPerFrame1; 61 const size_t EchoControlMobileImpl::kAllowedValuesOfSamplesPerFrame1;
62 const size_t EchoControlMobileImpl::kAllowedValuesOfSamplesPerFrame2; 62 const size_t EchoControlMobileImpl::kAllowedValuesOfSamplesPerFrame2;
63 63
64 size_t EchoControlMobile::echo_path_size_bytes() { 64 size_t EchoControlMobile::echo_path_size_bytes() {
65 return WebRtcAecm_echo_path_size_bytes(); 65 return WebRtcAecm_echo_path_size_bytes();
66 } 66 }
67 67
68 EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessing* apm, 68 EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessing* apm,
69 CriticalSectionWrapper* crit, 69 rtc::CriticalSection* crit_render,
70 rtc::CriticalSection* crit_capture,
70 rtc::ThreadChecker* render_thread, 71 rtc::ThreadChecker* render_thread,
71 rtc::ThreadChecker* capture_thread) 72 rtc::ThreadChecker* capture_thread)
72 : ProcessingComponent(), 73 : ProcessingComponent(),
73 apm_(apm), 74 apm_(apm),
74 crit_(crit), 75 crit_render_(crit_render),
76 crit_capture_(crit_capture),
75 render_thread_(render_thread), 77 render_thread_(render_thread),
76 capture_thread_(capture_thread), 78 capture_thread_(capture_thread),
77 routing_mode_(kSpeakerphone), 79 routing_mode_(kSpeakerphone),
78 comfort_noise_enabled_(true), 80 comfort_noise_enabled_(true),
79 external_echo_path_(NULL), 81 external_echo_path_(NULL),
80 render_queue_element_max_size_(0) { 82 render_queue_element_max_size_(0) {
81 AllocateRenderQueue(); 83 AllocateRenderQueue();
82 } 84 }
83 85
84 EchoControlMobileImpl::~EchoControlMobileImpl() { 86 EchoControlMobileImpl::~EchoControlMobileImpl() {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 for (int j = 0; j < apm_->num_reverse_channels(); j++) { 154 for (int j = 0; j < apm_->num_reverse_channels(); j++) {
153 Handle* my_handle = static_cast<Handle*>(handle(handle_index)); 155 Handle* my_handle = static_cast<Handle*>(handle(handle_index));
154 (void)WebRtcAecm_BufferFarend(my_handle, 156 (void)WebRtcAecm_BufferFarend(my_handle,
155 &capture_queue_buffer_[buffer_index], 157 &capture_queue_buffer_[buffer_index],
156 num_frames_per_band); 158 num_frames_per_band);
157 159
158 buffer_index += num_frames_per_band; 160 buffer_index += num_frames_per_band;
159 handle_index++; 161 handle_index++;
160 } 162 }
161 } 163 }
164
165 samples_read = render_signal_queue_->Remove(&capture_queue_buffer_);
162 } 166 }
163 } 167 }
164 168
165 int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio) { 169 int EchoControlMobileImpl::ProcessCaptureAudio(AudioBuffer* audio) {
166 RTC_DCHECK(capture_thread_->CalledOnValidThread()); 170 RTC_DCHECK(capture_thread_->CalledOnValidThread());
167 if (!is_component_enabled()) { 171 if (!is_component_enabled()) {
168 return apm_->kNoError; 172 return apm_->kNoError;
169 } 173 }
170 174
171 if (!apm_->was_stream_delay_set()) { 175 if (!apm_->was_stream_delay_set()) {
(...skipping 30 matching lines...) Expand all
202 return MapError(err); 206 return MapError(err);
203 207
204 handle_index++; 208 handle_index++;
205 } 209 }
206 } 210 }
207 211
208 return apm_->kNoError; 212 return apm_->kNoError;
209 } 213 }
210 214
211 int EchoControlMobileImpl::Enable(bool enable) { 215 int EchoControlMobileImpl::Enable(bool enable) {
212 CriticalSectionScoped crit_scoped(crit_); 216 // Run in a single-threaded manner
217 rtc::CritScope cs_render(crit_render_);
218 rtc::CritScope cs_capture(crit_capture_);
213 // Ensure AEC and AECM are not both enabled. 219 // Ensure AEC and AECM are not both enabled.
214 if (enable && apm_->echo_cancellation()->is_enabled()) { 220 if (enable && apm_->echo_cancellation()->is_enabled()) {
215 return apm_->kBadParameterError; 221 return apm_->kBadParameterError;
216 } 222 }
217 223
218 return EnableComponent(enable); 224 return EnableComponent(enable);
219 } 225 }
220 226
221 bool EchoControlMobileImpl::is_enabled() const { 227 bool EchoControlMobileImpl::is_enabled() const {
228 rtc::CritScope cs(crit_capture_);
222 return is_component_enabled(); 229 return is_component_enabled();
223 } 230 }
224 231
225 int EchoControlMobileImpl::set_routing_mode(RoutingMode mode) { 232 int EchoControlMobileImpl::set_routing_mode(RoutingMode mode) {
226 CriticalSectionScoped crit_scoped(crit_); 233 rtc::CritScope cs(crit_capture_);
227 if (MapSetting(mode) == -1) { 234 if (MapSetting(mode) == -1) {
228 return apm_->kBadParameterError; 235 return apm_->kBadParameterError;
229 } 236 }
230 237
231 routing_mode_ = mode; 238 routing_mode_ = mode;
232 return Configure(); 239 return Configure();
233 } 240 }
234 241
235 EchoControlMobile::RoutingMode EchoControlMobileImpl::routing_mode() 242 EchoControlMobile::RoutingMode EchoControlMobileImpl::routing_mode()
236 const { 243 const {
244 rtc::CritScope cs(crit_capture_);
237 return routing_mode_; 245 return routing_mode_;
238 } 246 }
239 247
240 int EchoControlMobileImpl::enable_comfort_noise(bool enable) { 248 int EchoControlMobileImpl::enable_comfort_noise(bool enable) {
241 CriticalSectionScoped crit_scoped(crit_); 249 rtc::CritScope cs(crit_capture_);
242 comfort_noise_enabled_ = enable; 250 comfort_noise_enabled_ = enable;
243 return Configure(); 251 return Configure();
244 } 252 }
245 253
246 bool EchoControlMobileImpl::is_comfort_noise_enabled() const { 254 bool EchoControlMobileImpl::is_comfort_noise_enabled() const {
255 rtc::CritScope cs(crit_capture_);
247 return comfort_noise_enabled_; 256 return comfort_noise_enabled_;
248 } 257 }
249 258
250 int EchoControlMobileImpl::SetEchoPath(const void* echo_path, 259 int EchoControlMobileImpl::SetEchoPath(const void* echo_path,
251 size_t size_bytes) { 260 size_t size_bytes) {
252 CriticalSectionScoped crit_scoped(crit_); 261 rtc::CritScope cs(crit_capture_);
253 if (echo_path == NULL) { 262 if (echo_path == NULL) {
254 return apm_->kNullPointerError; 263 return apm_->kNullPointerError;
255 } 264 }
256 if (size_bytes != echo_path_size_bytes()) { 265 if (size_bytes != echo_path_size_bytes()) {
257 // Size mismatch 266 // Size mismatch
258 return apm_->kBadParameterError; 267 return apm_->kBadParameterError;
259 } 268 }
260 269
261 if (external_echo_path_ == NULL) { 270 if (external_echo_path_ == NULL) {
262 external_echo_path_ = new unsigned char[size_bytes]; 271 external_echo_path_ = new unsigned char[size_bytes];
263 } 272 }
264 memcpy(external_echo_path_, echo_path, size_bytes); 273 memcpy(external_echo_path_, echo_path, size_bytes);
265 274
266 return Initialize(); 275 return Initialize();
267 } 276 }
268 277
269 int EchoControlMobileImpl::GetEchoPath(void* echo_path, 278 int EchoControlMobileImpl::GetEchoPath(void* echo_path,
270 size_t size_bytes) const { 279 size_t size_bytes) const {
271 CriticalSectionScoped crit_scoped(crit_); 280 rtc::CritScope cs(crit_capture_);
272 if (echo_path == NULL) { 281 if (echo_path == NULL) {
273 return apm_->kNullPointerError; 282 return apm_->kNullPointerError;
274 } 283 }
275 if (size_bytes != echo_path_size_bytes()) { 284 if (size_bytes != echo_path_size_bytes()) {
276 // Size mismatch 285 // Size mismatch
277 return apm_->kBadParameterError; 286 return apm_->kBadParameterError;
278 } 287 }
279 if (!is_component_enabled()) { 288 if (!is_component_enabled()) {
280 return apm_->kNotEnabledError; 289 return apm_->kNotEnabledError;
281 } 290 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 return apm_->num_output_channels() * 380 return apm_->num_output_channels() *
372 apm_->num_reverse_channels(); 381 apm_->num_reverse_channels();
373 } 382 }
374 383
375 int EchoControlMobileImpl::GetHandleError(void* handle) const { 384 int EchoControlMobileImpl::GetHandleError(void* handle) const {
376 assert(handle != NULL); 385 assert(handle != NULL);
377 return AudioProcessing::kUnspecifiedError; 386 return AudioProcessing::kUnspecifiedError;
378 } 387 }
379 388
380 } // namespace webrtc 389 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698