From bb561230652d8ff4961c0ef749304a24d47a9170 Mon Sep 17 00:00:00 2001 From: arpi Date: Thu, 16 Jan 2003 22:34:46 +0000 Subject: [PATCH] fixed the well-known DVD/DVB audio delay bug :) git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8966 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/stheader.h | 3 +++ libmpdemux/video.c | 29 ++++++++++++++++++++++++++++- mplayer.c | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/libmpdemux/stheader.h b/libmpdemux/stheader.h index af79be5bed..79a687d216 100644 --- a/libmpdemux/stheader.h +++ b/libmpdemux/stheader.h @@ -91,6 +91,9 @@ typedef struct { // frame counters: float num_frames; // number of frames played int num_frames_decoded; // number of frames decoded + // timing (mostly for mpeg): + float pts; // predicted/interpolated PTS of the current frame + float i_pts; // PTS for the _next_ I/P frame // output format: (set by demuxer) float fps; // frames per second (set only if constant fps) float frametime; // 1/fps diff --git a/libmpdemux/video.c b/libmpdemux/video.c index b883142b62..0c643c18fb 100644 --- a/libmpdemux/video.c +++ b/libmpdemux/video.c @@ -214,6 +214,8 @@ int video_read_frame(sh_video_t* sh_video,float* frame_time_ptr,unsigned char** demuxer_t *demuxer=d_video->demuxer; float frame_time=1; float pts1=d_video->pts; + float pts=0; + int picture_coding_type=0; // unsigned char* start=NULL; int in_size=0; @@ -246,6 +248,10 @@ int video_read_frame(sh_video_t* sh_video,float* frame_time_ptr,unsigned char** break; } } else { + if(i==0x100){ + pts=d_video->pts; + d_video->pts=0; + } //if(i==0x100) in_frame=1; // picture startcode if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode else if(!i) return -1; // EOF @@ -258,6 +264,7 @@ int video_read_frame(sh_video_t* sh_video,float* frame_time_ptr,unsigned char** case 0x1B3: mp_header_process_sequence_header (&picture, &videobuffer[start]);break; case 0x1B5: mp_header_process_extension (&picture, &videobuffer[start]);break; case 0x1B2: process_userdata (&videobuffer[start], videobuf_len-start);break; + case 0x100: picture_coding_type=(videobuffer[start+1] >> 3) & 7;break; } } @@ -336,7 +343,27 @@ int video_read_frame(sh_video_t* sh_video,float* frame_time_ptr,unsigned char** } if(demuxer->file_format==DEMUXER_TYPE_MPEG_PS || - demuxer->file_format==DEMUXER_TYPE_MPEG_ES) d_video->pts+=frame_time; + demuxer->file_format==DEMUXER_TYPE_MPEG_ES){ + +// if(pts>0.0001) printf("\r!!! pts: %5.3f [%d] (%5.3f) \n",pts,picture_coding_type,i_pts); + + sh_video->pts+=frame_time; + if(picture_coding_type<=2 && sh_video->i_pts){ +// printf("XXX predict: %5.3f pts: %5.3f error=%5.5f \n",i_pts,d_video->pts2,i_pts-d_video->pts2); + sh_video->pts=sh_video->i_pts; + sh_video->i_pts=pts; + } else { + if(pts){ + if(picture_coding_type<=2) sh_video->i_pts=pts; + else { +// printf("BBB predict: %5.3f pts: %5.3f error=%5.5f \n",pts,d_video->pts2,pts-d_video->pts2); + sh_video->pts=pts; + } + } + } +// printf("\rIII pts: %5.3f [%d] (%5.3f) \n",d_video->pts2,picture_coding_type,i_pts); + } else + sh_video->pts=d_video->pts; if(frame_time_ptr) *frame_time_ptr=frame_time; return in_size; diff --git a/mplayer.c b/mplayer.c index 85d6e02793..a54235d073 100644 --- a/mplayer.c +++ b/mplayer.c @@ -2052,7 +2052,7 @@ if(time_frame>0.001 && !(vo_flags&256)){ #endif a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; } - v_pts=d_video->pts; + v_pts=sh_video ? sh_video->pts : d_video->pts; mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"### A:%8.3f (%8.3f) V:%8.3f A-V:%7.4f \n",a_pts,a_pts-audio_delay-delay,v_pts,(a_pts-delay-audio_delay)-v_pts);