FFmpeg
ctu.c
Go to the documentation of this file.
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 "libavutil/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 {
39 } VVCModeType;
40 
41 static void set_tb_size(const VVCFrameContext *fc, const TransformBlock *tb)
42 {
43  const int x_tb = tb->x0 >> MIN_TU_LOG2;
44  const int y_tb = tb->y0 >> MIN_TU_LOG2;
45  const int hs = fc->ps.sps->hshift[tb->c_idx];
46  const int vs = fc->ps.sps->vshift[tb->c_idx];
47  const int is_chroma = tb->c_idx != 0;
48  const int width = FFMAX(1, tb->tb_width >> (MIN_TU_LOG2 - hs));
49  const int end = y_tb + FFMAX(1, tb->tb_height >> (MIN_TU_LOG2 - vs));
50 
51  for (int y = y_tb; y < end; y++) {
52  const int off = y * fc->ps.pps->min_tu_width + x_tb;
53  memset(fc->tab.tb_width [is_chroma] + off, tb->tb_width, width);
54  memset(fc->tab.tb_height[is_chroma] + off, tb->tb_height, width);
55  }
56 }
57 
58 static void set_tb_tab(uint8_t *tab, uint8_t v, const VVCFrameContext *fc,
59  const TransformBlock *tb)
60 {
61  const int width = tb->tb_width << fc->ps.sps->hshift[tb->c_idx];
62  const int height = tb->tb_height << fc->ps.sps->vshift[tb->c_idx];
63 
64  for (int h = 0; h < height; h += MIN_TU_SIZE) {
65  const int y = (tb->y0 + h) >> MIN_TU_LOG2;
66  const int off = y * fc->ps.pps->min_tu_width + (tb->x0 >> MIN_TU_LOG2);
67  const int w = FFMAX(1, width >> MIN_TU_LOG2);
68  memset(tab + off, v, w);
69  }
70 }
71 
72 // 8.7.1 Derivation process for quantization parameters
73 static int get_qp_y_pred(const VVCLocalContext *lc)
74 {
75  const VVCFrameContext *fc = lc->fc;
76  const VVCSPS *sps = fc->ps.sps;
77  const VVCPPS *pps = fc->ps.pps;
78  const CodingUnit *cu = lc->cu;
79  const int ctb_log2_size = sps->ctb_log2_size_y;
80  const int ctb_size_mask = (1 << ctb_log2_size) - 1;
81  const int xQg = lc->parse.cu_qg_top_left_x;
82  const int yQg = lc->parse.cu_qg_top_left_y;
83  const int min_cb_width = fc->ps.pps->min_cb_width;
84  const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
85  const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
86  const int rx = cu->x0 >> ctb_log2_size;
87  const int ry = cu->y0 >> ctb_log2_size;
88  const int in_same_ctb_a = ((xQg - 1) >> ctb_log2_size) == rx && (yQg >> ctb_log2_size) == ry;
89  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  if (lc->na.cand_up) {
93  const int first_qg_in_ctu = !(xQg & ctb_size_mask) && !(yQg & ctb_size_mask);
94  const int qPy_up = fc->tab.qp[LUMA][x_cb + (y_cb - 1) * min_cb_width];
95  if (first_qg_in_ctu && pps->ctb_to_col_bd[xQg >> ctb_log2_size] == xQg >> ctb_log2_size)
96  return qPy_up;
97  }
98 
99  // qPy_pred
100  qPy_pred = lc->ep->is_first_qg ? lc->sc->sh.slice_qp_y : lc->ep->qp_y;
101 
102  // qPy_b
103  if (!lc->na.cand_up || !in_same_ctb_b)
104  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  if (!lc->na.cand_left || !in_same_ctb_a)
110  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  return (qPy_a + qPy_b + 1) >> 1;
118 }
119 
120 static void set_cb_tab(const VVCLocalContext *lc, uint8_t *tab, const uint8_t v)
121 {
122  const VVCFrameContext *fc = lc->fc;
123  const VVCPPS *pps = fc->ps.pps;
124  const CodingUnit *cu = lc->cu;
125  const int log2_min_cb_size = fc->ps.sps->min_cb_log2_size_y;
126  const int x_cb = cu->x0 >> log2_min_cb_size;
127  const int y_cb = cu->y0 >> log2_min_cb_size;
128  const int cb_width = cu->cb_width;
129  const int cb_height = cu->cb_height;
130  int x = y_cb * pps->min_cb_width + x_cb;
131 
132  for (int y = 0; y < (cb_height >> log2_min_cb_size); y++) {
133  const int width = cb_width >> log2_min_cb_size;
134 
135  memset(&tab[x], v, width);
136  x += pps->min_cb_width;
137  }
138 }
139 
140 static int set_qp_y(VVCLocalContext *lc, const int x0, const int y0, const int has_qp_delta)
141 {
142  const VVCSPS *sps = lc->fc->ps.sps;
143  EntryPoint *ep = lc->ep;
144  CodingUnit *cu = lc->cu;
145  int cu_qp_delta = 0;
146 
147  if (!lc->fc->ps.pps->r->pps_cu_qp_delta_enabled_flag) {
148  ep->qp_y = lc->sc->sh.slice_qp_y;
149  } else if (ep->is_first_qg || (lc->parse.cu_qg_top_left_x == x0 && lc->parse.cu_qg_top_left_y == y0)) {
150  ep->qp_y = get_qp_y_pred(lc);
151  ep->is_first_qg = 0;
152  }
153 
154  if (has_qp_delta) {
155  const int cu_qp_delta_abs = ff_vvc_cu_qp_delta_abs(lc);
156 
157  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  if (cu_qp_delta > (31 + sps->qp_bd_offset / 2) || cu_qp_delta < -(32 + sps->qp_bd_offset / 2))
160  return AVERROR_INVALIDDATA;
161  lc->parse.is_cu_qp_delta_coded = 1;
162 
163  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  set_cb_tab(lc, lc->fc->tab.qp[LUMA], ep->qp_y);
170  cu->qp[LUMA] = ep->qp_y;
171 
172  return 0;
173 }
174 
175 static void set_qp_c_tab(const VVCLocalContext *lc, const TransformUnit *tu, const TransformBlock *tb)
176 {
177  const int is_jcbcr = tu->joint_cbcr_residual_flag && tu->coded_flag[CB] && tu->coded_flag[CR];
178  const int idx = is_jcbcr ? JCBCR : tb->c_idx;
179 
180  set_tb_tab(lc->fc->tab.qp[tb->c_idx], lc->cu->qp[idx], lc->fc, tb);
181 }
182 
183 static void set_qp_c(VVCLocalContext *lc)
184 {
185  const VVCFrameContext *fc = lc->fc;
186  const VVCSPS *sps = fc->ps.sps;
187  const VVCPPS *pps = fc->ps.pps;
188  const H266RawSliceHeader *rsh = lc->sc->sh.r;
189  CodingUnit *cu = lc->cu;
190  const int x_center = cu->x0 + cu->cb_width / 2;
191  const int y_center = cu->y0 + cu->cb_height / 2;
192  const int single_tree = cu->tree_type == SINGLE_TREE;
193  const int qp_luma = (single_tree ? lc->ep->qp_y : ff_vvc_get_qPy(fc, x_center, y_center)) + sps->qp_bd_offset;
194  const int qp_chroma = av_clip(qp_luma, 0, MAX_QP + sps->qp_bd_offset);
195  const int sh_chroma_qp_offset[] = {
196  rsh->sh_cb_qp_offset,
197  rsh->sh_cr_qp_offset,
199  };
200  int qp;
201 
202  for (int i = CB - 1; i < CR + sps->r->sps_joint_cbcr_enabled_flag; i++) {
203  qp = sps->chroma_qp_table[i][qp_chroma];
204  qp = qp + pps->chroma_qp_offset[i] + sh_chroma_qp_offset[i] + lc->parse.chroma_qp_offset[i];
205  qp = av_clip(qp, -sps->qp_bd_offset, MAX_QP) + sps->qp_bd_offset;
206  cu->qp[i + 1] = qp;
207  }
208 }
209 
211 {
212  TransformUnit *tu = av_refstruct_pool_get(fc->tu_pool);
213  if (!tu)
214  return NULL;
215 
216  tu->next = NULL;
217 
218  if (cu->tus.tail)
219  cu->tus.tail->next = tu;
220  else
221  cu->tus.head = tu;
222  cu->tus.tail = tu;
223 
224  return tu;
225 }
226 
227 static TransformUnit* add_tu(VVCFrameContext *fc, CodingUnit *cu, const int x0, const int y0, const int tu_width, const int tu_height)
228 {
229  TransformUnit *tu = alloc_tu(fc, cu);
230 
231  if (!tu)
232  return NULL;
233 
234  tu->x0 = x0;
235  tu->y0 = y0;
236  tu->width = tu_width;
237  tu->height = tu_height;
238  tu->joint_cbcr_residual_flag = 0;
239  memset(tu->coded_flag, 0, sizeof(tu->coded_flag));
240  tu->avail[LUMA] = tu->avail[CHROMA] = 0;
241  tu->nb_tbs = 0;
242 
243  return tu;
244 }
245 
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  tb = &tu->tbs[tu->nb_tbs++];
252  tb->has_coeffs = 0;
253  tb->x0 = x0;
254  tb->y0 = y0;
255  tb->tb_width = tb_width;
256  tb->tb_height = tb_height;
257  tb->log2_tb_width = av_log2(tb_width);
258  tb->log2_tb_height = av_log2(tb_height);
259 
260  tb->max_scan_x = tb->max_scan_y = 0;
261  tb->min_scan_x = tb->min_scan_y = 0;
262 
263  tb->c_idx = c_idx;
264  tb->ts = 0;
265  tb->coeffs = lc->coeffs;
266  lc->coeffs += tb_width * tb_height;
267  tu->avail[!!c_idx] = true;
268  return tb;
269 }
270 
271 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  uint8_t tu_y_coded_flag = 0;
275  const VVCSPS *sps = lc->fc->ps.sps;
276  CodingUnit *cu = lc->cu;
277 
278  if (!is_sbt_not_coded) {
279  int has_y_coded_flag = sub_tu_index < cu->num_intra_subpartitions - 1 || !lc->parse.infer_tu_cbf_luma;
280  if (!is_isp) {
281  const int is_large = cu->cb_width > sps->max_tb_size_y || cu->cb_height > sps->max_tb_size_y;
282  has_y_coded_flag = (cu->pred_mode == MODE_INTRA && !cu->act_enabled_flag) || is_chroma_coded || is_large;
283  }
284  tu_y_coded_flag = has_y_coded_flag ? ff_vvc_tu_y_coded_flag(lc) : 1;
285  }
286  if (is_isp)
287  lc->parse.infer_tu_cbf_luma = lc->parse.infer_tu_cbf_luma && !tu_y_coded_flag;
288  return tu_y_coded_flag;
289 }
290 
291 static void chroma_qp_offset_decode(VVCLocalContext *lc, const int is_128, const int is_chroma_coded)
292 {
293  const VVCPPS *pps = lc->fc->ps.pps;
294  const H266RawSliceHeader *rsh = lc->sc->sh.r;
295 
296  if ((is_128 || is_chroma_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  }
309  }
310 }
311 
312 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  VVCFrameContext *fc = lc->fc;
315  const VVCSPS *sps = fc->ps.sps;
316  const VVCPPS *pps = fc->ps.pps;
317  CodingUnit *cu = lc->cu;
318  TransformUnit *tu = add_tu(fc, cu, x0, y0, tu_width, tu_height);
319  const int min_cb_width = pps->min_cb_width;
320  const VVCTreeType tree_type = cu->tree_type;
321  const int is_128 = cu->cb_width > 64 || cu->cb_height > 64;
322  const int is_isp = cu->isp_split_type != ISP_NO_SPLIT;
323  const int is_isp_last_tu = is_isp && (sub_tu_index == cu->num_intra_subpartitions - 1);
324  const int is_sbt_not_coded = cu->sbt_flag &&
325  ((sub_tu_index == 0 && cu->sbt_pos_flag) || (sub_tu_index == 1 && !cu->sbt_pos_flag));
326  const int chroma_available = tree_type != DUAL_TREE_LUMA && sps->r->sps_chroma_format_idc &&
327  (!is_isp || is_isp_last_tu);
328  int ret, xc, yc, wc, hc, is_chroma_coded;
329 
330  if (!tu)
331  return AVERROR_INVALIDDATA;
332 
333  if (tree_type == SINGLE_TREE && is_isp_last_tu) {
334  const int x_cu = x0 >> fc->ps.sps->min_cb_log2_size_y;
335  const int y_cu = y0 >> fc->ps.sps->min_cb_log2_size_y;
336  xc = SAMPLE_CTB(fc->tab.cb_pos_x[ch_type], x_cu, y_cu);
337  yc = SAMPLE_CTB(fc->tab.cb_pos_y[ch_type], x_cu, y_cu);
338  wc = SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cu, y_cu);
339  hc = SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cu, y_cu);
340  } else {
341  xc = x0, yc = y0, wc = tu_width, hc = tu_height;
342  }
343 
344  if (chroma_available && !is_sbt_not_coded) {
347  }
348 
349  is_chroma_coded = chroma_available && (tu->coded_flag[CB] || tu->coded_flag[CR]);
350 
351  if (tree_type != DUAL_TREE_CHROMA) {
352  int has_qp_delta;
353  tu->coded_flag[LUMA] = tu_y_coded_flag_decode(lc, is_sbt_not_coded, sub_tu_index, is_isp, is_chroma_coded);
354  has_qp_delta = (is_128 || tu->coded_flag[LUMA] || is_chroma_coded) &&
355  pps->r->pps_cu_qp_delta_enabled_flag && !lc->parse.is_cu_qp_delta_coded;
356  ret = set_qp_y(lc, x0, y0, has_qp_delta);
357  if (ret < 0)
358  return ret;
359  add_tb(tu, lc, x0, y0, tu_width, tu_height, LUMA);
360  }
361  if (tree_type != DUAL_TREE_LUMA) {
362  chroma_qp_offset_decode(lc, is_128, is_chroma_coded);
363  if (chroma_available) {
364  const int hs = sps->hshift[CHROMA];
365  const int vs = sps->vshift[CHROMA];
366  add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CB);
367  add_tb(tu, lc, xc, yc, wc >> hs, hc >> vs, CR);
368  }
369  }
370  if (sps->r->sps_joint_cbcr_enabled_flag && ((cu->pred_mode == MODE_INTRA &&
371  (tu->coded_flag[CB] || tu->coded_flag[CR])) ||
372  (tu->coded_flag[CB] && tu->coded_flag[CR])) &&
373  chroma_available) {
375  }
376 
377  for (int i = 0; i < tu->nb_tbs; i++) {
378  TransformBlock *tb = &tu->tbs[i];
379  const int is_chroma = tb->c_idx != LUMA;
380  tb->has_coeffs = tu->coded_flag[tb->c_idx];
381  if (tb->has_coeffs && is_chroma)
382  tb->has_coeffs = tb->c_idx == CB ? 1 : !(tu->coded_flag[CB] && tu->joint_cbcr_residual_flag);
383  if (tb->has_coeffs) {
384  tb->ts = cu->bdpcm_flag[tb->c_idx];
385  if (sps->r->sps_transform_skip_enabled_flag && !cu->bdpcm_flag[tb->c_idx] &&
386  tb->tb_width <= sps->max_ts_size && tb->tb_height <= sps->max_ts_size &&
387  !cu->sbt_flag && (is_chroma || !is_isp)) {
388  tb->ts = ff_vvc_transform_skip_flag(lc, is_chroma);
389  }
390  ret = ff_vvc_residual_coding(lc, tb);
391  if (ret < 0)
392  return ret;
393  set_tb_tab(fc->tab.tu_coded_flag[tb->c_idx], tu->coded_flag[tb->c_idx], fc, tb);
394  }
395  if (tb->c_idx != CR)
396  set_tb_size(fc, tb);
397  if (tb->c_idx == CB)
398  set_tb_tab(fc->tab.tu_joint_cbcr_residual_flag, tu->joint_cbcr_residual_flag, fc, tb);
399  }
400 
401  return 0;
402 }
403 
404 static int hls_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height, int ch_type)
405 {
406  const CodingUnit *cu = lc->cu;
407  const VVCSPS *sps = lc->fc->ps.sps;
408  int ret;
409 
410  lc->parse.infer_tu_cbf_luma = 1;
411  if (cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag) {
412  if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
413  const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
414  const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
415  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  TRANSFORM_TREE(x0, y0);
424  if (ver_split_first)
425  TRANSFORM_TREE(x0 + trafo_width, y0);
426  else
427  TRANSFORM_TREE(x0, y0 + trafo_height);
428 
429  } else {
430  ret = hls_transform_unit(lc, x0, y0, tu_width, tu_height, 0, ch_type);
431  if (ret < 0)
432  return ret;
433 
434  }
435  } else if (cu->sbt_flag) {
436  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  const int trafo_width = tu_width * lc->parse.sbt_num_fourths_tb0 / 4;
444  TRANSFORM_UNIT(x0, trafo_width, 0);
445  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  const int trafo_height = tu_height * lc->parse.sbt_num_fourths_tb0 / 4;
456  TRANSFORM_UNIT(y0, trafo_height, 0);
457  TRANSFORM_UNIT(y0 + trafo_height, tu_height - trafo_height, 1);
458 
459  #undef TRANSFORM_UNIT
460  }
461  } else if (cu->isp_split_type == ISP_HOR_SPLIT) {
462  const int trafo_height = tu_height / cu->num_intra_subpartitions;
463  for (int i = 0; i < cu->num_intra_subpartitions; i++) {
464  ret = hls_transform_unit(lc, x0, y0 + trafo_height * i, tu_width, trafo_height, i, 0);
465  if (ret < 0)
466  return ret;
467  }
468  } else if (cu->isp_split_type == ISP_VER_SPLIT) {
469  const int trafo_width = tu_width / cu->num_intra_subpartitions;
470  for (int i = 0; i < cu->num_intra_subpartitions; i++) {
471  ret = hls_transform_unit(lc, x0 + trafo_width * i , y0, trafo_width, tu_height, i, 0);
472  if (ret < 0)
473  return ret;
474  }
475  }
476 
477  return 0;
478 }
479 
480 static int skipped_transform_tree(VVCLocalContext *lc, int x0, int y0,int tu_width, int tu_height)
481 {
482  VVCFrameContext *fc = lc->fc;
483  const CodingUnit *cu = lc->cu;
484  const VVCSPS *sps = fc->ps.sps;
485 
486  if (tu_width > sps->max_tb_size_y || tu_height > sps->max_tb_size_y) {
487  const int ver_split_first = tu_width > sps->max_tb_size_y && tu_width > tu_height;
488  const int trafo_width = ver_split_first ? (tu_width / 2) : tu_width;
489  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  SKIPPED_TRANSFORM_TREE(x0, y0);
498  if (ver_split_first)
499  SKIPPED_TRANSFORM_TREE(x0 + trafo_width, y0);
500  else
501  SKIPPED_TRANSFORM_TREE(x0, y0 + trafo_height);
502  } else {
503  TransformUnit *tu = add_tu(fc, lc->cu, x0, y0, tu_width, tu_height);
504  const int has_chroma = sps->r->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA;
505  const int c_start = cu->tree_type == DUAL_TREE_CHROMA ? CB : LUMA;
506  const int c_end = has_chroma ? VVC_MAX_SAMPLE_ARRAYS : CB;
507 
508  if (!tu)
509  return AVERROR_INVALIDDATA;
510  for (int i = c_start; i < c_end; i++) {
511  TransformBlock *tb = add_tb(tu, lc, x0, y0, tu_width >> sps->hshift[i], tu_height >> sps->vshift[i], i);
512  if (i != CR)
513  set_tb_size(fc, tb);
514  }
515  }
516 
517  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 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  const VVCFrameContext *fc = lc->fc;
529  const VVCSH *sh = &lc->sc->sh;
530  const VVCSPS *sps = fc->ps.sps;
531  const VVCPPS *pps = fc->ps.pps;
532  const int chroma = tree_type == DUAL_TREE_CHROMA;
533  int min_cb_size_y = sps->min_cb_size_y;
534  int *qt = &split->qt;
535  int *btv = &split->btv;
536  int *bth = &split->bth;
537  int *ttv = &split->ttv;
538  int *tth = &split->tth;
539 
540  *qt = *bth = *btv = *tth = *ttv = 1;
541 
542  if (mtt_depth)
543  *qt = 0;
544 
545  min_qt_size = sh->min_qt_size[chroma];
546  if (cb_width <= min_qt_size)
547  *qt = 0;
548 
549  if (chroma) {
550  int chroma_area = (cb_width >> sps->hshift[1]) * (cb_height >> sps->vshift[1]);
551  int chroma_width = cb_width >> sps->hshift[1];
552 
553  if (chroma_width == 8)
554  *ttv = 0;
555  else if (chroma_width <= 4) {
556  if (chroma_width == 4)
557  *btv = 0;
558  *qt = 0;
559  }
560  if (mode_type == MODE_TYPE_INTRA)
561  *qt = *btv = *bth = *ttv = *tth = 0;
562  if (chroma_area <= 32) {
563  *ttv = *tth = 0;
564  if (chroma_area <= 16)
565  *btv = *bth = 0;
566  }
567  }
568  max_bt_size = sh->max_bt_size[chroma];
569  max_tt_size = sh->max_tt_size[chroma];
570  max_mtt_depth = sh->max_mtt_depth[chroma] + depth_offset;
571 
572  if (mode_type == MODE_TYPE_INTER) {
573  int area = cb_width * cb_height;
574  if (area == 32)
575  *btv = *bth = 0;
576  else if (area == 64)
577  *ttv = *tth = 0;
578  }
579  if (cb_width <= 2 * min_cb_size_y) {
580  *ttv = 0;
581  if (cb_width <= min_cb_size_y)
582  *btv = 0;
583  }
584  if (cb_height <= 2 * min_cb_size_y) {
585  *tth = 0;
586  if (cb_height <= min_cb_size_y)
587  *bth = 0;
588  }
589  if (cb_width > max_bt_size || cb_height > max_bt_size)
590  *btv = *bth = 0;
591  max_tt_size = FFMIN(64, max_tt_size);
592  if (cb_width > max_tt_size || cb_height > max_tt_size)
593  *ttv = *tth = 0;
594  if (mtt_depth >= max_mtt_depth)
595  *btv = *bth = *ttv = *tth = 0;
596  if (x0 + cb_width > pps->width) {
597  *ttv = *tth = 0;
598  if (cb_height > 64)
599  *btv = 0;
600  if (y0 + cb_height <= pps->height)
601  *bth = 0;
602  else if (cb_width > min_qt_size)
603  *btv = *bth = 0;
604  }
605  if (y0 + cb_height > pps->height) {
606  *btv = *ttv = *tth = 0;
607  if (cb_width > 64)
608  *bth = 0;
609  }
610  if (mtt_depth > 0 && part_idx == 1) {
611  if (last_split_mode == SPLIT_TT_VER)
612  *btv = 0;
613  else if (last_split_mode == SPLIT_TT_HOR)
614  *bth = 0;
615  }
616  if (cb_width <= 64 && cb_height > 64)
617  *btv = 0;
618  if (cb_width > 64 && cb_height <= 64)
619  *bth = 0;
620 }
621 
622 static int get_num_intra_subpartitions(enum IspType isp_split_type, int cb_width, int cb_height)
623 {
624  if (isp_split_type == ISP_NO_SPLIT)
625  return 1;
626  if ((cb_width == 4 && cb_height == 8) || (cb_width == 8 && cb_height == 4))
627  return 2;
628  return 4;
629 }
630 
631 static int get_cclm_enabled(const VVCLocalContext *lc, const int x0, const int y0)
632 {
633  const VVCFrameContext *fc = lc->fc;
634  const VVCSPS *sps = fc->ps.sps;
635  int enabled = 0;
636 
637  if (!sps->r->sps_cclm_enabled_flag)
638  return 0;
639  if (!sps->r->sps_qtbtt_dual_tree_intra_flag || !IS_I(lc->sc->sh.r) || sps->ctb_log2_size_y < 6)
640  return 1;
641  else {
642  const int x64 = x0 >> 6 << 6;
643  const int y64 = y0 >> 6 << 6;
644  const int y32 = y0 >> 5 << 5;
645  const int x64_cu = x64 >> fc->ps.sps->min_cb_log2_size_y;
646  const int y64_cu = y64 >> fc->ps.sps->min_cb_log2_size_y;
647  const int y32_cu = y32 >> fc->ps.sps->min_cb_log2_size_y;
648  const int min_cb_width = fc->ps.pps->min_cb_width;
649  const int depth = SAMPLE_CTB(fc->tab.cqt_depth[1], x64_cu, y64_cu);
650  const int min_depth = fc->ps.sps->ctb_log2_size_y - 6;
651  const VVCSplitMode msm64 = (VVCSplitMode)TAB_MSM(fc, 0, x64, y64);
652  const VVCSplitMode msm32 = (VVCSplitMode)TAB_MSM(fc, 1, x64, y32);
653 
654  enabled = SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y64_cu) == 64 &&
655  SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y64_cu) == 64;
656  enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR &&
657  SAMPLE_CTB(fc->tab.cb_width[1], x64_cu, y32_cu) == 64 &&
658  SAMPLE_CTB(fc->tab.cb_height[1], x64_cu, y32_cu) == 32;
659  enabled |= depth > min_depth;
660  enabled |= depth == min_depth && msm64 == SPLIT_BT_HOR && msm32 == SPLIT_BT_VER;
661 
662  if (enabled) {
663  const int w = SAMPLE_CTB(fc->tab.cb_width[0], x64_cu, y64_cu);
664  const int h = SAMPLE_CTB(fc->tab.cb_height[0], x64_cu, y64_cu);
665  const int depth0 = SAMPLE_CTB(fc->tab.cqt_depth[0], x64_cu, y64_cu);
666  if ((w == 64 && h == 64 && TAB_ISPMF(fc, x64, y64)) ||
667  ((w < 64 || h < 64) && depth0 == min_depth))
668  return 0;
669  }
670 
671  }
672 
673  return enabled;
674 }
675 
676 static int less(const void *a, const void *b)
677 {
678  return *(const int*)a - *(const int*)b;
679 }
680 
681 //8.4.2 Derivation process for luma intra prediction mode
682 static enum IntraPredMode luma_intra_pred_mode(VVCLocalContext* lc, const int intra_subpartitions_mode_flag)
683 {
684  VVCFrameContext *fc = lc->fc;
685  CodingUnit *cu = lc->cu;
686  const int x0 = cu->x0;
687  const int y0 = cu->y0;
688  enum IntraPredMode pred;
689  int intra_luma_not_planar_flag = 1;
690  int intra_luma_mpm_remainder = 0;
691  int intra_luma_mpm_flag = 1;
692  int intra_luma_mpm_idx = 0;
693 
694  if (!cu->intra_luma_ref_idx)
695  intra_luma_mpm_flag = ff_vvc_intra_luma_mpm_flag(lc);
696  if (intra_luma_mpm_flag) {
697  if (!cu->intra_luma_ref_idx)
698  intra_luma_not_planar_flag = ff_vvc_intra_luma_not_planar_flag(lc, intra_subpartitions_mode_flag);
699  if (intra_luma_not_planar_flag)
700  intra_luma_mpm_idx = ff_vvc_intra_luma_mpm_idx(lc);
701  } else {
702  intra_luma_mpm_remainder = ff_vvc_intra_luma_mpm_remainder(lc);
703  }
704 
705  if (!intra_luma_not_planar_flag) {
706  pred = INTRA_PLANAR;
707  } else {
708  const VVCSPS *sps = fc->ps.sps;
709  const int x_a = (x0 - 1) >> sps->min_cb_log2_size_y;
710  const int y_a = (y0 + cu->cb_height - 1) >> sps->min_cb_log2_size_y;
711  const int x_b = (x0 + cu->cb_width - 1) >> sps->min_cb_log2_size_y;
712  const int y_b = (y0 - 1) >> sps->min_cb_log2_size_y;
713  int min_cb_width = fc->ps.pps->min_cb_width;
714  int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
715  int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
716  const int available_l = lc->ctb_left_flag || x0b;
717  const int available_u = lc->ctb_up_flag || y0b;
718 
719  int a, b, cand[5];
720 
721  if (!available_l || (SAMPLE_CTB(fc->tab.cpm[0], x_a, y_a) != MODE_INTRA) ||
722  SAMPLE_CTB(fc->tab.imf, x_a, y_a)) {
723  a = INTRA_PLANAR;
724  } else {
725  a = SAMPLE_CTB(fc->tab.ipm, x_a, y_a);
726  }
727 
728  if (!available_u || (SAMPLE_CTB(fc->tab.cpm[0], x_b, y_b) != MODE_INTRA) ||
729  SAMPLE_CTB(fc->tab.imf, x_b, y_b) || !y0b) {
730  b = INTRA_PLANAR;
731  } else {
732  b = SAMPLE_CTB(fc->tab.ipm, x_b, y_b);
733  }
734 
735  if (a == b && a > INTRA_DC) {
736  cand[0] = a;
737  cand[1] = 2 + ((a + 61) % 64);
738  cand[2] = 2 + ((a - 1) % 64);
739  cand[3] = 2 + ((a + 60) % 64);
740  cand[4] = 2 + (a % 64);
741  } else {
742  const int minab = FFMIN(a, b);
743  const int maxab = FFMAX(a, b);
744  if (a > INTRA_DC && b > INTRA_DC) {
745  const int diff = maxab - minab;
746  cand[0] = a;
747  cand[1] = b;
748  if (diff == 1) {
749  cand[2] = 2 + ((minab + 61) % 64);
750  cand[3] = 2 + ((maxab - 1) % 64);
751  cand[4] = 2 + ((minab + 60) % 64);
752  } else if (diff >= 62) {
753  cand[2] = 2 + ((minab - 1) % 64);
754  cand[3] = 2 + ((maxab + 61) % 64);
755  cand[4] = 2 + (minab % 64);
756  } else if (diff == 2) {
757  cand[2] = 2 + ((minab - 1) % 64);
758  cand[3] = 2 + ((minab + 61) % 64);
759  cand[4] = 2 + ((maxab - 1) % 64);
760  } else {
761  cand[2] = 2 + ((minab + 61) % 64);
762  cand[3] = 2 + ((minab - 1) % 64);
763  cand[4] = 2 + ((maxab + 61) % 64);
764  }
765  } else if (a > INTRA_DC || b > INTRA_DC) {
766  cand[0] = maxab;
767  cand[1] = 2 + ((maxab + 61 ) % 64);
768  cand[2] = 2 + ((maxab - 1) % 64);
769  cand[3] = 2 + ((maxab + 60 ) % 64);
770  cand[4] = 2 + (maxab % 64);
771  } else {
772  cand[0] = INTRA_DC;
773  cand[1] = INTRA_VERT;
774  cand[2] = INTRA_HORZ;
775  cand[3] = INTRA_VERT - 4;
776  cand[4] = INTRA_VERT + 4;
777  }
778  }
779  if (intra_luma_mpm_flag) {
780  pred = cand[intra_luma_mpm_idx];
781  } else {
782  qsort(cand, FF_ARRAY_ELEMS(cand), sizeof(cand[0]), less);
783  pred = intra_luma_mpm_remainder + 1;
784  for (int i = 0; i < FF_ARRAY_ELEMS(cand); i++) {
785  if (pred >= cand[i])
786  pred++;
787  }
788  }
789  }
790  return pred;
791 }
792 
794 {
795  CodingUnit *cu = lc->cu;
796  const VVCTreeType tree_type = cu->tree_type;
797  const VVCSPS *sps = lc->fc->ps.sps;
798  const int cb_width = cu->cb_width;
799  const int cb_height = cu->cb_height;
800  const TransformUnit *tu = cu->tus.head;
801  int lfnst_width, lfnst_height, min_lfnst;
802  int lfnst_idx = 0;
803 
804  memset(cu->apply_lfnst_flag, 0, sizeof(cu->apply_lfnst_flag));
805 
806  if (!sps->r->sps_lfnst_enabled_flag || cu->pred_mode != MODE_INTRA || FFMAX(cb_width, cb_height) > sps->max_tb_size_y)
807  return 0;
808 
809  while (tu) {
810  for (int j = 0; j < tu->nb_tbs; j++) {
811  const TransformBlock *tb = tu->tbs + j;
812  if (tu->coded_flag[tb->c_idx] && tb->ts)
813  return 0;
814  }
815  tu = tu->next;
816  }
817 
818  if (tree_type == DUAL_TREE_CHROMA) {
819  lfnst_width = cb_width >> sps->hshift[1];
820  lfnst_height = cb_height >> sps->vshift[1];
821  } else {
822  const int vs = cu->isp_split_type == ISP_VER_SPLIT;
823  const int hs = cu->isp_split_type == ISP_HOR_SPLIT;
824  lfnst_width = vs ? cb_width / cu->num_intra_subpartitions : cb_width;
825  lfnst_height = hs ? cb_height / cu->num_intra_subpartitions : cb_height;
826  }
827  min_lfnst = FFMIN(lfnst_width, lfnst_height);
828  if (tree_type != DUAL_TREE_CHROMA && cu->intra_mip_flag && min_lfnst < 16)
829  return 0;
830 
831  if (min_lfnst >= 4) {
833  lfnst_idx = ff_vvc_lfnst_idx(lc, tree_type != SINGLE_TREE);
834  }
835 
836  if (lfnst_idx) {
837  cu->apply_lfnst_flag[LUMA] = tree_type != DUAL_TREE_CHROMA;
838  cu->apply_lfnst_flag[CB] = cu->apply_lfnst_flag[CR] = tree_type == DUAL_TREE_CHROMA;
839  }
840 
841  return lfnst_idx;
842 }
843 
845 {
846  const CodingUnit *cu = lc->cu;
847  const VVCSPS *sps = lc->fc->ps.sps;
848  const int cb_width = cu->cb_width;
849  const int cb_height = cu->cb_height;
850  const uint8_t transform_skip_flag = cu->tus.head->tbs[0].ts; //fix me
851  int mts_idx = MTS_DCT2_DCT2;
852  if (cu->tree_type != DUAL_TREE_CHROMA && !cu->lfnst_idx &&
853  !transform_skip_flag && FFMAX(cb_width, cb_height) <= 32 &&
854  cu->isp_split_type == ISP_NO_SPLIT && !cu->sbt_flag &&
856  if ((cu->pred_mode == MODE_INTER && sps->r->sps_explicit_mts_inter_enabled_flag) ||
857  (cu->pred_mode == MODE_INTRA && sps->r->sps_explicit_mts_intra_enabled_flag)) {
858  mts_idx = ff_vvc_mts_idx(lc);
859  }
860  }
861 
862  return mts_idx;
863 }
864 
866 {
867  const int x_center = (cu->x0 + cu->cb_width / 2) >> sps->min_cb_log2_size_y;
868  const int y_center = (cu->y0 + cu->cb_height / 2) >> sps->min_cb_log2_size_y;
869  const int min_cb_width = pps->min_cb_width;
870  const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_center, y_center);
871  const int cu_pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_center, y_center);
872  const int intra_pred_mode_y = SAMPLE_CTB(fc->tab.ipm, x_center, y_center);
873 
874  if (intra_mip_flag) {
875  if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
876  return INTRA_INVALID;
877  return INTRA_PLANAR;
878  }
879  if (cu_pred_mode == MODE_IBC || cu_pred_mode == MODE_PLT)
880  return INTRA_DC;
881  return intra_pred_mode_y;
882 }
883 
885  const int cclm_mode_flag, const int cclm_mode_idx, const int intra_chroma_pred_mode)
886 {
887  const VVCFrameContext *fc = lc->fc;
888  CodingUnit *cu = lc->cu;
889  const VVCSPS *sps = fc->ps.sps;
890  const VVCPPS *pps = fc->ps.pps;
891  const int x_cb = cu->x0 >> sps->min_cb_log2_size_y;
892  const int y_cb = cu->y0 >> sps->min_cb_log2_size_y;
893  const int min_cb_width = pps->min_cb_width;
894  const int intra_mip_flag = SAMPLE_CTB(fc->tab.imf, x_cb, y_cb);
895  enum IntraPredMode luma_intra_pred_mode = SAMPLE_CTB(fc->tab.ipm, x_cb, y_cb);
896 
897  if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 &&
898  intra_chroma_pred_mode == 4 && intra_mip_flag) {
899  cu->mip_chroma_direct_flag = 1;
901  return;
902  }
904 
905  if (cu->act_enabled_flag) {
907  return;
908  }
909  if (cclm_mode_flag) {
910  cu->intra_pred_mode_c = INTRA_LT_CCLM + cclm_mode_idx;
911  } else if (intra_chroma_pred_mode == 4){
913  } else {
914  const static IntraPredMode pred_mode_c[][4 + 1] = {
919  };
920  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  if (cu->tree_type == SINGLE_TREE && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444 && intra_mip_flag) {
927  idx = 4;
928  } else {
929  for (idx = 0; idx < FF_ARRAY_ELEMS(modes); idx++) {
930  if (modes[idx] == luma_intra_pred_mode)
931  break;
932  }
933  }
934 
935  cu->intra_pred_mode_c = pred_mode_c[intra_chroma_pred_mode][idx];
936  }
937  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 static av_always_inline uint8_t pack_mip_info(int intra_mip_flag,
950  int intra_mip_transposed_flag, int intra_mip_mode)
951 {
952  return (intra_mip_mode << 2) | (intra_mip_transposed_flag << 1) | intra_mip_flag;
953 }
954 
956 {
957  VVCFrameContext *fc = lc->fc;
958  const VVCSPS *sps = fc->ps.sps;
959  const VVCPPS *pps = fc->ps.pps;
960  CodingUnit *cu = lc->cu;
961  const int log2_min_cb_size = sps->min_cb_log2_size_y;
962  const int x0 = cu->x0;
963  const int y0 = cu->y0;
964  const int x_cb = x0 >> log2_min_cb_size;
965  const int y_cb = y0 >> log2_min_cb_size;
966  const int cb_width = cu->cb_width;
967  const int cb_height = cu->cb_height;
968 
969  cu->intra_luma_ref_idx = 0;
970  if (sps->r->sps_bdpcm_enabled_flag && cb_width <= sps->max_ts_size && cb_height <= sps->max_ts_size)
972  if (cu->bdpcm_flag[LUMA]) {
974  } else {
975  if (sps->r->sps_mip_enabled_flag)
976  cu->intra_mip_flag = ff_vvc_intra_mip_flag(lc, fc->tab.imf);
977  if (cu->intra_mip_flag) {
978  int intra_mip_transposed_flag = ff_vvc_intra_mip_transposed_flag(lc);
979  int intra_mip_mode = ff_vvc_intra_mip_mode(lc);
980  int x = y_cb * pps->min_cb_width + x_cb;
981  for (int y = 0; y < (cb_height>>log2_min_cb_size); y++) {
982  int width = cb_width>>log2_min_cb_size;
983  const uint8_t mip_info = pack_mip_info(cu->intra_mip_flag,
984  intra_mip_transposed_flag, intra_mip_mode);
985  memset(&fc->tab.imf[x], mip_info, width);
986  x += pps->min_cb_width;
987  }
988  cu->intra_pred_mode_y = intra_mip_mode;
989  } else {
990  int intra_subpartitions_mode_flag = 0;
991  if (sps->r->sps_mrl_enabled_flag && ((y0 % sps->ctb_size_y) > 0))
993  if (sps->r->sps_isp_enabled_flag && !cu->intra_luma_ref_idx &&
994  (cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) &&
995  (cb_width * cb_height > MIN_TU_SIZE * MIN_TU_SIZE) &&
996  !cu->act_enabled_flag)
997  intra_subpartitions_mode_flag = ff_vvc_intra_subpartitions_mode_flag(lc);
998  if (!(x0 & 63) && !(y0 & 63))
999  TAB_ISPMF(fc, x0, y0) = intra_subpartitions_mode_flag;
1000  cu->isp_split_type = ff_vvc_isp_split_type(lc, intra_subpartitions_mode_flag);
1001  cu->num_intra_subpartitions = get_num_intra_subpartitions(cu->isp_split_type, cb_width, cb_height);
1002  cu->intra_pred_mode_y = luma_intra_pred_mode(lc, intra_subpartitions_mode_flag);
1003  }
1004  }
1005  set_cb_tab(lc, fc->tab.ipm, cu->intra_pred_mode_y);
1006 }
1007 
1009 {
1010  const VVCSPS *sps = lc->fc->ps.sps;
1011  CodingUnit *cu = lc->cu;
1012  const int hs = sps->hshift[CHROMA];
1013  const int vs = sps->vshift[CHROMA];
1014 
1015  cu->mip_chroma_direct_flag = 0;
1016  if (sps->r->sps_bdpcm_enabled_flag &&
1017  (cu->cb_width >> hs) <= sps->max_ts_size &&
1018  (cu->cb_height >> vs) <= sps->max_ts_size) {
1020  }
1021  if (cu->bdpcm_flag[CHROMA]) {
1023  } else {
1024  const int cclm_enabled = get_cclm_enabled(lc, cu->x0, cu->y0);
1025  int cclm_mode_flag = 0;
1026  int cclm_mode_idx = 0;
1027  int intra_chroma_pred_mode = 0;
1028 
1029  if (cclm_enabled)
1030  cclm_mode_flag = ff_vvc_cclm_mode_flag(lc);
1031 
1032  if (cclm_mode_flag)
1033  cclm_mode_idx = ff_vvc_cclm_mode_idx(lc);
1034  else
1035  intra_chroma_pred_mode = ff_vvc_intra_chroma_pred_mode(lc);
1036  derive_chroma_intra_pred_mode(lc, cclm_mode_flag, cclm_mode_idx, intra_chroma_pred_mode);
1037  }
1038 }
1039 
1041  const VVCTreeType tree_type,
1042  const VVCModeType mode_type)
1043 {
1044  const VVCFrameContext *fc = lc->fc;
1045  CodingUnit *cu = lc->cu;
1046  const VVCSPS *sps = fc->ps.sps;
1047  const H266RawSliceHeader *rsh = lc->sc->sh.r;
1048  const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1049  const int is_4x4 = cu->cb_width == 4 && cu->cb_height == 4;
1050  int pred_mode_flag;
1051  int pred_mode_ibc_flag;
1052  PredMode pred_mode;
1053 
1054  cu->skip_flag = 0;
1055  if (!IS_I(rsh) || sps->r->sps_ibc_enabled_flag) {
1056  const int is_128 = cu->cb_width == 128 || cu->cb_height == 128;
1057  if (tree_type != DUAL_TREE_CHROMA &&
1058  ((!is_4x4 && mode_type != MODE_TYPE_INTRA) ||
1059  (sps->r->sps_ibc_enabled_flag && !is_128))) {
1060  cu->skip_flag = ff_vvc_cu_skip_flag(lc, fc->tab.skip);
1061  }
1062 
1063  if (is_4x4 || mode_type == MODE_TYPE_INTRA || IS_I(rsh)) {
1064  pred_mode_flag = 1;
1065  } else if (mode_type == MODE_TYPE_INTER || cu->skip_flag) {
1066  pred_mode_flag = 0;
1067  } else {
1068  pred_mode_flag = ff_vvc_pred_mode_flag(lc, ch_type);
1069  }
1070  pred_mode = pred_mode_flag ? MODE_INTRA : MODE_INTER;
1071 
1072  if (((IS_I(rsh) && !cu->skip_flag) ||
1073  (!IS_I(rsh) && (pred_mode != MODE_INTRA ||
1074  ((is_4x4 || mode_type == MODE_TYPE_INTRA) && !cu->skip_flag)))) &&
1075  !is_128 && mode_type != MODE_TYPE_INTER && sps->r->sps_ibc_enabled_flag &&
1076  tree_type != DUAL_TREE_CHROMA) {
1077  pred_mode_ibc_flag = ff_vvc_pred_mode_ibc_flag(lc, ch_type);
1078  } else if (cu->skip_flag && (is_4x4 || mode_type == MODE_TYPE_INTRA)) {
1079  pred_mode_ibc_flag = 1;
1080  } else if (is_128 || mode_type == MODE_TYPE_INTER || tree_type == DUAL_TREE_CHROMA) {
1081  pred_mode_ibc_flag = 0;
1082  } else {
1083  pred_mode_ibc_flag = (IS_I(rsh)) ? sps->r->sps_ibc_enabled_flag : 0;
1084  }
1085  if (pred_mode_ibc_flag)
1086  pred_mode = MODE_IBC;
1087  } else {
1088  pred_mode = MODE_INTRA;
1089  }
1090 
1091  set_cb_tab(lc, fc->tab.cpm[cu->ch_type], pred_mode);
1092  if (tree_type == SINGLE_TREE)
1093  set_cb_tab(lc, fc->tab.cpm[CHROMA], pred_mode);
1094 
1095  return pred_mode;
1096 }
1097 
1098 static void sbt_info(VVCLocalContext *lc, const VVCSPS *sps)
1099 {
1100  CodingUnit *cu = lc->cu;
1101  const int cb_width = cu->cb_width;
1102  const int cb_height = cu->cb_height;
1103 
1104  if (cu->pred_mode == MODE_INTER && sps->r->sps_sbt_enabled_flag && !cu->ciip_flag
1105  && cb_width <= sps->max_tb_size_y && cb_height <= sps->max_tb_size_y) {
1106  const int sbt_ver_h = cb_width >= 8;
1107  const int sbt_hor_h = cb_height >= 8;
1108  cu->sbt_flag = 0;
1109  if (sbt_ver_h || sbt_hor_h)
1110  cu->sbt_flag = ff_vvc_sbt_flag(lc);
1111  if (cu->sbt_flag) {
1112  const int sbt_ver_q = cb_width >= 16;
1113  const int sbt_hor_q = cb_height >= 16;
1114  int cu_sbt_quad_flag = 0;
1115 
1116  if ((sbt_ver_h || sbt_hor_h) && (sbt_ver_q || sbt_hor_q))
1117  cu_sbt_quad_flag = ff_vvc_sbt_quad_flag(lc);
1118  if (cu_sbt_quad_flag) {
1119  cu->sbt_horizontal_flag = sbt_hor_q;
1120  if (sbt_ver_q && sbt_hor_q)
1122  } else {
1123  cu->sbt_horizontal_flag = sbt_hor_h;
1124  if (sbt_ver_h && sbt_hor_h)
1126  }
1128 
1129  {
1130  const int sbt_min = cu_sbt_quad_flag ? 1 : 2;
1131  lc->parse.sbt_num_fourths_tb0 = cu->sbt_pos_flag ? (4 - sbt_min) : sbt_min;
1132  }
1133  }
1134  }
1135 }
1136 
1138 {
1139  const H266RawSPS *rsps = lc->fc->ps.sps->r;
1140  const CodingUnit *cu = lc->cu;
1141  int ret;
1142 
1143  if (cu->tree_type != DUAL_TREE_CHROMA)
1144  set_qp_y(lc, cu->x0, cu->y0, 0);
1145  if (rsps->sps_chroma_format_idc && cu->tree_type != DUAL_TREE_LUMA)
1146  set_qp_c(lc);
1147  ret = skipped_transform_tree(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1148  if (ret < 0)
1149  return ret;
1150  return 0;
1151 }
1152 
1153 static void set_cb_pos(const VVCFrameContext *fc, const CodingUnit *cu)
1154 {
1155  const VVCSPS *sps = fc->ps.sps;
1156  const VVCPPS *pps = fc->ps.pps;
1157  const int log2_min_cb_size = sps->min_cb_log2_size_y;
1158  const int x_cb = cu->x0 >> log2_min_cb_size;
1159  const int y_cb = cu->y0 >> log2_min_cb_size;
1160  const int ch_type = cu->ch_type;
1161  int x, y;
1162 
1163  x = y_cb * pps->min_cb_width + x_cb;
1164  for (y = 0; y < (cu->cb_height >> log2_min_cb_size); y++) {
1165  const int width = cu->cb_width >> log2_min_cb_size;
1166 
1167  for (int i = 0; i < width; i++) {
1168  fc->tab.cb_pos_x[ch_type][x + i] = cu->x0;
1169  fc->tab.cb_pos_y[ch_type][x + i] = cu->y0;
1170  }
1171  memset(&fc->tab.cb_width[ch_type][x], cu->cb_width, width);
1172  memset(&fc->tab.cb_height[ch_type][x], cu->cb_height, width);
1173  memset(&fc->tab.cqt_depth[ch_type][x], cu->cqt_depth, width);
1174 
1175  x += pps->min_cb_width;
1176  }
1177 }
1178 
1179 static CodingUnit* alloc_cu(VVCLocalContext *lc, const int x0, const int y0)
1180 {
1181  VVCFrameContext *fc = lc->fc;
1182  const VVCSPS *sps = fc->ps.sps;
1183  const VVCPPS *pps = fc->ps.pps;
1184  const int rx = x0 >> sps->ctb_log2_size_y;
1185  const int ry = y0 >> sps->ctb_log2_size_y;
1186  CodingUnit **cus = fc->tab.cus + ry * pps->ctb_width + rx;
1187  CodingUnit *cu = av_refstruct_pool_get(fc->cu_pool);
1188 
1189  if (!cu)
1190  return NULL;
1191  cu->next = NULL;
1192 
1193  if (lc->cu)
1194  lc->cu->next = cu;
1195  else
1196  *cus = cu;
1197  lc->cu = cu;
1198 
1199  return cu;
1200 }
1201 
1202 static CodingUnit* add_cu(VVCLocalContext *lc, const int x0, const int y0,
1203  const int cb_width, const int cb_height, const int cqt_depth, const VVCTreeType tree_type)
1204 {
1205  VVCFrameContext *fc = lc->fc;
1206  const int ch_type = tree_type == DUAL_TREE_CHROMA ? 1 : 0;
1207  CodingUnit *cu = alloc_cu(lc, x0, y0);
1208 
1209  if (!cu)
1210  return NULL;
1211 
1212  memset(&cu->pu, 0, sizeof(cu->pu));
1213 
1214  lc->parse.prev_tu_cbf_y = 0;
1215 
1216  cu->sbt_flag = 0;
1217  cu->act_enabled_flag = 0;
1218 
1219  cu->tree_type = tree_type;
1220  cu->x0 = x0;
1221  cu->y0 = y0;
1222  cu->cb_width = cb_width;
1223  cu->cb_height = cb_height;
1224  cu->ch_type = ch_type;
1225  cu->cqt_depth = cqt_depth;
1226  cu->tus.head = cu->tus.tail = NULL;
1227  cu->bdpcm_flag[LUMA] = cu->bdpcm_flag[CB] = cu->bdpcm_flag[CR] = 0;
1229  cu->intra_mip_flag = 0;
1230  cu->ciip_flag = 0;
1231  cu->coded_flag = 1;
1232  cu->num_intra_subpartitions = 1;
1233  cu->pu.dmvr_flag = 0;
1234 
1235  set_cb_pos(fc, cu);
1236  return cu;
1237 }
1238 
1239 static void set_cu_tabs(const VVCLocalContext *lc, const CodingUnit *cu)
1240 {
1241  const VVCFrameContext *fc = lc->fc;
1242  const PredictionUnit *pu = &cu->pu;
1243  const TransformUnit *tu = cu->tus.head;
1244 
1245  set_cb_tab(lc, fc->tab.mmi, pu->mi.motion_model_idc);
1246  set_cb_tab(lc, fc->tab.msf, pu->merge_subblock_flag);
1247  if (cu->tree_type != DUAL_TREE_CHROMA) {
1248  set_cb_tab(lc, fc->tab.skip, cu->skip_flag);
1249  set_cb_tab(lc, fc->tab.pcmf[LUMA], cu->bdpcm_flag[LUMA]);
1250  }
1251  if (cu->tree_type != DUAL_TREE_LUMA)
1252  set_cb_tab(lc, fc->tab.pcmf[CHROMA], cu->bdpcm_flag[CHROMA]);
1253 
1254  while (tu) {
1255  for (int j = 0; j < tu->nb_tbs; j++) {
1256  const TransformBlock *tb = tu->tbs + j;
1257  if (tb->c_idx != LUMA)
1258  set_qp_c_tab(lc, tu, tb);
1259  }
1260  tu = tu->next;
1261  }
1262 }
1263 
1264 //8.5.2.7 Derivation process for merge motion vector difference
1265 static void derive_mmvd(const VVCLocalContext *lc, MvField *mvf, const Mv *mmvd_offset)
1266 {
1267  const SliceContext *sc = lc->sc;
1268  Mv mmvd[2];
1269 
1270  if (mvf->pred_flag == PF_BI) {
1271  const RefPicList *rpl = sc->rpl;
1272  const int poc = lc->fc->ps.ph.poc;
1273  const int diff[] = {
1274  poc - rpl[L0].refs[mvf->ref_idx[L0]].poc,
1275  poc - rpl[L1].refs[mvf->ref_idx[L1]].poc
1276  };
1277  const int sign = FFSIGN(diff[0]) != FFSIGN(diff[1]);
1278 
1279  if (diff[0] == diff[1]) {
1280  mmvd[1] = mmvd[0] = *mmvd_offset;
1281  }
1282  else {
1283  const int i = FFABS(diff[0]) < FFABS(diff[1]);
1284  const int o = !i;
1285  mmvd[i] = *mmvd_offset;
1286  if (!rpl[L0].refs[mvf->ref_idx[L0]].is_lt && !rpl[L1].refs[mvf->ref_idx[L1]].is_lt) {
1287  ff_vvc_mv_scale(&mmvd[o], mmvd_offset, diff[i], diff[o]);
1288  }
1289  else {
1290  mmvd[o].x = sign ? -mmvd[i].x : mmvd[i].x;
1291  mmvd[o].y = sign ? -mmvd[i].y : mmvd[i].y;
1292  }
1293  }
1294  mvf->mv[0].x += mmvd[0].x;
1295  mvf->mv[0].y += mmvd[0].y;
1296  mvf->mv[1].x += mmvd[1].x;
1297  mvf->mv[1].y += mmvd[1].y;
1298  } else {
1299  const int idx = mvf->pred_flag - PF_L0;
1300  mvf->mv[idx].x += mmvd_offset->x;
1301  mvf->mv[idx].y += mmvd_offset->y;
1302  }
1303 
1304 }
1305 
1306 static void mvf_to_mi(const MvField *mvf, MotionInfo *mi)
1307 {
1308  mi->pred_flag = mvf->pred_flag;
1309  mi->bcw_idx = mvf->bcw_idx;
1310  mi->hpel_if_idx = mvf->hpel_if_idx;
1311  for (int i = 0; i < 2; i++) {
1312  const PredFlag mask = i + 1;
1313  if (mvf->pred_flag & mask) {
1314  mi->mv[i][0] = mvf->mv[i];
1315  mi->ref_idx[i] = mvf->ref_idx[i];
1316  }
1317  }
1318 }
1319 
1320 static void mv_merge_refine_pred_flag(MvField *mvf, const int width, const int height)
1321 {
1322  if (mvf->pred_flag == PF_BI && (width + height) == 12) {
1323  mvf->pred_flag = PF_L0;
1324  mvf->bcw_idx = 0;
1325  }
1326 }
1327 
1328 // subblock-based inter prediction data
1330 {
1331  const VVCFrameContext *fc = lc->fc;
1332  const VVCPH *ph = &fc->ps.ph;
1333  CodingUnit* cu = lc->cu;
1334  PredictionUnit *pu = &cu->pu;
1335  int merge_subblock_idx = 0;
1336 
1337  if (ph->max_num_subblock_merge_cand > 1) {
1338  merge_subblock_idx = ff_vvc_merge_subblock_idx(lc, ph->max_num_subblock_merge_cand);
1339  }
1340  ff_vvc_sb_mv_merge_mode(lc, merge_subblock_idx, pu);
1341 }
1342 
1344 {
1345  const VVCFrameContext *fc = lc->fc;
1346  const VVCSPS *sps = fc->ps.sps;
1347  const VVCPH *ph = &fc->ps.ph;
1348  const CodingUnit* cu = lc->cu;
1349  PredictionUnit *pu = &lc->cu->pu;
1350  int merge_idx = 0;
1351  Mv mmvd_offset;
1352  MvField mvf;
1353 
1354  if (sps->r->sps_mmvd_enabled_flag)
1356  if (pu->mmvd_merge_flag) {
1357  int mmvd_cand_flag = 0;
1358  if (sps->max_num_merge_cand > 1)
1359  mmvd_cand_flag = ff_vvc_mmvd_cand_flag(lc);
1360  ff_vvc_mmvd_offset_coding(lc, &mmvd_offset, ph->r->ph_mmvd_fullpel_only_flag);
1361  merge_idx = mmvd_cand_flag;
1362  } else if (sps->max_num_merge_cand > 1) {
1363  merge_idx = ff_vvc_merge_idx(lc);
1364  }
1365  ff_vvc_luma_mv_merge_mode(lc, merge_idx, 0, &mvf);
1366  if (pu->mmvd_merge_flag)
1367  derive_mmvd(lc, &mvf, &mmvd_offset);
1369  ff_vvc_store_mvf(lc, &mvf);
1370  mvf_to_mi(&mvf, &pu->mi);
1371 }
1372 
1373 static int ciip_flag_decode(VVCLocalContext *lc, const int ciip_avaiable, const int gpm_avaiable, const int is_128)
1374 {
1375  const VVCFrameContext *fc = lc->fc;
1376  const VVCSPS *sps = fc->ps.sps;
1377  const CodingUnit *cu = lc->cu;
1378 
1379  if (ciip_avaiable && gpm_avaiable)
1380  return ff_vvc_ciip_flag(lc);
1381  return sps->r->sps_ciip_enabled_flag && !cu->skip_flag &&
1382  !is_128 && (cu->cb_width * cu->cb_height >= 64);
1383 }
1384 
1386 {
1387  const VVCFrameContext *fc = lc->fc;
1388  const VVCSPS *sps = fc->ps.sps;
1389  PredictionUnit *pu = &lc->cu->pu;
1390  int merge_gpm_idx[2];
1391 
1392  pu->merge_gpm_flag = 1;
1394  merge_gpm_idx[0] = ff_vvc_merge_gpm_idx(lc, 0);
1395  merge_gpm_idx[1] = 0;
1396  if (sps->max_num_gpm_merge_cand > 2)
1397  merge_gpm_idx[1] = ff_vvc_merge_gpm_idx(lc, 1);
1398 
1399  ff_vvc_luma_mv_merge_gpm(lc, merge_gpm_idx, pu->gpm_mv);
1400  ff_vvc_store_gpm_mvf(lc, pu);
1401 }
1402 
1404 {
1405  const VVCFrameContext* fc = lc->fc;
1406  const VVCSPS* sps = fc->ps.sps;
1407  CodingUnit *cu = lc->cu;
1408  MotionInfo *mi = &cu->pu.mi;
1409  int merge_idx = 0;
1410  MvField mvf;
1411 
1412  if (sps->max_num_merge_cand > 1)
1413  merge_idx = ff_vvc_merge_idx(lc);
1414  ff_vvc_luma_mv_merge_mode(lc, merge_idx, 1, &mvf);
1416  ff_vvc_store_mvf(lc, &mvf);
1417  mvf_to_mi(&mvf, mi);
1419  cu->intra_luma_ref_idx = 0;
1420  cu->intra_mip_flag = 0;
1421 }
1422 
1423 // block-based inter prediction data
1425 {
1426  const VVCFrameContext* fc = lc->fc;
1427  const VVCSPS *sps = fc->ps.sps;
1428  const H266RawSliceHeader *rsh = lc->sc->sh.r;
1429  CodingUnit *cu = lc->cu;
1430  const int cb_width = cu->cb_width;
1431  const int cb_height = cu->cb_height;
1432  const int is_128 = cb_width == 128 || cb_height == 128;
1433  const int ciip_avaiable = sps->r->sps_ciip_enabled_flag &&
1434  !cu->skip_flag && (cb_width * cb_height >= 64);
1435  const int gpm_avaiable = sps->r->sps_gpm_enabled_flag && IS_B(rsh) &&
1436  (cb_width >= 8) && (cb_height >=8) &&
1437  (cb_width < 8 * cb_height) && (cb_height < 8 *cb_width);
1438 
1439  int regular_merge_flag = 1;
1440 
1441  if (!is_128 && (ciip_avaiable || gpm_avaiable))
1442  regular_merge_flag = ff_vvc_regular_merge_flag(lc, cu->skip_flag);
1443  if (regular_merge_flag) {
1444  merge_data_regular(lc);
1445  } else {
1446  cu->ciip_flag = ciip_flag_decode(lc, ciip_avaiable, gpm_avaiable, is_128);
1447  if (cu->ciip_flag)
1448  merge_data_ciip(lc);
1449  else
1450  merge_data_gpm(lc);
1451  }
1452 }
1453 
1455 {
1456  const VVCFrameContext* fc = lc->fc;
1457  const VVCSPS* sps = fc->ps.sps;
1458  MotionInfo *mi = &lc->cu->pu.mi;
1459  int merge_idx = 0;
1460  int ret;
1461 
1462  mi->pred_flag = PF_IBC;
1463 
1464  if (sps->max_num_ibc_merge_cand > 1)
1465  merge_idx = ff_vvc_merge_idx(lc);
1466 
1467  ret = ff_vvc_luma_mv_merge_ibc(lc, merge_idx, &mi->mv[L0][0]);
1468  if (ret)
1469  return ret;
1470  ff_vvc_store_mv(lc, mi);
1471 
1472  return 0;
1473 }
1474 
1476 {
1477  const VVCFrameContext *fc = lc->fc;
1478  const VVCPH *ph = &fc->ps.ph;
1479  const CodingUnit *cu = lc->cu;
1480  PredictionUnit *pu = &lc->cu->pu;
1481  int ret;
1482 
1483  pu->merge_gpm_flag = 0;
1484  pu->mi.num_sb_x = pu->mi.num_sb_y = 1;
1485  if (cu->pred_mode == MODE_IBC) {
1486  ret = merge_data_ibc(lc);
1487  if (ret)
1488  return ret;
1489  } else {
1490  if (ph->max_num_subblock_merge_cand > 0 && cu->cb_width >= 8 && cu->cb_height >= 8)
1492  if (pu->merge_subblock_flag)
1493  merge_data_subblock(lc);
1494  else
1495  merge_data_block(lc);
1496  }
1497  return 0;
1498 }
1499 
1500 static void hls_mvd_coding(VVCLocalContext *lc, Mv* mvd)
1501 {
1502  int32_t mv[2];
1503 
1504  for (int i = 0; i < 2; i++) {
1506  }
1507 
1508  for (int i = 0; i < 2; i++) {
1509  if (mv[i])
1511  }
1512 
1513  for (int i = 0; i < 2; i++) {
1514  if (mv[i] > 0) {
1515  if (mv[i] == 2)
1516  mv[i] += ff_vvc_abs_mvd_minus2(lc);
1517  mv[i] = (1 - 2 * ff_vvc_mvd_sign_flag(lc)) * mv[i];
1518  }
1519  }
1520  mvd->x = mv[0];
1521  mvd->y = mv[1];
1522 }
1523 
1524 static int bcw_idx_decode(VVCLocalContext *lc, const MotionInfo *mi, const int cb_width, const int cb_height)
1525 {
1526  const VVCFrameContext *fc = lc->fc;
1527  const VVCSPS *sps = fc->ps.sps;
1528  const VVCPPS *pps = fc->ps.pps;
1529  const VVCPH *ph = &fc->ps.ph;
1530  const VVCSH *sh = &lc->sc->sh;
1531  const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &ph->pwt : &sh->pwt;
1532  int bcw_idx = 0;
1533 
1534  if (sps->r->sps_bcw_enabled_flag && mi->pred_flag == PF_BI &&
1535  !w->weight_flag[L0][LUMA][mi->ref_idx[0]] &&
1536  !w->weight_flag[L1][LUMA][mi->ref_idx[1]] &&
1537  !w->weight_flag[L0][CHROMA][mi->ref_idx[0]] &&
1538  !w->weight_flag[L1][CHROMA][mi->ref_idx[1]] &&
1539  cb_width * cb_height >= 256) {
1540  bcw_idx = ff_vvc_bcw_idx(lc, ff_vvc_no_backward_pred_flag(lc));
1541  }
1542  return bcw_idx;
1543 }
1544 
1545 static int8_t ref_idx_decode(VVCLocalContext *lc, const VVCSH *sh, const int sym_mvd_flag, const int lx)
1546 {
1547  const H266RawSliceHeader *rsh = sh->r;
1548  int ref_idx = 0;
1549 
1550  if (rsh->num_ref_idx_active[lx] > 1 && !sym_mvd_flag)
1551  ref_idx = ff_vvc_ref_idx_lx(lc, rsh->num_ref_idx_active[lx]);
1552  else if (sym_mvd_flag)
1553  ref_idx = sh->ref_idx_sym[lx];
1554  return ref_idx;
1555 }
1556 
1558  const int num_cp_mv, const int lx)
1559 {
1560  const VVCFrameContext *fc = lc->fc;
1561  const VVCPH *ph = &fc->ps.ph;
1562  const PredictionUnit *pu = &lc->cu->pu;
1563  const MotionInfo *mi = &pu->mi;
1564  int has_no_zero_mvd = 0;
1565 
1566  if (lx == L1 && ph->r->ph_mvd_l1_zero_flag && mi->pred_flag == PF_BI) {
1567  for (int j = 0; j < num_cp_mv; j++)
1568  AV_ZERO64(&mvds[lx][j]);
1569  } else {
1570  Mv *mvd0 = &mvds[lx][0];
1571  if (lx == L1 && pu->sym_mvd_flag) {
1572  mvd0->x = -mvds[L0][0].x;
1573  mvd0->y = -mvds[L0][0].y;
1574  } else {
1575  hls_mvd_coding(lc, mvd0);
1576  }
1577  has_no_zero_mvd |= (mvd0->x || mvd0->y);
1578  for (int j = 1; j < num_cp_mv; j++) {
1579  Mv *mvd = &mvds[lx][j];
1580  hls_mvd_coding(lc, mvd);
1581  mvd->x += mvd0->x;
1582  mvd->y += mvd0->y;
1583  has_no_zero_mvd |= (mvd->x || mvd->y);
1584  }
1585  }
1586  return has_no_zero_mvd;
1587 }
1588 
1589 static void mvp_add_difference(MotionInfo *mi, const int num_cp_mv,
1590  const Mv mvds[2][MAX_CONTROL_POINTS], const int amvr_shift)
1591 {
1592  for (int i = 0; i < 2; i++) {
1593  const PredFlag mask = i + PF_L0;
1594  if (mi->pred_flag & mask) {
1595  for (int j = 0; j < num_cp_mv; j++) {
1596  const Mv *mvd = &mvds[i][j];
1597  mi->mv[i][j].x += mvd->x * (1 << amvr_shift);
1598  mi->mv[i][j].y += mvd->y * (1 << amvr_shift);
1599  }
1600  }
1601  }
1602 }
1603 
1605 {
1606  const VVCFrameContext *fc = lc->fc;
1607  const CodingUnit *cu = lc->cu;
1608  const PredictionUnit *pu = &lc->cu->pu;
1609  const VVCSPS *sps = fc->ps.sps;
1610  MotionInfo *mi = &lc->cu->pu.mi;
1611  int mvp_l0_flag = 0;
1612  int amvr_shift = 4;
1613  Mv *mv = &mi->mv[L0][0];
1614  int ret;
1615 
1616  mi->pred_flag = PF_IBC;
1617  mi->num_sb_x = 1;
1618  mi->num_sb_y = 1;
1619 
1620  hls_mvd_coding(lc, mv);
1621  if (sps->max_num_ibc_merge_cand > 1)
1622  mvp_l0_flag = ff_vvc_mvp_lx_flag(lc);
1623  if (sps->r->sps_amvr_enabled_flag && (mv->x || mv->y))
1624  amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, 1);
1625 
1626  ret = ff_vvc_mvp_ibc(lc, mvp_l0_flag, amvr_shift, mv);
1627  if (ret)
1628  return ret;
1629  ff_vvc_store_mv(lc, mi);
1630 
1631  return 0;
1632 }
1633 
1634 static int mvp_data(VVCLocalContext *lc)
1635 {
1636  const VVCFrameContext *fc = lc->fc;
1637  const CodingUnit *cu = lc->cu;
1638  PredictionUnit *pu = &lc->cu->pu;
1639  const VVCSPS *sps = fc->ps.sps;
1640  const VVCPH *ph = &fc->ps.ph;
1641  const VVCSH *sh = &lc->sc->sh;
1642  const H266RawSliceHeader *rsh = sh->r;
1643  MotionInfo *mi = &pu->mi;
1644  const int cb_width = cu->cb_width;
1645  const int cb_height = cu->cb_height;
1646 
1647  int mvp_lx_flag[2] = {0};
1648  int cu_affine_type_flag = 0;
1649  int num_cp_mv;
1650  int amvr_enabled, has_no_zero_mvd = 0, amvr_shift;
1651  Mv mvds[2][MAX_CONTROL_POINTS];
1652 
1653  mi->pred_flag = ff_vvc_pred_flag(lc, IS_B(rsh));
1654  if (sps->r->sps_affine_enabled_flag && cb_width >= 16 && cb_height >= 16) {
1656  set_cb_tab(lc, fc->tab.iaf, pu->inter_affine_flag);
1657  if (sps->r->sps_6param_affine_enabled_flag && pu->inter_affine_flag)
1658  cu_affine_type_flag = ff_vvc_cu_affine_type_flag(lc);
1659  }
1660  mi->motion_model_idc = pu->inter_affine_flag + cu_affine_type_flag;
1661  num_cp_mv = mi->motion_model_idc + 1;
1662 
1663  if (sps->r->sps_smvd_enabled_flag && !ph->r->ph_mvd_l1_zero_flag &&
1664  mi->pred_flag == PF_BI && !pu->inter_affine_flag &&
1665  sh->ref_idx_sym[0] > -1 && sh->ref_idx_sym[1] > -1)
1667 
1668  for (int i = L0; i <= L1; i++) {
1669  const PredFlag pred_flag = PF_L0 + !i;
1670  if (mi->pred_flag != pred_flag) {
1671  mi->ref_idx[i] = ref_idx_decode(lc, sh, pu->sym_mvd_flag, i);
1672  has_no_zero_mvd |= mvds_decode(lc, mvds, num_cp_mv, i);
1673  mvp_lx_flag[i] = ff_vvc_mvp_lx_flag(lc);
1674  }
1675  }
1676 
1677  amvr_enabled = mi->motion_model_idc == MOTION_TRANSLATION ?
1678  sps->r->sps_amvr_enabled_flag : sps->r->sps_affine_amvr_enabled_flag;
1679  amvr_enabled &= has_no_zero_mvd;
1680 
1681  amvr_shift = ff_vvc_amvr_shift(lc, pu->inter_affine_flag, cu->pred_mode, amvr_enabled);
1682 
1683  mi->hpel_if_idx = amvr_shift == 3;
1684  mi->bcw_idx = bcw_idx_decode(lc, mi, cb_width, cb_height);
1685 
1686  if (mi->motion_model_idc)
1687  ff_vvc_affine_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1688  else
1689  ff_vvc_mvp(lc, mvp_lx_flag, amvr_shift, mi);
1690 
1691  mvp_add_difference(mi, num_cp_mv, mvds, amvr_shift);
1692 
1693  if (mi->motion_model_idc)
1694  ff_vvc_store_sb_mvs(lc, pu);
1695  else
1696  ff_vvc_store_mv(lc, &pu->mi);
1697 
1698  return 0;
1699 }
1700 
1701 // derive bdofFlag from 8.5.6 Decoding process for inter blocks
1702 // derive dmvr from 8.5.1 General decoding process for coding units coded in inter prediction mode
1704 {
1705  const VVCFrameContext *fc = lc->fc;
1706  const VVCPPS *pps = fc->ps.pps;
1707  const VVCPH *ph = &fc->ps.ph;
1708  const VVCSH *sh = &lc->sc->sh;
1709  const int poc = ph->poc;
1710  const MotionInfo *mi = &pu->mi;
1711  const int8_t *ref_idx = mi->ref_idx;
1712  const VVCRefPic *rp0 = &lc->sc->rpl[L0].refs[ref_idx[L0]];
1713  const VVCRefPic *rp1 = &lc->sc->rpl[L1].refs[ref_idx[L1]];
1714  const CodingUnit *cu = lc->cu;
1715  const PredWeightTable *w = pps->r->pps_wp_info_in_ph_flag ? &fc->ps.ph.pwt : &sh->pwt;
1716 
1717  pu->bdof_flag = 0;
1718 
1719  if (mi->pred_flag == PF_BI &&
1720  (poc - rp0->poc == rp1->poc - poc) &&
1721  !rp0->is_lt && !rp1->is_lt &&
1722  !cu->ciip_flag &&
1723  !mi->bcw_idx &&
1724  !w->weight_flag[L0][LUMA][ref_idx[L0]] && !w->weight_flag[L1][LUMA][ref_idx[L1]] &&
1725  !w->weight_flag[L0][CHROMA][ref_idx[L0]] && !w->weight_flag[L1][CHROMA][ref_idx[L1]] &&
1726  cu->cb_width >= 8 && cu->cb_height >= 8 &&
1727  (cu->cb_width * cu->cb_height >= 128) &&
1728  !rp0->is_scaled && !rp1->is_scaled) {
1729  if (!ph->r->ph_bdof_disabled_flag &&
1730  mi->motion_model_idc == MOTION_TRANSLATION &&
1731  !pu->merge_subblock_flag &&
1732  !pu->sym_mvd_flag)
1733  pu->bdof_flag = 1;
1734  if (!ph->r->ph_dmvr_disabled_flag &&
1735  pu->general_merge_flag &&
1736  !pu->mmvd_merge_flag)
1737  pu->dmvr_flag = 1;
1738  }
1739 }
1740 
1741 // part of 8.5.1 General decoding process for coding units coded in inter prediction mode
1743 {
1744  const CodingUnit *cu = lc->cu;
1745  PredictionUnit *pu = &lc->cu->pu;
1746 
1747  derive_dmvr_bdof_flag(lc, pu);
1748  if (pu->dmvr_flag || pu->bdof_flag) {
1749  pu->mi.num_sb_x = (cu->cb_width > 16) ? (cu->cb_width >> 4) : 1;
1750  pu->mi.num_sb_y = (cu->cb_height > 16) ? (cu->cb_height >> 4) : 1;
1751  }
1752 }
1753 
1754 static void fill_dmvr_info(const VVCLocalContext *lc)
1755 {
1756  const VVCFrameContext *fc = lc->fc;
1757  const CodingUnit *cu = lc->cu;
1758 
1759  if (cu->pred_mode == MODE_IBC) {
1760  ff_vvc_set_intra_mvf(lc, 1);
1761  } else {
1762  const VVCPPS *pps = fc->ps.pps;
1763  const int w = cu->cb_width >> MIN_PU_LOG2;
1764 
1765  for (int y = cu->y0 >> MIN_PU_LOG2; y < (cu->y0 + cu->cb_height) >> MIN_PU_LOG2; y++) {
1766  const int idx = pps->min_pu_width * y + (cu->x0 >> MIN_PU_LOG2);
1767  const MvField *mvf = fc->tab.mvf + idx;
1768  MvField *dmvr_mvf = fc->ref->tab_dmvr_mvf + idx;
1769 
1770  memcpy(dmvr_mvf, mvf, sizeof(MvField) * w);
1771  }
1772  }
1773 }
1774 
1776 {
1777  const CodingUnit *cu = lc->cu;
1778  PredictionUnit *pu = &lc->cu->pu;
1779  const MotionInfo *mi = &pu->mi;
1780  int ret = 0;
1781 
1782  pu->general_merge_flag = 1;
1783  if (!cu->skip_flag)
1785 
1786  if (pu->general_merge_flag) {
1787  ret = hls_merge_data(lc);
1788  } else if (cu->pred_mode == MODE_IBC) {
1789  ret = mvp_data_ibc(lc);
1790  } else {
1791  ret = mvp_data(lc);
1792  }
1793 
1794  if (ret)
1795  return ret;
1796 
1797  if (cu->pred_mode == MODE_IBC) {
1798  ff_vvc_update_hmvp(lc, mi);
1799  } else if (!pu->merge_gpm_flag && !pu->inter_affine_flag && !pu->merge_subblock_flag) {
1801  ff_vvc_update_hmvp(lc, mi);
1802  }
1803 
1804  if (!pu->dmvr_flag)
1805  fill_dmvr_info(lc);
1806  return ret;
1807 }
1808 
1809 static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height,
1810  int cqt_depth, const VVCTreeType tree_type, VVCModeType mode_type)
1811 {
1812  const VVCFrameContext *fc = lc->fc;
1813  const VVCSPS *sps = fc->ps.sps;
1814  const H266RawSliceHeader *rsh = lc->sc->sh.r;
1815  const int hs = sps->hshift[CHROMA];
1816  const int vs = sps->vshift[CHROMA];
1817  const int is_128 = cb_width > 64 || cb_height > 64;
1818  int pred_mode_plt_flag = 0;
1819  int ret;
1820 
1821  CodingUnit *cu = add_cu(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type);
1822 
1823  if (!cu)
1824  return AVERROR(ENOMEM);
1825 
1826  ff_vvc_set_neighbour_available(lc, cu->x0, cu->y0, cu->cb_width, cu->cb_height);
1827 
1828  if (IS_I(rsh) && is_128)
1829  mode_type = MODE_TYPE_INTRA;
1830  cu->pred_mode = pred_mode_decode(lc, tree_type, mode_type);
1831 
1832  if (cu->pred_mode == MODE_INTRA && sps->r->sps_palette_enabled_flag && !is_128 && !cu->skip_flag &&
1833  mode_type != MODE_TYPE_INTER && ((cb_width * cb_height) >
1834  (tree_type != DUAL_TREE_CHROMA ? 16 : (16 << hs << vs))) &&
1835  (mode_type != MODE_TYPE_INTRA || tree_type != DUAL_TREE_CHROMA)) {
1836  pred_mode_plt_flag = ff_vvc_pred_mode_plt_flag(lc);
1837  if (pred_mode_plt_flag) {
1838  avpriv_report_missing_feature(fc->log_ctx, "Palette");
1839  return AVERROR_PATCHWELCOME;
1840  }
1841  }
1842  if (cu->pred_mode == MODE_INTRA && sps->r->sps_act_enabled_flag && tree_type == SINGLE_TREE) {
1843  avpriv_report_missing_feature(fc->log_ctx, "Adaptive Color Transform");
1844  return AVERROR_PATCHWELCOME;
1845  }
1846  if (cu->pred_mode == MODE_INTRA || cu->pred_mode == MODE_PLT) {
1847  if (tree_type == SINGLE_TREE || tree_type == DUAL_TREE_LUMA) {
1848  if (pred_mode_plt_flag) {
1849  avpriv_report_missing_feature(fc->log_ctx, "Palette");
1850  return AVERROR_PATCHWELCOME;
1851  } else {
1853  }
1854  ff_vvc_set_intra_mvf(lc, 0);
1855  }
1856  if ((tree_type == SINGLE_TREE || tree_type == DUAL_TREE_CHROMA) && sps->r->sps_chroma_format_idc) {
1857  if (pred_mode_plt_flag && tree_type == DUAL_TREE_CHROMA) {
1858  avpriv_report_missing_feature(fc->log_ctx, "Palette");
1859  return AVERROR_PATCHWELCOME;
1860  } else if (!pred_mode_plt_flag) {
1861  if (!cu->act_enabled_flag)
1863  }
1864  }
1865  } else if (tree_type != DUAL_TREE_CHROMA) { /* MODE_INTER or MODE_IBC */
1866  if ((ret = inter_data(lc)) < 0)
1867  return ret;
1868  }
1869  if (cu->pred_mode != MODE_INTRA && !pred_mode_plt_flag && !lc->cu->pu.general_merge_flag)
1870  cu->coded_flag = ff_vvc_cu_coded_flag(lc);
1871  else
1872  cu->coded_flag = !(cu->skip_flag || pred_mode_plt_flag);
1873 
1874  if (cu->coded_flag) {
1875  sbt_info(lc, sps);
1876  if (sps->r->sps_act_enabled_flag && cu->pred_mode != MODE_INTRA && tree_type == SINGLE_TREE) {
1877  avpriv_report_missing_feature(fc->log_ctx, "Adaptive Color Transform");
1878  return AVERROR_PATCHWELCOME;
1879  }
1880  lc->parse.lfnst_dc_only = 1;
1882  lc->parse.mts_dc_only = 1;
1884  ret = hls_transform_tree(lc, x0, y0, cb_width, cb_height, cu->ch_type);
1885  if (ret < 0)
1886  return ret;
1887  cu->lfnst_idx = lfnst_idx_decode(lc);
1888  cu->mts_idx = mts_idx_decode(lc);
1889  set_qp_c(lc);
1890  } else {
1892  if (ret < 0)
1893  return ret;
1894  }
1895  set_cu_tabs(lc, cu);
1896 
1897  return 0;
1898 }
1899 
1901  const VVCSplitMode split, const int cb_width, const int cb_height, const VVCModeType mode_type_curr)
1902 {
1903  const H266RawSliceHeader *rsh = lc->sc->sh.r;
1904  const VVCSPS *sps = lc->fc->ps.sps;
1905  const int area = cb_width * cb_height;
1906 
1907  if ((IS_I(rsh) && sps->r->sps_qtbtt_dual_tree_intra_flag) ||
1908  mode_type_curr != MODE_TYPE_ALL || !sps->r->sps_chroma_format_idc ||
1909  sps->r->sps_chroma_format_idc == CHROMA_FORMAT_444)
1910  return 0;
1911  if ((area == 64 && (split == SPLIT_QT || split == SPLIT_TT_HOR || split == SPLIT_TT_VER)) ||
1912  (area == 32 && (split == SPLIT_BT_HOR || split == SPLIT_BT_VER)))
1913  return 1;
1914  if ((area == 64 && (split == SPLIT_BT_HOR || split == SPLIT_BT_VER) && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_420) ||
1915  (area == 128 && (split == SPLIT_TT_HOR || split == SPLIT_TT_VER) && sps->r->sps_chroma_format_idc == CHROMA_FORMAT_420) ||
1916  (cb_width == 8 && split == SPLIT_BT_VER) || (cb_width == 16 && split == SPLIT_TT_VER))
1917  return 1 + !IS_I(rsh);
1918 
1919  return 0;
1920 }
1921 
1922 static VVCModeType mode_type_decode(VVCLocalContext *lc, const int x0, const int y0,
1923  const int cb_width, const int cb_height, const VVCSplitMode split, const int ch_type,
1924  const VVCModeType mode_type_curr)
1925 {
1926  VVCModeType mode_type;
1927  const int mode_type_condition = derive_mode_type_condition(lc, split, cb_width, cb_height, mode_type_curr);
1928 
1929  if (mode_type_condition == 1)
1930  mode_type = MODE_TYPE_INTRA;
1931  else if (mode_type_condition == 2) {
1932  mode_type = ff_vvc_non_inter_flag(lc, x0, y0, ch_type) ? MODE_TYPE_INTRA : MODE_TYPE_INTER;
1933  } else {
1934  mode_type = mode_type_curr;
1935  }
1936 
1937  return mode_type;
1938 }
1939 
1940 static int hls_coding_tree(VVCLocalContext *lc,
1941  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
1942  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx,
1943  VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr);
1944 
1946  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
1947  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
1948  VVCTreeType tree_type, VVCModeType mode_type)
1949 {
1950 #define CODING_TREE(x, idx) do { \
1951  ret = hls_coding_tree(lc, x, y0, cb_width / 2, cb_height, \
1952  qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
1953  depth_offset, idx, SPLIT_BT_VER, tree_type, mode_type); \
1954  if (ret < 0) \
1955  return ret; \
1956 } while (0);
1957 
1958  const VVCPPS *pps = lc->fc->ps.pps;
1959  const int x1 = x0 + cb_width / 2;
1960  int ret = 0;
1961 
1962  depth_offset += (x0 + cb_width > pps->width) ? 1 : 0;
1963  CODING_TREE(x0, 0);
1964  if (x1 < pps->width)
1965  CODING_TREE(x1, 1);
1966 
1967  return 0;
1968 
1969 #undef CODING_TREE
1970 }
1971 
1973  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
1974  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
1975  VVCTreeType tree_type, VVCModeType mode_type)
1976 {
1977 #define CODING_TREE(y, idx) do { \
1978  ret = hls_coding_tree(lc, x0, y, cb_width , cb_height / 2, \
1979  qg_on_y, qg_on_c, cb_sub_div + 1, cqt_depth, mtt_depth + 1, \
1980  depth_offset, idx, SPLIT_BT_HOR, tree_type, mode_type); \
1981  if (ret < 0) \
1982  return ret; \
1983  } while (0);
1984 
1985  const VVCPPS *pps = lc->fc->ps.pps;
1986  const int y1 = y0 + (cb_height / 2);
1987  int ret = 0;
1988 
1989  depth_offset += (y0 + cb_height > pps->height) ? 1 : 0;
1990  CODING_TREE(y0, 0);
1991  if (y1 < pps->height)
1992  CODING_TREE(y1, 1);
1993 
1994  return 0;
1995 
1996 #undef CODING_TREE
1997 }
1998 
2000  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2001  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2002  VVCTreeType tree_type, VVCModeType mode_type)
2003 {
2004 #define CODING_TREE(x, w, sub_div, idx) do { \
2005  ret = hls_coding_tree(lc, x, y0, w, cb_height, \
2006  qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2007  depth_offset, idx, SPLIT_TT_VER, tree_type, mode_type); \
2008  if (ret < 0) \
2009  return ret; \
2010  } while (0);
2011 
2012  const VVCSH *sh = &lc->sc->sh;
2013  const int x1 = x0 + cb_width / 4;
2014  const int x2 = x0 + cb_width * 3 / 4;
2015  int ret;
2016 
2017  qg_on_y = qg_on_y && (cb_sub_div + 2 <= sh->cu_qp_delta_subdiv);
2018  qg_on_c = qg_on_c && (cb_sub_div + 2 <= sh->cu_chroma_qp_offset_subdiv);
2019 
2020  CODING_TREE(x0, cb_width / 4, cb_sub_div + 2, 0);
2021  CODING_TREE(x1, cb_width / 2, cb_sub_div + 1, 1);
2022  CODING_TREE(x2, cb_width / 4, cb_sub_div + 2, 2);
2023 
2024  return 0;
2025 
2026 #undef CODING_TREE
2027 }
2028 
2030  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2031  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2032  VVCTreeType tree_type, VVCModeType mode_type)
2033 {
2034 #define CODING_TREE(y, h, sub_div, idx) do { \
2035  ret = hls_coding_tree(lc, x0, y, cb_width, h, \
2036  qg_on_y, qg_on_c, sub_div, cqt_depth, mtt_depth + 1, \
2037  depth_offset, idx, SPLIT_TT_HOR, tree_type, mode_type); \
2038  if (ret < 0) \
2039  return ret; \
2040  } while (0);
2041 
2042  const VVCSH *sh = &lc->sc->sh;
2043  const int y1 = y0 + (cb_height / 4);
2044  const int y2 = y0 + (3 * cb_height / 4);
2045  int ret;
2046 
2047  qg_on_y = qg_on_y && (cb_sub_div + 2 <= sh->cu_qp_delta_subdiv);
2048  qg_on_c = qg_on_c && (cb_sub_div + 2 <= sh->cu_chroma_qp_offset_subdiv);
2049 
2050  CODING_TREE(y0, cb_height / 4, cb_sub_div + 2, 0);
2051  CODING_TREE(y1, cb_height / 2, cb_sub_div + 1, 1);
2052  CODING_TREE(y2, cb_height / 4, cb_sub_div + 2, 2);
2053 
2054  return 0;
2055 
2056 #undef CODING_TREE
2057 }
2058 
2060  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2061  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2062  VVCTreeType tree_type, VVCModeType mode_type)
2063 {
2064 #define CODING_TREE(x, y, idx) do { \
2065  ret = hls_coding_tree(lc, x, y, cb_width / 2, cb_height / 2, \
2066  qg_on_y, qg_on_c, cb_sub_div + 2, cqt_depth + 1, 0, 0, \
2067  idx, SPLIT_QT, tree_type, mode_type); \
2068  if (ret < 0) \
2069  return ret; \
2070  } while (0);
2071 
2072  const VVCPPS *pps = lc->fc->ps.pps;
2073  const int x1 = x0 + cb_width / 2;
2074  const int y1 = y0 + cb_height / 2;
2075  int ret = 0;
2076 
2077  CODING_TREE(x0, y0, 0);
2078  if (x1 < pps->width)
2079  CODING_TREE(x1, y0, 1);
2080  if (y1 < pps->height)
2081  CODING_TREE(x0, y1, 2);
2082  if (x1 < pps->width &&
2083  y1 < pps->height)
2084  CODING_TREE(x1, y1, 3);
2085 
2086  return 0;
2087 
2088 #undef CODING_TREE
2089 }
2090 
2091 typedef int (*coding_tree_fn)(VVCLocalContext *lc,
2092  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2093  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset,
2094  VVCTreeType tree_type, VVCModeType mode_type);
2095 
2096 const static coding_tree_fn coding_tree[] = {
2102 };
2103 
2105  int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c,
2106  int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx,
2107  VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr)
2108 {
2109  VVCFrameContext *fc = lc->fc;
2110  const VVCPPS *pps = fc->ps.pps;
2111  const VVCSH *sh = &lc->sc->sh;
2112  const H266RawSliceHeader *rsh = sh->r;
2113  const int ch_type = tree_type_curr == DUAL_TREE_CHROMA;
2114  int ret;
2115  VVCAllowedSplit allowed;
2116 
2117  if (pps->r->pps_cu_qp_delta_enabled_flag && qg_on_y && cb_sub_div <= sh->cu_qp_delta_subdiv) {
2118  lc->parse.is_cu_qp_delta_coded = 0;
2119  lc->parse.cu_qg_top_left_x = x0;
2120  lc->parse.cu_qg_top_left_y = y0;
2121  }
2122  if (rsh->sh_cu_chroma_qp_offset_enabled_flag && qg_on_c &&
2123  cb_sub_div <= sh->cu_chroma_qp_offset_subdiv) {
2125  memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2126  }
2127 
2128  can_split(lc, x0, y0, cb_width, cb_height, mtt_depth, depth_offset, part_idx,
2129  last_split_mode, tree_type_curr, mode_type_curr, &allowed);
2130  if (ff_vvc_split_cu_flag(lc, x0, y0, cb_width, cb_height, ch_type, &allowed)) {
2131  VVCSplitMode split = ff_vvc_split_mode(lc, x0, y0, cb_width, cb_height, cqt_depth, mtt_depth, ch_type, &allowed);
2132  VVCModeType mode_type = mode_type_decode(lc, x0, y0, cb_width, cb_height, split, ch_type, mode_type_curr);
2133 
2134  VVCTreeType tree_type = (mode_type == MODE_TYPE_INTRA) ? DUAL_TREE_LUMA : tree_type_curr;
2135 
2136  if (split != SPLIT_QT) {
2137  if (!(x0 & 31) && !(y0 & 31) && mtt_depth <= 1)
2138  TAB_MSM(fc, mtt_depth, x0, y0) = split;
2139  }
2140  ret = coding_tree[split - 1](lc, x0, y0, cb_width, cb_height, qg_on_y, qg_on_c,
2141  cb_sub_div, cqt_depth, mtt_depth, depth_offset, tree_type, mode_type);
2142  if (ret < 0)
2143  return ret;
2144  if (mode_type_curr == MODE_TYPE_ALL && mode_type == MODE_TYPE_INTRA) {
2145  ret = hls_coding_tree(lc, x0, y0, cb_width, cb_height, 0, qg_on_c, cb_sub_div,
2146  cqt_depth, mtt_depth, 0, 0, split, DUAL_TREE_CHROMA, mode_type);
2147  if (ret < 0)
2148  return ret;
2149  }
2150  } else {
2151  ret = hls_coding_unit(lc, x0, y0, cb_width, cb_height, cqt_depth, tree_type_curr, mode_type_curr);
2152  if (ret < 0)
2153  return ret;
2154  }
2155 
2156  return 0;
2157 }
2158 
2160  const int x0, const int y0, const int cb_size, const int cqt_depth)
2161 {
2162  const VVCSH *sh = &lc->sc->sh;
2163  const H266RawSliceHeader *rsh = sh->r;
2164  const VVCPPS *pps = lc->fc->ps.pps;
2165  const int cb_subdiv = 2 * cqt_depth;
2166  int ret;
2167 
2168  if (cb_size > 64) {
2169  #define DUAL_TREE(x, y) do { \
2170  ret = dual_tree_implicit_qt_split(lc, x, y, cb_size / 2, cqt_depth + 1); \
2171  if (ret < 0) \
2172  return ret; \
2173  } while (0)
2174 
2175  const int x1 = x0 + (cb_size / 2);
2176  const int y1 = y0 + (cb_size / 2);
2177  if (pps->r->pps_cu_qp_delta_enabled_flag && cb_subdiv <= sh->cu_qp_delta_subdiv) {
2178  lc->parse.is_cu_qp_delta_coded = 0;
2179  lc->parse.cu_qg_top_left_x = x0;
2180  lc->parse.cu_qg_top_left_y = y0;
2181  }
2182  if (rsh->sh_cu_chroma_qp_offset_enabled_flag && cb_subdiv <= sh->cu_chroma_qp_offset_subdiv) {
2184  memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2185  }
2186  DUAL_TREE(x0, y0);
2187  if (x1 < pps->width)
2188  DUAL_TREE(x1, y0);
2189  if (y1 < pps->height)
2190  DUAL_TREE(x0, y1);
2191  if (x1 < pps->width && y1 < pps->height)
2192  DUAL_TREE(x1, y1);
2193  #undef DUAL_TREE
2194  } else {
2195  #define CODING_TREE(tree_type) do { \
2196  const int qg_on_y = tree_type == DUAL_TREE_LUMA; \
2197  ret = hls_coding_tree(lc, x0, y0, cb_size, cb_size, qg_on_y, !qg_on_y, \
2198  cb_subdiv, cqt_depth, 0, 0, 0, SPLIT_NONE, tree_type, MODE_TYPE_ALL); \
2199  if (ret < 0) \
2200  return ret; \
2201  } while (0)
2204  #undef CODING_TREE
2205  }
2206  return 0;
2207 }
2208 
2209 #define SET_SAO(elem, value) \
2210 do { \
2211  if (!sao_merge_up_flag && !sao_merge_left_flag) \
2212  sao->elem = value; \
2213  else if (sao_merge_left_flag) \
2214  sao->elem = CTB(fc->tab.sao, rx-1, ry).elem; \
2215  else if (sao_merge_up_flag) \
2216  sao->elem = CTB(fc->tab.sao, rx, ry-1).elem; \
2217  else \
2218  sao->elem = 0; \
2219 } while (0)
2220 
2221 static void hls_sao(VVCLocalContext *lc, const int rx, const int ry)
2222 {
2223  VVCFrameContext *fc = lc->fc;
2224  const H266RawSliceHeader *rsh = lc->sc->sh.r;
2225  int sao_merge_left_flag = 0;
2226  int sao_merge_up_flag = 0;
2227  SAOParams *sao = &CTB(fc->tab.sao, rx, ry);
2228  int c_idx, i;
2229 
2231  if (rx > 0) {
2232  if (lc->ctb_left_flag)
2233  sao_merge_left_flag = ff_vvc_sao_merge_flag_decode(lc);
2234  }
2235  if (ry > 0 && !sao_merge_left_flag) {
2236  if (lc->ctb_up_flag)
2237  sao_merge_up_flag = ff_vvc_sao_merge_flag_decode(lc);
2238  }
2239  }
2240 
2241  for (c_idx = 0; c_idx < (fc->ps.sps->r->sps_chroma_format_idc ? 3 : 1); c_idx++) {
2242  const int sao_used_flag = !c_idx ? rsh->sh_sao_luma_used_flag : rsh->sh_sao_chroma_used_flag;
2243  if (!sao_used_flag) {
2244  sao->type_idx[c_idx] = SAO_NOT_APPLIED;
2245  continue;
2246  }
2247 
2248  if (c_idx == 2) {
2249  sao->type_idx[2] = sao->type_idx[1];
2250  sao->eo_class[2] = sao->eo_class[1];
2251  } else {
2252  SET_SAO(type_idx[c_idx], ff_vvc_sao_type_idx_decode(lc));
2253  }
2254 
2255  if (sao->type_idx[c_idx] == SAO_NOT_APPLIED)
2256  continue;
2257 
2258  for (i = 0; i < 4; i++)
2259  SET_SAO(offset_abs[c_idx][i], ff_vvc_sao_offset_abs_decode(lc));
2260 
2261  if (sao->type_idx[c_idx] == SAO_BAND) {
2262  for (i = 0; i < 4; i++) {
2263  if (sao->offset_abs[c_idx][i]) {
2264  SET_SAO(offset_sign[c_idx][i],
2266  } else {
2267  sao->offset_sign[c_idx][i] = 0;
2268  }
2269  }
2270  SET_SAO(band_position[c_idx], ff_vvc_sao_band_position_decode(lc));
2271  } else if (c_idx != 2) {
2272  SET_SAO(eo_class[c_idx], ff_vvc_sao_eo_class_decode(lc));
2273  }
2274 
2275  // Inferred parameters
2276  sao->offset_val[c_idx][0] = 0;
2277  for (i = 0; i < 4; i++) {
2278  sao->offset_val[c_idx][i + 1] = sao->offset_abs[c_idx][i];
2279  if (sao->type_idx[c_idx] == SAO_EDGE) {
2280  if (i > 1)
2281  sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
2282  } else if (sao->offset_sign[c_idx][i]) {
2283  sao->offset_val[c_idx][i + 1] = -sao->offset_val[c_idx][i + 1];
2284  }
2285  sao->offset_val[c_idx][i + 1] *= 1 << (fc->ps.sps->bit_depth - FFMIN(10, fc->ps.sps->bit_depth));
2286  }
2287  }
2288 }
2289 
2290 static void alf_params(VVCLocalContext *lc, const int rx, const int ry)
2291 {
2292  const VVCFrameContext *fc = lc->fc;
2293  const H266RawSliceHeader *sh = lc->sc->sh.r;
2294  ALFParams *alf = &CTB(fc->tab.alf, rx, ry);
2295 
2296  alf->ctb_flag[LUMA] = alf->ctb_flag[CB] = alf->ctb_flag[CR] = 0;
2297  if (sh->sh_alf_enabled_flag) {
2298  alf->ctb_flag[LUMA] = ff_vvc_alf_ctb_flag(lc, rx, ry, LUMA);
2299  if (alf->ctb_flag[LUMA]) {
2300  uint8_t alf_use_aps_flag = 0;
2301  if (sh->sh_num_alf_aps_ids_luma > 0)
2302  alf_use_aps_flag = ff_vvc_alf_use_aps_flag(lc);
2303  if (alf_use_aps_flag) {
2304  alf->ctb_filt_set_idx_y = 16;
2305  if (sh->sh_num_alf_aps_ids_luma > 1)
2307  } else {
2309  }
2310  }
2311  for (int c_idx = CB; c_idx <= CR; c_idx++) {
2312  const uint8_t alf_enabled_flag =
2313  c_idx == CB ? sh->sh_alf_cb_enabled_flag : sh->sh_alf_cr_enabled_flag;
2314  if (alf_enabled_flag) {
2315  const VVCALF *aps = fc->ps.alf_list[sh->sh_alf_aps_id_chroma];
2316  alf->ctb_flag[c_idx] = ff_vvc_alf_ctb_flag(lc, rx, ry, c_idx);
2317  alf->alf_ctb_filter_alt_idx[c_idx - 1] = 0;
2318  if (alf->ctb_flag[c_idx] && aps->num_chroma_filters > 1)
2319  alf->alf_ctb_filter_alt_idx[c_idx - 1] = ff_vvc_alf_ctb_filter_alt_idx(lc, c_idx, aps->num_chroma_filters);
2320  }
2321  }
2322  }
2323  if (fc->ps.sps->r->sps_ccalf_enabled_flag) {
2324  const uint8_t cc_enabled[] = { sh->sh_alf_cc_cb_enabled_flag, sh->sh_alf_cc_cr_enabled_flag };
2325  const uint8_t cc_aps_id[] = { sh->sh_alf_cc_cb_aps_id, sh->sh_alf_cc_cr_aps_id };
2326  for (int i = 0; i < 2; i++) {
2327  alf->ctb_cc_idc[i] = 0;
2328  if (cc_enabled[i]) {
2329  const VVCALF *aps = fc->ps.alf_list[cc_aps_id[i]];
2330  alf->ctb_cc_idc[i] = ff_vvc_alf_ctb_cc_idc(lc, rx, ry, i, aps->num_cc_filters[i]);
2331  }
2332  }
2333  }
2334 }
2335 
2336 static void deblock_params(VVCLocalContext *lc, const int rx, const int ry)
2337 {
2338  VVCFrameContext *fc = lc->fc;
2339  const VVCSH *sh = &lc->sc->sh;
2340  CTB(fc->tab.deblock, rx, ry) = sh->deblock;
2341 }
2342 
2344  const int x0, const int y0, const int ctu_idx, const int rx, const int ry)
2345 {
2346  const VVCFrameContext *fc = lc->fc;
2347  const VVCSPS *sps = fc->ps.sps;
2348  const VVCPPS *pps = fc->ps.pps;
2349  const VVCSH *sh = &lc->sc->sh;
2350  const H266RawSliceHeader *rsh = sh->r;
2351  const unsigned int ctb_size = sps->ctb_size_y;
2352  int ret = 0;
2353 
2354  memset(lc->parse.chroma_qp_offset, 0, sizeof(lc->parse.chroma_qp_offset));
2355 
2356  hls_sao(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2357  alf_params(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2358  deblock_params(lc, x0 >> sps->ctb_log2_size_y, y0 >> sps->ctb_log2_size_y);
2359 
2360  if (IS_I(rsh) && sps->r->sps_qtbtt_dual_tree_intra_flag)
2361  ret = dual_tree_implicit_qt_split(lc, x0, y0, ctb_size, 0);
2362  else
2363  ret = hls_coding_tree(lc, x0, y0, ctb_size, ctb_size,
2364  1, 1, 0, 0, 0, 0, 0, SPLIT_NONE, SINGLE_TREE, MODE_TYPE_ALL);
2365  if (ret < 0)
2366  return ret;
2367 
2368  if (rx == pps->ctb_to_col_bd[rx + 1] - 1) {
2369  if (ctu_idx == sh->num_ctus_in_curr_slice - 1) {
2370  const int end_of_slice_one_bit = ff_vvc_end_of_slice_flag_decode(lc);
2371  if (!end_of_slice_one_bit)
2372  return AVERROR_INVALIDDATA;
2373  } else {
2374  if (ry == pps->ctb_to_row_bd[ry + 1] - 1) {
2375  const int end_of_tile_one_bit = ff_vvc_end_of_tile_one_bit(lc);
2376  if (!end_of_tile_one_bit)
2377  return AVERROR_INVALIDDATA;
2378  } else {
2379  if (fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
2380  const int end_of_subset_one_bit = ff_vvc_end_of_subset_one_bit(lc);
2381  if (!end_of_subset_one_bit)
2382  return AVERROR_INVALIDDATA;
2383  }
2384  }
2385  }
2386  }
2387 
2388  return 0;
2389 }
2390 
2391 static int has_inter_luma(const CodingUnit *cu)
2392 {
2393  return cu->pred_mode != MODE_INTRA && cu->pred_mode != MODE_PLT && cu->tree_type != DUAL_TREE_CHROMA;
2394 }
2395 
2396 static int pred_get_y(const int y0, const Mv *mv, const int height)
2397 {
2398  return FFMAX(0, y0 + (mv->y >> 4) + height);
2399 }
2400 
2401 static void cu_get_max_y(const CodingUnit *cu, int max_y[2][VVC_MAX_REF_ENTRIES], const VVCFrameContext *fc)
2402 {
2403  const PredictionUnit *pu = &cu->pu;
2404 
2405  if (pu->merge_gpm_flag) {
2406  for (int i = 0; i < FF_ARRAY_ELEMS(pu->gpm_mv); i++) {
2407  const MvField *mvf = pu->gpm_mv + i;
2408  const int lx = mvf->pred_flag - PF_L0;
2409  const int idx = mvf->ref_idx[lx];
2410  const int y = pred_get_y(cu->y0, mvf->mv + lx, cu->cb_height);
2411 
2412  max_y[lx][idx] = FFMAX(max_y[lx][idx], y);
2413  }
2414  } else {
2415  const MotionInfo *mi = &pu->mi;
2416  const int max_dmvr_off = (!pu->inter_affine_flag && pu->dmvr_flag) ? 2 : 0;
2417  const int sbw = cu->cb_width / mi->num_sb_x;
2418  const int sbh = cu->cb_height / mi->num_sb_y;
2419  for (int sby = 0; sby < mi->num_sb_y; sby++) {
2420  for (int sbx = 0; sbx < mi->num_sb_x; sbx++) {
2421  const int x0 = cu->x0 + sbx * sbw;
2422  const int y0 = cu->y0 + sby * sbh;
2423  const MvField *mvf = ff_vvc_get_mvf(fc, x0, y0);
2424  for (int lx = 0; lx < 2; lx++) {
2425  const PredFlag mask = 1 << lx;
2426  if (mvf->pred_flag & mask) {
2427  const int idx = mvf->ref_idx[lx];
2428  const int y = pred_get_y(y0, mvf->mv + lx, sbh);
2429 
2430  max_y[lx][idx] = FFMAX(max_y[lx][idx], y + max_dmvr_off);
2431  }
2432  }
2433  }
2434  }
2435  }
2436 }
2437 
2438 static void ctu_get_pred(VVCLocalContext *lc, const int rs)
2439 {
2440  const VVCFrameContext *fc = lc->fc;
2441  const H266RawSliceHeader *rsh = lc->sc->sh.r;
2442  CTU *ctu = fc->tab.ctus + rs;
2443  const CodingUnit *cu = fc->tab.cus[rs];
2444 
2445  ctu->has_dmvr = 0;
2446 
2447  if (IS_I(rsh))
2448  return;
2449 
2450  for (int lx = 0; lx < 2; lx++)
2451  memset(ctu->max_y[lx], -1, sizeof(ctu->max_y[0][0]) * rsh->num_ref_idx_active[lx]);
2452 
2453  while (cu) {
2454  if (has_inter_luma(cu)) {
2455  cu_get_max_y(cu, ctu->max_y, fc);
2456  ctu->has_dmvr |= cu->pu.dmvr_flag;
2457  }
2458  cu = cu->next;
2459  }
2460  ctu->max_y_idx[0] = ctu->max_y_idx[1] = 0;
2461 }
2462 
2464  const int ctu_idx, const int rs, const int rx, const int ry)
2465 {
2466  const VVCFrameContext *fc = lc->fc;
2467  const VVCSPS *sps = fc->ps.sps;
2468  const VVCPPS *pps = fc->ps.pps;
2469  const int x_ctb = rx << sps->ctb_log2_size_y;
2470  const int y_ctb = ry << sps->ctb_log2_size_y;
2471  const int ctb_size = 1 << sps->ctb_log2_size_y << sps->ctb_log2_size_y;
2472  EntryPoint* ep = lc->ep;
2473  int ret;
2474 
2475  if (rx == pps->ctb_to_col_bd[rx]) {
2476  ep->num_hmvp = 0;
2477  ep->num_hmvp_ibc = 0;
2478  ep->is_first_qg = ry == pps->ctb_to_row_bd[ry] || !ctu_idx;
2479  }
2480 
2481  lc->coeffs = fc->tab.coeffs + rs * ctb_size * VVC_MAX_SAMPLE_ARRAYS;
2482  lc->cu = NULL;
2483 
2484  ff_vvc_cabac_init(lc, ctu_idx, rx, ry);
2485  ff_vvc_decode_neighbour(lc, x_ctb, y_ctb, rx, ry, rs);
2486  ret = hls_coding_tree_unit(lc, x_ctb, y_ctb, ctu_idx, rx, ry);
2487  if (ret < 0)
2488  return ret;
2489  ctu_get_pred(lc, rs);
2490 
2491  return 0;
2492 }
2493 
2494 void ff_vvc_decode_neighbour(VVCLocalContext *lc, const int x_ctb, const int y_ctb,
2495  const int rx, const int ry, const int rs)
2496 {
2497  VVCFrameContext *fc = lc->fc;
2498  const int ctb_size = fc->ps.sps->ctb_size_y;
2499 
2500  lc->end_of_tiles_x = fc->ps.pps->width;
2501  lc->end_of_tiles_y = fc->ps.pps->height;
2502  if (fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx + 1])
2503  lc->end_of_tiles_x = FFMIN(x_ctb + ctb_size, lc->end_of_tiles_x);
2504  if (fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry + 1])
2505  lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, lc->end_of_tiles_y);
2506 
2507  lc->boundary_flags = 0;
2508  if (rx > 0 && fc->ps.pps->ctb_to_col_bd[rx] != fc->ps.pps->ctb_to_col_bd[rx - 1])
2510  if (rx > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - 1])
2512  if (ry > 0 && fc->ps.pps->ctb_to_row_bd[ry] != fc->ps.pps->ctb_to_row_bd[ry - 1])
2514  if (ry > 0 && fc->tab.slice_idx[rs] != fc->tab.slice_idx[rs - fc->ps.pps->ctb_width])
2516  if (fc->ps.sps->r->sps_subpic_ctu_top_left_x[lc->sc->sh.r->curr_subpic_idx] == rx)
2518  if (fc->ps.sps->r->sps_subpic_ctu_top_left_y[lc->sc->sh.r->curr_subpic_idx] == ry)
2520  lc->ctb_left_flag = rx > 0 && !(lc->boundary_flags & BOUNDARY_LEFT_TILE);
2522  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]) &&
2523  (fc->ps.pps->ctb_to_row_bd[ry] == fc->ps.pps->ctb_to_row_bd[ry - 1]);
2524  lc->ctb_up_left_flag = lc->ctb_left_flag && lc->ctb_up_flag;
2525 }
2526 
2528  const int x0, const int y0, const int w, const int h)
2529 {
2530  const int log2_ctb_size = lc->fc->ps.sps->ctb_log2_size_y;
2531  const int x0b = av_zero_extend(x0, log2_ctb_size);
2532  const int y0b = av_zero_extend(y0, log2_ctb_size);
2533 
2534  lc->na.cand_up = (lc->ctb_up_flag || y0b);
2535  lc->na.cand_left = (lc->ctb_left_flag || x0b);
2536  lc->na.cand_up_left = (x0b || y0b) ? lc->na.cand_left && lc->na.cand_up : lc->ctb_up_left_flag;
2537  lc->na.cand_up_right_sap =
2538  (x0b + w == 1 << log2_ctb_size) ? lc->ctb_up_right_flag && !y0b : lc->na.cand_up;
2539  lc->na.cand_up_right = lc->na.cand_up_right_sap && (x0 + w) < lc->end_of_tiles_x;
2540 }
2541 
2543 {
2544  while (*cus) {
2545  CodingUnit *cu = *cus;
2546  TransformUnit **head = &cu->tus.head;
2547 
2548  *cus = cu->next;
2549 
2550  while (*head) {
2551  TransformUnit *tu = *head;
2552  *head = tu->next;
2553  av_refstruct_unref(&tu);
2554  }
2555  cu->tus.tail = NULL;
2556 
2557  av_refstruct_unref(&cu);
2558  }
2559 }
2560 
2561 int ff_vvc_get_qPy(const VVCFrameContext *fc, const int xc, const int yc)
2562 {
2563  const int min_cb_log2_size_y = fc->ps.sps->min_cb_log2_size_y;
2564  const int x = xc >> min_cb_log2_size_y;
2565  const int y = yc >> min_cb_log2_size_y;
2566  return fc->tab.qp[LUMA][x + y * fc->ps.pps->min_cb_width];
2567 }
2568 
2570  const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
2571 {
2572  for (size_t i = 0; i < FF_ARRAY_ELEMS(ep->stat_coeff); ++i) {
2573  ep->stat_coeff[i] =
2574  persistent_rice_adaptation_enabled_flag ? 2 * (av_log2(bit_depth - 10)) : 0;
2575  }
2576 }
VVCSPS
Definition: ps.h:58
ff_vvc_residual_coding
int ff_vvc_residual_coding(VVCLocalContext *lc, TransformBlock *tb)
Definition: cabac.c:2415
FFUMOD
#define FFUMOD(a, b)
Definition: common.h:66
L1
F H1 F F H1 F F F F H1<-F-------F-------F v v v H2 H3 H2 ^ ^ ^ F-------F-------F-> H1<-F-------F-------F|||||||||F H1 F|||||||||F H1 Funavailable fullpel samples(outside the picture for example) shall be equalto the closest available fullpel sampleSmaller pel interpolation:--------------------------if diag_mc is set then points which lie on a line between 2 vertically, horizontally or diagonally adjacent halfpel points shall be interpolatedlinearly with rounding to nearest and halfway values rounded up.points which lie on 2 diagonals at the same time should only use the onediagonal not containing the fullpel point F--> O q O<--h1-> O q O<--F v \/v \/v O O O O O O O|/|\|q q q q q|/|\|O O O O O O O ^/\ ^/\ ^ h2--> O q O<--h3-> O q O<--h2 v \/v \/v O O O O O O O|\|/|q q q q q|\|/|O O O O O O O ^/\ ^/\ ^ F--> O q O<--h1-> O q O<--Fthe remaining points shall be bilinearly interpolated from theup to 4 surrounding halfpel and fullpel points, again rounding should be tonearest and halfway values rounded upcompliant Snow decoders MUST support 1-1/8 pel luma and 1/2-1/16 pel chromainterpolation at leastOverlapped block motion compensation:-------------------------------------FIXMELL band prediction:===================Each sample in the LL0 subband is predicted by the median of the left, top andleft+top-topleft samples, samples outside the subband shall be considered tobe 0. To reverse this prediction in the decoder apply the following.for(y=0;y< height;y++){ for(x=0;x< width;x++){ sample[y][x]+=median(sample[y-1][x], sample[y][x-1], sample[y-1][x]+sample[y][x-1]-sample[y-1][x-1]);}}sample[-1][ *]=sample[ *][-1]=0;width, height here are the width and height of the LL0 subband not of the finalvideoDequantization:===============FIXMEWavelet Transform:==================Snow supports 2 wavelet transforms, the symmetric biorthogonal 5/3 integertransform and an integer approximation of the symmetric biorthogonal 9/7daubechies wavelet.2D IDWT(inverse discrete wavelet transform) --------------------------------------------The 2D IDWT applies a 2D filter recursively, each time combining the4 lowest frequency subbands into a single subband until only 1 subbandremains.The 2D filter is done by first applying a 1D filter in the vertical directionand then applying it in the horizontal one. --------------- --------------- --------------- ---------------|LL0|HL0|||||||||||||---+---|HL1||L0|H0|HL1||LL1|HL1|||||LH0|HH0|||||||||||||-------+-------|-> L1 H1 LH1 HH1 LH1 HH1 LH1 HH1 L1
Definition: snow.txt:554
VVCSH::cu_qp_delta_subdiv
uint8_t cu_qp_delta_subdiv
CuQpDeltaSubdiv.
Definition: ps.h:261
ff_vvc_cu_chroma_qp_offset_idx
int ff_vvc_cu_chroma_qp_offset_idx(VVCLocalContext *lc)
Definition: cabac.c:1671
H266RawSliceHeader::sh_alf_cc_cr_enabled_flag
uint8_t sh_alf_cc_cr_enabled_flag
Definition: cbs_h266.h:791
VVCSH::num_ctus_in_curr_slice
uint32_t num_ctus_in_curr_slice
NumCtusInCurrSlice.
Definition: ps.h:243
ff_vvc_mmvd_offset_coding
void ff_vvc_mmvd_offset_coding(VVCLocalContext *lc, Mv *mmvd_offset, const int ph_mmvd_fullpel_only_flag)
Definition: cabac.c:1417
VVCPH
Definition: ps.h:147
ff_vvc_update_hmvp
void ff_vvc_update_hmvp(VVCLocalContext *lc, const MotionInfo *mi)
Definition: mvs.c:1924
VVCPPS
Definition: ps.h:92
ff_vvc_sao_eo_class_decode
int ff_vvc_sao_eo_class_decode(VVCLocalContext *lc)
Definition: cabac.c:1015
av_clip
#define av_clip
Definition: common.h:100
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
less
static int less(const void *a, const void *b)
Definition: ctu.c:676
LUMA
#define LUMA
Definition: filter.c:31
skipped_transform_tree
static int skipped_transform_tree(VVCLocalContext *lc, int x0, int y0, int tu_width, int tu_height)
Definition: ctu.c:480
VVCLocalContext::mts_zero_out_sig_coeff_flag
int mts_zero_out_sig_coeff_flag
MtsZeroOutSigCoeffFlag;.
Definition: ctu.h:408
TransformBlock::tb_width
int tb_width
Definition: ctu.h:148
VVCPPS::r
const H266RawPPS * r
RefStruct reference.
Definition: ps.h:93
MOTION_TRANSLATION
@ MOTION_TRANSLATION
Definition: ctu.h:216
CODING_TREE
#define CODING_TREE(x, idx)
CTU::max_y_idx
int max_y_idx[2]
Definition: ctu.h:336
ff_vvc_affine_mvp
void ff_vvc_affine_mvp(VVCLocalContext *lc, const int *mvp_lx_flag, const int amvr_shift, MotionInfo *mi)
Definition: mvs.c:1856
MotionInfo
Definition: ctu.h:242
SAO_BAND
@ SAO_BAND
Definition: hevcdec.h:162
set_cb_pos
static void set_cb_pos(const VVCFrameContext *fc, const CodingUnit *cu)
Definition: ctu.c:1153
TransformUnit::height
int height
Definition: ctu.h:176
CB
#define CB
Definition: filter.c:32
ff_vvc_regular_merge_flag
int ff_vvc_regular_merge_flag(VVCLocalContext *lc, const int cu_skip_flag)
Definition: cabac.c:1386
intra_chroma_pred_modes
static void intra_chroma_pred_modes(VVCLocalContext *lc)
Definition: ctu.c:1008
add_tu
static TransformUnit * add_tu(VVCFrameContext *fc, CodingUnit *cu, const int x0, const int y0, const int tu_width, const int tu_height)
Definition: ctu.c:227
PF_IBC
@ PF_IBC
Definition: ctu.h:226
mts_idx_decode
static MtsIdx mts_idx_decode(VVCLocalContext *lc)
Definition: ctu.c:844
VVCSH::cu_chroma_qp_offset_subdiv
uint8_t cu_chroma_qp_offset_subdiv
CuChromaQpOffsetSubdiv.
Definition: ps.h:262
CodingUnit
Definition: hevcdec.h:288
mv
static const int8_t mv[256][2]
Definition: 4xm.c:81
CodingUnit::act_enabled_flag
uint8_t act_enabled_flag
Definition: ctu.h:298
PredictionUnit::gpm_partition_idx
uint8_t gpm_partition_idx
Definition: ctu.h:264
ff_vvc_ref_idx_lx
int ff_vvc_ref_idx_lx(VVCLocalContext *lc, const uint8_t nb_refs)
Definition: cabac.c:1519
CodingUnit::head
TransformUnit * head
RefStruct reference.
Definition: ctu.h:323
TransformUnit::nb_tbs
uint8_t nb_tbs
Definition: ctu.h:182
CodingUnit::bdpcm_flag
int bdpcm_flag[VVC_MAX_SAMPLE_ARRAYS]
BdpcmFlag.
Definition: ctu.h:318
ff_vvc_end_of_slice_flag_decode
int ff_vvc_end_of_slice_flag_decode(VVCLocalContext *lc)
Definition: cabac.c:2473
mask
int mask
Definition: mediacodecdec_common.c:154
MODE_IBC
@ MODE_IBC
Definition: ctu.h:193
TransformBlock::min_scan_y
int min_scan_y
Definition: ctu.h:156
ff_vvc_intra_luma_ref_idx
int ff_vvc_intra_luma_ref_idx(VVCLocalContext *lc)
Definition: cabac.c:1290
ff_vvc_inter_affine_flag
int ff_vvc_inter_affine_flag(VVCLocalContext *lc)
Definition: cabac.c:1503
ph
static int FUNC() ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
Definition: cbs_h266_syntax_template.c:3043
VVCRefPic
Definition: dec.h:45
w
uint8_t w
Definition: llviddspenc.c:38
VVCLocalContext::mts_dc_only
int mts_dc_only
MtsDcOnly.
Definition: ctu.h:407
NeighbourAvailable::cand_left
int cand_left
Definition: hevcdec.h:314
CodingUnit::intra_mip_flag
uint8_t intra_mip_flag
intra_mip_flag
Definition: ctu.h:301
NeighbourAvailable::cand_up
int cand_up
Definition: hevcdec.h:315
ff_vvc_intra_mip_flag
int ff_vvc_intra_mip_flag(VVCLocalContext *lc, const uint8_t *intra_mip_flag)
Definition: cabac.c:1268
VVCLocalContext::sc
SliceContext * sc
Definition: ctu.h:434
SAOParams::offset_sign
int offset_sign[3][4]
sao_offset_sign
Definition: dsp.h:36
TRANSFORM_UNIT
#define TRANSFORM_UNIT(x, width, idx)
add_cu
static CodingUnit * add_cu(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, const int cqt_depth, const VVCTreeType tree_type)
Definition: ctu.c:1202
INTRA_DC
@ INTRA_DC
Definition: hevcdec.h:124
ff_vvc_lfnst_idx
int ff_vvc_lfnst_idx(VVCLocalContext *lc, const int inc)
Definition: cabac.c:2454
b
#define b
Definition: input.c:41
chroma
static av_always_inline void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror, int jobnr, int nb_jobs)
Definition: vf_waveform.c:1639
H266RawSliceHeader::sh_sao_luma_used_flag
uint8_t sh_sao_luma_used_flag
Definition: cbs_h266.h:813
VVCModeType
VVCModeType
Definition: ctu.c:35
coding_tree_bth
static int coding_tree_bth(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:1972
SPLIT_BT_HOR
@ SPLIT_BT_HOR
Definition: ctu.h:127
NeighbourAvailable::cand_up_right
int cand_up_right
Definition: hevcdec.h:317
Mv::y
int16_t y
vertical component of motion vector
Definition: hevcdec.h:303
derive_mode_type_condition
static int derive_mode_type_condition(const VVCLocalContext *lc, const VVCSplitMode split, const int cb_width, const int cb_height, const VVCModeType mode_type_curr)
Definition: ctu.c:1900
ff_vvc_cu_affine_type_flag
int ff_vvc_cu_affine_type_flag(VVCLocalContext *lc)
Definition: cabac.c:1509
SAO_EDGE
@ SAO_EDGE
Definition: hevcdec.h:163
TransformUnit::x0
int x0
Definition: ctu.h:173
INTRA_VDIAG
@ INTRA_VDIAG
Definition: ctu.h:236
VVCSH::r
const H266RawSliceHeader * r
RefStruct reference.
Definition: ps.h:239
ff_vvc_mmvd_merge_flag
int ff_vvc_mmvd_merge_flag(VVCLocalContext *lc)
Definition: cabac.c:1392
TransformBlock::min_scan_x
int min_scan_x
Definition: ctu.h:155
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:472
derive_center_luma_intra_pred_mode
static enum IntraPredMode derive_center_luma_intra_pred_mode(const VVCFrameContext *fc, const VVCSPS *sps, const VVCPPS *pps, const CodingUnit *cu)
Definition: ctu.c:865
VVCSplitMode
VVCSplitMode
Definition: ctu.h:124
ff_vvc_ciip_flag
int ff_vvc_ciip_flag(VVCLocalContext *lc)
Definition: cabac.c:1483
CHROMA_FORMAT_422
@ CHROMA_FORMAT_422
Definition: ps.h:54
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
DUAL_TREE
#define DUAL_TREE(x, y)
ff_vvc_intra_luma_mpm_idx
int ff_vvc_intra_luma_mpm_idx(VVCLocalContext *lc)
Definition: cabac.c:1322
mv_merge_refine_pred_flag
static void mv_merge_refine_pred_flag(MvField *mvf, const int width, const int height)
Definition: ctu.c:1320
derive_chroma_intra_pred_mode
static void derive_chroma_intra_pred_mode(VVCLocalContext *lc, const int cclm_mode_flag, const int cclm_mode_idx, const int intra_chroma_pred_mode)
Definition: ctu.c:884
TransformBlock::max_scan_y
int max_scan_y
Definition: ctu.h:154
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
dual_tree_implicit_qt_split
static int dual_tree_implicit_qt_split(VVCLocalContext *lc, const int x0, const int y0, const int cb_size, const int cqt_depth)
Definition: ctu.c:2159
ff_vvc_abs_mvd_greater0_flag
int ff_vvc_abs_mvd_greater0_flag(VVCLocalContext *lc)
Definition: cabac.c:1534
RefPicList
Definition: hevcdec.h:192
alf_params
static void alf_params(VVCLocalContext *lc, const int rx, const int ry)
Definition: ctu.c:2290
ff_vvc_isp_split_type
enum IspType ff_vvc_isp_split_type(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
Definition: cabac.c:1305
VVCLocalContext::ctb_up_right_flag
uint8_t ctb_up_right_flag
Definition: ctu.h:376
ff_vvc_sbt_quad_flag
int ff_vvc_sbt_quad_flag(VVCLocalContext *lc)
Definition: cabac.c:2436
alloc_tu
static TransformUnit * alloc_tu(VVCFrameContext *fc, CodingUnit *cu)
Definition: ctu.c:210
VVCLocalContext::coeffs
int * coeffs
Definition: ctu.h:437
VVCLocalContext::lfnst_zero_out_sig_coeff_flag
int lfnst_zero_out_sig_coeff_flag
LfnstZeroOutSigCoeffFlag.
Definition: ctu.h:405
deblock_params
static void deblock_params(VVCLocalContext *lc, const int rx, const int ry)
Definition: ctu.c:2336
TransformBlock::max_scan_x
int max_scan_x
Definition: ctu.h:153
SPLIT_QT
@ SPLIT_QT
Definition: ctu.h:130
ref_idx_decode
static int8_t ref_idx_decode(VVCLocalContext *lc, const VVCSH *sh, const int sym_mvd_flag, const int lx)
Definition: ctu.c:1545
VVCLocalContext::lfnst_dc_only
int lfnst_dc_only
LfnstDcOnly.
Definition: ctu.h:404
ff_vvc_intra_mip_transposed_flag
int ff_vvc_intra_mip_transposed_flag(VVCLocalContext *lc)
Definition: cabac.c:1276
TRANSFORM_TREE
#define TRANSFORM_TREE(x, y)
ff_vvc_sb_mv_merge_mode
void ff_vvc_sb_mv_merge_mode(VVCLocalContext *lc, const int merge_subblock_idx, PredictionUnit *pu)
Definition: mvs.c:1407
BOUNDARY_LEFT_TILE
#define BOUNDARY_LEFT_TILE
Definition: hevcdec.h:437
H266RawPPS::pps_cu_qp_delta_enabled_flag
uint8_t pps_cu_qp_delta_enabled_flag
Definition: cbs_h266.h:552
pred_mode_decode
static PredMode pred_mode_decode(VVCLocalContext *lc, const VVCTreeType tree_type, const VVCModeType mode_type)
Definition: ctu.c:1040
JCBCR
#define JCBCR
Definition: dec.h:37
ff_vvc_sao_offset_sign_decode
int ff_vvc_sao_offset_sign_decode(VVCLocalContext *lc)
Definition: cabac.c:1010
SPLIT_BT_VER
@ SPLIT_BT_VER
Definition: ctu.h:129
coding_tree_qt
static int coding_tree_qt(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:2059
MIN_PU_LOG2
#define MIN_PU_LOG2
Definition: dec.h:40
CodingUnit::ch_type
int ch_type
Definition: ctu.h:286
H266RawSliceHeader::sh_alf_cc_cr_aps_id
uint8_t sh_alf_cc_cr_aps_id
Definition: cbs_h266.h:792
H266RawSliceHeader::sh_cb_qp_offset
int8_t sh_cb_qp_offset
Definition: cbs_h266.h:808
ff_vvc_intra_mip_mode
int ff_vvc_intra_mip_mode(VVCLocalContext *lc)
Definition: cabac.c:1281
VVCFrameParamSets::sps
const VVCSPS * sps
RefStruct reference.
Definition: ps.h:230
ff_vvc_coding_tree_unit
int ff_vvc_coding_tree_unit(VVCLocalContext *lc, const int ctu_idx, const int rs, const int rx, const int ry)
parse a CTU
Definition: ctu.c:2463
PredictionUnit::gpm_mv
MvField gpm_mv[2]
Definition: ctu.h:265
merge_data_regular
static void merge_data_regular(VVCLocalContext *lc)
Definition: ctu.c:1343
VVCLocalContext::fc
VVCFrameContext * fc
Definition: ctu.h:435
hls_coding_unit
static int hls_coding_unit(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int cqt_depth, const VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:1809
VVCSH::pwt
PredWeightTable pwt
Definition: ps.h:247
PredictionUnit
Definition: hevcdec.h:321
EntryPoint::stat_coeff
int stat_coeff[VVC_MAX_SAMPLE_ARRAYS]
StatCoeff.
Definition: ctu.h:357
MODE_INTER
@ MODE_INTER
Definition: hevcdec.h:104
FFSIGN
#define FFSIGN(a)
Definition: common.h:75
CodingUnit::apply_lfnst_flag
int apply_lfnst_flag[VVC_MAX_SAMPLE_ARRAYS]
ApplyLfnstFlag[].
Definition: ctu.h:320
IS_B
#define IS_B(rsh)
Definition: ps.h:40
derive_dmvr_bdof_flag
static void derive_dmvr_bdof_flag(const VVCLocalContext *lc, PredictionUnit *pu)
Definition: ctu.c:1703
ff_vvc_cu_coded_flag
int ff_vvc_cu_coded_flag(VVCLocalContext *lc)
Definition: cabac.c:2423
tab
static const struct twinvq_data tab
Definition: twinvq_data.h:10345
TransformBlock::c_idx
uint8_t c_idx
Definition: ctu.h:143
SPLIT_TT_VER
@ SPLIT_TT_VER
Definition: ctu.h:128
CodingUnit::sbt_pos_flag
uint8_t sbt_pos_flag
Definition: ctu.h:293
VVCLocalContext::ctb_up_left_flag
uint8_t ctb_up_left_flag
Definition: ctu.h:377
alloc_cu
static CodingUnit * alloc_cu(VVCLocalContext *lc, const int x0, const int y0)
Definition: ctu.c:1179
ctu_get_pred
static void ctu_get_pred(VVCLocalContext *lc, const int rs)
Definition: ctu.c:2438
TransformBlock::x0
int x0
Definition: ctu.h:145
SliceContext::rpl
RefPicList * rpl
Definition: dec.h:113
VVCALF
Definition: ps.h:171
MODE_TYPE_ALL
@ MODE_TYPE_ALL
Definition: ctu.c:36
ff_vvc_mvp_lx_flag
int ff_vvc_mvp_lx_flag(VVCLocalContext *lc)
Definition: cabac.c:1554
H266RawSliceHeader::sh_alf_enabled_flag
uint8_t sh_alf_enabled_flag
Definition: cbs_h266.h:783
refstruct.h
ISP_VER_SPLIT
@ ISP_VER_SPLIT
Definition: ctu.h:121
CodingUnit::cb_width
int cb_width
Definition: ctu.h:284
coding_tree_ttv
static int coding_tree_ttv(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:1999
merge_data_subblock
static void merge_data_subblock(VVCLocalContext *lc)
Definition: ctu.c:1329
ff_vvc_split_cu_flag
int ff_vvc_split_cu_flag(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, const int is_chroma, const VVCAllowedSplit *a)
Definition: cabac.c:1084
H266RawSliceHeader::num_ref_idx_active
uint8_t num_ref_idx_active[2]
NumRefIdxActive[].
Definition: cbs_h266.h:839
merge_data_ciip
static void merge_data_ciip(VVCLocalContext *lc)
Definition: ctu.c:1403
CodingUnit::pu
PredictionUnit pu
Definition: ctu.h:329
ff_vvc_merge_gpm_idx
int ff_vvc_merge_gpm_idx(VVCLocalContext *lc, const int idx)
Definition: cabac.c:1469
H266RawSPS::sps_chroma_format_idc
uint8_t sps_chroma_format_idc
Definition: cbs_h266.h:314
hls_coding_tree
static int hls_coding_tree(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, int part_idx, VVCSplitMode last_split_mode, VVCTreeType tree_type_curr, VVCModeType mode_type_curr)
Definition: ctu.c:2104
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
ff_vvc_store_gpm_mvf
void ff_vvc_store_gpm_mvf(const VVCLocalContext *lc, const PredictionUnit *pu)
Definition: mvs.c:452
MTS_DCT2_DCT2
@ MTS_DCT2_DCT2
Definition: ctu.h:134
add_tb
static TransformBlock * add_tb(TransformUnit *tu, VVCLocalContext *lc, const int x0, const int y0, const int tb_width, const int tb_height, const int c_idx)
Definition: ctu.c:246
RefPicList::refs
VVCRefPic refs[VVC_MAX_REF_ENTRIES]
Definition: dec.h:56
mode_type_decode
static VVCModeType mode_type_decode(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, const VVCSplitMode split, const int ch_type, const VVCModeType mode_type_curr)
Definition: ctu.c:1922
ff_vvc_tu_y_coded_flag
int ff_vvc_tu_y_coded_flag(VVCLocalContext *lc)
Definition: cabac.c:1619
ff_vvc_store_mv
void ff_vvc_store_mv(const VVCLocalContext *lc, const MotionInfo *mi)
Definition: mvs.c:503
TransformUnit::avail
bool avail[CHROMA+1]
Definition: ctu.h:177
CHROMA_FORMAT_444
@ CHROMA_FORMAT_444
Definition: ps.h:55
SAO_NOT_APPLIED
@ SAO_NOT_APPLIED
Definition: hevcdec.h:161
ISP_HOR_SPLIT
@ ISP_HOR_SPLIT
Definition: ctu.h:120
coding_tree_tth
static int coding_tree_tth(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:2029
bcw_idx_decode
static int bcw_idx_decode(VVCLocalContext *lc, const MotionInfo *mi, const int cb_width, const int cb_height)
Definition: ctu.c:1524
AV_ZERO64
#define AV_ZERO64(d)
Definition: intreadwrite.h:666
mi
#define mi
Definition: vf_colormatrix.c:106
TransformBlock::y0
int y0
Definition: ctu.h:146
TransformUnit::next
struct TransformUnit * next
RefStruct reference.
Definition: ctu.h:185
set_cu_tabs
static void set_cu_tabs(const VVCLocalContext *lc, const CodingUnit *cu)
Definition: ctu.c:1239
merge_data_ibc
static int merge_data_ibc(VVCLocalContext *lc)
Definition: ctu.c:1454
CodingUnit::cqt_depth
int cqt_depth
Definition: ctu.h:287
VVCSH
Definition: ps.h:238
mvp_add_difference
static void mvp_add_difference(MotionInfo *mi, const int num_cp_mv, const Mv mvds[2][MAX_CONTROL_POINTS], const int amvr_shift)
Definition: ctu.c:1589
ff_vvc_bcw_idx
int ff_vvc_bcw_idx(VVCLocalContext *lc, const int no_backward_pred_flag)
Definition: cabac.c:1598
PredWeightTable
Definition: ps.h:137
CodingUnit::tree_type
VVCTreeType tree_type
Definition: ctu.h:281
VVCFrameParamSets::ph
VVCPH ph
Definition: ps.h:232
PredictionUnit::bdof_flag
uint8_t bdof_flag
Definition: ctu.h:273
ff_vvc_sbt_pos_flag
int ff_vvc_sbt_pos_flag(VVCLocalContext *lc)
Definition: cabac.c:2449
CodingUnit::mts_idx
MtsIdx mts_idx
Definition: ctu.h:296
ff_vvc_intra_luma_not_planar_flag
int ff_vvc_intra_luma_not_planar_flag(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
Definition: cabac.c:1317
TransformUnit::coded_flag
uint8_t coded_flag[VVC_MAX_SAMPLE_ARRAYS]
tu_y_coded_flag, tu_cb_coded_flag, tu_cr_coded_flag
Definition: ctu.h:181
NeighbourAvailable::cand_up_right_sap
int cand_up_right_sap
Definition: hevcdec.h:318
ff_vvc_cu_skip_flag
int ff_vvc_cu_skip_flag(VVCLocalContext *lc, const uint8_t *cu_skip_flag)
Definition: cabac.c:1242
hls_merge_data
static int hls_merge_data(VVCLocalContext *lc)
Definition: ctu.c:1475
set_qp_y
static int set_qp_y(VVCLocalContext *lc, const int x0, const int y0, const int has_qp_delta)
Definition: ctu.c:140
ciip_flag_decode
static int ciip_flag_decode(VVCLocalContext *lc, const int ciip_avaiable, const int gpm_avaiable, const int is_128)
Definition: ctu.c:1373
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
H266RawSliceHeader::sh_cu_chroma_qp_offset_enabled_flag
uint8_t sh_cu_chroma_qp_offset_enabled_flag
Definition: cbs_h266.h:811
H266RawSPS
Definition: cbs_h266.h:308
CTU
Definition: ctu.h:334
hls_transform_unit
static int hls_transform_unit(VVCLocalContext *lc, int x0, int y0, int tu_width, int tu_height, int sub_tu_index, int ch_type)
Definition: ctu.c:312
aps
static int FUNC() aps(CodedBitstreamContext *ctx, RWContext *rw, H266RawAPS *current, int prefix)
Definition: cbs_h266_syntax_template.c:2501
EntryPoint::is_first_qg
uint8_t is_first_qg
Definition: ctu.h:365
VVCSPS::ctb_log2_size_y
uint8_t ctb_log2_size_y
CtbLog2SizeY.
Definition: ps.h:71
CodingUnit::sbt_flag
uint8_t sbt_flag
Definition: ctu.h:291
inter.h
VVCTreeType
VVCTreeType
Definition: ctu.h:166
IspType
IspType
Definition: ctu.h:118
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
SAOParams::offset_abs
int offset_abs[3][4]
sao_offset_abs
Definition: dsp.h:35
ff_vvc_mvp
void ff_vvc_mvp(VVCLocalContext *lc, const int *mvp_lx_flag, const int amvr_shift, MotionInfo *mi)
Definition: mvs.c:1597
VVC_MAX_SAMPLE_ARRAYS
@ VVC_MAX_SAMPLE_ARRAYS
Definition: vvc.h:77
ff_vvc_pred_mode_plt_flag
int ff_vvc_pred_mode_plt_flag(VVCLocalContext *lc)
Definition: cabac.c:1217
VVCLocalContext
Definition: ctu.h:373
VVCSH::ref_idx_sym
int8_t ref_idx_sym[2]
RefIdxSymL0, RefIdxSymL1.
Definition: ps.h:248
H266RawSliceHeader::curr_subpic_idx
uint16_t curr_subpic_idx
CurrSubpicIdx.
Definition: cbs_h266.h:837
CodingUnit::tus
struct CodingUnit::@285 tus
INTRA_HORZ
@ INTRA_HORZ
Definition: ctu.h:233
VVCSH::max_tt_size
uint8_t max_tt_size[2]
MaxTtSizeY, MaxTtSizeC.
Definition: ps.h:259
EntryPoint::qp_y
int8_t qp_y
QpY.
Definition: ctu.h:355
ff_vvc_cu_chroma_qp_offset_flag
int ff_vvc_cu_chroma_qp_offset_flag(VVCLocalContext *lc)
Definition: cabac.c:1666
TransformBlock::log2_tb_width
int log2_tb_width
Definition: ctu.h:150
CodingUnit::intra_luma_ref_idx
uint8_t intra_luma_ref_idx
IntraLumaRefLineIdx[][].
Definition: ctu.h:300
mvp_data_ibc
static int mvp_data_ibc(VVCLocalContext *lc)
Definition: ctu.c:1604
L0
#define L0
Definition: hevcdec.h:58
ff_vvc_sbt_horizontal_flag
int ff_vvc_sbt_horizontal_flag(VVCLocalContext *lc)
Definition: cabac.c:2441
ff_vvc_alf_ctb_filter_alt_idx
int ff_vvc_alf_ctb_filter_alt_idx(VVCLocalContext *lc, const int c_idx, const int num_chroma_filters)
Definition: cabac.c:1052
av_refstruct_pool_get
void * av_refstruct_pool_get(AVRefStructPool *pool)
Get an object from the pool, reusing an old one from the pool when available.
Definition: refstruct.c:297
hls_coding_tree_unit
static int hls_coding_tree_unit(VVCLocalContext *lc, const int x0, const int y0, const int ctu_idx, const int rx, const int ry)
Definition: ctu.c:2343
BOUNDARY_UPPER_TILE
#define BOUNDARY_UPPER_TILE
Definition: hevcdec.h:439
MODE_TYPE_INTRA
@ MODE_TYPE_INTRA
Definition: ctu.c:38
H266RawSliceHeader::sh_joint_cbcr_qp_offset
int8_t sh_joint_cbcr_qp_offset
Definition: cbs_h266.h:810
skipped_transform_tree_unit
static int skipped_transform_tree_unit(VVCLocalContext *lc)
Definition: ctu.c:1137
SPLIT_NONE
@ SPLIT_NONE
Definition: mss12.c:37
VVCRefPic::is_scaled
int is_scaled
RprConstraintsActiveFlag.
Definition: dec.h:51
SPLIT_TT_HOR
@ SPLIT_TT_HOR
Definition: ctu.h:126
MotionInfo::motion_model_idc
MotionModelIdc motion_model_idc
MotionModelIdc.
Definition: ctu.h:243
Mv::x
int16_t x
horizontal component of motion vector
Definition: hevcdec.h:302
CTB
#define CTB(tab, x, y)
Definition: filter.c:267
VVCRefPic::is_lt
int is_lt
Definition: dec.h:48
ff_vvc_alf_use_aps_flag
int ff_vvc_alf_use_aps_flag(VVCLocalContext *lc)
Definition: cabac.c:1037
PF_BI
@ PF_BI
Definition: hevcdec.h:119
MotionInfo::num_sb_y
int num_sb_y
Definition: ctu.h:251
ff_vvc_abs_mvd_minus2
int ff_vvc_abs_mvd_minus2(VVCLocalContext *lc)
Definition: cabac.c:1544
ff_vvc_tu_joint_cbcr_residual_flag
int ff_vvc_tu_joint_cbcr_residual_flag(VVCLocalContext *lc, const int tu_cb_coded_flag, const int tu_cr_coded_flag)
Definition: cabac.c:1725
SAMPLE_CTB
#define SAMPLE_CTB(tab, x, y)
Definition: hevcdec.h:74
ff_vvc_alf_luma_prev_filter_idx
int ff_vvc_alf_luma_prev_filter_idx(VVCLocalContext *lc)
Definition: cabac.c:1042
cabac.h
TransformUnit
Definition: hevcdec.h:331
ff_vvc_pred_mode_ibc_flag
int ff_vvc_pred_mode_ibc_flag(VVCLocalContext *lc, const int is_chroma)
Definition: cabac.c:1248
DUAL_TREE_LUMA
@ DUAL_TREE_LUMA
Definition: ctu.h:168
SliceContext
Definition: mss12.h:70
SAOParams::offset_val
int16_t offset_val[3][5]
SaoOffsetVal.
Definition: dsp.h:42
VVCFrameParamSets::pps
const VVCPPS * pps
RefStruct reference.
Definition: ps.h:231
PredictionUnit::mmvd_merge_flag
uint8_t mmvd_merge_flag
Definition: ctu.h:256
ff_vvc_luma_mv_merge_mode
void ff_vvc_luma_mv_merge_mode(VVCLocalContext *lc, const int merge_idx, const int ciip_flag, MvField *mv)
Definition: mvs.c:812
CHROMA_FORMAT_420
@ CHROMA_FORMAT_420
Definition: ps.h:53
VVCSH::max_mtt_depth
uint8_t max_mtt_depth[2]
MaxMttDepthY, MaxMttDepthC.
Definition: ps.h:260
ff_vvc_decode_neighbour
void ff_vvc_decode_neighbour(VVCLocalContext *lc, const int x_ctb, const int y_ctb, const int rx, const int ry, const int rs)
Definition: ctu.c:2494
TransformBlock::tb_height
int tb_height
Definition: ctu.h:149
ff_vvc_intra_luma_mpm_remainder
int ff_vvc_intra_luma_mpm_remainder(VVCLocalContext *lc)
Definition: cabac.c:1330
EntryPoint::num_hmvp_ibc
int num_hmvp_ibc
NumHmvpIbcCand.
Definition: ctu.h:370
TransformBlock::ts
uint8_t ts
transform_skip_flag
Definition: ctu.h:144
ff_vvc_intra_bdpcm_chroma_dir_flag
int ff_vvc_intra_bdpcm_chroma_dir_flag(VVCLocalContext *lc)
Definition: cabac.c:1237
mvs.h
BOUNDARY_UPPER_SLICE
#define BOUNDARY_UPPER_SLICE
Definition: hevcdec.h:438
mvf_to_mi
static void mvf_to_mi(const MvField *mvf, MotionInfo *mi)
Definition: ctu.c:1306
CodingUnit::intra_pred_mode_y
IntraPredMode intra_pred_mode_y
IntraPredModeY.
Definition: ctu.h:314
ff_vvc_pred_flag
PredFlag ff_vvc_pred_flag(VVCLocalContext *lc, const int is_b)
Definition: cabac.c:1488
height
#define height
Definition: dsp.h:85
INTRA_PLANAR
@ INTRA_PLANAR
Definition: hevcdec.h:123
coding_tree
const static coding_tree_fn coding_tree[]
Definition: ctu.c:2096
refine_regular_subblock
static void refine_regular_subblock(const VVCLocalContext *lc)
Definition: ctu.c:1742
ff_vvc_merge_subblock_idx
int ff_vvc_merge_subblock_idx(VVCLocalContext *lc, const int max_num_subblock_merge_cand)
Definition: cabac.c:1376
PredictionUnit::merge_gpm_flag
uint8_t merge_gpm_flag
Definition: ctu.h:263
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
VVCRefPic::poc
int poc
Definition: dec.h:47
CodingUnit::sbt_horizontal_flag
uint8_t sbt_horizontal_flag
Definition: ctu.h:292
ff_vvc_merge_gpm_partition_idx
int ff_vvc_merge_gpm_partition_idx(VVCLocalContext *lc)
Definition: cabac.c:1459
H266RawSliceHeader::sh_alf_aps_id_chroma
uint8_t sh_alf_aps_id_chroma
Definition: cbs_h266.h:788
VVCLocalContext::infer_tu_cbf_luma
int infer_tu_cbf_luma
InferTuCbfLuma.
Definition: ctu.h:401
MvField
Definition: hevcdec.h:306
VVCLocalContext::end_of_tiles_x
int end_of_tiles_x
Definition: ctu.h:378
INTRA_INVALID
@ INTRA_INVALID
Definition: ctu.h:230
ff_vvc_luma_mv_merge_gpm
void ff_vvc_luma_mv_merge_gpm(VVCLocalContext *lc, const int merge_gpm_idx[2], MvField *mv)
Definition: mvs.c:825
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:166
ff_vvc_sym_mvd_flag
int ff_vvc_sym_mvd_flag(VVCLocalContext *lc)
Definition: cabac.c:1514
CodingUnit::coded_flag
uint8_t coded_flag
Definition: ctu.h:289
split
static char * split(char *message, char delim)
Definition: af_channelmap.c:89
VVCLocalContext::ctb_up_flag
uint8_t ctb_up_flag
Definition: ctu.h:375
ff_vvc_end_of_tile_one_bit
int ff_vvc_end_of_tile_one_bit(VVCLocalContext *lc)
Definition: cabac.c:2478
VVCFrameContext::tab
struct VVCFrameContext::@288 tab
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
ff_vvc_intra_subpartitions_mode_flag
int ff_vvc_intra_subpartitions_mode_flag(VVCLocalContext *lc)
Definition: cabac.c:1300
CTU::has_dmvr
int has_dmvr
Definition: ctu.h:337
CodingUnit::lfnst_idx
int lfnst_idx
Definition: ctu.h:295
VVCSH::deblock
DBParams deblock
Definition: ps.h:254
MAX_CONTROL_POINTS
#define MAX_CONTROL_POINTS
Definition: ctu.h:66
H266RawSliceHeader::sh_cr_qp_offset
int8_t sh_cr_qp_offset
Definition: cbs_h266.h:809
H266RawSliceHeader::sh_alf_cb_enabled_flag
uint8_t sh_alf_cb_enabled_flag
Definition: cbs_h266.h:786
coding_tree_btv
static int coding_tree_btv(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:1945
av_zero_extend
#define av_zero_extend
Definition: common.h:151
VVCLocalContext::na
NeighbourAvailable na
Definition: ctu.h:422
CodingUnit::intra_pred_mode_c
IntraPredMode intra_pred_mode_c
IntraPredModeC.
Definition: ctu.h:315
ff_vvc_sao_band_position_decode
int ff_vvc_sao_band_position_decode(VVCLocalContext *lc)
Definition: cabac.c:991
MODE_TYPE_INTER
@ MODE_TYPE_INTER
Definition: ctu.c:37
MvField::pred_flag
int8_t pred_flag
Definition: hevcdec.h:309
MvField::hpel_if_idx
uint8_t hpel_if_idx
hpelIfIdx
Definition: ctu.h:204
SAOParams::eo_class
int eo_class[3]
sao_eo_class
Definition: dsp.h:40
ff_vvc_merge_idx
int ff_vvc_merge_idx(VVCLocalContext *lc)
Definition: cabac.c:1444
ff_vvc_merge_subblock_flag
int ff_vvc_merge_subblock_flag(VVCLocalContext *lc)
Definition: cabac.c:1370
ALFParams::ctb_cc_idc
uint8_t ctb_cc_idc[2]
alf_ctb_cc_cb_idc, alf_ctb_cc_cr_idc
Definition: ctu.h:465
av_refstruct_unref
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
ff_vvc_split_mode
VVCSplitMode ff_vvc_split_mode(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, const int cqt_depth, const int mtt_depth, const int ch_type, const VVCAllowedSplit *a)
Definition: cabac.c:1162
CTU::max_y
int max_y[2][VVC_MAX_REF_ENTRIES]
Definition: ctu.h:335
H266RawSliceHeader
Definition: cbs_h266.h:771
get_cclm_enabled
static int get_cclm_enabled(const VVCLocalContext *lc, const int x0, const int y0)
Definition: ctu.c:631
VVC_MAX_REF_ENTRIES
@ VVC_MAX_REF_ENTRIES
Definition: vvc.h:115
set_cb_tab
static void set_cb_tab(const VVCLocalContext *lc, uint8_t *tab, const uint8_t v)
Definition: ctu.c:120
VVCLocalContext::boundary_flags
int boundary_flags
Definition: ctu.h:432
PredictionUnit::mi
MotionInfo mi
Definition: ctu.h:269
MODE_INTRA
#define MODE_INTRA
Definition: vp3.c:84
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:67
CR
#define CR
Definition: filter.c:33
tu_y_coded_flag_decode
static uint8_t tu_y_coded_flag_decode(VVCLocalContext *lc, const int is_sbt_not_coded, const int sub_tu_index, const int is_isp, const int is_chroma_coded)
Definition: ctu.c:271
VVCAllowedSplit
Definition: ctu.h:440
BOUNDARY_LEFT_SUBPIC
#define BOUNDARY_LEFT_SUBPIC
Definition: ctu.h:426
MODE_PLT
@ MODE_PLT
Definition: ctu.h:192
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ISP_NO_SPLIT
@ ISP_NO_SPLIT
Definition: ctu.h:119
modes
const struct mode modes[]
Definition: swscale.c:57
luma_intra_pred_mode
static enum IntraPredMode luma_intra_pred_mode(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
Definition: ctu.c:682
pack_mip_info
static av_always_inline uint8_t pack_mip_info(int intra_mip_flag, int intra_mip_transposed_flag, int intra_mip_mode)
Definition: ctu.c:949
NeighbourAvailable::cand_up_left
int cand_up_left
Definition: hevcdec.h:316
ff_vvc_alf_ctb_flag
int ff_vvc_alf_ctb_flag(VVCLocalContext *lc, const int rx, const int ry, const int c_idx)
Definition: cabac.c:1022
ff_vvc_abs_mvd_greater1_flag
int ff_vvc_abs_mvd_greater1_flag(VVCLocalContext *lc)
Definition: cabac.c:1539
ff_vvc_transform_skip_flag
int ff_vvc_transform_skip_flag(VVCLocalContext *lc, const int inc)
Definition: cabac.c:1730
derive_mmvd
static void derive_mmvd(const VVCLocalContext *lc, MvField *mvf, const Mv *mmvd_offset)
Definition: ctu.c:1265
av_always_inline
#define av_always_inline
Definition: attributes.h:49
pred_get_y
static int pred_get_y(const int y0, const Mv *mv, const int height)
Definition: ctu.c:2396
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_vvc_tu_cb_coded_flag
int ff_vvc_tu_cb_coded_flag(VVCLocalContext *lc)
Definition: cabac.c:1609
PF_L0
@ PF_L0
Definition: hevcdec.h:117
VVCLocalContext::prev_tu_cbf_y
int prev_tu_cbf_y
prevTuCbfY;
Definition: ctu.h:402
VVCLocalContext::cu_qg_top_left_x
int cu_qg_top_left_x
CuQgTopLeftX.
Definition: ctu.h:396
get_num_intra_subpartitions
static int get_num_intra_subpartitions(enum IspType isp_split_type, int cb_width, int cb_height)
Definition: ctu.c:622
CodingUnit::x0
int x0
Definition: ctu.h:282
TransformUnit::tbs
TransformBlock tbs[VVC_MAX_SAMPLE_ARRAYS]
Definition: ctu.h:183
H266RawSliceHeader::sh_sao_chroma_used_flag
uint8_t sh_sao_chroma_used_flag
Definition: cbs_h266.h:814
VVCPH::poc
int32_t poc
PicOrderCntVal.
Definition: ps.h:153
EntryPoint
Definition: ctu.h:354
TransformBlock::coeffs
int * coeffs
Definition: ctu.h:163
ff_vvc_store_sb_mvs
void ff_vvc_store_sb_mvs(const VVCLocalContext *lc, PredictionUnit *pu)
Definition: mvs.c:407
ff_vvc_end_of_subset_one_bit
int ff_vvc_end_of_subset_one_bit(VVCLocalContext *lc)
Definition: cabac.c:2483
set_qp_c
static void set_qp_c(VVCLocalContext *lc)
Definition: ctu.c:183
H266RawSliceHeader::sh_alf_cc_cb_aps_id
uint8_t sh_alf_cc_cb_aps_id
Definition: cbs_h266.h:790
ff_vvc_no_backward_pred_flag
int ff_vvc_no_backward_pred_flag(const VVCLocalContext *lc)
Definition: mvs.c:121
TransformUnit::width
int width
Definition: ctu.h:175
hls_sao
static void hls_sao(VVCLocalContext *lc, const int rx, const int ry)
Definition: ctu.c:2221
SAOParams
Definition: dsp.h:34
chroma_qp_offset_decode
static void chroma_qp_offset_decode(VVCLocalContext *lc, const int is_128, const int is_chroma_coded)
Definition: ctu.c:291
VVCLocalContext::cu
CodingUnit * cu
Definition: ctu.h:418
ff_vvc_sbt_flag
int ff_vvc_sbt_flag(VVCLocalContext *lc)
Definition: cabac.c:2428
ff_vvc_get_qPy
int ff_vvc_get_qPy(const VVCFrameContext *fc, const int xc, const int yc)
Definition: ctu.c:2561
ff_vvc_cu_qp_delta_abs
int ff_vvc_cu_qp_delta_abs(VVCLocalContext *lc)
Definition: cabac.c:1633
INTRA_VERT
@ INTRA_VERT
Definition: ctu.h:235
BOUNDARY_UPPER_SUBPIC
#define BOUNDARY_UPPER_SUBPIC
Definition: ctu.h:429
PredictionUnit::dmvr_flag
uint8_t dmvr_flag
Definition: ctu.h:272
hls_transform_tree
static int hls_transform_tree(VVCLocalContext *lc, int x0, int y0, int tu_width, int tu_height, int ch_type)
Definition: ctu.c:404
ret
ret
Definition: filter_design.txt:187
VVCLocalContext::chroma_qp_offset
int chroma_qp_offset[3]
CuQpOffsetCb, CuQpOffsetCr, CuQpOffsetCbCr.
Definition: ctu.h:399
pred
static const float pred[4]
Definition: siprdata.h:259
ff_vvc_pred_mode_flag
int ff_vvc_pred_mode_flag(VVCLocalContext *lc, const int is_chroma)
Definition: cabac.c:1206
IntraPredMode
IntraPredMode
Definition: hevcdec.h:122
ff_vvc_alf_luma_fixed_filter_idx
int ff_vvc_alf_luma_fixed_filter_idx(VVCLocalContext *lc)
Definition: cabac.c:1047
hls_mvd_coding
static void hls_mvd_coding(VVCLocalContext *lc, Mv *mvd)
Definition: ctu.c:1500
VVCLocalContext::sbt_num_fourths_tb0
int sbt_num_fourths_tb0
SbtNumFourthsTb0.
Definition: ctu.h:393
CHROMA
@ CHROMA
Definition: vf_waveform.c:49
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
ff_vvc_mvd_sign_flag
int ff_vvc_mvd_sign_flag(VVCLocalContext *lc)
Definition: cabac.c:1549
ff_vvc_mvp_ibc
int ff_vvc_mvp_ibc(VVCLocalContext *lc, const int mvp_l0_flag, const int amvr_shift, Mv *mv)
Definition: mvs.c:1718
H266RawSliceHeader::sh_alf_cc_cb_enabled_flag
uint8_t sh_alf_cc_cb_enabled_flag
Definition: cbs_h266.h:789
ALFParams::alf_ctb_filter_alt_idx
uint8_t alf_ctb_filter_alt_idx[2]
alf_ctb_filter_alt_idx[]
Definition: ctu.h:464
PredictionUnit::inter_affine_flag
uint8_t inter_affine_flag
Definition: ctu.h:258
ff_vvc_get_mvf
MvField * ff_vvc_get_mvf(const VVCFrameContext *fc, const int x0, const int y0)
Definition: mvs.c:1943
SKIPPED_TRANSFORM_TREE
#define SKIPPED_TRANSFORM_TREE(x, y)
CodingUnit::cb_height
int cb_height
Definition: ctu.h:285
ff_vvc_cu_qp_delta_sign_flag
int ff_vvc_cu_qp_delta_sign_flag(VVCLocalContext *lc)
Definition: cabac.c:1661
VVCLocalContext::parse
struct VVCLocalContext::@286 parse
TransformBlock::log2_tb_height
int log2_tb_height
Definition: ctu.h:151
CodingUnit::tail
TransformUnit * tail
RefStruct reference.
Definition: ctu.h:324
ff_vvc_set_neighbour_available
void ff_vvc_set_neighbour_available(VVCLocalContext *lc, const int x0, const int y0, const int w, const int h)
Definition: ctu.c:2527
inter_data
static int inter_data(VVCLocalContext *lc)
Definition: ctu.c:1775
cu_get_max_y
static void cu_get_max_y(const CodingUnit *cu, int max_y[2][VVC_MAX_REF_ENTRIES], const VVCFrameContext *fc)
Definition: ctu.c:2401
DUAL_TREE_CHROMA
@ DUAL_TREE_CHROMA
Definition: ctu.h:169
can_split
static void can_split(const VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int mtt_depth, int depth_offset, int part_idx, VVCSplitMode last_split_mode, VVCTreeType tree_type, VVCModeType mode_type, VVCAllowedSplit *split)
Definition: ctu.c:523
TransformBlock::has_coeffs
uint8_t has_coeffs
Definition: ctu.h:142
PredMode
PredMode
Definition: hevcdec.h:103
MotionInfo::num_sb_x
int num_sb_x
Definition: ctu.h:251
PredictionUnit::sym_mvd_flag
int sym_mvd_flag
Definition: ctu.h:267
ff_vvc_cclm_mode_idx
int ff_vvc_cclm_mode_idx(VVCLocalContext *lc)
Definition: cabac.c:1340
ff_vvc_luma_mv_merge_ibc
int ff_vvc_luma_mv_merge_ibc(VVCLocalContext *lc, const int merge_idx, Mv *mv)
Definition: mvs.c:1727
fill_dmvr_info
static void fill_dmvr_info(const VVCLocalContext *lc)
Definition: ctu.c:1754
TransformBlock
Definition: ctu.h:141
intra_luma_pred_modes
static void intra_luma_pred_modes(VVCLocalContext *lc)
Definition: ctu.c:955
TAB_MSM
#define TAB_MSM(fc, depth, x, y)
Definition: ctu.c:32
VVCSH::slice_qp_y
int8_t slice_qp_y
SliceQpY.
Definition: ps.h:251
CodingUnit::pred_mode
enum PredMode pred_mode
PredMode.
Definition: hevcdec.h:292
ff_vvc_sao_type_idx_decode
int ff_vvc_sao_type_idx_decode(VVCLocalContext *lc)
Definition: cabac.c:981
ALFParams::ctb_filt_set_idx_y
uint8_t ctb_filt_set_idx_y
AlfCtbFiltSetIdxY.
Definition: ctu.h:463
ff_vvc_cabac_init
int ff_vvc_cabac_init(VVCLocalContext *lc, const int ctu_idx, const int rx, const int ry)
Definition: cabac.c:842
MIN_TU_SIZE
#define MIN_TU_SIZE
Definition: ctu.h:45
pps
uint64_t pps
Definition: dovi_rpuenc.c:35
SAOParams::type_idx
uint8_t type_idx[3]
sao_type_idx
Definition: dsp.h:44
mvp_data
static int mvp_data(VVCLocalContext *lc)
Definition: ctu.c:1634
EntryPoint::num_hmvp
int num_hmvp
NumHmvpCand.
Definition: ctu.h:368
get_qp_y_pred
static int get_qp_y_pred(const VVCLocalContext *lc)
Definition: ctu.c:73
PredictionUnit::general_merge_flag
uint8_t general_merge_flag
Definition: ctu.h:255
VVCLocalContext::end_of_tiles_y
int end_of_tiles_y
Definition: ctu.h:379
sbt_info
static void sbt_info(VVCLocalContext *lc, const VVCSPS *sps)
Definition: ctu.c:1098
MAX_QP
#define MAX_QP
Definition: hevcdec.h:50
TransformUnit::y0
int y0
Definition: ctu.h:174
VVCFrameContext::qp
int8_t * qp[VVC_MAX_SAMPLE_ARRAYS]
Definition: dec.h:159
CodingUnit::next
struct CodingUnit * next
RefStruct reference.
Definition: ctu.h:331
MvField::mv
Mv mv[2]
mvL0, vvL1
Definition: hevcdec.h:307
ALFParams
Definition: ctu.h:461
ff_vvc_sao_merge_flag_decode
int ff_vvc_sao_merge_flag_decode(VVCLocalContext *lc)
Definition: cabac.c:976
Mv
Definition: hevcdec.h:301
merge_data_block
static void merge_data_block(VVCLocalContext *lc)
Definition: ctu.c:1424
MvField::ref_idx
int8_t ref_idx[2]
refIdxL0, refIdxL1
Definition: hevcdec.h:308
set_tb_tab
static void set_tb_tab(uint8_t *tab, uint8_t v, const VVCFrameContext *fc, const TransformBlock *tb)
Definition: ctu.c:58
set_tb_size
static void set_tb_size(const VVCFrameContext *fc, const TransformBlock *tb)
Definition: ctu.c:41
lfnst_idx_decode
static int lfnst_idx_decode(VVCLocalContext *lc)
Definition: ctu.c:793
ff_vvc_mts_idx
int ff_vvc_mts_idx(VVCLocalContext *lc)
Definition: cabac.c:2463
ff_vvc_general_merge_flag
int ff_vvc_general_merge_flag(VVCLocalContext *lc)
Definition: cabac.c:1354
VVCFrameContext::ps
VVCFrameParamSets ps
Definition: dec.h:126
VVCSH::max_bt_size
uint8_t max_bt_size[2]
MaxBtSizeY, MaxBtSizeC.
Definition: ps.h:258
TAB_ISPMF
#define TAB_ISPMF(fc, x, y)
Definition: ctu.c:33
SINGLE_TREE
@ SINGLE_TREE
Definition: ctu.h:167
ff_vvc_intra_chroma_pred_mode
int ff_vvc_intra_chroma_pred_mode(VVCLocalContext *lc)
Definition: cabac.c:1347
VVCSPS::r
const H266RawSPS * r
RefStruct reference.
Definition: ps.h:59
PredFlag
PredFlag
Definition: hevcdec.h:115
H266RawSliceHeader::sh_num_alf_aps_ids_luma
uint8_t sh_num_alf_aps_ids_luma
Definition: cbs_h266.h:784
SliceContext::sh
VVCSH sh
Definition: dec.h:110
ff_vvc_tu_cr_coded_flag
int ff_vvc_tu_cr_coded_flag(VVCLocalContext *lc, int tu_cb_coded_flag)
Definition: cabac.c:1614
ff_vvc_alf_ctb_cc_idc
int ff_vvc_alf_ctb_cc_idc(VVCLocalContext *lc, const int rx, const int ry, const int idx, const int cc_filters_signalled)
Definition: cabac.c:1062
CodingUnit::isp_split_type
enum IspType isp_split_type
IntraSubPartitionsSplitType.
Definition: ctu.h:308
VVCFrameContext
Definition: dec.h:117
coding_tree_fn
int(* coding_tree_fn)(VVCLocalContext *lc, int x0, int y0, int cb_width, int cb_height, int qg_on_y, int qg_on_c, int cb_sub_div, int cqt_depth, int mtt_depth, int depth_offset, VVCTreeType tree_type, VVCModeType mode_type)
Definition: ctu.c:2091
ff_vvc_intra_luma_mpm_flag
int ff_vvc_intra_luma_mpm_flag(VVCLocalContext *lc)
Definition: cabac.c:1312
CodingUnit::mip_chroma_direct_flag
int mip_chroma_direct_flag
MipChromaDirectFlag.
Definition: ctu.h:316
ALFParams::ctb_flag
uint8_t ctb_flag[3]
alf_ctb_flag[]
Definition: ctu.h:462
MvField::bcw_idx
uint8_t bcw_idx
bcwIdx
Definition: ctu.h:205
ff_vvc_sao_offset_abs_decode
int ff_vvc_sao_offset_abs_decode(VVCLocalContext *lc)
Definition: cabac.c:1000
int32_t
int32_t
Definition: audioconvert.c:56
CodingUnit::skip_flag
uint8_t skip_flag
cu_skip_flag;
Definition: ctu.h:302
IS_I
#define IS_I(rsh)
Definition: ps.h:38
ff_vvc_mmvd_cand_flag
int ff_vvc_mmvd_cand_flag(VVCLocalContext *lc)
Definition: cabac.c:1397
ff_vvc_store_mvf
void ff_vvc_store_mvf(const VVCLocalContext *lc, const MvField *mvf)
Definition: mvs.c:497
SET_SAO
#define SET_SAO(elem, value)
Definition: ctu.c:2209
VVCSH::min_qt_size
uint8_t min_qt_size[2]
MinQtSizeY, MinQtSizeC.
Definition: ps.h:257
mvds_decode
static int mvds_decode(VVCLocalContext *lc, Mv mvds[2][MAX_CONTROL_POINTS], const int num_cp_mv, const int lx)
Definition: ctu.c:1557
ff_vvc_amvr_shift
int ff_vvc_amvr_shift(VVCLocalContext *lc, const int inter_affine_flag, const PredMode pred_mode, const int has_amvr_flag)
Definition: cabac.c:1575
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
TransformUnit::joint_cbcr_residual_flag
uint8_t joint_cbcr_residual_flag
tu_joint_cbcr_residual_flag
Definition: ctu.h:179
ff_vvc_intra_bdpcm_luma_dir_flag
int ff_vvc_intra_bdpcm_luma_dir_flag(VVCLocalContext *lc)
Definition: cabac.c:1227
ff_vvc_intra_bdpcm_luma_flag
int ff_vvc_intra_bdpcm_luma_flag(VVCLocalContext *lc)
Definition: cabac.c:1222
h
h
Definition: vp9dsp_template.c:2070
ctu.h
BOUNDARY_LEFT_SLICE
#define BOUNDARY_LEFT_SLICE
Definition: hevcdec.h:436
VVCLocalContext::ep
EntryPoint * ep
Definition: ctu.h:436
width
#define width
Definition: dsp.h:85
set_qp_c_tab
static void set_qp_c_tab(const VVCLocalContext *lc, const TransformUnit *tu, const TransformBlock *tb)
Definition: ctu.c:175
VVCLocalContext::cu_qg_top_left_y
int cu_qg_top_left_y
CuQgTopLeftY.
Definition: ctu.h:397
ff_vvc_ep_init_stat_coeff
void ff_vvc_ep_init_stat_coeff(EntryPoint *ep, const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
Definition: ctu.c:2569
INTRA_LT_CCLM
@ INTRA_LT_CCLM
Definition: ctu.h:237
H266RawSliceHeader::sh_alf_cr_enabled_flag
uint8_t sh_alf_cr_enabled_flag
Definition: cbs_h266.h:787
CodingUnit::ciip_flag
uint8_t ciip_flag
Definition: ctu.h:305
ff_vvc_non_inter_flag
int ff_vvc_non_inter_flag(VVCLocalContext *lc, const int x0, const int y0, const int ch_type)
Definition: cabac.c:1196
ff_vvc_cclm_mode_flag
int ff_vvc_cclm_mode_flag(VVCLocalContext *lc)
Definition: cabac.c:1335
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
PredictionUnit::merge_subblock_flag
uint8_t merge_subblock_flag
Definition: ctu.h:261
has_inter_luma
static int has_inter_luma(const CodingUnit *cu)
Definition: ctu.c:2391
CodingUnit::num_intra_subpartitions
int num_intra_subpartitions
Definition: ctu.h:312
ff_vvc_set_intra_mvf
void ff_vvc_set_intra_mvf(const VVCLocalContext *lc, const int dmvr)
Definition: mvs.c:269
VVCLocalContext::ctb_left_flag
uint8_t ctb_left_flag
Definition: ctu.h:374
ff_vvc_mv_scale
void ff_vvc_mv_scale(Mv *dst, const Mv *src, int td, int tb)
Definition: mvs.c:71
MtsIdx
MtsIdx
Definition: ctu.h:133
MIN_TU_LOG2
#define MIN_TU_LOG2
MinTbLog2SizeY.
Definition: dec.h:39
VVCLocalContext::is_cu_chroma_qp_offset_coded
int is_cu_chroma_qp_offset_coded
IsCuChromaQpOffsetCoded.
Definition: ctu.h:398
VVCLocalContext::is_cu_qp_delta_coded
uint8_t is_cu_qp_delta_coded
IsCuQpDeltaCoded.
Definition: ctu.h:395
merge_data_gpm
static void merge_data_gpm(VVCLocalContext *lc)
Definition: ctu.c:1385
CodingUnit::y0
int y0
Definition: ctu.h:283
CodingUnit::qp
int8_t qp[4]
QpY, Qp′Cb, Qp′Cr, Qp′CbCr.
Definition: ctu.h:327
ff_vvc_intra_bdpcm_chroma_flag
int ff_vvc_intra_bdpcm_chroma_flag(VVCLocalContext *lc)
Definition: cabac.c:1232
ff_vvc_ctu_free_cus
void ff_vvc_ctu_free_cus(CodingUnit **cus)
Definition: ctu.c:2542