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
This commit is contained in:
Sebastian Dröge 2018-07-27 15:15:34 +03:00
parent eadedc68f8
commit 2f497ed217

View file

@ -1036,7 +1036,7 @@ gst_tag_demux_srcpad_event (GstPad * pad, GstObject * parent, GstEvent * event)
/* 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;
@ -1045,7 +1045,6 @@ gst_tag_demux_pull_end_tag (GstTagDemux * demux, GstTagList ** tags)
GstTagList *new_tags = NULL;
GstBuffer *buffer = NULL;
gboolean have_tag;
gboolean res = FALSE;
guint64 offset;
guint tagsize;
gsize bsize;
@ -1057,12 +1056,12 @@ gst_tag_demux_pull_end_tag (GstTagDemux * demux, GstTagList ** tags)
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 */
@ -1082,6 +1081,7 @@ gst_tag_demux_pull_end_tag (GstTagDemux * demux, GstTagList ** tags)
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;
}
@ -1089,6 +1089,7 @@ gst_tag_demux_pull_end_tag (GstTagDemux * demux, GstTagList ** tags)
if (!have_tag) {
GST_DEBUG_OBJECT (demux, "Could not find tag at end");
flow_ret = GST_FLOW_OK;
goto done;
}
@ -1124,6 +1125,7 @@ gst_tag_demux_pull_end_tag (GstTagDemux * demux, GstTagList ** tags)
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;
}
}
@ -1140,13 +1142,13 @@ gst_tag_demux_pull_end_tag (GstTagDemux * demux, GstTagList ** tags)
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);
@ -1167,12 +1169,12 @@ done:
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;
@ -1181,7 +1183,6 @@ gst_tag_demux_pull_start_tag (GstTagDemux * demux, GstTagList ** tags)
GstTagList *new_tags = NULL;
GstBuffer *buffer = NULL;
gboolean have_tag;
gboolean res = FALSE;
guint req, tagsize;
gsize bsize;
@ -1192,7 +1193,7 @@ gst_tag_demux_pull_start_tag (GstTagDemux * demux, GstTagList ** tags)
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 */
@ -1211,6 +1212,7 @@ gst_tag_demux_pull_start_tag (GstTagDemux * demux, GstTagList ** tags)
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;
}
@ -1218,7 +1220,7 @@ gst_tag_demux_pull_start_tag (GstTagDemux * demux, GstTagList ** tags)
if (!have_tag) {
GST_DEBUG_OBJECT (demux, "Could not find start tag");
res = TRUE;
flow_ret = GST_FLOW_OK;
goto done;
}
@ -1250,6 +1252,7 @@ gst_tag_demux_pull_start_tag (GstTagDemux * demux, GstTagList ** tags)
" 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;
}
}
@ -1263,12 +1266,12 @@ gst_tag_demux_pull_start_tag (GstTagDemux * demux, GstTagList ** tags)
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);
@ -1289,7 +1292,7 @@ done:
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
@ -1319,8 +1322,15 @@ gst_tag_demux_element_find (GstTagDemux * demux)
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));
@ -1339,6 +1349,7 @@ gst_tag_demux_element_find (GstTagDemux * demux)
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;
@ -1390,6 +1401,12 @@ no_size:
("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,