From 3a0a82a783b2a8af4c0962bcf3b238ca927e4714 Mon Sep 17 00:00:00 2001 From: Wangfei Date: Fri, 26 Apr 2019 09:52:43 +0800 Subject: [PATCH] h265parser: parse range extension message in SPS/PPS. Range extension message may exist in some extension-profile clips. --- gst-libs/gst/codecparsers/gsth265parser.c | 69 ++++++++++++++++- gst-libs/gst/codecparsers/gsth265parser.h | 93 +++++++++++++++++++++++ 2 files changed, 161 insertions(+), 1 deletion(-) diff --git a/gst-libs/gst/codecparsers/gsth265parser.c b/gst-libs/gst/codecparsers/gsth265parser.c index 16fce006b9..972691896f 100644 --- a/gst-libs/gst/codecparsers/gsth265parser.c +++ b/gst-libs/gst/codecparsers/gsth265parser.c @@ -1775,6 +1775,31 @@ gst_h265_parse_sps (GstH265Parser * parser, GstH265NalUnit * nalu, READ_UINT8 (&nr, sps->sps_extension_flag, 1); + if (sps->sps_extension_flag) { + READ_UINT8 (&nr, sps->sps_range_extension_flag, 1); + READ_UINT8 (&nr, sps->sps_multilayer_extension_flag, 1); + READ_UINT8 (&nr, sps->sps_3d_extension_flag, 1); + READ_UINT8 (&nr, sps->sps_extension_5bits, 5); + } + + if (sps->sps_range_extension_flag) { + READ_UINT8 (&nr, + sps->sps_extnsion_params.transform_skip_rotation_enabled_flag, 1); + READ_UINT8 (&nr, + sps->sps_extnsion_params.transform_skip_context_enabled_flag, 1); + READ_UINT8 (&nr, sps->sps_extnsion_params.implicit_rdpcm_enabled_flag, 1); + READ_UINT8 (&nr, sps->sps_extnsion_params.explicit_rdpcm_enabled_flag, 1); + READ_UINT8 (&nr, + sps->sps_extnsion_params.extended_precision_processing_flag, 1); + READ_UINT8 (&nr, sps->sps_extnsion_params.intra_smoothing_disabled_flag, 1); + READ_UINT8 (&nr, + sps->sps_extnsion_params.high_precision_offsets_enabled_flag, 1); + READ_UINT8 (&nr, + sps->sps_extnsion_params.persistent_rice_adaptation_enabled_flag, 1); + READ_UINT8 (&nr, + sps->sps_extnsion_params.cabac_bypass_alignment_enabled_flag, 1); + } + /* calculate ChromaArrayType */ if (!sps->separate_colour_plane_flag) sps->chroma_array_type = sps->chroma_format_idc; @@ -1847,7 +1872,7 @@ gst_h265_parse_pps (GstH265Parser * parser, GstH265NalUnit * nalu, GstH265SPS *sps; gint sps_id; gint qp_bd_offset; - guint32 CtbSizeY, MinCbLog2SizeY, CtbLog2SizeY; + guint32 CtbSizeY, MinCbLog2SizeY, CtbLog2SizeY, MaxBitDepthY, MaxBitDepthC; guint8 i; INITIALIZE_DEBUG_CATEGORY; @@ -1977,6 +2002,45 @@ gst_h265_parse_pps (GstH265Parser * parser, GstH265NalUnit * nalu, READ_UINT8 (&nr, pps->slice_segment_header_extension_present_flag, 1); READ_UINT8 (&nr, pps->pps_extension_flag, 1); + if (pps->pps_extension_flag) { + READ_UINT8 (&nr, pps->pps_range_extension_flag, 1); + READ_UINT8 (&nr, pps->pps_multilayer_extension_flag, 1); + READ_UINT8 (&nr, pps->pps_3d_extension_flag, 1); + READ_UINT8 (&nr, pps->pps_extension_5bits, 5); + } + + if (pps->pps_range_extension_flag) { + READ_UE (&nr, + pps->pps_extension_params.log2_max_transform_skip_block_size_minus2); + READ_UINT8 (&nr, + pps->pps_extension_params.cross_component_prediction_enabled_flag, 1); + READ_UINT8 (&nr, + pps->pps_extension_params.chroma_qp_offset_list_enabled_flag, 1); + if (pps->pps_extension_params.chroma_qp_offset_list_enabled_flag) { + READ_UE_MAX (&nr, + pps->pps_extension_params.diff_cu_chroma_qp_offset_depth, + sps->log2_diff_max_min_luma_coding_block_size); + READ_UE_MAX (&nr, + pps->pps_extension_params.chroma_qp_offset_list_len_minus1, 5); + for (i = 0; + i <= pps->pps_extension_params.chroma_qp_offset_list_len_minus1; + i++) { + READ_SE_ALLOWED (&nr, pps->pps_extension_params.cb_qp_offset_list[i], + -12, 12); + READ_SE_ALLOWED (&nr, pps->pps_extension_params.cr_qp_offset_list[i], + -12, 12); + } + } + MaxBitDepthY = + sps->bit_depth_luma_minus8 > 2 ? sps->bit_depth_luma_minus8 - 2 : 0; + MaxBitDepthC = + sps->bit_depth_chroma_minus8 > 2 ? sps->bit_depth_chroma_minus8 - 2 : 0; + READ_UE_ALLOWED (&nr, pps->pps_extension_params.log2_sao_offset_scale_luma, + 0, MaxBitDepthY); + READ_UE_ALLOWED (&nr, + pps->pps_extension_params.log2_sao_offset_scale_chroma, 0, + MaxBitDepthC); + } pps->valid = TRUE; return GST_H265_PARSER_OK; @@ -2241,6 +2305,9 @@ gst_h265_parser_parse_slice_hdr (GstH265Parser * parser, READ_SE_ALLOWED (&nr, slice->cr_qp_offset, -12, 12); } + if (pps->pps_extension_params.chroma_qp_offset_list_enabled_flag) + READ_UINT8 (&nr, slice->cu_chroma_qp_offset_enabled_flag, 1); + if (pps->deblocking_filter_override_enabled_flag) READ_UINT8 (&nr, slice->deblocking_filter_override_flag, 1); if (slice->deblocking_filter_override_flag) { diff --git a/gst-libs/gst/codecparsers/gsth265parser.h b/gst-libs/gst/codecparsers/gsth265parser.h index 488405b39c..bd9a19c90c 100644 --- a/gst-libs/gst/codecparsers/gsth265parser.h +++ b/gst-libs/gst/codecparsers/gsth265parser.h @@ -308,6 +308,8 @@ typedef struct _GstH265ProfileTierLevel GstH265ProfileTierLevel; typedef struct _GstH265SubLayerHRDParams GstH265SubLayerHRDParams; typedef struct _GstH265HRDParams GstH265HRDParams; typedef struct _GstH265VUIParams GstH265VUIParams; +typedef struct _GstH265SPSExtensionParams GstH265SPSExtensionParams; +typedef struct _GstH265PPSExtensionParams GstH265PPSExtensionParams; typedef struct _GstH265ScalingList GstH265ScalingList; typedef struct _GstH265RefPicListModification GstH265RefPicListModification; @@ -755,6 +757,77 @@ struct _GstH265VUIParams guint par_d; }; +/** + * GstH265SPSExtensionParams: + * @transform_skip_rotation_enabled_flag: %TRUE specifies that a rotation is applied to + * the residual data block from intra 4X4 blocks coded using a transform skip operation. + * @transform_skip_context_enabled_flag: %TRUE specifies tspecifies that a particular + * context is used for the parsing of the sig_coeff_flag for transform blocks with a skipped + * transform. + * @implicit_residual_dpcm_enabled_flag: %TRUE specifies that the residual modification process + * for blocks using a transform bypass may be used for intra blocks in the CVS + * @explicit_residual_dpcm_enabled_flag: %TRUE specifies that the residual modification process + * for blocks using a transform bypass may be used for inter blocks in the CVS + * @extended_precision_processing_flag: %TRUE specifies that an extended dynamic range is used + * for coefficient parsing and inverse transform processing + * @intra_smoothing_disabled_flag: %TRUE specifies that the filtering process of neighbouring + * samples is unconditionally disabled for intra prediction + * @high_precision_offsets_enabled_flag: %TRUE specifies that weighted prediction offset values + * are signalled using a bit-depth-dependent precision. + * @persistent_rice_adaptation_enabled_flag: %TRUE specifies that the Rice parameter derivation + * for the binarization of coeff_abs_level_remaining[] is initialized at the start of each + * sub-block using mode dependent statistics accumulated from previous sub-blocks. + * @cabac_bypass_alignment_enabled_flag: %TRUE specifies that a context-based adaptive binary + * arithmetic coding (CABAC) alignment process is used prior to bypass decoding of the syntax + * elements coeff_sign_flag[] and coeff_abs_level_remaining[] + * + * Defines the GstH265SPSExtensionParams + */ +struct _GstH265SPSExtensionParams { + guint8 transform_skip_rotation_enabled_flag; + guint8 transform_skip_context_enabled_flag; + guint8 implicit_rdpcm_enabled_flag; + guint8 explicit_rdpcm_enabled_flag; + guint8 extended_precision_processing_flag; + guint8 intra_smoothing_disabled_flag; + guint8 high_precision_offsets_enabled_flag; + guint8 persistent_rice_adaptation_enabled_flag; + guint8 cabac_bypass_alignment_enabled_flag; +}; + +/** + * GstH265PPSExtensionParams: + * @log2_max_transform_skip_block_size_minus2: plus 2 specifies the maximum transform block size for which + * transform_skip_flag may be present in coded pictures referring to the PPS. + * @cross_component_prediction_enabled_flag: equal to 1 specifies that log2_res_scale_abs_plus1 and + * res_scale_sign_flag may be present in the transform unit syntax for pictures referring to the PPS. + * @chroma_qp_offset_list_enabled_flag: equal to 1 specifies that the cu_chroma_qp_offset_flag may be + * present in the transform unit syntax. + * @diff_cu_chroma_qp_offset_depth: specifies the difference between the luma coding tree block size and + * the minimum luma coding block size of coding units that convey cu_chroma_qp_offset_flag. + * @chroma_qp_offset_list_len_minus1: plus 1 specifies the number of cb_qp_offset_list[] and + * cr_qp_offset_list[] syntax elements that are present in the PPS. + * @cb_qp_offset_list: specify offsets used in the derivation of qp cb. + * @cr_qp_offset_list: specify offsets used in the derivation of qp cr. + * @log2_sao_offset_scale_luma: the base 2 logarithm of the scaling parameter that is used to scale sample + * adaptive offset (SAO) offset values for luma samples. + * @log2_sao_offset_scale_chroma: the base 2 logarithm of the scaling parameter that is used to scale SAO + * offset values for chroma samples. + * + * Defines the GstH265SPSExtensionParams + */ +struct _GstH265PPSExtensionParams { + guint32 log2_max_transform_skip_block_size_minus2; + guint8 cross_component_prediction_enabled_flag; + guint8 chroma_qp_offset_list_enabled_flag; + guint8 diff_cu_chroma_qp_offset_depth; + guint8 chroma_qp_offset_list_len_minus1; + gint8 cb_qp_offset_list[6]; + gint8 cr_qp_offset_list[6]; + guint8 log2_sao_offset_scale_luma; + guint8 log2_sao_offset_scale_chroma; +}; + /** * GstH265ScalingList: * @scaling_list_dc_coef_minus8_16x16: this plus 8 specifies the DC @@ -859,6 +932,15 @@ struct _GstH265SPS guint8 sps_extension_flag; + /* if sps_extension_present_flag */ + guint8 sps_range_extension_flag; + guint8 sps_multilayer_extension_flag; + guint8 sps_3d_extension_flag; + guint8 sps_extension_5bits; + +/* if sps_range_extension_flag */ + GstH265SPSExtensionParams sps_extnsion_params; + /* calculated values */ guint8 chroma_array_type; gint width, height; @@ -926,6 +1008,15 @@ struct _GstH265PPS guint8 pps_extension_flag; + /* if pps_extension_flag*/ + guint8 pps_range_extension_flag; + guint8 pps_multilayer_extension_flag; + guint8 pps_3d_extension_flag; + guint8 pps_extension_5bits; + + /* if pps_range_extension_flag*/ + GstH265PPSExtensionParams pps_extension_params; + /* calculated values */ guint32 PicWidthInCtbsY; guint32 PicHeightInCtbsY; @@ -1010,6 +1101,8 @@ struct _GstH265SliceHdr gint8 cb_qp_offset; gint8 cr_qp_offset; + guint8 cu_chroma_qp_offset_enabled_flag; + guint8 deblocking_filter_override_flag; guint8 deblocking_filter_disabled_flag; gint8 beta_offset_div2;