summaryrefslogtreecommitdiffstats
path: root/gst/qtdemux
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2009-05-04 12:35:19 +0200
committerWim Taymans <wim.taymans@collabora.co.uk>2009-05-04 12:35:19 +0200
commit70d1b6e1ae83107e9a94b02c6aa47ac0678fd88b (patch)
treed8acb27246416f25a2abd5f5f920c340af93458e /gst/qtdemux
parent9ea2c113bacfe8d13d0c6e4fd479cd2b1ca6c6f1 (diff)
qtdemux: use binary search for index
Use the new binary search method for finding the right index entry faster.
Diffstat (limited to 'gst/qtdemux')
-rw-r--r--gst/qtdemux/qtdemux.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/gst/qtdemux/qtdemux.c b/gst/qtdemux/qtdemux.c
index 64c32f46..775626ee 100644
--- a/gst/qtdemux/qtdemux.c
+++ b/gst/qtdemux/qtdemux.c
@@ -584,28 +584,41 @@ gst_qtdemux_push_pending_newsegment (GstQTDemux * qtdemux)
}
}
+typedef struct
+{
+ guint64 media_time;
+} FindData;
+
+static gint
+find_func (QtDemuxSample * s1, guint64 * media_time, gpointer user_data)
+{
+ if (s1->timestamp > *media_time)
+ return 1;
+
+ return -1;
+}
+
/* find the index of the sample that includes the data for @media_time
*
- * Returns the index of the sample or n_samples when the sample was not
- * found.
+ * Returns the index of the sample.
*/
-/* FIXME, binary search would be nice here */
static guint32
gst_qtdemux_find_index (GstQTDemux * qtdemux, QtDemuxStream * str,
guint64 media_time)
{
- guint32 i;
+ QtDemuxSample *result;
+ guint32 index;
- if (str->n_samples == 0)
- return 0;
+ result = gst_util_array_binary_search (str->samples, str->n_samples,
+ sizeof (QtDemuxSample), (GCompareDataFunc) find_func,
+ GST_SEARCH_MODE_BEFORE, &media_time, NULL);
- for (i = 0; i < str->n_samples; i++) {
- if (str->samples[i].timestamp > media_time) {
- /* first sample after media_time, we need the previous one */
- return (i == 0 ? 0 : i - 1);
- }
- }
- return str->n_samples - 1;
+ if (G_LIKELY (result))
+ index = result - str->samples;
+ else
+ index = 0;
+
+ return index;
}
/* find the index of the keyframe needed to decode the sample at @index