mpeg4videoparse: avoid stale parsing state
authorMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Tue, 17 May 2011 20:18:51 +0000 (22:18 +0200)
committerMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Mon, 23 May 2011 14:57:25 +0000 (16:57 +0200)
gst/mpeg4videoparse/mpeg4videoparse.c

index ebb818a..af8eb8f 100644 (file)
@@ -321,6 +321,10 @@ gst_mpeg4vparse_process_sc (GstMpeg4VParse * mp4vparse, GstBuffer * buf,
   return FALSE;
 }
 
+/* FIXME move into baseparse, or anything equivalent;
+ * see https://bugzilla.gnome.org/show_bug.cgi?id=650093 */
+#define GST_BASE_PARSE_FRAME_FLAG_PARSING   0x10000
+
 static gboolean
 gst_mpeg4vparse_check_valid_frame (GstBaseParse * parse,
     GstBaseParseFrame * frame, guint * framesize, gint * skipsize)
@@ -337,6 +341,15 @@ retry:
   if (G_UNLIKELY (GST_BUFFER_SIZE (buf) - off < 5))
     return FALSE;
 
+  /* avoid stale cached parsing state */
+  if (!(frame->flags & GST_BASE_PARSE_FRAME_FLAG_PARSING)) {
+    GST_LOG_OBJECT (mp4vparse, "parsing new frame");
+    gst_mpeg4vparse_reset_frame (mp4vparse);
+    frame->flags |= GST_BASE_PARSE_FRAME_FLAG_PARSING;
+  } else {
+    GST_LOG_OBJECT (mp4vparse, "resuming frame parsing");
+  }
+
   /* if already found a previous start code, e.g. start of frame, go for next */
   if (mp4vparse->last_sc >= 0) {
     off = mp4vparse->last_sc;
@@ -410,7 +423,6 @@ next:
 
   if (ret) {
     *framesize = off;
-    gst_mpeg4vparse_reset_frame (mp4vparse);
   } else {
     goto next;
   }