From eeb4d19992f2a22faa5a0199e8eceb14a6926778 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Sat, 28 May 2011 10:59:09 +0530 Subject: [PATCH] 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 --- gst/matroska/matroska-demux.c | 48 +---------------------------- gst/matroska/matroska-parse.c | 48 +---------------------------- gst/matroska/matroska-read-common.c | 46 +++++++++++++++++++++++++++ gst/matroska/matroska-read-common.h | 5 +++ 4 files changed, 53 insertions(+), 94 deletions(-) diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c index 70b9a54a5b..cb5d3d14d9 100644 --- a/gst/matroska/matroska-demux.c +++ b/gst/matroska/matroska-demux.c @@ -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 */ diff --git a/gst/matroska/matroska-parse.c b/gst/matroska/matroska-parse.c index b45ebea7a1..04ccd710c6 100644 --- a/gst/matroska/matroska-parse.c +++ b/gst/matroska/matroska-parse.c @@ -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 */ diff --git a/gst/matroska/matroska-read-common.c b/gst/matroska/matroska-read-common.c index cddb6ee88b..6ee04bdbfd 100644 --- a/gst/matroska/matroska-read-common.c +++ b/gst/matroska/matroska-read-common.c @@ -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) diff --git a/gst/matroska/matroska-read-common.h b/gst/matroska/matroska-read-common.h index 94f21c163a..8b49b7ce43 100644 --- a/gst/matroska/matroska-read-common.h +++ b/gst/matroska/matroska-read-common.h @@ -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);