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

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: Merge with latest changes in master 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 case AECM_BAD_PARAMETER_ERROR: 49 case AECM_BAD_PARAMETER_ERROR:
50 return AudioProcessing::kBadParameterError; 50 return AudioProcessing::kBadParameterError;
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 // Maximum length that a frame of samples can have.
60 static const size_t kMaxAllowedValuesOfSamplesPerFrame = 160;
61 // Maximum number of frames to buffer in the render queue.
62 // TODO(peah): Decrease this once we properly handle hugely unbalanced
63 // reverse and forward call numbers.
64 static const size_t kMaxNumFramesToBuffer = 100;
59 } // namespace 65 } // namespace
60 66
61 const size_t EchoControlMobileImpl::kAllowedValuesOfSamplesPerFrame1;
62 const size_t EchoControlMobileImpl::kAllowedValuesOfSamplesPerFrame2;
63
64 size_t EchoControlMobile::echo_path_size_bytes() { 67 size_t EchoControlMobile::echo_path_size_bytes() {
65 return WebRtcAecm_echo_path_size_bytes(); 68 return WebRtcAecm_echo_path_size_bytes();
66 } 69 }
67 70
68 EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessing* apm, 71 EchoControlMobileImpl::EchoControlMobileImpl(const AudioProcessing* apm,
69 CriticalSectionWrapper* crit) 72 CriticalSectionWrapper* crit)
70 : ProcessingComponent(), 73 : ProcessingComponent(),
71 apm_(apm), 74 apm_(apm),
72 crit_(crit), 75 crit_(crit),
73 routing_mode_(kSpeakerphone), 76 routing_mode_(kSpeakerphone),
74 comfort_noise_enabled_(true), 77 comfort_noise_enabled_(true),
75 external_echo_path_(NULL), 78 external_echo_path_(NULL),
76 render_queue_element_max_size_(0) { 79 render_queue_element_max_size_(0) {}
77 AllocateRenderQueue();
78 }
79 80
80 EchoControlMobileImpl::~EchoControlMobileImpl() { 81 EchoControlMobileImpl::~EchoControlMobileImpl() {
81 if (external_echo_path_ != NULL) { 82 if (external_echo_path_ != NULL) {
82 delete [] external_echo_path_; 83 delete [] external_echo_path_;
83 external_echo_path_ = NULL; 84 external_echo_path_ = NULL;
84 } 85 }
85 } 86 }
86 87
87 int EchoControlMobileImpl::ProcessRenderAudio(const AudioBuffer* audio) { 88 int EchoControlMobileImpl::ProcessRenderAudio(const AudioBuffer* audio) {
88 if (!is_component_enabled()) { 89 if (!is_component_enabled()) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 if (err != apm_->kNoError) { 295 if (err != apm_->kNoError) {
295 return err; 296 return err;
296 } 297 }
297 298
298 AllocateRenderQueue(); 299 AllocateRenderQueue();
299 300
300 return apm_->kNoError; 301 return apm_->kNoError;
301 } 302 }
302 303
303 void EchoControlMobileImpl::AllocateRenderQueue() { 304 void EchoControlMobileImpl::AllocateRenderQueue() {
304 const size_t max_frame_size = std::max<size_t>(
305 kAllowedValuesOfSamplesPerFrame1, kAllowedValuesOfSamplesPerFrame2);
306 const size_t new_render_queue_element_max_size = std::max<size_t>( 305 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()); 306 static_cast<size_t>(1),
307 kMaxAllowedValuesOfSamplesPerFrame * num_handles_required());
308 308
309 // Reallocate the queue if the queue item size is too small to fit the 309 // Reallocate the queue if the queue item size is too small to fit the
310 // data to put in the queue. 310 // data to put in the queue.
311 if (new_render_queue_element_max_size > render_queue_element_max_size_) { 311 if (render_queue_element_max_size_ < new_render_queue_element_max_size) {
312 render_queue_element_max_size_ = new_render_queue_element_max_size; 312 render_queue_element_max_size_ = new_render_queue_element_max_size;
313 313
314 std::vector<int16_t> template_queue_element(render_queue_element_max_size_); 314 std::vector<int16_t> template_queue_element(render_queue_element_max_size_);
315 315
316 render_signal_queue_.reset( 316 render_signal_queue_.reset(
317 new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>( 317 new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>(
318 kMaxNumFramesToBuffer, template_queue_element, 318 kMaxNumFramesToBuffer, template_queue_element,
319 RenderQueueItemVerifier<int16_t>(render_queue_element_max_size_))); 319 RenderQueueItemVerifier<int16_t>(render_queue_element_max_size_)));
320
321 render_queue_buffer_.resize(render_queue_element_max_size_);
322 capture_queue_buffer_.resize(render_queue_element_max_size_);
320 } else { 323 } else {
321 render_signal_queue_->Clear(); 324 render_signal_queue_->Clear();
322 } 325 }
323
324 render_queue_buffer_.resize(new_render_queue_element_max_size);
325 capture_queue_buffer_.resize(new_render_queue_element_max_size);
326 } 326 }
327 327
328 void* EchoControlMobileImpl::CreateHandle() const { 328 void* EchoControlMobileImpl::CreateHandle() const {
329 return WebRtcAecm_Create(); 329 return WebRtcAecm_Create();
330 } 330 }
331 331
332 void EchoControlMobileImpl::DestroyHandle(void* handle) const { 332 void EchoControlMobileImpl::DestroyHandle(void* handle) const {
333 WebRtcAecm_Free(static_cast<Handle*>(handle)); 333 WebRtcAecm_Free(static_cast<Handle*>(handle));
334 } 334 }
335 335
(...skipping 25 matching lines...) Expand all
361 int EchoControlMobileImpl::num_handles_required() const { 361 int EchoControlMobileImpl::num_handles_required() const {
362 return apm_->num_output_channels() * 362 return apm_->num_output_channels() *
363 apm_->num_reverse_channels(); 363 apm_->num_reverse_channels();
364 } 364 }
365 365
366 int EchoControlMobileImpl::GetHandleError(void* handle) const { 366 int EchoControlMobileImpl::GetHandleError(void* handle) const {
367 assert(handle != NULL); 367 assert(handle != NULL);
368 return AudioProcessing::kUnspecifiedError; 368 return AudioProcessing::kUnspecifiedError;
369 } 369 }
370 } // namespace webrtc 370 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/echo_control_mobile_impl.h ('k') | webrtc/modules/audio_processing/gain_control_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698