]> git.sesse.net Git - vlc/commitdiff
* modules/codec/libmpeg2.c, modules/packetizer/mpegvideo.c: Fixed wrong PTS
authorChristophe Massiot <massiot@videolan.org>
Wed, 8 Nov 2006 14:24:54 +0000 (14:24 +0000)
committerChristophe Massiot <massiot@videolan.org>
Wed, 8 Nov 2006 14:24:54 +0000 (14:24 +0000)
   and DTS for field pictures.

modules/codec/libmpeg2.c
modules/packetizer/mpegvideo.c

index 0205c9170b3eec4f7239d1cd8ead5f6a5869a753..33f9e0dba0b9505ddb4e689f9c52631ee80ec677 100644 (file)
@@ -64,8 +64,9 @@ struct decoder_sys_t
     vlc_bool_t       b_after_sequence_header; /* is it the next frame after
                                                * the sequence header ?    */
     vlc_bool_t       b_slice_i;             /* intra-slice refresh stream */
+    vlc_bool_t       b_second_field;
 
-    vlc_bool_t      b_preroll;
+    vlc_bool_t       b_preroll;
 
     /*
      * Output properties
@@ -143,6 +144,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_sys->p_picture_to_destroy = NULL;
     p_sys->b_garbage_pic = 0;
     p_sys->b_slice_i  = 0;
+    p_sys->b_second_field = 0;
     p_sys->b_skip     = 0;
     p_sys->b_preroll = VLC_FALSE;
 
@@ -339,20 +341,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         break;
 
         case STATE_PICTURE_2ND:
-            vout_SynchroNewPicture( p_sys->p_synchro,
-                p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
-                p_sys->p_info->current_picture->nb_fields,
-                0, 0, p_sys->i_current_rate,
-                p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
-
-            if( p_sys->b_skip )
-            {
-                vout_SynchroTrash( p_sys->p_synchro );
-            }
-            else
-            {
-                vout_SynchroDecode( p_sys->p_synchro );
-            }
+            p_sys->b_second_field = 1;
             break;
 
         case STATE_PICTURE:
@@ -408,8 +397,15 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                   p_sys->i_current_dts : p_sys->i_previous_dts ) : 0;
 #endif
 
+            /* If nb_fields == 1, it is a field picture, and it will be
+             * followed by another field picture for which we won't call
+             * vout_SynchroNewPicture() because this would have other 
+             * problems, so we take it into account here.
+             * This kind of sucks, but I didn't think better. --Meuuh
+             */
             vout_SynchroNewPicture( p_sys->p_synchro,
                 p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
+                p_sys->p_info->current_picture->nb_fields == 1 ? 2 :
                 p_sys->p_info->current_picture->nb_fields, i_pts, i_dts,
                 p_sys->i_current_rate,
                 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
index c307db513ce9f091d664217823f013f9f3400850..18402807e86eae208fdc7d49858eea9141a3c9d6 100644 (file)
@@ -118,6 +118,7 @@ struct decoder_sys_t
     mtime_t i_interpolated_dts;
     mtime_t i_old_duration;
     mtime_t i_last_ref_pts;
+    vlc_bool_t b_second_field;
 
     /* Number of pictures since last sequence header */
     int i_seq_old;
@@ -185,6 +186,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->i_interpolated_dts = 0;
     p_sys->i_old_duration = 0;
     p_sys->i_last_ref_pts = 0;
+    p_sys->b_second_field = 0;
 
     p_sys->b_discontinuity = VLC_FALSE;
     p_sys->b_sync_on_intra_frame = var_CreateGetBool( p_dec, "packetizer-mpegvideo-sync-iframe" );
@@ -433,14 +435,16 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
         else
         {
             /* Correct interpolated dts when we receive a new pts/dts */
-            if( p_sys->i_last_ref_pts > 0 )
+            if( p_sys->i_last_ref_pts > 0 && !p_sys->b_second_field )
                 p_sys->i_interpolated_dts = p_sys->i_last_ref_pts;
             if( p_sys->i_dts > 0 ) p_sys->i_interpolated_dts = p_sys->i_dts;
 
-            p_sys->i_last_ref_pts = p_sys->i_pts;
+            if( !p_sys->b_second_field )
+                p_sys->i_last_ref_pts = p_sys->i_pts;
         }
 
         p_pic->i_dts = p_sys->i_interpolated_dts;
+        p_sys->i_interpolated_dts += i_duration;
 
         /* Set PTS only if we have a B frame or if it comes from the stream */
         if( p_sys->i_pts > 0 )
@@ -456,17 +460,6 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
             p_pic->i_pts = 0;
         }
 
-        if( p_sys->b_low_delay || p_sys->i_picture_type == 0x03 )
-        {
-            /* Trivial case (DTS == PTS) */
-            p_sys->i_interpolated_dts += i_duration;
-        }
-        else
-        {
-            p_sys->i_interpolated_dts += p_sys->i_old_duration;
-            p_sys->i_old_duration = i_duration;
-        }
-
         switch ( p_sys->i_picture_type )
         {
         case 0x01:
@@ -491,6 +484,15 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
         p_sys->p_frame = NULL;
         p_sys->pp_last = &p_sys->p_frame;
         p_sys->b_frame_slice = VLC_FALSE;
+
+        if( p_sys->i_picture_structure != 0x03 )
+        {
+            p_sys->b_second_field = !p_sys->b_second_field;
+        }
+        else
+        {
+            p_sys->b_second_field = 0;
+        }
     }
 
     /*