[vlc-commits] packetizer: h264: remove last ep3b to rbsp copy conversion

Francois Cartegnie git at videolan.org
Sun Dec 20 16:45:53 CET 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Dec 19 23:31:32 2015 +0100| [9b24493afcc29d2c1406dfc2b4a9afae8f5d9713] | committer: Francois Cartegnie

packetizer: h264: remove last ep3b to rbsp copy conversion

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9b24493afcc29d2c1406dfc2b4a9afae8f5d9713
---

 modules/packetizer/h264.c     |  173 ++++++++++++++++++++++-------------------
 modules/packetizer/hxxx_nal.h |    2 +
 2 files changed, 93 insertions(+), 82 deletions(-)

diff --git a/modules/packetizer/h264.c b/modules/packetizer/h264.c
index 5a28fed..e603eea 100644
--- a/modules/packetizer/h264.c
+++ b/modules/packetizer/h264.c
@@ -908,116 +908,125 @@ static bool ParseSlice( decoder_t *p_dec, bool *pb_new_picture, slice_t *p_slice
 static void ParseSei( decoder_t *p_dec, block_t *p_frag )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
-    uint8_t *pb_dec;
-    size_t i_dec = 0;
+    bs_t s;
+    unsigned i_bitflow = 0;
 
-    if( p_frag->i_buffer < 6 )
-        return;
+    const uint8_t *p_stripped = p_frag->p_buffer;
+    size_t i_stripped = p_frag->i_buffer;
 
-    /* */
-    pb_dec = hxxx_ep3b_to_rbsp( &p_frag->p_buffer[5], p_frag->i_buffer - 5, &i_dec );
-    if( !pb_dec )
+    if( !hxxx_strip_AnnexB_startcode( &p_stripped, &i_stripped ) || i_stripped < 2 )
         return;
 
-    /* The +1 is for rbsp trailing bits */
-    for( size_t i_used = 0; i_used+1 < i_dec; )
+    bs_init( &s, p_stripped, i_stripped );
+    s.p_fwpriv = &i_bitflow;
+    s.pf_forward = hxxx_bsfw_ep3b_to_rbsp;  /* Does the emulated 3bytes conversion to rbsp */
+    bs_skip( &s, 8 ); /* nal unit header */
+
+    while( bs_remain( &s ) >= 8 && bs_aligned( &s ) )
     {
         /* Read type */
-        int i_type = 0;
-        while( i_used+1 < i_dec )
+        unsigned i_type = 0;
+        while( bs_remain( &s ) >= 8 )
         {
-            const int i_byte = pb_dec[i_used++];
+            const uint8_t i_byte = bs_read( &s, 8 );
             i_type += i_byte;
             if( i_byte != 0xff )
                 break;
         }
+
         /* Read size */
-        int i_size = 0;
-        while( i_used+1 < i_dec )
+        unsigned i_size = 0;
+        while( bs_remain( &s ) >= 8 )
         {
-            const int i_byte = pb_dec[i_used++];
+            const uint8_t i_byte = bs_read( &s, 8 );
             i_size += i_byte;
             if( i_byte != 0xff )
                 break;
         }
+
         /* Check room */
-        if( i_used + i_size + 1 > i_dec )
+        if( bs_remain( &s ) < 8 )
             break;
 
-        /* Look for pic timing */
-        if( i_type == H264_SEI_PIC_TIMING )
-        {
-            bs_t s;
-            const int      i_tim = i_size;
-            const uint8_t *p_tim = &pb_dec[i_used];
-
-            bs_init( &s, p_tim, i_tim );
+        /* Save start offset */
+        const unsigned i_start_bit_pos = bs_pos( &s );
 
-            if( p_sys->b_cpb_dpb_delays_present_flag )
-            {
-                bs_read( &s, p_sys->i_cpb_removal_delay_length_minus1 + 1 );
-                bs_read( &s, p_sys->i_dpb_output_delay_length_minus1 + 1 );
-            }
-
-            if( p_sys->b_pic_struct_present_flag )
-                p_sys->i_pic_struct = bs_read( &s, 4 );
-            /* + unparsed remains */
-        }
-
-        /* Look for user_data_registered_itu_t_t35 */
-        if( i_type == H264_SEI_USER_DATA_REGISTERED_ITU_T_T35 )
+        switch( i_type )
         {
-            /* TS 101 154 Auxiliary Data and H264/AVC video */
-            static const uint8_t p_DVB1_data_start_code[] = {
-                0xb5, /* United States */
-                0x00, 0x31, /* US provider code */
-                0x47, 0x41, 0x39, 0x34 /* user identifier */
-            };
-
-            static const uint8_t p_DIRECTV_data_start_code[] = {
-                0xb5, /* United States */
-                0x00, 0x2f, /* US provider code */
-                0x03  /* Captions */
-            };
-
-            const unsigned i_t35 = i_size;
-            const uint8_t *p_t35 = &pb_dec[i_used];
-
-            /* Check for we have DVB1_data() */
-            if( i_t35 >= sizeof(p_DVB1_data_start_code) &&
-                !memcmp( p_t35, p_DVB1_data_start_code, sizeof(p_DVB1_data_start_code) ) )
+            /* Look for pic timing */
+            case H264_SEI_PIC_TIMING:
             {
-                cc_Extract( &p_sys->cc_next, true, &p_t35[3], i_t35 - 3 );
-            } else if( i_t35 >= sizeof(p_DIRECTV_data_start_code) &&
-                !memcmp( p_t35, p_DIRECTV_data_start_code, sizeof(p_DIRECTV_data_start_code) ) )
+                if( p_sys->b_cpb_dpb_delays_present_flag )
+                {
+                    bs_read( &s, p_sys->i_cpb_removal_delay_length_minus1 + 1 );
+                    bs_read( &s, p_sys->i_dpb_output_delay_length_minus1 + 1 );
+                }
+
+                if( p_sys->b_pic_struct_present_flag )
+                    p_sys->i_pic_struct = bs_read( &s, 4 );
+                /* + unparsed remains */
+            } break;
+
+            /* Look for user_data_registered_itu_t_t35 */
+            case H264_SEI_USER_DATA_REGISTERED_ITU_T_T35:
             {
-                cc_Extract( &p_sys->cc_next, true, &p_t35[3], i_t35 - 3 );
-            }
-        }
-
-        /* Look for SEI recovery point */
-        if( i_type == H264_SEI_RECOVERY_POINT )
-        {
-            bs_t s;
-            const int      i_rec = i_size;
-            const uint8_t *p_rec = &pb_dec[i_used];
-
-            bs_init( &s, p_rec, i_rec );
-            int i_recovery_frames = bs_read_ue( &s );
-            //bool b_exact_match = bs_read( &s, 1 );
-            //bool b_broken_link = bs_read( &s, 1 );
-            //int i_changing_slice_group = bs_read( &s, 2 );
-            if( !p_sys->b_header )
+                /* TS 101 154 Auxiliary Data and H264/AVC video */
+                static const uint8_t p_DVB1_data_start_code[] = {
+                    0xb5, /* United States */
+                    0x00, 0x31, /* US provider code */
+                    0x47, 0x41, 0x39, 0x34 /* user identifier */
+                };
+
+                static const uint8_t p_DIRECTV_data_start_code[] = {
+                    0xb5, /* United States */
+                    0x00, 0x2f, /* US provider code */
+                    0x03  /* Captions */
+                };
+
+                const unsigned i_t35 = i_size;
+                uint8_t *p_t35 = malloc( i_t35 );
+                if( !p_t35 )
+                    break;
+                for( unsigned i=0; i<i_t35; i++ )
+                    p_t35[i] = bs_read( &s, 8 );
+
+                /* Check for we have DVB1_data() */
+                if( i_t35 >= sizeof(p_DVB1_data_start_code) &&
+                        !memcmp( p_t35, p_DVB1_data_start_code, sizeof(p_DVB1_data_start_code) ) )
+                {
+                    cc_Extract( &p_sys->cc_next, true, &p_t35[3], i_t35 - 3 );
+                } else if( i_t35 >= sizeof(p_DIRECTV_data_start_code) &&
+                           !memcmp( p_t35, p_DIRECTV_data_start_code, sizeof(p_DIRECTV_data_start_code) ) )
+                {
+                    cc_Extract( &p_sys->cc_next, true, &p_t35[3], i_t35 - 3 );
+                }
+
+                free( p_t35 );
+            } break;
+
+            /* Look for SEI recovery point */
+            case H264_SEI_RECOVERY_POINT:
             {
-                msg_Dbg( p_dec, "Seen SEI recovery point, %d recovery frames", i_recovery_frames );
-                if ( p_sys->i_recovery_frames == -1 || i_recovery_frames < p_sys->i_recovery_frames )
-                    p_sys->i_recovery_frames = i_recovery_frames;
-            }
+                int i_recovery_frames = bs_read_ue( &s );
+                //bool b_exact_match = bs_read( &s, 1 );
+                //bool b_broken_link = bs_read( &s, 1 );
+                //int i_changing_slice_group = bs_read( &s, 2 );
+                if( !p_sys->b_header )
+                {
+                    msg_Dbg( p_dec, "Seen SEI recovery point, %d recovery frames", i_recovery_frames );
+                    if ( p_sys->i_recovery_frames == -1 || i_recovery_frames < p_sys->i_recovery_frames )
+                        p_sys->i_recovery_frames = i_recovery_frames;
+                }
+            } break;
+
+            default:
+                /* Will skip */
+                break;
         }
 
-        i_used += i_size;
+        /* Skip unsparsed content */
+        bs_skip( &s, i_size * 8 - i_start_bit_pos );
     }
 
-    free( pb_dec );
 }
 
diff --git a/modules/packetizer/hxxx_nal.h b/modules/packetizer/hxxx_nal.h
index c0bfd5e..768c223 100644
--- a/modules/packetizer/hxxx_nal.h
+++ b/modules/packetizer/hxxx_nal.h
@@ -79,6 +79,7 @@ static inline uint8_t *hxxx_bsfw_ep3b_to_rbsp( uint8_t *p, uint8_t *end, void *p
     return p;
 }
 
+#if 0
 /* Discards emulation prevention three bytes */
 static inline uint8_t * hxxx_ep3b_to_rbsp(const uint8_t *p_src, size_t i_src, size_t *pi_ret)
 {
@@ -100,5 +101,6 @@ static inline uint8_t * hxxx_ep3b_to_rbsp(const uint8_t *p_src, size_t i_src, si
     *pi_ret = j;
     return p_dst;
 }
+#endif
 
 #endif // HXXX_NAL_H



More information about the vlc-commits mailing list