Bug 816741 - Add a callback function in WebMReader for nestegg logging r=kinetik
authorSteve Workman <sworkman@mozilla.com>
Mon, 17 Dec 2012 14:26:55 -0800
changeset 116328 f3de630ebd0d9f86e003c7fa06b0dc4d62e78942
parent 116327 6493a073d5ca4f37cb094d3c0d175a338c2a4d42
child 116329 e0fce89f61286f413457c93e49f9bfaff4b7a153
push id19859
push usersworkman@mozilla.com
push dateMon, 17 Dec 2012 22:27:17 +0000
treeherdermozilla-inbound@f3de630ebd0d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs816741
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 816741 - Add a callback function in WebMReader for nestegg logging r=kinetik
content/media/webm/WebMReader.cpp
--- a/content/media/webm/WebMReader.cpp
+++ b/content/media/webm/WebMReader.cpp
@@ -30,16 +30,17 @@ namespace mozilla {
 
 using namespace layers;
 
 // Un-comment to enable logging of seek bisections.
 //#define SEEK_LOGGING
 
 #ifdef PR_LOGGING
 extern PRLogModuleInfo* gMediaDecoderLog;
+PRLogModuleInfo* gNesteggLog;
 #define LOG(type, msg) PR_LOG(gMediaDecoderLog, type, msg)
 #ifdef SEEK_LOGGING
 #define SEEK_LOG(type, msg) PR_LOG(gMediaDecoderLog, type, msg)
 #else
 #define SEEK_LOG(type, msg)
 #endif
 #else
 #define LOG(type, msg)
@@ -97,16 +98,56 @@ static int64_t webm_tell(void *aUserData
 {
   NS_ASSERTION(aUserData, "aUserData must point to a valid AbstractMediaDecoder");
   AbstractMediaDecoder* decoder = reinterpret_cast<AbstractMediaDecoder*>(aUserData);
   MediaResource* resource = decoder->GetResource();
   NS_ASSERTION(resource, "Decoder has no media resource");
   return resource->Tell();
 }
 
+static void webm_log(nestegg * context,
+                     unsigned int severity,
+                     char const * format, ...)
+{
+#ifdef PR_LOGGING
+  va_list args;
+  char msg[256];
+  const char * sevStr;
+
+  switch(severity) {
+    case NESTEGG_LOG_DEBUG:
+      sevStr = "DBG";
+      break;
+    case NESTEGG_LOG_INFO:
+      sevStr = "INF";
+      break;
+    case NESTEGG_LOG_WARNING:
+      sevStr = "WRN";
+      break;
+    case NESTEGG_LOG_ERROR:
+      sevStr = "ERR";
+      break;
+    case NESTEGG_LOG_CRITICAL:
+      sevStr = "CRT";
+      break;
+    default:
+      sevStr = "UNK";
+      break;
+  }
+
+  va_start(args, format);
+
+  PR_snprintf(msg, sizeof(msg), "%p [Nestegg-%s] ", context, sevStr);
+  PR_vsnprintf(msg+strlen(msg), sizeof(msg)-strlen(msg), format, args);
+  PR_LOG(gNesteggLog, PR_LOG_DEBUG, (msg));
+
+  va_end(args);
+#endif
+}
+
 WebMReader::WebMReader(AbstractMediaDecoder* aDecoder)
 #ifdef MOZ_DASH
   : DASHRepReader(aDecoder),
 #else
   : MediaDecoderReader(aDecoder),
 #endif
   mContext(nullptr),
   mPacketCount(0),
@@ -123,16 +164,21 @@ WebMReader::WebMReader(AbstractMediaDeco
   mNextReader(nullptr),
   mSeekToCluster(-1),
   mCurrentOffset(-1),
   mPushVideoPacketToNextReader(false),
   mReachedSwitchAccessPoint(false)
 #endif
 {
   MOZ_COUNT_CTOR(WebMReader);
+#ifdef PR_LOGGING
+  if (!gNesteggLog) {
+    gNesteggLog = PR_NewLogModule("Nestegg");
+  }
+#endif
   // Zero these member vars to avoid crashes in VP8 destroy and Vorbis clear
   // functions when destructor is called before |Init|.
   memset(&mVP8, 0, sizeof(vpx_codec_ctx_t));
   memset(&mVorbisBlock, 0, sizeof(vorbis_block));
   memset(&mVorbisDsp, 0, sizeof(vorbis_dsp_state));
   memset(&mVorbisInfo, 0, sizeof(vorbis_info));
   memset(&mVorbisComment, 0, sizeof(vorbis_comment));
 }
@@ -227,17 +273,17 @@ nsresult WebMReader::ReadMetadata(VideoI
   io.seek = webm_seek;
   io.tell = webm_tell;
   io.userdata = mDecoder;
 #ifdef MOZ_DASH
   int64_t maxOffset = mInitByteRange.IsNull() ? -1 : mInitByteRange.mEnd;
 #else
   int64_t maxOffset = -1;
 #endif
-  int r = nestegg_init(&mContext, io, nullptr, maxOffset);
+  int r = nestegg_init(&mContext, io, &webm_log, maxOffset);
   if (r == -1) {
     return NS_ERROR_FAILURE;
   }
 
   uint64_t duration = 0;
   r = nestegg_duration(mContext, &duration);
   if (r == 0) {
     ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());