FFmpeg
vvcdec.h
Go to the documentation of this file.
1 /*
2  * VVC video decoder
3  *
4  * Copyright (C) 2021 Nuo Mi
5  * Copyright (C) 2022 Xu Mu
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #ifndef AVCODEC_VVC_VVCDEC_H
25 #define AVCODEC_VVC_VVCDEC_H
26 
27 #include "libavcodec/videodsp.h"
28 #include "libavcodec/vvc.h"
29 
30 #include "vvc_ps.h"
31 #include "vvcdsp.h"
32 
33 #define LUMA 0
34 #define CHROMA 1
35 #define CB 1
36 #define CR 2
37 #define JCBCR 3
38 
39 #define MIN_TU_LOG2 2 ///< MinTbLog2SizeY
40 #define MIN_PU_LOG2 2
41 
42 #define L0 0
43 #define L1 1
44 
45 typedef struct RefPicList {
49  int nb_refs;
50 } RefPicList;
51 
52 typedef struct RefPicListTab {
55 
56 typedef struct VVCFrame {
57  struct AVFrame *frame;
58 
59  struct MvField *tab_dmvr_mvf; ///< RefStruct reference
60  RefPicListTab **rpl_tab; ///< RefStruct reference
61  RefPicListTab *rpl; ///< RefStruct reference
63 
64  int ctb_count;
65 
66  int poc;
67 
69 
70  struct FrameProgress *progress; ///< RefStruct reference
71 
72  /**
73  * A sequence counter, so that old frames are output first
74  * after a POC reset
75  */
76  uint16_t sequence;
77  /**
78  * A combination of VVC_FRAME_FLAG_*
79  */
80  uint8_t flags;
81 } VVCFrame;
82 
83 typedef struct SliceContext {
84  int slice_idx;
86  struct EntryPoint *eps;
87  int nb_eps;
89  void *ref; ///< RefStruct reference, backing slice data
90 } SliceContext;
91 
92 typedef struct VVCFrameContext {
93  void *log_ctx;
94 
95  // +1 for the current frame
97 
98  struct AVFrame *frame;
100 
102 
106 
108 
111 
113 
114  uint64_t decode_order;
115 
118 
121 
122  struct {
123  int16_t *slice_idx;
124 
126  struct SAOParams *sao;
127  struct ALFParams *alf;
128 
129  int *cb_pos_x[2]; ///< CbPosX[][][]
130  int *cb_pos_y[2]; ///< CbPosY[][][]
131  uint8_t *cb_width[2]; ///< CbWidth[][][]
132  uint8_t *cb_height[2]; ///< CbHeight[][][]
133  uint8_t *cqt_depth[2]; ///< CqtDepth[][][]
135 
136  uint8_t *skip; ///< CuSkipFlag[][]
137  uint8_t *ispmf; ///< intra_sub_partitions_mode_flag
138  uint8_t *msm[2]; ///< MttSplitMode[][][] in 32 pixels
139  uint8_t *imf; ///< IntraMipFlag[][]
140  uint8_t *imtf; ///< intra_mip_transposed_flag[][]
141  uint8_t *imm; ///< intra_mip_mode[][]
142  uint8_t *ipm; ///< IntraPredModeY[][]
143  uint8_t *cpm[2]; ///< CuPredMode[][][]
144  uint8_t *msf; ///< MergeSubblockFlag[][]
145  uint8_t *iaf; ///< InterAffineFlag[][]
146  uint8_t *mmi; ///< MotionModelIdc[][]
147  struct Mv *cp_mv[2]; ///< CpMvLX[][][][MAX_CONTROL_POINTS];
148  struct MvField *mvf; ///< MvDmvrL0, MvDmvrL1
149 
150  uint8_t *tu_coded_flag[VVC_MAX_SAMPLE_ARRAYS]; ///< tu_y_coded_flag[][], tu_cb_coded_flag[][], tu_cr_coded_flag[][]
151  uint8_t *tu_joint_cbcr_residual_flag; ///< tu_joint_cbcr_residual_flag[][]
152  int *tb_pos_x0[2];
153  int *tb_pos_y0[2];
154  uint8_t *tb_width[2];
155  uint8_t *tb_height[2];
156  uint8_t *pcmf[2];
157 
160  uint8_t *horizontal_p; ///< horizontal maxFilterLengthPs for luma
161  uint8_t *horizontal_q; ///< horizontal maxFilterLengthQs for luma
162  uint8_t *vertical_p; ///< vertical maxFilterLengthPs for luma
163  uint8_t *vertical_q; ///< vertical maxFilterLengthQs for luma
164 
169 
170  int *coeffs;
171  struct CTU *ctus;
172 
173  uint8_t *ibc_vir_buf[VVC_MAX_SAMPLE_ARRAYS]; ///< IbcVirBuf[]
174 
175  //used in arrays_init only
176  struct {
178  int ctu_size;
184  int width;
185  int height;
188  int bs_width;
190  int ibc_buffer_width; ///< IbcBufWidth
191  } sz;
192  } tab;
194 
195 typedef struct VVCContext {
197 
200 
202 
203  int temporal_id; ///< temporal_id_plus1 - 1
204  int poc_tid0;
205 
206  int eos; ///< current packet contains an EOS/EOB NAL
207  int last_eos; ///< last packet contains an EOS/EOB NAL
208 
210  int no_output_before_recovery_flag; ///< NoOutputBeforeRecoveryFlag
211  int gdr_recovery_point_poc; ///< recoveryPointPocVal
212 
213  /**
214  * Sequence counters for decoded and output frames, so that old
215  * frames are output first after a POC reset
216  */
217  uint16_t seq_decode;
218  uint16_t seq_output;
219 
221 
223  int nb_fcs;
224 
225  uint64_t nb_frames; ///< processed frames
226  int nb_delayed; ///< delayed frames
227 } VVCContext ;
228 
229 #endif /* AVCODEC_VVC_VVCDEC_H */
VVCContext::vcl_unit_type
enum VVCNALUnitType vcl_unit_type
Definition: vvcdec.h:209
DBParams
Definition: hevcdec.h:341
VVCFrameContext::tb_width
uint8_t * tb_width[2]
Definition: vvcdec.h:154
VVCFrameContext::vertical_q
uint8_t * vertical_q
vertical maxFilterLengthQs for luma
Definition: vvcdec.h:163
VVCContext::avctx
struct AVCodecContext * avctx
Definition: vvcdec.h:196
VVCFrameContext::output_frame
struct AVFrame * output_frame
Definition: vvcdec.h:99
VVCFrameContext::decode_order
uint64_t decode_order
Definition: vvcdec.h:114
VVCFrameContext::frame
struct AVFrame * frame
Definition: vvcdec.h:98
VVCFrameContext::pic_size_in_min_cb
int pic_size_in_min_cb
Definition: vvcdec.h:179
VVCFrameContext::tu_joint_cbcr_residual_flag
uint8_t * tu_joint_cbcr_residual_flag
tu_joint_cbcr_residual_flag[][]
Definition: vvcdec.h:151
VVCFrameContext::ctu_count
int ctu_count
Definition: vvcdec.h:177
VVCFrameContext::mmi
uint8_t * mmi
MotionModelIdc[][].
Definition: vvcdec.h:146
VVCFrameContext::cpm
uint8_t * cpm[2]
CuPredMode[][][].
Definition: vvcdec.h:143
VVCFrameContext::ispmf
uint8_t * ispmf
intra_sub_partitions_mode_flag
Definition: vvcdec.h:137
VVCFrameContext::alf_pixel_buffer_v
uint8_t * alf_pixel_buffer_v[VVC_MAX_SAMPLE_ARRAYS][2]
Definition: vvcdec.h:168
VVCContext::last_eos
int last_eos
last packet contains an EOS/EOB NAL
Definition: vvcdec.h:207
VVCFrameContext::ctu_size
int ctu_size
Definition: vvcdec.h:178
VVCFrameContext::tab
struct VVCFrameContext::@228 tab
VVCContext::seq_output
uint16_t seq_output
Definition: vvcdec.h:218
VVCContext::cbc
CodedBitstreamContext * cbc
Definition: vvcdec.h:198
vvcdsp.h
VVCFrameContext::cb_width
uint8_t * cb_width[2]
CbWidth[][][].
Definition: vvcdec.h:131
VVCFrameContext::msm
uint8_t * msm[2]
MttSplitMode[][][] in 32 pixels.
Definition: vvcdec.h:138
VVCFrameContext::ipm
uint8_t * ipm
IntraPredModeY[][].
Definition: vvcdec.h:142
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:375
VVCFrameContext::deblock
DBParams * deblock
Definition: vvcdec.h:125
VVCFrameContext::chroma_format_idc
int chroma_format_idc
Definition: vvcdec.h:186
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
VVCFrame::collocated_ref
struct VVCFrame * collocated_ref
Definition: vvcdec.h:68
DPB
Decoded Picture Buffer (DPB).
Definition: vaapi_h264.c:82
RefPicList
Definition: hevcdec.h:189
VVCFrameContext::slices
SliceContext ** slices
Definition: vvcdec.h:103
VVCContext::no_output_before_recovery_flag
int no_output_before_recovery_flag
NoOutputBeforeRecoveryFlag.
Definition: vvcdec.h:210
VVC_MAX_DPB_SIZE
@ VVC_MAX_DPB_SIZE
Definition: vvc.h:109
VVCFrameParamSets
Definition: vvc_ps.h:219
VVCFrame::rpl
RefPicListTab * rpl
RefStruct reference.
Definition: vvcdec.h:61
VVCNALUnitType
VVCNALUnitType
Table 5 – NAL unit type codes and NAL unit type classes in T-REC-H.266-202008.
Definition: vvc.h:28
VVCContext::executor
struct AVExecutor * executor
Definition: vvcdec.h:220
VVCFrameContext::ctus
struct CTU * ctus
Definition: vvcdec.h:171
SliceContext::rpl
RefPicList * rpl
Definition: vvcdec.h:88
RefPicList::nb_refs
int nb_refs
Definition: hevcdec.h:193
VVCFrameContext::sao_pixel_buffer_h
uint8_t * sao_pixel_buffer_h[VVC_MAX_SAMPLE_ARRAYS]
Definition: vvcdec.h:165
VVCContext::seq_decode
uint16_t seq_decode
Sequence counters for decoded and output frames, so that old frames are output first after a POC rese...
Definition: vvcdec.h:217
VVCFrameContext::ctu_height
int ctu_height
Definition: vvcdec.h:183
VVCFrameContext::pcmf
uint8_t * pcmf[2]
Definition: vvcdec.h:156
VVCFrameThread
Definition: vvc_thread.c:83
VVCFrameContext::cb_pos_y
int * cb_pos_y[2]
CbPosY[][][].
Definition: vvcdec.h:130
VVCFrameContext::tu_coded_flag
uint8_t * tu_coded_flag[VVC_MAX_SAMPLE_ARRAYS]
tu_y_coded_flag[][], tu_cb_coded_flag[][], tu_cr_coded_flag[][]
Definition: vvcdec.h:150
VVCFrame::flags
uint8_t flags
A combination of VVC_FRAME_FLAG_*.
Definition: vvcdec.h:80
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:122
VVCFrameContext::cp_mv
struct Mv * cp_mv[2]
CpMvLX[][][][MAX_CONTROL_POINTS];.
Definition: vvcdec.h:147
VVCFrameContext::pixel_shift
int pixel_shift
Definition: vvcdec.h:187
VVCFrameContext::imf
uint8_t * imf
IntraMipFlag[][].
Definition: vvcdec.h:139
VVCFrameContext::cb_pos_x
int * cb_pos_x[2]
CbPosX[][][].
Definition: vvcdec.h:129
VVCFrameContext::tab_dmvr_mvf_pool
struct FFRefStructPool * tab_dmvr_mvf_pool
Definition: vvcdec.h:116
VVCFrameContext::alf
struct ALFParams * alf
Definition: vvcdec.h:127
SliceContext::slice_idx
int slice_idx
Definition: vvcdec.h:84
VVCFrameContext::imtf
uint8_t * imtf
intra_mip_transposed_flag[][]
Definition: vvcdec.h:140
VVCFrameContext::tu_pool
struct FFRefStructPool * tu_pool
Definition: vvcdec.h:120
VVCSH
Definition: vvc_ps.h:228
VVCContext::temporal_id
int temporal_id
temporal_id_plus1 - 1
Definition: vvcdec.h:203
VVCFrameContext::vertical_bs
uint8_t * vertical_bs[VVC_MAX_SAMPLE_ARRAYS]
Definition: vvcdec.h:159
VVCFrameContext::ft
struct VVCFrameThread * ft
Definition: vvcdec.h:112
RefPicList::ref
struct HEVCFrame * ref[HEVC_MAX_REFS]
Definition: hevcdec.h:190
FFRefStructPool
FFRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition: refstruct.c:183
VVCFrameContext::slice_idx
int16_t * slice_idx
Definition: vvcdec.h:123
VVCFrameContext::log_ctx
void * log_ctx
Definition: vvcdec.h:93
VVCFrameContext::vdsp
VideoDSPContext vdsp
Definition: vvcdec.h:110
VVCContext::nb_frames
uint64_t nb_frames
processed frames
Definition: vvcdec.h:225
CTU
Definition: vvc_ctu.h:328
AVExecutor
Definition: executor.c:49
VVCFrameContext::bs_height
int bs_height
Definition: vvcdec.h:189
VVCFrameContext::pic_size_in_min_pu
int pic_size_in_min_pu
Definition: vvcdec.h:180
VVCFrameContext::vvcdsp
VVCDSPContext vvcdsp
Definition: vvcdec.h:109
SliceContext::eps
struct EntryPoint * eps
Definition: vvcdec.h:86
VVCFrameContext::alf_pixel_buffer_h
uint8_t * alf_pixel_buffer_h[VVC_MAX_SAMPLE_ARRAYS][2]
Definition: vvcdec.h:167
VVCFrameContext::horizontal_bs
uint8_t * horizontal_bs[VVC_MAX_SAMPLE_ARRAYS]
Definition: vvcdec.h:158
RefPicListTab
Definition: hevcdec.h:196
VVCContext::current_frame
CodedBitstreamFragment current_frame
Definition: vvcdec.h:199
VVCContext::eos
int eos
current packet contains an EOS/EOB NAL
Definition: vvcdec.h:206
VVCFrameContext::nb_slices_allocated
int nb_slices_allocated
Definition: vvcdec.h:105
VVCFrame::sequence
uint16_t sequence
A sequence counter, so that old frames are output first after a POC reset.
Definition: vvcdec.h:76
SliceContext
Definition: mss12.h:70
VVCFrameContext::horizontal_p
uint8_t * horizontal_p
horizontal maxFilterLengthPs for luma
Definition: vvcdec.h:160
VVCFrameContext::ctu_width
int ctu_width
Definition: vvcdec.h:182
RefPicList::isLongTerm
int isLongTerm[HEVC_MAX_REFS]
Definition: hevcdec.h:192
VVCFrameContext::sao_pixel_buffer_v
uint8_t * sao_pixel_buffer_v[VVC_MAX_SAMPLE_ARRAYS]
Definition: vvcdec.h:166
VVCContext::gdr_recovery_point_poc
int gdr_recovery_point_poc
recoveryPointPocVal
Definition: vvcdec.h:211
VVCFrameContext::coeffs
int * coeffs
Definition: vvcdec.h:170
SliceContext::ref
void * ref
RefStruct reference, backing slice data.
Definition: vvcdec.h:89
MvField
Definition: hevcdec.h:300
VVCFrameContext::height
int height
Definition: vvcdec.h:185
VVCFrame
Definition: vvcdec.h:56
VVCFrameContext::cu_pool
struct FFRefStructPool * cu_pool
Definition: vvcdec.h:119
VVCFrame::tab_dmvr_mvf
struct MvField * tab_dmvr_mvf
RefStruct reference.
Definition: vvcdec.h:59
VVCFrameContext::mvf
struct MvField * mvf
MvDmvrL0, MvDmvrL1.
Definition: vvcdec.h:148
vvc.h
SliceContext::nb_eps
int nb_eps
Definition: vvcdec.h:87
VVCFrame::nb_rpl_elems
int nb_rpl_elems
Definition: vvcdec.h:62
VVCFrame::progress
struct FrameProgress * progress
RefStruct reference.
Definition: vvcdec.h:70
VVC_MAX_REF_ENTRIES
@ VVC_MAX_REF_ENTRIES
Definition: vvc.h:115
VVCFrameContext::ibc_vir_buf
uint8_t * ibc_vir_buf[VVC_MAX_SAMPLE_ARRAYS]
IbcVirBuf[].
Definition: vvcdec.h:173
VVCFrameContext::sz
struct VVCFrameContext::@228::@229 sz
VVCFrameContext::cqt_depth
uint8_t * cqt_depth[2]
CqtDepth[][][].
Definition: vvcdec.h:133
VVCContext::nb_delayed
int nb_delayed
delayed frames
Definition: vvcdec.h:226
EntryPoint
Definition: vvc_ctu.h:349
SAOParams
Definition: hevcdsp.h:34
VVCFrameContext::cb_height
uint8_t * cb_height[2]
CbHeight[][][].
Definition: vvcdec.h:132
VVCFrameContext::tb_height
uint8_t * tb_height[2]
Definition: vvcdec.h:155
VVCFrameContext::width
int width
Definition: vvcdec.h:184
VVCFrame::frame
struct AVFrame * frame
Definition: vvcdec.h:57
VVCFrameContext::horizontal_q
uint8_t * horizontal_q
horizontal maxFilterLengthQs for luma
Definition: vvcdec.h:161
VVCContext::ps
VVCParamSets ps
Definition: vvcdec.h:201
AVCodecContext
main external API structure.
Definition: avcodec.h:445
VVCFrame::poc
int poc
Definition: vvcdec.h:66
VVCFrameContext::rpl_tab_pool
struct FFRefStructPool * rpl_tab_pool
Definition: vvcdec.h:117
FrameProgress
Definition: vvc_refs.c:37
RefPicList::list
int list[HEVC_MAX_REFS]
Definition: hevcdec.h:191
VideoDSPContext
Definition: videodsp.h:40
VVCContext::fcs
VVCFrameContext * fcs
Definition: vvcdec.h:222
VVCFrameContext::qp
int8_t * qp[VVC_MAX_SAMPLE_ARRAYS]
Definition: vvcdec.h:134
ALFParams
Definition: vvc_ctu.h:459
VVCFrameContext::imm
uint8_t * imm
intra_mip_mode[][]
Definition: vvcdec.h:141
Mv
Definition: hevcdec.h:295
VVCFrameContext::ps
VVCFrameParamSets ps
Definition: vvcdec.h:101
VVCParamSets
Definition: vvc_ps.h:211
VVC_MAX_SAMPLE_ARRAYS
@ VVC_MAX_SAMPLE_ARRAYS
Definition: vvc.h:77
VVCFrameContext::pic_size_in_min_tu
int pic_size_in_min_tu
Definition: vvcdec.h:181
SliceContext::sh
VVCSH sh
Definition: vvcdec.h:85
VVCFrameContext::ref
VVCFrame * ref
Definition: vvcdec.h:107
VVCFrameContext::bs_width
int bs_width
Definition: vvcdec.h:188
videodsp.h
VVCFrameContext
Definition: vvcdec.h:92
VVCFrameContext::sao
struct SAOParams * sao
Definition: vvcdec.h:126
VVCFrameContext::iaf
uint8_t * iaf
InterAffineFlag[][].
Definition: vvcdec.h:145
VVCFrame::ctb_count
int ctb_count
Definition: vvcdec.h:64
VVCFrameContext::vertical_p
uint8_t * vertical_p
vertical maxFilterLengthPs for luma
Definition: vvcdec.h:162
VVCFrame::rpl_tab
RefPicListTab ** rpl_tab
RefStruct reference.
Definition: vvcdec.h:60
VVCFrameContext::tb_pos_x0
int * tb_pos_x0[2]
Definition: vvcdec.h:152
VVCFrameContext::msf
uint8_t * msf
MergeSubblockFlag[][].
Definition: vvcdec.h:144
VVCFrameContext::tb_pos_y0
int * tb_pos_y0[2]
Definition: vvcdec.h:153
VVCFrameContext::nb_slices
int nb_slices
Definition: vvcdec.h:104
VVCContext::nb_fcs
int nb_fcs
Definition: vvcdec.h:223
VVCContext
Definition: vvcdec.h:195
VVCFrameContext::skip
uint8_t * skip
CuSkipFlag[][].
Definition: vvcdec.h:136
VVCContext::poc_tid0
int poc_tid0
Definition: vvcdec.h:204
vvc_ps.h
VVCDSPContext
Definition: vvcdsp.h:158
RefPicListTab::refPicList
RefPicList refPicList[2]
Definition: hevcdec.h:197
VVCFrameContext::ibc_buffer_width
int ibc_buffer_width
IbcBufWidth.
Definition: vvcdec.h:190