blob: c31f3a471a5ce23f20497fb0aed67b74a13cb631 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
18#include "modules/audio_processing/aec_dump/aec_dump_factory.h"
19#include "modules/audio_processing/test/debug_dump_replayer.h"
20#include "modules/audio_processing/test/test_utils.h"
21#include "rtc_base/task_queue.h"
22#include "test/gtest.h"
23#include "test/testsupport/fileutils.h"
minyue275d2552015-11-04 06:23:54 -080024
25namespace webrtc {
26namespace test {
27
28namespace {
29
kwiberg62eaacf2016-02-17 06:39:05 -080030void MaybeResetBuffer(std::unique_ptr<ChannelBuffer<float>>* buffer,
minyue275d2552015-11-04 06:23:54 -080031 const StreamConfig& config) {
32 auto& buffer_ref = *buffer;
33 if (!buffer_ref.get() || buffer_ref->num_frames() != config.num_frames() ||
34 buffer_ref->num_channels() != config.num_channels()) {
35 buffer_ref.reset(new ChannelBuffer<float>(config.num_frames(),
36 config.num_channels()));
37 }
38}
39
40class DebugDumpGenerator {
41 public:
42 DebugDumpGenerator(const std::string& input_file_name,
Alex Loiko890988c2017-08-31 10:25:48 +020043 int input_rate_hz,
minyue275d2552015-11-04 06:23:54 -080044 int input_channels,
45 const std::string& reverse_file_name,
Alex Loiko890988c2017-08-31 10:25:48 +020046 int reverse_rate_hz,
minyue275d2552015-11-04 06:23:54 -080047 int reverse_channels,
48 const Config& config,
49 const std::string& dump_file_name);
50
51 // Constructor that uses default input files.
peah88ac8532016-09-12 16:47:25 -070052 explicit DebugDumpGenerator(const Config& config,
53 const AudioProcessing::Config& apm_config);
minyue275d2552015-11-04 06:23:54 -080054
55 ~DebugDumpGenerator();
56
57 // Changes the sample rate of the input audio to the APM.
58 void SetInputRate(int rate_hz);
59
60 // Sets if converts stereo input signal to mono by discarding other channels.
61 void ForceInputMono(bool mono);
62
63 // Changes the sample rate of the reverse audio to the APM.
64 void SetReverseRate(int rate_hz);
65
66 // Sets if converts stereo reverse signal to mono by discarding other
67 // channels.
68 void ForceReverseMono(bool mono);
69
70 // Sets the required sample rate of the APM output.
71 void SetOutputRate(int rate_hz);
72
73 // Sets the required channels of the APM output.
74 void SetOutputChannels(int channels);
75
76 std::string dump_file_name() const { return dump_file_name_; }
77
78 void StartRecording();
79 void Process(size_t num_blocks);
80 void StopRecording();
81 AudioProcessing* apm() const { return apm_.get(); }
82
83 private:
84 static void ReadAndDeinterleave(ResampleInputAudioFile* audio, int channels,
85 const StreamConfig& config,
86 float* const* buffer);
87
88 // APM input/output settings.
89 StreamConfig input_config_;
90 StreamConfig reverse_config_;
91 StreamConfig output_config_;
92
93 // Input file format.
94 const std::string input_file_name_;
95 ResampleInputAudioFile input_audio_;
96 const int input_file_channels_;
97
98 // Reverse file format.
99 const std::string reverse_file_name_;
100 ResampleInputAudioFile reverse_audio_;
101 const int reverse_file_channels_;
102
103 // Buffer for APM input/output.
kwiberg62eaacf2016-02-17 06:39:05 -0800104 std::unique_ptr<ChannelBuffer<float>> input_;
105 std::unique_ptr<ChannelBuffer<float>> reverse_;
106 std::unique_ptr<ChannelBuffer<float>> output_;
minyue275d2552015-11-04 06:23:54 -0800107
aleloif4dd1912017-06-15 01:55:38 -0700108 rtc::TaskQueue worker_queue_;
kwiberg62eaacf2016-02-17 06:39:05 -0800109 std::unique_ptr<AudioProcessing> apm_;
minyue275d2552015-11-04 06:23:54 -0800110
111 const std::string dump_file_name_;
112};
113
114DebugDumpGenerator::DebugDumpGenerator(const std::string& input_file_name,
115 int input_rate_hz,
116 int input_channels,
117 const std::string& reverse_file_name,
118 int reverse_rate_hz,
119 int reverse_channels,
120 const Config& config,
121 const std::string& dump_file_name)
122 : input_config_(input_rate_hz, input_channels),
123 reverse_config_(reverse_rate_hz, reverse_channels),
124 output_config_(input_rate_hz, input_channels),
125 input_audio_(input_file_name, input_rate_hz, input_rate_hz),
126 input_file_channels_(input_channels),
127 reverse_audio_(reverse_file_name, reverse_rate_hz, reverse_rate_hz),
128 reverse_file_channels_(reverse_channels),
129 input_(new ChannelBuffer<float>(input_config_.num_frames(),
130 input_config_.num_channels())),
131 reverse_(new ChannelBuffer<float>(reverse_config_.num_frames(),
132 reverse_config_.num_channels())),
133 output_(new ChannelBuffer<float>(output_config_.num_frames(),
134 output_config_.num_channels())),
aleloif4dd1912017-06-15 01:55:38 -0700135 worker_queue_("debug_dump_generator_worker_queue"),
minyue275d2552015-11-04 06:23:54 -0800136 apm_(AudioProcessing::Create(config)),
aleloif4dd1912017-06-15 01:55:38 -0700137 dump_file_name_(dump_file_name) {}
minyue275d2552015-11-04 06:23:54 -0800138
peah88ac8532016-09-12 16:47:25 -0700139DebugDumpGenerator::DebugDumpGenerator(
140 const Config& config,
141 const AudioProcessing::Config& apm_config)
142 : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"),
143 32000,
144 2,
145 ResourcePath("far32_stereo", "pcm"),
146 32000,
147 2,
148 config,
149 TempFilename(OutputPath(), "debug_aec")) {
150 apm_->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800151}
152
153DebugDumpGenerator::~DebugDumpGenerator() {
154 remove(dump_file_name_.c_str());
155}
156
157void DebugDumpGenerator::SetInputRate(int rate_hz) {
158 input_audio_.set_output_rate_hz(rate_hz);
159 input_config_.set_sample_rate_hz(rate_hz);
160 MaybeResetBuffer(&input_, input_config_);
161}
162
163void DebugDumpGenerator::ForceInputMono(bool mono) {
164 const int channels = mono ? 1 : input_file_channels_;
165 input_config_.set_num_channels(channels);
166 MaybeResetBuffer(&input_, input_config_);
167}
168
169void DebugDumpGenerator::SetReverseRate(int rate_hz) {
170 reverse_audio_.set_output_rate_hz(rate_hz);
171 reverse_config_.set_sample_rate_hz(rate_hz);
172 MaybeResetBuffer(&reverse_, reverse_config_);
173}
174
175void DebugDumpGenerator::ForceReverseMono(bool mono) {
176 const int channels = mono ? 1 : reverse_file_channels_;
177 reverse_config_.set_num_channels(channels);
178 MaybeResetBuffer(&reverse_, reverse_config_);
179}
180
181void DebugDumpGenerator::SetOutputRate(int rate_hz) {
182 output_config_.set_sample_rate_hz(rate_hz);
183 MaybeResetBuffer(&output_, output_config_);
184}
185
186void DebugDumpGenerator::SetOutputChannels(int channels) {
187 output_config_.set_num_channels(channels);
188 MaybeResetBuffer(&output_, output_config_);
189}
190
191void DebugDumpGenerator::StartRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700192 apm_->AttachAecDump(
193 AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_));
minyue275d2552015-11-04 06:23:54 -0800194}
195
196void DebugDumpGenerator::Process(size_t num_blocks) {
197 for (size_t i = 0; i < num_blocks; ++i) {
198 ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_,
199 reverse_config_, reverse_->channels());
200 ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_,
201 input_->channels());
202 RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100));
203 apm_->set_stream_key_pressed(i % 10 == 9);
204 RTC_CHECK_EQ(AudioProcessing::kNoError,
205 apm_->ProcessStream(input_->channels(), input_config_,
206 output_config_, output_->channels()));
207
208 RTC_CHECK_EQ(AudioProcessing::kNoError,
209 apm_->ProcessReverseStream(reverse_->channels(),
210 reverse_config_,
211 reverse_config_,
212 reverse_->channels()));
213 }
214}
215
216void DebugDumpGenerator::StopRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700217 apm_->DetachAecDump();
minyue275d2552015-11-04 06:23:54 -0800218}
219
220void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio,
221 int channels,
222 const StreamConfig& config,
223 float* const* buffer) {
224 const size_t num_frames = config.num_frames();
225 const int out_channels = config.num_channels();
226
227 std::vector<int16_t> signal(channels * num_frames);
228
229 audio->Read(num_frames * channels, &signal[0]);
230
231 // We only allow reducing number of channels by discarding some channels.
232 RTC_CHECK_LE(out_channels, channels);
233 for (int channel = 0; channel < out_channels; ++channel) {
234 for (size_t i = 0; i < num_frames; ++i) {
235 buffer[channel][i] = S16ToFloat(signal[i * channels + channel]);
236 }
237 }
238}
239
240} // namespace
241
242class DebugDumpTest : public ::testing::Test {
243 public:
minyue275d2552015-11-04 06:23:54 -0800244 // VerifyDebugDump replays a debug dump using APM and verifies that the result
245 // is bit-exact-identical to the output channel in the dump. This is only
246 // guaranteed if the debug dump is started on the first frame.
Alex Loiko890988c2017-08-31 10:25:48 +0200247 void VerifyDebugDump(const std::string& in_filename);
minyue275d2552015-11-04 06:23:54 -0800248
249 private:
minyue0de1c132016-03-17 02:39:30 -0700250 DebugDumpReplayer debug_dump_replayer_;
minyue275d2552015-11-04 06:23:54 -0800251};
252
minyue275d2552015-11-04 06:23:54 -0800253void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) {
minyue0de1c132016-03-17 02:39:30 -0700254 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename));
minyue275d2552015-11-04 06:23:54 -0800255
minyue9705bb82016-04-05 04:39:15 -0700256 while (const rtc::Optional<audioproc::Event> event =
minyue0de1c132016-03-17 02:39:30 -0700257 debug_dump_replayer_.GetNextEvent()) {
258 debug_dump_replayer_.RunNextEvent();
259 if (event->type() == audioproc::Event::STREAM) {
260 const audioproc::Stream* msg = &event->stream();
261 const StreamConfig output_config = debug_dump_replayer_.GetOutputConfig();
262 const ChannelBuffer<float>* output = debug_dump_replayer_.GetOutput();
263 // Check that output of APM is bit-exact to the output in the dump.
264 ASSERT_EQ(output_config.num_channels(),
265 static_cast<size_t>(msg->output_channel_size()));
266 ASSERT_EQ(output_config.num_frames() * sizeof(float),
267 msg->output_channel(0).size());
268 for (int i = 0; i < msg->output_channel_size(); ++i) {
269 ASSERT_EQ(0, memcmp(output->channels()[i],
270 msg->output_channel(i).data(),
271 msg->output_channel(i).size()));
272 }
minyue275d2552015-11-04 06:23:54 -0800273 }
274 }
minyue275d2552015-11-04 06:23:54 -0800275}
276
277TEST_F(DebugDumpTest, SimpleCase) {
278 Config config;
peah88ac8532016-09-12 16:47:25 -0700279 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800280 generator.StartRecording();
281 generator.Process(100);
282 generator.StopRecording();
283 VerifyDebugDump(generator.dump_file_name());
284}
285
286TEST_F(DebugDumpTest, ChangeInputFormat) {
287 Config config;
peah88ac8532016-09-12 16:47:25 -0700288 DebugDumpGenerator generator(config, AudioProcessing::Config());
289
minyue275d2552015-11-04 06:23:54 -0800290 generator.StartRecording();
291 generator.Process(100);
292 generator.SetInputRate(48000);
293
294 generator.ForceInputMono(true);
295 // Number of output channel should not be larger than that of input. APM will
296 // fail otherwise.
297 generator.SetOutputChannels(1);
298
299 generator.Process(100);
300 generator.StopRecording();
301 VerifyDebugDump(generator.dump_file_name());
302}
303
304TEST_F(DebugDumpTest, ChangeReverseFormat) {
305 Config config;
peah88ac8532016-09-12 16:47:25 -0700306 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800307 generator.StartRecording();
308 generator.Process(100);
309 generator.SetReverseRate(48000);
310 generator.ForceReverseMono(true);
311 generator.Process(100);
312 generator.StopRecording();
313 VerifyDebugDump(generator.dump_file_name());
314}
315
316TEST_F(DebugDumpTest, ChangeOutputFormat) {
317 Config config;
peah88ac8532016-09-12 16:47:25 -0700318 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800319 generator.StartRecording();
320 generator.Process(100);
321 generator.SetOutputRate(48000);
322 generator.SetOutputChannels(1);
323 generator.Process(100);
324 generator.StopRecording();
325 VerifyDebugDump(generator.dump_file_name());
326}
327
328TEST_F(DebugDumpTest, ToggleAec) {
329 Config config;
peah88ac8532016-09-12 16:47:25 -0700330 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800331 generator.StartRecording();
332 generator.Process(100);
333
334 EchoCancellation* aec = generator.apm()->echo_cancellation();
335 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled()));
336
337 generator.Process(100);
338 generator.StopRecording();
339 VerifyDebugDump(generator.dump_file_name());
340}
341
342TEST_F(DebugDumpTest, ToggleDelayAgnosticAec) {
343 Config config;
344 config.Set<DelayAgnostic>(new DelayAgnostic(true));
peah88ac8532016-09-12 16:47:25 -0700345 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800346 generator.StartRecording();
347 generator.Process(100);
348
349 EchoCancellation* aec = generator.apm()->echo_cancellation();
350 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled()));
351
352 generator.Process(100);
353 generator.StopRecording();
354 VerifyDebugDump(generator.dump_file_name());
355}
356
peah0332c2d2016-04-15 11:23:33 -0700357TEST_F(DebugDumpTest, VerifyRefinedAdaptiveFilterExperimentalString) {
358 Config config;
359 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
peah88ac8532016-09-12 16:47:25 -0700360 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah0332c2d2016-04-15 11:23:33 -0700361 generator.StartRecording();
362 generator.Process(100);
363 generator.StopRecording();
364
365 DebugDumpReplayer debug_dump_replayer_;
366
367 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
368
369 while (const rtc::Optional<audioproc::Event> event =
370 debug_dump_replayer_.GetNextEvent()) {
371 debug_dump_replayer_.RunNextEvent();
372 if (event->type() == audioproc::Event::CONFIG) {
373 const audioproc::Config* msg = &event->config();
374 ASSERT_TRUE(msg->has_experiments_description());
375 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
376 msg->experiments_description().c_str());
377 }
378 }
379}
380
381TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) {
382 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800383 AudioProcessing::Config apm_config;
peah0332c2d2016-04-15 11:23:33 -0700384 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
henrik.lundinbd681b92016-12-05 09:08:42 -0800385 // Arbitrarily set clipping gain to 17, which will never be the default.
386 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
peahe0eae3c2016-12-14 01:16:23 -0800387 apm_config.echo_canceller3.enabled = true;
388 DebugDumpGenerator generator(config, apm_config);
peah0332c2d2016-04-15 11:23:33 -0700389 generator.StartRecording();
390 generator.Process(100);
391 generator.StopRecording();
392
393 DebugDumpReplayer debug_dump_replayer_;
394
395 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
396
397 while (const rtc::Optional<audioproc::Event> event =
398 debug_dump_replayer_.GetNextEvent()) {
399 debug_dump_replayer_.RunNextEvent();
400 if (event->type() == audioproc::Event::CONFIG) {
401 const audioproc::Config* msg = &event->config();
402 ASSERT_TRUE(msg->has_experiments_description());
403 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
404 msg->experiments_description().c_str());
peahe0eae3c2016-12-14 01:16:23 -0800405 EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoCanceller3",
peah0332c2d2016-04-15 11:23:33 -0700406 msg->experiments_description().c_str());
henrik.lundinbd681b92016-12-05 09:08:42 -0800407 EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment",
408 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700409 }
410 }
411}
412
413TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) {
414 Config config;
415 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
peah88ac8532016-09-12 16:47:25 -0700416 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah0332c2d2016-04-15 11:23:33 -0700417 generator.StartRecording();
418 generator.Process(100);
419 generator.StopRecording();
420
421 DebugDumpReplayer debug_dump_replayer_;
422
423 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
424
425 while (const rtc::Optional<audioproc::Event> event =
426 debug_dump_replayer_.GetNextEvent()) {
427 debug_dump_replayer_.RunNextEvent();
428 if (event->type() == audioproc::Event::CONFIG) {
429 const audioproc::Config* msg = &event->config();
430 ASSERT_TRUE(msg->has_experiments_description());
431 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
432 msg->experiments_description().c_str());
433 EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AEC3",
434 msg->experiments_description().c_str());
henrik.lundinbd681b92016-12-05 09:08:42 -0800435 EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AgcClippingLevelExperiment",
436 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700437 }
438 }
439}
440
peah7789fe72016-04-15 01:19:44 -0700441TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) {
442 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800443 AudioProcessing::Config apm_config;
444 apm_config.echo_canceller3.enabled = true;
445 DebugDumpGenerator generator(config, apm_config);
peah7789fe72016-04-15 01:19:44 -0700446 generator.StartRecording();
447 generator.Process(100);
448 generator.StopRecording();
449
450 DebugDumpReplayer debug_dump_replayer_;
451
452 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
453
454 while (const rtc::Optional<audioproc::Event> event =
455 debug_dump_replayer_.GetNextEvent()) {
456 debug_dump_replayer_.RunNextEvent();
457 if (event->type() == audioproc::Event::CONFIG) {
458 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700459 ASSERT_TRUE(msg->has_experiments_description());
peahe0eae3c2016-12-14 01:16:23 -0800460 EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoCanceller3",
peah0332c2d2016-04-15 11:23:33 -0700461 msg->experiments_description().c_str());
peah7789fe72016-04-15 01:19:44 -0700462 }
463 }
464}
465
peahca4cac72016-06-29 15:26:12 -0700466TEST_F(DebugDumpTest, VerifyLevelControllerExperimentalString) {
467 Config config;
peah88ac8532016-09-12 16:47:25 -0700468 AudioProcessing::Config apm_config;
469 apm_config.level_controller.enabled = true;
470 DebugDumpGenerator generator(config, apm_config);
peahca4cac72016-06-29 15:26:12 -0700471 generator.StartRecording();
472 generator.Process(100);
473 generator.StopRecording();
474
475 DebugDumpReplayer debug_dump_replayer_;
476
477 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
478
479 while (const rtc::Optional<audioproc::Event> event =
480 debug_dump_replayer_.GetNextEvent()) {
481 debug_dump_replayer_.RunNextEvent();
482 if (event->type() == audioproc::Event::CONFIG) {
483 const audioproc::Config* msg = &event->config();
484 ASSERT_TRUE(msg->has_experiments_description());
485 EXPECT_PRED_FORMAT2(testing::IsSubstring, "LevelController",
486 msg->experiments_description().c_str());
487 }
488 }
489}
490
henrik.lundinbd681b92016-12-05 09:08:42 -0800491TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) {
492 Config config;
493 // Arbitrarily set clipping gain to 17, which will never be the default.
494 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
495 DebugDumpGenerator generator(config, AudioProcessing::Config());
496 generator.StartRecording();
497 generator.Process(100);
498 generator.StopRecording();
499
500 DebugDumpReplayer debug_dump_replayer_;
501
502 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
503
504 while (const rtc::Optional<audioproc::Event> event =
505 debug_dump_replayer_.GetNextEvent()) {
506 debug_dump_replayer_.RunNextEvent();
507 if (event->type() == audioproc::Event::CONFIG) {
508 const audioproc::Config* msg = &event->config();
509 ASSERT_TRUE(msg->has_experiments_description());
510 EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment",
511 msg->experiments_description().c_str());
512 }
513 }
514}
515
peah7789fe72016-04-15 01:19:44 -0700516TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) {
517 Config config;
peah88ac8532016-09-12 16:47:25 -0700518 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah7789fe72016-04-15 01:19:44 -0700519 generator.StartRecording();
520 generator.Process(100);
521 generator.StopRecording();
522
523 DebugDumpReplayer debug_dump_replayer_;
524
525 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
526
527 while (const rtc::Optional<audioproc::Event> event =
528 debug_dump_replayer_.GetNextEvent()) {
529 debug_dump_replayer_.RunNextEvent();
530 if (event->type() == audioproc::Event::CONFIG) {
531 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700532 ASSERT_TRUE(msg->has_experiments_description());
peah7789fe72016-04-15 01:19:44 -0700533 EXPECT_EQ(0u, msg->experiments_description().size());
534 }
535 }
536}
537
minyue275d2552015-11-04 06:23:54 -0800538TEST_F(DebugDumpTest, ToggleAecLevel) {
539 Config config;
peah88ac8532016-09-12 16:47:25 -0700540 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800541 EchoCancellation* aec = generator.apm()->echo_cancellation();
542 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(true));
543 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