History

lavc/hevcdec: move active SPS from HEVCParamSets to HEVCLayerContext

Currently active SPS is a per-layer property.

Anton Khirnov committed 2 years ago

Commit fc8df811 parent 9bccc637 files · +33 −37Browse files

Unified · Split

7 files
  1. libavcodec/hevc/hevcdec.c +16 −13
  2. libavcodec/hevc/hevcdec.h +2 −0
  3. libavcodec/hevc/ps.c +0 −6
  4. libavcodec/hevc/ps.h +0 −3
  5. libavcodec/hevc/refs.c +12 −12
  6. libavcodec/vaapi_hevc.c +2 −2
  7. libavcodec/vdpau_hevc.c +1 −1
libavcodec/hevc/hevcdec.c+16−13
@@ -555,7 +555,7 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) · 554 unmodified lines
555555 int ret;
556556
557557 pic_arrays_free(l);
558− s->ps.sps = NULL;
558+ ff_refstruct_unref(&l->sps);
559559 ff_refstruct_unref(&s->vps);
560560
561561 if (!sps)
@@ -569,14 +569,14 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) · 7 unmodified lines
569569 ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);
570570 ff_videodsp_init (&s->vdsp, sps->bit_depth);
571571
572− s->ps.sps = sps;
572+ l->sps = ff_refstruct_ref_c(sps);
573573 s->vps = ff_refstruct_ref_c(sps->vps);
574574
575575 return 0;
576576
577577 fail:
578578 pic_arrays_free(l);
579− s->ps.sps = NULL;
579+ ff_refstruct_unref(&l->sps);
580580 return ret;
581581 }
582582
@@ -2831,6 +2831,7 @@ static int decode_slice_data(HEVCContext *s, const HEVCLayerContext *l, · 2248 unmodified lines
28312831
28322832 static int set_side_data(HEVCContext *s)
28332833 {
2834+ const HEVCSPS *sps = s->cur_frame->pps->sps;
28342835 AVFrame *out = s->cur_frame->f;
28352836 int ret;
28362837
@@ -2846,8 +2847,8 @@ static int set_side_data(HEVCContext *s) · 9 unmodified lines
28462847 }
28472848
28482849 ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx,
2849− &s->ps.sps->vui.common,
2850− s->ps.sps->bit_depth, s->ps.sps->bit_depth_chroma,
2850+ &sps->vui.common,
2851+ sps->bit_depth, sps->bit_depth_chroma,
28512852 s->cur_frame->poc /* no poc_offset in HEVC */);
28522853 if (ret < 0)
28532854 return ret;
@@ -2932,7 +2933,7 @@ static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l) · 78 unmodified lines
29322933 }
29332934
29342935 ff_refstruct_replace(&s->pps, pps);
2935− if (s->ps.sps != sps) {
2936+ if (l->sps != sps) {
29362937 enum AVPixelFormat pix_fmt;
29372938
29382939 ff_hevc_clear_refs(l);
@@ -3523,8 +3524,10 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx) · 584 unmodified lines
35233524 {
35243525 HEVCContext *s = avctx->priv_data;
35253526
3526− for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++)
3527+ for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) {
35273528 pic_arrays_free(&s->layers[i]);
3529+ ff_refstruct_unref(&s->layers[i].sps);
3530+ }
35283531
35293532 ff_refstruct_unref(&s->vps);
35303533 ff_refstruct_unref(&s->pps);
@@ -3620,10 +3623,14 @@ static int hevc_update_thread_context(AVCodecContext *dst, · 89 unmodified lines
36203623 return ret;
36213624 }
36223625 }
3626+
3627+ if (l->sps != l0->sps) {
3628+ ret = set_sps(s, l, l0->sps);
3629+ if (ret < 0)
3630+ return ret;
3631+ }
36233632 }
36243633
3625− if (s->ps.sps != s0->ps.sps)
3626− s->ps.sps = NULL;
36273634 for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++)
36283635 ff_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]);
36293636
@@ -3636,10 +3643,6 @@ static int hevc_update_thread_context(AVCodecContext *dst, · 6 unmodified lines
36363643 // PPS do not persist between frames
36373644 ff_refstruct_unref(&s->pps);
36383645
3639− if (s->ps.sps != s0->ps.sps)
3640− if ((ret = set_sps(s, &s->layers[0], s0->ps.sps)) < 0)
3641− return ret;
3642−
36433646 s->poc_tid0 = s0->poc_tid0;
36443647 s->eos = s0->eos;
36453648 s->no_rasl_output_flag = s0->no_rasl_output_flag;
libavcodec/hevc/hevcdec.h+2−0
@@ -442,6 +442,8 @@ typedef struct HEVCLocalContext { · 441 unmodified lines
442442 typedef struct HEVCLayerContext {
443443 HEVCFrame DPB[32];
444444
445+ const HEVCSPS *sps; // RefStruct reference
446+
445447 int bs_width;
446448 int bs_height;
447449
libavcodec/hevc/ps.c+0−6
@@ -66,15 +66,11 @@ static void remove_sps(HEVCParamSets *s, int id) · 65 unmodified lines
6666 {
6767 int i;
6868 if (s->sps_list[id]) {
69− if (s->sps == s->sps_list[id])
70− s->sps = NULL;
71−
7269 /* drop all PPS that depend on this SPS */
7370 for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++)
7471 if (s->pps_list[i] && s->pps_list[i]->sps_id == id)
7572 ff_refstruct_unref(&s->pps_list[i]);
7673
77− av_assert0(!(s->sps_list[id] && s->sps == s->sps_list[id]));
7874 ff_refstruct_unref(&s->sps_list[id]);
7975 }
8076 }
@@ -2045,8 +2041,6 @@ void ff_hevc_ps_uninit(HEVCParamSets *ps) · 1964 unmodified lines
20452041 ff_refstruct_unref(&ps->sps_list[i]);
20462042 for (i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++)
20472043 ff_refstruct_unref(&ps->pps_list[i]);
2048−
2049− ps->sps = NULL;
20502044 }
20512045
20522046 int ff_hevc_compute_poc(const HEVCSPS *sps, int pocTid0, int poc_lsb, int nal_unit_type)
libavcodec/hevc/ps.h+0−3
@@ -447,9 +447,6 @@ typedef struct HEVCParamSets { · 446 unmodified lines
447447 const HEVCVPS *vps_list[HEVC_MAX_VPS_COUNT]; ///< RefStruct references
448448 const HEVCSPS *sps_list[HEVC_MAX_SPS_COUNT]; ///< RefStruct references
449449 const HEVCPPS *pps_list[HEVC_MAX_PPS_COUNT]; ///< RefStruct references
450−
451− /* currently active parameter sets */
452− const HEVCSPS *sps;
453450 } HEVCParamSets;
454451
455452 /**
libavcodec/hevc/refs.c+12−12
@@ -103,7 +103,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s, HEVCLayerContext *l) · 102 unmodified lines
103103 frame->rpl_tab = ff_refstruct_pool_get(l->rpl_tab_pool);
104104 if (!frame->rpl_tab)
105105 goto fail;
106− frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height;
106+ frame->ctb_count = l->sps->ctb_width * l->sps->ctb_height;
107107 for (j = 0; j < frame->ctb_count; j++)
108108 frame->rpl_tab[j] = frame->rpl;
109109
@@ -157,10 +157,10 @@ int ff_hevc_set_new_ref(HEVCContext *s, HEVCLayerContext *l, int poc) · 47 unmodified lines
157157 ref->flags = HEVC_FRAME_FLAG_SHORT_REF;
158158
159159 ref->poc = poc;
160− ref->f->crop_left = s->ps.sps->output_window.left_offset;
161− ref->f->crop_right = s->ps.sps->output_window.right_offset;
162− ref->f->crop_top = s->ps.sps->output_window.top_offset;
163− ref->f->crop_bottom = s->ps.sps->output_window.bottom_offset;
160+ ref->f->crop_left = l->sps->output_window.left_offset;
161+ ref->f->crop_right = l->sps->output_window.right_offset;
162+ ref->f->crop_top = l->sps->output_window.top_offset;
163+ ref->f->crop_bottom = l->sps->output_window.bottom_offset;
164164
165165 return 0;
166166 }
@@ -321,7 +321,7 @@ int ff_hevc_slice_rpl(HEVCContext *s) · 154 unmodified lines
321321 static HEVCFrame *find_ref_idx(HEVCContext *s, HEVCLayerContext *l,
322322 int poc, uint8_t use_msb)
323323 {
324− int mask = use_msb ? ~0 : (1 << s->ps.sps->log2_max_poc_lsb) - 1;
324+ int mask = use_msb ? ~0 : (1 << l->sps->log2_max_poc_lsb) - 1;
325325 int i;
326326
327327 for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) {
@@ -354,16 +354,16 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, HEVCLayerContext *l, int · 26 unmodified lines
354354 return NULL;
355355
356356 if (!s->avctx->hwaccel) {
357− if (!s->ps.sps->pixel_shift) {
357+ if (!l->sps->pixel_shift) {
358358 for (i = 0; frame->f->data[i]; i++)
359− memset(frame->f->data[i], 1 << (s->ps.sps->bit_depth - 1),
360− frame->f->linesize[i] * AV_CEIL_RSHIFT(s->ps.sps->height, s->ps.sps->vshift[i]));
359+ memset(frame->f->data[i], 1 << (l->sps->bit_depth - 1),
360+ frame->f->linesize[i] * AV_CEIL_RSHIFT(l->sps->height, l->sps->vshift[i]));
361361 } else {
362362 for (i = 0; frame->f->data[i]; i++)
363− for (y = 0; y < (s->ps.sps->height >> s->ps.sps->vshift[i]); y++) {
363+ for (y = 0; y < (l->sps->height >> l->sps->vshift[i]); y++) {
364364 uint8_t *dst = frame->f->data[i] + y * frame->f->linesize[i];
365− AV_WN16(dst, 1 << (s->ps.sps->bit_depth - 1));
366− av_memcpy_backptr(dst + 2, 2, 2*(s->ps.sps->width >> s->ps.sps->hshift[i]) - 2);
365+ AV_WN16(dst, 1 << (l->sps->bit_depth - 1));
366+ av_memcpy_backptr(dst + 2, 2, 2*(l->sps->width >> l->sps->hshift[i]) - 2);
367367 }
368368 }
369369 }
libavcodec/vaapi_hevc.c+2−2
@@ -407,7 +407,7 @@ static void fill_pred_weight_table(AVCodecContext *avctx, · 406 unmodified lines
407407
408408 slice_param->luma_log2_weight_denom = sh->luma_log2_weight_denom;
409409
410− if (h->ps.sps->chroma_format_idc) {
410+ if (h->pps->sps->chroma_format_idc) {
411411 slice_param->delta_chroma_log2_weight_denom = sh->chroma_log2_weight_denom - sh->luma_log2_weight_denom;
412412 }
413413
@@ -596,7 +596,7 @@ static int ptl_convert(const PTLCommon *general_ptl, H265RawProfileTierLevel *h2 · 182 unmodified lines
596596 VAProfile ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx)
597597 {
598598 const HEVCContext *h = avctx->priv_data;
599− const HEVCSPS *sps = h->ps.sps;
599+ const HEVCSPS *sps = h->pps->sps;
600600 const PTL *ptl = &sps->ptl;
601601 const PTLCommon *general_ptl = &ptl->general_ptl;
602602 const H265ProfileDescriptor *profile;
libavcodec/vdpau_hevc.c+1−1
@@ -470,7 +470,7 @@ static int ptl_convert(const PTLCommon *general_ptl, H265RawProfileTierLevel *h2 · 469 unmodified lines
470470 static int vdpau_hevc_parse_rext_profile(AVCodecContext *avctx, VdpDecoderProfile *vdp_profile)
471471 {
472472 const HEVCContext *h = avctx->priv_data;
473− const HEVCSPS *sps = h->ps.sps;
473+ const HEVCSPS *sps = h->pps->sps;
474474 const PTL *ptl = &sps->ptl;
475475 const PTLCommon *general_ptl = &ptl->general_ptl;
476476 const H265ProfileDescriptor *profile;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t