changeset 20070:b4d4142f7ae8

Implement absolute and percent-based seek
author reimar
date Thu, 05 Oct 2006 21:25:22 +0000
parents 609c0cd1a85b
children 672123d27ae3
files libmpdemux/demux_lavf.c
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_lavf.c	Thu Oct 05 18:39:06 2006 +0000
+++ b/libmpdemux/demux_lavf.c	Thu Oct 05 21:25:22 2006 +0000
@@ -403,9 +403,20 @@
 
 static void demux_seek_lavf(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags){
     lavf_priv_t *priv = demuxer->priv;
+    int avsflags = 0;
     mp_msg(MSGT_DEMUX,MSGL_DBG2,"demux_seek_lavf(%p, %f, %f, %d)\n", demuxer, rel_seek_secs, audio_delay, flags);
 
-    av_seek_frame(priv->avfc, -1, priv->last_pts + rel_seek_secs*AV_TIME_BASE, rel_seek_secs < 0 ? AVSEEK_FLAG_BACKWARD : 0);
+    if (flags & 1) // absolute seek
+      priv->last_pts = priv->avfc->start_time;
+    if (flags & 2) { // percent seek
+      if (priv->avfc->duration == 0 || priv->avfc->duration == AV_NOPTS_VALUE)
+        return;
+      priv->last_pts += rel_seek_secs * priv->avfc->duration;
+    } else {
+      priv->last_pts += rel_seek_secs * AV_TIME_BASE;
+      if (rel_seek_secs < 0) avsflags = AVSEEK_FLAG_BACKWARD;
+    }
+    av_seek_frame(priv->avfc, -1, priv->last_pts, avsflags);
 }
 
 static int demux_lavf_control(demuxer_t *demuxer, int cmd, void *arg)