Currently active SPS is a per-layer property.
Showing the changes to libavcodec (7 of 7 files). Show all
Unified · Split
| @@ -555,7 +555,7 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) · 554 unmodified lines | |||
| 555 | int ret; | 555 | int ret; |
| 556 | 556 | ||
| 557 | pic_arrays_free(l); | 557 | pic_arrays_free(l); |
| 558 | s->ps.sps = NULL; | 558 | ff_refstruct_unref(&l->sps); |
| 559 | ff_refstruct_unref(&s->vps); | 559 | ff_refstruct_unref(&s->vps); |
| 560 | 560 | ||
| 561 | if (!sps) | 561 | if (!sps) |
| @@ -569,14 +569,14 @@ static int set_sps(HEVCContext *s, HEVCLayerContext *l, const HEVCSPS *sps) · 7 unmodified lines | |||
| 569 | ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); | 569 | ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth); |
| 570 | ff_videodsp_init (&s->vdsp, sps->bit_depth); | 570 | ff_videodsp_init (&s->vdsp, sps->bit_depth); |
| 571 | 571 | ||
| 572 | s->ps.sps = sps; | 572 | l->sps = ff_refstruct_ref_c(sps); |
| 573 | s->vps = ff_refstruct_ref_c(sps->vps); | 573 | s->vps = ff_refstruct_ref_c(sps->vps); |
| 574 | 574 | ||
| 575 | return 0; | 575 | return 0; |
| 576 | 576 | ||
| 577 | fail: | 577 | fail: |
| 578 | pic_arrays_free(l); | 578 | pic_arrays_free(l); |
| 579 | s->ps.sps = NULL; | 579 | ff_refstruct_unref(&l->sps); |
| 580 | return ret; | 580 | return ret; |
| 581 | } | 581 | } |
| 582 | 582 | ||
| @@ -2831,6 +2831,7 @@ static int decode_slice_data(HEVCContext *s, const HEVCLayerContext *l, · 2248 unmodified lines | |||
| 2831 | 2831 | ||
| 2832 | static int set_side_data(HEVCContext *s) | 2832 | static int set_side_data(HEVCContext *s) |
| 2833 | { | 2833 | { |
| 2834 | const HEVCSPS *sps = s->cur_frame->pps->sps; | ||
| 2834 | AVFrame *out = s->cur_frame->f; | 2835 | AVFrame *out = s->cur_frame->f; |
| 2835 | int ret; | 2836 | int ret; |
| 2836 | 2837 | ||
| @@ -2846,8 +2847,8 @@ static int set_side_data(HEVCContext *s) · 9 unmodified lines | |||
| 2846 | } | 2847 | } |
| 2847 | 2848 | ||
| 2848 | ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx, | 2849 | ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx, |
| 2849 | &s->ps.sps->vui.common, | 2850 | &sps->vui.common, |
| 2850 | s->ps.sps->bit_depth, s->ps.sps->bit_depth_chroma, | 2851 | sps->bit_depth, sps->bit_depth_chroma, |
| 2851 | s->cur_frame->poc /* no poc_offset in HEVC */); | 2852 | s->cur_frame->poc /* no poc_offset in HEVC */); |
| 2852 | if (ret < 0) | 2853 | if (ret < 0) |
| 2853 | return ret; | 2854 | return ret; |
| @@ -2932,7 +2933,7 @@ static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l) · 78 unmodified lines | |||
| 2932 | } | 2933 | } |
| 2933 | 2934 | ||
| 2934 | ff_refstruct_replace(&s->pps, pps); | 2935 | ff_refstruct_replace(&s->pps, pps); |
| 2935 | if (s->ps.sps != sps) { | 2936 | if (l->sps != sps) { |
| 2936 | enum AVPixelFormat pix_fmt; | 2937 | enum AVPixelFormat pix_fmt; |
| 2937 | 2938 | ||
| 2938 | ff_hevc_clear_refs(l); | 2939 | ff_hevc_clear_refs(l); |
| @@ -3523,8 +3524,10 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx) · 584 unmodified lines | |||
| 3523 | { | 3524 | { |
| 3524 | HEVCContext *s = avctx->priv_data; | 3525 | HEVCContext *s = avctx->priv_data; |
| 3525 | 3526 | ||
| 3526 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) | 3527 | for (int i = 0; i < FF_ARRAY_ELEMS(s->layers); i++) { |
| 3527 | pic_arrays_free(&s->layers[i]); | 3528 | pic_arrays_free(&s->layers[i]); |
| 3529 | ff_refstruct_unref(&s->layers[i].sps); | ||
| 3530 | } | ||
| 3528 | 3531 | ||
| 3529 | ff_refstruct_unref(&s->vps); | 3532 | ff_refstruct_unref(&s->vps); |
| 3530 | ff_refstruct_unref(&s->pps); | 3533 | ff_refstruct_unref(&s->pps); |
| @@ -3620,10 +3623,14 @@ static int hevc_update_thread_context(AVCodecContext *dst, · 89 unmodified lines | |||
| 3620 | return ret; | 3623 | return ret; |
| 3621 | } | 3624 | } |
| 3622 | } | 3625 | } |
| 3626 | |||
| 3627 | if (l->sps != l0->sps) { | ||
| 3628 | ret = set_sps(s, l, l0->sps); | ||
| 3629 | if (ret < 0) | ||
| 3630 | return ret; | ||
| 3631 | } | ||
| 3623 | } | 3632 | } |
| 3624 | 3633 | ||
| 3625 | if (s->ps.sps != s0->ps.sps) | ||
| 3626 | s->ps.sps = NULL; | ||
| 3627 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++) | 3634 | for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++) |
| 3628 | ff_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); | 3635 | ff_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); |
| 3629 | 3636 | ||
| @@ -3636,10 +3643,6 @@ static int hevc_update_thread_context(AVCodecContext *dst, · 6 unmodified lines | |||
| 3636 | // PPS do not persist between frames | 3643 | // PPS do not persist between frames |
| 3637 | ff_refstruct_unref(&s->pps); | 3644 | ff_refstruct_unref(&s->pps); |
| 3638 | 3645 | ||
| 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 | |||
| 3643 | s->poc_tid0 = s0->poc_tid0; | 3646 | s->poc_tid0 = s0->poc_tid0; |
| 3644 | s->eos = s0->eos; | 3647 | s->eos = s0->eos; |
| 3645 | s->no_rasl_output_flag = s0->no_rasl_output_flag; | 3648 | s->no_rasl_output_flag = s0->no_rasl_output_flag; |
| @@ -442,6 +442,8 @@ typedef struct HEVCLocalContext { · 441 unmodified lines | |||
| 442 | typedef struct HEVCLayerContext { | 442 | typedef struct HEVCLayerContext { |
| 443 | HEVCFrame DPB[32]; | 443 | HEVCFrame DPB[32]; |
| 444 | 444 | ||
| 445 | const HEVCSPS *sps; // RefStruct reference | ||
| 446 | |||
| 445 | int bs_width; | 447 | int bs_width; |
| 446 | int bs_height; | 448 | int bs_height; |
| 447 | 449 | ||
| @@ -66,15 +66,11 @@ static void remove_sps(HEVCParamSets *s, int id) · 65 unmodified lines | |||
| 66 | { | 66 | { |
| 67 | int i; | 67 | int i; |
| 68 | if (s->sps_list[id]) { | 68 | if (s->sps_list[id]) { |
| 69 | if (s->sps == s->sps_list[id]) | ||
| 70 | s->sps = NULL; | ||
| 71 | |||
| 72 | /* drop all PPS that depend on this SPS */ | 69 | /* drop all PPS that depend on this SPS */ |
| 73 | for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) | 70 | for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) |
| 74 | if (s->pps_list[i] && s->pps_list[i]->sps_id == id) | 71 | if (s->pps_list[i] && s->pps_list[i]->sps_id == id) |
| 75 | ff_refstruct_unref(&s->pps_list[i]); | 72 | ff_refstruct_unref(&s->pps_list[i]); |
| 76 | 73 | ||
| 77 | av_assert0(!(s->sps_list[id] && s->sps == s->sps_list[id])); | ||
| 78 | ff_refstruct_unref(&s->sps_list[id]); | 74 | ff_refstruct_unref(&s->sps_list[id]); |
| 79 | } | 75 | } |
| 80 | } | 76 | } |
| @@ -2045,8 +2041,6 @@ void ff_hevc_ps_uninit(HEVCParamSets *ps) · 1964 unmodified lines | |||
| 2045 | ff_refstruct_unref(&ps->sps_list[i]); | 2041 | ff_refstruct_unref(&ps->sps_list[i]); |
| 2046 | for (i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++) | 2042 | for (i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++) |
| 2047 | ff_refstruct_unref(&ps->pps_list[i]); | 2043 | ff_refstruct_unref(&ps->pps_list[i]); |
| 2048 | |||
| 2049 | ps->sps = NULL; | ||
| 2050 | } | 2044 | } |
| 2051 | 2045 | ||
| 2052 | int ff_hevc_compute_poc(const HEVCSPS *sps, int pocTid0, int poc_lsb, int nal_unit_type) | 2046 | int ff_hevc_compute_poc(const HEVCSPS *sps, int pocTid0, int poc_lsb, int nal_unit_type) |
| @@ -447,9 +447,6 @@ typedef struct HEVCParamSets { · 446 unmodified lines | |||
| 447 | const HEVCVPS *vps_list[HEVC_MAX_VPS_COUNT]; ///< RefStruct references | 447 | const HEVCVPS *vps_list[HEVC_MAX_VPS_COUNT]; ///< RefStruct references |
| 448 | const HEVCSPS *sps_list[HEVC_MAX_SPS_COUNT]; ///< RefStruct references | 448 | const HEVCSPS *sps_list[HEVC_MAX_SPS_COUNT]; ///< RefStruct references |
| 449 | const HEVCPPS *pps_list[HEVC_MAX_PPS_COUNT]; ///< RefStruct references | 449 | const HEVCPPS *pps_list[HEVC_MAX_PPS_COUNT]; ///< RefStruct references |
| 450 | |||
| 451 | /* currently active parameter sets */ | ||
| 452 | const HEVCSPS *sps; | ||
| 453 | } HEVCParamSets; | 450 | } HEVCParamSets; |
| 454 | 451 | ||
| 455 | /** | 452 | /** |
| @@ -103,7 +103,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s, HEVCLayerContext *l) · 102 unmodified lines | |||
| 103 | frame->rpl_tab = ff_refstruct_pool_get(l->rpl_tab_pool); | 103 | frame->rpl_tab = ff_refstruct_pool_get(l->rpl_tab_pool); |
| 104 | if (!frame->rpl_tab) | 104 | if (!frame->rpl_tab) |
| 105 | goto fail; | 105 | 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; |
| 107 | for (j = 0; j < frame->ctb_count; j++) | 107 | for (j = 0; j < frame->ctb_count; j++) |
| 108 | frame->rpl_tab[j] = frame->rpl; | 108 | frame->rpl_tab[j] = frame->rpl; |
| 109 | 109 | ||
| @@ -157,10 +157,10 @@ int ff_hevc_set_new_ref(HEVCContext *s, HEVCLayerContext *l, int poc) · 47 unmodified lines | |||
| 157 | ref->flags = HEVC_FRAME_FLAG_SHORT_REF; | 157 | ref->flags = HEVC_FRAME_FLAG_SHORT_REF; |
| 158 | 158 | ||
| 159 | ref->poc = poc; | 159 | ref->poc = poc; |
| 160 | ref->f->crop_left = s->ps.sps->output_window.left_offset; | 160 | ref->f->crop_left = l->sps->output_window.left_offset; |
| 161 | ref->f->crop_right = s->ps.sps->output_window.right_offset; | 161 | ref->f->crop_right = l->sps->output_window.right_offset; |
| 162 | ref->f->crop_top = s->ps.sps->output_window.top_offset; | 162 | ref->f->crop_top = l->sps->output_window.top_offset; |
| 163 | ref->f->crop_bottom = s->ps.sps->output_window.bottom_offset; | 163 | ref->f->crop_bottom = l->sps->output_window.bottom_offset; |
| 164 | 164 | ||
| 165 | return 0; | 165 | return 0; |
| 166 | } | 166 | } |
| @@ -321,7 +321,7 @@ int ff_hevc_slice_rpl(HEVCContext *s) · 154 unmodified lines | |||
| 321 | static HEVCFrame *find_ref_idx(HEVCContext *s, HEVCLayerContext *l, | 321 | static HEVCFrame *find_ref_idx(HEVCContext *s, HEVCLayerContext *l, |
| 322 | int poc, uint8_t use_msb) | 322 | int poc, uint8_t use_msb) |
| 323 | { | 323 | { |
| 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; |
| 325 | int i; | 325 | int i; |
| 326 | 326 | ||
| 327 | for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { | 327 | 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 | |||
| 354 | return NULL; | 354 | return NULL; |
| 355 | 355 | ||
| 356 | if (!s->avctx->hwaccel) { | 356 | if (!s->avctx->hwaccel) { |
| 357 | if (!s->ps.sps->pixel_shift) { | 357 | if (!l->sps->pixel_shift) { |
| 358 | for (i = 0; frame->f->data[i]; i++) | 358 | for (i = 0; frame->f->data[i]; i++) |
| 359 | memset(frame->f->data[i], 1 << (s->ps.sps->bit_depth - 1), | 359 | memset(frame->f->data[i], 1 << (l->sps->bit_depth - 1), |
| 360 | frame->f->linesize[i] * AV_CEIL_RSHIFT(s->ps.sps->height, s->ps.sps->vshift[i])); | 360 | frame->f->linesize[i] * AV_CEIL_RSHIFT(l->sps->height, l->sps->vshift[i])); |
| 361 | } else { | 361 | } else { |
| 362 | for (i = 0; frame->f->data[i]; i++) | 362 | 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++) { |
| 364 | uint8_t *dst = frame->f->data[i] + y * frame->f->linesize[i]; | 364 | uint8_t *dst = frame->f->data[i] + y * frame->f->linesize[i]; |
| 365 | AV_WN16(dst, 1 << (s->ps.sps->bit_depth - 1)); | 365 | AV_WN16(dst, 1 << (l->sps->bit_depth - 1)); |
| 366 | av_memcpy_backptr(dst + 2, 2, 2*(s->ps.sps->width >> s->ps.sps->hshift[i]) - 2); | 366 | av_memcpy_backptr(dst + 2, 2, 2*(l->sps->width >> l->sps->hshift[i]) - 2); |
| 367 | } | 367 | } |
| 368 | } | 368 | } |
| 369 | } | 369 | } |
| @@ -407,7 +407,7 @@ static void fill_pred_weight_table(AVCodecContext *avctx, · 406 unmodified lines | |||
| 407 | 407 | ||
| 408 | slice_param->luma_log2_weight_denom = sh->luma_log2_weight_denom; | 408 | slice_param->luma_log2_weight_denom = sh->luma_log2_weight_denom; |
| 409 | 409 | ||
| 410 | if (h->ps.sps->chroma_format_idc) { | 410 | if (h->pps->sps->chroma_format_idc) { |
| 411 | slice_param->delta_chroma_log2_weight_denom = sh->chroma_log2_weight_denom - sh->luma_log2_weight_denom; | 411 | slice_param->delta_chroma_log2_weight_denom = sh->chroma_log2_weight_denom - sh->luma_log2_weight_denom; |
| 412 | } | 412 | } |
| 413 | 413 | ||
| @@ -596,7 +596,7 @@ static int ptl_convert(const PTLCommon *general_ptl, H265RawProfileTierLevel *h2 · 182 unmodified lines | |||
| 596 | VAProfile ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx) | 596 | VAProfile ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx) |
| 597 | { | 597 | { |
| 598 | const HEVCContext *h = avctx->priv_data; | 598 | const HEVCContext *h = avctx->priv_data; |
| 599 | const HEVCSPS *sps = h->ps.sps; | 599 | const HEVCSPS *sps = h->pps->sps; |
| 600 | const PTL *ptl = &sps->ptl; | 600 | const PTL *ptl = &sps->ptl; |
| 601 | const PTLCommon *general_ptl = &ptl->general_ptl; | 601 | const PTLCommon *general_ptl = &ptl->general_ptl; |
| 602 | const H265ProfileDescriptor *profile; | 602 | const H265ProfileDescriptor *profile; |
| @@ -470,7 +470,7 @@ static int ptl_convert(const PTLCommon *general_ptl, H265RawProfileTierLevel *h2 · 469 unmodified lines | |||
| 470 | static int vdpau_hevc_parse_rext_profile(AVCodecContext *avctx, VdpDecoderProfile *vdp_profile) | 470 | static int vdpau_hevc_parse_rext_profile(AVCodecContext *avctx, VdpDecoderProfile *vdp_profile) |
| 471 | { | 471 | { |
| 472 | const HEVCContext *h = avctx->priv_data; | 472 | const HEVCContext *h = avctx->priv_data; |
| 473 | const HEVCSPS *sps = h->ps.sps; | 473 | const HEVCSPS *sps = h->pps->sps; |
| 474 | const PTL *ptl = &sps->ptl; | 474 | const PTL *ptl = &sps->ptl; |
| 475 | const PTLCommon *general_ptl = &ptl->general_ptl; | 475 | const PTLCommon *general_ptl = &ptl->general_ptl; |
| 476 | const H265ProfileDescriptor *profile; | 476 | const H265ProfileDescriptor *profile; |