From 67bbaed5c498212bdd70b13b4fdcb37f4c9c77f5 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sat, 14 Dec 2013 15:50:29 +0100 Subject: [PATCH 1/2] hevc: don't check for errors in PTL code According to the spec, the value of XXX_reserved_zero_44bits should be ignored, so don't report an error when it's not zero. Signed-off-by: Anton Khirnov --- libavcodec/hevc_ps.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index d9811253ee..5f33005f21 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -192,7 +192,7 @@ int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps, return 0; } -static int decode_profile_tier_level(HEVCLocalContext *lc, PTL *ptl, +static void decode_profile_tier_level(HEVCLocalContext *lc, PTL *ptl, int max_num_sub_layers) { int i, j; @@ -207,12 +207,9 @@ static int decode_profile_tier_level(HEVCLocalContext *lc, PTL *ptl, skip_bits1(gb); // general_interlaced_source_flag skip_bits1(gb); // general_non_packed_constraint_flag skip_bits1(gb); // general_frame_only_constraint_flag - if (get_bits(gb, 16) != 0) // XXX_reserved_zero_44bits[0..15] - return -1; - if (get_bits(gb, 16) != 0) // XXX_reserved_zero_44bits[16..31] - return -1; - if (get_bits(gb, 12) != 0) // XXX_reserved_zero_44bits[32..43] - return -1; + skip_bits(gb, 16); // XXX_reserved_zero_44bits[0..15] + skip_bits(gb, 16); // XXX_reserved_zero_44bits[16..31] + skip_bits(gb, 12); // XXX_reserved_zero_44bits[32..43] ptl->general_level_idc = get_bits(gb, 8); for (i = 0; i < max_num_sub_layers - 1; i++) { @@ -234,17 +231,13 @@ static int decode_profile_tier_level(HEVCLocalContext *lc, PTL *ptl, skip_bits1(gb); // sub_layer_non_packed_constraint_flag skip_bits1(gb); // sub_layer_frame_only_constraint_flag - if (get_bits(gb, 16) != 0) // sub_layer_reserved_zero_44bits[0..15] - return -1; - if (get_bits(gb, 16) != 0) // sub_layer_reserved_zero_44bits[16..31] - return -1; - if (get_bits(gb, 12) != 0) // sub_layer_reserved_zero_44bits[32..43] - return -1; + skip_bits(gb, 16); // sub_layer_reserved_zero_44bits[0..15] + skip_bits(gb, 16); // sub_layer_reserved_zero_44bits[16..31] + skip_bits(gb, 12); // sub_layer_reserved_zero_44bits[32..43] } if (ptl->sub_layer_level_present_flag[i]) ptl->sub_layer_level_idc[i] = get_bits(gb, 8); } - return 0; } static void decode_sublayer_hrd(HEVCContext *s, int nb_cpb, @@ -362,10 +355,7 @@ int ff_hevc_decode_nal_vps(HEVCContext *s) goto err; } - if (decode_profile_tier_level(&s->HEVClc, &vps->ptl, vps->vps_max_sub_layers) < 0) { - av_log(s->avctx, AV_LOG_ERROR, "Error decoding profile tier level.\n"); - goto err; - } + decode_profile_tier_level(&s->HEVClc, &vps->ptl, vps->vps_max_sub_layers); vps->vps_sub_layer_ordering_info_present_flag = get_bits1(gb); i = vps->vps_sub_layer_ordering_info_present_flag ? 0 : vps->vps_max_sub_layers - 1; @@ -647,12 +637,7 @@ int ff_hevc_decode_nal_sps(HEVCContext *s) } skip_bits1(gb); // temporal_id_nesting_flag - if (decode_profile_tier_level(&s->HEVClc, &sps->ptl, - sps->max_sub_layers) < 0) { - av_log(s->avctx, AV_LOG_ERROR, "error decoding profile tier level\n"); - ret = AVERROR_INVALIDDATA; - goto err; - } + decode_profile_tier_level(&s->HEVClc, &sps->ptl, sps->max_sub_layers); sps_id = get_ue_golomb_long(gb); if (sps_id >= MAX_SPS_COUNT) { av_log(s->avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", sps_id); From 2d18aaa14bc2233b0647d2c5abb72e0bc828c2a8 Mon Sep 17 00:00:00 2001 From: Gildas Cocherel Date: Thu, 19 Dec 2013 00:36:45 +0100 Subject: [PATCH 2/2] hevc: refactor Profile Tier Level Also store a few PTL flags which were skipped before Signed-off-by: Anton Khirnov --- libavcodec/hevc.h | 25 +++++++++-------- libavcodec/hevc_ps.c | 65 ++++++++++++++++++++++---------------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h index bd6f50fdea..f2a8dfa9f2 100644 --- a/libavcodec/hevc.h +++ b/libavcodec/hevc.h @@ -328,21 +328,24 @@ typedef struct VUI { int log2_max_mv_length_vertical; } VUI; +typedef struct PTLCommon { + uint8_t profile_space; + uint8_t tier_flag; + uint8_t profile_idc; + uint8_t profile_compatibility_flag[32]; + uint8_t level_idc; + uint8_t progressive_source_flag; + uint8_t interlaced_source_flag; + uint8_t non_packed_constraint_flag; + uint8_t frame_only_constraint_flag; +} PTLCommon; + typedef struct PTL { - int general_profile_space; - uint8_t general_tier_flag; - int general_profile_idc; - int general_profile_compatibility_flag[32]; - int general_level_idc; + PTLCommon general_ptl; + PTLCommon sub_layer_ptl[MAX_SUB_LAYERS]; uint8_t sub_layer_profile_present_flag[MAX_SUB_LAYERS]; uint8_t sub_layer_level_present_flag[MAX_SUB_LAYERS]; - - int sub_layer_profile_space[MAX_SUB_LAYERS]; - uint8_t sub_layer_tier_flag[MAX_SUB_LAYERS]; - int sub_layer_profile_idc[MAX_SUB_LAYERS]; - uint8_t sub_layer_profile_compatibility_flags[MAX_SUB_LAYERS][32]; - int sub_layer_level_idc[MAX_SUB_LAYERS]; } PTL; typedef struct HEVCVPS { diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index 5f33005f21..5dde0cd49a 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -192,51 +192,47 @@ int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps, return 0; } -static void decode_profile_tier_level(HEVCLocalContext *lc, PTL *ptl, - int max_num_sub_layers) -{ - int i, j; - GetBitContext *gb = &lc->gb; - ptl->general_profile_space = get_bits(gb, 2); - ptl->general_tier_flag = get_bits1(gb); - ptl->general_profile_idc = get_bits(gb, 5); +static void decode_profile_tier_level(HEVCContext *s, PTLCommon *ptl) +{ + int i; + GetBitContext *gb = &s->HEVClc.gb; + + ptl->profile_space = get_bits(gb, 2); + ptl->tier_flag = get_bits1(gb); + ptl->profile_idc = get_bits(gb, 5); + for (i = 0; i < 32; i++) - ptl->general_profile_compatibility_flag[i] = get_bits1(gb); - skip_bits1(gb); // general_progressive_source_flag - skip_bits1(gb); // general_interlaced_source_flag - skip_bits1(gb); // general_non_packed_constraint_flag - skip_bits1(gb); // general_frame_only_constraint_flag + ptl->profile_compatibility_flag[i] = get_bits1(gb); + ptl->progressive_source_flag = get_bits1(gb); + ptl->interlaced_source_flag = get_bits1(gb); + ptl->non_packed_constraint_flag = get_bits1(gb); + ptl->frame_only_constraint_flag = get_bits1(gb); + skip_bits(gb, 16); // XXX_reserved_zero_44bits[0..15] skip_bits(gb, 16); // XXX_reserved_zero_44bits[16..31] skip_bits(gb, 12); // XXX_reserved_zero_44bits[32..43] +} + +static void parse_ptl(HEVCContext *s, PTL *ptl, int max_num_sub_layers) +{ + int i; + GetBitContext *gb = &s->HEVClc.gb; + decode_profile_tier_level(s, &ptl->general_ptl); + ptl->general_ptl.level_idc = get_bits(gb, 8); - ptl->general_level_idc = get_bits(gb, 8); for (i = 0; i < max_num_sub_layers - 1; i++) { ptl->sub_layer_profile_present_flag[i] = get_bits1(gb); ptl->sub_layer_level_present_flag[i] = get_bits1(gb); } if (max_num_sub_layers - 1 > 0) for (i = max_num_sub_layers - 1; i < 8; i++) - skip_bits(gb, 2); // reserved_zero_2bits[i] + skip_bits(gb, 2); // reserved_zero_2bits[i] for (i = 0; i < max_num_sub_layers - 1; i++) { - if (ptl->sub_layer_profile_present_flag[i]) { - ptl->sub_layer_profile_space[i] = get_bits(gb, 2); - ptl->sub_layer_tier_flag[i] = get_bits(gb, 1); - ptl->sub_layer_profile_idc[i] = get_bits(gb, 5); - for (j = 0; j < 32; j++) - ptl->sub_layer_profile_compatibility_flags[i][j] = get_bits1(gb); - skip_bits1(gb); // sub_layer_progressive_source_flag - skip_bits1(gb); // sub_layer_interlaced_source_flag - skip_bits1(gb); // sub_layer_non_packed_constraint_flag - skip_bits1(gb); // sub_layer_frame_only_constraint_flag - - skip_bits(gb, 16); // sub_layer_reserved_zero_44bits[0..15] - skip_bits(gb, 16); // sub_layer_reserved_zero_44bits[16..31] - skip_bits(gb, 12); // sub_layer_reserved_zero_44bits[32..43] - } + if (ptl->sub_layer_profile_present_flag[i]) + decode_profile_tier_level(s, &ptl->sub_layer_ptl[i]); if (ptl->sub_layer_level_present_flag[i]) - ptl->sub_layer_level_idc[i] = get_bits(gb, 8); + ptl->sub_layer_ptl[i].level_idc = get_bits(gb, 8); } } @@ -355,7 +351,8 @@ int ff_hevc_decode_nal_vps(HEVCContext *s) goto err; } - decode_profile_tier_level(&s->HEVClc, &vps->ptl, vps->vps_max_sub_layers); + parse_ptl(s, &vps->ptl, vps->vps_max_sub_layers); + vps->vps_sub_layer_ordering_info_present_flag = get_bits1(gb); i = vps->vps_sub_layer_ordering_info_present_flag ? 0 : vps->vps_max_sub_layers - 1; @@ -637,7 +634,9 @@ int ff_hevc_decode_nal_sps(HEVCContext *s) } skip_bits1(gb); // temporal_id_nesting_flag - decode_profile_tier_level(&s->HEVClc, &sps->ptl, sps->max_sub_layers); + + parse_ptl(s, &sps->ptl, sps->max_sub_layers); + sps_id = get_ue_golomb_long(gb); if (sps_id >= MAX_SPS_COUNT) { av_log(s->avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", sps_id);