changeset 3863:64f5c5749bad

Applied Rik Snel's seeking patch
author alex
date Fri, 28 Dec 2001 22:58:49 +0000
parents 74622f23bce5
children edc0a581abf3
files libmpdemux/demux_y4m.c libmpdemux/demuxer.c
diffstat 2 files changed, 35 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_y4m.c	Fri Dec 28 22:48:25 2001 +0000
+++ b/libmpdemux/demux_y4m.c	Fri Dec 28 22:58:49 2001 +0000
@@ -88,7 +88,7 @@
 	return 0; /* EOF */
     if (c != 'F')
     {
-	printf("Bad frame at %p\n", stream_tell(demux->stream)-1);
+	mp_msg(MSGT_DEMUX, MSGL_V, "Bad frame at %d\n", (int)stream_tell(demux->stream)-1);
 	return 0;
     }
     stream_skip(demux->stream, 5); /* RAME\n */
@@ -128,7 +128,6 @@
 	char buf[4];
 	int frame_rate_code;
 
-	priv->framenum = 1;
 	stream_skip(demuxer->stream, 8); /* YUV4MPEG */
 	stream_skip(demuxer->stream, 1); /* space */
 	stream_read(demuxer->stream, (char *)&buf[0], 3);
@@ -200,6 +199,7 @@
 
 	sh->disp_w = y4m_si_get_width(priv->si);
 	sh->disp_h = y4m_si_get_height(priv->si);
+    	demuxer->seekable = 0;
     }
 
     sh->format = mmioFOURCC('Y', 'V', '1', '2');
@@ -218,14 +218,40 @@
     sh->ds=demuxer->video;
     demuxer->video->id=0;
 		
-    /* disable seeking, lazy */
-    demuxer->seekable = 0;
 
-    printf("YUV4MPEG2 Video stream %d size: display: %dx%d, codec: %ux%u\n",
+    mp_msg(MSGT_DEMUX, MSGL_INFO, "YUV4MPEG2 Video stream %d size: display: %dx%d, codec: %ux%u\n",
             demuxer->video->id, sh->disp_w, sh->disp_h, sh->bih->biWidth,
             sh->bih->biHeight);
 }
 
+int demux_seek_y4m(demuxer_t *demuxer, float rel_seek_secs, int flags) {
+    sh_video_t* sh = demuxer->video->sh;
+    y4m_priv_t* priv = demuxer->priv;
+    int rel_seek_frames = sh->fps*rel_seek_secs;
+    int size = 3*sh->disp_w*sh->disp_h/2;
+    off_t curr_pos = stream_tell(demuxer->stream);
+
+    if (priv->framenum + rel_seek_frames < 0) rel_seek_frames = -priv->framenum;
+
+    //printf("seektoframe=%d rel_seek_secs=%f seektooffset=%ld\n", priv->framenum + rel_seek_frames, rel_seek_secs, curr_pos + rel_seek_frames*(size+6));
+    //printf("framenum=%d, curr_pos=%ld, currpos/(size+6)=%f\n", priv->framenum, curr_pos, (float)curr_pos/(float)(size+6));
+    priv->framenum += rel_seek_frames;
+
+    if (priv->is_older) {
+        /* Well this is easy: every frame takes up size+6 bytes
+         * in the stream and we may assume that the stream pointer
+         * is always at the beginning of a frame.
+         * framenum is the number of the frame that is about to be
+         * demuxed (counting from ONE (see demux_open_y4m)) */
+        stream_seek(demuxer->stream, curr_pos + rel_seek_frames*(size+6));
+    } else {
+	    /* should never come here, because seeking for YUV4MPEG2 
+	     * is disabled. */
+	    mp_msg(MSGT_DEMUX, MSGL_WARN, "Seeking for YUV4MPEG2 not yet implemented!\n");
+    }
+    return 0; 
+}
+
 void demux_close_y4m(demuxer_t *demuxer)
 {
     y4m_priv_t* priv = demuxer->priv;
--- a/libmpdemux/demuxer.c	Fri Dec 28 22:48:25 2001 +0000
+++ b/libmpdemux/demuxer.c	Fri Dec 28 22:58:49 2001 +0000
@@ -658,6 +658,7 @@
 int demux_seek_avi(demuxer_t *demuxer,float rel_seek_secs,int flags);
 int demux_seek_asf(demuxer_t *demuxer,float rel_seek_secs,int flags);
 int demux_seek_mpg(demuxer_t *demuxer,float rel_seek_secs,int flags);
+int demux_seek_y4m(demuxer_t *demuxer,float rel_seek_secs,int flags);
 int demux_seek_fli(demuxer_t *demuxer,float rel_seek_secs,int flags);
 void demux_seek_mov(demuxer_t *demuxer,float pts,int flags);
 
@@ -709,6 +710,9 @@
   case DEMUXER_TYPE_MOV:
       demux_seek_mov(demuxer,rel_seek_secs,flags);  break;
 
+  case DEMUXER_TYPE_Y4M:
+      demux_seek_y4m(demuxer,rel_seek_secs,flags);  break;
+
   case DEMUXER_TYPE_FLI:
       demux_seek_fli(demuxer,rel_seek_secs,flags);  break;