Switching WebrtcGlobalInformation/Child to using Start/StopAecLog. draft
author[:ng] <na-g@nostrum.com>
Thu, 17 Mar 2016 12:34:36 -0700
changeset 342211 f5292b77b4efdecdba734710e12bfbb2b91fd640
parent 342210 0b91107491ce6cbf3d43477f9b73357883f5bdf3
child 342212 faec5b6a30e3f3951e54baa642fcebb036857dcb
push id13362
push userna-g@nostrum.com
push dateFri, 18 Mar 2016 16:26:54 +0000
milestone48.0a1
Switching WebrtcGlobalInformation/Child to using Start/StopAecLog. MozReview-Commit-ID: 5eciS7177Tl
media/webrtc/signaling/src/common/browser_logging/WebRtcLog.cpp
media/webrtc/signaling/src/common/browser_logging/WebRtcLog.h
media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
--- a/media/webrtc/signaling/src/common/browser_logging/WebRtcLog.cpp
+++ b/media/webrtc/signaling/src/common/browser_logging/WebRtcLog.cpp
@@ -18,18 +18,19 @@
 #endif
 
 #include "nsIFile.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsDirectoryServiceDefs.h"
 
 using mozilla::LogLevel;
 
+//@@NG TODO This is not thread safe. I am not sure if it is necessary at all though. gWebRtcTraceLoggingOn is _never_ set a non-false value.
 static int gWebRtcTraceLoggingOn = 0;
-static int gAecLogginOn = 0;
+
 
 #if defined(ANDROID)
 static const char *default_tmp_dir = "/dev/null";
 static const char *default_log_name = "nspr";
 #else // Assume a POSIX environment
 NS_NAMED_LITERAL_CSTRING(default_log_name, "WebRTC.log");
 #endif
 
@@ -100,63 +101,57 @@ void CheckOverrides(uint32_t *aTraceMask
 
   const char *file_name = PR_GetEnv("WEBRTC_TRACE_FILE");
   if (file_name) {
     aLogFile->Assign(file_name);
   }
 }
 
 void ConfigAecLog(nsCString &aAECLogDir) {
-  if (gAecLogginOn) {
+  printf("@@NG ConfigAecLog entered.\n");
+  if (webrtc::Trace::aec_debug()) {
     return;
   }
-  
+  printf("@@NG ConfigAecLog past guard.\n");
 #if defined(ANDROID)
   // For AEC, do not use a default value: force the user to specify a directory.
   if (aAECLogDir.IsEmpty()) {
     aAECLogDir.Assign(default_tmp_dir);
   }
-#elif defined(XP_MACOSX)
+  /*#elif defined(XP_MACOSX)
   printf("@@NG assigning default /tmp/ AEC log dir.\n");
   if( aAECLogDir.IsEmpty()) {
     aAECLogDir.Assign("/tmp/");
   } else {
     printf("@@NG aECLogDir is not empty: \"%s\"",aAECLogDir.get());
-  }
-#else  
-  if (aLogFile.IsEmpty() || aAECLogDir.IsEmpty()) {    
+  }*/
+#else
+  if (aAECLogDir.IsEmpty()) {
     nsCOMPtr<nsIFile> tempDir;
     nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tempDir));
-
     if (NS_SUCCEEDED(rv)) {
       if (aAECLogDir.IsEmpty()) {
         tempDir->GetNativePath(aAECLogDir);
       }
-
-      if (aLogFile.IsEmpty()) {
-        tempDir->AppendNative(default_log_name);
-        tempDir->GetNativePath(aLogFile);
-      }
     }
   }
 #endif
   webrtc::Trace::set_aec_debug_filename(aAECLogDir.get());
 #if !defined(MOZILLA_EXTERNAL_LINKAGE)
   if (XRE_IsParentProcess()) {
     // Capture the final choices for the trace settings.
     mozilla::Preferences::SetCString("media.webrtc.debug.aec_log_dir", aAECLogDir);
   }
+  printf("@@NG ConfigAecLog aAECLogDir is %s.\n",aAECLogDir.get());
 #endif
 }
 
 void ConfigWebRtcLog(uint32_t trace_mask, nsCString &aLogFile, nsCString &aAECLogDir, bool multi_log)
 {
   if (gWebRtcTraceLoggingOn) {
-    //@@NG DEBUG ONLY - FOR PETE'S SAKE DON'T LET ANYONE SEE THIS ...
-    goto ret;
     return;
   }
 #if defined(ANDROID)
   // Special case: use callback to pipe to NSPR logging.
   aLogFile.Assign(default_log_name);
 #endif
   ConfigAecLog(aAECLogDir);
 
@@ -180,41 +175,42 @@ void ConfigWebRtcLog(uint32_t trace_mask
   }
 
 #if !defined(MOZILLA_EXTERNAL_LINKAGE)
   if (XRE_IsParentProcess()) {
     // Capture the final choices for the trace settings.
     mozilla::Preferences::SetCString("media.webrtc.debug.aec_log_dir", aAECLogDir);
   }
 #endif
-ret:
   printf("@@NG FINAL CONFIG VALUES, trace_mask:%u, aLogFile:%s, aAECLogDir:%s, multi_log:%d\n", trace_mask,aLogFile.get(),aAECLogDir.get(),multi_log);
   return;
 }
 
 void StartAecLog()
 {
-  if (gAecLogginOn) {
+  if (webrtc::Trace::aec_debug()) {
     return;
   }
   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, &aec_log_dir, &multi_log);
 #endif
   CheckOverrides(&trace_mask, &log_file, &multi_log);
+  ConfigAecLog(aec_log_dir);
 
-  if (trace_mask == 0) {
-    trace_mask = log_level;
-  }
+  webrtc::Trace::set_aec_debug(true);
+}
 
-  ConfigAecLog(trace_mask, log_file, aec_log_dir, multi_log);
+void StopAecLog()
+{
+  webrtc::Trace::set_aec_debug(false);
 }
 
 void StartWebRtcLog(uint32_t log_level)
 {
   if (gWebRtcTraceLoggingOn && log_level != 0) {
     return;
   }
 
@@ -242,17 +238,17 @@ void StartWebRtcLog(uint32_t log_level)
 
   ConfigWebRtcLog(trace_mask, log_file, aec_log_dir, multi_log);
   return;
 
 }
 
 void EnableWebRtcLog()
 {
-  if (gWebRtcTraceLoggingOn) {
+  if (webrtc::Trace::aec_debug()) {
     return;
   }
 
   uint32_t trace_mask = 0;
   bool multi_log = false;
   nsAutoCString log_file;
   nsAutoCString aec_log_dir;
 
--- a/media/webrtc/signaling/src/common/browser_logging/WebRtcLog.h
+++ b/media/webrtc/signaling/src/common/browser_logging/WebRtcLog.h
@@ -3,13 +3,14 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef WEBRTCLOG_H_
 #define WEBRTCLOG_H_
 
 #include "webrtc/common_types.h"
 
 void StartAecLog();
+void StopAecLog();
 void StartWebRtcLog(uint32_t log_level = webrtc::kTraceDefault);
 void EnableWebRtcLog();
 void StopWebRtcLog();
 
 #endif
--- a/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
+++ b/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
@@ -676,28 +676,39 @@ int32_t
 WebrtcGlobalInformation::DebugLevel(const GlobalObject& aGlobal)
 {
   return sLastSetLevel;
 }
 
 void
 WebrtcGlobalInformation::SetAecDebug(const GlobalObject& aGlobal, bool aEnable)
 {
-  StartWebRtcLog(sLastSetLevel); // to make it read the aec path
-  webrtc::Trace::set_aec_debug(aEnable);
+  printf("@@NG WebrtcGlobalInformation::SetAecDebug aEnable=%d XRE_isParentProcess()=%d\n",aEnable,XRE_IsParentProcess());
+  //StartWebRtcLog(sLastSetLevel); // to make it read the aec path
+  if( aEnable ) {
+    printf("@@NG WebrtcGlobalInformation::SetAecDebug->StartAecLog()\n");
+    StartAecLog();
+  } else {
+    printf("@@NG WebrtcGlobalInformation::SetAecDebug->StoptAecLog()\n");
+    StopAecLog();
+  }
+
+  //webrtc::Trace::set_aec_debug(aEnable);
   sLastAECDebug = aEnable;
 
   for (auto& cp : WebrtcContentParents::GetAll()){
+    printf("@@NG WebrtcGlobalInformation->SendSetAecLogging aEnable=%d\n",aEnable);
     Unused << cp->SendSetAecLogging(aEnable);
   }
 }
 
 bool
 WebrtcGlobalInformation::AecDebug(const GlobalObject& aGlobal)
 {
+  printf("@@NG WebrtcGlobalInformation::AecDebug == %d \n",sLastAECDebug);
   return sLastAECDebug;
 }
 
 bool
 WebrtcGlobalParent::RecvGetStatsResult(const int& aRequestId,
                                        nsTArray<RTCStatsReportInternal>&& Stats)
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -875,19 +886,25 @@ WebrtcGlobalChild::RecvClearLogRequest()
 
   RunLogClear();
   return true;
 }
 
 bool
 WebrtcGlobalChild::RecvSetAecLogging(const bool& aEnable)
 {
+  printf("@@NG RecvSetAecLogging\n");
   if (!mShutdown) {
-    StartWebRtcLog(sLastSetLevel); // to make it read the aec path
-    webrtc::Trace::set_aec_debug(aEnable);
+    if( aEnable ) {
+      printf("@@NG WebrtcGlobalChild::RecvSetAecLogging->StartAecLog\n");
+      StartAecLog();
+    } else {
+      printf("@@NG WebrtcGlobalChild::RecvSetAecLogging->StopAecLog\n");
+      StopAecLog();
+    }
   }
   return true;
 }
 
 bool
 WebrtcGlobalChild::RecvSetDebugMode(const int& aLevel)
 {
   if (!mShutdown) {