Commit a0e20c60 authored by François Cartegnie's avatar François Cartegnie 🤞

packetizer: hevc: convert all parsers to handle ep3b input

parent ada921a4
......@@ -256,15 +256,14 @@ static int32_t getFPS(demux_t *p_demux, uint8_t i_nal_type, block_t *p_block)
if( p_sys->rgp_vps[i_id] && i_nal_type == HEVC_NAL_VPS )
return -1;
size_t i_rbsp;
uint8_t *p_rbsp = hxxx_AnnexB_NAL_to_rbsp( p_block->p_buffer, p_block->i_buffer, &i_rbsp );
if( p_rbsp )
const uint8_t *p_nald = p_block->p_buffer;
size_t i_nald = p_block->i_buffer;
if( hxxx_strip_AnnexB_startcode( &p_nald, &i_nald ) )
{
if( i_nal_type == HEVC_NAL_VPS )
p_sys->rgp_vps[i_id] = hevc_rbsp_decode_vps( p_rbsp, i_rbsp );
p_sys->rgp_vps[i_id] = hevc_decode_vps( p_nald, i_nald, true );
else
p_sps = hevc_rbsp_decode_sps( p_rbsp, i_rbsp );
free( p_rbsp );
p_sps = hevc_decode_sps( p_nald, i_nald, true );
}
if( p_sps )
......
......@@ -663,22 +663,33 @@ void hevc_rbsp_release_vps( hevc_video_parameter_set_t *p_vps )
free( p_vps );
}
hevc_video_parameter_set_t * hevc_rbsp_decode_vps( const uint8_t *p_buf, size_t i_buf )
{
hevc_video_parameter_set_t *p_vps = calloc(1, sizeof(hevc_video_parameter_set_t));
if(likely(p_vps))
{
bs_t bs;
bs_init( &bs, p_buf, i_buf );
bs_skip( &bs, 16 ); /* Skip nal_unit_header */
if( !hevc_parse_video_parameter_set_rbsp( &bs, p_vps ) )
{
hevc_rbsp_release_vps( p_vps );
p_vps = NULL;
}
#define IMPL_hevc_generic_decode( name, hevctype, decode, release ) \
hevctype * name( const uint8_t *p_buf, size_t i_buf, bool b_escaped ) \
{ \
hevctype *p_hevctype = calloc(1, sizeof(hevctype)); \
if(likely(p_hevctype)) \
{ \
bs_t bs; \
bs_init( &bs, p_buf, i_buf ); \
unsigned i_bitflow = 0; \
if( b_escaped ) \
{ \
bs.p_fwpriv = &i_bitflow; \
bs.pf_forward = hxxx_bsfw_ep3b_to_rbsp; /* Does the emulated 3bytes conversion to rbsp */ \
} \
else (void) i_bitflow;\
bs_skip( &bs, 16 ); /* Skip nal_unit_header */ \
if( !decode( &bs, p_hevctype ) ) \
{ \
release( p_hevctype ); \
p_hevctype = NULL; \
} \
} \
return p_hevctype; \
}
return p_vps;
}
IMPL_hevc_generic_decode( hevc_decode_vps, hevc_video_parameter_set_t,
hevc_parse_video_parameter_set_rbsp, hevc_rbsp_release_vps )
static bool hevc_parse_st_ref_pic_set( bs_t *p_bs, unsigned idx,
unsigned num_short_term_ref_pic_sets,
......@@ -862,22 +873,8 @@ void hevc_rbsp_release_sps( hevc_sequence_parameter_set_t *p_sps )
free( p_sps );
}
hevc_sequence_parameter_set_t * hevc_rbsp_decode_sps( const uint8_t *p_buf, size_t i_buf )
{
hevc_sequence_parameter_set_t *p_sps = calloc(1, sizeof(hevc_sequence_parameter_set_t));
if(likely(p_sps))
{
bs_t bs;
bs_init( &bs, p_buf, i_buf );
bs_skip( &bs, 16 ); /* Skip nal_unit_header */
if( !hevc_parse_sequence_parameter_set_rbsp( &bs, p_sps ) )
{
hevc_rbsp_release_sps( p_sps );
p_sps = NULL;
}
}
return p_sps;
}
IMPL_hevc_generic_decode( hevc_decode_sps, hevc_sequence_parameter_set_t,
hevc_parse_sequence_parameter_set_rbsp, hevc_rbsp_release_sps )
static bool hevc_parse_pic_parameter_set_rbsp( bs_t *p_bs,
hevc_picture_parameter_set_t *p_pps )
......@@ -976,22 +973,8 @@ void hevc_rbsp_release_pps( hevc_picture_parameter_set_t *p_pps )
free( p_pps );
}
hevc_picture_parameter_set_t * hevc_rbsp_decode_pps( const uint8_t *p_buf, size_t i_buf )
{
hevc_picture_parameter_set_t *p_pps = calloc(1, sizeof(hevc_picture_parameter_set_t));
if(likely(p_pps))
{
bs_t bs;
bs_init( &bs, p_buf, i_buf );
bs_skip( &bs, 16 ); /* Skip nal_unit_header */
if( !hevc_parse_pic_parameter_set_rbsp( &bs, p_pps ) )
{
hevc_rbsp_release_pps( p_pps );
p_pps = NULL;
}
}
return p_pps;
}
IMPL_hevc_generic_decode( hevc_decode_pps, hevc_picture_parameter_set_t,
hevc_parse_pic_parameter_set_rbsp, hevc_rbsp_release_pps )
bool hevc_get_picture_size( const hevc_sequence_parameter_set_t *p_sps,
unsigned *p_w, unsigned *p_h, unsigned *p_vw, unsigned *p_vh )
......@@ -1048,8 +1031,8 @@ bool hevc_get_frame_rate( const hevc_sequence_parameter_set_t *p_sps,
static bool hevc_parse_slice_segment_header_rbsp( bs_t *p_bs,
uint8_t i_nal_type,
const hevc_sequence_parameter_set_t **pp_sps,
const hevc_picture_parameter_set_t **pp_pps,
hevc_sequence_parameter_set_t **pp_sps,
hevc_picture_parameter_set_t **pp_pps,
hevc_slice_segment_header_t *p_sl )
{
if( bs_remain( p_bs ) < 3 )
......@@ -1119,9 +1102,9 @@ void hevc_rbsp_release_slice_header( hevc_slice_segment_header_t *p_sh )
free( p_sh );
}
hevc_slice_segment_header_t * hevc_rbsp_decode_slice_header( const uint8_t *p_buf, size_t i_buf,
const hevc_sequence_parameter_set_t **pp_sps,
const hevc_picture_parameter_set_t **pp_pps )
hevc_slice_segment_header_t * hevc_decode_slice_header( const uint8_t *p_buf, size_t i_buf, bool b_escaped,
hevc_sequence_parameter_set_t **pp_sps,
hevc_picture_parameter_set_t **pp_pps )
{
if(!pp_sps || !pp_pps)
return NULL;
......@@ -1132,6 +1115,13 @@ hevc_slice_segment_header_t * hevc_rbsp_decode_slice_header( const uint8_t *p_bu
uint8_t i_nal_type = ((p_buf[0] & 0x7E) >> 1);
bs_t bs;
bs_init( &bs, p_buf, i_buf );
unsigned i_bitflow = 0;
if( b_escaped )
{
bs.p_fwpriv = &i_bitflow;
bs.pf_forward = hxxx_bsfw_ep3b_to_rbsp; /* Does the emulated 3bytes conversion to rbsp */
}
else (void) i_bitflow;
bs_skip( &bs, 16 ); /* Skip nal_unit_header */
if( !hevc_parse_slice_segment_header_rbsp( &bs, i_nal_type, pp_sps, pp_pps, p_sh ) )
{
......
......@@ -141,12 +141,13 @@ typedef struct hevc_sequence_parameter_set_t hevc_sequence_parameter_set_t;
typedef struct hevc_picture_parameter_set_t hevc_picture_parameter_set_t;
typedef struct hevc_slice_segment_header_t hevc_slice_segment_header_t;
hevc_video_parameter_set_t * hevc_rbsp_decode_vps( const uint8_t *, size_t ) VLC_USED;
hevc_sequence_parameter_set_t * hevc_rbsp_decode_sps( const uint8_t *, size_t ) VLC_USED;
hevc_picture_parameter_set_t * hevc_rbsp_decode_pps( const uint8_t *, size_t ) VLC_USED;
hevc_slice_segment_header_t * hevc_rbsp_decode_slice_header( const uint8_t *, size_t,
const hevc_sequence_parameter_set_t **pp_sps/* HEVC_MAX_SPS */,
const hevc_picture_parameter_set_t **pp_pps /* HEVC_MAX_PPS */) VLC_USED;
/* Decodes from three bytes emulation prevented or rbsp stream */
hevc_video_parameter_set_t * hevc_decode_vps( const uint8_t *, size_t, bool );
hevc_sequence_parameter_set_t * hevc_decode_sps( const uint8_t *, size_t, bool );
hevc_picture_parameter_set_t * hevc_decode_pps( const uint8_t *, size_t, bool );
hevc_slice_segment_header_t * hevc_decode_slice_header( const uint8_t *, size_t, bool,
hevc_sequence_parameter_set_t **pp_sps/* HEVC_MAX_SPS */,
hevc_picture_parameter_set_t **pp_pps /* HEVC_MAX_PPS */);
void hevc_rbsp_release_vps( hevc_video_parameter_set_t * );
void hevc_rbsp_release_sps( hevc_sequence_parameter_set_t * );
......
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