From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/cbs_h265: add partial support for Multilayer extension fields in parameter set NALUs Date: Sat, 13 Jul 2024 11:58:44 -0300 Message-ID: <20240713145846.1331-2-jamrial@gmail.com> (raw) In-Reply-To: <20240713145846.1331-1-jamrial@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/cbs_h2645.c | 3 +- libavcodec/cbs_h265.h | 44 ++++++++++ libavcodec/cbs_h265_syntax_template.c | 113 +++++++++++++++++++++++++- libavcodec/hevc/ps.h | 4 +- 4 files changed, 159 insertions(+), 5 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 5ec781ddab..828e56b8c0 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -499,7 +499,8 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, size_t size = nal->size; enum AVCodecID codec_id = ctx->codec->codec_id; - if (codec_id != AV_CODEC_ID_VVC && nal->nuh_layer_id > 0) + if (codec_id == AV_CODEC_ID_HEVC && nal->nuh_layer_id > 0 && + (nal->type < HEVC_NAL_VPS || nal->type > HEVC_NAL_PPS)) continue; // Remove trailing zeroes. diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h index 91a5a55317..afb942ced5 100644 --- a/libavcodec/cbs_h265.h +++ b/libavcodec/cbs_h265.h @@ -248,12 +248,16 @@ typedef struct H265RawSPS { uint8_t sps_video_parameter_set_id; uint8_t sps_max_sub_layers_minus1; + uint8_t sps_ext_or_max_sub_layers_minus1; uint8_t sps_temporal_id_nesting_flag; H265RawProfileTierLevel profile_tier_level; uint8_t sps_seq_parameter_set_id; + uint8_t update_rep_format_flag; + uint8_t sps_rep_format_idx; + uint8_t chroma_format_idc; uint8_t separate_colour_plane_flag; @@ -284,6 +288,8 @@ typedef struct H265RawSPS { uint8_t max_transform_hierarchy_depth_intra; uint8_t scaling_list_enabled_flag; + uint8_t sps_infer_scaling_list_flag; + uint8_t sps_scaling_list_ref_layer_id; uint8_t sps_scaling_list_data_present_flag; H265RawScalingList scaling_list; @@ -342,6 +348,9 @@ typedef struct H265RawSPS { uint8_t motion_vector_resolution_control_idc; uint8_t intra_boundary_filtering_disable_flag; + + // Multilayer extension. + uint8_t inter_view_mv_vert_constraint_flag; } H265RawSPS; typedef struct H265RawPPS { @@ -433,6 +442,41 @@ typedef struct H265RawPPS { uint8_t luma_bit_depth_entry_minus8; uint8_t chroma_bit_depth_entry_minus8; uint16_t pps_palette_predictor_initializers[3][128]; + + // Multilayer extension. + uint8_t poc_reset_info_present_flag; + uint8_t pps_infer_scaling_list_flag; + uint8_t pps_scaling_list_ref_layer_id; + uint8_t num_ref_loc_offsets; + uint8_t ref_loc_offset_layer_id[64]; + uint8_t scaled_ref_layer_offset_present_flag[64]; + int16_t scaled_ref_layer_left_offset[64]; + int16_t scaled_ref_layer_top_offset[64]; + int16_t scaled_ref_layer_right_offset[64]; + int16_t scaled_ref_layer_bottom_offset[64]; + uint8_t ref_region_offset_present_flag[64]; + int16_t ref_region_left_offset[64]; + int16_t ref_region_top_offset[64]; + int16_t ref_region_right_offset[64]; + int16_t ref_region_bottom_offset[64]; + uint8_t resample_phase_set_present_flag[64]; + uint8_t phase_hor_luma[64]; + uint8_t phase_ver_luma[64]; + uint8_t phase_hor_chroma_plus8[64]; + uint8_t phase_ver_chroma_plus8[64]; + uint8_t colour_mapping_enabled_flag; + uint8_t num_cm_ref_layers; + uint8_t cm_ref_layer_id[62]; + uint8_t cm_octant_depth; + uint8_t cm_y_part_num_log2; + uint8_t luma_bit_depth_cm_input; + uint8_t chroma_bit_depth_cm_input; + uint8_t luma_bit_depth_cm_output; + uint8_t chroma_bit_depth_cm_output; + uint8_t cm_res_quant_bits; + uint8_t cm_delta_flc_bits; + int8_t cm_adapt_threshold_u_delta; + int8_t cm_adapt_threshold_v_delta; } H265RawPPS; typedef struct H265RawAUD { diff --git a/libavcodec/cbs_h265_syntax_template.c b/libavcodec/cbs_h265_syntax_template.c index c6db439b3b..2f8ee0db10 100644 --- a/libavcodec/cbs_h265_syntax_template.c +++ b/libavcodec/cbs_h265_syntax_template.c @@ -747,6 +747,16 @@ static int FUNC(sps_scc_extension)(CodedBitstreamContext *ctx, RWContext *rw, return 0; } +static int FUNC(sps_multilayer_extension)(CodedBitstreamContext *ctx, RWContext *rw, + H265RawSPS *current) +{ + int err; + + flag(inter_view_mv_vert_constraint_flag); + + return 0; +} + static int FUNC(vui_parameters_default)(CodedBitstreamContext *ctx, RWContext *rw, H265RawVUI *current, H265RawSPS *sps) @@ -781,6 +791,7 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, int err, i; unsigned int min_cb_log2_size_y, ctb_log2_size_y, min_cb_size_y, min_tb_log2_size_y; + unsigned int multi_layer_ext_sps_flag; HEADER("Sequence Parameter Set"); @@ -794,7 +805,17 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, return AVERROR_INVALIDDATA; } + if (current->nal_unit_header.nuh_layer_id == 0) u(3, sps_max_sub_layers_minus1, 0, vps->vps_max_sub_layers_minus1); + else { + u(3, sps_ext_or_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS); + infer(sps_max_sub_layers_minus1, current->sps_ext_or_max_sub_layers_minus1 == 7 + ? vps->vps_max_sub_layers_minus1 + : current->sps_ext_or_max_sub_layers_minus1); + } + multi_layer_ext_sps_flag = current->nal_unit_header.nuh_layer_id && + current->sps_ext_or_max_sub_layers_minus1 == 7; + if (!multi_layer_ext_sps_flag) { flag(sps_temporal_id_nesting_flag); if (vps->vps_temporal_id_nesting_flag && @@ -814,9 +835,20 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, CHECK(FUNC(profile_tier_level)(ctx, rw, ¤t->profile_tier_level, 1, current->sps_max_sub_layers_minus1)); + } else { + if (current->sps_max_sub_layers_minus1 > 0) + infer(sps_temporal_id_nesting_flag, vps->vps_temporal_id_nesting_flag); + else + infer(sps_temporal_id_nesting_flag, 1); + } ue(sps_seq_parameter_set_id, 0, 15); + if (multi_layer_ext_sps_flag) { + flag(update_rep_format_flag); + if (current->update_rep_format_flag) + ub(8, sps_rep_format_idx); + } else { ue(chroma_format_idc, 0, 3); if (current->chroma_format_idc == 3) flag(separate_colour_plane_flag); @@ -841,9 +873,11 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, ue(bit_depth_luma_minus8, 0, 8); ue(bit_depth_chroma_minus8, 0, 8); + } ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12); + if (!multi_layer_ext_sps_flag) { flag(sps_sub_layer_ordering_info_present_flag); for (i = (current->sps_sub_layer_ordering_info_present_flag ? 0 : current->sps_max_sub_layers_minus1); @@ -865,6 +899,7 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, current->sps_max_latency_increase_plus1[current->sps_max_sub_layers_minus1]); } } + } ue(log2_min_luma_coding_block_size_minus3, 0, 3); min_cb_log2_size_y = current->log2_min_luma_coding_block_size_minus3 + 3; @@ -895,9 +930,17 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, flag(scaling_list_enabled_flag); if (current->scaling_list_enabled_flag) { + if (multi_layer_ext_sps_flag) + flag(sps_infer_scaling_list_flag); + else + infer(sps_infer_scaling_list_flag, 0); + if (current->sps_infer_scaling_list_flag) + ub(6, sps_scaling_list_ref_layer_id); + else { flag(sps_scaling_list_data_present_flag); if (current->sps_scaling_list_data_present_flag) CHECK(FUNC(scaling_list_data)(ctx, rw, ¤t->scaling_list)); + } } else { infer(sps_scaling_list_data_present_flag, 0); } @@ -955,7 +998,7 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, if (current->sps_range_extension_flag) CHECK(FUNC(sps_range_extension)(ctx, rw, current)); if (current->sps_multilayer_extension_flag) - return AVERROR_PATCHWELCOME; + CHECK(FUNC(sps_multilayer_extension)(ctx, rw, current)); if (current->sps_3d_extension_flag) return AVERROR_PATCHWELCOME; if (current->sps_scc_extension_flag) @@ -996,6 +1039,72 @@ static int FUNC(pps_range_extension)(CodedBitstreamContext *ctx, RWContext *rw, return 0; } +static int FUNC(pps_multilayer_extension)(CodedBitstreamContext *ctx, RWContext *rw, + H265RawPPS *current) +{ + CodedBitstreamH265Context *h265 = ctx->priv_data; + const H265RawVPS *vps = h265->active_vps; + int offset; + int err, i; + + flag(poc_reset_info_present_flag); + flag(pps_infer_scaling_list_flag); + if (current->pps_infer_scaling_list_flag) + ub(6, pps_scaling_list_ref_layer_id); + + if (!vps) { + av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS missing for PPS Multilayer Extension.\n"); + return AVERROR_INVALIDDATA; + } + + ue(num_ref_loc_offsets, 0, vps->vps_max_layers_minus1); + for (i = 0; i < current->num_ref_loc_offsets; i++) { + ubs(6, ref_loc_offset_layer_id[i], 1, i); + offset = current->ref_loc_offset_layer_id[i]; + flags(scaled_ref_layer_offset_present_flag[i], 1, i); + if (current->scaled_ref_layer_offset_present_flag[i]) { + ses(scaled_ref_layer_left_offset[offset], -16384, 16383, 1, offset); + ses(scaled_ref_layer_top_offset[offset], -16384, 16383, 1, offset); + ses(scaled_ref_layer_right_offset[offset], -16384, 16383, 1, offset); + ses(scaled_ref_layer_bottom_offset[offset], -16384, 16383, 1, offset); + } else { + infer(scaled_ref_layer_left_offset[offset], 0); + infer(scaled_ref_layer_top_offset[offset], 0); + infer(scaled_ref_layer_right_offset[offset], 0); + infer(scaled_ref_layer_bottom_offset[offset], 0); + } + flags(ref_region_offset_present_flag[i], 1, i); + if (current->ref_region_offset_present_flag[i]) { + ses(ref_region_left_offset[offset], -16384, 16383, 1, offset); + ses(ref_region_top_offset[offset], -16384, 16383, 1, offset); + ses(ref_region_right_offset[offset], -16384, 16383, 1, offset); + ses(ref_region_bottom_offset[offset], -16384, 16383, 1, offset); + } else { + infer(ref_region_left_offset[offset], 0); + infer(ref_region_top_offset[offset], 0); + infer(ref_region_right_offset[offset], 0); + infer(ref_region_bottom_offset[offset], 0); + } + flags(resample_phase_set_present_flag[i], 1, i); + if (current->resample_phase_set_present_flag[i]) { + ues(phase_hor_luma[offset], 0, 31, 1, offset); + ues(phase_ver_luma[offset], 0, 31, 1, offset); + ues(phase_hor_chroma_plus8[offset], 0, 63, 1, offset); + ues(phase_ver_chroma_plus8[offset], 0, 63, 1, offset); + } else { + infer(phase_hor_luma[offset], 0); + infer(phase_ver_luma[offset], 0); + infer(phase_hor_chroma_plus8[offset], 8); + } + } + + flag(colour_mapping_enabled_flag); + if (current->colour_mapping_enabled_flag) + return AVERROR_PATCHWELCOME; + + return 0; +} + static int FUNC(pps_scc_extension)(CodedBitstreamContext *ctx, RWContext *rw, H265RawPPS *current) { @@ -1146,7 +1255,7 @@ static int FUNC(pps)(CodedBitstreamContext *ctx, RWContext *rw, if (current->pps_range_extension_flag) CHECK(FUNC(pps_range_extension)(ctx, rw, current)); if (current->pps_multilayer_extension_flag) - return AVERROR_PATCHWELCOME; + CHECK(FUNC(pps_multilayer_extension)(ctx, rw, current)); if (current->pps_3d_extension_flag) return AVERROR_PATCHWELCOME; if (current->pps_scc_extension_flag) diff --git a/libavcodec/hevc/ps.h b/libavcodec/hevc/ps.h index 17395c5510..fab5a46273 100644 --- a/libavcodec/hevc/ps.h +++ b/libavcodec/hevc/ps.h @@ -390,8 +390,8 @@ typedef struct HEVCPPS { uint8_t resample_phase_set_present_flag[64]; uint8_t phase_hor_luma[64]; uint8_t phase_ver_luma[64]; - int8_t phase_hor_chroma[64]; - int8_t phase_ver_chroma[64]; + uint8_t phase_hor_chroma[64]; + uint8_t phase_ver_chroma[64]; uint8_t colour_mapping_enabled_flag; uint8_t num_cm_ref_layers; uint8_t cm_ref_layer_id[62]; -- 2.45.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-07-13 14:59 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-07-13 14:58 [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h265: fix range of sps_max_sub_layers_minus1 James Almer 2024-07-13 14:58 ` James Almer [this message] 2024-07-13 14:58 ` [FFmpeg-devel] [PATCH 3/4] avcodec/cbs_h265: reindent after the previous commit James Almer 2024-07-13 14:58 ` [FFmpeg-devel] [PATCH 4/4] avcodec/cbs_h265: add support for 3D Reference Displays Information SEI James Almer 2024-07-15 18:29 ` [FFmpeg-devel] [PATCH 1/4] avcodec/cbs_h265: fix range of sps_max_sub_layers_minus1 James Almer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240713145846.1331-2-jamrial@gmail.com \ --to=jamrial@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git