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

Side by Side Diff: webrtc/modules/audio_processing/gain_control_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 17 matching lines...) Expand all
28 case GainControl::kAdaptiveDigital: 28 case GainControl::kAdaptiveDigital:
29 return kAgcModeAdaptiveDigital; 29 return kAgcModeAdaptiveDigital;
30 case GainControl::kFixedDigital: 30 case GainControl::kFixedDigital:
31 return kAgcModeFixedDigital; 31 return kAgcModeFixedDigital;
32 } 32 }
33 assert(false); 33 assert(false);
34 return -1; 34 return -1;
35 } 35 }
36 } // namespace 36 } // namespace
37 37
38 const size_t GainControlImpl::kAllowedValuesOfSamplesPerFrame1;
39 const size_t GainControlImpl::kAllowedValuesOfSamplesPerFrame2;
40
41 GainControlImpl::GainControlImpl(const AudioProcessing* apm, 38 GainControlImpl::GainControlImpl(const AudioProcessing* apm,
42 CriticalSectionWrapper* crit) 39 CriticalSectionWrapper* crit)
43 : ProcessingComponent(), 40 : ProcessingComponent(),
44 apm_(apm), 41 apm_(apm),
45 crit_(crit), 42 crit_(crit),
46 mode_(kAdaptiveAnalog), 43 mode_(kAdaptiveAnalog),
47 minimum_capture_level_(0), 44 minimum_capture_level_(0),
48 maximum_capture_level_(255), 45 maximum_capture_level_(255),
49 limiter_enabled_(true), 46 limiter_enabled_(true),
50 target_level_dbfs_(3), 47 target_level_dbfs_(3),
51 compression_gain_db_(9), 48 compression_gain_db_(9),
52 analog_capture_level_(0), 49 analog_capture_level_(0),
53 was_analog_level_set_(false), 50 was_analog_level_set_(false),
54 stream_is_saturated_(false), 51 stream_is_saturated_(false),
55 render_queue_element_max_size_(0) { 52 render_queue_element_max_size_(0) {}
56 AllocateRenderQueue();
57 }
58 53
59 GainControlImpl::~GainControlImpl() {} 54 GainControlImpl::~GainControlImpl() {}
60 55
61 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { 56 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) {
62 if (!is_component_enabled()) { 57 if (!is_component_enabled()) {
63 return apm_->kNoError; 58 return apm_->kNoError;
64 } 59 }
65 60
66 assert(audio->num_frames_per_band() <= 160); 61 assert(audio->num_frames_per_band() <= 160);
67 62
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 205
211 analog_capture_level_ /= num_handles(); 206 analog_capture_level_ /= num_handles();
212 } 207 }
213 208
214 was_analog_level_set_ = false; 209 was_analog_level_set_ = false;
215 return apm_->kNoError; 210 return apm_->kNoError;
216 } 211 }
217 212
218 // TODO(ajm): ensure this is called under kAdaptiveAnalog. 213 // TODO(ajm): ensure this is called under kAdaptiveAnalog.
219 int GainControlImpl::set_stream_analog_level(int level) { 214 int GainControlImpl::set_stream_analog_level(int level) {
220 // TODO(peah): Verify that this is really needed to do the reading
221 // here as well as in ProcessStream. It works since these functions
222 // are called from the same thread, but it is not nice to do it in two
223 // places if not needed.
224 ReadQueuedRenderData();
225
226 CriticalSectionScoped crit_scoped(crit_); 215 CriticalSectionScoped crit_scoped(crit_);
227 was_analog_level_set_ = true; 216 was_analog_level_set_ = true;
228 if (level < minimum_capture_level_ || level > maximum_capture_level_) { 217 if (level < minimum_capture_level_ || level > maximum_capture_level_) {
229 return apm_->kBadParameterError; 218 return apm_->kBadParameterError;
230 } 219 }
231 analog_capture_level_ = level; 220 analog_capture_level_ = level;
232 221
233 return apm_->kNoError; 222 return apm_->kNoError;
234 } 223 }
235 224
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 331
343 AllocateRenderQueue(); 332 AllocateRenderQueue();
344 333
345 const int n = num_handles(); 334 const int n = num_handles();
346 RTC_CHECK_GE(n, 0) << "Bad number of handles: " << n; 335 RTC_CHECK_GE(n, 0) << "Bad number of handles: " << n;
347 capture_levels_.assign(n, analog_capture_level_); 336 capture_levels_.assign(n, analog_capture_level_);
348 return apm_->kNoError; 337 return apm_->kNoError;
349 } 338 }
350 339
351 void GainControlImpl::AllocateRenderQueue() { 340 void GainControlImpl::AllocateRenderQueue() {
352 const size_t max_frame_size = std::max<size_t>( 341 const size_t max_frame_size =
353 kAllowedValuesOfSamplesPerFrame1, kAllowedValuesOfSamplesPerFrame2); 342 std::max<size_t>(static_cast<size_t>(kAllowedValuesOfSamplesPerFrame1),
343 static_cast<size_t>(kAllowedValuesOfSamplesPerFrame2));
354 344
355 const size_t new_render_queue_element_max_size = std::max<size_t>( 345 const size_t new_render_queue_element_max_size = std::max<size_t>(
356 static_cast<size_t>(1), (max_frame_size * num_handles())); 346 static_cast<size_t>(1), (max_frame_size * num_handles()));
357 347
358 if (new_render_queue_element_max_size > render_queue_element_max_size_) { 348 if (new_render_queue_element_max_size > render_queue_element_max_size_) {
349 render_queue_element_max_size_ = new_render_queue_element_max_size;
359 std::vector<int16_t> template_queue_element(render_queue_element_max_size_); 350 std::vector<int16_t> template_queue_element(render_queue_element_max_size_);
360 351
361 render_signal_queue_.reset( 352 render_signal_queue_.reset(
362 new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>( 353 new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>(
363 kMaxNumFramesToBuffer, template_queue_element, 354 kMaxNumFramesToBuffer, template_queue_element,
364 RenderQueueItemVerifier<int16_t>(render_queue_element_max_size_))); 355 RenderQueueItemVerifier<int16_t>(render_queue_element_max_size_)));
356
357 render_queue_buffer_.resize(render_queue_element_max_size_);
358 capture_queue_buffer_.resize(render_queue_element_max_size_);
365 } else { 359 } else {
366 render_signal_queue_->Clear(); 360 render_signal_queue_->Clear();
367 } 361 }
368
369 render_queue_buffer_.resize(new_render_queue_element_max_size);
370 capture_queue_buffer_.resize(new_render_queue_element_max_size);
371 } 362 }
372 363
373 void* GainControlImpl::CreateHandle() const { 364 void* GainControlImpl::CreateHandle() const {
374 return WebRtcAgc_Create(); 365 return WebRtcAgc_Create();
375 } 366 }
376 367
377 void GainControlImpl::DestroyHandle(void* handle) const { 368 void GainControlImpl::DestroyHandle(void* handle) const {
378 WebRtcAgc_Free(static_cast<Handle*>(handle)); 369 WebRtcAgc_Free(static_cast<Handle*>(handle));
379 } 370 }
380 371
(...skipping 23 matching lines...) Expand all
404 return apm_->num_output_channels(); 395 return apm_->num_output_channels();
405 } 396 }
406 397
407 int GainControlImpl::GetHandleError(void* handle) const { 398 int GainControlImpl::GetHandleError(void* handle) const {
408 // The AGC has no get_error() function. 399 // The AGC has no get_error() function.
409 // (Despite listing errors in its interface...) 400 // (Despite listing errors in its interface...)
410 assert(handle != NULL); 401 assert(handle != NULL);
411 return apm_->kUnspecifiedError; 402 return apm_->kUnspecifiedError;
412 } 403 }
413 } // namespace webrtc 404 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698