[Mplayer-cvslog] CVS: main/libmpdemux aviheader.h,1.4,1.5 demux_avi.c,1.47,1.48 demuxer.c,1.119,1.120 demuxer.h,1.49,1.50

Arpi of Ize arpi at mplayerhq.hu
Sat Nov 2 01:45:15 CET 2002


Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var/tmp.root/cvs-serv22794/libmpdemux

Modified Files:
	aviheader.h demux_avi.c demuxer.c demuxer.h 
Log Message:
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
instead doing it in demux_avi.c, storing private data in priv insteda of
demuxer structs)


Index: aviheader.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/aviheader.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- aviheader.h	12 May 2002 01:51:09 -0000	1.4
+++ aviheader.h	2 Nov 2002 00:45:12 -0000	1.5
@@ -93,6 +93,10 @@
   off_t idx_pos_a;
   off_t idx_pos_v;
   off_t idx_offset;  // ennyit kell hozzaadni az index offset ertekekhez
+  // bps-based PTS stuff:
+  int video_pack_no;
+  int audio_block_size;
+  off_t audio_block_no;
   // interleaved PTS stuff:
   int skip_video_frames;
   int audio_streams;

Index: demux_avi.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demux_avi.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- demux_avi.c	17 Oct 2002 22:12:32 -0000	1.47
+++ demux_avi.c	2 Nov 2002 00:45:12 -0000	1.48
@@ -14,6 +14,9 @@
 
 #include "aviheader.h"
 
+// PTS:  0=interleaved  1=BPS-based
+int pts_from_bps=1;
+
 // Select ds from ID
 demux_stream_t* demux_avi_select_stream(demuxer_t *demux,unsigned int id){
   int stream_id=avi_stream_id(id);
@@ -32,15 +35,20 @@
   if(stream_id==demux->audio->id){
       if(!demux->audio->sh){
         sh_audio_t* sh;
+	avi_priv_t *priv=demux->priv;
         sh=demux->audio->sh=demux->a_streams[stream_id];
         mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected AVI audio ID = %d\n",demux->audio->id);
 	if(sh->wf){
-	  demux->audio->block_size=sh->wf->nBlockAlign;
-	  if(!demux->audio->block_size){
+	  priv->audio_block_size=sh->wf->nBlockAlign;
+	  if(!priv->audio_block_size){
 	    // for PCM audio we can calculate the blocksize:
-	    if(sh->format==1) demux->audio->block_size=sh->wf->nChannels*(sh->wf->wBitsPerSample/8);
-	    if(!demux->audio->block_size) demux->audio->block_size=1; // bug!
+	    if(sh->format==1)
+		priv->audio_block_size=sh->wf->nChannels*(sh->wf->wBitsPerSample/8);
+	    else
+		priv->audio_block_size=1; // hope the best...
 	  }
+	} else {
+	  priv->audio_block_size=sh->audio.dwSampleSize;
 	}
 	//printf("&&&&& setting blocksize to %d &&&&&\n",demux->audio->block_size);
       }
@@ -88,12 +96,10 @@
   avi_priv_t *priv=demux->priv;
   int skip;
   float pts=0;
-//  demux_stream_t *ds=demux_avi_select_stream(demux,id);
   
   mp_dbg(MSGT_DEMUX,MSGL_DBG3,"demux_avi.read_packet: %X\n",id);
 
   if(ds==demux->audio){
-
       if(priv->pts_corrected==0){
 //          printf("\rYYY-A  A: %5.3f  V: %5.3f  \n",priv->avi_audio_pts,priv->avi_video_pts);
           if(priv->pts_has_video){
@@ -107,10 +113,18 @@
 	      priv->avi_audio_pts+=priv->pts_correction;
 	      priv->pts_corrected=1;
 	  } else
-          priv->pts_corr_bytes+=len;
+	      priv->pts_corr_bytes+=len;
       }
-            pts=priv->avi_audio_pts; //+priv->pts_correction;
-            priv->avi_audio_pts=0;
+      if(pts_from_bps){
+	  pts = priv->audio_block_no *
+	    (float)((sh_audio_t*)demux->audio->sh)->audio.dwScale /
+	    (float)((sh_audio_t*)demux->audio->sh)->audio.dwRate;
+      } else
+          pts=priv->avi_audio_pts; //+priv->pts_correction;
+      priv->avi_audio_pts=0;
+      // update blockcount:
+      priv->audio_block_no+=priv->audio_block_size ?
+	((len+priv->audio_block_size-1)/priv->audio_block_size) : 1;
   } else 
   if(ds==demux->video){
      // video
@@ -118,36 +132,21 @@
        // drop frame (seeking)
        --priv->skip_video_frames;
        ds=NULL;
-//     } else {
-//       pts=priv->avi_video_pts;
      }
-     // ezt a 2 sort lehet hogy fell kell majd cserelni:
-     //priv->avi_video_pts+=avi_pts_frametime;
-     //priv->avi_video_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
-     //priv->avi_video_pts+=((sh_video_t*)ds->sh)->frametime;
-// FIXME!!!
-#if 1
-//       printf("ds=0x%X\n",ds);
-//       printf("packno=%d\n",ds->pack_no);
-//    printf("### pack_no=%d\n",demux->video->pack_no+demux->video->packs);
-       priv->avi_video_pts = (demux->video->pack_no+demux->video->packs) *
+
+     pts = priv->avi_video_pts = priv->video_pack_no *
          (float)((sh_video_t*)demux->video->sh)->video.dwScale /
 	 (float)((sh_video_t*)demux->video->sh)->video.dwRate;
-#else
-     priv->avi_video_pts+=(float)((sh_video_t*)(demux->video->sh))->video.dwScale/(float)((sh_video_t*)(demux->video->sh))->video.dwRate;
-//     priv->avi_video_pts+=avi_video_ftime;
-#endif
 //          printf("\rYYY-V  A: %5.3f  V: %5.3f  \n",priv->avi_audio_pts,priv->avi_video_pts);
+
      priv->avi_audio_pts=priv->avi_video_pts+priv->pts_correction;
      priv->pts_has_video=1;
 
-     pts=priv->avi_video_pts;
+     if(ds) ++priv->video_pack_no;
 
      //printf("read  pack_no: %d  pts %5.3f  \n",demux->video->pack_no+demux->video->packs,pts);
-
   }
   
-//  len=stream_read_dword_le(demux->stream);
   skip=(len+1)&(~1); // total bytes in this chunk
   
   if(ds){
@@ -341,8 +340,6 @@
           if(!valid_fourcc(id)) continue; // drop chunk if both id and idx bad
     }
     len=stream_read_dword_le(demux->stream);
-//    if((len&(~1))!=(idx->dwChunkLength&(~1))){
-//    if((len)!=(idx->dwChunkLength)){
     if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){
       mp_msg(MSGT_DEMUX,MSGL_V,"ChunkSize mismatch! raw=%d idx=%ld  \n",len,idx->dwChunkLength);
       if(len>0x200000 && idx->dwChunkLength>0x200000) continue; // both values bad :(
@@ -417,23 +414,10 @@
   return 1;
 }
 
-//extern int audio_id;
-//extern int video_id;
-//extern int index_mode;  // -1=untouched  0=don't use index  1=use (geneate) index
-//extern int force_ni;
-//extern int pts_from_bps;
-
 // AVI demuxer parameters:
 int index_mode=-1;  // -1=untouched  0=don't use index  1=use (geneate) index
 int force_ni=0;     // force non-interleaved AVI parsing
 
-// PTS:  0=interleaved  1=BPS-based
-#ifdef AVI_SYNC_BPS
-int pts_from_bps=1;
-#else
-int pts_from_bps=0;
-#endif
-
 void read_avi_header(demuxer_t *demuxer,int index_mode);
 
 demuxer_t* demux_open_avi(demuxer_t* demuxer){
@@ -449,6 +433,9 @@
   priv->skip_video_frames=0;
   priv->pts_corr_bytes=0;
   priv->pts_has_video=priv->pts_corrected=0;
+  priv->video_pack_no=0;
+  priv->audio_block_no=0;
+  priv->audio_block_size=0;
   demuxer->priv=(void*)priv;
 
   //---- AVI header:
@@ -636,6 +623,7 @@
           int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
           if(avi_stream_id(id)==d_video->id) ++d_video->pack_no;
       }
+      priv->video_pack_no=
       sh_video->num_frames=sh_video->num_frames_decoded=d_video->pack_no;
       priv->avi_video_pts=d_video->pack_no*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
       d_video->pos=video_chunk_pos;
@@ -645,7 +633,8 @@
 // ------------ STEP 2: seek audio, find the right chunk & pos ------------
 
       d_audio->pack_no=0;
-      d_audio->block_no=0;
+//      d_audio->block_no=0;
+      priv->audio_block_no=0;
       d_audio->dpos=0;
 
       if(sh_audio){
@@ -677,11 +666,12 @@
             int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
             if(avi_stream_id(id)==d_audio->id){
                 len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength;
-                ++d_audio->pack_no;
-		d_audio->block_no+=(len+d_audio->block_size-1)/d_audio->block_size;
                 if(d_audio->dpos<=curr_audio_pos && curr_audio_pos<(d_audio->dpos+len)){
                   break;
                 }
+                ++d_audio->pack_no;
+                priv->audio_block_no+=priv->audio_block_size ?
+		    ((len+priv->audio_block_size-1)/priv->audio_block_size) : 1;
                 d_audio->dpos+=len;
             }
           }
@@ -705,12 +695,14 @@
 		  skip_audio_bytes+=len;
 		} else {
 		  ++d_audio->pack_no;
-		  d_audio->block_no+=(len+d_audio->block_size-1)/d_audio->block_size;
+                  priv->audio_block_no+=priv->audio_block_size ?
+		    ((len+priv->audio_block_size-1)/priv->audio_block_size) : 1;
                   d_audio->dpos+=len;
 		  audio_chunk_pos=i;
 		}
 //		--chunks;
-		chunks-=(len+d_audio->block_size-1)/d_audio->block_size;
+		if(priv->audio_block_size)
+		    chunks-=(len+priv->audio_block_size-1)/priv->audio_block_size;
             }
           }
 	  //if(audio_chunk_pos>chunk_max) audio_chunk_pos=chunk_max;
@@ -742,6 +734,8 @@
             }
             // requires for correct audio pts calculation (demuxer):
             priv->avi_video_pts-=priv->skip_video_frames*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
+	    priv->avi_audio_pts=priv->avi_video_pts;
+	    // set index position:
 	    priv->idx_pos_a=priv->idx_pos_v=priv->idx_pos=audio_chunk_pos;
 	  }
 	} else {

Index: demuxer.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.c,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -r1.119 -r1.120
--- demuxer.c	23 Oct 2002 17:21:00 -0000	1.119
+++ demuxer.c	2 Nov 2002 00:45:12 -0000	1.120
@@ -35,7 +35,6 @@
   ds->pos=0;
   ds->dpos=0;
   ds->pack_no=0;
-  ds->block_no=0;
 //---------------
   ds->packs=0;
   ds->bytes=0;
@@ -47,7 +46,6 @@
   ds->asf_packet=NULL;
 //----------------
   ds->ss_mul=ds->ss_div=0;
-  ds->block_size=1;
 //----------------
   ds->sh=NULL;
   return ds;
@@ -340,7 +338,6 @@
       ds->pos=p->pos;
       ds->dpos+=p->len; // !!!
       ++ds->pack_no;
-      ds->block_no+=(p->len+ds->block_size-1)/ds->block_size;
       if(p->pts){
         ds->pts=p->pts;
         ds->pts_bytes=0;

Index: demuxer.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.h,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- demuxer.h	17 Oct 2002 00:54:13 -0000	1.49
+++ demuxer.h	2 Nov 2002 00:45:12 -0000	1.50
@@ -71,7 +71,6 @@
   int eof;                 // end of demuxed stream? (true if all buffer empty)
   off_t pos;                 // position in the input stream (file)
   off_t dpos;                // position in the demuxed stream
-  off_t block_no;            // number of <=block_size length blocks (for VBR mp3)
   int pack_no;		   // serial number of packet
   int flags;               // flags of current packet (keyframe etc)
 //---------------
@@ -87,8 +86,6 @@
   int asf_seq;
 // ---- mov -----
   unsigned int ss_mul,ss_div;
-// ---- avi -----
-  unsigned int block_size;
 // ---- stream header ----
   void* sh;
 } demux_stream_t;
@@ -183,10 +180,6 @@
 
 inline static int ds_tell_pts(demux_stream_t *ds){
   return (ds->pts_bytes-ds->buffer_size)+ds->buffer_pos;
-}
-
-inline static off_t ds_tell_block(demux_stream_t *ds){
-  return ds->block_no-(ds->buffer_size-ds->buffer_pos)/ds->block_size;
 }
 
 int demux_read_data(demux_stream_t *ds,unsigned char* mem,int len);




More information about the MPlayer-cvslog mailing list