Bug 1025176: Save AEC dumps in a specified directory depending on platform/pref r=pkerr

This commit is contained in:
Randell Jesup 2014-06-16 15:51:45 -04:00
parent 29acbb866c
commit 2697000e13
7 changed files with 108 additions and 42 deletions

View File

@ -52,11 +52,12 @@ public:
static WebRtcTraceCallback gWebRtcCallback;
#ifdef MOZILLA_INTERNAL_API
void GetWebRtcLogPrefs(uint32_t *aTraceMask, nsACString* aLogFile, bool *aMultiLog)
void GetWebRtcLogPrefs(uint32_t *aTraceMask, nsACString* aLogFile, nsACString *aAECLogDir, bool *aMultiLog)
{
*aMultiLog = mozilla::Preferences::GetBool("media.webrtc.debug.multi_log");
*aTraceMask = mozilla::Preferences::GetUint("media.webrtc.debug.trace_mask");
mozilla::Preferences::GetCString("media.webrtc.debug.log_file", aLogFile);
mozilla::Preferences::GetCString("media.webrtc.debug.aec_log_dir", aAECLogDir);
webrtc::Trace::set_aec_debug_size(mozilla::Preferences::GetUint("media.webrtc.debug.aec_dump_max_size"));
}
#endif
@ -91,40 +92,52 @@ void CheckOverrides(uint32_t *aTraceMask, nsACString *aLogFile, bool *aMultiLog)
}
}
void ConfigWebRtcLog(uint32_t trace_mask, nsCString &aLogFile, bool multi_log)
void ConfigWebRtcLog(uint32_t trace_mask, nsCString &aLogFile, nsCString &aAECLogDir, bool multi_log)
{
if (gWebRtcTraceLoggingOn || trace_mask == 0) {
if (gWebRtcTraceLoggingOn) {
return;
}
if (aLogFile.IsEmpty()) {
nsCString logFile;
nsCString aecLogDir;
#if defined(XP_WIN)
// Use the Windows TEMP environment variable as part of the default location.
const char *temp_dir = PR_GetEnv("TEMP");
if (!temp_dir) {
aLogFile.Assign(default_log);
} else {
aLogFile.Assign(temp_dir);
aLogFile.Append('/');
aLogFile.Append(default_log);
}
// Use the Windows TEMP environment variable as part of the default location.
const char *temp_dir = PR_GetEnv("TEMP");
if (!temp_dir) {
logFile.Assign(default_log);
} else {
logFile.Assign(temp_dir);
logFile.Append('/');
aecLogDir = logFile;
logFile.Append(default_log);
}
#elif defined(ANDROID)
// Special case: use callback to pipe to NSPR logging.
aLogFile.Assign("nspr");
// Special case: use callback to pipe to NSPR logging.
logFile.Assign("nspr");
// for AEC, force the user to specify a directory
aecLogDir.Assign("/dev/null");
#else
// UNIX-like place for the others
aLogFile.Assign("/tmp/");
aLogFile.Append(default_log);
// UNIX-like place for the others
logFile.Assign("/tmp/");
aecLogDir = logFile;
logFile.Append(default_log);
#endif
if (aLogFile.IsEmpty()) {
aLogFile = logFile;
}
if (aAECLogDir.IsEmpty()) {
aAECLogDir = aecLogDir;
}
webrtc::Trace::set_level_filter(trace_mask);
if (aLogFile.EqualsLiteral("nspr")) {
webrtc::Trace::SetTraceCallback(&gWebRtcCallback);
} else {
webrtc::Trace::SetTraceFile(aLogFile.get(), multi_log);
webrtc::Trace::set_aec_debug_filename(aAECLogDir.get());
if (trace_mask != 0) {
if (aLogFile.EqualsLiteral("nspr")) {
webrtc::Trace::SetTraceCallback(&gWebRtcCallback);
} else {
webrtc::Trace::SetTraceFile(aLogFile.get(), multi_log);
}
}
return;
}
@ -134,7 +147,7 @@ void StartWebRtcLog(uint32_t log_level)
return;
}
if (log_level == 0) {
if (log_level == 0) {
if (gWebRtcTraceLoggingOn) {
gWebRtcTraceLoggingOn = false;
webrtc::Trace::set_level_filter(webrtc::kTraceNone);
@ -145,9 +158,10 @@ void StartWebRtcLog(uint32_t log_level)
uint32_t trace_mask = 0;
bool multi_log = false;
nsAutoCString log_file;
nsAutoCString aec_log_dir;
#ifdef MOZILLA_INTERNAL_API
GetWebRtcLogPrefs(&trace_mask, &log_file, &multi_log);
GetWebRtcLogPrefs(&trace_mask, &log_file, &aec_log_dir, &multi_log);
#endif
CheckOverrides(&trace_mask, &log_file, &multi_log);
@ -155,7 +169,7 @@ void StartWebRtcLog(uint32_t log_level)
trace_mask = log_level;
}
ConfigWebRtcLog(trace_mask, log_file, multi_log);
ConfigWebRtcLog(trace_mask, log_file, aec_log_dir, multi_log);
return;
}
@ -169,12 +183,12 @@ void EnableWebRtcLog()
uint32_t trace_mask = 0;
bool multi_log = false;
nsAutoCString log_file;
nsAutoCString aec_log_dir;
#ifdef MOZILLA_INTERNAL_API
GetWebRtcLogPrefs(&trace_mask, &log_file, &multi_log);
GetWebRtcLogPrefs(&trace_mask, &log_file, &aec_log_dir, &multi_log);
#endif
CheckOverrides(&trace_mask, &log_file, &multi_log);
ConfigWebRtcLog(trace_mask, log_file, multi_log);
ConfigWebRtcLog(trace_mask, log_file, aec_log_dir, multi_log);
return;
}

View File

@ -252,6 +252,7 @@ WebrtcGlobalInformation::DebugLevel(const GlobalObject& aGlobal)
void
WebrtcGlobalInformation::SetAecDebug(const GlobalObject& aGlobal, bool aEnable)
{
StartWebRtcLog(sLastSetLevel); // to make it read the aec path
webrtc::Trace::set_aec_debug(aEnable);
sLastAECDebug = aEnable;
}

View File

@ -31,6 +31,7 @@
extern int AECDebug();
extern uint32_t AECDebugMaxSize();
extern void AECDebugEnable(uint32_t enable);
extern void AECDebugFilenameBase(char *buffer, size_t size);
static void OpenCoreDebugFiles(AecCore* aec, int *instance_count);
// Buffer size (samples)
@ -1730,16 +1731,34 @@ OpenCoreDebugFiles(AecCore* aec,
// XXX If this impacts performance (opening files here), move file open
// to Trace::set_aec_debug(), and just grab them here
if (AECDebug() && !aec->farFile) {
char filename[128];
if (!aec->farFile) {
char path[1024];
char *filename;
path[0] = '\0';
AECDebugFilenameBase(path, sizeof(path));
filename = path + strlen(path);
if (&path[sizeof(path)] - filename < 128) {
return; // avoid a lot of snprintf's and checks lower
}
if (filename > path) {
#ifdef XP_WIN
if (*(filename-1) != '\\') {
*filename++ = '\\';
}
#else
if (*(filename-1) != '/') {
*filename++ = '/';
}
#endif
}
sprintf(filename, "aec_far%d.pcm", webrtc_aec_instance_count);
aec->farFile = fopen(filename, "wb");
aec->farFile = fopen(path, "wb");
sprintf(filename, "aec_near%d.pcm", webrtc_aec_instance_count);
aec->nearFile = fopen(filename, "wb");
aec->nearFile = fopen(path, "wb");
sprintf(filename, "aec_out%d.pcm", webrtc_aec_instance_count);
aec->outFile = fopen(filename, "wb");
aec->outFile = fopen(path, "wb");
sprintf(filename, "aec_out_linear%d.pcm", webrtc_aec_instance_count);
aec->outLinearFile = fopen(filename, "wb");
aec->outLinearFile = fopen(path, "wb");
aec->debugWritten = 0;
if (!aec->outLinearFile || !aec->outFile || !aec->nearFile || !aec->farFile) {
error = 1;

View File

@ -30,6 +30,7 @@
extern int AECDebug();
extern uint32_t AECDebugMaxSize();
extern void AECDebugEnable(uint32_t enable);
extern void AECDebugFilenameBase(char *buffer, size_t size);
static void OpenDebugFiles(aecpc_t* aecpc, int *instance_count);
// Measured delays [ms]
@ -985,13 +986,31 @@ OpenDebugFiles(aecpc_t* aecpc,
// XXX If this impacts performance (opening files here), move file open
// to Trace::set_aec_debug(), and just grab them here
if (AECDebug() && !aecpc->bufFile) {
char filename[128];
char path[1024];
char *filename;
path[0] = '\0';
AECDebugFilenameBase(path, sizeof(path));
filename = path + strlen(path);
if (&path[sizeof(path)] - filename < 128) {
return; // avoid a lot of snprintf's and checks lower
}
if (filename > path) {
#ifdef XP_WIN
if (*(filename-1) != '\\') {
*filename++ = '\\';
}
#else
if (*(filename-1) != '/') {
*filename++ = '/';
}
#endif
}
sprintf(filename, "aec_buf%d.dat", *instance_count);
aecpc->bufFile = fopen(filename, "wb");
aecpc->bufFile = fopen(path, "wb");
sprintf(filename, "aec_skew%d.dat", *instance_count);
aecpc->skewFile = fopen(filename, "wb");
aecpc->skewFile = fopen(path, "wb");
sprintf(filename, "aec_delay%d.dat", *instance_count);
aecpc->delayFile = fopen(filename, "wb");
aecpc->delayFile = fopen(path, "wb");
if (!aecpc->bufFile || !aecpc->skewFile || !aecpc->delayFile) {
error = 1;

View File

@ -18,6 +18,7 @@
#include "webrtc/common_types.h"
#include "webrtc/typedefs.h"
#include <string>
namespace webrtc {
@ -59,6 +60,10 @@ class Trace {
static void set_aec_debug_size(uint32_t size) { aec_debug_size_ = size; }
static bool aec_debug() { return aec_debug_; }
static uint32_t aec_debug_size() { return aec_debug_size_; }
static void aec_debug_filename(char *buffer, size_t size);
static void set_aec_debug_filename(const char* filename) {
aec_filename_base_ = filename;
}
// Sets the file name. If add_file_counter is false the same file will be
// reused when it fills up. If it's true a new file with incremented name
@ -93,6 +98,7 @@ class Trace {
static uint32_t level_filter_;
static bool aec_debug_;
static uint32_t aec_debug_size_;
static std::string aec_filename_base_;
};
} // namespace webrtc
@ -101,6 +107,7 @@ extern "C" {
extern int AECDebug();
extern uint32_t AECDebugMaxSize();
extern void AECDebugEnable(uint32_t enable);
extern void AECDebugFilenameBase(char *buffer, size_t size);
}
#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_

View File

@ -33,6 +33,9 @@ extern "C" {
int AECDebug() { return (int) webrtc::Trace::aec_debug(); }
uint32_t AECDebugMaxSize() { return webrtc::Trace::aec_debug_size(); }
void AECDebugEnable(uint32_t enable) { webrtc::Trace::set_aec_debug(!!enable); }
void AECDebugFilenameBase(char *buffer, size_t size) {
webrtc::Trace::aec_debug_filename(buffer, size);
}
}
namespace webrtc {
@ -43,6 +46,12 @@ const int Trace::kTimestampLength = 12;
uint32_t Trace::level_filter_ = kTraceDefault;
bool Trace::aec_debug_ = false;
uint32_t Trace::aec_debug_size_ = 4*1024*1024;
std::string Trace::aec_filename_base_;
void Trace::aec_debug_filename(char *buffer, size_t size) {
strncpy(buffer, aec_filename_base_.c_str(), size-1);
buffer[size-1] = '\0';
}
// Construct On First Use idiom. Avoids "static initialization order fiasco".
TraceImpl* TraceImpl::StaticInstance(CountOperation count_operation,

View File

@ -260,11 +260,8 @@ pref("media.navigator.video.default_minfps",10);
pref("media.webrtc.debug.trace_mask", 0);
pref("media.webrtc.debug.multi_log", false);
#if defined(ANDROID) || defined(XP_WIN)
pref("media.webrtc.debug.aec_log_dir", "");
pref("media.webrtc.debug.log_file", "");
#else
pref("media.webrtc.debug.log_file", "/tmp/WebRTC.log");
#endif
pref("media.webrtc.debug.aec_dump_max_size", 4194304); // 4MB
#ifdef MOZ_WIDGET_GONK