FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/ctu.c
Date: 2024-10-21 19:12:57
Exec Total Coverage
Lines: 1580 1651 95.7%
Functions: 79 79 100.0%
Branches: 1339 1556 86.1%

Line Branch Exec Source
1 /*
2 * VVC CTU(Coding Tree Unit) parser
3 *
4 * Copyright (C) 2022 Nuo Mi
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "libavcodec/refstruct.h"
24
25 #include "cabac.h"
26 #include "ctu.h"
27 #include "inter.h"
28 #include "mvs.h"
29
30 #define PROF_TEMP_SIZE (PROF_BLOCK_SIZE) * sizeof(int16_t)
31
32 #define TAB_MSM(fc, depth, x, y) fc->tab.msm[(depth)][((y) >> 5) * fc->ps.pps->width32 + ((x) >> 5)]
33 #define TAB_ISPMF(fc, x, y) fc->tab.ispmf[((y) >> 6) * fc->ps.pps->width64 + ((x) >> 6)]
34
35 typedef enum VVCModeType {
36 MODE_TYPE_ALL,
37 MODE_TYPE_INTER,
38 MODE_TYPE_INTRA,
39 } VVCModeType;
40
41 1842849 static void set_tb_size(const VVCFrameContext *fc, const TransformBlock *tb)
42 {
43 1842849 const int x_tb = tb->x0 >> MIN_TU_LOG2;
44 1842849 const int y_tb = tb->y0 >> MIN_TU_LOG2;
45 1842849 const int hs = fc->ps.sps->hshift[tb->c_idx];
46 1842849 const int vs = fc->ps.sps->vshift[tb->c_idx];
47 1842849 const int is_chroma = tb->c_idx != 0;
48 1842849 const int width = FFMAX(1, tb->tb_width >> (MIN_TU_LOG2 - hs));
49 1842849 const int end = y_tb + FFMAX(1, tb->tb_height >> (MIN_TU_LOG2 - vs));
50
51
2/2
✓ Branch 0 taken 9142734 times.
✓ Branch 1 taken 1842849 times.
10985583 for (int y = y_tb; y < end; y++) {
52 9142734 const int off = y * fc->ps.pps->min_tu_width + x_tb;
53 9142734 memset(fc->tab.tb_width [is_chroma] + off, tb->tb_width, width);
54 9142734 memset(fc->tab.tb_height[is_chroma] + off, tb->tb_height, width);
55 }
56 1842849 }
57
58 2550871 static void set_tb_tab(uint8_t *tab, uint8_t v, const VVCFrameContext *fc,
59 const TransformBlock *tb)
60 {
61 2550871 const int width = tb->tb_width << fc->ps.sps->hshift[tb->c_idx];
62 2550871 const int height = tb->tb_height << fc->ps.sps->vshift[tb->c_idx];
63
64
2/2
✓ Branch 0 taken 12400048 times.
✓ Branch 1 taken 2550871 times.
14950919 for (int h = 0; h < height; h += MIN_TU_SIZE) {
65 12400048 const int y = (tb->y0 + h) >> MIN_TU_LOG2;
66 12400048 const int off = y * fc->ps.pps->min_tu_width + (tb->x0 >> MIN_TU_LOG2);
67 12400048 const int w = FFMAX(1, width >> MIN_TU_LOG2);
68 12400048 memset(tab + off, v, w);
69 }
70 2550871 }
71
72 // 8.7.1 Derivation process for quantization parameters
73 496 static int get_qp_y_pred(const VVCLocalContext *lc)
74 {
75 496 const VVCFrameContext *fc = lc->fc;
76 496 const VVCSPS *sps = fc->ps.sps;
77 496 const VVCPPS *pps = fc->ps.pps;
78 496 const CodingUnit *cu = lc->cu;
79 496 const int ctb_log2_size = sps->ctb_log2_size_y;
80 496 const int ctb_size_mask = (1 << ctb_log2_size) - 1;
81 496 const int xQg = lc->parse.cu_qg_top_left_x;
82 496 const int yQg = lc->parse.cu_qg_top_left_y;
83 496 const int min_cb_width = fc->ps.pps->min_cb_width;
84 496 const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
85 496 const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
86 496 const int rx = cu->x0 >> ctb_log2_size;
87 496 const int ry = cu->y0 >> ctb_log2_size;
88
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 496 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
496 const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == rx && (yQg >> ctb_log2_size) == ry;
89
2/4
✓ Branch 0 taken 496 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 496 times.
496 const int in_same_ctb_b = (xQg >> ctb_log2_size) == rx && ((yQg - 1) >> ctb_log2_size) == ry;
90 int qPy_pred, qPy_a, qPy_b;
91
92
2/2
✓ Branch 0 taken 248 times.
✓ Branch 1 taken 248 times.
496 if (lc->na.cand_up) {
93
2/4
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 248 times.
✗ Branch 3 not taken.
248 const int first_qg_in_ctu = !(xQg & ctb_size_mask) && !(yQg & ctb_size_mask);
94 248 const int qPy_up = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
95
3/4
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 186 times.
248 if (first_qg_in_ctu && pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg >> ctb_log2_size)
96 62 return qPy_up;
97 }
98
99 // qPy_pred
100
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 372 times.
434 qPy_pred = lc->ep->is_first_qg ? lc->sc->sh.slice_qp_y : lc->ep->qp_y;
101
102 // qPy_b
103
3/4
✓ Branch 0 taken 186 times.
✓ Branch 1 taken 248 times.
✓ Branch 2 taken 186 times.
✗ Branch 3 not taken.
434 if (!lc->na.cand_up || !in_same_ctb_b)
104 434 qPy_b = qPy_pred;
105 else
106 qPy_b = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
107
108 // qPy_a
109
3/4
✓ Branch 0 taken 372 times.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 372 times.
✗ Branch 3 not taken.
434 if (!lc->na.cand_left || !in_same_ctb_a)
110 434 qPy_a = qPy_pred;
111 else
112 qPy_a = fc->tab.qp[LUMA][(x_cb - 1) + y_cb * min_cb_width];
113
114 av_assert2(qPy_a >= -fc->ps.sps->qp_bd_offset && qPy_a <= 63);
115 av_assert2(qPy_b >= -fc->ps.sps->qp_bd_offset && qPy_b <= 63);
116
117 434 return (qPy_a + qPy_b + 1) >> 1;
118 }
119
120 7834993 static void set_cb_tab(const VVCLocalContext *lc, uint8_t *tab, const uint8_t v)
121 {
122 7834993 const VVCFrameContext *fc = lc->fc;
123 7834993 const VVCPPS *pps = fc->ps.pps;
124 7834993 const CodingUnit *cu = lc->cu;
125 7834993 const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y;
126 7834993 const int x_cb = cu->x0 >> log2_min_cb_size;
127 7834993 const int y_cb = cu->y0 >> log2_min_cb_size;
128 7834993 const int cb_width = cu->cb_width;
129 7834993 const int cb_height = cu->cb_height;
130 7834993 int x = y_cb * pps->min_cb_width + x_cb;
131
132
2/2
✓ Branch 0 taken 35253640 times.
✓ Branch 1 taken 7834993 times.
43088633 for (int y = 0; y < (cb_height >> log2_min_cb_size); y++) {
133 35253640 const int width = cb_width >> log2_min_cb_size;
134
135 35253640 memset(&tab[x], v, width);
136 35253640 x += pps->min_cb_width;
137 }
138 7834993 }
139
140 1107468 static int set_qp_y(VVCLocalContext *lc, const int x0, const int y0, const int has_qp_delta)
141 {
142 1107468 const VVCSPS *sps = lc->fc->ps.sps;
143 1107468 EntryPoint *ep = lc->ep;
144 1107468 CodingUnit *cu = lc->cu;
145 1107468 int cu_qp_delta = 0;
146
147
2/2
✓ Branch 0 taken 1079795 times.
✓ Branch 1 taken 27673 times.
1107468 if (!lc->fc->ps.pps->r->pps_cu_qp_delta_enabled_flag) {
148 1079795 ep->qp_y = lc->sc->sh.slice_qp_y;
149
6/6
✓ Branch 0 taken 27611 times.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 2963 times.
✓ Branch 3 taken 24648 times.
✓ Branch 4 taken 434 times.
✓ Branch 5 taken 2529 times.
27673 } else if (ep->is_first_qg || (lc->parse.cu_qg_top_left_x == x0 && lc->parse.cu_qg_top_left_y == y0)) {
150 496 ep->qp_y = get_qp_y_pred(lc);
151 496 ep->is_first_qg = 0;
152 }
153
154
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 1107084 times.
1107468 if (has_qp_delta) {
155 384 const int cu_qp_delta_abs = ff_vvc_cu_qp_delta_abs(lc);
156
157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 384 times.
384 if (cu_qp_delta_abs)
158 cu_qp_delta = ff_vvc_cu_qp_delta_sign_flag(lc) ? -cu_qp_delta_abs : cu_qp_delta_abs;
159
2/4
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 384 times.
384 if (cu_qp_delta > (31 + sps->qp_bd_offset / 2) || cu_qp_delta < -(32 + sps->qp_bd_offset / 2))
160 return AVERROR_INVALIDDATA;
161 384 lc->parse.is_cu_qp_delta_coded = 1;
162
163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 384 times.
384 if (cu_qp_delta) {
164 int off = sps->qp_bd_offset;
165 ep->qp_y = FFUMOD(ep->qp_y + cu_qp_delta + 64 + 2 * off, 64 + off) - off;
166 }
167 }
168
169 1107468 set_cb_tab(lc, lc->fc->tab.qp[LUMA], ep->qp_y);
170 1107468 cu->qp[LUMA] = ep->qp_y;
171
172 1107468 return 0;
173 }
174
175 1346552 static void set_qp_c_tab(const VVCLocalContext *lc, const TransformUnit *tu, const TransformBlock *tb)
176 {
177
6/6
✓ Branch 0 taken 66654 times.
✓ Branch 1 taken 1279898 times.
✓ Branch 2 taken 52920 times.
✓ Branch 3 taken 13734 times.
✓ Branch 4 taken 24580 times.
✓ Branch 5 taken 28340 times.
1346552 const int is_jcbcr = tu->joint_cbcr_residual_flag && tu->coded_flag[CB] && tu->coded_flag[CR];
178
2/2
✓ Branch 0 taken 1321972 times.
✓ Branch 1 taken 24580 times.
1346552 const int idx = is_jcbcr ? JCBCR : tb->c_idx;
179
180 1346552 set_tb_tab(lc->fc->tab.qp[tb->c_idx], lc->cu->qp[idx], lc->fc, tb);
181 1346552 }
182
183 1067743 static void set_qp_c(VVCLocalContext *lc)
184 {
185 1067743 const VVCFrameContext *fc = lc->fc;
186 1067743 const VVCSPS *sps = fc->ps.sps;
187 1067743 const VVCPPS *pps = fc->ps.pps;
188 1067743 const H266RawSliceHeader *rsh = lc->sc->sh.r;
189 1067743 CodingUnit *cu = lc->cu;
190 1067743 const int x_center = cu->x0 + cu->cb_width / 2;
191 1067743 const int y_center = cu->y0 + cu->cb_height / 2;
192 1067743 const int single_tree = cu->tree_type == SINGLE_TREE;
193
2/2
✓ Branch 0 taken 435514 times.
✓ Branch 1 taken 632229 times.
1067743 const int qp_luma = (single_tree ? lc->ep->qp_y : ff_vvc_get_qPy(fc, x_center, y_center)) + sps->qp_bd_offset;
194 1067743 const int qp_chroma = av_clip(qp_luma, 0, MAX_QP + sps->qp_bd_offset);
195 1067743 const int sh_chroma_qp_offset[] = {
196 1067743 rsh->sh_cb_qp_offset,
197 1067743 rsh->sh_cr_qp_offset,
198 1067743 rsh->sh_joint_cbcr_qp_offset,
199 };
200 int qp;
201
202
2/2
✓ Branch 0 taken 3183161 times.
✓ Branch 1 taken 1067743 times.
4250904 for (int i = CB - 1; i < CR + sps->r->sps_joint_cbcr_enabled_flag; i++) {
203 3183161 qp = sps->chroma_qp_table[i][qp_chroma];
204 3183161 qp = qp + pps->chroma_qp_offset[i] + sh_chroma_qp_offset[i] + lc->parse.chroma_qp_offset[i];
205 3183161 qp = av_clip(qp, -sps->qp_bd_offset, MAX_QP) + sps->qp_bd_offset;
206 3183161 cu->qp[i + 1] = qp;
207 }
208 1067743 }
209
210 1326571 static TransformUnit* alloc_tu(VVCFrameContext *fc, CodingUnit *cu)
211 {
212 1326571 TransformUnit *tu = ff_refstruct_pool_get(fc->tu_pool);
213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1326571 times.
1326571 if (!tu)
214 return NULL;
215
216 1326571 tu->next = NULL;
217
218
2/2
✓ Branch 0 taken 241521 times.
✓ Branch 1 taken 1085050 times.
1326571 if (cu->tus.tail)
219 241521 cu->tus.tail->next = tu;
220 else
221 1085050 cu->tus.head = tu;
222 1326571 cu->tus.tail = tu;
223
224 1326571 return tu;
225 }
226
227 1326571 static TransformUnit* add_tu(VVCFrameContext *fc, CodingUnit *cu, const int x0, const int y0, const int tu_width, const int tu_height)
228 {
229 1326571 TransformUnit *tu = alloc_tu(fc, cu);
230
231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1326571 times.
1326571 if (!tu)
232 return NULL;
233
234 1326571 tu->x0 = x0;
235 1326571 tu->y0 = y0;
236 1326571 tu->width = tu_width;
237 1326571 tu->height = tu_height;
238 1326571 tu->joint_cbcr_residual_flag = 0;
239 1326571 memset(tu->coded_flag, 0, sizeof(tu->coded_flag));
240 1326571 tu->avail[LUMA] = tu->avail[CHROMA] = 0;
241 1326571 tu->nb_tbs = 0;
242
243 1326571 return tu;
244 }
245
246 2516125 static TransformBlock* add_tb(TransformUnit *tu, VVCLocalContext *lc,
247 const int x0, const int y0, const int tb_width, const int tb_height, const int c_idx)
248 {
249 TransformBlock *tb;
250
251 2516125 tb = &tu->tbs[tu->nb_tbs++];
252 2516125 tb->has_coeffs = 0;
253 2516125 tb->x0 = x0;
254 2516125 tb->y0 = y0;
255 2516125 tb->tb_width = tb_width;
256 2516125 tb->tb_height = tb_height;
257 2516125 tb->log2_tb_width = av_log2(tb_width);
258 2516125 tb->log2_tb_height = av_log2(tb_height);
259
260 2516125 tb->max_scan_x = tb->max_scan_y = 0;
261 2516125 tb->min_scan_x = tb->min_scan_y = 0;
262
263 2516125 tb->c_idx = c_idx;
264 2516125 tb->ts = 0;
265 2516125 tb->coeffs = lc->coeffs;
266 2516125 lc->coeffs += tb_width * tb_height;
267 2516125 tu->avail[!!c_idx] = true;
268 2516125 return tb;
269 }
270
271 845421 static uint8_t tu_y_coded_flag_decode(VVCLocalContext *lc, const int is_sbt_not_coded,
272 const int sub_tu_index, const int is_isp, const int is_chroma_coded)
273 {
274 845421 uint8_t tu_y_coded_flag = 0;
275 845421 const VVCSPS *sps = lc->fc->ps.sps;
276 845421 CodingUnit *cu = lc->cu;
277
278
2/2
✓ Branch 0 taken 808115 times.
✓ Branch 1 taken 37306 times.
845421 if (!is_sbt_not_coded) {
279
4/4
✓ Branch 0 taken 667778 times.
✓ Branch 1 taken 140337 times.
✓ Branch 2 taken 49921 times.
✓ Branch 3 taken 617857 times.
808115 int has_y_coded_flag = sub_tu_index < cu->num_intra_subpartitions - 1 || !lc->parse.infer_tu_cbf_luma;
280
2/2
✓ Branch 0 taken 606169 times.
✓ Branch 1 taken 201946 times.
808115 if (!is_isp) {
281
4/4
✓ Branch 0 taken 603957 times.
✓ Branch 1 taken 2212 times.
✓ Branch 2 taken 486 times.
✓ Branch 3 taken 603471 times.
606169 const int is_large = cu->cb_width > sps->max_tb_size_y || cu->cb_height > sps->max_tb_size_y;
282
7/8
✓ Branch 0 taken 467943 times.
✓ Branch 1 taken 138226 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 467943 times.
✓ Branch 4 taken 99937 times.
✓ Branch 5 taken 38289 times.
✓ Branch 6 taken 2298 times.
✓ Branch 7 taken 97639 times.
606169 has_y_coded_flag = (cu->pred_mode == MODE_INTRA && !cu->act_enabled_flag) || is_chroma_coded || is_large;
283 }
284
2/2
✓ Branch 0 taken 698788 times.
✓ Branch 1 taken 109327 times.
808115 tu_y_coded_flag = has_y_coded_flag ? ff_vvc_tu_y_coded_flag(lc) : 1;
285 }
286
2/2
✓ Branch 0 taken 201946 times.
✓ Branch 1 taken 643475 times.
845421 if (is_isp)
287
4/4
✓ Branch 0 taken 100512 times.
✓ Branch 1 taken 101434 times.
✓ Branch 2 taken 38903 times.
✓ Branch 3 taken 61609 times.
201946 lc->parse.infer_tu_cbf_luma = lc->parse.infer_tu_cbf_luma && !tu_y_coded_flag;
288 845421 return tu_y_coded_flag;
289 }
290
291 405308 static void chroma_qp_offset_decode(VVCLocalContext *lc, const int is_128, const int is_chroma_coded)
292 {
293 405308 const VVCPPS *pps = lc->fc->ps.pps;
294 405308 const H266RawSliceHeader *rsh = lc->sc->sh.r;
295
296
4/4
✓ Branch 0 taken 402610 times.
✓ Branch 1 taken 2698 times.
✓ Branch 2 taken 146044 times.
✓ Branch 3 taken 256566 times.
405308 if ((is_128 || is_chroma_coded) &&
297
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 148742 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
148742 rsh->sh_cu_chroma_qp_offset_enabled_flag && !lc->parse.is_cu_chroma_qp_offset_coded) {
298 const int cu_chroma_qp_offset_flag = ff_vvc_cu_chroma_qp_offset_flag(lc);
299 if (cu_chroma_qp_offset_flag) {
300 int cu_chroma_qp_offset_idx = 0;
301 if (pps->r->pps_chroma_qp_offset_list_len_minus1 > 0)
302 cu_chroma_qp_offset_idx = ff_vvc_cu_chroma_qp_offset_idx(lc);
303 for (int i = CB - 1; i < JCBCR; i++)
304 lc->parse.chroma_qp_offset[i] = pps->chroma_qp_offset_list[cu_chroma_qp_offset_idx][i];
305 } else {
306 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
307 }
308 lc->parse.is_cu_chroma_qp_offset_coded = 1;
309 }
310 405308 }
311
312 1002419 static int hls_transform_unit(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height, int sub_tu_index, int ch_type)
313 {
314 1002419 VVCFrameContext *fc = lc->fc;
315 1002419 const VVCSPS *sps = fc->ps.sps;
316 1002419 const VVCPPS *pps = fc->ps.pps;
317 1002419 CodingUnit *cu = lc->cu;
318 1002419 TransformUnit *tu = add_tu(fc, cu, x0, y0, tu_width, tu_height);
319 1002419 const int min_cb_width = pps->min_cb_width;
320 1002419 const VVCTreeType tree_type = cu->tree_type;
321
4/4
✓ Branch 0 taken 1000207 times.
✓ Branch 1 taken 2212 times.
✓ Branch 2 taken 486 times.
✓ Branch 3 taken 999721 times.
1002419 const int is_128 = cu->cb_width > 64 || cu->cb_height > 64;
322 1002419 const int is_isp = cu->isp_split_type != ISP_NO_SPLIT;
323
4/4
✓ Branch 0 taken 201946 times.
✓ Branch 1 taken 800473 times.
✓ Branch 2 taken 61609 times.
✓ Branch 3 taken 140337 times.
1002419 const int is_isp_last_tu = is_isp && (sub_tu_index == cu->num_intra_subpartitions - 1);
324
4/4
✓ Branch 0 taken 74612 times.
✓ Branch 1 taken 927807 times.
✓ Branch 2 taken 37306 times.
✓ Branch 3 taken 37306 times.
1077031 const int is_sbt_not_coded = cu->sbt_flag &&
325
6/6
✓ Branch 0 taken 19540 times.
✓ Branch 1 taken 17766 times.
✓ Branch 2 taken 37306 times.
✓ Branch 3 taken 19540 times.
✓ Branch 4 taken 19540 times.
✓ Branch 5 taken 17766 times.
74612 ((sub_tu_index == 0 && cu->sbt_pos_flag) || (sub_tu_index == 1 && !cu->sbt_pos_flag));
326
6/6
✓ Branch 0 taken 405308 times.
✓ Branch 1 taken 597111 times.
✓ Branch 2 taken 381836 times.
✓ Branch 3 taken 23472 times.
✓ Branch 4 taken 20558 times.
✓ Branch 5 taken 361278 times.
1022977 const int chroma_available = tree_type != DUAL_TREE_LUMA && sps->r->sps_chroma_format_idc &&
327
2/2
✓ Branch 0 taken 5153 times.
✓ Branch 1 taken 15405 times.
20558 (!is_isp || is_isp_last_tu);
328 int ret, xc, yc, wc, hc, is_chroma_coded;
329
330
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1002419 times.
1002419 if (!tu)
331 return AVERROR_INVALIDDATA;
332
333
4/4
✓ Branch 0 taken 248310 times.
✓ Branch 1 taken 754109 times.
✓ Branch 2 taken 6935 times.
✓ Branch 3 taken 241375 times.
1002419 if (tree_type == SINGLE_TREE && is_isp_last_tu) {
334 6935 const int x_cu = x0 >> fc->ps.sps->min_cb_log2_size_y;
335 6935 const int y_cu = y0 >> fc->ps.sps->min_cb_log2_size_y;
336 6935 xc = SAMPLE_CTB(fc->tab.cb_pos_x[ch_type], x_cu, y_cu);
337 6935 yc = SAMPLE_CTB(fc->tab.cb_pos_y[ch_type], x_cu, y_cu);
338 6935 wc = SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cu, y_cu);
339 6935 hc = SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cu, y_cu);
340 } else {
341 995484 xc = x0, yc = y0, wc = tu_width, hc = tu_height;
342 }
343
344
4/4
✓ Branch 0 taken 366431 times.
✓ Branch 1 taken 635988 times.
✓ Branch 2 taken 330417 times.
✓ Branch 3 taken 36014 times.
1002419 if (chroma_available && !is_sbt_not_coded) {
345 330417 tu->coded_flag[CB] = ff_vvc_tu_cb_coded_flag(lc);
346 330417 tu->coded_flag[CR] = ff_vvc_tu_cr_coded_flag(lc, tu->coded_flag[CB]);
347 }
348
349
6/6
✓ Branch 0 taken 366431 times.
✓ Branch 1 taken 635988 times.
✓ Branch 2 taken 241689 times.
✓ Branch 3 taken 124742 times.
✓ Branch 4 taken 21702 times.
✓ Branch 5 taken 219987 times.
1002419 is_chroma_coded = chroma_available && (tu->coded_flag[CB] || tu->coded_flag[CR]);
350
351
2/2
✓ Branch 0 taken 845421 times.
✓ Branch 1 taken 156998 times.
1002419 if (tree_type != DUAL_TREE_CHROMA) {
352 int has_qp_delta;
353 845421 tu->coded_flag[LUMA] = tu_y_coded_flag_decode(lc, is_sbt_not_coded, sub_tu_index, is_isp, is_chroma_coded);
354
4/4
✓ Branch 0 taken 197929 times.
✓ Branch 1 taken 644794 times.
✓ Branch 2 taken 24069 times.
✓ Branch 3 taken 173860 times.
842723 has_qp_delta = (is_128 || tu->coded_flag[LUMA] || is_chroma_coded) &&
355
6/6
✓ Branch 0 taken 842723 times.
✓ Branch 1 taken 2698 times.
✓ Branch 2 taken 16238 times.
✓ Branch 3 taken 655323 times.
✓ Branch 4 taken 384 times.
✓ Branch 5 taken 15854 times.
1688144 pps->r->pps_cu_qp_delta_enabled_flag && !lc->parse.is_cu_qp_delta_coded;
356 845421 ret = set_qp_y(lc, x0, y0, has_qp_delta);
357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 845421 times.
845421 if (ret < 0)
358 return ret;
359 845421 add_tb(tu, lc, x0, y0, tu_width, tu_height, LUMA);
360 }
361
2/2
✓ Branch 0 taken 405308 times.
✓ Branch 1 taken 597111 times.
1002419 if (tree_type != DUAL_TREE_LUMA) {
362 405308 chroma_qp_offset_decode(lc, is_128, is_chroma_coded);
363
2/2
✓ Branch 0 taken 366431 times.
✓ Branch 1 taken 38877 times.
405308 if (chroma_available) {
364 366431 const int hs = sps->hshift[CHROMA];
365 366431 const int vs = sps->vshift[CHROMA];
366 366431 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CB);
367 366431 add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CR);
368 }
369 }
370
4/4
✓ Branch 0 taken 978007 times.
✓ Branch 1 taken 24412 times.
✓ Branch 2 taken 807773 times.
✓ Branch 3 taken 170234 times.
1002419 if (sps->r->sps_joint_cbcr_enabled_flag && ((cu->pred_mode == MODE_INTRA &&
371
4/4
✓ Branch 0 taken 718278 times.
✓ Branch 1 taken 89495 times.
✓ Branch 2 taken 699712 times.
✓ Branch 3 taken 18566 times.
807773 (tu->coded_flag[CB] || tu->coded_flag[CR])) ||
372
5/6
✓ Branch 0 taken 35165 times.
✓ Branch 1 taken 834781 times.
✓ Branch 2 taken 4217 times.
✓ Branch 3 taken 30948 times.
✓ Branch 4 taken 112278 times.
✗ Branch 5 not taken.
978007 (tu->coded_flag[CB] && tu->coded_flag[CR])) &&
373 chroma_available) {
374 112278 tu->joint_cbcr_residual_flag = ff_vvc_tu_joint_cbcr_residual_flag(lc, tu->coded_flag[1], tu->coded_flag[2]);
375 }
376
377
2/2
✓ Branch 0 taken 1578283 times.
✓ Branch 1 taken 1002419 times.
2580702 for (int i = 0; i < tu->nb_tbs; i++) {
378 1578283 TransformBlock *tb = &tu->tbs[i];
379 1578283 const int is_chroma = tb->c_idx != LUMA;
380 1578283 tb->has_coeffs = tu->coded_flag[tb->c_idx];
381
4/4
✓ Branch 0 taken 850178 times.
✓ Branch 1 taken 728105 times.
✓ Branch 2 taken 203479 times.
✓ Branch 3 taken 646699 times.
1578283 if (tb->has_coeffs && is_chroma)
382
6/6
✓ Branch 0 taken 78737 times.
✓ Branch 1 taken 124742 times.
✓ Branch 2 taken 57035 times.
✓ Branch 3 taken 21702 times.
✓ Branch 4 taken 44745 times.
✓ Branch 5 taken 12290 times.
203479 tb->has_coeffs = tb->c_idx == CB ? 1 : !(tu->coded_flag[CB] && tu->joint_cbcr_residual_flag);
383
2/2
✓ Branch 0 taken 837888 times.
✓ Branch 1 taken 740395 times.
1578283 if (tb->has_coeffs) {
384 837888 tb->ts = cu->bdpcm_flag[tb->c_idx];
385
4/4
✓ Branch 0 taken 833175 times.
✓ Branch 1 taken 4713 times.
✓ Branch 2 taken 833165 times.
✓ Branch 3 taken 10 times.
837888 if (sps->r->sps_transform_skip_enabled_flag && !cu->bdpcm_flag[tb->c_idx] &&
386
4/4
✓ Branch 0 taken 816774 times.
✓ Branch 1 taken 16391 times.
✓ Branch 2 taken 809604 times.
✓ Branch 3 taken 7170 times.
833165 tb->tb_width <= sps->max_ts_size && tb->tb_height <= sps->max_ts_size &&
387
6/6
✓ Branch 0 taken 769958 times.
✓ Branch 1 taken 39646 times.
✓ Branch 2 taken 594055 times.
✓ Branch 3 taken 175903 times.
✓ Branch 4 taken 460979 times.
✓ Branch 5 taken 133076 times.
809604 !cu->sbt_flag && (is_chroma || !is_isp)) {
388 636882 tb->ts = ff_vvc_transform_skip_flag(lc, is_chroma);
389 }
390 837888 ret = ff_vvc_residual_coding(lc, tb);
391
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 837888 times.
837888 if (ret < 0)
392 return ret;
393 837888 set_tb_tab(fc->tab.tu_coded_flag[tb->c_idx], tu->coded_flag[tb->c_idx], fc, tb);
394 }
395
2/2
✓ Branch 0 taken 1211852 times.
✓ Branch 1 taken 366431 times.
1578283 if (tb->c_idx != CR)
396 1211852 set_tb_size(fc, tb);
397
2/2
✓ Branch 0 taken 366431 times.
✓ Branch 1 taken 1211852 times.
1578283 if (tb->c_idx == CB)
398 366431 set_tb_tab(fc->tab.tu_joint_cbcr_residual_flag, tu->joint_cbcr_residual_flag, fc, tb);
399 }
400
401 1002419 return 0;
402 }
403
404 826549 static int hls_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height, int ch_type)
405 {
406 826549 const CodingUnit *cu = lc->cu;
407 826549 const VVCSPS *sps = lc->fc->ps.sps;
408 int ret;
409
410 826549 lc->parse.infer_tu_cbf_luma = 1;
411
4/4
✓ Branch 0 taken 764940 times.
✓ Branch 1 taken 61609 times.
✓ Branch 2 taken 727634 times.
✓ Branch 3 taken 37306 times.
826549 if (cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag) {
412
4/4
✓ Branch 0 taken 726104 times.
✓ Branch 1 taken 1530 times.
✓ Branch 2 taken 243 times.
✓ Branch 3 taken 725861 times.
729407 if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
413
4/4
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 243 times.
✓ Branch 2 taken 1106 times.
✓ Branch 3 taken 424 times.
1773 const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
414
2/2
✓ Branch 0 taken 1106 times.
✓ Branch 1 taken 667 times.
1773 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
415
2/2
✓ Branch 0 taken 667 times.
✓ Branch 1 taken 1106 times.
1773 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
416
417 #define TRANSFORM_TREE(x, y) do { \
418 ret = hls_transform_tree(lc, x, y, trafo_width, trafo_height, ch_type); \
419 if (ret < 0) \
420 return ret; \
421 } while (0)
422
423
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1773 times.
1773 TRANSFORM_TREE(x0, y0);
424
2/2
✓ Branch 0 taken 1106 times.
✓ Branch 1 taken 667 times.
1773 if (ver_split_first)
425
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1106 times.
1106 TRANSFORM_TREE(x0 + trafo_width, y0);
426 else
427
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 667 times.
667 TRANSFORM_TREE(x0, y0 + trafo_height);
428
429 } else {
430 725861 ret = hls_transform_unit(lc, x0, y0, tu_width, tu_height, 0, ch_type);
431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 725861 times.
725861 if (ret < 0)
432 return ret;
433
434 }
435
2/2
✓ Branch 0 taken 37306 times.
✓ Branch 1 taken 61609 times.
98915 } else if (cu->sbt_flag) {
436
2/2
✓ Branch 0 taken 19479 times.
✓ Branch 1 taken 17827 times.
37306 if (!cu->sbt_horizontal_flag) {
437 #define TRANSFORM_UNIT(x, width, idx) do { \
438 ret = hls_transform_unit(lc, x, y0, width, tu_height, idx, ch_type); \
439 if (ret < 0) \
440 return ret; \
441 } while (0)
442
443 19479 const int trafo_width = tu_width * lc->parse.sbt_num_fourths_tb0 / 4;
444
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 19479 times.
19479 TRANSFORM_UNIT(x0, trafo_width, 0);
445
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 19479 times.
19479 TRANSFORM_UNIT(x0 + trafo_width, tu_width - trafo_width, 1);
446
447 #undef TRANSFORM_UNIT
448 } else {
449 #define TRANSFORM_UNIT(y, height, idx) do { \
450 ret = hls_transform_unit(lc, x0, y, tu_width, height, idx, ch_type); \
451 if (ret < 0) \
452 return ret; \
453 } while (0)
454
455 17827 const int trafo_height = tu_height * lc->parse.sbt_num_fourths_tb0 / 4;
456
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 17827 times.
17827 TRANSFORM_UNIT(y0, trafo_height, 0);
457
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 17827 times.
17827 TRANSFORM_UNIT(y0 + trafo_height, tu_height - trafo_height, 1);
458
459 #undef TRANSFORM_UNIT
460 }
461
2/2
✓ Branch 0 taken 38154 times.
✓ Branch 1 taken 23455 times.
61609 } else if (cu->isp_split_type == ISP_HOR_SPLIT) {
462 38154 const int trafo_height = tu_height / cu->num_intra_subpartitions;
463
2/2
✓ Branch 0 taken 128776 times.
✓ Branch 1 taken 38154 times.
166930 for (int i = 0; i < cu->num_intra_subpartitions; i++) {
464 128776 ret = hls_transform_unit(lc, x0, y0 + trafo_height * i, tu_width, trafo_height, i, 0);
465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 128776 times.
128776 if (ret < 0)
466 return ret;
467 }
468
1/2
✓ Branch 0 taken 23455 times.
✗ Branch 1 not taken.
23455 } else if (cu->isp_split_type == ISP_VER_SPLIT) {
469 23455 const int trafo_width = tu_width / cu->num_intra_subpartitions;
470
2/2
✓ Branch 0 taken 73170 times.
✓ Branch 1 taken 23455 times.
96625 for (int i = 0; i < cu->num_intra_subpartitions; i++) {
471 73170 ret = hls_transform_unit(lc, x0 + trafo_width * i , y0, trafo_width, tu_height, i, 0);
472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73170 times.
73170 if (ret < 0)
473 return ret;
474 }
475 }
476
477 826549 return 0;
478 }
479
480 386257 static int skipped_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height)
481 {
482 386257 VVCFrameContext *fc = lc->fc;
483 386257 const CodingUnit *cu = lc->cu;
484 386257 const VVCSPS *sps = fc->ps.sps;
485
486
4/4
✓ Branch 0 taken 326062 times.
✓ Branch 1 taken 60195 times.
✓ Branch 2 taken 1910 times.
✓ Branch 3 taken 324152 times.
448362 if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
487
4/4
✓ Branch 0 taken 60195 times.
✓ Branch 1 taken 1910 times.
✓ Branch 2 taken 40745 times.
✓ Branch 3 taken 19450 times.
62105 const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
488
2/2
✓ Branch 0 taken 40745 times.
✓ Branch 1 taken 21360 times.
62105 const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
489
2/2
✓ Branch 0 taken 21360 times.
✓ Branch 1 taken 40745 times.
62105 const int trafo_height = !ver_split_first ? (tu_height / 2) : tu_height;
490
491 #define SKIPPED_TRANSFORM_TREE(x, y) do { \
492 int ret = skipped_transform_tree(lc, x, y, trafo_width, trafo_height); \
493 if (ret < 0) \
494 return ret; \
495 } while (0)
496
497
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62105 times.
62105 SKIPPED_TRANSFORM_TREE(x0, y0);
498
2/2
✓ Branch 0 taken 40745 times.
✓ Branch 1 taken 21360 times.
62105 if (ver_split_first)
499
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 40745 times.
40745 SKIPPED_TRANSFORM_TREE(x0 + trafo_width, y0);
500 else
501
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21360 times.
21360 SKIPPED_TRANSFORM_TREE(x0, y0 + trafo_height);
502 } else {
503 324152 TransformUnit *tu = add_tu(fc, lc->cu, x0, y0, tu_width, tu_height);
504
4/4
✓ Branch 0 taken 307641 times.
✓ Branch 1 taken 16511 times.
✓ Branch 2 taken 306845 times.
✓ Branch 3 taken 796 times.
324152 const int has_chroma = sps->r->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA;
505 324152 const int c_start = cu->tree_type == DUAL_TREE_CHROMA ? CB : LUMA;
506
2/2
✓ Branch 0 taken 306845 times.
✓ Branch 1 taken 17307 times.
324152 const int c_end = has_chroma ? VVC_MAX_SAMPLE_ARRAYS : CB;
507
508
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 324152 times.
324152 if (!tu)
509 return AVERROR_INVALIDDATA;
510
2/2
✓ Branch 0 taken 937842 times.
✓ Branch 1 taken 324152 times.
1261994 for (int i = c_start; i < c_end; i++) {
511 937842 TransformBlock *tb = add_tb(tu, lc, x0, y0, tu_width >> sps->hshift[i], tu_height >> sps->vshift[i], i);
512
2/2
✓ Branch 0 taken 630997 times.
✓ Branch 1 taken 306845 times.
937842 if (i != CR)
513 630997 set_tb_size(fc, tb);
514 }
515 }
516
517 386257 return 0;
518 }
519
520 //6.4.1 Allowed quad split process
521 //6.4.2 Allowed binary split process
522 //6.4.3 Allowed ternary split process
523 1794106 static void can_split(const VVCLocalContext *lc, int x0, int y0,int cb_width, int cb_height,
524 int mtt_depth, int depth_offset, int part_idx, VVCSplitMode last_split_mode,
525 VVCTreeType tree_type, VVCModeType mode_type, VVCAllowedSplit* split)
526 {
527 int min_qt_size, max_bt_size, max_tt_size, max_mtt_depth;
528 1794106 const VVCFrameContext *fc = lc->fc;
529 1794106 const VVCSH *sh = &lc->sc->sh;
530 1794106 const VVCSPS *sps = fc->ps.sps;
531 1794106 const VVCPPS *pps = fc->ps.pps;
532 1794106 const int chroma = tree_type == DUAL_TREE_CHROMA;
533 1794106 int min_cb_size_y = sps->min_cb_size_y;
534 1794106 int *qt = &split->qt;
535 1794106 int *btv = &split->btv;
536 1794106 int *bth = &split->bth;
537 1794106 int *ttv = &split->ttv;
538 1794106 int *tth = &split->tth;
539
540 1794106 *qt = *bth = *btv = *tth = *ttv = 1;
541
542
2/2
✓ Branch 0 taken 1361501 times.
✓ Branch 1 taken 432605 times.
1794106 if (mtt_depth)
543 1361501 *qt = 0;
544
545 1794106 min_qt_size = sh->min_qt_size[chroma];
546
2/2
✓ Branch 0 taken 669411 times.
✓ Branch 1 taken 1124695 times.
1794106 if (cb_width <= min_qt_size)
547 669411 *qt = 0;
548
549
2/2
✓ Branch 0 taken 253573 times.
✓ Branch 1 taken 1540533 times.
1794106 if (chroma) {
550 253573 int chroma_area = (cb_width >> sps->hshift[1]) * (cb_height >> sps->vshift[1]);
551 253573 int chroma_width = cb_width >> sps->hshift[1];
552
553
2/2
✓ Branch 0 taken 75596 times.
✓ Branch 1 taken 177977 times.
253573 if (chroma_width == 8)
554 75596 *ttv = 0;
555
2/2
✓ Branch 0 taken 56419 times.
✓ Branch 1 taken 121558 times.
177977 else if (chroma_width <= 4) {
556
1/2
✓ Branch 0 taken 56419 times.
✗ Branch 1 not taken.
56419 if (chroma_width == 4)
557 56419 *btv = 0;
558 56419 *qt = 0;
559 }
560
2/2
✓ Branch 0 taken 8364 times.
✓ Branch 1 taken 245209 times.
253573 if (mode_type == MODE_TYPE_INTRA)
561 8364 *qt = *btv = *bth = *ttv = *tth = 0;
562
2/2
✓ Branch 0 taken 80781 times.
✓ Branch 1 taken 172792 times.
253573 if (chroma_area <= 32) {
563 80781 *ttv = *tth = 0;
564
2/2
✓ Branch 0 taken 32240 times.
✓ Branch 1 taken 48541 times.
80781 if (chroma_area <= 16)
565 32240 *btv = *bth = 0;
566 }
567 }
568 1794106 max_bt_size = sh->max_bt_size[chroma];
569 1794106 max_tt_size = sh->max_tt_size[chroma];
570 1794106 max_mtt_depth = sh->max_mtt_depth[chroma] + depth_offset;
571
572
2/2
✓ Branch 0 taken 59865 times.
✓ Branch 1 taken 1734241 times.
1794106 if (mode_type == MODE_TYPE_INTER) {
573 59865 int area = cb_width * cb_height;
574
2/2
✓ Branch 0 taken 22852 times.
✓ Branch 1 taken 37013 times.
59865 if (area == 32)
575 22852 *btv = *bth = 0;
576
2/2
✓ Branch 0 taken 21705 times.
✓ Branch 1 taken 15308 times.
37013 else if (area == 64)
577 21705 *ttv = *tth = 0;
578 }
579
2/2
✓ Branch 0 taken 679976 times.
✓ Branch 1 taken 1114130 times.
1794106 if (cb_width <= 2 * min_cb_size_y) {
580 679976 *ttv = 0;
581
2/2
✓ Branch 0 taken 229418 times.
✓ Branch 1 taken 450558 times.
679976 if (cb_width <= min_cb_size_y)
582 229418 *btv = 0;
583 }
584
2/2
✓ Branch 0 taken 745697 times.
✓ Branch 1 taken 1048409 times.
1794106 if (cb_height <= 2 * min_cb_size_y) {
585 745697 *tth = 0;
586
2/2
✓ Branch 0 taken 266775 times.
✓ Branch 1 taken 478922 times.
745697 if (cb_height <= min_cb_size_y)
587 266775 *bth = 0;
588 }
589
4/4
✓ Branch 0 taken 1764510 times.
✓ Branch 1 taken 29596 times.
✓ Branch 2 taken 590 times.
✓ Branch 3 taken 1763920 times.
1794106 if (cb_width > max_bt_size || cb_height > max_bt_size)
590 30186 *btv = *bth = 0;
591 1794106 max_tt_size = FFMIN(64, max_tt_size);
592
4/4
✓ Branch 0 taken 1695415 times.
✓ Branch 1 taken 98691 times.
✓ Branch 2 taken 8126 times.
✓ Branch 3 taken 1687289 times.
1794106 if (cb_width > max_tt_size || cb_height > max_tt_size)
593 106817 *ttv = *tth = 0;
594
2/2
✓ Branch 0 taken 378106 times.
✓ Branch 1 taken 1416000 times.
1794106 if (mtt_depth >= max_mtt_depth)
595 378106 *btv = *bth = *ttv = *tth = 0;
596
2/2
✓ Branch 0 taken 4050 times.
✓ Branch 1 taken 1790056 times.
1794106 if (x0 + cb_width > pps->width) {
597 4050 *ttv = *tth = 0;
598
2/2
✓ Branch 0 taken 1320 times.
✓ Branch 1 taken 2730 times.
4050 if (cb_height > 64)
599 1320 *btv = 0;
600
2/2
✓ Branch 0 taken 2907 times.
✓ Branch 1 taken 1143 times.
4050 if (y0 + cb_height <= pps->height)
601 2907 *bth = 0;
602
1/2
✓ Branch 0 taken 1143 times.
✗ Branch 1 not taken.
1143 else if (cb_width > min_qt_size)
603 1143 *btv = *bth = 0;
604 }
605
2/2
✓ Branch 0 taken 48253 times.
✓ Branch 1 taken 1745853 times.
1794106 if (y0 + cb_height > pps->height) {
606 48253 *btv = *ttv = *tth = 0;
607
2/2
✓ Branch 0 taken 6171 times.
✓ Branch 1 taken 42082 times.
48253 if (cb_width > 64)
608 6171 *bth = 0;
609 }
610
4/4
✓ Branch 0 taken 1361501 times.
✓ Branch 1 taken 432605 times.
✓ Branch 2 taken 598696 times.
✓ Branch 3 taken 762805 times.
1794106 if (mtt_depth > 0 && part_idx == 1) {
611
2/2
✓ Branch 0 taken 67604 times.
✓ Branch 1 taken 531092 times.
598696 if (last_split_mode == SPLIT_TT_VER)
612 67604 *btv = 0;
613
2/2
✓ Branch 0 taken 71930 times.
✓ Branch 1 taken 459162 times.
531092 else if (last_split_mode == SPLIT_TT_HOR)
614 71930 *bth = 0;
615 }
616
4/4
✓ Branch 0 taken 1752190 times.
✓ Branch 1 taken 41916 times.
✓ Branch 2 taken 2994 times.
✓ Branch 3 taken 1749196 times.
1794106 if (cb_width <= 64 && cb_height > 64)
617 2994 *btv = 0;
618
4/4
✓ Branch 0 taken 41916 times.
✓ Branch 1 taken 1752190 times.
✓ Branch 2 taken 2954 times.
✓ Branch 3 taken 38962 times.
1794106 if (cb_width > 64 && cb_height <= 64)
619 2954 *bth = 0;
620 1794106 }
621
622 431531 static int get_num_intra_subpartitions(enum IspType isp_split_type, int cb_width, int cb_height)
623 {
624
2/2
✓ Branch 0 taken 369922 times.
✓ Branch 1 taken 61609 times.
431531 if (isp_split_type == ISP_NO_SPLIT)
625 369922 return 1;
626
8/8
✓ Branch 0 taken 14568 times.
✓ Branch 1 taken 47041 times.
✓ Branch 2 taken 4140 times.
✓ Branch 3 taken 10428 times.
✓ Branch 4 taken 21929 times.
✓ Branch 5 taken 29252 times.
✓ Branch 6 taken 11817 times.
✓ Branch 7 taken 10112 times.
61609 if ((cb_width == 4 && cb_height == 8) || (cb_width == 8 && cb_height == 4))
627 22245 return 2;
628 39364 return 4;
629 }
630
631 196941 static int get_cclm_enabled(const VVCLocalContext *lc, const int x0, const int y0)
632 {
633 196941 const VVCFrameContext *fc = lc->fc;
634 196941 const VVCSPS *sps = fc->ps.sps;
635 196941 int enabled = 0;
636
637
2/2
✓ Branch 0 taken 449 times.
✓ Branch 1 taken 196492 times.
196941 if (!sps->r->sps_cclm_enabled_flag)
638 449 return 0;
639
5/6
✓ Branch 0 taken 196492 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 148631 times.
✓ Branch 3 taken 47861 times.
✓ Branch 4 taken 1163 times.
✓ Branch 5 taken 147468 times.
196492 if (!sps->r->sps_qtbtt_dual_tree_intra_flag || !IS_I(lc->sc->sh.r) || sps->ctb_log2_size_y < 6)
640 49024 return 1;
641 else {
642 147468 const int x64 = x0 >> 6 << 6;
643 147468 const int y64 = y0 >> 6 << 6;
644 147468 const int y32 = y0 >> 5 << 5;
645 147468 const int x64_cu = x64 >> fc->ps.sps->min_cb_log2_size_y;
646 147468 const int y64_cu = y64 >> fc->ps.sps->min_cb_log2_size_y;
647 147468 const int y32_cu = y32 >> fc->ps.sps->min_cb_log2_size_y;
648 147468 const int min_cb_width = fc->ps.pps->min_cb_width;
649 147468 const int depth = SAMPLE_CTB(fc->tab.cqt_depth[1], x64_cu, y64_cu);
650 147468 const int min_depth = fc->ps.sps->ctb_log2_size_y - 6;
651 147468 const VVCSplitMode msm64 = (VVCSplitMode)TAB_MSM(fc, 0, x64, y64);
652 147468 const VVCSplitMode msm32 = (VVCSplitMode)TAB_MSM(fc, 1, x64, y32);
653
654
2/2
✓ Branch 0 taken 18431 times.
✓ Branch 1 taken 129037 times.
165899 enabled = SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y64_cu) == 64 &&
655
2/2
✓ Branch 0 taken 6475 times.
✓ Branch 1 taken 11956 times.
18431 SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y64_cu) == 64;
656
2/2
✓ Branch 0 taken 20278 times.
✓ Branch 1 taken 11757 times.
32035 enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR &&
657
4/4
✓ Branch 0 taken 32035 times.
✓ Branch 1 taken 115433 times.
✓ Branch 2 taken 11900 times.
✓ Branch 3 taken 8378 times.
191403 SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y32_cu) == 64 &&
658
2/2
✓ Branch 0 taken 4694 times.
✓ Branch 1 taken 7206 times.
11900 SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y32_cu) == 32;
659 147468 enabled |= depth > min_depth;
660
6/6
✓ Branch 0 taken 32035 times.
✓ Branch 1 taken 115433 times.
✓ Branch 2 taken 20278 times.
✓ Branch 3 taken 11757 times.
✓ Branch 4 taken 7430 times.
✓ Branch 5 taken 12848 times.
147468 enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR && msm32 == SPLIT_BT_VER;
661
662
2/2
✓ Branch 0 taken 133581 times.
✓ Branch 1 taken 13887 times.
147468 if (enabled) {
663 133581 const int w = SAMPLE_CTB(fc->tab.cb_width[0], x64_cu, y64_cu);
664 133581 const int h = SAMPLE_CTB(fc->tab.cb_height[0], x64_cu, y64_cu);
665 133581 const int depth0 = SAMPLE_CTB(fc->tab.cqt_depth[0], x64_cu, y64_cu);
666
7/8
✓ Branch 0 taken 5054 times.
✓ Branch 1 taken 128527 times.
✓ Branch 2 taken 5054 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4462 times.
✓ Branch 5 taken 592 times.
✓ Branch 6 taken 4462 times.
✓ Branch 7 taken 128527 times.
133581 if ((w == 64 && h == 64 && TAB_ISPMF(fc, x64, y64)) ||
667
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4462 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 128527 times.
132989 ((w < 64 || h < 64) && depth0 == min_depth))
668 592 return 0;
669 }
670
671 }
672
673 146876 return enabled;
674 }
675
676 699251 static int less(const void *a, const void *b)
677 {
678 699251 return *(const int*)a - *(const int*)b;
679 }
680
681 //8.4.2 Derivation process for luma intra prediction mode
682 431531 static enum IntraPredMode luma_intra_pred_mode(VVCLocalContext* lc, const int intra_subpartitions_mode_flag)
683 {
684 431531 VVCFrameContext *fc = lc->fc;
685 431531 CodingUnit *cu = lc->cu;
686 431531 const int x0 = cu->x0;
687 431531 const int y0 = cu->y0;
688 enum IntraPredMode pred;
689 431531 int intra_luma_not_planar_flag = 1;
690 431531 int intra_luma_mpm_remainder = 0;
691 431531 int intra_luma_mpm_flag = 1;
692 431531 int intra_luma_mpm_idx = 0;
693
694
2/2
✓ Branch 0 taken 401385 times.
✓ Branch 1 taken 30146 times.
431531 if (!cu->intra_luma_ref_idx)
695 401385 intra_luma_mpm_flag = ff_vvc_intra_luma_mpm_flag(lc);
696
2/2
✓ Branch 0 taken 331876 times.
✓ Branch 1 taken 99655 times.
431531 if (intra_luma_mpm_flag) {
697
2/2
✓ Branch 0 taken 301730 times.
✓ Branch 1 taken 30146 times.
331876 if (!cu->intra_luma_ref_idx)
698 301730 intra_luma_not_planar_flag = ff_vvc_intra_luma_not_planar_flag(lc, intra_subpartitions_mode_flag);
699
2/2
✓ Branch 0 taken 167864 times.
✓ Branch 1 taken 164012 times.
331876 if (intra_luma_not_planar_flag)
700 167864 intra_luma_mpm_idx = ff_vvc_intra_luma_mpm_idx(lc);
701 } else {
702 99655 intra_luma_mpm_remainder = ff_vvc_intra_luma_mpm_remainder(lc);
703 }
704
705
2/2
✓ Branch 0 taken 164012 times.
✓ Branch 1 taken 267519 times.
431531 if (!intra_luma_not_planar_flag) {
706 164012 pred = INTRA_PLANAR;
707 } else {
708 267519 const VVCSPS *sps = fc->ps.sps;
709 267519 const int x_a = (x0 - 1) >> sps->min_cb_log2_size_y;
710 267519 const int y_a = (y0 + cu->cb_height - 1) >> sps->min_cb_log2_size_y;
711 267519 const int x_b = (x0 + cu->cb_width - 1) >> sps->min_cb_log2_size_y;
712 267519 const int y_b = (y0 - 1) >> sps->min_cb_log2_size_y;
713 267519 int min_cb_width = fc->ps.pps->min_cb_width;
714 267519 int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
715 267519 int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
716
4/4
✓ Branch 0 taken 48043 times.
✓ Branch 1 taken 219476 times.
✓ Branch 2 taken 43867 times.
✓ Branch 3 taken 4176 times.
267519 const int available_l = lc->ctb_left_flag || x0b;
717
4/4
✓ Branch 0 taken 87706 times.
✓ Branch 1 taken 179813 times.
✓ Branch 2 taken 82913 times.
✓ Branch 3 taken 4793 times.
267519 const int available_u = lc->ctb_up_flag || y0b;
718
719 int a, b, cand[5];
720
721
4/4
✓ Branch 0 taken 263343 times.
✓ Branch 1 taken 4176 times.
✓ Branch 2 taken 251287 times.
✓ Branch 3 taken 12056 times.
267519 if (!available_l || (SAMPLE_CTB(fc->tab.cpm[0], x_a, y_a) != MODE_INTRA) ||
722
2/2
✓ Branch 0 taken 34605 times.
✓ Branch 1 taken 216682 times.
251287 SAMPLE_CTB(fc->tab.imf, x_a, y_a)) {
723 50837 a = INTRA_PLANAR;
724 } else {
725 216682 a = SAMPLE_CTB(fc->tab.ipm, x_a, y_a);
726 }
727
728
4/4
✓ Branch 0 taken 262726 times.
✓ Branch 1 taken 4793 times.
✓ Branch 2 taken 250679 times.
✓ Branch 3 taken 12047 times.
267519 if (!available_u || (SAMPLE_CTB(fc->tab.cpm[0], x_b, y_b) != MODE_INTRA) ||
729
4/4
✓ Branch 0 taken 215742 times.
✓ Branch 1 taken 34937 times.
✓ Branch 2 taken 13249 times.
✓ Branch 3 taken 202493 times.
250679 SAMPLE_CTB(fc->tab.imf, x_b, y_b) || !y0b) {
730 65026 b = INTRA_PLANAR;
731 } else {
732 202493 b = SAMPLE_CTB(fc->tab.ipm, x_b, y_b);
733 }
734
735
4/4
✓ Branch 0 taken 80330 times.
✓ Branch 1 taken 187189 times.
✓ Branch 2 taken 17759 times.
✓ Branch 3 taken 62571 times.
267519 if (a == b && a > INTRA_DC) {
736 17759 cand[0] = a;
737 17759 cand[1] = 2 + ((a + 61) % 64);
738 17759 cand[2] = 2 + ((a - 1) % 64);
739 17759 cand[3] = 2 + ((a + 60) % 64);
740 17759 cand[4] = 2 + (a % 64);
741 } else {
742 249760 const int minab = FFMIN(a, b);
743 249760 const int maxab = FFMAX(a, b);
744
4/4
✓ Branch 0 taken 124670 times.
✓ Branch 1 taken 125090 times.
✓ Branch 2 taken 64217 times.
✓ Branch 3 taken 60453 times.
313977 if (a > INTRA_DC && b > INTRA_DC) {
745 64217 const int diff = maxab - minab;
746 64217 cand[0] = a;
747 64217 cand[1] = b;
748
2/2
✓ Branch 0 taken 13548 times.
✓ Branch 1 taken 50669 times.
64217 if (diff == 1) {
749 13548 cand[2] = 2 + ((minab + 61) % 64);
750 13548 cand[3] = 2 + ((maxab - 1) % 64);
751 13548 cand[4] = 2 + ((minab + 60) % 64);
752
2/2
✓ Branch 0 taken 515 times.
✓ Branch 1 taken 50154 times.
50669 } else if (diff >= 62) {
753 515 cand[2] = 2 + ((minab - 1) % 64);
754 515 cand[3] = 2 + ((maxab + 61) % 64);
755 515 cand[4] = 2 + (minab % 64);
756
2/2
✓ Branch 0 taken 6057 times.
✓ Branch 1 taken 44097 times.
50154 } else if (diff == 2) {
757 6057 cand[2] = 2 + ((minab - 1) % 64);
758 6057 cand[3] = 2 + ((minab + 61) % 64);
759 6057 cand[4] = 2 + ((maxab - 1) % 64);
760 } else {
761 44097 cand[2] = 2 + ((minab + 61) % 64);
762 44097 cand[3] = 2 + ((minab - 1) % 64);
763 44097 cand[4] = 2 + ((maxab + 61) % 64);
764 }
765
4/4
✓ Branch 0 taken 125090 times.
✓ Branch 1 taken 60453 times.
✓ Branch 2 taken 49759 times.
✓ Branch 3 taken 75331 times.
185543 } else if (a > INTRA_DC || b > INTRA_DC) {
766 110212 cand[0] = maxab;
767 110212 cand[1] = 2 + ((maxab + 61 ) % 64);
768 110212 cand[2] = 2 + ((maxab - 1) % 64);
769 110212 cand[3] = 2 + ((maxab + 60 ) % 64);
770 110212 cand[4] = 2 + (maxab % 64);
771 } else {
772 75331 cand[0] = INTRA_DC;
773 75331 cand[1] = INTRA_VERT;
774 75331 cand[2] = INTRA_HORZ;
775 75331 cand[3] = INTRA_VERT - 4;
776 75331 cand[4] = INTRA_VERT + 4;
777 }
778 }
779
2/2
✓ Branch 0 taken 167864 times.
✓ Branch 1 taken 99655 times.
267519 if (intra_luma_mpm_flag) {
780 167864 pred = cand[intra_luma_mpm_idx];
781 } else {
782 99655 qsort(cand, FF_ARRAY_ELEMS(cand), sizeof(cand[0]), less);
783 99655 pred = intra_luma_mpm_remainder + 1;
784
2/2
✓ Branch 0 taken 498275 times.
✓ Branch 1 taken 99655 times.
597930 for (int i = 0; i < FF_ARRAY_ELEMS(cand); i++) {
785
2/2
✓ Branch 0 taken 244830 times.
✓ Branch 1 taken 253445 times.
498275 if (pred >= cand[i])
786 244830 pred++;
787 }
788 }
789 }
790 431531 return pred;
791 }
792
793 823003 static int lfnst_idx_decode(VVCLocalContext *lc)
794 {
795 823003 CodingUnit *cu = lc->cu;
796 823003 const VVCTreeType tree_type = cu->tree_type;
797 823003 const VVCSPS *sps = lc->fc->ps.sps;
798 823003 const int cb_width = cu->cb_width;
799 823003 const int cb_height = cu->cb_height;
800 823003 const TransformUnit *tu = cu->tus.head;
801 int lfnst_width, lfnst_height, min_lfnst;
802 823003 int lfnst_idx = 0;
803
804 823003 memset(cu->apply_lfnst_flag, 0, sizeof(cu->apply_lfnst_flag));
805
806
5/6
✓ Branch 0 taken 619048 times.
✓ Branch 1 taken 203955 times.
✓ Branch 2 taken 523975 times.
✓ Branch 3 taken 95073 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 523975 times.
823003 if (!sps->r->sps_lfnst_enabled_flag || cu->pred_mode != MODE_INTRA || FFMAX(cb_width, cb_height) > sps->max_tb_size_y)
807 299028 return 0;
808
809
2/2
✓ Branch 0 taken 630629 times.
✓ Branch 1 taken 510117 times.
1140746 while (tu) {
810
2/2
✓ Branch 0 taken 816487 times.
✓ Branch 1 taken 616771 times.
1433258 for (int j = 0; j < tu->nb_tbs; j++) {
811 816487 const TransformBlock *tb = tu->tbs + j;
812
4/4
✓ Branch 0 taken 552604 times.
✓ Branch 1 taken 263883 times.
✓ Branch 2 taken 13858 times.
✓ Branch 3 taken 538746 times.
816487 if (tu->coded_flag[tb->c_idx] && tb->ts)
813 13858 return 0;
814 }
815 616771 tu = tu->next;
816 }
817
818
2/2
✓ Branch 0 taken 120767 times.
✓ Branch 1 taken 389350 times.
510117 if (tree_type == DUAL_TREE_CHROMA) {
819 120767 lfnst_width = cb_width >> sps->hshift[1];
820 120767 lfnst_height = cb_height >> sps->vshift[1];
821 } else {
822 389350 const int vs = cu->isp_split_type == ISP_VER_SPLIT;
823 389350 const int hs = cu->isp_split_type == ISP_HOR_SPLIT;
824
2/2
✓ Branch 0 taken 17044 times.
✓ Branch 1 taken 372306 times.
389350 lfnst_width = vs ? cb_width / cu->num_intra_subpartitions : cb_width;
825
2/2
✓ Branch 0 taken 29922 times.
✓ Branch 1 taken 359428 times.
389350 lfnst_height = hs ? cb_height / cu->num_intra_subpartitions : cb_height;
826 }
827 510117 min_lfnst = FFMIN(lfnst_width, lfnst_height);
828
6/6
✓ Branch 0 taken 389350 times.
✓ Branch 1 taken 120767 times.
✓ Branch 2 taken 94493 times.
✓ Branch 3 taken 294857 times.
✓ Branch 4 taken 74841 times.
✓ Branch 5 taken 19652 times.
510117 if (tree_type != DUAL_TREE_CHROMA && cu->intra_mip_flag && min_lfnst < 16)
829 74841 return 0;
830
831
2/2
✓ Branch 0 taken 405293 times.
✓ Branch 1 taken 29983 times.
435276 if (min_lfnst >= 4) {
832
6/6
✓ Branch 0 taken 378404 times.
✓ Branch 1 taken 26889 times.
✓ Branch 2 taken 168565 times.
✓ Branch 3 taken 209839 times.
✓ Branch 4 taken 164626 times.
✓ Branch 5 taken 30828 times.
405293 if ((cu->isp_split_type != ISP_NO_SPLIT || !lc->parse.lfnst_dc_only) && lc->parse.lfnst_zero_out_sig_coeff_flag)
833 164626 lfnst_idx = ff_vvc_lfnst_idx(lc, tree_type != SINGLE_TREE);
834 }
835
836
2/2
✓ Branch 0 taken 122033 times.
✓ Branch 1 taken 313243 times.
435276 if (lfnst_idx) {
837 122033 cu->apply_lfnst_flag[LUMA] = tree_type != DUAL_TREE_CHROMA;
838 122033 cu->apply_lfnst_flag[CB] = cu->apply_lfnst_flag[CR] = tree_type == DUAL_TREE_CHROMA;
839 }
840
841 435276 return lfnst_idx;
842 }
843
844 823003 static MtsIdx mts_idx_decode(VVCLocalContext *lc)
845 {
846 823003 const CodingUnit *cu = lc->cu;
847 823003 const VVCSPS *sps = lc->fc->ps.sps;
848 823003 const int cb_width = cu->cb_width;
849 823003 const int cb_height = cu->cb_height;
850 823003 const uint8_t transform_skip_flag = cu->tus.head->tbs[0].ts; //fix me
851 823003 int mts_idx = MTS_DCT2_DCT2;
852
6/6
✓ Branch 0 taken 666005 times.
✓ Branch 1 taken 156998 times.
✓ Branch 2 taken 572290 times.
✓ Branch 3 taken 93715 times.
✓ Branch 4 taken 547039 times.
✓ Branch 5 taken 25251 times.
823003 if (cu->tree_type != DUAL_TREE_CHROMA && !cu->lfnst_idx &&
853
2/2
✓ Branch 0 taken 528513 times.
✓ Branch 1 taken 18526 times.
547039 !transform_skip_flag && FFMAX(cb_width, cb_height) <= 32 &&
854
4/4
✓ Branch 0 taken 483274 times.
✓ Branch 1 taken 45239 times.
✓ Branch 2 taken 447505 times.
✓ Branch 3 taken 35769 times.
528513 cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag &&
855
4/4
✓ Branch 0 taken 438836 times.
✓ Branch 1 taken 8669 times.
✓ Branch 2 taken 299351 times.
✓ Branch 3 taken 139485 times.
447505 lc->parse.mts_zero_out_sig_coeff_flag && !lc->parse.mts_dc_only) {
856
3/4
✓ Branch 0 taken 51885 times.
✓ Branch 1 taken 247466 times.
✓ Branch 2 taken 51885 times.
✗ Branch 3 not taken.
299351 if ((cu->pred_mode == MODE_INTER && sps->r->sps_explicit_mts_inter_enabled_flag) ||
857
4/4
✓ Branch 0 taken 247421 times.
✓ Branch 1 taken 51930 times.
✓ Branch 2 taken 244197 times.
✓ Branch 3 taken 3224 times.
299351 (cu->pred_mode == MODE_INTRA && sps->r->sps_explicit_mts_intra_enabled_flag)) {
858 244197 mts_idx = ff_vvc_mts_idx(lc);
859 }
860 }
861
862 823003 return mts_idx;
863 }
864
865 196797 static enum IntraPredMode derive_center_luma_intra_pred_mode(const VVCFrameContext *fc, const VVCSPS *sps, const VVCPPS *pps, const CodingUnit *cu)
866 {
867 196797 const int x_center = (cu->x0 + cu->cb_width / 2) >> sps->min_cb_log2_size_y;
868 196797 const int y_center = (cu->y0 + cu->cb_height / 2) >> sps->min_cb_log2_size_y;
869 196797 const int min_cb_width = pps->min_cb_width;
870 196797 const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_center, y_center);
871 196797 const int cu_pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_center, y_center);
872 196797 const int intra_pred_mode_y = SAMPLE_CTB(fc->tab.ipm, x_center, y_center);
873
874
2/2
✓ Branch 0 taken 41927 times.
✓ Branch 1 taken 154870 times.
196797 if (intra_mip_flag) {
875
4/4
✓ Branch 0 taken 8686 times.
✓ Branch 1 taken 33241 times.
✓ Branch 2 taken 244 times.
✓ Branch 3 taken 8442 times.
41927 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
876 244 return INTRA_INVALID;
877 41683 return INTRA_PLANAR;
878 }
879
3/4
✓ Branch 0 taken 154764 times.
✓ Branch 1 taken 106 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 154764 times.
154870 if (cu_pred_mode == MODE_IBC || cu_pred_mode == MODE_PLT)
880 106 return INTRA_DC;
881 154764 return intra_pred_mode_y;
882 }
883
884 196941 static void derive_chroma_intra_pred_mode(VVCLocalContext *lc,
885 const int cclm_mode_flag, const int cclm_mode_idx, const int intra_chroma_pred_mode)
886 {
887 196941 const VVCFrameContext *fc = lc->fc;
888 196941 CodingUnit *cu = lc->cu;
889 196941 const VVCSPS *sps = fc->ps.sps;
890 196941 const VVCPPS *pps = fc->ps.pps;
891 196941 const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
892 196941 const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
893 196941 const int min_cb_width = pps->min_cb_width;
894 196941 const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_cb, y_cb);
895 196941 enum IntraPredMode luma_intra_pred_mode = SAMPLE_CTB(fc->tab.ipm, x_cb, y_cb);
896
897
6/6
✓ Branch 0 taken 39946 times.
✓ Branch 1 taken 156995 times.
✓ Branch 2 taken 2125 times.
✓ Branch 3 taken 37821 times.
✓ Branch 4 taken 679 times.
✓ Branch 5 taken 1446 times.
196941 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 &&
898
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 535 times.
679 intra_chroma_pred_mode == 4 && intra_mip_flag) {
899 144 cu->mip_chroma_direct_flag = 1;
900 144 cu->intra_pred_mode_c = luma_intra_pred_mode;
901 144 return;
902 }
903 196797 luma_intra_pred_mode = derive_center_luma_intra_pred_mode(fc, sps, pps, cu);
904
905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 196797 times.
196797 if (cu->act_enabled_flag) {
906 cu->intra_pred_mode_c = luma_intra_pred_mode;
907 return;
908 }
909
2/2
✓ Branch 0 taken 79138 times.
✓ Branch 1 taken 117659 times.
196797 if (cclm_mode_flag) {
910 79138 cu->intra_pred_mode_c = INTRA_LT_CCLM + cclm_mode_idx;
911
2/2
✓ Branch 0 taken 87347 times.
✓ Branch 1 taken 30312 times.
117659 } else if (intra_chroma_pred_mode == 4){
912 87347 cu->intra_pred_mode_c = luma_intra_pred_mode;
913 } else {
914 const static IntraPredMode pred_mode_c[][4 + 1] = {
915 {INTRA_VDIAG, INTRA_PLANAR, INTRA_PLANAR, INTRA_PLANAR, INTRA_PLANAR},
916 {INTRA_VERT, INTRA_VDIAG, INTRA_VERT, INTRA_VERT, INTRA_VERT},
917 {INTRA_HORZ, INTRA_HORZ, INTRA_VDIAG, INTRA_HORZ, INTRA_HORZ},
918 {INTRA_DC, INTRA_DC, INTRA_DC, INTRA_VDIAG, INTRA_DC},
919 };
920 30312 const int modes[4] = {INTRA_PLANAR, INTRA_VERT, INTRA_HORZ, INTRA_DC};
921 int idx;
922
923 // This workaround is necessary to have 4:4:4 video decode correctly
924 // See VVC ticket https://jvet.hhi.fraunhofer.de/trac/vvc/ticket/1602
925 // and VTM source https://vcgit.hhi.fraunhofer.de/jvet/VVCSoftware_VTM/-/blob/master/source/Lib/CommonLib/UnitTools.cpp#L736
926
6/6
✓ Branch 0 taken 1955 times.
✓ Branch 1 taken 28357 times.
✓ Branch 2 taken 243 times.
✓ Branch 3 taken 1712 times.
✓ Branch 4 taken 43 times.
✓ Branch 5 taken 200 times.
30312 if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 && intra_mip_flag) {
927 43 idx = 4;
928 } else {
929
2/2
✓ Branch 0 taken 67570 times.
✓ Branch 1 taken 10180 times.
77750 for (idx = 0; idx < FF_ARRAY_ELEMS(modes); idx++) {
930
2/2
✓ Branch 0 taken 20089 times.
✓ Branch 1 taken 47481 times.
67570 if (modes[idx] == luma_intra_pred_mode)
931 20089 break;
932 }
933 }
934
935 30312 cu->intra_pred_mode_c = pred_mode_c[intra_chroma_pred_mode][idx];
936 }
937
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 196797 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
196797 if (sps->r->sps_chroma_format_idc == CHROMA_FORMAT_422 && cu->intra_pred_mode_c <= INTRA_VDIAG) {
938 const static int mode_map_422[INTRA_VDIAG + 1] = {
939 0, 1, 61, 62, 63, 64, 65, 66, 2, 3, 5, 6, 8, 10, 12, 13,
940 14, 16, 18, 20, 22, 23, 24, 26, 28, 30, 31, 33, 34, 35, 36, 37,
941 38, 39, 40, 41, 41, 42, 43, 43, 44, 44, 45, 45, 46, 47, 48, 48,
942 49, 49, 50, 51, 51, 52, 52, 53, 54, 55, 55, 56, 56, 57, 57, 58,
943 59, 59, 60,
944 };
945 cu->intra_pred_mode_c = mode_map_422[cu->intra_pred_mode_c];
946 }
947 }
948
949 529552 static void intra_luma_pred_modes(VVCLocalContext *lc)
950 {
951 529552 VVCFrameContext *fc = lc->fc;
952 529552 const VVCSPS *sps = fc->ps.sps;
953 529552 const VVCPPS *pps = fc->ps.pps;
954 529552 CodingUnit *cu = lc->cu;
955 529552 const int log2_min_cb_size = sps->min_cb_log2_size_y;
956 529552 const int x0 = cu->x0;
957 529552 const int y0 = cu->y0;
958 529552 const int x_cb = x0 >> log2_min_cb_size;
959 529552 const int y_cb = y0 >> log2_min_cb_size;
960 529552 const int cb_width = cu->cb_width;
961 529552 const int cb_height = cu->cb_height;
962
963 529552 cu->intra_luma_ref_idx = 0;
964
6/6
✓ Branch 0 taken 28688 times.
✓ Branch 1 taken 500864 times.
✓ Branch 2 taken 27889 times.
✓ Branch 3 taken 799 times.
✓ Branch 4 taken 27878 times.
✓ Branch 5 taken 11 times.
529552 if (sps->r->sps_bdpcm_enabled_flag && cb_width <= sps->max_ts_size && cb_height <= sps->max_ts_size)
965 27878 cu->bdpcm_flag[LUMA] = ff_vvc_intra_bdpcm_luma_flag(lc);
966
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 529514 times.
529552 if (cu->bdpcm_flag[LUMA]) {
967
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 18 times.
38 cu->intra_pred_mode_y = ff_vvc_intra_bdpcm_luma_dir_flag(lc) ? INTRA_VERT : INTRA_HORZ;
968 } else {
969
2/2
✓ Branch 0 taken 401168 times.
✓ Branch 1 taken 128346 times.
529514 if (sps->r->sps_mip_enabled_flag)
970 401168 cu->intra_mip_flag = ff_vvc_intra_mip_flag(lc, fc->tab.imf);
971
2/2
✓ Branch 0 taken 97983 times.
✓ Branch 1 taken 431531 times.
529514 if (cu->intra_mip_flag) {
972 97983 int intra_mip_transposed_flag = ff_vvc_intra_mip_transposed_flag(lc);
973 97983 int intra_mip_mode = ff_vvc_intra_mip_mode(lc);
974 97983 int x = y_cb * pps->min_cb_width + x_cb;
975
2/2
✓ Branch 0 taken 268606 times.
✓ Branch 1 taken 97983 times.
366589 for (int y = 0; y < (cb_height>>log2_min_cb_size); y++) {
976 268606 int width = cb_width>>log2_min_cb_size;
977 268606 memset(&fc->tab.imf[x], cu->intra_mip_flag, width);
978 268606 fc->tab.imtf[x] = intra_mip_transposed_flag;
979 268606 fc->tab.imm[x] = intra_mip_mode;
980 268606 x += pps->min_cb_width;
981 }
982 97983 cu->intra_pred_mode_y = intra_mip_mode;
983 } else {
984 431531 int intra_subpartitions_mode_flag = 0;
985
4/4
✓ Branch 0 taken 426093 times.
✓ Branch 1 taken 5438 times.
✓ Branch 2 taken 389011 times.
✓ Branch 3 taken 37082 times.
431531 if (sps->r->sps_mrl_enabled_flag && ((y0 % sps->ctb_size_y) > 0))
986 389011 cu->intra_luma_ref_idx = ff_vvc_intra_luma_ref_idx(lc);
987
4/4
✓ Branch 0 taken 426093 times.
✓ Branch 1 taken 5438 times.
✓ Branch 2 taken 395947 times.
✓ Branch 3 taken 30146 times.
431531 if (sps->r->sps_isp_enabled_flag && !cu->intra_luma_ref_idx &&
988
2/4
✓ Branch 0 taken 395947 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 395947 times.
✗ Branch 3 not taken.
395947 (cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) &&
989
2/2
✓ Branch 0 taken 349125 times.
✓ Branch 1 taken 46822 times.
395947 (cb_width * cb_height > MIN_TU_SIZE * MIN_TU_SIZE) &&
990
1/2
✓ Branch 0 taken 349125 times.
✗ Branch 1 not taken.
349125 !cu->act_enabled_flag)
991 349125 intra_subpartitions_mode_flag = ff_vvc_intra_subpartitions_mode_flag(lc);
992
4/4
✓ Branch 0 taken 89156 times.
✓ Branch 1 taken 342375 times.
✓ Branch 2 taken 19868 times.
✓ Branch 3 taken 69288 times.
431531 if (!(x0 & 63) && !(y0 & 63))
993 19868 TAB_ISPMF(fc, x0, y0) = intra_subpartitions_mode_flag;
994 431531 cu->isp_split_type = ff_vvc_isp_split_type(lc, intra_subpartitions_mode_flag);
995 431531 cu->num_intra_subpartitions = get_num_intra_subpartitions(cu->isp_split_type, cb_width, cb_height);
996 431531 cu->intra_pred_mode_y = luma_intra_pred_mode(lc, intra_subpartitions_mode_flag);
997 }
998 }
999 529552 set_cb_tab(lc, fc->tab.ipm, cu->intra_pred_mode_y);
1000 529552 }
1001
1002 196944 static void intra_chroma_pred_modes(VVCLocalContext *lc)
1003 {
1004 196944 const VVCSPS *sps = lc->fc->ps.sps;
1005 196944 CodingUnit *cu = lc->cu;
1006 196944 const int hs = sps->hshift[CHROMA];
1007 196944 const int vs = sps->vshift[CHROMA];
1008
1009 196944 cu->mip_chroma_direct_flag = 0;
1010
2/2
✓ Branch 0 taken 25937 times.
✓ Branch 1 taken 171007 times.
196944 if (sps->r->sps_bdpcm_enabled_flag &&
1011
2/2
✓ Branch 0 taken 24636 times.
✓ Branch 1 taken 1301 times.
25937 (cu->cb_width >> hs) <= sps->max_ts_size &&
1012
2/2
✓ Branch 0 taken 24174 times.
✓ Branch 1 taken 462 times.
24636 (cu->cb_height >> vs) <= sps->max_ts_size) {
1013 24174 cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = ff_vvc_intra_bdpcm_chroma_flag(lc);
1014 }
1015
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 196941 times.
196944 if (cu->bdpcm_flag[CHROMA]) {
1016
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
3 cu->intra_pred_mode_c = ff_vvc_intra_bdpcm_chroma_dir_flag(lc) ? INTRA_VERT : INTRA_HORZ;
1017 } else {
1018 196941 const int cclm_enabled = get_cclm_enabled(lc, cu->x0, cu->y0);
1019 196941 int cclm_mode_flag = 0;
1020 196941 int cclm_mode_idx = 0;
1021 196941 int intra_chroma_pred_mode = 0;
1022
1023
2/2
✓ Branch 0 taken 182013 times.
✓ Branch 1 taken 14928 times.
196941 if (cclm_enabled)
1024 182013 cclm_mode_flag = ff_vvc_cclm_mode_flag(lc);
1025
1026
2/2
✓ Branch 0 taken 79138 times.
✓ Branch 1 taken 117803 times.
196941 if (cclm_mode_flag)
1027 79138 cclm_mode_idx = ff_vvc_cclm_mode_idx(lc);
1028 else
1029 117803 intra_chroma_pred_mode = ff_vvc_intra_chroma_pred_mode(lc);
1030 196941 derive_chroma_intra_pred_mode(lc, cclm_mode_flag, cclm_mode_idx, intra_chroma_pred_mode);
1031 }
1032 196944 }
1033
1034 1085050 static PredMode pred_mode_decode(VVCLocalContext *lc,
1035 const VVCTreeType tree_type,
1036 const VVCModeType mode_type)
1037 {
1038 1085050 const VVCFrameContext *fc = lc->fc;
1039 1085050 CodingUnit *cu = lc->cu;
1040 1085050 const VVCSPS *sps = fc->ps.sps;
1041 1085050 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1042 1085050 const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1043
4/4
✓ Branch 0 taken 200795 times.
✓ Branch 1 taken 884255 times.
✓ Branch 2 taken 63222 times.
✓ Branch 3 taken 137573 times.
1085050 const int is_4x4 = cu->cb_width == 4 && cu->cb_height == 4;
1044 int pred_mode_flag;
1045 int pred_mode_ibc_flag;
1046 PredMode pred_mode;
1047
1048 1085050 cu->skip_flag = 0;
1049
4/4
✓ Branch 0 taken 609002 times.
✓ Branch 1 taken 476048 times.
✓ Branch 2 taken 2408 times.
✓ Branch 3 taken 606594 times.
1563506 if (!IS_I(rsh) || sps->r->sps_ibc_enabled_flag) {
1050
4/4
✓ Branch 0 taken 456479 times.
✓ Branch 1 taken 21977 times.
✓ Branch 2 taken 2153 times.
✓ Branch 3 taken 454326 times.
478456 const int is_128 = cu->cb_width == 128 || cu->cb_height == 128;
1051
4/4
✓ Branch 0 taken 470100 times.
✓ Branch 1 taken 8356 times.
✓ Branch 2 taken 461892 times.
✓ Branch 3 taken 8208 times.
478456 if (tree_type != DUAL_TREE_CHROMA &&
1052
2/2
✓ Branch 0 taken 18718 times.
✓ Branch 1 taken 443174 times.
461892 ((!is_4x4 && mode_type != MODE_TYPE_INTRA) ||
1053
3/4
✓ Branch 0 taken 436 times.
✓ Branch 1 taken 26490 times.
✓ Branch 2 taken 436 times.
✗ Branch 3 not taken.
26926 (sps->r->sps_ibc_enabled_flag && !is_128))) {
1054 443610 cu->skip_flag = ff_vvc_cu_skip_flag(lc, fc->tab.skip);
1055 }
1056
1057
6/6
✓ Branch 0 taken 470248 times.
✓ Branch 1 taken 8208 times.
✓ Branch 2 taken 443334 times.
✓ Branch 3 taken 26914 times.
✓ Branch 4 taken 2112 times.
✓ Branch 5 taken 441222 times.
478456 if (is_4x4 || mode_type == MODE_TYPE_INTRA || IS_I(rsh)) {
1058 37234 pred_mode_flag = 1;
1059
4/4
✓ Branch 0 taken 385582 times.
✓ Branch 1 taken 55640 times.
✓ Branch 2 taken 204940 times.
✓ Branch 3 taken 180642 times.
441222 } else if (mode_type == MODE_TYPE_INTER || cu->skip_flag) {
1060 260580 pred_mode_flag = 0;
1061 } else {
1062 180642 pred_mode_flag = ff_vvc_pred_mode_flag(lc, ch_type);
1063 }
1064 478456 pred_mode = pred_mode_flag ? MODE_INTRA : MODE_INTER;
1065
1066
4/4
✓ Branch 0 taken 2408 times.
✓ Branch 1 taken 476048 times.
✓ Branch 2 taken 96 times.
✓ Branch 3 taken 2312 times.
478456 if (((IS_I(rsh) && !cu->skip_flag) ||
1067
6/6
✓ Branch 0 taken 476048 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 79091 times.
✓ Branch 3 taken 396957 times.
✓ Branch 4 taken 71179 times.
✓ Branch 5 taken 7912 times.
476144 (!IS_I(rsh) && (pred_mode != MODE_INTRA ||
1068
6/6
✓ Branch 0 taken 26914 times.
✓ Branch 1 taken 44265 times.
✓ Branch 2 taken 34802 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 409941 times.
✓ Branch 5 taken 24130 times.
478360 ((is_4x4 || mode_type == MODE_TYPE_INTRA) && !cu->skip_flag)))) &&
1069
6/6
✓ Branch 0 taken 354301 times.
✓ Branch 1 taken 55640 times.
✓ Branch 2 taken 3239 times.
✓ Branch 3 taken 351062 times.
✓ Branch 4 taken 3032 times.
✓ Branch 5 taken 207 times.
409941 !is_128 && mode_type != MODE_TYPE_INTER && sps->r->sps_ibc_enabled_flag &&
1070 tree_type != DUAL_TREE_CHROMA) {
1071 3032 pred_mode_ibc_flag = ff_vvc_pred_mode_ibc_flag(lc, ch_type);
1072
6/6
✓ Branch 0 taken 229690 times.
✓ Branch 1 taken 245734 times.
✓ Branch 2 taken 229663 times.
✓ Branch 3 taken 27 times.
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 229648 times.
475424 } else if (cu->skip_flag && (is_4x4 || mode_type == MODE_TYPE_INTRA)) {
1073 42 pred_mode_ibc_flag = 1;
1074
6/6
✓ Branch 0 taken 451252 times.
✓ Branch 1 taken 24130 times.
✓ Branch 2 taken 395612 times.
✓ Branch 3 taken 55640 times.
✓ Branch 4 taken 8356 times.
✓ Branch 5 taken 387256 times.
475382 } else if (is_128 || mode_type == MODE_TYPE_INTER || tree_type == DUAL_TREE_CHROMA) {
1075 88126 pred_mode_ibc_flag = 0;
1076 } else {
1077
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 387178 times.
387256 pred_mode_ibc_flag = (IS_I(rsh)) ? sps->r->sps_ibc_enabled_flag : 0;
1078 }
1079
2/2
✓ Branch 0 taken 1582 times.
✓ Branch 1 taken 476874 times.
478456 if (pred_mode_ibc_flag)
1080 1582 pred_mode = MODE_IBC;
1081 } else {
1082 606594 pred_mode = MODE_INTRA;
1083 }
1084
1085 1085050 set_cb_tab(lc, fc->tab.cpm[cu->ch_type], pred_mode);
1086
2/2
✓ Branch 0 taken 452025 times.
✓ Branch 1 taken 633025 times.
1085050 if (tree_type == SINGLE_TREE)
1087 452025 set_cb_tab(lc, fc->tab.cpm[CHROMA], pred_mode);
1088
1089 1085050 return pred_mode;
1090 }
1091
1092 823003 static void sbt_info(VVCLocalContext *lc, const VVCSPS *sps)
1093 {
1094 823003 CodingUnit *cu = lc->cu;
1095 823003 const int cb_width = cu->cb_width;
1096 823003 const int cb_height = cu->cb_height;
1097
1098
6/6
✓ Branch 0 taken 135689 times.
✓ Branch 1 taken 687314 times.
✓ Branch 2 taken 132984 times.
✓ Branch 3 taken 2705 times.
✓ Branch 4 taken 117891 times.
✓ Branch 5 taken 15093 times.
823003 if (cu->pred_mode == MODE_INTER && sps->r->sps_sbt_enabled_flag && !cu->ciip_flag
1099
4/4
✓ Branch 0 taken 117209 times.
✓ Branch 1 taken 682 times.
✓ Branch 2 taken 116966 times.
✓ Branch 3 taken 243 times.
117891 && cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) {
1100 116966 const int sbt_ver_h = cb_width >= 8;
1101 116966 const int sbt_hor_h = cb_height >= 8;
1102 116966 cu->sbt_flag = 0;
1103
3/4
✓ Branch 0 taken 16948 times.
✓ Branch 1 taken 100018 times.
✓ Branch 2 taken 16948 times.
✗ Branch 3 not taken.
116966 if (sbt_ver_h || sbt_hor_h)
1104 116966 cu->sbt_flag = ff_vvc_sbt_flag(lc);
1105
2/2
✓ Branch 0 taken 37306 times.
✓ Branch 1 taken 79660 times.
116966 if (cu->sbt_flag) {
1106 37306 const int sbt_ver_q = cb_width >= 16;
1107 37306 const int sbt_hor_q = cb_height >= 16;
1108 37306 int cu_sbt_quad_flag = 0;
1109
1110
7/8
✓ Branch 0 taken 5966 times.
✓ Branch 1 taken 31340 times.
✓ Branch 2 taken 5966 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20658 times.
✓ Branch 5 taken 16648 times.
✓ Branch 6 taken 10919 times.
✓ Branch 7 taken 9739 times.
37306 if ((sbt_ver_h || sbt_hor_h) && (sbt_ver_q || sbt_hor_q))
1111 27567 cu_sbt_quad_flag = ff_vvc_sbt_quad_flag(lc);
1112
2/2
✓ Branch 0 taken 9645 times.
✓ Branch 1 taken 27661 times.
37306 if (cu_sbt_quad_flag) {
1113 9645 cu->sbt_horizontal_flag = sbt_hor_q;
1114
4/4
✓ Branch 0 taken 6106 times.
✓ Branch 1 taken 3539 times.
✓ Branch 2 taken 3101 times.
✓ Branch 3 taken 3005 times.
9645 if (sbt_ver_q && sbt_hor_q)
1115 3101 cu->sbt_horizontal_flag = ff_vvc_sbt_horizontal_flag(lc);
1116 } else {
1117 27661 cu->sbt_horizontal_flag = sbt_hor_h;
1118
4/4
✓ Branch 0 taken 23046 times.
✓ Branch 1 taken 4615 times.
✓ Branch 2 taken 19107 times.
✓ Branch 3 taken 3939 times.
27661 if (sbt_ver_h && sbt_hor_h)
1119 19107 cu->sbt_horizontal_flag = ff_vvc_sbt_horizontal_flag(lc);
1120 }
1121 37306 cu->sbt_pos_flag = ff_vvc_sbt_pos_flag(lc);
1122
1123 {
1124
2/2
✓ Branch 0 taken 9645 times.
✓ Branch 1 taken 27661 times.
37306 const int sbt_min = cu_sbt_quad_flag ? 1 : 2;
1125
2/2
✓ Branch 0 taken 17766 times.
✓ Branch 1 taken 19540 times.
37306 lc->parse.sbt_num_fourths_tb0 = cu->sbt_pos_flag ? (4 - sbt_min) : sbt_min;
1126 }
1127 }
1128 }
1129 823003 }
1130
1131 262047 static int skipped_transform_tree_unit(VVCLocalContext *lc)
1132 {
1133 262047 const H266RawSPS *rsps = lc->fc->ps.sps->r;
1134 262047 const CodingUnit *cu = lc->cu;
1135 int ret;
1136
1137
1/2
✓ Branch 0 taken 262047 times.
✗ Branch 1 not taken.
262047 if (cu->tree_type != DUAL_TREE_CHROMA)
1138 262047 set_qp_y(lc, cu->x0, cu->y0, 0);
1139
4/4
✓ Branch 0 taken 245536 times.
✓ Branch 1 taken 16511 times.
✓ Branch 2 taken 244740 times.
✓ Branch 3 taken 796 times.
262047 if (rsps->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA)
1140 244740 set_qp_c(lc);
1141 262047 ret = skipped_transform_tree(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 262047 times.
262047 if (ret < 0)
1143 return ret;
1144 262047 return 0;
1145 }
1146
1147 1085050 static void set_cb_pos(const VVCFrameContext *fc, const CodingUnit *cu)
1148 {
1149 1085050 const VVCSPS *sps = fc->ps.sps;
1150 1085050 const VVCPPS *pps = fc->ps.pps;
1151 1085050 const int log2_min_cb_size = sps->min_cb_log2_size_y;
1152 1085050 const int x_cb = cu->x0 >> log2_min_cb_size;
1153 1085050 const int y_cb = cu->y0 >> log2_min_cb_size;
1154 1085050 const int ch_type = cu->ch_type;
1155 int x, y;
1156
1157 1085050 x = y_cb * pps->min_cb_width + x_cb;
1158
2/2
✓ Branch 0 taken 4767066 times.
✓ Branch 1 taken 1085050 times.
5852116 for (y = 0; y < (cu->cb_height >> log2_min_cb_size); y++) {
1159 4767066 const int width = cu->cb_width >> log2_min_cb_size;
1160
1161
2/2
✓ Branch 0 taken 46356016 times.
✓ Branch 1 taken 4767066 times.
51123082 for (int i = 0; i < width; i++) {
1162 46356016 fc->tab.cb_pos_x[ch_type][x + i] = cu->x0;
1163 46356016 fc->tab.cb_pos_y[ch_type][x + i] = cu->y0;
1164 }
1165 4767066 memset(&fc->tab.cb_width[ch_type][x], cu->cb_width, width);
1166 4767066 memset(&fc->tab.cb_height[ch_type][x], cu->cb_height, width);
1167 4767066 memset(&fc->tab.cqt_depth[ch_type][x], cu->cqt_depth, width);
1168
1169 4767066 x += pps->min_cb_width;
1170 }
1171 1085050 }
1172
1173 1085050 static CodingUnit* alloc_cu(VVCLocalContext *lc, const int x0, const int y0)
1174 {
1175 1085050 VVCFrameContext *fc = lc->fc;
1176 1085050 const VVCSPS *sps = fc->ps.sps;
1177 1085050 const VVCPPS *pps = fc->ps.pps;
1178 1085050 const int rx = x0 >> sps->ctb_log2_size_y;
1179 1085050 const int ry = y0 >> sps->ctb_log2_size_y;
1180 1085050 CodingUnit **cus = fc->tab.cus + ry * pps->ctb_width + rx;
1181 1085050 CodingUnit *cu = ff_refstruct_pool_get(fc->cu_pool);
1182
1183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1085050 times.
1085050 if (!cu)
1184 return NULL;
1185 1085050 cu->next = NULL;
1186
1187
2/2
✓ Branch 0 taken 1040498 times.
✓ Branch 1 taken 44552 times.
1085050 if (lc->cu)
1188 1040498 lc->cu->next = cu;
1189 else
1190 44552 *cus = cu;
1191 1085050 lc->cu = cu;
1192
1193 1085050 return cu;
1194 }
1195
1196 1085050 static CodingUnit* add_cu(VVCLocalContext *lc, const int x0, const int y0,
1197 const int cb_width, const int cb_height, const int cqt_depth, const VVCTreeType tree_type)
1198 {
1199 1085050 VVCFrameContext *fc = lc->fc;
1200 1085050 const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1201 1085050 CodingUnit *cu = alloc_cu(lc, x0, y0);
1202
1203
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1085050 times.
1085050 if (!cu)
1204 return NULL;
1205
1206 1085050 memset(&cu->pu, 0, sizeof(cu->pu));
1207
1208 1085050 lc->parse.prev_tu_cbf_y = 0;
1209
1210 1085050 cu->sbt_flag = 0;
1211 1085050 cu->act_enabled_flag = 0;
1212
1213 1085050 cu->tree_type = tree_type;
1214 1085050 cu->x0 = x0;
1215 1085050 cu->y0 = y0;
1216 1085050 cu->cb_width = cb_width;
1217 1085050 cu->cb_height = cb_height;
1218 1085050 cu->ch_type = ch_type;
1219 1085050 cu->cqt_depth = cqt_depth;
1220 1085050 cu->tus.head = cu->tus.tail = NULL;
1221 1085050 cu->bdpcm_flag[LUMA] = cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = 0;
1222 1085050 cu->isp_split_type = ISP_NO_SPLIT;
1223 1085050 cu->intra_mip_flag = 0;
1224 1085050 cu->ciip_flag = 0;
1225 1085050 cu->coded_flag = 1;
1226 1085050 cu->num_intra_subpartitions = 1;
1227 1085050 cu->pu.dmvr_flag = 0;
1228
1229 1085050 set_cb_pos(fc, cu);
1230 1085050 return cu;
1231 }
1232
1233 1085050 static void set_cu_tabs(const VVCLocalContext *lc, const CodingUnit *cu)
1234 {
1235 1085050 const VVCFrameContext *fc = lc->fc;
1236 1085050 const PredictionUnit *pu = &cu->pu;
1237 1085050 const TransformUnit *tu = cu->tus.head;
1238
1239 1085050 set_cb_tab(lc, fc->tab.mmi, pu->mi.motion_model_idc);
1240 1085050 set_cb_tab(lc, fc->tab.msf, pu->merge_subblock_flag);
1241
2/2
✓ Branch 0 taken 928052 times.
✓ Branch 1 taken 156998 times.
1085050 if (cu->tree_type != DUAL_TREE_CHROMA) {
1242 928052 set_cb_tab(lc, fc->tab.skip, cu->skip_flag);
1243 928052 set_cb_tab(lc, fc->tab.pcmf[LUMA], cu->bdpcm_flag[LUMA]);
1244 }
1245
2/2
✓ Branch 0 taken 609023 times.
✓ Branch 1 taken 476027 times.
1085050 if (cu->tree_type != DUAL_TREE_LUMA)
1246 609023 set_cb_tab(lc, fc->tab.pcmf[CHROMA], cu->bdpcm_flag[CHROMA]);
1247
1248
2/2
✓ Branch 0 taken 1326571 times.
✓ Branch 1 taken 1085050 times.
2411621 while (tu) {
1249
2/2
✓ Branch 0 taken 2516125 times.
✓ Branch 1 taken 1326571 times.
3842696 for (int j = 0; j < tu->nb_tbs; j++) {
1250 2516125 const TransformBlock *tb = tu->tbs + j;
1251
2/2
✓ Branch 0 taken 1346552 times.
✓ Branch 1 taken 1169573 times.
2516125 if (tb->c_idx != LUMA)
1252 1346552 set_qp_c_tab(lc, tu, tb);
1253 }
1254 1326571 tu = tu->next;
1255 }
1256 1085050 }
1257
1258 //8.5.2.7 Derivation process for merge motion vector difference
1259 54381 static void derive_mmvd(const VVCLocalContext *lc, MvField *mvf, const Mv *mmvd_offset)
1260 {
1261 54381 const SliceContext *sc = lc->sc;
1262 Mv mmvd[2];
1263
1264
2/2
✓ Branch 0 taken 22866 times.
✓ Branch 1 taken 31515 times.
54381 if (mvf->pred_flag == PF_BI) {
1265 22866 const RefPicList *rpl = sc->rpl;
1266 22866 const int poc = lc->fc->ps.ph.poc;
1267 22866 const int diff[] = {
1268 22866 poc - rpl[L0].refs[mvf->ref_idx[L0]].poc,
1269 22866 poc - rpl[L1].refs[mvf->ref_idx[L1]].poc
1270 };
1271
4/4
✓ Branch 0 taken 21698 times.
✓ Branch 1 taken 1168 times.
✓ Branch 2 taken 8539 times.
✓ Branch 3 taken 14327 times.
22866 const int sign = FFSIGN(diff[0]) != FFSIGN(diff[1]);
1272
1273
2/2
✓ Branch 0 taken 7861 times.
✓ Branch 1 taken 15005 times.
22866 if (diff[0] == diff[1]) {
1274 7861 mmvd[1] = mmvd[0] = *mmvd_offset;
1275 }
1276 else {
1277 15005 const int i = FFABS(diff[0]) < FFABS(diff[1]);
1278 15005 const int o = !i;
1279 15005 mmvd[i] = *mmvd_offset;
1280
2/4
✓ Branch 0 taken 15005 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15005 times.
✗ Branch 3 not taken.
15005 if (!rpl[L0].refs[mvf->ref_idx[L0]].is_lt && !rpl[L1].refs[mvf->ref_idx[L1]].is_lt) {
1281 15005 ff_vvc_mv_scale(&mmvd[o], mmvd_offset, diff[i], diff[o]);
1282 }
1283 else {
1284 mmvd[o].x = sign ? -mmvd[i].x : mmvd[i].x;
1285 mmvd[o].y = sign ? -mmvd[i].y : mmvd[i].y;
1286 }
1287 }
1288 22866 mvf->mv[0].x += mmvd[0].x;
1289 22866 mvf->mv[0].y += mmvd[0].y;
1290 22866 mvf->mv[1].x += mmvd[1].x;
1291 22866 mvf->mv[1].y += mmvd[1].y;
1292 } else {
1293 31515 const int idx = mvf->pred_flag - PF_L0;
1294 31515 mvf->mv[idx].x += mmvd_offset->x;
1295 31515 mvf->mv[idx].y += mmvd_offset->y;
1296 }
1297
1298 54381 }
1299
1300 265675 static void mvf_to_mi(const MvField *mvf, MotionInfo *mi)
1301 {
1302 265675 mi->pred_flag = mvf->pred_flag;
1303 265675 mi->bcw_idx = mvf->bcw_idx;
1304 265675 mi->hpel_if_idx = mvf->hpel_if_idx;
1305
2/2
✓ Branch 0 taken 531350 times.
✓ Branch 1 taken 265675 times.
797025 for (int i = 0; i < 2; i++) {
1306 531350 const PredFlag mask = i + 1;
1307
2/2
✓ Branch 0 taken 418479 times.
✓ Branch 1 taken 112871 times.
531350 if (mvf->pred_flag & mask) {
1308 418479 mi->mv[i][0] = mvf->mv[i];
1309 418479 mi->ref_idx[i] = mvf->ref_idx[i];
1310 }
1311 }
1312 265675 }
1313
1314 265675 static void mv_merge_refine_pred_flag(MvField *mvf, const int width, const int height)
1315 {
1316
4/4
✓ Branch 0 taken 157573 times.
✓ Branch 1 taken 108102 times.
✓ Branch 2 taken 4769 times.
✓ Branch 3 taken 152804 times.
265675 if (mvf->pred_flag == PF_BI && (width + height) == 12) {
1317 4769 mvf->pred_flag = PF_L0;
1318 4769 mvf->bcw_idx = 0;
1319 }
1320 265675 }
1321
1322 // subblock-based inter prediction data
1323 48721 static void merge_data_subblock(VVCLocalContext *lc)
1324 {
1325 48721 const VVCFrameContext *fc = lc->fc;
1326 48721 const VVCPH *ph = &fc->ps.ph;
1327 48721 CodingUnit* cu = lc->cu;
1328 48721 PredictionUnit *pu = &cu->pu;
1329 48721 int merge_subblock_idx = 0;
1330
1331
1/2
✓ Branch 0 taken 48721 times.
✗ Branch 1 not taken.
48721 if (ph->max_num_subblock_merge_cand > 1) {
1332 48721 merge_subblock_idx = ff_vvc_merge_subblock_idx(lc, ph->max_num_subblock_merge_cand);
1333 }
1334 48721 ff_vvc_sb_mv_merge_mode(lc, merge_subblock_idx, pu);
1335 48721 }
1336
1337 250158 static void merge_data_regular(VVCLocalContext *lc)
1338 {
1339 250158 const VVCFrameContext *fc = lc->fc;
1340 250158 const VVCSPS *sps = fc->ps.sps;
1341 250158 const VVCPH *ph = &fc->ps.ph;
1342 250158 const CodingUnit* cu = lc->cu;
1343 250158 PredictionUnit *pu = &lc->cu->pu;
1344 250158 int merge_idx = 0;
1345 Mv mmvd_offset;
1346 MvField mvf;
1347
1348
1/2
✓ Branch 0 taken 250158 times.
✗ Branch 1 not taken.
250158 if (sps->r->sps_mmvd_enabled_flag)
1349 250158 pu->mmvd_merge_flag = ff_vvc_mmvd_merge_flag(lc);
1350
2/2
✓ Branch 0 taken 54381 times.
✓ Branch 1 taken 195777 times.
250158 if (pu->mmvd_merge_flag) {
1351 54381 int mmvd_cand_flag = 0;
1352
1/2
✓ Branch 0 taken 54381 times.
✗ Branch 1 not taken.
54381 if (sps->max_num_merge_cand > 1)
1353 54381 mmvd_cand_flag = ff_vvc_mmvd_cand_flag(lc);
1354 54381 ff_vvc_mmvd_offset_coding(lc, &mmvd_offset, ph->r->ph_mmvd_fullpel_only_flag);
1355 54381 merge_idx = mmvd_cand_flag;
1356
1/2
✓ Branch 0 taken 195777 times.
✗ Branch 1 not taken.
195777 } else if (sps->max_num_merge_cand > 1) {
1357 195777 merge_idx = ff_vvc_merge_idx(lc);
1358 }
1359 250158 ff_vvc_luma_mv_merge_mode(lc, merge_idx, 0, &mvf);
1360
2/2
✓ Branch 0 taken 54381 times.
✓ Branch 1 taken 195777 times.
250158 if (pu->mmvd_merge_flag)
1361 54381 derive_mmvd(lc, &mvf, &mmvd_offset);
1362 250158 mv_merge_refine_pred_flag(&mvf, cu->cb_width, cu->cb_height);
1363 250158 ff_vvc_store_mvf(lc, &mvf);
1364 250158 mvf_to_mi(&mvf, &pu->mi);
1365 250158 }
1366
1367 40254 static int ciip_flag_decode(VVCLocalContext *lc, const int ciip_avaiable, const int gpm_avaiable, const int is_128)
1368 {
1369 40254 const VVCFrameContext *fc = lc->fc;
1370 40254 const VVCSPS *sps = fc->ps.sps;
1371 40254 const CodingUnit *cu = lc->cu;
1372
1373
4/4
✓ Branch 0 taken 25226 times.
✓ Branch 1 taken 15028 times.
✓ Branch 2 taken 18681 times.
✓ Branch 3 taken 6545 times.
40254 if (ciip_avaiable && gpm_avaiable)
1374 18681 return ff_vvc_ciip_flag(lc);
1375
3/4
✓ Branch 0 taken 6545 times.
✓ Branch 1 taken 15028 times.
✓ Branch 2 taken 6545 times.
✗ Branch 3 not taken.
21573 return sps->r->sps_ciip_enabled_flag && !cu->skip_flag &&
1376
2/4
✓ Branch 0 taken 21573 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6545 times.
✗ Branch 3 not taken.
43146 !is_128 && (cu->cb_width * cu->cb_height >= 64);
1377 }
1378
1379 24737 static void merge_data_gpm(VVCLocalContext *lc)
1380 {
1381 24737 const VVCFrameContext *fc = lc->fc;
1382 24737 const VVCSPS *sps = fc->ps.sps;
1383 24737 PredictionUnit *pu = &lc->cu->pu;
1384 int merge_gpm_idx[2];
1385
1386 24737 pu->merge_gpm_flag = 1;
1387 24737 pu->gpm_partition_idx = ff_vvc_merge_gpm_partition_idx(lc);
1388 24737 merge_gpm_idx[0] = ff_vvc_merge_gpm_idx(lc, 0);
1389 24737 merge_gpm_idx[1] = 0;
1390
1/2
✓ Branch 0 taken 24737 times.
✗ Branch 1 not taken.
24737 if (sps->max_num_gpm_merge_cand > 2)
1391 24737 merge_gpm_idx[1] = ff_vvc_merge_gpm_idx(lc, 1);
1392
1393 24737 ff_vvc_luma_mv_merge_gpm(lc, merge_gpm_idx, pu->gpm_mv);
1394 24737 ff_vvc_store_gpm_mvf(lc, pu);
1395 24737 }
1396
1397 15517 static void merge_data_ciip(VVCLocalContext *lc)
1398 {
1399 15517 const VVCFrameContext* fc = lc->fc;
1400 15517 const VVCSPS* sps = fc->ps.sps;
1401 15517 CodingUnit *cu = lc->cu;
1402 15517 MotionInfo *mi = &cu->pu.mi;
1403 15517 int merge_idx = 0;
1404 MvField mvf;
1405
1406
1/2
✓ Branch 0 taken 15517 times.
✗ Branch 1 not taken.
15517 if (sps->max_num_merge_cand > 1)
1407 15517 merge_idx = ff_vvc_merge_idx(lc);
1408 15517 ff_vvc_luma_mv_merge_mode(lc, merge_idx, 1, &mvf);
1409 15517 mv_merge_refine_pred_flag(&mvf, cu->cb_width, cu->cb_height);
1410 15517 ff_vvc_store_mvf(lc, &mvf);
1411 15517 mvf_to_mi(&mvf, mi);
1412 15517 cu->intra_pred_mode_y = cu->intra_pred_mode_c = INTRA_PLANAR;
1413 15517 cu->intra_luma_ref_idx = 0;
1414 15517 cu->intra_mip_flag = 0;
1415 15517 }
1416
1417 // block-based inter prediction data
1418 290412 static void merge_data_block(VVCLocalContext *lc)
1419 {
1420 290412 const VVCFrameContext* fc = lc->fc;
1421 290412 const VVCSPS *sps = fc->ps.sps;
1422 290412 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1423 290412 CodingUnit *cu = lc->cu;
1424 290412 const int cb_width = cu->cb_width;
1425 290412 const int cb_height = cu->cb_height;
1426
4/4
✓ Branch 0 taken 273143 times.
✓ Branch 1 taken 17269 times.
✓ Branch 2 taken 1327 times.
✓ Branch 3 taken 271816 times.
290412 const int is_128 = cb_width == 128 || cb_height == 128;
1427 871236 const int ciip_avaiable = sps->r->sps_ciip_enabled_flag &&
1428
5/6
✓ Branch 0 taken 290412 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96788 times.
✓ Branch 3 taken 193624 times.
✓ Branch 4 taken 86785 times.
✓ Branch 5 taken 10003 times.
290412 !cu->skip_flag && (cb_width * cb_height >= 64);
1429
3/4
✓ Branch 0 taken 276144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 241923 times.
✓ Branch 3 taken 34221 times.
276144 const int gpm_avaiable = sps->r->sps_gpm_enabled_flag && IS_B(rsh) &&
1430
2/2
✓ Branch 0 taken 216496 times.
✓ Branch 1 taken 25427 times.
241923 (cb_width >= 8) && (cb_height >=8) &&
1431
6/6
✓ Branch 0 taken 276144 times.
✓ Branch 1 taken 14268 times.
✓ Branch 2 taken 210430 times.
✓ Branch 3 taken 6066 times.
✓ Branch 4 taken 208603 times.
✓ Branch 5 taken 1827 times.
566556 (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1432
1433 290412 int regular_merge_flag = 1;
1434
1435
6/6
✓ Branch 0 taken 271816 times.
✓ Branch 1 taken 18596 times.
✓ Branch 2 taken 185327 times.
✓ Branch 3 taken 86489 times.
✓ Branch 4 taken 129209 times.
✓ Branch 5 taken 56118 times.
290412 if (!is_128 && (ciip_avaiable || gpm_avaiable))
1436 215698 regular_merge_flag = ff_vvc_regular_merge_flag(lc, cu->skip_flag);
1437
2/2
✓ Branch 0 taken 250158 times.
✓ Branch 1 taken 40254 times.
290412 if (regular_merge_flag) {
1438 250158 merge_data_regular(lc);
1439 } else {
1440 40254 cu->ciip_flag = ciip_flag_decode(lc, ciip_avaiable, gpm_avaiable, is_128);
1441
2/2
✓ Branch 0 taken 15517 times.
✓ Branch 1 taken 24737 times.
40254 if (cu->ciip_flag)
1442 15517 merge_data_ciip(lc);
1443 else
1444 24737 merge_data_gpm(lc);
1445 }
1446 290412 }
1447
1448 240 static int merge_data_ibc(VVCLocalContext *lc)
1449 {
1450 240 const VVCFrameContext* fc = lc->fc;
1451 240 const VVCSPS* sps = fc->ps.sps;
1452 240 MotionInfo *mi = &lc->cu->pu.mi;
1453 240 int merge_idx = 0;
1454 int ret;
1455
1456 240 mi->pred_flag = PF_IBC;
1457
1458
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 if (sps->max_num_ibc_merge_cand > 1)
1459 merge_idx = ff_vvc_merge_idx(lc);
1460
1461 240 ret = ff_vvc_luma_mv_merge_ibc(lc, merge_idx, &mi->mv[L0][0]);
1462
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 if (ret)
1463 return ret;
1464 240 ff_vvc_store_mv(lc, mi);
1465
1466 240 return 0;
1467 }
1468
1469 339373 static int hls_merge_data(VVCLocalContext *lc)
1470 {
1471 339373 const VVCFrameContext *fc = lc->fc;
1472 339373 const VVCPH *ph = &fc->ps.ph;
1473 339373 const CodingUnit *cu = lc->cu;
1474 339373 PredictionUnit *pu = &lc->cu->pu;
1475 int ret;
1476
1477 339373 pu->merge_gpm_flag = 0;
1478 339373 pu->mi.num_sb_x = pu->mi.num_sb_y = 1;
1479
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 339133 times.
339373 if (cu->pred_mode == MODE_IBC) {
1480 240 ret = merge_data_ibc(lc);
1481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 if (ret)
1482 return ret;
1483 } else {
1484
5/6
✓ Branch 0 taken 339133 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 303260 times.
✓ Branch 3 taken 35873 times.
✓ Branch 4 taken 276219 times.
✓ Branch 5 taken 27041 times.
339133 if (ph->max_num_subblock_merge_cand > 0 && cu->cb_width >= 8 && cu->cb_height >= 8)
1485 276219 pu->merge_subblock_flag = ff_vvc_merge_subblock_flag(lc);
1486
2/2
✓ Branch 0 taken 48721 times.
✓ Branch 1 taken 290412 times.
339133 if (pu->merge_subblock_flag)
1487 48721 merge_data_subblock(lc);
1488 else
1489 290412 merge_data_block(lc);
1490 }
1491 339373 return 0;
1492 }
1493
1494 81166 static void hls_mvd_coding(VVCLocalContext *lc, Mv* mvd)
1495 {
1496 int16_t mv[2];
1497
1498
2/2
✓ Branch 0 taken 162332 times.
✓ Branch 1 taken 81166 times.
243498 for (int i = 0; i < 2; i++) {
1499 162332 mv[i] = ff_vvc_abs_mvd_greater0_flag(lc);
1500 }
1501
1502
2/2
✓ Branch 0 taken 162332 times.
✓ Branch 1 taken 81166 times.
243498 for (int i = 0; i < 2; i++) {
1503
2/2
✓ Branch 0 taken 113271 times.
✓ Branch 1 taken 49061 times.
162332 if (mv[i])
1504 113271 mv[i] += ff_vvc_abs_mvd_greater1_flag(lc);
1505 }
1506
1507
2/2
✓ Branch 0 taken 162332 times.
✓ Branch 1 taken 81166 times.
243498 for (int i = 0; i < 2; i++) {
1508
2/2
✓ Branch 0 taken 113271 times.
✓ Branch 1 taken 49061 times.
162332 if (mv[i] > 0) {
1509
2/2
✓ Branch 0 taken 66424 times.
✓ Branch 1 taken 46847 times.
113271 if (mv[i] == 2)
1510 66424 mv[i] += ff_vvc_abs_mvd_minus2(lc);
1511 113271 mv[i] = (1 - 2 * ff_vvc_mvd_sign_flag(lc)) * mv[i];
1512 }
1513 }
1514 81166 mvd->x = mv[0];
1515 81166 mvd->y = mv[1];
1516 81166 }
1517
1518 57785 static int bcw_idx_decode(VVCLocalContext *lc, const MotionInfo *mi, const int cb_width, const int cb_height)
1519 {
1520 57785 const VVCFrameContext *fc = lc->fc;
1521 57785 const VVCSPS *sps = fc->ps.sps;
1522 57785 const VVCPPS *pps = fc->ps.pps;
1523 57785 const VVCPH *ph = &fc->ps.ph;
1524 57785 const VVCSH *sh = &lc->sc->sh;
1525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57785 times.
57785 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &ph->pwt : &sh->pwt;
1526 57785 int bcw_idx = 0;
1527
1528
4/4
✓ Branch 0 taken 55847 times.
✓ Branch 1 taken 1938 times.
✓ Branch 2 taken 17075 times.
✓ Branch 3 taken 38772 times.
57785 if (sps->r->sps_bcw_enabled_flag && mi->pred_flag == PF_BI &&
1529
2/2
✓ Branch 0 taken 16887 times.
✓ Branch 1 taken 188 times.
17075 !w->weight_flag[L0][LUMA][mi->ref_idx[0]] &&
1530
1/2
✓ Branch 0 taken 16887 times.
✗ Branch 1 not taken.
16887 !w->weight_flag[L1][LUMA][mi->ref_idx[1]] &&
1531
1/2
✓ Branch 0 taken 16887 times.
✗ Branch 1 not taken.
16887 !w->weight_flag[L0][CHROMA][mi->ref_idx[0]] &&
1532
1/2
✓ Branch 0 taken 16887 times.
✗ Branch 1 not taken.
16887 !w->weight_flag[L1][CHROMA][mi->ref_idx[1]] &&
1533
2/2
✓ Branch 0 taken 11078 times.
✓ Branch 1 taken 5809 times.
16887 cb_width * cb_height >= 256) {
1534 11078 bcw_idx = ff_vvc_bcw_idx(lc, ff_vvc_no_backward_pred_flag(lc));
1535 }
1536 57785 return bcw_idx;
1537 }
1538
1539 74860 static int8_t ref_idx_decode(VVCLocalContext *lc, const VVCSH *sh, const int sym_mvd_flag, const int lx)
1540 {
1541 74860 const H266RawSliceHeader *rsh = sh->r;
1542 74860 int ref_idx = 0;
1543
1544
4/4
✓ Branch 0 taken 58572 times.
✓ Branch 1 taken 16288 times.
✓ Branch 2 taken 47090 times.
✓ Branch 3 taken 11482 times.
74860 if (rsh->num_ref_idx_active[lx] > 1 && !sym_mvd_flag)
1545 47090 ref_idx = ff_vvc_ref_idx_lx(lc, rsh->num_ref_idx_active[lx]);
1546
2/2
✓ Branch 0 taken 11482 times.
✓ Branch 1 taken 16288 times.
27770 else if (sym_mvd_flag)
1547 11482 ref_idx = sh->ref_idx_sym[lx];
1548 74860 return ref_idx;
1549 }
1550
1551 74860 static int mvds_decode(VVCLocalContext *lc, Mv mvds[2][MAX_CONTROL_POINTS],
1552 const int num_cp_mv, const int lx)
1553 {
1554 74860 const VVCFrameContext *fc = lc->fc;
1555 74860 const VVCPH *ph = &fc->ps.ph;
1556 74860 const PredictionUnit *pu = &lc->cu->pu;
1557 74860 const MotionInfo *mi = &pu->mi;
1558 74860 int has_no_zero_mvd = 0;
1559
1560
5/6
✓ Branch 0 taken 25055 times.
✓ Branch 1 taken 49805 times.
✓ Branch 2 taken 4514 times.
✓ Branch 3 taken 20541 times.
✓ Branch 4 taken 4514 times.
✗ Branch 5 not taken.
74860 if (lx == L1 && ph->r->ph_mvd_l1_zero_flag && mi->pred_flag == PF_BI) {
1561
2/2
✓ Branch 0 taken 5825 times.
✓ Branch 1 taken 4514 times.
10339 for (int j = 0; j < num_cp_mv; j++)
1562 5825 AV_ZERO64(&mvds[lx][j]);
1563 } else {
1564 70346 Mv *mvd0 = &mvds[lx][0];
1565
4/4
✓ Branch 0 taken 20541 times.
✓ Branch 1 taken 49805 times.
✓ Branch 2 taken 5741 times.
✓ Branch 3 taken 14800 times.
70346 if (lx == L1 && pu->sym_mvd_flag) {
1566 5741 mvd0->x = -mvds[L0][0].x;
1567 5741 mvd0->y = -mvds[L0][0].y;
1568 } else {
1569 64605 hls_mvd_coding(lc, mvd0);
1570 }
1571
4/4
✓ Branch 0 taken 20836 times.
✓ Branch 1 taken 49510 times.
✓ Branch 2 taken 13288 times.
✓ Branch 3 taken 7548 times.
70346 has_no_zero_mvd |= (mvd0->x || mvd0->y);
1572
2/2
✓ Branch 0 taken 15219 times.
✓ Branch 1 taken 70346 times.
85565 for (int j = 1; j < num_cp_mv; j++) {
1573 15219 Mv *mvd = &mvds[lx][j];
1574 15219 hls_mvd_coding(lc, mvd);
1575 15219 mvd->x += mvd0->x;
1576 15219 mvd->y += mvd0->y;
1577
4/4
✓ Branch 0 taken 2925 times.
✓ Branch 1 taken 12294 times.
✓ Branch 2 taken 1999 times.
✓ Branch 3 taken 926 times.
15219 has_no_zero_mvd |= (mvd->x || mvd->y);
1578 }
1579 }
1580 74860 return has_no_zero_mvd;
1581 }
1582
1583 57785 static void mvp_add_difference(MotionInfo *mi, const int num_cp_mv,
1584 const Mv mvds[2][MAX_CONTROL_POINTS], const int amvr_shift)
1585 {
1586
2/2
✓ Branch 0 taken 115570 times.
✓ Branch 1 taken 57785 times.
173355 for (int i = 0; i < 2; i++) {
1587 115570 const PredFlag mask = i + PF_L0;
1588
2/2
✓ Branch 0 taken 74860 times.
✓ Branch 1 taken 40710 times.
115570 if (mi->pred_flag & mask) {
1589
2/2
✓ Branch 0 taken 91390 times.
✓ Branch 1 taken 74860 times.
166250 for (int j = 0; j < num_cp_mv; j++) {
1590 91390 const Mv *mvd = &mvds[i][j];
1591 91390 mi->mv[i][j].x += mvd->x * (1 << amvr_shift);
1592 91390 mi->mv[i][j].y += mvd->y * (1 << amvr_shift);
1593 }
1594 }
1595 }
1596 57785 }
1597
1598 1342 static int mvp_data_ibc(VVCLocalContext *lc)
1599 {
1600 1342 const VVCFrameContext *fc = lc->fc;
1601 1342 const CodingUnit *cu = lc->cu;
1602 1342 const PredictionUnit *pu = &lc->cu->pu;
1603 1342 const VVCSPS *sps = fc->ps.sps;
1604 1342 MotionInfo *mi = &lc->cu->pu.mi;
1605 1342 int mvp_l0_flag = 0;
1606 1342 int amvr_shift = 4;
1607 1342 Mv *mv = &mi->mv[L0][0];
1608 int ret;
1609
1610 1342 mi->pred_flag = PF_IBC;
1611 1342 mi->num_sb_x = 1;
1612 1342 mi->num_sb_y = 1;
1613
1614 1342 hls_mvd_coding(lc, mv);
1615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1342 times.
1342 if (sps->max_num_ibc_merge_cand > 1)
1616 mvp_l0_flag = ff_vvc_mvp_lx_flag(lc);
1617
5/6
✓ Branch 0 taken 1342 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 317 times.
✓ Branch 3 taken 1025 times.
✓ Branch 4 taken 53 times.
✓ Branch 5 taken 264 times.
1342 if (sps->r->sps_amvr_enabled_flag && (mv->x || mv->y))
1618 1078 amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, 1);
1619
1620 1342 ret = ff_vvc_mvp_ibc(lc, mvp_l0_flag, amvr_shift, mv);
1621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1342 times.
1342 if (ret)
1622 return ret;
1623 1342 ff_vvc_store_mv(lc, mi);
1624
1625 1342 return 0;
1626 }
1627
1628 57785 static int mvp_data(VVCLocalContext *lc)
1629 {
1630 57785 const VVCFrameContext *fc = lc->fc;
1631 57785 const CodingUnit *cu = lc->cu;
1632 57785 PredictionUnit *pu = &lc->cu->pu;
1633 57785 const VVCSPS *sps = fc->ps.sps;
1634 57785 const VVCPH *ph = &fc->ps.ph;
1635 57785 const VVCSH *sh = &lc->sc->sh;
1636 57785 const H266RawSliceHeader *rsh = sh->r;
1637 57785 MotionInfo *mi = &pu->mi;
1638 57785 const int cb_width = cu->cb_width;
1639 57785 const int cb_height = cu->cb_height;
1640
1641 57785 int mvp_lx_flag[2] = {0};
1642 57785 int cu_affine_type_flag = 0;
1643 int num_cp_mv;
1644 57785 int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1645 Mv mvds[2][MAX_CONTROL_POINTS];
1646
1647 57785 mi->pred_flag = ff_vvc_pred_flag(lc, IS_B(rsh));
1648
5/6
✓ Branch 0 taken 57785 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33237 times.
✓ Branch 3 taken 24548 times.
✓ Branch 4 taken 25671 times.
✓ Branch 5 taken 7566 times.
57785 if (sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1649 25671 pu->inter_affine_flag = ff_vvc_inter_affine_flag(lc);
1650 25671 set_cb_tab(lc, fc->tab.iaf, pu->inter_affine_flag);
1651
3/4
✓ Branch 0 taken 25671 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9102 times.
✓ Branch 3 taken 16569 times.
25671 if (sps->r->sps_6param_affine_enabled_flag && pu->inter_affine_flag)
1652 9102 cu_affine_type_flag = ff_vvc_cu_affine_type_flag(lc);
1653 }
1654 57785 mi->motion_model_idc = pu->inter_affine_flag + cu_affine_type_flag;
1655 57785 num_cp_mv = mi->motion_model_idc + 1;
1656
1657
4/4
✓ Branch 0 taken 47609 times.
✓ Branch 1 taken 10176 times.
✓ Branch 2 taken 37569 times.
✓ Branch 3 taken 10040 times.
57785 if (sps->r->sps_smvd_enabled_flag && !ph->r->ph_mvd_l1_zero_flag &&
1658
4/4
✓ Branch 0 taken 12561 times.
✓ Branch 1 taken 25008 times.
✓ Branch 2 taken 11430 times.
✓ Branch 3 taken 1131 times.
37569 mi->pred_flag == PF_BI && !pu->inter_affine_flag &&
1659
2/4
✓ Branch 0 taken 11430 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11430 times.
✗ Branch 3 not taken.
11430 sh->ref_idx_sym[0] > -1 && sh->ref_idx_sym[1] > -1)
1660 11430 pu->sym_mvd_flag = ff_vvc_sym_mvd_flag(lc);
1661
1662
2/2
✓ Branch 0 taken 115570 times.
✓ Branch 1 taken 57785 times.
173355 for (int i = L0; i <= L1; i++) {
1663
2/2
✓ Branch 0 taken 57785 times.
✓ Branch 1 taken 57785 times.
115570 const PredFlag pred_flag = PF_L0 + !i;
1664
2/2
✓ Branch 0 taken 74860 times.
✓ Branch 1 taken 40710 times.
115570 if (mi->pred_flag != pred_flag) {
1665 74860 mi->ref_idx[i] = ref_idx_decode(lc, sh, pu->sym_mvd_flag, i);
1666 74860 has_no_zero_mvd |= mvds_decode(lc, mvds, num_cp_mv, i);
1667 74860 mvp_lx_flag[i] = ff_vvc_mvp_lx_flag(lc);
1668 }
1669 }
1670
1671 115570 amvr_enabled = mi->motion_model_idc == MOTION_TRANSLATION ?
1672
2/2
✓ Branch 0 taken 48683 times.
✓ Branch 1 taken 9102 times.
57785 sps->r->sps_amvr_enabled_flag : sps->r->sps_affine_amvr_enabled_flag;
1673 57785 amvr_enabled &= has_no_zero_mvd;
1674
1675 57785 amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, amvr_enabled);
1676
1677 57785 mi->hpel_if_idx = amvr_shift == 3;
1678 57785 mi->bcw_idx = bcw_idx_decode(lc, mi, cb_width, cb_height);
1679
1680
2/2
✓ Branch 0 taken 9102 times.
✓ Branch 1 taken 48683 times.
57785 if (mi->motion_model_idc)
1681 9102 ff_vvc_affine_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1682 else
1683 48683 ff_vvc_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1684
1685 57785 mvp_add_difference(mi, num_cp_mv, mvds, amvr_shift);
1686
1687
2/2
✓ Branch 0 taken 9102 times.
✓ Branch 1 taken 48683 times.
57785 if (mi->motion_model_idc)
1688 9102 ff_vvc_store_sb_mvs(lc, pu);
1689 else
1690 48683 ff_vvc_store_mv(lc, &pu->mi);
1691
1692 57785 return 0;
1693 }
1694
1695 // derive bdofFlag from 8.5.6 Decoding process for inter blocks
1696 // derive dmvr from 8.5.1 General decoding process for coding units coded in inter prediction mode
1697 314358 static void derive_dmvr_bdof_flag(const VVCLocalContext *lc, PredictionUnit *pu)
1698 {
1699 314358 const VVCFrameContext *fc = lc->fc;
1700 314358 const VVCPPS *pps = fc->ps.pps;
1701 314358 const VVCPH *ph = &fc->ps.ph;
1702 314358 const VVCSH *sh = &lc->sc->sh;
1703 314358 const int poc = ph->poc;
1704 314358 const MotionInfo *mi = &pu->mi;
1705 314358 const int8_t *ref_idx = mi->ref_idx;
1706 314358 const VVCRefPic *rp0 = &lc->sc->rpl[L0].refs[ref_idx[L0]];
1707 314358 const VVCRefPic *rp1 = &lc->sc->rpl[L1].refs[ref_idx[L1]];
1708 314358 const CodingUnit *cu = lc->cu;
1709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 314358 times.
314358 const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
1710
1711 314358 pu->bdof_flag = 0;
1712
1713
2/2
✓ Branch 0 taken 167832 times.
✓ Branch 1 taken 146526 times.
314358 if (mi->pred_flag == PF_BI &&
1714
2/2
✓ Branch 0 taken 114623 times.
✓ Branch 1 taken 53209 times.
167832 (poc - rp0->poc == rp1->poc - poc) &&
1715
2/4
✓ Branch 0 taken 114623 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 114623 times.
✗ Branch 3 not taken.
114623 !rp0->is_lt && !rp1->is_lt &&
1716
2/2
✓ Branch 0 taken 111903 times.
✓ Branch 1 taken 2720 times.
114623 !cu->ciip_flag &&
1717
2/2
✓ Branch 0 taken 98407 times.
✓ Branch 1 taken 13496 times.
111903 !mi->bcw_idx &&
1718
3/4
✓ Branch 0 taken 97437 times.
✓ Branch 1 taken 970 times.
✓ Branch 2 taken 97437 times.
✗ Branch 3 not taken.
98407 !w->weight_flag[L0][LUMA][ref_idx[L0]] && !w->weight_flag[L1][LUMA][ref_idx[L1]] &&
1719
2/4
✓ Branch 0 taken 97437 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 97437 times.
✗ Branch 3 not taken.
97437 !w->weight_flag[L0][CHROMA][ref_idx[L0]] && !w->weight_flag[L1][CHROMA][ref_idx[L1]] &&
1720
4/4
✓ Branch 0 taken 91685 times.
✓ Branch 1 taken 5752 times.
✓ Branch 2 taken 88098 times.
✓ Branch 3 taken 3587 times.
97437 cu->cb_width >= 8 && cu->cb_height >= 8 &&
1721
2/2
✓ Branch 0 taken 83260 times.
✓ Branch 1 taken 4838 times.
88098 (cu->cb_width * cu->cb_height >= 128) &&
1722
2/4
✓ Branch 0 taken 83260 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 83260 times.
✗ Branch 3 not taken.
83260 !rp0->is_scaled && !rp1->is_scaled) {
1723
1/2
✓ Branch 0 taken 83260 times.
✗ Branch 1 not taken.
83260 if (!ph->r->ph_bdof_disabled_flag &&
1724
1/2
✓ Branch 0 taken 83260 times.
✗ Branch 1 not taken.
83260 mi->motion_model_idc == MOTION_TRANSLATION &&
1725
1/2
✓ Branch 0 taken 83260 times.
✗ Branch 1 not taken.
83260 !pu->merge_subblock_flag &&
1726
2/2
✓ Branch 0 taken 80450 times.
✓ Branch 1 taken 2810 times.
83260 !pu->sym_mvd_flag)
1727 80450 pu->bdof_flag = 1;
1728
2/2
✓ Branch 0 taken 80803 times.
✓ Branch 1 taken 2457 times.
83260 if (!ph->r->ph_dmvr_disabled_flag &&
1729
2/2
✓ Branch 0 taken 75478 times.
✓ Branch 1 taken 5325 times.
80803 pu->general_merge_flag &&
1730
2/2
✓ Branch 0 taken 68451 times.
✓ Branch 1 taken 7027 times.
75478 !pu->mmvd_merge_flag)
1731 68451 pu->dmvr_flag = 1;
1732 }
1733 314358 }
1734
1735 // part of 8.5.1 General decoding process for coding units coded in inter prediction mode
1736 314358 static void refine_regular_subblock(const VVCLocalContext *lc)
1737 {
1738 314358 const CodingUnit *cu = lc->cu;
1739 314358 PredictionUnit *pu = &lc->cu->pu;
1740
1741 314358 derive_dmvr_bdof_flag(lc, pu);
1742
4/4
✓ Branch 0 taken 245907 times.
✓ Branch 1 taken 68451 times.
✓ Branch 2 taken 11999 times.
✓ Branch 3 taken 233908 times.
314358 if (pu->dmvr_flag || pu->bdof_flag) {
1743
2/2
✓ Branch 0 taken 47628 times.
✓ Branch 1 taken 32822 times.
80450 pu->mi.num_sb_x = (cu->cb_width > 16) ? (cu->cb_width >> 4) : 1;
1744
2/2
✓ Branch 0 taken 45500 times.
✓ Branch 1 taken 34950 times.
80450 pu->mi.num_sb_y = (cu->cb_height > 16) ? (cu->cb_height >> 4) : 1;
1745 }
1746 314358 }
1747
1748 330049 static void fill_dmvr_info(const VVCLocalContext *lc)
1749 {
1750 330049 const VVCFrameContext *fc = lc->fc;
1751 330049 const CodingUnit *cu = lc->cu;
1752
1753
2/2
✓ Branch 0 taken 1582 times.
✓ Branch 1 taken 328467 times.
330049 if (cu->pred_mode == MODE_IBC) {
1754 1582 ff_vvc_set_intra_mvf(lc, 1);
1755 } else {
1756 328467 const VVCPPS *pps = fc->ps.pps;
1757 328467 const int w = cu->cb_width >> MIN_PU_LOG2;
1758
1759
2/2
✓ Branch 0 taken 1890903 times.
✓ Branch 1 taken 328467 times.
2219370 for (int y = cu->y0 >> MIN_PU_LOG2; y < (cu->y0 + cu->cb_height) >> MIN_PU_LOG2; y++) {
1760 1890903 const int idx = pps->min_pu_width * y + (cu->x0 >> MIN_PU_LOG2);
1761 1890903 const MvField *mvf = fc->tab.mvf + idx;
1762 1890903 MvField *dmvr_mvf = fc->ref->tab_dmvr_mvf + idx;
1763
1764 1890903 memcpy(dmvr_mvf, mvf, sizeof(MvField) * w);
1765 }
1766 }
1767 330049 }
1768
1769 398500 static int inter_data(VVCLocalContext *lc)
1770 {
1771 398500 const CodingUnit *cu = lc->cu;
1772 398500 PredictionUnit *pu = &lc->cu->pu;
1773 398500 const MotionInfo *mi = &pu->mi;
1774 398500 int ret = 0;
1775
1776 398500 pu->general_merge_flag = 1;
1777
2/2
✓ Branch 0 taken 168217 times.
✓ Branch 1 taken 230283 times.
398500 if (!cu->skip_flag)
1778 168217 pu->general_merge_flag = ff_vvc_general_merge_flag(lc);
1779
1780
2/2
✓ Branch 0 taken 339373 times.
✓ Branch 1 taken 59127 times.
398500 if (pu->general_merge_flag) {
1781 339373 hls_merge_data(lc);
1782
2/2
✓ Branch 0 taken 1342 times.
✓ Branch 1 taken 57785 times.
59127 } else if (cu->pred_mode == MODE_IBC){
1783 1342 ret = mvp_data_ibc(lc);
1784 } else {
1785 57785 ret = mvp_data(lc);
1786 }
1787
1788
2/2
✓ Branch 0 taken 1582 times.
✓ Branch 1 taken 396918 times.
398500 if (cu->pred_mode == MODE_IBC)
1789 {
1790 1582 ff_vvc_update_hmvp(lc, mi);
1791
6/6
✓ Branch 0 taken 372181 times.
✓ Branch 1 taken 24737 times.
✓ Branch 2 taken 339712 times.
✓ Branch 3 taken 32469 times.
✓ Branch 4 taken 314358 times.
✓ Branch 5 taken 25354 times.
396918 } else if (!pu->merge_gpm_flag && !pu->inter_affine_flag && !pu->merge_subblock_flag) {
1792 314358 refine_regular_subblock(lc);
1793 314358 ff_vvc_update_hmvp(lc, mi);
1794 }
1795
1796
2/2
✓ Branch 0 taken 330049 times.
✓ Branch 1 taken 68451 times.
398500 if (!pu->dmvr_flag)
1797 330049 fill_dmvr_info(lc);
1798 398500 return ret;
1799 }
1800
1801 1085050 static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height,
1802 int cqt_depth, const VVCTreeType tree_type, VVCModeType mode_type)
1803 {
1804 1085050 const VVCFrameContext *fc = lc->fc;
1805 1085050 const VVCSPS *sps = fc->ps.sps;
1806 1085050 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1807 1085050 const int hs = sps->hshift[CHROMA];
1808 1085050 const int vs = sps->vshift[CHROMA];
1809
4/4
✓ Branch 0 taken 1063073 times.
✓ Branch 1 taken 21977 times.
✓ Branch 2 taken 2153 times.
✓ Branch 3 taken 1060920 times.
1085050 const int is_128 = cb_width > 64 || cb_height > 64;
1810 1085050 int pred_mode_plt_flag = 0;
1811 int ret;
1812
1813 1085050 CodingUnit *cu = add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
1814
1815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1085050 times.
1085050 if (!cu)
1816 return AVERROR(ENOMEM);
1817
1818 1085050 ff_vvc_set_neighbour_available(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1819
1820
3/4
✓ Branch 0 taken 609002 times.
✓ Branch 1 taken 476048 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 609002 times.
1085050 if (IS_I(rsh) && is_128)
1821 mode_type = MODE_TYPE_INTRA;
1822 1085050 cu->pred_mode = pred_mode_decode(lc, tree_type, mode_type);
1823
1824
3/10
✓ Branch 0 taken 686550 times.
✓ Branch 1 taken 398500 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 686550 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
1085050 if (cu->pred_mode == MODE_INTRA && sps->r->sps_palette_enabled_flag && !is_128 && !cu->skip_flag &&
1825 mode_type != MODE_TYPE_INTER && ((cb_width * cb_height) >
1826 (tree_type != DUAL_TREE_CHROMA ? 16 : (16 << hs << vs))) &&
1827 (mode_type != MODE_TYPE_INTRA || tree_type != DUAL_TREE_CHROMA)) {
1828 pred_mode_plt_flag = ff_vvc_pred_mode_plt_flag(lc);
1829 if (pred_mode_plt_flag) {
1830 avpriv_report_missing_feature(fc->log_ctx, "Palette");
1831 return AVERROR_PATCHWELCOME;
1832 }
1833 }
1834
3/6
✓ Branch 0 taken 686550 times.
✓ Branch 1 taken 398500 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 686550 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1085050 if (cu->pred_mode == MODE_INTRA && sps->r->sps_act_enabled_flag && tree_type == SINGLE_TREE) {
1835 avpriv_report_missing_feature(fc->log_ctx, "Adaptive Color Transform");
1836 return AVERROR_PATCHWELCOME;
1837 }
1838
3/4
✓ Branch 0 taken 398500 times.
✓ Branch 1 taken 686550 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 398500 times.
1085050 if (cu->pred_mode == MODE_INTRA || cu->pred_mode == MODE_PLT) {
1839
4/4
✓ Branch 0 taken 631482 times.
✓ Branch 1 taken 55068 times.
✓ Branch 2 taken 474484 times.
✓ Branch 3 taken 156998 times.
686550 if (tree_type == SINGLE_TREE || tree_type == DUAL_TREE_LUMA) {
1840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 529552 times.
529552 if (pred_mode_plt_flag) {
1841 avpriv_report_missing_feature(fc->log_ctx, "Palette");
1842 return AVERROR_PATCHWELCOME;
1843 } else {
1844 529552 intra_luma_pred_modes(lc);
1845 }
1846 529552 ff_vvc_set_intra_mvf(lc, 0);
1847 }
1848
6/6
✓ Branch 0 taken 631482 times.
✓ Branch 1 taken 55068 times.
✓ Branch 2 taken 156998 times.
✓ Branch 3 taken 474484 times.
✓ Branch 4 taken 196944 times.
✓ Branch 5 taken 15122 times.
686550 if ((tree_type == SINGLE_TREE || tree_type == DUAL_TREE_CHROMA) && sps->r->sps_chroma_format_idc) {
1849
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 196944 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
196944 if (pred_mode_plt_flag && tree_type == DUAL_TREE_CHROMA) {
1850 avpriv_report_missing_feature(fc->log_ctx, "Palette");
1851 return AVERROR_PATCHWELCOME;
1852
1/2
✓ Branch 0 taken 196944 times.
✗ Branch 1 not taken.
196944 } else if (!pred_mode_plt_flag) {
1853
1/2
✓ Branch 0 taken 196944 times.
✗ Branch 1 not taken.
196944 if (!cu->act_enabled_flag)
1854 196944 intra_chroma_pred_modes(lc);
1855 }
1856 }
1857
1/2
✓ Branch 0 taken 398500 times.
✗ Branch 1 not taken.
398500 } else if (tree_type != DUAL_TREE_CHROMA) { /* MODE_INTER or MODE_IBC */
1858
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 398500 times.
398500 if ((ret = inter_data(lc)) < 0)
1859 return ret;
1860 }
1861
5/6
✓ Branch 0 taken 398500 times.
✓ Branch 1 taken 686550 times.
✓ Branch 2 taken 398500 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 59127 times.
✓ Branch 5 taken 339373 times.
1085050 if (cu->pred_mode != MODE_INTRA && !pred_mode_plt_flag && !lc->cu->pu.general_merge_flag)
1862 59127 cu->coded_flag = ff_vvc_cu_coded_flag(lc);
1863 else
1864
3/4
✓ Branch 0 taken 795640 times.
✓ Branch 1 taken 230283 times.
✓ Branch 2 taken 795640 times.
✗ Branch 3 not taken.
1025923 cu->coded_flag = !(cu->skip_flag || pred_mode_plt_flag);
1865
1866
2/2
✓ Branch 0 taken 823003 times.
✓ Branch 1 taken 262047 times.
1085050 if (cu->coded_flag) {
1867 823003 sbt_info(lc, sps);
1868
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 823003 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
823003 if (sps->r->sps_act_enabled_flag && cu->pred_mode != MODE_INTRA && tree_type == SINGLE_TREE) {
1869 avpriv_report_missing_feature(fc->log_ctx, "Adaptive Color Transform");
1870 return AVERROR_PATCHWELCOME;
1871 }
1872 823003 lc->parse.lfnst_dc_only = 1;
1873 823003 lc->parse.lfnst_zero_out_sig_coeff_flag = 1;
1874 823003 lc->parse.mts_dc_only = 1;
1875 823003 lc->parse.mts_zero_out_sig_coeff_flag = 1;
1876 823003 ret = hls_transform_tree(lc, x0, y0, cb_width, cb_height, cu->ch_type);
1877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 823003 times.
823003 if (ret < 0)
1878 return ret;
1879 823003 cu->lfnst_idx = lfnst_idx_decode(lc);
1880 823003 cu->mts_idx = mts_idx_decode(lc);
1881 823003 set_qp_c(lc);
1882 } else {
1883 262047 ret = skipped_transform_tree_unit(lc);
1884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 262047 times.
262047 if (ret < 0)
1885 return ret;
1886 }
1887 1085050 set_cu_tabs(lc, cu);
1888
1889 1085050 return 0;
1890 }
1891
1892 709056 static int derive_mode_type_condition(const VVCLocalContext *lc,
1893 const VVCSplitMode split, const int cb_width, const int cb_height, const VVCModeType mode_type_curr)
1894 {
1895 709056 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1896 709056 const VVCSPS *sps = lc->fc->ps.sps;
1897 709056 const int area = cb_width * cb_height;
1898
1899
6/6
✓ Branch 0 taken 411813 times.
✓ Branch 1 taken 297243 times.
✓ Branch 2 taken 7116 times.
✓ Branch 3 taken 404697 times.
✓ Branch 4 taken 295364 times.
✓ Branch 5 taken 8995 times.
709056 if ((IS_I(rsh) && sps->r->sps_qtbtt_dual_tree_intra_flag) ||
1900
2/2
✓ Branch 0 taken 271185 times.
✓ Branch 1 taken 24179 times.
295364 mode_type_curr != MODE_TYPE_ALL || !sps->r->sps_chroma_format_idc ||
1901
2/2
✓ Branch 0 taken 41943 times.
✓ Branch 1 taken 229242 times.
271185 sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
1902 479814 return 0;
1903
7/10
✓ Branch 0 taken 9504 times.
✓ Branch 1 taken 219738 times.
✓ Branch 2 taken 9504 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9504 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8918 times.
✓ Branch 7 taken 586 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 228656 times.
229242 if ((area == 64 && (split == SPLIT_QT || split == SPLIT_TT_HOR || split == SPLIT_TT_VER)) ||
1904 (area == 32 && (split == SPLIT_BT_HOR || split == SPLIT_BT_VER)))
1905 586 return 1;
1906
8/10
✓ Branch 0 taken 8918 times.
✓ Branch 1 taken 219738 times.
✓ Branch 2 taken 5572 times.
✓ Branch 3 taken 3346 times.
✓ Branch 4 taken 5572 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 8918 times.
✓ Branch 8 taken 21318 times.
✓ Branch 9 taken 198420 times.
228656 if ((area == 64 && (split == SPLIT_BT_HOR || split == SPLIT_BT_VER) && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_420) ||
1907
7/8
✓ Branch 0 taken 18977 times.
✓ Branch 1 taken 2341 times.
✓ Branch 2 taken 2755 times.
✓ Branch 3 taken 16222 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5096 times.
✓ Branch 6 taken 17347 times.
✓ Branch 7 taken 197295 times.
219738 (area == 128 && (split == SPLIT_TT_HOR || split == SPLIT_TT_VER) && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_420) ||
1908
6/6
✓ Branch 0 taken 12017 times.
✓ Branch 1 taken 5330 times.
✓ Branch 2 taken 59395 times.
✓ Branch 3 taken 149917 times.
✓ Branch 4 taken 8299 times.
✓ Branch 5 taken 51096 times.
214642 (cb_width == 8 && split == SPLIT_BT_VER) || (cb_width == 16 && split == SPLIT_TT_VER))
1909
2/2
✓ Branch 0 taken 27488 times.
✓ Branch 1 taken 155 times.
27643 return 1 + !IS_I(rsh);
1910
1911 201013 return 0;
1912 }
1913
1914 709056 static VVCModeType mode_type_decode(VVCLocalContext *lc, const int x0, const int y0,
1915 const int cb_width, const int cb_height, const VVCSplitMode split, const int ch_type,
1916 const VVCModeType mode_type_curr)
1917 {
1918 VVCModeType mode_type;
1919 709056 const int mode_type_condition = derive_mode_type_condition(lc, split, cb_width, cb_height, mode_type_curr);
1920
1921
2/2
✓ Branch 0 taken 741 times.
✓ Branch 1 taken 708315 times.
709056 if (mode_type_condition == 1)
1922 741 mode_type = MODE_TYPE_INTRA;
1923
2/2
✓ Branch 0 taken 27488 times.
✓ Branch 1 taken 680827 times.
708315 else if (mode_type_condition == 2) {
1924
2/2
✓ Branch 1 taken 7623 times.
✓ Branch 2 taken 19865 times.
27488 mode_type = ff_vvc_non_inter_flag(lc, x0, y0, ch_type) ? MODE_TYPE_INTRA : MODE_TYPE_INTER;
1925 } else {
1926 680827 mode_type = mode_type_curr;
1927 }
1928
1929 709056 return mode_type;
1930 }
1931
1932 static int hls_coding_tree(VVCLocalContext *lc,
1933 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
1934 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx,
1935 VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr);
1936
1937 212191 static int coding_tree_btv(VVCLocalContext *lc,
1938 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
1939 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
1940 VVCTreeType tree_type, VVCModeType mode_type)
1941 {
1942 #define CODING_TREE(x, idx) do { \
1943 ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
1944 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
1945 depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
1946 if (ret < 0) \
1947 return ret; \
1948 } while (0);
1949
1950 212191 const VVCPPS *pps = lc->fc->ps.pps;
1951 212191 const int x1 = x0 + cb_width / 2;
1952 212191 int ret = 0;
1953
1954 212191 depth_offset += (x0 + cb_width > pps->width) ? 1 : 0;
1955
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 212191 times.
212191 CODING_TREE(x0, 0);
1956
2/2
✓ Branch 0 taken 211019 times.
✓ Branch 1 taken 1172 times.
212191 if (x1 < pps->width)
1957
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 211019 times.
211019 CODING_TREE(x1, 1);
1958
1959 212191 return 0;
1960
1961 #undef CODING_TREE
1962 }
1963
1964 265185 static int coding_tree_bth(VVCLocalContext *lc,
1965 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
1966 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
1967 VVCTreeType tree_type, VVCModeType mode_type)
1968 {
1969 #define CODING_TREE(y, idx) do { \
1970 ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
1971 qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
1972 depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
1973 if (ret < 0) \
1974 return ret; \
1975 } while (0);
1976
1977 265185 const VVCPPS *pps = lc->fc->ps.pps;
1978 265185 const int y1 = y0 + (cb_height / 2);
1979 265185 int ret = 0;
1980
1981 265185 depth_offset += (y0 + cb_height > pps->height) ? 1 : 0;
1982
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 265185 times.
265185 CODING_TREE(y0, 0);
1983
2/2
✓ Branch 0 taken 248143 times.
✓ Branch 1 taken 17042 times.
265185 if (y1 < pps->height)
1984
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 248143 times.
248143 CODING_TREE(y1, 1);
1985
1986 265185 return 0;
1987
1988 #undef CODING_TREE
1989 }
1990
1991 67604 static int coding_tree_ttv(VVCLocalContext *lc,
1992 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
1993 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
1994 VVCTreeType tree_type, VVCModeType mode_type)
1995 {
1996 #define CODING_TREE(x, w, sub_div, idx) do { \
1997 ret = hls_coding_tree(lc, x, y0, w, cb_height, \
1998 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
1999 depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
2000 if (ret < 0) \
2001 return ret; \
2002 } while (0);
2003
2004 67604 const VVCSH *sh = &lc->sc->sh;
2005 67604 const int x1 = x0 + cb_width / 4;
2006 67604 const int x2 = x0 + cb_width * 3 / 4;
2007 int ret;
2008
2009
3/4
✓ Branch 0 taken 45056 times.
✓ Branch 1 taken 22548 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45056 times.
67604 qg_on_y = qg_on_y && (cb_sub_div + 2 <= sh->cu_qp_delta_subdiv);
2010
3/4
✓ Branch 0 taken 31955 times.
✓ Branch 1 taken 35649 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31955 times.
67604 qg_on_c = qg_on_c && (cb_sub_div + 2 <= sh->cu_chroma_qp_offset_subdiv);
2011
2012
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 67604 times.
67604 CODING_TREE(x0, cb_width / 4, cb_sub_div + 2, 0);
2013
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 67604 times.
67604 CODING_TREE(x1, cb_width / 2, cb_sub_div + 1, 1);
2014
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 67604 times.
67604 CODING_TREE(x2, cb_width / 4, cb_sub_div + 2, 2);
2015
2016 67604 return 0;
2017
2018 #undef CODING_TREE
2019 }
2020
2021 71930 static int coding_tree_tth(VVCLocalContext *lc,
2022 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2023 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2024 VVCTreeType tree_type, VVCModeType mode_type)
2025 {
2026 #define CODING_TREE(y, h, sub_div, idx) do { \
2027 ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2028 qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2029 depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2030 if (ret < 0) \
2031 return ret; \
2032 } while (0);
2033
2034 71930 const VVCSH *sh = &lc->sc->sh;
2035 71930 const int y1 = y0 + (cb_height / 4);
2036 71930 const int y2 = y0 + (3 * cb_height / 4);
2037 int ret;
2038
2039
3/4
✓ Branch 0 taken 45670 times.
✓ Branch 1 taken 26260 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45670 times.
71930 qg_on_y = qg_on_y && (cb_sub_div + 2 <= sh->cu_qp_delta_subdiv);
2040
3/4
✓ Branch 0 taken 28201 times.
✓ Branch 1 taken 43729 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 28201 times.
71930 qg_on_c = qg_on_c && (cb_sub_div + 2 <= sh->cu_chroma_qp_offset_subdiv);
2041
2042
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 71930 times.
71930 CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2043
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 71930 times.
71930 CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2044
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 71930 times.
71930 CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2045
2046 71930 return 0;
2047
2048 #undef CODING_TREE
2049 }
2050
2051 92146 static int coding_tree_qt(VVCLocalContext *lc,
2052 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2053 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2054 VVCTreeType tree_type, VVCModeType mode_type)
2055 {
2056 #define CODING_TREE(x, y, idx) do { \
2057 ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2058 qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2059 idx, SPLIT_QT, tree_type, mode_type); \
2060 if (ret < 0) \
2061 return ret; \
2062 } while (0);
2063
2064 92146 const VVCPPS *pps = lc->fc->ps.pps;
2065 92146 const int x1 = x0 + cb_width / 2;
2066 92146 const int y1 = y0 + cb_height / 2;
2067 92146 int ret = 0;
2068
2069
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 92146 times.
92146 CODING_TREE(x0, y0, 0);
2070
2/2
✓ Branch 0 taken 89268 times.
✓ Branch 1 taken 2878 times.
92146 if (x1 < pps->width)
2071
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 89268 times.
89268 CODING_TREE(x1, y0, 1);
2072
2/2
✓ Branch 0 taken 86715 times.
✓ Branch 1 taken 5431 times.
92146 if (y1 < pps->height)
2073
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 86715 times.
86715 CODING_TREE(x0, y1, 2);
2074
2/2
✓ Branch 0 taken 89268 times.
✓ Branch 1 taken 2878 times.
92146 if (x1 < pps->width &&
2075
2/2
✓ Branch 0 taken 83845 times.
✓ Branch 1 taken 5423 times.
89268 y1 < pps->height)
2076
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 83845 times.
83845 CODING_TREE(x1, y1, 3);
2077
2078 92146 return 0;
2079
2080 #undef CODING_TREE
2081 }
2082
2083 typedef int (*coding_tree_fn)(VVCLocalContext *lc,
2084 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2085 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2086 VVCTreeType tree_type, VVCModeType mode_type);
2087
2088 const static coding_tree_fn coding_tree[] = {
2089 coding_tree_tth,
2090 coding_tree_bth,
2091 coding_tree_ttv,
2092 coding_tree_btv,
2093 coding_tree_qt,
2094 };
2095
2096 1794106 static int hls_coding_tree(VVCLocalContext *lc,
2097 int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2098 int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx,
2099 VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr)
2100 {
2101 1794106 VVCFrameContext *fc = lc->fc;
2102 1794106 const VVCPPS *pps = fc->ps.pps;
2103 1794106 const VVCSH *sh = &lc->sc->sh;
2104 1794106 const H266RawSliceHeader *rsh = sh->r;
2105 1794106 const int ch_type = tree_type_curr == DUAL_TREE_CHROMA;
2106 int ret;
2107 VVCAllowedSplit allowed;
2108
2109
6/6
✓ Branch 0 taken 44856 times.
✓ Branch 1 taken 1749250 times.
✓ Branch 2 taken 25516 times.
✓ Branch 3 taken 19340 times.
✓ Branch 4 taken 464 times.
✓ Branch 5 taken 25052 times.
1794106 if (pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2110 464 lc->parse.is_cu_qp_delta_coded = 0;
2111 464 lc->parse.cu_qg_top_left_x = x0;
2112 464 lc->parse.cu_qg_top_left_y = y0;
2113 }
2114
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1794106 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1794106 if (rsh->sh_cu_chroma_qp_offset_enabled_flag && qg_on_c &&
2115 cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2116 lc->parse.is_cu_chroma_qp_offset_coded = 0;
2117 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2118 }
2119
2120 1794106 can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2121 last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2122
2/2
✓ Branch 1 taken 709056 times.
✓ Branch 2 taken 1085050 times.
1794106 if (ff_vvc_split_cu_flag(lc, x0, y0, cb_width, cb_height, ch_type, &allowed)) {
2123 709056 VVCSplitMode split = ff_vvc_split_mode(lc, x0, y0, cb_width, cb_height, cqt_depth, mtt_depth, ch_type, &allowed);
2124 709056 VVCModeType mode_type = mode_type_decode(lc, x0, y0, cb_width, cb_height, split, ch_type, mode_type_curr);
2125
2126
2/2
✓ Branch 0 taken 695922 times.
✓ Branch 1 taken 13134 times.
709056 VVCTreeType tree_type = (mode_type == MODE_TYPE_INTRA) ? DUAL_TREE_LUMA : tree_type_curr;
2127
2128
2/2
✓ Branch 0 taken 616910 times.
✓ Branch 1 taken 92146 times.
709056 if (split != SPLIT_QT) {
2129
6/6
✓ Branch 0 taken 393567 times.
✓ Branch 1 taken 223343 times.
✓ Branch 2 taken 263210 times.
✓ Branch 3 taken 130357 times.
✓ Branch 4 taken 228433 times.
✓ Branch 5 taken 34777 times.
616910 if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2130 228433 TAB_MSM(fc, mtt_depth, x0, y0) = split;
2131 }
2132 709056 ret = coding_tree[split - 1](lc, x0, y0, cb_width, cb_height, qg_on_y, qg_on_c,
2133 cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 709056 times.
709056 if (ret < 0)
2135 return ret;
2136
4/4
✓ Branch 0 taken 700061 times.
✓ Branch 1 taken 8995 times.
✓ Branch 2 taken 8364 times.
✓ Branch 3 taken 691697 times.
709056 if (mode_type_curr == MODE_TYPE_ALL && mode_type == MODE_TYPE_INTRA) {
2137 8364 ret = hls_coding_tree(lc, x0, y0, cb_width, cb_height, 0, qg_on_c, cb_sub_div,
2138 cqt_depth, mtt_depth, 0, 0, split, DUAL_TREE_CHROMA, mode_type);
2139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8364 times.
8364 if (ret < 0)
2140 return ret;
2141 }
2142 } else {
2143 1085050 ret = hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1085050 times.
1085050 if (ret < 0)
2145 return ret;
2146 }
2147
2148 1794106 return 0;
2149 }
2150
2151 25007 static int dual_tree_implicit_qt_split(VVCLocalContext *lc,
2152 const int x0, const int y0, const int cb_size, const int cqt_depth)
2153 {
2154 25007 const VVCSH *sh = &lc->sc->sh;
2155 25007 const H266RawSliceHeader *rsh = sh->r;
2156 25007 const VVCPPS *pps = lc->fc->ps.pps;
2157 25007 const int cb_subdiv = 2 * cqt_depth;
2158 int ret;
2159
2160
2/2
✓ Branch 0 taken 5174 times.
✓ Branch 1 taken 19833 times.
25007 if (cb_size > 64) {
2161 #define DUAL_TREE(x, y) do { \
2162 ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2163 if (ret < 0) \
2164 return ret; \
2165 } while (0)
2166
2167 5174 const int x1 = x0 + (cb_size / 2);
2168 5174 const int y1 = y0 + (cb_size / 2);
2169
3/4
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 5142 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
5174 if (pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2170 32 lc->parse.is_cu_qp_delta_coded = 0;
2171 32 lc->parse.cu_qg_top_left_x = x0;
2172 32 lc->parse.cu_qg_top_left_y = y0;
2173 }
2174
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5174 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5174 if (rsh->sh_cu_chroma_qp_offset_enabled_flag && cb_subdiv <= sh->cu_chroma_qp_offset_subdiv) {
2175 lc->parse.is_cu_chroma_qp_offset_coded = 0;
2176 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2177 }
2178
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5174 times.
5174 DUAL_TREE(x0, y0);
2179
2/2
✓ Branch 0 taken 5025 times.
✓ Branch 1 taken 149 times.
5174 if (x1 < pps->width)
2180
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5025 times.
5025 DUAL_TREE(x1, y0);
2181
2/2
✓ Branch 0 taken 4682 times.
✓ Branch 1 taken 492 times.
5174 if (y1 < pps->height)
2182
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4682 times.
4682 DUAL_TREE(x0, y1);
2183
4/4
✓ Branch 0 taken 5025 times.
✓ Branch 1 taken 149 times.
✓ Branch 2 taken 4536 times.
✓ Branch 3 taken 489 times.
5174 if (x1 < pps->width && y1 < pps->height)
2184
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4536 times.
4536 DUAL_TREE(x1, y1);
2185 #undef DUAL_TREE
2186 } else {
2187 #define CODING_TREE(tree_type) do { \
2188 const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2189 ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2190 cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2191 if (ret < 0) \
2192 return ret; \
2193 } while (0)
2194
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 19833 times.
19833 CODING_TREE(DUAL_TREE_LUMA);
2195
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 19833 times.
19833 CODING_TREE(DUAL_TREE_CHROMA);
2196 #undef CODING_TREE
2197 }
2198 25007 return 0;
2199 }
2200
2201 #define SET_SAO(elem, value) \
2202 do { \
2203 if (!sao_merge_up_flag && !sao_merge_left_flag) \
2204 sao->elem = value; \
2205 else if (sao_merge_left_flag) \
2206 sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2207 else if (sao_merge_up_flag) \
2208 sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2209 else \
2210 sao->elem = 0; \
2211 } while (0)
2212
2213 44552 static void hls_sao(VVCLocalContext *lc, const int rx, const int ry)
2214 {
2215 44552 VVCFrameContext *fc = lc->fc;
2216 44552 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2217 44552 int sao_merge_left_flag = 0;
2218 44552 int sao_merge_up_flag = 0;
2219 44552 SAOParams *sao = &CTB(fc->tab.sao, rx, ry);
2220 int c_idx, i;
2221
2222
3/4
✓ Branch 0 taken 28125 times.
✓ Branch 1 taken 16427 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 28125 times.
44552 if (rsh->sh_sao_luma_used_flag || rsh->sh_sao_chroma_used_flag) {
2223
2/2
✓ Branch 0 taken 14869 times.
✓ Branch 1 taken 1558 times.
16427 if (rx > 0) {
2224
2/2
✓ Branch 0 taken 14317 times.
✓ Branch 1 taken 552 times.
14869 if (lc->ctb_left_flag)
2225 14317 sao_merge_left_flag = ff_vvc_sao_merge_flag_decode(lc);
2226 }
2227
4/4
✓ Branch 0 taken 13651 times.
✓ Branch 1 taken 2776 times.
✓ Branch 2 taken 6939 times.
✓ Branch 3 taken 6712 times.
16427 if (ry > 0 && !sao_merge_left_flag) {
2228
2/2
✓ Branch 0 taken 6333 times.
✓ Branch 1 taken 606 times.
6939 if (lc->ctb_up_flag)
2229 6333 sao_merge_up_flag = ff_vvc_sao_merge_flag_decode(lc);
2230 }
2231 }
2232
2233
4/4
✓ Branch 0 taken 176096 times.
✓ Branch 1 taken 1056 times.
✓ Branch 2 taken 132600 times.
✓ Branch 3 taken 44552 times.
177152 for (c_idx = 0; c_idx < (fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2234
2/2
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 88048 times.
132600 const int sao_used_flag = !c_idx ? rsh->sh_sao_luma_used_flag : rsh->sh_sao_chroma_used_flag;
2235
2/2
✓ Branch 0 taken 98047 times.
✓ Branch 1 taken 34553 times.
132600 if (!sao_used_flag) {
2236 98047 sao->type_idx[c_idx] = SAO_NOT_APPLIED;
2237 98047 continue;
2238 }
2239
2240
2/2
✓ Branch 0 taken 9063 times.
✓ Branch 1 taken 25490 times.
34553 if (c_idx == 2) {
2241 9063 sao->type_idx[2] = sao->type_idx[1];
2242 9063 sao->eo_class[2] = sao->eo_class[1];
2243 } else {
2244
7/8
✓ Branch 0 taken 22059 times.
✓ Branch 1 taken 3431 times.
✓ Branch 2 taken 10137 times.
✓ Branch 3 taken 11922 times.
✓ Branch 5 taken 11922 times.
✓ Branch 6 taken 3431 times.
✓ Branch 7 taken 3431 times.
✗ Branch 8 not taken.
25490 SET_SAO(type_idx[c_idx], ff_vvc_sao_type_idx_decode(lc));
2245 }
2246
2247
2/2
✓ Branch 0 taken 22072 times.
✓ Branch 1 taken 12481 times.
34553 if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
2248 22072 continue;
2249
2250
2/2
✓ Branch 0 taken 49924 times.
✓ Branch 1 taken 12481 times.
62405 for (i = 0; i < 4; i++)
2251
7/8
✓ Branch 0 taken 41152 times.
✓ Branch 1 taken 8772 times.
✓ Branch 2 taken 16336 times.
✓ Branch 3 taken 24816 times.
✓ Branch 5 taken 24816 times.
✓ Branch 6 taken 8772 times.
✓ Branch 7 taken 8772 times.
✗ Branch 8 not taken.
49924 SET_SAO(offset_abs[c_idx][i], ff_vvc_sao_offset_abs_decode(lc));
2252
2253
2/2
✓ Branch 0 taken 4894 times.
✓ Branch 1 taken 7587 times.
12481 if (sao->type_idx[c_idx] == SAO_BAND) {
2254
2/2
✓ Branch 0 taken 19576 times.
✓ Branch 1 taken 4894 times.
24470 for (i = 0; i < 4; i++) {
2255
2/2
✓ Branch 0 taken 6006 times.
✓ Branch 1 taken 13570 times.
19576 if (sao->offset_abs[c_idx][i]) {
2256
7/8
✓ Branch 0 taken 5258 times.
✓ Branch 1 taken 748 times.
✓ Branch 2 taken 1691 times.
✓ Branch 3 taken 3567 times.
✓ Branch 5 taken 3567 times.
✓ Branch 6 taken 748 times.
✓ Branch 7 taken 748 times.
✗ Branch 8 not taken.
6006 SET_SAO(offset_sign[c_idx][i],
2257 ff_vvc_sao_offset_sign_decode(lc));
2258 } else {
2259 13570 sao->offset_sign[c_idx][i] = 0;
2260 }
2261 }
2262
7/8
✓ Branch 0 taken 4282 times.
✓ Branch 1 taken 612 times.
✓ Branch 2 taken 1144 times.
✓ Branch 3 taken 3138 times.
✓ Branch 5 taken 3138 times.
✓ Branch 6 taken 612 times.
✓ Branch 7 taken 612 times.
✗ Branch 8 not taken.
4894 SET_SAO(band_position[c_idx], ff_vvc_sao_band_position_decode(lc));
2263
2/2
✓ Branch 0 taken 6233 times.
✓ Branch 1 taken 1354 times.
7587 } else if (c_idx != 2) {
2264
7/8
✓ Branch 0 taken 4936 times.
✓ Branch 1 taken 1297 times.
✓ Branch 2 taken 2298 times.
✓ Branch 3 taken 2638 times.
✓ Branch 5 taken 2638 times.
✓ Branch 6 taken 1297 times.
✓ Branch 7 taken 1297 times.
✗ Branch 8 not taken.
6233 SET_SAO(eo_class[c_idx], ff_vvc_sao_eo_class_decode(lc));
2265 }
2266
2267 // Inferred parameters
2268 12481 sao->offset_val[c_idx][0] = 0;
2269
2/2
✓ Branch 0 taken 49924 times.
✓ Branch 1 taken 12481 times.
62405 for (i = 0; i < 4; i++) {
2270 49924 sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
2271
2/2
✓ Branch 0 taken 30348 times.
✓ Branch 1 taken 19576 times.
49924 if (sao->type_idx[c_idx] == SAO_EDGE) {
2272
2/2
✓ Branch 0 taken 15174 times.
✓ Branch 1 taken 15174 times.
30348 if (i > 1)
2273 15174 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
2274
2/2
✓ Branch 0 taken 5088 times.
✓ Branch 1 taken 14488 times.
19576 } else if (sao->offset_sign[c_idx][i]) {
2275 5088 sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
2276 }
2277 49924 sao->offset_val[c_idx][i + 1] *= 1 << (fc->ps.sps->bit_depth - FFMIN(10, fc->ps.sps->bit_depth));
2278 }
2279 }
2280 44552 }
2281
2282 44552 static void alf_params(VVCLocalContext *lc, const int rx, const int ry)
2283 {
2284 44552 const VVCFrameContext *fc = lc->fc;
2285 44552 const H266RawSliceHeader *sh = lc->sc->sh.r;
2286 44552 ALFParams *alf = &CTB(fc->tab.alf, rx, ry);
2287
2288 44552 alf->ctb_flag[LUMA] = alf->ctb_flag[CB] = alf->ctb_flag[CR] = 0;
2289
2/2
✓ Branch 0 taken 26288 times.
✓ Branch 1 taken 18264 times.
44552 if (sh->sh_alf_enabled_flag) {
2290 26288 alf->ctb_flag[LUMA] = ff_vvc_alf_ctb_flag(lc, rx, ry, LUMA);
2291
2/2
✓ Branch 0 taken 18836 times.
✓ Branch 1 taken 7452 times.
26288 if (alf->ctb_flag[LUMA]) {
2292 18836 uint8_t alf_use_aps_flag = 0;
2293
2/2
✓ Branch 0 taken 18110 times.
✓ Branch 1 taken 726 times.
18836 if (sh->sh_num_alf_aps_ids_luma > 0)
2294 18110 alf_use_aps_flag = ff_vvc_alf_use_aps_flag(lc);
2295
2/2
✓ Branch 0 taken 16340 times.
✓ Branch 1 taken 2496 times.
18836 if (alf_use_aps_flag) {
2296 16340 alf->ctb_filt_set_idx_y = 16;
2297
2/2
✓ Branch 0 taken 4492 times.
✓ Branch 1 taken 11848 times.
16340 if (sh->sh_num_alf_aps_ids_luma > 1)
2298 4492 alf->ctb_filt_set_idx_y += ff_vvc_alf_luma_prev_filter_idx(lc);
2299 } else {
2300 2496 alf->ctb_filt_set_idx_y = ff_vvc_alf_luma_fixed_filter_idx(lc);
2301 }
2302 }
2303
2/2
✓ Branch 0 taken 52576 times.
✓ Branch 1 taken 26288 times.
78864 for (int c_idx = CB; c_idx <= CR; c_idx++) {
2304
2/2
✓ Branch 0 taken 26288 times.
✓ Branch 1 taken 26288 times.
52576 const uint8_t alf_enabled_flag =
2305 c_idx == CB ? sh->sh_alf_cb_enabled_flag : sh->sh_alf_cr_enabled_flag;
2306
2/2
✓ Branch 0 taken 31037 times.
✓ Branch 1 taken 21539 times.
52576 if (alf_enabled_flag) {
2307 31037 const VVCALF *aps = fc->ps.alf_list[sh->sh_alf_aps_id_chroma];
2308 31037 alf->ctb_flag[c_idx] = ff_vvc_alf_ctb_flag(lc, rx, ry, c_idx);
2309 31037 alf->alf_ctb_filter_alt_idx[c_idx - 1] = 0;
2310
4/4
✓ Branch 0 taken 23232 times.
✓ Branch 1 taken 7805 times.
✓ Branch 2 taken 15333 times.
✓ Branch 3 taken 7899 times.
31037 if (alf->ctb_flag[c_idx] && aps->num_chroma_filters > 1)
2311 15333 alf->alf_ctb_filter_alt_idx[c_idx - 1] = ff_vvc_alf_ctb_filter_alt_idx(lc, c_idx, aps->num_chroma_filters);
2312 }
2313 }
2314 }
2315
2/2
✓ Branch 0 taken 35226 times.
✓ Branch 1 taken 9326 times.
44552 if (fc->ps.sps->r->sps_ccalf_enabled_flag) {
2316 35226 const uint8_t cc_enabled[] = { sh->sh_alf_cc_cb_enabled_flag, sh->sh_alf_cc_cr_enabled_flag };
2317 35226 const uint8_t cc_aps_id[] = { sh->sh_alf_cc_cb_aps_id, sh->sh_alf_cc_cr_aps_id };
2318
2/2
✓ Branch 0 taken 70452 times.
✓ Branch 1 taken 35226 times.
105678 for (int i = 0; i < 2; i++) {
2319 70452 alf->ctb_cc_idc[i] = 0;
2320
2/2
✓ Branch 0 taken 21273 times.
✓ Branch 1 taken 49179 times.
70452 if (cc_enabled[i]) {
2321 21273 const VVCALF *aps = fc->ps.alf_list[cc_aps_id[i]];
2322 21273 alf->ctb_cc_idc[i] = ff_vvc_alf_ctb_cc_idc(lc, rx, ry, i, aps->num_cc_filters[i]);
2323 }
2324 }
2325 }
2326 44552 }
2327
2328 44552 static void deblock_params(VVCLocalContext *lc, const int rx, const int ry)
2329 {
2330 44552 VVCFrameContext *fc = lc->fc;
2331 44552 const VVCSH *sh = &lc->sc->sh;
2332 44552 CTB(fc->tab.deblock, rx, ry) = sh->deblock;
2333 44552 }
2334
2335 44552 static int hls_coding_tree_unit(VVCLocalContext *lc,
2336 const int x0, const int y0, const int ctu_idx, const int rx, const int ry)
2337 {
2338 44552 const VVCFrameContext *fc = lc->fc;
2339 44552 const VVCSPS *sps = fc->ps.sps;
2340 44552 const VVCPPS *pps = fc->ps.pps;
2341 44552 const VVCSH *sh = &lc->sc->sh;
2342 44552 const H266RawSliceHeader *rsh = sh->r;
2343 44552 const unsigned int ctb_size = sps->ctb_size_y;
2344 44552 int ret = 0;
2345
2346 44552 memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2347
2348 44552 hls_sao(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2349 44552 alf_params(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2350 44552 deblock_params(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2351
2352
4/4
✓ Branch 0 taken 5626 times.
✓ Branch 1 taken 38926 times.
✓ Branch 2 taken 5590 times.
✓ Branch 3 taken 36 times.
44552 if (IS_I(rsh) && sps->r->sps_qtbtt_dual_tree_intra_flag)
2353 5590 ret = dual_tree_implicit_qt_split(lc, x0, y0, ctb_size, 0);
2354 else
2355 38962 ret = hls_coding_tree(lc, x0, y0, ctb_size, ctb_size,
2356 1, 1, 0, 0, 0, 0, 0, SPLIT_NONE, SINGLE_TREE, MODE_TYPE_ALL);
2357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44552 times.
44552 if (ret < 0)
2358 return ret;
2359
2360
2/2
✓ Branch 0 taken 5110 times.
✓ Branch 1 taken 39442 times.
44552 if (rx == pps->ctb_to_col_bd[rx + 1] - 1) {
2361
2/2
✓ Branch 0 taken 1628 times.
✓ Branch 1 taken 3482 times.
5110 if (ctu_idx == sh->num_ctus_in_curr_slice - 1) {
2362 1628 const int end_of_slice_one_bit = ff_vvc_end_of_slice_flag_decode(lc);
2363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1628 times.
1628 if (!end_of_slice_one_bit)
2364 return AVERROR_INVALIDDATA;
2365 } else {
2366
2/2
✓ Branch 0 taken 214 times.
✓ Branch 1 taken 3268 times.
3482 if (ry == pps->ctb_to_row_bd[ry + 1] - 1) {
2367 214 const int end_of_tile_one_bit = ff_vvc_end_of_tile_one_bit(lc);
2368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 214 times.
214 if (!end_of_tile_one_bit)
2369 return AVERROR_INVALIDDATA;
2370 } else {
2371
2/2
✓ Branch 0 taken 153 times.
✓ Branch 1 taken 3115 times.
3268 if (fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2372 153 const int end_of_subset_one_bit = ff_vvc_end_of_subset_one_bit(lc);
2373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 153 times.
153 if (!end_of_subset_one_bit)
2374 return AVERROR_INVALIDDATA;
2375 }
2376 }
2377 }
2378 }
2379
2380 44552 return 0;
2381 }
2382
2383 476048 static int has_inter_luma(const CodingUnit *cu)
2384 {
2385
4/6
✓ Branch 0 taken 397072 times.
✓ Branch 1 taken 78976 times.
✓ Branch 2 taken 397072 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 397072 times.
✗ Branch 5 not taken.
476048 return cu->pred_mode != MODE_INTRA && cu->pred_mode != MODE_PLT && cu->tree_type != DUAL_TREE_CHROMA;
2386 }
2387
2388 7727116 static int pred_get_y(const int y0, const Mv *mv, const int height)
2389 {
2390 7727116 return FFMAX(0, y0 + (mv->y >> 4) + height);
2391 }
2392
2393 397072 static void cu_get_max_y(const CodingUnit *cu, int max_y[2][VVC_MAX_REF_ENTRIES], const VVCFrameContext *fc)
2394 {
2395 397072 const PredictionUnit *pu = &cu->pu;
2396
2397
2/2
✓ Branch 0 taken 24737 times.
✓ Branch 1 taken 372335 times.
397072 if (pu->merge_gpm_flag) {
2398
2/2
✓ Branch 0 taken 49474 times.
✓ Branch 1 taken 24737 times.
74211 for (int i = 0; i < FF_ARRAY_ELEMS(pu->gpm_mv); i++) {
2399 49474 const MvField *mvf = pu->gpm_mv + i;
2400 49474 const int lx = mvf->pred_flag - PF_L0;
2401 49474 const int idx = mvf->ref_idx[lx];
2402 49474 const int y = pred_get_y(cu->y0, mvf->mv + lx, cu->cb_height);
2403
2404 49474 max_y[lx][idx] = FFMAX(max_y[lx][idx], y);
2405 }
2406 } else {
2407 372335 const MotionInfo *mi = &pu->mi;
2408
4/4
✓ Branch 0 taken 339866 times.
✓ Branch 1 taken 32469 times.
✓ Branch 2 taken 68451 times.
✓ Branch 3 taken 271415 times.
372335 const int max_dmvr_off = (!pu->inter_affine_flag && pu->dmvr_flag) ? 2 : 0;
2409 372335 const int sbw = cu->cb_width / mi->num_sb_x;
2410 372335 const int sbh = cu->cb_height / mi->num_sb_y;
2411
2/2
✓ Branch 0 taken 823876 times.
✓ Branch 1 taken 372335 times.
1196211 for (int sby = 0; sby < mi->num_sb_y; sby++) {
2412
2/2
✓ Branch 0 taken 5297343 times.
✓ Branch 1 taken 823876 times.
6121219 for (int sbx = 0; sbx < mi->num_sb_x; sbx++) {
2413 5297343 const int x0 = cu->x0 + sbx * sbw;
2414 5297343 const int y0 = cu->y0 + sby * sbh;
2415 5297343 const MvField *mvf = ff_vvc_get_mvf(fc, x0, y0);
2416
2/2
✓ Branch 0 taken 10594686 times.
✓ Branch 1 taken 5297343 times.
15892029 for (int lx = 0; lx < 2; lx++) {
2417 10594686 const PredFlag mask = 1 << lx;
2418
2/2
✓ Branch 0 taken 7677642 times.
✓ Branch 1 taken 2917044 times.
10594686 if (mvf->pred_flag & mask) {
2419 7677642 const int idx = mvf->ref_idx[lx];
2420 7677642 const int y = pred_get_y(y0, mvf->mv + lx, sbh);
2421
2422 7677642 max_y[lx][idx] = FFMAX(max_y[lx][idx], y + max_dmvr_off);
2423 }
2424 }
2425 }
2426 }
2427 }
2428 397072 }
2429
2430 44552 static void ctu_get_pred(VVCLocalContext *lc, const int rs)
2431 {
2432 44552 const VVCFrameContext *fc = lc->fc;
2433 44552 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2434 44552 CTU *ctu = fc->tab.ctus + rs;
2435 44552 const CodingUnit *cu = fc->tab.cus[rs];
2436
2437 44552 ctu->has_dmvr = 0;
2438
2439
2/2
✓ Branch 0 taken 5626 times.
✓ Branch 1 taken 38926 times.
44552 if (IS_I(rsh))
2440 5626 return;
2441
2442
2/2
✓ Branch 0 taken 77852 times.
✓ Branch 1 taken 38926 times.
116778 for (int lx = 0; lx < 2; lx++)
2443 77852 memset(ctu->max_y[lx], -1, sizeof(ctu->max_y[0][0]) * rsh->num_ref_idx_active[lx]);
2444
2445
2/2
✓ Branch 0 taken 476048 times.
✓ Branch 1 taken 38926 times.
514974 while (cu) {
2446
2/2
✓ Branch 1 taken 397072 times.
✓ Branch 2 taken 78976 times.
476048 if (has_inter_luma(cu)) {
2447 397072 cu_get_max_y(cu, ctu->max_y, fc);
2448 397072 ctu->has_dmvr |= cu->pu.dmvr_flag;
2449 }
2450 476048 cu = cu->next;
2451 }
2452 38926 ctu->max_y_idx[0] = ctu->max_y_idx[1] = 0;
2453 }
2454
2455 44552 int ff_vvc_coding_tree_unit(VVCLocalContext *lc,
2456 const int ctu_idx, const int rs, const int rx, const int ry)
2457 {
2458 44552 const VVCFrameContext *fc = lc->fc;
2459 44552 const VVCSPS *sps = fc->ps.sps;
2460 44552 const VVCPPS *pps = fc->ps.pps;
2461 44552 const int x_ctb = rx << sps->ctb_log2_size_y;
2462 44552 const int y_ctb = ry << sps->ctb_log2_size_y;
2463 44552 const int ctb_size = 1 << sps->ctb_log2_size_y << sps->ctb_log2_size_y;
2464 44552 EntryPoint* ep = lc->ep;
2465 int ret;
2466
2467
2/2
✓ Branch 0 taken 5110 times.
✓ Branch 1 taken 39442 times.
44552 if (rx == pps->ctb_to_col_bd[rx]) {
2468 5110 ep->num_hmvp = 0;
2469 5110 ep->num_hmvp_ibc = 0;
2470
4/4
✓ Branch 0 taken 3380 times.
✓ Branch 1 taken 1730 times.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 3268 times.
5110 ep->is_first_qg = ry == pps->ctb_to_row_bd[ry] || !ctu_idx;
2471 }
2472
2473 44552 lc->coeffs = fc->tab.coeffs + rs * ctb_size * VVC_MAX_SAMPLE_ARRAYS;
2474 44552 lc->cu = NULL;
2475
2476 44552 ff_vvc_cabac_init(lc, ctu_idx, rx, ry);
2477 44552 ff_vvc_decode_neighbour(lc, x_ctb, y_ctb, rx, ry, rs);
2478 44552 ret = hls_coding_tree_unit(lc, x_ctb, y_ctb, ctu_idx, rx, ry);
2479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44552 times.
44552 if (ret < 0)
2480 return ret;
2481 44552 ctu_get_pred(lc, rs);
2482
2483 44552 return 0;
2484 }
2485
2486 302634 void ff_vvc_decode_neighbour(VVCLocalContext *lc, const int x_ctb, const int y_ctb,
2487 const int rx, const int ry, const int rs)
2488 {
2489 302634 VVCFrameContext *fc = lc->fc;
2490 302634 const int ctb_size = fc->ps.sps->ctb_size_y;
2491
2492 302634 lc->end_of_tiles_x = fc->ps.pps->width;
2493 302634 lc->end_of_tiles_y = fc->ps.pps->height;
2494
2/2
✓ Branch 0 taken 35136 times.
✓ Branch 1 taken 267498 times.
302634 if (fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx + 1])
2495 35136 lc->end_of_tiles_x = FFMIN(x_ctb + ctb_size, lc->end_of_tiles_x);
2496
2/2
✓ Branch 0 taken 59362 times.
✓ Branch 1 taken 243272 times.
302634 if (fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry + 1])
2497 59362 lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, lc->end_of_tiles_y);
2498
2499 302634 lc->boundary_flags = 0;
2500
4/4
✓ Branch 0 taken 275562 times.
✓ Branch 1 taken 27072 times.
✓ Branch 2 taken 8064 times.
✓ Branch 3 taken 267498 times.
302634 if (rx > 0 && fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx - 1])
2501 8064 lc->boundary_flags |= BOUNDARY_LEFT_TILE;
2502
4/4
✓ Branch 0 taken 275562 times.
✓ Branch 1 taken 27072 times.
✓ Branch 2 taken 5278 times.
✓ Branch 3 taken 270284 times.
302634 if (rx > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - 1])
2503 5278 lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
2504
4/4
✓ Branch 0 taken 254696 times.
✓ Branch 1 taken 47938 times.
✓ Branch 2 taken 11424 times.
✓ Branch 3 taken 243272 times.
302634 if (ry > 0 && fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry - 1])
2505 11424 lc->boundary_flags |= BOUNDARY_UPPER_TILE;
2506
4/4
✓ Branch 0 taken 254696 times.
✓ Branch 1 taken 47938 times.
✓ Branch 2 taken 11312 times.
✓ Branch 3 taken 243384 times.
302634 if (ry > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - fc->ps.pps->ctb_width])
2507 11312 lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
2508
2/2
✓ Branch 0 taken 29088 times.
✓ Branch 1 taken 273546 times.
302634 if (fc->ps.sps->r->sps_subpic_ctu_top_left_x[lc->sc->sh.r->curr_subpic_idx] == rx)
2509 29088 lc->boundary_flags |= BOUNDARY_LEFT_SUBPIC;
2510
2/2
✓ Branch 0 taken 49492 times.
✓ Branch 1 taken 253142 times.
302634 if (fc->ps.sps->r->sps_subpic_ctu_top_left_y[lc->sc->sh.r->curr_subpic_idx] == ry)
2511 49492 lc->boundary_flags |= BOUNDARY_UPPER_SUBPIC;
2512
4/4
✓ Branch 0 taken 275562 times.
✓ Branch 1 taken 27072 times.
✓ Branch 2 taken 267498 times.
✓ Branch 3 taken 8064 times.
302634 lc->ctb_left_flag = rx > 0 && !(lc->boundary_flags & BOUNDARY_LEFT_TILE);
2513
6/6
✓ Branch 0 taken 254696 times.
✓ Branch 1 taken 47938 times.
✓ Branch 2 taken 243272 times.
✓ Branch 3 taken 11424 times.
✓ Branch 4 taken 240920 times.
✓ Branch 5 taken 2352 times.
302634 lc->ctb_up_flag = ry > 0 && !(lc->boundary_flags & BOUNDARY_UPPER_TILE) && !(lc->boundary_flags & BOUNDARY_UPPER_SLICE);
2514
4/4
✓ Branch 0 taken 240920 times.
✓ Branch 1 taken 61714 times.
✓ Branch 2 taken 218602 times.
✓ Branch 3 taken 22318 times.
521236 lc->ctb_up_right_flag = lc->ctb_up_flag && (fc->ps.pps->ctb_to_col_bd[rx] == fc->ps.pps->ctb_to_col_bd[rx + 1]) &&
2515
1/2
✓ Branch 0 taken 218602 times.
✗ Branch 1 not taken.
218602 (fc->ps.pps->ctb_to_row_bd[ry] == fc->ps.pps->ctb_to_row_bd[ry - 1]);
2516
4/4
✓ Branch 0 taken 267498 times.
✓ Branch 1 taken 35136 times.
✓ Branch 2 taken 218602 times.
✓ Branch 3 taken 48896 times.
302634 lc->ctb_up_left_flag = lc->ctb_left_flag && lc->ctb_up_flag;
2517 302634 }
2518
2519 2351808 void ff_vvc_set_neighbour_available(VVCLocalContext *lc,
2520 const int x0, const int y0, const int w, const int h)
2521 {
2522 2351808 const int log2_ctb_size = lc->fc->ps.sps->ctb_log2_size_y;
2523 2351808 const int x0b = av_zero_extend(x0, log2_ctb_size);
2524 2351808 const int y0b = av_zero_extend(y0, log2_ctb_size);
2525
2526
4/4
✓ Branch 0 taken 663237 times.
✓ Branch 1 taken 1688571 times.
✓ Branch 2 taken 588638 times.
✓ Branch 3 taken 74599 times.
2351808 lc->na.cand_up = (lc->ctb_up_flag || y0b);
2527
4/4
✓ Branch 0 taken 393400 times.
✓ Branch 1 taken 1958408 times.
✓ Branch 2 taken 338487 times.
✓ Branch 3 taken 54913 times.
2351808 lc->na.cand_left = (lc->ctb_left_flag || x0b);
2528
8/8
✓ Branch 0 taken 374147 times.
✓ Branch 1 taken 1977661 times.
✓ Branch 2 taken 272241 times.
✓ Branch 3 taken 101906 times.
✓ Branch 4 taken 2207138 times.
✓ Branch 5 taken 42764 times.
✓ Branch 6 taken 2153683 times.
✓ Branch 7 taken 53455 times.
2351808 lc->na.cand_up_left = (x0b || y0b) ? lc->na.cand_left && lc->na.cand_up : lc->ctb_up_left_flag;
2529 2351808 lc->na.cand_up_right_sap =
2530
6/6
✓ Branch 0 taken 349159 times.
✓ Branch 1 taken 2002649 times.
✓ Branch 2 taken 246755 times.
✓ Branch 3 taken 102404 times.
✓ Branch 4 taken 73078 times.
✓ Branch 5 taken 173677 times.
2351808 (x0b + w == 1 << log2_ctb_size) ? lc->ctb_up_right_flag && !y0b : lc->na.cand_up;
2531
4/4
✓ Branch 0 taken 2020869 times.
✓ Branch 1 taken 330939 times.
✓ Branch 2 taken 2003602 times.
✓ Branch 3 taken 17267 times.
2351808 lc->na.cand_up_right = lc->na.cand_up_right_sap && (x0 + w) < lc->end_of_tiles_x;
2532 2351808 }
2533
2534 89104 void ff_vvc_ctu_free_cus(CodingUnit **cus)
2535 {
2536
2/2
✓ Branch 0 taken 1085050 times.
✓ Branch 1 taken 89104 times.
1174154 while (*cus) {
2537 1085050 CodingUnit *cu = *cus;
2538 1085050 TransformUnit **head = &cu->tus.head;
2539
2540 1085050 *cus = cu->next;
2541
2542
2/2
✓ Branch 0 taken 1326571 times.
✓ Branch 1 taken 1085050 times.
2411621 while (*head) {
2543 1326571 TransformUnit *tu = *head;
2544 1326571 *head = tu->next;
2545 1326571 ff_refstruct_unref(&tu);
2546 }
2547 1085050 cu->tus.tail = NULL;
2548
2549 1085050 ff_refstruct_unref(&cu);
2550 }
2551 89104 }
2552
2553 14395071 int ff_vvc_get_qPy(const VVCFrameContext *fc, const int xc, const int yc)
2554 {
2555 14395071 const int min_cb_log2_size_y = fc->ps.sps->min_cb_log2_size_y;
2556 14395071 const int x = xc >> min_cb_log2_size_y;
2557 14395071 const int y = yc >> min_cb_log2_size_y;
2558 14395071 return fc->tab.qp[LUMA][x + y * fc->ps.pps->min_cb_width];
2559 }
2560
2561 1995 void ff_vvc_ep_init_stat_coeff(EntryPoint *ep,
2562 const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
2563 {
2564
2/2
✓ Branch 0 taken 5985 times.
✓ Branch 1 taken 1995 times.
7980 for (size_t i = 0; i < FF_ARRAY_ELEMS(ep->stat_coeff); ++i) {
2565 5985 ep->stat_coeff[i] =
2566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5985 times.
5985 persistent_rice_adaptation_enabled_flag ? 2 * (av_log2(bit_depth - 10)) : 0;
2567 }
2568 1995 }
2569