[MPlayer-dev-eng] Reverted patch of time-based PTS locking

Pásztor Szilárd don at tricon.hu
Mon Aug 20 15:44:37 CEST 2012


 Reimar Döffinger:
> Well, the problem is that with e.g. mp4 container it is the container
> time stamp that counts, not the one in the frames.
> However you could try having the PTS values reordered by the FFmpeg
> decoder (I think nowadays that works by putting the timestamp in in
> the AVPacket and getting it out in the AVFrame).
> I would kind of like the general code to handle mixed up timestamps
> anyway though if reasonably possible....

 Ok I finally gave up on my hacking attempts. Fumbling in ffmpeg code 
 led
 me to see that much work would be needed in mplayer to make ffmpeg 
 reorder
 pts by setting a lot of stream defaults in a context and the code is 
 way
 too much complicated to worth the effort for me.

 So I instead opted for using the existing (and not bad) pts reorder 
 code
 in mplayer. Here is a patch for it.

 demux_ts.c: change to activate pts correction by default, unless the 
 user
 wants otherwise, and only for H.264. Not a nice solution, but it is the
 same logic as in demux_lavf.c.

 dec_video.c: a safety change and small addition to prevent the "too 
 many
 buffered pts" message. If the frame is to be dropped, the code would 
 have
 ended up putting its pts into the buffer, then returning to drop the 
 frame
 and never removing a pts from the buffer. This is now checked, 
 hopefully
 correctly.

 mplayer.c: important change to prevent framedrop at stream beginning as
 video pts is never initialized from 0 then, causing a huge A-V sync
 difference (audio pts is set regardless), and this resulted in mass
 framedrops and a never-initializing video.

 Please check if this is OK or something should be fixed.

 (I also have a stable new patch for time-based PTS recalculation but it
 doesn't take buffered pts delay into account so A-V sync is not 
 perfect.)
-------------- next part --------------
Index: mplayer/libmpdemux/demux_ts.c
===================================================================
--- mplayer/libmpdemux/demux_ts.c	(revision 35107)
+++ mplayer/libmpdemux/demux_ts.c	(working copy)
@@ -3379,6 +3379,12 @@
 
 	switch(cmd)
 	{
+		case DEMUXER_CTRL_CORRECT_PTS:
+		{
+		    // Hack to return OK if H264 so that pts correction will be active
+		    return ((sh_video_t *)(demuxer->video->sh))->format == 0x10000005 ?
+			DEMUXER_CTRL_OK : DEMUXER_CTRL_DONTKNOW;
+		}
 		case DEMUXER_CTRL_SWITCH_AUDIO:
 		case DEMUXER_CTRL_SWITCH_VIDEO:
 		{
Index: mplayer/libmpcodecs/dec_video.c
===================================================================
--- mplayer/libmpcodecs/dec_video.c	(revision 35107)
+++ mplayer/libmpcodecs/dec_video.c	(working copy)
@@ -404,7 +404,7 @@
 
     delay = get_current_video_decoder_lag(sh_video);
     if (correct_pts && pts != MP_NOPTS_VALUE
-        && (got_picture || sh_video->num_buffered_pts < delay)) {
+        && (mpi || sh_video->num_buffered_pts < delay)) {
         if (sh_video->num_buffered_pts ==
             sizeof(sh_video->buffered_pts) / sizeof(double))
             mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Too many buffered pts\n");
@@ -433,6 +433,9 @@
     tt = t * 0.000001f;
     video_time_usage += tt;
 
+    if (mpi && drop_frame && sh_video->num_buffered_pts)
+	sh_video->num_buffered_pts--;
+
     if (!mpi || drop_frame)
         return NULL;            // error / skipped frame
 
Index: mplayer/mplayer.c
===================================================================
--- mplayer/mplayer.c	(revision 35107)
+++ mplayer/mplayer.c	(working copy)
@@ -1758,7 +1758,8 @@
 {
     // check for frame-drop:
     current_module = "check_framedrop";
-    if (mpctx->sh_audio && !mpctx->d_audio->eof) {
+    // don't let us drop frames until video pts has not yet been picked up
+    if (mpctx->sh_video->pts && mpctx->sh_audio && !mpctx->d_audio->eof) {
         static int dropped_frames;
         float delay = playback_speed * mpctx->audio_out->get_delay();
         float d     = delay - mpctx->delay;


More information about the MPlayer-dev-eng mailing list