mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-12 10:25:33 +00:00
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
This commit is contained in:
parent
1f707ac3e0
commit
f3820b61a1
6 changed files with 39 additions and 42 deletions
|
@ -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;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#define __GST_MATROSKA_DEMUX_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/base/gstadapter.h>
|
||||
|
||||
#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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#define __GST_MATROSKA_PARSE_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/base/gstadapter.h>
|
||||
|
||||
#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;
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <glib.h>
|
||||
#include <gst/gst.h>
|
||||
#include <gst/base/gstadapter.h>
|
||||
|
||||
#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 *
|
||||
|
|
Loading…
Reference in a new issue