FFmpeg
dec.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_DEC_H
25 #define AVCODEC_VVC_DEC_H
26 
27 #include "libavcodec/videodsp.h"
28 #include "libavcodec/vvc.h"
29 
30 #include "ps.h"
31 #include "dsp.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 VVCRefPic {
46  struct VVCFrame *ref;
47  int poc;
48  int is_lt; // is long term reference
49 
50  // for RPR
51  int is_scaled; ///< RprConstraintsActiveFlag
52  int scale[2]; ///< RefPicScale[]
53 } VVCRefPic;
54 
55 typedef struct RefPicList {
57  int nb_refs;
58 } RefPicList;
59 
60 typedef struct RefPicListTab {
63 
64 typedef struct VVCWindow {
65  int16_t left_offset;
66  int16_t right_offset;
67  int16_t top_offset;
68  int16_t bottom_offset;
69 } VVCWindow;
70 
71 typedef struct VVCFrame {
72  struct AVFrame *frame;
73 
74  const VVCSPS *sps; ///< RefStruct reference
75  const VVCPPS *pps; ///< RefStruct reference
76  struct MvField *tab_dmvr_mvf; ///< RefStruct reference
77  RefPicListTab **rpl_tab; ///< RefStruct reference
78  RefPicListTab *rpl; ///< RefStruct reference
80 
81  int ctb_count;
82 
83  int poc;
84 
85  //for RPR
86  VVCWindow scaling_win; ///< pps_scaling_win_left_offset * SubWithC, pps_scaling_win_right_offset * SubWithC,
87  ///< pps_scaling_win_top_offset * SubHeigtC, pps_scaling_win_bottom_offset * SubHiehgtC
88  int ref_width; ///< CurrPicScalWinWidthL
89  int ref_height; ///< CurrPicScalWinHeightL
90 
92 
93  struct FrameProgress *progress; ///< RefStruct reference
94 
95  /**
96  * A sequence counter, so that old frames are output first
97  * after a POC reset
98  */
99  uint16_t sequence;
100  /**
101  * A combination of VVC_FRAME_FLAG_*
102  */
103  uint8_t flags;
104 } VVCFrame;
105 
106 typedef struct SliceContext {
109  struct EntryPoint *eps;
110  int nb_eps;
112  void *ref; ///< RefStruct reference, backing slice data
113 } SliceContext;
114 
115 typedef struct VVCFrameContext {
116  void *log_ctx;
117 
118  // +1 for the current frame
120 
121  struct AVFrame *frame;
123 
125 
129 
131 
134 
136 
137  uint64_t decode_order;
138 
141 
144 
145  struct {
146  int16_t *slice_idx;
147 
149  struct SAOParams *sao;
150  struct ALFParams *alf;
151 
152  int *cb_pos_x[2]; ///< CbPosX[][][]
153  int *cb_pos_y[2]; ///< CbPosY[][][]
154  uint8_t *cb_width[2]; ///< CbWidth[][][]
155  uint8_t *cb_height[2]; ///< CbHeight[][][]
156  uint8_t *cqt_depth[2]; ///< CqtDepth[][][]
158 
159  uint8_t *skip; ///< CuSkipFlag[][]
160  uint8_t *ispmf; ///< intra_sub_partitions_mode_flag
161  uint8_t *msm[2]; ///< MttSplitMode[][][] in 32 pixels
162  uint8_t *imf; ///< IntraMipFlag[][]
163  uint8_t *imtf; ///< intra_mip_transposed_flag[][]
164  uint8_t *imm; ///< intra_mip_mode[][]
165  uint8_t *ipm; ///< IntraPredModeY[][]
166  uint8_t *cpm[2]; ///< CuPredMode[][][]
167  uint8_t *msf; ///< MergeSubblockFlag[][]
168  uint8_t *iaf; ///< InterAffineFlag[][]
169  uint8_t *mmi; ///< MotionModelIdc[][]
170  struct Mv *cp_mv[2]; ///< CpMvLX[][][][MAX_CONTROL_POINTS];
171  struct MvField *mvf; ///< MvDmvrL0, MvDmvrL1
172 
173  uint8_t *tu_coded_flag[VVC_MAX_SAMPLE_ARRAYS]; ///< tu_y_coded_flag[][], tu_cb_coded_flag[][], tu_cr_coded_flag[][]
174  uint8_t *tu_joint_cbcr_residual_flag; ///< tu_joint_cbcr_residual_flag[][]
175  int *tb_pos_x0[2];
176  int *tb_pos_y0[2];
177  uint8_t *tb_width[2];
178  uint8_t *tb_height[2];
179  uint8_t *pcmf[2];
180 
183  uint8_t *horizontal_p; ///< horizontal maxFilterLengthPs for luma
184  uint8_t *horizontal_q; ///< horizontal maxFilterLengthQs for luma
185  uint8_t *vertical_p; ///< vertical maxFilterLengthPs for luma
186  uint8_t *vertical_q; ///< vertical maxFilterLengthQs for luma
187 
192 
193  int *coeffs;
194  struct CTU *ctus;
195 
196  uint8_t *ibc_vir_buf[VVC_MAX_SAMPLE_ARRAYS]; ///< IbcVirBuf[]
197 
198  //used in arrays_init only
199  struct {
201  int ctu_size;
207  int width;
208  int height;
211  int bs_width;
213  int ibc_buffer_width; ///< IbcBufWidth
214  } sz;
215  } tab;
217 
218 typedef struct VVCContext {
220 
223 
225 
226  int temporal_id; ///< temporal_id_plus1 - 1
227  int poc_tid0;
228 
229  int eos; ///< current packet contains an EOS/EOB NAL
230  int last_eos; ///< last packet contains an EOS/EOB NAL
231 
233  int no_output_before_recovery_flag; ///< NoOutputBeforeRecoveryFlag
234  int gdr_recovery_point_poc; ///< recoveryPointPocVal
235 
236  /**
237  * Sequence counters for decoded and output frames, so that old
238  * frames are output first after a POC reset
239  */
240  uint16_t seq_decode;
241  uint16_t seq_output;
242 
244 
246  int nb_fcs;
247 
248  uint64_t nb_frames; ///< processed frames
249  int nb_delayed; ///< delayed frames
250 } VVCContext ;
251 
252 #endif /* AVCODEC_VVC_DEC_H */
VVCSPS
Definition: ps.h:58
VVCContext::vcl_unit_type
enum VVCNALUnitType vcl_unit_type
Definition: dec.h:232
DBParams
Definition: hevcdec.h:344
VVCFrameContext::tb_width
uint8_t * tb_width[2]
Definition: dec.h:177
VVCFrameContext::vertical_q
uint8_t * vertical_q
vertical maxFilterLengthQs for luma
Definition: dec.h:186
VVCWindow::right_offset
int16_t right_offset
Definition: dec.h:66
VVCContext::avctx
struct AVCodecContext * avctx
Definition: dec.h:219
VVCFrameContext::output_frame
struct AVFrame * output_frame
Definition: dec.h:122
VVCPPS
Definition: ps.h:92
VVCFrameContext::decode_order
uint64_t decode_order
Definition: dec.h:137
VVCFrameContext::frame
struct AVFrame * frame
Definition: dec.h:121
VVCFrameContext::pic_size_in_min_cb
int pic_size_in_min_cb
Definition: dec.h:202
VVCFrameContext::tu_joint_cbcr_residual_flag
uint8_t * tu_joint_cbcr_residual_flag
tu_joint_cbcr_residual_flag[][]
Definition: dec.h:174
VVCFrame::pps
const VVCPPS * pps
RefStruct reference.
Definition: dec.h:75
VVCFrameContext::ctu_count
int ctu_count
Definition: dec.h:200
VVCFrameContext::mmi
uint8_t * mmi
MotionModelIdc[][].
Definition: dec.h:169
VVCFrameContext::cpm
uint8_t * cpm[2]
CuPredMode[][][].
Definition: dec.h:166
VVCFrameContext::ispmf
uint8_t * ispmf
intra_sub_partitions_mode_flag
Definition: dec.h:160
VVCFrameContext::alf_pixel_buffer_v
uint8_t * alf_pixel_buffer_v[VVC_MAX_SAMPLE_ARRAYS][2]
Definition: dec.h:191
VVCContext::last_eos
int last_eos
last packet contains an EOS/EOB NAL
Definition: dec.h:230
VVCFrameContext::ctu_size
int ctu_size
Definition: dec.h:201
VVCContext::seq_output
uint16_t seq_output
Definition: dec.h:241
VVCContext::cbc
CodedBitstreamContext * cbc
Definition: dec.h:221
VVCFrameContext::cb_width
uint8_t * cb_width[2]
CbWidth[][][].
Definition: dec.h:154
VVCFrameContext::msm
uint8_t * msm[2]
MttSplitMode[][][] in 32 pixels.
Definition: dec.h:161
VVCFrameContext::ipm
uint8_t * ipm
IntraPredModeY[][].
Definition: dec.h:165
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
VVCFrameContext::deblock
DBParams * deblock
Definition: dec.h:148
VVCRefPic
Definition: dec.h:45
VVCFrameContext::chroma_format_idc
int chroma_format_idc
Definition: dec.h:209
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
VVCFrame::collocated_ref
struct VVCFrame * collocated_ref
Definition: dec.h:91
DPB
Decoded Picture Buffer (DPB).
Definition: vaapi_h264.c:82
RefPicList
Definition: hevcdec.h:190
VVCRefPic::ref
struct VVCFrame * ref
Definition: dec.h:46
VVCFrameContext::slices
SliceContext ** slices
Definition: dec.h:126
VVCContext::no_output_before_recovery_flag
int no_output_before_recovery_flag
NoOutputBeforeRecoveryFlag.
Definition: dec.h:233
ps.h
VVCFrameParamSets
Definition: ps.h:222
VVCWindow::left_offset
int16_t left_offset
Definition: dec.h:65
VVCFrame::rpl
RefPicListTab * rpl
RefStruct reference.
Definition: dec.h:78
VVCFrame::ref_height
int ref_height
CurrPicScalWinHeightL.
Definition: dec.h:89
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: dec.h:243
VVCFrameContext::ctus
struct CTU * ctus
Definition: dec.h:194
SliceContext::rpl
RefPicList * rpl
Definition: dec.h:111
RefPicList::nb_refs
int nb_refs
Definition: hevcdec.h:194
VVCFrameContext::sao_pixel_buffer_h
uint8_t * sao_pixel_buffer_h[VVC_MAX_SAMPLE_ARRAYS]
Definition: dec.h:188
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: dec.h:240
VVCFrameContext::ctu_height
int ctu_height
Definition: dec.h:206
VVCFrameContext::pcmf
uint8_t * pcmf[2]
Definition: dec.h:179
VVCFrame::scaling_win
VVCWindow scaling_win
pps_scaling_win_left_offset * SubWithC, pps_scaling_win_right_offset * SubWithC, pps_scaling_win_top_...
Definition: dec.h:86
VVCFrameThread
Definition: thread.c:83
VVCFrameContext::cb_pos_y
int * cb_pos_y[2]
CbPosY[][][].
Definition: dec.h:153
dsp.h
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: dec.h:173
RefPicList::refs
VVCRefPic refs[VVC_MAX_REF_ENTRIES]
Definition: dec.h:56
VVCFrame::flags
uint8_t flags
A combination of VVC_FRAME_FLAG_*.
Definition: dec.h:103
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: dec.h:170
VVCFrameContext::pixel_shift
int pixel_shift
Definition: dec.h:210
VVCFrameContext::imf
uint8_t * imf
IntraMipFlag[][].
Definition: dec.h:162
VVCFrameContext::cb_pos_x
int * cb_pos_x[2]
CbPosX[][][].
Definition: dec.h:152
VVCFrameContext::tab_dmvr_mvf_pool
struct FFRefStructPool * tab_dmvr_mvf_pool
Definition: dec.h:139
VVCFrameContext::alf
struct ALFParams * alf
Definition: dec.h:150
SliceContext::slice_idx
int slice_idx
Definition: dec.h:107
VVCFrameContext::imtf
uint8_t * imtf
intra_mip_transposed_flag[][]
Definition: dec.h:163
VVCFrameContext::tu_pool
struct FFRefStructPool * tu_pool
Definition: dec.h:143
VVC_MAX_REF_ENTRIES
@ VVC_MAX_REF_ENTRIES
Definition: vvc.h:115
VVCSH
Definition: ps.h:231
VVCContext::temporal_id
int temporal_id
temporal_id_plus1 - 1
Definition: dec.h:226
VVCFrameContext::vertical_bs
uint8_t * vertical_bs[VVC_MAX_SAMPLE_ARRAYS]
Definition: dec.h:182
VVCFrameContext::ft
struct VVCFrameThread * ft
Definition: dec.h:135
VVCWindow
Definition: dec.h:64
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: dec.h:146
VVCFrameContext::log_ctx
void * log_ctx
Definition: dec.h:116
VVCFrameContext::vdsp
VideoDSPContext vdsp
Definition: dec.h:133
VVC_MAX_DPB_SIZE
@ VVC_MAX_DPB_SIZE
Definition: vvc.h:109
VVCContext::nb_frames
uint64_t nb_frames
processed frames
Definition: dec.h:248
CTU
Definition: ctu.h:331
AVExecutor
Definition: executor.c:49
VVCFrameContext::bs_height
int bs_height
Definition: dec.h:212
VVCFrameContext::pic_size_in_min_pu
int pic_size_in_min_pu
Definition: dec.h:203
VVCFrameContext::vvcdsp
VVCDSPContext vvcdsp
Definition: dec.h:132
SliceContext::eps
struct EntryPoint * eps
Definition: dec.h:109
VVCFrameContext::alf_pixel_buffer_h
uint8_t * alf_pixel_buffer_h[VVC_MAX_SAMPLE_ARRAYS][2]
Definition: dec.h:190
VVCFrameContext::horizontal_bs
uint8_t * horizontal_bs[VVC_MAX_SAMPLE_ARRAYS]
Definition: dec.h:181
RefPicListTab
Definition: hevcdec.h:197
VVC_MAX_SAMPLE_ARRAYS
@ VVC_MAX_SAMPLE_ARRAYS
Definition: vvc.h:77
VVCContext::current_frame
CodedBitstreamFragment current_frame
Definition: dec.h:222
VVCRefPic::is_scaled
int is_scaled
RprConstraintsActiveFlag.
Definition: dec.h:51
VVCRefPic::is_lt
int is_lt
Definition: dec.h:48
VVCContext::eos
int eos
current packet contains an EOS/EOB NAL
Definition: dec.h:229
VVCFrameContext::nb_slices_allocated
int nb_slices_allocated
Definition: dec.h:128
VVCFrame::sequence
uint16_t sequence
A sequence counter, so that old frames are output first after a POC reset.
Definition: dec.h:99
SliceContext
Definition: mss12.h:70
VVCFrameContext::horizontal_p
uint8_t * horizontal_p
horizontal maxFilterLengthPs for luma
Definition: dec.h:183
VVCFrameContext::ctu_width
int ctu_width
Definition: dec.h:205
VVCFrameContext::sao_pixel_buffer_v
uint8_t * sao_pixel_buffer_v[VVC_MAX_SAMPLE_ARRAYS]
Definition: dec.h:189
VVCContext::gdr_recovery_point_poc
int gdr_recovery_point_poc
recoveryPointPocVal
Definition: dec.h:234
VVCFrameContext::coeffs
int * coeffs
Definition: dec.h:193
VVCWindow::bottom_offset
int16_t bottom_offset
Definition: dec.h:68
VVCRefPic::poc
int poc
Definition: dec.h:47
SliceContext::ref
void * ref
RefStruct reference, backing slice data.
Definition: dec.h:112
MvField
Definition: hevcdec.h:303
VVCFrameContext::height
int height
Definition: dec.h:208
VVCFrame
Definition: dec.h:71
VVCFrameContext::cu_pool
struct FFRefStructPool * cu_pool
Definition: dec.h:142
VVCFrame::tab_dmvr_mvf
struct MvField * tab_dmvr_mvf
RefStruct reference.
Definition: dec.h:76
VVCFrameContext::mvf
struct MvField * mvf
MvDmvrL0, MvDmvrL1.
Definition: dec.h:171
VVCFrameContext::sz
struct VVCFrameContext::@267::@268 sz
vvc.h
VVCFrameContext::tab
struct VVCFrameContext::@267 tab
SliceContext::nb_eps
int nb_eps
Definition: dec.h:110
VVCFrame::nb_rpl_elems
int nb_rpl_elems
Definition: dec.h:79
VVCFrame::progress
struct FrameProgress * progress
RefStruct reference.
Definition: dec.h:93
VVCFrameContext::ibc_vir_buf
uint8_t * ibc_vir_buf[VVC_MAX_SAMPLE_ARRAYS]
IbcVirBuf[].
Definition: dec.h:196
VVCFrameContext::cqt_depth
uint8_t * cqt_depth[2]
CqtDepth[][][].
Definition: dec.h:156
VVCContext::nb_delayed
int nb_delayed
delayed frames
Definition: dec.h:249
EntryPoint
Definition: ctu.h:352
SAOParams
Definition: dsp.h:34
VVCFrameContext::cb_height
uint8_t * cb_height[2]
CbHeight[][][].
Definition: dec.h:155
VVCFrameContext::tb_height
uint8_t * tb_height[2]
Definition: dec.h:178
VVCFrameContext::width
int width
Definition: dec.h:207
VVCFrame::frame
struct AVFrame * frame
Definition: dec.h:72
VVCFrameContext::horizontal_q
uint8_t * horizontal_q
horizontal maxFilterLengthQs for luma
Definition: dec.h:184
VVCContext::ps
VVCParamSets ps
Definition: dec.h:224
AVCodecContext
main external API structure.
Definition: avcodec.h:445
VVCFrame::poc
int poc
Definition: dec.h:83
VVCFrameContext::rpl_tab_pool
struct FFRefStructPool * rpl_tab_pool
Definition: dec.h:140
FrameProgress
Definition: refs.c:37
VideoDSPContext
Definition: videodsp.h:40
VVCContext::fcs
VVCFrameContext * fcs
Definition: dec.h:245
VVCFrameContext::qp
int8_t * qp[VVC_MAX_SAMPLE_ARRAYS]
Definition: dec.h:157
ALFParams
Definition: ctu.h:459
VVCFrameContext::imm
uint8_t * imm
intra_mip_mode[][]
Definition: dec.h:164
Mv
Definition: hevcdec.h:298
VVCFrameContext::ps
VVCFrameParamSets ps
Definition: dec.h:124
VVCParamSets
Definition: ps.h:211
VVCFrameContext::pic_size_in_min_tu
int pic_size_in_min_tu
Definition: dec.h:204
SliceContext::sh
VVCSH sh
Definition: dec.h:108
VVCFrameContext::ref
VVCFrame * ref
Definition: dec.h:130
VVCFrameContext::bs_width
int bs_width
Definition: dec.h:211
videodsp.h
VVCFrameContext
Definition: dec.h:115
VVCFrameContext::sao
struct SAOParams * sao
Definition: dec.h:149
VVCWindow::top_offset
int16_t top_offset
Definition: dec.h:67
VVCFrameContext::iaf
uint8_t * iaf
InterAffineFlag[][].
Definition: dec.h:168
VVCFrame::ctb_count
int ctb_count
Definition: dec.h:81
VVCFrameContext::vertical_p
uint8_t * vertical_p
vertical maxFilterLengthPs for luma
Definition: dec.h:185
VVCFrame::rpl_tab
RefPicListTab ** rpl_tab
RefStruct reference.
Definition: dec.h:77
VVCFrameContext::tb_pos_x0
int * tb_pos_x0[2]
Definition: dec.h:175
VVCFrameContext::msf
uint8_t * msf
MergeSubblockFlag[][].
Definition: dec.h:167
VVCFrame::ref_width
int ref_width
CurrPicScalWinWidthL.
Definition: dec.h:88
VVCFrameContext::tb_pos_y0
int * tb_pos_y0[2]
Definition: dec.h:176
VVCFrameContext::nb_slices
int nb_slices
Definition: dec.h:127
VVCFrame::sps
const VVCSPS * sps
RefStruct reference.
Definition: dec.h:74
VVCContext::nb_fcs
int nb_fcs
Definition: dec.h:246
VVCRefPic::scale
int scale[2]
RefPicScale[].
Definition: dec.h:52
VVCContext
Definition: dec.h:218
VVCFrameContext::skip
uint8_t * skip
CuSkipFlag[][].
Definition: dec.h:159
VVCContext::poc_tid0
int poc_tid0
Definition: dec.h:227
VVCDSPContext
Definition: dsp.h:171
RefPicListTab::refPicList
RefPicList refPicList[2]
Definition: hevcdec.h:198
VVCFrameContext::ibc_buffer_width
int ibc_buffer_width
IbcBufWidth.
Definition: dec.h:213