Bug 822704: Enable WEBRTC_TRACE() logging via NSPR_LOG_MODULES and rename signaling log module r=derf
authorRandell Jesup <rjesup@jesup.org>
Tue, 18 Dec 2012 23:27:38 -0500
changeset 125604 ccf586b1e67950cf102aace4aa00455b2a9e6af5
parent 125603 70f1b2db9f5f87c945be774bdb844a2671979a5b
child 125605 dc5725f89edf46327bf8391049aeeac4180819d6
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersderf
bugs822704
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 822704: Enable WEBRTC_TRACE() logging via NSPR_LOG_MODULES and rename signaling log module r=derf
media/webrtc/signaling/src/common/browser_logging/CSFLog.cpp
media/webrtc/signaling/src/common/browser_logging/CSFLog.h
media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
--- a/media/webrtc/signaling/src/common/browser_logging/CSFLog.cpp
+++ b/media/webrtc/signaling/src/common/browser_logging/CSFLog.cpp
@@ -4,34 +4,52 @@
 
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
 
 #include "CSFLog.h"
 #include "base/basictypes.h"
 #include "prtypes.h"
-#include "prlog.h"
 
 static PRLogModuleInfo *gLogModuleInfo = NULL;
 
+PRLogModuleInfo *GetSignalingLogInfo()
+{
+  if (gLogModuleInfo == NULL)
+    gLogModuleInfo = PR_NewLogModule("signaling");
+
+  return gLogModuleInfo;
+}
+
+static PRLogModuleInfo *gWebRTCLogModuleInfo = NULL;
+int gWebrtcTraceLoggingOn = 0;
+
+PRLogModuleInfo *GetWebRTCLogInfo()
+{
+  if (gWebRTCLogModuleInfo == NULL)
+    gWebRTCLogModuleInfo = PR_NewLogModule("webrtc_trace");
+
+  return gWebRTCLogModuleInfo;
+}
+
+
 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
 
 #define MAX_MESSAGE_LENGTH 1024
   char message[MAX_MESSAGE_LENGTH];
 
   vsnprintf(message, MAX_MESSAGE_LENGTH, format, args);
 
-  if (gLogModuleInfo == NULL)
-    gLogModuleInfo = PR_NewLogModule("ikran");
+  GetSignalingLogInfo();
 
   switch(priority)
   {
     case CSF_LOG_CRITICAL:
     case CSF_LOG_ERROR:
       PR_LOG(gLogModuleInfo, PR_LOG_ERROR, ("%s %s", tag, message));
       break;
     case CSF_LOG_WARNING:
--- a/media/webrtc/signaling/src/common/browser_logging/CSFLog.h
+++ b/media/webrtc/signaling/src/common/browser_logging/CSFLog.h
@@ -1,16 +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 CSFLOG_H
 #define CSFLOG_H
 
 #include <stdarg.h>
+#include "prlog.h"
 
 typedef enum{
 	CSF_LOG_CRITICAL =1,
 	CSF_LOG_ERROR,
 	CSF_LOG_WARNING,
 	CSF_LOG_NOTICE,
 	CSF_LOG_INFO,
 	CSF_LOG_DEBUG
@@ -28,14 +29,19 @@ typedef enum{
 #define CSFLogDebugV(tag , format, va_list_arg) CSFLogV(CSF_LOG_DEBUG, __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, ...);
 void CSFLogV( CSFLogLevel priority, const char* sourceFile, int sourceLine, const char* tag , const char* format, va_list args);
+
+PRLogModuleInfo *GetSignalingLogInfo();
+PRLogModuleInfo *GetWebRTCLogInfo();
+extern int gWebrtcTraceLoggingOn;
+
 #ifdef __cplusplus
 }
 #endif
 
 #endif
 
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
@@ -88,16 +88,31 @@ MediaConduitErrorCode WebrtcAudioConduit
 
   //Per WebRTC APIs below function calls return NULL on failure
   if(!(mVoiceEngine = webrtc::VoiceEngine::Create()))
   {
     CSFLogError(logTag, "%s Unable to create voice engine", __FUNCTION__);
     return kMediaConduitSessionNotInited;
   }
 
+  PRLogModuleInfo *logs = GetWebRTCLogInfo();
+  if (!gWebrtcTraceLoggingOn && logs && logs->level > 0) {
+    // no need to a critical section or lock here
+    gWebrtcTraceLoggingOn = 1;
+
+    const char *file = PR_GetEnv("WEBRTC_TRACE_FILE");
+    if (!file) {
+      file = "WebRTC.log";
+    }
+    CSFLogDebug(logTag,  "%s Logging webrtc to %s level %d", __FUNCTION__,
+                file, logs->level);
+    mVoiceEngine->SetTraceFilter(logs->level);
+    mVoiceEngine->SetTraceFile(file);
+  }
+
   if(!(mPtrVoEBase = VoEBase::GetInterface(mVoiceEngine)))
   {
     CSFLogError(logTag, "%s Unable to initialize VoEBase", __FUNCTION__);
     return kMediaConduitSessionNotInited;
   }
 
   if(!(mPtrVoENetwork = VoENetwork::GetInterface(mVoiceEngine)))
   {
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -75,17 +75,16 @@ WebrtcVideoConduit::~WebrtcVideoConduit(
     mPtrViEBase->DeleteChannel(mChannel);
     mPtrViEBase->Release();
   }
 
   if (mPtrRTP)
   {
     mPtrRTP->Release();
   }
-
   if(mVideoEngine)
   {
     webrtc::VideoEngine::Delete(mVideoEngine);
   }
 }
 
 /**
  * Peforms intialization of the MANDATORY components of the Video Engine
@@ -96,21 +95,30 @@ MediaConduitErrorCode WebrtcVideoConduit
   CSFLogDebug(logTag,  "%s ", __FUNCTION__);
 
   if( !(mVideoEngine = webrtc::VideoEngine::Create()) )
   {
     CSFLogError(logTag, "%s Unable to create video engine ", __FUNCTION__);
      return kMediaConduitSessionNotInited;
   }
 
-#if 0
-  // TRACING
-  mVideoEngine->SetTraceFilter(webrtc::kTraceAll);
-  mVideoEngine->SetTraceFile( "Vievideotrace.out" );
-#endif
+  PRLogModuleInfo *logs = GetWebRTCLogInfo();
+  if (!gWebrtcTraceLoggingOn && logs && logs->level > 0) {
+    // no need to a critical section or lock here
+    gWebrtcTraceLoggingOn = 1;
+
+    const char *file = PR_GetEnv("WEBRTC_TRACE_FILE");
+    if (!file) {
+      file = "WebRTC.log";
+    }
+    CSFLogDebug(logTag,  "%s Logging webrtc to %s level %d", __FUNCTION__,
+                file, logs->level);
+    mVideoEngine->SetTraceFilter(logs->level);
+    mVideoEngine->SetTraceFile(file);
+  }
 
   if( !(mPtrViEBase = ViEBase::GetInterface(mVideoEngine)))
   {
     CSFLogError(logTag, "%s Unable to get video base interface ", __FUNCTION__);
     return kMediaConduitSessionNotInited;
   }
 
   if( !(mPtrViECapture = ViECapture::GetInterface(mVideoEngine)))