Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: webrtc/modules/audio_processing/test/debug_dump_replayer.cc

Issue 1810463002: Adding DebugDumpReplayer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: actual change Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/audio_processing/test/debug_dump_replayer.h"
12
13 #include "webrtc/base/checks.h"
14 #include "webrtc/modules/audio_processing/test/protobuf_utils.h"
15
16
17 namespace webrtc {
18 namespace test {
19
20 namespace {
21
22 void MaybeResetBuffer(std::unique_ptr<ChannelBuffer<float>>* buffer,
23 const StreamConfig& config) {
24 auto& buffer_ref = *buffer;
25 if (!buffer_ref.get() || buffer_ref->num_frames() != config.num_frames() ||
26 buffer_ref->num_channels() != config.num_channels()) {
27 buffer_ref.reset(new ChannelBuffer<float>(config.num_frames(),
28 config.num_channels()));
29 }
30 }
31
32 } // namespace
33
34 DebugDumpReplayer::DebugDumpReplayer()
35 : input_(nullptr), // will be created upon usage.
36 reverse_(nullptr),
37 output_(nullptr),
38 apm_(nullptr),
39 debug_file_(nullptr) {}
40
41 DebugDumpReplayer::~DebugDumpReplayer() {
42 if (debug_file_)
43 fclose(debug_file_);
44 }
45
46 bool DebugDumpReplayer::SetDumpFile(const std::string& filename) {
47 debug_file_ = fopen(filename.c_str(), "rb");
48 LoadNextMessage();
49 return debug_file_;
50 }
51
52 // Get next event that has not run.
53 rtc::Optional<audioproc::Event> DebugDumpReplayer::GetNextEvent() const {
54 if (!has_next_event_)
55 return rtc::Optional<audioproc::Event>();
56 else
57 return rtc::Optional<audioproc::Event>(next_event_);
58 }
59
60 // Run the next event. Returns the event type.
61 bool DebugDumpReplayer::RunNextEvent() {
62 if (!has_next_event_)
63 return false;
64 switch (next_event_.type()) {
65 case audioproc::Event::INIT:
66 OnInitEvent(next_event_.init());
67 break;
68 case audioproc::Event::STREAM:
69 OnStreamEvent(next_event_.stream());
70 break;
71 case audioproc::Event::REVERSE_STREAM:
72 OnReverseStreamEvent(next_event_.reverse_stream());
73 break;
74 case audioproc::Event::CONFIG:
75 OnConfigEvent(next_event_.config());
76 break;
77 case audioproc::Event::UNKNOWN_EVENT:
78 // We do not expect receive UNKNOWN event.
hlundin-webrtc 2016/03/16 13:30:07 expect to receive
79 return false;
80 }
81 LoadNextMessage();
82 return true;
83 }
84
85 const ChannelBuffer<float>* DebugDumpReplayer::GetOutput() const {
86 return output_.get();
87 }
88
89 StreamConfig DebugDumpReplayer::GetOutputConfig() const {
90 return output_config_;
91 }
92
93 // OnInitEvent reset the input/output/reserve channel format.
94 void DebugDumpReplayer::OnInitEvent(const audioproc::Init& msg) {
95 RTC_CHECK(msg.has_num_input_channels());
96 RTC_CHECK(msg.has_output_sample_rate());
97 RTC_CHECK(msg.has_num_output_channels());
98 RTC_CHECK(msg.has_reverse_sample_rate());
99 RTC_CHECK(msg.has_num_reverse_channels());
100
101 input_config_ = StreamConfig(msg.sample_rate(), msg.num_input_channels());
102 output_config_ =
103 StreamConfig(msg.output_sample_rate(), msg.num_output_channels());
104 reverse_config_ =
105 StreamConfig(msg.reverse_sample_rate(), msg.num_reverse_channels());
106
107 MaybeResetBuffer(&input_, input_config_);
108 MaybeResetBuffer(&output_, output_config_);
109 MaybeResetBuffer(&reverse_, reverse_config_);
110 }
111
112 // OnStreamEvent replays an input signal and verifies the output.
113 void DebugDumpReplayer::OnStreamEvent(const audioproc::Stream& msg) {
114 // APM should have been created.
115 RTC_CHECK(apm_.get());
116
117 RTC_CHECK_EQ(AudioProcessing::kNoError,
118 apm_->gain_control()->set_stream_analog_level(msg.level()));
119 RTC_CHECK_EQ(AudioProcessing::kNoError,
120 apm_->set_stream_delay_ms(msg.delay()));
121
122 apm_->echo_cancellation()->set_stream_drift_samples(msg.drift());
123 if (msg.has_keypress()) {
124 apm_->set_stream_key_pressed(msg.keypress());
125 } else {
126 apm_->set_stream_key_pressed(true);
127 }
128
129 RTC_CHECK_EQ(input_config_.num_channels(),
130 static_cast<size_t>(msg.input_channel_size()));
131 RTC_CHECK_EQ(input_config_.num_frames() * sizeof(float),
132 msg.input_channel(0).size());
133
134 for (int i = 0; i < msg.input_channel_size(); ++i) {
135 memcpy(input_->channels()[i], msg.input_channel(i).data(),
136 msg.input_channel(i).size());
137 }
138
139 RTC_CHECK_EQ(AudioProcessing::kNoError,
140 apm_->ProcessStream(input_->channels(), input_config_,
141 output_config_, output_->channels()));
142 }
143
144 void DebugDumpReplayer::OnReverseStreamEvent(
145 const audioproc::ReverseStream& msg) {
146 // APM should have been created.
147 RTC_CHECK(apm_.get());
148
149 RTC_CHECK_GT(msg.channel_size(), 0);
150 RTC_CHECK_EQ(reverse_config_.num_channels(),
151 static_cast<size_t>(msg.channel_size()));
152 RTC_CHECK_EQ(reverse_config_.num_frames() * sizeof(float),
153 msg.channel(0).size());
154
155 for (int i = 0; i < msg.channel_size(); ++i) {
156 memcpy(reverse_->channels()[i], msg.channel(i).data(),
157 msg.channel(i).size());
158 }
159
160 RTC_CHECK_EQ(
161 AudioProcessing::kNoError,
162 apm_->ProcessReverseStream(reverse_->channels(), reverse_config_,
163 reverse_config_, reverse_->channels()));
164 }
165
166 void DebugDumpReplayer::OnConfigEvent(const audioproc::Config& msg) {
167 MaybeRecreateApm(msg);
168 ConfigureApm(msg);
169 }
170
171 void DebugDumpReplayer::MaybeRecreateApm(const audioproc::Config& msg) {
172 // These configurations cannot be changed on the fly.
173 Config config;
174 RTC_CHECK(msg.has_aec_delay_agnostic_enabled());
175 config.Set<DelayAgnostic>(
176 new DelayAgnostic(msg.aec_delay_agnostic_enabled()));
177
178 RTC_CHECK(msg.has_noise_robust_agc_enabled());
179 config.Set<ExperimentalAgc>(
180 new ExperimentalAgc(msg.noise_robust_agc_enabled()));
181
182 RTC_CHECK(msg.has_transient_suppression_enabled());
183 config.Set<ExperimentalNs>(
184 new ExperimentalNs(msg.transient_suppression_enabled()));
185
186 RTC_CHECK(msg.has_aec_extended_filter_enabled());
187 config.Set<ExtendedFilter>(
188 new ExtendedFilter(msg.aec_extended_filter_enabled()));
189
190 // We only create APM once, since changes on these fields should not
191 // happen in current implementation.
192 if (!apm_.get()) {
193 apm_.reset(AudioProcessing::Create(config));
194 }
195 }
196
197 void DebugDumpReplayer::ConfigureApm(const audioproc::Config& msg) {
198 // AEC configs.
199 RTC_CHECK(msg.has_aec_enabled());
200 RTC_CHECK_EQ(AudioProcessing::kNoError,
201 apm_->echo_cancellation()->Enable(msg.aec_enabled()));
202
203 RTC_CHECK(msg.has_aec_drift_compensation_enabled());
204 RTC_CHECK_EQ(AudioProcessing::kNoError,
205 apm_->echo_cancellation()->enable_drift_compensation(
206 msg.aec_drift_compensation_enabled()));
207
208 RTC_CHECK(msg.has_aec_suppression_level());
209 RTC_CHECK_EQ(AudioProcessing::kNoError,
210 apm_->echo_cancellation()->set_suppression_level(
211 static_cast<EchoCancellation::SuppressionLevel>(
212 msg.aec_suppression_level())));
213
214 // AECM configs.
215 RTC_CHECK(msg.has_aecm_enabled());
216 RTC_CHECK_EQ(AudioProcessing::kNoError,
217 apm_->echo_control_mobile()->Enable(msg.aecm_enabled()));
218
219 RTC_CHECK(msg.has_aecm_comfort_noise_enabled());
220 RTC_CHECK_EQ(AudioProcessing::kNoError,
221 apm_->echo_control_mobile()->enable_comfort_noise(
222 msg.aecm_comfort_noise_enabled()));
223
224 RTC_CHECK(msg.has_aecm_routing_mode());
225 RTC_CHECK_EQ(AudioProcessing::kNoError,
226 apm_->echo_control_mobile()->set_routing_mode(
227 static_cast<EchoControlMobile::RoutingMode>(
228 msg.aecm_routing_mode())));
229
230 // AGC configs.
231 RTC_CHECK(msg.has_agc_enabled());
232 RTC_CHECK_EQ(AudioProcessing::kNoError,
233 apm_->gain_control()->Enable(msg.agc_enabled()));
234
235 RTC_CHECK(msg.has_agc_mode());
236 RTC_CHECK_EQ(AudioProcessing::kNoError,
237 apm_->gain_control()->set_mode(
238 static_cast<GainControl::Mode>(msg.agc_mode())));
239
240 RTC_CHECK(msg.has_agc_limiter_enabled());
241 RTC_CHECK_EQ(AudioProcessing::kNoError,
242 apm_->gain_control()->enable_limiter(msg.agc_limiter_enabled()));
243
244 // HPF configs.
245 RTC_CHECK(msg.has_hpf_enabled());
246 RTC_CHECK_EQ(AudioProcessing::kNoError,
247 apm_->high_pass_filter()->Enable(msg.hpf_enabled()));
248
249 // NS configs.
250 RTC_CHECK(msg.has_ns_enabled());
251 RTC_CHECK_EQ(AudioProcessing::kNoError,
252 apm_->noise_suppression()->Enable(msg.ns_enabled()));
253
254 RTC_CHECK(msg.has_ns_level());
255 RTC_CHECK_EQ(AudioProcessing::kNoError,
256 apm_->noise_suppression()->set_level(
257 static_cast<NoiseSuppression::Level>(msg.ns_level())));
258 }
259
260 void DebugDumpReplayer::LoadNextMessage() {
261 has_next_event_ =
262 debug_file_ && ReadMessageFromFile(debug_file_, &next_event_);
263 }
264
265 } // namespace test
266 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/test/debug_dump_replayer.h ('k') | webrtc/modules/audio_processing/test/debug_dump_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698