summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrtognimp <rtognimp@b3059339-0415-0410-9bf9-f77b7e298cf2>2006-04-24 10:58:40 +0000
committerrtognimp <rtognimp@b3059339-0415-0410-9bf9-f77b7e298cf2>2006-04-24 10:58:40 +0000
commit6c4d9bfe5127da2a4e2afbe1d6e585ebeb7c5949 (patch)
tree6057e1a4875492c40543d4ac2e43adbbd53afff2
parent4b45ec30e4b8ced93aa10792aa18a8f96b3cd104 (diff)
downloadmpv-6c4d9bfe5127da2a4e2afbe1d6e585ebeb7c5949.tar.bz2
mpv-6c4d9bfe5127da2a4e2afbe1d6e585ebeb7c5949.tar.xz
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
-rw-r--r--libmpcodecs/ad_faad.c8
-rw-r--r--libmpcodecs/ad_ffmpeg.c8
-rw-r--r--libmpcodecs/ad_libvorbis.c8
-rw-r--r--libmpdemux/demuxer.c21
-rw-r--r--libmpdemux/demuxer.h1
-rw-r--r--libmpdemux/stheader.h2
-rw-r--r--mplayer.c20
7 files changed, 55 insertions, 13 deletions
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;j<faac_finfo.channels;j++) printf("%d:%d\n", j, faac_finfo.channel_position[j]);
@@ -271,6 +276,7 @@ static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen)
memcpy(buf+len,faac_sample_buffer, sh->samplesize*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(len<minlen){
int len2=0;
- int x=ds_get_packet(sh_audio->ds,&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
diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c
index f45d325d55..14709e9e82 100644
--- a/libmpdemux/demuxer.c
+++ b/libmpdemux/demuxer.c
@@ -224,6 +224,7 @@ sh_audio_t* new_sh_audio(demuxer_t *demuxer,int id){
sh->samplesize=2;
sh->sample_format=AF_FORMAT_S16_NE;
sh->audio_out_minsize=8192;/* default size, maybe not enough for Win32/ACM*/
+ sh->pts=MP_NOPTS_VALUE;
if (!demux_aid_vid_mismatch)
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_ID=%d\n", id);
}
@@ -502,6 +503,26 @@ int ds_get_packet(demux_stream_t *ds,unsigned char **start){
}
}
+int ds_get_packet_pts(demux_stream_t *ds,unsigned char **start, double *pts)
+{
+ int len;
+ *pts = MP_NOPTS_VALUE;
+ if(ds->buffer_pos>=ds->buffer_size){
+ if (!ds_fill_buffer(ds)) {
+ // EOF
+ *start = NULL;
+ return -1;
+ }
+ // Should use MP_NOPTS_VALUE for "unknown pts" in the packets too
+ if (ds->current->pts)
+ *pts = ds->current->pts;
+ }
+ len=ds->buffer_size-ds->buffer_pos;
+ *start = &ds->buffer[ds->buffer_pos];
+ ds->buffer_pos+=len;
+ return len;
+}
+
int ds_get_packet_sub(demux_stream_t *ds,unsigned char **start){
while(1){
int len;
diff --git a/libmpdemux/demuxer.h b/libmpdemux/demuxer.h
index 939a3b5577..35c3ac3982 100644
--- a/libmpdemux/demuxer.h
+++ b/libmpdemux/demuxer.h
@@ -284,6 +284,7 @@ inline static int demux_getc(demux_stream_t *ds){
void ds_free_packs(demux_stream_t *ds);
int ds_get_packet(demux_stream_t *ds,unsigned char **start);
+int ds_get_packet_pts(demux_stream_t *ds, unsigned char **start, double *pts);
int ds_get_packet_sub(demux_stream_t *ds,unsigned char **start);
float ds_get_next_pts(demux_stream_t *ds);
diff --git a/libmpdemux/stheader.h b/libmpdemux/stheader.h
index 3fcfebac7c..bc6a63cd45 100644
--- a/libmpdemux/stheader.h
+++ b/libmpdemux/stheader.h
@@ -47,6 +47,8 @@ typedef struct {
void* context; // codec-specific stuff (usually HANDLE or struct pointer)
unsigned char* codecdata; // extra header data passed from demuxer to codec
int codecdata_len;
+ double pts; // last known pts value in output from decoder
+ int pts_bytes; // bytes output by decoder after last known pts
} sh_audio_t;
typedef struct {
diff --git a/mplayer.c b/mplayer.c
index ea1999bb63..d129e2ef15 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -3874,6 +3874,7 @@ if(time_frame>0.001 && !(vo_flags&256)){
delay=sh_audio->delay;
delay+=(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps;
}
+ delay += sh_audio->a_out_buffer_len*playback_speed/(float)ao_data.bps;
#if 0
if(pts_from_bps){
@@ -3890,16 +3891,15 @@ if(time_frame>0.001 && !(vo_flags&256)){
#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;
-#if 0
- mp_msg(MSGT_FIXME, MSGL_FIXME, "\n#X# pts=%5.3f ds_pts=%5.3f buff=%5.3f total=%5.3f\n",
- a_pts,
- ds_tell_pts(d_audio)/(float)sh_audio->i_bps,
- -sh_audio->a_in_buffer_len/(float)sh_audio->i_bps,
- a_pts+(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps);
-#endif
- a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps - sh_audio->a_out_buffer_len*playback_speed/(float)ao_data.bps;
+ a_pts = sh_audio->pts;
+ if (a_pts == MP_NOPTS_VALUE) {
+ // Decoder doesn't support tracking timestamps or demuxer doesn't
+ // set them properly in individual packets, use old inaccurate method
+ a_pts=d_audio->pts;
+ a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
+ }
+ else
+ a_pts += sh_audio->pts_bytes / (float)sh_audio->o_bps;
}
v_pts=sh_video ? sh_video->pts : d_video->pts;