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:
committed by
Commit Bot
parent
388e4e9d96
commit
4bc60452f7
@ -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>>
|
||||
|
||||
Reference in New Issue
Block a user