Chromium Code Reviews| 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 <memory> | |
| 13 | |
| 12 #include "webrtc/base/atomicops.h" | 14 #include "webrtc/base/atomicops.h" |
| 15 #include "webrtc/base/constructormagic.h" | |
| 13 #include "webrtc/base/optional.h" | 16 #include "webrtc/base/optional.h" |
| 14 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h" | 17 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h" |
| 18 #include "webrtc/modules/audio_processing/aec3/echo_path_variability.h" | |
| 19 #include "webrtc/modules/audio_processing/aec3/echo_remover.h" | |
|
aleloi
2017/01/20 14:45:37
echo_remover.h is also included in parent header.
peah-webrtc
2017/01/23 14:16:40
Done.
| |
| 20 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | |
| 21 #include "webrtc/system_wrappers/include/logging.h" | |
| 15 | 22 |
| 16 namespace webrtc { | 23 namespace webrtc { |
| 17 namespace { | 24 namespace { |
| 18 | 25 |
| 19 class BlockProcessorImpl final : public BlockProcessor { | 26 class BlockProcessorImpl final : public BlockProcessor { |
| 20 public: | 27 public: |
| 21 explicit BlockProcessorImpl(int sample_rate_hz); | 28 BlockProcessorImpl(int sample_rate_hz, |
| 29 std::unique_ptr<RenderDelayBuffer> render_buffer, | |
| 30 std::unique_ptr<RenderDelayController> delay_controller, | |
| 31 std::unique_ptr<EchoRemover> echo_remover); | |
| 32 | |
| 22 ~BlockProcessorImpl() override; | 33 ~BlockProcessorImpl() override; |
| 23 | 34 |
| 24 void ProcessCapture(bool known_echo_path_change, | 35 void ProcessCapture(bool echo_path_gain_change, |
| 25 bool saturated_microphone_signal, | 36 bool capture_signal_saturation, |
| 26 std::vector<std::vector<float>>* capture_block) override; | 37 std::vector<std::vector<float>>* capture_block) override; |
| 27 | 38 |
| 28 bool BufferRender(std::vector<std::vector<float>>* block) override; | 39 bool BufferRender(std::vector<std::vector<float>>* block) override; |
| 29 | 40 |
| 30 void ReportEchoLeakage(bool leakage_detected) override; | 41 void UpdateEchoLeakageStatus(bool leakage_detected) override; |
| 31 | 42 |
| 32 private: | 43 private: |
| 33 const size_t sample_rate_hz_; | |
| 34 static int instance_count_; | 44 static int instance_count_; |
| 35 std::unique_ptr<ApmDataDumper> data_dumper_; | 45 std::unique_ptr<ApmDataDumper> data_dumper_; |
| 46 const size_t sample_rate_hz_; | |
| 47 std::unique_ptr<RenderDelayBuffer> render_buffer_; | |
| 48 std::unique_ptr<RenderDelayController> delay_controller_; | |
| 49 std::unique_ptr<EchoRemover> echo_remover_; | |
| 36 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BlockProcessorImpl); | 50 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BlockProcessorImpl); |
| 37 }; | 51 }; |
| 38 | 52 |
| 53 static const size_t kRenderBufferSize = 250; | |
| 39 int BlockProcessorImpl::instance_count_ = 0; | 54 int BlockProcessorImpl::instance_count_ = 0; |
| 55 constexpr size_t kMaxApiJitter = 30; | |
|
aleloi
2017/01/20 14:45:37
I think kRenderBufferSize and kMaxApiJitter should
peah-webrtc
2017/01/23 14:16:40
I agree.
Done.
| |
| 40 | 56 |
| 41 BlockProcessorImpl::BlockProcessorImpl(int sample_rate_hz) | 57 BlockProcessorImpl::BlockProcessorImpl( |
| 42 : sample_rate_hz_(sample_rate_hz), | 58 int sample_rate_hz, |
| 43 data_dumper_( | 59 std::unique_ptr<RenderDelayBuffer> render_buffer, |
| 44 new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))) {} | 60 std::unique_ptr<RenderDelayController> delay_controller, |
| 61 std::unique_ptr<EchoRemover> echo_remover) | |
| 62 : data_dumper_( | |
| 63 new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))), | |
| 64 sample_rate_hz_(sample_rate_hz), | |
| 65 render_buffer_(std::move(render_buffer)), | |
| 66 delay_controller_(std::move(delay_controller)), | |
| 67 echo_remover_(std::move(echo_remover)) {} | |
| 45 | 68 |
| 46 BlockProcessorImpl::~BlockProcessorImpl() = default; | 69 BlockProcessorImpl::~BlockProcessorImpl() = default; |
| 47 | 70 |
| 48 void BlockProcessorImpl::ProcessCapture( | 71 void BlockProcessorImpl::ProcessCapture( |
| 49 bool known_echo_path_change, | 72 bool echo_path_gain_change, |
| 50 bool saturated_microphone_signal, | 73 bool capture_signal_saturation, |
| 51 std::vector<std::vector<float>>* capture_block) { | 74 std::vector<std::vector<float>>* capture_block) { |
| 52 RTC_DCHECK(capture_block); | 75 RTC_DCHECK(capture_block); |
| 53 RTC_DCHECK_EQ(NumBandsForRate(sample_rate_hz_), capture_block->size()); | 76 RTC_DCHECK_EQ(NumBandsForRate(sample_rate_hz_), capture_block->size()); |
| 54 RTC_DCHECK_EQ(kBlockSize, (*capture_block)[0].size()); | 77 RTC_DCHECK_EQ(kBlockSize, (*capture_block)[0].size()); |
| 78 | |
| 79 const size_t delay = delay_controller_->GetDelay((*capture_block)[0]); | |
| 80 const bool render_delay_change = delay != render_buffer_->Delay(); | |
| 81 | |
| 82 if (render_delay_change) { | |
| 83 render_buffer_->SetDelay(delay); | |
| 84 } | |
| 85 | |
| 86 if (render_buffer_->IsBlockAvailable()) { | |
| 87 auto& render_block = render_buffer_->GetNext(); | |
| 88 echo_remover_->ProcessBlock( | |
| 89 delay_controller_->AlignmentHeadroom(), | |
| 90 EchoPathVariability(echo_path_gain_change, render_delay_change), | |
| 91 capture_signal_saturation, render_block, capture_block); | |
| 92 } else { | |
| 93 LOG(LS_INFO) << "AEC3 empty render buffer"; | |
| 94 } | |
| 55 } | 95 } |
| 56 | 96 |
| 57 bool BlockProcessorImpl::BufferRender( | 97 bool BlockProcessorImpl::BufferRender(std::vector<std::vector<float>>* block) { |
| 58 std::vector<std::vector<float>>* render_block) { | 98 RTC_DCHECK(block); |
| 59 RTC_DCHECK(render_block); | 99 RTC_DCHECK_EQ(NumBandsForRate(sample_rate_hz_), block->size()); |
| 60 RTC_DCHECK_EQ(NumBandsForRate(sample_rate_hz_), render_block->size()); | 100 RTC_DCHECK_EQ(kBlockSize, (*block)[0].size()); |
| 61 RTC_DCHECK_EQ(kBlockSize, (*render_block)[0].size()); | 101 |
| 62 return false; | 102 const bool delay_controller_overrun = |
| 103 !delay_controller_->AnalyzeRender((*block)[0]); | |
| 104 const bool render_buffer_overrun = !render_buffer_->Insert(block); | |
| 105 if (delay_controller_overrun || render_buffer_overrun) { | |
| 106 LOG(LS_INFO) << "AEC3 buffer overrrun"; | |
| 107 return false; | |
| 108 } | |
| 109 | |
| 110 return true; | |
| 63 } | 111 } |
| 64 | 112 |
| 65 void BlockProcessorImpl::ReportEchoLeakage(bool leakage_detected) {} | 113 void BlockProcessorImpl::UpdateEchoLeakageStatus(bool leakage_detected) { |
| 114 echo_remover_->UpdateEchoLeakageStatus(leakage_detected); | |
| 115 } | |
| 66 | 116 |
| 67 } // namespace | 117 } // namespace |
| 68 | 118 |
| 69 BlockProcessor* BlockProcessor::Create(int sample_rate_hz) { | 119 BlockProcessor* BlockProcessor::Create(int sample_rate_hz) { |
|
aleloi
2017/01/20 14:45:37
I think keeping the number of 'new' low is a good
peah-webrtc
2017/01/23 14:16:40
Good point!
Done.
| |
| 70 return new BlockProcessorImpl(sample_rate_hz); | 120 std::unique_ptr<RenderDelayBuffer> render_buffer(RenderDelayBuffer::Create( |
| 121 kRenderBufferSize, NumBandsForRate(sample_rate_hz), kMaxApiJitter)); | |
| 122 std::unique_ptr<RenderDelayController> delay_controller( | |
| 123 RenderDelayController::Create(sample_rate_hz, *render_buffer)); | |
| 124 std::unique_ptr<EchoRemover> echo_remover( | |
| 125 EchoRemover::Create(sample_rate_hz)); | |
| 126 return new BlockProcessorImpl(sample_rate_hz, std::move(render_buffer), | |
| 127 std::move(delay_controller), | |
| 128 std::move(echo_remover)); | |
| 129 } | |
| 130 | |
| 131 BlockProcessor* BlockProcessor::Create( | |
|
aleloi
2017/01/20 14:45:37
Same here.
peah-webrtc
2017/01/23 14:16:40
Done.
| |
| 132 int sample_rate_hz, | |
| 133 std::unique_ptr<RenderDelayBuffer> render_buffer) { | |
| 134 std::unique_ptr<RenderDelayController> delay_controller( | |
| 135 RenderDelayController::Create(sample_rate_hz, *render_buffer)); | |
| 136 std::unique_ptr<EchoRemover> echo_remover( | |
| 137 EchoRemover::Create(sample_rate_hz)); | |
| 138 return new BlockProcessorImpl(sample_rate_hz, std::move(render_buffer), | |
| 139 std::move(delay_controller), | |
| 140 std::move(echo_remover)); | |
| 141 } | |
| 142 | |
| 143 BlockProcessor* BlockProcessor::Create( | |
| 144 int sample_rate_hz, | |
| 145 std::unique_ptr<RenderDelayBuffer> render_buffer, | |
| 146 std::unique_ptr<RenderDelayController> delay_controller, | |
| 147 std::unique_ptr<EchoRemover> echo_remover) { | |
| 148 return new BlockProcessorImpl(sample_rate_hz, std::move(render_buffer), | |
| 149 std::move(delay_controller), | |
| 150 std::move(echo_remover)); | |
| 71 } | 151 } |
| 72 | 152 |
| 73 } // namespace webrtc | 153 } // namespace webrtc |
| OLD | NEW |