From 2589f1cd2d64c792d8ba5e141f2042a349de4e54 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Mon, 23 May 2011 18:06:44 +0300 Subject: [PATCH] matroska: refactor code common to matroskademux and matroskaparse Move the following functions to matroska-read-common.[ch] from matroska-demux.c and matroska-parse.c: - gst_matroska_{demux,parse}_peek_id_length_pull - gst_matroska_{demux,parse}_peek_id_length_push https://bugzilla.gnome.org/show_bug.cgi?id=650877 --- gst/matroska/matroska-demux.c | 49 +++++++++++++------------------------ gst/matroska/matroska-parse.c | 37 ++++++++-------------------- gst/matroska/matroska-read-common.c | 22 +++++++++++++++-- gst/matroska/matroska-read-common.h | 10 +++++--- 4 files changed, 53 insertions(+), 65 deletions(-) diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c index 31bafbf..3de7172 100644 --- a/gst/matroska/matroska-demux.c +++ b/gst/matroska/matroska-demux.c @@ -461,16 +461,6 @@ gst_matroska_demux_reset (GstElement * element) } } -static GstFlowReturn -gst_matroska_demux_peek_id_length_pull (GstMatroskaDemux * demux, guint32 * _id, - guint64 * _length, guint * _needed) -{ - return gst_ebml_peek_id_length (_id, _length, _needed, - (GstPeekData) gst_matroska_read_common_peek_pull, - (gpointer) (&demux->common), GST_ELEMENT_CAST (demux), - demux->common.offset); -} - static gint64 gst_matroska_demux_get_length (GstMatroskaDemux * demux) { @@ -1865,8 +1855,8 @@ gst_matroska_demux_search_cluster (GstMatroskaDemux * demux, gint64 * pos) GST_DEBUG_OBJECT (demux, "cluster reported at offset %" G_GINT64_FORMAT, *cpos); demux->common.offset = *cpos; - ret = - gst_matroska_demux_peek_id_length_pull (demux, &id, &length, &needed); + ret = gst_matroska_read_common_peek_id_length_pull (&demux->common, + GST_ELEMENT_CAST (demux), &id, &length, &needed); if (ret == GST_FLOW_OK && id == GST_MATROSKA_ID_CLUSTER) { newpos = *cpos; goto exit; @@ -1905,8 +1895,8 @@ gst_matroska_demux_search_cluster (GstMatroskaDemux * demux, gint64 * pos) break; } demux->common.offset = newpos; - ret = - gst_matroska_demux_peek_id_length_pull (demux, &id, &length, &needed); + ret = gst_matroska_read_common_peek_id_length_pull (&demux->common, + GST_ELEMENT_CAST (demux), &id, &length, &needed); if (ret != GST_FLOW_OK) goto resume; g_assert (id == GST_MATROSKA_ID_CLUSTER); @@ -1919,8 +1909,8 @@ gst_matroska_demux_search_cluster (GstMatroskaDemux * demux, gint64 * pos) } /* skip cluster */ demux->common.offset += length + needed; - ret = - gst_matroska_demux_peek_id_length_pull (demux, &id, &length, &needed); + ret = gst_matroska_read_common_peek_id_length_pull (&demux->common, + GST_ELEMENT_CAST (demux), &id, &length, &needed); if (ret != GST_FLOW_OK) goto resume; GST_DEBUG_OBJECT (demux, "next element is %scluster", @@ -2035,7 +2025,8 @@ retry: guint64 cluster_size = 0; /* peek and parse some elements */ - ret = gst_matroska_demux_peek_id_length_pull (demux, &id, &length, &needed); + ret = gst_matroska_read_common_peek_id_length_pull (&demux->common, + GST_ELEMENT_CAST (demux), &id, &length, &needed); if (ret != GST_FLOW_OK) goto error; GST_LOG_OBJECT (demux, "Offset %" G_GUINT64_FORMAT ", Element id 0x%x, " @@ -4667,8 +4658,9 @@ gst_matroska_demux_parse_contents_seekentry (GstMatroskaDemux * demux, demux->common.offset = seek_pos + demux->common.ebml_segment_start; /* check ID */ - if ((ret = gst_matroska_demux_peek_id_length_pull (demux, &id, &length, - &needed)) != GST_FLOW_OK) + if ((ret = gst_matroska_read_common_peek_id_length_pull (&demux->common, + GST_ELEMENT_CAST (demux), &id, &length, &needed)) != + GST_FLOW_OK) goto finish; if (id != seek_id) { @@ -4924,7 +4916,8 @@ gst_matroska_demux_find_tracks (GstMatroskaDemux * demux) /* Search Tracks element */ while (TRUE) { - ret = gst_matroska_demux_peek_id_length_pull (demux, &id, &length, &needed); + ret = gst_matroska_read_common_peek_id_length_pull (&demux->common, + GST_ELEMENT_CAST (demux), &id, &length, &needed); if (ret != GST_FLOW_OK) break; @@ -5259,7 +5252,8 @@ gst_matroska_demux_loop (GstPad * pad) } } - ret = gst_matroska_demux_peek_id_length_pull (demux, &id, &length, &needed); + ret = gst_matroska_read_common_peek_id_length_pull (&demux->common, + GST_ELEMENT_CAST (demux), &id, &length, &needed); if (ret == GST_FLOW_UNEXPECTED) goto eos; if (ret != GST_FLOW_OK) { @@ -5400,16 +5394,6 @@ perform_seek_to_offset (GstMatroskaDemux * demux, guint64 offset) } static GstFlowReturn -gst_matroska_demux_peek_id_length_push (GstMatroskaDemux * demux, guint32 * _id, - guint64 * _length, guint * _needed) -{ - return gst_ebml_peek_id_length (_id, _length, _needed, - (GstPeekData) gst_matroska_read_common_peek_adapter, - (gpointer) (&demux->common), GST_ELEMENT_CAST (demux), - demux->common.offset); -} - -static GstFlowReturn gst_matroska_demux_chain (GstPad * pad, GstBuffer * buffer) { GstMatroskaDemux *demux = GST_MATROSKA_DEMUX (GST_PAD_PARENT (pad)); @@ -5433,7 +5417,8 @@ gst_matroska_demux_chain (GstPad * pad, GstBuffer * buffer) next: available = gst_adapter_available (demux->common.adapter); - ret = gst_matroska_demux_peek_id_length_push (demux, &id, &length, &needed); + ret = gst_matroska_read_common_peek_id_length_push (&demux->common, + GST_ELEMENT_CAST (demux), &id, &length, &needed); if (G_UNLIKELY (ret != GST_FLOW_OK && ret != GST_FLOW_UNEXPECTED)) return ret; diff --git a/gst/matroska/matroska-parse.c b/gst/matroska/matroska-parse.c index 07b3fe1..091992d 100644 --- a/gst/matroska/matroska-parse.c +++ b/gst/matroska/matroska-parse.c @@ -384,16 +384,6 @@ gst_matroska_parse_reset (GstElement * element) } } -static GstFlowReturn -gst_matroska_parse_peek_id_length_pull (GstMatroskaParse * parse, guint32 * _id, - guint64 * _length, guint * _needed) -{ - return gst_ebml_peek_id_length (_id, _length, _needed, - (GstPeekData) gst_matroska_read_common_peek_pull, - (gpointer) (&parse->common), GST_ELEMENT_CAST (parse), - parse->common.offset); -} - static gint64 gst_matroska_parse_get_length (GstMatroskaParse * parse) { @@ -1549,8 +1539,8 @@ gst_matroska_parse_search_cluster (GstMatroskaParse * parse, gint64 * pos) break; } parse->common.offset = newpos; - ret = - gst_matroska_parse_peek_id_length_pull (parse, &id, &length, &needed); + ret = gst_matroska_read_common_peek_id_length_pull (&parse->common, + GST_ELEMENT_CAST (parse), &id, &length, &needed); if (ret != GST_FLOW_OK) goto resume; g_assert (id == GST_MATROSKA_ID_CLUSTER); @@ -1563,8 +1553,8 @@ gst_matroska_parse_search_cluster (GstMatroskaParse * parse, gint64 * pos) } /* skip cluster */ parse->common.offset += length + needed; - ret = - gst_matroska_parse_peek_id_length_pull (parse, &id, &length, &needed); + ret = gst_matroska_read_common_peek_id_length_pull (&parse->common, + GST_ELEMENT_CAST (parse), &id, &length, &needed); if (ret != GST_FLOW_OK) goto resume; GST_DEBUG_OBJECT (parse, "next element is %scluster", @@ -3463,7 +3453,8 @@ gst_matroska_parse_find_tracks (GstMatroskaParse * parse) /* Search Tracks element */ while (TRUE) { - ret = gst_matroska_parse_peek_id_length_pull (parse, &id, &length, &needed); + ret = gst_matroska_read_common_peek_id_length_pull (&parse->common, + GST_ELEMENT_CAST (parse), &id, &length, &needed); if (ret != GST_FLOW_OK) break; @@ -3885,7 +3876,8 @@ gst_matroska_parse_loop (GstPad * pad) } } - ret = gst_matroska_parse_peek_id_length_pull (parse, &id, &length, &needed); + ret = gst_matroska_read_common_peek_id_length_pull (&parse->common, + GST_ELEMENT_CAST (parse), &id, &length, &needed); if (ret == GST_FLOW_UNEXPECTED) goto eos; if (ret != GST_FLOW_OK) { @@ -4025,16 +4017,6 @@ perform_seek_to_offset (GstMatroskaParse * parse, guint64 offset) } static GstFlowReturn -gst_matroska_parse_peek_id_length_push (GstMatroskaParse * parse, guint32 * _id, - guint64 * _length, guint * _needed) -{ - return gst_ebml_peek_id_length (_id, _length, _needed, - (GstPeekData) gst_matroska_read_common_peek_adapter, - (gpointer) (&parse->common), GST_ELEMENT_CAST (parse), - parse->common.offset); -} - -static GstFlowReturn gst_matroska_parse_chain (GstPad * pad, GstBuffer * buffer) { GstMatroskaParse *parse = GST_MATROSKA_PARSE (GST_PAD_PARENT (pad)); @@ -4058,7 +4040,8 @@ gst_matroska_parse_chain (GstPad * pad, GstBuffer * buffer) next: available = gst_adapter_available (parse->common.adapter); - ret = gst_matroska_parse_peek_id_length_push (parse, &id, &length, &needed); + ret = gst_matroska_read_common_peek_id_length_push (&parse->common, + GST_ELEMENT_CAST (parse), &id, &length, &needed); if (G_UNLIKELY (ret != GST_FLOW_OK && ret != GST_FLOW_UNEXPECTED)) return ret; diff --git a/gst/matroska/matroska-read-common.c b/gst/matroska/matroska-read-common.c index 0d7b716..28df40b 100644 --- a/gst/matroska/matroska-read-common.c +++ b/gst/matroska/matroska-read-common.c @@ -624,7 +624,7 @@ gst_matroska_read_common_parse_index (GstMatroskaReadCommon * common, return ret; } -const guint8 * +static const guint8 * gst_matroska_read_common_peek_adapter (GstMatroskaReadCommon * common, guint peek) { @@ -716,7 +716,7 @@ gst_matroska_read_common_peek_bytes (GstMatroskaReadCommon * common, guint64 return GST_FLOW_OK; } -const guint8 * +static const guint8 * gst_matroska_read_common_peek_pull (GstMatroskaReadCommon * common, guint peek) { guint8 *data = NULL; @@ -727,6 +727,24 @@ gst_matroska_read_common_peek_pull (GstMatroskaReadCommon * common, guint peek) } GstFlowReturn +gst_matroska_read_common_peek_id_length_pull (GstMatroskaReadCommon * common, + GstElement * el, guint32 * _id, guint64 * _length, guint * _needed) +{ + return gst_ebml_peek_id_length (_id, _length, _needed, + (GstPeekData) gst_matroska_read_common_peek_pull, (gpointer) common, el, + common->offset); +} + +GstFlowReturn +gst_matroska_read_common_peek_id_length_push (GstMatroskaReadCommon * common, + GstElement * el, guint32 * _id, guint64 * _length, guint * _needed) +{ + return gst_ebml_peek_id_length (_id, _length, _needed, + (GstPeekData) gst_matroska_read_common_peek_adapter, (gpointer) common, + el, common->offset); +} + +GstFlowReturn gst_matroska_read_common_read_track_encoding (GstMatroskaReadCommon * common, GstEbmlRead * ebml, GstMatroskaTrackContext * context) { diff --git a/gst/matroska/matroska-read-common.h b/gst/matroska/matroska-read-common.h index 3bd2b82..daa3793 100644 --- a/gst/matroska/matroska-read-common.h +++ b/gst/matroska/matroska-read-common.h @@ -82,12 +82,14 @@ GstFlowReturn gst_matroska_read_common_parse_index (GstMatroskaReadCommon * common, GstEbmlRead * ebml); GstFlowReturn gst_matroska_read_common_parse_skip (GstMatroskaReadCommon * common, GstEbmlRead * ebml, const gchar * parent_name, guint id); -const guint8 * gst_matroska_read_common_peek_adapter (GstMatroskaReadCommon * - common, guint peek); GstFlowReturn gst_matroska_read_common_peek_bytes (GstMatroskaReadCommon * common, guint64 offset, guint size, GstBuffer ** p_buf, guint8 ** bytes); -const guint8 * gst_matroska_read_common_peek_pull (GstMatroskaReadCommon * - common, guint peek); +GstFlowReturn gst_matroska_read_common_peek_id_length_pull (GstMatroskaReadCommon * + common, GstElement * el, guint32 * _id, guint64 * _length, guint * + _needed); +GstFlowReturn gst_matroska_read_common_peek_id_length_push (GstMatroskaReadCommon * + common, GstElement * el, guint32 * _id, guint64 * _length, guint * + _needed); gint gst_matroska_read_common_stream_from_num (GstMatroskaReadCommon * common, guint track_num); GstFlowReturn gst_matroska_read_common_read_track_encoding ( -- 2.7.4