baseparse: fix draining with less data than min frame size available
authorTim-Philipp Müller <tim@centricular.com>
Sat, 29 Oct 2016 10:17:38 +0000 (11:17 +0100)
committerSebastian Dröge <sebastian@centricular.com>
Tue, 1 Nov 2016 18:33:56 +0000 (20:33 +0200)
baseparse would pass whatever is left in the adapter to the
subclass when draining, even if it's less than the minimum
frame size required. This is bogus, baseparse should just
discard that data then. The original intention of that code
seems to have been that if we have more data available than
the minimum required we should pass all of the data available
and not just the minimum required, which does make sense, so
we'll continue to do that in the case that more data is available.

Fixes assertions in rawvideoparse on EOS after not-negotiated with
fakesrc sizetype=random ! queue ! rawvideoparse format=rgb ! appsink caps=video/x-raw,format=I420

https://bugzilla.gnome.org/show_bug.cgi?id=773666

libs/gst/base/gstbaseparse.c

index 816b7ab..168b81b 100644 (file)
@@ -3184,9 +3184,17 @@ gst_base_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
     av = gst_adapter_available (parse->priv->adapter);
 
     if (G_UNLIKELY (parse->priv->drain)) {
-      min_size = av;
-      GST_DEBUG_OBJECT (parse, "draining, data left: %d", min_size);
-      if (G_UNLIKELY (!min_size)) {
+      GST_DEBUG_OBJECT (parse, "draining, data left: %u, min %u", av, min_size);
+      /* pass all available data to subclass, not just the minimum,
+       * but never pass less than the minimum required to the subclass */
+      if (av >= min_size) {
+        min_size = av;
+        if (G_UNLIKELY (!min_size))
+          goto done;
+      } else if (av > 0) {
+        GST_DEBUG_OBJECT (parse, "draining, but not enough data available, "
+            "discarding %u bytes", av);
+        gst_adapter_clear (parse->priv->adapter);
         goto done;
       }
     }