[Mplayer-cvslog] CVS: main mplayer.c,1.191,1.192 seek.c,1.1,1.2 Makefile,1.58,1.59

Arpi of Ize arpi at mplayer.dev.hu
Sat Jul 28 23:57:24 CEST 2001


Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv18834

Modified Files:
	mplayer.c seek.c Makefile 
Log Message:
seeking code moved out from mplayer.c -> seek.c

Index: mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.191
retrieving revision 1.192
diff -u -r1.191 -r1.192
--- mplayer.c	28 Jul 2001 21:21:54 -0000	1.191
+++ mplayer.c	28 Jul 2001 21:57:21 -0000	1.192
@@ -159,6 +159,7 @@
 int read_asf_header(demuxer_t *demuxer);
 
 demuxer_t* demux_open(stream_t *stream,int file_format);
+int demux_seek(demuxer_t *demuxer,float rel_seek_secs,int flags);
 
 // MPEG video stream parser:
 #include "parse_es.h"
@@ -1524,231 +1525,13 @@
   }
   
   if(rel_seek_secs)
-  if(file_format==DEMUXER_TYPE_AVI && demuxer->idx_size<=0){
-    printf("Can't seek in raw .AVI streams! (index required, try with the -idx switch!)  \n");
-  } else {
-    int skip_audio_bytes=0;
-    float skip_audio_secs=0;
-
-    // clear demux buffers:
-    if(sh_audio){ ds_free_packs(d_audio);sh_audio->a_buffer_len=0;}
-    ds_free_packs(d_video);
-    
-//    printf("sh_audio->a_buffer_len=%d  \n",sh_audio->a_buffer_len);
-    
-
-switch(file_format){
-
-  case DEMUXER_TYPE_AVI: {
-  //================= seek in AVI ==========================
-    int rel_seek_frames=rel_seek_secs*sh_video->fps;
-    int curr_audio_pos=0;
-    int audio_chunk_pos=-1;
-    int video_chunk_pos=d_video->pos;
-    
-      skip_video_frames=0;
-      avi_audio_pts=0;
-
-      // find nearest video keyframe chunk pos:
-      if(rel_seek_frames>0){
-        // seek forward
-        while(video_chunk_pos<demuxer->idx_size){
-          int id=((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].ckid;
-          if(avi_stream_id(id)==d_video->id){  // video frame
-            if((--rel_seek_frames)<0 && ((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
-            ++skip_audio_bytes;
-          }
-          ++video_chunk_pos;
-        }
-      } else {
-        // seek backward
-        while(video_chunk_pos>=0){
-          int id=((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].ckid;
-          if(avi_stream_id(id)==d_video->id){  // video frame
-            if((++rel_seek_frames)>0 && ((AVIINDEXENTRY *)demuxer->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
-            --skip_audio_bytes;
-          }
-          --video_chunk_pos;
-        }
-      }
-      demuxer->idx_pos_a=demuxer->idx_pos_v=demuxer->idx_pos=video_chunk_pos;
-//      printf("%d frames skipped\n",skip_audio_bytes);
-
-      // re-calc video pts:
-      d_video->pack_no=0;
-      for(i=0;i<video_chunk_pos;i++){
-          int id=((AVIINDEXENTRY *)demuxer->idx)[i].ckid;
-          if(avi_stream_id(id)==d_video->id) ++d_video->pack_no;
-      }
-      sh_video->num_frames=d_video->pack_no;
-      avi_video_pts=d_video->pack_no*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
-
-      if(sh_audio){
-        int i;
-        int apos=0;
-        int last=0;
-        int len=0;
-
-        // calc new audio position in audio stream: (using avg.bps value)
-        curr_audio_pos=(avi_video_pts) * sh_audio->wf->nAvgBytesPerSec;
-        if(curr_audio_pos<0)curr_audio_pos=0;
-#if 1
-        curr_audio_pos&=~15; // requires for PCM formats!!!
-#else
-        curr_audio_pos/=sh_audio->wf->nBlockAlign;
-        curr_audio_pos*=sh_audio->wf->nBlockAlign;
-        demuxer->audio_seekable=1;
-#endif
-
-        // find audio chunk pos:
-          for(i=0;i<video_chunk_pos;i++){
-            int id=((AVIINDEXENTRY *)demuxer->idx)[i].ckid;
-            if(avi_stream_id(id)==d_audio->id){
-                len=((AVIINDEXENTRY *)demuxer->idx)[i].dwChunkLength;
-                last=i;
-                if(apos<=curr_audio_pos && curr_audio_pos<(apos+len)){
-                  if(verbose)printf("break;\n");
-                  break;
-                }
-                apos+=len;
-            }
-          }
-          if(verbose)printf("XXX i=%d  last=%d  apos=%d  curr_audio_pos=%d  \n",
-           i,last,apos,curr_audio_pos);
-//          audio_chunk_pos=last; // maybe wrong (if not break; )
-          audio_chunk_pos=i; // maybe wrong (if not break; )
-          skip_audio_bytes=curr_audio_pos-apos;
-
-          // update stream position:
-          d_audio->pos=audio_chunk_pos;
-          d_audio->dpos=apos;
-	  d_audio->pts=initial_pts_delay+(float)apos/(float)sh_audio->wf->nAvgBytesPerSec;
-          demuxer->idx_pos_a=demuxer->idx_pos_v=demuxer->idx_pos=audio_chunk_pos;
-
-          if(!(sh_audio->codec->flags&CODECS_FLAG_SEEKABLE)){
-#if 0
-//             curr_audio_pos=apos; // selected audio codec can't seek in chunk
-             skip_audio_secs=(float)skip_audio_bytes/(float)sh_audio->wf->nAvgBytesPerSec;
-             //printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",skip_audio_bytes,skip_audio_secs);
-             skip_audio_bytes=0;
-#else
-             int d=skip_audio_bytes % sh_audio->wf->nBlockAlign;
-             skip_audio_bytes-=d;
-//             curr_audio_pos-=d;
-             skip_audio_secs=(float)d/(float)sh_audio->wf->nAvgBytesPerSec;
-             //printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",d,skip_audio_secs);
-#endif
-          }
-          // now: audio_chunk_pos=pos in index
-          //      skip_audio_bytes=bytes to skip from that chunk
-          //      skip_audio_secs=time to play audio before video (if can't skip)
-          
-          // calc skip_video_frames & adjust video pts counter:
-//          i=last;
-	  for(i=demuxer->idx_pos;i<video_chunk_pos;i++){
-            int id=((AVIINDEXENTRY *)demuxer->idx)[i].ckid;
-            if(avi_stream_id(id)==d_video->id) ++skip_video_frames;
-          }
-          // requires for correct audio pts calculation (demuxer):
-          avi_video_pts-=skip_video_frames*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
-          
-      }
-
-      if(verbose) printf("SEEK: idx=%d  (a:%d v:%d)  v.skip=%d  a.skip=%d/%4.3f  \n",
-        demuxer->idx_pos,audio_chunk_pos,video_chunk_pos,
-        skip_video_frames,skip_audio_bytes,skip_audio_secs);
-
-  }
-  break;
+  if(demux_seek(demuxer,rel_seek_secs,0)){
+      // success:
 
-  case DEMUXER_TYPE_ASF: {
-  //================= seek in ASF ==========================
-    float p_rate=10; // packets / sec
-    int rel_seek_packs=rel_seek_secs*p_rate;
-    int rel_seek_bytes=rel_seek_packs*asf_packetsize;
-    int newpos;
-    //printf("ASF: packs: %d  duration: %d  \n",(int)fileh.packets,*((int*)&fileh.duration));
-//    printf("ASF_seek: %d secs -> %d packs -> %d bytes  \n",
-//       rel_seek_secs,rel_seek_packs,rel_seek_bytes);
-    newpos=demuxer->filepos+rel_seek_bytes;
-    if(newpos<0 || newpos<demuxer->movi_start) newpos=demuxer->movi_start;
-//    printf("\r -- asf: newpos=%d -- \n",newpos);
-    stream_seek(demuxer->stream,newpos);
-
-    ds_fill_buffer(d_video);
-    if(sh_audio) ds_fill_buffer(d_audio);
-    
-    while(1){
-	if(sh_audio){
-	  // sync audio:
-          if (d_video->pts > d_audio->pts){
-	      if(!ds_fill_buffer(d_audio)) sh_audio=NULL; // skip audio. EOF?
-	      continue;
-	  }
-	}
-	if(d_video->flags&1) break; // found a keyframe!
-	if(!ds_fill_buffer(d_video)) break; // skip frame.  EOF?
-    }
-
-  }
-  break;
-  
-  case DEMUXER_TYPE_MPEG_ES:
-  case DEMUXER_TYPE_MPEG_PS: {
-  //================= seek in MPEG ==========================
-        int newpos;
-        if(!sh_video->i_bps) // unspecified?
-          newpos=demuxer->filepos+2324*75*rel_seek_secs; // 174.3 kbyte/sec
-        else
-          newpos=demuxer->filepos+(sh_video->i_bps)*rel_seek_secs;
-
-        if(newpos<seek_to_byte) newpos=seek_to_byte;
-        newpos&=~(STREAM_BUFFER_SIZE-1);  /* sector boundary */
-        stream_seek(demuxer->stream,newpos);
-        // re-sync video:
-        videobuf_code_len=0; // reset ES stream buffer
-        while(1){
-          int i=sync_video_packet(d_video);
-          if(i==0x1B3 || i==0x1B8) break; // found it!
-          if(!i || !skip_video_packet(d_video)){ eof=1; break;} // EOF
-        }
-  }
-  break;
-
-} // switch(file_format)
-
-      //====================== re-sync audio: =====================
       if(sh_audio){
-
-        if(skip_audio_bytes){
-          demux_read_data(d_audio,NULL,skip_audio_bytes);
-          //d_audio->pts=0; // PTS is outdated because of the raw data skipping
-        }
-        
-        current_module="resync_audio";
-	resync_audio_stream(sh_audio);
-
-        // re-sync PTS (MPEG-PS only!!!)
-        if(file_format==DEMUXER_TYPE_MPEG_PS)
-        if(d_video->pts && d_audio->pts){
-          if (d_video->pts < d_audio->pts){
-          
-          } else {
-            while(d_video->pts > d_audio->pts){
-	      skip_audio_frame(sh_audio);
-            }
-          }
-        }
-
         current_module="audio_reset";
         audio_out->reset(); // stop audio, throwing away buffered data
         current_module=NULL;
-
-        c_total=0; // kell ez?
-        printf("A:%6.1f  V:%6.1f  A-V:%7.3f",d_audio->pts,d_video->pts,0.0f);
-        printf("  ct:%7.3f   \r",c_total);fflush(stdout);
-      } else {
-        printf("A: ---   V:%6.1f   \r",d_video->pts);fflush(stdout);
       }
 
         // Set OSD:
@@ -1760,17 +1543,17 @@
           vo_osd_progbar_value=(demuxer->filepos-demuxer->movi_start)/len;
         }
       }
-
+      
+      c_total=0; // kell ez?
       max_pts_correction=0.1;
-      frame_corr_num=0; // -5
+      frame_corr_num=0; // -5   FIXME!!!
       frame_correction=0;
       force_redraw=5;
-      if(sh_audio) sh_audio->timer=-skip_audio_secs;
-      sh_video->timer=0; // !!!!!!
       audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
-
+  
   }
- rel_seek_secs=0;
+  rel_seek_secs=0;
+  
 } // keyboard event handler
 
 //================= Update OSD ====================

Index: seek.c
===================================================================
RCS file: /cvsroot/mplayer/main/seek.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- seek.c	28 Jul 2001 21:23:45 -0000	1.1
+++ seek.c	28 Jul 2001 21:57:21 -0000	1.2
@@ -1,10 +1,53 @@
+#include <stdio.h>
+#include <stdlib.h>
 
-  if(file_format==DEMUXER_TYPE_AVI && demuxer->idx_size<=0){
-    printf("Can't seek in raw .AVI streams! (index required, try with the -idx switch!)  \n");
-  } else {
+extern int verbose; // defined in mplayer.c
+
+#include "config.h"
+
+#include "stream.h"
+#include "demuxer.h"
+#include "parse_es.h"
+
+#include "wine/mmreg.h"
+#include "wine/avifmt.h"
+#include "wine/vfw.h"
+
+#include "codec-cfg.h"
+#include "stheader.h"
+
+extern void resync_audio_stream(sh_audio_t *sh_audio);
+extern void skip_audio_frame(sh_audio_t *sh_audio);
+
+extern int asf_packetsize; // for seeking
+
+extern float avi_audio_pts;
+extern float avi_video_pts;
+extern float avi_video_ftime;
+extern int skip_video_frames;
+extern float initial_pts_delay;
+extern int seek_to_byte;
+extern char* current_module; // for debugging
+
+// flags:
+//   0x1 - absolute/relative
+//   0x2 - keyframe/hard
+
+int demux_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){
+    demux_stream_t *d_audio=demuxer->audio;
+    demux_stream_t *d_video=demuxer->video;
+    sh_audio_t *sh_audio=d_audio->sh;
+    sh_video_t *sh_video=d_video->sh;
     int skip_audio_bytes=0;
     float skip_audio_secs=0;
 
+if(demuxer->file_format==DEMUXER_TYPE_AVI && demuxer->idx_size<=0){
+    printf("Can't seek in raw .AVI streams! (index required, try with the -idx switch!)  \n");
+    return 0;
+}
+
+    current_module="seek";
+
     // clear demux buffers:
     if(sh_audio){ ds_free_packs(d_audio);sh_audio->a_buffer_len=0;}
     ds_free_packs(d_video);
@@ -12,7 +55,7 @@
 //    printf("sh_audio->a_buffer_len=%d  \n",sh_audio->a_buffer_len);
     
 
-switch(file_format){
+switch(demuxer->file_format){
 
   case DEMUXER_TYPE_AVI: {
   //================= seek in AVI ==========================
@@ -20,6 +63,7 @@
     int curr_audio_pos=0;
     int audio_chunk_pos=-1;
     int video_chunk_pos=d_video->pos;
+    int i;
     
       skip_video_frames=0;
       avi_audio_pts=0;
@@ -185,12 +229,12 @@
         while(1){
           int i=sync_video_packet(d_video);
           if(i==0x1B3 || i==0x1B8) break; // found it!
-          if(!i || !skip_video_packet(d_video)){ eof=1; break;} // EOF
+          if(!i || !skip_video_packet(d_video)) break; // EOF?
         }
   }
   break;
 
-} // switch(file_format)
+} // switch(demuxer->file_format)
 
       //====================== re-sync audio: =====================
       if(sh_audio){
@@ -204,7 +248,7 @@
 	resync_audio_stream(sh_audio);
 
         // re-sync PTS (MPEG-PS only!!!)
-        if(file_format==DEMUXER_TYPE_MPEG_PS)
+        if(demuxer->file_format==DEMUXER_TYPE_MPEG_PS)
         if(d_video->pts && d_audio->pts){
           if (d_video->pts < d_audio->pts){
           
@@ -215,34 +259,14 @@
           }
         }
 
-        current_module="audio_reset";
-        audio_out->reset(); // stop audio, throwing away buffered data
-        current_module=NULL;
-
-        c_total=0; // kell ez?
-        printf("A:%6.1f  V:%6.1f  A-V:%7.3f",d_audio->pts,d_video->pts,0.0f);
-        printf("  ct:%7.3f   \r",c_total);fflush(stdout);
+        printf("A:%6.1f  V:%6.1f  A-V:%7.3f  ct: ?   \r",d_audio->pts,d_video->pts,0.0f);
       } else {
-        printf("A: ---   V:%6.1f   \r",d_video->pts);fflush(stdout);
+        printf("A: ---   V:%6.1f   \r",d_video->pts);
       }
+      fflush(stdout);
 
-        // Set OSD:
-      if(osd_level){
-        int len=((demuxer->movi_end-demuxer->movi_start)>>8);
-        if(len>0){
-          osd_visible=sh_video->fps; // 1 sec
-          vo_osd_progbar_type=0;
-          vo_osd_progbar_value=(demuxer->filepos-demuxer->movi_start)/len;
-        }
-      }
-
-      max_pts_correction=0.1;
-      frame_corr_num=0; // -5
-      frame_correction=0;
-      force_redraw=5;
       if(sh_audio) sh_audio->timer=-skip_audio_secs;
       sh_video->timer=0; // !!!!!!
-      audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
 
-  }
- rel_seek_secs=0;
+return 1;
+}

Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/Makefile,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- Makefile	28 Jul 2001 05:36:44 -0000	1.58
+++ Makefile	28 Jul 2001 21:57:21 -0000	1.59
@@ -16,7 +16,7 @@
 #prefix = /usr/local
 BINDIR = ${prefix}/bin
 # BINDIR = /usr/local/bin
-SRCS = parse_es.c find_sub.c aviprint.c dec_audio.c dec_video.c aviwrite.c aviheader.c asfheader.c demux_avi.c demux_asf.c demux_mpg.c demuxer.c stream.c codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c mixer.c dvdauth.c spudec.c $(STREAM_SRCS)
+SRCS = seek.c parse_es.c find_sub.c aviprint.c dec_audio.c dec_video.c aviwrite.c aviheader.c asfheader.c demux_avi.c demux_asf.c demux_mpg.c demuxer.c stream.c codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c mixer.c dvdauth.c spudec.c $(STREAM_SRCS)
 OBJS = $(SRCS:.c=.o)
 CFLAGS = $(OPTFLAGS) -Iloader -Ilibvo $(CSS_INC) $(EXTRA_INC) # -Wall
 A_LIBS = -Lmp3lib -lMP3 -Llibac3 -lac3 $(ALSA_LIB) $(ESD_LIB)




More information about the MPlayer-cvslog mailing list