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 21 matching lines...) Expand all Loading... |
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(const AudioProcessing* apm, |
42 CriticalSectionWrapper* crit) | 42 CriticalSectionWrapper* crit, |
| 43 rtc::ThreadChecker* render_thread_checker, |
| 44 rtc::ThreadChecker* capture_thread_checker) |
43 : ProcessingComponent(), | 45 : ProcessingComponent(), |
44 apm_(apm), | 46 apm_(apm), |
45 crit_(crit), | 47 crit_(crit), |
| 48 render_thread_checker_(render_thread_checker), |
| 49 capture_thread_checker_(capture_thread_checker), |
46 mode_(kAdaptiveAnalog), | 50 mode_(kAdaptiveAnalog), |
47 minimum_capture_level_(0), | 51 minimum_capture_level_(0), |
48 maximum_capture_level_(255), | 52 maximum_capture_level_(255), |
49 limiter_enabled_(true), | 53 limiter_enabled_(true), |
50 target_level_dbfs_(3), | 54 target_level_dbfs_(3), |
51 compression_gain_db_(9), | 55 compression_gain_db_(9), |
52 analog_capture_level_(0), | 56 analog_capture_level_(0), |
53 was_analog_level_set_(false), | 57 was_analog_level_set_(false), |
54 stream_is_saturated_(false), | 58 stream_is_saturated_(false), |
55 render_queue_element_max_size_(0) { | 59 render_queue_element_max_size_(0) { |
56 AllocateRenderQueue(); | 60 AllocateRenderQueue(); |
57 } | 61 } |
58 | 62 |
59 GainControlImpl::~GainControlImpl() {} | 63 GainControlImpl::~GainControlImpl() {} |
60 | 64 |
61 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { | 65 int GainControlImpl::ProcessRenderAudio(AudioBuffer* audio) { |
| 66 RTC_DCHECK(render_thread_checker_->CalledOnValidThread()); |
62 if (!is_component_enabled()) { | 67 if (!is_component_enabled()) { |
63 return apm_->kNoError; | 68 return apm_->kNoError; |
64 } | 69 } |
65 | 70 |
66 assert(audio->num_frames_per_band() <= 160); | 71 assert(audio->num_frames_per_band() <= 160); |
67 | 72 |
68 render_queue_buffer_.resize(0); | 73 render_queue_buffer_.resize(0); |
69 for (int i = 0; i < num_handles(); i++) { | 74 for (int i = 0; i < num_handles(); i++) { |
70 Handle* my_handle = static_cast<Handle*>(handle(i)); | 75 Handle* my_handle = static_cast<Handle*>(handle(i)); |
71 int err = | 76 int err = |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 211 |
207 analog_capture_level_ /= num_handles(); | 212 analog_capture_level_ /= num_handles(); |
208 } | 213 } |
209 | 214 |
210 was_analog_level_set_ = false; | 215 was_analog_level_set_ = false; |
211 return apm_->kNoError; | 216 return apm_->kNoError; |
212 } | 217 } |
213 | 218 |
214 // TODO(ajm): ensure this is called under kAdaptiveAnalog. | 219 // TODO(ajm): ensure this is called under kAdaptiveAnalog. |
215 int GainControlImpl::set_stream_analog_level(int level) { | 220 int GainControlImpl::set_stream_analog_level(int level) { |
| 221 RTC_DCHECK(capture_thread_checker_->CalledOnValidThread()); |
216 // TODO(peah): Verify that this is really needed to do the reading. | 222 // TODO(peah): Verify that this is really needed to do the reading. |
217 // here as well as in ProcessStream. It works since these functions | 223 // 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 | 224 // are called from the same thread, but it is not nice to do it in two |
219 // places if not needed. | 225 // places if not needed. |
220 ReadQueuedRenderData(); | 226 ReadQueuedRenderData(); |
221 | 227 |
222 CriticalSectionScoped crit_scoped(crit_); | 228 CriticalSectionScoped crit_scoped(crit_); |
223 was_analog_level_set_ = true; | 229 was_analog_level_set_ = true; |
224 if (level < minimum_capture_level_ || level > maximum_capture_level_) { | 230 if (level < minimum_capture_level_ || level > maximum_capture_level_) { |
225 return apm_->kBadParameterError; | 231 return apm_->kBadParameterError; |
226 } | 232 } |
227 analog_capture_level_ = level; | 233 analog_capture_level_ = level; |
228 | 234 |
229 return apm_->kNoError; | 235 return apm_->kNoError; |
230 } | 236 } |
231 | 237 |
232 int GainControlImpl::stream_analog_level() { | 238 int GainControlImpl::stream_analog_level() { |
| 239 RTC_DCHECK(capture_thread_checker_->CalledOnValidThread()); |
233 // TODO(ajm): enable this assertion? | 240 // TODO(ajm): enable this assertion? |
234 //assert(mode_ == kAdaptiveAnalog); | 241 //assert(mode_ == kAdaptiveAnalog); |
235 | 242 |
236 return analog_capture_level_; | 243 return analog_capture_level_; |
237 } | 244 } |
238 | 245 |
239 int GainControlImpl::Enable(bool enable) { | 246 int GainControlImpl::Enable(bool enable) { |
240 CriticalSectionScoped crit_scoped(crit_); | 247 CriticalSectionScoped crit_scoped(crit_); |
241 return EnableComponent(enable); | 248 return EnableComponent(enable); |
242 } | 249 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 return apm_->num_output_channels(); | 406 return apm_->num_output_channels(); |
400 } | 407 } |
401 | 408 |
402 int GainControlImpl::GetHandleError(void* handle) const { | 409 int GainControlImpl::GetHandleError(void* handle) const { |
403 // The AGC has no get_error() function. | 410 // The AGC has no get_error() function. |
404 // (Despite listing errors in its interface...) | 411 // (Despite listing errors in its interface...) |
405 assert(handle != NULL); | 412 assert(handle != NULL); |
406 return apm_->kUnspecifiedError; | 413 return apm_->kUnspecifiedError; |
407 } | 414 } |
408 } // namespace webrtc | 415 } // namespace webrtc |
OLD | NEW |