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

@ -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<const double> 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<const float> 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<int16_t>(v));
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
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);
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
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<const int16_t> 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<const int32_t> 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<std::string, std::unique_ptr<FILE, RawFileCloseFunctor>>