changeset 31953:2b390c08ed07

Improve correct-pts with PAFF streams. Patch by P«”sztor Szil«”rd, bartosteka freemail hu
author cehoyos
date Mon, 30 Aug 2010 23:24:56 +0000
parents beaf6bf007a5
children 7eaaed7331f3
files libmpcodecs/dec_video.c libmpcodecs/mp_image.h libmpcodecs/vd_ffmpeg.c
diffstat 3 files changed, 29 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/dec_video.c	Mon Aug 30 16:48:52 2010 +0000
+++ b/libmpcodecs/dec_video.c	Mon Aug 30 23:24:56 2010 +0000
@@ -394,8 +394,21 @@
     unsigned int t = GetTimer();
     unsigned int t2;
     double tt;
+    int delay;
+    int got_picture = 1;
 
-    if (correct_pts && pts != MP_NOPTS_VALUE) {
+    mpi = mpvdec->decode(sh_video, start, in_size, drop_frame);
+
+    //------------------------ frame decoded. --------------------
+
+    if (mpi && mpi->type == MP_IMGTYPE_INCOMPLETE) {
+	got_picture = 0;
+	mpi = NULL;
+    }
+
+    delay = get_current_video_decoder_lag(sh_video);
+    if (correct_pts && pts != MP_NOPTS_VALUE
+        && (got_picture || 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");
@@ -411,10 +424,6 @@
         }
     }
 
-    mpi = mpvdec->decode(sh_video, start, in_size, drop_frame);
-
-    //------------------------ frame decoded. --------------------
-
 #if HAVE_MMX
     // some codecs are broken, and doesn't restore MMX state :(
     // it happens usually with broken/damaged files.
@@ -439,7 +448,6 @@
         mpi->fields &= ~MP_IMGFIELD_TOP_FIRST;
 
     if (correct_pts) {
-        int delay = get_current_video_decoder_lag(sh_video);
         if (sh_video->num_buffered_pts) {
             sh_video->num_buffered_pts--;
             sh_video->pts = sh_video->buffered_pts[sh_video->num_buffered_pts];
--- a/libmpcodecs/mp_image.h	Mon Aug 30 16:48:52 2010 +0000
+++ b/libmpcodecs/mp_image.h	Mon Aug 30 23:24:56 2010 +0000
@@ -86,6 +86,10 @@
 #define MP_IMGTYPE_IPB 4
 // Upper 16 bits give desired buffer number, -1 means get next available
 #define MP_IMGTYPE_NUMBERED 5
+// Doesn't need any buffer, incomplete image (probably a first field only)
+// we need this type to be able to differentiate between half frames and
+// all other cases
+#define MP_IMGTYPE_INCOMPLETE 6
 
 #define MP_MAX_PLANES	4
 
--- a/libmpcodecs/vd_ffmpeg.c	Mon Aug 30 16:48:52 2010 +0000
+++ b/libmpcodecs/vd_ffmpeg.c	Mon Aug 30 23:24:56 2010 +0000
@@ -103,6 +103,11 @@
 static int lavc_param_bitexact=0;
 static char *lavc_avopt = NULL;
 
+static const mp_image_t mpi_no_picture =
+{
+	.type = MP_IMGTYPE_INCOMPLETE
+};
+
 const m_option_t lavc_decode_opts_conf[]={
     {"bug", &lavc_param_workaround_bugs, CONF_TYPE_INT, CONF_RANGE, -1, 999999, NULL},
     {"er", &lavc_param_error_resilience, CONF_TYPE_INT, CONF_RANGE, 0, 99, NULL},
@@ -901,7 +906,12 @@
     }
 //--
 
-    if(!got_picture) return NULL;        // skipped image
+    if(!got_picture) {
+	if (avctx->codec->id == CODEC_ID_H264)
+	    return &mpi_no_picture; // H.264 first field only
+	else
+	    return NULL;    // skipped image
+    }
 
     if(init_vo(sh, avctx->pix_fmt) < 0) return NULL;