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> | |
hlundin-webrtc
2017/01/18 13:08:48
memory already included in .h file.
peah-webrtc
2017/01/19 15:33:04
Done.
hlundin-webrtc
2017/01/20 09:31:44
No, not done. I meant that you should remove it fr
peah-webrtc
2017/01/23 14:16:39
Sorry.
Done.
| |
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" | |
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 explicit BlockProcessorImpl(int sample_rate_hz); |
29 BlockProcessorImpl(int sample_rate_hz, | |
30 std::unique_ptr<RenderDelayBuffer> render_buffer); | |
31 BlockProcessorImpl(int sample_rate_hz, | |
32 std::unique_ptr<RenderDelayBuffer> render_buffer, | |
33 std::unique_ptr<RenderDelayController> delay_controller, | |
34 std::unique_ptr<EchoRemover> echo_remover); | |
35 | |
22 ~BlockProcessorImpl() override; | 36 ~BlockProcessorImpl() override; |
23 | 37 |
24 void ProcessCapture(bool known_echo_path_change, | 38 void ProcessCapture(bool echo_path_gain_change, |
25 bool saturated_microphone_signal, | 39 bool capture_signal_saturation, |
26 std::vector<std::vector<float>>* capture_block) override; | 40 std::vector<std::vector<float>>* capture_block) override; |
27 | 41 |
28 bool BufferRender(std::vector<std::vector<float>>* block) override; | 42 bool BufferRender(std::vector<std::vector<float>>* block) override; |
29 | 43 |
30 void ReportEchoLeakage(bool leakage_detected) override; | 44 void UpdateEchoLeakageStatus(bool leakage_detected) override; |
31 | 45 |
32 private: | 46 private: |
33 const size_t sample_rate_hz_; | |
34 static int instance_count_; | 47 static int instance_count_; |
35 std::unique_ptr<ApmDataDumper> data_dumper_; | 48 std::unique_ptr<ApmDataDumper> data_dumper_; |
49 const size_t sample_rate_hz_; | |
50 std::unique_ptr<RenderDelayBuffer> render_buffer_; | |
51 std::unique_ptr<RenderDelayController> delay_controller_; | |
52 std::unique_ptr<EchoRemover> echo_remover_; | |
36 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BlockProcessorImpl); | 53 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BlockProcessorImpl); |
37 }; | 54 }; |
38 | 55 |
56 static const size_t kRenderBufferSize = 250; | |
39 int BlockProcessorImpl::instance_count_ = 0; | 57 int BlockProcessorImpl::instance_count_ = 0; |
58 constexpr size_t kMaxApiJitter = 30; | |
40 | 59 |
41 BlockProcessorImpl::BlockProcessorImpl(int sample_rate_hz) | 60 BlockProcessorImpl::BlockProcessorImpl(int sample_rate_hz) |
42 : sample_rate_hz_(sample_rate_hz), | 61 : data_dumper_( |
43 data_dumper_( | 62 new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))), |
hlundin-webrtc
2017/01/18 13:08:47
You only need one ctor (the one with 4 parameters)
peah-webrtc
2017/01/19 15:33:04
Good point! I needed to do some other changes as w
| |
44 new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))) {} | 63 sample_rate_hz_(sample_rate_hz), |
64 render_buffer_(RenderDelayBuffer::Create(kRenderBufferSize, | |
65 NumBandsForRate(sample_rate_hz_), | |
66 kMaxApiJitter)), | |
67 delay_controller_(RenderDelayController::Create(data_dumper_.get(), | |
68 sample_rate_hz, | |
69 *render_buffer_)), | |
70 echo_remover_(EchoRemover::Create(data_dumper_.get(), sample_rate_hz)) {} | |
71 | |
72 BlockProcessorImpl::BlockProcessorImpl( | |
73 int sample_rate_hz, | |
74 std::unique_ptr<RenderDelayBuffer> render_buffer) | |
75 : data_dumper_( | |
76 new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))), | |
77 sample_rate_hz_(sample_rate_hz), | |
78 render_buffer_(std::move(render_buffer)), | |
79 delay_controller_(RenderDelayController::Create(data_dumper_.get(), | |
80 sample_rate_hz, | |
81 *render_buffer_)), | |
82 echo_remover_(EchoRemover::Create(data_dumper_.get(), sample_rate_hz)) {} | |
83 | |
84 BlockProcessorImpl::BlockProcessorImpl( | |
85 int sample_rate_hz, | |
86 std::unique_ptr<RenderDelayBuffer> render_buffer, | |
87 std::unique_ptr<RenderDelayController> delay_controller, | |
88 std::unique_ptr<EchoRemover> echo_remover) | |
89 : data_dumper_( | |
90 new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))), | |
91 sample_rate_hz_(sample_rate_hz), | |
92 render_buffer_(std::move(render_buffer)), | |
93 delay_controller_(std::move(delay_controller)), | |
94 echo_remover_(std::move(echo_remover)) {} | |
45 | 95 |
46 BlockProcessorImpl::~BlockProcessorImpl() = default; | 96 BlockProcessorImpl::~BlockProcessorImpl() = default; |
47 | 97 |
48 void BlockProcessorImpl::ProcessCapture( | 98 void BlockProcessorImpl::ProcessCapture( |
49 bool known_echo_path_change, | 99 bool echo_path_gain_change, |
50 bool saturated_microphone_signal, | 100 bool capture_signal_saturation, |
51 std::vector<std::vector<float>>* capture_block) { | 101 std::vector<std::vector<float>>* capture_block) { |
52 RTC_DCHECK(capture_block); | 102 RTC_DCHECK(capture_block); |
53 RTC_DCHECK_EQ(NumBandsForRate(sample_rate_hz_), capture_block->size()); | 103 RTC_DCHECK_EQ(NumBandsForRate(sample_rate_hz_), capture_block->size()); |
54 RTC_DCHECK_EQ(kBlockSize, (*capture_block)[0].size()); | 104 RTC_DCHECK_EQ(kBlockSize, (*capture_block)[0].size()); |
105 | |
106 const size_t delay = delay_controller_->SelectDelay((*capture_block)[0]); | |
107 const bool render_delay_change = delay != render_buffer_->Delay(); | |
108 | |
109 if (render_delay_change) { | |
110 render_buffer_->SetDelay(delay); | |
111 } | |
112 | |
113 if (render_buffer_->IsBlockAvailable()) { | |
114 const std::vector<std::vector<float>>& render_block = | |
hlundin-webrtc
2017/01/18 13:08:47
auto
peah-webrtc
2017/01/19 15:33:04
Done.
| |
115 render_buffer_->GetNext(); | |
116 echo_remover_->ProcessBlock( | |
117 delay_controller_->AlignmentHeadroom(), | |
118 EchoPathVariability(echo_path_gain_change, render_delay_change), | |
119 capture_signal_saturation, render_block, capture_block); | |
120 } else { | |
121 LOG(LS_INFO) << "AEC3 empty render buffer"; | |
hlundin-webrtc
2017/01/18 13:08:48
Is this an error? When does it happen? Should we (
peah-webrtc
2017/01/19 15:33:04
I'm not sure how we should handle this. It is basi
hlundin-webrtc
2017/01/20 09:31:44
Sure.
peah-webrtc
2017/01/23 14:16:39
Acknowledged.
| |
122 } | |
55 } | 123 } |
56 | 124 |
57 bool BlockProcessorImpl::BufferRender( | 125 bool BlockProcessorImpl::BufferRender(std::vector<std::vector<float>>* block) { |
58 std::vector<std::vector<float>>* render_block) { | 126 RTC_DCHECK(block); |
59 RTC_DCHECK(render_block); | 127 RTC_DCHECK_EQ(NumBandsForRate(sample_rate_hz_), block->size()); |
60 RTC_DCHECK_EQ(NumBandsForRate(sample_rate_hz_), render_block->size()); | 128 RTC_DCHECK_EQ(kBlockSize, (*block)[0].size()); |
61 RTC_DCHECK_EQ(kBlockSize, (*render_block)[0].size()); | 129 |
130 bool overrun = !delay_controller_->AnalyzeRender((*block)[0]); | |
hlundin-webrtc
2017/01/18 13:08:47
I think this code would be easier to read if you s
peah-webrtc
2017/01/19 15:33:04
Good point! Agree I do.
Done.
| |
131 overrun = !render_buffer_->Insert(block) || overrun; | |
132 if (overrun) { | |
133 LOG(LS_INFO) << "AEC3 Buffer overrrun"; | |
hlundin-webrtc
2017/01/18 13:08:47
buffer
peah-webrtc
2017/01/19 15:33:04
Done.
| |
134 return true; | |
hlundin-webrtc
2017/01/18 13:08:48
I guess "true" means "overrun happened". But we us
peah-webrtc
2017/01/19 15:33:04
Makes sense. I did that change in some other place
| |
135 } | |
136 | |
62 return false; | 137 return false; |
63 } | 138 } |
64 | 139 |
65 void BlockProcessorImpl::ReportEchoLeakage(bool leakage_detected) {} | 140 void BlockProcessorImpl::UpdateEchoLeakageStatus(bool leakage_detected) { |
141 echo_remover_->UpdateEchoLeakageStatus(leakage_detected); | |
142 } | |
66 | 143 |
67 } // namespace | 144 } // namespace |
68 | 145 |
69 BlockProcessor* BlockProcessor::Create(int sample_rate_hz) { | 146 BlockProcessor* BlockProcessor::Create(int sample_rate_hz) { |
70 return new BlockProcessorImpl(sample_rate_hz); | 147 return new BlockProcessorImpl(sample_rate_hz); |
71 } | 148 } |
72 | 149 |
150 BlockProcessor* BlockProcessor::Create( | |
151 int sample_rate_hz, | |
152 std::unique_ptr<RenderDelayBuffer> render_buffer) { | |
153 return new BlockProcessorImpl(sample_rate_hz, std::move(render_buffer)); | |
154 } | |
155 | |
156 BlockProcessor* BlockProcessor::Create( | |
157 int sample_rate_hz, | |
158 std::unique_ptr<RenderDelayBuffer> render_buffer, | |
159 std::unique_ptr<RenderDelayController> delay_controller, | |
160 std::unique_ptr<EchoRemover> echo_remover) { | |
161 return new BlockProcessorImpl(sample_rate_hz, std::move(render_buffer), | |
162 std::move(delay_controller), | |
163 std::move(echo_remover)); | |
164 } | |
165 | |
73 } // namespace webrtc | 166 } // namespace webrtc |
OLD | NEW |