[vlc-commits] vlc_bits: remove bs_remain uses
Francois Cartegnie
git at videolan.org
Fri Jul 24 11:23:15 CEST 2020
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Jul 23 16:25:39 2020 +0200| [4319f4bdb9f089efba797eeefe56d708ccb7c05b] | committer: Francois Cartegnie
vlc_bits: remove bs_remain uses
Performance regression due to the need of parsing
each buffer and compute emulation stripped size
when used with ep3bi handlers.
Changes pre-check for truncated reads as failure instead.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4319f4bdb9f089efba797eeefe56d708ccb7c05b
---
modules/demux/mpeg/es.c | 4 +-
modules/packetizer/av1_obu.c | 10 ++---
modules/packetizer/h264_nal.c | 6 +--
modules/packetizer/h264_slice.c | 7 +++-
modules/packetizer/hevc_nal.c | 88 +++++++++++++++--------------------------
modules/packetizer/hxxx_sei.c | 29 ++++++++------
modules/packetizer/mpeg4audio.c | 21 +++++-----
modules/packetizer/vc1.c | 6 ++-
8 files changed, 80 insertions(+), 91 deletions(-)
diff --git a/modules/demux/mpeg/es.c b/modules/demux/mpeg/es.c
index 2371ddbde3..58b2ad1c9a 100644
--- a/modules/demux/mpeg/es.c
+++ b/modules/demux/mpeg/es.c
@@ -1025,10 +1025,12 @@ static uint64_t SeekByMlltTable( demux_t *p_demux, vlc_tick_t *pi_time )
bs_init(&p_cur->br, p_sys->mllt.p_bits, p_sys->mllt.i_bits);
}
- while(bs_remain(&p_cur->br) >= p_sys->mllt.i_bits_per_bytes_dev + p_sys->mllt.i_bits_per_ms_dev)
+ while(!bs_eof(&p_cur->br))
{
const uint32_t i_bytesdev = bs_read(&p_cur->br, p_sys->mllt.i_bits_per_bytes_dev);
const uint32_t i_msdev = bs_read(&p_cur->br, p_sys->mllt.i_bits_per_ms_dev);
+ if(bs_error(&p_cur->br))
+ break;
const vlc_tick_t i_deltatime = VLC_TICK_FROM_MS(p_sys->mllt.i_ms_btw_refs + i_msdev);
if( p_cur->i_time + i_deltatime > *pi_time )
break;
diff --git a/modules/packetizer/av1_obu.c b/modules/packetizer/av1_obu.c
index 1707f3ee88..9778beb212 100644
--- a/modules/packetizer/av1_obu.c
+++ b/modules/packetizer/av1_obu.c
@@ -70,8 +70,6 @@ static bool av1_read_header(bs_t *p_bs, struct av1_header_info_s *p_hdr)
return false;
if(obu_extension_flag)
{
- if(bs_remain(p_bs) < 8)
- return false;
p_hdr->temporal_id = bs_read(p_bs, 3);
p_hdr->spatial_id = bs_read(p_bs, 2);
bs_skip(p_bs, 3);
@@ -80,8 +78,6 @@ static bool av1_read_header(bs_t *p_bs, struct av1_header_info_s *p_hdr)
{
for (uint8_t i = 0; i < 8; i++)
{
- if(bs_remain(p_bs) < 8)
- return false;
uint8_t v = bs_read(p_bs, 8);
if (!(v & 0x80))
break;
@@ -89,7 +85,7 @@ static bool av1_read_header(bs_t *p_bs, struct av1_header_info_s *p_hdr)
return false;
}
}
- return true;
+ return !bs_error(p_bs);
}
/*
@@ -394,11 +390,13 @@ av1_OBU_sequence_header_t *
p_seq->enable_cdef = bs_read1(&bs);
p_seq->enable_restoration = bs_read1(&bs);
av1_parse_color_config(&bs, &p_seq->color_config, p_seq->seq_profile);
- if(bs_remain(&bs) < 1)
+
+ if(bs_error(&bs))
{
AV1_release_sequence_header(p_seq);
return NULL;
}
+
p_seq->film_grain_params_present = bs_read1(&bs);
return p_seq;
diff --git a/modules/packetizer/h264_nal.c b/modules/packetizer/h264_nal.c
index 4499fdeb97..8233a3e6f7 100644
--- a/modules/packetizer/h264_nal.c
+++ b/modules/packetizer/h264_nal.c
@@ -506,11 +506,11 @@ static bool h264_parse_sequence_parameter_set_rbsp( bs_t *p_bs,
bs_read( p_bs, 4 );
for( uint32_t j = 0; j < count; j++ )
{
- if( bs_remain( p_bs ) < 23 )
- return false;
bs_read_ue( p_bs );
bs_read_ue( p_bs );
bs_read( p_bs, 1 );
+ if( bs_error( p_bs ) )
+ return false;
}
bs_read( p_bs, 5 );
p_sps->vui.i_cpb_removal_delay_length_minus1 = bs_read( p_bs, 5 );
@@ -538,7 +538,7 @@ static bool h264_parse_sequence_parameter_set_rbsp( bs_t *p_bs,
}
}
- return true;
+ return !bs_error( p_bs );
}
void h264_release_pps( h264_picture_parameter_set_t *p_pps )
diff --git a/modules/packetizer/h264_slice.c b/modules/packetizer/h264_slice.c
index 91b43a3a7e..5319957006 100644
--- a/modules/packetizer/h264_slice.c
+++ b/modules/packetizer/h264_slice.c
@@ -144,10 +144,13 @@ bool h264_decode_slice( const uint8_t *p_buffer, size_t i_buffer,
if( mod < 3 || ( b_mvc && (mod == 4 || mod == 5) ) )
bs_read_ue( &s ); /* abs_diff_pic_num_minus1, long_term_pic_num, abs_diff_view_idx_min1 */
}
- while( mod != 3 && bs_remain( &s ) );
+ while( mod != 3 && !bs_eof( &s ) );
}
}
+ if( bs_error( &s ) )
+ return false;
+
/* pred_weight_table() */
if( ( p_pps->weighted_pred_flag && ( i_slice_type == 0 || i_slice_type == 5 || /* P, SP */
i_slice_type == 3 || i_slice_type == 8 ) ) ||
@@ -210,7 +213,7 @@ bool h264_decode_slice( const uint8_t *p_buffer, size_t i_buffer,
/* If you need to store anything else than MMCO presence above, care of "Early END" cases */
- return true;
+ return !bs_error( &s );
}
diff --git a/modules/packetizer/hevc_nal.c b/modules/packetizer/hevc_nal.c
index 309c6d0e7c..0f8daf263c 100644
--- a/modules/packetizer/hevc_nal.c
+++ b/modules/packetizer/hevc_nal.c
@@ -412,9 +412,6 @@ uint8_t * hevc_hvcC_to_AnnexB_NAL( const uint8_t *p_buf, size_t i_buf,
static bool hevc_parse_scaling_list_rbsp( bs_t *p_bs )
{
- if( bs_remain( p_bs ) < 16 )
- return false;
-
for( int i=0; i<4; i++ )
{
for( int j=0; j<6; j += (i == 3) ? 3 : 1 )
@@ -443,9 +440,6 @@ static bool hevc_parse_scaling_list_rbsp( bs_t *p_bs )
static bool hevc_parse_vui_parameters_rbsp( bs_t *p_bs, hevc_vui_parameters_t *p_vui,
bool b_broken )
{
- if( bs_remain( p_bs ) < 10 )
- return false;
-
p_vui->aspect_ratio_info_present_flag = bs_read1( p_bs );
if( p_vui->aspect_ratio_info_present_flag )
{
@@ -506,16 +500,10 @@ static bool hevc_parse_vui_parameters_rbsp( bs_t *p_bs, hevc_vui_parameters_t *p
{
p_vui->timing.vui_num_units_in_tick = bs_read( p_bs, 32 );
p_vui->timing.vui_time_scale = bs_read( p_bs, 32 );
-
- if( bs_remain( p_bs ) < 3 )
- return false;
}
/* incomplete */
- if( bs_remain( p_bs ) < 1 ) /* late fail */
- return false;
-
- return true;
+ return !bs_error( p_bs );
}
/* Shortcut for retrieving vps/sps/pps id */
@@ -550,9 +538,6 @@ bool hevc_get_xps_id(const uint8_t *p_buf, size_t i_buf, uint8_t *pi_id)
static bool hevc_parse_inner_profile_tier_level_rbsp( bs_t *p_bs,
hevc_inner_profile_tier_level_t *p_in )
{
- if( bs_remain( p_bs ) < 88 )
- return false;
-
p_in->profile_space = bs_read( p_bs, 2 );
p_in->tier_flag = bs_read1( p_bs );
p_in->profile_idc = bs_read( p_bs, 5 );
@@ -603,7 +588,7 @@ static bool hevc_parse_inner_profile_tier_level_rbsp( bs_t *p_bs,
else
bs_skip( p_bs, 1 );
- return true;
+ return !bs_error( p_bs );
}
static bool hevc_parse_profile_tier_level_rbsp( bs_t *p_bs, bool profile_present,
@@ -613,14 +598,14 @@ static bool hevc_parse_profile_tier_level_rbsp( bs_t *p_bs, bool profile_present
if( profile_present && !hevc_parse_inner_profile_tier_level_rbsp( p_bs, &p_ptl->general ) )
return false;
- if( bs_remain( p_bs ) < 8)
+ if( bs_error( p_bs ) )
return false;
p_ptl->general_level_idc = bs_read( p_bs, 8 );
if( max_num_sub_layers_minus1 > 0 )
{
- if( bs_remain( p_bs ) < 16 )
+ if( bs_eof( p_bs ) )
return false;
for( uint8_t i=0; i< 8; i++ )
@@ -644,20 +629,20 @@ static bool hevc_parse_profile_tier_level_rbsp( bs_t *p_bs, bool profile_present
if( p_ptl->sublayer_profile_present_flag & (0x80 >> i) )
{
- if( bs_remain( p_bs ) < 8 )
+ if( bs_eof( p_bs ) )
return false;
p_ptl->sub_layer_level_idc[i] = bs_read( p_bs, 8 );
}
}
}
- return true;
+ return !bs_error( p_bs );
}
static bool hevc_parse_video_parameter_set_rbsp( bs_t *p_bs,
hevc_video_parameter_set_t *p_vps )
{
- if( bs_remain( p_bs ) < 134 )
+ if( bs_eof( p_bs ) )
return false;
p_vps->vps_video_parameter_set_id = bs_read( p_bs, 4 );
@@ -681,15 +666,14 @@ static bool hevc_parse_video_parameter_set_rbsp( bs_t *p_bs,
p_vps->vps_max[i].num_reorder_pics = bs_read_ue( p_bs );
p_vps->vps_max[i].max_latency_increase_plus1 = bs_read_ue( p_bs );
}
- if( bs_remain( p_bs ) < 10 )
+
+ if( bs_error( p_bs ) )
return false;
p_vps->vps_max_layer_id = bs_read( p_bs, 6 );
p_vps->vps_num_layer_set_minus1 = bs_read_ue( p_bs );
// layer_id_included_flag; read but discarded
bs_skip( p_bs, p_vps->vps_num_layer_set_minus1 * (p_vps->vps_max_layer_id + 1) );
- if( bs_remain( p_bs ) < 2 )
- return false;
p_vps->vps_timing_info_present_flag = bs_read1( p_bs );
if( p_vps->vps_timing_info_present_flag )
@@ -699,10 +683,7 @@ static bool hevc_parse_video_parameter_set_rbsp( bs_t *p_bs,
}
/* parsing incomplete */
- if( bs_remain( p_bs ) < 1 )
- return false;
-
- return true;
+ return !bs_error( p_bs );
}
void hevc_rbsp_release_vps( hevc_video_parameter_set_t *p_vps )
@@ -778,7 +759,7 @@ static bool hevc_parse_st_ref_pic_set( bs_t *p_bs, unsigned stRpsIdx,
{
nal_ue_t num_negative_pics = bs_read_ue( p_bs );
nal_ue_t num_positive_pics = bs_read_ue( p_bs );
- if( bs_remain( p_bs ) < (num_negative_pics + num_positive_pics) * 2 )
+ if( bs_error( p_bs ) )
return false;
for(unsigned int i=0; i<num_negative_pics; i++)
{
@@ -793,7 +774,7 @@ static bool hevc_parse_st_ref_pic_set( bs_t *p_bs, unsigned stRpsIdx,
p_sets[stRpsIdx].num_delta_pocs = num_positive_pics + num_negative_pics;
}
- return true;
+ return !bs_error( p_bs );
}
static bool hevc_parse_sequence_parameter_set_rbsp( bs_t *p_bs,
@@ -806,7 +787,7 @@ static bool hevc_parse_sequence_parameter_set_rbsp( bs_t *p_bs,
&p_sps->profile_tier_level ) )
return false;
- if( bs_remain( p_bs ) < 1 )
+ if( bs_error( p_bs ) )
return false;
p_sps->sps_seq_parameter_set_id = bs_read_ue( p_bs );
@@ -843,14 +824,12 @@ static bool hevc_parse_sequence_parameter_set_rbsp( bs_t *p_bs,
p_sps->sps_max[i].latency_increase_plus1 = bs_read_ue( p_bs );
}
- if( bs_remain( p_bs ) < 4 )
+ if( bs_eof( p_bs ) )
return false;
p_sps->log2_min_luma_coding_block_size_minus3 = bs_read_ue( p_bs );
p_sps->log2_diff_max_min_luma_coding_block_size = bs_read_ue( p_bs );
p_sps->log2_min_luma_transform_block_size_minus2 = bs_read_ue( p_bs );
- if( bs_remain( p_bs ) < 1 ) /* last late fail check */
- return false;
p_sps->log2_diff_max_min_luma_transform_block_size = bs_read_ue( p_bs );
/* parsing incomplete */
@@ -868,6 +847,9 @@ static bool hevc_parse_sequence_parameter_set_rbsp( bs_t *p_bs,
}
}
+ if( bs_error( p_bs ) )
+ return false;
+
p_sps->amp_enabled_flag = bs_read1( p_bs );
p_sps->sample_adaptive_offset_enabled_flag = bs_read1( p_bs );
@@ -911,7 +893,7 @@ static bool hevc_parse_sequence_parameter_set_rbsp( bs_t *p_bs,
p_sps->sps_temporal_mvp_enabled_flag = bs_read1( p_bs );
p_sps->strong_intra_smoothing_enabled_flag = bs_read1( p_bs );
- if( bs_remain( p_bs ) < 1 ) /* late fail */
+ if( bs_error( p_bs ) )
return false;
p_sps->vui_parameters_present_flag = bs_read1( p_bs );
@@ -920,7 +902,7 @@ static bool hevc_parse_sequence_parameter_set_rbsp( bs_t *p_bs,
bs_t rollbackpoint = *p_bs;
if( !hevc_parse_vui_parameters_rbsp( p_bs, &p_sps->vui, false ) &&
p_sps->vui.default_display_window_flag &&
- bs_remain( p_bs ) < 66 )
+ !bs_error( p_bs ) )
{
/* Broken MKV SPS vui bitstreams with missing display_window bits.
* Forced to accept it since some decided to accept it...
@@ -936,7 +918,7 @@ static bool hevc_parse_sequence_parameter_set_rbsp( bs_t *p_bs,
/* incomplete */
- return true;
+ return !bs_error( p_bs );
}
void hevc_rbsp_release_sps( hevc_sequence_parameter_set_t *p_sps )
@@ -950,10 +932,10 @@ IMPL_hevc_generic_decode( hevc_decode_sps, hevc_sequence_parameter_set_t,
static bool hevc_parse_pic_parameter_set_rbsp( bs_t *p_bs,
hevc_picture_parameter_set_t *p_pps )
{
- if( bs_remain( p_bs ) < 1 )
+ if( bs_eof( p_bs ) )
return false;
p_pps->pps_pic_parameter_set_id = bs_read_ue( p_bs );
- if( p_pps->pps_pic_parameter_set_id > HEVC_PPS_ID_MAX || bs_remain( p_bs ) < 1 )
+ if( p_pps->pps_pic_parameter_set_id > HEVC_PPS_ID_MAX )
return false;
p_pps->pps_seq_parameter_set_id = bs_read_ue( p_bs );
if( p_pps->pps_seq_parameter_set_id > HEVC_SPS_ID_MAX )
@@ -974,7 +956,7 @@ static bool hevc_parse_pic_parameter_set_rbsp( bs_t *p_bs,
if( p_pps->cu_qp_delta_enabled_flag )
p_pps->diff_cu_qp_delta_depth = bs_read_ue( p_bs );
- if( bs_remain( p_bs ) < 1 )
+ if( bs_error( p_bs ) )
return false;
p_pps->pps_cb_qp_offset = bs_read_se( p_bs );
@@ -993,15 +975,14 @@ static bool hevc_parse_pic_parameter_set_rbsp( bs_t *p_bs,
p_pps->uniform_spacing_flag = bs_read1( p_bs );
if( !p_pps->uniform_spacing_flag )
{
- if( bs_remain( p_bs ) < p_pps->num_tile_columns_minus1 +
- p_pps->num_tile_rows_minus1 + 1 )
- return false;
for( unsigned i=0; i< p_pps->num_tile_columns_minus1; i++ )
(void) bs_read_ue( p_bs );
for( unsigned i=0; i< p_pps->num_tile_rows_minus1; i++ )
(void) bs_read_ue( p_bs );
}
p_pps->loop_filter_across_tiles_enabled_flag = bs_read1( p_bs );
+ if( bs_error( p_bs ) )
+ return false;
}
p_pps->pps_loop_filter_across_slices_enabled_flag = bs_read1( p_bs );
@@ -1025,21 +1006,16 @@ static bool hevc_parse_pic_parameter_set_rbsp( bs_t *p_bs,
p_pps->log2_parallel_merge_level_minus2 = bs_read_ue( p_bs );
p_pps->slice_header_extension_present_flag = bs_read1( p_bs );
- if( bs_remain( p_bs ) < 1 )
- return false;
-
p_pps->pps_extension_present_flag = bs_read1( p_bs );
if( p_pps->pps_extension_present_flag )
{
p_pps->pps_range_extension_flag = bs_read1( p_bs );
p_pps->pps_multilayer_extension_flag = bs_read1( p_bs );
p_pps->pps_3d_extension_flag = bs_read1( p_bs );
- if( bs_remain( p_bs ) < 5 )
- return false;
p_pps->pps_extension_5bits = bs_read( p_bs, 5 );
}
- return true;
+ return !bs_error( p_bs );
}
void hevc_rbsp_release_pps( hevc_picture_parameter_set_t *p_pps )
@@ -1232,14 +1208,17 @@ static bool hevc_parse_slice_segment_header_rbsp( bs_t *p_bs,
hevc_picture_parameter_set_t *p_pps;
hevc_video_parameter_set_t *p_vps;
- if( bs_remain( p_bs ) < 3 )
+ if( bs_eof( p_bs ) )
return false;
p_sl->first_slice_segment_in_pic_flag = bs_read1( p_bs );
if( p_sl->nal_type >= HEVC_NAL_BLA_W_LP && p_sl->nal_type <= HEVC_NAL_IRAP_VCL23 )
p_sl->no_output_of_prior_pics_flag = bs_read1( p_bs );
p_sl->slice_pic_parameter_set_id = bs_read_ue( p_bs );
- if( p_sl->slice_pic_parameter_set_id > HEVC_PPS_ID_MAX || bs_remain( p_bs ) < 1 )
+ if( p_sl->slice_pic_parameter_set_id > HEVC_PPS_ID_MAX )
+ return false;
+
+ if( bs_error( p_bs ) )
return false;
get_matchedxps( p_sl->slice_pic_parameter_set_id, priv, &p_pps, &p_sps, &p_vps );
@@ -1294,10 +1273,7 @@ static bool hevc_parse_slice_segment_header_rbsp( bs_t *p_bs,
else
p_sl->pic_order_cnt_lsb = 0;
- if( bs_remain( p_bs ) < 1 )
- return false;
-
- return true;
+ return !bs_error( p_bs );
}
void hevc_rbsp_release_slice_header( hevc_slice_segment_header_t *p_sh )
diff --git a/modules/packetizer/hxxx_sei.c b/modules/packetizer/hxxx_sei.c
index 79cfa91b3d..b6661f80b5 100644
--- a/modules/packetizer/hxxx_sei.c
+++ b/modules/packetizer/hxxx_sei.c
@@ -51,11 +51,11 @@ void HxxxParseSEI(const uint8_t *p_buf, size_t i_buf,
&hxxx_bsfw_ep3b_callbacks, &bsctx );
- while( bs_remain( &s ) >= 8 && bs_aligned( &s ) && b_continue )
+ while( !bs_eof( &s ) && bs_aligned( &s ) && b_continue )
{
/* Read type */
unsigned i_type = 0;
- while( bs_remain( &s ) >= 8 )
+ while( !bs_eof( &s ) )
{
const uint8_t i_byte = bs_read( &s, 8 );
i_type += i_byte;
@@ -63,9 +63,12 @@ void HxxxParseSEI(const uint8_t *p_buf, size_t i_buf,
break;
}
+ if( bs_error( &s ) )
+ return;
+
/* Read size */
unsigned i_size = 0;
- while( bs_remain( &s ) >= 8 )
+ while( !bs_eof( &s ) )
{
const uint8_t i_byte = bs_read( &s, 8 );
i_size += i_byte;
@@ -73,8 +76,11 @@ void HxxxParseSEI(const uint8_t *p_buf, size_t i_buf,
break;
}
+ if( bs_error( &s ) )
+ return;
+
/* Check room */
- if( bs_remain( &s ) < 8 )
+ if( bs_eof( &s ) )
break;
hxxx_sei_data_t sei_data;
@@ -99,9 +105,12 @@ void HxxxParseSEI(const uint8_t *p_buf, size_t i_buf,
if( !p_t35 )
break;
- for( i_t35 = 0; i_t35<i_size && bs_remain( &s ) >= 8; i_t35++ )
+ for( i_t35 = 0; i_t35<i_size && !bs_eof( &s ); i_t35++ )
p_t35[i_t35] = bs_read( &s, 8 );
+ if( bs_error( &s ) )
+ break;
+
/* TS 101 154 Auxiliary Data and H264/AVC video */
if( i_t35 > 4 && p_t35[0] == 0xb5 /* United States */ )
{
@@ -168,25 +177,23 @@ void HxxxParseSEI(const uint8_t *p_buf, size_t i_buf,
case HXXX_SEI_MASTERING_DISPLAY_COLOUR_VOLUME:
{
- if ( bs_remain( &s ) < (16*6+16*2+32+32) )
- /* not enough data */
- break;
for ( size_t i = 0; i < 6 ; ++i)
sei_data.colour_volume.primaries[i] = bs_read( &s, 16 );
for ( size_t i = 0; i < 2 ; ++i)
sei_data.colour_volume.white_point[i] = bs_read( &s, 16 );
sei_data.colour_volume.max_luminance = bs_read( &s, 32 );
sei_data.colour_volume.min_luminance = bs_read( &s, 32 );
+ if( bs_error( &s ) ) /* not enough data */
+ break;
b_continue = pf_callback( &sei_data, cbdata );
} break;
case HXXX_SEI_CONTENT_LIGHT_LEVEL:
{
- if ( bs_remain( &s ) < (16+16) )
- /* not enough data */
- break;
sei_data.content_light_lvl.MaxCLL = bs_read( &s, 16 );
sei_data.content_light_lvl.MaxFALL = bs_read( &s, 16 );
+ if( bs_error( &s ) ) /* not enough data */
+ break;
b_continue = pf_callback( &sei_data, cbdata );
} break;
diff --git a/modules/packetizer/mpeg4audio.c b/modules/packetizer/mpeg4audio.c
index 5f8cfd3be4..48ce90901e 100644
--- a/modules/packetizer/mpeg4audio.c
+++ b/modules/packetizer/mpeg4audio.c
@@ -750,7 +750,7 @@ static int Mpeg4ReadAudioSpecificConfig(bs_t *s, mpeg4_asc_t *p_cfg, bool b_with
}
if (b_withext && p_cfg->extension.i_object_type != AOT_AAC_SBR &&
- bs_remain(s) >= 16 && bs_read(s, 11) == 0x2b7)
+ !bs_eof(s) && bs_read(s, 11) == 0x2b7)
{
p_cfg->extension.i_object_type = Mpeg4ReadAudioObjectType(s);
if (p_cfg->extension.i_object_type == AOT_AAC_SBR)
@@ -758,7 +758,7 @@ static int Mpeg4ReadAudioSpecificConfig(bs_t *s, mpeg4_asc_t *p_cfg, bool b_with
p_cfg->i_sbr = bs_read1(s);
if (p_cfg->i_sbr == 1) {
p_cfg->extension.i_samplerate = Mpeg4ReadAudioSamplerate(s);
- if (bs_remain(s) >= 12 && bs_read(s, 11) == 0x548)
+ if (bs_read(s, 11) == 0x548)
p_cfg->i_ps = bs_read1(s);
}
}
@@ -796,7 +796,7 @@ static int Mpeg4ReadAudioSpecificConfig(bs_t *s, mpeg4_asc_t *p_cfg, bool b_with
ppsz_otype[p_cfg->i_object_type], p_cfg->i_object_type,
p_cfg->i_samplerate, p_cfg->i_channel, p_cfg->i_sbr);
#endif
- return VLC_SUCCESS;
+ return bs_error(&s) ? VLC_EGENERIC : VLC_SUCCESS;
}
static uint32_t LatmGetValue(bs_t *s)
@@ -836,7 +836,7 @@ static int LatmReadStreamMuxConfiguration(latm_mux_t *m, bs_t *s)
if (i_mux_version == 1)
LatmGetValue(s); /* taraBufferFullness */
- if(bs_remain(s) < 11)
+ if(bs_eof(s))
return -1;
m->b_same_time_framing = bs_read1(s);
@@ -844,7 +844,7 @@ static int LatmReadStreamMuxConfiguration(latm_mux_t *m, bs_t *s)
m->i_programs = 1 + bs_read(s, 4);
for (uint8_t i_program = 0; i_program < m->i_programs; i_program++) {
- if(bs_remain(s) < 3)
+ if(bs_eof(s))
return -1;
m->pi_layers[i_program] = 1+bs_read(s, 3);
@@ -906,7 +906,7 @@ static int LatmReadStreamMuxConfiguration(latm_mux_t *m, bs_t *s)
}
}
- if(bs_remain(s) < 2)
+ if(bs_error(s) || bs_eof(s))
return -1;
/* other data */
@@ -927,7 +927,7 @@ static int LatmReadStreamMuxConfiguration(latm_mux_t *m, bs_t *s)
if (bs_read1(s))
m->i_crc = bs_read(s, 8);
- return 0;
+ return bs_error(s) ? -1 : 0;
}
static int LOASParse(decoder_t *p_dec, uint8_t *p_buffer, int i_buffer)
@@ -988,7 +988,7 @@ static int LOASParse(decoder_t *p_dec, uint8_t *p_buffer, int i_buffer)
else return 0;
}
- if(bs_remain(&s) == 0 && i_buffer)
+ if(bs_eof(&s) && i_buffer)
goto truncated;
/* FIXME do we need to split the subframe into independent packet ? */
@@ -1034,14 +1034,13 @@ static int LOASParse(decoder_t *p_dec, uint8_t *p_buffer, int i_buffer)
if (pi_payload[i_program][i_layer] <= 0)
continue;
- if(pi_payload[i_program][i_layer] > (bs_remain(&s) >> 3))
- goto truncated;
-
/* FIXME that's slow (and a bit ugly to write in place) */
for (unsigned i = 0; i < pi_payload[i_program][i_layer]; i++) {
if (i_accumulated >= i_buffer)
return 0;
p_buffer[i_accumulated++] = bs_read(&s, 8);
+ if(bs_error(&s))
+ goto truncated;
}
}
}
diff --git a/modules/packetizer/vc1.c b/modules/packetizer/vc1.c
index 7317d440e2..d8f43f3060 100644
--- a/modules/packetizer/vc1.c
+++ b/modules/packetizer/vc1.c
@@ -754,8 +754,12 @@ static block_t *ParseIDU( decoder_t *p_dec, bool *pb_ts_used, block_t *p_frag )
if( p_data )
{
/* store converted data */
- for( i_data = 0; i_data<i_size && bs_remain( &s ) >= 16 /* trailing 0x80 flush byte */; i_data++ )
+ for( i_data = 0; i_data + 1 /* trailing 0x80 flush byte */<i_size; i_data++ )
+ {
p_data[i_data] = bs_read( &s, 8 );
+ if( bs_error(&s) )
+ break;
+ }
/* TS 101 154 Auxiliary Data and VC-1 video */
static const uint8_t p_DVB1_user_identifier[] = {
More information about the vlc-commits
mailing list