Commit 15893adb authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/hevc_ps: Remove gotos from ff_hevc_parse_sps()

They are currently unnecessary
Found-by: 's avatarJames Almer <jamrial@gmail.com>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 4a5074d7
...@@ -756,35 +756,31 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -756,35 +756,31 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
sps->vps_id = get_bits(gb, 4); sps->vps_id = get_bits(gb, 4);
if (sps->vps_id >= MAX_VPS_COUNT) { if (sps->vps_id >= MAX_VPS_COUNT) {
av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", sps->vps_id); av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", sps->vps_id);
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
if (vps_list && !vps_list[sps->vps_id]) { if (vps_list && !vps_list[sps->vps_id]) {
av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n", av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
sps->vps_id); sps->vps_id);
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
sps->max_sub_layers = get_bits(gb, 3) + 1; sps->max_sub_layers = get_bits(gb, 3) + 1;
if (sps->max_sub_layers > MAX_SUB_LAYERS) { if (sps->max_sub_layers > MAX_SUB_LAYERS) {
av_log(avctx, AV_LOG_ERROR, "sps_max_sub_layers out of range: %d\n", av_log(avctx, AV_LOG_ERROR, "sps_max_sub_layers out of range: %d\n",
sps->max_sub_layers); sps->max_sub_layers);
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
skip_bits1(gb); // temporal_id_nesting_flag skip_bits1(gb); // temporal_id_nesting_flag
if ((ret = parse_ptl(gb, avctx, &sps->ptl, sps->max_sub_layers)) < 0) if ((ret = parse_ptl(gb, avctx, &sps->ptl, sps->max_sub_layers)) < 0)
goto err; return ret;
*sps_id = get_ue_golomb_long(gb); *sps_id = get_ue_golomb_long(gb);
if (*sps_id >= MAX_SPS_COUNT) { if (*sps_id >= MAX_SPS_COUNT) {
av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", *sps_id); av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", *sps_id);
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
sps->chroma_format_idc = get_ue_golomb_long(gb); sps->chroma_format_idc = get_ue_golomb_long(gb);
...@@ -799,7 +795,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -799,7 +795,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
sps->height = get_ue_golomb_long(gb); sps->height = get_ue_golomb_long(gb);
if ((ret = av_image_check_size(sps->width, if ((ret = av_image_check_size(sps->width,
sps->height, 0, avctx)) < 0) sps->height, 0, avctx)) < 0)
goto err; return ret;
if (get_bits1(gb)) { // pic_conformance_flag if (get_bits1(gb)) { // pic_conformance_flag
//TODO: * 2 is only valid for 420 //TODO: * 2 is only valid for 420
...@@ -832,8 +828,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -832,8 +828,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
"Luma bit depth (%d) is different from chroma bit depth (%d), " "Luma bit depth (%d) is different from chroma bit depth (%d), "
"this is unsupported.\n", "this is unsupported.\n",
sps->bit_depth, bit_depth_chroma); sps->bit_depth, bit_depth_chroma);
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
switch (sps->bit_depth) { switch (sps->bit_depth) {
...@@ -864,14 +859,12 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -864,14 +859,12 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
default: default:
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"4:2:0, 4:2:2, 4:4:4 supports are currently specified for 8, 10 and 12 bits.\n"); "4:2:0, 4:2:2, 4:4:4 supports are currently specified for 8, 10 and 12 bits.\n");
ret = AVERROR_PATCHWELCOME; return AVERROR_INVALIDDATA;
goto err;
} }
desc = av_pix_fmt_desc_get(sps->pix_fmt); desc = av_pix_fmt_desc_get(sps->pix_fmt);
if (!desc) { if (!desc) {
ret = AVERROR(EINVAL); return AVERROR(EINVAL);
goto err;
} }
sps->hshift[0] = sps->vshift[0] = 0; sps->hshift[0] = sps->vshift[0] = 0;
...@@ -884,8 +877,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -884,8 +877,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
if (sps->log2_max_poc_lsb > 16) { if (sps->log2_max_poc_lsb > 16) {
av_log(avctx, AV_LOG_ERROR, "log2_max_pic_order_cnt_lsb_minus4 out range: %d\n", av_log(avctx, AV_LOG_ERROR, "log2_max_pic_order_cnt_lsb_minus4 out range: %d\n",
sps->log2_max_poc_lsb - 4); sps->log2_max_poc_lsb - 4);
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
sublayer_ordering_info = get_bits1(gb); sublayer_ordering_info = get_bits1(gb);
...@@ -897,16 +889,14 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -897,16 +889,14 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
if (sps->temporal_layer[i].max_dec_pic_buffering > MAX_DPB_SIZE) { if (sps->temporal_layer[i].max_dec_pic_buffering > MAX_DPB_SIZE) {
av_log(avctx, AV_LOG_ERROR, "sps_max_dec_pic_buffering_minus1 out of range: %d\n", av_log(avctx, AV_LOG_ERROR, "sps_max_dec_pic_buffering_minus1 out of range: %d\n",
sps->temporal_layer[i].max_dec_pic_buffering - 1); sps->temporal_layer[i].max_dec_pic_buffering - 1);
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
if (sps->temporal_layer[i].num_reorder_pics > sps->temporal_layer[i].max_dec_pic_buffering - 1) { if (sps->temporal_layer[i].num_reorder_pics > sps->temporal_layer[i].max_dec_pic_buffering - 1) {
av_log(avctx, AV_LOG_WARNING, "sps_max_num_reorder_pics out of range: %d\n", av_log(avctx, AV_LOG_WARNING, "sps_max_num_reorder_pics out of range: %d\n",
sps->temporal_layer[i].num_reorder_pics); sps->temporal_layer[i].num_reorder_pics);
if (avctx->err_recognition & AV_EF_EXPLODE || if (avctx->err_recognition & AV_EF_EXPLODE ||
sps->temporal_layer[i].num_reorder_pics > MAX_DPB_SIZE - 1) { sps->temporal_layer[i].num_reorder_pics > MAX_DPB_SIZE - 1) {
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
sps->temporal_layer[i].max_dec_pic_buffering = sps->temporal_layer[i].num_reorder_pics + 1; sps->temporal_layer[i].max_dec_pic_buffering = sps->temporal_layer[i].num_reorder_pics + 1;
} }
...@@ -929,26 +919,22 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -929,26 +919,22 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
if (sps->log2_min_cb_size < 3 || sps->log2_min_cb_size > 30) { if (sps->log2_min_cb_size < 3 || sps->log2_min_cb_size > 30) {
av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_min_cb_size", sps->log2_min_cb_size); av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_min_cb_size", sps->log2_min_cb_size);
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
if (sps->log2_diff_max_min_coding_block_size > 30) { if (sps->log2_diff_max_min_coding_block_size > 30) {
av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_diff_max_min_coding_block_size", sps->log2_diff_max_min_coding_block_size); av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_diff_max_min_coding_block_size", sps->log2_diff_max_min_coding_block_size);
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
if (sps->log2_min_tb_size >= sps->log2_min_cb_size || sps->log2_min_tb_size < 2) { if (sps->log2_min_tb_size >= sps->log2_min_cb_size || sps->log2_min_tb_size < 2) {
av_log(avctx, AV_LOG_ERROR, "Invalid value for log2_min_tb_size"); av_log(avctx, AV_LOG_ERROR, "Invalid value for log2_min_tb_size");
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
if (log2_diff_max_min_transform_block_size < 0 || log2_diff_max_min_transform_block_size > 30) { if (log2_diff_max_min_transform_block_size < 0 || log2_diff_max_min_transform_block_size > 30) {
av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_diff_max_min_transform_block_size", log2_diff_max_min_transform_block_size); av_log(avctx, AV_LOG_ERROR, "Invalid value %d for log2_diff_max_min_transform_block_size", log2_diff_max_min_transform_block_size);
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
sps->max_transform_hierarchy_depth_inter = get_ue_golomb_long(gb); sps->max_transform_hierarchy_depth_inter = get_ue_golomb_long(gb);
...@@ -961,7 +947,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -961,7 +947,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
if (get_bits1(gb)) { if (get_bits1(gb)) {
ret = scaling_list_data(gb, avctx, &sps->scaling_list, sps); ret = scaling_list_data(gb, avctx, &sps->scaling_list, sps);
if (ret < 0) if (ret < 0)
goto err; return ret;
} }
} }
...@@ -979,8 +965,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -979,8 +965,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"PCM bit depth (%d) is greater than normal bit depth (%d)\n", "PCM bit depth (%d) is greater than normal bit depth (%d)\n",
sps->pcm.bit_depth, sps->bit_depth); sps->pcm.bit_depth, sps->bit_depth);
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
sps->pcm.loop_filter_disable_flag = get_bits1(gb); sps->pcm.loop_filter_disable_flag = get_bits1(gb);
...@@ -990,15 +975,13 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -990,15 +975,13 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
if (sps->nb_st_rps > MAX_SHORT_TERM_RPS_COUNT) { if (sps->nb_st_rps > MAX_SHORT_TERM_RPS_COUNT) {
av_log(avctx, AV_LOG_ERROR, "Too many short term RPS: %d.\n", av_log(avctx, AV_LOG_ERROR, "Too many short term RPS: %d.\n",
sps->nb_st_rps); sps->nb_st_rps);
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
for (i = 0; i < sps->nb_st_rps; i++) { for (i = 0; i < sps->nb_st_rps; i++) {
if ((ret = ff_hevc_decode_short_term_rps(gb, avctx, &sps->st_rps[i], if ((ret = ff_hevc_decode_short_term_rps(gb, avctx, &sps->st_rps[i],
sps, 0)) < 0) sps, 0)) < 0)
goto err; return ret;
} }
ret = AVERROR_INVALIDDATA;
sps->long_term_ref_pics_present_flag = get_bits1(gb); sps->long_term_ref_pics_present_flag = get_bits1(gb);
if (sps->long_term_ref_pics_present_flag) { if (sps->long_term_ref_pics_present_flag) {
...@@ -1006,7 +989,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -1006,7 +989,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
if (sps->num_long_term_ref_pics_sps > 31U) { if (sps->num_long_term_ref_pics_sps > 31U) {
av_log(avctx, AV_LOG_ERROR, "num_long_term_ref_pics_sps %d is out of range.\n", av_log(avctx, AV_LOG_ERROR, "num_long_term_ref_pics_sps %d is out of range.\n",
sps->num_long_term_ref_pics_sps); sps->num_long_term_ref_pics_sps);
goto err; return AVERROR_INVALIDDATA;
} }
for (i = 0; i < sps->num_long_term_ref_pics_sps; i++) { for (i = 0; i < sps->num_long_term_ref_pics_sps; i++) {
sps->lt_ref_pic_poc_lsb_sps[i] = get_bits(gb, sps->log2_max_poc_lsb); sps->lt_ref_pic_poc_lsb_sps[i] = get_bits(gb, sps->log2_max_poc_lsb);
...@@ -1078,8 +1061,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -1078,8 +1061,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
av_log(avctx, AV_LOG_WARNING, "Invalid visible frame dimensions: %dx%d.\n", av_log(avctx, AV_LOG_WARNING, "Invalid visible frame dimensions: %dx%d.\n",
sps->output_width, sps->output_height); sps->output_width, sps->output_height);
if (avctx->err_recognition & AV_EF_EXPLODE) { if (avctx->err_recognition & AV_EF_EXPLODE) {
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto err;
} }
av_log(avctx, AV_LOG_WARNING, av_log(avctx, AV_LOG_WARNING,
"Displaying the whole video surface.\n"); "Displaying the whole video surface.\n");
...@@ -1096,7 +1078,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -1096,7 +1078,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
if (sps->log2_ctb_size > MAX_LOG2_CTB_SIZE) { if (sps->log2_ctb_size > MAX_LOG2_CTB_SIZE) {
av_log(avctx, AV_LOG_ERROR, "CTB size out of range: 2^%d\n", sps->log2_ctb_size); av_log(avctx, AV_LOG_ERROR, "CTB size out of range: 2^%d\n", sps->log2_ctb_size);
goto err; return AVERROR_INVALIDDATA;
} }
if (sps->log2_ctb_size < 4) { if (sps->log2_ctb_size < 4) {
av_log(avctx, av_log(avctx,
...@@ -1104,7 +1086,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -1104,7 +1086,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
"log2_ctb_size %d differs from the bounds of any known profile\n", "log2_ctb_size %d differs from the bounds of any known profile\n",
sps->log2_ctb_size); sps->log2_ctb_size);
avpriv_request_sample(avctx, "log2_ctb_size %d", sps->log2_ctb_size); avpriv_request_sample(avctx, "log2_ctb_size %d", sps->log2_ctb_size);
goto err; return AVERROR_INVALIDDATA;
} }
sps->ctb_width = (sps->width + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size; sps->ctb_width = (sps->width + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size;
...@@ -1124,36 +1106,33 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, ...@@ -1124,36 +1106,33 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
if (av_mod_uintp2(sps->width, sps->log2_min_cb_size) || if (av_mod_uintp2(sps->width, sps->log2_min_cb_size) ||
av_mod_uintp2(sps->height, sps->log2_min_cb_size)) { av_mod_uintp2(sps->height, sps->log2_min_cb_size)) {
av_log(avctx, AV_LOG_ERROR, "Invalid coded frame dimensions.\n"); av_log(avctx, AV_LOG_ERROR, "Invalid coded frame dimensions.\n");
goto err; return AVERROR_INVALIDDATA;
} }
if (sps->max_transform_hierarchy_depth_inter > sps->log2_ctb_size - sps->log2_min_tb_size) { if (sps->max_transform_hierarchy_depth_inter > sps->log2_ctb_size - sps->log2_min_tb_size) {
av_log(avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_inter out of range: %d\n", av_log(avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_inter out of range: %d\n",
sps->max_transform_hierarchy_depth_inter); sps->max_transform_hierarchy_depth_inter);
goto err; return AVERROR_INVALIDDATA;
} }
if (sps->max_transform_hierarchy_depth_intra > sps->log2_ctb_size - sps->log2_min_tb_size) { if (sps->max_transform_hierarchy_depth_intra > sps->log2_ctb_size - sps->log2_min_tb_size) {
av_log(avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_intra out of range: %d\n", av_log(avctx, AV_LOG_ERROR, "max_transform_hierarchy_depth_intra out of range: %d\n",
sps->max_transform_hierarchy_depth_intra); sps->max_transform_hierarchy_depth_intra);
goto err; return AVERROR_INVALIDDATA;
} }
if (sps->log2_max_trafo_size > FFMIN(sps->log2_ctb_size, 5)) { if (sps->log2_max_trafo_size > FFMIN(sps->log2_ctb_size, 5)) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"max transform block size out of range: %d\n", "max transform block size out of range: %d\n",
sps->log2_max_trafo_size); sps->log2_max_trafo_size);
goto err; return AVERROR_INVALIDDATA;
} }
if (get_bits_left(gb) < 0) { if (get_bits_left(gb) < 0) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"Overread SPS by %d bits\n", -get_bits_left(gb)); "Overread SPS by %d bits\n", -get_bits_left(gb));
goto err; return AVERROR_INVALIDDATA;
} }
return 0; return 0;
err:
return ret;
} }
int ff_hevc_decode_nal_sps(HEVCContext *s) int ff_hevc_decode_nal_sps(HEVCContext *s)
......
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