Add output directory option for audioproc_f data dump files.
Bug: webrtc:10000 Change-Id: Iac21f826e78d6cb339c68fdeeedf9fe39920ac31 Reviewed-on: https://webrtc-review.googlesource.com/c/110904 Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25713}
This commit is contained in:
parent
388e4e9d96
commit
4bc60452f7
@ -329,6 +329,7 @@ rtc_source_set("apm_logging") {
|
||||
deps = [
|
||||
"../../api:array_view",
|
||||
"../../common_audio:common_audio",
|
||||
"../../rtc_base:checks",
|
||||
"../../rtc_base:rtc_base_approved",
|
||||
"../../rtc_base:stringutils",
|
||||
]
|
||||
|
||||
@ -19,16 +19,30 @@
|
||||
#endif
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
#if WEBRTC_APM_DEBUG_DUMP == 1
|
||||
std::string FormFileName(const char* name,
|
||||
|
||||
#if defined(WEBRTC_WIN)
|
||||
constexpr char kPathDelimiter = '\\';
|
||||
#else
|
||||
constexpr char kPathDelimiter = '/';
|
||||
#endif
|
||||
|
||||
std::string FormFileName(const char* output_dir,
|
||||
const char* name,
|
||||
int instance_index,
|
||||
int reinit_index,
|
||||
const std::string& suffix) {
|
||||
char buf[1024];
|
||||
rtc::SimpleStringBuilder ss(buf);
|
||||
const size_t output_dir_size = strlen(output_dir);
|
||||
if (output_dir_size > 0) {
|
||||
ss << output_dir;
|
||||
if (output_dir[output_dir_size - 1] != kPathDelimiter) {
|
||||
ss << kPathDelimiter;
|
||||
}
|
||||
}
|
||||
ss << name << "_" << instance_index << "-" << reinit_index << suffix;
|
||||
return ss.str();
|
||||
}
|
||||
@ -40,20 +54,22 @@ std::string FormFileName(const char* name,
|
||||
ApmDataDumper::ApmDataDumper(int instance_index)
|
||||
: instance_index_(instance_index) {}
|
||||
#else
|
||||
ApmDataDumper::ApmDataDumper(int instance_index) {}
|
||||
ApmDataDumper::ApmDataDumper(int instance_index){};
|
||||
#endif
|
||||
|
||||
ApmDataDumper::~ApmDataDumper() {}
|
||||
ApmDataDumper::~ApmDataDumper() = default;
|
||||
|
||||
#if WEBRTC_APM_DEBUG_DUMP == 1
|
||||
bool ApmDataDumper::recording_activated_ = false;
|
||||
;
|
||||
char ApmDataDumper::output_dir_[] = "";
|
||||
|
||||
FILE* ApmDataDumper::GetRawFile(const char* name) {
|
||||
std::string filename =
|
||||
FormFileName(name, instance_index_, recording_set_index_, ".dat");
|
||||
std::string filename = FormFileName(output_dir_, name, instance_index_,
|
||||
recording_set_index_, ".dat");
|
||||
auto& f = raw_files_[filename];
|
||||
if (!f) {
|
||||
f.reset(fopen(filename.c_str(), "wb"));
|
||||
RTC_CHECK(f.get()) << "Cannot write to " << filename << ".";
|
||||
}
|
||||
return f.get();
|
||||
}
|
||||
@ -61,15 +77,14 @@ FILE* ApmDataDumper::GetRawFile(const char* name) {
|
||||
WavWriter* ApmDataDumper::GetWavFile(const char* name,
|
||||
int sample_rate_hz,
|
||||
int num_channels) {
|
||||
std::string filename =
|
||||
FormFileName(name, instance_index_, recording_set_index_, ".wav");
|
||||
std::string filename = FormFileName(output_dir_, name, instance_index_,
|
||||
recording_set_index_, ".wav");
|
||||
auto& f = wav_files_[filename];
|
||||
if (!f) {
|
||||
f.reset(new WavWriter(filename.c_str(), sample_rate_hz, num_channels));
|
||||
}
|
||||
return f.get();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -13,7 +13,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
#if WEBRTC_APM_DEBUG_DUMP == 1
|
||||
#include <unordered_map>
|
||||
#endif
|
||||
@ -21,6 +23,7 @@
|
||||
#include "api/array_view.h"
|
||||
#if WEBRTC_APM_DEBUG_DUMP == 1
|
||||
#include "common_audio/wav_file.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#endif
|
||||
#include "rtc_base/constructormagic.h"
|
||||
|
||||
@ -57,6 +60,14 @@ class ApmDataDumper {
|
||||
#endif
|
||||
}
|
||||
|
||||
// Set an optional output directory.
|
||||
static void SetOutputDirectory(const std::string& output_dir) {
|
||||
#if WEBRTC_APM_DEBUG_DUMP == 1
|
||||
RTC_CHECK_LT(output_dir.size(), kOutputDirMaxLength);
|
||||
strncpy(output_dir_, output_dir.c_str(), output_dir.size());
|
||||
#endif
|
||||
}
|
||||
|
||||
// Reinitializes the data dumping such that new versions
|
||||
// of all files being dumped to are created.
|
||||
void InitiateNewSetOfRecordings() {
|
||||
@ -250,6 +261,8 @@ class ApmDataDumper {
|
||||
private:
|
||||
#if WEBRTC_APM_DEBUG_DUMP == 1
|
||||
static bool recording_activated_;
|
||||
static constexpr size_t kOutputDirMaxLength = 1024;
|
||||
static char output_dir_[kOutputDirMaxLength];
|
||||
const int instance_index_;
|
||||
int recording_set_index_ = 0;
|
||||
std::unordered_map<std::string, std::unique_ptr<FILE, RawFileCloseFunctor>>
|
||||
|
||||
@ -128,6 +128,10 @@ AudioProcessingSimulator::AudioProcessingSimulator(
|
||||
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_.dump_internal_data_output_dir.has_value()) {
|
||||
ApmDataDumper::SetOutputDirectory(
|
||||
settings_.dump_internal_data_output_dir.value());
|
||||
}
|
||||
|
||||
if (settings_.ed_graph_output_filename &&
|
||||
!settings_.ed_graph_output_filename->empty()) {
|
||||
|
||||
@ -95,6 +95,7 @@ struct SimulationSettings {
|
||||
bool store_intermediate_output = false;
|
||||
bool print_aec3_parameter_values = false;
|
||||
bool dump_internal_data = false;
|
||||
absl::optional<std::string> dump_internal_data_output_dir;
|
||||
absl::optional<std::string> custom_call_order_filename;
|
||||
absl::optional<std::string> aec3_settings_filename;
|
||||
};
|
||||
|
||||
@ -216,6 +216,9 @@ WEBRTC_DEFINE_string(aec3_settings,
|
||||
WEBRTC_DEFINE_bool(dump_data,
|
||||
false,
|
||||
"Dump internal data during the call (requires build flag)");
|
||||
WEBRTC_DEFINE_string(dump_data_output_dir,
|
||||
"",
|
||||
"Internal data dump output directory");
|
||||
WEBRTC_DEFINE_bool(help, false, "Print this message");
|
||||
|
||||
void SetSettingIfSpecified(const std::string& value,
|
||||
@ -351,6 +354,8 @@ SimulationSettings CreateSettings() {
|
||||
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;
|
||||
SetSettingIfSpecified(FLAG_dump_data_output_dir,
|
||||
&settings.dump_internal_data_output_dir);
|
||||
|
||||
return settings;
|
||||
}
|
||||
@ -505,6 +510,11 @@ void PerformBasicParameterSanityChecks(const SimulationSettings& settings) {
|
||||
ReportConditionalErrorAndExit(
|
||||
WEBRTC_APM_DEBUG_DUMP == 0 && settings.dump_internal_data,
|
||||
"Error: --dump_data cannot be set without proper build support.\n");
|
||||
|
||||
ReportConditionalErrorAndExit(
|
||||
!settings.dump_internal_data &&
|
||||
settings.dump_internal_data_output_dir.has_value(),
|
||||
"Error: --dump_data_output_dir cannot be set without --dump_data.\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user