blob: 72cefdd791f61d3fc6eb0a6c9e571802f2328df6 [file] [log] [blame]
minyue275d2552015-11-04 06:23:54 -08001/*
2 * Copyright (c) 2015 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 <stddef.h> // size_t
kwiberg62eaacf2016-02-17 06:39:05 -080012
kwiberg84be5112016-04-27 01:19:58 -070013#include <memory>
minyue275d2552015-11-04 06:23:54 -080014#include <string>
15#include <vector>
16
Gustaf Ullberg0efa9412018-02-27 13:58:45 +010017#include "api/audio/echo_canceller3_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
19#include "modules/audio_processing/aec_dump/aec_dump_factory.h"
20#include "modules/audio_processing/test/debug_dump_replayer.h"
21#include "modules/audio_processing/test/test_utils.h"
22#include "rtc_base/task_queue.h"
23#include "test/gtest.h"
24#include "test/testsupport/fileutils.h"
minyue275d2552015-11-04 06:23:54 -080025
26namespace webrtc {
27namespace test {
28
29namespace {
30
kwiberg62eaacf2016-02-17 06:39:05 -080031void MaybeResetBuffer(std::unique_ptr<ChannelBuffer<float>>* buffer,
minyue275d2552015-11-04 06:23:54 -080032 const StreamConfig& config) {
33 auto& buffer_ref = *buffer;
34 if (!buffer_ref.get() || buffer_ref->num_frames() != config.num_frames() ||
35 buffer_ref->num_channels() != config.num_channels()) {
Yves Gerey665174f2018-06-19 15:03:05 +020036 buffer_ref.reset(
37 new ChannelBuffer<float>(config.num_frames(), config.num_channels()));
minyue275d2552015-11-04 06:23:54 -080038 }
39}
40
41class DebugDumpGenerator {
42 public:
43 DebugDumpGenerator(const std::string& input_file_name,
Alex Loiko890988c2017-08-31 10:25:48 +020044 int input_rate_hz,
minyue275d2552015-11-04 06:23:54 -080045 int input_channels,
46 const std::string& reverse_file_name,
Alex Loiko890988c2017-08-31 10:25:48 +020047 int reverse_rate_hz,
minyue275d2552015-11-04 06:23:54 -080048 int reverse_channels,
49 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +020050 const std::string& dump_file_name,
51 bool enable_aec3);
minyue275d2552015-11-04 06:23:54 -080052
53 // Constructor that uses default input files.
peah88ac8532016-09-12 16:47:25 -070054 explicit DebugDumpGenerator(const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +020055 const AudioProcessing::Config& apm_config,
56 bool enable_aec3);
57
58 explicit DebugDumpGenerator(const Config& config,
peah88ac8532016-09-12 16:47:25 -070059 const AudioProcessing::Config& apm_config);
minyue275d2552015-11-04 06:23:54 -080060
61 ~DebugDumpGenerator();
62
63 // Changes the sample rate of the input audio to the APM.
64 void SetInputRate(int rate_hz);
65
66 // Sets if converts stereo input signal to mono by discarding other channels.
67 void ForceInputMono(bool mono);
68
69 // Changes the sample rate of the reverse audio to the APM.
70 void SetReverseRate(int rate_hz);
71
72 // Sets if converts stereo reverse signal to mono by discarding other
73 // channels.
74 void ForceReverseMono(bool mono);
75
76 // Sets the required sample rate of the APM output.
77 void SetOutputRate(int rate_hz);
78
79 // Sets the required channels of the APM output.
80 void SetOutputChannels(int channels);
81
82 std::string dump_file_name() const { return dump_file_name_; }
83
84 void StartRecording();
85 void Process(size_t num_blocks);
86 void StopRecording();
87 AudioProcessing* apm() const { return apm_.get(); }
88
89 private:
Yves Gerey665174f2018-06-19 15:03:05 +020090 static void ReadAndDeinterleave(ResampleInputAudioFile* audio,
91 int channels,
minyue275d2552015-11-04 06:23:54 -080092 const StreamConfig& config,
93 float* const* buffer);
94
95 // APM input/output settings.
96 StreamConfig input_config_;
97 StreamConfig reverse_config_;
98 StreamConfig output_config_;
99
100 // Input file format.
101 const std::string input_file_name_;
102 ResampleInputAudioFile input_audio_;
103 const int input_file_channels_;
104
105 // Reverse file format.
106 const std::string reverse_file_name_;
107 ResampleInputAudioFile reverse_audio_;
108 const int reverse_file_channels_;
109
110 // Buffer for APM input/output.
kwiberg62eaacf2016-02-17 06:39:05 -0800111 std::unique_ptr<ChannelBuffer<float>> input_;
112 std::unique_ptr<ChannelBuffer<float>> reverse_;
113 std::unique_ptr<ChannelBuffer<float>> output_;
minyue275d2552015-11-04 06:23:54 -0800114
aleloif4dd1912017-06-15 01:55:38 -0700115 rtc::TaskQueue worker_queue_;
kwiberg62eaacf2016-02-17 06:39:05 -0800116 std::unique_ptr<AudioProcessing> apm_;
minyue275d2552015-11-04 06:23:54 -0800117
118 const std::string dump_file_name_;
119};
120
121DebugDumpGenerator::DebugDumpGenerator(const std::string& input_file_name,
122 int input_rate_hz,
123 int input_channels,
124 const std::string& reverse_file_name,
125 int reverse_rate_hz,
126 int reverse_channels,
127 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200128 const std::string& dump_file_name,
129 bool enable_aec3)
minyue275d2552015-11-04 06:23:54 -0800130 : input_config_(input_rate_hz, input_channels),
131 reverse_config_(reverse_rate_hz, reverse_channels),
132 output_config_(input_rate_hz, input_channels),
133 input_audio_(input_file_name, input_rate_hz, input_rate_hz),
134 input_file_channels_(input_channels),
135 reverse_audio_(reverse_file_name, reverse_rate_hz, reverse_rate_hz),
136 reverse_file_channels_(reverse_channels),
137 input_(new ChannelBuffer<float>(input_config_.num_frames(),
138 input_config_.num_channels())),
139 reverse_(new ChannelBuffer<float>(reverse_config_.num_frames(),
140 reverse_config_.num_channels())),
141 output_(new ChannelBuffer<float>(output_config_.num_frames(),
142 output_config_.num_channels())),
aleloif4dd1912017-06-15 01:55:38 -0700143 worker_queue_("debug_dump_generator_worker_queue"),
Ivo Creusen62337e52018-01-09 14:17:33 +0100144 dump_file_name_(dump_file_name) {
145 AudioProcessingBuilder apm_builder;
146 if (enable_aec3) {
147 apm_builder.SetEchoControlFactory(
148 std::unique_ptr<EchoControlFactory>(new EchoCanceller3Factory()));
149 }
150 apm_.reset(apm_builder.Create(config));
151}
minyue275d2552015-11-04 06:23:54 -0800152
peah88ac8532016-09-12 16:47:25 -0700153DebugDumpGenerator::DebugDumpGenerator(
154 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200155 const AudioProcessing::Config& apm_config,
156 bool enable_aec3)
peah88ac8532016-09-12 16:47:25 -0700157 : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"),
158 32000,
159 2,
160 ResourcePath("far32_stereo", "pcm"),
161 32000,
162 2,
163 config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200164 TempFilename(OutputPath(), "debug_aec"),
165 enable_aec3) {
166 apm_->ApplyConfig(apm_config);
167}
168
169DebugDumpGenerator::DebugDumpGenerator(
170 const Config& config,
171 const AudioProcessing::Config& apm_config)
172 : DebugDumpGenerator(config, apm_config, false) {
peah88ac8532016-09-12 16:47:25 -0700173 apm_->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800174}
175
176DebugDumpGenerator::~DebugDumpGenerator() {
177 remove(dump_file_name_.c_str());
178}
179
180void DebugDumpGenerator::SetInputRate(int rate_hz) {
181 input_audio_.set_output_rate_hz(rate_hz);
182 input_config_.set_sample_rate_hz(rate_hz);
183 MaybeResetBuffer(&input_, input_config_);
184}
185
186void DebugDumpGenerator::ForceInputMono(bool mono) {
187 const int channels = mono ? 1 : input_file_channels_;
188 input_config_.set_num_channels(channels);
189 MaybeResetBuffer(&input_, input_config_);
190}
191
192void DebugDumpGenerator::SetReverseRate(int rate_hz) {
193 reverse_audio_.set_output_rate_hz(rate_hz);
194 reverse_config_.set_sample_rate_hz(rate_hz);
195 MaybeResetBuffer(&reverse_, reverse_config_);
196}
197
198void DebugDumpGenerator::ForceReverseMono(bool mono) {
199 const int channels = mono ? 1 : reverse_file_channels_;
200 reverse_config_.set_num_channels(channels);
201 MaybeResetBuffer(&reverse_, reverse_config_);
202}
203
204void DebugDumpGenerator::SetOutputRate(int rate_hz) {
205 output_config_.set_sample_rate_hz(rate_hz);
206 MaybeResetBuffer(&output_, output_config_);
207}
208
209void DebugDumpGenerator::SetOutputChannels(int channels) {
210 output_config_.set_num_channels(channels);
211 MaybeResetBuffer(&output_, output_config_);
212}
213
214void DebugDumpGenerator::StartRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700215 apm_->AttachAecDump(
216 AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_));
minyue275d2552015-11-04 06:23:54 -0800217}
218
219void DebugDumpGenerator::Process(size_t num_blocks) {
220 for (size_t i = 0; i < num_blocks; ++i) {
221 ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_,
222 reverse_config_, reverse_->channels());
223 ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_,
224 input_->channels());
225 RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100));
226 apm_->set_stream_key_pressed(i % 10 == 9);
227 RTC_CHECK_EQ(AudioProcessing::kNoError,
228 apm_->ProcessStream(input_->channels(), input_config_,
229 output_config_, output_->channels()));
230
Yves Gerey665174f2018-06-19 15:03:05 +0200231 RTC_CHECK_EQ(
232 AudioProcessing::kNoError,
233 apm_->ProcessReverseStream(reverse_->channels(), reverse_config_,
234 reverse_config_, reverse_->channels()));
minyue275d2552015-11-04 06:23:54 -0800235 }
236}
237
238void DebugDumpGenerator::StopRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700239 apm_->DetachAecDump();
minyue275d2552015-11-04 06:23:54 -0800240}
241
242void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio,
243 int channels,
244 const StreamConfig& config,
245 float* const* buffer) {
246 const size_t num_frames = config.num_frames();
247 const int out_channels = config.num_channels();
248
249 std::vector<int16_t> signal(channels * num_frames);
250
251 audio->Read(num_frames * channels, &signal[0]);
252
253 // We only allow reducing number of channels by discarding some channels.
254 RTC_CHECK_LE(out_channels, channels);
255 for (int channel = 0; channel < out_channels; ++channel) {
256 for (size_t i = 0; i < num_frames; ++i) {
257 buffer[channel][i] = S16ToFloat(signal[i * channels + channel]);
258 }
259 }
260}
261
262} // namespace
263
264class DebugDumpTest : public ::testing::Test {
265 public:
minyue275d2552015-11-04 06:23:54 -0800266 // VerifyDebugDump replays a debug dump using APM and verifies that the result
267 // is bit-exact-identical to the output channel in the dump. This is only
268 // guaranteed if the debug dump is started on the first frame.
Alex Loiko890988c2017-08-31 10:25:48 +0200269 void VerifyDebugDump(const std::string& in_filename);
minyue275d2552015-11-04 06:23:54 -0800270
271 private:
minyue0de1c132016-03-17 02:39:30 -0700272 DebugDumpReplayer debug_dump_replayer_;
minyue275d2552015-11-04 06:23:54 -0800273};
274
minyue275d2552015-11-04 06:23:54 -0800275void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) {
minyue0de1c132016-03-17 02:39:30 -0700276 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename));
minyue275d2552015-11-04 06:23:54 -0800277
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200278 while (const absl::optional<audioproc::Event> event =
279 debug_dump_replayer_.GetNextEvent()) {
minyue0de1c132016-03-17 02:39:30 -0700280 debug_dump_replayer_.RunNextEvent();
281 if (event->type() == audioproc::Event::STREAM) {
282 const audioproc::Stream* msg = &event->stream();
283 const StreamConfig output_config = debug_dump_replayer_.GetOutputConfig();
284 const ChannelBuffer<float>* output = debug_dump_replayer_.GetOutput();
285 // Check that output of APM is bit-exact to the output in the dump.
286 ASSERT_EQ(output_config.num_channels(),
287 static_cast<size_t>(msg->output_channel_size()));
288 ASSERT_EQ(output_config.num_frames() * sizeof(float),
289 msg->output_channel(0).size());
290 for (int i = 0; i < msg->output_channel_size(); ++i) {
Yves Gerey665174f2018-06-19 15:03:05 +0200291 ASSERT_EQ(0,
292 memcmp(output->channels()[i], msg->output_channel(i).data(),
293 msg->output_channel(i).size()));
minyue0de1c132016-03-17 02:39:30 -0700294 }
minyue275d2552015-11-04 06:23:54 -0800295 }
296 }
minyue275d2552015-11-04 06:23:54 -0800297}
298
299TEST_F(DebugDumpTest, SimpleCase) {
300 Config config;
peah88ac8532016-09-12 16:47:25 -0700301 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800302 generator.StartRecording();
303 generator.Process(100);
304 generator.StopRecording();
305 VerifyDebugDump(generator.dump_file_name());
306}
307
308TEST_F(DebugDumpTest, ChangeInputFormat) {
309 Config config;
peah88ac8532016-09-12 16:47:25 -0700310 DebugDumpGenerator generator(config, AudioProcessing::Config());
311
minyue275d2552015-11-04 06:23:54 -0800312 generator.StartRecording();
313 generator.Process(100);
314 generator.SetInputRate(48000);
315
316 generator.ForceInputMono(true);
317 // Number of output channel should not be larger than that of input. APM will
318 // fail otherwise.
319 generator.SetOutputChannels(1);
320
321 generator.Process(100);
322 generator.StopRecording();
323 VerifyDebugDump(generator.dump_file_name());
324}
325
326TEST_F(DebugDumpTest, ChangeReverseFormat) {
327 Config config;
peah88ac8532016-09-12 16:47:25 -0700328 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800329 generator.StartRecording();
330 generator.Process(100);
331 generator.SetReverseRate(48000);
332 generator.ForceReverseMono(true);
333 generator.Process(100);
334 generator.StopRecording();
335 VerifyDebugDump(generator.dump_file_name());
336}
337
338TEST_F(DebugDumpTest, ChangeOutputFormat) {
339 Config config;
peah88ac8532016-09-12 16:47:25 -0700340 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800341 generator.StartRecording();
342 generator.Process(100);
343 generator.SetOutputRate(48000);
344 generator.SetOutputChannels(1);
345 generator.Process(100);
346 generator.StopRecording();
347 VerifyDebugDump(generator.dump_file_name());
348}
349
350TEST_F(DebugDumpTest, ToggleAec) {
351 Config config;
peah88ac8532016-09-12 16:47:25 -0700352 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800353 generator.StartRecording();
354 generator.Process(100);
355
356 EchoCancellation* aec = generator.apm()->echo_cancellation();
357 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled()));
358
359 generator.Process(100);
360 generator.StopRecording();
361 VerifyDebugDump(generator.dump_file_name());
362}
363
364TEST_F(DebugDumpTest, ToggleDelayAgnosticAec) {
365 Config config;
366 config.Set<DelayAgnostic>(new DelayAgnostic(true));
peah88ac8532016-09-12 16:47:25 -0700367 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800368 generator.StartRecording();
369 generator.Process(100);
370
Sam Zackrisson2a959d92018-07-23 14:48:07 +0000371 EchoCancellation* aec = generator.apm()->echo_cancellation();
372 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled()));
minyue275d2552015-11-04 06:23:54 -0800373
374 generator.Process(100);
375 generator.StopRecording();
376 VerifyDebugDump(generator.dump_file_name());
377}
378
peah0332c2d2016-04-15 11:23:33 -0700379TEST_F(DebugDumpTest, VerifyRefinedAdaptiveFilterExperimentalString) {
380 Config config;
381 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
peah88ac8532016-09-12 16:47:25 -0700382 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah0332c2d2016-04-15 11:23:33 -0700383 generator.StartRecording();
384 generator.Process(100);
385 generator.StopRecording();
386
387 DebugDumpReplayer debug_dump_replayer_;
388
389 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
390
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200391 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700392 debug_dump_replayer_.GetNextEvent()) {
393 debug_dump_replayer_.RunNextEvent();
394 if (event->type() == audioproc::Event::CONFIG) {
395 const audioproc::Config* msg = &event->config();
396 ASSERT_TRUE(msg->has_experiments_description());
397 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
398 msg->experiments_description().c_str());
399 }
400 }
401}
402
403TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) {
404 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800405 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200406 apm_config.echo_canceller.enabled = true;
peah0332c2d2016-04-15 11:23:33 -0700407 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
henrik.lundinbd681b92016-12-05 09:08:42 -0800408 // Arbitrarily set clipping gain to 17, which will never be the default.
409 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200410 bool enable_aec3 = true;
411 DebugDumpGenerator generator(config, apm_config, enable_aec3);
peah0332c2d2016-04-15 11:23:33 -0700412 generator.StartRecording();
413 generator.Process(100);
414 generator.StopRecording();
415
416 DebugDumpReplayer debug_dump_replayer_;
417
418 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
419
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200420 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700421 debug_dump_replayer_.GetNextEvent()) {
422 debug_dump_replayer_.RunNextEvent();
423 if (event->type() == audioproc::Event::CONFIG) {
424 const audioproc::Config* msg = &event->config();
425 ASSERT_TRUE(msg->has_experiments_description());
426 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
427 msg->experiments_description().c_str());
Gustaf Ullbergce045ac2017-10-16 13:49:04 +0200428 EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700429 msg->experiments_description().c_str());
henrik.lundinbd681b92016-12-05 09:08:42 -0800430 EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment",
431 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700432 }
433 }
434}
435
436TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) {
437 Config config;
438 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
peah88ac8532016-09-12 16:47:25 -0700439 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah0332c2d2016-04-15 11:23:33 -0700440 generator.StartRecording();
441 generator.Process(100);
442 generator.StopRecording();
443
444 DebugDumpReplayer debug_dump_replayer_;
445
446 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
447
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200448 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700449 debug_dump_replayer_.GetNextEvent()) {
450 debug_dump_replayer_.RunNextEvent();
451 if (event->type() == audioproc::Event::CONFIG) {
452 const audioproc::Config* msg = &event->config();
453 ASSERT_TRUE(msg->has_experiments_description());
454 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
455 msg->experiments_description().c_str());
456 EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AEC3",
457 msg->experiments_description().c_str());
henrik.lundinbd681b92016-12-05 09:08:42 -0800458 EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AgcClippingLevelExperiment",
459 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700460 }
461 }
462}
463
peah7789fe72016-04-15 01:19:44 -0700464TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) {
465 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800466 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200467 apm_config.echo_canceller.enabled = true;
Sam Zackrisson2a959d92018-07-23 14:48:07 +0000468 DebugDumpGenerator generator(config, apm_config, true);
peah7789fe72016-04-15 01:19:44 -0700469 generator.StartRecording();
470 generator.Process(100);
471 generator.StopRecording();
472
473 DebugDumpReplayer debug_dump_replayer_;
474
475 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
476
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200477 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700478 debug_dump_replayer_.GetNextEvent()) {
479 debug_dump_replayer_.RunNextEvent();
480 if (event->type() == audioproc::Event::CONFIG) {
481 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700482 ASSERT_TRUE(msg->has_experiments_description());
Gustaf Ullbergce045ac2017-10-16 13:49:04 +0200483 EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700484 msg->experiments_description().c_str());
peah7789fe72016-04-15 01:19:44 -0700485 }
486 }
487}
488
henrik.lundinbd681b92016-12-05 09:08:42 -0800489TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) {
490 Config config;
491 // Arbitrarily set clipping gain to 17, which will never be the default.
492 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
493 DebugDumpGenerator generator(config, AudioProcessing::Config());
494 generator.StartRecording();
495 generator.Process(100);
496 generator.StopRecording();
497
498 DebugDumpReplayer debug_dump_replayer_;
499
500 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
501
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200502 while (const absl::optional<audioproc::Event> event =
henrik.lundinbd681b92016-12-05 09:08:42 -0800503 debug_dump_replayer_.GetNextEvent()) {
504 debug_dump_replayer_.RunNextEvent();
505 if (event->type() == audioproc::Event::CONFIG) {
506 const audioproc::Config* msg = &event->config();
507 ASSERT_TRUE(msg->has_experiments_description());
508 EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment",
509 msg->experiments_description().c_str());
510 }
511 }
512}
513
peah7789fe72016-04-15 01:19:44 -0700514TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) {
515 Config config;
peah88ac8532016-09-12 16:47:25 -0700516 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah7789fe72016-04-15 01:19:44 -0700517 generator.StartRecording();
518 generator.Process(100);
519 generator.StopRecording();
520
521 DebugDumpReplayer debug_dump_replayer_;
522
523 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
524
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200525 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700526 debug_dump_replayer_.GetNextEvent()) {
527 debug_dump_replayer_.RunNextEvent();
528 if (event->type() == audioproc::Event::CONFIG) {
529 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700530 ASSERT_TRUE(msg->has_experiments_description());
peah7789fe72016-04-15 01:19:44 -0700531 EXPECT_EQ(0u, msg->experiments_description().size());
532 }
533 }
534}
535
minyue275d2552015-11-04 06:23:54 -0800536TEST_F(DebugDumpTest, ToggleAecLevel) {
537 Config config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200538 AudioProcessing::Config apm_config;
539 apm_config.echo_canceller.enabled = true;
540 apm_config.echo_canceller.mobile_mode = false;
541 DebugDumpGenerator generator(config, apm_config);
minyue275d2552015-11-04 06:23:54 -0800542 EchoCancellation* aec = generator.apm()->echo_cancellation();
minyue275d2552015-11-04 06:23:54 -0800543 EXPECT_EQ(AudioProcessing::kNoError,
544 aec->set_suppression_level(EchoCancellation::kLowSuppression));
545 generator.StartRecording();
546 generator.Process(100);
547
548 EXPECT_EQ(AudioProcessing::kNoError,
549 aec->set_suppression_level(EchoCancellation::kHighSuppression));
550 generator.Process(100);
551 generator.StopRecording();
552 VerifyDebugDump(generator.dump_file_name());
553}
554
Kári Tristan Helgason470c0882016-10-03 13:13:29 +0200555// AGC is not supported on Android or iOS.
556#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
minyue275d2552015-11-04 06:23:54 -0800557#define MAYBE_ToggleAgc DISABLED_ToggleAgc
558#else
559#define MAYBE_ToggleAgc ToggleAgc
560#endif
561TEST_F(DebugDumpTest, MAYBE_ToggleAgc) {
562 Config config;
peah88ac8532016-09-12 16:47:25 -0700563 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800564 generator.StartRecording();
565 generator.Process(100);
566
567 GainControl* agc = generator.apm()->gain_control();
568 EXPECT_EQ(AudioProcessing::kNoError, agc->Enable(!agc->is_enabled()));
569
570 generator.Process(100);
571 generator.StopRecording();
572 VerifyDebugDump(generator.dump_file_name());
573}
574
575TEST_F(DebugDumpTest, ToggleNs) {
576 Config config;
peah88ac8532016-09-12 16:47:25 -0700577 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800578 generator.StartRecording();
579 generator.Process(100);
580
581 NoiseSuppression* ns = generator.apm()->noise_suppression();
582 EXPECT_EQ(AudioProcessing::kNoError, ns->Enable(!ns->is_enabled()));
583
584 generator.Process(100);
585 generator.StopRecording();
586 VerifyDebugDump(generator.dump_file_name());
587}
588
589TEST_F(DebugDumpTest, TransientSuppressionOn) {
590 Config config;
591 config.Set<ExperimentalNs>(new ExperimentalNs(true));
peah88ac8532016-09-12 16:47:25 -0700592 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800593 generator.StartRecording();
594 generator.Process(100);
595 generator.StopRecording();
596 VerifyDebugDump(generator.dump_file_name());
597}
598
minyue275d2552015-11-04 06:23:54 -0800599} // namespace test
600} // namespace webrtc