From f3820b61a181d12c3b3e36234e2c8336683b9daf 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 function to matroska-read-common.[ch] from matroska-demux.c and matroska-parse.c: - gst_matroska_{demux,parse}_peek_adapter https://bugzilla.gnome.org/show_bug.cgi?id=650877 --- gst/matroska/matroska-demux.c | 33 ++++++++++++++------------------- gst/matroska/matroska-demux.h | 3 --- gst/matroska/matroska-parse.c | 29 ++++++++++++----------------- gst/matroska/matroska-parse.h | 3 --- gst/matroska/matroska-read-common.c | 7 +++++++ gst/matroska/matroska-read-common.h | 6 ++++++ 6 files changed, 39 insertions(+), 42 deletions(-) diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c index 3b20acc..31bafbf 100644 --- a/gst/matroska/matroska-demux.c +++ b/gst/matroska/matroska-demux.c @@ -209,7 +209,7 @@ gst_matroska_demux_finalize (GObject * object) demux->global_tags = NULL; } - g_object_unref (demux->adapter); + g_object_unref (demux->common.adapter); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -262,7 +262,7 @@ gst_matroska_demux_init (GstMatroskaDemux * demux, demux->common.index = NULL; demux->global_tags = NULL; - demux->adapter = gst_adapter_new (); + demux->common.adapter = gst_adapter_new (); /* finish off */ gst_matroska_demux_reset (GST_ELEMENT (demux)); @@ -4820,8 +4820,8 @@ gst_matroska_demux_flush (GstMatroskaDemux * demux, guint flush) ret = gst_matroska_demux_check_read_size (demux, flush); if (ret != GST_FLOW_OK) return ret; - if (flush <= gst_adapter_available (demux->adapter)) - gst_adapter_flush (demux->adapter, flush); + if (flush <= gst_adapter_available (demux->common.adapter)) + gst_adapter_flush (demux->common.adapter, flush); else return GST_FLOW_UNEXPECTED; } @@ -4853,8 +4853,8 @@ gst_matroska_demux_take (GstMatroskaDemux * demux, guint64 bytes, goto exit; } if (demux->streaming) { - if (gst_adapter_available (demux->adapter) >= bytes) - buffer = gst_adapter_take_buffer (demux->adapter, bytes); + if (gst_adapter_available (demux->common.adapter) >= bytes) + buffer = gst_adapter_take_buffer (demux->common.adapter, bytes); else ret = GST_FLOW_UNEXPECTED; } else @@ -5399,19 +5399,14 @@ perform_seek_to_offset (GstMatroskaDemux * demux, guint64 offset) return res; } -static const guint8 * -gst_matroska_demux_peek_adapter (GstMatroskaDemux * demux, guint peek) -{ - return gst_adapter_peek (demux->adapter, peek); -} - 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_demux_peek_adapter, (gpointer) demux, - GST_ELEMENT_CAST (demux), demux->common.offset); + (GstPeekData) gst_matroska_read_common_peek_adapter, + (gpointer) (&demux->common), GST_ELEMENT_CAST (demux), + demux->common.offset); } static GstFlowReturn @@ -5426,17 +5421,17 @@ gst_matroska_demux_chain (GstPad * pad, GstBuffer * buffer) if (G_UNLIKELY (GST_BUFFER_IS_DISCONT (buffer))) { GST_DEBUG_OBJECT (demux, "got DISCONT"); - gst_adapter_clear (demux->adapter); + gst_adapter_clear (demux->common.adapter); GST_OBJECT_LOCK (demux); gst_matroska_demux_reset_streams (demux, GST_CLOCK_TIME_NONE, FALSE); GST_OBJECT_UNLOCK (demux); } - gst_adapter_push (demux->adapter, buffer); + gst_adapter_push (demux->common.adapter, buffer); buffer = NULL; next: - available = gst_adapter_available (demux->adapter); + available = gst_adapter_available (demux->common.adapter); ret = gst_matroska_demux_peek_id_length_push (demux, &id, &length, &needed); if (G_UNLIKELY (ret != GST_FLOW_OK && ret != GST_FLOW_UNEXPECTED)) @@ -5501,7 +5496,7 @@ gst_matroska_demux_handle_sink_event (GstPad * pad, GstEvent * event) GST_DEBUG_OBJECT (demux, "clearing segment state"); GST_OBJECT_LOCK (demux); /* clear current segment leftover */ - gst_adapter_clear (demux->adapter); + gst_adapter_clear (demux->common.adapter); /* and some streaming setup */ demux->common.offset = start; /* do not know where we are; @@ -5537,7 +5532,7 @@ gst_matroska_demux_handle_sink_event (GstPad * pad, GstEvent * event) } case GST_EVENT_FLUSH_STOP: { - gst_adapter_clear (demux->adapter); + gst_adapter_clear (demux->common.adapter); GST_OBJECT_LOCK (demux); gst_matroska_demux_reset_streams (demux, GST_CLOCK_TIME_NONE, TRUE); demux->segment.last_stop = GST_CLOCK_TIME_NONE; diff --git a/gst/matroska/matroska-demux.h b/gst/matroska/matroska-demux.h index 1b63a70..a234a40 100644 --- a/gst/matroska/matroska-demux.h +++ b/gst/matroska/matroska-demux.h @@ -24,7 +24,6 @@ #define __GST_MATROSKA_DEMUX_H__ #include -#include #include "ebml-read.h" #include "matroska-ids.h" @@ -92,8 +91,6 @@ typedef struct _GstMatroskaDemux { guint64 first_cluster_offset; guint64 next_cluster_offset; - /* push based mode usual suspects */ - GstAdapter *adapter; /* index stuff */ gboolean seekable; gboolean building_index; diff --git a/gst/matroska/matroska-parse.c b/gst/matroska/matroska-parse.c index 2b0fb02..07b3fe1 100644 --- a/gst/matroska/matroska-parse.c +++ b/gst/matroska/matroska-parse.c @@ -171,7 +171,7 @@ gst_matroska_parse_finalize (GObject * object) parse->global_tags = NULL; } - g_object_unref (parse->adapter); + g_object_unref (parse->common.adapter); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -231,7 +231,7 @@ gst_matroska_parse_init (GstMatroskaParse * parse, parse->common.index = NULL; parse->global_tags = NULL; - parse->adapter = gst_adapter_new (); + parse->common.adapter = gst_adapter_new (); /* finish off */ gst_matroska_parse_reset (GST_ELEMENT (parse)); @@ -3394,8 +3394,8 @@ gst_matroska_parse_take (GstMatroskaParse * parse, guint64 bytes, ret = GST_FLOW_ERROR; goto exit; } - if (gst_adapter_available (parse->adapter) >= bytes) - buffer = gst_adapter_take_buffer (parse->adapter, bytes); + if (gst_adapter_available (parse->common.adapter) >= bytes) + buffer = gst_adapter_take_buffer (parse->common.adapter, bytes); else ret = GST_FLOW_UNEXPECTED; if (G_LIKELY (buffer)) { @@ -4024,19 +4024,14 @@ perform_seek_to_offset (GstMatroskaParse * parse, guint64 offset) return res; } -static const guint8 * -gst_matroska_parse_peek_adapter (GstMatroskaParse * parse, guint peek) -{ - return gst_adapter_peek (parse->adapter, peek); -} - 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_parse_peek_adapter, (gpointer) parse, - GST_ELEMENT_CAST (parse), parse->common.offset); + (GstPeekData) gst_matroska_read_common_peek_adapter, + (gpointer) (&parse->common), GST_ELEMENT_CAST (parse), + parse->common.offset); } static GstFlowReturn @@ -4051,17 +4046,17 @@ gst_matroska_parse_chain (GstPad * pad, GstBuffer * buffer) if (G_UNLIKELY (GST_BUFFER_IS_DISCONT (buffer))) { GST_DEBUG_OBJECT (parse, "got DISCONT"); - gst_adapter_clear (parse->adapter); + gst_adapter_clear (parse->common.adapter); GST_OBJECT_LOCK (parse); gst_matroska_parse_reset_streams (parse, GST_CLOCK_TIME_NONE, FALSE); GST_OBJECT_UNLOCK (parse); } - gst_adapter_push (parse->adapter, buffer); + gst_adapter_push (parse->common.adapter, buffer); buffer = NULL; next: - available = gst_adapter_available (parse->adapter); + available = gst_adapter_available (parse->common.adapter); ret = gst_matroska_parse_peek_id_length_push (parse, &id, &length, &needed); if (G_UNLIKELY (ret != GST_FLOW_OK && ret != GST_FLOW_UNEXPECTED)) @@ -4125,7 +4120,7 @@ gst_matroska_parse_handle_sink_event (GstPad * pad, GstEvent * event) GST_DEBUG_OBJECT (parse, "clearing segment state"); /* clear current segment leftover */ - gst_adapter_clear (parse->adapter); + gst_adapter_clear (parse->common.adapter); /* and some streaming setup */ parse->common.offset = start; /* do not know where we are; @@ -4160,7 +4155,7 @@ gst_matroska_parse_handle_sink_event (GstPad * pad, GstEvent * event) } case GST_EVENT_FLUSH_STOP: { - gst_adapter_clear (parse->adapter); + gst_adapter_clear (parse->common.adapter); GST_OBJECT_LOCK (parse); gst_matroska_parse_reset_streams (parse, GST_CLOCK_TIME_NONE, TRUE); GST_OBJECT_UNLOCK (parse); diff --git a/gst/matroska/matroska-parse.h b/gst/matroska/matroska-parse.h index 3add6956..1772920 100644 --- a/gst/matroska/matroska-parse.h +++ b/gst/matroska/matroska-parse.h @@ -24,7 +24,6 @@ #define __GST_MATROSKA_PARSE_H__ #include -#include #include "ebml-read.h" #include "matroska-ids.h" @@ -94,8 +93,6 @@ typedef struct _GstMatroskaParse { guint64 first_cluster_offset; guint64 next_cluster_offset; - /* push based mode usual suspects */ - GstAdapter *adapter; /* index stuff */ gboolean seekable; gboolean building_index; diff --git a/gst/matroska/matroska-read-common.c b/gst/matroska/matroska-read-common.c index f1fb262..0d7b716 100644 --- a/gst/matroska/matroska-read-common.c +++ b/gst/matroska/matroska-read-common.c @@ -624,6 +624,13 @@ gst_matroska_read_common_parse_index (GstMatroskaReadCommon * common, return ret; } +const guint8 * +gst_matroska_read_common_peek_adapter (GstMatroskaReadCommon * common, guint + peek) +{ + return gst_adapter_peek (common->adapter, peek); +} + /* * Calls pull_range for (offset,size) without advancing our offset */ diff --git a/gst/matroska/matroska-read-common.h b/gst/matroska/matroska-read-common.h index bd715f0..3bd2b82 100644 --- a/gst/matroska/matroska-read-common.h +++ b/gst/matroska/matroska-read-common.h @@ -25,6 +25,7 @@ #include #include +#include #include "matroska-ids.h" @@ -68,6 +69,9 @@ typedef struct _GstMatroskaReadCommon { /* push and pull mode */ guint64 offset; + + /* push based mode usual suspects */ + GstAdapter *adapter; } GstMatroskaReadCommon; GstFlowReturn gst_matroska_decode_content_encodings (GArray * encodings); @@ -78,6 +82,8 @@ 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 * -- 2.7.4