changeset 6871:88953ff93743

count blocks by rounded-up chunksizes instead of chunks - we need full emulation of dshow avi demuxer bugs :( fixes silly nandub-style a-v delaying in avi with vbr mp3...
author arpi
date Fri, 02 Aug 2002 17:44:16 +0000
parents dad5f8b3e8a0
children e75137e656d3
files libmpdemux/demux_avi.c libmpdemux/demuxer.c libmpdemux/demuxer.h mencoder.c mplayer.c
diffstat 5 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_avi.c	Fri Aug 02 17:41:02 2002 +0000
+++ b/libmpdemux/demux_avi.c	Fri Aug 02 17:44:16 2002 +0000
@@ -33,6 +33,8 @@
       if(!demux->audio->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);
+	demux->audio->block_size=((sh_audio_t*)(demux->audio->sh))->wf->nBlockAlign;
+	//printf("&&&&& setting blocksize to %d &&&&&\n",demux->audio->block_size);
       }
       return demux->audio;
   }
@@ -602,6 +604,7 @@
 // ------------ STEP 2: seek audio, find the right chunk & pos ------------
 
       d_audio->pack_no=0;
+      d_audio->block_no=0;
       d_audio->dpos=0;
 
       if(sh_audio){
@@ -636,6 +639,7 @@
             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;
                 }
@@ -662,10 +666,12 @@
 		  skip_audio_bytes+=len;
 		} else {
 		  ++d_audio->pack_no;
+		  d_audio->block_no+=(len+d_audio->block_size-1)/d_audio->block_size;
                   d_audio->dpos+=len;
 		  audio_chunk_pos=i;
 		}
-		--chunks;
+//		--chunks;
+		chunks-=(len+d_audio->block_size-1)/d_audio->block_size;
             }
           }
 	  //if(audio_chunk_pos>chunk_max) audio_chunk_pos=chunk_max;
--- a/libmpdemux/demuxer.c	Fri Aug 02 17:41:02 2002 +0000
+++ b/libmpdemux/demuxer.c	Fri Aug 02 17:44:16 2002 +0000
@@ -35,6 +35,7 @@
   ds->pos=0;
   ds->dpos=0;
   ds->pack_no=0;
+  ds->block_no=0;
 //---------------
   ds->packs=0;
   ds->bytes=0;
@@ -46,6 +47,7 @@
   ds->asf_packet=NULL;
 //----------------
   ds->ss_mul=ds->ss_div=1;
+  ds->block_size=1;
 //----------------
   ds->sh=NULL;
   return ds;
@@ -320,6 +322,7 @@
       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;
--- a/libmpdemux/demuxer.h	Fri Aug 02 17:41:02 2002 +0000
+++ b/libmpdemux/demuxer.h	Fri Aug 02 17:44:16 2002 +0000
@@ -67,6 +67,7 @@
   off_t pos;                 // position in the input stream (file)
   off_t dpos;                // position in the demuxed stream
   int pack_no;		   // serial number of packet
+  int block_no;            // number of <=block_size length blocks (for VBR mp3)
   int flags;               // flags of current packet (keyframe etc)
 //---------------
   int packs;              // number of packets in buffer
@@ -81,6 +82,8 @@
   int asf_seq;
 // ---- mov -----
   unsigned int ss_mul,ss_div;
+// ---- avi -----
+  unsigned int block_size;
 // ---- stream header ----
   void* sh;
 } demux_stream_t;
--- a/mencoder.c	Fri Aug 02 17:41:02 2002 +0000
+++ b/mencoder.c	Fri Aug 02 17:44:16 2002 +0000
@@ -1071,7 +1071,7 @@
     if(pts_from_bps){
         unsigned int samples=(sh_audio->audio.dwSampleSize)?
           ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
-          (d_audio->pack_no); // <- used for VBR audio
+          (d_audio->block_no); // <- used for VBR audio
 //	printf("samples=%d  \n",samples);
         a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate;
       delay_corrected=1;
@@ -1119,7 +1119,7 @@
 	float len=(demuxer->movi_end-demuxer->movi_start);
 	float p=len>1000 ? (float)(demuxer->filepos-demuxer->movi_start) / len : 0;
 	if(!len && sh_audio && sh_audio->audio.dwLength>100){
-	    p=(sh_audio->audio.dwSampleSize? ds_tell(sh_audio->ds)/sh_audio->audio.dwSampleSize : sh_audio->ds->pack_no)
+	    p=(sh_audio->audio.dwSampleSize? ds_tell(sh_audio->ds)/sh_audio->audio.dwSampleSize : sh_audio->ds->block_no)
 	     / (float)(sh_audio->audio.dwLength);
 	}
 #if 0
--- a/mplayer.c	Fri Aug 02 17:41:02 2002 +0000
+++ b/mplayer.c	Fri Aug 02 17:44:16 2002 +0000
@@ -1769,7 +1769,7 @@
 	// PTS = sample_no / samplerate
         unsigned int samples=(sh_audio->audio.dwSampleSize)?
           ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
-          (d_audio->pack_no); // <- used for VBR audio
+          (d_audio->block_no); // <- used for VBR audio
 	samples+=sh_audio->audio.dwStart; // offset
         a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate;
 	delay_corrected=1;