OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 #include "webrtc/modules/audio_processing/aec3/render_delay_controller.h" | 10 #include "webrtc/modules/audio_processing/aec3/render_delay_controller.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 void SetDelay(size_t render_delay) override; | 35 void SetDelay(size_t render_delay) override; |
36 size_t GetDelay(const DownsampledRenderBuffer& render_buffer, | 36 size_t GetDelay(const DownsampledRenderBuffer& render_buffer, |
37 rtc::ArrayView<const float> capture) override; | 37 rtc::ArrayView<const float> capture) override; |
38 rtc::Optional<size_t> AlignmentHeadroomSamples() const override { | 38 rtc::Optional<size_t> AlignmentHeadroomSamples() const override { |
39 return headroom_samples_; | 39 return headroom_samples_; |
40 } | 40 } |
41 | 41 |
42 private: | 42 private: |
43 static int instance_count_; | 43 static int instance_count_; |
44 std::unique_ptr<ApmDataDumper> data_dumper_; | 44 std::unique_ptr<ApmDataDumper> data_dumper_; |
45 size_t delay_ = 0; | 45 size_t delay_ = kMinEchoPathDelayBlocks; |
peah-webrtc
2017/09/11 12:31:42
This is a bit of an unrelated change, but I includ
| |
46 EchoPathDelayEstimator delay_estimator_; | 46 EchoPathDelayEstimator delay_estimator_; |
47 size_t blocks_since_last_delay_estimate_ = 300000; | 47 size_t blocks_since_last_delay_estimate_ = 300000; |
48 int echo_path_delay_samples_ = 0; | 48 int echo_path_delay_samples_ = kMinEchoPathDelayBlocks * kBlockSize; |
49 size_t align_call_counter_ = 0; | 49 size_t align_call_counter_ = 0; |
50 rtc::Optional<size_t> headroom_samples_; | 50 rtc::Optional<size_t> headroom_samples_; |
51 RenderDelayControllerMetrics metrics_; | 51 RenderDelayControllerMetrics metrics_; |
52 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderDelayControllerImpl); | 52 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderDelayControllerImpl); |
53 }; | 53 }; |
54 | 54 |
55 size_t ComputeNewBufferDelay(size_t current_delay, | 55 size_t ComputeNewBufferDelay(size_t current_delay, |
56 size_t echo_path_delay_samples) { | 56 size_t echo_path_delay_samples) { |
57 // The below division is not exact and the truncation is intended. | 57 // The below division is not exact and the truncation is intended. |
58 const int echo_path_delay_blocks = echo_path_delay_samples / kBlockSize; | 58 const int echo_path_delay_blocks = echo_path_delay_samples / kBlockSize; |
(...skipping 19 matching lines...) Expand all Loading... | |
78 new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))), | 78 new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))), |
79 delay_estimator_(data_dumper_.get(), config) { | 79 delay_estimator_(data_dumper_.get(), config) { |
80 RTC_DCHECK(ValidFullBandRate(sample_rate_hz)); | 80 RTC_DCHECK(ValidFullBandRate(sample_rate_hz)); |
81 } | 81 } |
82 | 82 |
83 RenderDelayControllerImpl::~RenderDelayControllerImpl() = default; | 83 RenderDelayControllerImpl::~RenderDelayControllerImpl() = default; |
84 | 84 |
85 void RenderDelayControllerImpl::Reset() { | 85 void RenderDelayControllerImpl::Reset() { |
86 delay_ = kMinEchoPathDelayBlocks; | 86 delay_ = kMinEchoPathDelayBlocks; |
87 blocks_since_last_delay_estimate_ = 300000; | 87 blocks_since_last_delay_estimate_ = 300000; |
88 echo_path_delay_samples_ = 0; | 88 echo_path_delay_samples_ = delay_ * kBlockSize; |
peah-webrtc
2017/09/11 12:31:42
This is a bit of an unrelated change, but since I
| |
89 align_call_counter_ = 0; | 89 align_call_counter_ = 0; |
90 headroom_samples_ = rtc::Optional<size_t>(); | 90 headroom_samples_ = rtc::Optional<size_t>(); |
91 | 91 |
92 delay_estimator_.Reset(); | 92 delay_estimator_.Reset(); |
93 } | 93 } |
94 | 94 |
95 void RenderDelayControllerImpl::SetDelay(size_t render_delay) { | 95 void RenderDelayControllerImpl::SetDelay(size_t render_delay) { |
96 if (delay_ != render_delay) { | 96 if (delay_ != render_delay) { |
97 // If a the delay set does not match the actual delay, reset the delay | 97 // If a the delay set does not match the actual delay, reset the delay |
98 // controller. | 98 // controller. |
(...skipping 18 matching lines...) Expand all Loading... | |
117 const size_t new_delay = | 117 const size_t new_delay = |
118 ComputeNewBufferDelay(delay_, echo_path_delay_samples_); | 118 ComputeNewBufferDelay(delay_, echo_path_delay_samples_); |
119 if (align_call_counter_ > kNumBlocksPerSecond) { | 119 if (align_call_counter_ > kNumBlocksPerSecond) { |
120 delay_ = new_delay; | 120 delay_ = new_delay; |
121 | 121 |
122 // Update render delay buffer headroom. | 122 // Update render delay buffer headroom. |
123 const int headroom = echo_path_delay_samples_ - delay_ * kBlockSize; | 123 const int headroom = echo_path_delay_samples_ - delay_ * kBlockSize; |
124 RTC_DCHECK_LE(0, headroom); | 124 RTC_DCHECK_LE(0, headroom); |
125 headroom_samples_ = rtc::Optional<size_t>(headroom); | 125 headroom_samples_ = rtc::Optional<size_t>(headroom); |
126 } | 126 } |
127 } else if (++blocks_since_last_delay_estimate_ > 20 * kNumBlocksPerSecond) { | |
128 headroom_samples_ = rtc::Optional<size_t>(); | |
129 } | 127 } |
130 | 128 |
131 metrics_.Update(echo_path_delay_samples, delay_); | 129 metrics_.Update(echo_path_delay_samples, delay_); |
132 | 130 |
133 data_dumper_->DumpRaw("aec3_render_delay_controller_delay", 1, | 131 data_dumper_->DumpRaw("aec3_render_delay_controller_delay", 1, |
134 &echo_path_delay_samples_); | 132 &echo_path_delay_samples_); |
135 data_dumper_->DumpRaw("aec3_render_delay_controller_buffer_delay", delay_); | 133 data_dumper_->DumpRaw("aec3_render_delay_controller_buffer_delay", delay_); |
136 | 134 |
137 return delay_; | 135 return delay_; |
138 } | 136 } |
139 | 137 |
140 } // namespace | 138 } // namespace |
141 | 139 |
142 RenderDelayController* RenderDelayController::Create( | 140 RenderDelayController* RenderDelayController::Create( |
143 const AudioProcessing::Config::EchoCanceller3& config, | 141 const AudioProcessing::Config::EchoCanceller3& config, |
144 int sample_rate_hz) { | 142 int sample_rate_hz) { |
145 return new RenderDelayControllerImpl(config, sample_rate_hz); | 143 return new RenderDelayControllerImpl(config, sample_rate_hz); |
146 } | 144 } |
147 | 145 |
148 } // namespace webrtc | 146 } // namespace webrtc |
OLD | NEW |