changeset 2227:10b279d72a8f

mov seeking implemented
author arpi
date Tue, 16 Oct 2001 22:41:46 +0000
parents 9582af160d04
children ac517956d9b0
files demux_mov.c demuxer.c
diffstat 2 files changed, 57 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/demux_mov.c	Tue Oct 16 21:23:59 2001 +0000
+++ b/demux_mov.c	Tue Oct 16 22:41:46 2001 +0000
@@ -107,6 +107,7 @@
     if(!trak->samples_size){
 	// constant sampesize
 	if(trak->durmap_size==1 || (trak->durmap_size==2 && trak->durmap[1].num==1)){
+	    trak->duration=trak->durmap[0].dur;
 	} else printf("*** constant samplesize & variable duration not yet supported! ***\nContact the author if you have such sample file!\n");
 	return;
     }
@@ -558,3 +559,55 @@
     return 1;
     
 }
+
+static float mov_seek_track(mov_track_t* trak,float pts,int flags){
+
+//    printf("MOV track seek called  %5.3f  \n",pts);
+    if(flags&2) pts*=trak->length; else pts*=(float)trak->timescale;
+
+if(trak->samplesize){
+    int sample=pts/trak->duration;
+//    printf("MOV track seek - chunk: %d  (pts: %5.3f  dur=%d)  \n",sample,pts,trak->duration);
+    if(!(flags&1)) sample+=trak->chunks[trak->pos].sample; // relative
+    trak->pos=0;
+    while(trak->pos<trak->chunks_size && trak->chunks[trak->pos].sample<sample) ++trak->pos;
+    pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale;
+} else {
+    unsigned int ipts=pts;
+//    printf("MOV track seek - sample: %d  \n",ipts);
+    if(!(flags&1)) ipts+=trak->samples[trak->pos].pts;
+    trak->pos=0;
+    while(trak->pos<trak->samples_size && trak->samples[trak->pos].pts<ipts) ++trak->pos;
+    pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale;
+}
+
+//    printf("MOV track seek done:  %5.3f  \n",pts);
+
+return pts;
+}
+
+void demux_seek_mov(demuxer_t *demuxer,float pts,int flags){
+    mov_priv_t* priv=demuxer->priv;
+    demux_stream_t* ds;
+
+//    printf("MOV seek called  %5.3f  flag=%d  \n",pts,flags);
+    
+    ds=demuxer->video;
+    if(ds && ds->id>=0 && ds->id<priv->track_db){
+	mov_track_t* trak=priv->tracks[ds->id];
+	//if(flags&2) pts*=(float)trak->length/(float)trak->timescale;
+	//if(!(flags&1)) pts+=ds->pts;
+	pts=ds->pts=mov_seek_track(trak,pts,flags);
+	flags=1; // absolute seconds
+    }
+
+    ds=demuxer->audio;
+    if(ds && ds->id>=0 && ds->id<priv->track_db){
+	mov_track_t* trak=priv->tracks[ds->id];
+	//if(flags&2) pts*=(float)trak->length/(float)trak->timescale;
+	//if(!(flags&1)) pts+=ds->pts;
+	ds->pts=mov_seek_track(trak,pts,flags);
+    }
+
+}
+
--- a/demuxer.c	Tue Oct 16 21:23:59 2001 +0000
+++ b/demuxer.c	Tue Oct 16 22:41:46 2001 +0000
@@ -532,6 +532,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);
+void demux_seek_mov(demuxer_t *demuxer,float pts,int flags);
 
 int demux_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){
     demux_stream_t *d_audio=demuxer->audio;
@@ -568,6 +569,9 @@
   case DEMUXER_TYPE_MPEG_PS:
       demux_seek_mpg(demuxer,rel_seek_secs,flags);  break;
 
+  case DEMUXER_TYPE_MOV:
+      demux_seek_mov(demuxer,rel_seek_secs,flags);  break;
+
 } // switch(demuxer->file_format)
 
 return 1;