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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 size_t ComputeNewBufferDelay(size_t current_delay, | 52 size_t ComputeNewBufferDelay(size_t current_delay, |
53 size_t echo_path_delay_samples) { | 53 size_t echo_path_delay_samples) { |
54 // The below division is not exact and the truncation is intended. | 54 // The below division is not exact and the truncation is intended. |
55 const int echo_path_delay_blocks = echo_path_delay_samples / kBlockSize; | 55 const int echo_path_delay_blocks = echo_path_delay_samples / kBlockSize; |
56 constexpr int kDelayHeadroomBlocks = 1; | 56 constexpr int kDelayHeadroomBlocks = 1; |
57 | 57 |
58 // Compute the buffer delay increase required to achieve the desired latency. | 58 // Compute the buffer delay increase required to achieve the desired latency. |
59 size_t new_delay = std::max(echo_path_delay_blocks - kDelayHeadroomBlocks, 0); | 59 size_t new_delay = std::max(echo_path_delay_blocks - kDelayHeadroomBlocks, 0); |
60 | 60 |
61 // Add hysteresis. | 61 // Add hysteresis. |
62 if (new_delay == current_delay + 1 || new_delay + 1 == current_delay) { | 62 if (new_delay == current_delay + 1) { |
63 new_delay = current_delay; | 63 new_delay = current_delay; |
64 } | 64 } |
65 | 65 |
66 return new_delay; | 66 return new_delay; |
67 } | 67 } |
68 | 68 |
69 int RenderDelayControllerImpl::instance_count_ = 0; | 69 int RenderDelayControllerImpl::instance_count_ = 0; |
70 | 70 |
71 RenderDelayControllerImpl::RenderDelayControllerImpl(int sample_rate_hz) | 71 RenderDelayControllerImpl::RenderDelayControllerImpl(int sample_rate_hz) |
72 : data_dumper_( | 72 : data_dumper_( |
73 new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))), | 73 new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))), |
74 delay_estimator_(data_dumper_.get()) { | 74 delay_estimator_(data_dumper_.get()) { |
75 RTC_DCHECK(ValidFullBandRate(sample_rate_hz)); | 75 RTC_DCHECK(ValidFullBandRate(sample_rate_hz)); |
76 } | 76 } |
77 | 77 |
78 RenderDelayControllerImpl::~RenderDelayControllerImpl() = default; | 78 RenderDelayControllerImpl::~RenderDelayControllerImpl() = default; |
79 | 79 |
80 void RenderDelayControllerImpl::Reset() { | 80 void RenderDelayControllerImpl::Reset() { |
81 delay_ = 0; | 81 delay_ = kMinEchoPathDelayBlocks; |
82 blocks_since_last_delay_estimate_ = 300000; | 82 blocks_since_last_delay_estimate_ = 300000; |
83 echo_path_delay_samples_ = 0; | 83 echo_path_delay_samples_ = 0; |
84 align_call_counter_ = 0; | 84 align_call_counter_ = 0; |
85 headroom_samples_ = rtc::Optional<size_t>(); | 85 headroom_samples_ = rtc::Optional<size_t>(); |
86 | 86 |
87 delay_estimator_.Reset(); | 87 delay_estimator_.Reset(); |
88 } | 88 } |
89 | 89 |
90 void RenderDelayControllerImpl::SetDelay(size_t render_delay) { | 90 void RenderDelayControllerImpl::SetDelay(size_t render_delay) { |
91 if (delay_ != render_delay) { | 91 if (delay_ != render_delay) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 return delay_; | 132 return delay_; |
133 } | 133 } |
134 | 134 |
135 } // namespace | 135 } // namespace |
136 | 136 |
137 RenderDelayController* RenderDelayController::Create(int sample_rate_hz) { | 137 RenderDelayController* RenderDelayController::Create(int sample_rate_hz) { |
138 return new RenderDelayControllerImpl(sample_rate_hz); | 138 return new RenderDelayControllerImpl(sample_rate_hz); |
139 } | 139 } |
140 | 140 |
141 } // namespace webrtc | 141 } // namespace webrtc |
OLD | NEW |