From 7a95e0fcf4eb82b1366501c6465d0f35aa4dca25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Thu, 25 Oct 2018 09:56:49 +0200 Subject: [PATCH] APM: Add ability to turn on/off dumping of internal data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL modifies the internal data logging and the audioproc_f tool to allow controlling that via the command line, rather than solely via a build flag. The logging of internal data is by default off. Bug: webrtc:5298 Change-Id: I96d1b4f990582938527b9039d6c2ecbb6f76e9ca Reviewed-on: https://webrtc-review.googlesource.com/c/107713 Reviewed-by: Gustaf Ullberg Commit-Queue: Per Ã…hgren Cr-Commit-Position: refs/heads/master@{#25352} --- modules/audio_processing/BUILD.gn | 2 + .../logging/apm_data_dumper.cc | 2 + .../logging/apm_data_dumper.h | 112 ++++++++++++------ .../test/audio_processing_simulator.cc | 4 + .../test/audio_processing_simulator.h | 1 + .../test/audioproc_float_impl.cc | 8 ++ 6 files changed, 96 insertions(+), 33 deletions(-) diff --git a/modules/audio_processing/BUILD.gn b/modules/audio_processing/BUILD.gn index dd1569e415..3b558921b9 100644 --- a/modules/audio_processing/BUILD.gn +++ b/modules/audio_processing/BUILD.gn @@ -514,6 +514,7 @@ if (rtc_include_tests) { if (rtc_enable_protobuf) { rtc_source_set("audioproc_f_impl") { testonly = true + configs += [ ":apm_debug_dump" ] sources = [ "test/aec_dump_based_simulator.cc", "test/aec_dump_based_simulator.h", @@ -527,6 +528,7 @@ if (rtc_include_tests) { deps = [ ":analog_mic_simulation", + ":apm_logging", ":audio_processing", ":audioproc_debug_proto", ":audioproc_protobuf_utils", diff --git a/modules/audio_processing/logging/apm_data_dumper.cc b/modules/audio_processing/logging/apm_data_dumper.cc index ebb85268f9..45d8088c98 100644 --- a/modules/audio_processing/logging/apm_data_dumper.cc +++ b/modules/audio_processing/logging/apm_data_dumper.cc @@ -46,6 +46,8 @@ ApmDataDumper::ApmDataDumper(int instance_index) {} ApmDataDumper::~ApmDataDumper() {} #if WEBRTC_APM_DEBUG_DUMP == 1 +bool ApmDataDumper::recording_activated_ = false; +; FILE* ApmDataDumper::GetRawFile(const char* name) { std::string filename = FormFileName(name, instance_index_, recording_set_index_, ".dat"); diff --git a/modules/audio_processing/logging/apm_data_dumper.h b/modules/audio_processing/logging/apm_data_dumper.h index 10deb35edd..f0c5978200 100644 --- a/modules/audio_processing/logging/apm_data_dumper.h +++ b/modules/audio_processing/logging/apm_data_dumper.h @@ -50,6 +50,13 @@ class ApmDataDumper { ~ApmDataDumper(); + // Activates or deactivate the dumping functionality. + static void SetActivated(bool activated) { +#if WEBRTC_APM_DEBUG_DUMP == 1 + recording_activated_ = activated; +#endif + } + // Reinitializes the data dumping such that new versions // of all files being dumped to are created. void InitiateNewSetOfRecordings() { @@ -62,117 +69,151 @@ class ApmDataDumper { // various formats. void DumpRaw(const char* name, double v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - FILE* file = GetRawFile(name); - fwrite(&v, sizeof(v), 1, file); + if (recording_activated_) { + FILE* file = GetRawFile(name); + fwrite(&v, sizeof(v), 1, file); + } #endif } void DumpRaw(const char* name, size_t v_length, const double* v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - FILE* file = GetRawFile(name); - fwrite(v, sizeof(v[0]), v_length, file); + if (recording_activated_) { + FILE* file = GetRawFile(name); + fwrite(v, sizeof(v[0]), v_length, file); + } #endif } void DumpRaw(const char* name, rtc::ArrayView v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - DumpRaw(name, v.size(), v.data()); + if (recording_activated_) { + DumpRaw(name, v.size(), v.data()); + } #endif } void DumpRaw(const char* name, float v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - FILE* file = GetRawFile(name); - fwrite(&v, sizeof(v), 1, file); + if (recording_activated_) { + FILE* file = GetRawFile(name); + fwrite(&v, sizeof(v), 1, file); + } #endif } void DumpRaw(const char* name, size_t v_length, const float* v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - FILE* file = GetRawFile(name); - fwrite(v, sizeof(v[0]), v_length, file); + if (recording_activated_) { + FILE* file = GetRawFile(name); + fwrite(v, sizeof(v[0]), v_length, file); + } #endif } void DumpRaw(const char* name, rtc::ArrayView v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - DumpRaw(name, v.size(), v.data()); + if (recording_activated_) { + DumpRaw(name, v.size(), v.data()); + } #endif } void DumpRaw(const char* name, bool v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - DumpRaw(name, static_cast(v)); + if (recording_activated_) { + DumpRaw(name, static_cast(v)); + } #endif } void DumpRaw(const char* name, size_t v_length, const bool* v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - FILE* file = GetRawFile(name); - for (size_t k = 0; k < v_length; ++k) { - int16_t value = static_cast(v[k]); - fwrite(&value, sizeof(value), 1, file); + if (recording_activated_) { + FILE* file = GetRawFile(name); + for (size_t k = 0; k < v_length; ++k) { + int16_t value = static_cast(v[k]); + fwrite(&value, sizeof(value), 1, file); + } } #endif } void DumpRaw(const char* name, rtc::ArrayView v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - DumpRaw(name, v.size(), v.data()); + if (recording_activated_) { + DumpRaw(name, v.size(), v.data()); + } #endif } void DumpRaw(const char* name, int16_t v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - FILE* file = GetRawFile(name); - fwrite(&v, sizeof(v), 1, file); + if (recording_activated_) { + FILE* file = GetRawFile(name); + fwrite(&v, sizeof(v), 1, file); + } #endif } void DumpRaw(const char* name, size_t v_length, const int16_t* v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - FILE* file = GetRawFile(name); - fwrite(v, sizeof(v[0]), v_length, file); + if (recording_activated_) { + FILE* file = GetRawFile(name); + fwrite(v, sizeof(v[0]), v_length, file); + } #endif } void DumpRaw(const char* name, rtc::ArrayView v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - DumpRaw(name, v.size(), v.data()); + if (recording_activated_) { + DumpRaw(name, v.size(), v.data()); + } #endif } void DumpRaw(const char* name, int32_t v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - FILE* file = GetRawFile(name); - fwrite(&v, sizeof(v), 1, file); + if (recording_activated_) { + FILE* file = GetRawFile(name); + fwrite(&v, sizeof(v), 1, file); + } #endif } void DumpRaw(const char* name, size_t v_length, const int32_t* v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - FILE* file = GetRawFile(name); - fwrite(v, sizeof(v[0]), v_length, file); + if (recording_activated_) { + FILE* file = GetRawFile(name); + fwrite(v, sizeof(v[0]), v_length, file); + } #endif } void DumpRaw(const char* name, size_t v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - FILE* file = GetRawFile(name); - fwrite(&v, sizeof(v), 1, file); + if (recording_activated_) { + FILE* file = GetRawFile(name); + fwrite(&v, sizeof(v), 1, file); + } #endif } void DumpRaw(const char* name, size_t v_length, const size_t* v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - FILE* file = GetRawFile(name); - fwrite(v, sizeof(v[0]), v_length, file); + if (recording_activated_) { + FILE* file = GetRawFile(name); + fwrite(v, sizeof(v[0]), v_length, file); + } #endif } void DumpRaw(const char* name, rtc::ArrayView v) { #if WEBRTC_APM_DEBUG_DUMP == 1 - DumpRaw(name, v.size(), v.data()); + if (recording_activated_) { + DumpRaw(name, v.size(), v.data()); + } #endif } @@ -182,8 +223,10 @@ class ApmDataDumper { int sample_rate_hz, int num_channels) { #if WEBRTC_APM_DEBUG_DUMP == 1 - WavWriter* file = GetWavFile(name, sample_rate_hz, num_channels); - file->WriteSamples(v, v_length); + if (recording_activated_) { + WavWriter* file = GetWavFile(name, sample_rate_hz, num_channels); + file->WriteSamples(v, v_length); + } #endif } @@ -192,12 +235,15 @@ class ApmDataDumper { int sample_rate_hz, int num_channels) { #if WEBRTC_APM_DEBUG_DUMP == 1 - DumpWav(name, v.size(), v.data(), sample_rate_hz, num_channels); + if (recording_activated_) { + DumpWav(name, v.size(), v.data(), sample_rate_hz, num_channels); + } #endif } private: #if WEBRTC_APM_DEBUG_DUMP == 1 + static bool recording_activated_; const int instance_index_; int recording_set_index_ = 0; std::unordered_map> diff --git a/modules/audio_processing/test/audio_processing_simulator.cc b/modules/audio_processing/test/audio_processing_simulator.cc index cd682d0ae1..e4ac57b069 100644 --- a/modules/audio_processing/test/audio_processing_simulator.cc +++ b/modules/audio_processing/test/audio_processing_simulator.cc @@ -25,6 +25,7 @@ #include "modules/audio_processing/echo_cancellation_impl.h" #include "modules/audio_processing/echo_control_mobile_impl.h" #include "modules/audio_processing/include/audio_processing.h" +#include "modules/audio_processing/logging/apm_data_dumper.h" #include "modules/audio_processing/test/fake_recording_device.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" @@ -114,6 +115,9 @@ AudioProcessingSimulator::AudioProcessingSimulator( settings.initial_mic_level, settings_.simulate_mic_gain ? *settings.simulated_mic_kind : 0), worker_queue_("file_writer_task_queue") { + RTC_CHECK(!settings_.dump_internal_data || WEBRTC_APM_DEBUG_DUMP == 1); + ApmDataDumper::SetActivated(settings_.dump_internal_data); + if (settings_.ed_graph_output_filename && !settings_.ed_graph_output_filename->empty()) { residual_echo_likelihood_graph_writer_.open( diff --git a/modules/audio_processing/test/audio_processing_simulator.h b/modules/audio_processing/test/audio_processing_simulator.h index 4e580b4fce..6e21eb3e3a 100644 --- a/modules/audio_processing/test/audio_processing_simulator.h +++ b/modules/audio_processing/test/audio_processing_simulator.h @@ -92,6 +92,7 @@ struct SimulationSettings { bool fixed_interface = false; bool store_intermediate_output = false; bool print_aec3_parameter_values = false; + bool dump_internal_data = false; absl::optional custom_call_order_filename; absl::optional aec3_settings_filename; }; diff --git a/modules/audio_processing/test/audioproc_float_impl.cc b/modules/audio_processing/test/audioproc_float_impl.cc index e3f5004637..b098e22eb2 100644 --- a/modules/audio_processing/test/audioproc_float_impl.cc +++ b/modules/audio_processing/test/audioproc_float_impl.cc @@ -200,6 +200,9 @@ WEBRTC_DEFINE_bool(print_aec3_parameter_values, WEBRTC_DEFINE_string(aec3_settings, "", "File in JSON-format with custom AEC3 settings"); +WEBRTC_DEFINE_bool(dump_data, + false, + "Dump internal data during the call (requires build flag)"); WEBRTC_DEFINE_bool(help, false, "Print this message"); void SetSettingIfSpecified(const std::string& value, @@ -311,6 +314,7 @@ SimulationSettings CreateSettings() { settings.fixed_interface = FLAG_fixed_interface; settings.store_intermediate_output = FLAG_store_intermediate_output; settings.print_aec3_parameter_values = FLAG_print_aec3_parameter_values; + settings.dump_internal_data = FLAG_dump_data; return settings; } @@ -461,6 +465,10 @@ void PerformBasicParameterSanityChecks(const SimulationSettings& settings) { settings.artificial_nearend_filename && !valid_wav_name(*settings.artificial_nearend_filename), "Error: --artifical_nearend must be a valid .wav file name.\n"); + + ReportConditionalErrorAndExit( + WEBRTC_APM_DEBUG_DUMP == 0 && settings.dump_internal_data, + "Error: --dump_data cannot be set without proper build support.\n"); } } // namespace