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 20 matching lines...) Expand all Loading... | |
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; | 38 const size_t GainControlImpl::kAllowedValuesOfSamplesPerFrame1; |
39 const size_t GainControlImpl::kAllowedValuesOfSamplesPerFrame2; | 39 const size_t GainControlImpl::kAllowedValuesOfSamplesPerFrame2; |
40 | 40 |
41 GainControlImpl::GainControlImpl(const AudioProcessing* apm, | 41 GainControlImpl::GainControlImpl( |
42 CriticalSectionWrapper* crit) | 42 const AudioProcessing* apm, |
43 CriticalSectionWrapper* crit, | |
44 const rtc::ThreadChecker* render_thread_checker, | |
45 const rtc::ThreadChecker* capture_thread_checker) | |
43 : ProcessingComponent(), | 46 : ProcessingComponent(), |
44 apm_(apm), | 47 apm_(apm), |
45 crit_(crit), | 48 crit_(crit), |
49 render_thread_checker_(render_thread_checker), | |
50 capture_thread_checker_(capture_thread_checker), | |
46 mode_(kAdaptiveAnalog), | 51 mode_(kAdaptiveAnalog), |
47 minimum_capture_level_(0), | 52 minimum_capture_level_(0), |
48 maximum_capture_level_(255), | 53 maximum_capture_level_(255), |
49 limiter_enabled_(true), | 54 limiter_enabled_(true), |
50 target_level_dbfs_(3), | 55 target_level_dbfs_(3), |
51 compression_gain_db_(9), | 56 compression_gain_db_(9), |
52 analog_capture_level_(0), | 57 analog_capture_level_(0), |
53 was_analog_level_set_(false), | 58 was_analog_level_set_(false), |
54 stream_is_saturated_(false), | 59 stream_is_saturated_(false), |
55 render_queue_element_max_size_(0) { | 60 render_queue_element_max_size_(0) { |
56 AllocateRenderQueue(); | 61 AllocateRenderQueue(); |
57 } | 62 } |
58 | 63 |
59 GainControlImpl::~GainControlImpl() {} | 64 GainControlImpl::~GainControlImpl() {} |
60 | 65 |
61 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { | 66 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { |
67 RTC_DCHECK(render_thread_checker_->CalledOnValidThread()); | |
62 if (!is_component_enabled()) { | 68 if (!is_component_enabled()) { |
63 return apm_->kNoError; | 69 return apm_->kNoError; |
64 } | 70 } |
65 | 71 |
66 assert(audio->num_frames_per_band() <= 160); | 72 assert(audio->num_frames_per_band() <= 160); |
67 | 73 |
68 render_queue_buffer_.resize(0); | 74 render_queue_buffer_.resize(0); |
69 for (int i = 0; i < num_handles(); i++) { | 75 for (int i = 0; i < num_handles(); i++) { |
70 Handle* my_handle = static_cast<Handle*>(handle(i)); | 76 Handle* my_handle = static_cast<Handle*>(handle(i)); |
71 int err = | 77 int err = |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 | 212 |
207 analog_capture_level_ /= num_handles(); | 213 analog_capture_level_ /= num_handles(); |
208 } | 214 } |
209 | 215 |
210 was_analog_level_set_ = false; | 216 was_analog_level_set_ = false; |
211 return apm_->kNoError; | 217 return apm_->kNoError; |
212 } | 218 } |
213 | 219 |
214 // TODO(ajm): ensure this is called under kAdaptiveAnalog. | 220 // TODO(ajm): ensure this is called under kAdaptiveAnalog. |
215 int GainControlImpl::set_stream_analog_level(int level) { | 221 int GainControlImpl::set_stream_analog_level(int level) { |
222 RTC_DCHECK(capture_thread_checker_->CalledOnValidThread()); | |
216 // TODO(peah): Verify that this is really needed to do the reading | 223 // TODO(peah): Verify that this is really needed to do the reading |
217 // here as well as in ProcessStream. It works since these functions | 224 // here as well as in ProcessStream. It works since these functions |
218 // are called from the same thread, but it is not nice to do it in two | 225 // are called from the same thread, but it is not nice to do it in two |
219 // places if not needed. | 226 // places if not needed. |
220 ReadQueuedRenderData(); | 227 ReadQueuedRenderData(); |
221 | 228 |
222 CriticalSectionScoped crit_scoped(crit_); | 229 CriticalSectionScoped crit_scoped(crit_); |
223 was_analog_level_set_ = true; | 230 was_analog_level_set_ = true; |
224 if (level < minimum_capture_level_ || level > maximum_capture_level_) { | 231 if (level < minimum_capture_level_ || level > maximum_capture_level_) { |
225 return apm_->kBadParameterError; | 232 return apm_->kBadParameterError; |
226 } | 233 } |
227 analog_capture_level_ = level; | 234 analog_capture_level_ = level; |
228 | 235 |
229 return apm_->kNoError; | 236 return apm_->kNoError; |
230 } | 237 } |
231 | 238 |
232 int GainControlImpl::stream_analog_level() { | 239 int GainControlImpl::stream_analog_level() { |
240 RTC_DCHECK(capture_thread_checker_->CalledOnValidThread()); | |
233 // TODO(ajm): enable this assertion? | 241 // TODO(ajm): enable this assertion? |
234 //assert(mode_ == kAdaptiveAnalog); | 242 //assert(mode_ == kAdaptiveAnalog); |
235 | 243 |
236 return analog_capture_level_; | 244 return analog_capture_level_; |
237 } | 245 } |
238 | 246 |
239 int GainControlImpl::Enable(bool enable) { | 247 int GainControlImpl::Enable(bool enable) { |
240 CriticalSectionScoped crit_scoped(crit_); | 248 CriticalSectionScoped crit_scoped(crit_); |
241 return EnableComponent(enable); | 249 return EnableComponent(enable); |
242 } | 250 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 } | 339 } |
332 | 340 |
333 int GainControlImpl::Initialize() { | 341 int GainControlImpl::Initialize() { |
334 int err = ProcessingComponent::Initialize(); | 342 int err = ProcessingComponent::Initialize(); |
335 if (err != apm_->kNoError || !is_component_enabled()) { | 343 if (err != apm_->kNoError || !is_component_enabled()) { |
336 return err; | 344 return err; |
337 } | 345 } |
338 | 346 |
339 AllocateRenderQueue(); | 347 AllocateRenderQueue(); |
340 | 348 |
341 const int n = num_handles(); | 349 const int n = num_handles(); |
hlundin-webrtc
2015/11/06 07:45:07
(Effects of rebase.)
peah-webrtc
2015/11/06 08:11:47
Yep. That is the cause
| |
342 RTC_CHECK_GE(n, 0) << "Bad number of handles: " << n; | 350 RTC_CHECK_GE(n, 0) << "Bad number of handles: " << n; |
343 capture_levels_.assign(n, analog_capture_level_); | 351 capture_levels_.assign(n, analog_capture_level_); |
344 return apm_->kNoError; | 352 return apm_->kNoError; |
345 } | 353 } |
346 | 354 |
347 void GainControlImpl::AllocateRenderQueue() { | 355 void GainControlImpl::AllocateRenderQueue() { |
348 const size_t max_frame_size = std::max<size_t>( | 356 const size_t max_frame_size = std::max<size_t>( |
349 kAllowedValuesOfSamplesPerFrame1, kAllowedValuesOfSamplesPerFrame2); | 357 kAllowedValuesOfSamplesPerFrame1, kAllowedValuesOfSamplesPerFrame2); |
350 | 358 |
351 const size_t new_render_queue_element_max_size = std::max<size_t>( | 359 const size_t new_render_queue_element_max_size = std::max<size_t>( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 return apm_->num_output_channels(); | 409 return apm_->num_output_channels(); |
402 } | 410 } |
403 | 411 |
404 int GainControlImpl::GetHandleError(void* handle) const { | 412 int GainControlImpl::GetHandleError(void* handle) const { |
405 // The AGC has no get_error() function. | 413 // The AGC has no get_error() function. |
406 // (Despite listing errors in its interface...) | 414 // (Despite listing errors in its interface...) |
407 assert(handle != NULL); | 415 assert(handle != NULL); |
408 return apm_->kUnspecifiedError; | 416 return apm_->kUnspecifiedError; |
409 } | 417 } |
410 } // namespace webrtc | 418 } // namespace webrtc |
OLD | NEW |