tagdemux: Properly propagate gst_pad_pull_range() errors

And don't consider FLUSHING an actual error, just stop in that case.

https://bugzilla.gnome.org/show_bug.cgi?id=796883
diff --git a/gst-libs/gst/tag/gsttagdemux.c b/gst-libs/gst/tag/gsttagdemux.c
index 8a127c8..f31d15e 100644
--- a/gst-libs/gst/tag/gsttagdemux.c
+++ b/gst-libs/gst/tag/gsttagdemux.c
@@ -1026,7 +1026,7 @@
 
 /* Read and interpret any end tag when activating in pull_range.
  * Returns FALSE if pad activation should fail. */
-static gboolean
+static GstFlowReturn
 gst_tag_demux_pull_end_tag (GstTagDemux * demux, GstTagList ** tags)
 {
   GstTagDemuxResult parse_ret;
@@ -1035,7 +1035,6 @@
   GstTagList *new_tags = NULL;
   GstBuffer *buffer = NULL;
   gboolean have_tag;
-  gboolean res = FALSE;
   guint64 offset;
   guint tagsize;
   gsize bsize;
@@ -1047,12 +1046,12 @@
 
   if (klass->min_end_size == 0) {
     GST_DEBUG_OBJECT (demux, "Not looking for tag at the end");
-    return TRUE;
+    return GST_FLOW_OK;
   }
 
   if (demux->priv->upstream_size < klass->min_end_size) {
     GST_DEBUG_OBJECT (demux, "File too small");
-    return TRUE;
+    return GST_FLOW_OK;
   }
 
   /* Pull enough to identify the tag and retrieve its total size */
@@ -1072,6 +1071,7 @@
   if (bsize < klass->min_end_size) {
     GST_DEBUG_OBJECT (demux, "Only managed to read %" G_GSIZE_FORMAT " bytes"
         "from file (required: %u bytes)", bsize, klass->min_end_size);
+    flow_ret = GST_FLOW_EOS;
     goto done;
   }
 
@@ -1079,6 +1079,7 @@
 
   if (!have_tag) {
     GST_DEBUG_OBJECT (demux, "Could not find tag at end");
+    flow_ret = GST_FLOW_OK;
     goto done;
   }
 
@@ -1114,6 +1115,7 @@
       if (bsize < tagsize) {
         GST_DEBUG_OBJECT (demux, "Only managed to read %" G_GSIZE_FORMAT
             " bytes from file", bsize);
+        flow_ret = GST_FLOW_EOS;
         goto done;
       }
     }
@@ -1130,13 +1132,13 @@
 
     switch (parse_ret) {
       case GST_TAG_DEMUX_RESULT_OK:
-        res = TRUE;
+        flow_ret = GST_FLOW_OK;
         demux->priv->strip_end = newsize;
         GST_DEBUG_OBJECT (demux, "Read tag at end, size %d",
             demux->priv->strip_end);
         break;
       case GST_TAG_DEMUX_RESULT_BROKEN_TAG:
-        res = TRUE;
+        flow_ret = GST_FLOW_OK;
         demux->priv->strip_end = newsize;
         GST_WARNING_OBJECT (demux, "Ignoring broken tag at end, size %d",
             demux->priv->strip_end);
@@ -1157,12 +1159,12 @@
     gst_tag_list_unref (new_tags);
   if (buffer)
     gst_buffer_unref (buffer);
-  return res;
+  return flow_ret;
 }
 
 /* Read and interpret any tag at the start when activating in
  * pull_range. Returns FALSE if pad activation should fail. */
-static gboolean
+static GstFlowReturn
 gst_tag_demux_pull_start_tag (GstTagDemux * demux, GstTagList ** tags)
 {
   GstTagDemuxResult parse_ret;
@@ -1171,7 +1173,6 @@
   GstTagList *new_tags = NULL;
   GstBuffer *buffer = NULL;
   gboolean have_tag;
-  gboolean res = FALSE;
   guint req, tagsize;
   gsize bsize;
 
@@ -1182,7 +1183,7 @@
 
   if (klass->min_start_size == 0) {
     GST_DEBUG_OBJECT (demux, "Not looking for tag at the beginning");
-    return TRUE;
+    return GST_FLOW_OK;
   }
 
   /* Handle tag at start. Try with 4kB to start with */
@@ -1201,6 +1202,7 @@
   if (bsize < klass->min_start_size) {
     GST_DEBUG_OBJECT (demux, "Only managed to read %" G_GSIZE_FORMAT
         " bytes from file - no tag in this file", bsize);
+    flow_ret = GST_FLOW_EOS;
     goto done;
   }
 
@@ -1208,7 +1210,7 @@
 
   if (!have_tag) {
     GST_DEBUG_OBJECT (demux, "Could not find start tag");
-    res = TRUE;
+    flow_ret = GST_FLOW_OK;
     goto done;
   }
 
@@ -1240,6 +1242,7 @@
             " bytes from file", bsize);
         GST_ELEMENT_ERROR (demux, STREAM, DECODE,
             (_("Failed to read tag: not enough data")), (NULL));
+        flow_ret = GST_FLOW_EOS;
         goto done;
       }
     }
@@ -1253,12 +1256,12 @@
 
     switch (parse_ret) {
       case GST_TAG_DEMUX_RESULT_OK:
-        res = TRUE;
+        flow_ret = GST_FLOW_OK;
         demux->priv->strip_start = newsize;
         GST_DEBUG_OBJECT (demux, "Read start tag of size %d", newsize);
         break;
       case GST_TAG_DEMUX_RESULT_BROKEN_TAG:
-        res = TRUE;
+        flow_ret = GST_FLOW_OK;
         demux->priv->strip_start = newsize;
         GST_WARNING_OBJECT (demux, "Ignoring broken start tag of size %d",
             demux->priv->strip_start);
@@ -1279,7 +1282,7 @@
     gst_tag_list_unref (new_tags);
   if (buffer)
     gst_buffer_unref (buffer);
-  return res;
+  return flow_ret;
 }
 
 /* This function operates similarly to gst_type_find_element_loop
@@ -1309,8 +1312,15 @@
   demux->priv->strip_end = 0;
 
   /* 1 - Read tags */
-  s_tag_ok = gst_tag_demux_pull_start_tag (demux, &start_tags);
-  e_tag_ok = gst_tag_demux_pull_end_tag (demux, &end_tags);
+  ret = gst_tag_demux_pull_start_tag (demux, &start_tags);
+  if (ret != GST_FLOW_OK && ret != GST_FLOW_EOS)
+    goto read_tag_error;
+  s_tag_ok = ret == GST_FLOW_OK;
+  ret = gst_tag_demux_pull_end_tag (demux, &end_tags);
+  if (ret != GST_FLOW_OK && ret != GST_FLOW_EOS)
+    goto read_tag_error;
+  e_tag_ok = ret == GST_FLOW_OK;
+  ret = GST_FLOW_OK;
 
   klass = GST_TAG_DEMUX_CLASS (G_OBJECT_GET_CLASS (demux));
 
@@ -1329,6 +1339,7 @@
   if (end_tags)
     gst_tag_list_unref (end_tags);
 
+  /* Only happens if both are EOS, i.e. not enough data could be read */
   if (!e_tag_ok && !s_tag_ok)
     goto no_tags;
 
@@ -1380,6 +1391,12 @@
         ("Could not get stream size"), (NULL));
     return GST_FLOW_ERROR;
   }
+read_tag_error:
+  {
+    if (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS)
+      GST_ELEMENT_FLOW_ERROR (demux, ret);
+    return ret;
+  }
 no_tags:
   {
     GST_ELEMENT_ERROR (demux, STREAM, TYPE_NOT_FOUND,