| 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 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 // Maximum length that a frame of samples can have. | 37 // Maximum length that a frame of samples can have. |
| 38 static const size_t kMaxAllowedValuesOfSamplesPerFrame = 160; | 38 static const size_t kMaxAllowedValuesOfSamplesPerFrame = 160; |
| 39 // Maximum number of frames to buffer in the render queue. | 39 // Maximum number of frames to buffer in the render queue. |
| 40 // TODO(peah): Decrease this once we properly handle hugely unbalanced | 40 // TODO(peah): Decrease this once we properly handle hugely unbalanced |
| 41 // reverse and forward call numbers. | 41 // reverse and forward call numbers. |
| 42 static const size_t kMaxNumFramesToBuffer = 100; | 42 static const size_t kMaxNumFramesToBuffer = 100; |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 GainControlImpl::GainControlImpl(const AudioProcessing* apm, | 46 GainControlImpl::GainControlImpl( |
| 47 CriticalSectionWrapper* crit) | 47 const AudioProcessing* apm, |
| 48 CriticalSectionWrapper* crit, |
| 49 const rtc::ThreadChecker* render_thread_checker, |
| 50 const rtc::ThreadChecker* capture_thread_checker) |
| 48 : ProcessingComponent(), | 51 : ProcessingComponent(), |
| 49 apm_(apm), | 52 apm_(apm), |
| 50 crit_(crit), | 53 crit_(crit), |
| 54 render_thread_checker_(render_thread_checker), |
| 55 capture_thread_checker_(capture_thread_checker), |
| 51 mode_(kAdaptiveAnalog), | 56 mode_(kAdaptiveAnalog), |
| 52 minimum_capture_level_(0), | 57 minimum_capture_level_(0), |
| 53 maximum_capture_level_(255), | 58 maximum_capture_level_(255), |
| 54 limiter_enabled_(true), | 59 limiter_enabled_(true), |
| 55 target_level_dbfs_(3), | 60 target_level_dbfs_(3), |
| 56 compression_gain_db_(9), | 61 compression_gain_db_(9), |
| 57 analog_capture_level_(0), | 62 analog_capture_level_(0), |
| 58 was_analog_level_set_(false), | 63 was_analog_level_set_(false), |
| 59 stream_is_saturated_(false), | 64 stream_is_saturated_(false), |
| 60 render_queue_element_max_size_(0) {} | 65 render_queue_element_max_size_(0) {} |
| 61 | 66 |
| 62 GainControlImpl::~GainControlImpl() {} | 67 GainControlImpl::~GainControlImpl() {} |
| 63 | 68 |
| 64 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { | 69 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { |
| 70 RTC_DCHECK(render_thread_checker_->CalledOnValidThread()); |
| 65 if (!is_component_enabled()) { | 71 if (!is_component_enabled()) { |
| 66 return apm_->kNoError; | 72 return apm_->kNoError; |
| 67 } | 73 } |
| 68 | 74 |
| 69 assert(audio->num_frames_per_band() <= 160); | 75 assert(audio->num_frames_per_band() <= 160); |
| 70 | 76 |
| 71 render_queue_buffer_.resize(0); | 77 render_queue_buffer_.resize(0); |
| 72 for (int i = 0; i < num_handles(); i++) { | 78 for (int i = 0; i < num_handles(); i++) { |
| 73 Handle* my_handle = static_cast<Handle*>(handle(i)); | 79 Handle* my_handle = static_cast<Handle*>(handle(i)); |
| 74 int err = | 80 int err = |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 219 |
| 214 analog_capture_level_ /= num_handles(); | 220 analog_capture_level_ /= num_handles(); |
| 215 } | 221 } |
| 216 | 222 |
| 217 was_analog_level_set_ = false; | 223 was_analog_level_set_ = false; |
| 218 return apm_->kNoError; | 224 return apm_->kNoError; |
| 219 } | 225 } |
| 220 | 226 |
| 221 // TODO(ajm): ensure this is called under kAdaptiveAnalog. | 227 // TODO(ajm): ensure this is called under kAdaptiveAnalog. |
| 222 int GainControlImpl::set_stream_analog_level(int level) { | 228 int GainControlImpl::set_stream_analog_level(int level) { |
| 229 RTC_DCHECK(capture_thread_checker_->CalledOnValidThread()); |
| 223 CriticalSectionScoped crit_scoped(crit_); | 230 CriticalSectionScoped crit_scoped(crit_); |
| 224 was_analog_level_set_ = true; | 231 was_analog_level_set_ = true; |
| 225 if (level < minimum_capture_level_ || level > maximum_capture_level_) { | 232 if (level < minimum_capture_level_ || level > maximum_capture_level_) { |
| 226 return apm_->kBadParameterError; | 233 return apm_->kBadParameterError; |
| 227 } | 234 } |
| 228 analog_capture_level_ = level; | 235 analog_capture_level_ = level; |
| 229 | 236 |
| 230 return apm_->kNoError; | 237 return apm_->kNoError; |
| 231 } | 238 } |
| 232 | 239 |
| 233 int GainControlImpl::stream_analog_level() { | 240 int GainControlImpl::stream_analog_level() { |
| 241 RTC_DCHECK(capture_thread_checker_->CalledOnValidThread()); |
| 234 // TODO(ajm): enable this assertion? | 242 // TODO(ajm): enable this assertion? |
| 235 //assert(mode_ == kAdaptiveAnalog); | 243 //assert(mode_ == kAdaptiveAnalog); |
| 236 | 244 |
| 237 return analog_capture_level_; | 245 return analog_capture_level_; |
| 238 } | 246 } |
| 239 | 247 |
| 240 int GainControlImpl::Enable(bool enable) { | 248 int GainControlImpl::Enable(bool enable) { |
| 241 CriticalSectionScoped crit_scoped(crit_); | 249 CriticalSectionScoped crit_scoped(crit_); |
| 242 return EnableComponent(enable); | 250 return EnableComponent(enable); |
| 243 } | 251 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 return apm_->num_output_channels(); | 408 return apm_->num_output_channels(); |
| 401 } | 409 } |
| 402 | 410 |
| 403 int GainControlImpl::GetHandleError(void* handle) const { | 411 int GainControlImpl::GetHandleError(void* handle) const { |
| 404 // The AGC has no get_error() function. | 412 // The AGC has no get_error() function. |
| 405 // (Despite listing errors in its interface...) | 413 // (Despite listing errors in its interface...) |
| 406 assert(handle != NULL); | 414 assert(handle != NULL); |
| 407 return apm_->kUnspecifiedError; | 415 return apm_->kUnspecifiedError; |
| 408 } | 416 } |
| 409 } // namespace webrtc | 417 } // namespace webrtc |
| OLD | NEW |