Mercurial > mplayer.hg
changeset 8030:2b39ff3860b7
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)
author | arpi |
---|---|
date | Sat, 02 Nov 2002 00:45:12 +0000 |
parents | 6ccd72982b88 |
children | ad62a544964c |
files | libmpdemux/aviheader.h libmpdemux/demux_avi.c libmpdemux/demuxer.c libmpdemux/demuxer.h mencoder.c mplayer.c |
diffstat | 6 files changed, 58 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/libmpdemux/aviheader.h Sat Nov 02 00:27:57 2002 +0000 +++ b/libmpdemux/aviheader.h Sat Nov 02 00:45:12 2002 +0000 @@ -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;
--- a/libmpdemux/demux_avi.c Sat Nov 02 00:27:57 2002 +0000 +++ b/libmpdemux/demux_avi.c Sat Nov 02 00:45:12 2002 +0000 @@ -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 {
--- a/libmpdemux/demuxer.c Sat Nov 02 00:27:57 2002 +0000 +++ b/libmpdemux/demuxer.c Sat Nov 02 00:45:12 2002 +0000 @@ -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;
--- a/libmpdemux/demuxer.h Sat Nov 02 00:27:57 2002 +0000 +++ b/libmpdemux/demuxer.h Sat Nov 02 00:45:12 2002 +0000 @@ -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; @@ -185,10 +182,6 @@ 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); int demux_read_data_pack(demux_stream_t *ds,unsigned char* mem,int len);
--- a/mencoder.c Sat Nov 02 00:27:57 2002 +0000 +++ b/mencoder.c Sat Nov 02 00:45:12 2002 +0000 @@ -647,7 +647,7 @@ mux_v->bih->biCompression, (char *)&mux_v->bih->biCompression); } -if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf! +//if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf! // ============= AUDIO =============== if(sh_audio){ @@ -1053,6 +1053,7 @@ if(sh_audio && !demuxer2){ float AV_delay,x; // A-V sync! +#if 0 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) : @@ -1060,7 +1061,9 @@ // printf("samples=%d \n",samples); a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate; delay_corrected=1; - } else { + } else +#endif + { // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec) a_pts=d_audio->pts; if(!delay_corrected) if(a_pts) delay_corrected=1; @@ -1103,10 +1106,12 @@ { float t=(GetTimerMS()-timer_start)*0.001f; float len=(demuxer->movi_end-demuxer->movi_start); float p=len>1000 ? (float)(demuxer->filepos-demuxer->movi_start) / len : 0; +#if 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->block_no) / (float)(sh_audio->audio.dwLength); } +#endif #if 0 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"%d < %d < %d \r", (int)demuxer->movi_start,
--- a/mplayer.c Sat Nov 02 00:27:57 2002 +0000 +++ b/mplayer.c Sat Nov 02 00:45:12 2002 +0000 @@ -1369,7 +1369,7 @@ if (!sh_video && !sh_audio) goto goto_next_file; -if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf! +//if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf! if(force_fps && sh_video){ vo_fps = sh_video->fps=force_fps; sh_video->frametime=1.0f/sh_video->fps; @@ -1697,6 +1697,7 @@ delay+=(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps; } +#if 0 if(pts_from_bps){ // PTS = sample_no / samplerate unsigned int samples= @@ -1707,7 +1708,9 @@ a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate; delay_corrected=1; a_pts-=(sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; - } else { + } else +#endif + { // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec) a_pts=d_audio->pts; if(!delay_corrected) if(a_pts) delay_corrected=1;