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
--- 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; \
} \
} \