summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/common/browser_logging
diff options
context:
space:
mode:
Diffstat (limited to 'dom/media/webrtc/common/browser_logging')
-rw-r--r--dom/media/webrtc/common/browser_logging/CSFLog.cpp85
-rw-r--r--dom/media/webrtc/common/browser_logging/CSFLog.h58
-rw-r--r--dom/media/webrtc/common/browser_logging/WebRtcLog.cpp162
-rw-r--r--dom/media/webrtc/common/browser_logging/WebRtcLog.h17
4 files changed, 322 insertions, 0 deletions
diff --git a/dom/media/webrtc/common/browser_logging/CSFLog.cpp b/dom/media/webrtc/common/browser_logging/CSFLog.cpp
new file mode 100644
index 0000000000..d58f5726a5
--- /dev/null
+++ b/dom/media/webrtc/common/browser_logging/CSFLog.cpp
@@ -0,0 +1,85 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "CSFLog.h"
+
+#include <map>
+#include "prrwlock.h"
+#include "prthread.h"
+#include "nsThreadUtils.h"
+
+#include "mozilla/Logging.h"
+#include "mozilla/Sprintf.h"
+
+mozilla::LazyLogModule gSignalingLog("signaling");
+
+void CSFLogV(CSFLogLevel priority, const char* sourceFile, int sourceLine,
+ const char* tag, const char* format, va_list args) {
+#ifdef STDOUT_LOGGING
+ printf("%s\n:", tag);
+ vprintf(format, args);
+#else
+
+ mozilla::LogLevel level =
+ static_cast<mozilla::LogLevel>(static_cast<unsigned int>(priority));
+
+ // Skip doing any of this work if we're not logging the indicated level...
+ if (!MOZ_LOG_TEST(gSignalingLog, level)) {
+ return;
+ }
+
+ // Trim the path component from the filename
+ const char* lastSlash = sourceFile;
+ while (*sourceFile) {
+ if (*sourceFile == '/' || *sourceFile == '\\') {
+ lastSlash = sourceFile;
+ }
+ sourceFile++;
+ }
+ sourceFile = lastSlash;
+ if (*sourceFile == '/' || *sourceFile == '\\') {
+ sourceFile++;
+ }
+
+# define MAX_MESSAGE_LENGTH 1024
+ char message[MAX_MESSAGE_LENGTH];
+
+ const char* threadName = NULL;
+
+ // Check if we're the main thread...
+ if (NS_IsMainThread()) {
+ threadName = "main";
+ } else {
+ threadName = PR_GetThreadName(PR_GetCurrentThread());
+ }
+
+ // If we can't find it anywhere, use a blank string
+ if (!threadName) {
+ threadName = "";
+ }
+
+ VsprintfLiteral(message, format, args);
+ MOZ_LOG(
+ gSignalingLog, level,
+ ("[%s|%s] %s:%d: %s", threadName, tag, sourceFile, sourceLine, message));
+#endif
+}
+
+void CSFLog(CSFLogLevel priority, const char* sourceFile, int sourceLine,
+ const char* tag, const char* format, ...) {
+ va_list ap;
+ va_start(ap, format);
+
+ CSFLogV(priority, sourceFile, sourceLine, tag, format, ap);
+ va_end(ap);
+}
+
+int CSFLogTestLevel(CSFLogLevel priority) {
+ return MOZ_LOG_TEST(gSignalingLog, static_cast<mozilla::LogLevel>(
+ static_cast<unsigned int>(priority)));
+}
diff --git a/dom/media/webrtc/common/browser_logging/CSFLog.h b/dom/media/webrtc/common/browser_logging/CSFLog.h
new file mode 100644
index 0000000000..eb46b37cc3
--- /dev/null
+++ b/dom/media/webrtc/common/browser_logging/CSFLog.h
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef CSFLOG_H
+#define CSFLOG_H
+
+#include <stdarg.h>
+
+typedef enum {
+ CSF_LOG_ERROR = 1,
+ CSF_LOG_WARNING,
+ CSF_LOG_INFO,
+ CSF_LOG_DEBUG,
+ CSF_LOG_VERBOSE,
+} CSFLogLevel;
+
+#define CSFLogError(tag, format, ...) \
+ CSFLog(CSF_LOG_ERROR, __FILE__, __LINE__, tag, format, ##__VA_ARGS__)
+#define CSFLogErrorV(tag, format, va_list_arg) \
+ CSFLogV(CSF_LOG_ERROR, __FILE__, __LINE__, tag, format, va_list_arg)
+#define CSFLogWarn(tag, format, ...) \
+ CSFLog(CSF_LOG_WARNING, __FILE__, __LINE__, tag, format, ##__VA_ARGS__)
+#define CSFLogWarnV(tag, format, va_list_arg) \
+ CSFLogV(CSF_LOG_WARNING, __FILE__, __LINE__, tag, format, va_list_arg)
+#define CSFLogInfo(tag, format, ...) \
+ CSFLog(CSF_LOG_INFO, __FILE__, __LINE__, tag, format, ##__VA_ARGS__)
+#define CSFLogInfoV(tag, format, va_list_arg) \
+ CSFLogV(CSF_LOG_INFO, __FILE__, __LINE__, tag, format, va_list_arg)
+#define CSFLogDebug(tag, format, ...) \
+ CSFLog(CSF_LOG_DEBUG, __FILE__, __LINE__, tag, format, ##__VA_ARGS__)
+#define CSFLogDebugV(tag, format, va_list_arg) \
+ CSFLogV(CSF_LOG_DEBUG, __FILE__, __LINE__, tag, format, va_list_arg)
+#define CSFLogVerbose(tag, format, ...) \
+ CSFLog(CSF_LOG_VERBOSE, __FILE__, __LINE__, tag, format, ##__VA_ARGS__)
+#define CSFLogVerboseV(tag, format, va_list_arg) \
+ CSFLogV(CSF_LOG_VERBOSE, __FILE__, __LINE__, tag, format, va_list_arg)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+void CSFLog(CSFLogLevel priority, const char* sourceFile, int sourceLine,
+ const char* tag, const char* format, ...)
+#ifdef __GNUC__
+ __attribute__((format(printf, 5, 6)))
+#endif
+ ;
+
+void CSFLogV(CSFLogLevel priority, const char* sourceFile, int sourceLine,
+ const char* tag, const char* format, va_list args);
+
+int CSFLogTestLevel(CSFLogLevel priority);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/dom/media/webrtc/common/browser_logging/WebRtcLog.cpp b/dom/media/webrtc/common/browser_logging/WebRtcLog.cpp
new file mode 100644
index 0000000000..0f3769604e
--- /dev/null
+++ b/dom/media/webrtc/common/browser_logging/WebRtcLog.cpp
@@ -0,0 +1,162 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "WebRtcLog.h"
+
+#include "mozilla/Logging.h"
+#include "mozilla/StaticPtr.h"
+#include "prenv.h"
+#include "rtc_base/logging.h"
+
+#include "nscore.h"
+#include "nsString.h"
+#include "nsXULAppAPI.h"
+#include "mozilla/Preferences.h"
+
+#include "nsIFile.h"
+#include "nsDirectoryServiceUtils.h"
+#include "nsDirectoryServiceDefs.h"
+#include "nsNativeCharsetUtils.h"
+
+using mozilla::LogLevel;
+
+static mozilla::LazyLogModule sWebRtcLog("webrtc_trace");
+static mozilla::LazyLogModule sLogAEC("AEC");
+
+class LogSinkImpl : public rtc::LogSink {
+ public:
+ LogSinkImpl() {}
+
+ private:
+ void OnLogMessage(const std::string& message) override {
+ MOZ_LOG(sWebRtcLog, LogLevel::Debug, ("%s", message.data()));
+ }
+};
+
+// For RTC_LOG()
+static mozilla::StaticAutoPtr<LogSinkImpl> sSink;
+
+void GetWebRtcLogPrefs() {
+ rtc::LogMessage::set_aec_debug_size(
+ mozilla::Preferences::GetUint("media.webrtc.debug.aec_dump_max_size"));
+}
+
+mozilla::LogLevel CheckOverrides() {
+ mozilla::LogModule* log_info = sWebRtcLog;
+ mozilla::LogLevel log_level = log_info->Level();
+
+ log_info = sLogAEC;
+ if (sLogAEC && (log_info->Level() != mozilla::LogLevel::Disabled)) {
+ rtc::LogMessage::set_aec_debug(true);
+ }
+
+ return log_level;
+}
+
+void ConfigWebRtcLog(mozilla::LogLevel level) {
+ rtc::LoggingSeverity log_level;
+ switch (level) {
+ case mozilla::LogLevel::Verbose:
+ log_level = rtc::LoggingSeverity::LS_VERBOSE;
+ break;
+ case mozilla::LogLevel::Debug:
+ case mozilla::LogLevel::Info:
+ log_level = rtc::LoggingSeverity::LS_INFO;
+ break;
+ case mozilla::LogLevel::Warning:
+ log_level = rtc::LoggingSeverity::LS_WARNING;
+ break;
+ case mozilla::LogLevel::Error:
+ log_level = rtc::LoggingSeverity::LS_ERROR;
+ break;
+ case mozilla::LogLevel::Disabled:
+ log_level = rtc::LoggingSeverity::LS_NONE;
+ break;
+ default:
+ MOZ_ASSERT(false);
+ break;
+ }
+ rtc::LogMessage::LogToDebug(log_level);
+ if (level != mozilla::LogLevel::Disabled) {
+ // always capture LOG(...) << ... logging in webrtc.org code to nspr logs
+ if (!sSink) {
+ sSink = new LogSinkImpl();
+ rtc::LogMessage::AddLogToStream(sSink, log_level);
+ // it's ok if this leaks to program end
+ }
+ } else if (sSink) {
+ rtc::LogMessage::RemoveLogToStream(sSink);
+ sSink = nullptr;
+ }
+}
+
+void StartWebRtcLog(mozilla::LogLevel log_level) {
+ if (log_level == mozilla::LogLevel::Disabled) {
+ return;
+ }
+
+ GetWebRtcLogPrefs();
+ mozilla::LogLevel level = CheckOverrides();
+
+ ConfigWebRtcLog(level);
+}
+
+void EnableWebRtcLog() {
+ GetWebRtcLogPrefs();
+ mozilla::LogLevel level = CheckOverrides();
+ ConfigWebRtcLog(level);
+}
+
+// Called when we destroy the singletons from PeerConnectionCtx or if the
+// user changes logging in about:webrtc
+void StopWebRtcLog() {
+ if (sSink) {
+ rtc::LogMessage::RemoveLogToStream(sSink);
+ sSink = nullptr;
+ }
+}
+
+nsCString ConfigAecLog() {
+ nsCString aecLogDir;
+ if (rtc::LogMessage::aec_debug()) {
+ return ""_ns;
+ }
+#if defined(ANDROID)
+ const char* default_tmp_dir = "/dev/null";
+ aecLogDir.Assign(default_tmp_dir);
+#else
+ nsCOMPtr<nsIFile> tempDir;
+ nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tempDir));
+ if (NS_SUCCEEDED(rv)) {
+# ifdef XP_WIN
+ // WebRTC wants a path encoded in the native charset, not UTF-8.
+ nsAutoString temp;
+ tempDir->GetPath(temp);
+ NS_CopyUnicodeToNative(temp, aecLogDir);
+# else
+ tempDir->GetNativePath(aecLogDir);
+# endif
+ }
+#endif
+ rtc::LogMessage::set_aec_debug_filename(aecLogDir.get());
+
+ return aecLogDir;
+}
+
+nsCString StartAecLog() {
+ nsCString aecLogDir;
+ if (rtc::LogMessage::aec_debug()) {
+ return ""_ns;
+ }
+
+ GetWebRtcLogPrefs();
+ CheckOverrides();
+ aecLogDir = ConfigAecLog();
+
+ rtc::LogMessage::set_aec_debug(true);
+
+ return aecLogDir;
+}
+
+void StopAecLog() { rtc::LogMessage::set_aec_debug(false); }
diff --git a/dom/media/webrtc/common/browser_logging/WebRtcLog.h b/dom/media/webrtc/common/browser_logging/WebRtcLog.h
new file mode 100644
index 0000000000..b933ff43a5
--- /dev/null
+++ b/dom/media/webrtc/common/browser_logging/WebRtcLog.h
@@ -0,0 +1,17 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef WEBRTCLOG_H_
+#define WEBRTCLOG_H_
+
+#include "mozilla/Logging.h"
+#include "nsStringFwd.h"
+
+nsCString StartAecLog();
+void StopAecLog();
+void EnableWebRtcLog();
+void StartWebRtcLog(mozilla::LogLevel level);
+void StopWebRtcLog();
+
+#endif