FFmpeg
av1dec.c
Go to the documentation of this file.
1 /*
2  * AV1 video decoder
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "config_components.h"
22 
26 #include "libavutil/pixdesc.h"
27 #include "libavutil/opt.h"
28 #include "avcodec.h"
29 #include "av1_parse.h"
30 #include "av1dec.h"
31 #include "atsc_a53.h"
32 #include "bytestream.h"
33 #include "codec_internal.h"
34 #include "decode.h"
35 #include "hwaccel_internal.h"
36 #include "internal.h"
37 #include "itut35.h"
38 #include "hwconfig.h"
39 #include "profiles.h"
40 #include "refstruct.h"
41 #include "thread.h"
42 
43 /**< same with Div_Lut defined in spec 7.11.3.7 */
44 static const uint16_t div_lut[AV1_DIV_LUT_NUM] = {
45  16384, 16320, 16257, 16194, 16132, 16070, 16009, 15948, 15888, 15828, 15768,
46  15709, 15650, 15592, 15534, 15477, 15420, 15364, 15308, 15252, 15197, 15142,
47  15087, 15033, 14980, 14926, 14873, 14821, 14769, 14717, 14665, 14614, 14564,
48  14513, 14463, 14413, 14364, 14315, 14266, 14218, 14170, 14122, 14075, 14028,
49  13981, 13935, 13888, 13843, 13797, 13752, 13707, 13662, 13618, 13574, 13530,
50  13487, 13443, 13400, 13358, 13315, 13273, 13231, 13190, 13148, 13107, 13066,
51  13026, 12985, 12945, 12906, 12866, 12827, 12788, 12749, 12710, 12672, 12633,
52  12596, 12558, 12520, 12483, 12446, 12409, 12373, 12336, 12300, 12264, 12228,
53  12193, 12157, 12122, 12087, 12053, 12018, 11984, 11950, 11916, 11882, 11848,
54  11815, 11782, 11749, 11716, 11683, 11651, 11619, 11586, 11555, 11523, 11491,
55  11460, 11429, 11398, 11367, 11336, 11305, 11275, 11245, 11215, 11185, 11155,
56  11125, 11096, 11067, 11038, 11009, 10980, 10951, 10923, 10894, 10866, 10838,
57  10810, 10782, 10755, 10727, 10700, 10673, 10645, 10618, 10592, 10565, 10538,
58  10512, 10486, 10460, 10434, 10408, 10382, 10356, 10331, 10305, 10280, 10255,
59  10230, 10205, 10180, 10156, 10131, 10107, 10082, 10058, 10034, 10010, 9986,
60  9963, 9939, 9916, 9892, 9869, 9846, 9823, 9800, 9777, 9754, 9732,
61  9709, 9687, 9664, 9642, 9620, 9598, 9576, 9554, 9533, 9511, 9489,
62  9468, 9447, 9425, 9404, 9383, 9362, 9341, 9321, 9300, 9279, 9259,
63  9239, 9218, 9198, 9178, 9158, 9138, 9118, 9098, 9079, 9059, 9039,
64  9020, 9001, 8981, 8962, 8943, 8924, 8905, 8886, 8867, 8849, 8830,
65  8812, 8793, 8775, 8756, 8738, 8720, 8702, 8684, 8666, 8648, 8630,
66  8613, 8595, 8577, 8560, 8542, 8525, 8508, 8490, 8473, 8456, 8439,
67  8422, 8405, 8389, 8372, 8355, 8339, 8322, 8306, 8289, 8273, 8257,
68  8240, 8224, 8208, 8192
69 };
70 
71 static uint32_t inverse_recenter(int r, uint32_t v)
72 {
73  if (v > 2 * r)
74  return v;
75  else if (v & 1)
76  return r - ((v + 1) >> 1);
77  else
78  return r + (v >> 1);
79 }
80 
81 static uint32_t decode_unsigned_subexp_with_ref(uint32_t sub_exp,
82  int mx, int r)
83 {
84  if ((r << 1) <= mx) {
85  return inverse_recenter(r, sub_exp);
86  } else {
87  return mx - 1 - inverse_recenter(mx - 1 - r, sub_exp);
88  }
89 }
90 
91 static int32_t decode_signed_subexp_with_ref(uint32_t sub_exp, int low,
92  int high, int r)
93 {
94  int32_t x = decode_unsigned_subexp_with_ref(sub_exp, high - low, r - low);
95  return x + low;
96 }
97 
98 static void read_global_param(AV1DecContext *s, int type, int ref, int idx)
99 {
100  uint8_t primary_frame, prev_frame;
101  uint32_t abs_bits, prec_bits, round, prec_diff, sub, mx;
102  int32_t r, prev_gm_param;
103 
104  primary_frame = s->raw_frame_header->primary_ref_frame;
105  prev_frame = s->raw_frame_header->ref_frame_idx[primary_frame];
106  abs_bits = AV1_GM_ABS_ALPHA_BITS;
107  prec_bits = AV1_GM_ALPHA_PREC_BITS;
108 
109  /* setup_past_independence() sets PrevGmParams to default values. We can
110  * simply point to the current's frame gm_params as they will be initialized
111  * with defaults at this point.
112  */
113  if (s->raw_frame_header->primary_ref_frame == AV1_PRIMARY_REF_NONE)
114  prev_gm_param = s->cur_frame.gm_params[ref][idx];
115  else
116  prev_gm_param = s->ref[prev_frame].gm_params[ref][idx];
117 
118  if (idx < 2) {
120  abs_bits = AV1_GM_ABS_TRANS_ONLY_BITS -
121  !s->raw_frame_header->allow_high_precision_mv;
122  prec_bits = AV1_GM_TRANS_ONLY_PREC_BITS -
123  !s->raw_frame_header->allow_high_precision_mv;
124  } else {
125  abs_bits = AV1_GM_ABS_TRANS_BITS;
126  prec_bits = AV1_GM_TRANS_PREC_BITS;
127  }
128  }
129  round = (idx % 3) == 2 ? (1 << AV1_WARPEDMODEL_PREC_BITS) : 0;
130  prec_diff = AV1_WARPEDMODEL_PREC_BITS - prec_bits;
131  sub = (idx % 3) == 2 ? (1 << prec_bits) : 0;
132  mx = 1 << abs_bits;
133  r = (prev_gm_param >> prec_diff) - sub;
134 
135  s->cur_frame.gm_params[ref][idx] =
136  (decode_signed_subexp_with_ref(s->raw_frame_header->gm_params[ref][idx],
137  -mx, mx + 1, r) << prec_diff) + round;
138 }
139 
140 static uint64_t round_two(uint64_t x, uint16_t n)
141 {
142  if (n == 0)
143  return x;
144  return ((x + ((uint64_t)1 << (n - 1))) >> n);
145 }
146 
147 static int64_t round_two_signed(int64_t x, uint16_t n)
148 {
149  return ((x<0) ? -((int64_t)round_two(-x, n)) : (int64_t)round_two(x, n));
150 }
151 
152 /**
153  * Resolve divisor process.
154  * see spec 7.11.3.7
155  */
156 static int16_t resolve_divisor(uint32_t d, uint16_t *shift)
157 {
158  int32_t e, f;
159 
160  *shift = av_log2(d);
161  e = d - (1 << (*shift));
162  if (*shift > AV1_DIV_LUT_BITS)
164  else
165  f = e << (AV1_DIV_LUT_BITS - (*shift));
166 
168 
169  return div_lut[f];
170 }
171 
172 /**
173  * check if global motion params is valid.
174  * see spec 7.11.3.6
175  */
176 static uint8_t get_shear_params_valid(AV1DecContext *s, int idx)
177 {
178  int16_t alpha, beta, gamma, delta, divf, divs;
179  int64_t v, w;
180  int32_t *param = &s->cur_frame.gm_params[idx][0];
181  if (param[2] <= 0)
182  return 0;
183 
184  alpha = av_clip_int16(param[2] - (1 << AV1_WARPEDMODEL_PREC_BITS));
185  beta = av_clip_int16(param[3]);
186  divf = resolve_divisor(abs(param[2]), &divs);
187  v = (int64_t)param[4] * (1 << AV1_WARPEDMODEL_PREC_BITS);
188  w = (int64_t)param[3] * param[4];
189  gamma = av_clip_int16((int)round_two_signed((v * divf), divs));
190  delta = av_clip_int16(param[5] - (int)round_two_signed((w * divf), divs) - (1 << AV1_WARPEDMODEL_PREC_BITS));
191 
196 
197  if ((4 * abs(alpha) + 7 * abs(beta)) >= (1 << AV1_WARPEDMODEL_PREC_BITS) ||
198  (4 * abs(gamma) + 4 * abs(delta)) >= (1 << AV1_WARPEDMODEL_PREC_BITS))
199  return 0;
200 
201  return 1;
202 }
203 
204 /**
205 * update gm type/params, since cbs already implemented part of this function,
206 * so we don't need to full implement spec.
207 */
209 {
210  const AV1RawFrameHeader *header = s->raw_frame_header;
211  int type, ref;
212 
214  s->cur_frame.gm_type[ref] = AV1_WARP_MODEL_IDENTITY;
215  for (int i = 0; i < 6; i++)
216  s->cur_frame.gm_params[ref][i] = (i % 3 == 2) ?
217  1 << AV1_WARPEDMODEL_PREC_BITS : 0;
218  }
219  if (header->frame_type == AV1_FRAME_KEY ||
220  header->frame_type == AV1_FRAME_INTRA_ONLY)
221  return;
222 
224  if (header->is_global[ref]) {
225  if (header->is_rot_zoom[ref]) {
227  } else {
228  type = header->is_translation[ref] ? AV1_WARP_MODEL_TRANSLATION
230  }
231  } else {
233  }
234  s->cur_frame.gm_type[ref] = type;
235 
236  if (type >= AV1_WARP_MODEL_ROTZOOM) {
237  read_global_param(s, type, ref, 2);
238  read_global_param(s, type, ref, 3);
239  if (type == AV1_WARP_MODEL_AFFINE) {
240  read_global_param(s, type, ref, 4);
241  read_global_param(s, type, ref, 5);
242  } else {
243  s->cur_frame.gm_params[ref][4] = -s->cur_frame.gm_params[ref][3];
244  s->cur_frame.gm_params[ref][5] = s->cur_frame.gm_params[ref][2];
245  }
246  }
248  read_global_param(s, type, ref, 0);
249  read_global_param(s, type, ref, 1);
250  }
251  if (type <= AV1_WARP_MODEL_AFFINE) {
252  s->cur_frame.gm_invalid[ref] = !get_shear_params_valid(s, ref);
253  }
254  }
255 }
256 
258  unsigned int a, unsigned int b)
259 {
260  unsigned int diff = a - b;
261  unsigned int m = 1 << seq->order_hint_bits_minus_1;
262  return (diff & (m - 1)) - (diff & m);
263 }
264 
266 {
267  const AV1RawFrameHeader *header = s->raw_frame_header;
268  const AV1RawSequenceHeader *seq = s->raw_seq;
269 
270  int forward_idx, backward_idx;
271  int forward_hint, backward_hint;
272  int second_forward_idx, second_forward_hint;
273  int ref_hint, dist, i;
274 
275  if (header->frame_type == AV1_FRAME_KEY ||
276  header->frame_type == AV1_FRAME_INTRA_ONLY ||
277  !header->reference_select || !seq->enable_order_hint)
278  return;
279 
280  forward_idx = -1;
281  backward_idx = -1;
282  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
283  ref_hint = s->ref[header->ref_frame_idx[i]].raw_frame_header->order_hint;
284  dist = get_relative_dist(seq, ref_hint, header->order_hint);
285  if (dist < 0) {
286  if (forward_idx < 0 ||
287  get_relative_dist(seq, ref_hint, forward_hint) > 0) {
288  forward_idx = i;
289  forward_hint = ref_hint;
290  }
291  } else if (dist > 0) {
292  if (backward_idx < 0 ||
293  get_relative_dist(seq, ref_hint, backward_hint) < 0) {
294  backward_idx = i;
295  backward_hint = ref_hint;
296  }
297  }
298  }
299 
300  if (forward_idx < 0) {
301  return;
302  } else if (backward_idx >= 0) {
303  s->cur_frame.skip_mode_frame_idx[0] =
304  AV1_REF_FRAME_LAST + FFMIN(forward_idx, backward_idx);
305  s->cur_frame.skip_mode_frame_idx[1] =
306  AV1_REF_FRAME_LAST + FFMAX(forward_idx, backward_idx);
307  return;
308  }
309 
310  second_forward_idx = -1;
311  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
312  ref_hint = s->ref[header->ref_frame_idx[i]].raw_frame_header->order_hint;
313  if (get_relative_dist(seq, ref_hint, forward_hint) < 0) {
314  if (second_forward_idx < 0 ||
315  get_relative_dist(seq, ref_hint, second_forward_hint) > 0) {
316  second_forward_idx = i;
317  second_forward_hint = ref_hint;
318  }
319  }
320  }
321 
322  if (second_forward_idx < 0)
323  return;
324 
325  s->cur_frame.skip_mode_frame_idx[0] =
326  AV1_REF_FRAME_LAST + FFMIN(forward_idx, second_forward_idx);
327  s->cur_frame.skip_mode_frame_idx[1] =
328  AV1_REF_FRAME_LAST + FFMAX(forward_idx, second_forward_idx);
329 }
330 
332 {
333  const AV1RawFrameHeader *header = s->raw_frame_header;
334  int i;
335 
336  if (header->delta_q_y_dc || header->delta_q_u_ac ||
337  header->delta_q_u_dc || header->delta_q_v_ac ||
338  header->delta_q_v_dc) {
339  s->cur_frame.coded_lossless = 0;
340  return;
341  }
342 
343  s->cur_frame.coded_lossless = 1;
344  for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
345  int qindex;
346  if (header->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) {
347  qindex = (header->base_q_idx +
348  header->feature_value[i][AV1_SEG_LVL_ALT_Q]);
349  } else {
350  qindex = header->base_q_idx;
351  }
352  qindex = av_clip_uintp2(qindex, 8);
353 
354  if (qindex) {
355  s->cur_frame.coded_lossless = 0;
356  return;
357  }
358  }
359 }
360 
362 {
363  const AV1RawFrameHeader *header = s->raw_frame_header;
364  const AV1RawSequenceHeader *seq = s->raw_seq;
365  AV1Frame *frame = &s->cur_frame;
366 
367  frame->order_hint = header->order_hint;
368 
369  for (int i = 0; i < AV1_REFS_PER_FRAME; i++) {
370  int ref_name = i + AV1_REF_FRAME_LAST;
371  int ref_slot = header->ref_frame_idx[i];
372  int ref_order_hint = s->ref[ref_slot].order_hint;
373 
374  frame->order_hints[ref_name] = ref_order_hint;
375  if (!seq->enable_order_hint) {
376  frame->ref_frame_sign_bias[ref_name] = 0;
377  } else {
378  frame->ref_frame_sign_bias[ref_name] =
379  get_relative_dist(seq, ref_order_hint,
380  frame->order_hint) > 0;
381  }
382  }
383 }
384 
386 {
387  const AV1RawFrameHeader *header = s->raw_frame_header;
388  const AV1RawFilmGrainParams *film_grain = &header->film_grain, *src;
389  AV1RawFilmGrainParams *dst = &s->cur_frame.film_grain;
390 
391  if (!film_grain->apply_grain)
392  return;
393 
394  if (film_grain->update_grain) {
395  memcpy(dst, film_grain, sizeof(*dst));
396  return;
397  }
398 
399  src = &s->ref[film_grain->film_grain_params_ref_idx].film_grain;
400 
401  memcpy(dst, src, sizeof(*dst));
402  dst->grain_seed = film_grain->grain_seed;
403 }
404 
406 
407 {
408  int cur_tile_num =
409  s->raw_frame_header->tile_cols * s->raw_frame_header->tile_rows;
410  if (s->tile_num < cur_tile_num) {
411  int ret = av_reallocp_array(&s->tile_group_info, cur_tile_num,
412  sizeof(TileGroupInfo));
413  if (ret < 0) {
414  s->tile_num = 0;
415  return ret;
416  }
417  }
418  s->tile_num = cur_tile_num;
419 
420  return 0;
421 }
422 
423 static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_group)
424 {
425  AV1DecContext *s = avctx->priv_data;
426  GetByteContext gb;
427  uint16_t tile_num, tile_row, tile_col;
428  uint32_t size = 0, size_bytes = 0;
429 
430  bytestream2_init(&gb, tile_group->tile_data.data,
431  tile_group->tile_data.data_size);
432  s->tg_start = tile_group->tg_start;
433  s->tg_end = tile_group->tg_end;
434 
435  for (tile_num = tile_group->tg_start; tile_num <= tile_group->tg_end; tile_num++) {
436  tile_row = tile_num / s->raw_frame_header->tile_cols;
437  tile_col = tile_num % s->raw_frame_header->tile_cols;
438 
439  if (tile_num == tile_group->tg_end) {
440  s->tile_group_info[tile_num].tile_size = bytestream2_get_bytes_left(&gb);
441  s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
442  s->tile_group_info[tile_num].tile_row = tile_row;
443  s->tile_group_info[tile_num].tile_column = tile_col;
444  return 0;
445  }
446  size_bytes = s->raw_frame_header->tile_size_bytes_minus1 + 1;
447  if (bytestream2_get_bytes_left(&gb) < size_bytes)
448  return AVERROR_INVALIDDATA;
449  size = 0;
450  for (int i = 0; i < size_bytes; i++)
451  size |= bytestream2_get_byteu(&gb) << 8 * i;
452  if (bytestream2_get_bytes_left(&gb) <= size)
453  return AVERROR_INVALIDDATA;
454  size++;
455 
456  s->tile_group_info[tile_num].tile_size = size;
457  s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
458  s->tile_group_info[tile_num].tile_row = tile_row;
459  s->tile_group_info[tile_num].tile_column = tile_col;
460 
461  bytestream2_skipu(&gb, size);
462  }
463 
464  return 0;
465 
466 }
467 
468 static enum AVPixelFormat get_sw_pixel_format(void *logctx,
469  const AV1RawSequenceHeader *seq)
470 {
471  int bit_depth;
473 
474  if (seq->seq_profile == 2 && seq->color_config.high_bitdepth)
475  bit_depth = seq->color_config.twelve_bit ? 12 : 10;
476  else if (seq->seq_profile <= 2)
477  bit_depth = seq->color_config.high_bitdepth ? 10 : 8;
478  else {
479  av_log(logctx, AV_LOG_ERROR,
480  "Unknown AV1 profile %d.\n", seq->seq_profile);
481  return AV_PIX_FMT_NONE;
482  }
483 
484  if (!seq->color_config.mono_chrome) {
485  // 4:4:4 x:0 y:0, 4:2:2 x:1 y:0, 4:2:0 x:1 y:1
486  if (seq->color_config.subsampling_x == 0 &&
487  seq->color_config.subsampling_y == 0) {
488  if (bit_depth == 8)
490  else if (bit_depth == 10)
492  else if (bit_depth == 12)
494  else
495  av_assert0(0);
496  } else if (seq->color_config.subsampling_x == 1 &&
497  seq->color_config.subsampling_y == 0) {
498  if (bit_depth == 8)
500  else if (bit_depth == 10)
502  else if (bit_depth == 12)
504  else
505  av_assert0(0);
506  } else if (seq->color_config.subsampling_x == 1 &&
507  seq->color_config.subsampling_y == 1) {
508  if (bit_depth == 8)
510  else if (bit_depth == 10)
512  else if (bit_depth == 12)
514  else
515  av_assert0(0);
516  }
517  } else {
518  if (bit_depth == 8)
520  else if (bit_depth == 10)
522  else if (bit_depth == 12)
524  else
525  av_assert0(0);
526  }
527 
528  return pix_fmt;
529 }
530 
532 {
533  AV1DecContext *s = avctx->priv_data;
534  const AV1RawSequenceHeader *seq = s->raw_seq;
535  int ret;
536  enum AVPixelFormat pix_fmt = get_sw_pixel_format(avctx, seq);
537 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
538  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
539  CONFIG_AV1_D3D12VA_HWACCEL + \
540  CONFIG_AV1_NVDEC_HWACCEL + \
541  CONFIG_AV1_VAAPI_HWACCEL + \
542  CONFIG_AV1_VDPAU_HWACCEL + \
543  CONFIG_AV1_VULKAN_HWACCEL)
544  enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
545 
546  if (pix_fmt == AV_PIX_FMT_NONE)
547  return -1;
548 
549  switch (pix_fmt) {
550  case AV_PIX_FMT_YUV420P:
551 #if CONFIG_AV1_DXVA2_HWACCEL
552  *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
553 #endif
554 #if CONFIG_AV1_D3D11VA_HWACCEL
555  *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
556  *fmtp++ = AV_PIX_FMT_D3D11;
557 #endif
558 #if CONFIG_AV1_D3D12VA_HWACCEL
559  *fmtp++ = AV_PIX_FMT_D3D12;
560 #endif
561 #if CONFIG_AV1_NVDEC_HWACCEL
562  *fmtp++ = AV_PIX_FMT_CUDA;
563 #endif
564 #if CONFIG_AV1_VAAPI_HWACCEL
565  *fmtp++ = AV_PIX_FMT_VAAPI;
566 #endif
567 #if CONFIG_AV1_VDPAU_HWACCEL
568  *fmtp++ = AV_PIX_FMT_VDPAU;
569 #endif
570 #if CONFIG_AV1_VULKAN_HWACCEL
571  *fmtp++ = AV_PIX_FMT_VULKAN;
572 #endif
573  break;
575 #if CONFIG_AV1_DXVA2_HWACCEL
576  *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
577 #endif
578 #if CONFIG_AV1_D3D11VA_HWACCEL
579  *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
580  *fmtp++ = AV_PIX_FMT_D3D11;
581 #endif
582 #if CONFIG_AV1_D3D12VA_HWACCEL
583  *fmtp++ = AV_PIX_FMT_D3D12;
584 #endif
585 #if CONFIG_AV1_NVDEC_HWACCEL
586  *fmtp++ = AV_PIX_FMT_CUDA;
587 #endif
588 #if CONFIG_AV1_VAAPI_HWACCEL
589  *fmtp++ = AV_PIX_FMT_VAAPI;
590 #endif
591 #if CONFIG_AV1_VDPAU_HWACCEL
592  *fmtp++ = AV_PIX_FMT_VDPAU;
593 #endif
594 #if CONFIG_AV1_VULKAN_HWACCEL
595  *fmtp++ = AV_PIX_FMT_VULKAN;
596 #endif
597  break;
599 #if CONFIG_AV1_VULKAN_HWACCEL
600  *fmtp++ = AV_PIX_FMT_VULKAN;
601 #endif
602  break;
603  case AV_PIX_FMT_YUV422P:
604 #if CONFIG_AV1_VULKAN_HWACCEL
605  *fmtp++ = AV_PIX_FMT_VULKAN;
606 #endif
607  break;
609 #if CONFIG_AV1_VULKAN_HWACCEL
610  *fmtp++ = AV_PIX_FMT_VULKAN;
611 #endif
612  break;
614 #if CONFIG_AV1_VULKAN_HWACCEL
615  *fmtp++ = AV_PIX_FMT_VULKAN;
616 #endif
617  break;
618  case AV_PIX_FMT_YUV444P:
619 #if CONFIG_AV1_VULKAN_HWACCEL
620  *fmtp++ = AV_PIX_FMT_VULKAN;
621 #endif
622  break;
624 #if CONFIG_AV1_VULKAN_HWACCEL
625  *fmtp++ = AV_PIX_FMT_VULKAN;
626 #endif
627  break;
629 #if CONFIG_AV1_VULKAN_HWACCEL
630  *fmtp++ = AV_PIX_FMT_VULKAN;
631 #endif
632  break;
633  case AV_PIX_FMT_GRAY8:
634 #if CONFIG_AV1_NVDEC_HWACCEL
635  *fmtp++ = AV_PIX_FMT_CUDA;
636 #endif
637  break;
638  case AV_PIX_FMT_GRAY10:
639 #if CONFIG_AV1_NVDEC_HWACCEL
640  *fmtp++ = AV_PIX_FMT_CUDA;
641 #endif
642  break;
643  }
644 
645  *fmtp++ = pix_fmt;
646  *fmtp = AV_PIX_FMT_NONE;
647 
648  for (int i = 0; pix_fmts[i] != pix_fmt; i++)
649  if (pix_fmts[i] == avctx->pix_fmt) {
650  s->pix_fmt = pix_fmt;
651  return 1;
652  }
653 
654  ret = ff_get_format(avctx, pix_fmts);
655 
656  /**
657  * check if the HW accel is inited correctly. If not, return un-implemented.
658  * Since now the av1 decoder doesn't support native decode, if it will be
659  * implemented in the future, need remove this check.
660  */
661  if (!avctx->hwaccel) {
662  av_log(avctx, AV_LOG_ERROR, "Your platform doesn't support"
663  " hardware accelerated AV1 decoding.\n");
664  avctx->pix_fmt = AV_PIX_FMT_NONE;
665  return AVERROR(ENOSYS);
666  }
667 
668  s->pix_fmt = pix_fmt;
669  avctx->pix_fmt = ret;
670 
671  av_log(avctx, AV_LOG_DEBUG, "AV1 decode get format: %s.\n",
672  av_get_pix_fmt_name(avctx->pix_fmt));
673 
674  return 0;
675 }
676 
678 {
679  av_frame_unref(f->f);
680  ff_refstruct_unref(&f->hwaccel_picture_private);
681  ff_refstruct_unref(&f->header_ref);
682  f->raw_frame_header = NULL;
683  f->spatial_id = f->temporal_id = 0;
684  memset(f->skip_mode_frame_idx, 0,
685  2 * sizeof(uint8_t));
686  memset(&f->film_grain, 0, sizeof(f->film_grain));
687  f->coded_lossless = 0;
688 }
689 
690 static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src)
691 {
692  int ret;
693 
694  ff_refstruct_replace(&dst->header_ref, src->header_ref);
695 
696  dst->raw_frame_header = src->raw_frame_header;
697 
698  if (!src->f->buf[0])
699  return 0;
700 
701  ret = av_frame_ref(dst->f, src->f);
702  if (ret < 0)
703  goto fail;
704 
706  src->hwaccel_picture_private);
707 
708  dst->spatial_id = src->spatial_id;
709  dst->temporal_id = src->temporal_id;
710  memcpy(dst->gm_invalid,
711  src->gm_invalid,
712  AV1_NUM_REF_FRAMES * sizeof(uint8_t));
713  memcpy(dst->gm_type,
714  src->gm_type,
715  AV1_NUM_REF_FRAMES * sizeof(uint8_t));
716  memcpy(dst->gm_params,
717  src->gm_params,
718  AV1_NUM_REF_FRAMES * 6 * sizeof(int32_t));
719  memcpy(dst->skip_mode_frame_idx,
720  src->skip_mode_frame_idx,
721  2 * sizeof(uint8_t));
722  memcpy(&dst->film_grain,
723  &src->film_grain,
724  sizeof(dst->film_grain));
725  dst->coded_lossless = src->coded_lossless;
726 
727  dst->order_hint = src->order_hint;
728  memcpy(dst->ref_frame_sign_bias, src->ref_frame_sign_bias,
729  sizeof(dst->ref_frame_sign_bias));
730  memcpy(dst->order_hints, src->order_hints,
731  sizeof(dst->order_hints));
732 
733  dst->force_integer_mv = src->force_integer_mv;
734 
735  return 0;
736 
737 fail:
738  av1_frame_unref(dst);
739  return AVERROR(ENOMEM);
740 }
741 
743 {
744  AV1DecContext *s = avctx->priv_data;
745  AV1RawMetadataITUTT35 itut_t35;
746 
747  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) {
748  if (s->ref[i].f) {
749  av1_frame_unref(&s->ref[i]);
750  av_frame_free(&s->ref[i].f);
751  }
752  }
753  if (s->cur_frame.f) {
754  av1_frame_unref(&s->cur_frame);
755  av_frame_free(&s->cur_frame.f);
756  }
757  av_buffer_unref(&s->seq_data_ref);
758  ff_refstruct_unref(&s->seq_ref);
759  ff_refstruct_unref(&s->header_ref);
760  ff_refstruct_unref(&s->cll_ref);
761  ff_refstruct_unref(&s->mdcv_ref);
762  av_freep(&s->tile_group_info);
763 
764  while (s->itut_t35_fifo && av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0)
765  av_buffer_unref(&itut_t35.payload_ref);
766  av_fifo_freep2(&s->itut_t35_fifo);
767 
768  ff_cbs_fragment_free(&s->current_obu);
769  ff_cbs_close(&s->cbc);
770  ff_dovi_ctx_unref(&s->dovi);
771 
772  return 0;
773 }
774 
776  const AV1RawSequenceHeader *seq)
777 {
778  int width = seq->max_frame_width_minus_1 + 1;
779  int height = seq->max_frame_height_minus_1 + 1;
780 
781  avctx->profile = seq->seq_profile;
782  avctx->level = seq->seq_level_idx[0];
783 
784  avctx->color_range =
789 
790  switch (seq->color_config.chroma_sample_position) {
791  case AV1_CSP_VERTICAL:
793  break;
794  case AV1_CSP_COLOCATED:
796  break;
797  }
798 
799  if (seq->film_grain_params_present)
801  else
803 
804  if (avctx->width != width || avctx->height != height) {
805  int ret = ff_set_dimensions(avctx, width, height);
806  if (ret < 0)
807  return ret;
808  }
809 
810  if (seq->timing_info_present_flag)
813  seq->timing_info.time_scale);
814 
815  if (avctx->pix_fmt == AV_PIX_FMT_NONE)
816  avctx->pix_fmt = get_sw_pixel_format(avctx, seq);
817 
818  return 0;
819 }
820 
822  const AV1RawFrameHeader *header)
823 {
824  AVRational aspect_ratio;
825  int width = header->frame_width_minus_1 + 1;
826  int height = header->frame_height_minus_1 + 1;
827  int r_width = header->render_width_minus_1 + 1;
828  int r_height = header->render_height_minus_1 + 1;
829  int ret;
830 
831  if (avctx->width != width || avctx->height != height) {
832  ret = ff_set_dimensions(avctx, width, height);
833  if (ret < 0)
834  return ret;
835  }
836 
837  av_reduce(&aspect_ratio.num, &aspect_ratio.den,
838  (int64_t)height * r_width,
839  (int64_t)width * r_height,
840  INT_MAX);
841 
842  if (av_cmp_q(avctx->sample_aspect_ratio, aspect_ratio)) {
843  ret = ff_set_sar(avctx, aspect_ratio);
844  if (ret < 0)
845  return ret;
846  }
847 
848  return 0;
849 }
850 
859 };
860 
862 {
863  AV1DecContext *s = avctx->priv_data;
865  const AVPacketSideData *sd;
866  int ret;
867 
868  s->avctx = avctx;
869  s->pkt = avctx->internal->in_pkt;
870  s->pix_fmt = AV_PIX_FMT_NONE;
871 
872  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) {
873  s->ref[i].f = av_frame_alloc();
874  if (!s->ref[i].f)
875  return AVERROR(ENOMEM);
876  }
877 
878  s->cur_frame.f = av_frame_alloc();
879  if (!s->cur_frame.f)
880  return AVERROR(ENOMEM);
881 
882  ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, avctx);
883  if (ret < 0)
884  return ret;
885 
886  s->cbc->decompose_unit_types = decompose_unit_types;
887  s->cbc->nb_decompose_unit_types = FF_ARRAY_ELEMS(decompose_unit_types);
888 
889  s->itut_t35_fifo = av_fifo_alloc2(1, sizeof(AV1RawMetadataITUTT35),
891  if (!s->itut_t35_fifo)
892  return AVERROR(ENOMEM);
893 
894  av_opt_set_int(s->cbc->priv_data, "operating_point", s->operating_point, 0);
895 
896  if (avctx->extradata && avctx->extradata_size) {
898  &s->current_obu,
899  avctx);
900  if (ret < 0) {
901  av_log(avctx, AV_LOG_WARNING, "Failed to read extradata.\n");
902  goto end;
903  }
904 
905  seq = ((CodedBitstreamAV1Context *)(s->cbc->priv_data))->sequence_header;
906  if (!seq) {
907  av_log(avctx, AV_LOG_WARNING, "No sequence header available.\n");
908  goto end;
909  }
910 
911  ret = set_context_with_sequence(avctx, seq);
912  if (ret < 0) {
913  av_log(avctx, AV_LOG_WARNING, "Failed to set decoder context.\n");
914  goto end;
915  }
916 
917  end:
918  ff_cbs_fragment_reset(&s->current_obu);
919  }
920 
921  s->dovi.logctx = avctx;
922  s->dovi.dv_profile = 10; // default for AV1
924  if (sd && sd->size > 0)
926 
927  return ret;
928 }
929 
931 {
932  AV1DecContext *s = avctx->priv_data;
933  AV1RawFrameHeader *header= s->raw_frame_header;
934  AVFrame *frame;
935  int ret;
936 
938  if (ret < 0) {
939  av_log(avctx, AV_LOG_ERROR, "Failed to update context with frame header\n");
940  return ret;
941  }
942 
943  if ((ret = ff_thread_get_buffer(avctx, f->f, AV_GET_BUFFER_FLAG_REF)) < 0)
944  goto fail;
945 
946  frame = f->f;
947  if (header->frame_type == AV1_FRAME_KEY)
949  else
951 
952  switch (header->frame_type) {
953  case AV1_FRAME_KEY:
956  break;
957  case AV1_FRAME_INTER:
959  break;
960  case AV1_FRAME_SWITCH:
962  break;
963  }
964 
965  ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private);
966  if (ret < 0)
967  goto fail;
968 
969  return 0;
970 
971 fail:
973  return ret;
974 }
975 
977  const AV1RawMetadataITUTT35 *itut_t35)
978 {
979  GetByteContext gb;
980  AV1DecContext *s = avctx->priv_data;
981  int ret, provider_code;
982 
983  bytestream2_init(&gb, itut_t35->payload, itut_t35->payload_size);
984 
985  provider_code = bytestream2_get_be16(&gb);
986  switch (provider_code) {
988  uint32_t user_identifier = bytestream2_get_be32(&gb);
989  switch (user_identifier) {
990  case MKBETAG('G', 'A', '9', '4'): { // closed captions
991  AVBufferRef *buf = NULL;
992 
994  if (ret < 0)
995  return ret;
996  if (!ret)
997  break;
998 
1000  if (ret < 0)
1001  return ret;
1002 
1004  break;
1005  }
1006  default: // ignore unsupported identifiers
1007  break;
1008  }
1009  break;
1010  }
1012  AVDynamicHDRPlus *hdrplus;
1013  int provider_oriented_code = bytestream2_get_be16(&gb);
1014  int application_identifier = bytestream2_get_byte(&gb);
1015 
1017  provider_oriented_code != 1 || application_identifier != 4)
1018  break;
1019 
1021  if (!hdrplus)
1022  return AVERROR(ENOMEM);
1023 
1024  ret = av_dynamic_hdr_plus_from_t35(hdrplus, gb.buffer,
1026  if (ret < 0)
1027  return ret;
1028  break;
1029  }
1031  int provider_oriented_code = bytestream2_get_be32(&gb);
1033  provider_oriented_code != 0x800)
1034  break;
1035 
1036  ret = ff_dovi_rpu_parse(&s->dovi, gb.buffer, gb.buffer_end - gb.buffer);
1037  if (ret < 0) {
1038  av_log(avctx, AV_LOG_WARNING, "Error parsing DOVI OBU.\n");
1039  break; // ignore
1040  }
1041 
1042  ret = ff_dovi_attach_side_data(&s->dovi, frame);
1043  if (ret < 0)
1044  return ret;
1045  break;
1046  }
1047  default: // ignore unsupported provider codes
1048  break;
1049  }
1050 
1051  return 0;
1052 }
1053 
1055 {
1056  AV1DecContext *s = avctx->priv_data;
1057  AV1RawMetadataITUTT35 itut_t35;
1058  int ret = 0;
1059 
1060  if (s->mdcv) {
1061  AVMasteringDisplayMetadata *mastering;
1062 
1063  ret = ff_decode_mastering_display_new(avctx, frame, &mastering);
1064  if (ret < 0)
1065  return ret;
1066 
1067  if (mastering) {
1068  for (int i = 0; i < 3; i++) {
1069  mastering->display_primaries[i][0] = av_make_q(s->mdcv->primary_chromaticity_x[i], 1 << 16);
1070  mastering->display_primaries[i][1] = av_make_q(s->mdcv->primary_chromaticity_y[i], 1 << 16);
1071  }
1072  mastering->white_point[0] = av_make_q(s->mdcv->white_point_chromaticity_x, 1 << 16);
1073  mastering->white_point[1] = av_make_q(s->mdcv->white_point_chromaticity_y, 1 << 16);
1074 
1075  mastering->max_luminance = av_make_q(s->mdcv->luminance_max, 1 << 8);
1076  mastering->min_luminance = av_make_q(s->mdcv->luminance_min, 1 << 14);
1077 
1078  mastering->has_primaries = 1;
1079  mastering->has_luminance = 1;
1080  }
1081  }
1082 
1083  if (s->cll) {
1084  AVContentLightMetadata *light;
1085 
1086  ret = ff_decode_content_light_new(avctx, frame, &light);
1087  if (ret < 0)
1088  return ret;
1089 
1090  if (light) {
1091  light->MaxCLL = s->cll->max_cll;
1092  light->MaxFALL = s->cll->max_fall;
1093  }
1094  }
1095 
1096  while (av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0) {
1097  if (ret >= 0)
1098  ret = export_itut_t35(avctx, frame, &itut_t35);
1099  av_buffer_unref(&itut_t35.payload_ref);
1100  }
1101 
1102  return ret;
1103 }
1104 
1106 {
1107  AV1DecContext *s = avctx->priv_data;
1108  const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
1110  AVFilmGrainParams *fgp;
1111  AVFilmGrainAOMParams *aom;
1112 
1113  av_assert0(pixdesc);
1114  if (!film_grain->apply_grain)
1115  return 0;
1116 
1118  if (!fgp)
1119  return AVERROR(ENOMEM);
1120 
1122  fgp->seed = film_grain->grain_seed;
1123  fgp->width = frame->width;
1124  fgp->height = frame->height;
1125  fgp->color_range = frame->color_range;
1127  fgp->color_trc = frame->color_trc;
1128  fgp->color_space = frame->colorspace;
1129  fgp->subsampling_x = pixdesc->log2_chroma_w;
1130  fgp->subsampling_y = pixdesc->log2_chroma_h;
1131 
1132  aom = &fgp->codec.aom;
1134  aom->scaling_shift = film_grain->grain_scaling_minus_8 + 8;
1135  aom->ar_coeff_lag = film_grain->ar_coeff_lag;
1136  aom->ar_coeff_shift = film_grain->ar_coeff_shift_minus_6 + 6;
1137  aom->grain_scale_shift = film_grain->grain_scale_shift;
1138  aom->overlap_flag = film_grain->overlap_flag;
1139  aom->limit_output_range = film_grain->clip_to_restricted_range;
1140 
1141  aom->num_y_points = film_grain->num_y_points;
1142  for (int i = 0; i < film_grain->num_y_points; i++) {
1143  aom->y_points[i][0] = film_grain->point_y_value[i];
1144  aom->y_points[i][1] = film_grain->point_y_scaling[i];
1145  }
1146  aom->num_uv_points[0] = film_grain->num_cb_points;
1147  for (int i = 0; i < film_grain->num_cb_points; i++) {
1148  aom->uv_points[0][i][0] = film_grain->point_cb_value[i];
1149  aom->uv_points[0][i][1] = film_grain->point_cb_scaling[i];
1150  }
1151  aom->num_uv_points[1] = film_grain->num_cr_points;
1152  for (int i = 0; i < film_grain->num_cr_points; i++) {
1153  aom->uv_points[1][i][0] = film_grain->point_cr_value[i];
1154  aom->uv_points[1][i][1] = film_grain->point_cr_scaling[i];
1155  }
1156 
1157  for (int i = 0; i < 24; i++) {
1158  aom->ar_coeffs_y[i] = film_grain->ar_coeffs_y_plus_128[i] - 128;
1159  }
1160  for (int i = 0; i < 25; i++) {
1161  aom->ar_coeffs_uv[0][i] = film_grain->ar_coeffs_cb_plus_128[i] - 128;
1162  aom->ar_coeffs_uv[1][i] = film_grain->ar_coeffs_cr_plus_128[i] - 128;
1163  }
1164 
1165  aom->uv_mult[0] = film_grain->cb_mult;
1166  aom->uv_mult[1] = film_grain->cr_mult;
1167  aom->uv_mult_luma[0] = film_grain->cb_luma_mult;
1168  aom->uv_mult_luma[1] = film_grain->cr_luma_mult;
1169  aom->uv_offset[0] = film_grain->cb_offset;
1170  aom->uv_offset[1] = film_grain->cr_offset;
1171 
1172  return 0;
1173 }
1174 
1176 {
1177  AV1DecContext *s = avctx->priv_data;
1178  const AVFrame *srcframe = s->cur_frame.f;
1179  AVPacket *pkt = s->pkt;
1180  int ret;
1181 
1182  // TODO: all layers
1183  if (s->operating_point_idc &&
1184  av_log2(s->operating_point_idc >> 8) > s->cur_frame.spatial_id)
1185  return 0;
1186 
1187  ret = av_frame_ref(frame, srcframe);
1188  if (ret < 0)
1189  return ret;
1190 
1191  ret = export_metadata(avctx, frame);
1192  if (ret < 0) {
1194  return ret;
1195  }
1196 
1198  ret = export_film_grain(avctx, frame);
1199  if (ret < 0) {
1201  return ret;
1202  }
1203  }
1204 
1205  frame->pts = pkt->pts;
1206  frame->pkt_dts = pkt->dts;
1207 #if FF_API_FRAME_PKT
1209  frame->pkt_size = pkt->size;
1210  frame->pkt_pos = pkt->pos;
1212 #endif
1213 
1215 
1216  return 0;
1217 }
1218 
1220 {
1221  AV1DecContext *s = avctx->priv_data;
1222  const AV1RawFrameHeader *header = s->raw_frame_header;
1223  int ret;
1224 
1225  for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1226  if (header->refresh_frame_flags & (1 << i)) {
1227  av1_frame_unref(&s->ref[i]);
1228  if ((ret = av1_frame_ref(avctx, &s->ref[i], &s->cur_frame)) < 0) {
1229  av_log(avctx, AV_LOG_ERROR,
1230  "Failed to update frame %d in reference list\n", i);
1231  return ret;
1232  }
1233  }
1234  }
1235  return 0;
1236 }
1237 
1239 {
1240  AV1DecContext *s = avctx->priv_data;
1241  int ret;
1242 
1243  av1_frame_unref(&s->cur_frame);
1244 
1245  s->cur_frame.header_ref = ff_refstruct_ref(s->header_ref);
1246 
1247  s->cur_frame.raw_frame_header = s->raw_frame_header;
1248 
1249  ret = init_tile_data(s);
1250  if (ret < 0) {
1251  av_log(avctx, AV_LOG_ERROR, "Failed to init tile data.\n");
1252  return ret;
1253  }
1254 
1255  if ((avctx->skip_frame >= AVDISCARD_NONINTRA &&
1256  (s->raw_frame_header->frame_type != AV1_FRAME_KEY &&
1257  s->raw_frame_header->frame_type != AV1_FRAME_INTRA_ONLY)) ||
1258  (avctx->skip_frame >= AVDISCARD_NONKEY &&
1259  s->raw_frame_header->frame_type != AV1_FRAME_KEY) ||
1260  avctx->skip_frame >= AVDISCARD_ALL)
1261  return 0;
1262 
1263  if (s->pix_fmt == AV_PIX_FMT_NONE) {
1264  ret = get_pixel_format(avctx);
1265  if (ret < 0) {
1266  av_log(avctx, AV_LOG_ERROR, "Failed to get pixel format.\n");
1267  return ret;
1268  }
1269 
1270  if (!ret && FF_HW_HAS_CB(avctx, decode_params)) {
1271  ret = FF_HW_CALL(avctx, decode_params, AV1_OBU_SEQUENCE_HEADER,
1272  s->seq_data_ref->data, s->seq_data_ref->size);
1273  if (ret < 0) {
1274  av_log(avctx, AV_LOG_ERROR, "HW accel decode params fail.\n");
1275  return ret;
1276  }
1277  }
1278  }
1279 
1280  ret = av1_frame_alloc(avctx, &s->cur_frame);
1281  if (ret < 0) {
1282  av_log(avctx, AV_LOG_ERROR,
1283  "Failed to allocate space for current frame.\n");
1284  return ret;
1285  }
1286 
1290  order_hint_info(s);
1292 
1293  s->cur_frame.force_integer_mv =
1294  s->raw_frame_header->force_integer_mv ||
1295  s->raw_frame_header->frame_type == AV1_FRAME_KEY ||
1296  s->raw_frame_header->frame_type == AV1_FRAME_INTRA_ONLY;
1297 
1298  return ret;
1299 }
1300 
1302 {
1303  AV1DecContext *s = avctx->priv_data;
1304  AV1RawTileGroup *raw_tile_group = NULL;
1305  int i = 0, ret;
1306 
1307  for (i = s->nb_unit; i < s->current_obu.nb_units; i++) {
1308  CodedBitstreamUnit *unit = &s->current_obu.units[i];
1309  AV1RawOBU *obu = unit->content;
1310  const AV1RawOBUHeader *header;
1311 
1312  av_log(avctx, AV_LOG_DEBUG, "OBU idx:%d, type:%d, content available:%d.\n", i, unit->type, !!obu);
1313 
1314  if (unit->type == AV1_OBU_TILE_LIST) {
1315  av_log(avctx, AV_LOG_ERROR, "Large scale tile decoding is unsupported.\n");
1317  goto end;
1318  }
1319 
1320  if (!obu)
1321  continue;
1322 
1323  header = &obu->header;
1324 
1325  switch (unit->type) {
1327  ret = av_buffer_replace(&s->seq_data_ref, unit->data_ref);
1328  if (ret < 0)
1329  goto end;
1330 
1331  s->seq_data_ref->data = unit->data;
1332  s->seq_data_ref->size = unit->data_size;
1333  ff_refstruct_replace(&s->seq_ref, unit->content_ref);
1334 
1335  s->raw_seq = &obu->obu.sequence_header;
1336 
1337  ret = set_context_with_sequence(avctx, s->raw_seq);
1338  if (ret < 0) {
1339  av_log(avctx, AV_LOG_ERROR, "Failed to set context.\n");
1340  s->raw_seq = NULL;
1341  goto end;
1342  }
1343 
1344  s->operating_point_idc = s->raw_seq->operating_point_idc[s->operating_point];
1345 
1346  s->pix_fmt = AV_PIX_FMT_NONE;
1347 
1348  break;
1350  if (s->raw_frame_header)
1351  break;
1352  // fall-through
1353  case AV1_OBU_FRAME:
1354  case AV1_OBU_FRAME_HEADER:
1355  if (!s->raw_seq) {
1356  av_log(avctx, AV_LOG_ERROR, "Missing Sequence Header.\n");
1358  goto end;
1359  }
1360 
1361  ff_refstruct_replace(&s->header_ref, unit->content_ref);
1362 
1363  if (unit->type == AV1_OBU_FRAME)
1364  s->raw_frame_header = &obu->obu.frame.header;
1365  else
1366  s->raw_frame_header = &obu->obu.frame_header;
1367 
1368  if (s->raw_frame_header->show_existing_frame) {
1369  av1_frame_unref(&s->cur_frame);
1370 
1371  ret = av1_frame_ref(avctx, &s->cur_frame,
1372  &s->ref[s->raw_frame_header->frame_to_show_map_idx]);
1373  if (ret < 0) {
1374  av_log(avctx, AV_LOG_ERROR, "Failed to get reference frame.\n");
1375  goto end;
1376  }
1377 
1378  ret = update_reference_list(avctx);
1379  if (ret < 0) {
1380  av_log(avctx, AV_LOG_ERROR, "Failed to update reference list.\n");
1381  goto end;
1382  }
1383 
1384  if (s->cur_frame.f->buf[0]) {
1385  ret = set_output_frame(avctx, frame);
1386  if (ret < 0)
1387  av_log(avctx, AV_LOG_ERROR, "Set output frame error.\n");
1388  }
1389 
1390  s->raw_frame_header = NULL;
1391  i++;
1392 
1393  goto end;
1394  }
1395 
1396  ret = get_current_frame(avctx);
1397  if (ret < 0) {
1398  av_log(avctx, AV_LOG_ERROR, "Get current frame error\n");
1399  goto end;
1400  }
1401 
1402  s->cur_frame.spatial_id = header->spatial_id;
1403  s->cur_frame.temporal_id = header->temporal_id;
1404 
1405  if (avctx->hwaccel && s->cur_frame.f->buf[0]) {
1406  ret = FF_HW_CALL(avctx, start_frame, unit->data, unit->data_size);
1407  if (ret < 0) {
1408  av_log(avctx, AV_LOG_ERROR, "HW accel start frame fail.\n");
1409  goto end;
1410  }
1411  }
1412  if (unit->type != AV1_OBU_FRAME)
1413  break;
1414  // fall-through
1415  case AV1_OBU_TILE_GROUP:
1416  if (!s->raw_frame_header) {
1417  av_log(avctx, AV_LOG_ERROR, "Missing Frame Header.\n");
1419  goto end;
1420  }
1421 
1422  if (unit->type == AV1_OBU_FRAME)
1423  raw_tile_group = &obu->obu.frame.tile_group;
1424  else
1425  raw_tile_group = &obu->obu.tile_group;
1426 
1427  ret = get_tiles_info(avctx, raw_tile_group);
1428  if (ret < 0)
1429  goto end;
1430 
1431  if (avctx->hwaccel && s->cur_frame.f->buf[0]) {
1432  ret = FF_HW_CALL(avctx, decode_slice, raw_tile_group->tile_data.data,
1433  raw_tile_group->tile_data.data_size);
1434  if (ret < 0) {
1435  av_log(avctx, AV_LOG_ERROR,
1436  "HW accel decode slice fail.\n");
1437  goto end;
1438  }
1439  }
1440  break;
1441  case AV1_OBU_TILE_LIST:
1443  case AV1_OBU_PADDING:
1444  break;
1445  case AV1_OBU_METADATA:
1446  switch (obu->obu.metadata.metadata_type) {
1448  ff_refstruct_replace(&s->cll_ref, unit->content_ref);
1449  s->cll = &obu->obu.metadata.metadata.hdr_cll;
1450  break;
1452  ff_refstruct_replace(&s->mdcv_ref, unit->content_ref);
1453  s->mdcv = &obu->obu.metadata.metadata.hdr_mdcv;
1454  break;
1456  AV1RawMetadataITUTT35 itut_t35;
1457  memcpy(&itut_t35, &obu->obu.metadata.metadata.itut_t35, sizeof(itut_t35));
1459  if (!itut_t35.payload_ref) {
1460  ret = AVERROR(ENOMEM);
1461  goto end;
1462  }
1463  ret = av_fifo_write(s->itut_t35_fifo, &itut_t35, 1);
1464  if (ret < 0) {
1465  av_buffer_unref(&itut_t35.payload_ref);
1466  goto end;
1467  }
1468  break;
1469  }
1470  default:
1471  break;
1472  }
1473  break;
1474  default:
1475  av_log(avctx, AV_LOG_DEBUG,
1476  "Unknown obu type: %d (%"SIZE_SPECIFIER" bits).\n",
1477  unit->type, unit->data_size);
1478  }
1479 
1480  if (raw_tile_group && (s->tile_num == raw_tile_group->tg_end + 1)) {
1481  int show_frame = s->raw_frame_header->show_frame;
1482  if (avctx->hwaccel && s->cur_frame.f->buf[0]) {
1483  ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
1484  if (ret < 0) {
1485  av_log(avctx, AV_LOG_ERROR, "HW accel end frame fail.\n");
1486  goto end;
1487  }
1488  }
1489 
1490  ret = update_reference_list(avctx);
1491  if (ret < 0) {
1492  av_log(avctx, AV_LOG_ERROR, "Failed to update reference list.\n");
1493  goto end;
1494  }
1495 
1496  if (s->raw_frame_header->show_frame && s->cur_frame.f->buf[0]) {
1497  ret = set_output_frame(avctx, frame);
1498  if (ret < 0) {
1499  av_log(avctx, AV_LOG_ERROR, "Set output frame error\n");
1500  goto end;
1501  }
1502  }
1503  raw_tile_group = NULL;
1504  s->raw_frame_header = NULL;
1505  if (show_frame) {
1506  i++;
1507  goto end;
1508  }
1509  }
1510  }
1511 
1512  ret = AVERROR(EAGAIN);
1513 end:
1514  av_assert0(i <= s->current_obu.nb_units);
1515  s->nb_unit = i;
1516 
1517  if ((ret < 0 && ret != AVERROR(EAGAIN)) || s->current_obu.nb_units == i) {
1518  if (ret < 0)
1519  s->raw_frame_header = NULL;
1520  av_packet_unref(s->pkt);
1521  ff_cbs_fragment_reset(&s->current_obu);
1522  s->nb_unit = 0;
1523  }
1524  if (!ret && !frame->buf[0])
1525  ret = AVERROR(EAGAIN);
1526 
1527  return ret;
1528 }
1529 
1531 {
1532  AV1DecContext *s = avctx->priv_data;
1533  int ret;
1534 
1535  do {
1536  if (!s->current_obu.nb_units) {
1537  ret = ff_decode_get_packet(avctx, s->pkt);
1538  if (ret < 0)
1539  return ret;
1540 
1541  ret = ff_cbs_read_packet(s->cbc, &s->current_obu, s->pkt);
1542  if (ret < 0) {
1543  ff_cbs_fragment_reset(&s->current_obu);
1544  av_packet_unref(s->pkt);
1545  av_log(avctx, AV_LOG_ERROR, "Failed to read packet.\n");
1546  return ret;
1547  }
1548 
1549  s->nb_unit = 0;
1550  av_log(avctx, AV_LOG_DEBUG, "Total OBUs on this packet: %d.\n",
1551  s->current_obu.nb_units);
1552  }
1553 
1555  } while (ret == AVERROR(EAGAIN));
1556 
1557  return ret;
1558 }
1559 
1561 {
1562  AV1DecContext *s = avctx->priv_data;
1563  AV1RawMetadataITUTT35 itut_t35;
1564 
1565  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++)
1566  av1_frame_unref(&s->ref[i]);
1567 
1568  av1_frame_unref(&s->cur_frame);
1569  s->operating_point_idc = 0;
1570  s->nb_unit = 0;
1571  s->raw_frame_header = NULL;
1572  s->raw_seq = NULL;
1573  s->cll = NULL;
1574  s->mdcv = NULL;
1575  while (av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0)
1576  av_buffer_unref(&itut_t35.payload_ref);
1577 
1578  ff_cbs_fragment_reset(&s->current_obu);
1579  ff_cbs_flush(s->cbc);
1580 
1581  if (FF_HW_HAS_CB(avctx, flush))
1582  FF_HW_SIMPLE_CALL(avctx, flush);
1583 }
1584 
1585 #define OFFSET(x) offsetof(AV1DecContext, x)
1586 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1587 static const AVOption av1_options[] = {
1588  { "operating_point", "Select an operating point of the scalable bitstream",
1589  OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, AV1_MAX_OPERATING_POINTS - 1, VD },
1590  { NULL }
1591 };
1592 
1593 static const AVClass av1_class = {
1594  .class_name = "AV1 decoder",
1595  .item_name = av_default_item_name,
1596  .option = av1_options,
1597  .version = LIBAVUTIL_VERSION_INT,
1598 };
1599 
1601  .p.name = "av1",
1602  CODEC_LONG_NAME("Alliance for Open Media AV1"),
1603  .p.type = AVMEDIA_TYPE_VIDEO,
1604  .p.id = AV_CODEC_ID_AV1,
1605  .priv_data_size = sizeof(AV1DecContext),
1606  .init = av1_decode_init,
1607  .close = av1_decode_free,
1609  .p.capabilities = AV_CODEC_CAP_DR1,
1611  .flush = av1_decode_flush,
1612  .p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
1613  .p.priv_class = &av1_class,
1614  .hw_configs = (const AVCodecHWConfigInternal *const []) {
1615 #if CONFIG_AV1_DXVA2_HWACCEL
1616  HWACCEL_DXVA2(av1),
1617 #endif
1618 #if CONFIG_AV1_D3D11VA_HWACCEL
1619  HWACCEL_D3D11VA(av1),
1620 #endif
1621 #if CONFIG_AV1_D3D11VA2_HWACCEL
1622  HWACCEL_D3D11VA2(av1),
1623 #endif
1624 #if CONFIG_AV1_D3D12VA_HWACCEL
1625  HWACCEL_D3D12VA(av1),
1626 #endif
1627 #if CONFIG_AV1_NVDEC_HWACCEL
1628  HWACCEL_NVDEC(av1),
1629 #endif
1630 #if CONFIG_AV1_VAAPI_HWACCEL
1631  HWACCEL_VAAPI(av1),
1632 #endif
1633 #if CONFIG_AV1_VDPAU_HWACCEL
1634  HWACCEL_VDPAU(av1),
1635 #endif
1636 #if CONFIG_AV1_VULKAN_HWACCEL
1637  HWACCEL_VULKAN(av1),
1638 #endif
1639 
1640  NULL
1641  },
1642 };
HWACCEL_D3D12VA
#define HWACCEL_D3D12VA(codec)
Definition: hwconfig.h:80
ff_get_coded_side_data
const AVPacketSideData * ff_get_coded_side_data(const AVCodecContext *avctx, enum AVPacketSideDataType type)
Get side data of the given type from a decoding context.
Definition: decode.c:1358
AVFrame::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:627
hwconfig.h
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
AV1RawTimingInfo::num_units_in_display_tick
uint32_t num_units_in_display_tick
Definition: cbs_av1.h:59
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:427
AV1RawTimingInfo::time_scale
uint32_t time_scale
Definition: cbs_av1.h:60
AV1_MAX_SEGMENTS
@ AV1_MAX_SEGMENTS
Definition: av1.h:89
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1427
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
ff_decode_get_packet
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
Definition: decode.c:220
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:623
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
CodedBitstreamUnit::content_ref
void * content_ref
If content is reference counted, a RefStruct reference backing content.
Definition: cbs.h:112
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AV1RawColorConfig::color_primaries
uint8_t color_primaries
Definition: cbs_av1.h:47
av1_decode_init
static av_cold int av1_decode_init(AVCodecContext *avctx)
Definition: av1dec.c:861
AV1_OBU_REDUNDANT_FRAME_HEADER
@ AV1_OBU_REDUNDANT_FRAME_HEADER
Definition: av1.h:36
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
ff_refstruct_ref
void * ff_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition: refstruct.c:140
AV1RawSequenceHeader::seq_level_idx
uint8_t seq_level_idx[AV1_MAX_OPERATING_POINTS]
Definition: cbs_av1.h:87
r
const char * r
Definition: vf_curves.c:126
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
decode_slice
static int decode_slice(AVCodecContext *c, void *arg)
Definition: ffv1dec.c:255
AV1RawFilmGrainParams::clip_to_restricted_range
uint8_t clip_to_restricted_range
Definition: cbs_av1.h:162
opt.h
ff_dovi_ctx_unref
void ff_dovi_ctx_unref(DOVIContext *s)
Completely reset a DOVIContext, preserving only logctx.
Definition: dovi_rpu.c:44
AV1_CSP_VERTICAL
@ AV1_CSP_VERTICAL
Definition: av1.h:134
ff_frame_new_side_data_from_buf
int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef **buf, AVFrameSideData **psd)
Similar to ff_frame_new_side_data, but using an existing buffer ref.
Definition: decode.c:1838
AV1RawFilmGrainParams::grain_seed
uint16_t grain_seed
Definition: cbs_av1.h:135
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:685
AV1_WARP_PARAM_REDUCE_BITS
@ AV1_WARP_PARAM_REDUCE_BITS
Definition: av1.h:118
AV1_WARP_MODEL_IDENTITY
@ AV1_WARP_MODEL_IDENTITY
Definition: av1.h:114
AV1RawSequenceHeader::timing_info_present_flag
uint8_t timing_info_present_flag
Definition: cbs_av1.h:78
AV1RawSequenceHeader
Definition: cbs_av1.h:73
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1220
order_hint_info
static void order_hint_info(AV1DecContext *s)
Definition: av1dec.c:361
AV1RawOBU::obu
union AV1RawOBU::@40 obu
AV1RawColorConfig::color_range
uint8_t color_range
Definition: cbs_av1.h:51
coded_lossless_param
static void coded_lossless_param(AV1DecContext *s)
Definition: av1dec.c:331
GetByteContext
Definition: bytestream.h:33
ff_cbs_fragment_free
av_cold void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
Definition: cbs.c:185
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2962
av1_frame_alloc
static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f)
Definition: av1dec.c:930
AV_FRAME_DATA_A53_CC
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: frame.h:59
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:122
AV1_GM_ABS_TRANS_ONLY_BITS
@ AV1_GM_ABS_TRANS_ONLY_BITS
Definition: av1.h:108
AVMasteringDisplayMetadata::display_primaries
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
Definition: mastering_display_metadata.h:42
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
AV1RawFilmGrainParams::point_cb_value
uint8_t point_cb_value[10]
Definition: cbs_av1.h:143
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:107
AV1RawFilmGrainParams::apply_grain
uint8_t apply_grain
Definition: cbs_av1.h:134
bytestream2_skipu
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:174
int64_t
long long int64_t
Definition: coverity.c:34
AVFilmGrainAOMParams::uv_points
uint8_t uv_points[2][10][2]
Definition: film_grain_params.h:63
AVFrame::color_primaries
enum AVColorPrimaries color_primaries
Definition: frame.h:625
get_current_frame
static int get_current_frame(AVCodecContext *avctx)
Definition: av1dec.c:1238
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:130
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:102
AVFilmGrainParams::aom
AVFilmGrainAOMParams aom
Definition: film_grain_params.h:260
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:634
AV1_DIV_LUT_BITS
@ AV1_DIV_LUT_BITS
Definition: av1.h:120
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:456
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:678
AVFrame::width
int width
Definition: frame.h:416
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:373
set_context_with_sequence
static int set_context_with_sequence(AVCodecContext *avctx, const AV1RawSequenceHeader *seq)
Definition: av1dec.c:775
w
uint8_t w
Definition: llviddspenc.c:38
HWACCEL_DXVA2
#define HWACCEL_DXVA2(codec)
Definition: hwconfig.h:64
AV1RawFilmGrainParams::point_y_value
uint8_t point_y_value[14]
Definition: cbs_av1.h:139
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:683
ff_cbs_fragment_reset
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment's own data buffer, but not the units a...
Definition: cbs.c:171
internal.h
AV1Frame::raw_frame_header
AV1RawFrameHeader * raw_frame_header
Definition: av1dec.h:42
AVOption
AVOption.
Definition: opt.h:346
HWACCEL_D3D11VA2
#define HWACCEL_D3D11VA2(codec)
Definition: hwconfig.h:66
b
#define b
Definition: input.c:41
AV1RawSequenceHeader::timing_info
AV1RawTimingInfo timing_info
Definition: cbs_av1.h:83
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:478
AVFilmGrainParams::color_space
enum AVColorSpace color_space
Definition: film_grain_params.h:282
AV1RawTileGroup::tg_end
uint16_t tg_end
Definition: cbs_av1.h:300
AV_PIX_FMT_D3D11VA_VLD
@ AV_PIX_FMT_D3D11VA_VLD
HW decoding through Direct3D11 via old API, Picture.data[3] contains a ID3D11VideoDecoderOutputView p...
Definition: pixfmt.h:254
FFCodec
Definition: codec_internal.h:127
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:74
FF_HW_SIMPLE_CALL
#define FF_HW_SIMPLE_CALL(avctx, function)
Definition: hwaccel_internal.h:174
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:616
decompose_unit_types
static const CodedBitstreamUnitType decompose_unit_types[]
Definition: av1dec.c:851
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AV1_OBU_TEMPORAL_DELIMITER
@ AV1_OBU_TEMPORAL_DELIMITER
Definition: av1.h:31
AV1RawTileData::data
uint8_t * data
Definition: cbs_av1.h:292
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:245
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:557
get_relative_dist
static int get_relative_dist(const AV1RawSequenceHeader *seq, unsigned int a, unsigned int b)
Definition: av1dec.c:257
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:94
AV1RawOBU::header
AV1RawOBUHeader header
Definition: cbs_av1.h:401
thread.h
AVFilmGrainParams::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: film_grain_params.h:281
AVFilmGrainParams::seed
uint64_t seed
Seed to use for the synthesis process, if the codec allows for it.
Definition: film_grain_params.h:250
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
AV1RawSequenceHeader::seq_profile
uint8_t seq_profile
Definition: cbs_av1.h:74
AV1RawMetadata::itut_t35
AV1RawMetadataITUTT35 itut_t35
Definition: cbs_av1.h:387
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:70
ff_cbs_close
av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:141
AV1RawColorConfig::subsampling_y
uint8_t subsampling_y
Definition: cbs_av1.h:53
ff_thread_get_buffer
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have so the codec calls ff_thread_report set FF_CODEC_CAP_ALLOCATE_PROGRESS in FFCodec caps_internal and use ff_thread_get_buffer() to allocate frames. Otherwise decode directly into the user-supplied frames. Call ff_thread_report_progress() after some part of the current picture has decoded. A good place to put this is where draw_horiz_band() is called - add this if it isn 't called anywhere
round_two
static uint64_t round_two(uint64_t x, uint16_t n)
Definition: av1dec.c:140
AV1RawFrame::header
AV1RawFrameHeader header
Definition: cbs_av1.h:306
AV1RawFilmGrainParams::cr_mult
uint8_t cr_mult
Definition: cbs_av1.h:158
AV1_WARP_MODEL_TRANSLATION
@ AV1_WARP_MODEL_TRANSLATION
Definition: av1.h:115
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:98
AV_PKT_DATA_DOVI_CONF
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
Definition: packet.h:284
AV1RawFilmGrainParams::chroma_scaling_from_luma
uint8_t chroma_scaling_from_luma
Definition: cbs_av1.h:141
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:560
AVPacketSideData::size
size_t size
Definition: packet.h:375
AV1RawFilmGrainParams::ar_coeffs_cr_plus_128
uint8_t ar_coeffs_cr_plus_128[25]
Definition: cbs_av1.h:152
AV1RawSequenceHeader::film_grain_params_present
uint8_t film_grain_params_present
Definition: cbs_av1.h:130
AV1_REF_FRAME_ALTREF
@ AV1_REF_FRAME_ALTREF
Definition: av1.h:69
av1_parse.h
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
av1_options
static const AVOption av1_options[]
Definition: av1dec.c:1587
av1_frame_ref
static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src)
Definition: av1dec.c:690
AVCodecContext::skip_frame
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:1819
fail
#define fail()
Definition: checkasm.h:179
AV1_OBU_FRAME_HEADER
@ AV1_OBU_FRAME_HEADER
Definition: av1.h:32
av_fifo_write
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
Definition: fifo.c:188
AVFilmGrainAOMParams::grain_scale_shift
int grain_scale_shift
Signals the down shift applied to the generated gaussian numbers during synthesis.
Definition: film_grain_params.h:99
AV1RawFilmGrainParams::point_cr_scaling
uint8_t point_cr_scaling[10]
Definition: cbs_av1.h:147
AV1RawMetadataITUTT35::payload_size
size_t payload_size
Definition: cbs_av1.h:356
inverse_recenter
static uint32_t inverse_recenter(int r, uint32_t v)
Definition: av1dec.c:71
HWACCEL_VDPAU
#define HWACCEL_VDPAU(codec)
Definition: hwconfig.h:72
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AV1RawFilmGrainParams::ar_coeff_shift_minus_6
uint8_t ar_coeff_shift_minus_6
Definition: cbs_av1.h:153
CodedBitstreamUnit::data
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
Definition: cbs.h:81
AV1RawFilmGrainParams::num_y_points
uint8_t num_y_points
Definition: cbs_av1.h:138
AVFilmGrainAOMParams::limit_output_range
int limit_output_range
Signals to clip to limited color levels after film grain application.
Definition: film_grain_params.h:122
AVFilmGrainAOMParams::num_y_points
int num_y_points
Number of points, and the scale and value for each point of the piecewise linear scaling function for...
Definition: film_grain_params.h:49
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
round_two_signed
static int64_t round_two_signed(int64_t x, uint16_t n)
Definition: av1dec.c:147
AVRational::num
int num
Numerator.
Definition: rational.h:59
refstruct.h
ITU_T_T35_PROVIDER_CODE_ATSC
#define ITU_T_T35_PROVIDER_CODE_ATSC
Definition: itut35.h:25
AV1_REF_FRAME_LAST
@ AV1_REF_FRAME_LAST
Definition: av1.h:63
AVFilmGrainAOMParams
This structure describes how to handle film grain synthesis for AOM codecs.
Definition: film_grain_params.h:44
AV1RawFilmGrainParams::num_cb_points
uint8_t num_cb_points
Definition: cbs_av1.h:142
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:118
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:481
AV1RawFilmGrainParams::cb_luma_mult
uint8_t cb_luma_mult
Definition: cbs_av1.h:156
AV1Frame
Definition: av1dec.h:36
AV1RawFilmGrainParams::overlap_flag
uint8_t overlap_flag
Definition: cbs_av1.h:161
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:671
show_frame
static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream, AVFormatContext *fmt_ctx)
Definition: ffprobe.c:2909
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AV1Frame::ref_frame_sign_bias
uint8_t ref_frame_sign_bias[AV1_TOTAL_REFS_PER_FRAME]
Definition: av1dec.h:60
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
av_fifo_read
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
Definition: fifo.c:240
AVFilmGrainParams::width
int width
Intended display resolution.
Definition: film_grain_params.h:269
AV1RawFilmGrainParams::grain_scaling_minus_8
uint8_t grain_scaling_minus_8
Definition: cbs_av1.h:148
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:595
AV1Frame::force_integer_mv
uint8_t force_integer_mv
Definition: av1dec.h:69
global_motion_params
static void global_motion_params(AV1DecContext *s)
update gm type/params, since cbs already implemented part of this function, so we don't need to full ...
Definition: av1dec.c:208
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:524
AV1Frame::spatial_id
int spatial_id
Definition: av1dec.h:45
width
#define width
ff_hwaccel_frame_priv_alloc
int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
Allocate a hwaccel frame private data if the provided avctx uses a hwaccel method that needs it.
Definition: decode.c:1901
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
AV_PIX_FMT_DXVA2_VLD
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
Definition: pixfmt.h:134
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_GET_BUFFER_FLAG_REF
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:425
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
av_film_grain_params_create_side_data
AVFilmGrainParams * av_film_grain_params_create_side_data(AVFrame *frame)
Allocate a complete AVFilmGrainParams and add it to the frame.
Definition: film_grain_params.c:32
GetByteContext::buffer
const uint8_t * buffer
Definition: bytestream.h:34
AV1Frame::film_grain
AV1RawFilmGrainParams film_grain
Definition: av1dec.h:53
av1_decode_free
static av_cold int av1_decode_free(AVCodecContext *avctx)
Definition: av1dec.c:742
AV1RawMetadata::hdr_cll
AV1RawMetadataHDRCLL hdr_cll
Definition: cbs_av1.h:384
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:304
init_tile_data
static int init_tile_data(AV1DecContext *s)
Definition: av1dec.c:405
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AVPacketSideData::data
uint8_t * data
Definition: packet.h:374
update_reference_list
static int update_reference_list(AVCodecContext *avctx)
Definition: av1dec.c:1219
decode.h
ff_av1_profiles
const AVProfile ff_av1_profiles[]
Definition: profiles.c:160
AV1_METADATA_TYPE_HDR_MDCV
@ AV1_METADATA_TYPE_HDR_MDCV
Definition: av1.h:45
get_sw_pixel_format
static enum AVPixelFormat get_sw_pixel_format(void *logctx, const AV1RawSequenceHeader *seq)
Definition: av1dec.c:468
AVFrame::pkt_size
attribute_deprecated int pkt_size
size of the corresponding packet containing the compressed frame.
Definition: frame.h:688
AV1RawColorConfig::transfer_characteristics
uint8_t transfer_characteristics
Definition: cbs_av1.h:48
AVPixFmtDescriptor::log2_chroma_w
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
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
av1dec.h
get_tiles_info
static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_group)
Definition: av1dec.c:423
export_itut_t35
static int export_itut_t35(AVCodecContext *avctx, AVFrame *frame, const AV1RawMetadataITUTT35 *itut_t35)
Definition: av1dec.c:976
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
ff_decode_mastering_display_new
int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, AVMasteringDisplayMetadata **mdm)
Wrapper around av_mastering_display_metadata_create_side_data(), which rejects side data overridden b...
Definition: decode.c:1862
FF_CODEC_PROPERTY_FILM_GRAIN
#define FF_CODEC_PROPERTY_FILM_GRAIN
Definition: avcodec.h:1798
load_grain_params
static void load_grain_params(AV1DecContext *s)
Definition: av1dec.c:385
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:459
ff_av1_decoder
const FFCodec ff_av1_decoder
Definition: av1dec.c:1600
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:219
AVFilmGrainAOMParams::uv_mult_luma
int uv_mult_luma[2]
Definition: film_grain_params.h:106
ff_parse_a53_cc
int ff_parse_a53_cc(AVBufferRef **pbuf, const uint8_t *data, int size)
Parse a data array for ATSC A53 Part 4 Closed Captions and store them in an AVBufferRef.
Definition: atsc_a53.c:68
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AV1RawOBU
Definition: cbs_av1.h:400
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
av_clip_int16
#define av_clip_int16
Definition: common.h:113
HWACCEL_MAX
#define HWACCEL_MAX
NULL
#define NULL
Definition: coverity.c:32
AV1Frame::gm_params
int32_t gm_params[AV1_NUM_REF_FRAMES][6]
Definition: av1dec.h:49
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AV1_GM_ABS_TRANS_BITS
@ AV1_GM_ABS_TRANS_BITS
Definition: av1.h:110
AV1RawFilmGrainParams::cb_mult
uint8_t cb_mult
Definition: cbs_av1.h:155
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:695
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:280
hwaccel_internal.h
AV1RawFrameHeader
Definition: cbs_av1.h:165
AV1_FRAME_KEY
@ AV1_FRAME_KEY
Definition: av1.h:53
AVCHROMA_LOC_LEFT
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:704
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVCHROMA_LOC_TOPLEFT
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition: pixfmt.h:706
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:480
AV1RawTileData::data_size
size_t data_size
Definition: cbs_av1.h:294
av1_frame_unref
static void av1_frame_unref(AV1Frame *f)
Definition: av1dec.c:677
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
AV1RawColorConfig::chroma_sample_position
uint8_t chroma_sample_position
Definition: cbs_av1.h:54
ff_dovi_update_cfg
void ff_dovi_update_cfg(DOVIContext *s, const AVDOVIDecoderConfigurationRecord *cfg)
Read the contents of an AVDOVIDecoderConfigurationRecord (usually provided by stream side data) and u...
Definition: dovi_rpu.c:75
profiles.h
CodedBitstreamUnit::data_size
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
Definition: cbs.h:86
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:109
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:367
AV1_OBU_TILE_GROUP
@ AV1_OBU_TILE_GROUP
Definition: av1.h:33
AVFrame::pkt_dts
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:463
update_context_with_frame_header
static int update_context_with_frame_header(AVCodecContext *avctx, const AV1RawFrameHeader *header)
Definition: av1dec.c:821
abs
#define abs(x)
Definition: cuda_runtime.h:35
AV1_FRAME_INTER
@ AV1_FRAME_INTER
Definition: av1.h:54
AV_PIX_FMT_D3D12
@ AV_PIX_FMT_D3D12
Hardware surfaces for Direct3D 12.
Definition: pixfmt.h:440
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:479
skip_mode_params
static void skip_mode_params(AV1DecContext *s)
Definition: av1dec.c:265
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
AVFilmGrainParams::subsampling_x
int subsampling_x
Intended subsampling ratio, or 0 for luma-only streams.
Definition: film_grain_params.h:274
FF_HW_HAS_CB
#define FF_HW_HAS_CB(avctx, function)
Definition: hwaccel_internal.h:177
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1783
AV_PICTURE_TYPE_SP
@ AV_PICTURE_TYPE_SP
Switching Predicted.
Definition: avutil.h:284
av_opt_set_int
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:789
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
bytestream2_tell
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:192
AV1RawSequenceHeader::max_frame_height_minus_1
uint16_t max_frame_height_minus_1
Definition: cbs_av1.h:99
AV1_DIV_LUT_PREC_BITS
@ AV1_DIV_LUT_PREC_BITS
Definition: av1.h:121
resolve_divisor
static int16_t resolve_divisor(uint32_t d, uint16_t *shift)
Resolve divisor process.
Definition: av1dec.c:156
AV1_OBU_FRAME
@ AV1_OBU_FRAME
Definition: av1.h:35
AVFilmGrainAOMParams::num_uv_points
int num_uv_points[2]
If chroma_scaling_from_luma is set to 0, signals the chroma scaling function parameters.
Definition: film_grain_params.h:62
ITU_T_T35_PROVIDER_CODE_DOLBY
#define ITU_T_T35_PROVIDER_CODE_DOLBY
Definition: itut35.h:27
AV1RawFilmGrainParams::point_cr_value
uint8_t point_cr_value[10]
Definition: cbs_av1.h:146
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:218
f
f
Definition: af_crystalizer.c:121
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:446
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
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:523
AV1_DIV_LUT_NUM
@ AV1_DIV_LUT_NUM
Definition: av1.h:122
AV1RawFilmGrainParams::cb_offset
uint16_t cb_offset
Definition: cbs_av1.h:157
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:106
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:354
decode_unsigned_subexp_with_ref
static uint32_t decode_unsigned_subexp_with_ref(uint32_t sub_exp, int mx, int r)
Definition: av1dec.c:81
codec_internal.h
AV1RawTimingInfo::num_ticks_per_picture_minus_1
uint32_t num_ticks_per_picture_minus_1
Definition: cbs_av1.h:63
shift
static int shift(int a, int b)
Definition: bonk.c:262
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:483
AV1_METADATA_TYPE_HDR_CLL
@ AV1_METADATA_TYPE_HDR_CLL
Definition: av1.h:44
AV1_REFS_PER_FRAME
@ AV1_REFS_PER_FRAME
Definition: av1.h:85
size
int size
Definition: twinvq_data.h:10344
AV1DecContext
Definition: av1dec.h:79
AV1RawOBU::sequence_header
AV1RawSequenceHeader sequence_header
Definition: cbs_av1.h:406
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
AV1_GM_TRANS_ONLY_PREC_BITS
@ AV1_GM_TRANS_ONLY_PREC_BITS
Definition: av1.h:109
AV1Frame::skip_mode_frame_idx
uint8_t skip_mode_frame_idx[2]
Definition: av1dec.h:51
MKBETAG
#define MKBETAG(a, b, c, d)
Definition: macros.h:56
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
Definition: codec_internal.h:54
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:485
AVFilmGrainParams
This structure describes how to handle film grain synthesis in video for specific codecs.
Definition: film_grain_params.h:238
AVFrame::pkt_pos
attribute_deprecated int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
Definition: frame.h:654
AV1_OBU_SEQUENCE_HEADER
@ AV1_OBU_SEQUENCE_HEADER
Definition: av1.h:30
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:431
AVCodecHWConfigInternal
Definition: hwconfig.h:25
ff_av1_framerate
AVRational ff_av1_framerate(int64_t ticks_per_frame, int64_t units_per_tick, int64_t time_scale)
Definition: av1_parse.c:110
AVFilmGrainParams::codec
union AVFilmGrainParams::@357 codec
Additional fields may be added both here and in any structure included.
header
static const uint8_t header[24]
Definition: sdr2.c:68
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:164
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:521
height
#define height
AV1Frame::f
AVFrame * f
Definition: av1dec.h:37
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
av_reallocp_array
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
Definition: mem.c:223
VD
#define VD
Definition: av1dec.c:1586
HWACCEL_D3D11VA
#define HWACCEL_D3D11VA(codec)
Definition: hwconfig.h:78
AV1Frame::order_hint
uint8_t order_hint
Definition: av1dec.h:58
AV_PIX_FMT_D3D11
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition: pixfmt.h:336
AV1RawFilmGrainParams::grain_scale_shift
uint8_t grain_scale_shift
Definition: cbs_av1.h:154
HWACCEL_NVDEC
#define HWACCEL_NVDEC(codec)
Definition: hwconfig.h:68
AVFilmGrainAOMParams::ar_coeffs_y
int8_t ar_coeffs_y[24]
Luma auto-regression coefficients.
Definition: film_grain_params.h:80
AV_PIX_FMT_VAAPI
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition: pixfmt.h:126
AV1RawOBU::frame_header
AV1RawFrameHeader frame_header
Definition: cbs_av1.h:407
ff_cbs_read_extradata_from_codec
int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx)
Definition: cbs.c:294
av1_receive_frame
static int av1_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:1530
AV1_MAX_OPERATING_POINTS
@ AV1_MAX_OPERATING_POINTS
Definition: av1.h:74
av1_decode_flush
static void av1_decode_flush(AVCodecContext *avctx)
Definition: av1dec.c:1560
AV_PIX_FMT_VDPAU
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:194
AV1RawOBU::metadata
AV1RawMetadata metadata
Definition: cbs_av1.h:411
AV1RawMetadata::metadata_type
uint64_t metadata_type
Definition: cbs_av1.h:382
export_film_grain
static int export_film_grain(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:1105
AV1_FRAME_SWITCH
@ AV1_FRAME_SWITCH
Definition: av1.h:56
AV1_OBU_PADDING
@ AV1_OBU_PADDING
Definition: av1.h:39
AVFilmGrainParams::color_primaries
enum AVColorPrimaries color_primaries
Definition: film_grain_params.h:280
AVDISCARD_NONINTRA
@ AVDISCARD_NONINTRA
discard all non intra frames
Definition: defs.h:217
CodedBitstreamUnit::data_ref
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:98
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:515
AVCodecContext::properties
unsigned properties
Properties of the stream that gets decoded.
Definition: avcodec.h:1795
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:523
div_lut
static const uint16_t div_lut[AV1_DIV_LUT_NUM]
< same with Div_Lut defined in spec 7.11.3.7
Definition: av1dec.c:44
AV1Frame::hwaccel_picture_private
void * hwaccel_picture_private
RefStruct reference.
Definition: av1dec.h:39
AV1RawMetadata::hdr_mdcv
AV1RawMetadataHDRMDCV hdr_mdcv
Definition: cbs_av1.h:385
AV1Frame::header_ref
AV1RawOBU * header_ref
RefStruct reference backing raw_frame_header.
Definition: av1dec.h:41
AV1RawMetadata::metadata
union AV1RawMetadata::@39 metadata
AVFilmGrainParams::subsampling_y
int subsampling_y
Definition: film_grain_params.h:274
AVCodecInternal::in_pkt
AVPacket * in_pkt
This packet is used to hold the packet given to decoders implementing the .decode API; it is unused b...
Definition: internal.h:74
delta
float delta
Definition: vorbis_enc_data.h:430
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV1RawSequenceHeader::max_frame_width_minus_1
uint16_t max_frame_width_minus_1
Definition: cbs_av1.h:98
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:576
AV1RawSequenceHeader::color_config
AV1RawColorConfig color_config
Definition: cbs_av1.h:128
AV1RawMetadataITUTT35::payload
uint8_t * payload
Definition: cbs_av1.h:354
AVFilmGrainAOMParams::scaling_shift
int scaling_shift
Specifies the shift applied to the chroma components.
Definition: film_grain_params.h:69
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
av_buffer_replace
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition: buffer.c:233
AVCodecContext::chroma_sample_location
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:702
AV1RawTileGroup::tg_start
uint16_t tg_start
Definition: cbs_av1.h:299
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
AV1RawSequenceHeader::enable_order_hint
uint8_t enable_order_hint
Definition: cbs_av1.h:113
AVCodecContext::height
int height
Definition: avcodec.h:618
GetByteContext::buffer_end
const uint8_t * buffer_end
Definition: bytestream.h:34
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:657
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:666
AV1_WARPEDMODEL_PREC_BITS
@ AV1_WARPEDMODEL_PREC_BITS
Definition: av1.h:112
AV1RawMetadataITUTT35::payload_ref
AVBufferRef * payload_ref
Definition: cbs_av1.h:355
AV1RawOBU::tile_group
AV1RawTileGroup tile_group
Definition: cbs_av1.h:409
AVDynamicHDRPlus
This struct represents dynamic metadata for color volume transform - application 4 of SMPTE 2094-40:2...
Definition: hdr_dynamic_metadata.h:243
AV1RawFilmGrainParams::update_grain
uint8_t update_grain
Definition: cbs_av1.h:136
AV1_METADATA_TYPE_ITUT_T35
@ AV1_METADATA_TYPE_ITUT_T35
Definition: av1.h:47
avcodec.h
AV1RawTileGroup::tile_data
AV1RawTileData tile_data
Definition: cbs_av1.h:302
ff_dovi_rpu_parse
int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size)
Parse the contents of a Dovi RPU NAL and update the parsed values in the DOVIContext struct.
Definition: dovi_rpu.c:198
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
av1_class
static const AVClass av1_class
Definition: av1dec.c:1593
av_dynamic_hdr_plus_create_side_data
AVDynamicHDRPlus * av_dynamic_hdr_plus_create_side_data(AVFrame *frame)
Allocate a complete AVDynamicHDRPlus and add it to the frame.
Definition: hdr_dynamic_metadata.c:48
AVFilmGrainParams::height
int height
Definition: film_grain_params.h:269
AV1Frame::order_hints
uint8_t order_hints[AV1_TOTAL_REFS_PER_FRAME]
Definition: av1dec.h:63
ret
ret
Definition: filter_design.txt:187
AV1RawColorConfig::subsampling_x
uint8_t subsampling_x
Definition: cbs_av1.h:52
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
AV1_OBU_TILE_LIST
@ AV1_OBU_TILE_LIST
Definition: av1.h:37
AV1Frame::gm_invalid
uint8_t gm_invalid[AV1_NUM_REF_FRAMES]
Definition: av1dec.h:47
atsc_a53.h
AV1RawColorConfig::high_bitdepth
uint8_t high_bitdepth
Definition: cbs_av1.h:42
AV1RawFilmGrainParams::cr_luma_mult
uint8_t cr_luma_mult
Definition: cbs_av1.h:159
ff_decode_content_light_new
int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame, AVContentLightMetadata **clm)
Wrapper around av_content_light_metadata_create_side_data(), which rejects side data overridden by th...
Definition: decode.c:1874
ff_refstruct_replace
void ff_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition: refstruct.c:160
AV1RawFilmGrainParams::film_grain_params_ref_idx
uint8_t film_grain_params_ref_idx
Definition: cbs_av1.h:137
read_global_param
static void read_global_param(AV1DecContext *s, int type, int ref, int idx)
Definition: av1dec.c:98
AV1_CSP_COLOCATED
@ AV1_CSP_COLOCATED
Definition: av1.h:135
av_fifo_alloc2
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
Definition: fifo.c:47
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:482
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:141
HWACCEL_VULKAN
#define HWACCEL_VULKAN(codec)
Definition: hwconfig.h:76
AV1RawMetadataITUTT35
Definition: cbs_av1.h:350
AV1_WARP_MODEL_AFFINE
@ AV1_WARP_MODEL_AFFINE
Definition: av1.h:117
AVCodecContext
main external API structure.
Definition: avcodec.h:445
AVFrame::height
int height
Definition: frame.h:416
get_shear_params_valid
static uint8_t get_shear_params_valid(AV1DecContext *s, int idx)
check if global motion params is valid.
Definition: av1dec.c:176
AVFilmGrainAOMParams::ar_coeff_lag
int ar_coeff_lag
Specifies the auto-regression lag.
Definition: film_grain_params.h:74
itut35.h
FF_CODEC_RECEIVE_FRAME_CB
#define FF_CODEC_RECEIVE_FRAME_CB(func)
Definition: codec_internal.h:293
AVFilmGrainAOMParams::y_points
uint8_t y_points[14][2]
Definition: film_grain_params.h:50
CodedBitstreamUnitType
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:47
AVFilmGrainAOMParams::uv_offset
int uv_offset[2]
Offset used for component scaling function.
Definition: film_grain_params.h:112
AVRational::den
int den
Denominator.
Definition: rational.h:60
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:171
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
AV1RawFilmGrainParams::ar_coeff_lag
uint8_t ar_coeff_lag
Definition: cbs_av1.h:149
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1639
AV1RawColorConfig::mono_chrome
uint8_t mono_chrome
Definition: cbs_av1.h:44
export_metadata
static int export_metadata(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:1054
AVFilmGrainAOMParams::uv_mult
int uv_mult[2]
Specifies the luma/chroma multipliers for the index to the component scaling function.
Definition: film_grain_params.h:105
hdr_dynamic_metadata.h
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
AVCodecContext::export_side_data
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame,...
Definition: avcodec.h:1926
AV1RawFilmGrainParams::ar_coeffs_cb_plus_128
uint8_t ar_coeffs_cb_plus_128[25]
Definition: cbs_av1.h:151
AV1RawFilmGrainParams::ar_coeffs_y_plus_128
uint8_t ar_coeffs_y_plus_128[24]
Definition: cbs_av1.h:150
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
FF_CODEC_PROPERTY_CLOSED_CAPTIONS
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS
Definition: avcodec.h:1797
ff_cbs_read_packet
int ff_cbs_read_packet(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt)
Read the data bitstream from a packet into a fragment, then split into units and decompose.
Definition: cbs.c:303
AV1RawSequenceHeader::order_hint_bits_minus_1
uint8_t order_hint_bits_minus_1
Definition: cbs_av1.h:122
AV1RawColorConfig::matrix_coefficients
uint8_t matrix_coefficients
Definition: cbs_av1.h:49
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
AV1RawTileGroup
Definition: cbs_av1.h:297
AVFilmGrainParams::color_range
enum AVColorRange color_range
Intended video signal characteristics.
Definition: film_grain_params.h:279
AV1RawFilmGrainParams::cr_offset
uint16_t cr_offset
Definition: cbs_av1.h:160
AV1RawFilmGrainParams::point_y_scaling
uint8_t point_y_scaling[14]
Definition: cbs_av1.h:140
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AVFilmGrainAOMParams::overlap_flag
int overlap_flag
Signals whether to overlap film grain blocks.
Definition: film_grain_params.h:117
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:280
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV1RawOBU::frame
AV1RawFrame frame
Definition: cbs_av1.h:408
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
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AV1RawFilmGrainParams::point_cb_scaling
uint8_t point_cb_scaling[10]
Definition: cbs_av1.h:144
AV1RawMetadataITUTT35::itu_t_t35_country_code
uint8_t itu_t_t35_country_code
Definition: cbs_av1.h:351
mastering_display_metadata.h
AV1RawFrame::tile_group
AV1RawTileGroup tile_group
Definition: cbs_av1.h:307
ITU_T_T35_COUNTRY_CODE_US
#define ITU_T_T35_COUNTRY_CODE_US
Definition: itut35.h:23
decode_signed_subexp_with_ref
static int32_t decode_signed_subexp_with_ref(uint32_t sub_exp, int low, int high, int r)
Definition: av1dec.c:91
AV1_WARP_MODEL_ROTZOOM
@ AV1_WARP_MODEL_ROTZOOM
Definition: av1.h:116
AV1Frame::temporal_id
int temporal_id
Definition: av1dec.h:44
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
ff_cbs_init
av_cold int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
Definition: cbs.c:89
AV1_GM_ABS_ALPHA_BITS
@ AV1_GM_ABS_ALPHA_BITS
Definition: av1.h:106
AV1RawColorConfig::twelve_bit
uint8_t twelve_bit
Definition: cbs_av1.h:43
AV1_NUM_REF_FRAMES
@ AV1_NUM_REF_FRAMES
Definition: av1.h:84
get_pixel_format
static int get_pixel_format(AVCodecContext *avctx)
Definition: av1dec.c:531
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
ITU_T_T35_PROVIDER_CODE_SMTPE
#define ITU_T_T35_PROVIDER_CODE_SMTPE
Definition: itut35.h:28
AVPacket
This structure stores compressed data.
Definition: packet.h:499
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:107
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
OFFSET
#define OFFSET(x)
Definition: av1dec.c:1585
AV1_GM_ALPHA_PREC_BITS
@ AV1_GM_ALPHA_PREC_BITS
Definition: av1.h:107
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:542
av_dynamic_hdr_plus_from_t35
int av_dynamic_hdr_plus_from_t35(AVDynamicHDRPlus *s, const uint8_t *data, size_t size)
Parse the user data registered ITU-T T.35 to AVbuffer (AVDynamicHDRPlus).
Definition: hdr_dynamic_metadata.c:61
AV1_FRAME_INTRA_ONLY
@ AV1_FRAME_INTRA_ONLY
Definition: av1.h:55
HWACCEL_VAAPI
#define HWACCEL_VAAPI(codec)
Definition: hwconfig.h:70
d
d
Definition: ffmpeg_filter.c:409
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
TileGroupInfo
Definition: av1dec.h:72
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
AV1_PRIMARY_REF_NONE
@ AV1_PRIMARY_REF_NONE
Definition: av1.h:87
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
AV1RawFilmGrainParams
Definition: cbs_av1.h:133
sequence_header
static int FUNC() sequence_header(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawSequenceHeader *current)
Definition: cbs_mpeg2_syntax_template.c:19
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AV1_SEG_LVL_ALT_Q
@ AV1_SEG_LVL_ALT_Q
Definition: av1.h:92
AV1_GM_TRANS_PREC_BITS
@ AV1_GM_TRANS_PREC_BITS
Definition: av1.h:111
av_fifo_freep2
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition: fifo.c:286
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
av1_receive_frame_internal
static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:1301
AV1Frame::coded_lossless
uint8_t coded_lossless
Definition: av1dec.h:55
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:460
AVFilmGrainAOMParams::chroma_scaling_from_luma
int chroma_scaling_from_luma
Signals whether to derive the chroma scaling function from the luma.
Definition: film_grain_params.h:56
ff_cbs_flush
av_cold void ff_cbs_flush(CodedBitstreamContext *ctx)
Reset all internal state in a context.
Definition: cbs.c:135
AV1Frame::gm_type
uint8_t gm_type[AV1_NUM_REF_FRAMES]
Definition: av1dec.h:48
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
AV1RawOBUHeader
Definition: cbs_av1.h:29
AVFilmGrainParams::type
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
Definition: film_grain_params.h:242
set_output_frame
static int set_output_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:1175
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
AV1_OBU_METADATA
@ AV1_OBU_METADATA
Definition: av1.h:34
AV1RawFilmGrainParams::num_cr_points
uint8_t num_cr_points
Definition: cbs_av1.h:145
ff_refstruct_unref
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
AVCodecContext::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition: avcodec.h:642
AVPixFmtDescriptor::log2_chroma_h
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
ff_dovi_attach_side_data
int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame)
Attach the decoded AVDOVIMetadata as side data to an AVFrame.
Definition: dovi_rpu.c:83
AV_CODEC_EXPORT_DATA_FILM_GRAIN
#define AV_CODEC_EXPORT_DATA_FILM_GRAIN
Decoding only.
Definition: avcodec.h:420
AV_FIFO_FLAG_AUTO_GROW
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
Definition: fifo.h:67
AVFilmGrainAOMParams::ar_coeff_shift
int ar_coeff_shift
Specifies the range of the auto-regressive coefficients.
Definition: film_grain_params.h:93
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2882
AVDOVIDecoderConfigurationRecord
Definition: dovi_meta.h:52
AVFilmGrainAOMParams::ar_coeffs_uv
int8_t ar_coeffs_uv[2][25]
Chroma auto-regression coefficients.
Definition: film_grain_params.h:86
CodedBitstreamAV1Context
Definition: cbs_av1.h:438