lavc/hevc/parser: stop using HEVCParamSets.[psv]ps

The parser does not need to preserve these between frames.
This commit is contained in:
Anton Khirnov 2024-05-31 10:55:19 +02:00
parent 2e46d68f55
commit 6ddba110eb
1 changed files with 27 additions and 28 deletions

View File

@ -58,6 +58,8 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
HEVCParamSets *ps = &ctx->ps; HEVCParamSets *ps = &ctx->ps;
HEVCSEI *sei = &ctx->sei; HEVCSEI *sei = &ctx->sei;
GetBitContext *gb = &nal->gb; GetBitContext *gb = &nal->gb;
const HEVCPPS *pps;
const HEVCSPS *sps;
const HEVCWindow *ow; const HEVCWindow *ow;
int i, num = 0, den = 0; 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); av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
return AVERROR_INVALIDDATA; 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) { ow = &sps->output_window;
ps->sps = ps->pps->sps;
ps->vps = ps->sps->vps;
}
ow = &ps->sps->output_window;
s->coded_width = ps->sps->width; s->coded_width = sps->width;
s->coded_height = ps->sps->height; s->coded_height = sps->height;
s->width = ps->sps->width - ow->left_offset - ow->right_offset; s->width = sps->width - ow->left_offset - ow->right_offset;
s->height = ps->sps->height - ow->top_offset - ow->bottom_offset; s->height = sps->height - ow->top_offset - ow->bottom_offset;
s->format = ps->sps->pix_fmt; s->format = sps->pix_fmt;
avctx->profile = ps->sps->ptl.general_ptl.profile_idc; avctx->profile = sps->ptl.general_ptl.profile_idc;
avctx->level = ps->sps->ptl.general_ptl.level_idc; avctx->level = sps->ptl.general_ptl.level_idc;
if (ps->vps->vps_timing_info_present_flag) { if (sps->vps->vps_timing_info_present_flag) {
num = ps->vps->vps_num_units_in_tick; num = sps->vps->vps_num_units_in_tick;
den = ps->vps->vps_time_scale; den = sps->vps->vps_time_scale;
} else if (ps->sps->vui.vui_timing_info_present_flag) { } else if (sps->vui.vui_timing_info_present_flag) {
num = ps->sps->vui.vui_num_units_in_tick; num = sps->vui.vui_num_units_in_tick;
den = ps->sps->vui.vui_time_scale; den = sps->vui.vui_time_scale;
} }
if (num != 0 && den != 0) if (num != 0 && den != 0)
@ -110,15 +109,15 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
unsigned int slice_segment_addr; unsigned int slice_segment_addr;
int slice_address_length; 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); dependent_slice_segment_flag = get_bits1(gb);
else else
dependent_slice_segment_flag = 0; dependent_slice_segment_flag = 0;
slice_address_length = av_ceil_log2_c(ps->sps->ctb_width * slice_address_length = av_ceil_log2_c(sps->ctb_width *
ps->sps->ctb_height); sps->ctb_height);
slice_segment_addr = get_bitsz(gb, slice_address_length); 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", av_log(avctx, AV_LOG_ERROR, "Invalid slice segment address: %u.\n",
slice_segment_addr); slice_segment_addr);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
@ -129,7 +128,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
if (dependent_slice_segment_flag) if (dependent_slice_segment_flag)
return 0; /* break; */ 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[] skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
slice_type = get_ue_golomb_31(gb); 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 : slice_type == HEVC_SLICE_P ? AV_PICTURE_TYPE_P :
AV_PICTURE_TYPE_I; AV_PICTURE_TYPE_I;
if (ps->pps->output_flag_present_flag) if (pps->output_flag_present_flag)
skip_bits1(gb); // pic_output_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 skip_bits(gb, 2); // colour_plane_id
if (!IS_IDR_NAL(nal)) { 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 = 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 } else
s->output_picture_number = ctx->poc = 0; s->output_picture_number = ctx->poc = 0;