Commit 9b24493a authored by Francois Cartegnie's avatar Francois Cartegnie

packetizer: h264: remove last ep3b to rbsp copy conversion

parent e047c398
...@@ -908,116 +908,125 @@ static bool ParseSlice( decoder_t *p_dec, bool *pb_new_picture, slice_t *p_slice ...@@ -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 ) static void ParseSei( decoder_t *p_dec, block_t *p_frag )
{ {
decoder_sys_t *p_sys = p_dec->p_sys; decoder_sys_t *p_sys = p_dec->p_sys;
uint8_t *pb_dec; bs_t s;
size_t i_dec = 0; unsigned i_bitflow = 0;
if( p_frag->i_buffer < 6 ) const uint8_t *p_stripped = p_frag->p_buffer;
return; size_t i_stripped = p_frag->i_buffer;
/* */ if( !hxxx_strip_AnnexB_startcode( &p_stripped, &i_stripped ) || i_stripped < 2 )
pb_dec = hxxx_ep3b_to_rbsp( &p_frag->p_buffer[5], p_frag->i_buffer - 5, &i_dec );
if( !pb_dec )
return; return;
/* The +1 is for rbsp trailing bits */ bs_init( &s, p_stripped, i_stripped );
for( size_t i_used = 0; i_used+1 < i_dec; ) 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 */ /* Read type */
int i_type = 0; unsigned i_type = 0;
while( i_used+1 < i_dec ) 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; i_type += i_byte;
if( i_byte != 0xff ) if( i_byte != 0xff )
break; break;
} }
/* Read size */ /* Read size */
int i_size = 0; unsigned i_size = 0;
while( i_used+1 < i_dec ) 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; i_size += i_byte;
if( i_byte != 0xff ) if( i_byte != 0xff )
break; break;
} }
/* Check room */ /* Check room */
if( i_used + i_size + 1 > i_dec ) if( bs_remain( &s ) < 8 )
break; break;
/* Look for pic timing */ /* Save start offset */
if( i_type == H264_SEI_PIC_TIMING ) const unsigned i_start_bit_pos = bs_pos( &s );
{
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 );
if( p_sys->b_cpb_dpb_delays_present_flag ) switch( i_type )
{
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 )
{ {
/* TS 101 154 Auxiliary Data and H264/AVC video */ /* Look for pic timing */
static const uint8_t p_DVB1_data_start_code[] = { case H264_SEI_PIC_TIMING:
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) ) )
{ {
cc_Extract( &p_sys->cc_next, true, &p_t35[3], i_t35 - 3 ); if( p_sys->b_cpb_dpb_delays_present_flag )
} else if( i_t35 >= sizeof(p_DIRECTV_data_start_code) && {
!memcmp( p_t35, p_DIRECTV_data_start_code, sizeof(p_DIRECTV_data_start_code) ) ) 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 ); /* 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 */
/* Look for SEI recovery point */ 0x47, 0x41, 0x39, 0x34 /* user identifier */
if( i_type == H264_SEI_RECOVERY_POINT ) };
{
bs_t s; static const uint8_t p_DIRECTV_data_start_code[] = {
const int i_rec = i_size; 0xb5, /* United States */
const uint8_t *p_rec = &pb_dec[i_used]; 0x00, 0x2f, /* US provider code */
0x03 /* Captions */
bs_init( &s, p_rec, i_rec ); };
int i_recovery_frames = bs_read_ue( &s );
//bool b_exact_match = bs_read( &s, 1 ); const unsigned i_t35 = i_size;
//bool b_broken_link = bs_read( &s, 1 ); uint8_t *p_t35 = malloc( i_t35 );
//int i_changing_slice_group = bs_read( &s, 2 ); if( !p_t35 )
if( !p_sys->b_header ) 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 ); int i_recovery_frames = bs_read_ue( &s );
if ( p_sys->i_recovery_frames == -1 || i_recovery_frames < p_sys->i_recovery_frames ) //bool b_exact_match = bs_read( &s, 1 );
p_sys->i_recovery_frames = i_recovery_frames; //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 );
} }
...@@ -79,6 +79,7 @@ static inline uint8_t *hxxx_bsfw_ep3b_to_rbsp( uint8_t *p, uint8_t *end, void *p ...@@ -79,6 +79,7 @@ static inline uint8_t *hxxx_bsfw_ep3b_to_rbsp( uint8_t *p, uint8_t *end, void *p
return p; return p;
} }
#if 0
/* Discards emulation prevention three bytes */ /* 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) 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 ...@@ -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; *pi_ret = j;
return p_dst; return p_dst;
} }
#endif
#endif // HXXX_NAL_H #endif // HXXX_NAL_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment