summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>2011-02-10 11:56:33 +0100
committerMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>2011-02-10 18:17:31 +0100
commitb70f4b6ffad984f76efc6f5916f7d8db42c9e496 (patch)
tree8fb3610a00bcb68e2672ec013cd5b69fa1416075
parent9de84b45bcbd43e2e96b0287355f5695bc911280 (diff)
matroskademux: store cluster positions provided by SeekHead
... and use those, if available, to locate a cluster rather than scanning.
-rw-r--r--gst/matroska/matroska-demux.c55
-rw-r--r--gst/matroska/matroska-demux.h2
2 files changed, 57 insertions, 0 deletions
diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c
index f1b2b783f..76431193c 100644
--- a/gst/matroska/matroska-demux.c
+++ b/gst/matroska/matroska-demux.c
@@ -401,2 +401,7 @@ gst_matroska_demux_reset (GstElement * element)
+ if (demux->clusters) {
+ g_array_free (demux->clusters, TRUE);
+ demux->clusters = NULL;
+ }
+
/* reset timers */
@@ -2328,2 +2333,13 @@ gst_matroska_demux_move_to_entry (GstMatroskaDemux * demux,
+static gint
+gst_matroska_cluster_compare (gint64 * i1, gint64 * i2)
+{
+ if (*i1 < *i2)
+ return -1;
+ else if (*i1 > *i2)
+ return 1;
+ else
+ return 0;
+}
+
/* searches for a cluster start from @pos,
@@ -2344,2 +2360,26 @@ gst_matroska_demux_search_cluster (GstMatroskaDemux * demux, gint64 * pos)
+ GST_LOG_OBJECT (demux, "searching cluster following offset %" G_GINT64_FORMAT,
+ *pos);
+
+ if (demux->clusters) {
+ gint64 *cpos;
+
+ cpos = gst_util_array_binary_search (demux->clusters->data,
+ demux->clusters->len, sizeof (gint64),
+ (GCompareDataFunc) gst_matroska_cluster_compare,
+ GST_SEARCH_MODE_AFTER, pos, NULL);
+ /* sanity check */
+ if (cpos) {
+ GST_DEBUG_OBJECT (demux,
+ "cluster reported at offset %" G_GINT64_FORMAT, *cpos);
+ demux->offset = *cpos;
+ ret =
+ gst_matroska_demux_peek_id_length_pull (demux, &id, &length, &needed);
+ if (ret == GST_FLOW_OK && id == GST_MATROSKA_ID_CLUSTER) {
+ newpos = *cpos;
+ goto exit;
+ }
+ }
+ }
+
/* read in at newpos and scan for ebml cluster id */
@@ -2412,2 +2452,3 @@ gst_matroska_demux_search_cluster (GstMatroskaDemux * demux, gint64 * pos)
+exit:
demux->offset = orig_offset;
@@ -5385,2 +5426,13 @@ gst_matroska_demux_parse_contents_seekentry (GstMatroskaDemux * demux,
+ case GST_MATROSKA_ID_CLUSTER:
+ {
+ guint64 pos = seek_pos + demux->ebml_segment_start;
+
+ GST_LOG_OBJECT (demux, "Cluster position");
+ if (G_UNLIKELY (!demux->clusters))
+ demux->clusters = g_array_sized_new (TRUE, TRUE, sizeof (guint64), 100);
+ g_array_append_val (demux->clusters, pos);
+ break;
+ }
+
default:
@@ -5431,2 +5483,5 @@ gst_matroska_demux_parse_contents (GstMatroskaDemux * demux, GstEbmlRead * ebml)
+ /* Sort clusters by position for easier searching */
+ g_array_sort (demux->clusters, (GCompareFunc) gst_matroska_cluster_compare);
+
return ret;
diff --git a/gst/matroska/matroska-demux.h b/gst/matroska/matroska-demux.h
index b31f79cb6..a35a5935a 100644
--- a/gst/matroska/matroska-demux.h
+++ b/gst/matroska/matroska-demux.h
@@ -94,2 +94,4 @@ typedef struct _GstMatroskaDemux {
GArray *index;
+ /* cluster positions (optional) */
+ GArray *clusters;