mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-09-16 17:10:35 +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
|
static gint64
|
||||||
gst_matroska_demux_get_length (GstMatroskaDemux * demux)
|
gst_matroska_demux_get_length (GstMatroskaDemux * demux)
|
||||||
{
|
{
|
||||||
|
@ -1865,8 +1855,8 @@ gst_matroska_demux_search_cluster (GstMatroskaDemux * demux, gint64 * pos)
|
||||||
GST_DEBUG_OBJECT (demux,
|
GST_DEBUG_OBJECT (demux,
|
||||||
"cluster reported at offset %" G_GINT64_FORMAT, *cpos);
|
"cluster reported at offset %" G_GINT64_FORMAT, *cpos);
|
||||||
demux->common.offset = *cpos;
|
demux->common.offset = *cpos;
|
||||||
ret =
|
ret = gst_matroska_read_common_peek_id_length_pull (&demux->common,
|
||||||
gst_matroska_demux_peek_id_length_pull (demux, &id, &length, &needed);
|
GST_ELEMENT_CAST (demux), &id, &length, &needed);
|
||||||
if (ret == GST_FLOW_OK && id == GST_MATROSKA_ID_CLUSTER) {
|
if (ret == GST_FLOW_OK && id == GST_MATROSKA_ID_CLUSTER) {
|
||||||
newpos = *cpos;
|
newpos = *cpos;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -1905,8 +1895,8 @@ gst_matroska_demux_search_cluster (GstMatroskaDemux * demux, gint64 * pos)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
demux->common.offset = newpos;
|
demux->common.offset = newpos;
|
||||||
ret =
|
ret = gst_matroska_read_common_peek_id_length_pull (&demux->common,
|
||||||
gst_matroska_demux_peek_id_length_pull (demux, &id, &length, &needed);
|
GST_ELEMENT_CAST (demux), &id, &length, &needed);
|
||||||
if (ret != GST_FLOW_OK)
|
if (ret != GST_FLOW_OK)
|
||||||
goto resume;
|
goto resume;
|
||||||
g_assert (id == GST_MATROSKA_ID_CLUSTER);
|
g_assert (id == GST_MATROSKA_ID_CLUSTER);
|
||||||
|
@ -1919,8 +1909,8 @@ gst_matroska_demux_search_cluster (GstMatroskaDemux * demux, gint64 * pos)
|
||||||
}
|
}
|
||||||
/* skip cluster */
|
/* skip cluster */
|
||||||
demux->common.offset += length + needed;
|
demux->common.offset += length + needed;
|
||||||
ret =
|
ret = gst_matroska_read_common_peek_id_length_pull (&demux->common,
|
||||||
gst_matroska_demux_peek_id_length_pull (demux, &id, &length, &needed);
|
GST_ELEMENT_CAST (demux), &id, &length, &needed);
|
||||||
if (ret != GST_FLOW_OK)
|
if (ret != GST_FLOW_OK)
|
||||||
goto resume;
|
goto resume;
|
||||||
GST_DEBUG_OBJECT (demux, "next element is %scluster",
|
GST_DEBUG_OBJECT (demux, "next element is %scluster",
|
||||||
|
@ -2035,7 +2025,8 @@ retry:
|
||||||
guint64 cluster_size = 0;
|
guint64 cluster_size = 0;
|
||||||
|
|
||||||
/* peek and parse some elements */
|
/* 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)
|
if (ret != GST_FLOW_OK)
|
||||||
goto error;
|
goto error;
|
||||||
GST_LOG_OBJECT (demux, "Offset %" G_GUINT64_FORMAT ", Element id 0x%x, "
|
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;
|
demux->common.offset = seek_pos + demux->common.ebml_segment_start;
|
||||||
|
|
||||||
/* check ID */
|
/* check ID */
|
||||||
if ((ret = gst_matroska_demux_peek_id_length_pull (demux, &id, &length,
|
if ((ret = gst_matroska_read_common_peek_id_length_pull (&demux->common,
|
||||||
&needed)) != GST_FLOW_OK)
|
GST_ELEMENT_CAST (demux), &id, &length, &needed)) !=
|
||||||
|
GST_FLOW_OK)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
if (id != seek_id) {
|
if (id != seek_id) {
|
||||||
|
@ -4924,7 +4916,8 @@ gst_matroska_demux_find_tracks (GstMatroskaDemux * demux)
|
||||||
|
|
||||||
/* Search Tracks element */
|
/* Search Tracks element */
|
||||||
while (TRUE) {
|
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)
|
if (ret != GST_FLOW_OK)
|
||||||
break;
|
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)
|
if (ret == GST_FLOW_UNEXPECTED)
|
||||||
goto eos;
|
goto eos;
|
||||||
if (ret != GST_FLOW_OK) {
|
if (ret != GST_FLOW_OK) {
|
||||||
|
@ -5399,16 +5393,6 @@ perform_seek_to_offset (GstMatroskaDemux * demux, guint64 offset)
|
||||||
return res;
|
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
|
static GstFlowReturn
|
||||||
gst_matroska_demux_chain (GstPad * pad, GstBuffer * buffer)
|
gst_matroska_demux_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
|
@ -5433,7 +5417,8 @@ gst_matroska_demux_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
next:
|
next:
|
||||||
available = gst_adapter_available (demux->common.adapter);
|
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))
|
if (G_UNLIKELY (ret != GST_FLOW_OK && ret != GST_FLOW_UNEXPECTED))
|
||||||
return ret;
|
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
|
static gint64
|
||||||
gst_matroska_parse_get_length (GstMatroskaParse * parse)
|
gst_matroska_parse_get_length (GstMatroskaParse * parse)
|
||||||
{
|
{
|
||||||
|
@ -1549,8 +1539,8 @@ gst_matroska_parse_search_cluster (GstMatroskaParse * parse, gint64 * pos)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
parse->common.offset = newpos;
|
parse->common.offset = newpos;
|
||||||
ret =
|
ret = gst_matroska_read_common_peek_id_length_pull (&parse->common,
|
||||||
gst_matroska_parse_peek_id_length_pull (parse, &id, &length, &needed);
|
GST_ELEMENT_CAST (parse), &id, &length, &needed);
|
||||||
if (ret != GST_FLOW_OK)
|
if (ret != GST_FLOW_OK)
|
||||||
goto resume;
|
goto resume;
|
||||||
g_assert (id == GST_MATROSKA_ID_CLUSTER);
|
g_assert (id == GST_MATROSKA_ID_CLUSTER);
|
||||||
|
@ -1563,8 +1553,8 @@ gst_matroska_parse_search_cluster (GstMatroskaParse * parse, gint64 * pos)
|
||||||
}
|
}
|
||||||
/* skip cluster */
|
/* skip cluster */
|
||||||
parse->common.offset += length + needed;
|
parse->common.offset += length + needed;
|
||||||
ret =
|
ret = gst_matroska_read_common_peek_id_length_pull (&parse->common,
|
||||||
gst_matroska_parse_peek_id_length_pull (parse, &id, &length, &needed);
|
GST_ELEMENT_CAST (parse), &id, &length, &needed);
|
||||||
if (ret != GST_FLOW_OK)
|
if (ret != GST_FLOW_OK)
|
||||||
goto resume;
|
goto resume;
|
||||||
GST_DEBUG_OBJECT (parse, "next element is %scluster",
|
GST_DEBUG_OBJECT (parse, "next element is %scluster",
|
||||||
|
@ -3463,7 +3453,8 @@ gst_matroska_parse_find_tracks (GstMatroskaParse * parse)
|
||||||
|
|
||||||
/* Search Tracks element */
|
/* Search Tracks element */
|
||||||
while (TRUE) {
|
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)
|
if (ret != GST_FLOW_OK)
|
||||||
break;
|
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)
|
if (ret == GST_FLOW_UNEXPECTED)
|
||||||
goto eos;
|
goto eos;
|
||||||
if (ret != GST_FLOW_OK) {
|
if (ret != GST_FLOW_OK) {
|
||||||
|
@ -4024,16 +4016,6 @@ perform_seek_to_offset (GstMatroskaParse * parse, guint64 offset)
|
||||||
return res;
|
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
|
static GstFlowReturn
|
||||||
gst_matroska_parse_chain (GstPad * pad, GstBuffer * buffer)
|
gst_matroska_parse_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
|
@ -4058,7 +4040,8 @@ gst_matroska_parse_chain (GstPad * pad, GstBuffer * buffer)
|
||||||
next:
|
next:
|
||||||
available = gst_adapter_available (parse->common.adapter);
|
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))
|
if (G_UNLIKELY (ret != GST_FLOW_OK && ret != GST_FLOW_UNEXPECTED))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
|
@ -624,7 +624,7 @@ gst_matroska_read_common_parse_index (GstMatroskaReadCommon * common,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const guint8 *
|
static const guint8 *
|
||||||
gst_matroska_read_common_peek_adapter (GstMatroskaReadCommon * common, guint
|
gst_matroska_read_common_peek_adapter (GstMatroskaReadCommon * common, guint
|
||||||
peek)
|
peek)
|
||||||
{
|
{
|
||||||
|
@ -716,7 +716,7 @@ gst_matroska_read_common_peek_bytes (GstMatroskaReadCommon * common, guint64
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
const guint8 *
|
static const guint8 *
|
||||||
gst_matroska_read_common_peek_pull (GstMatroskaReadCommon * common, guint peek)
|
gst_matroska_read_common_peek_pull (GstMatroskaReadCommon * common, guint peek)
|
||||||
{
|
{
|
||||||
guint8 *data = NULL;
|
guint8 *data = NULL;
|
||||||
|
@ -726,6 +726,24 @@ gst_matroska_read_common_peek_pull (GstMatroskaReadCommon * common, guint peek)
|
||||||
return data;
|
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
|
GstFlowReturn
|
||||||
gst_matroska_read_common_read_track_encoding (GstMatroskaReadCommon * common,
|
gst_matroska_read_common_read_track_encoding (GstMatroskaReadCommon * common,
|
||||||
GstEbmlRead * ebml, GstMatroskaTrackContext * context)
|
GstEbmlRead * ebml, GstMatroskaTrackContext * context)
|
||||||
|
|
|
@ -82,12 +82,14 @@ GstFlowReturn gst_matroska_read_common_parse_index (GstMatroskaReadCommon *
|
||||||
common, GstEbmlRead * ebml);
|
common, GstEbmlRead * ebml);
|
||||||
GstFlowReturn gst_matroska_read_common_parse_skip (GstMatroskaReadCommon *
|
GstFlowReturn gst_matroska_read_common_parse_skip (GstMatroskaReadCommon *
|
||||||
common, GstEbmlRead * ebml, const gchar * parent_name, guint id);
|
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 *
|
GstFlowReturn gst_matroska_read_common_peek_bytes (GstMatroskaReadCommon *
|
||||||
common, guint64 offset, guint size, GstBuffer ** p_buf, guint8 ** bytes);
|
common, guint64 offset, guint size, GstBuffer ** p_buf, guint8 ** bytes);
|
||||||
const guint8 * gst_matroska_read_common_peek_pull (GstMatroskaReadCommon *
|
GstFlowReturn gst_matroska_read_common_peek_id_length_pull (GstMatroskaReadCommon *
|
||||||
common, guint peek);
|
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,
|
gint gst_matroska_read_common_stream_from_num (GstMatroskaReadCommon * common,
|
||||||
guint track_num);
|
guint track_num);
|
||||||
GstFlowReturn gst_matroska_read_common_read_track_encoding (
|
GstFlowReturn gst_matroska_read_common_read_track_encoding (
|
||||||
|
|
Loading…
Reference in a new issue