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

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

Issue 1454683002: Fixed the render queue item size preallocation and verification, moved constant declarations, remov… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
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
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 case AECM_BAD_PARAMETER_WARNING: 51 case AECM_BAD_PARAMETER_WARNING:
52 return AudioProcessing::kBadStreamParameterWarning; 52 return AudioProcessing::kBadStreamParameterWarning;
53 default: 53 default:
54 // AECM_UNSPECIFIED_ERROR 54 // AECM_UNSPECIFIED_ERROR
55 // AECM_UNINITIALIZED_ERROR 55 // AECM_UNINITIALIZED_ERROR
56 return AudioProcessing::kUnspecifiedError; 56 return AudioProcessing::kUnspecifiedError;
57 } 57 }
58 } 58 }
59 } // namespace 59 } // namespace
60 60
61 const size_t EchoControlMobileImpl::kAllowedValuesOfSamplesPerFrame1;
62 const size_t EchoControlMobileImpl::kAllowedValuesOfSamplesPerFrame2;
63
64 size_t EchoControlMobile::echo_path_size_bytes() { 61 size_t EchoControlMobile::echo_path_size_bytes() {
65 return WebRtcAecm_echo_path_size_bytes(); 62 return WebRtcAecm_echo_path_size_bytes();
66 } 63 }
67 64
68 EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessing* apm, 65 EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessing* apm,
69 CriticalSectionWrapper* crit) 66 CriticalSectionWrapper* crit)
70 : ProcessingComponent(), 67 : ProcessingComponent(),
71 apm_(apm), 68 apm_(apm),
72 crit_(crit), 69 crit_(crit),
73 routing_mode_(kSpeakerphone), 70 routing_mode_(kSpeakerphone),
74 comfort_noise_enabled_(true), 71 comfort_noise_enabled_(true),
75 external_echo_path_(NULL), 72 external_echo_path_(NULL),
76 render_queue_element_max_size_(0) { 73 render_queue_element_max_size_(0) {}
77 AllocateRenderQueue();
78 }
79 74
80 EchoControlMobileImpl::~EchoControlMobileImpl() { 75 EchoControlMobileImpl::~EchoControlMobileImpl() {
81 if (external_echo_path_ != NULL) { 76 if (external_echo_path_ != NULL) {
82 delete [] external_echo_path_; 77 delete [] external_echo_path_;
83 external_echo_path_ = NULL; 78 external_echo_path_ = NULL;
84 } 79 }
85 } 80 }
86 81
87 int EchoControlMobileImpl::ProcessRenderAudio(const AudioBuffer* audio) { 82 int EchoControlMobileImpl::ProcessRenderAudio(const AudioBuffer* audio) {
88 if (!is_component_enabled()) { 83 if (!is_component_enabled()) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 if (err != apm_->kNoError) { 289 if (err != apm_->kNoError) {
295 return err; 290 return err;
296 } 291 }
297 292
298 AllocateRenderQueue(); 293 AllocateRenderQueue();
299 294
300 return apm_->kNoError; 295 return apm_->kNoError;
301 } 296 }
302 297
303 void EchoControlMobileImpl::AllocateRenderQueue() { 298 void EchoControlMobileImpl::AllocateRenderQueue() {
304 const size_t max_frame_size = std::max<size_t>( 299 const size_t max_frame_size =
305 kAllowedValuesOfSamplesPerFrame1, kAllowedValuesOfSamplesPerFrame2); 300 std::max<size_t>(static_cast<size_t>(kAllowedValuesOfSamplesPerFrame1),
301 static_cast<size_t>(kAllowedValuesOfSamplesPerFrame2));
306 const size_t new_render_queue_element_max_size = std::max<size_t>( 302 const size_t new_render_queue_element_max_size = std::max<size_t>(
307 static_cast<size_t>(1), max_frame_size * num_handles_required()); 303 static_cast<size_t>(1), max_frame_size * num_handles_required());
308 304
309 // Reallocate the queue if the queue item size is too small to fit the 305 // Reallocate the queue if the queue item size is too small to fit the
310 // data to put in the queue. 306 // data to put in the queue.
311 if (new_render_queue_element_max_size > render_queue_element_max_size_) { 307 if (new_render_queue_element_max_size > render_queue_element_max_size_) {
312 render_queue_element_max_size_ = new_render_queue_element_max_size; 308 render_queue_element_max_size_ = new_render_queue_element_max_size;
313 309
314 std::vector<int16_t> template_queue_element(render_queue_element_max_size_); 310 std::vector<int16_t> template_queue_element(render_queue_element_max_size_);
315 311
316 render_signal_queue_.reset( 312 render_signal_queue_.reset(
317 new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>( 313 new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>(
318 kMaxNumFramesToBuffer, template_queue_element, 314 kMaxNumFramesToBuffer, template_queue_element,
319 RenderQueueItemVerifier<int16_t>(render_queue_element_max_size_))); 315 RenderQueueItemVerifier<int16_t>(render_queue_element_max_size_)));
316
317 render_queue_buffer_.resize(render_queue_element_max_size_);
318 capture_queue_buffer_.resize(render_queue_element_max_size_);
320 } else { 319 } else {
321 render_signal_queue_->Clear(); 320 render_signal_queue_->Clear();
322 } 321 }
323
324 render_queue_buffer_.resize(new_render_queue_element_max_size);
325 capture_queue_buffer_.resize(new_render_queue_element_max_size);
326 } 322 }
327 323
328 void* EchoControlMobileImpl::CreateHandle() const { 324 void* EchoControlMobileImpl::CreateHandle() const {
329 return WebRtcAecm_Create(); 325 return WebRtcAecm_Create();
330 } 326 }
331 327
332 void EchoControlMobileImpl::DestroyHandle(void* handle) const { 328 void EchoControlMobileImpl::DestroyHandle(void* handle) const {
333 WebRtcAecm_Free(static_cast<Handle*>(handle)); 329 WebRtcAecm_Free(static_cast<Handle*>(handle));
334 } 330 }
335 331
(...skipping 25 matching lines...) Expand all
361 int EchoControlMobileImpl::num_handles_required() const { 357 int EchoControlMobileImpl::num_handles_required() const {
362 return apm_->num_output_channels() * 358 return apm_->num_output_channels() *
363 apm_->num_reverse_channels(); 359 apm_->num_reverse_channels();
364 } 360 }
365 361
366 int EchoControlMobileImpl::GetHandleError(void* handle) const { 362 int EchoControlMobileImpl::GetHandleError(void* handle) const {
367 assert(handle != NULL); 363 assert(handle != NULL);
368 return AudioProcessing::kUnspecifiedError; 364 return AudioProcessing::kUnspecifiedError;
369 } 365 }
370 } // namespace webrtc 366 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698