From 5ad5de37160c4a650ed388a7c82533919937b5e1 Mon Sep 17 00:00:00 2001 From: peah Date: Fri, 9 Dec 2016 03:18:22 -0800 Subject: [PATCH] During AEC development, it is handy to be able to simulate different orders of the ProcessStream and ProcessReverseStream API calls. This CL adds the ability to specify that call order in a file. BUG=webrtc:6018 Review-Url: https://codereview.webrtc.org/2561843003 Cr-Commit-Position: refs/heads/master@{#15503} --- .../test/audio_processing_simulator.h | 1 + .../audio_processing/test/audioproc_float.cc | 8 ++++ .../test/wav_based_simulator.cc | 47 ++++++++++++++++++- .../test/wav_based_simulator.h | 4 +- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/webrtc/modules/audio_processing/test/audio_processing_simulator.h b/webrtc/modules/audio_processing/test/audio_processing_simulator.h index 2564dc4bf2..06735c47b0 100644 --- a/webrtc/modules/audio_processing/test/audio_processing_simulator.h +++ b/webrtc/modules/audio_processing/test/audio_processing_simulator.h @@ -81,6 +81,7 @@ struct SimulationSettings { rtc::Optional aec_dump_output_filename; bool fixed_interface = false; bool store_intermediate_output = false; + rtc::Optional custom_call_order_filename; }; // Holds a few statistics about a series of TickIntervals. diff --git a/webrtc/modules/audio_processing/test/audioproc_float.cc b/webrtc/modules/audio_processing/test/audioproc_float.cc index edc775986f..c4e7c3dced 100644 --- a/webrtc/modules/audio_processing/test/audioproc_float.cc +++ b/webrtc/modules/audio_processing/test/audioproc_float.cc @@ -166,6 +166,7 @@ DEFINE_bool(discard_settings_in_aecdump, DEFINE_bool(store_intermediate_output, false, "Creates new output files after each init"); +DEFINE_string(custom_call_order_file, "", "Custom process API call order file"); void SetSettingIfSpecified(const std::string value, rtc::Optional* parameter) { @@ -257,6 +258,8 @@ SimulationSettings CreateSettings() { SetSettingIfSpecified(FLAGS_stream_delay, &settings.stream_delay); SetSettingIfSpecified(FLAGS_stream_drift_samples, &settings.stream_drift_samples); + SetSettingIfSpecified(FLAGS_custom_call_order_file, + &settings.custom_call_order_filename); settings.report_performance = FLAGS_performance_report; settings.use_verbose_logging = FLAGS_verbose; settings.report_bitexactness = FLAGS_bitexactness_report; @@ -368,6 +371,11 @@ void PerformBasicParameterSanityChecks(const SimulationSettings& settings) { "Error: --bitexactness_report can only be used when operating on an " "aecdump\n"); + ReportConditionalErrorAndExit( + settings.custom_call_order_filename && settings.aec_dump_input_filename, + "Error: --custom_call_order_file cannot be used when operating on an " + "aecdump\n"); + auto valid_wav_name = [](const std::string& wav_file_name) { if (wav_file_name.size() < 5) { return false; diff --git a/webrtc/modules/audio_processing/test/wav_based_simulator.cc b/webrtc/modules/audio_processing/test/wav_based_simulator.cc index dd680dfdfb..6cf0b744e6 100644 --- a/webrtc/modules/audio_processing/test/wav_based_simulator.cc +++ b/webrtc/modules/audio_processing/test/wav_based_simulator.cc @@ -10,19 +10,57 @@ #include "webrtc/modules/audio_processing/test/wav_based_simulator.h" +#include +#include + #include "webrtc/base/checks.h" +#include "webrtc/modules/audio_processing/test/test_utils.h" #include "webrtc/test/testsupport/trace_to_stderr.h" namespace webrtc { namespace test { +std::vector +WavBasedSimulator::GetCustomEventChain(const std::string& filename) { + std::vector call_chain; + FILE* stream = OpenFile(filename.c_str(), "r"); + + RTC_CHECK(stream) << "Could not open the custom call order file, reverting " + "to using the default call order"; + + char c; + size_t num_read = fread(&c, sizeof(char), 1, stream); + while (num_read > 0) { + switch (c) { + case 'r': + call_chain.push_back(SimulationEventType::kProcessReverseStream); + break; + case 'c': + call_chain.push_back(SimulationEventType::kProcessStream); + break; + case '\n': + break; + default: + FATAL() << "Incorrect custom call order file, reverting to using the " + "default call order"; + fclose(stream); + return WavBasedSimulator::GetDefaultEventChain(); + } + + num_read = fread(&c, sizeof(char), 1, stream); + } + + fclose(stream); + return call_chain; +} + WavBasedSimulator::WavBasedSimulator(const SimulationSettings& settings) : AudioProcessingSimulator(settings) {} WavBasedSimulator::~WavBasedSimulator() = default; std::vector -WavBasedSimulator::GetDefaultEventChain() const { +WavBasedSimulator::GetDefaultEventChain() { std::vector call_chain(2); call_chain[0] = SimulationEventType::kProcessStream; call_chain[1] = SimulationEventType::kProcessReverseStream; @@ -59,7 +97,12 @@ void WavBasedSimulator::Process() { trace_to_stderr.reset(new test::TraceToStderr(true)); } - call_chain_ = GetDefaultEventChain(); + if (settings_.custom_call_order_filename) { + call_chain_ = WavBasedSimulator::GetCustomEventChain( + *settings_.custom_call_order_filename); + } else { + call_chain_ = WavBasedSimulator::GetDefaultEventChain(); + } CreateAudioProcessor(); Initialize(); diff --git a/webrtc/modules/audio_processing/test/wav_based_simulator.h b/webrtc/modules/audio_processing/test/wav_based_simulator.h index 5bf93d16d1..c1fcf6163b 100644 --- a/webrtc/modules/audio_processing/test/wav_based_simulator.h +++ b/webrtc/modules/audio_processing/test/wav_based_simulator.h @@ -40,7 +40,9 @@ class WavBasedSimulator final : public AudioProcessingSimulator { bool HandleProcessReverseStreamCall(); void PrepareProcessStreamCall(); void PrepareReverseProcessStreamCall(); - std::vector GetDefaultEventChain() const; + static std::vector GetDefaultEventChain(); + static std::vector GetCustomEventChain( + const std::string& filename); std::vector call_chain_; int last_specified_microphone_level_ = 100;