parse extradata field populated by FFMpeg and set subpicture screen size information...
authorVoyager-xbmc <patrick.middag@telenet.be>
Sun, 9 Jan 2011 15:37:17 +0000 (16:37 +0100)
committerCrystalP <CrystalP@xbmc.org>
Tue, 11 Jan 2011 08:34:13 +0000 (03:34 -0500)
(slightly edited by CrystalP in merge)

xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecFFmpeg.cpp

index 9c4761f..3acf8fe 100644 (file)
@@ -62,6 +62,43 @@ bool CDVDOverlayCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &optio
     m_pCodecContext->extradata_size = hints.extrasize;
     m_pCodecContext->extradata = (uint8_t*)m_dllAvUtil.av_mallocz(hints.extrasize + FF_INPUT_BUFFER_PADDING_SIZE);
     memcpy(m_pCodecContext->extradata, hints.extradata, hints.extrasize);
+
+    // start parsing of extra data - create a copy to be safe and make it zero-terminating to avoid access violations!
+    unsigned int parse_extrasize = hints.extrasize;
+    char* parse_extra = new char[parse_extrasize + 1];
+    memcpy(parse_extra, hints.extradata, parse_extrasize);
+    parse_extra[parse_extrasize] = '\0';
+
+    // assume that the extra data is formatted as a concatenation of lines ('\n' terminated) 
+    char *ptr = parse_extra;
+    do // read line by line
+    {
+      if (!strncmp(ptr, "size:", 5))
+      {
+        int width = 0, height = 0;
+        sscanf(ptr, "size: %dx%d", &width, &height);
+        if (width > 0 && height > 0)
+        {
+          m_pCodecContext->width = width;
+          m_pCodecContext->height = height;
+          CLog::Log(LOGDEBUG,"%s - parsed extradata: size: %d x %d", __FUNCTION__,  width, height);
+        }
+      }
+      /*        
+      // leaving commented code: these items don't work yet... but they may be meaningful
+      if (!strncmp(ptr, "palette:", 8))
+        if (sscanf(ptr, "palette: %x, %x, %x, %x, %x, %x, %x, %x,"
+                                " %x, %x, %x, %x, %x, %x, %x, %x", ...        
+      if (!strncasecmp(ptr, "forced subs: on", 15))
+        forced_subs_only = 1;
+      */
+      // if tried all possibilities, then read newline char and move to next line
+      ptr = strchr(ptr, '\n');
+      if (ptr != NULL) ptr++;
+    } 
+    while (ptr != NULL && ptr <= parse_extra + parse_extrasize);
+
+    delete[] parse_extra;
   }
 
   AVCodec* pCodec = m_dllAvCodec.avcodec_find_decoder(hints.codec);