]> git.sesse.net Git - vlc/blobdiff - modules/packetizer/h264.c
Fix Windows case which implements fd_set differently:
[vlc] / modules / packetizer / h264.c
index 0825ae9bdb306de32b3f2dd017ba997d7b7cbce1..31cef6cff98c2151e89fc2ea4c8fa152c4783775 100644 (file)
@@ -27,7 +27,6 @@
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 
 #include <vlc/vlc.h>
 #include <vlc_sout.h>
@@ -246,23 +245,27 @@ static int Open( vlc_object_t *p_this )
         /* FIXME: FFMPEG isn't happy at all if you leave this */
         if( p_dec->fmt_out.i_extra ) free( p_dec->fmt_out.p_extra );
         p_dec->fmt_out.i_extra = 0; p_dec->fmt_out.p_extra = NULL;
-        
+
         /* Set the new extradata */
         p_dec->fmt_out.i_extra = p_sys->p_pps->i_buffer + p_sys->p_sps->i_buffer;
         p_dec->fmt_out.p_extra = (uint8_t*)malloc( p_dec->fmt_out.i_extra );
-        memcpy( (uint8_t*)p_dec->fmt_out.p_extra, p_sys->p_sps->p_buffer, p_sys->p_sps->i_buffer);
-        memcpy( (uint8_t*)p_dec->fmt_out.p_extra+p_sys->p_sps->i_buffer, p_sys->p_pps->p_buffer, p_sys->p_pps->i_buffer);
-        p_sys->b_header = VLC_TRUE;
+        if( p_dec->fmt_out.p_extra )
+        {
+            memcpy( (uint8_t*)p_dec->fmt_out.p_extra, p_sys->p_sps->p_buffer, p_sys->p_sps->i_buffer);
+            memcpy( (uint8_t*)p_dec->fmt_out.p_extra+p_sys->p_sps->i_buffer, p_sys->p_pps->p_buffer, p_sys->p_pps->i_buffer);
+            p_sys->b_header = VLC_TRUE;
+        }
+        else p_dec->fmt_out.i_extra = 0;
 
         /* Set callback */
         p_dec->pf_packetize = PacketizeAVC1;
     }
     else
     {
-        /* This type of stream contains data with 3 of 4 byte startcodes 
+        /* This type of stream contains data with 3 of 4 byte startcodes
          * The fmt_in.p_extra MAY contain SPS/PPS with 4 byte startcodes
          * The fmt_out.p_extra should be the same */
-         
         /* Set callback */
         p_dec->pf_packetize = Packetize;
 
@@ -313,9 +316,20 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
 
     if( !pp_block || !*pp_block )
         return NULL;
+
     if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
     {
-        p_sys->i_state = STATE_NOSYNC;
+        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->slice.i_frame_type = 0;
+            p_sys->b_slice = VLC_FALSE;
+        }
         block_Release( *pp_block );
         return NULL;
     }
@@ -475,20 +489,22 @@ static void nal_get_decoded( uint8_t **pp_ret, int *pi_ret,
 
     *pp_ret = dst;
 
-    while( src < end )
+    if( dst )
     {
-        if( src < end - 3 && src[0] == 0x00 && src[1] == 0x00 &&
-            src[2] == 0x03 )
+        while( src < end )
         {
-            *dst++ = 0x00;
-            *dst++ = 0x00;
+            if( src < end - 3 && src[0] == 0x00 && src[1] == 0x00 &&
+                src[2] == 0x03 )
+            {
+                *dst++ = 0x00;
+                *dst++ = 0x00;
 
-            src += 3;
-            continue;
+                src += 3;
+                continue;
+            }
+            *dst++ = *src++;
         }
-        *dst++ = *src++;
     }
-
     *pi_ret = dst - *pp_ret;
 }
 
@@ -510,10 +526,9 @@ static inline int bs_read_se( bs_t *s )
     return val&0x01 ? (val+1)/2 : -(val/2);
 }
 
-
 /*****************************************************************************
  * ParseNALBlock: parses annexB type NALs
- * All p_frag blocks are required to start with 0 0 0 1 4-byte startcode 
+ * All p_frag blocks are required to start with 0 0 0 1 4-byte startcode
  *****************************************************************************/
 static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
 {
@@ -528,7 +543,7 @@ static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
         if( !p_sys->b_header && p_sys->slice.i_frame_type != BLOCK_FLAG_TYPE_I) \
             break;                                            \
                                                               \
-        if( p_sys->slice.i_frame_type == BLOCK_FLAG_TYPE_I && p_sys->p_sps && p_sys->p_pps && !p_sys->b_header ) \
+        if( p_sys->slice.i_frame_type == BLOCK_FLAG_TYPE_I && p_sys->p_sps && p_sys->p_pps ) \
         { \
             block_t *p_sps = block_Duplicate( p_sys->p_sps ); \
             block_t *p_pps = block_Duplicate( p_sys->p_pps ); \
@@ -568,8 +583,8 @@ static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
     }
     else if( i_nal_type >= NAL_SLICE && i_nal_type <= NAL_SLICE_IDR )
     {
-        uint8_t *dec;
-        int i_dec, i_first_mb, i_slice_type;
+        uint8_t *dec = NULL;
+        int i_dec = 0, i_first_mb, i_slice_type;
         slice_t slice;
         vlc_bool_t b_pic;
         bs_t s;
@@ -636,7 +651,8 @@ static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
             if( p_sys->i_pic_order_present_flag && !slice.i_field_pic_flag )
                 slice.i_delta_pic_order_cnt_bottom = bs_read_se( &s );
         }
-        else if( p_sys->i_pic_order_cnt_type == 1 && !p_sys->i_delta_pic_order_always_zero_flag )
+        else if( (p_sys->i_pic_order_cnt_type == 1) &&
+                 (!p_sys->i_delta_pic_order_always_zero_flag) )
         {
             slice.i_delta_pic_order_cnt0 = bs_read_se( &s );
             if( p_sys->i_pic_order_present_flag && !slice.i_field_pic_flag )
@@ -651,7 +667,9 @@ static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
             slice.i_field_pic_flag != p_sys->slice.i_field_pic_flag ||
             slice.i_nal_ref_idc != p_sys->slice.i_nal_ref_idc )
             b_pic = VLC_TRUE;
-        if( slice.i_bottom_field_flag != -1 && p_sys->slice.i_bottom_field_flag != -1 && slice.i_bottom_field_flag != p_sys->slice.i_bottom_field_flag )
+        if( (slice.i_bottom_field_flag != -1) &&
+            (p_sys->slice.i_bottom_field_flag != -1) &&
+            (slice.i_bottom_field_flag != p_sys->slice.i_bottom_field_flag) )
             b_pic = VLC_TRUE;
         if( p_sys->i_pic_order_cnt_type == 0 &&
             ( slice.i_pic_order_cnt_lsb != p_sys->slice.i_pic_order_cnt_lsb ||
@@ -677,8 +695,8 @@ static block_t *ParseNALBlock( decoder_t *p_dec, block_t *p_frag )
     }
     else if( i_nal_type == NAL_SPS )
     {
-        uint8_t *dec;
-        int     i_dec;
+        uint8_t *dec = NULL;
+        int     i_dec = 0;
         bs_t s;
         int i_tmp;