[FFmpeg-devel] [PATCH 06/39] lavc/hevc/parser: stop using HEVCParamSets.[psv]ps
Anton Khirnov
anton at khirnov.net
Fri Jun 7 16:01:02 EEST 2024
The parser does not need to preserve these between frames.
---
libavcodec/hevc/parser.c | 55 ++++++++++++++++++++--------------------
1 file changed, 27 insertions(+), 28 deletions(-)
diff --git a/libavcodec/hevc/parser.c b/libavcodec/hevc/parser.c
index 49f7bccdfa..f4e6e3c36d 100644
--- a/libavcodec/hevc/parser.c
+++ b/libavcodec/hevc/parser.c
@@ -58,6 +58,8 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
HEVCParamSets *ps = &ctx->ps;
HEVCSEI *sei = &ctx->sei;
GetBitContext *gb = &nal->gb;
+ const HEVCPPS *pps;
+ const HEVCSPS *sps;
const HEVCWindow *ow;
int i, num = 0, den = 0;
@@ -78,28 +80,25 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
return AVERROR_INVALIDDATA;
}
- ps->pps = ps->pps_list[pps_id];
+ pps = ps->pps_list[pps_id];
+ sps = pps->sps;
- if (ps->sps != ps->pps->sps) {
- ps->sps = ps->pps->sps;
- ps->vps = ps->sps->vps;
- }
- ow = &ps->sps->output_window;
+ ow = &sps->output_window;
- s->coded_width = ps->sps->width;
- s->coded_height = ps->sps->height;
- s->width = ps->sps->width - ow->left_offset - ow->right_offset;
- s->height = ps->sps->height - ow->top_offset - ow->bottom_offset;
- s->format = ps->sps->pix_fmt;
- avctx->profile = ps->sps->ptl.general_ptl.profile_idc;
- avctx->level = ps->sps->ptl.general_ptl.level_idc;
+ s->coded_width = sps->width;
+ s->coded_height = sps->height;
+ s->width = sps->width - ow->left_offset - ow->right_offset;
+ s->height = sps->height - ow->top_offset - ow->bottom_offset;
+ s->format = sps->pix_fmt;
+ avctx->profile = sps->ptl.general_ptl.profile_idc;
+ avctx->level = sps->ptl.general_ptl.level_idc;
- if (ps->vps->vps_timing_info_present_flag) {
- num = ps->vps->vps_num_units_in_tick;
- den = ps->vps->vps_time_scale;
- } else if (ps->sps->vui.vui_timing_info_present_flag) {
- num = ps->sps->vui.vui_num_units_in_tick;
- den = ps->sps->vui.vui_time_scale;
+ if (sps->vps->vps_timing_info_present_flag) {
+ num = sps->vps->vps_num_units_in_tick;
+ den = sps->vps->vps_time_scale;
+ } else if (sps->vui.vui_timing_info_present_flag) {
+ num = sps->vui.vui_num_units_in_tick;
+ den = sps->vui.vui_time_scale;
}
if (num != 0 && den != 0)
@@ -110,15 +109,15 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
unsigned int slice_segment_addr;
int slice_address_length;
- if (ps->pps->dependent_slice_segments_enabled_flag)
+ if (pps->dependent_slice_segments_enabled_flag)
dependent_slice_segment_flag = get_bits1(gb);
else
dependent_slice_segment_flag = 0;
- slice_address_length = av_ceil_log2_c(ps->sps->ctb_width *
- ps->sps->ctb_height);
+ slice_address_length = av_ceil_log2_c(sps->ctb_width *
+ sps->ctb_height);
slice_segment_addr = get_bitsz(gb, slice_address_length);
- if (slice_segment_addr >= ps->sps->ctb_width * ps->sps->ctb_height) {
+ if (slice_segment_addr >= sps->ctb_width * sps->ctb_height) {
av_log(avctx, AV_LOG_ERROR, "Invalid slice segment address: %u.\n",
slice_segment_addr);
return AVERROR_INVALIDDATA;
@@ -129,7 +128,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
if (dependent_slice_segment_flag)
return 0; /* break; */
- for (i = 0; i < ps->pps->num_extra_slice_header_bits; i++)
+ for (i = 0; i < pps->num_extra_slice_header_bits; i++)
skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
slice_type = get_ue_golomb_31(gb);
@@ -143,16 +142,16 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
slice_type == HEVC_SLICE_P ? AV_PICTURE_TYPE_P :
AV_PICTURE_TYPE_I;
- if (ps->pps->output_flag_present_flag)
+ if (pps->output_flag_present_flag)
skip_bits1(gb); // pic_output_flag
- if (ps->sps->separate_colour_plane)
+ if (sps->separate_colour_plane)
skip_bits(gb, 2); // colour_plane_id
if (!IS_IDR_NAL(nal)) {
- int pic_order_cnt_lsb = get_bits(gb, ps->sps->log2_max_poc_lsb);
+ int pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
s->output_picture_number = ctx->poc =
- ff_hevc_compute_poc(ps->sps, ctx->pocTid0, pic_order_cnt_lsb, nal->type);
+ ff_hevc_compute_poc(sps, ctx->pocTid0, pic_order_cnt_lsb, nal->type);
} else
s->output_picture_number = ctx->poc = 0;
--
2.43.0
More information about the ffmpeg-devel
mailing list