From 7f63b50f3fcd6c98672b9d2481d8e56026c90197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 15 Nov 2005 19:41:21 +0000 Subject: [PATCH] gst/matroska/matroska-demux.c: When seeking, seek to closest index entry at or before the requested seek position, no... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message from CVS: Reviewed by: Tim-Philipp Müller * gst/matroska/matroska-demux.c: (gst_matroskademux_do_index_seek): When seeking, seek to closest index entry at or before the requested seek position, not just the closest one (#321001). --- ChangeLog | 8 ++++++++ gst/matroska/matroska-demux.c | 27 +++++++++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index b0fb89d0a5..a495970dbf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-11-15 Vincent Torri + + Reviewed by: Tim-Philipp Müller + + * gst/matroska/matroska-demux.c: (gst_matroskademux_do_index_seek): + When seeking, seek to closest index entry at or before the requested + seek position, not just the closest one (#321001). + 2005-11-15 Tim-Philipp Müller * gst/avi/gstavidemux.c: (swap_line), (gst_avi_demux_invert), diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c index 3a363ca0cf..dca6f39772 100644 --- a/gst/matroska/matroska-demux.c +++ b/gst/matroska/matroska-demux.c @@ -992,27 +992,22 @@ gst_matroska_demux_handle_src_query (GstPad * pad, GstQuery * query) static GstMatroskaIndex * gst_matroskademux_do_index_seek (GstMatroskaDemux * demux, guint64 seek_pos) { - guint entry = (guint) - 1; - guint n; + guint entry = demux->num_indexes - 1; + guint n = 0; - for (n = 0; n < demux->num_indexes; n++) { - if (entry == (guint) - 1) { + if (!demux->num_indexes) + return NULL; + + while (n < demux->num_indexes - 1) { + if ((demux->index[n].time <= seek_pos) && + (demux->index[n + 1].time > seek_pos)) { entry = n; - } else { - gfloat diff_old = fabs (1. * (demux->index[entry].time - seek_pos)), - diff_new = fabs (1. * (demux->index[n].time - seek_pos)); - - if (diff_new < diff_old) { - entry = n; - } + break; } + n++; } - if (entry != (guint) - 1) { - return &demux->index[entry]; - } - - return NULL; + return &demux->index[entry]; } /* takes ownership of the passed event! */