Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
b1651b88 by François Cartegnie at 2026-02-14T11:04:26+01:00
packetizer: hevc: check extradata conversion
- - - - -
36e30562 by François Cartegnie at 2026-02-14T11:04:26+01:00
packetizer: hevc: allow empty SPS/PPS in DCR
- - - - -
b53be538 by François Cartegnie at 2026-02-14T11:04:26+01:00
packetizer: h264: allow empty SPS/PPS in DCR
- - - - -
0c9dc7ff by François Cartegnie at 2026-02-14T11:04:26+01:00
packetizer: hevc: fix incomplete copy of xPS sets
- - - - -
896ba389 by François Cartegnie at 2026-02-14T11:04:26+01:00
packetizer: h264: use MAX_NUM defines
- - - - -
0e3eb4cb by François Cartegnie at 2026-02-14T11:04:26+01:00
packetizer: hevc: use MAX_NUM defines
- - - - -
61c5a923 by François Cartegnie at 2026-02-14T11:04:26+01:00
codec: hxxx_helper: use MAX_NUM instead of ID_MAX
- - - - -
9 changed files:
- modules/codec/hxxx_helper.c
- modules/codec/hxxx_helper.h
- modules/codec/omxil/omxil.c
- modules/packetizer/h264.c
- modules/packetizer/h264_nal.c
- modules/packetizer/h264_nal.h
- modules/packetizer/hevc.c
- modules/packetizer/hevc_nal.c
- modules/packetizer/hevc_nal.h
Changes:
=====================================
modules/codec/hxxx_helper.c
=====================================
@@ -176,8 +176,8 @@ helper_load_sei(struct hxxx_helper *hh, const uint8_t
*p_nal, size_t i_nal)
hh->hevc.i_sei_count++;
}
-#define LOAD_xPS(list, count, id, max, xpstype, xpsdecode, xpsrelease) \
- if (helper_search_nal(list, count, max+1, p_nal, i_nal) != NULL)\
+#define LOAD_xPS(list, count, id, maxnum, xpstype, xpsdecode, xpsrelease) \
+ if (helper_search_nal(list, count, maxnum, p_nal, i_nal) != NULL)\
return VLC_SUCCESS;\
xpstype *p_xps = xpsdecode(p_nal, i_nal, true);\
if (!p_xps)\
@@ -210,7 +210,7 @@ h264_helper_parse_nal(struct hxxx_helper *hh, const uint8_t
*p_nal, size_t i_nal
{
h264_get_xps_id(p_nal, i_nal, &i_id);
LOAD_xPS(hh->h264.sps_list, hh->h264.i_sps_count,
- i_id, H264_SPS_ID_MAX,
+ i_id, H264_MAX_NUM_SPS,
h264_sequence_parameter_set_t,
h264_decode_sps,
h264_release_sps);
@@ -221,7 +221,7 @@ h264_helper_parse_nal(struct hxxx_helper *hh, const uint8_t
*p_nal, size_t i_nal
{
h264_get_xps_id(p_nal, i_nal, &i_id);
LOAD_xPS(hh->h264.pps_list, hh->h264.i_pps_count,
- i_id, H264_PPS_ID_MAX,
+ i_id, H264_MAX_NUM_PPS,
h264_picture_parameter_set_t,
h264_decode_pps,
h264_release_pps);
@@ -231,7 +231,7 @@ h264_helper_parse_nal(struct hxxx_helper *hh, const uint8_t
*p_nal, size_t i_nal
{
h264_get_xps_id(p_nal, i_nal, &i_id);
LOAD_xPS(hh->h264.spsext_list, hh->h264.i_spsext_count,
- i_id, H264_SPSEXT_ID_MAX,
+ i_id, H264_MAX_NUM_SPSEXT,
h264_sequence_parameter_set_extension_t,
h264_decode_sps_extension,
h264_release_sps_extension);
@@ -308,7 +308,7 @@ hevc_helper_parse_nal(struct hxxx_helper *hh, const uint8_t
*p_nal, size_t i_nal
if( !hevc_get_xps_id(p_nal, i_nal, &i_id) )
return VLC_EGENERIC;
LOAD_xPS(hh->hevc.vps_list, hh->hevc.i_vps_count,
- i_id, HEVC_VPS_ID_MAX,
+ i_id, HEVC_MAX_NUM_VPS,
hevc_video_parameter_set_t,
hevc_decode_vps,
hevc_rbsp_release_vps);
@@ -320,7 +320,7 @@ hevc_helper_parse_nal(struct hxxx_helper *hh, const uint8_t
*p_nal, size_t i_nal
if( !hevc_get_xps_id(p_nal, i_nal, &i_id) )
return VLC_EGENERIC;
LOAD_xPS(hh->hevc.sps_list, hh->hevc.i_sps_count,
- i_id, HEVC_SPS_ID_MAX,
+ i_id, HEVC_MAX_NUM_SPS,
hevc_sequence_parameter_set_t,
hevc_decode_sps,
hevc_rbsp_release_sps);
@@ -332,7 +332,7 @@ hevc_helper_parse_nal(struct hxxx_helper *hh, const uint8_t
*p_nal, size_t i_nal
if( !hevc_get_xps_id(p_nal, i_nal, &i_id) )
return VLC_EGENERIC;
LOAD_xPS(hh->hevc.pps_list, hh->hevc.i_pps_count,
- i_id, HEVC_PPS_ID_MAX,
+ i_id, HEVC_MAX_NUM_PPS,
hevc_picture_parameter_set_t,
hevc_decode_pps,
hevc_rbsp_release_pps);
=====================================
modules/codec/hxxx_helper.h
=====================================
@@ -54,18 +54,18 @@ struct hxxx_helper
uint8_t i_config_version;
union {
struct {
- struct hxxx_helper_nal sps_list[H264_SPS_ID_MAX + 1];
- struct hxxx_helper_nal pps_list[H264_PPS_ID_MAX + 1];
- struct hxxx_helper_nal spsext_list[H264_SPS_ID_MAX + 1];
+ struct hxxx_helper_nal sps_list[H264_MAX_NUM_SPS];
+ struct hxxx_helper_nal pps_list[H264_MAX_NUM_PPS];
+ struct hxxx_helper_nal spsext_list[H264_MAX_NUM_SPS];
uint8_t i_current_sps;
uint8_t i_sps_count;
uint8_t i_pps_count;
uint8_t i_spsext_count;
} h264;
struct {
- struct hxxx_helper_nal sps_list[HEVC_SPS_ID_MAX + 1];
- struct hxxx_helper_nal pps_list[HEVC_PPS_ID_MAX + 1];
- struct hxxx_helper_nal vps_list[HEVC_VPS_ID_MAX + 1];
+ struct hxxx_helper_nal sps_list[HEVC_MAX_NUM_SPS];
+ struct hxxx_helper_nal pps_list[HEVC_MAX_NUM_PPS];
+ struct hxxx_helper_nal vps_list[HEVC_MAX_NUM_VPS];
struct hxxx_helper_nal sei_list[HXXX_HELPER_SEI_COUNT];
uint8_t i_current_sps;
uint8_t i_current_vps;
=====================================
modules/codec/omxil/omxil.c
=====================================
@@ -1040,11 +1040,8 @@ static int OpenGeneric( vlc_object_t *p_this, bool
b_encode )
h264_isavcC(p_dec->fmt_in->p_extra, p_dec->fmt_in->i_extra) )
{
size_t i_filled_len = 0;
- uint8_t *p_buf = h264_avcC_to_AnnexB_NAL(
- p_dec->fmt_in->p_extra, p_dec->fmt_in->i_extra,
- &i_filled_len, NULL );
-
- if( p_buf == NULL )
+ if( !h264_avcC_to_AnnexB_NAL( p_dec->fmt_in->p_extra,
p_dec->fmt_in->i_extra,
+ &p_buf, &i_filled_len, NULL )
{
msg_Dbg(p_dec, "h264_avcC_to_AnnexB_NAL() failed");
goto error;
@@ -1064,12 +1061,10 @@ static int OpenGeneric( vlc_object_t *p_this, bool
b_encode )
}
else if( p_dec->fmt_in->i_codec == VLC_CODEC_HEVC &&
!p_sys->in.b_direct )
{
- size_t i_filled_len = 0;
- uint8_t *p_buf = hevc_hvcC_to_AnnexB_NAL(
- p_dec->fmt_in->p_extra, p_dec->fmt_in->i_extra,
- &i_filled_len, &p_sys->i_nal_size_length );
-
- if( p_buf == NULL )
+ size_t i_filled_len;
+ if( !hevc_hvcC_to_AnnexB_NAL( p_dec->fmt_in->p_extra,
p_dec->fmt_in->i_extra,
+ &p_buf, &i_filled_len,
+ &p_sys->i_nal_size_length )
{
msg_Dbg(p_dec, "hevc_hvcC_to_AnnexB_NAL() failed");
goto error;
=====================================
modules/packetizer/h264.c
=====================================
@@ -87,16 +87,16 @@ typedef struct
{
block_t *p_block;
h264_sequence_parameter_set_t *p_sps;
- } sps[H264_SPS_ID_MAX + 1];
+ } sps[H264_MAX_NUM_SPS];
struct
{
block_t *p_block;
h264_picture_parameter_set_t *p_pps;
- } pps[H264_PPS_ID_MAX + 1];
+ } pps[H264_MAX_NUM_PPS];
struct
{
block_t *p_block;
- } spsext[H264_SPSEXT_ID_MAX + 1];
+ } spsext[H264_MAX_NUM_SPSEXT];
const h264_sequence_parameter_set_t *p_active_sps;
const h264_picture_parameter_set_t *p_active_pps;
@@ -318,19 +318,19 @@ static int Open( vlc_object_t *p_this )
p_sys->b_new_sps = false;
p_sys->b_new_pps = false;
- for( i = 0; i <= H264_SPS_ID_MAX; i++ )
+ for( i = 0; i < H264_MAX_NUM_SPS; i++ )
{
p_sys->sps[i].p_sps = NULL;
p_sys->sps[i].p_block = NULL;
}
p_sys->p_active_sps = NULL;
- for( i = 0; i <= H264_PPS_ID_MAX; i++ )
+ for( i = 0; i < H264_MAX_NUM_PPS; i++ )
{
p_sys->pps[i].p_pps = NULL;
p_sys->pps[i].p_block = NULL;
}
p_sys->p_active_pps = NULL;
- for( i = 0; i <= H264_SPSEXT_ID_MAX; i++ )
+ for( i = 0; i < H264_MAX_NUM_SPSEXT; i++ )
p_sys->spsext[i].p_block = NULL;
p_sys->i_recovery_frame_cnt = UINT_MAX;
@@ -368,21 +368,20 @@ static int Open( vlc_object_t *p_this )
* The fmt_out.p_extra should contain all the SPS and PPS with 4 byte
startcodes */
if( h264_isavcC( p_dec->fmt_in->p_extra, p_dec->fmt_in->i_extra ) )
{
- free( p_dec->fmt_out.p_extra );
- size_t i_size;
- p_dec->fmt_out.p_extra = h264_avcC_to_AnnexB_NAL(
p_dec->fmt_in->p_extra,
-
p_dec->fmt_in->i_extra,
- &i_size,
-
&p_sys->i_avcC_length_size );
- p_dec->fmt_out.i_extra = i_size;
- p_sys->b_recovered = !!p_dec->fmt_out.i_extra;
-
- if(!p_dec->fmt_out.p_extra)
+ size_t i_newextra_size; uint8_t *p_newextra;
+ if( !h264_avcC_to_AnnexB_NAL( p_dec->fmt_in->p_extra,
+ p_dec->fmt_in->i_extra,
+ &p_newextra, &i_newextra_size,
+ &p_sys->i_avcC_length_size ) )
{
msg_Err( p_dec, "Invalid AVC extradata");
Close( p_this );
return VLC_EGENERIC;
}
+ free( p_dec->fmt_out.p_extra );
+ p_dec->fmt_out.p_extra = p_newextra;
+ p_dec->fmt_out.i_extra = i_newextra_size;
+ p_sys->b_recovered = !!p_dec->fmt_out.i_extra;
}
else
{
@@ -1033,21 +1032,21 @@ wrap_h264_xps_release(h264_release_pps,
h264_picture_parameter_set_t)
static void ReleaseXPS( decoder_sys_t *p_sys )
{
- for( int i = 0; i <= H264_SPS_ID_MAX; i++ )
+ for( int i = 0; i < H264_MAX_NUM_SPS; i++ )
{
if( !p_sys->sps[i].p_block )
continue;
block_Release( p_sys->sps[i].p_block );
h264_release_sps( p_sys->sps[i].p_sps );
}
- for( int i = 0; i <= H264_PPS_ID_MAX; i++ )
+ for( int i = 0; i < H264_MAX_NUM_PPS; i++ )
{
if( !p_sys->pps[i].p_block )
continue;
block_Release( p_sys->pps[i].p_block );
h264_release_pps( p_sys->pps[i].p_pps );
}
- for( int i = 0; i <= H264_SPSEXT_ID_MAX; i++ )
+ for( int i = 0; i < H264_MAX_NUM_SPSEXT; i++ )
{
if( p_sys->spsext[i].p_block )
block_Release( p_sys->spsext[i].p_block );
=====================================
modules/packetizer/h264_nal.c
=====================================
@@ -107,12 +107,12 @@ bool h264_isavcC( const uint8_t *p_buf, size_t i_buf )
);
}
-static size_t get_avcC_to_AnnexB_NAL_size( const uint8_t *p_buf, size_t i_buf )
+static bool get_avcC_to_AnnexB_NAL_size( const uint8_t *p_buf, size_t i_buf,
size_t *pi_res )
{
size_t i_total = 0;
if( i_buf < H264_MIN_AVCC_SIZE )
- return 0;
+ return false;
p_buf += 5;
i_buf -= 5;
@@ -126,63 +126,70 @@ static size_t get_avcC_to_AnnexB_NAL_size( const uint8_t
*p_buf, size_t i_buf )
for ( unsigned int i = 0; i < i_loop_end; i++ )
{
if( i_buf < 2 )
- return 0;
+ return false;
uint16_t i_nal_size = (p_buf[0] << 8) | p_buf[1];
if(i_nal_size > i_buf - 2)
- return 0;
+ return false;
i_total += i_nal_size + 4;
p_buf += i_nal_size + 2;
i_buf -= i_nal_size + 2;
}
if( j == 0 && i_buf < 1 )
- return 0;
+ return false;
}
- return i_total;
+ *pi_res = i_total;
+ return true;
}
-uint8_t *h264_avcC_to_AnnexB_NAL( const uint8_t *p_buf, size_t i_buf,
- size_t *pi_result, uint8_t
*pi_nal_length_size )
+bool h264_avcC_to_AnnexB_NAL( const uint8_t *p_buf, size_t i_buf,
+ uint8_t **pp_result, size_t *pi_result,
+ uint8_t *pi_nal_length_size )
{
- *pi_result = get_avcC_to_AnnexB_NAL_size( p_buf, i_buf ); /* Does check
min size */
- if( *pi_result == 0 )
- return NULL;
+ size_t i_result;
+ if( !get_avcC_to_AnnexB_NAL_size( p_buf, i_buf, &i_result ) ) /* Does
check min size */
+ return false;
/* Read infos in first 6 bytes */
- if ( pi_nal_length_size )
- *pi_nal_length_size = (p_buf[4] & 0x03) + 1;
+ const uint8_t i_nal_length_size = (p_buf[4] & 0x03) + 1;
- uint8_t *p_ret;
- uint8_t *p_out_buf = p_ret = malloc( *pi_result );
- if( !p_out_buf )
+ uint8_t *p_out_buf = NULL;
+ if( i_result > 0 )
{
- *pi_result = 0;
- return NULL;
- }
-
- p_buf += 5;
+ p_out_buf = malloc( i_result );
+ if( !p_out_buf )
+ return false;
- for ( unsigned int j = 0; j < 2; j++ )
- {
- const unsigned int i_loop_end = p_buf[0] & (j == 0 ? 0x1f : 0xff);
- p_buf++;
+ p_buf += 5;
- for ( unsigned int i = 0; i < i_loop_end; i++)
+ for ( unsigned int j = 0; j < 2; j++ )
{
- uint16_t i_nal_size = (p_buf[0] << 8) | p_buf[1];
- p_buf += 2;
+ const unsigned int i_loop_end = p_buf[0] & (j == 0 ? 0x1f : 0xff);
+ p_buf++;
+
+ for ( unsigned int i = 0; i < i_loop_end; i++)
+ {
+ uint16_t i_nal_size = (p_buf[0] << 8) | p_buf[1];
+ p_buf += 2;
- memcpy( p_out_buf, annexb_startcode4, 4 );
- p_out_buf += 4;
+ memcpy( p_out_buf, annexb_startcode4, 4 );
+ p_out_buf += 4;
- memcpy( p_out_buf, p_buf, i_nal_size );
- p_out_buf += i_nal_size;
- p_buf += i_nal_size;
+ memcpy( p_out_buf, p_buf, i_nal_size );
+ p_out_buf += i_nal_size;
+ p_buf += i_nal_size;
+ }
}
}
- return p_ret;
+ *pp_result = p_out_buf;
+ *pi_result = i_result;
+
+ if ( pi_nal_length_size )
+ *pi_nal_length_size = i_nal_length_size;
+
+ return true;
}
void h264_AVC_to_AnnexB( uint8_t *p_buf, uint32_t i_len,
=====================================
modules/packetizer/h264_nal.h
=====================================
@@ -50,6 +50,10 @@ extern "C" {
#define H264_SPS_ID_MAX (31)
#define H264_PPS_ID_MAX (255)
#define H264_SPSEXT_ID_MAX H264_SPS_ID_MAX
+#define H264_MAX_NUM_SPS (H264_SPS_ID_MAX + 1)
+#define H264_MAX_NUM_PPS (H264_PPS_ID_MAX + 1)
+#define H264_MAX_NUM_SPSEXT (H264_SPSEXT_ID_MAX + 1)
+
enum h264_nal_unit_type_e
{
@@ -206,8 +210,9 @@ block_t *h264_NAL_to_avcC( uint8_t i_nal_length_size,
const size_t *p_sps_ext_size, uint8_t
i_sps_ext_count);
/* Convert AVCDecoderConfigurationRecord SPS/PPS to Annex B format */
-uint8_t * h264_avcC_to_AnnexB_NAL( const uint8_t *p_buf, size_t i_buf,
- size_t *pi_result, uint8_t
*pi_nal_length_size );
+bool h264_avcC_to_AnnexB_NAL( const uint8_t *p_buf, size_t i_buf,
+ uint8_t **pp_result, size_t *pi_result,
+ uint8_t *pi_nal_length_size );
bool h264_get_dpb_values( const h264_sequence_parameter_set_t *,
uint8_t *pi_max_num_reorder, uint8_t
*pi_max_dec_buffering );
=====================================
modules/packetizer/hevc.c
=====================================
@@ -80,9 +80,9 @@ typedef struct
uint8_t i_nal_length_size;
- struct hevc_tuple_s rg_vps[HEVC_VPS_ID_MAX + 1],
- rg_sps[HEVC_SPS_ID_MAX + 1],
- rg_pps[HEVC_PPS_ID_MAX + 1];
+ struct hevc_tuple_s rg_vps[HEVC_MAX_NUM_VPS],
+ rg_sps[HEVC_MAX_NUM_SPS],
+ rg_pps[HEVC_MAX_NUM_PPS];
const hevc_video_parameter_set_t *p_active_vps;
const hevc_sequence_parameter_set_t *p_active_sps;
@@ -250,18 +250,21 @@ static int Open(vlc_object_t *p_this)
/* Check if we have hvcC as extradata */
if(hevc_ishvcC(p_extra, i_extra))
{
- p_dec->pf_packetize = PacketizeHVC1;
-
+ uint8_t *p_new_extra;
+ size_t i_new_extra;
+ if(!hevc_hvcC_to_AnnexB_NAL(p_extra, i_extra,
+ &p_new_extra, &i_new_extra,
+ &p_sys->i_nal_length_size))
+ {
+ msg_Err( p_dec, "Invalid HVCC extradata");
+ Close( VLC_OBJECT(p_dec) );
+ return VLC_EGENERIC;
+ }
/* Clear hvcC/HVC1 extra, to be replaced with AnnexB */
free(p_dec->fmt_out.p_extra);
- p_dec->fmt_out.i_extra = 0;
-
- size_t i_new_extra = 0;
- p_dec->fmt_out.p_extra =
- hevc_hvcC_to_AnnexB_NAL(p_extra, i_extra,
- &i_new_extra,
&p_sys->i_nal_length_size);
- if(p_dec->fmt_out.p_extra)
- p_dec->fmt_out.i_extra = i_new_extra;
+ p_dec->fmt_out.p_extra = p_new_extra;
+ p_dec->fmt_out.i_extra = i_new_extra;
+ p_dec->pf_packetize = PacketizeHVC1;
}
else
{
@@ -293,7 +296,7 @@ static void Close(vlc_object_t *p_this)
block_ChainRelease(p_sys->pre.p_chain);
block_ChainRelease(p_sys->post.p_chain);
- for(unsigned i=0;i<=HEVC_PPS_ID_MAX; i++)
+ for(unsigned i=0;i<HEVC_MAX_NUM_PPS; i++)
{
if(p_sys->rg_pps[i].p_decoded)
hevc_rbsp_release_pps(p_sys->rg_pps[i].p_decoded);
@@ -301,7 +304,7 @@ static void Close(vlc_object_t *p_this)
block_Release(p_sys->rg_pps[i].p_nal);
}
- for(unsigned i=0;i<=HEVC_SPS_ID_MAX; i++)
+ for(unsigned i=0;i<HEVC_MAX_NUM_SPS; i++)
{
if(p_sys->rg_sps[i].p_decoded)
hevc_rbsp_release_sps(p_sys->rg_sps[i].p_decoded);
@@ -309,7 +312,7 @@ static void Close(vlc_object_t *p_this)
block_Release(p_sys->rg_sps[i].p_nal);
}
- for(unsigned i=0;i<=HEVC_VPS_ID_MAX; i++)
+ for(unsigned i=0;i<HEVC_MAX_NUM_VPS; i++)
{
if(p_sys->rg_vps[i].p_decoded)
hevc_rbsp_release_vps(p_sys->rg_vps[i].p_decoded);
@@ -503,7 +506,7 @@ static block_t *GetXPSCopy(decoder_sys_t *p_sys)
block_t *p_chain = NULL;
block_t **pp_append = &p_chain;
struct hevc_tuple_s *xpstype[3] = {p_sys->rg_vps, p_sys->rg_sps,
p_sys->rg_pps};
- size_t xpsmax[3] = {HEVC_VPS_ID_MAX, HEVC_SPS_ID_MAX, HEVC_PPS_ID_MAX};
+ size_t xpsmax[3] = {HEVC_MAX_NUM_VPS, HEVC_MAX_NUM_SPS, HEVC_MAX_NUM_PPS};
for(size_t i=0; i<3; i++)
{
struct hevc_tuple_s *xps = xpstype[i];
@@ -520,7 +523,7 @@ static block_t *GetXPSCopy(decoder_sys_t *p_sys)
static bool XPSReady(decoder_sys_t *p_sys)
{
- for(unsigned i=0;i<=HEVC_PPS_ID_MAX; i++)
+ for(unsigned i=0;i<HEVC_MAX_NUM_PPS; i++)
{
const hevc_picture_parameter_set_t *p_pps = p_sys->rg_pps[i].p_decoded;
if (p_pps)
@@ -554,8 +557,8 @@ static void AppendAsAnnexB(const block_t *p_block,
}
}
-#define APPENDIF(idmax, set, rg, b) \
- for(size_t i=0; i<=idmax; i++)\
+#define APPENDIF(maxcount, set, rg, b) \
+ for(size_t i=0; i<maxcount; i++)\
{\
if(((set != rg[i].p_decoded) == !b) && rg[i].p_nal)\
{\
@@ -573,12 +576,12 @@ static void SetsToAnnexB(decoder_sys_t *p_sys,
uint8_t *p_data = NULL;
size_t i_data = 0;
- APPENDIF(HEVC_VPS_ID_MAX, p_vps, p_sys->rg_vps, true);
- APPENDIF(HEVC_VPS_ID_MAX, p_vps, p_sys->rg_vps, false);
- APPENDIF(HEVC_SPS_ID_MAX, p_sps, p_sys->rg_sps, true);
- APPENDIF(HEVC_SPS_ID_MAX, p_sps, p_sys->rg_sps, false);
- APPENDIF(HEVC_PPS_ID_MAX, p_pps, p_sys->rg_pps, true);
- APPENDIF(HEVC_PPS_ID_MAX, p_pps, p_sys->rg_pps, false);
+ APPENDIF(HEVC_MAX_NUM_VPS, p_vps, p_sys->rg_vps, true);
+ APPENDIF(HEVC_MAX_NUM_VPS, p_vps, p_sys->rg_vps, false);
+ APPENDIF(HEVC_MAX_NUM_SPS, p_sps, p_sys->rg_sps, true);
+ APPENDIF(HEVC_MAX_NUM_SPS, p_sps, p_sys->rg_sps, false);
+ APPENDIF(HEVC_MAX_NUM_PPS, p_pps, p_sys->rg_pps, true);
+ APPENDIF(HEVC_MAX_NUM_PPS, p_pps, p_sys->rg_pps, false);
/* because we copy to i_extra :/ */
if(i_data <= INT_MAX)
=====================================
modules/packetizer/hevc_nal.c
=====================================
@@ -303,16 +303,16 @@ struct hevc_slice_segment_header_t
};
/* Computes size and does check the whole struct integrity */
-static size_t get_hvcC_to_AnnexB_NAL_size( const uint8_t *p_buf, size_t i_buf )
+static bool get_hvcC_to_AnnexB_NAL_size( const uint8_t *p_buf, size_t i_buf,
size_t *pi_res )
{
size_t i_total = 0;
if( i_buf < HEVC_MIN_HVCC_SIZE )
- return 0;
+ return false;
const uint8_t i_nal_length_size = (p_buf[21] & 0x03) + 1;
if(i_nal_length_size == 3)
- return 0;
+ return false;
const uint8_t i_num_array = p_buf[22];
p_buf += 23; i_buf -= 23;
@@ -320,7 +320,7 @@ static size_t get_hvcC_to_AnnexB_NAL_size( const uint8_t
*p_buf, size_t i_buf )
for( uint8_t i = 0; i < i_num_array; i++ )
{
if(i_buf < 3)
- return 0;
+ return false;
const uint16_t i_num_nalu = p_buf[1] << 8 | p_buf[2];
p_buf += 3; i_buf -= 3;
@@ -328,11 +328,11 @@ static size_t get_hvcC_to_AnnexB_NAL_size( const uint8_t
*p_buf, size_t i_buf )
for( uint16_t j = 0; j < i_num_nalu; j++ )
{
if(i_buf < 2)
- return 0;
+ return false;
const uint16_t i_nalu_length = p_buf[0] << 8 | p_buf[1];
if(i_buf < (size_t)i_nalu_length + 2)
- return 0;
+ return false;
i_total += i_nalu_length + 4; // annexb_startcode4;
p_buf += i_nalu_length + 2;
@@ -340,48 +340,53 @@ static size_t get_hvcC_to_AnnexB_NAL_size( const uint8_t
*p_buf, size_t i_buf )
}
}
- return i_total;
+ *pi_res = i_total;
+ return true;
}
-uint8_t * hevc_hvcC_to_AnnexB_NAL( const uint8_t *p_buf, size_t i_buf,
- size_t *pi_result, uint8_t
*pi_nal_length_size )
+bool hevc_hvcC_to_AnnexB_NAL( const uint8_t *p_buf, size_t i_buf,
+ uint8_t **pp_result, size_t *pi_result,
+ uint8_t *pi_nal_length_size )
{
- *pi_result = get_hvcC_to_AnnexB_NAL_size( p_buf, i_buf ); /* Does all
checks */
- if( *pi_result == 0 )
- return NULL;
-
- if( pi_nal_length_size )
- *pi_nal_length_size = hevc_getNALLengthSize( p_buf );
+ size_t i_result;
+ if(!get_hvcC_to_AnnexB_NAL_size( p_buf, i_buf, &i_result )) /* Does all
checks */
+ return false;
- uint8_t *p_ret;
- uint8_t *p_out_buf = p_ret = malloc( *pi_result );
- if( !p_out_buf )
+ const uint8_t i_nal_length_size = hevc_getNALLengthSize( p_buf );
+ uint8_t *p_out_buf = NULL;
+ if( i_result > 0 )
{
- *pi_result = 0;
- return NULL;
- }
-
- const uint8_t i_num_array = p_buf[22];
- p_buf += 23;
+ p_out_buf = malloc( i_result );
+ if( !p_out_buf )
+ return false;
- for( uint8_t i = 0; i < i_num_array; i++ )
- {
- const uint16_t i_num_nalu = p_buf[1] << 8 | p_buf[2];
- p_buf += 3;
+ const uint8_t i_num_array = p_buf[22];
+ p_buf += 23;
- for( uint16_t j = 0; j < i_num_nalu; j++ )
+ for( uint8_t i = 0; i < i_num_array; i++ )
{
- const uint16_t i_nalu_length = p_buf[0] << 8 | p_buf[1];
+ const uint16_t i_num_nalu = p_buf[1] << 8 | p_buf[2];
+ p_buf += 3;
- memcpy( p_out_buf, annexb_startcode4, 4 );
- memcpy( &p_out_buf[4], &p_buf[2], i_nalu_length );
+ for( uint16_t j = 0; j < i_num_nalu; j++ )
+ {
+ const uint16_t i_nalu_length = p_buf[0] << 8 | p_buf[1];
+
+ memcpy( p_out_buf, annexb_startcode4, 4 );
+ memcpy( &p_out_buf[4], &p_buf[2], i_nalu_length );
- p_out_buf += 4 + i_nalu_length;
- p_buf += 2 + i_nalu_length;
+ p_out_buf += 4 + i_nalu_length;
+ p_buf += 2 + i_nalu_length;
+ }
}
}
- return p_ret;
+ *pp_result = p_out_buf;
+ *pi_result = i_result;
+ if( pi_nal_length_size )
+ *pi_nal_length_size = i_nal_length_size;
+
+ return true;
}
static bool hevc_parse_scaling_list_rbsp( bs_t *p_bs )
=====================================
modules/packetizer/hevc_nal.h
=====================================
@@ -30,6 +30,9 @@ extern "C" {
#define HEVC_VPS_ID_MAX 15
#define HEVC_SPS_ID_MAX 15
#define HEVC_PPS_ID_MAX 63
+#define HEVC_MAX_NUM_VPS (HEVC_VPS_ID_MAX + 1)
+#define HEVC_MAX_NUM_SPS (HEVC_SPS_ID_MAX + 1)
+#define HEVC_MAX_NUM_PPS (HEVC_PPS_ID_MAX + 1)
enum hevc_general_profile_idc_e
{
@@ -349,8 +352,8 @@ uint8_t * hevc_create_dcr( const struct hevc_dcr_params
*p_params,
bool b_completeness, size_t *pi_size );
/* Converts HEVCDecoderConfigurationRecord to Annex B format */
-uint8_t * hevc_hvcC_to_AnnexB_NAL( const uint8_t *p_buf, size_t i_buf,
- size_t *pi_res, uint8_t *pi_nal_length_size
);
+bool hevc_hvcC_to_AnnexB_NAL( const uint8_t *p_buf, size_t i_buf,
+ uint8_t **pp_res, size_t *pi_res, uint8_t
*pi_nal_length_size );
/*
* POC computing
View it on GitLab:
https://code.videolan.org/videolan/vlc/-/compare/1fd0564673699416f21f3a7f9d443fa55dbefea5...61c5a923b012518ac862bb27ef347258e5754e2b
--
View it on GitLab:
https://code.videolan.org/videolan/vlc/-/compare/1fd0564673699416f21f3a7f9d443fa55dbefea5...61c5a923b012518ac862bb27ef347258e5754e2b
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits