]> git.sesse.net Git - vlc/blobdiff - modules/packetizer/mpegvideo.c
Removes trailing spaces. Removes tabs.
[vlc] / modules / packetizer / mpegvideo.c
index f65e3b6a444130bc65ac11d98a8db2cd0803cb29..704f4d08d7cad2a28c39575e7dd7c6c957eeafab 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * mpegvideo.c: parse and packetize an MPEG1/2 video stream
  *****************************************************************************
- * Copyright (C) 2001-2005 VideoLAN (Centrale Réseaux) and its contributors
+ * Copyright (C) 2001-2006 the VideoLAN team
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 
 #include <vlc/vlc.h>
-#include <vlc/decoder.h>
-#include <vlc/input.h>
+#include <vlc_block.h>
+#include <vlc_codec.h>
+#include <vlc_block_helper.h>
 
-#include "vlc_block_helper.h"
-
-#define SYNC_INTRAFRAME_TEXT N_("Sync on intraframe")
+#define SYNC_INTRAFRAME_TEXT N_("Sync on Intra Frame")
 #define SYNC_INTRAFRAME_LONGTEXT N_("Normally the packetizer would " \
     "sync on the next full frame. This flags instructs the packetizer " \
-    "to sync on the first intraframe found.")
+    "to sync on the first Intra Frame found.")
 
 /*****************************************************************************
  * Module descriptor
@@ -116,8 +114,8 @@ struct decoder_sys_t
     int i_progressive_frame;
 
     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;
@@ -183,13 +181,13 @@ static int Open( vlc_object_t *p_this )
     p_sys->b_inited = 0;
 
     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" );
     if( p_sys->b_sync_on_intra_frame )
-        msg_Dbg( p_dec, "syncing happens on intraframe now." );
+        msg_Dbg( p_dec, "syncing on intra frame now" );
 
     return VLC_SUCCESS;
 }
@@ -235,19 +233,28 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     }
 
-    if( (*pp_block)->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
+    if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
     {
-        p_sys->i_state = STATE_NOSYNC;
-        p_sys->b_discontinuity = VLC_TRUE;
-        if( p_sys->p_frame )
-            block_ChainRelease( p_sys->p_frame );
-        p_sys->p_frame = NULL;
-        p_sys->pp_last = &p_sys->p_frame;
-        p_sys->b_frame_slice = VLC_FALSE;
+        if( (*pp_block)->i_flags&BLOCK_FLAG_CORRUPTED )
+        {
+            p_sys->i_state = STATE_NOSYNC;
+            block_BytestreamFlush( &p_sys->bytestream );
+
+            p_sys->b_discontinuity = VLC_TRUE;
+            if( p_sys->p_frame )
+                block_ChainRelease( p_sys->p_frame );
+            p_sys->p_frame = NULL;
+            p_sys->pp_last = &p_sys->p_frame;
+            p_sys->b_frame_slice = VLC_FALSE;
+        }
+//        p_sys->i_interpolated_dts =
+//        p_sys->i_last_ref_pts = 0;
+
         block_Release( *pp_block );
         return NULL;
     }
 
+
     block_BytestreamPush( &p_sys->bytestream, *pp_block );
 
     while( 1 )
@@ -322,13 +329,13 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
             {
                 if( p_pic->i_flags & BLOCK_FLAG_TYPE_I )
                 {
-                    msg_Dbg( p_dec, "synced on Intra frame" );
+                    msg_Dbg( p_dec, "synced on intra frame" );
                     p_sys->b_discontinuity = VLC_FALSE;
                     p_pic->i_flags |= BLOCK_FLAG_DISCONTINUITY;
                 }
                 else
                 {
-                    msg_Dbg( p_dec, "waiting on Intra frame" );
+                    msg_Dbg( p_dec, "waiting on intra frame" );
                     p_sys->i_state = STATE_NOSYNC;
                     block_Release( p_pic );
                     break;
@@ -433,14 +440,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 +465,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 +489,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;
+        }
     }
 
     /*
@@ -554,7 +561,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
 
         if ( !p_sys->b_inited )
         {
-            msg_Dbg( p_dec, "Size %dx%d fps=%.3f",
+            msg_Dbg( p_dec, "size %dx%d fps=%.3f",
                  p_dec->fmt_out.video.i_width, p_dec->fmt_out.video.i_height,
                  p_sys->i_frame_rate / (float)p_sys->i_frame_rate_base );
             p_sys->b_inited = 1;
@@ -564,7 +571,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
     {
         int i_type = p_frag->p_buffer[4] >> 4;
 
-        /* Extention start code */
+        /* Extension start code */
         if( i_type == 0x01 )
         {
 #if 0
@@ -576,7 +583,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
             };
 #endif
 
-            /* sequence extention */
+            /* sequence extension */
             if( p_sys->p_ext) block_Release( p_sys->p_ext );
             p_sys->p_ext = block_Duplicate( p_frag );
 
@@ -604,7 +611,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
         }
         else if( i_type == 0x08 )
         {
-            /* picture extention */
+            /* picture extension */
             p_sys->i_picture_structure = p_frag->p_buffer[6]&0x03;
             p_sys->i_top_field_first   = p_frag->p_buffer[7] >> 7;
             p_sys->i_repeat_first_field= (p_frag->p_buffer[7]>>1)&0x01;