diff --git a/modules/audio_processing/test/aec_dump_based_simulator.cc b/modules/audio_processing/test/aec_dump_based_simulator.cc index 230d56b696..a0106dc679 100644 --- a/modules/audio_processing/test/aec_dump_based_simulator.cc +++ b/modules/audio_processing/test/aec_dump_based_simulator.cc @@ -10,6 +10,7 @@ #include +#include "absl/memory/memory.h" #include "modules/audio_processing/echo_cancellation_impl.h" #include "modules/audio_processing/echo_control_mobile_impl.h" #include "modules/audio_processing/test/aec_dump_based_simulator.h" @@ -69,7 +70,9 @@ bool VerifyFloatBitExactness(const webrtc::audioproc::Stream& msg, AecDumpBasedSimulator::AecDumpBasedSimulator( const SimulationSettings& settings, std::unique_ptr ap_builder) - : AudioProcessingSimulator(settings, std::move(ap_builder)) {} + : AudioProcessingSimulator(settings, std::move(ap_builder)) { + MaybeOpenCallOrderFile(); +} AecDumpBasedSimulator::~AecDumpBasedSimulator() = default; @@ -474,6 +477,7 @@ void AecDumpBasedSimulator::HandleMessage(const webrtc::audioproc::Init& msg) { RTC_CHECK(msg.has_num_input_channels()); RTC_CHECK(msg.has_num_reverse_channels()); RTC_CHECK(msg.has_reverse_sample_rate()); + MaybeOpenCallOrderFile(); if (settings_.use_verbose_logging) { std::cout << "Init at frame:" << std::endl; @@ -525,6 +529,9 @@ void AecDumpBasedSimulator::HandleMessage(const webrtc::audioproc::Init& msg) { void AecDumpBasedSimulator::HandleMessage( const webrtc::audioproc::Stream& msg) { + if (call_order_output_file_) { + *call_order_output_file_ << "c"; + } PrepareProcessStreamCall(msg); ProcessStream(interface_used_ == InterfaceType::kFixedInterface); VerifyProcessStreamBitExactness(msg); @@ -532,6 +539,9 @@ void AecDumpBasedSimulator::HandleMessage( void AecDumpBasedSimulator::HandleMessage( const webrtc::audioproc::ReverseStream& msg) { + if (call_order_output_file_) { + *call_order_output_file_ << "r"; + } PrepareReverseProcessStreamCall(msg); ProcessReverseStream(interface_used_ == InterfaceType::kFixedInterface); } @@ -542,5 +552,16 @@ void AecDumpBasedSimulator::HandleMessage( ReplayRuntimeSetting(ap_.get(), msg); } +void AecDumpBasedSimulator::MaybeOpenCallOrderFile() { + if (settings_.call_order_output_filename.has_value()) { + const std::string filename = settings_.store_intermediate_output + ? *settings_.call_order_output_filename + + "_" + + std::to_string(output_reset_counter_) + : *settings_.call_order_output_filename; + call_order_output_file_ = absl::make_unique(filename); + } +} + } // namespace test } // namespace webrtc diff --git a/modules/audio_processing/test/aec_dump_based_simulator.h b/modules/audio_processing/test/aec_dump_based_simulator.h index 78c1210c59..f15aa2762f 100644 --- a/modules/audio_processing/test/aec_dump_based_simulator.h +++ b/modules/audio_processing/test/aec_dump_based_simulator.h @@ -11,6 +11,9 @@ #ifndef MODULES_AUDIO_PROCESSING_TEST_AEC_DUMP_BASED_SIMULATOR_H_ #define MODULES_AUDIO_PROCESSING_TEST_AEC_DUMP_BASED_SIMULATOR_H_ +#include +#include + #include "modules/audio_processing/test/audio_processing_simulator.h" #include "rtc_base/constructor_magic.h" @@ -47,7 +50,7 @@ class AecDumpBasedSimulator final : public AudioProcessingSimulator { void PrepareReverseProcessStreamCall( const webrtc::audioproc::ReverseStream& msg); void VerifyProcessStreamBitExactness(const webrtc::audioproc::Stream& msg); - + void MaybeOpenCallOrderFile(); enum InterfaceType { kFixedInterface, kFloatInterface, @@ -59,7 +62,7 @@ class AecDumpBasedSimulator final : public AudioProcessingSimulator { std::unique_ptr artificial_nearend_buffer_reader_; bool artificial_nearend_eof_reported_ = false; InterfaceType interface_used_ = InterfaceType::kNotSpecified; - + std::unique_ptr call_order_output_file_; RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AecDumpBasedSimulator); }; diff --git a/modules/audio_processing/test/audio_processing_simulator.h b/modules/audio_processing/test/audio_processing_simulator.h index cba3134b16..97b3db523a 100644 --- a/modules/audio_processing/test/audio_processing_simulator.h +++ b/modules/audio_processing/test/audio_processing_simulator.h @@ -96,7 +96,8 @@ struct SimulationSettings { bool print_aec_parameter_values = false; bool dump_internal_data = false; absl::optional dump_internal_data_output_dir; - absl::optional custom_call_order_filename; + absl::optional call_order_input_filename; + absl::optional call_order_output_filename; absl::optional aec_settings_filename; }; @@ -183,12 +184,14 @@ class AudioProcessingSimulator { bool bitexact_output_ = true; int aec_dump_mic_level_ = 0; + protected: + size_t output_reset_counter_ = 0; + private: void SetupOutput(); size_t num_process_stream_calls_ = 0; size_t num_reverse_process_stream_calls_ = 0; - size_t output_reset_counter_ = 0; std::unique_ptr buffer_writer_; std::unique_ptr reverse_buffer_writer_; TickIntervalStats proc_time_; diff --git a/modules/audio_processing/test/audioproc_float_impl.cc b/modules/audio_processing/test/audioproc_float_impl.cc index af439b7c05..f0e57a90b9 100644 --- a/modules/audio_processing/test/audioproc_float_impl.cc +++ b/modules/audio_processing/test/audioproc_float_impl.cc @@ -206,6 +206,10 @@ WEBRTC_DEFINE_bool(store_intermediate_output, WEBRTC_DEFINE_string(custom_call_order_file, "", "Custom process API call order file"); +WEBRTC_DEFINE_string( + output_custom_call_order_file, + "", + "Generate custom process API call order file from AEC dump"); WEBRTC_DEFINE_bool(print_aec_parameter_values, false, "Print parameter values used in AEC in JSON-format"); @@ -339,7 +343,9 @@ SimulationSettings CreateSettings() { SetSettingIfSpecified(FLAG_stream_drift_samples, &settings.stream_drift_samples); SetSettingIfSpecified(FLAG_custom_call_order_file, - &settings.custom_call_order_filename); + &settings.call_order_input_filename); + SetSettingIfSpecified(FLAG_output_custom_call_order_file, + &settings.call_order_output_filename); SetSettingIfSpecified(FLAG_aec_settings, &settings.aec_settings_filename); settings.initial_mic_level = FLAG_initial_mic_level; settings.simulate_mic_gain = FLAG_simulate_mic_gain; @@ -454,7 +460,7 @@ void PerformBasicParameterSanityChecks(const SimulationSettings& settings) { "aecdump\n"); ReportConditionalErrorAndExit( - settings.custom_call_order_filename && settings.aec_dump_input_filename, + settings.call_order_input_filename && settings.aec_dump_input_filename, "Error: --custom_call_order_file cannot be used when operating on an " "aecdump\n"); @@ -514,6 +520,11 @@ void PerformBasicParameterSanityChecks(const SimulationSettings& settings) { !settings.dump_internal_data && settings.dump_internal_data_output_dir.has_value(), "Error: --dump_data_output_dir cannot be set without --dump_data.\n"); + + ReportConditionalErrorAndExit( + !settings.aec_dump_input_filename && + settings.call_order_output_filename.has_value(), + "Error: --output_custom_call_order_file needs an AEC dump input file.\n"); } } // namespace diff --git a/modules/audio_processing/test/wav_based_simulator.cc b/modules/audio_processing/test/wav_based_simulator.cc index 865ced70c2..1160ba8565 100644 --- a/modules/audio_processing/test/wav_based_simulator.cc +++ b/modules/audio_processing/test/wav_based_simulator.cc @@ -88,9 +88,9 @@ void WavBasedSimulator::PrepareReverseProcessStreamCall() { } void WavBasedSimulator::Process() { - if (settings_.custom_call_order_filename) { + if (settings_.call_order_input_filename) { call_chain_ = WavBasedSimulator::GetCustomEventChain( - *settings_.custom_call_order_filename); + *settings_.call_order_input_filename); } else { call_chain_ = WavBasedSimulator::GetDefaultEventChain(); }