matroska: refactor code common to matroskademux and matroskaparse
authorDebarshi Ray <rishi@gnu.org>
Sat, 28 May 2011 05:29:09 +0000 (10:59 +0530)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Mon, 30 May 2011 05:56:54 +0000 (07:56 +0200)
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
gst/matroska/matroska-parse.c
gst/matroska/matroska-read-common.c
gst/matroska/matroska-read-common.h

index 70b9a54..cb5d3d1 100644 (file)
@@ -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 */
index b45ebea..04ccd71 100644 (file)
@@ -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 */
index cddb6ee..6ee04bd 100644 (file)
@@ -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)
index 94f21c1..8b49b7c 100644 (file)
@@ -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);