| 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, |
| 44 rtc::ThreadChecker* capture_thread) |
| 43 : ProcessingComponent(), | 45 : ProcessingComponent(), |
| 44 apm_(apm), | 46 apm_(apm), |
| 45 crit_(crit), | 47 crit_(crit), |
| 48 render_thread_(render_thread), |
| 49 capture_thread_(capture_thread), |
| 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_->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 int buffer_index = 0; | 73 int buffer_index = 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 15 matching lines...) Expand all Loading... |
| 87 | 92 |
| 88 render_queue_buffer_.resize(buffer_index); | 93 render_queue_buffer_.resize(buffer_index); |
| 89 render_signal_queue_->Insert(&render_queue_buffer_); | 94 render_signal_queue_->Insert(&render_queue_buffer_); |
| 90 | 95 |
| 91 return apm_->kNoError; | 96 return apm_->kNoError; |
| 92 } | 97 } |
| 93 | 98 |
| 94 // Read chunks of data that were received and queued on the render side from | 99 // Read chunks of data that were received and queued on the render side from |
| 95 // a queue. All the data chunks are buffered into the farend signal of the AGC. | 100 // a queue. All the data chunks are buffered into the farend signal of the AGC. |
| 96 void GainControlImpl::ReadQueuedRenderData() { | 101 void GainControlImpl::ReadQueuedRenderData() { |
| 102 RTC_DCHECK(capture_thread_->CalledOnValidThread()); |
| 97 if (!is_component_enabled()) { | 103 if (!is_component_enabled()) { |
| 98 return; | 104 return; |
| 99 } | 105 } |
| 100 | 106 |
| 101 bool samples_read = render_signal_queue_->Remove(&capture_queue_buffer_); | 107 bool samples_read = render_signal_queue_->Remove(&capture_queue_buffer_); |
| 102 while (samples_read) { | 108 while (samples_read) { |
| 103 int buffer_index = 0; | 109 int buffer_index = 0; |
| 104 const int num_frames_per_band = | 110 const int num_frames_per_band = |
| 105 capture_queue_buffer_.size() / num_handles(); | 111 capture_queue_buffer_.size() / num_handles(); |
| 106 for (int i = 0; i < num_handles(); i++) { | 112 for (int i = 0; i < num_handles(); i++) { |
| 107 Handle* my_handle = static_cast<Handle*>(handle(i)); | 113 Handle* my_handle = static_cast<Handle*>(handle(i)); |
| 108 (void)WebRtcAgc_AddFarend(my_handle, &capture_queue_buffer_[buffer_index], | 114 (void)WebRtcAgc_AddFarend(my_handle, &capture_queue_buffer_[buffer_index], |
| 109 num_frames_per_band); | 115 num_frames_per_band); |
| 110 | 116 |
| 111 buffer_index += num_frames_per_band; | 117 buffer_index += num_frames_per_band; |
| 112 } | 118 } |
| 113 samples_read = render_signal_queue_->Remove(&capture_queue_buffer_); | 119 samples_read = render_signal_queue_->Remove(&capture_queue_buffer_); |
| 114 } | 120 } |
| 115 } | 121 } |
| 116 | 122 |
| 117 int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { | 123 int GainControlImpl::AnalyzeCaptureAudio(AudioBuffer* audio) { |
| 124 RTC_DCHECK(capture_thread_->CalledOnValidThread()); |
| 118 if (!is_component_enabled()) { | 125 if (!is_component_enabled()) { |
| 119 return apm_->kNoError; | 126 return apm_->kNoError; |
| 120 } | 127 } |
| 121 | 128 |
| 122 assert(audio->num_frames_per_band() <= 160); | 129 assert(audio->num_frames_per_band() <= 160); |
| 123 assert(audio->num_channels() == num_handles()); | 130 assert(audio->num_channels() == num_handles()); |
| 124 | 131 |
| 125 int err = apm_->kNoError; | 132 int err = apm_->kNoError; |
| 126 | 133 |
| 127 if (mode_ == kAdaptiveAnalog) { | 134 if (mode_ == kAdaptiveAnalog) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 158 return GetHandleError(my_handle); | 165 return GetHandleError(my_handle); |
| 159 } | 166 } |
| 160 | 167 |
| 161 } | 168 } |
| 162 } | 169 } |
| 163 | 170 |
| 164 return apm_->kNoError; | 171 return apm_->kNoError; |
| 165 } | 172 } |
| 166 | 173 |
| 167 int GainControlImpl::ProcessCaptureAudio(AudioBuffer* audio) { | 174 int GainControlImpl::ProcessCaptureAudio(AudioBuffer* audio) { |
| 175 RTC_DCHECK(capture_thread_->CalledOnValidThread()); |
| 168 if (!is_component_enabled()) { | 176 if (!is_component_enabled()) { |
| 169 return apm_->kNoError; | 177 return apm_->kNoError; |
| 170 } | 178 } |
| 171 | 179 |
| 172 if (mode_ == kAdaptiveAnalog && !was_analog_level_set_) { | 180 if (mode_ == kAdaptiveAnalog && !was_analog_level_set_) { |
| 173 return apm_->kStreamParameterNotSetError; | 181 return apm_->kStreamParameterNotSetError; |
| 174 } | 182 } |
| 175 | 183 |
| 176 assert(audio->num_frames_per_band() <= 160); | 184 assert(audio->num_frames_per_band() <= 160); |
| 177 assert(audio->num_channels() == num_handles()); | 185 assert(audio->num_channels() == num_handles()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 220 |
| 213 analog_capture_level_ /= num_handles(); | 221 analog_capture_level_ /= num_handles(); |
| 214 } | 222 } |
| 215 | 223 |
| 216 was_analog_level_set_ = false; | 224 was_analog_level_set_ = false; |
| 217 return apm_->kNoError; | 225 return apm_->kNoError; |
| 218 } | 226 } |
| 219 | 227 |
| 220 // TODO(ajm): ensure this is called under kAdaptiveAnalog. | 228 // TODO(ajm): ensure this is called under kAdaptiveAnalog. |
| 221 int GainControlImpl::set_stream_analog_level(int level) { | 229 int GainControlImpl::set_stream_analog_level(int level) { |
| 230 RTC_DCHECK(capture_thread_->CalledOnValidThread()); |
| 222 // TODO(peah): Verify that this is really needed to do the reading. | 231 // TODO(peah): Verify that this is really needed to do the reading. |
| 223 // here as well as in ProcessStream. It works since these functions | 232 // here as well as in ProcessStream. It works since these functions |
| 224 // are called from the same thread, but it is not nice to do it in two | 233 // are called from the same thread, but it is not nice to do it in two |
| 225 // places if not needed. | 234 // places if not needed. |
| 226 ReadQueuedRenderData(); | 235 ReadQueuedRenderData(); |
| 227 | 236 |
| 228 CriticalSectionScoped crit_scoped(crit_); | 237 CriticalSectionScoped crit_scoped(crit_); |
| 229 was_analog_level_set_ = true; | 238 was_analog_level_set_ = true; |
| 230 if (level < minimum_capture_level_ || level > maximum_capture_level_) { | 239 if (level < minimum_capture_level_ || level > maximum_capture_level_) { |
| 231 return apm_->kBadParameterError; | 240 return apm_->kBadParameterError; |
| 232 } | 241 } |
| 233 analog_capture_level_ = level; | 242 analog_capture_level_ = level; |
| 234 | 243 |
| 235 return apm_->kNoError; | 244 return apm_->kNoError; |
| 236 } | 245 } |
| 237 | 246 |
| 238 int GainControlImpl::stream_analog_level() { | 247 int GainControlImpl::stream_analog_level() { |
| 248 RTC_DCHECK(capture_thread_->CalledOnValidThread()); |
| 239 // TODO(ajm): enable this assertion? | 249 // TODO(ajm): enable this assertion? |
| 240 //assert(mode_ == kAdaptiveAnalog); | 250 //assert(mode_ == kAdaptiveAnalog); |
| 241 | 251 |
| 242 return analog_capture_level_; | 252 return analog_capture_level_; |
| 243 } | 253 } |
| 244 | 254 |
| 245 int GainControlImpl::Enable(bool enable) { | 255 int GainControlImpl::Enable(bool enable) { |
| 246 CriticalSectionScoped crit_scoped(crit_); | 256 CriticalSectionScoped crit_scoped(crit_); |
| 247 return EnableComponent(enable); | 257 return EnableComponent(enable); |
| 248 } | 258 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 return apm_->num_output_channels(); | 417 return apm_->num_output_channels(); |
| 408 } | 418 } |
| 409 | 419 |
| 410 int GainControlImpl::GetHandleError(void* handle) const { | 420 int GainControlImpl::GetHandleError(void* handle) const { |
| 411 // The AGC has no get_error() function. | 421 // The AGC has no get_error() function. |
| 412 // (Despite listing errors in its interface...) | 422 // (Despite listing errors in its interface...) |
| 413 assert(handle != NULL); | 423 assert(handle != NULL); |
| 414 return apm_->kUnspecifiedError; | 424 return apm_->kUnspecifiedError; |
| 415 } | 425 } |
| 416 } // namespace webrtc | 426 } // namespace webrtc |
| OLD | NEW |