diff mbox series

[FFmpeg-devel,v2,03/13] lavc/hevc_ps: Add SPS/PPS parse support for HEVC extension syntax

Message ID 20221205060929.2511871-3-fei.w.wang@intel.com
State New
Headers show
Series [FFmpeg-devel,v2,01/13] lavc/hevc_ps: remove profile limitation of pps_range_extensions() | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Wang, Fei W Dec. 5, 2022, 6:09 a.m. UTC
From: Linjie Fu <linjie.fu@intel.com>

1. Add extension syntax according to 7.3.2.2.3/7.3.2.3.3 in T-REC-H.265-201911.
2. Keep using parsed PPS when bitstream overread for compatibility. For
example, the clip PS_A_VIDYO_3.bit in FATE test has incomplete extension
syntax which will be overread and un-decodable if without this change.
3. Format brace in pps_range_extensions().

Signed-off-by: Linjie Fu <linjie.justin.fu@gmail.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
---
 libavcodec/hevc.h    |   3 +
 libavcodec/hevc_ps.c | 288 +++++++++++++++++++++++++++++++++++++++++--
 libavcodec/hevc_ps.h |  69 +++++++++++
 3 files changed, 349 insertions(+), 11 deletions(-)

Comments

Xiang, Haihao Jan. 3, 2023, 6:20 a.m. UTC | #1
On Ma, 2022-12-05 at 14:09 +0800, Fei Wang wrote:
> From: Linjie Fu <linjie.fu@intel.com>
> 
> 1. Add extension syntax according to 7.3.2.2.3/7.3.2.3.3 in T-REC-H.265-
> 201911.
> 2. Keep using parsed PPS when bitstream overread for compatibility. For
> example, the clip PS_A_VIDYO_3.bit in FATE test has incomplete extension
> syntax which will be overread and un-decodable if without this change.
> 3. Format brace in pps_range_extensions().
> 
> Signed-off-by: Linjie Fu <linjie.justin.fu@gmail.com>
> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> Signed-off-by: Fei Wang <fei.w.wang@intel.com>
> ---
>  libavcodec/hevc.h    |   3 +
>  libavcodec/hevc_ps.c | 288 +++++++++++++++++++++++++++++++++++++++++--
>  libavcodec/hevc_ps.h |  69 +++++++++++
>  3 files changed, 349 insertions(+), 11 deletions(-)
> 
> diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
> index 1804755327..6b454a75c1 100644
> --- a/libavcodec/hevc.h
> +++ b/libavcodec/hevc.h
> @@ -154,6 +154,9 @@ enum {
>      // get near that, though, so set a lower limit here with the maximum
>      // possible value for 4K video (at most 135 16x16 Ctb rows).
>      HEVC_MAX_ENTRY_POINT_OFFSETS = HEVC_MAX_TILE_COLUMNS * 135,
> +
> +    // A.3.7: Screen content coding extensions
> +    HEVC_MAX_PALETTE_PREDICTOR_SIZE = 128,
>  };
>  
>  
> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
> index ad92b6bcbc..3181962918 100644
> --- a/libavcodec/hevc_ps.c
> +++ b/libavcodec/hevc_ps.c
> @@ -853,7 +853,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb,
> unsigned int *sps_id,
>      HEVCWindow *ow;
>      int ret = 0;
>      int log2_diff_max_min_transform_block_size;
> -    int bit_depth_chroma, start, vui_present, sublayer_ordering_info;
> +    int bit_depth_chroma, start, vui_present, sublayer_ordering_info,
> num_comps;
>      int i;
>  
>      // Coded parameters
> @@ -1074,8 +1074,12 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb,
> unsigned int *sps_id,
>          decode_vui(gb, avctx, apply_defdispwin, sps);
>  
>      if (get_bits1(gb)) { // sps_extension_flag
> -        sps->sps_range_extension_flag = get_bits1(gb);
> -        skip_bits(gb, 7); //sps_extension_7bits = get_bits(gb, 7);
> +        sps->sps_range_extension_flag      = get_bits1(gb);
> +        sps->sps_multilayer_extension_flag = get_bits1(gb);
> +        sps->sps_3d_extension_flag         = get_bits1(gb);
> +        sps->sps_scc_extension_flag        = get_bits1(gb);
> +        skip_bits(gb, 4); // sps_extension_4bits
> +
>          if (sps->sps_range_extension_flag) {
>              sps->transform_skip_rotation_enabled_flag = get_bits1(gb);
>              sps->transform_skip_context_enabled_flag  = get_bits1(gb);
> @@ -1101,6 +1105,57 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb,
> unsigned int *sps_id,
>                  av_log(avctx, AV_LOG_WARNING,
>                     "cabac_bypass_alignment_enabled_flag not yet
> implemented\n");
>          }
> +
> +        if (sps->sps_multilayer_extension_flag) {
> +            skip_bits1(gb); // inter_view_mv_vert_constraint_flag
> +            av_log(avctx, AV_LOG_WARNING,
> +                   "sps_multilayer_extension_flag not yet implemented\n");
> +        }
> +
> +        if (sps->sps_3d_extension_flag) {
> +            for (i = 0; i <= 1; i++) {
> +                skip_bits1(gb); // iv_di_mc_enabled_flag
> +                skip_bits1(gb); // iv_mv_scal_enabled_flag
> +                if (i == 0) {
> +                    get_ue_golomb_long(gb); // log2_ivmc_sub_pb_size_minus3
> +                    skip_bits1(gb); // iv_res_pred_enabled_flag
> +                    skip_bits1(gb); // depth_ref_enabled_flag
> +                    skip_bits1(gb); // vsp_mc_enabled_flag
> +                    skip_bits1(gb); // dbbp_enabled_flag
> +                } else {
> +                    skip_bits1(gb); // tex_mc_enabled_flag
> +                    get_ue_golomb_long(gb); // log2_ivmc_sub_pb_size_minus3
> +                    skip_bits1(gb); // intra_contour_enabled_flag
> +                    skip_bits1(gb); // intra_dc_only_wedge_enabled_flag
> +                    skip_bits1(gb); // cqt_cu_part_pred_enabled_flag
> +                    skip_bits1(gb); // inter_dc_only_enabled_flag
> +                    skip_bits1(gb); // skip_intra_enabled_flag
> +                }
> +            }
> +            av_log(avctx, AV_LOG_WARNING,
> +                   "sps_3d_extension_flag not yet implemented\n");
> +        }
> +
> +        if (sps->sps_scc_extension_flag) {
> +            sps->sps_curr_pic_ref_enabled_flag = get_bits1(gb);
> +            sps->palette_mode_enabled_flag     = get_bits1(gb);
> +            if (sps->palette_mode_enabled_flag) {
> +                sps->palette_max_size = get_ue_golomb_long(gb);
> +                sps->delta_palette_max_predictor_size =
> get_ue_golomb_long(gb);
> +                sps->sps_palette_predictor_initializers_present_flag =
> get_bits1(gb);
> +
> +                if (sps->sps_palette_predictor_initializers_present_flag) {
> +                    sps->sps_num_palette_predictor_initializers_minus1 =
> get_ue_golomb_long(gb);
> +                    num_comps = !sps->chroma_format_idc ? 1 : 3;
> +                    for (int comp = 0; comp < num_comps; comp++)
> +                        for (i = 0; i <= sps-
> >sps_num_palette_predictor_initializers_minus1; i++)
> +                            sps->sps_palette_predictor_initializer[comp][i] =
> +                                    get_bits(gb, !comp ? sps->bit_depth :
> sps->bit_depth_chroma);
> +                }
> +            }
> +            sps->motion_vector_resolution_control_idc   = get_bits(gb, 2);
> +            sps->intra_boundary_filtering_disabled_flag = get_bits1(gb);
> +        }
>      }
>      if (apply_defdispwin) {
>          sps->output_window.left_offset   += sps-
> >vui.def_disp_win.left_offset;
> @@ -1265,10 +1320,162 @@ static void hevc_pps_free(void *opaque, uint8_t
> *data)
>      av_freep(&pps);
>  }
>  
> -static int pps_range_extensions(GetBitContext *gb, AVCodecContext *avctx,
> -                                HEVCPPS *pps, HEVCSPS *sps) {
> -    int i;
> +static void colour_mapping_octants(GetBitContext *gb, HEVCPPS *pps, int
> inp_depth,
> +                                   int idx_y, int idx_cb, int idx_cr, int
> inp_length)
> +{
> +    unsigned int split_octant_flag, part_num_y, coded_res_flag, res_coeff_q,
> res_coeff_r;
> +    int bit_depth_cm_input_y, bit_depth_cm_output_y, cm_res_bits;
> +
> +    part_num_y = 1 << pps->cm_y_part_num_log2;
> +
> +    split_octant_flag = inp_depth < pps->cm_octant_depth ? get_bits1(gb) : 0;
> +
> +    if (split_octant_flag)
> +        for (int k = 0; k < 2; k++)
> +            for (int m = 0; m < 2; m++)
> +                for (int n = 0; n < 2; n++)
> +                    colour_mapping_octants(gb, pps, inp_depth + 1,
> +                                           idx_y + part_num_y * k *
> inp_length / 2,
> +                                           idx_cb + m * inp_length / 2,
> +                                           idx_cr + n * inp_length / 2,
> +                                           inp_length / 2);
> +    else
> +        for (int i = 0; i < part_num_y; i++) {
> +            for (int j = 0; j < 4; j++) {
> +                coded_res_flag = get_bits1(gb);
> +                if (coded_res_flag)
> +                    for (int c = 0; c < 3; c++) {
> +                        res_coeff_q = get_ue_golomb_long(gb);
> +                        bit_depth_cm_input_y = 8 + pps-
> >luma_bit_depth_cm_input_minus8;
> +                        bit_depth_cm_output_y = 8 + pps-
> >luma_bit_depth_cm_output_minus8;
> +                        cm_res_bits = FFMAX(0, 10 + bit_depth_cm_input_y -
> bit_depth_cm_output_y -
> +                                            pps->cm_res_quant_bits - (pps-
> >cm_delta_flc_bits_minus1 + 1));
> +                        res_coeff_r = cm_res_bits ? get_bits(gb, cm_res_bits)
> : 0;
> +                        if (res_coeff_q || res_coeff_r)
> +                            skip_bits1(gb);
> +                    }
> +            }
> +        }
> +}
>  
> +static void colour_mapping_table(GetBitContext *gb, HEVCPPS *pps)
> +{
> +    pps->num_cm_ref_layers_minus1 = get_ue_golomb_long(gb);
> +    for (int i = 0; i <= pps->num_cm_ref_layers_minus1; i++)
> +        pps->cm_ref_layer_id[i] = get_bits(gb, 6);
> +
> +    pps->cm_octant_depth = get_bits(gb, 2);
> +    pps->cm_y_part_num_log2 = get_bits(gb, 2);
> +
> +    pps->luma_bit_depth_cm_input_minus8    = get_ue_golomb_long(gb);
> +    pps->chroma_bit_depth_cm_input_minus8  = get_ue_golomb_long(gb);
> +    pps->luma_bit_depth_cm_output_minus8   = get_ue_golomb_long(gb);
> +    pps->chroma_bit_depth_cm_output_minus8 = get_ue_golomb_long(gb);
> +
> +    pps->cm_res_quant_bits = get_bits(gb, 2);
> +    pps->cm_delta_flc_bits_minus1 = get_bits(gb, 2);
> +
> +    if (pps->cm_octant_depth == 1) {
> +        pps->cm_adapt_threshold_u_delta = get_se_golomb_long(gb);
> +        pps->cm_adapt_threshold_v_delta = get_se_golomb_long(gb);
> +    }
> +
> +    colour_mapping_octants(gb, pps, 0, 0, 0, 0, 1 << pps->cm_octant_depth);
> +}
> +
> +static int pps_multilayer_extension(GetBitContext *gb, AVCodecContext *avctx,
> +                                    HEVCPPS *pps, HEVCSPS *sps)
> +{
> +    pps->poc_reset_info_present_flag = get_bits1(gb);
> +    pps->pps_infer_scaling_list_flag = get_bits1(gb);
> +    if (pps->pps_infer_scaling_list_flag)
> +        pps->pps_scaling_list_ref_layer_id = get_bits(gb, 6);
> +
> +    pps->num_ref_loc_offsets = get_ue_golomb_long(gb);
> +    for (int i = 0; i < pps->num_ref_loc_offsets; i++) {
> +        pps->ref_loc_offset_layer_id[i] = get_bits(gb, 6);
> +        pps->scaled_ref_layer_offset_present_flag[i] = get_bits1(gb);
> +        if (pps->scaled_ref_layer_offset_present_flag[i]) {
> +            pps->scaled_ref_layer_left_offset[pps-
> >ref_loc_offset_layer_id[i]]   = get_se_golomb_long(gb);
> +            pps->scaled_ref_layer_top_offset[pps-
> >ref_loc_offset_layer_id[i]]    = get_se_golomb_long(gb);
> +            pps->scaled_ref_layer_right_offset[pps-
> >ref_loc_offset_layer_id[i]]  = get_se_golomb_long(gb);
> +            pps->scaled_ref_layer_bottom_offset[pps-
> >ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb);
> +        }
> +
> +        pps->ref_region_offset_present_flag[i] = get_bits1(gb);
> +        if (pps->ref_region_offset_present_flag[i]) {
> +            pps->ref_region_left_offset[pps->ref_loc_offset_layer_id[i]]   =
> get_se_golomb_long(gb);
> +            pps->ref_region_top_offset[pps->ref_loc_offset_layer_id[i]]    =
> get_se_golomb_long(gb);
> +            pps->ref_region_right_offset[pps->ref_loc_offset_layer_id[i]]  =
> get_se_golomb_long(gb);
> +            pps->ref_region_bottom_offset[pps->ref_loc_offset_layer_id[i]] =
> get_se_golomb_long(gb);
> +        }
> +
> +        pps->resample_phase_set_present_flag[i] = get_bits1(gb);
> +        if (pps->resample_phase_set_present_flag[i]) {
> +            pps->phase_hor_luma[pps->ref_loc_offset_layer_id[i]]         =
> get_ue_golomb_long(gb);
> +            pps->phase_ver_luma[pps->ref_loc_offset_layer_id[i]]         =
> get_ue_golomb_long(gb);
> +            pps->phase_hor_chroma_plus8[pps->ref_loc_offset_layer_id[i]] =
> get_ue_golomb_long(gb);
> +            pps->phase_ver_chroma_plus8[pps->ref_loc_offset_layer_id[i]] =
> get_ue_golomb_long(gb);
> +        }
> +    }
> +
> +    pps->colour_mapping_enabled_flag = get_bits1(gb);
> +    if (pps->colour_mapping_enabled_flag)
> +        colour_mapping_table(gb, pps);
> +
> +    return 0;
> +}
> +
> +static void delta_dlt(GetBitContext *gb, HEVCPPS *pps)
> +{
> +    unsigned int num_val_delta_dlt, max_diff = 0;
> +    int min_diff_minus1 = -1;
> +    unsigned int len;
> +
> +    num_val_delta_dlt = get_bits(gb, pps-
> >pps_bit_depth_for_depth_layers_minus8 + 8);
> +    if (num_val_delta_dlt) {
> +        if (num_val_delta_dlt > 1)
> +            max_diff = get_bits(gb, pps-
> >pps_bit_depth_for_depth_layers_minus8 + 8);
> +        if (num_val_delta_dlt > 2 && max_diff) {
> +            len = av_log2(max_diff) + 1;
> +            min_diff_minus1 = get_bits(gb, len);
> +        }
> +        if (max_diff > (min_diff_minus1 + 1))
> +            for (int k = 1; k < num_val_delta_dlt; k++) {
> +                len = av_log2(max_diff - (min_diff_minus1 + 1)) + 1;
> +                skip_bits(gb, len); // delta_val_diff_minus_min
> +            }
> +    }
> +}
> +
> +static int pps_3d_extension(GetBitContext *gb, AVCodecContext *avctx,
> +                            HEVCPPS *pps, HEVCSPS *sps)
> +{
> +    unsigned int pps_depth_layers_minus1;
> +    int i, j;
> +
> +    if (get_bits1(gb)) { // dlts_present_flag
> +        pps_depth_layers_minus1 = get_bits(gb, 6);
> +        pps->pps_bit_depth_for_depth_layers_minus8 = get_bits(gb, 4);
> +        for (i = 0; i <= pps_depth_layers_minus1; i++) {

Please use the same coding style, 

for (int i = 0; ......)

> +            if (get_bits1(gb)) { // dlt_flag[i]
> +                if (!get_bits1(gb)) { // dlt_pred_flag[i]
> +                    if (get_bits1(gb)) { // dlt_val_flags_present_flag[i]
> +                        for (j = 0; j <= ((1 << (pps-
> >pps_bit_depth_for_depth_layers_minus8 + 8)) - 1); j++)

for (int j = 0; ......)

Thanks
Haihao


> +                            skip_bits1(gb); // dlt_value_flag[i][j]
> +                    } else
> +                        delta_dlt(gb, pps);
> +                }
> +            }
> +        }
> +    }
> +
> +    return 0;
> +}
> +
> +static int pps_range_extensions(GetBitContext *gb, AVCodecContext *avctx,
> +                                HEVCPPS *pps, HEVCSPS *sps)
> +{
>      if (pps->transform_skip_enabled_flag) {
>          pps->log2_max_transform_skip_block_size = get_ue_golomb_long(gb) + 2;
>      }
> @@ -1282,7 +1489,7 @@ static int pps_range_extensions(GetBitContext *gb,
> AVCodecContext *avctx,
>                     "chroma_qp_offset_list_len_minus1 shall be in the range
> [0, 5].\n");
>              return AVERROR_INVALIDDATA;
>          }
> -        for (i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) {
> +        for (int i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) {
>              pps->cb_qp_offset_list[i] = get_se_golomb_long(gb);
>              if (pps->cb_qp_offset_list[i]) {
>                  av_log(avctx, AV_LOG_WARNING,
> @@ -1306,6 +1513,47 @@ static int pps_range_extensions(GetBitContext *gb,
> AVCodecContext *avctx,
>      return(0);
>  }
>  
> +static int pps_scc_extension(GetBitContext *gb, AVCodecContext *avctx,
> +                             HEVCPPS *pps, HEVCSPS *sps)
> +{
> +    int num_comps, ret;
> +
> +    pps->pps_curr_pic_ref_enabled_flag = get_bits1(gb);
> +    if (pps->residual_adaptive_colour_transform_enabled_flag = get_bits1(gb))
> {
> +        pps->pps_slice_act_qp_offsets_present_flag = get_bits1(gb);
> +        pps->pps_act_y_qp_offset  = get_se_golomb_long(gb) - 5;
> +        pps->pps_act_cb_qp_offset = get_se_golomb_long(gb) - 5;
> +        pps->pps_act_cr_qp_offset = get_se_golomb_long(gb) - 3;
> +
> +#define CHECK_QP_OFFSET(name) (pps->pps_act_ ## name ## _qp_offset <= -12 ||
> \
> +                               pps->pps_act_ ## name ## _qp_offset >= 12)
> +        ret = CHECK_QP_OFFSET(y) || CHECK_QP_OFFSET(cb) ||
> CHECK_QP_OFFSET(cr);
> +#undef CHECK_QP_OFFSET
> +        if (ret) {
> +            av_log(avctx, AV_LOG_ERROR,
> +                   "PpsActQpOffsetY/Cb/Cr shall be in the range of [-12,
> 12].\n");
> +            return AVERROR_INVALIDDATA;
> +        }
> +    }
> +
> +    if (pps->pps_palette_predictor_initializers_present_flag = get_bits1(gb))
> {
> +        if ((pps->pps_num_palette_predictor_initializers =
> get_ue_golomb_long(gb)) > 0) {
> +            pps->monochrome_palette_flag = get_bits1(gb);
> +            pps->luma_bit_depth_entry_minus8 = get_ue_golomb_long(gb);
> +            if (!pps->monochrome_palette_flag)
> +                pps->chroma_bit_depth_entry_minus8 = get_ue_golomb_long(gb);
> +            num_comps = pps->monochrome_palette_flag ? 1 : 3;
> +            for (int comp = 0; comp < num_comps; comp++)
> +                for (int i = 0; i < pps-
> >pps_num_palette_predictor_initializers; i++)
> +                    pps->pps_palette_predictor_initializer[comp][i] =
> +                        get_bits(gb, 8 + (!comp ? pps-
> >luma_bit_depth_entry_minus8 :
> +                                          pps-
> >chroma_bit_depth_entry_minus8));
> +        }
> +    }
> +
> +    return 0;
> +}
> +
>  static inline int setup_pps(AVCodecContext *avctx, GetBitContext *gb,
>                              HEVCPPS *pps, HEVCSPS *sps)
>  {
> @@ -1658,12 +1906,31 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb,
> AVCodecContext *avctx,
>      pps->slice_header_extension_present_flag = get_bits1(gb);
>  
>      if (get_bits1(gb)) { // pps_extension_present_flag
> -        pps->pps_range_extensions_flag = get_bits1(gb);
> -        skip_bits(gb, 7); // pps_extension_7bits
> +        pps->pps_range_extensions_flag     = get_bits1(gb);
> +        pps->pps_multilayer_extension_flag = get_bits1(gb);
> +        pps->pps_3d_extension_flag         = get_bits1(gb);
> +        pps->pps_scc_extension_flag        = get_bits1(gb);
> +        skip_bits(gb, 4); // pps_extension_4bits
> +
>          if (pps->pps_range_extensions_flag) {
>              if ((ret = pps_range_extensions(gb, avctx, pps, sps)) < 0)
>                  goto err;
>          }
> +
> +        if (pps->pps_multilayer_extension_flag) {
> +            if ((ret = pps_multilayer_extension(gb, avctx, pps, sps)) < 0)
> +                goto err;
> +        }
> +
> +        if (pps->pps_3d_extension_flag) {
> +            if ((ret = pps_3d_extension(gb, avctx, pps, sps)) < 0)
> +                goto err;
> +        }
> +
> +        if (pps->pps_scc_extension_flag) {
> +            if ((ret = pps_scc_extension(gb, avctx, pps, sps)) < 0)
> +                goto err;
> +        }
>      }
>  
>      ret = setup_pps(avctx, gb, pps, sps);
> @@ -1671,9 +1938,8 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb,
> AVCodecContext *avctx,
>          goto err;
>  
>      if (get_bits_left(gb) < 0) {
> -        av_log(avctx, AV_LOG_ERROR,
> +        av_log(avctx, AV_LOG_WARNING,
>                 "Overread PPS by %d bits\n", -get_bits_left(gb));
> -        goto err;
>      }
>  
>      remove_pps(ps, pps_id);
> diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
> index 18894cfed1..1f704108e3 100644
> --- a/libavcodec/hevc_ps.h
> +++ b/libavcodec/hevc_ps.h
> @@ -210,6 +210,20 @@ typedef struct HEVCSPS {
>      int persistent_rice_adaptation_enabled_flag;
>      int cabac_bypass_alignment_enabled_flag;
>  
> +    int sps_multilayer_extension_flag;
> +    int sps_3d_extension_flag;
> +
> +    int sps_scc_extension_flag;
> +    int sps_curr_pic_ref_enabled_flag;
> +    int palette_mode_enabled_flag;
> +    int palette_max_size;
> +    int delta_palette_max_predictor_size;
> +    int sps_palette_predictor_initializers_present_flag;
> +    int sps_num_palette_predictor_initializers_minus1;
> +    int
> sps_palette_predictor_initializer[3][HEVC_MAX_PALETTE_PREDICTOR_SIZE];
> +    int motion_vector_resolution_control_idc;
> +    int intra_boundary_filtering_disabled_flag;
> +
>      ///< coded frame dimension in various units
>      int width;
>      int height;
> @@ -284,6 +298,9 @@ typedef struct HEVCPPS {
>      uint8_t slice_header_extension_present_flag;
>      uint8_t log2_max_transform_skip_block_size;
>      uint8_t pps_range_extensions_flag;
> +    uint8_t pps_multilayer_extension_flag;
> +    uint8_t pps_3d_extension_flag;
> +    uint8_t pps_scc_extension_flag;
>      uint8_t cross_component_prediction_enabled_flag;
>      uint8_t chroma_qp_offset_list_enabled_flag;
>      uint8_t diff_cu_chroma_qp_offset_depth;
> @@ -293,6 +310,58 @@ typedef struct HEVCPPS {
>      uint8_t log2_sao_offset_scale_luma;
>      uint8_t log2_sao_offset_scale_chroma;
>  
> +    // Multilayer extension parameters
> +    uint8_t poc_reset_info_present_flag;
> +    uint8_t pps_infer_scaling_list_flag;
> +    uint8_t pps_scaling_list_ref_layer_id;
> +    uint16_t num_ref_loc_offsets;
> +    uint8_t ref_loc_offset_layer_id[64];
> +    uint8_t scaled_ref_layer_offset_present_flag[64];
> +    int8_t scaled_ref_layer_left_offset[64];
> +    int8_t scaled_ref_layer_top_offset[64];
> +    int8_t scaled_ref_layer_right_offset[64];
> +    int8_t scaled_ref_layer_bottom_offset[64];
> +    uint8_t ref_region_offset_present_flag[64];
> +    int8_t ref_region_left_offset[64];
> +    int8_t ref_region_top_offset[64];
> +    int8_t ref_region_right_offset[64];
> +    int8_t ref_region_bottom_offset[64];
> +    uint8_t resample_phase_set_present_flag[64];
> +    uint16_t phase_hor_luma[64];
> +    uint16_t phase_ver_luma[64];
> +    uint16_t phase_hor_chroma_plus8[64];
> +    uint16_t phase_ver_chroma_plus8[64];
> +    uint8_t colour_mapping_enabled_flag;
> +    uint16_t num_cm_ref_layers_minus1;
> +    uint8_t cm_ref_layer_id[63];
> +    uint8_t cm_octant_depth;
> +    uint8_t cm_y_part_num_log2;
> +    uint16_t luma_bit_depth_cm_input_minus8;
> +    uint16_t chroma_bit_depth_cm_input_minus8;
> +    uint16_t luma_bit_depth_cm_output_minus8;
> +    uint16_t chroma_bit_depth_cm_output_minus8;
> +    uint8_t cm_res_quant_bits;
> +    uint8_t cm_delta_flc_bits_minus1;
> +    int8_t cm_adapt_threshold_u_delta;
> +    int8_t cm_adapt_threshold_v_delta;
> +
> +    // 3D extension parameters
> +    uint8_t pps_bit_depth_for_depth_layers_minus8;
> +
> +    // SCC extension parameters
> +    uint8_t pps_curr_pic_ref_enabled_flag;
> +    uint8_t residual_adaptive_colour_transform_enabled_flag;
> +    uint8_t pps_slice_act_qp_offsets_present_flag;
> +    int8_t  pps_act_y_qp_offset;  // _plus5
> +    int8_t  pps_act_cb_qp_offset; // _plus5
> +    int8_t  pps_act_cr_qp_offset; // _plus3
> +    uint8_t pps_palette_predictor_initializers_present_flag;
> +    uint8_t pps_num_palette_predictor_initializers;
> +    uint8_t monochrome_palette_flag;
> +    uint8_t luma_bit_depth_entry_minus8;
> +    uint8_t chroma_bit_depth_entry_minus8;
> +    uint8_t
> pps_palette_predictor_initializer[3][HEVC_MAX_PALETTE_PREDICTOR_SIZE];
> +
>      // Inferred parameters
>      unsigned int *column_width;  ///< ColumnWidth
>      unsigned int *row_height;    ///< RowHeight
diff mbox series

Patch

diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
index 1804755327..6b454a75c1 100644
--- a/libavcodec/hevc.h
+++ b/libavcodec/hevc.h
@@ -154,6 +154,9 @@  enum {
     // get near that, though, so set a lower limit here with the maximum
     // possible value for 4K video (at most 135 16x16 Ctb rows).
     HEVC_MAX_ENTRY_POINT_OFFSETS = HEVC_MAX_TILE_COLUMNS * 135,
+
+    // A.3.7: Screen content coding extensions
+    HEVC_MAX_PALETTE_PREDICTOR_SIZE = 128,
 };
 
 
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index ad92b6bcbc..3181962918 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -853,7 +853,7 @@  int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
     HEVCWindow *ow;
     int ret = 0;
     int log2_diff_max_min_transform_block_size;
-    int bit_depth_chroma, start, vui_present, sublayer_ordering_info;
+    int bit_depth_chroma, start, vui_present, sublayer_ordering_info, num_comps;
     int i;
 
     // Coded parameters
@@ -1074,8 +1074,12 @@  int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
         decode_vui(gb, avctx, apply_defdispwin, sps);
 
     if (get_bits1(gb)) { // sps_extension_flag
-        sps->sps_range_extension_flag = get_bits1(gb);
-        skip_bits(gb, 7); //sps_extension_7bits = get_bits(gb, 7);
+        sps->sps_range_extension_flag      = get_bits1(gb);
+        sps->sps_multilayer_extension_flag = get_bits1(gb);
+        sps->sps_3d_extension_flag         = get_bits1(gb);
+        sps->sps_scc_extension_flag        = get_bits1(gb);
+        skip_bits(gb, 4); // sps_extension_4bits
+
         if (sps->sps_range_extension_flag) {
             sps->transform_skip_rotation_enabled_flag = get_bits1(gb);
             sps->transform_skip_context_enabled_flag  = get_bits1(gb);
@@ -1101,6 +1105,57 @@  int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
                 av_log(avctx, AV_LOG_WARNING,
                    "cabac_bypass_alignment_enabled_flag not yet implemented\n");
         }
+
+        if (sps->sps_multilayer_extension_flag) {
+            skip_bits1(gb); // inter_view_mv_vert_constraint_flag
+            av_log(avctx, AV_LOG_WARNING,
+                   "sps_multilayer_extension_flag not yet implemented\n");
+        }
+
+        if (sps->sps_3d_extension_flag) {
+            for (i = 0; i <= 1; i++) {
+                skip_bits1(gb); // iv_di_mc_enabled_flag
+                skip_bits1(gb); // iv_mv_scal_enabled_flag
+                if (i == 0) {
+                    get_ue_golomb_long(gb); // log2_ivmc_sub_pb_size_minus3
+                    skip_bits1(gb); // iv_res_pred_enabled_flag
+                    skip_bits1(gb); // depth_ref_enabled_flag
+                    skip_bits1(gb); // vsp_mc_enabled_flag
+                    skip_bits1(gb); // dbbp_enabled_flag
+                } else {
+                    skip_bits1(gb); // tex_mc_enabled_flag
+                    get_ue_golomb_long(gb); // log2_ivmc_sub_pb_size_minus3
+                    skip_bits1(gb); // intra_contour_enabled_flag
+                    skip_bits1(gb); // intra_dc_only_wedge_enabled_flag
+                    skip_bits1(gb); // cqt_cu_part_pred_enabled_flag
+                    skip_bits1(gb); // inter_dc_only_enabled_flag
+                    skip_bits1(gb); // skip_intra_enabled_flag
+                }
+            }
+            av_log(avctx, AV_LOG_WARNING,
+                   "sps_3d_extension_flag not yet implemented\n");
+        }
+
+        if (sps->sps_scc_extension_flag) {
+            sps->sps_curr_pic_ref_enabled_flag = get_bits1(gb);
+            sps->palette_mode_enabled_flag     = get_bits1(gb);
+            if (sps->palette_mode_enabled_flag) {
+                sps->palette_max_size = get_ue_golomb_long(gb);
+                sps->delta_palette_max_predictor_size = get_ue_golomb_long(gb);
+                sps->sps_palette_predictor_initializers_present_flag = get_bits1(gb);
+
+                if (sps->sps_palette_predictor_initializers_present_flag) {
+                    sps->sps_num_palette_predictor_initializers_minus1 = get_ue_golomb_long(gb);
+                    num_comps = !sps->chroma_format_idc ? 1 : 3;
+                    for (int comp = 0; comp < num_comps; comp++)
+                        for (i = 0; i <= sps->sps_num_palette_predictor_initializers_minus1; i++)
+                            sps->sps_palette_predictor_initializer[comp][i] =
+                                    get_bits(gb, !comp ? sps->bit_depth : sps->bit_depth_chroma);
+                }
+            }
+            sps->motion_vector_resolution_control_idc   = get_bits(gb, 2);
+            sps->intra_boundary_filtering_disabled_flag = get_bits1(gb);
+        }
     }
     if (apply_defdispwin) {
         sps->output_window.left_offset   += sps->vui.def_disp_win.left_offset;
@@ -1265,10 +1320,162 @@  static void hevc_pps_free(void *opaque, uint8_t *data)
     av_freep(&pps);
 }
 
-static int pps_range_extensions(GetBitContext *gb, AVCodecContext *avctx,
-                                HEVCPPS *pps, HEVCSPS *sps) {
-    int i;
+static void colour_mapping_octants(GetBitContext *gb, HEVCPPS *pps, int inp_depth,
+                                   int idx_y, int idx_cb, int idx_cr, int inp_length)
+{
+    unsigned int split_octant_flag, part_num_y, coded_res_flag, res_coeff_q, res_coeff_r;
+    int bit_depth_cm_input_y, bit_depth_cm_output_y, cm_res_bits;
+
+    part_num_y = 1 << pps->cm_y_part_num_log2;
+
+    split_octant_flag = inp_depth < pps->cm_octant_depth ? get_bits1(gb) : 0;
+
+    if (split_octant_flag)
+        for (int k = 0; k < 2; k++)
+            for (int m = 0; m < 2; m++)
+                for (int n = 0; n < 2; n++)
+                    colour_mapping_octants(gb, pps, inp_depth + 1,
+                                           idx_y + part_num_y * k * inp_length / 2,
+                                           idx_cb + m * inp_length / 2,
+                                           idx_cr + n * inp_length / 2,
+                                           inp_length / 2);
+    else
+        for (int i = 0; i < part_num_y; i++) {
+            for (int j = 0; j < 4; j++) {
+                coded_res_flag = get_bits1(gb);
+                if (coded_res_flag)
+                    for (int c = 0; c < 3; c++) {
+                        res_coeff_q = get_ue_golomb_long(gb);
+                        bit_depth_cm_input_y = 8 + pps->luma_bit_depth_cm_input_minus8;
+                        bit_depth_cm_output_y = 8 + pps->luma_bit_depth_cm_output_minus8;
+                        cm_res_bits = FFMAX(0, 10 + bit_depth_cm_input_y - bit_depth_cm_output_y -
+                                            pps->cm_res_quant_bits - (pps->cm_delta_flc_bits_minus1 + 1));
+                        res_coeff_r = cm_res_bits ? get_bits(gb, cm_res_bits) : 0;
+                        if (res_coeff_q || res_coeff_r)
+                            skip_bits1(gb);
+                    }
+            }
+        }
+}
 
+static void colour_mapping_table(GetBitContext *gb, HEVCPPS *pps)
+{
+    pps->num_cm_ref_layers_minus1 = get_ue_golomb_long(gb);
+    for (int i = 0; i <= pps->num_cm_ref_layers_minus1; i++)
+        pps->cm_ref_layer_id[i] = get_bits(gb, 6);
+
+    pps->cm_octant_depth = get_bits(gb, 2);
+    pps->cm_y_part_num_log2 = get_bits(gb, 2);
+
+    pps->luma_bit_depth_cm_input_minus8    = get_ue_golomb_long(gb);
+    pps->chroma_bit_depth_cm_input_minus8  = get_ue_golomb_long(gb);
+    pps->luma_bit_depth_cm_output_minus8   = get_ue_golomb_long(gb);
+    pps->chroma_bit_depth_cm_output_minus8 = get_ue_golomb_long(gb);
+
+    pps->cm_res_quant_bits = get_bits(gb, 2);
+    pps->cm_delta_flc_bits_minus1 = get_bits(gb, 2);
+
+    if (pps->cm_octant_depth == 1) {
+        pps->cm_adapt_threshold_u_delta = get_se_golomb_long(gb);
+        pps->cm_adapt_threshold_v_delta = get_se_golomb_long(gb);
+    }
+
+    colour_mapping_octants(gb, pps, 0, 0, 0, 0, 1 << pps->cm_octant_depth);
+}
+
+static int pps_multilayer_extension(GetBitContext *gb, AVCodecContext *avctx,
+                                    HEVCPPS *pps, HEVCSPS *sps)
+{
+    pps->poc_reset_info_present_flag = get_bits1(gb);
+    pps->pps_infer_scaling_list_flag = get_bits1(gb);
+    if (pps->pps_infer_scaling_list_flag)
+        pps->pps_scaling_list_ref_layer_id = get_bits(gb, 6);
+
+    pps->num_ref_loc_offsets = get_ue_golomb_long(gb);
+    for (int i = 0; i < pps->num_ref_loc_offsets; i++) {
+        pps->ref_loc_offset_layer_id[i] = get_bits(gb, 6);
+        pps->scaled_ref_layer_offset_present_flag[i] = get_bits1(gb);
+        if (pps->scaled_ref_layer_offset_present_flag[i]) {
+            pps->scaled_ref_layer_left_offset[pps->ref_loc_offset_layer_id[i]]   = get_se_golomb_long(gb);
+            pps->scaled_ref_layer_top_offset[pps->ref_loc_offset_layer_id[i]]    = get_se_golomb_long(gb);
+            pps->scaled_ref_layer_right_offset[pps->ref_loc_offset_layer_id[i]]  = get_se_golomb_long(gb);
+            pps->scaled_ref_layer_bottom_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb);
+        }
+
+        pps->ref_region_offset_present_flag[i] = get_bits1(gb);
+        if (pps->ref_region_offset_present_flag[i]) {
+            pps->ref_region_left_offset[pps->ref_loc_offset_layer_id[i]]   = get_se_golomb_long(gb);
+            pps->ref_region_top_offset[pps->ref_loc_offset_layer_id[i]]    = get_se_golomb_long(gb);
+            pps->ref_region_right_offset[pps->ref_loc_offset_layer_id[i]]  = get_se_golomb_long(gb);
+            pps->ref_region_bottom_offset[pps->ref_loc_offset_layer_id[i]] = get_se_golomb_long(gb);
+        }
+
+        pps->resample_phase_set_present_flag[i] = get_bits1(gb);
+        if (pps->resample_phase_set_present_flag[i]) {
+            pps->phase_hor_luma[pps->ref_loc_offset_layer_id[i]]         = get_ue_golomb_long(gb);
+            pps->phase_ver_luma[pps->ref_loc_offset_layer_id[i]]         = get_ue_golomb_long(gb);
+            pps->phase_hor_chroma_plus8[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb_long(gb);
+            pps->phase_ver_chroma_plus8[pps->ref_loc_offset_layer_id[i]] = get_ue_golomb_long(gb);
+        }
+    }
+
+    pps->colour_mapping_enabled_flag = get_bits1(gb);
+    if (pps->colour_mapping_enabled_flag)
+        colour_mapping_table(gb, pps);
+
+    return 0;
+}
+
+static void delta_dlt(GetBitContext *gb, HEVCPPS *pps)
+{
+    unsigned int num_val_delta_dlt, max_diff = 0;
+    int min_diff_minus1 = -1;
+    unsigned int len;
+
+    num_val_delta_dlt = get_bits(gb, pps->pps_bit_depth_for_depth_layers_minus8 + 8);
+    if (num_val_delta_dlt) {
+        if (num_val_delta_dlt > 1)
+            max_diff = get_bits(gb, pps->pps_bit_depth_for_depth_layers_minus8 + 8);
+        if (num_val_delta_dlt > 2 && max_diff) {
+            len = av_log2(max_diff) + 1;
+            min_diff_minus1 = get_bits(gb, len);
+        }
+        if (max_diff > (min_diff_minus1 + 1))
+            for (int k = 1; k < num_val_delta_dlt; k++) {
+                len = av_log2(max_diff - (min_diff_minus1 + 1)) + 1;
+                skip_bits(gb, len); // delta_val_diff_minus_min
+            }
+    }
+}
+
+static int pps_3d_extension(GetBitContext *gb, AVCodecContext *avctx,
+                            HEVCPPS *pps, HEVCSPS *sps)
+{
+    unsigned int pps_depth_layers_minus1;
+    int i, j;
+
+    if (get_bits1(gb)) { // dlts_present_flag
+        pps_depth_layers_minus1 = get_bits(gb, 6);
+        pps->pps_bit_depth_for_depth_layers_minus8 = get_bits(gb, 4);
+        for (i = 0; i <= pps_depth_layers_minus1; i++) {
+            if (get_bits1(gb)) { // dlt_flag[i]
+                if (!get_bits1(gb)) { // dlt_pred_flag[i]
+                    if (get_bits1(gb)) { // dlt_val_flags_present_flag[i]
+                        for (j = 0; j <= ((1 << (pps->pps_bit_depth_for_depth_layers_minus8 + 8)) - 1); j++)
+                            skip_bits1(gb); // dlt_value_flag[i][j]
+                    } else
+                        delta_dlt(gb, pps);
+                }
+            }
+        }
+    }
+
+    return 0;
+}
+
+static int pps_range_extensions(GetBitContext *gb, AVCodecContext *avctx,
+                                HEVCPPS *pps, HEVCSPS *sps)
+{
     if (pps->transform_skip_enabled_flag) {
         pps->log2_max_transform_skip_block_size = get_ue_golomb_long(gb) + 2;
     }
@@ -1282,7 +1489,7 @@  static int pps_range_extensions(GetBitContext *gb, AVCodecContext *avctx,
                    "chroma_qp_offset_list_len_minus1 shall be in the range [0, 5].\n");
             return AVERROR_INVALIDDATA;
         }
-        for (i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) {
+        for (int i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) {
             pps->cb_qp_offset_list[i] = get_se_golomb_long(gb);
             if (pps->cb_qp_offset_list[i]) {
                 av_log(avctx, AV_LOG_WARNING,
@@ -1306,6 +1513,47 @@  static int pps_range_extensions(GetBitContext *gb, AVCodecContext *avctx,
     return(0);
 }
 
+static int pps_scc_extension(GetBitContext *gb, AVCodecContext *avctx,
+                             HEVCPPS *pps, HEVCSPS *sps)
+{
+    int num_comps, ret;
+
+    pps->pps_curr_pic_ref_enabled_flag = get_bits1(gb);
+    if (pps->residual_adaptive_colour_transform_enabled_flag = get_bits1(gb)) {
+        pps->pps_slice_act_qp_offsets_present_flag = get_bits1(gb);
+        pps->pps_act_y_qp_offset  = get_se_golomb_long(gb) - 5;
+        pps->pps_act_cb_qp_offset = get_se_golomb_long(gb) - 5;
+        pps->pps_act_cr_qp_offset = get_se_golomb_long(gb) - 3;
+
+#define CHECK_QP_OFFSET(name) (pps->pps_act_ ## name ## _qp_offset <= -12 || \
+                               pps->pps_act_ ## name ## _qp_offset >= 12)
+        ret = CHECK_QP_OFFSET(y) || CHECK_QP_OFFSET(cb) || CHECK_QP_OFFSET(cr);
+#undef CHECK_QP_OFFSET
+        if (ret) {
+            av_log(avctx, AV_LOG_ERROR,
+                   "PpsActQpOffsetY/Cb/Cr shall be in the range of [-12, 12].\n");
+            return AVERROR_INVALIDDATA;
+        }
+    }
+
+    if (pps->pps_palette_predictor_initializers_present_flag = get_bits1(gb)) {
+        if ((pps->pps_num_palette_predictor_initializers = get_ue_golomb_long(gb)) > 0) {
+            pps->monochrome_palette_flag = get_bits1(gb);
+            pps->luma_bit_depth_entry_minus8 = get_ue_golomb_long(gb);
+            if (!pps->monochrome_palette_flag)
+                pps->chroma_bit_depth_entry_minus8 = get_ue_golomb_long(gb);
+            num_comps = pps->monochrome_palette_flag ? 1 : 3;
+            for (int comp = 0; comp < num_comps; comp++)
+                for (int i = 0; i < pps->pps_num_palette_predictor_initializers; i++)
+                    pps->pps_palette_predictor_initializer[comp][i] =
+                        get_bits(gb, 8 + (!comp ? pps->luma_bit_depth_entry_minus8 :
+                                          pps->chroma_bit_depth_entry_minus8));
+        }
+    }
+
+    return 0;
+}
+
 static inline int setup_pps(AVCodecContext *avctx, GetBitContext *gb,
                             HEVCPPS *pps, HEVCSPS *sps)
 {
@@ -1658,12 +1906,31 @@  int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx,
     pps->slice_header_extension_present_flag = get_bits1(gb);
 
     if (get_bits1(gb)) { // pps_extension_present_flag
-        pps->pps_range_extensions_flag = get_bits1(gb);
-        skip_bits(gb, 7); // pps_extension_7bits
+        pps->pps_range_extensions_flag     = get_bits1(gb);
+        pps->pps_multilayer_extension_flag = get_bits1(gb);
+        pps->pps_3d_extension_flag         = get_bits1(gb);
+        pps->pps_scc_extension_flag        = get_bits1(gb);
+        skip_bits(gb, 4); // pps_extension_4bits
+
         if (pps->pps_range_extensions_flag) {
             if ((ret = pps_range_extensions(gb, avctx, pps, sps)) < 0)
                 goto err;
         }
+
+        if (pps->pps_multilayer_extension_flag) {
+            if ((ret = pps_multilayer_extension(gb, avctx, pps, sps)) < 0)
+                goto err;
+        }
+
+        if (pps->pps_3d_extension_flag) {
+            if ((ret = pps_3d_extension(gb, avctx, pps, sps)) < 0)
+                goto err;
+        }
+
+        if (pps->pps_scc_extension_flag) {
+            if ((ret = pps_scc_extension(gb, avctx, pps, sps)) < 0)
+                goto err;
+        }
     }
 
     ret = setup_pps(avctx, gb, pps, sps);
@@ -1671,9 +1938,8 @@  int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx,
         goto err;
 
     if (get_bits_left(gb) < 0) {
-        av_log(avctx, AV_LOG_ERROR,
+        av_log(avctx, AV_LOG_WARNING,
                "Overread PPS by %d bits\n", -get_bits_left(gb));
-        goto err;
     }
 
     remove_pps(ps, pps_id);
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index 18894cfed1..1f704108e3 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -210,6 +210,20 @@  typedef struct HEVCSPS {
     int persistent_rice_adaptation_enabled_flag;
     int cabac_bypass_alignment_enabled_flag;
 
+    int sps_multilayer_extension_flag;
+    int sps_3d_extension_flag;
+
+    int sps_scc_extension_flag;
+    int sps_curr_pic_ref_enabled_flag;
+    int palette_mode_enabled_flag;
+    int palette_max_size;
+    int delta_palette_max_predictor_size;
+    int sps_palette_predictor_initializers_present_flag;
+    int sps_num_palette_predictor_initializers_minus1;
+    int sps_palette_predictor_initializer[3][HEVC_MAX_PALETTE_PREDICTOR_SIZE];
+    int motion_vector_resolution_control_idc;
+    int intra_boundary_filtering_disabled_flag;
+
     ///< coded frame dimension in various units
     int width;
     int height;
@@ -284,6 +298,9 @@  typedef struct HEVCPPS {
     uint8_t slice_header_extension_present_flag;
     uint8_t log2_max_transform_skip_block_size;
     uint8_t pps_range_extensions_flag;
+    uint8_t pps_multilayer_extension_flag;
+    uint8_t pps_3d_extension_flag;
+    uint8_t pps_scc_extension_flag;
     uint8_t cross_component_prediction_enabled_flag;
     uint8_t chroma_qp_offset_list_enabled_flag;
     uint8_t diff_cu_chroma_qp_offset_depth;
@@ -293,6 +310,58 @@  typedef struct HEVCPPS {
     uint8_t log2_sao_offset_scale_luma;
     uint8_t log2_sao_offset_scale_chroma;
 
+    // Multilayer extension parameters
+    uint8_t poc_reset_info_present_flag;
+    uint8_t pps_infer_scaling_list_flag;
+    uint8_t pps_scaling_list_ref_layer_id;
+    uint16_t num_ref_loc_offsets;
+    uint8_t ref_loc_offset_layer_id[64];
+    uint8_t scaled_ref_layer_offset_present_flag[64];
+    int8_t scaled_ref_layer_left_offset[64];
+    int8_t scaled_ref_layer_top_offset[64];
+    int8_t scaled_ref_layer_right_offset[64];
+    int8_t scaled_ref_layer_bottom_offset[64];
+    uint8_t ref_region_offset_present_flag[64];
+    int8_t ref_region_left_offset[64];
+    int8_t ref_region_top_offset[64];
+    int8_t ref_region_right_offset[64];
+    int8_t ref_region_bottom_offset[64];
+    uint8_t resample_phase_set_present_flag[64];
+    uint16_t phase_hor_luma[64];
+    uint16_t phase_ver_luma[64];
+    uint16_t phase_hor_chroma_plus8[64];
+    uint16_t phase_ver_chroma_plus8[64];
+    uint8_t colour_mapping_enabled_flag;
+    uint16_t num_cm_ref_layers_minus1;
+    uint8_t cm_ref_layer_id[63];
+    uint8_t cm_octant_depth;
+    uint8_t cm_y_part_num_log2;
+    uint16_t luma_bit_depth_cm_input_minus8;
+    uint16_t chroma_bit_depth_cm_input_minus8;
+    uint16_t luma_bit_depth_cm_output_minus8;
+    uint16_t chroma_bit_depth_cm_output_minus8;
+    uint8_t cm_res_quant_bits;
+    uint8_t cm_delta_flc_bits_minus1;
+    int8_t cm_adapt_threshold_u_delta;
+    int8_t cm_adapt_threshold_v_delta;
+
+    // 3D extension parameters
+    uint8_t pps_bit_depth_for_depth_layers_minus8;
+
+    // SCC extension parameters
+    uint8_t pps_curr_pic_ref_enabled_flag;
+    uint8_t residual_adaptive_colour_transform_enabled_flag;
+    uint8_t pps_slice_act_qp_offsets_present_flag;
+    int8_t  pps_act_y_qp_offset;  // _plus5
+    int8_t  pps_act_cb_qp_offset; // _plus5
+    int8_t  pps_act_cr_qp_offset; // _plus3
+    uint8_t pps_palette_predictor_initializers_present_flag;
+    uint8_t pps_num_palette_predictor_initializers;
+    uint8_t monochrome_palette_flag;
+    uint8_t luma_bit_depth_entry_minus8;
+    uint8_t chroma_bit_depth_entry_minus8;
+    uint8_t pps_palette_predictor_initializer[3][HEVC_MAX_PALETTE_PREDICTOR_SIZE];
+
     // Inferred parameters
     unsigned int *column_width;  ///< ColumnWidth
     unsigned int *row_height;    ///< RowHeight