mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 02:31:03 +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_index_seek_find - gst_matroska{demux,parse}_do_index_seek https://bugzilla.gnome.org/show_bug.cgi?id=650877
This commit is contained in:
parent
1a6e658444
commit
eeb4d19992
4 changed files with 53 additions and 94 deletions
|
@ -1445,52 +1445,6 @@ gst_matroska_demux_handle_src_query (GstPad * pad, GstQuery * query)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static gint
|
||||
gst_matroska_index_seek_find (GstMatroskaIndex * i1, GstClockTime * time,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (i1->time < *time)
|
||||
return -1;
|
||||
else if (i1->time > *time)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static GstMatroskaIndex *
|
||||
gst_matroskademux_do_index_seek (GstMatroskaDemux * demux,
|
||||
GstMatroskaTrackContext * track, gint64 seek_pos, GArray ** _index,
|
||||
gint * _entry_index)
|
||||
{
|
||||
GstMatroskaIndex *entry = NULL;
|
||||
GArray *index;
|
||||
|
||||
if (!demux->common.index || !demux->common.index->len)
|
||||
return NULL;
|
||||
|
||||
/* find entry just before or at the requested position */
|
||||
if (track && track->index_table)
|
||||
index = track->index_table;
|
||||
else
|
||||
index = demux->common.index;
|
||||
|
||||
entry =
|
||||
gst_util_array_binary_search (index->data, index->len,
|
||||
sizeof (GstMatroskaIndex),
|
||||
(GCompareDataFunc) gst_matroska_index_seek_find, GST_SEARCH_MODE_BEFORE,
|
||||
&seek_pos, NULL);
|
||||
|
||||
if (entry == NULL)
|
||||
entry = &g_array_index (index, GstMatroskaIndex, 0);
|
||||
|
||||
if (_index)
|
||||
*_index = index;
|
||||
if (_entry_index)
|
||||
*_entry_index = entry - (GstMatroskaIndex *) index->data;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
/* takes ownership of taglist */
|
||||
static void
|
||||
gst_matroska_demux_found_global_tag (GstMatroskaDemux * demux,
|
||||
|
@ -2009,7 +1963,7 @@ gst_matroska_demux_handle_seek_event (GstMatroskaDemux * demux,
|
|||
/* check sanity before we start flushing and all that */
|
||||
GST_OBJECT_LOCK (demux);
|
||||
track = gst_matroska_demux_get_seek_track (demux, track);
|
||||
if ((entry = gst_matroskademux_do_index_seek (demux, track,
|
||||
if ((entry = gst_matroska_read_common_do_index_seek (&demux->common, track,
|
||||
seeksegment.last_stop, &demux->seek_index, &demux->seek_entry)) ==
|
||||
NULL) {
|
||||
/* pull mode without index can scan later on */
|
||||
|
|
|
@ -1197,52 +1197,6 @@ gst_matroska_parse_handle_src_query (GstPad * pad, GstQuery * query)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static gint
|
||||
gst_matroska_index_seek_find (GstMatroskaIndex * i1, GstClockTime * time,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (i1->time < *time)
|
||||
return -1;
|
||||
else if (i1->time > *time)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static GstMatroskaIndex *
|
||||
gst_matroskaparse_do_index_seek (GstMatroskaParse * parse,
|
||||
GstMatroskaTrackContext * track, gint64 seek_pos, GArray ** _index,
|
||||
gint * _entry_index)
|
||||
{
|
||||
GstMatroskaIndex *entry = NULL;
|
||||
GArray *index;
|
||||
|
||||
if (!parse->common.index || !parse->common.index->len)
|
||||
return NULL;
|
||||
|
||||
/* find entry just before or at the requested position */
|
||||
if (track && track->index_table)
|
||||
index = track->index_table;
|
||||
else
|
||||
index = parse->common.index;
|
||||
|
||||
entry =
|
||||
gst_util_array_binary_search (index->data, index->len,
|
||||
sizeof (GstMatroskaIndex),
|
||||
(GCompareDataFunc) gst_matroska_index_seek_find, GST_SEARCH_MODE_BEFORE,
|
||||
&seek_pos, NULL);
|
||||
|
||||
if (entry == NULL)
|
||||
entry = &g_array_index (index, GstMatroskaIndex, 0);
|
||||
|
||||
if (_index)
|
||||
*_index = index;
|
||||
if (_entry_index)
|
||||
*_entry_index = entry - (GstMatroskaIndex *) index->data;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
/* takes ownership of taglist */
|
||||
static void
|
||||
gst_matroska_parse_found_global_tag (GstMatroskaParse * parse,
|
||||
|
@ -1477,7 +1431,7 @@ gst_matroska_parse_handle_seek_event (GstMatroskaParse * parse,
|
|||
|
||||
/* check sanity before we start flushing and all that */
|
||||
GST_OBJECT_LOCK (parse);
|
||||
if ((entry = gst_matroskaparse_do_index_seek (parse, track,
|
||||
if ((entry = gst_matroska_read_common_do_index_seek (&parse->common, track,
|
||||
seeksegment.last_stop, &parse->seek_index, &parse->seek_entry)) ==
|
||||
NULL) {
|
||||
/* pull mode without index can scan later on */
|
||||
|
|
|
@ -342,6 +342,52 @@ gst_matroska_index_compare (GstMatroskaIndex * i1, GstMatroskaIndex * i2)
|
|||
return 0;
|
||||
}
|
||||
|
||||
gint
|
||||
gst_matroska_index_seek_find (GstMatroskaIndex * i1, GstClockTime * time,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (i1->time < *time)
|
||||
return -1;
|
||||
else if (i1->time > *time)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
GstMatroskaIndex *
|
||||
gst_matroska_read_common_do_index_seek (GstMatroskaReadCommon * common,
|
||||
GstMatroskaTrackContext * track, gint64 seek_pos, GArray ** _index,
|
||||
gint * _entry_index)
|
||||
{
|
||||
GstMatroskaIndex *entry = NULL;
|
||||
GArray *index;
|
||||
|
||||
if (!common->index || !common->index->len)
|
||||
return NULL;
|
||||
|
||||
/* find entry just before or at the requested position */
|
||||
if (track && track->index_table)
|
||||
index = track->index_table;
|
||||
else
|
||||
index = common->index;
|
||||
|
||||
entry =
|
||||
gst_util_array_binary_search (index->data, index->len,
|
||||
sizeof (GstMatroskaIndex),
|
||||
(GCompareDataFunc) gst_matroska_index_seek_find, GST_SEARCH_MODE_BEFORE,
|
||||
&seek_pos, NULL);
|
||||
|
||||
if (entry == NULL)
|
||||
entry = &g_array_index (index, GstMatroskaIndex, 0);
|
||||
|
||||
if (_index)
|
||||
*_index = index;
|
||||
if (_entry_index)
|
||||
*_entry_index = entry - (GstMatroskaIndex *) index->data;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
static gint
|
||||
gst_matroska_read_common_encoding_cmp (GstMatroskaTrackEncoding * a,
|
||||
GstMatroskaTrackEncoding * b)
|
||||
|
|
|
@ -77,6 +77,11 @@ typedef struct _GstMatroskaReadCommon {
|
|||
GstFlowReturn gst_matroska_decode_content_encodings (GArray * encodings);
|
||||
gboolean gst_matroska_decode_data (GArray * encodings, guint8 ** data_out,
|
||||
guint * size_out, GstMatroskaTrackEncodingScope scope, gboolean free);
|
||||
gint gst_matroska_index_seek_find (GstMatroskaIndex * i1, GstClockTime * time,
|
||||
gpointer user_data);
|
||||
GstMatroskaIndex * gst_matroska_read_common_do_index_seek (
|
||||
GstMatroskaReadCommon * common, GstMatroskaTrackContext * track, gint64
|
||||
seek_pos, GArray ** _index, gint * _entry_index);
|
||||
gint64 gst_matroska_read_common_get_length (GstMatroskaReadCommon * common);
|
||||
GstFlowReturn gst_matroska_read_common_parse_index (GstMatroskaReadCommon *
|
||||
common, GstEbmlRead * ebml);
|
||||
|
|
Loading…
Reference in a new issue