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