APM: Add ability to turn on/off dumping of internal data

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 <gustaf@webrtc.org>
Commit-Queue: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25352}
This commit is contained in:
Per Åhgren
2018-10-25 09:56:49 +02:00
committed by Commit Bot
parent e2fd86a79c
commit 7a95e0fcf4
6 changed files with 96 additions and 33 deletions

View File

@ -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",

View File

@ -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");

View File

@ -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
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
if (recording_activated_) {
FILE* file = GetRawFile(name);
fwrite(v, sizeof(v[0]), v_length, file);
}
#endif
}
void DumpRaw(const char* name, rtc::ArrayView<const double> v) {
#if WEBRTC_APM_DEBUG_DUMP == 1
if (recording_activated_) {
DumpRaw(name, v.size(), v.data());
}
#endif
}
void DumpRaw(const char* name, float v) {
#if WEBRTC_APM_DEBUG_DUMP == 1
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
if (recording_activated_) {
FILE* file = GetRawFile(name);
fwrite(v, sizeof(v[0]), v_length, file);
}
#endif
}
void DumpRaw(const char* name, rtc::ArrayView<const float> v) {
#if WEBRTC_APM_DEBUG_DUMP == 1
if (recording_activated_) {
DumpRaw(name, v.size(), v.data());
}
#endif
}
void DumpRaw(const char* name, bool v) {
#if WEBRTC_APM_DEBUG_DUMP == 1
if (recording_activated_) {
DumpRaw(name, static_cast<int16_t>(v));
}
#endif
}
void DumpRaw(const char* name, size_t v_length, const bool* v) {
#if WEBRTC_APM_DEBUG_DUMP == 1
if (recording_activated_) {
FILE* file = GetRawFile(name);
for (size_t k = 0; k < v_length; ++k) {
int16_t value = static_cast<int16_t>(v[k]);
fwrite(&value, sizeof(value), 1, file);
}
}
#endif
}
void DumpRaw(const char* name, rtc::ArrayView<const bool> v) {
#if WEBRTC_APM_DEBUG_DUMP == 1
if (recording_activated_) {
DumpRaw(name, v.size(), v.data());
}
#endif
}
void DumpRaw(const char* name, int16_t v) {
#if WEBRTC_APM_DEBUG_DUMP == 1
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
if (recording_activated_) {
FILE* file = GetRawFile(name);
fwrite(v, sizeof(v[0]), v_length, file);
}
#endif
}
void DumpRaw(const char* name, rtc::ArrayView<const int16_t> v) {
#if WEBRTC_APM_DEBUG_DUMP == 1
if (recording_activated_) {
DumpRaw(name, v.size(), v.data());
}
#endif
}
void DumpRaw(const char* name, int32_t v) {
#if WEBRTC_APM_DEBUG_DUMP == 1
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
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
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
if (recording_activated_) {
FILE* file = GetRawFile(name);
fwrite(v, sizeof(v[0]), v_length, file);
}
#endif
}
void DumpRaw(const char* name, rtc::ArrayView<const int32_t> v) {
#if WEBRTC_APM_DEBUG_DUMP == 1
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
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
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<std::string, std::unique_ptr<FILE, RawFileCloseFunctor>>

View File

@ -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(

View File

@ -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<std::string> custom_call_order_filename;
absl::optional<std::string> aec3_settings_filename;
};

View File

@ -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