FFmpeg
ps.c
Go to the documentation of this file.
1 /*
2  * VVC parameter set parser
3  *
4  * Copyright (C) 2023 Nuo Mi
5  * Copyright (C) 2022 Xu Mu
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 #include <stdbool.h>
24 
25 #include "libavcodec/cbs_h266.h"
26 #include "libavcodec/decode.h"
27 #include "libavcodec/h2645data.h"
28 #include "libavutil/mem.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/refstruct.h"
31 #include "data.h"
32 #include "ps.h"
33 #include "dec.h"
34 
35 static int sps_map_pixel_format(VVCSPS *sps, void *log_ctx)
36 {
37  const H266RawSPS *r = sps->r;
38  const AVPixFmtDescriptor *desc;
39 
40  switch (sps->bit_depth) {
41  case 8:
42  if (r->sps_chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY8;
43  if (r->sps_chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P;
44  if (r->sps_chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P;
45  if (r->sps_chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P;
46  break;
47  case 10:
48  if (r->sps_chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY10;
49  if (r->sps_chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P10;
50  if (r->sps_chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P10;
51  if (r->sps_chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P10;
52  break;
53  case 12:
54  if (r->sps_chroma_format_idc == 0) sps->pix_fmt = AV_PIX_FMT_GRAY12;
55  if (r->sps_chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P12;
56  if (r->sps_chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P12;
57  if (r->sps_chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P12;
58  break;
59  default:
60  av_log(log_ctx, AV_LOG_ERROR,
61  "The following bit-depths are currently specified: 8, 10, 12 bits, "
62  "chroma_format_idc is %d, depth is %d\n",
63  r->sps_chroma_format_idc, sps->bit_depth);
64  return AVERROR_INVALIDDATA;
65  }
66 
67  desc = av_pix_fmt_desc_get(sps->pix_fmt);
68  if (!desc)
69  return AVERROR(EINVAL);
70 
71  sps->hshift[0] = sps->vshift[0] = 0;
72  sps->hshift[2] = sps->hshift[1] = desc->log2_chroma_w;
73  sps->vshift[2] = sps->vshift[1] = desc->log2_chroma_h;
74 
75  sps->pixel_shift = sps->bit_depth > 8;
76 
77  return 0;
78 }
79 
80 static int sps_bit_depth(VVCSPS *sps, void *log_ctx)
81 {
82  const H266RawSPS *r = sps->r;
83 
84  sps->bit_depth = r->sps_bitdepth_minus8 + 8;
85  sps->qp_bd_offset = 6 * (sps->bit_depth - 8);
86  sps->log2_transform_range =
87  r->sps_extended_precision_flag ? FFMAX(15, FFMIN(20, sps->bit_depth + 6)) : 15;
88  return sps_map_pixel_format(sps, log_ctx);
89 }
90 
92 {
93  const H266RawSPS *r = sps->r;
94  const int num_qp_tables = r->sps_same_qp_table_for_chroma_flag ?
95  1 : (r->sps_joint_cbcr_enabled_flag ? 3 : 2);
96 
97  for (int i = 0; i < num_qp_tables; i++) {
98  int num_points_in_qp_table;
100  unsigned int delta_qp_in[VVC_MAX_POINTS_IN_QP_TABLE];
101  int off = sps->qp_bd_offset;
102 
103  num_points_in_qp_table = r->sps_num_points_in_qp_table_minus1[i] + 1;
104 
105  qp_out[0] = qp_in[0] = r->sps_qp_table_start_minus26[i] + 26;
106  for (int j = 0; j < num_points_in_qp_table; j++ ) {
107  const uint8_t delta_qp_out = (r->sps_delta_qp_in_val_minus1[i][j] ^ r->sps_delta_qp_diff_val[i][j]);
108  delta_qp_in[j] = r->sps_delta_qp_in_val_minus1[i][j] + 1;
109  // Note: we cannot check qp_{in,out}[j+1] here as qp_*[j] + delta_qp_*
110  // may not fit in an 8-bit signed integer.
111  if (qp_in[j] + delta_qp_in[j] > 63 || qp_out[j] + delta_qp_out > 63)
112  return AVERROR(EINVAL);
113  qp_in[j+1] = qp_in[j] + delta_qp_in[j];
114  qp_out[j+1] = qp_out[j] + delta_qp_out;
115  }
116  sps->chroma_qp_table[i][qp_in[0] + off] = qp_out[0];
117  for (int k = qp_in[0] - 1 + off; k >= 0; k--)
118  sps->chroma_qp_table[i][k] = av_clip(sps->chroma_qp_table[i][k+1]-1, -off, 63);
119 
120  for (int j = 0; j < num_points_in_qp_table; j++) {
121  int sh = delta_qp_in[j] >> 1;
122  for (int k = qp_in[j] + 1 + off, m = 1; k <= qp_in[j+1] + off; k++, m++) {
123  sps->chroma_qp_table[i][k] = sps->chroma_qp_table[i][qp_in[j] + off] +
124  ((qp_out[j+1] - qp_out[j]) * m + sh) / delta_qp_in[j];
125  }
126  }
127  for (int k = qp_in[num_points_in_qp_table] + 1 + off; k <= 63 + off; k++)
128  sps->chroma_qp_table[i][k] = av_clip(sps->chroma_qp_table[i][k-1] + 1, -sps->qp_bd_offset, 63);
129  }
130  if (r->sps_same_qp_table_for_chroma_flag) {
131  memcpy(&sps->chroma_qp_table[1], &sps->chroma_qp_table[0], sizeof(sps->chroma_qp_table[0]));
132  memcpy(&sps->chroma_qp_table[2], &sps->chroma_qp_table[0], sizeof(sps->chroma_qp_table[0]));
133  }
134 
135  return 0;
136 }
137 
138 static void sps_poc(VVCSPS *sps)
139 {
140  sps->max_pic_order_cnt_lsb = 1 << (sps->r->sps_log2_max_pic_order_cnt_lsb_minus4 + 4);
141 }
142 
143 static void sps_inter(VVCSPS *sps)
144 {
145  const H266RawSPS *r = sps->r;
146 
147  sps->max_num_merge_cand = 6 - r->sps_six_minus_max_num_merge_cand;
148  sps->max_num_ibc_merge_cand = 6 - r->sps_six_minus_max_num_ibc_merge_cand;
149 
150  if (sps->r->sps_gpm_enabled_flag) {
151  sps->max_num_gpm_merge_cand = 2;
152  if (sps->max_num_merge_cand >= 3)
153  sps->max_num_gpm_merge_cand = sps->max_num_merge_cand - r->sps_max_num_merge_cand_minus_max_num_gpm_cand;
154  }
155 
156  sps->log2_parallel_merge_level = r->sps_log2_parallel_merge_level_minus2 + 2;
157 }
158 
160 {
161  const H266RawSPS *r = sps->r;
162 
163  sps->ctb_log2_size_y = r->sps_log2_ctu_size_minus5 + 5;
164  sps->ctb_size_y = 1 << sps->ctb_log2_size_y;
165  sps->min_cb_log2_size_y = r->sps_log2_min_luma_coding_block_size_minus2 + 2;
166  sps->min_cb_size_y = 1 << sps->min_cb_log2_size_y;
167  sps->max_tb_size_y = 1 << (r->sps_max_luma_transform_size_64_flag ? 6 : 5);
168  sps->max_ts_size = 1 << (r->sps_log2_transform_skip_max_size_minus2 + 2);
169 }
170 
171 static void sps_ladf(VVCSPS* sps)
172 {
173  const H266RawSPS *r = sps->r;
174 
175  if (r->sps_ladf_enabled_flag) {
176  sps->num_ladf_intervals = r->sps_num_ladf_intervals_minus2 + 2;
177  sps->ladf_interval_lower_bound[0] = 0;
178  for (int i = 0; i < sps->num_ladf_intervals - 1; i++) {
179  sps->ladf_interval_lower_bound[i + 1] =
180  sps->ladf_interval_lower_bound[i] + r->sps_ladf_delta_threshold_minus1[i] + 1;
181  }
182  }
183 }
184 
185 #define EXTENDED_SAR 255
186 static void sps_vui(AVCodecContext *c, const H266RawVUI *vui)
187 {
188  AVRational sar = (AVRational){ 0, 1 };
192  else if (vui->vui_aspect_ratio_idc == EXTENDED_SAR) {
193  sar = (AVRational){ vui->vui_sar_width, vui->vui_sar_height };
194  } else {
195  av_log(c, AV_LOG_WARNING, "Unknown SAR index: %u.\n", vui->vui_aspect_ratio_idc);
196  }
197  }
198  ff_set_sar(c, sar);
199 
201  c->color_primaries = vui->vui_colour_primaries;
202  c->color_trc = vui->vui_transfer_characteristics;
203  c->colorspace = vui->vui_matrix_coeffs;
204  c->color_range = vui->vui_full_range_flag ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
205 
206  // Set invalid values to "unspecified"
207  if (!av_color_primaries_name(c->color_primaries))
208  c->color_primaries = AVCOL_PRI_UNSPECIFIED;
209  if (!av_color_transfer_name(c->color_trc))
210  c->color_trc = AVCOL_TRC_UNSPECIFIED;
211  if (!av_color_space_name(c->colorspace))
212  c->colorspace = AVCOL_SPC_UNSPECIFIED;
213  } else {
214  c->color_primaries = AVCOL_PRI_UNSPECIFIED;
215  c->color_trc = AVCOL_TRC_UNSPECIFIED;
216  c->colorspace = AVCOL_SPC_UNSPECIFIED;
217  c->color_range = AVCOL_RANGE_MPEG;
218  }
219 }
220 
221 
223 {
224  const H266RawSPS *r = sps->r;
225 
226  c->has_b_frames = !!r->sps_dpb_params.dpb_max_num_reorder_pics[r->sps_max_sublayers_minus1];
227  if (r->sps_vui_parameters_present_flag)
228  sps_vui(c, &r->vui);
229 }
230 
232 {
233  int ret;
234  const H266RawSPS *r = sps->r;
235 
236  ret = sps_bit_depth(sps, c);
237  if (ret < 0)
238  return ret;
239  sps_poc(sps);
240  sps_inter(sps);
242  sps_ladf(sps);
243  if (r->sps_chroma_format_idc != 0) {
245  if (ret < 0)
246  return ret;
247  }
249 
250  return 0;
251 }
252 
253 static void sps_free(AVRefStructOpaque opaque, void *obj)
254 {
255  VVCSPS *sps = obj;
256  av_refstruct_unref(&sps->r);
257 }
258 
259 static const VVCSPS *sps_alloc(const H266RawSPS *rsps, AVCodecContext *c)
260 {
261  int ret;
262  VVCSPS *sps = av_refstruct_alloc_ext(sizeof(*sps), 0, NULL, sps_free);
263 
264  if (!sps)
265  return NULL;
266 
267  av_refstruct_replace(&sps->r, rsps);
268 
269  ret = sps_derive(sps, c);
270  if (ret < 0)
271  goto fail;
272 
273  return sps;
274 
275 fail:
277  return NULL;
278 }
279 
280 static int decode_sps(VVCParamSets *ps, AVCodecContext *c, const H266RawSPS *rsps, int is_clvss)
281 {
282  VVCContext *s = c->priv_data;
283  const int sps_id = rsps->sps_seq_parameter_set_id;
284  const VVCSPS *old_sps = ps->sps_list[sps_id];
285  const VVCSPS *sps;
286 
287  if (is_clvss) {
288  ps->sps_id_used = 0;
289  s->seq_decode = (s->seq_decode + 1) & 0xff;
290  }
291 
292  if (old_sps) {
293  if (old_sps->r == rsps || !memcmp(old_sps->r, rsps, sizeof(*old_sps->r))) {
294  ps->sps_id_used |= (1 << sps_id);
295  return 0;
296  } else if (ps->sps_id_used & (1 << sps_id))
297  return AVERROR_INVALIDDATA;
298  }
299 
300  sps = sps_alloc(rsps, c);
301  if (!sps)
302  return AVERROR(ENOMEM);
303 
305  ps->sps_list[sps_id] = sps;
306  ps->sps_id_used |= (1 << sps_id);
307 
308  return 0;
309 }
310 
312 {
313  pps->chroma_qp_offset[CB - 1] = pps->r->pps_cb_qp_offset;
314  pps->chroma_qp_offset[CR - 1] = pps->r->pps_cr_qp_offset;
315  pps->chroma_qp_offset[JCBCR - 1]= pps->r->pps_joint_cbcr_qp_offset_value;
316  for (int i = 0; i < 6; i++) {
317  pps->chroma_qp_offset_list[i][CB - 1] = pps->r->pps_cb_qp_offset_list[i];
318  pps->chroma_qp_offset_list[i][CR - 1] = pps->r->pps_cr_qp_offset_list[i];
319  pps->chroma_qp_offset_list[i][JCBCR - 1]= pps->r->pps_joint_cbcr_qp_offset_list[i];
320  }
321 }
322 
323 static void pps_width_height(VVCPPS *pps, const VVCSPS *sps)
324 {
325  const H266RawPPS *r = pps->r;
326 
327  pps->width = r->pps_pic_width_in_luma_samples;
328  pps->height = r->pps_pic_height_in_luma_samples;
329 
330  pps->ctb_width = AV_CEIL_RSHIFT(pps->width, sps->ctb_log2_size_y);
331  pps->ctb_height = AV_CEIL_RSHIFT(pps->height, sps->ctb_log2_size_y);
332  pps->ctb_count = pps->ctb_width * pps->ctb_height;
333 
334  pps->min_cb_width = pps->width >> sps->min_cb_log2_size_y;
335  pps->min_cb_height = pps->height >> sps->min_cb_log2_size_y;
336 
337  pps->min_pu_width = pps->width >> MIN_PU_LOG2;
338  pps->min_pu_height = pps->height >> MIN_PU_LOG2;
339  pps->min_tu_width = pps->width >> MIN_TU_LOG2;
340  pps->min_tu_height = pps->height >> MIN_TU_LOG2;
341 
342  pps->width32 = AV_CEIL_RSHIFT(pps->width, 5);
343  pps->height32 = AV_CEIL_RSHIFT(pps->height, 5);
344  pps->width64 = AV_CEIL_RSHIFT(pps->width, 6);
345  pps->height64 = AV_CEIL_RSHIFT(pps->height, 6);
346 }
347 
348 static int pps_bd(VVCPPS *pps)
349 {
350  const H266RawPPS *r = pps->r;
351 
352  pps->col_bd = av_calloc(r->num_tile_columns + 1, sizeof(*pps->col_bd));
353  pps->row_bd = av_calloc(r->num_tile_rows + 1, sizeof(*pps->row_bd));
354  pps->ctb_to_col_bd = av_calloc(pps->ctb_width + 1, sizeof(*pps->ctb_to_col_bd));
355  pps->ctb_to_row_bd = av_calloc(pps->ctb_height + 1, sizeof(*pps->ctb_to_col_bd));
356  if (!pps->col_bd || !pps->row_bd || !pps->ctb_to_col_bd || !pps->ctb_to_row_bd)
357  return AVERROR(ENOMEM);
358 
359  for (int i = 0, j = 0; i < r->num_tile_columns; i++) {
360  pps->col_bd[i] = j;
361  j += r->col_width_val[i];
362  for (int k = pps->col_bd[i]; k < j; k++)
363  pps->ctb_to_col_bd[k] = pps->col_bd[i];
364  }
365  pps->col_bd[r->num_tile_columns] = pps->ctb_to_col_bd[pps->ctb_width] = pps->ctb_width;
366 
367  for (int i = 0, j = 0; i < r->num_tile_rows; i++) {
368  pps->row_bd[i] = j;
369  j += r->row_height_val[i];
370  for (int k = pps->row_bd[i]; k < j; k++)
371  pps->ctb_to_row_bd[k] = pps->row_bd[i];
372  }
373  pps->row_bd[r->num_tile_rows] = pps->ctb_to_row_bd[pps->ctb_height] = pps->ctb_height;
374 
375  return 0;
376 }
377 
378 
379 static int next_tile_idx(int tile_idx, const int i, const H266RawPPS *r)
380 {
381  if (r->pps_tile_idx_delta_present_flag) {
382  tile_idx += r->pps_tile_idx_delta_val[i];
383  } else {
384  tile_idx += r->pps_slice_width_in_tiles_minus1[i] + 1;
385  if (tile_idx % r->num_tile_columns == 0)
386  tile_idx += (r->pps_slice_height_in_tiles_minus1[i]) * r->num_tile_columns;
387  }
388  return tile_idx;
389 }
390 
391 static void tile_xy(int *tile_x, int *tile_y, const int tile_idx, const VVCPPS *pps)
392 {
393  *tile_x = tile_idx % pps->r->num_tile_columns;
394  *tile_y = tile_idx / pps->r->num_tile_columns;
395 }
396 
397 static void ctu_xy(int *rx, int *ry, const int tile_x, const int tile_y, const VVCPPS *pps)
398 {
399  *rx = pps->col_bd[tile_x];
400  *ry = pps->row_bd[tile_y];
401 }
402 
403 static int ctu_rs(const int rx, const int ry, const VVCPPS *pps)
404 {
405  return pps->ctb_width * ry + rx;
406 }
407 
408 static int pps_add_ctus(VVCPPS *pps, int *off, const int rx, const int ry,
409  const int w, const int h)
410 {
411  int start = *off;
412  for (int y = 0; y < h; y++) {
413  for (int x = 0; x < w; x++) {
414  if (*off >= pps->ctb_count)
415  return AVERROR_INVALIDDATA;
416  pps->ctb_addr_in_slice[*off] = ctu_rs(rx + x, ry + y, pps);
417  (*off)++;
418  }
419  }
420  return *off - start;
421 }
422 
423 static int pps_single_slice_picture(VVCPPS *pps, int *off)
424 {
425  pps->num_ctus_in_slice[0] = 0;
426  for (int j = 0; j < pps->r->num_tile_rows; j++) {
427  for (int i = 0; i < pps->r->num_tile_columns; i++) {
428  const int ret = pps_add_ctus(pps, off,
429  pps->col_bd[i], pps->row_bd[j],
430  pps->r->col_width_val[i], pps->r->row_height_val[j]);
431  if (ret < 0)
432  return ret;
433  pps->num_ctus_in_slice[0] += ret;
434  }
435  }
436 
437  return 0;
438 }
439 
440 static void subpic_tiles(int *tile_x, int *tile_y, int *tile_x_end, int *tile_y_end,
441  const VVCSPS *sps, const VVCPPS *pps, const int i)
442 {
443  const int rx = sps->r->sps_subpic_ctu_top_left_x[i];
444  const int ry = sps->r->sps_subpic_ctu_top_left_y[i];
445 
446  *tile_x = *tile_y = 0;
447 
448  while (pps->col_bd[*tile_x] < rx)
449  (*tile_x)++;
450 
451  while (pps->row_bd[*tile_y] < ry)
452  (*tile_y)++;
453 
454  *tile_x_end = (*tile_x);
455  *tile_y_end = (*tile_y);
456 
457  while (pps->col_bd[*tile_x_end] < rx + sps->r->sps_subpic_width_minus1[i] + 1)
458  (*tile_x_end)++;
459 
460  while (pps->row_bd[*tile_y_end] < ry + sps->r->sps_subpic_height_minus1[i] + 1)
461  (*tile_y_end)++;
462 }
463 
464 static int pps_subpic_less_than_one_tile_slice(VVCPPS *pps, const VVCSPS *sps, const int i, const int tx, const int ty, int *off)
465 {
466  const int ret = pps_add_ctus(pps, off,
467  sps->r->sps_subpic_ctu_top_left_x[i], sps->r->sps_subpic_ctu_top_left_y[i],
468  sps->r->sps_subpic_width_minus1[i] + 1, sps->r->sps_subpic_height_minus1[i] + 1);
469  if (ret < 0)
470  return ret;
471 
472  pps->num_ctus_in_slice[i] = ret;
473  return 0;
474 }
475 
476 static int pps_subpic_one_or_more_tiles_slice(VVCPPS *pps, const int tile_x, const int tile_y, const int x_end, const int y_end,
477  const int i, int *off)
478 {
479  for (int ty = tile_y; ty < y_end; ty++) {
480  for (int tx = tile_x; tx < x_end; tx++) {
481  const int ret = pps_add_ctus(pps, off,
482  pps->col_bd[tx], pps->row_bd[ty],
483  pps->r->col_width_val[tx], pps->r->row_height_val[ty]);
484  if (ret < 0)
485  return ret;
486 
487  pps->num_ctus_in_slice[i] += ret;
488  }
489  }
490  return 0;
491 }
492 
493 static int pps_subpic_slice(VVCPPS *pps, const VVCSPS *sps, const int i, int *off)
494 {
495  int tx, ty, x_end, y_end;
496 
497  pps->slice_start_offset[i] = *off;
498  pps->num_ctus_in_slice[i] = 0;
499 
500  subpic_tiles(&tx, &ty, &x_end, &y_end, sps, pps, i);
501  if (ty + 1 == y_end && sps->r->sps_subpic_height_minus1[i] + 1 < pps->r->row_height_val[ty])
502  return pps_subpic_less_than_one_tile_slice(pps, sps, i, tx, ty, off);
503  else
504  return pps_subpic_one_or_more_tiles_slice(pps, tx, ty, x_end, y_end, i, off);
505 }
506 
507 static int pps_single_slice_per_subpic(VVCPPS *pps, const VVCSPS *sps, int *off)
508 {
509  int ret;
510 
511  if (!sps->r->sps_subpic_info_present_flag) {
513  if (ret < 0)
514  return ret;
515  } else {
516  for (int i = 0; i < pps->r->pps_num_slices_in_pic_minus1 + 1; i++) {
517  const int ret = pps_subpic_slice(pps, sps, i, off);
518  if (ret < 0)
519  return ret;
520  }
521  }
522  return 0;
523 }
524 
525 static int pps_one_tile_slices(VVCPPS *pps, const int tile_idx, int i, int *off)
526 {
527  const H266RawPPS *r = pps->r;
528  int rx, ry, ctu_y_end, tile_x, tile_y;
529 
530  tile_xy(&tile_x, &tile_y, tile_idx, pps);
531  ctu_xy(&rx, &ry, tile_x, tile_y, pps);
532  ctu_y_end = ry + r->row_height_val[tile_y];
533  while (ry < ctu_y_end) {
534  int ret;
535  pps->slice_start_offset[i] = *off;
536  ret = pps_add_ctus(pps, off, rx, ry,
537  r->col_width_val[tile_x], r->slice_height_in_ctus[i]);
538  if (ret < 0)
539  return ret;
540  pps->num_ctus_in_slice[i] = ret;
541  ry += r->slice_height_in_ctus[i++];
542  }
543  i--;
544  return i;
545 }
546 
547 static int pps_multi_tiles_slice(VVCPPS *pps, const int tile_idx, const int i, int *off, bool *tile_in_slice)
548 {
549  const H266RawPPS *r = pps->r;
550  int rx, ry, tile_x, tile_y;
551 
552  tile_xy(&tile_x, &tile_y, tile_idx, pps);
553  pps->slice_start_offset[i] = *off;
554  pps->num_ctus_in_slice[i] = 0;
555  for (int ty = tile_y; ty <= tile_y + r->pps_slice_height_in_tiles_minus1[i]; ty++) {
556  for (int tx = tile_x; tx <= tile_x + r->pps_slice_width_in_tiles_minus1[i]; tx++) {
557  int ret;
558  const int idx = ty * r->num_tile_columns + tx;
559  if (tile_in_slice[idx])
560  return AVERROR_INVALIDDATA;
561  tile_in_slice[idx] = true;
562  ctu_xy(&rx, &ry, tx, ty, pps);
563  ret = pps_add_ctus(pps, off, rx, ry,
564  r->col_width_val[tx], r->row_height_val[ty]);
565  if (ret < 0)
566  return ret;
567  pps->num_ctus_in_slice[i] += ret;
568  }
569  }
570 
571  return 0;
572 }
573 
574 static int pps_rect_slice(VVCPPS *pps, const VVCSPS *sps)
575 {
576  const H266RawPPS *r = pps->r;
577  bool tile_in_slice[VVC_MAX_TILES_PER_AU] = {false};
578  int tile_idx = 0, off = 0, ret;
579 
580  if (r->pps_single_slice_per_subpic_flag) {
581  return pps_single_slice_per_subpic(pps, sps, &off);
582  }
583 
584  for (int i = 0; i < r->pps_num_slices_in_pic_minus1 + 1; i++) {
585  if (!r->pps_slice_width_in_tiles_minus1[i] &&
586  !r->pps_slice_height_in_tiles_minus1[i]) {
587  if (tile_in_slice[tile_idx])
588  return AVERROR_INVALIDDATA;
589  tile_in_slice[tile_idx] = true;
590  ret = pps_one_tile_slices(pps, tile_idx, i, &off);
591  if (ret < 0)
592  return ret;
593  i = ret;
594  } else {
595  ret = pps_multi_tiles_slice(pps, tile_idx, i, &off, tile_in_slice);
596  if (ret < 0)
597  return ret;
598  }
599  tile_idx = next_tile_idx(tile_idx, i, r);
600  }
601 
602  for (int i = 0; i < r->num_tiles_in_pic; i++) {
603  if (!tile_in_slice[i])
604  return AVERROR_INVALIDDATA;
605  }
606 
607  return 0;
608 }
609 
611 {
612  const H266RawPPS* r = pps->r;
613  int rx, ry, off = 0;
614 
615  for (int tile_y = 0; tile_y < r->num_tile_rows; tile_y++) {
616  for (int tile_x = 0; tile_x < r->num_tile_columns; tile_x++) {
617  int ret;
618  ctu_xy(&rx, &ry, tile_x, tile_y, pps);
619  ret = pps_add_ctus(pps, &off, rx, ry, r->col_width_val[tile_x], r->row_height_val[tile_y]);
620  if (ret < 0)
621  return ret;
622  }
623  }
624 
625  return 0;
626 }
627 
628 static int pps_slice_map(VVCPPS *pps, const VVCSPS *sps)
629 {
630  int ret;
631 
632  pps->ctb_addr_in_slice = av_calloc(pps->ctb_count, sizeof(*pps->ctb_addr_in_slice));
633  if (!pps->ctb_addr_in_slice)
634  return AVERROR(ENOMEM);
635 
636  if (pps->r->pps_rect_slice_flag)
637  return pps_rect_slice(pps, sps);
638 
640  if (ret < 0)
641  return ret;
642 
643  return 0;
644 }
645 
647 {
648  const H266RawPPS *r = pps->r;
649 
650  if (r->pps_ref_wraparound_enabled_flag)
651  pps->ref_wraparound_offset = (pps->width / sps->min_cb_size_y) - r->pps_pic_width_minus_wraparound_offset;
652 }
653 
654 static void pps_subpic(VVCPPS *pps, const VVCSPS *sps)
655 {
656  const H266RawSPS *rsps = sps->r;
657  for (int i = 0; i < rsps->sps_num_subpics_minus1 + 1; i++) {
658  if (rsps->sps_subpic_treated_as_pic_flag[i]) {
659  pps->subpic_x[i] = rsps->sps_subpic_ctu_top_left_x[i] << sps->ctb_log2_size_y;
660  pps->subpic_y[i] = rsps->sps_subpic_ctu_top_left_y[i] << sps->ctb_log2_size_y;
661  pps->subpic_width[i] = FFMIN(pps->width - pps->subpic_x[i], (rsps->sps_subpic_width_minus1[i] + 1) << sps->ctb_log2_size_y);
662  pps->subpic_height[i] = FFMIN(pps->height - pps->subpic_y[i], (rsps->sps_subpic_height_minus1[i] + 1) << sps->ctb_log2_size_y);
663  } else {
664  pps->subpic_x[i] = 0;
665  pps->subpic_y[i] = 0;
666  pps->subpic_width[i] = pps->width;
667  pps->subpic_height[i] = pps->height;
668  }
669  }
670 }
671 
672 static int pps_derive(VVCPPS *pps, const VVCSPS *sps)
673 {
674  int ret;
675 
678 
679  ret = pps_bd(pps);
680  if (ret < 0)
681  return ret;
682 
683  ret = pps_slice_map(pps, sps);
684  if (ret < 0)
685  return ret;
686 
688  pps_subpic(pps, sps);
689 
690  return 0;
691 }
692 
693 static void pps_free(AVRefStructOpaque opaque, void *obj)
694 {
695  VVCPPS *pps = obj;
696 
697  av_refstruct_unref(&pps->r);
698 
699  av_freep(&pps->col_bd);
700  av_freep(&pps->row_bd);
701  av_freep(&pps->ctb_to_col_bd);
702  av_freep(&pps->ctb_to_row_bd);
703  av_freep(&pps->ctb_addr_in_slice);
704 }
705 
706 static const VVCPPS *pps_alloc(const H266RawPPS *rpps, const VVCSPS *sps)
707 {
708  int ret;
709  VVCPPS *pps = av_refstruct_alloc_ext(sizeof(*pps), 0, NULL, pps_free);
710 
711  if (!pps)
712  return NULL;
713 
714  av_refstruct_replace(&pps->r, rpps);
715 
716  ret = pps_derive(pps, sps);
717  if (ret < 0)
718  goto fail;
719 
720  return pps;
721 
722 fail:
724  return NULL;
725 }
726 
727 static int decode_pps(VVCParamSets *ps, const H266RawPPS *rpps)
728 {
729  int ret = 0;
730  const int pps_id = rpps->pps_pic_parameter_set_id;
731  const int sps_id = rpps->pps_seq_parameter_set_id;
732  const VVCPPS *old_pps = ps->pps_list[pps_id];
733  const VVCPPS *pps;
734 
735  if (old_pps && old_pps->r == rpps)
736  return 0;
737 
738  pps = pps_alloc(rpps, ps->sps_list[sps_id]);
739  if (!pps)
740  return AVERROR(ENOMEM);
741 
743  ps->pps_list[pps_id] = pps;
744 
745  return ret;
746 }
747 
748 static int decode_ps(VVCParamSets *ps, AVCodecContext *c, const SliceContext *sc, int is_clvss)
749 {
750  const H266RawSlice *sl = sc->ref;
751  const H266RawPPS *rpps = sl->pps;
752  const H266RawSPS *rsps = sl->sps;
753  int ret;
754 
755  if (!rpps)
756  return AVERROR_INVALIDDATA;
757 
758  if (!rsps)
759  return AVERROR_INVALIDDATA;
760 
761  ret = decode_sps(ps, c, rsps, is_clvss);
762  if (ret < 0)
763  return ret;
764 
765  if (rsps->sps_log2_ctu_size_minus5 > 2) {
766  // CTU > 128 are reserved in vvc spec v3
767  av_log(c, AV_LOG_ERROR, "CTU size > 128. \n");
768  return AVERROR_PATCHWELCOME;
769  }
770 
771  ret = decode_pps(ps, rpps);
772  if (ret < 0)
773  return ret;
774 
775  return 0;
776 }
777 
778 #define WEIGHT_TABLE(x) \
779  w->nb_weights[L##x] = r->num_weights_l##x; \
780  for (int i = 0; i < w->nb_weights[L##x]; i++) { \
781  w->weight_flag[L##x][LUMA][i] = r->luma_weight_l##x##_flag[i]; \
782  w->weight_flag[L##x][CHROMA][i] = r->chroma_weight_l##x##_flag[i]; \
783  w->weight[L##x][LUMA][i] = denom[LUMA] + r->delta_luma_weight_l##x[i]; \
784  w->offset[L##x][LUMA][i] = r->luma_offset_l##x[i]; \
785  for (int j = CB; j <= CR; j++) { \
786  w->weight[L##x][j][i] = denom[CHROMA] + r->delta_chroma_weight_l##x[i][j - 1]; \
787  w->offset[L##x][j][i] = 128 + r->delta_chroma_offset_l##x[i][j - 1]; \
788  w->offset[L##x][j][i] -= (128 * w->weight[L##x][j][i]) >> w->log2_denom[CHROMA]; \
789  w->offset[L##x][j][i] = av_clip_intp2(w->offset[L##x][j][i], 7); \
790  } \
791  } \
792 
794 {
795  int denom[2];
796 
797  w->log2_denom[LUMA] = r->luma_log2_weight_denom;
798  w->log2_denom[CHROMA] = w->log2_denom[LUMA] + r->delta_chroma_log2_weight_denom;
799  denom[LUMA] = 1 << w->log2_denom[LUMA];
800  denom[CHROMA] = 1 << w->log2_denom[CHROMA];
801  WEIGHT_TABLE(0)
802  WEIGHT_TABLE(1)
803 }
804 
805 // 8.3.1 Decoding process for picture order count
806 static int ph_compute_poc(const H266RawPictureHeader *ph, const H266RawSPS *sps, const int poc_tid0, const int is_clvss)
807 {
808  const int max_poc_lsb = 1 << (sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4);
809  const int prev_poc_lsb = poc_tid0 % max_poc_lsb;
810  const int prev_poc_msb = poc_tid0 - prev_poc_lsb;
811  const int poc_lsb = ph->ph_pic_order_cnt_lsb;
812  int poc_msb;
813 
814  if (ph->ph_poc_msb_cycle_present_flag) {
815  poc_msb = ph->ph_poc_msb_cycle_val * max_poc_lsb;
816  } else if (is_clvss) {
817  poc_msb = 0;
818  } else {
819  if (poc_lsb < prev_poc_lsb && prev_poc_lsb - poc_lsb >= max_poc_lsb / 2)
820  poc_msb = prev_poc_msb + max_poc_lsb;
821  else if (poc_lsb > prev_poc_lsb && poc_lsb - prev_poc_lsb > max_poc_lsb / 2)
822  poc_msb = prev_poc_msb - max_poc_lsb;
823  else
824  poc_msb = prev_poc_msb;
825  }
826 
827  return poc_msb + poc_lsb;
828 }
829 
831  uint16_t *pivot1, uint16_t *pivot2, uint16_t *scale_coeff, const int idx, const int max)
832 {
833  const int lut_sample =
834  pivot1[idx] + ((scale_coeff[idx] * (sample - pivot2[idx]) + (1<< 10)) >> 11);
835  return av_clip(lut_sample, 0, max - 1);
836 }
837 
838 //8.8.2.2 Inverse mapping process for a luma sample
839 static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266RawSPS *sps)
840 {
841  const int bit_depth = (sps->sps_bitdepth_minus8 + 8);
842  const int max = (1 << bit_depth);
843  const int org_cw = max / LMCS_MAX_BIN_SIZE;
844  const int shift = av_log2(org_cw);
845  const int off = 1 << (shift - 1);
846  int cw[LMCS_MAX_BIN_SIZE];
847  uint16_t input_pivot[LMCS_MAX_BIN_SIZE];
848  uint16_t scale_coeff[LMCS_MAX_BIN_SIZE];
849  uint16_t inv_scale_coeff[LMCS_MAX_BIN_SIZE];
850  int i, delta_crs, sum_cw = 0;
852  return AVERROR_PATCHWELCOME;
853 
854  if (!rlmcs)
855  return AVERROR_INVALIDDATA;
856 
857  lmcs->min_bin_idx = rlmcs->lmcs_min_bin_idx;
859 
860  memset(cw, 0, sizeof(cw));
861  for (int i = lmcs->min_bin_idx; i <= lmcs->max_bin_idx; i++) {
862  cw[i] = org_cw + (1 - 2 * rlmcs->lmcs_delta_sign_cw_flag[i]) * rlmcs->lmcs_delta_abs_cw[i];
863  sum_cw += cw[i];
864  }
865  if (sum_cw > (1 << bit_depth) - 1)
866  return AVERROR_INVALIDDATA;
867 
868  delta_crs = (1 - 2 * rlmcs->lmcs_delta_sign_crs_flag) * rlmcs->lmcs_delta_abs_crs;
869 
870  lmcs->pivot[0] = 0;
871  for (i = 0; i < LMCS_MAX_BIN_SIZE; i++) {
872  input_pivot[i] = i * org_cw;
873  lmcs->pivot[i + 1] = lmcs->pivot[i] + cw[i];
874  if (i >= lmcs->min_bin_idx && i <= lmcs->max_bin_idx &&
875  lmcs->pivot[i] % (1 << (bit_depth - 5)) != 0 &&
876  lmcs->pivot[i] >> (bit_depth - 5) == lmcs->pivot[i + 1] >> (bit_depth - 5))
877  return AVERROR_INVALIDDATA;
878  scale_coeff[i] = (cw[i] * (1 << 11) + off) >> shift;
879  if (cw[i] == 0) {
880  inv_scale_coeff[i] = 0;
881  lmcs->chroma_scale_coeff[i] = (1 << 11);
882  } else {
883  const int cw_plus_d = cw[i] + delta_crs;
884  if (cw_plus_d < (org_cw >> 3) || cw_plus_d > ((org_cw << 3) - 1))
885  return AVERROR_INVALIDDATA;
886  inv_scale_coeff[i] = org_cw * (1 << 11) / cw[i];
887  lmcs->chroma_scale_coeff[i] = org_cw * (1 << 11) / cw_plus_d;
888  }
889  }
890 
891  //derive lmcs_fwd_lut
892  for (uint16_t sample = 0; sample < max; sample++) {
893  const int idx_y = sample >> shift;
894  const uint16_t fwd_sample = lmcs_derive_lut_sample(sample, lmcs->pivot,
895  input_pivot, scale_coeff, idx_y, max);
896  if (bit_depth > 8)
897  lmcs->fwd_lut.u16[sample] = fwd_sample;
898  else
899  lmcs->fwd_lut.u8 [sample] = fwd_sample;
900 
901  }
902 
903  //derive lmcs_inv_lut
904  i = lmcs->min_bin_idx;
905  for (uint16_t sample = 0; sample < max; sample++) {
906  uint16_t inv_sample;
907  while (i <= lmcs->max_bin_idx && sample >= lmcs->pivot[i + 1])
908  i++;
909  i = FFMIN(i, LMCS_MAX_BIN_SIZE - 1);
910 
911  inv_sample = lmcs_derive_lut_sample(sample, input_pivot, lmcs->pivot,
912  inv_scale_coeff, i, max);
913 
914  if (bit_depth > 8)
915  lmcs->inv_lut.u16[sample] = inv_sample;
916  else
917  lmcs->inv_lut.u8 [sample] = inv_sample;
918  }
919 
920  return 0;
921 }
922 
924 {
925  if (sps->sps_affine_enabled_flag)
926  return 5 - sps->sps_five_minus_max_num_subblock_merge_cand;
927  return sps->sps_sbtmvp_enabled_flag && ph->ph_temporal_mvp_enabled_flag;
928 }
929 
930 static int ph_vb_pos(uint16_t *vbs, uint8_t *num_vbs, const uint16_t *pos_minus_1, const uint8_t num_pos, uint16_t max, const int ctb_size_y)
931 {
932  max = FF_CEIL_RSHIFT(max, 3) - 2;
933  for (int i = 0; i < num_pos; i++) {
934  if (pos_minus_1[i] > max)
935  return AVERROR_INVALIDDATA;
936 
937  vbs[i] = (pos_minus_1[i] + 1) << 3;
938 
939  // The distance between any two vertical virtual boundaries shall be greater than or equal to CtbSizeY luma samples
940  if (i && vbs[i] < vbs[i - 1] + ctb_size_y)
941  return AVERROR_INVALIDDATA;
942  }
943  *num_vbs = num_pos;
944 
945  return 0;
946 }
947 
948 #define VBF(f) (sps->sps_virtual_boundaries_present_flag ? sps->sps_##f : ph->r->ph_##f)
949 #define VBFS(c, d) VBF(virtual_boundary_pos_##c##_minus1), VBF(num_##d##_virtual_boundaries)
950 
951 static int ph_vb(VVCPH *ph, const H266RawSPS *sps, const H266RawPPS *pps)
952 {
953  const int ctb_size_y = 1 << (sps->sps_log2_ctu_size_minus5 + 5);
954  int ret;
955 
956  if (!sps->sps_virtual_boundaries_enabled_flag)
957  return 0;
958 
959  ret = ph_vb_pos(ph->vb_pos_x, &ph->num_ver_vbs, VBFS(x, ver), pps->pps_pic_width_in_luma_samples, ctb_size_y);
960  if (ret < 0)
961  return ret;
962 
963  ret = ph_vb_pos(ph->vb_pos_y, &ph->num_hor_vbs, VBFS(y, hor), pps->pps_pic_height_in_luma_samples, ctb_size_y);
964  if (ret < 0)
965  return ret;
966 
967  return 0;
968 }
969 
970 static int ph_derive(VVCPH *ph, const H266RawSPS *sps, const H266RawPPS *pps, const int poc_tid0, const int is_clvss)
971 {
972  int ret;
973  ph->max_num_subblock_merge_cand = ph_max_num_subblock_merge_cand(sps, ph->r);
974 
975  ph->poc = ph_compute_poc(ph->r, sps, poc_tid0, is_clvss);
976 
977  if (pps->pps_wp_info_in_ph_flag)
978  pred_weight_table(&ph->pwt, &ph->r->ph_pred_weight_table);
979 
980  ret = ph_vb(ph, sps, pps);
981  if (ret < 0)
982  return ret;
983 
984  return 0;
985 }
986 
987 static int decode_ph(VVCFrameParamSets *fps, const H266RawPictureHeader *rph, void *rph_ref,
988  const int poc_tid0, const int is_clvss)
989 {
990  int ret;
991  VVCPH *ph = &fps->ph;
992  const H266RawSPS *sps = fps->sps->r;
993  const H266RawPPS *pps = fps->pps->r;
994 
995  ph->r = rph;
996  av_refstruct_replace(&ph->rref, rph_ref);
997  ret = ph_derive(ph, sps, pps, poc_tid0, is_clvss);
998  if (ret < 0)
999  return ret;
1000 
1001  return 0;
1002 }
1003 
1005  const SliceContext *sc, const int poc_tid0, const int is_clvss, const VVCContext *s)
1006 {
1007  const H266RawSlice *sl = sc->ref;
1008  const H266RawPictureHeader *ph = sl->ph;
1009  const H266RawPPS *rpps = sl->pps;
1010  int ret;
1011 
1012  if (!ph)
1013  return AVERROR_INVALIDDATA;
1014 
1015  if (!rpps)
1016  return AVERROR_INVALIDDATA;
1017 
1020 
1021  ret = decode_ph(fps, ph, sl->ph_ref, poc_tid0, is_clvss);
1022  if (ret < 0)
1023  return ret;
1024 
1025  if (ph->ph_explicit_scaling_list_enabled_flag)
1026  av_refstruct_replace(&fps->sl, ps->scaling_list[ph->ph_scaling_list_aps_id]);
1027 
1028  if (ph->ph_lmcs_enabled_flag) {
1029  ret = lmcs_derive_lut(&fps->lmcs, ps->lmcs_list[ph->ph_lmcs_aps_id], fps->sps->r);
1030  if (ret < 0)
1031  return ret;
1032  }
1033 
1034  for (int i = 0; i < FF_ARRAY_ELEMS(fps->alf_list); i++)
1035  av_refstruct_replace(&fps->alf_list[i], ps->alf_list[i]);
1036 
1037  return 0;
1038 }
1039 
1041 {
1042  if (IS_IDR(s))
1043  s->no_output_before_recovery_flag = 1;
1044  else if (IS_CRA(s) || IS_GDR(s))
1045  s->no_output_before_recovery_flag = s->last_eos;
1046 }
1047 
1048 static void decode_recovery_poc(VVCContext *s, const VVCPH *ph)
1049 {
1050  if (s->no_output_before_recovery_flag) {
1051  if (IS_GDR(s))
1052  s->gdr_recovery_point_poc = ph->poc + ph->r->ph_recovery_poc_cnt;
1053  if (!GDR_IS_RECOVERED(s) && s->gdr_recovery_point_poc <= ph->poc)
1055  }
1056 }
1057 
1059 {
1060  int ret = 0;
1061  VVCFrameParamSets *fps = &fc->ps;
1062  VVCParamSets *ps = &s->ps;
1063  const SliceContext *sc = fc->slices[0];
1064  int is_clvss;
1065 
1067  is_clvss = IS_CLVSS(s);
1068 
1069  ret = decode_ps(ps, s->avctx, sc, is_clvss);
1070  if (ret < 0)
1071  return ret;
1072 
1073  ret = decode_frame_ps(fps, ps, sc, s->poc_tid0, is_clvss, s);
1074  decode_recovery_poc(s, &fps->ph);
1075  return ret;
1076 }
1077 
1079 {
1080  av_refstruct_unref(&fps->sps);
1081  av_refstruct_unref(&fps->pps);
1082  av_refstruct_unref(&fps->ph.rref);
1083  av_refstruct_unref(&fps->sl);
1084  for (int i = 0; i < FF_ARRAY_ELEMS(fps->alf_list); i++)
1085  av_refstruct_unref(&fps->alf_list[i]);
1086 }
1087 
1089 {
1090  for (int i = 0; i < FF_ARRAY_ELEMS(ps->scaling_list); i++)
1092  for (int i = 0; i < FF_ARRAY_ELEMS(ps->lmcs_list); i++)
1094  for (int i = 0; i < FF_ARRAY_ELEMS(ps->alf_list); i++)
1095  av_refstruct_unref(&ps->alf_list[i]);
1096  for (int i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++)
1097  av_refstruct_unref(&ps->sps_list[i]);
1098  for (int i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++)
1099  av_refstruct_unref(&ps->pps_list[i]);
1100 }
1101 
1102 static void alf_coeff(int16_t *coeff,
1103  const uint8_t *abs, const uint8_t *sign, const int size)
1104 {
1105  for (int i = 0; i < size; i++)
1106  coeff[i] = (1 - 2 * sign[i]) * abs[i];
1107 }
1108 
1109 static void alf_coeff_cc(int16_t *coeff,
1110  const uint8_t *mapped_abs, const uint8_t *sign)
1111 {
1112  for (int i = 0; i < ALF_NUM_COEFF_CC; i++) {
1113  int c = mapped_abs[i];
1114  if (c)
1115  c = (1 - 2 * sign[i]) * (1 << (c - 1));
1116  coeff[i] = c;
1117  }
1118 }
1119 
1120 static void alf_luma(VVCALF *alf, const H266RawAPS *aps)
1121 {
1122  if (!aps->alf_luma_filter_signal_flag)
1123  return;
1124 
1125  for (int i = 0; i < ALF_NUM_FILTERS_LUMA; i++) {
1126  const int ref = aps->alf_luma_coeff_delta_idx[i];
1127  const uint8_t *abs = aps->alf_luma_coeff_abs[ref];
1128  const uint8_t *sign = aps->alf_luma_coeff_sign[ref];
1129 
1130  alf_coeff(alf->luma_coeff[i], abs, sign, ALF_NUM_COEFF_LUMA);
1131  memcpy(alf->luma_clip_idx[i], aps->alf_luma_clip_idx[ref],
1132  sizeof(alf->luma_clip_idx[i]));
1133  }
1134 }
1135 
1136 static void alf_chroma(VVCALF *alf, const H266RawAPS *aps)
1137 {
1138  if (!aps->alf_chroma_filter_signal_flag)
1139  return;
1140 
1141  alf->num_chroma_filters = aps->alf_chroma_num_alt_filters_minus1 + 1;
1142  for (int i = 0; i < alf->num_chroma_filters; i++) {
1143  const uint8_t *abs = aps->alf_chroma_coeff_abs[i];
1144  const uint8_t *sign = aps->alf_chroma_coeff_sign[i];
1145 
1147  memcpy(alf->chroma_clip_idx[i], aps->alf_chroma_clip_idx[i],
1148  sizeof(alf->chroma_clip_idx[i]));
1149  }
1150 }
1151 
1152 static void alf_cc(VVCALF *alf, const H266RawAPS *aps)
1153 {
1154  const uint8_t (*abs[])[ALF_NUM_COEFF_CC] =
1155  { aps->alf_cc_cb_mapped_coeff_abs, aps->alf_cc_cr_mapped_coeff_abs };
1156  const uint8_t (*sign[])[ALF_NUM_COEFF_CC] =
1157  {aps->alf_cc_cb_coeff_sign, aps->alf_cc_cr_coeff_sign };
1158  const int signaled[] = { aps->alf_cc_cb_filter_signal_flag, aps->alf_cc_cr_filter_signal_flag};
1159 
1160  alf->num_cc_filters[0] = aps->alf_cc_cb_filters_signalled_minus1 + 1;
1161  alf->num_cc_filters[1] = aps->alf_cc_cr_filters_signalled_minus1 + 1;
1162 
1163  for (int idx = 0; idx < 2; idx++) {
1164  if (signaled[idx]) {
1165  for (int i = 0; i < alf->num_cc_filters[idx]; i++)
1166  alf_coeff_cc(alf->cc_coeff[idx][i], abs[idx][i], sign[idx][i]);
1167  }
1168  }
1169 }
1170 
1171 static void alf_derive(VVCALF *alf, const H266RawAPS *aps)
1172 {
1173  alf_luma(alf, aps);
1174  alf_chroma(alf, aps);
1175  alf_cc(alf, aps);
1176 }
1177 
1178 static void alf_free(AVRefStructOpaque unused, void *obj)
1179 {
1180  VVCALF *alf = obj;
1181 
1182  av_refstruct_unref(&alf->r);
1183 }
1184 
1185 static int aps_decode_alf(const VVCALF **alf, const H266RawAPS *aps)
1186 {
1187  VVCALF *a = av_refstruct_alloc_ext(sizeof(*a), 0, NULL, alf_free);
1188  if (!a)
1189  return AVERROR(ENOMEM);
1190 
1191  alf_derive(a, aps);
1192  av_refstruct_replace(&a->r, aps);
1193  av_refstruct_replace(alf, a);
1195 
1196  return 0;
1197 }
1198 
1199 static int is_luma_list(const int id)
1200 {
1201  return id % VVC_MAX_SAMPLE_ARRAYS == SL_START_4x4 || id == SL_START_64x64 + 1;
1202 }
1203 
1204 static int derive_matrix_size(const int id)
1205 {
1206  return id < SL_START_4x4 ? 2 : (id < SL_START_8x8 ? 4 : 8);
1207 }
1208 
1209 // 7.4.3.20 Scaling list data semantics
1211 {
1212  for (int id = 0; id < SL_MAX_ID; id++) {
1213  const int matrix_size = derive_matrix_size(id);
1214  const int log2_size = av_log2(matrix_size);
1215  const int list_size = matrix_size * matrix_size;
1217  const uint8_t *pred;
1218  const int *scaling_list;
1219  int dc = 0;
1220 
1221  if (aps->aps_chroma_present_flag || is_luma_list(id)) {
1222  if (!aps->scaling_list_copy_mode_flag[id]) {
1223  int next_coef = 0;
1224 
1225  if (id >= SL_START_16x16)
1226  dc = next_coef = aps->scaling_list_dc_coef[id - SL_START_16x16];
1227 
1228  for (int i = 0; i < list_size; i++) {
1229  const int x = ff_vvc_diag_scan_x[3][3][i];
1230  const int y = ff_vvc_diag_scan_y[3][3][i];
1231 
1232  if (!(id >= SL_START_64x64 && x >= 4 && y >= 4))
1233  next_coef += aps->scaling_list_delta_coef[id][i];
1234  coeff[i] = next_coef;
1235  }
1236  }
1237  }
1238 
1239  //dc
1240  if (id >= SL_START_16x16) {
1241  if (!aps->scaling_list_copy_mode_flag[id] && !aps->scaling_list_pred_mode_flag[id]) {
1242  dc += 8;
1243  } else if (!aps->scaling_list_pred_id_delta[id]) {
1244  dc += 16;
1245  } else {
1246  const int ref_id = id - aps->scaling_list_pred_id_delta[id];
1247  if (ref_id >= SL_START_16x16)
1248  dc += sl->scaling_matrix_dc_rec[ref_id - SL_START_16x16];
1249  else
1250  dc += sl->scaling_matrix_rec[ref_id][0];
1251  }
1252  sl->scaling_matrix_dc_rec[id - SL_START_16x16] = dc & 255;
1253  }
1254 
1255  //ac
1256  scaling_list = aps->scaling_list_copy_mode_flag[id] ? ff_vvc_scaling_list0 : coeff;
1257  if (!aps->scaling_list_copy_mode_flag[id] && !aps->scaling_list_pred_mode_flag[id])
1259  else if (!aps->scaling_list_pred_id_delta[id])
1261  else
1262  pred = sl->scaling_matrix_rec[id - aps->scaling_list_pred_id_delta[id]];
1263  for (int i = 0; i < list_size; i++) {
1264  const int x = ff_vvc_diag_scan_x[log2_size][log2_size][i];
1265  const int y = ff_vvc_diag_scan_y[log2_size][log2_size][i];
1266  const int off = y * matrix_size + x;
1267  sl->scaling_matrix_rec[id][off] = (pred[off] + scaling_list[i]) & 255;
1268  }
1269  }
1270 }
1271 
1272 static int aps_decode_scaling(const VVCScalingList **scaling, const H266RawAPS *aps)
1273 {
1274  VVCScalingList *sl = av_refstruct_allocz(sizeof(*sl));
1275  if (!sl)
1276  return AVERROR(ENOMEM);
1277 
1278  scaling_derive(sl, aps);
1279  av_refstruct_replace(scaling, sl);
1280  av_refstruct_unref(&sl);
1281 
1282  return 0;
1283 }
1284 
1286 {
1287  const H266RawAPS *aps = unit->content_ref;
1288  int ret = 0;
1289 
1290  if (!aps)
1291  return AVERROR_INVALIDDATA;
1292 
1293  switch (aps->aps_params_type) {
1294  case VVC_ASP_TYPE_ALF:
1295  ret = aps_decode_alf(&ps->alf_list[aps->aps_adaptation_parameter_set_id], aps);
1296  break;
1297  case VVC_ASP_TYPE_LMCS:
1298  av_refstruct_replace(&ps->lmcs_list[aps->aps_adaptation_parameter_set_id], aps);
1299  break;
1300  case VVC_ASP_TYPE_SCALING:
1301  ret = aps_decode_scaling(&ps->scaling_list[aps->aps_adaptation_parameter_set_id], aps);
1302  break;
1303  }
1304 
1305  return ret;
1306 }
1307 
1308 static int sh_alf_aps(const VVCSH *sh, const VVCFrameParamSets *fps)
1309 {
1310  if (!sh->r->sh_alf_enabled_flag)
1311  return 0;
1312 
1313  for (int i = 0; i < sh->r->sh_num_alf_aps_ids_luma; i++) {
1314  const VVCALF *alf_aps_luma = fps->alf_list[sh->r->sh_alf_aps_id_luma[i]];
1315  if (!alf_aps_luma)
1316  return AVERROR_INVALIDDATA;
1317  }
1318 
1319  if (sh->r->sh_alf_cb_enabled_flag || sh->r->sh_alf_cr_enabled_flag) {
1320  const VVCALF *alf_aps_chroma = fps->alf_list[sh->r->sh_alf_aps_id_chroma];
1321  if (!alf_aps_chroma)
1322  return AVERROR_INVALIDDATA;
1323  }
1324 
1325  if (fps->sps->r->sps_ccalf_enabled_flag) {
1326  if (sh->r->sh_alf_cc_cb_enabled_flag) {
1327  const VVCALF *alf_aps_cc_cr = fps->alf_list[sh->r->sh_alf_cc_cb_aps_id];
1328  if (!alf_aps_cc_cr)
1329  return AVERROR_INVALIDDATA;
1330  }
1331  if (sh->r->sh_alf_cc_cr_enabled_flag) {
1332  const VVCALF *alf_aps_cc_cr = fps->alf_list[sh->r->sh_alf_cc_cr_aps_id];
1333  if (!alf_aps_cc_cr)
1334  return AVERROR_INVALIDDATA;
1335  }
1336  }
1337 
1338  return 0;
1339 }
1340 
1341 static int sh_slice_address(VVCSH *sh, const H266RawSPS *sps, const VVCPPS *pps)
1342 {
1343  const int slice_address = sh->r->sh_slice_address;
1344 
1345  if (pps->r->pps_rect_slice_flag) {
1346  int pic_level_slice_idx = slice_address;
1347  for (int j = 0; j < sh->r->curr_subpic_idx; j++)
1348  pic_level_slice_idx += pps->r->num_slices_in_subpic[j];
1349  sh->ctb_addr_in_curr_slice = pps->ctb_addr_in_slice + pps->slice_start_offset[pic_level_slice_idx];
1350  sh->num_ctus_in_curr_slice = pps->num_ctus_in_slice[pic_level_slice_idx];
1351  } else {
1352  int tile_x = slice_address % pps->r->num_tile_columns;
1353  int tile_y = slice_address / pps->r->num_tile_columns;
1354  const int slice_start_ctb = pps->row_bd[tile_y] * pps->ctb_width + pps->col_bd[tile_x] * pps->r->row_height_val[tile_y];
1355 
1356  sh->ctb_addr_in_curr_slice = pps->ctb_addr_in_slice + slice_start_ctb;
1357 
1358  sh->num_ctus_in_curr_slice = 0;
1359  for (int tile_idx = slice_address; tile_idx <= slice_address + sh->r->sh_num_tiles_in_slice_minus1; tile_idx++) {
1360  tile_x = tile_idx % pps->r->num_tile_columns;
1361  tile_y = tile_idx / pps->r->num_tile_columns;
1362  sh->num_ctus_in_curr_slice += pps->r->row_height_val[tile_y] * pps->r->col_width_val[tile_x];
1363  }
1364  }
1365 
1366  if (!sh->num_ctus_in_curr_slice)
1367  return AVERROR_INVALIDDATA;
1368 
1369  return 0;
1370 }
1371 
1372 static void sh_qp_y(VVCSH *sh, const H266RawPPS *pps, const H266RawPictureHeader *ph)
1373 {
1374  const int init_qp = pps->pps_init_qp_minus26 + 26;
1375 
1376  if (!pps->pps_qp_delta_info_in_ph_flag)
1377  sh->slice_qp_y = init_qp + sh->r->sh_qp_delta;
1378  else
1379  sh->slice_qp_y = init_qp + ph->ph_qp_delta;
1380 }
1381 
1382 static void sh_inter(VVCSH *sh, const H266RawSPS *sps, const H266RawPPS *pps)
1383 {
1384  const H266RawSliceHeader *rsh = sh->r;
1385 
1386  if (!pps->pps_wp_info_in_ph_flag &&
1387  ((pps->pps_weighted_pred_flag && IS_P(rsh)) ||
1388  (pps->pps_weighted_bipred_flag && IS_B(rsh))))
1390 }
1391 
1392 static void sh_deblock_offsets(VVCSH *sh)
1393 {
1394  const H266RawSliceHeader *r = sh->r;
1395 
1396  if (!r->sh_deblocking_filter_disabled_flag) {
1397  sh->deblock.beta_offset[LUMA] = r->sh_luma_beta_offset_div2 * 2;
1398  sh->deblock.tc_offset[LUMA] = r->sh_luma_tc_offset_div2 * 2;
1399  sh->deblock.beta_offset[CB] = r->sh_cb_beta_offset_div2 * 2;
1400  sh->deblock.tc_offset[CB] = r->sh_cb_tc_offset_div2 * 2;
1401  sh->deblock.beta_offset[CR] = r->sh_cr_beta_offset_div2 * 2;
1402  sh->deblock.tc_offset[CR] = r->sh_cr_tc_offset_div2 * 2;
1403  }
1404 }
1405 
1407 {
1408  const int min_cb_log2_size_y = sps->sps_log2_min_luma_coding_block_size_minus2 + 2;
1409  int min_qt_log2_size_y[2];
1410 
1411  if (IS_I(sh->r)) {
1412  min_qt_log2_size_y[LUMA] = (min_cb_log2_size_y + ph->ph_log2_diff_min_qt_min_cb_intra_slice_luma);
1413  min_qt_log2_size_y[CHROMA] = (min_cb_log2_size_y + ph->ph_log2_diff_min_qt_min_cb_intra_slice_chroma);
1414 
1415  sh->max_bt_size[LUMA] = 1 << (min_qt_log2_size_y[LUMA] + ph->ph_log2_diff_max_bt_min_qt_intra_slice_luma);
1416  sh->max_bt_size[CHROMA] = 1 << (min_qt_log2_size_y[CHROMA]+ ph->ph_log2_diff_max_bt_min_qt_intra_slice_chroma);
1417 
1418  sh->max_tt_size[LUMA] = 1 << (min_qt_log2_size_y[LUMA] + ph->ph_log2_diff_max_tt_min_qt_intra_slice_luma);
1419  sh->max_tt_size[CHROMA] = 1 << (min_qt_log2_size_y[CHROMA]+ ph->ph_log2_diff_max_tt_min_qt_intra_slice_chroma);
1420 
1421  sh->max_mtt_depth[LUMA] = ph->ph_max_mtt_hierarchy_depth_intra_slice_luma;
1422  sh->max_mtt_depth[CHROMA] = ph->ph_max_mtt_hierarchy_depth_intra_slice_chroma;
1423 
1424  sh->cu_qp_delta_subdiv = ph->ph_cu_qp_delta_subdiv_intra_slice;
1425  sh->cu_chroma_qp_offset_subdiv = ph->ph_cu_chroma_qp_offset_subdiv_intra_slice;
1426  } else {
1427  for (int i = LUMA; i <= CHROMA; i++) {
1428  min_qt_log2_size_y[i] = (min_cb_log2_size_y + ph->ph_log2_diff_min_qt_min_cb_inter_slice);
1429  sh->max_bt_size[i] = 1 << (min_qt_log2_size_y[i] + ph->ph_log2_diff_max_bt_min_qt_inter_slice);
1430  sh->max_tt_size[i] = 1 << (min_qt_log2_size_y[i] + ph->ph_log2_diff_max_tt_min_qt_inter_slice);
1431  sh->max_mtt_depth[i] = ph->ph_max_mtt_hierarchy_depth_inter_slice;
1432  }
1433 
1434  sh->cu_qp_delta_subdiv = ph->ph_cu_qp_delta_subdiv_inter_slice;
1435  sh->cu_chroma_qp_offset_subdiv = ph->ph_cu_chroma_qp_offset_subdiv_inter_slice;
1436  }
1437 
1438  sh->min_qt_size[LUMA] = 1 << min_qt_log2_size_y[LUMA];
1439  sh->min_qt_size[CHROMA] = 1 << min_qt_log2_size_y[CHROMA];
1440 }
1441 
1442 static void sh_entry_points(VVCSH *sh, const H266RawSPS *sps, const VVCPPS *pps)
1443 {
1444  if (sps->sps_entry_point_offsets_present_flag) {
1445  for (int i = 1, j = 0; i < sh->num_ctus_in_curr_slice; i++) {
1446  const int pre_ctb_addr_x = sh->ctb_addr_in_curr_slice[i - 1] % pps->ctb_width;
1447  const int pre_ctb_addr_y = sh->ctb_addr_in_curr_slice[i - 1] / pps->ctb_width;
1448  const int ctb_addr_x = sh->ctb_addr_in_curr_slice[i] % pps->ctb_width;
1449  const int ctb_addr_y = sh->ctb_addr_in_curr_slice[i] / pps->ctb_width;
1450  if (pps->ctb_to_row_bd[ctb_addr_y] != pps->ctb_to_row_bd[pre_ctb_addr_y] ||
1451  pps->ctb_to_col_bd[ctb_addr_x] != pps->ctb_to_col_bd[pre_ctb_addr_x] ||
1452  (ctb_addr_y != pre_ctb_addr_y && sps->sps_entropy_coding_sync_enabled_flag)) {
1453  sh->entry_point_start_ctu[j++] = i;
1454  }
1455  }
1456  }
1457 }
1458 
1459 static int sh_derive(VVCSH *sh, const VVCFrameParamSets *fps)
1460 {
1461  const H266RawSPS *sps = fps->sps->r;
1462  const H266RawPPS *pps = fps->pps->r;
1463  const H266RawPictureHeader *ph = fps->ph.r;
1464  int ret;
1465 
1466  ret = sh_slice_address(sh, sps, fps->pps);
1467  if (ret < 0)
1468  return ret;
1469  ret = sh_alf_aps(sh, fps);
1470  if (ret < 0)
1471  return ret;
1472  sh_inter(sh, sps, pps);
1473  sh_qp_y(sh, pps, ph);
1474  sh_deblock_offsets(sh);
1476  sh_entry_points(sh, sps, fps->pps);
1477 
1478  return 0;
1479 }
1480 
1482 {
1483  int ret;
1484 
1485  if (!fps->sps || !fps->pps)
1486  return AVERROR_INVALIDDATA;
1487 
1488  av_refstruct_replace(&sh->r, unit->content_ref);
1489 
1490  ret = sh_derive(sh, fps);
1491  if (ret < 0)
1492  return ret;
1493 
1494  return 0;
1495 }
H266RawVUI::vui_colour_primaries
uint8_t vui_colour_primaries
Definition: cbs_h266.h:228
VVCSPS
Definition: ps.h:58
sh_slice_address
static int sh_slice_address(VVCSH *sh, const H266RawSPS *sps, const VVCPPS *pps)
Definition: ps.c:1341
H266RawSPS::sps_subpic_height_minus1
uint16_t sps_subpic_height_minus1[VVC_MAX_SLICES]
Definition: cbs_h266.h:338
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
VVCSH::cu_qp_delta_subdiv
uint8_t cu_qp_delta_subdiv
CuQpDeltaSubdiv.
Definition: ps.h:261
H266RawSliceHeader::sh_alf_cc_cr_enabled_flag
uint8_t sh_alf_cc_cr_enabled_flag
Definition: cbs_h266.h:791
CodedBitstreamUnit::content_ref
void * content_ref
If content is reference counted, a RefStruct reference backing content.
Definition: cbs.h:119
VVCSH::num_ctus_in_curr_slice
uint32_t num_ctus_in_curr_slice
NumCtusInCurrSlice.
Definition: ps.h:243
VVCPH
Definition: ps.h:147
VVCPPS
Definition: ps.h:92
av_clip
#define av_clip
Definition: common.h:100
VVCLMCS::min_bin_idx
uint8_t min_bin_idx
Definition: ps.h:202
cbs_h266.h
r
const char * r
Definition: vf_curves.c:127
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
LUMA
#define LUMA
Definition: filter.c:31
H266RawSPS::sps_log2_ctu_size_minus5
uint8_t sps_log2_ctu_size_minus5
Definition: cbs_h266.h:315
ff_vvc_decode_frame_ps
int ff_vvc_decode_frame_ps(struct VVCFrameContext *fc, struct VVCContext *s)
Definition: ps.c:1058
H266RawVUI::vui_aspect_ratio_info_present_flag
uint8_t vui_aspect_ratio_info_present_flag
Definition: cbs_h266.h:217
VVCSH::entry_point_start_ctu
uint32_t entry_point_start_ctu[VVC_MAX_ENTRY_POINTS]
entry point start in ctu_addr
Definition: ps.h:265
VVCPPS::r
const H266RawPPS * r
RefStruct reference.
Definition: ps.h:93
SL_MAX_MATRIX_SIZE
#define SL_MAX_MATRIX_SIZE
Definition: ps.h:194
CB
#define CB
Definition: filter.c:32
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
AVRefStructOpaque
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition: refstruct.h:58
VVCSH::cu_chroma_qp_offset_subdiv
uint8_t cu_chroma_qp_offset_subdiv
CuChromaQpOffsetSubdiv.
Definition: ps.h:262
alf_derive
static void alf_derive(VVCALF *alf, const H266RawAPS *aps)
Definition: ps.c:1171
LMCS_MAX_BIN_SIZE
#define LMCS_MAX_BIN_SIZE
Definition: ps.h:48
IS_P
#define IS_P(rsh)
Definition: ps.h:39
data.h
scale_coeff
static av_always_inline int scale_coeff(const TransformBlock *tb, int coeff, const int scale, const int scale_m, const int log2_transform_range)
Definition: intra.c:395
ph
static int FUNC() ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
Definition: cbs_h266_syntax_template.c:3037
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:777
H266RawSPS::sps_subpic_ctu_top_left_y
uint16_t sps_subpic_ctu_top_left_y[VVC_MAX_SLICES]
Definition: cbs_h266.h:336
aps_decode_scaling
static int aps_decode_scaling(const VVCScalingList **scaling, const H266RawAPS *aps)
Definition: ps.c:1272
VVCLMCS::max_bin_idx
uint8_t max_bin_idx
Definition: ps.h:203
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:669
H266RawAPS::lmcs_delta_abs_crs
uint8_t lmcs_delta_abs_crs
Definition: cbs_h266.h:639
H266RawSPS::sps_ccalf_enabled_flag
uint8_t sps_ccalf_enabled_flag
Definition: cbs_h266.h:404
H266RawSliceHeader::sh_qp_delta
int8_t sh_qp_delta
Definition: cbs_h266.h:807
sh_qp_y
static void sh_qp_y(VVCSH *sh, const H266RawPPS *pps, const H266RawPictureHeader *ph)
Definition: ps.c:1372
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:539
VVCSH::r
const H266RawSliceHeader * r
RefStruct reference.
Definition: ps.h:239
pps_single_slice_per_subpic
static int pps_single_slice_per_subpic(VVCPPS *pps, const VVCSPS *sps, int *off)
Definition: ps.c:507
sps_chroma_qp_table
static int sps_chroma_qp_table(VVCSPS *sps)
Definition: ps.c:91
pps_subpic
static void pps_subpic(VVCPPS *pps, const VVCSPS *sps)
Definition: ps.c:654
decode_ph
static int decode_ph(VVCFrameParamSets *fps, const H266RawPictureHeader *rph, void *rph_ref, const int poc_tid0, const int is_clvss)
Definition: ps.c:987
pps_add_ctus
static int pps_add_ctus(VVCPPS *pps, int *off, const int rx, const int ry, const int w, const int h)
Definition: ps.c:408
max
#define max(a, b)
Definition: cuda_runtime.h:33
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
H266RawPPS::pps_seq_parameter_set_id
uint8_t pps_seq_parameter_set_id
Definition: cbs_h266.h:500
VVCLMCS
Definition: ps.h:201
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
H266RawAPS::lmcs_delta_max_bin_idx
uint8_t lmcs_delta_max_bin_idx
Definition: cbs_h266.h:635
pps_alloc
static const VVCPPS * pps_alloc(const H266RawPPS *rpps, const VVCSPS *sps)
Definition: ps.c:706
VVCALF::num_chroma_filters
uint8_t num_chroma_filters
Definition: ps.h:176
SL_MAX_ID
@ SL_MAX_ID
Definition: ps.h:191
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:77
sps_derive
static int sps_derive(VVCSPS *sps, AVCodecContext *c)
Definition: ps.c:231
sh_inter
static void sh_inter(VVCSH *sh, const H266RawSPS *sps, const H266RawPPS *pps)
Definition: ps.c:1382
decode_pps
static int decode_pps(VVCParamSets *ps, const H266RawPPS *rpps)
Definition: ps.c:727
VVCLMCS::chroma_scale_coeff
uint16_t chroma_scale_coeff[LMCS_MAX_BIN_SIZE]
Definition: ps.h:211
VVCLMCS::fwd_lut
union VVCLMCS::@336 fwd_lut
VVC_MAX_TILES_PER_AU
@ VVC_MAX_TILES_PER_AU
Definition: vvc.h:136
JCBCR
#define JCBCR
Definition: dec.h:39
pps_subpic_one_or_more_tiles_slice
static int pps_subpic_one_or_more_tiles_slice(VVCPPS *pps, const int tile_x, const int tile_y, const int x_end, const int y_end, const int i, int *off)
Definition: ps.c:476
MIN_PU_LOG2
#define MIN_PU_LOG2
Definition: dec.h:42
H266RawSliceHeader::sh_alf_cc_cr_aps_id
uint8_t sh_alf_cc_cr_aps_id
Definition: cbs_h266.h:792
ps.h
VVCFrameParamSets::sps
const VVCSPS * sps
RefStruct reference.
Definition: ps.h:230
VVC_ASP_TYPE_ALF
@ VVC_ASP_TYPE_ALF
Definition: vvc.h:70
av_color_space_name
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:3856
ALF_NUM_COEFF_CHROMA
#define ALF_NUM_COEFF_CHROMA
Definition: ps.h:168
VVCFrameParamSets
Definition: ps.h:229
pps_slice_map
static int pps_slice_map(VVCPPS *pps, const VVCSPS *sps)
Definition: ps.c:628
fail
#define fail()
Definition: checkasm.h:208
VVCSH::pwt
PredWeightTable pwt
Definition: ps.h:247
H266RawSPS::sps_subpic_width_minus1
uint16_t sps_subpic_width_minus1[VVC_MAX_SLICES]
Definition: cbs_h266.h:337
IS_B
#define IS_B(rsh)
Definition: ps.h:40
H266RawAPS
Definition: cbs_h266.h:600
ff_vvc_decode_sh
int ff_vvc_decode_sh(VVCSH *sh, const VVCFrameParamSets *fps, const CodedBitstreamUnit *unit)
Definition: ps.c:1481
VVCParamSets::pps_list
const VVCPPS * pps_list[VVC_MAX_PPS_COUNT]
RefStruct reference.
Definition: ps.h:220
derive_matrix_size
static int derive_matrix_size(const int id)
Definition: ps.c:1204
VVCALF::cc_coeff
int16_t cc_coeff[2][ALF_NUM_FILTERS_CC][ALF_NUM_COEFF_CC]
Definition: ps.h:181
VVCFrameParamSets::sl
const VVCScalingList * sl
RefStruct reference.
Definition: ps.h:235
VVCALF
Definition: ps.h:171
H266RawSliceHeader::sh_alf_enabled_flag
uint8_t sh_alf_enabled_flag
Definition: cbs_h266.h:783
refstruct.h
ff_vvc_scaling_pred_16
const uint8_t ff_vvc_scaling_pred_16[8 *8]
Definition: data.c:288
ff_vvc_frame_ps_free
void ff_vvc_frame_ps_free(VVCFrameParamSets *fps)
Definition: ps.c:1078
EXTENDED_SAR
#define EXTENDED_SAR
Definition: ps.c:185
av_refstruct_allocz
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition: refstruct.h:105
VVCALF::chroma_clip_idx
uint8_t chroma_clip_idx[ALF_NUM_FILTERS_CHROMA][ALF_NUM_COEFF_CHROMA]
Definition: ps.h:178
GDR_SET_RECOVERED
#define GDR_SET_RECOVERED(s)
Definition: ps.h:44
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:542
sps_ladf
static void sps_ladf(VVCSPS *sps)
Definition: ps.c:171
H266RawSlice::ph_ref
void * ph_ref
RefStruct reference backing referred-to PH above.
Definition: cbs_h266.h:855
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
H266RawAPS::lmcs_delta_abs_cw
uint16_t lmcs_delta_abs_cw[16]
Definition: cbs_h266.h:637
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
H266RawVUI
Definition: cbs_h266.h:211
H266RawSlice::ph
H266RawPictureHeader * ph
Definition: cbs_h266.h:854
DBParams::beta_offset
int beta_offset
Definition: hevcdec.h:350
H266RawVUI::vui_full_range_flag
uint8_t vui_full_range_flag
Definition: cbs_h266.h:232
DBParams::tc_offset
int tc_offset
Definition: hevcdec.h:351
H266RawSPS::sps_seq_parameter_set_id
uint8_t sps_seq_parameter_set_id
Definition: cbs_h266.h:311
s
#define s(width, name)
Definition: cbs_vp9.c:198
H266RawSliceHeader::sh_slice_address
uint16_t sh_slice_address
Definition: cbs_h266.h:777
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:494
VVCFrameParamSets::lmcs
VVCLMCS lmcs
Definition: ps.h:234
av_refstruct_alloc_ext
static void * av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
A wrapper around av_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
Definition: refstruct.h:94
VVCSH
Definition: ps.h:238
decode.h
IS_IDR
#define IS_IDR(s)
Definition: hevcdec.h:74
PredWeightTable
Definition: ps.h:137
VVCFrameParamSets::ph
VVCPH ph
Definition: ps.h:232
decode_ps
static int decode_ps(VVCParamSets *ps, AVCodecContext *c, const SliceContext *sc, int is_clvss)
Definition: ps.c:748
ph_vb
static int ph_vb(VVCPH *ph, const H266RawSPS *sps, const H266RawPPS *pps)
Definition: ps.c:951
IS_GDR
#define IS_GDR(s)
Definition: ps.h:32
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
WEIGHT_TABLE
#define WEIGHT_TABLE(x)
Definition: ps.c:778
h2645data.h
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:639
VVCParamSets::sps_list
const VVCSPS * sps_list[VVC_MAX_SPS_COUNT]
RefStruct reference.
Definition: ps.h:219
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:519
if
if(ret)
Definition: filter_design.txt:179
H266RawSPS
Definition: cbs_h266.h:308
FF_CEIL_RSHIFT
#define FF_CEIL_RSHIFT
Definition: common.h:63
pred_weight_table
static void pred_weight_table(PredWeightTable *w, const H266RawPredWeightTable *r)
Definition: ps.c:793
H266RawPPS
Definition: cbs_h266.h:496
aps
static int FUNC() aps(CodedBitstreamContext *ctx, RWContext *rw, H266RawAPS *current, int prefix)
Definition: cbs_h266_syntax_template.c:2495
pps_free
static void pps_free(AVRefStructOpaque opaque, void *obj)
Definition: ps.c:693
decode_frame_ps
static int decode_frame_ps(VVCFrameParamSets *fps, const VVCParamSets *ps, const SliceContext *sc, const int poc_tid0, const int is_clvss, const VVCContext *s)
Definition: ps.c:1004
alf_coeff_cc
static void alf_coeff_cc(int16_t *coeff, const uint8_t *mapped_abs, const uint8_t *sign)
Definition: ps.c:1109
NULL
#define NULL
Definition: coverity.c:32
H266RawPictureHeader
Definition: cbs_h266.h:676
pps_subpic_slice
static int pps_subpic_slice(VVCPPS *pps, const VVCSPS *sps, const int i, int *off)
Definition: ps.c:493
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
lmcs_derive_lut_sample
static av_always_inline uint16_t lmcs_derive_lut_sample(uint16_t sample, uint16_t *pivot1, uint16_t *pivot2, uint16_t *scale_coeff, const int idx, const int max)
Definition: ps.c:830
H266RawPPS::pps_pic_parameter_set_id
uint8_t pps_pic_parameter_set_id
Definition: cbs_h266.h:499
H266RawSliceHeader::curr_subpic_idx
uint16_t curr_subpic_idx
CurrSubpicIdx.
Definition: cbs_h266.h:837
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
VVCFrameParamSets::alf_list
const VVCALF * alf_list[VVC_MAX_ALF_COUNT]
RefStruct reference.
Definition: ps.h:233
H266RawAPS::lmcs_delta_sign_cw_flag
uint8_t lmcs_delta_sign_cw_flag[16]
Definition: cbs_h266.h:638
ph_max_num_subblock_merge_cand
static int ph_max_num_subblock_merge_cand(const H266RawSPS *sps, const H266RawPictureHeader *ph)
Definition: ps.c:923
is_luma_list
static int is_luma_list(const int id)
Definition: ps.c:1199
sh_partition_constraints
static void sh_partition_constraints(VVCSH *sh, const H266RawSPS *sps, const H266RawPictureHeader *ph)
Definition: ps.c:1406
H266RawPredWeightTable
Definition: cbs_h266.h:652
VVCSH::max_tt_size
uint8_t max_tt_size[2]
MaxTtSizeY, MaxTtSizeC.
Definition: ps.h:259
VVC_ASP_TYPE_LMCS
@ VVC_ASP_TYPE_LMCS
Definition: vvc.h:71
ff_set_sar
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition: utils.c:106
sps_vui
static void sps_vui(AVCodecContext *c, const H266RawVUI *vui)
Definition: ps.c:186
av_color_primaries_name
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:3790
VVCParamSets::scaling_list
const VVCScalingList * scaling_list[VVC_MAX_SL_COUNT]
RefStruct reference.
Definition: ps.h:223
H266RawSliceHeader::sh_num_tiles_in_slice_minus1
uint8_t sh_num_tiles_in_slice_minus1
Definition: cbs_h266.h:779
abs
#define abs(x)
Definition: cuda_runtime.h:35
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:540
ph_vb_pos
static int ph_vb_pos(uint16_t *vbs, uint8_t *num_vbs, const uint16_t *pos_minus_1, const uint8_t num_pos, uint16_t max, const int ctb_size_y)
Definition: ps.c:930
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
ff_vvc_scaling_list0
const int ff_vvc_scaling_list0[8 *8]
Definition: data.c:299
alf_free
static void alf_free(AVRefStructOpaque unused, void *obj)
Definition: ps.c:1178
decode_recovery_poc
static void decode_recovery_poc(VVCContext *s, const VVCPH *ph)
Definition: ps.c:1048
VVCPH::r
const H266RawPictureHeader * r
Definition: ps.h:148
sps_partition_constraints
static void sps_partition_constraints(VVCSPS *sps)
Definition: ps.c:159
ff_vvc_diag_scan_y
const uint8_t ff_vvc_diag_scan_y[5][5][16 *16]
Definition: data.c:152
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
VVCALF::luma_coeff
int16_t luma_coeff[ALF_NUM_FILTERS_LUMA][ALF_NUM_COEFF_LUMA]
Definition: ps.h:173
pps_ref_wraparound_offset
static void pps_ref_wraparound_offset(VVCPPS *pps, const VVCSPS *sps)
Definition: ps.c:646
SliceContext
Definition: mss12.h:70
VVCFrameParamSets::pps
const VVCPPS * pps
RefStruct reference.
Definition: ps.h:231
H266RawVUI::vui_transfer_characteristics
uint8_t vui_transfer_characteristics
Definition: cbs_h266.h:230
sps_export_stream_params
static void sps_export_stream_params(AVCodecContext *c, const VVCSPS *sps)
Definition: ps.c:222
VVCSH::max_mtt_depth
uint8_t max_mtt_depth[2]
MaxMttDepthY, MaxMttDepthC.
Definition: ps.h:260
HEVCPPS::pps_id
unsigned int pps_id
Definition: ps.h:375
VVCScalingList
Definition: ps.h:196
H266RawSPS::sps_subpic_ctu_top_left_x
uint16_t sps_subpic_ctu_top_left_x[VVC_MAX_SLICES]
Definition: cbs_h266.h:335
dc
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
Definition: snow.txt:400
SL_START_64x64
@ SL_START_64x64
Definition: ps.h:190
shift
static int shift(int a, int b)
Definition: bonk.c:261
SL_START_16x16
@ SL_START_16x16
Definition: ps.h:188
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
subpic_tiles
static void subpic_tiles(int *tile_x, int *tile_y, int *tile_x_end, int *tile_y_end, const VVCSPS *sps, const VVCPPS *pps, const int i)
Definition: ps.c:440
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:544
sample
#define sample
Definition: flacdsp_template.c:44
size
int size
Definition: twinvq_data.h:10344
VVC_MAX_SAMPLE_ARRAYS
@ VVC_MAX_SAMPLE_ARRAYS
Definition: vvc.h:77
aps_decode_alf
static int aps_decode_alf(const VVCALF **alf, const H266RawAPS *aps)
Definition: ps.c:1185
H266RawVUI::vui_sar_height
uint16_t vui_sar_height
Definition: cbs_h266.h:222
VVCLMCS::inv_lut
union VVCLMCS::@336 inv_lut
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:546
ctu_rs
static int ctu_rs(const int rx, const int ry, const VVCPPS *pps)
Definition: ps.c:403
H266RawAPS::lmcs_min_bin_idx
uint8_t lmcs_min_bin_idx
Definition: cbs_h266.h:634
H266RawSliceHeader::sh_alf_aps_id_chroma
uint8_t sh_alf_aps_id_chroma
Definition: cbs_h266.h:788
SliceContext::ref
void * ref
RefStruct reference, backing slice data.
Definition: dec.h:119
sh_derive
static int sh_derive(VVCSH *sh, const VVCFrameParamSets *fps)
Definition: ps.c:1459
IS_CRA
#define IS_CRA(s)
Definition: ps.h:30
next_tile_idx
static int next_tile_idx(int tile_idx, const int i, const H266RawPPS *r)
Definition: ps.c:379
alf_coeff
static void alf_coeff(int16_t *coeff, const uint8_t *abs, const uint8_t *sign, const int size)
Definition: ps.c:1102
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
VVCSH::deblock
DBParams deblock
Definition: ps.h:254
VVCSH::ctb_addr_in_curr_slice
const uint32_t * ctb_addr_in_curr_slice
CtbAddrInCurrSlice.
Definition: ps.h:244
VVCScalingList::scaling_matrix_dc_rec
uint8_t scaling_matrix_dc_rec[SL_MAX_ID - SL_START_16x16]
ScalingMatrixDcRec[refId − 14].
Definition: ps.h:198
H266RawVUI::vui_sar_width
uint16_t vui_sar_width
Definition: cbs_h266.h:221
H266RawSliceHeader::sh_alf_cb_enabled_flag
uint8_t sh_alf_cb_enabled_flag
Definition: cbs_h266.h:786
SL_START_4x4
@ SL_START_4x4
Definition: ps.h:186
av_refstruct_unref
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
H266RawSliceHeader::sh_pred_weight_table
H266RawPredWeightTable sh_pred_weight_table
Definition: cbs_h266.h:805
H266RawSliceHeader
Definition: cbs_h266.h:771
VVCLMCS::pivot
uint16_t pivot[LMCS_MAX_BIN_SIZE+1]
Definition: ps.h:210
lmcs_derive_lut
static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266RawSPS *sps)
Definition: ps.c:839
pps_chroma_qp_offset
static void pps_chroma_qp_offset(VVCPPS *pps)
Definition: ps.c:311
CR
#define CR
Definition: filter.c:33
pps_derive
static int pps_derive(VVCPPS *pps, const VVCSPS *sps)
Definition: ps.c:672
H266RawSlice::pps
H266RawPPS * pps
RefStruct reference to referred-to PPS.
Definition: cbs_h266.h:853
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
sps_bit_depth
static int sps_bit_depth(VVCSPS *sps, void *log_ctx)
Definition: ps.c:80
H266RawSliceHeader::sh_alf_aps_id_luma
uint8_t sh_alf_aps_id_luma[8]
Definition: cbs_h266.h:785
ff_vvc_diag_scan_x
const uint8_t ff_vvc_diag_scan_x[5][5][16 *16]
Definition: data.c:27
sh_alf_aps
static int sh_alf_aps(const VVCSH *sh, const VVCFrameParamSets *fps)
Definition: ps.c:1308
scaling_derive
static void scaling_derive(VVCScalingList *sl, const H266RawAPS *aps)
Definition: ps.c:1210
pps_single_slice_picture
static int pps_single_slice_picture(VVCPPS *pps, int *off)
Definition: ps.c:423
pps_no_rect_slice
static int pps_no_rect_slice(VVCPPS *pps)
Definition: ps.c:610
sps_alloc
static const VVCSPS * sps_alloc(const H266RawSPS *rsps, AVCodecContext *c)
Definition: ps.c:259
VVCPH::rref
void * rref
RefStruct reference, backing ph above.
Definition: ps.h:149
ff_vvc_decode_aps
int ff_vvc_decode_aps(VVCParamSets *ps, const CodedBitstreamUnit *unit)
Definition: ps.c:1285
av_always_inline
#define av_always_inline
Definition: attributes.h:63
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
VVCLMCS::u16
uint16_t u16[LMCS_MAX_LUT_SIZE]
for high bit-depth
Definition: ps.h:207
ph_compute_poc
static int ph_compute_poc(const H266RawPictureHeader *ph, const H266RawSPS *sps, const int poc_tid0, const int is_clvss)
Definition: ps.c:806
ALF_NUM_COEFF_CC
#define ALF_NUM_COEFF_CC
Definition: ps.h:169
ff_h2645_pixel_aspect
const AVRational ff_h2645_pixel_aspect[]
Definition: h2645data.c:21
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:703
H266RawSliceHeader::sh_alf_cc_cb_aps_id
uint8_t sh_alf_cc_cb_aps_id
Definition: cbs_h266.h:790
pps_rect_slice
static int pps_rect_slice(VVCPPS *pps, const VVCSPS *sps)
Definition: ps.c:574
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:760
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
GDR_IS_RECOVERED
#define GDR_IS_RECOVERED(s)
Definition: ps.h:43
decode_sps
static int decode_sps(VVCParamSets *ps, AVCodecContext *c, const H266RawSPS *rsps, int is_clvss)
Definition: ps.c:280
H266RawAPS::lmcs_delta_sign_crs_flag
uint8_t lmcs_delta_sign_crs_flag
Definition: cbs_h266.h:640
decode_recovery_flag
static void decode_recovery_flag(VVCContext *s)
Definition: ps.c:1040
pps_width_height
static void pps_width_height(VVCPPS *pps, const VVCSPS *sps)
Definition: ps.c:323
ff_vvc_ps_uninit
void ff_vvc_ps_uninit(VVCParamSets *ps)
Definition: ps.c:1088
VVCALF::r
const H266RawAPS * r
Definition: ps.h:172
ret
ret
Definition: filter_design.txt:187
pred
static const float pred[4]
Definition: siprdata.h:259
ALF_NUM_COEFF_LUMA
#define ALF_NUM_COEFF_LUMA
Definition: ps.h:167
pps_one_tile_slices
static int pps_one_tile_slices(VVCPPS *pps, const int tile_idx, int i, int *off)
Definition: ps.c:525
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
H266RawSliceHeader::sh_alf_cc_cb_enabled_flag
uint8_t sh_alf_cc_cb_enabled_flag
Definition: cbs_h266.h:789
H266RawVUI::vui_colour_description_present_flag
uint8_t vui_colour_description_present_flag
Definition: cbs_h266.h:227
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:543
id
enum AVCodecID id
Definition: dts2pts.c:549
AVCodecContext
main external API structure.
Definition: avcodec.h:431
H266RawVUI::vui_matrix_coeffs
uint8_t vui_matrix_coeffs
Definition: cbs_h266.h:231
av_refstruct_replace
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition: refstruct.c:160
VVCParamSets::alf_list
const VVCALF * alf_list[VVC_MAX_ALF_COUNT]
RefStruct reference.
Definition: ps.h:221
VVCSH::slice_qp_y
int8_t slice_qp_y
SliceQpY.
Definition: ps.h:251
H266RawSPS::sps_num_subpics_minus1
uint16_t sps_num_subpics_minus1
Definition: cbs_h266.h:332
ctu_xy
static void ctu_xy(int *rx, int *ry, const int tile_x, const int tile_y, const VVCPPS *pps)
Definition: ps.c:397
VVC_ASP_TYPE_SCALING
@ VVC_ASP_TYPE_SCALING
Definition: vvc.h:72
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
pps
uint64_t pps
Definition: dovi_rpuenc.c:36
scaling_list
static int FUNC() scaling_list(CodedBitstreamContext *ctx, RWContext *rw, H264RawScalingList *current, int size_of_scaling_list)
Definition: cbs_h264_syntax_template.c:71
alf_luma
static void alf_luma(VVCALF *alf, const H266RawAPS *aps)
Definition: ps.c:1120
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
VVCLMCS::u8
uint8_t u8[LMCS_MAX_LUT_SIZE]
Definition: ps.h:206
ph_derive
static int ph_derive(VVCPH *ph, const H266RawSPS *sps, const H266RawPPS *pps, const int poc_tid0, const int is_clvss)
Definition: ps.c:970
H266RawVUI::vui_aspect_ratio_idc
uint8_t vui_aspect_ratio_idc
Definition: cbs_h266.h:219
pps_subpic_less_than_one_tile_slice
static int pps_subpic_less_than_one_tile_slice(VVCPPS *pps, const VVCSPS *sps, const int i, const int tx, const int ty, int *off)
Definition: ps.c:464
alf_cc
static void alf_cc(VVCALF *alf, const H266RawAPS *aps)
Definition: ps.c:1152
pps_bd
static int pps_bd(VVCPPS *pps)
Definition: ps.c:348
desc
const char * desc
Definition: libsvtav1.c:78
H266RawSlice::sps
H266RawSPS * sps
RefStruct reference to referred-to SPS.
Definition: cbs_h266.h:852
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
mem.h
VVCALF::luma_clip_idx
uint8_t luma_clip_idx[ALF_NUM_FILTERS_LUMA][ALF_NUM_COEFF_LUMA]
Definition: ps.h:174
pps_multi_tiles_slice
static int pps_multi_tiles_slice(VVCPPS *pps, const int tile_idx, const int i, int *off, bool *tile_in_slice)
Definition: ps.c:547
tile_xy
static void tile_xy(int *tile_x, int *tile_y, const int tile_idx, const VVCPPS *pps)
Definition: ps.c:391
VVCParamSets
Definition: ps.h:218
VVCSH::max_bt_size
uint8_t max_bt_size[2]
MaxBtSizeY, MaxBtSizeC.
Definition: ps.h:258
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
HEVCPPS::sps_id
unsigned int sps_id
seq_parameter_set_id
Definition: ps.h:376
IS_CLVSS
#define IS_CLVSS(s)
Definition: ps.h:34
sps_poc
static void sps_poc(VVCSPS *sps)
Definition: ps.c:138
VVCSPS::r
const H266RawSPS * r
RefStruct reference.
Definition: ps.h:59
VVCALF::num_cc_filters
uint8_t num_cc_filters[2]
alf_cc_cb_filters_signalled_minus1 + 1, alf_cc_cr_filters_signalled_minus1 + 1
Definition: ps.h:180
H266RawSliceHeader::sh_num_alf_aps_ids_luma
uint8_t sh_num_alf_aps_ids_luma
Definition: cbs_h266.h:784
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
sps_free
static void sps_free(AVRefStructOpaque opaque, void *obj)
Definition: ps.c:253
VVCFrameContext
Definition: dec.h:122
ALF_NUM_FILTERS_LUMA
#define ALF_NUM_FILTERS_LUMA
Definition: ps.h:163
IS_I
#define IS_I(rsh)
Definition: ps.h:38
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:80
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
VVCSH::min_qt_size
uint8_t min_qt_size[2]
MinQtSizeY, MinQtSizeC.
Definition: ps.h:257
SL_START_8x8
@ SL_START_8x8
Definition: ps.h:187
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
h
h
Definition: vp9dsp_template.c:2070
sps_inter
static void sps_inter(VVCSPS *sps)
Definition: ps.c:143
sh_deblock_offsets
static void sh_deblock_offsets(VVCSH *sh)
Definition: ps.c:1392
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:520
LMCS_MAX_BIT_DEPTH
#define LMCS_MAX_BIT_DEPTH
Definition: ps.h:46
H266RawSliceHeader::sh_alf_cr_enabled_flag
uint8_t sh_alf_cr_enabled_flag
Definition: cbs_h266.h:787
alf_chroma
static void alf_chroma(VVCALF *alf, const H266RawAPS *aps)
Definition: ps.c:1136
VBFS
#define VBFS(c, d)
Definition: ps.c:949
sh_entry_points
static void sh_entry_points(VVCSH *sh, const H266RawSPS *sps, const VVCPPS *pps)
Definition: ps.c:1442
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
VVCALF::chroma_coeff
int16_t chroma_coeff[ALF_NUM_FILTERS_CHROMA][ALF_NUM_COEFF_CHROMA]
Definition: ps.h:177
H266RawSPS::sps_subpic_treated_as_pic_flag
uint8_t sps_subpic_treated_as_pic_flag[VVC_MAX_SLICES]
Definition: cbs_h266.h:339
av_color_transfer_name
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:3823
VVCParamSets::sps_id_used
uint16_t sps_id_used
Definition: ps.h:226
sps_map_pixel_format
static int sps_map_pixel_format(VVCSPS *sps, void *log_ctx)
Definition: ps.c:35
VVCParamSets::lmcs_list
const H266RawAPS * lmcs_list[VVC_MAX_LMCS_COUNT]
RefStruct reference.
Definition: ps.h:222
ff_vvc_scaling_pred_8
const uint8_t ff_vvc_scaling_pred_8[8 *8]
Definition: data.c:277
MIN_TU_LOG2
#define MIN_TU_LOG2
MinTbLog2SizeY.
Definition: dec.h:41
H266RawSlice
Definition: cbs_h266.h:843
VVCContext
Definition: dec.h:218
VVCScalingList::scaling_matrix_rec
uint8_t scaling_matrix_rec[SL_MAX_ID][SL_MAX_MATRIX_SIZE *SL_MAX_MATRIX_SIZE]
ScalingMatrixRec.
Definition: ps.h:197
dec.h
VVC_MAX_POINTS_IN_QP_TABLE
@ VVC_MAX_POINTS_IN_QP_TABLE
Definition: vvc.h:121