]> git.sesse.net Git - vlc/blobdiff - modules/packetizer/vc1.c
Fix parsing of SPS for particular profiles
[vlc] / modules / packetizer / vc1.c
index 4511ef1cf98421e6837dc65de4e75043e0be0277..15ee82a187ca43372ef245985013ea528d35ca31 100644 (file)
@@ -2,7 +2,7 @@
  * vc1.c
  *****************************************************************************
  * Copyright (C) 2001, 2002, 2006 the VideoLAN team
- * $Id: copy.c 18231 2006-12-03 17:02:02Z courmisch $
+ * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Gildas Bazin <gbazin@videolan.org>
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_codec.h>
 #include <vlc_block.h>
 
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
-vlc_module_begin();
-    set_category( CAT_SOUT );
-    set_subcategory( SUBCAT_SOUT_PACKETIZER );
-    set_description( _("VC-1 packetizer") );
-    set_capability( "packetizer", 50 );
-    set_callbacks( Open, Close );
-vlc_module_end();
+vlc_module_begin ()
+    set_category( CAT_SOUT )
+    set_subcategory( SUBCAT_SOUT_PACKETIZER )
+    set_description( N_("VC-1 packetizer") )
+    set_capability( "packetizer", 50 )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 /*****************************************************************************
  * Local prototypes
@@ -58,28 +62,28 @@ struct decoder_sys_t
      */
     block_bytestream_t bytestream;
     int i_state;
-    int i_offset;
+    size_t i_offset;
     uint8_t p_startcode[3];
 
     /* Current sequence header */
-    vlc_bool_t b_sequence_header;
+    bool b_sequence_header;
     struct
     {
         block_t *p_sh;
-        vlc_bool_t b_advanced_profile;
-        vlc_bool_t b_interlaced;
-        vlc_bool_t b_frame_interpolation;
-        vlc_bool_t b_range_reduction;
-        vlc_bool_t b_has_bframe;
+        bool b_advanced_profile;
+        bool b_interlaced;
+        bool b_frame_interpolation;
+        bool b_range_reduction;
+        bool b_has_bframe;
     } sh;
-    vlc_bool_t b_entry_point;
+    bool b_entry_point;
     struct
     {
         block_t *p_ep;
     } ep;
 
     /* */
-    vlc_bool_t  b_frame;
+    bool  b_frame;
 
     /* Current frame being built */
     block_t    *p_frame;
@@ -134,18 +138,18 @@ static int Open( vlc_object_t *p_this )
     p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) );
 
     p_sys->i_state = STATE_NOSYNC;
-    p_sys->bytestream = block_BytestreamInit( p_dec );
+    p_sys->bytestream = block_BytestreamInit();
     p_sys->p_startcode[0] = 0x00;
     p_sys->p_startcode[1] = 0x00;
     p_sys->p_startcode[2] = 0x01;
     p_sys->i_offset = 0;
 
-    p_sys->b_sequence_header = VLC_FALSE;
+    p_sys->b_sequence_header = false;
     p_sys->sh.p_sh = NULL;
-    p_sys->b_entry_point = VLC_FALSE;
+    p_sys->b_entry_point = false;
     p_sys->ep.p_ep = NULL;
 
-    p_sys->b_frame = VLC_FALSE;
+    p_sys->b_frame = false;
     p_sys->p_frame = NULL;
     p_sys->pp_last = &p_sys->p_frame;
 
@@ -194,13 +198,20 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
     if( pp_block == NULL || *pp_block == NULL )
         return NULL;
 
-    if( (*pp_block)->i_flags & (BLOCK_FLAG_CORRUPTED|BLOCK_FLAG_DISCONTINUITY) )
+    if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
     {
-        p_sys->i_state = STATE_NOSYNC;
-        if( p_sys->p_frame )
-            block_ChainRelease( p_sys->p_frame );
-        p_sys->p_frame = NULL;
-        p_sys->pp_last = &p_sys->p_frame;
+        if( (*pp_block)->i_flags&BLOCK_FLAG_CORRUPTED )
+        {
+            p_sys->i_state = STATE_NOSYNC;
+            block_BytestreamFlush( &p_sys->bytestream );
+
+            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 = false;
+        }
+//        p_sys->i_interpolated_dts = 0;
         block_Release( *pp_block );
         return NULL;
     }
@@ -241,7 +252,6 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
             block_BytestreamFlush( &p_sys->bytestream );
             p_pic->i_pts = p_sys->bytestream.p_block->i_pts;
             p_pic->i_dts = p_sys->bytestream.p_block->i_dts;
-            p_pic->i_rate = p_sys->bytestream.p_block->i_rate;
 
             block_GetBytes( &p_sys->bytestream, p_pic->p_buffer, p_pic->i_buffer );
 
@@ -327,7 +337,7 @@ static void BuildExtraData( decoder_t *p_dec )
     memcpy( (uint8_t*)p_es->p_extra + p_sys->sh.p_sh->i_buffer,
             p_sys->ep.p_ep->p_buffer, p_sys->ep.p_ep->i_buffer );
 }
-/* ParseIDU: parse an Independant Decoding Unit */
+/* ParseIDU: parse an Independent Decoding Unit */
 static block_t *ParseIDU( decoder_t *p_dec, block_t *p_frag )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
@@ -363,11 +373,11 @@ static block_t *ParseIDU( decoder_t *p_dec, block_t *p_frag )
         /* We can interpolate dts/pts only if we have a frame rate */
         if( p_dec->fmt_out.video.i_frame_rate != 0 && p_dec->fmt_out.video.i_frame_rate_base != 0 )
         {
-            //msg_Dbg( p_dec, "-------------- XXX0 dts="I64Fd" pts="I64Fd" interpolated="I64Fd, p_pic->i_dts, p_pic->i_pts, p_sys->i_interpolated_dts );
+            //msg_Dbg( p_dec, "-------------- XXX0 dts=%"PRId64" pts=%"PRId64" interpolated=%"PRId64, p_pic->i_dts, p_pic->i_pts, p_sys->i_interpolated_dts );
             if( p_pic->i_dts <= 0 )
                 p_pic->i_dts = p_sys->i_interpolated_dts;
 
-            p_sys->i_interpolated_dts += I64C(1000000) * p_dec->fmt_out.video.i_frame_rate_base / p_dec->fmt_out.video.i_frame_rate;
+            p_sys->i_interpolated_dts += INT64_C(1000000) * p_dec->fmt_out.video.i_frame_rate_base / p_dec->fmt_out.video.i_frame_rate;
             if( p_pic->i_pts <= 0 )
             {
                 if( !p_sys->sh.b_has_bframe || (p_pic->i_flags & BLOCK_FLAG_TYPE_B ) )
@@ -377,7 +387,7 @@ static block_t *ParseIDU( decoder_t *p_dec, block_t *p_frag )
         }
         p_sys->i_interpolated_dts = p_pic->i_dts;
 
-        //msg_Dbg( p_dec, "-------------- dts="I64Fd" pts="I64Fd, p_pic->i_dts, p_pic->i_pts );
+        //msg_Dbg( p_dec, "-------------- dts=%"PRId64" pts=%"PRId64, p_pic->i_dts, p_pic->i_pts );
 
         /* Reset context */
         p_sys->p_frame = NULL;
@@ -417,8 +427,8 @@ static block_t *ParseIDU( decoder_t *p_dec, block_t *p_frag )
         if( i_ridu > 4 && (ridu[0]&0x80) == 0 ) /* for advanced profile, the first bit is 1 */
         {
             video_format_t *p_v = &p_dec->fmt_in.video;
-            const int i_potential_width  = GetWBE( &ridu[0] );
-            const int i_potential_height = GetWBE( &ridu[2] );
+            const size_t i_potential_width  = GetWBE( &ridu[0] );
+            const size_t i_potential_height = GetWBE( &ridu[2] );
 
             if( i_potential_width >= 2  && i_potential_width <= 8192 &&
                 i_potential_height >= 2 && i_potential_height <= 8192 )
@@ -446,9 +456,9 @@ static block_t *ParseIDU( decoder_t *p_dec, block_t *p_frag )
             const int i_level = bs_read( &s, 3 );
 
             /* Advanced profile */
-            p_sys->sh.b_advanced_profile = VLC_TRUE;
-            p_sys->sh.b_range_reduction = VLC_FALSE;
-            p_sys->sh.b_has_bframe = VLC_TRUE;
+            p_sys->sh.b_advanced_profile = true;
+            p_sys->sh.b_range_reduction = false;
+            p_sys->sh.b_has_bframe = true;
 
             bs_skip( &s, 2+3+5+1 ); // chroma format + frame rate Q + bit rate Q + postprocflag
 
@@ -484,7 +494,7 @@ static block_t *ParseIDU( decoder_t *p_dec, block_t *p_frag )
                         {64,33}, {160,99},{ 0, 0}, { 0, 0}
                     };
                     int i_ar = bs_read( &s, 4 );
-                    int i_ar_w, i_ar_h;
+                    unsigned i_ar_w, i_ar_h;
 
                     if( i_ar == 15 )
                     {
@@ -541,8 +551,8 @@ static block_t *ParseIDU( decoder_t *p_dec, block_t *p_frag )
         else
         {
             /* Simple and main profile */
-            p_sys->sh.b_advanced_profile = VLC_FALSE;
-            p_sys->sh.b_interlaced = VLC_FALSE;
+            p_sys->sh.b_advanced_profile = false;
+            p_sys->sh.b_interlaced = false;
 
             if( !p_sys->b_sequence_header )
                 msg_Dbg( p_dec, "found sequence header for %s profile", i_profile == 0 ? "simple" : "main" );
@@ -552,14 +562,14 @@ static block_t *ParseIDU( decoder_t *p_dec, block_t *p_frag )
                          1+1+1+1 );     // variable size transform + reserved + overlap + sync marker
             p_sys->sh.b_range_reduction = bs_read( &s, 1 );
             if( bs_read( &s, 3 ) > 0 )
-                p_sys->sh.b_has_bframe = VLC_TRUE;
+                p_sys->sh.b_has_bframe = true;
             else
-                p_sys->sh.b_has_bframe = VLC_FALSE;
+                p_sys->sh.b_has_bframe = false;
             bs_skip( &s, 2 );           // quantizer
 
             p_sys->sh.b_frame_interpolation = bs_read( &s, 1 );
         }
-        p_sys->b_sequence_header = VLC_TRUE;
+        p_sys->b_sequence_header = true;
         BuildExtraData( p_dec );
     }
     else if( idu == IDU_TYPE_ENTRY_POINT )
@@ -568,7 +578,7 @@ static block_t *ParseIDU( decoder_t *p_dec, block_t *p_frag )
             block_Release( p_sys->ep.p_ep );
         p_sys->ep.p_ep = block_Duplicate( p_frag );
 
-        p_sys->b_entry_point = VLC_TRUE;
+        p_sys->b_entry_point = true;
         BuildExtraData( p_dec );
     }
     else if( idu == IDU_TYPE_FRAME )
@@ -650,7 +660,7 @@ static block_t *ParseIDU( decoder_t *p_dec, block_t *p_frag )
             else
                 p_sys->p_frame->i_flags |= BLOCK_FLAG_TYPE_B;
         }
-        p_sys->b_frame = VLC_TRUE;
+        p_sys->b_frame = true;
     }
     return p_pic;
 }