mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 11:10:37 +00:00
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
This commit is contained in:
parent
f3820b61a1
commit
2589f1cd2d
4 changed files with 53 additions and 65 deletions
|
@ -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) {
|
||||
|
@ -5399,16 +5393,6 @@ perform_seek_to_offset (GstMatroskaDemux * demux, guint64 offset)
|
|||
return res;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
@ -4024,16 +4016,6 @@ perform_seek_to_offset (GstMatroskaParse * parse, guint64 offset)
|
|||
return res;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -726,6 +726,24 @@ gst_matroska_read_common_peek_pull (GstMatroskaReadCommon * common, guint peek)
|
|||
return data;
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -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 (
|
||||
|
|
Loading…
Reference in a new issue