| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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/block_processor.h" | 10 #include "webrtc/modules/audio_processing/aec3/block_processor.h" |
| 11 | 11 |
| 12 #include "webrtc/base/atomicops.h" | 12 #include "webrtc/base/atomicops.h" |
| 13 #include "webrtc/base/constructormagic.h" | 13 #include "webrtc/base/constructormagic.h" |
| 14 #include "webrtc/base/optional.h" | 14 #include "webrtc/base/optional.h" |
| 15 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" | 15 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" |
| 16 #include "webrtc/modules/audio_processing/aec3/block_processor_metrics.h" |
| 16 #include "webrtc/modules/audio_processing/aec3/echo_path_variability.h" | 17 #include "webrtc/modules/audio_processing/aec3/echo_path_variability.h" |
| 17 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | 18 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" |
| 18 #include "webrtc/system_wrappers/include/logging.h" | |
| 19 | 19 |
| 20 namespace webrtc { | 20 namespace webrtc { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class BlockProcessorImpl final : public BlockProcessor { | 23 class BlockProcessorImpl final : public BlockProcessor { |
| 24 public: | 24 public: |
| 25 BlockProcessorImpl(int sample_rate_hz, | 25 BlockProcessorImpl(int sample_rate_hz, |
| 26 std::unique_ptr<RenderDelayBuffer> render_buffer, | 26 std::unique_ptr<RenderDelayBuffer> render_buffer, |
| 27 std::unique_ptr<RenderDelayController> delay_controller, | 27 std::unique_ptr<RenderDelayController> delay_controller, |
| 28 std::unique_ptr<EchoRemover> echo_remover); | 28 std::unique_ptr<EchoRemover> echo_remover); |
| 29 | 29 |
| 30 ~BlockProcessorImpl() override; | 30 ~BlockProcessorImpl() override; |
| 31 | 31 |
| 32 void ProcessCapture(bool echo_path_gain_change, | 32 void ProcessCapture(bool echo_path_gain_change, |
| 33 bool capture_signal_saturation, | 33 bool capture_signal_saturation, |
| 34 std::vector<std::vector<float>>* capture_block) override; | 34 std::vector<std::vector<float>>* capture_block) override; |
| 35 | 35 |
| 36 bool BufferRender(std::vector<std::vector<float>>* block) override; | 36 bool BufferRender(std::vector<std::vector<float>>* block) override; |
| 37 | 37 |
| 38 void UpdateEchoLeakageStatus(bool leakage_detected) override; | 38 void UpdateEchoLeakageStatus(bool leakage_detected) override; |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 static int instance_count_; | 41 static int instance_count_; |
| 42 std::unique_ptr<ApmDataDumper> data_dumper_; | 42 std::unique_ptr<ApmDataDumper> data_dumper_; |
| 43 const size_t sample_rate_hz_; | 43 const size_t sample_rate_hz_; |
| 44 std::unique_ptr<RenderDelayBuffer> render_buffer_; | 44 std::unique_ptr<RenderDelayBuffer> render_buffer_; |
| 45 std::unique_ptr<RenderDelayController> delay_controller_; | 45 std::unique_ptr<RenderDelayController> delay_controller_; |
| 46 std::unique_ptr<EchoRemover> echo_remover_; | 46 std::unique_ptr<EchoRemover> echo_remover_; |
| 47 BlockProcessorMetrics metrics_; |
| 47 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BlockProcessorImpl); | 48 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BlockProcessorImpl); |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 constexpr size_t kRenderBufferSize = 250; | 51 constexpr size_t kRenderBufferSize = 250; |
| 51 int BlockProcessorImpl::instance_count_ = 0; | 52 int BlockProcessorImpl::instance_count_ = 0; |
| 52 constexpr size_t kMaxApiJitter = 30; | 53 constexpr size_t kMaxApiJitter = 30; |
| 53 | 54 |
| 54 BlockProcessorImpl::BlockProcessorImpl( | 55 BlockProcessorImpl::BlockProcessorImpl( |
| 55 int sample_rate_hz, | 56 int sample_rate_hz, |
| 56 std::unique_ptr<RenderDelayBuffer> render_buffer, | 57 std::unique_ptr<RenderDelayBuffer> render_buffer, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 81 if (render_delay_change) { | 82 if (render_delay_change) { |
| 82 render_buffer_->SetDelay(delay); | 83 render_buffer_->SetDelay(delay); |
| 83 } | 84 } |
| 84 | 85 |
| 85 if (render_buffer_->IsBlockAvailable()) { | 86 if (render_buffer_->IsBlockAvailable()) { |
| 86 auto& render_block = render_buffer_->GetNext(); | 87 auto& render_block = render_buffer_->GetNext(); |
| 87 echo_remover_->ProcessBlock( | 88 echo_remover_->ProcessBlock( |
| 88 delay_controller_->AlignmentHeadroomSamples(), | 89 delay_controller_->AlignmentHeadroomSamples(), |
| 89 EchoPathVariability(echo_path_gain_change, render_delay_change), | 90 EchoPathVariability(echo_path_gain_change, render_delay_change), |
| 90 capture_signal_saturation, render_block, capture_block); | 91 capture_signal_saturation, render_block, capture_block); |
| 92 metrics_.UpdateCapture(false); |
| 91 } else { | 93 } else { |
| 92 LOG(LS_INFO) << "AEC3 empty render buffer"; | 94 metrics_.UpdateCapture(true); |
| 93 } | 95 } |
| 94 } | 96 } |
| 95 | 97 |
| 96 bool BlockProcessorImpl::BufferRender(std::vector<std::vector<float>>* block) { | 98 bool BlockProcessorImpl::BufferRender(std::vector<std::vector<float>>* block) { |
| 97 RTC_DCHECK(block); | 99 RTC_DCHECK(block); |
| 98 RTC_DCHECK_EQ(NumBandsForRate(sample_rate_hz_), block->size()); | 100 RTC_DCHECK_EQ(NumBandsForRate(sample_rate_hz_), block->size()); |
| 99 RTC_DCHECK_EQ(kBlockSize, (*block)[0].size()); | 101 RTC_DCHECK_EQ(kBlockSize, (*block)[0].size()); |
| 100 | 102 |
| 101 const bool delay_controller_overrun = | 103 const bool delay_controller_overrun = |
| 102 !delay_controller_->AnalyzeRender((*block)[0]); | 104 !delay_controller_->AnalyzeRender((*block)[0]); |
| 103 const bool render_buffer_overrun = !render_buffer_->Insert(block); | 105 const bool render_buffer_overrun = !render_buffer_->Insert(block); |
| 104 if (delay_controller_overrun || render_buffer_overrun) { | 106 if (delay_controller_overrun || render_buffer_overrun) { |
| 105 LOG(LS_INFO) << "AEC3 buffer overrrun"; | 107 metrics_.UpdateRender(true); |
| 106 return false; | 108 return false; |
| 107 } | 109 } |
| 108 | 110 metrics_.UpdateRender(false); |
| 109 return true; | 111 return true; |
| 110 } | 112 } |
| 111 | 113 |
| 112 void BlockProcessorImpl::UpdateEchoLeakageStatus(bool leakage_detected) { | 114 void BlockProcessorImpl::UpdateEchoLeakageStatus(bool leakage_detected) { |
| 113 echo_remover_->UpdateEchoLeakageStatus(leakage_detected); | 115 echo_remover_->UpdateEchoLeakageStatus(leakage_detected); |
| 114 } | 116 } |
| 115 | 117 |
| 116 } // namespace | 118 } // namespace |
| 117 | 119 |
| 118 BlockProcessor* BlockProcessor::Create(int sample_rate_hz) { | 120 BlockProcessor* BlockProcessor::Create(int sample_rate_hz) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 141 int sample_rate_hz, | 143 int sample_rate_hz, |
| 142 std::unique_ptr<RenderDelayBuffer> render_buffer, | 144 std::unique_ptr<RenderDelayBuffer> render_buffer, |
| 143 std::unique_ptr<RenderDelayController> delay_controller, | 145 std::unique_ptr<RenderDelayController> delay_controller, |
| 144 std::unique_ptr<EchoRemover> echo_remover) { | 146 std::unique_ptr<EchoRemover> echo_remover) { |
| 145 return new BlockProcessorImpl(sample_rate_hz, std::move(render_buffer), | 147 return new BlockProcessorImpl(sample_rate_hz, std::move(render_buffer), |
| 146 std::move(delay_controller), | 148 std::move(delay_controller), |
| 147 std::move(echo_remover)); | 149 std::move(echo_remover)); |
| 148 } | 150 } |
| 149 | 151 |
| 150 } // namespace webrtc | 152 } // namespace webrtc |
| OLD | NEW |