From 6c4d9bfe5127da2a4e2afbe1d6e585ebeb7c5949 Mon Sep 17 00:00:00 2001 From: rtognimp Date: Mon, 24 Apr 2006 10:58:40 +0000 Subject: 4 - Implement a better way to calculate current audio pts and use it for audio decoded with ad_libvorbis, ad_ffmpeg and ad_faad. Patch by Uoti Urpala git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@18243 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpcodecs/ad_faad.c | 8 +++++++- libmpcodecs/ad_ffmpeg.c | 8 +++++++- libmpcodecs/ad_libvorbis.c | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) (limited to 'libmpcodecs') diff --git a/libmpcodecs/ad_faad.c b/libmpcodecs/ad_faad.c index b681a9c7a3..80470d4a49 100644 --- a/libmpcodecs/ad_faad.c +++ b/libmpcodecs/ad_faad.c @@ -253,8 +253,13 @@ static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen) } else { // packetized (.mp4) aac stream: unsigned char* bufptr=NULL; - int buflen=ds_get_packet(sh->ds, &bufptr); + double pts; + int buflen=ds_get_packet_pts(sh->ds, &bufptr, &pts); if(buflen<=0) break; + if (pts != MP_NOPTS_VALUE) { + sh->pts = pts; + sh->pts_bytes = 0; + } faac_sample_buffer = faacDecDecode(faac_hdec, &faac_finfo, bufptr, buflen); } //for (j=0;jsamplesize*faac_finfo.samples); last_dec_len = sh->samplesize*faac_finfo.samples; len += last_dec_len; + sh->pts_bytes += last_dec_len; //printf("FAAD: buffer: %d bytes consumed: %d \n", k, faac_finfo.bytesconsumed); } } diff --git a/libmpcodecs/ad_ffmpeg.c b/libmpcodecs/ad_ffmpeg.c index 22cb72b8a5..f9fb0455a6 100644 --- a/libmpcodecs/ad_ffmpeg.c +++ b/libmpcodecs/ad_ffmpeg.c @@ -149,8 +149,13 @@ static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int m int y,len=-1; while(lends,&start); + double pts; + int x=ds_get_packet_pts(sh_audio->ds,&start, &pts); if(x<=0) break; // error + if (pts != MP_NOPTS_VALUE) { + sh_audio->pts = pts; + sh_audio->pts_bytes = 0; + } y=avcodec_decode_audio(sh_audio->context,(int16_t*)buf,&len2,start,x); //printf("return:%d samples_out:%d bitstream_in:%d sample_sum:%d\n", y, len2, x, len); fflush(stdout); if(y<0){ mp_msg(MSGT_DECAUDIO,MSGL_V,"lavc_audio: error\n");break; } @@ -159,6 +164,7 @@ static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int m //len=len2;break; if(len<0) len=len2; else len+=len2; buf+=len2; + sh_audio->pts_bytes += len2; } mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"Decoded %d -> %d \n",y,len2); } diff --git a/libmpcodecs/ad_libvorbis.c b/libmpcodecs/ad_libvorbis.c index 3c765b6acd..2d94ac4431 100644 --- a/libmpcodecs/ad_libvorbis.c +++ b/libmpcodecs/ad_libvorbis.c @@ -229,9 +229,14 @@ static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen) while(len < minlen) { while((samples=vorbis_synthesis_pcmout(&ov->vd,&pcm))<=0){ ogg_packet op; + double pts; memset(&op,0,sizeof(op)); //op.b_o_s = op.e_o_s = 0; - op.bytes = ds_get_packet(sh->ds,&op.packet); + op.bytes = ds_get_packet_pts(sh->ds,&op.packet, &pts); if(op.bytes<=0) break; + if (pts != MP_NOPTS_VALUE) { + sh->pts = pts; + sh->pts_bytes = 0; + } if(vorbis_synthesis(&ov->vb,&op)==0) /* test for success! */ vorbis_synthesis_blockin(&ov->vd,&ov->vb); } @@ -303,6 +308,7 @@ static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen) if(clipflag) mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"Clipping in frame %ld\n",(long)(ov->vd.sequence)); len+=2*ov->vi.channels*bout; + sh->pts_bytes += 2*ov->vi.channels*bout; mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[decoded: %d / %d ]\n",bout,samples); samples-=bout; vorbis_synthesis_read(&ov->vd,bout); /* tell libvorbis how -- cgit v1.2.3