FFmpeg
dec.c
Go to the documentation of this file.
1 /*
2  * VVC video decoder
3  *
4  * Copyright (C) 2021 Nuo Mi
5  * Copyright (C) 2022 Xu Mu
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
24 #include "libavcodec/decode.h"
26 #include "libavcodec/hwconfig.h"
27 #include "libavcodec/profiles.h"
28 #include "libavutil/refstruct.h"
30 #include "libavcodec/thread.h"
31 #include "libavutil/cpu.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/thread.h"
35 
36 #include "dec.h"
37 #include "ctu.h"
38 #include "data.h"
39 #include "refs.h"
40 #include "thread.h"
41 #include "config_components.h"
42 
43 #define TAB_MAX 32
44 
45 typedef struct Tab {
46  void **tab;
47  size_t size;
48 } Tab;
49 
50 typedef struct TabList {
52  int nb_tabs;
53 
54  int zero;
55  int realloc;
56 } TabList;
57 
58 #define TL_ADD(t, s) do { \
59  av_assert0(l->nb_tabs < TAB_MAX); \
60  l->tabs[l->nb_tabs].tab = (void**)&fc->tab.t; \
61  l->tabs[l->nb_tabs].size = sizeof(*fc->tab.t) * (s); \
62  l->nb_tabs++; \
63 } while (0)
64 
65 static void tl_init(TabList *l, const int zero, const int realloc)
66 {
67  l->nb_tabs = 0;
68  l->zero = zero;
69  l->realloc = realloc;
70 }
71 
72 static int tl_free(TabList *l)
73 {
74  for (int i = 0; i < l->nb_tabs; i++)
75  av_freep(l->tabs[i].tab);
76 
77  return 0;
78 }
79 
80 static int tl_create(TabList *l)
81 {
82  if (l->realloc) {
83  tl_free(l);
84 
85  for (int i = 0; i < l->nb_tabs; i++) {
86  Tab *t = l->tabs + i;
87  *t->tab = l->zero ? av_mallocz(t->size) : av_malloc(t->size);
88  if (!*t->tab)
89  return AVERROR(ENOMEM);
90  }
91  }
92  return 0;
93 }
94 
95 static int tl_zero(TabList *l)
96 {
97  if (l->zero) {
98  for (int i = 0; i < l->nb_tabs; i++) {
99  Tab *t = l->tabs + i;
100  memset(*t->tab, 0, t->size);
101  }
102  }
103  return 0;
104 }
105 
107 {
108  const VVCSPS *sps = fc->ps.sps;
109  const VVCPPS *pps = fc->ps.pps;
110  const int ctu_size = sps ? (1 << sps->ctb_log2_size_y << sps->ctb_log2_size_y) : 0;
111  const int ctu_count = pps ? pps->ctb_count : 0;
112  const int changed = fc->tab.sz.ctu_count != ctu_count || fc->tab.sz.ctu_size != ctu_size;
113 
114  tl_init(l, 0, changed);
115 
116  TL_ADD(cus, ctu_count);
117  TL_ADD(ctus, ctu_count);
118  TL_ADD(deblock, ctu_count);
119  TL_ADD(sao, ctu_count);
120  TL_ADD(alf, ctu_count);
121  TL_ADD(slice_idx, ctu_count);
122  TL_ADD(coeffs, ctu_count * ctu_size * VVC_MAX_SAMPLE_ARRAYS);
123 }
124 
126 {
127  const VVCPPS *pps = fc->ps.pps;
128  const int pic_size_in_min_cb = pps ? pps->min_cb_width * pps->min_cb_height : 0;
129  const int changed = fc->tab.sz.pic_size_in_min_cb != pic_size_in_min_cb;
130 
131  tl_init(l, 1, changed);
132 
133  TL_ADD(imf, pic_size_in_min_cb);
134 
135  for (int i = LUMA; i <= CHROMA; i++)
136  TL_ADD(cb_width[i], pic_size_in_min_cb); //is_a0_available requires this
137 }
138 
140 {
141  const VVCPPS *pps = fc->ps.pps;
142  const int pic_size_in_min_cb = pps ? pps->min_cb_width * pps->min_cb_height : 0;
143  const int changed = fc->tab.sz.pic_size_in_min_cb != pic_size_in_min_cb;
144 
145  tl_init(l, 0, changed);
146 
147  TL_ADD(skip, pic_size_in_min_cb);
148  TL_ADD(ipm, pic_size_in_min_cb);
149 
150  for (int i = LUMA; i <= CHROMA; i++) {
151  TL_ADD(cqt_depth[i], pic_size_in_min_cb);
152  TL_ADD(cb_pos_x[i], pic_size_in_min_cb);
153  TL_ADD(cb_pos_y[i], pic_size_in_min_cb);
154  TL_ADD(cb_height[i], pic_size_in_min_cb);
155  TL_ADD(cp_mv[i], pic_size_in_min_cb * MAX_CONTROL_POINTS);
156  TL_ADD(cpm[i], pic_size_in_min_cb);
157  TL_ADD(pcmf[i], pic_size_in_min_cb);
158  }
159  // For luma, qp can only change at the CU level, so the qp tab size is related to the CU.
160  TL_ADD(qp[LUMA], pic_size_in_min_cb);
161 }
162 
164 {
165  const VVCPPS *pps = fc->ps.pps;
166  const int pic_size_in_min_pu = pps ? pps->min_pu_width * pps->min_pu_height : 0;
167  const int changed = fc->tab.sz.pic_size_in_min_pu != pic_size_in_min_pu;
168 
169  tl_init(l, 1, changed);
170 
171  TL_ADD(iaf, pic_size_in_min_pu);
172 }
173 
175 {
176  const VVCPPS *pps = fc->ps.pps;
177  const int pic_size_in_min_pu = pps ? pps->min_pu_width * pps->min_pu_height : 0;
178  const int changed = fc->tab.sz.pic_size_in_min_pu != pic_size_in_min_pu;
179 
180  tl_init(l, 0, changed);
181 
182  TL_ADD(msf, pic_size_in_min_pu);
183  TL_ADD(mmi, pic_size_in_min_pu);
184  TL_ADD(mvf, pic_size_in_min_pu);
185 }
186 
188 {
189  const VVCPPS *pps = fc->ps.pps;
190  const int pic_size_in_min_tu = pps ? pps->min_tu_width * pps->min_tu_height : 0;
191  const int changed = fc->tab.sz.pic_size_in_min_tu != pic_size_in_min_tu;
192 
193  tl_init(l, 1, changed);
194 
195  TL_ADD(tu_joint_cbcr_residual_flag, pic_size_in_min_tu);
196 
197  for (int i = 0; i < VVC_MAX_SAMPLE_ARRAYS; i++) {
198  TL_ADD(tu_coded_flag[i], pic_size_in_min_tu);
199 
200  for (int vertical = 0; vertical < 2; vertical++)
201  TL_ADD(bs[vertical][i], pic_size_in_min_tu);
202  }
203 }
204 
206 {
207  const VVCPPS *pps = fc->ps.pps;
208  const int pic_size_in_min_tu = pps ? pps->min_tu_width * pps->min_tu_height : 0;
209  const int changed = fc->tab.sz.pic_size_in_min_tu != pic_size_in_min_tu;
210 
211  tl_init(l, 0, changed);
212 
213  for (int i = LUMA; i <= CHROMA; i++) {
214  TL_ADD(tb_width[i], pic_size_in_min_tu);
215  TL_ADD(tb_height[i], pic_size_in_min_tu);
216  }
217 
218  for (int vertical = 0; vertical < 2; vertical++) {
219  TL_ADD(max_len_p[vertical], pic_size_in_min_tu);
220  TL_ADD(max_len_q[vertical], pic_size_in_min_tu);
221  }
222 
223  // For chroma, considering the joint CbCr, the QP tab size is related to the TU.
224  for (int i = CB; i < VVC_MAX_SAMPLE_ARRAYS; i++)
225  TL_ADD(qp[i], pic_size_in_min_tu);
226 }
227 
229 {
230  const VVCSPS *sps = fc->ps.sps;
231  const VVCPPS *pps = fc->ps.pps;
232  const int width = pps ? pps->width : 0;
233  const int height = pps ? pps->height : 0;
234  const int ctu_width = pps ? pps->ctb_width : 0;
235  const int ctu_height = pps ? pps->ctb_height : 0;
236  const int chroma_idc = sps ? sps->r->sps_chroma_format_idc : 0;
237  const int ps = sps ? sps->pixel_shift : 0;
238  const int c_end = chroma_idc ? VVC_MAX_SAMPLE_ARRAYS : 1;
239  const int changed = fc->tab.sz.chroma_format_idc != chroma_idc ||
240  fc->tab.sz.width != width || fc->tab.sz.height != height ||
241  fc->tab.sz.ctu_width != ctu_width || fc->tab.sz.ctu_height != ctu_height ||
242  fc->tab.sz.pixel_shift != ps;
243 
244  tl_init(l, 0, changed);
245 
246  for (int c_idx = 0; c_idx < c_end; c_idx++) {
247  const int w = width >> (sps ? sps->hshift[c_idx] : 0);
248  const int h = height >> (sps ? sps->vshift[c_idx] : 0);
249  TL_ADD(sao_pixel_buffer_h[c_idx], (w * 2 * ctu_height) << ps);
250  TL_ADD(sao_pixel_buffer_v[c_idx], (h * 2 * ctu_width) << ps);
251  }
252 
253  for (int c_idx = 0; c_idx < c_end; c_idx++) {
254  const int w = width >> (sps ? sps->hshift[c_idx] : 0);
255  const int h = height >> (sps ? sps->vshift[c_idx] : 0);
256  const int border_pixels = c_idx ? ALF_BORDER_CHROMA : ALF_BORDER_LUMA;
257  for (int i = 0; i < 2; i++) {
258  TL_ADD(alf_pixel_buffer_h[c_idx][i], (w * border_pixels * ctu_height) << ps);
259  TL_ADD(alf_pixel_buffer_v[c_idx][i], h * ALF_PADDING_SIZE * ctu_width);
260  }
261  }
262 }
263 
265 {
266  const VVCPPS *pps = fc->ps.pps;
267  const int w32 = pps ? AV_CEIL_RSHIFT(pps->width, 5) : 0;
268  const int h32 = pps ? AV_CEIL_RSHIFT(pps->height, 5) : 0;
269  const int changed = AV_CEIL_RSHIFT(fc->tab.sz.width, 5) != w32 ||
270  AV_CEIL_RSHIFT(fc->tab.sz.height, 5) != h32;
271 
272  tl_init(l, 1, changed);
273 
274  for (int i = LUMA; i <= CHROMA; i++)
275  TL_ADD(msm[i], w32 * h32);
276 }
277 
279 {
280  const VVCPPS *pps = fc->ps.pps;
281  const int w64 = pps ? AV_CEIL_RSHIFT(pps->width, 6) : 0;
282  const int h64 = pps ? AV_CEIL_RSHIFT(pps->height, 6) : 0;
283  const int changed = AV_CEIL_RSHIFT(fc->tab.sz.width, 6) != w64 ||
284  AV_CEIL_RSHIFT(fc->tab.sz.height, 6) != h64;
285 
286  tl_init(l, 1, changed);
287 
288  TL_ADD(ispmf, w64 * h64);
289 }
290 
292 {
293  const VVCSPS *sps = fc->ps.sps;
294  const VVCPPS *pps = fc->ps.pps;
295  const int ctu_height = pps ? pps->ctb_height : 0;
296  const int ctu_size = sps ? sps->ctb_size_y : 0;
297  const int ps = sps ? sps->pixel_shift : 0;
298  const int chroma_idc = sps ? sps->r->sps_chroma_format_idc : 0;
299  const int has_ibc = sps ? sps->r->sps_ibc_enabled_flag : 0;
300  const int changed = fc->tab.sz.chroma_format_idc != chroma_idc ||
301  fc->tab.sz.ctu_height != ctu_height ||
302  fc->tab.sz.ctu_size != ctu_size ||
303  fc->tab.sz.pixel_shift != ps;
304 
305  fc->tab.sz.ibc_buffer_width = ctu_size ? 2 * MAX_CTU_SIZE * MAX_CTU_SIZE / ctu_size : 0;
306 
307  tl_init(l, has_ibc, changed);
308 
309  for (int i = LUMA; i < VVC_MAX_SAMPLE_ARRAYS; i++) {
310  const int hs = sps ? sps->hshift[i] : 0;
311  const int vs = sps ? sps->vshift[i] : 0;
312  TL_ADD(ibc_vir_buf[i], fc->tab.sz.ibc_buffer_width * ctu_size * ctu_height << ps >> hs >> vs);
313  }
314 }
315 
316 typedef void (*tl_init_fn)(TabList *l, VVCFrameContext *fc);
317 
318 static int frame_context_for_each_tl(VVCFrameContext *fc, int (*unary_fn)(TabList *l))
319 {
320  const tl_init_fn init[] = {
329  msm_tl_init,
331  ibc_tl_init,
332  };
333 
334  for (int i = 0; i < FF_ARRAY_ELEMS(init); i++) {
335  TabList l;
336  int ret;
337 
338  init[i](&l, fc);
339  ret = unary_fn(&l);
340  if (ret < 0)
341  return ret;
342  }
343  return 0;
344 }
345 
347 {
348  if (fc->tab.cus) {
349  for (int i = 0; i < fc->tab.sz.ctu_count; i++)
350  ff_vvc_ctu_free_cus(fc->tab.cus + i);
351  }
352 }
353 
355 {
356  free_cus(fc);
358  av_refstruct_pool_uninit(&fc->rpl_tab_pool);
359  av_refstruct_pool_uninit(&fc->tab_dmvr_mvf_pool);
360 
361  memset(&fc->tab.sz, 0, sizeof(fc->tab.sz));
362 }
363 
365 {
366  const VVCSPS *sps = fc->ps.sps;
367  const VVCPPS *pps = fc->ps.pps;
368  const int ctu_count = pps->ctb_count;
369  const int pic_size_in_min_pu = pps->min_pu_width * pps->min_pu_height;
370  int ret;
371 
372  free_cus(fc);
373 
375  if (ret < 0)
376  return ret;
377 
378  // for error handling case, we may call free_cus before VVC_TASK_STAGE_INIT, so we need to set cus to 0 here
379  memset(fc->tab.cus, 0, sizeof(*fc->tab.cus) * ctu_count);
380 
381  memset(fc->tab.slice_idx, -1, sizeof(*fc->tab.slice_idx) * ctu_count);
382 
383  if (fc->tab.sz.ctu_count != ctu_count) {
384  av_refstruct_pool_uninit(&fc->rpl_tab_pool);
385  fc->rpl_tab_pool = av_refstruct_pool_alloc(ctu_count * sizeof(RefPicListTab), 0);
386  if (!fc->rpl_tab_pool)
387  return AVERROR(ENOMEM);
388  }
389 
390  if (fc->tab.sz.pic_size_in_min_pu != pic_size_in_min_pu) {
391  av_refstruct_pool_uninit(&fc->tab_dmvr_mvf_pool);
392  fc->tab_dmvr_mvf_pool = av_refstruct_pool_alloc(
393  pic_size_in_min_pu * sizeof(MvField), AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME);
394  if (!fc->tab_dmvr_mvf_pool)
395  return AVERROR(ENOMEM);
396  }
397 
398  fc->tab.sz.ctu_count = pps->ctb_count;
399  fc->tab.sz.ctu_size = 1 << sps->ctb_log2_size_y << sps->ctb_log2_size_y;
400  fc->tab.sz.pic_size_in_min_cb = pps->min_cb_width * pps->min_cb_height;
401  fc->tab.sz.pic_size_in_min_pu = pic_size_in_min_pu;
402  fc->tab.sz.pic_size_in_min_tu = pps->min_tu_width * pps->min_tu_height;
403  fc->tab.sz.width = pps->width;
404  fc->tab.sz.height = pps->height;
405  fc->tab.sz.ctu_width = pps->ctb_width;
406  fc->tab.sz.ctu_height = pps->ctb_height;
407  fc->tab.sz.chroma_format_idc = sps->r->sps_chroma_format_idc;
408  fc->tab.sz.pixel_shift = sps->pixel_shift;
409 
410  return 0;
411 }
412 
414 {
416 }
417 
418 static int min_positive(const int idx, const int diff, const int min_diff)
419 {
420  return diff > 0 && (idx < 0 || diff < min_diff);
421 }
422 
423 static int max_negtive(const int idx, const int diff, const int max_diff)
424 {
425  return diff < 0 && (idx < 0 || diff > max_diff);
426 }
427 
428 typedef int (*smvd_find_fxn)(const int idx, const int diff, const int old_diff);
429 
430 static int8_t smvd_find(const VVCFrameContext *fc, const SliceContext *sc, int lx, smvd_find_fxn find)
431 {
432  const H266RawSliceHeader *rsh = sc->sh.r;
433  const RefPicList *rpl = sc->rpl + lx;
434  const int poc = fc->ref->poc;
435  int8_t idx = -1;
436  int old_diff = -1;
437  for (int i = 0; i < rsh->num_ref_idx_active[lx]; i++) {
438  if (!rpl->refs[i].is_lt) {
439  int diff = poc - rpl->refs[i].poc;
440  if (find(idx, diff, old_diff)) {
441  idx = i;
442  old_diff = diff;
443  }
444  }
445  }
446  return idx;
447 }
448 
449 static void smvd_ref_idx(const VVCFrameContext *fc, SliceContext *sc)
450 {
451  VVCSH *sh = &sc->sh;
452  if (IS_B(sh->r)) {
453  sh->ref_idx_sym[0] = smvd_find(fc, sc, 0, min_positive);
454  sh->ref_idx_sym[1] = smvd_find(fc, sc, 1, max_negtive);
455  if (sh->ref_idx_sym[0] == -1 || sh->ref_idx_sym[1] == -1) {
456  sh->ref_idx_sym[0] = smvd_find(fc, sc, 0, max_negtive);
457  sh->ref_idx_sym[1] = smvd_find(fc, sc, 1, min_positive);
458  }
459  }
460 }
461 
462 static void eps_free(SliceContext *slice)
463 {
464  av_freep(&slice->eps);
465  slice->nb_eps = 0;
466 }
467 
469 {
470  if (fc->slices) {
471  for (int i = 0; i < fc->nb_slices_allocated; i++) {
472  SliceContext *slice = fc->slices[i];
473  if (slice) {
474  av_refstruct_unref(&slice->ref);
475  av_refstruct_unref(&slice->sh.r);
476  eps_free(slice);
477  av_free(slice);
478  }
479  }
480  av_freep(&fc->slices);
481  }
482  fc->nb_slices_allocated = 0;
483  fc->nb_slices = 0;
484 }
485 
487 {
488  void *p;
489  const int size = (fc->nb_slices_allocated + 1) * 3 / 2;
490 
491  if (fc->nb_slices < fc->nb_slices_allocated)
492  return 0;
493 
494  p = av_realloc_array(fc->slices, size, sizeof(*fc->slices));
495  if (!p)
496  return AVERROR(ENOMEM);
497 
498  fc->slices = p;
499  for (int i = fc->nb_slices_allocated; i < size; i++) {
500  fc->slices[i] = av_mallocz(sizeof(*fc->slices[0]));
501  if (!fc->slices[i]) {
502  fc->nb_slices_allocated = i;
503  return AVERROR(ENOMEM);
504  }
505  fc->slices[i]->slice_idx = i;
506  }
507  fc->nb_slices_allocated = size;
508 
509  return 0;
510 }
511 
512 static int get_ep_size(const H266RawSliceHeader *rsh, GetBitContext *gb, const H2645NAL *nal, const int header_size, const int ep_index)
513 {
514  int size;
515 
516  if (ep_index < rsh->num_entry_points) {
517  int skipped = 0;
518  int64_t start = (gb->index >> 3);
519  int64_t end = start + rsh->sh_entry_point_offset_minus1[ep_index] + 1;
520  while (skipped < nal->skipped_bytes && nal->skipped_bytes_pos[skipped] <= start + header_size) {
521  skipped++;
522  }
523  while (skipped < nal->skipped_bytes && nal->skipped_bytes_pos[skipped] <= end + header_size) {
524  end--;
525  skipped++;
526  }
527  size = end - start;
528  size = av_clip(size, 0, get_bits_left(gb) / 8);
529  } else {
530  size = get_bits_left(gb) / 8;
531  }
532  return size;
533 }
534 
535 static int ep_init_cabac_decoder(EntryPoint *ep, GetBitContext *gb, const int size)
536 {
537  int ret;
538 
539  av_assert0(gb->buffer + get_bits_count(gb) / 8 + size <= gb->buffer_end);
540  ret = ff_init_cabac_decoder (&ep->cc, gb->buffer + get_bits_count(gb) / 8, size);
541  if (ret < 0)
542  return ret;
543  skip_bits(gb, size * 8);
544  return 0;
545 }
546 
547 static int ep_init(EntryPoint *ep, const int ctu_addr, const int ctu_end, GetBitContext *gb, const int size)
548 {
549  const int ret = ep_init_cabac_decoder(ep, gb, size);
550 
551  if (ret < 0)
552  return ret;
553 
554  ep->ctu_start = ctu_addr;
555  ep->ctu_end = ctu_end;
556 
557  for (int c_idx = LUMA; c_idx <= CR; c_idx++)
558  ep->pp[c_idx].size = 0;
559 
560  return 0;
561 }
562 
564  VVCFrameContext *fc, const H2645NAL *nal, const CodedBitstreamUnit *unit)
565 {
566  const VVCSH *sh = &sc->sh;
567  const H266RawSlice *slice = unit->content_ref;
568  int nb_eps = sh->r->num_entry_points + 1;
569  int ctu_addr = 0;
570  GetBitContext gb;
571  int ret;
572 
573  if (sc->nb_eps != nb_eps) {
574  eps_free(sc);
575  sc->eps = av_calloc(nb_eps, sizeof(*sc->eps));
576  if (!sc->eps)
577  return AVERROR(ENOMEM);
578  sc->nb_eps = nb_eps;
579  }
580 
581  ret = init_get_bits8(&gb, slice->data, slice->data_size);
582  if (ret < 0)
583  return ret;
584  for (int i = 0; i < sc->nb_eps; i++)
585  {
586  const int size = get_ep_size(sc->sh.r, &gb, nal, slice->header_size, i);
587  const int ctu_end = (i + 1 == sc->nb_eps ? sh->num_ctus_in_curr_slice : sh->entry_point_start_ctu[i]);
588  EntryPoint *ep = sc->eps + i;
589 
590  ret = ep_init(ep, ctu_addr, ctu_end, &gb, size);
591  if (ret < 0)
592  return ret;
593 
594  for (int j = ep->ctu_start; j < ep->ctu_end; j++) {
595  const int rs = sc->sh.ctb_addr_in_curr_slice[j];
596  fc->tab.slice_idx[rs] = sc->slice_idx;
597  }
598 
599  if (i + 1 < sc->nb_eps)
600  ctu_addr = sh->entry_point_start_ctu[i];
601  }
602 
603  return 0;
604 }
605 
607 {
608  const int size = s->nb_fcs;
609  const int idx = (fc - s->fcs + delta + size) % size;
610  return s->fcs + idx;
611 }
612 
613 static int ref_frame(VVCFrame *dst, const VVCFrame *src)
614 {
615  int ret;
616 
617  ret = av_frame_ref(dst->frame, src->frame);
618  if (ret < 0)
619  return ret;
620 
621  av_refstruct_replace(&dst->sps, src->sps);
622  av_refstruct_replace(&dst->pps, src->pps);
623 
624  if (src->needs_fg) {
625  ret = av_frame_ref(dst->frame_grain, src->frame_grain);
626  if (ret < 0)
627  return ret;
628 
629  dst->needs_fg = src->needs_fg;
630  }
631 
632  av_refstruct_replace(&dst->progress, src->progress);
633 
634  av_refstruct_replace(&dst->tab_dmvr_mvf, src->tab_dmvr_mvf);
635 
636  av_refstruct_replace(&dst->rpl_tab, src->rpl_tab);
637  av_refstruct_replace(&dst->rpl, src->rpl);
638  av_refstruct_replace(&dst->hwaccel_picture_private,
639  src->hwaccel_picture_private);
640  dst->nb_rpl_elems = src->nb_rpl_elems;
641 
642  dst->poc = src->poc;
643  dst->ctb_count = src->ctb_count;
644 
645  dst->scaling_win = src->scaling_win;
646  dst->ref_width = src->ref_width;
647  dst->ref_height = src->ref_height;
648 
649  dst->flags = src->flags;
650  dst->sequence = src->sequence;
651 
652  return 0;
653 }
654 
656 {
657  slices_free(fc);
658 
659  av_refstruct_pool_uninit(&fc->tu_pool);
660  av_refstruct_pool_uninit(&fc->cu_pool);
661 
662  for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
663  ff_vvc_unref_frame(fc, &fc->DPB[i], ~0);
664  av_frame_free(&fc->DPB[i].frame);
665  av_frame_free(&fc->DPB[i].frame_grain);
666  }
667 
670  av_frame_free(&fc->output_frame);
671  ff_vvc_frame_ps_free(&fc->ps);
672  ff_vvc_sei_reset(&fc->sei);
673 }
674 
676 {
677 
678  fc->log_ctx = avctx;
679 
680  fc->output_frame = av_frame_alloc();
681  if (!fc->output_frame)
682  return AVERROR(ENOMEM);
683 
684  for (int j = 0; j < FF_ARRAY_ELEMS(fc->DPB); j++) {
685  fc->DPB[j].frame = av_frame_alloc();
686  if (!fc->DPB[j].frame)
687  return AVERROR(ENOMEM);
688 
689  fc->DPB[j].frame_grain = av_frame_alloc();
690  if (!fc->DPB[j].frame_grain)
691  return AVERROR(ENOMEM);
692  }
693  fc->cu_pool = av_refstruct_pool_alloc(sizeof(CodingUnit), 0);
694  if (!fc->cu_pool)
695  return AVERROR(ENOMEM);
696 
697  fc->tu_pool = av_refstruct_pool_alloc(sizeof(TransformUnit), 0);
698  if (!fc->tu_pool)
699  return AVERROR(ENOMEM);
700 
701  return 0;
702 }
703 
705 {
706  int ret;
707 
708  // copy refs from the last frame
709  if (s->nb_frames && s->nb_fcs > 1) {
710  VVCFrameContext *prev = get_frame_context(s, fc, -1);
711  for (int i = 0; i < FF_ARRAY_ELEMS(fc->DPB); i++) {
712  ff_vvc_unref_frame(fc, &fc->DPB[i], ~0);
713  if (prev->DPB[i].frame->buf[0]) {
714  ret = ref_frame(&fc->DPB[i], &prev->DPB[i]);
715  if (ret < 0)
716  return ret;
717  }
718  }
719 
720  ret = ff_vvc_sei_replace(&fc->sei, &prev->sei);
721  if (ret < 0)
722  return ret;
723  }
724 
725  if (IS_IDR(s)) {
726  s->seq_decode = (s->seq_decode + 1) & 0xff;
728  }
729 
730  ret = pic_arrays_init(s, fc);
731  if (ret < 0)
732  return ret;
733  ff_vvc_dsp_init(&fc->vvcdsp, fc->ps.sps->bit_depth);
734  ff_videodsp_init(&fc->vdsp, fc->ps.sps->bit_depth);
735  return 0;
736 }
737 
738 /* SEI does not affect decoding, so we ignore the return value */
740 {
741  CodedBitstreamFragment *frame = &s->current_frame;
742 
743  for (int i = 0; i < frame->nb_units; i++) {
744  const CodedBitstreamUnit *unit = frame->units + i;
745 
746  if (unit->type == VVC_PREFIX_SEI_NUT) {
747  int ret = ff_vvc_sei_decode(&fc->sei, unit->content_ref, fc);
748  if (ret < 0)
749  return;
750  }
751  }
752 }
753 
755 {
756  AVFrame *out = fc->ref->frame;
757 
758  return ff_h2645_sei_to_frame(out, &fc->sei.common, AV_CODEC_ID_VVC, s->avctx,
759  NULL, fc->ps.sps->bit_depth, fc->ps.sps->bit_depth, fc->ref->poc);
760 }
761 
763 {
764  int ret;
765 
766  fc->ref->needs_fg = (fc->sei.common.film_grain_characteristics &&
767  fc->sei.common.film_grain_characteristics->present ||
768  fc->sei.common.aom_film_grain.enable) &&
769  !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
770  !s->avctx->hwaccel;
771 
772  if (fc->ref->needs_fg &&
773  (fc->sei.common.film_grain_characteristics &&
774  fc->sei.common.film_grain_characteristics->present &&
775  !ff_h274_film_grain_params_supported(fc->sei.common.film_grain_characteristics->model_id,
776  fc->ref->frame->format) ||
777  !av_film_grain_params_select(fc->ref->frame))) {
778  av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown,
779  "Unsupported film grain parameters. Ignoring film grain.\n");
780  fc->ref->needs_fg = 0;
781  }
782 
783  if (fc->ref->needs_fg) {
784  fc->ref->frame_grain->format = fc->ref->frame->format;
785  fc->ref->frame_grain->width = fc->ref->frame->width;
786  fc->ref->frame_grain->height = fc->ref->frame->height;
787 
788  ret = ff_thread_get_buffer(s->avctx, fc->ref->frame_grain, 0);
789  if (ret < 0)
790  return ret;
791 
792  return av_frame_copy_props(fc->ref->frame_grain, fc->ref->frame);
793  }
794 
795  return 0;
796 }
797 
799 {
800  const VVCPH *ph = &fc->ps.ph;
801  const H266RawSliceHeader *rsh = sc->sh.r;
802  int ret;
803 
804  // 8.3.1 Decoding process for picture order count
805  if (!s->temporal_id && !ph->r->ph_non_ref_pic_flag && !(IS_RASL(s) || IS_RADL(s)))
806  s->poc_tid0 = ph->poc;
807 
808  if ((ret = ff_vvc_set_new_ref(s, fc, &fc->frame)) < 0)
809  goto fail;
810 
812 
813  ret = set_side_data(s, fc);
814  if (ret < 0)
815  goto fail;
816 
817  ret = check_film_grain(s, fc);
818  if (ret < 0)
819  goto fail;
820 
821  if (!IS_IDR(s))
823 
824  av_frame_unref(fc->output_frame);
825 
826  if ((ret = ff_vvc_output_frame(s, fc, fc->output_frame,rsh->sh_no_output_of_prior_pics_flag, 0)) < 0)
827  goto fail;
828 
829  if ((ret = ff_vvc_frame_rpl(s, fc, sc)) < 0)
830  goto fail;
831 
832  if ((ret = ff_vvc_frame_thread_init(fc)) < 0)
833  goto fail;
834  return 0;
835 fail:
836  if (fc->ref)
837  ff_vvc_unref_frame(fc, fc->ref, ~0);
838  fc->ref = NULL;
839  return ret;
840 }
841 
843  const CodedBitstreamUnit *unit, const int is_first_slice)
844 {
845  VVCSH *sh = &sc->sh;
846  int ret;
847 
848  ret = ff_vvc_decode_sh(sh, &fc->ps, unit);
849  if (ret < 0)
850  return ret;
851 
852  av_refstruct_replace(&sc->ref, unit->content_ref);
853 
854  if (is_first_slice) {
855  ret = frame_start(s, fc, sc);
856  if (ret < 0)
857  return ret;
858  } else if (fc->ref) {
859  if (!IS_I(sh->r)) {
860  ret = ff_vvc_slice_rpl(s, fc, sc);
861  if (ret < 0) {
862  av_log(fc->log_ctx, AV_LOG_WARNING,
863  "Error constructing the reference lists for the current slice.\n");
864  return ret;
865  }
866  }
867  } else {
868  av_log(fc->log_ctx, AV_LOG_ERROR, "First slice in a frame missing.\n");
869  return ret;
870  }
871 
872  if (!IS_I(sh->r))
873  smvd_ref_idx(fc, sc);
874 
875  return 0;
876 }
877 
878 static enum AVPixelFormat get_format(AVCodecContext *avctx, const VVCSPS *sps)
879 {
880 #define HWACCEL_MAX CONFIG_VVC_VAAPI_HWACCEL
881 
882  enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
883 
884  switch (sps->pix_fmt) {
885  case AV_PIX_FMT_YUV420P:
886 #if CONFIG_VVC_VAAPI_HWACCEL
887  *fmt++ = AV_PIX_FMT_VAAPI;
888 #endif
889  break;
891 #if CONFIG_VVC_VAAPI_HWACCEL
892  *fmt++ = AV_PIX_FMT_VAAPI;
893 #endif
894  break;
895  }
896 
897  *fmt++ = sps->pix_fmt;
898  *fmt = AV_PIX_FMT_NONE;
899 
900  return ff_get_format(avctx, pix_fmts);
901 }
902 
904 {
905  AVCodecContext *c = s->avctx;
906  const VVCSPS *sps = fc->ps.sps;
907  const VVCPPS *pps = fc->ps.pps;
908 
909  // Reset the format if pix_fmt/w/h change.
910  if (c->sw_pix_fmt != sps->pix_fmt || c->coded_width != pps->width || c->coded_height != pps->height) {
911  c->coded_width = pps->width;
912  c->coded_height = pps->height;
913  c->sw_pix_fmt = sps->pix_fmt;
914  c->pix_fmt = get_format(c, sps);
915  if (c->pix_fmt < 0)
916  return AVERROR_INVALIDDATA;
917  }
918 
919  c->width = pps->width - ((pps->r->pps_conf_win_left_offset + pps->r->pps_conf_win_right_offset) << sps->hshift[CHROMA]);
920  c->height = pps->height - ((pps->r->pps_conf_win_top_offset + pps->r->pps_conf_win_bottom_offset) << sps->vshift[CHROMA]);
921 
922  return 0;
923 }
924 
926 {
927  int ret = ff_vvc_decode_frame_ps(&fc->ps, s);
928  if (ret < 0)
929  return ret;
930 
932  if (ret < 0)
933  return ret;
934 
936  if (ret < 0)
937  return ret;
938 
939  return 0;
940 }
941 
943  const H2645NAL *nal, const CodedBitstreamUnit *unit)
944 {
945  int ret;
946  SliceContext *sc;
947  const int is_first_slice = !fc->nb_slices;
948 
949  ret = slices_realloc(fc);
950  if (ret < 0)
951  return ret;
952 
953  sc = fc->slices[fc->nb_slices];
954 
955  s->vcl_unit_type = nal->type;
956  if (is_first_slice) {
957  ret = frame_setup(fc, s);
958  if (ret < 0)
959  return ret;
960  }
961 
962  ret = slice_start(sc, s, fc, unit, is_first_slice);
963  if (ret < 0)
964  return ret;
965 
966  ret = slice_init_entry_points(sc, fc, nal, unit);
967  if (ret < 0)
968  return ret;
969 
970  if (s->avctx->hwaccel) {
971  if (is_first_slice) {
972  ret = FF_HW_CALL(s->avctx, start_frame, buf_ref, NULL, 0);
973  if (ret < 0)
974  return ret;
975  }
976 
977  ret = FF_HW_CALL(s->avctx, decode_slice,
978  nal->raw_data, nal->raw_size);
979  if (ret < 0)
980  return ret;
981  }
982 
983  fc->nb_slices++;
984 
985  return 0;
986 }
987 
989  const H2645NAL *nal, const CodedBitstreamUnit *unit)
990 {
991  int ret;
992 
993  s->temporal_id = nal->temporal_id;
994 
995  if (nal->nuh_layer_id > 0) {
997  "Decoding of multilayer bitstreams");
998  return AVERROR_PATCHWELCOME;
999  }
1000 
1001  switch (unit->type) {
1002  case VVC_VPS_NUT:
1003  case VVC_SPS_NUT:
1004  case VVC_PPS_NUT:
1005  /* vps, sps, sps cached by s->cbc */
1006  break;
1007  case VVC_TRAIL_NUT:
1008  case VVC_STSA_NUT:
1009  case VVC_RADL_NUT:
1010  case VVC_RASL_NUT:
1011  case VVC_IDR_W_RADL:
1012  case VVC_IDR_N_LP:
1013  case VVC_CRA_NUT:
1014  case VVC_GDR_NUT:
1015  ret = decode_slice(s, fc, buf_ref, nal, unit);
1016  if (ret < 0)
1017  return ret;
1018  break;
1019  case VVC_PREFIX_APS_NUT:
1020  case VVC_SUFFIX_APS_NUT:
1021  ret = ff_vvc_decode_aps(&s->ps, unit);
1022  if (ret < 0)
1023  return ret;
1024  break;
1025  case VVC_PREFIX_SEI_NUT:
1026  /* handle by decode_prefix_sei() */
1027  break;
1028 
1029  case VVC_SUFFIX_SEI_NUT:
1030  /* SEI does not affect decoding, so we ignore the return value*/
1031  if (fc)
1032  ff_vvc_sei_decode(&fc->sei, unit->content_ref, fc);
1033  break;
1034  }
1035 
1036  return 0;
1037 }
1038 
1040 {
1041  const CodedBitstreamH266Context *h266 = s->cbc->priv_data;
1042  CodedBitstreamFragment *frame = &s->current_frame;
1043  int ret = 0;
1044  s->last_eos = s->eos;
1045  s->eos = 0;
1046  fc->ref = NULL;
1047 
1048  ff_cbs_fragment_reset(frame);
1049  ret = ff_cbs_read_packet(s->cbc, frame, avpkt);
1050  if (ret < 0) {
1051  av_log(s->avctx, AV_LOG_ERROR, "Failed to read packet.\n");
1052  return ret;
1053  }
1054  /* decode the NAL units */
1055  for (int i = 0; i < frame->nb_units; i++) {
1056  const H2645NAL *nal = h266->common.read_packet.nals + i;
1057  const CodedBitstreamUnit *unit = frame->units + i;
1058 
1059  if (unit->type == VVC_EOB_NUT || unit->type == VVC_EOS_NUT) {
1060  s->last_eos = 1;
1061  } else {
1062  ret = decode_nal_unit(s, fc, avpkt->buf, nal, unit);
1063  if (ret < 0) {
1064  av_log(s->avctx, AV_LOG_WARNING,
1065  "Error parsing NAL unit #%d.\n", i);
1066  goto fail;
1067  }
1068  }
1069  }
1070  return 0;
1071 
1072 fail:
1073  if (fc->ref)
1075  return ret;
1076 }
1077 
1079 {
1080  const AVFilmGrainParams *fgp;
1081  int ret;
1082 
1083  if (fc->ref->needs_fg) {
1084  av_assert0(fc->ref->frame_grain->buf[0]);
1085  fgp = av_film_grain_params_select(fc->ref->frame);
1086  switch (fgp->type) {
1088  av_assert0(0);
1089  return AVERROR_BUG;
1091  ret = ff_h274_apply_film_grain(fc->ref->frame_grain, fc->ref->frame,
1092  &s->h274db, fgp);
1093  if (ret < 0)
1094  return ret;
1095  break;
1097  ret = ff_aom_apply_film_grain(fc->ref->frame_grain, fc->ref->frame, fgp);
1098  if (ret < 0)
1099  return ret;
1100  break;
1101  }
1102  }
1103 
1104  if (!s->avctx->hwaccel && s->avctx->err_recognition & AV_EF_CRCCHECK) {
1105  VVCSEI *sei = &fc->sei;
1106  if (sei->picture_hash.present) {
1107  ret = ff_h274_hash_init(&s->hash_ctx, sei->picture_hash.hash_type);
1108  if (ret < 0)
1109  return ret;
1110 
1111  ret = ff_h274_hash_verify(s->hash_ctx, &sei->picture_hash, fc->ref->frame, fc->ps.pps->width, fc->ps.pps->height);
1112  if (ret < 0) {
1113  av_log(s->avctx, AV_LOG_ERROR,
1114  "Verifying checksum for frame with decoder_order %d: failed\n",
1115  (int)fc->decode_order);
1116  if (s->avctx->err_recognition & AV_EF_EXPLODE)
1117  return ret;
1118  }
1119  }
1120  }
1121 
1122  return 0;
1123 }
1124 
1125 static int wait_delayed_frame(VVCContext *s, AVFrame *output, int *got_output)
1126 {
1127  VVCFrameContext *delayed = get_frame_context(s, s->fcs, s->nb_frames - s->nb_delayed);
1128  int ret = ff_vvc_frame_wait(s, delayed);
1129 
1130  if (!ret) {
1131  ret = frame_end(s, delayed);
1132  if (ret >= 0 && delayed->output_frame->buf[0] && output) {
1134  *got_output = 1;
1135  }
1136  }
1137  s->nb_delayed--;
1138 
1139  return ret;
1140 }
1141 
1142 static int submit_frame(VVCContext *s, VVCFrameContext *fc, AVFrame *output, int *got_output)
1143 {
1144  int ret;
1145 
1146  if (s->avctx->hwaccel) {
1147  if (ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame) < 0) {
1148  av_log(s->avctx, AV_LOG_ERROR,
1149  "Hardware accelerator failed to decode picture\n");
1150  ff_vvc_unref_frame(fc, fc->ref, ~0);
1151  return ret;
1152  }
1153  } else {
1154  if (ret = ff_vvc_frame_submit(s, fc) < 0) {
1156  return ret;
1157  }
1158  }
1159 
1160  s->nb_frames++;
1161  s->nb_delayed++;
1162 
1163  if (s->nb_delayed >= s->nb_fcs || s->avctx->hwaccel) {
1164  if ((ret = wait_delayed_frame(s, output, got_output)) < 0)
1165  return ret;
1166  }
1167  return 0;
1168 }
1169 
1170 static int get_decoded_frame(VVCContext *s, AVFrame *output, int *got_output)
1171 {
1172  int ret;
1173  while (s->nb_delayed) {
1174  if ((ret = wait_delayed_frame(s, output, got_output)) < 0)
1175  return ret;
1176  if (*got_output)
1177  return 0;
1178  }
1179  if (s->nb_frames) {
1180  //we still have frames cached in dpb.
1181  VVCFrameContext *last = get_frame_context(s, s->fcs, s->nb_frames - 1);
1182 
1183  ret = ff_vvc_output_frame(s, last, output, 0, 1);
1184  if (ret < 0)
1185  return ret;
1186  *got_output = ret;
1187  }
1188  return 0;
1189 }
1190 
1192  int *got_output, AVPacket *avpkt)
1193 {
1194  VVCContext *s = avctx->priv_data;
1196  int ret;
1197 
1198  if (!avpkt->size)
1199  return get_decoded_frame(s, output, got_output);
1200 
1201  fc = get_frame_context(s, s->fcs, s->nb_frames);
1202 
1203  fc->nb_slices = 0;
1204  fc->decode_order = s->nb_frames;
1205 
1206  ret = decode_nal_units(s, fc, avpkt);
1207  if (ret < 0)
1208  return ret;
1209 
1210  if (!fc->ft || !fc->ref)
1211  return avpkt->size;
1212 
1213  ret = submit_frame(s, fc, output, got_output);
1214  if (ret < 0)
1215  return ret;
1216 
1217  return avpkt->size;
1218 }
1219 
1221 {
1222  VVCContext *s = avctx->priv_data;
1223  int got_output = 0;
1224 
1225  while (s->nb_delayed)
1226  wait_delayed_frame(s, NULL, &got_output);
1227 
1228  if (s->fcs) {
1229  VVCFrameContext *last = get_frame_context(s, s->fcs, s->nb_frames - 1);
1230  ff_vvc_flush_dpb(last);
1231  }
1232 
1233  s->ps.sps_id_used = 0;
1234 
1235  s->eos = 1;
1236 }
1237 
1239 {
1240  VVCContext *s = avctx->priv_data;
1241 
1242  ff_cbs_fragment_free(&s->current_frame);
1243  vvc_decode_flush(avctx);
1244  ff_vvc_executor_free(&s->executor);
1245  if (s->fcs) {
1246  for (int i = 0; i < s->nb_fcs; i++)
1247  frame_context_free(s->fcs + i);
1248  av_free(s->fcs);
1249  }
1250  ff_h274_hash_freep(&s->hash_ctx);
1251  ff_vvc_ps_uninit(&s->ps);
1252  ff_cbs_close(&s->cbc);
1253 
1254  return 0;
1255 }
1256 
1258 {
1259  memset(&ff_vvc_default_scale_m, 16, sizeof(ff_vvc_default_scale_m));
1260 }
1261 
1262 #define VVC_MAX_DELAYED_FRAMES 16
1264 {
1265  VVCContext *s = avctx->priv_data;
1266  static AVOnce init_static_once = AV_ONCE_INIT;
1267  const int cpu_count = av_cpu_count();
1268  const int delayed = FFMIN(cpu_count, VVC_MAX_DELAYED_FRAMES);
1269  int thread_count = avctx->thread_count ? avctx->thread_count : delayed;
1270  int ret;
1271 
1272  s->avctx = avctx;
1273 
1274  ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_VVC, avctx);
1275  if (ret)
1276  return ret;
1277 
1278  if (avctx->extradata_size > 0 && avctx->extradata) {
1279  ret = ff_cbs_read_extradata_from_codec(s->cbc, &s->current_frame, avctx);
1280  if (ret < 0)
1281  return ret;
1282  }
1283 
1284  s->nb_fcs = (avctx->flags & AV_CODEC_FLAG_LOW_DELAY) ? 1 : delayed;
1285  s->fcs = av_calloc(s->nb_fcs, sizeof(*s->fcs));
1286  if (!s->fcs)
1287  return AVERROR(ENOMEM);
1288 
1289  for (int i = 0; i < s->nb_fcs; i++) {
1290  VVCFrameContext *fc = s->fcs + i;
1291  ret = frame_context_init(fc, avctx);
1292  if (ret < 0)
1293  return ret;
1294  }
1295 
1296  if (thread_count == 1)
1297  thread_count = 0;
1298  s->executor = ff_vvc_executor_alloc(s, thread_count);
1299  if (!s->executor)
1300  return AVERROR(ENOMEM);
1301 
1302  s->eos = 1;
1304  ff_thread_once(&init_static_once, init_default_scale_m);
1305 
1306  return 0;
1307 }
1308 
1310  .p.name = "vvc",
1311  .p.long_name = NULL_IF_CONFIG_SMALL("VVC (Versatile Video Coding)"),
1312  .p.type = AVMEDIA_TYPE_VIDEO,
1313  .p.id = AV_CODEC_ID_VVC,
1314  .priv_data_size = sizeof(VVCContext),
1315  .init = vvc_decode_init,
1318  .flush = vvc_decode_flush,
1322  .p.profiles = NULL_IF_CONFIG_SMALL(ff_vvc_profiles),
1323  .hw_configs = (const AVCodecHWConfigInternal *const []) {
1324 #if CONFIG_VVC_VAAPI_HWACCEL
1325  HWACCEL_VAAPI(vvc),
1326 #endif
1327  NULL
1328  },
1329 };
VVC_RADL_NUT
@ VVC_RADL_NUT
Definition: vvc.h:31
VVC_RASL_NUT
@ VVC_RASL_NUT
Definition: vvc.h:32
VVC_GDR_NUT
@ VVC_GDR_NUT
Definition: vvc.h:39
VVC_STSA_NUT
@ VVC_STSA_NUT
Definition: vvc.h:30
hwconfig.h
VVCSPS
Definition: ps.h:58
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
ALF_BORDER_LUMA
#define ALF_BORDER_LUMA
Definition: ctu.h:79
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
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
ep_init
static int ep_init(EntryPoint *ep, const int ctu_addr, const int ctu_end, GetBitContext *gb, const int size)
Definition: dec.c:547
VVCPH
Definition: ps.h:147
VVCFrameContext::output_frame
struct AVFrame * output_frame
Definition: dec.h:129
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
VVCPPS
Definition: ps.h:92
av_clip
#define av_clip
Definition: common.h:100
VVC_MAX_DELAYED_FRAMES
#define VVC_MAX_DELAYED_FRAMES
Definition: dec.c:1262
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:678
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
cpu_count
static atomic_int cpu_count
Definition: cpu.c:57
min_cb_tl_init
static void min_cb_tl_init(TabList *l, VVCFrameContext *fc)
Definition: dec.c:125
ff_vvc_decode_frame_ps
int ff_vvc_decode_frame_ps(VVCFrameParamSets *fps, struct VVCContext *s)
Definition: ps.c:1060
smvd_ref_idx
static void smvd_ref_idx(const VVCFrameContext *fc, SliceContext *sc)
Definition: dec.c:449
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
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1200
out
FILE * out
Definition: movenc.c:55
tl_create
static int tl_create(TabList *l)
Definition: dec.c:80
slices_realloc
static int slices_realloc(VVCFrameContext *fc)
Definition: dec.c:486
ff_vvc_sei_reset
void ff_vvc_sei_reset(VVCSEI *s)
Definition: sei.c:249
deblock
static void deblock(const RV60Context *s, AVFrame *frame, int xpos, int ypos, int size, int dpos)
Definition: rv60dec.c:2149
CB
#define CB
Definition: filter.c:32
thread.h
ff_vvc_report_frame_finished
void ff_vvc_report_frame_finished(VVCFrame *frame)
Definition: refs.c:616
ff_h2645_sei_to_frame
int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, enum AVCodecID codec_id, AVCodecContext *avctx, const H2645VUI *vui, unsigned bit_depth_luma, unsigned bit_depth_chroma, int seed)
Definition: h2645_sei.c:719
CodingUnit
Definition: hevcdec.h:292
int64_t
long long int64_t
Definition: coverity.c:34
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
H266RawSliceHeader::sh_no_output_of_prior_pics_flag
uint8_t sh_no_output_of_prior_pics_flag
Definition: cbs_h266.h:781
VVCFrameContext::DPB
VVCFrame DPB[VVC_MAX_DPB_SIZE+1]
Definition: dec.h:126
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:249
decode_nal_unit
static int decode_nal_unit(VVCContext *s, VVCFrameContext *fc, AVBufferRef *buf_ref, const H2645NAL *nal, const CodedBitstreamUnit *unit)
Definition: dec.c:988
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:63
data.h
ph
static int FUNC() ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
Definition: cbs_h266_syntax_template.c:3043
H2645NAL::nuh_layer_id
int nuh_layer_id
Definition: h2645_parse.h:67
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:421
w
uint8_t w
Definition: llviddspenc.c:38
decode_slice
static int decode_slice(VVCContext *s, VVCFrameContext *fc, AVBufferRef *buf_ref, const H2645NAL *nal, const CodedBitstreamUnit *unit)
Definition: dec.c:942
ff_h274_hash_init
int ff_h274_hash_init(H274HashContext **ctx, const int type)
Definition: h274.c:881
ff_vvc_executor_alloc
FFExecutor * ff_vvc_executor_alloc(VVCContext *s, const int thread_count)
Definition: thread.c:687
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:528
free_cus
static void free_cus(VVCFrameContext *fc)
Definition: dec.c:346
tl_init_fn
void(* tl_init_fn)(TabList *l, VVCFrameContext *fc)
Definition: dec.c:316
ff_aom_apply_film_grain
int ff_aom_apply_film_grain(AVFrame *out, const AVFrame *in, const AVFilmGrainParams *params)
Definition: aom_film_grain.c:68
VVCSH::r
const H266RawSliceHeader * r
RefStruct reference.
Definition: ps.h:239
FFCodec
Definition: codec_internal.h:127
IS_RADL
#define IS_RADL(s)
Definition: ps.h:36
msm_tl_init
static void msm_tl_init(TabList *l, VVCFrameContext *fc)
Definition: dec.c:264
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:81
FF_HW_SIMPLE_CALL
#define FF_HW_SIMPLE_CALL(avctx, function)
Definition: hwaccel_internal.h:176
ctu_nz_tl_init
static void ctu_nz_tl_init(TabList *l, VVCFrameContext *fc)
Definition: dec.c:106
ff_vvc_slice_rpl
int ff_vvc_slice_rpl(VVCContext *s, VVCFrameContext *fc, SliceContext *sc)
Definition: refs.c:533
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:598
H2645NAL::temporal_id
int temporal_id
HEVC only, nuh_temporal_id_plus_1 - 1.
Definition: h2645_parse.h:62
RefPicList
Definition: hevcdec.h:196
thread.h
ff_h274_hash_freep
void ff_h274_hash_freep(H274HashContext **ctx)
Definition: h274.c:871
min_pu_tl_init
static void min_pu_tl_init(TabList *l, VVCFrameContext *fc)
Definition: dec.c:163
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:77
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:364
pixel_buffer_nz_tl_init
static void pixel_buffer_nz_tl_init(TabList *l, VVCFrameContext *fc)
Definition: dec.c:228
close
static av_cold void close(AVCodecParserContext *s)
Definition: apv_parser.c:135
set_side_data
static int set_side_data(VVCContext *s, VVCFrameContext *fc)
Definition: dec.c:754
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
decode_nal_units
static int decode_nal_units(VVCContext *s, VVCFrameContext *fc, AVPacket *avpkt)
Definition: dec.c:1039
fail
#define fail()
Definition: checkasm.h:196
AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME
#define AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME
If this flag is set, the entries will be zeroed before being returned to the user (after the init or ...
Definition: refstruct.h:221
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1561
IS_B
#define IS_B(rsh)
Definition: ps.h:40
GetBitContext
Definition: get_bits.h:108
ff_vvc_decode_sh
int ff_vvc_decode_sh(VVCSH *sh, const VVCFrameParamSets *fps, const CodedBitstreamUnit *unit)
Definition: ps.c:1482
av_film_grain_params_select
const AVFilmGrainParams * av_film_grain_params_select(const AVFrame *frame)
Select the most appropriate film grain parameters set for the frame, taking into account the frame's ...
Definition: film_grain_params.c:53
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:488
ff_videodsp_init
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
Definition: videodsp.c:39
AV_CODEC_FLAG_LOW_DELAY
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
Definition: avcodec.h:314
SliceContext::rpl
RefPicList * rpl
Definition: dec.h:118
tl_zero
static int tl_zero(TabList *l)
Definition: dec.c:95
VVC_IDR_W_RADL
@ VVC_IDR_W_RADL
Definition: vvc.h:36
refstruct.h
ff_vvc_executor_free
void ff_vvc_executor_free(FFExecutor **e)
Definition: thread.c:698
ff_vvc_frame_ps_free
void ff_vvc_frame_ps_free(VVCFrameParamSets *fps)
Definition: ps.c:1079
VVC_EOS_NUT
@ VVC_EOS_NUT
Definition: vvc.h:50
ff_vvc_frame_submit
int ff_vvc_frame_submit(VVCContext *s, VVCFrameContext *fc)
Definition: thread.c:808
GDR_SET_RECOVERED
#define GDR_SET_RECOVERED(s)
Definition: ps.h:44
frame_context_setup
static int frame_context_setup(VVCFrameContext *fc, VVCContext *s)
Definition: dec.c:704
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:51
vvc_decode_frame
static int vvc_decode_frame(AVCodecContext *avctx, AVFrame *output, int *got_output, AVPacket *avpkt)
Definition: dec.c:1191
H266RawSliceHeader::num_ref_idx_active
uint8_t num_ref_idx_active[2]
NumRefIdxActive[].
Definition: cbs_h266.h:839
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
H266RawSlice::data
uint8_t * data
Definition: cbs_h266.h:846
film_grain_params.h
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
vvc_decode_init
static av_cold int vvc_decode_init(AVCodecContext *avctx)
Definition: dec.c:1263
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:528
RefPicList::refs
VVCRefPic refs[VVC_MAX_REF_ENTRIES]
Definition: dec.h:58
smvd_find_fxn
int(* smvd_find_fxn)(const int idx, const int diff, const int old_diff)
Definition: dec.c:428
ff_vvc_unref_frame
void ff_vvc_unref_frame(VVCFrameContext *fc, VVCFrame *frame, int flags)
Definition: refs.c:44
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:515
ff_vvc_frame_wait
int ff_vvc_frame_wait(VVCContext *s, VVCFrameContext *fc)
Definition: thread.c:837
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:129
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:341
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_vvc_decoder
const FFCodec ff_vvc_decoder
Definition: dec.c:1309
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
SliceContext::slice_idx
int slice_idx
Definition: dec.h:114
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
frame_context_for_each_tl
static int frame_context_for_each_tl(VVCFrameContext *fc, int(*unary_fn)(TabList *l))
Definition: dec.c:318
ff_thread_get_buffer
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: pthread_frame.c:1048
AV_CODEC_CAP_OTHER_THREADS
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition: codec.h:109
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:493
pic_arrays_init
static int pic_arrays_init(VVCContext *s, VVCFrameContext *fc)
Definition: dec.c:364
vvc_decode_free
static av_cold int vvc_decode_free(AVCodecContext *avctx)
Definition: dec.c:1238
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:298
pic_arrays_free
static void pic_arrays_free(VVCFrameContext *fc)
Definition: dec.c:354
VVCSH
Definition: ps.h:238
slice_init_entry_points
static int slice_init_entry_points(SliceContext *sc, VVCFrameContext *fc, const H2645NAL *nal, const CodedBitstreamUnit *unit)
Definition: dec.c:563
ff_vvc_clear_refs
void ff_vvc_clear_refs(VVCFrameContext *fc)
Definition: refs.c:86
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
decode.h
IS_IDR
#define IS_IDR(s)
Definition: hevcdec.h:76
Palette::size
uint8_t size
Definition: ctu.h:283
H2645NAL::skipped_bytes_pos
int * skipped_bytes_pos
Definition: h2645_parse.h:71
TabList::tabs
Tab tabs[TAB_MAX]
Definition: dec.c:51
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
ff_vvc_default_scale_m
uint8_t ff_vvc_default_scale_m[64 *64]
Definition: data.c:1641
AV_FILM_GRAIN_PARAMS_NONE
@ AV_FILM_GRAIN_PARAMS_NONE
Definition: film_grain_params.h:25
H2645NAL::type
int type
NAL unit type.
Definition: h2645_parse.h:52
min_tu_tl_init
static void min_tu_tl_init(TabList *l, VVCFrameContext *fc)
Definition: dec.c:187
get_frame_context
static VVCFrameContext * get_frame_context(const VVCContext *s, const VVCFrameContext *fc, const int delta)
Definition: dec.c:606
frame_context_free
static av_cold void frame_context_free(VVCFrameContext *fc)
Definition: dec.c:655
GetBitContext::buffer
const uint8_t * buffer
Definition: get_bits.h:109
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:529
H2645NAL::raw_size
int raw_size
Definition: h2645_parse.h:44
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
NULL
#define NULL
Definition: coverity.c:32
ff_vvc_frame_thread_init
int ff_vvc_frame_thread_init(VVCFrameContext *fc)
Definition: thread.c:743
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:597
TabList
Definition: dec.c:50
get_ep_size
static int get_ep_size(const H266RawSliceHeader *rsh, GetBitContext *gb, const H2645NAL *nal, const int header_size, const int ep_index)
Definition: dec.c:512
hwaccel_internal.h
VVCSH::ref_idx_sym
int8_t ref_idx_sym[2]
RefIdxSymL0, RefIdxSymL1.
Definition: ps.h:248
HWACCEL_MAX
#define HWACCEL_MAX
frame_setup
static int frame_setup(VVCFrameContext *fc, VVCContext *s)
Definition: dec.c:925
SliceContext::eps
struct EntryPoint * eps
Definition: dec.h:116
frame_end
static int frame_end(VVCContext *s, VVCFrameContext *fc)
Definition: dec.c:1078
VVC_PREFIX_SEI_NUT
@ VVC_PREFIX_SEI_NUT
Definition: vvc.h:52
profiles.h
CodedBitstreamH266Context::common
CodedBitstreamH2645Context common
Definition: cbs_h266.h:860
CodedBitstreamH2645Context::read_packet
H2645Packet read_packet
Definition: cbs_h2645.h:32
RefPicListTab
Definition: hevcdec.h:203
aom_film_grain.h
MAX_CTU_SIZE
#define MAX_CTU_SIZE
Definition: ctu.h:33
AV_EF_CRCCHECK
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
Definition: defs.h:48
VVCRefPic::is_lt
int is_lt
Definition: dec.h:50
sei
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
Definition: cbs_h264_syntax_template.c:858
TL_ADD
#define TL_ADD(t, s)
Definition: dec.c:58
AVOnce
#define AVOnce
Definition: thread.h:202
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
IS_RASL
#define IS_RASL(s)
Definition: ps.h:35
check_film_grain
static int check_film_grain(VVCContext *s, VVCFrameContext *fc)
Definition: dec.c:762
TransformUnit
Definition: hevcdec.h:335
TAB_MAX
#define TAB_MAX
Definition: dec.c:43
SliceContext
Definition: mss12.h:70
av_cpu_count
int av_cpu_count(void)
Definition: cpu.c:221
VVCSEI
Definition: sei.h:36
ff_vvc_flush_dpb
void ff_vvc_flush_dpb(VVCFrameContext *fc)
Definition: refs.c:93
export_frame_params
static int export_frame_params(VVCContext *s, const VVCFrameContext *fc)
Definition: dec.c:903
H266RawSliceHeader::sh_entry_point_offset_minus1
uint32_t sh_entry_point_offset_minus1[VVC_MAX_ENTRY_POINTS]
Definition: cbs_h266.h:834
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
TabList::nb_tabs
int nb_tabs
Definition: dec.c:52
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:547
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
min_cb_nz_tl_init
static void min_cb_nz_tl_init(TabList *l, VVCFrameContext *fc)
Definition: dec.c:139
height
#define height
Definition: dsp.h:89
Tab
Definition: dec.c:45
av_frame_ref
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:276
codec_internal.h
VVC_VPS_NUT
@ VVC_VPS_NUT
Definition: vvc.h:43
ALF_PADDING_SIZE
#define ALF_PADDING_SIZE
Definition: ctu.h:76
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
cpu.h
vvc_decode_flush
static av_cold void vvc_decode_flush(AVCodecContext *avctx)
Definition: dec.c:1220
FF_CODEC_CAP_EXPORTS_CROPPING
#define FF_CODEC_CAP_EXPORTS_CROPPING
The decoder sets the cropping fields in the output frames manually.
Definition: codec_internal.h:60
ff_vvc_frame_thread_free
void ff_vvc_frame_thread_free(VVCFrameContext *fc)
Definition: thread.c:703
size
int size
Definition: twinvq_data.h:10344
EntryPoint::cc
CABACContext cc
Definition: ctu.h:371
EntryPoint::ctu_end
int ctu_end
Definition: ctu.h:374
max_negtive
static int max_negtive(const int idx, const int diff, const int max_diff)
Definition: dec.c:423
ref_frame
static int ref_frame(VVCFrame *dst, const VVCFrame *src)
Definition: dec.c:613
get_decoded_frame
static int get_decoded_frame(VVCContext *s, AVFrame *output, int *got_output)
Definition: dec.c:1170
min_tu_nz_tl_init
static void min_tu_nz_tl_init(TabList *l, VVCFrameContext *fc)
Definition: dec.c:205
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.
H2645NAL
Definition: h2645_parse.h:34
VVCRefPic::poc
int poc
Definition: dec.h:49
AVFilmGrainParams
This structure describes how to handle film grain synthesis in video for specific codecs.
Definition: film_grain_params.h:201
GetBitContext::index
int index
Definition: get_bits.h:110
SliceContext::ref
void * ref
RefStruct reference, backing slice data.
Definition: dec.h:119
AVCodecHWConfigInternal
Definition: hwconfig.h:25
MvField
Definition: hevcdec.h:310
refs.h
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:166
VVCFrame
Definition: dec.h:73
ff_vvc_dsp_init
void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth)
Definition: dsp.c:86
CodedBitstreamH266Context
Definition: cbs_h266.h:858
AV_CODEC_ID_VVC
@ AV_CODEC_ID_VVC
Definition: codec_id.h:252
MAX_CONTROL_POINTS
#define MAX_CONTROL_POINTS
Definition: ctu.h:67
VVCSH::ctb_addr_in_curr_slice
const uint32_t * ctb_addr_in_curr_slice
CtbAddrInCurrSlice.
Definition: ps.h:244
frame_start
static int frame_start(VVCContext *s, VVCFrameContext *fc, SliceContext *sc)
Definition: dec.c:798
VVC_TRAIL_NUT
@ VVC_TRAIL_NUT
Definition: vvc.h:29
VVC_SPS_NUT
@ VVC_SPS_NUT
Definition: vvc.h:44
AV_PIX_FMT_VAAPI
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition: pixfmt.h:126
zero
static int zero(InterplayACMContext *s, unsigned ind, unsigned col)
Definition: interplayacm.c:121
ff_vvc_output_frame
int ff_vvc_output_frame(VVCContext *s, VVCFrameContext *fc, AVFrame *out, const int no_output_of_prior_pics_flag, int flush)
Definition: refs.c:261
av_refstruct_unref
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
ff_init_cabac_decoder
int ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size)
Definition: cabac.c:162
H2645Packet::nals
H2645NAL * nals
Definition: h2645_parse.h:83
ff_vvc_sei_decode
int ff_vvc_sei_decode(VVCSEI *s, const H266RawSEI *sei, const struct VVCFrameContext *fc)
Definition: sei.c:179
H266RawSliceHeader
Definition: cbs_h266.h:771
H266RawSliceHeader::num_entry_points
uint32_t num_entry_points
NumEntryPoints.
Definition: cbs_h266.h:838
TabList::realloc
int realloc
Definition: dec.c:55
CR
#define CR
Definition: filter.c:33
ff_h274_apply_film_grain
int ff_h274_apply_film_grain(AVFrame *out_frame, const AVFrame *in_frame, H274FilmGrainDatabase *database, const AVFilmGrainParams *params)
Definition: h274.c:221
SliceContext::nb_eps
int nb_eps
Definition: dec.h:117
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:514
VVC_SUFFIX_SEI_NUT
@ VVC_SUFFIX_SEI_NUT
Definition: vvc.h:53
delta
float delta
Definition: vorbis_enc_data.h:430
ff_vvc_decode_aps
int ff_vvc_decode_aps(VVCParamSets *ps, const CodedBitstreamUnit *unit)
Definition: ps.c:1286
H266RawSlice::header_size
size_t header_size
Definition: cbs_h266.h:848
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:521
VVC_IDR_N_LP
@ VVC_IDR_N_LP
Definition: vvc.h:37
H266RawSlice::data_size
size_t data_size
Definition: cbs_h266.h:849
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:494
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
EntryPoint
Definition: ctu.h:363
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
VVC_MAX_SAMPLE_ARRAYS
@ VVC_MAX_SAMPLE_ARRAYS
Definition: vvc.h:77
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
EntryPoint::pp
Palette pp[VVC_MAX_SAMPLE_ARRAYS]
Definition: ctu.h:368
slice_start
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition: dec.c:842
ff_vvc_ps_uninit
void ff_vvc_ps_uninit(VVCParamSets *ps)
Definition: ps.c:1089
ret
ret
Definition: filter_design.txt:187
H2645NAL::raw_data
const uint8_t * raw_data
Definition: h2645_parse.h:45
VVCFrame::frame
struct AVFrame * frame
Definition: dec.h:74
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
ibc_tl_init
static void ibc_tl_init(TabList *l, VVCFrameContext *fc)
Definition: dec.c:291
ff_vvc_sei_replace
int ff_vvc_sei_replace(VVCSEI *dst, const VVCSEI *src)
Definition: sei.c:242
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
av_refstruct_pool_alloc
AVRefStructPool * av_refstruct_pool_alloc(size_t size, unsigned flags)
Equivalent to av_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL)
Definition: refstruct.c:335
VVC_PPS_NUT
@ VVC_PPS_NUT
Definition: vvc.h:45
ispmf_tl_init
static void ispmf_tl_init(TabList *l, VVCFrameContext *fc)
Definition: dec.c:278
slices_free
static void slices_free(VVCFrameContext *fc)
Definition: dec.c:468
AVCodecContext
main external API structure.
Definition: avcodec.h:431
eps_free
static void eps_free(SliceContext *slice)
Definition: dec.c:462
VVC_PREFIX_APS_NUT
@ VVC_PREFIX_APS_NUT
Definition: vvc.h:46
AV_FILM_GRAIN_PARAMS_H274
@ AV_FILM_GRAIN_PARAMS_H274
The union is valid when interpreted as AVFilmGrainH274Params (codec.h274)
Definition: film_grain_params.h:35
ff_h274_film_grain_params_supported
static int ff_h274_film_grain_params_supported(int model_id, enum AVPixelFormat pix_fmt)
Check whether ff_h274_apply_film_grain() supports the given parameter combination.
Definition: h274.h:49
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
TabList::zero
int zero
Definition: dec.c:54
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
FF_HW_CALL
#define FF_HW_CALL(avctx, function,...)
Definition: hwaccel_internal.h:173
VVC_SUFFIX_APS_NUT
@ VVC_SUFFIX_APS_NUT
Definition: vvc.h:47
Tab::size
size_t size
Definition: dec.c:47
ep_init_cabac_decoder
static int ep_init_cabac_decoder(EntryPoint *ep, GetBitContext *gb, const int size)
Definition: dec.c:535
pps
uint64_t pps
Definition: dovi_rpuenc.c:36
imf
#define imf
Definition: vf_colormatrix.c:113
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
get_format
static enum AVPixelFormat get_format(AVCodecContext *avctx, const VVCSPS *sps)
Definition: dec.c:878
VVC_CRA_NUT
@ VVC_CRA_NUT
Definition: vvc.h:38
ff_vvc_set_new_ref
int ff_vvc_set_new_ref(VVCContext *s, VVCFrameContext *fc, AVFrame **frame)
Definition: refs.c:218
wait_delayed_frame
static int wait_delayed_frame(VVCContext *s, AVFrame *output, int *got_output)
Definition: dec.c:1125
frame_context_init
static av_cold int frame_context_init(VVCFrameContext *fc, AVCodecContext *avctx)
Definition: dec.c:675
ALF_BORDER_CHROMA
#define ALF_BORDER_CHROMA
Definition: ctu.h:80
av_log_once
void av_log_once(void *avcl, int initial_level, int subsequent_level, int *state, const char *fmt,...)
Definition: log.c:449
ff_h274_hash_verify
int ff_h274_hash_verify(H274HashContext *c, const H274SEIPictureHash *hash, const AVFrame *frame, const int coded_width, const int coded_height)
Definition: h274.c:912
ff_vvc_frame_rpl
int ff_vvc_frame_rpl(VVCContext *s, VVCFrameContext *fc, SliceContext *sc)
Definition: refs.c:592
ff_vvc_profiles
const AVProfile ff_vvc_profiles[]
Definition: profiles.c:91
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
init_default_scale_m
static av_cold void init_default_scale_m(void)
Definition: dec.c:1257
FF_CODEC_CAP_AUTO_THREADS
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: codec_internal.h:72
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
av_refstruct_pool_uninit
static void av_refstruct_pool_uninit(AVRefStructPool **poolp)
Mark the pool as being available for freeing.
Definition: refstruct.h:292
min_pu_nz_tl_init
static void min_pu_nz_tl_init(TabList *l, VVCFrameContext *fc)
Definition: dec.c:174
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
AVPacket
This structure stores compressed data.
Definition: packet.h:523
SliceContext::sh
VVCSH sh
Definition: dec.h:115
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
HWACCEL_VAAPI
#define HWACCEL_VAAPI(codec)
Definition: hwconfig.h:70
submit_frame
static int submit_frame(VVCContext *s, VVCFrameContext *fc, AVFrame *output, int *got_output)
Definition: dec.c:1142
VVCFrameContext
Definition: dec.h:122
VVCFrameContext::sei
VVCSEI sei
Definition: dec.h:132
EntryPoint::ctu_start
int ctu_start
Definition: ctu.h:373
IS_I
#define IS_I(rsh)
Definition: ps.h:38
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
tl_free
static int tl_free(TabList *l)
Definition: dec.c:72
tl_init
static void tl_init(TabList *l, const int zero, const int realloc)
Definition: dec.c:65
VVC_EOB_NUT
@ VVC_EOB_NUT
Definition: vvc.h:51
h
h
Definition: vp9dsp_template.c:2070
ctu.h
ff_vvc_per_frame_init
int ff_vvc_per_frame_init(VVCFrameContext *fc)
Definition: dec.c:413
width
#define width
Definition: dsp.h:89
AV_FILM_GRAIN_PARAMS_AV1
@ AV_FILM_GRAIN_PARAMS_AV1
The union is valid when interpreted as AVFilmGrainAOMParams (codec.aom)
Definition: film_grain_params.h:30
AVFilmGrainParams::type
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
Definition: film_grain_params.h:205
min_positive
static int min_positive(const int idx, const int diff, const int min_diff)
Definition: dec.c:418
decode_prefix_sei
static void decode_prefix_sei(VVCFrameContext *fc, VVCContext *s)
Definition: dec.c:739
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375
src
#define src
Definition: vp8dsp.c:248
AV_CODEC_EXPORT_DATA_FILM_GRAIN
#define AV_CODEC_EXPORT_DATA_FILM_GRAIN
Decoding only.
Definition: avcodec.h:400
smvd_find
static int8_t smvd_find(const VVCFrameContext *fc, const SliceContext *sc, int lx, smvd_find_fxn find)
Definition: dec.c:430
ff_vvc_bump_frame
void ff_vvc_bump_frame(VVCContext *s, VVCFrameContext *fc)
Definition: refs.c:328
H266RawSlice
Definition: cbs_h266.h:843
VVCContext
Definition: dec.h:218
dec.h
Tab::tab
void ** tab
Definition: dec.c:46
ff_vvc_ctu_free_cus
void ff_vvc_ctu_free_cus(CodingUnit **cus)
Definition: ctu.c:2864