FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 #include "libavcodec/h274.h"
30 
31 #include "ps.h"
32 #include "dsp.h"
33 #include "sei.h"
34 
35 #define LUMA 0
36 #define CHROMA 1
37 #define CB 1
38 #define CR 2
39 #define JCBCR 3
40 
41 #define MIN_TU_LOG2 2 ///< MinTbLog2SizeY
42 #define MIN_PU_LOG2 2
43 
44 #define L0 0
45 #define L1 1
46 
47 typedef struct VVCRefPic {
48  struct VVCFrame *ref;
49  int poc;
50  int is_lt; // is long term reference
51 
52  // for RPR
53  int is_scaled; ///< RprConstraintsActiveFlag
54  int scale[2]; ///< RefPicScale[]
55 } VVCRefPic;
56 
57 typedef struct RefPicList {
59  int nb_refs;
60 } RefPicList;
61 
62 typedef struct RefPicListTab {
65 
66 typedef struct VVCWindow {
67  int16_t left_offset;
68  int16_t right_offset;
69  int16_t top_offset;
70  int16_t bottom_offset;
71 } VVCWindow;
72 
73 typedef struct VVCFrame {
74  struct AVFrame *frame;
76  const VVCSPS *sps; ///< RefStruct reference
77  const VVCPPS *pps; ///< RefStruct reference
78  struct MvField *tab_dmvr_mvf; ///< RefStruct reference
79  RefPicListTab **rpl_tab; ///< RefStruct reference
80  RefPicListTab *rpl; ///< RefStruct reference
81 
82  int needs_fg; ///< 1 if grain needs to be applied by the decoder
83 
85 
86  int ctb_count;
87 
88  int poc;
89 
90  //for RPR
91  VVCWindow scaling_win; ///< pps_scaling_win_left_offset * SubWithC, pps_scaling_win_right_offset * SubWithC,
92  ///< pps_scaling_win_top_offset * SubHeigtC, pps_scaling_win_bottom_offset * SubHiehgtC
93  int ref_width; ///< CurrPicScalWinWidthL
94  int ref_height; ///< CurrPicScalWinHeightL
95 
97 
98  struct FrameProgress *progress; ///< RefStruct reference
99 
100  /**
101  * A sequence counter, so that old frames are output first
102  * after a POC reset
103  */
104  uint16_t sequence;
105  /**
106  * A combination of VVC_FRAME_FLAG_*
107  */
108  uint8_t flags;
109 
110  void *hwaccel_picture_private; ///< hardware accelerator private data
111 } VVCFrame;
112 
113 typedef struct SliceContext {
116  struct EntryPoint *eps;
117  int nb_eps;
119  void *ref; ///< RefStruct reference, backing slice data
120 } SliceContext;
121 
122 typedef struct VVCFrameContext {
123  void *log_ctx;
124 
125  // +1 for the current frame
127 
128  struct AVFrame *frame;
130 
133 
137 
139 
142 
144 
145  uint64_t decode_order;
146 
149 
152 
153  struct {
154  int16_t *slice_idx;
155 
157  struct SAOParams *sao;
158  struct ALFParams *alf;
159 
160  int *cb_pos_x[2]; ///< CbPosX[][][]
161  int *cb_pos_y[2]; ///< CbPosY[][][]
162  uint8_t *cb_width[2]; ///< CbWidth[][][]
163  uint8_t *cb_height[2]; ///< CbHeight[][][]
164  uint8_t *cqt_depth[2]; ///< CqtDepth[][][]
166 
167  uint8_t *skip; ///< CuSkipFlag[][]
168  uint8_t *ispmf; ///< intra_sub_partitions_mode_flag
169  uint8_t *msm[2]; ///< MttSplitMode[][][] in 32 pixels
170  uint8_t *imf; ///< IntraMipFlag[][], intra_mip_transposed_flag[][], intra_mip_mode[][]
171  uint8_t *ipm; ///< IntraPredModeY[][]
172  uint8_t *cpm[2]; ///< CuPredMode[][][]
173  uint8_t *msf; ///< MergeSubblockFlag[][]
174  uint8_t *iaf; ///< InterAffineFlag[][]
175  uint8_t *mmi; ///< MotionModelIdc[][]
176  struct Mv *cp_mv[2]; ///< CpMvLX[][][][MAX_CONTROL_POINTS];
177  struct MvField *mvf; ///< MvDmvrL0, MvDmvrL1
178 
179  uint8_t *tu_coded_flag[VVC_MAX_SAMPLE_ARRAYS]; ///< tu_y_coded_flag[][], tu_cb_coded_flag[][], tu_cr_coded_flag[][]
180  uint8_t *tu_joint_cbcr_residual_flag; ///< tu_joint_cbcr_residual_flag[][]
181  uint8_t *tb_width[2];
182  uint8_t *tb_height[2];
183  uint8_t *pcmf[2];
184 
185  uint8_t *bs[2][VVC_MAX_SAMPLE_ARRAYS]; ///< horizontal, vertical boundary filtering strength
186  uint8_t *max_len_p[2]; ///< horizontal, vertical maxFilterLengthPs for luma
187  uint8_t *max_len_q[2]; ///< horizontal, vertical maxFilterLengthQs for luma
188 
193 
194  int *coeffs;
195  struct CTU *ctus;
196  struct CodingUnit **cus;
197 
198  uint8_t *ibc_vir_buf[VVC_MAX_SAMPLE_ARRAYS]; ///< IbcVirBuf[]
199 
200  //used in arrays_init only
201  struct {
203  int ctu_size;
209  int width;
210  int height;
213  int ibc_buffer_width; ///< IbcBufWidth
214  } sz;
215  } tab;
217 
218 typedef struct VVCContext {
220 
223 
226 
227  int temporal_id; ///< temporal_id_plus1 - 1
228  int poc_tid0;
229 
230  int eos; ///< current packet contains an EOS/EOB NAL
231  int last_eos; ///< last packet contains an EOS/EOB NAL
232 
234  int no_output_before_recovery_flag; ///< NoOutputBeforeRecoveryFlag
235  int gdr_recovery_point_poc; ///< recoveryPointPocVal
237 
238  /**
239  * Sequence counters for decoded and output frames, so that old
240  * frames are output first after a POC reset
241  */
242  uint16_t seq_decode;
243  uint16_t seq_output;
244 
246 
248  int nb_fcs;
249 
250  uint64_t nb_frames; ///< processed frames
251  int nb_delayed; ///< delayed frames
252 
254 } VVCContext ;
255 
256 #endif /* AVCODEC_VVC_DEC_H */
VVCSPS
Definition: ps.h:58
VVCContext::vcl_unit_type
enum VVCNALUnitType vcl_unit_type
Definition: dec.h:233
DBParams
Definition: hevcdec.h:351
VVCFrameContext::tb_width
uint8_t * tb_width[2]
Definition: dec.h:181
VVCWindow::right_offset
int16_t right_offset
Definition: dec.h:68
VVCContext::avctx
struct AVCodecContext * avctx
Definition: dec.h:219
VVCFrameContext::output_frame
struct AVFrame * output_frame
Definition: dec.h:129
VVCPPS
Definition: ps.h:92
VVCFrameContext::decode_order
uint64_t decode_order
Definition: dec.h:145
VVCFrameContext::frame
struct AVFrame * frame
Definition: dec.h:128
VVCFrameContext::pic_size_in_min_cb
int pic_size_in_min_cb
Definition: dec.h:204
VVCFrameContext::tu_joint_cbcr_residual_flag
uint8_t * tu_joint_cbcr_residual_flag
tu_joint_cbcr_residual_flag[][]
Definition: dec.h:180
VVCFrame::pps
const VVCPPS * pps
RefStruct reference.
Definition: dec.h:77
VVCFrameContext::ctu_count
int ctu_count
Definition: dec.h:202
VVCFrameContext::mmi
uint8_t * mmi
MotionModelIdc[][].
Definition: dec.h:175
VVCFrameContext::cpm
uint8_t * cpm[2]
CuPredMode[][][].
Definition: dec.h:172
VVCFrameContext::ispmf
uint8_t * ispmf
intra_sub_partitions_mode_flag
Definition: dec.h:168
VVCFrameContext::alf_pixel_buffer_v
uint8_t * alf_pixel_buffer_v[VVC_MAX_SAMPLE_ARRAYS][2]
Definition: dec.h:192
VVCFrameContext::cu_pool
struct AVRefStructPool * cu_pool
Definition: dec.h:150
VVCContext::last_eos
int last_eos
last packet contains an EOS/EOB NAL
Definition: dec.h:231
VVCFrameContext::ctu_size
int ctu_size
Definition: dec.h:203
VVCContext::seq_output
uint16_t seq_output
Definition: dec.h:243
VVCContext::cbc
CodedBitstreamContext * cbc
Definition: dec.h:221
sei.h
VVCFrameContext::cb_width
uint8_t * cb_width[2]
CbWidth[][][].
Definition: dec.h:162
VVCFrameContext::msm
uint8_t * msm[2]
MttSplitMode[][][] in 32 pixels.
Definition: dec.h:169
CodingUnit
Definition: hevcdec.h:292
VVCFrameContext::ipm
uint8_t * ipm
IntraPredModeY[][].
Definition: dec.h:171
H274HashContext
Definition: h274.c:866
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
VVCFrameContext::deblock
DBParams * deblock
Definition: dec.h:156
VVCRefPic
Definition: dec.h:47
VVCFrameContext::chroma_format_idc
int chroma_format_idc
Definition: dec.h:211
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:226
VVCFrameContext::cus
struct CodingUnit ** cus
Definition: dec.h:196
VVCFrameContext::tu_pool
struct AVRefStructPool * tu_pool
Definition: dec.h:151
VVCFrame::collocated_ref
struct VVCFrame * collocated_ref
Definition: dec.h:96
DPB
Decoded Picture Buffer (DPB).
Definition: vaapi_h264.c:82
RefPicList
Definition: hevcdec.h:196
VVCRefPic::ref
struct VVCFrame * ref
Definition: dec.h:48
VVCFrameContext::slices
SliceContext ** slices
Definition: dec.h:134
VVCContext::no_output_before_recovery_flag
int no_output_before_recovery_flag
NoOutputBeforeRecoveryFlag.
Definition: dec.h:234
ps.h
VVCFrameParamSets
Definition: ps.h:229
VVCWindow::left_offset
int16_t left_offset
Definition: dec.h:67
VVCFrame::rpl
RefPicListTab * rpl
RefStruct reference.
Definition: dec.h:80
VVCFrame::ref_height
int ref_height
CurrPicScalWinHeightL.
Definition: dec.h:94
VVCNALUnitType
VVCNALUnitType
Table 5 – NAL unit type codes and NAL unit type classes in T-REC-H.266-202008.
Definition: vvc.h:28
VVCFrameContext::ctus
struct CTU * ctus
Definition: dec.h:195
SliceContext::rpl
RefPicList * rpl
Definition: dec.h:118
RefPicList::nb_refs
int nb_refs
Definition: hevcdec.h:200
VVCFrameContext::sao_pixel_buffer_h
uint8_t * sao_pixel_buffer_h[VVC_MAX_SAMPLE_ARRAYS]
Definition: dec.h:189
VVCContext::hash_ctx
H274HashContext * hash_ctx
Definition: dec.h:253
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:242
VVCFrameContext::ctu_height
int ctu_height
Definition: dec.h:208
VVCFrameContext::pcmf
uint8_t * pcmf[2]
Definition: dec.h:183
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:91
VVCFrameThread
Definition: thread.c:85
VVCFrameContext::cb_pos_y
int * cb_pos_y[2]
CbPosY[][][].
Definition: dec.h:161
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:179
RefPicList::refs
VVCRefPic refs[VVC_MAX_REF_ENTRIES]
Definition: dec.h:58
VVCFrame::flags
uint8_t flags
A combination of VVC_FRAME_FLAG_*.
Definition: dec.h:108
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:129
VVCFrameContext::cp_mv
struct Mv * cp_mv[2]
CpMvLX[][][][MAX_CONTROL_POINTS];.
Definition: dec.h:176
VVCFrameContext::pixel_shift
int pixel_shift
Definition: dec.h:212
VVCFrameContext::imf
uint8_t * imf
IntraMipFlag[][], intra_mip_transposed_flag[][], intra_mip_mode[][].
Definition: dec.h:170
FFExecutor
Definition: executor.c:56
VVCFrameContext::cb_pos_x
int * cb_pos_x[2]
CbPosX[][][].
Definition: dec.h:160
VVCFrameContext::alf
struct ALFParams * alf
Definition: dec.h:158
VVCContext::film_grain_warning_shown
int film_grain_warning_shown
Definition: dec.h:236
SliceContext::slice_idx
int slice_idx
Definition: dec.h:114
VVCFrameContext::tab_dmvr_mvf_pool
struct AVRefStructPool * tab_dmvr_mvf_pool
Definition: dec.h:147
VVCContext::h274db
H274FilmGrainDatabase h274db
Definition: dec.h:225
VVCSH
Definition: ps.h:238
VVCFrameContext::max_len_p
uint8_t * max_len_p[2]
horizontal, vertical maxFilterLengthPs for luma
Definition: dec.h:186
VVCContext::temporal_id
int temporal_id
temporal_id_plus1 - 1
Definition: dec.h:227
AVRefStructPool
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition: refstruct.c:183
VVCFrameContext::ft
struct VVCFrameThread * ft
Definition: dec.h:143
VVCWindow
Definition: dec.h:66
VVCFrameContext::slice_idx
int16_t * slice_idx
Definition: dec.h:154
VVCFrameContext::log_ctx
void * log_ctx
Definition: dec.h:123
VVCFrameContext::vdsp
VideoDSPContext vdsp
Definition: dec.h:141
VVCContext::nb_frames
uint64_t nb_frames
processed frames
Definition: dec.h:250
CTU
Definition: ctu.h:343
VVCFrameContext::pic_size_in_min_pu
int pic_size_in_min_pu
Definition: dec.h:205
VVCFrameContext::vvcdsp
VVCDSPContext vvcdsp
Definition: dec.h:140
SliceContext::eps
struct EntryPoint * eps
Definition: dec.h:116
VVCFrameContext::alf_pixel_buffer_h
uint8_t * alf_pixel_buffer_h[VVC_MAX_SAMPLE_ARRAYS][2]
Definition: dec.h:191
VVCFrame::hwaccel_picture_private
void * hwaccel_picture_private
hardware accelerator private data
Definition: dec.h:110
VVCFrameContext::max_len_q
uint8_t * max_len_q[2]
horizontal, vertical maxFilterLengthQs for luma
Definition: dec.h:187
RefPicListTab
Definition: hevcdec.h:203
h274.h
VVCContext::current_frame
CodedBitstreamFragment current_frame
Definition: dec.h:222
VVCRefPic::is_scaled
int is_scaled
RprConstraintsActiveFlag.
Definition: dec.h:53
VVCRefPic::is_lt
int is_lt
Definition: dec.h:50
VVCContext::eos
int eos
current packet contains an EOS/EOB NAL
Definition: dec.h:230
VVCFrameContext::nb_slices_allocated
int nb_slices_allocated
Definition: dec.h:136
VVCFrame::sequence
uint16_t sequence
A sequence counter, so that old frames are output first after a POC reset.
Definition: dec.h:104
SliceContext
Definition: mss12.h:70
VVCSEI
Definition: sei.h:36
VVCFrameContext::ctu_width
int ctu_width
Definition: dec.h:207
H274FilmGrainDatabase
Definition: h274.h:34
VVCFrameContext::tab
struct VVCFrameContext::@324 tab
VVCFrameContext::sz
struct VVCFrameContext::@324::@325 sz
VVCFrameContext::sao_pixel_buffer_v
uint8_t * sao_pixel_buffer_v[VVC_MAX_SAMPLE_ARRAYS]
Definition: dec.h:190
VVCContext::gdr_recovery_point_poc
int gdr_recovery_point_poc
recoveryPointPocVal
Definition: dec.h:235
VVCFrameContext::coeffs
int * coeffs
Definition: dec.h:194
VVC_MAX_DPB_SIZE
@ VVC_MAX_DPB_SIZE
Definition: vvc.h:109
VVCWindow::bottom_offset
int16_t bottom_offset
Definition: dec.h:70
VVCRefPic::poc
int poc
Definition: dec.h:49
SliceContext::ref
void * ref
RefStruct reference, backing slice data.
Definition: dec.h:119
MvField
Definition: hevcdec.h:310
VVCFrameContext::height
int height
Definition: dec.h:210
VVCFrame
Definition: dec.h:73
VVCFrame::tab_dmvr_mvf
struct MvField * tab_dmvr_mvf
RefStruct reference.
Definition: dec.h:78
VVCFrameContext::mvf
struct MvField * mvf
MvDmvrL0, MvDmvrL1.
Definition: dec.h:177
VVCFrame::needs_fg
int needs_fg
1 if grain needs to be applied by the decoder
Definition: dec.h:82
vvc.h
SliceContext::nb_eps
int nb_eps
Definition: dec.h:117
VVCFrame::nb_rpl_elems
int nb_rpl_elems
Definition: dec.h:84
VVCFrame::progress
struct FrameProgress * progress
RefStruct reference.
Definition: dec.h:98
VVCFrameContext::ibc_vir_buf
uint8_t * ibc_vir_buf[VVC_MAX_SAMPLE_ARRAYS]
IbcVirBuf[].
Definition: dec.h:198
VVCFrameContext::cqt_depth
uint8_t * cqt_depth[2]
CqtDepth[][][].
Definition: dec.h:164
VVCContext::nb_delayed
int nb_delayed
delayed frames
Definition: dec.h:251
EntryPoint
Definition: ctu.h:363
VVC_MAX_SAMPLE_ARRAYS
@ VVC_MAX_SAMPLE_ARRAYS
Definition: vvc.h:77
SAOParams
Definition: dsp.h:34
VVCFrameContext::cb_height
uint8_t * cb_height[2]
CbHeight[][][].
Definition: dec.h:163
VVCContext::executor
struct FFExecutor * executor
Definition: dec.h:245
VVCFrameContext::tb_height
uint8_t * tb_height[2]
Definition: dec.h:182
VVCFrameContext::width
int width
Definition: dec.h:209
VVCFrame::frame
struct AVFrame * frame
Definition: dec.h:74
VVCContext::ps
VVCParamSets ps
Definition: dec.h:224
VVCFrameContext::rpl_tab_pool
struct AVRefStructPool * rpl_tab_pool
Definition: dec.h:148
VVCFrameContext::bs
uint8_t * bs[2][VVC_MAX_SAMPLE_ARRAYS]
horizontal, vertical boundary filtering strength
Definition: dec.h:185
AVCodecContext
main external API structure.
Definition: avcodec.h:431
VVCFrame::frame_grain
struct AVFrame * frame_grain
Definition: dec.h:75
VVCFrame::poc
int poc
Definition: dec.h:88
FrameProgress
Definition: refs.c:35
VideoDSPContext
Definition: videodsp.h:40
VVCContext::fcs
VVCFrameContext * fcs
Definition: dec.h:247
VVCFrameContext::qp
int8_t * qp[VVC_MAX_SAMPLE_ARRAYS]
Definition: dec.h:165
ALFParams
Definition: ctu.h:472
Mv
Definition: hevcdec.h:305
VVCFrameContext::ps
VVCFrameParamSets ps
Definition: dec.h:131
VVCParamSets
Definition: ps.h:218
VVCFrameContext::pic_size_in_min_tu
int pic_size_in_min_tu
Definition: dec.h:206
SliceContext::sh
VVCSH sh
Definition: dec.h:115
VVCFrameContext::ref
VVCFrame * ref
Definition: dec.h:138
videodsp.h
VVCFrameContext
Definition: dec.h:122
VVCFrameContext::sei
VVCSEI sei
Definition: dec.h:132
VVCFrameContext::sao
struct SAOParams * sao
Definition: dec.h:157
VVCWindow::top_offset
int16_t top_offset
Definition: dec.h:69
VVCFrameContext::iaf
uint8_t * iaf
InterAffineFlag[][].
Definition: dec.h:174
VVCFrame::ctb_count
int ctb_count
Definition: dec.h:86
VVCFrame::rpl_tab
RefPicListTab ** rpl_tab
RefStruct reference.
Definition: dec.h:79
VVCFrameContext::msf
uint8_t * msf
MergeSubblockFlag[][].
Definition: dec.h:173
VVCFrame::ref_width
int ref_width
CurrPicScalWinWidthL.
Definition: dec.h:93
VVCFrameContext::nb_slices
int nb_slices
Definition: dec.h:135
VVC_MAX_REF_ENTRIES
@ VVC_MAX_REF_ENTRIES
Definition: vvc.h:115
VVCFrame::sps
const VVCSPS * sps
RefStruct reference.
Definition: dec.h:76
VVCContext::nb_fcs
int nb_fcs
Definition: dec.h:248
VVCRefPic::scale
int scale[2]
RefPicScale[].
Definition: dec.h:54
VVCContext
Definition: dec.h:218
VVCFrameContext::skip
uint8_t * skip
CuSkipFlag[][].
Definition: dec.h:167
VVCContext::poc_tid0
int poc_tid0
Definition: dec.h:228
VVCDSPContext
Definition: dsp.h:170
RefPicListTab::refPicList
RefPicList refPicList[2]
Definition: hevcdec.h:204
VVCFrameContext::ibc_buffer_width
int ibc_buffer_width
IbcBufWidth.
Definition: dec.h:213