From 11b0a0effcf0e23d9abf8425f191b932188e3a74 Mon Sep 17 00:00:00 2001 From: Branko Subasic Date: Fri, 16 Sep 2011 15:03:23 +0200 Subject: [PATCH] matroskademux: Avoid sending EOS when in paused state Changed the ebml reader's gst_ebml_peek_id_length() function so that it returns the actual reason for why the peek failed, instead of (almost) always returning GST_FLOW_UNEXPECTED. This prevents the pulling task from sending EOS when doing a flushing seek. --- gst/matroska/ebml-read.c | 39 +++++++++++++---------------- gst/matroska/ebml-read.h | 2 +- gst/matroska/matroska-read-common.c | 12 ++++----- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/gst/matroska/ebml-read.c b/gst/matroska/ebml-read.c index c2dfa522a4..f6bf1348c9 100644 --- a/gst/matroska/ebml-read.c +++ b/gst/matroska/ebml-read.c @@ -60,6 +60,7 @@ gst_ebml_peek_id_length (guint32 * _id, guint64 * _length, guint * _needed, gint len_mask = 0x80, read = 1, n = 1, num_ffs = 0; guint64 total; guint8 b; + GstFlowReturn ret; g_return_val_if_fail (_id != NULL, GST_FLOW_ERROR); g_return_val_if_fail (_length != NULL, GST_FLOW_ERROR); @@ -71,10 +72,9 @@ gst_ebml_peek_id_length (guint32 * _id, guint64 * _length, guint * _needed, /* read element id */ needed = 2; - buf = peek (ctx, needed); - if (!buf) - goto not_enough_data; - + ret = peek (ctx, needed, &buf); + if (ret != GST_FLOW_OK) + goto peek_error; b = GST_READ_UINT8 (buf); total = (guint64) b; while (read <= 4 && !(total & len_mask)) { @@ -86,10 +86,9 @@ gst_ebml_peek_id_length (guint32 * _id, guint64 * _length, guint * _needed, /* need id and at least something for subsequent length */ needed = read + 1; - buf = peek (ctx, needed); - if (!buf) - goto not_enough_data; - + ret = peek (ctx, needed, &buf); + if (ret != GST_FLOW_OK) + goto peek_error; while (n < read) { b = GST_READ_UINT8 (buf + n); total = (total << 8) | b; @@ -112,10 +111,9 @@ gst_ebml_peek_id_length (guint32 * _id, guint64 * _length, guint * _needed, num_ffs++; needed += read - 1; - buf = peek (ctx, needed); - if (!buf) - goto not_enough_data; - + ret = peek (ctx, needed, &buf); + if (ret != GST_FLOW_OK) + goto peek_error; buf += (needed - read); n = 1; while (n < read) { @@ -137,10 +135,11 @@ gst_ebml_peek_id_length (guint32 * _id, guint64 * _length, guint * _needed, return GST_FLOW_OK; /* ERRORS */ -not_enough_data: +peek_error: { + GST_WARNING_OBJECT (el, "peek failed, ret = %d", ret); *_needed = needed; - return GST_FLOW_UNEXPECTED; + return ret; } invalid_id: { @@ -190,15 +189,13 @@ gst_ebml_read_clear (GstEbmlRead * ebml) ebml->el = NULL; } -static const guint8 * -gst_ebml_read_peek (GstByteReader * br, guint peek) +static GstFlowReturn +gst_ebml_read_peek (GstByteReader * br, guint peek, const guint8 ** data) { - const guint8 *data = NULL; - - if (G_LIKELY (gst_byte_reader_peek_data (br, peek, &data))) - return data; + if (G_LIKELY (gst_byte_reader_peek_data (br, peek, data))) + return GST_FLOW_OK; else - return NULL; + return GST_FLOW_UNEXPECTED; } static GstFlowReturn diff --git a/gst/matroska/ebml-read.h b/gst/matroska/ebml-read.h index b40c31d352..9db38f54ca 100644 --- a/gst/matroska/ebml-read.h +++ b/gst/matroska/ebml-read.h @@ -59,7 +59,7 @@ typedef struct _GstEbmlRead { GArray *readers; } GstEbmlRead; -typedef const guint8 * (*GstPeekData) (gpointer * context, guint peek); +typedef GstFlowReturn (*GstPeekData) (gpointer * context, guint peek, const guint8 ** data); /* returns UNEXPECTED if not enough data */ GstFlowReturn gst_ebml_peek_id_length (guint32 * _id, guint64 * _length, diff --git a/gst/matroska/matroska-read-common.c b/gst/matroska/matroska-read-common.c index 32b513e12b..672dcc3fc6 100644 --- a/gst/matroska/matroska-read-common.c +++ b/gst/matroska/matroska-read-common.c @@ -1639,14 +1639,12 @@ gst_matroska_read_common_peek_bytes (GstMatroskaReadCommon * common, guint64 return GST_FLOW_OK; } -static const guint8 * -gst_matroska_read_common_peek_pull (GstMatroskaReadCommon * common, guint peek) +static GstFlowReturn +gst_matroska_read_common_peek_pull (GstMatroskaReadCommon * common, guint peek, + guint8 ** data) { - guint8 *data = NULL; - - gst_matroska_read_common_peek_bytes (common, common->offset, peek, NULL, - &data); - return data; + return gst_matroska_read_common_peek_bytes (common, common->offset, peek, + NULL, data); } GstFlowReturn