| 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" |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "webrtc/base/atomicops.h" | 17 #include "webrtc/base/atomicops.h" |
| 18 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
| 19 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" | 19 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" |
| 20 #include "webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h" | 20 #include "webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h" |
| 21 #include "webrtc/system_wrappers/include/logging.h" | 21 #include "webrtc/modules/audio_processing/aec3/render_delay_controller_metrics.h
" |
| 22 | 22 |
| 23 namespace webrtc { | 23 namespace webrtc { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 class RenderBuffer { | 27 class RenderBuffer { |
| 28 public: | 28 public: |
| 29 explicit RenderBuffer(size_t size) | 29 explicit RenderBuffer(size_t size) |
| 30 : buffer_(size, std::vector<float>(kBlockSize, 0.f)) {} | 30 : buffer_(size, std::vector<float>(kBlockSize, 0.f)) {} |
| 31 ~RenderBuffer() = default; | 31 ~RenderBuffer() = default; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 static int instance_count_; | 74 static int instance_count_; |
| 75 std::unique_ptr<ApmDataDumper> data_dumper_; | 75 std::unique_ptr<ApmDataDumper> data_dumper_; |
| 76 const size_t max_delay_; | 76 const size_t max_delay_; |
| 77 size_t delay_; | 77 size_t delay_; |
| 78 RenderBuffer render_buffer_; | 78 RenderBuffer render_buffer_; |
| 79 EchoPathDelayEstimator delay_estimator_; | 79 EchoPathDelayEstimator delay_estimator_; |
| 80 size_t blocks_since_last_delay_estimate_ = 300000; | 80 size_t blocks_since_last_delay_estimate_ = 300000; |
| 81 int echo_path_delay_samples_ = 0; | 81 int echo_path_delay_samples_ = 0; |
| 82 size_t align_call_counter_ = 0; | 82 size_t align_call_counter_ = 0; |
| 83 rtc::Optional<size_t> headroom_samples_; | 83 rtc::Optional<size_t> headroom_samples_; |
| 84 RenderDelayControllerMetrics metrics_; |
| 84 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderDelayControllerImpl); | 85 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderDelayControllerImpl); |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 size_t ComputeNewBufferDelay(size_t current_delay, | 88 size_t ComputeNewBufferDelay(size_t current_delay, |
| 88 size_t max_delay, | 89 size_t max_delay, |
| 89 size_t echo_path_delay_samples) { | 90 size_t echo_path_delay_samples) { |
| 90 // The below division is not exact and the truncation is intended. | 91 // The below division is not exact and the truncation is intended. |
| 91 const int echo_path_delay_blocks = echo_path_delay_samples / kBlockSize; | 92 const int echo_path_delay_blocks = echo_path_delay_samples / kBlockSize; |
| 92 constexpr int kDelayHeadroomBlocks = 1; | 93 constexpr int kDelayHeadroomBlocks = 1; |
| 93 | 94 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 145 |
| 145 // Update render delay buffer headroom. | 146 // Update render delay buffer headroom. |
| 146 blocks_since_last_delay_estimate_ = 0; | 147 blocks_since_last_delay_estimate_ = 0; |
| 147 const int headroom = echo_path_delay_samples_ - delay_ * kBlockSize; | 148 const int headroom = echo_path_delay_samples_ - delay_ * kBlockSize; |
| 148 RTC_DCHECK_LE(0, headroom); | 149 RTC_DCHECK_LE(0, headroom); |
| 149 headroom_samples_ = rtc::Optional<size_t>(headroom); | 150 headroom_samples_ = rtc::Optional<size_t>(headroom); |
| 150 } else if (++blocks_since_last_delay_estimate_ > 250 * 20) { | 151 } else if (++blocks_since_last_delay_estimate_ > 250 * 20) { |
| 151 headroom_samples_ = rtc::Optional<size_t>(); | 152 headroom_samples_ = rtc::Optional<size_t>(); |
| 152 } | 153 } |
| 153 | 154 |
| 155 metrics_.Update(echo_path_delay_samples, delay_); |
| 156 |
| 154 data_dumper_->DumpRaw("aec3_render_delay_controller_delay", 1, | 157 data_dumper_->DumpRaw("aec3_render_delay_controller_delay", 1, |
| 155 &echo_path_delay_samples_); | 158 &echo_path_delay_samples_); |
| 156 data_dumper_->DumpRaw("aec3_render_delay_controller_buffer_delay", delay_); | 159 data_dumper_->DumpRaw("aec3_render_delay_controller_buffer_delay", delay_); |
| 157 | 160 |
| 158 return delay_; | 161 return delay_; |
| 159 } | 162 } |
| 160 | 163 |
| 161 bool RenderDelayControllerImpl::AnalyzeRender( | 164 bool RenderDelayControllerImpl::AnalyzeRender( |
| 162 rtc::ArrayView<const float> render) { | 165 rtc::ArrayView<const float> render) { |
| 163 return render_buffer_.Insert(render); | 166 return render_buffer_.Insert(render); |
| 164 } | 167 } |
| 165 | 168 |
| 166 } // namespace | 169 } // namespace |
| 167 | 170 |
| 168 RenderDelayController* RenderDelayController::Create( | 171 RenderDelayController* RenderDelayController::Create( |
| 169 int sample_rate_hz, | 172 int sample_rate_hz, |
| 170 const RenderDelayBuffer& render_delay_buffer) { | 173 const RenderDelayBuffer& render_delay_buffer) { |
| 171 return new RenderDelayControllerImpl(sample_rate_hz, render_delay_buffer); | 174 return new RenderDelayControllerImpl(sample_rate_hz, render_delay_buffer); |
| 172 } | 175 } |
| 173 | 176 |
| 174 } // namespace webrtc | 177 } // namespace webrtc |
| OLD | NEW |