Bug 1337159 - Use MOZ_LOG for WidevineAdapter logging. r?gerald draft
authorChris Pearce <cpearce@mozilla.com>
Tue, 07 Feb 2017 10:12:06 +1300
changeset 479572 9050df76c8ab90352767514bad16a46262bfcc01
parent 479455 12c02bf624c48903b155428f7c8a419ba7a333a6
child 544727 46602784a0e6c59d4c3e1565685f994b5b1f6d38
push id44298
push usercpearce@mozilla.com
push dateMon, 06 Feb 2017 22:54:17 +0000
reviewersgerald
bugs1337159
milestone54.0a1
Bug 1337159 - Use MOZ_LOG for WidevineAdapter logging. r?gerald This works, at least on Windows, if the NSPR_LOG_FILE is set at a file in the OS temp dir. This means we can turn on CDM logging in release builds, in the sandboxed child process, without needing to recompile to #define on logging. This will make debugging issues with the CDM easier. MozReview-Commit-ID: 6cAxMy4lv3T
dom/media/gmp/widevine-adapter/WidevineAdapter.cpp
dom/media/gmp/widevine-adapter/WidevineUtils.cpp
dom/media/gmp/widevine-adapter/WidevineUtils.h
--- a/dom/media/gmp/widevine-adapter/WidevineAdapter.cpp
+++ b/dom/media/gmp/widevine-adapter/WidevineAdapter.cpp
@@ -51,26 +51,16 @@ void* GetCdmHost(int aHostInterfaceVersi
 }
 
 #define STRINGIFY(s) _STRINGIFY(s)
 #define _STRINGIFY(s) #s
 
 GMPErr
 WidevineAdapter::GMPInit(const GMPPlatformAPI* aPlatformAPI)
 {
-#ifdef ENABLE_WIDEVINE_LOG
-  if (getenv("GMP_LOG_FILE")) {
-    // Clear log file.
-    FILE* f = fopen(getenv("GMP_LOG_FILE"), "w");
-    if (f) {
-      fclose(f);
-    }
-  }
-#endif
-
   sPlatform = aPlatformAPI;
   if (!mLib) {
     return GMPGenericErr;
   }
 
   auto init = reinterpret_cast<decltype(::INITIALIZE_CDM_MODULE)*>(
     PR_FindFunctionSymbol(mLib, STRINGIFY(INITIALIZE_CDM_MODULE)));
   if (!init) {
--- a/dom/media/gmp/widevine-adapter/WidevineUtils.cpp
+++ b/dom/media/gmp/widevine-adapter/WidevineUtils.cpp
@@ -7,39 +7,23 @@
 #include "WidevineDecryptor.h"
 
 #include "gmp-api/gmp-errors.h"
 #include <stdarg.h>
 #include <stdio.h>
 
 namespace mozilla {
 
-#ifdef ENABLE_WIDEVINE_LOG
-void
-Log(const char* aFormat, ...)
+namespace detail {
+LogModule* GetCDMLog()
 {
-  va_list ap;
-  va_start(ap, aFormat);
-  const size_t len = 1024;
-  char buf[len];
-  vsnprintf(buf, len, aFormat, ap);
-  va_end(ap);
-  if (getenv("GMP_LOG_FILE")) {
-    FILE* f = fopen(getenv("GMP_LOG_FILE"), "a");
-    if (f) {
-      fprintf(f, "%s\n", buf);
-      fflush(f);
-      fclose(f);
-      f = nullptr;
-    }
-  } else {
-    printf("LOG: %s\n", buf);
-  }
+  static LazyLogModule sLog("CDM");
+  return sLog;
 }
-#endif // ENABLE_WIDEVINE_LOG
+} // namespace detail
 
 GMPErr
 ToGMPErr(cdm::Status aStatus)
 {
   switch (aStatus) {
     case cdm::kSuccess: return GMPNoErr;
     case cdm::kNeedMoreData: return GMPGenericErr;
     case cdm::kNoKey: return GMPNoKeyErr;
--- a/dom/media/gmp/widevine-adapter/WidevineUtils.h
+++ b/dom/media/gmp/widevine-adapter/WidevineUtils.h
@@ -7,28 +7,25 @@
 #define WidevineUtils_h_
 
 #include "stddef.h"
 #include "content_decryption_module.h"
 #include "gmp-api/gmp-decryption.h"
 #include "gmp-api/gmp-platform.h"
 #include "nsISupportsImpl.h"
 #include "nsTArray.h"
+#include "mozilla/Logging.h"
 
 namespace mozilla {
 
-// Uncomment for logging...
-//#define ENABLE_WIDEVINE_LOG 1
-#ifdef ENABLE_WIDEVINE_LOG
-void
-Log(const char* aFormat, ...);
-#else
-#define Log(...)
-#endif // ENABLE_WIDEVINE_LOG
+namespace detail {
+LogModule* GetCDMLog();
+} // namespace detail
 
+#define Log(...) MOZ_LOG(detail::GetCDMLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
 
 #define ENSURE_TRUE(condition, rv) { \
   if (!(condition)) {\
     Log("ENSURE_TRUE FAILED %s:%d", __FILE__, __LINE__); \
     return rv; \
   } \
 } \