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 
23 #include "libavutil/attributes.h"
27 #include "libavutil/mem.h"
28 #include "libavutil/pixdesc.h"
29 #include "libavutil/opt.h"
30 #include "avcodec.h"
31 #include "av1_parse.h"
32 #include "av1dec.h"
33 #include "atsc_a53.h"
34 #include "bytestream.h"
35 #include "codec_internal.h"
36 #include "decode.h"
37 #include "hwaccel_internal.h"
38 #include "internal.h"
39 #include "itut35.h"
40 #include "hwconfig.h"
41 #include "profiles.h"
42 #include "progressframe.h"
43 #include "libavutil/refstruct.h"
44 
45 /** same with Div_Lut defined in spec 7.11.3.7 */
46 static const uint16_t div_lut[AV1_DIV_LUT_NUM] = {
47  16384, 16320, 16257, 16194, 16132, 16070, 16009, 15948, 15888, 15828, 15768,
48  15709, 15650, 15592, 15534, 15477, 15420, 15364, 15308, 15252, 15197, 15142,
49  15087, 15033, 14980, 14926, 14873, 14821, 14769, 14717, 14665, 14614, 14564,
50  14513, 14463, 14413, 14364, 14315, 14266, 14218, 14170, 14122, 14075, 14028,
51  13981, 13935, 13888, 13843, 13797, 13752, 13707, 13662, 13618, 13574, 13530,
52  13487, 13443, 13400, 13358, 13315, 13273, 13231, 13190, 13148, 13107, 13066,
53  13026, 12985, 12945, 12906, 12866, 12827, 12788, 12749, 12710, 12672, 12633,
54  12596, 12558, 12520, 12483, 12446, 12409, 12373, 12336, 12300, 12264, 12228,
55  12193, 12157, 12122, 12087, 12053, 12018, 11984, 11950, 11916, 11882, 11848,
56  11815, 11782, 11749, 11716, 11683, 11651, 11619, 11586, 11555, 11523, 11491,
57  11460, 11429, 11398, 11367, 11336, 11305, 11275, 11245, 11215, 11185, 11155,
58  11125, 11096, 11067, 11038, 11009, 10980, 10951, 10923, 10894, 10866, 10838,
59  10810, 10782, 10755, 10727, 10700, 10673, 10645, 10618, 10592, 10565, 10538,
60  10512, 10486, 10460, 10434, 10408, 10382, 10356, 10331, 10305, 10280, 10255,
61  10230, 10205, 10180, 10156, 10131, 10107, 10082, 10058, 10034, 10010, 9986,
62  9963, 9939, 9916, 9892, 9869, 9846, 9823, 9800, 9777, 9754, 9732,
63  9709, 9687, 9664, 9642, 9620, 9598, 9576, 9554, 9533, 9511, 9489,
64  9468, 9447, 9425, 9404, 9383, 9362, 9341, 9321, 9300, 9279, 9259,
65  9239, 9218, 9198, 9178, 9158, 9138, 9118, 9098, 9079, 9059, 9039,
66  9020, 9001, 8981, 8962, 8943, 8924, 8905, 8886, 8867, 8849, 8830,
67  8812, 8793, 8775, 8756, 8738, 8720, 8702, 8684, 8666, 8648, 8630,
68  8613, 8595, 8577, 8560, 8542, 8525, 8508, 8490, 8473, 8456, 8439,
69  8422, 8405, 8389, 8372, 8355, 8339, 8322, 8306, 8289, 8273, 8257,
70  8240, 8224, 8208, 8192
71 };
72 
73 static uint32_t inverse_recenter(int r, uint32_t v)
74 {
75  if (v > 2 * r)
76  return v;
77  else if (v & 1)
78  return r - ((v + 1) >> 1);
79  else
80  return r + (v >> 1);
81 }
82 
83 static uint32_t decode_unsigned_subexp_with_ref(uint32_t sub_exp,
84  int mx, int r)
85 {
86  if ((r << 1) <= mx) {
87  return inverse_recenter(r, sub_exp);
88  } else {
89  return mx - 1 - inverse_recenter(mx - 1 - r, sub_exp);
90  }
91 }
92 
93 static int32_t decode_signed_subexp_with_ref(uint32_t sub_exp, int low,
94  int high, int r)
95 {
96  int32_t x = decode_unsigned_subexp_with_ref(sub_exp, high - low, r - low);
97  return x + low;
98 }
99 
100 static void read_global_param(AV1DecContext *s, int type, int ref, int idx)
101 {
102  int primary_frame;
103  uint32_t abs_bits, prec_bits, round, prec_diff, sub, mx;
104  int32_t r, prev_gm_param;
105 
106  primary_frame = s->raw_frame_header->primary_ref_frame;
107  abs_bits = AV1_GM_ABS_ALPHA_BITS;
108  prec_bits = AV1_GM_ALPHA_PREC_BITS;
109 
110  /* setup_past_independence() sets PrevGmParams to default values. We can
111  * simply point to the current's frame gm_params as they will be initialized
112  * with defaults at this point.
113  */
114  if (s->raw_frame_header->primary_ref_frame == AV1_PRIMARY_REF_NONE)
115  prev_gm_param = s->cur_frame.gm_params[ref][idx];
116  else {
117  int prev_frame = s->raw_frame_header->ref_frame_idx[primary_frame];
118  prev_gm_param = s->ref[prev_frame].gm_params[ref][idx];
119  }
120 
121  if (idx < 2) {
123  abs_bits = AV1_GM_ABS_TRANS_ONLY_BITS -
124  !s->raw_frame_header->allow_high_precision_mv;
125  prec_bits = AV1_GM_TRANS_ONLY_PREC_BITS -
126  !s->raw_frame_header->allow_high_precision_mv;
127  } else {
128  abs_bits = AV1_GM_ABS_TRANS_BITS;
129  prec_bits = AV1_GM_TRANS_PREC_BITS;
130  }
131  }
132  round = (idx % 3) == 2 ? (1 << AV1_WARPEDMODEL_PREC_BITS) : 0;
133  prec_diff = AV1_WARPEDMODEL_PREC_BITS - prec_bits;
134  sub = (idx % 3) == 2 ? (1 << prec_bits) : 0;
135  mx = 1 << abs_bits;
136  r = (prev_gm_param >> prec_diff) - sub;
137 
138  s->cur_frame.gm_params[ref][idx] =
139  (decode_signed_subexp_with_ref(s->raw_frame_header->gm_params[ref][idx],
140  -mx, mx + 1, r) << prec_diff) + round;
141 }
142 
143 static uint64_t round_two(uint64_t x, uint16_t n)
144 {
145  if (n == 0)
146  return x;
147  return ((x + ((uint64_t)1 << (n - 1))) >> n);
148 }
149 
150 static int64_t round_two_signed(int64_t x, uint16_t n)
151 {
152  return ((x<0) ? -((int64_t)round_two(-x, n)) : (int64_t)round_two(x, n));
153 }
154 
155 /**
156  * Resolve divisor process.
157  * see spec 7.11.3.7
158  */
159 static int16_t resolve_divisor(uint32_t d, uint16_t *shift)
160 {
161  int32_t e, f;
162 
163  *shift = av_log2(d);
164  e = d - (1 << (*shift));
165  if (*shift > AV1_DIV_LUT_BITS)
167  else
168  f = e << (AV1_DIV_LUT_BITS - (*shift));
169 
171 
172  return div_lut[f];
173 }
174 
175 /**
176  * check if global motion params is valid.
177  * see spec 7.11.3.6
178  */
179 static uint8_t get_shear_params_valid(AV1DecContext *s, int idx)
180 {
181  int16_t alpha, beta, gamma, delta, divf, divs;
182  int64_t v, w;
183  int32_t *param = &s->cur_frame.gm_params[idx][0];
184  if (param[2] <= 0)
185  return 0;
186 
187  alpha = av_clip_int16(param[2] - (1 << AV1_WARPEDMODEL_PREC_BITS));
188  beta = av_clip_int16(param[3]);
189  divf = resolve_divisor(abs(param[2]), &divs);
190  v = (int64_t)param[4] * (1 << AV1_WARPEDMODEL_PREC_BITS);
191  w = (int64_t)param[3] * param[4];
192  gamma = av_clip_int16((int)round_two_signed((v * divf), divs));
193  delta = av_clip_int16(param[5] - (int)round_two_signed((w * divf), divs) - (1 << AV1_WARPEDMODEL_PREC_BITS));
194 
199 
200  if ((4 * abs(alpha) + 7 * abs(beta)) >= (1 << AV1_WARPEDMODEL_PREC_BITS) ||
201  (4 * abs(gamma) + 4 * abs(delta)) >= (1 << AV1_WARPEDMODEL_PREC_BITS))
202  return 0;
203 
204  return 1;
205 }
206 
207 /**
208 * update gm type/params, since cbs already implemented part of this function,
209 * so we don't need to full implement spec.
210 */
212 {
213  const AV1RawFrameHeader *header = s->raw_frame_header;
214  int type, ref;
215 
217  s->cur_frame.gm_type[ref] = AV1_WARP_MODEL_IDENTITY;
218  for (int i = 0; i < 6; i++)
219  s->cur_frame.gm_params[ref][i] = (i % 3 == 2) ?
220  1 << AV1_WARPEDMODEL_PREC_BITS : 0;
221  }
222  if (header->frame_type == AV1_FRAME_KEY ||
223  header->frame_type == AV1_FRAME_INTRA_ONLY)
224  return;
225 
227  if (header->is_global[ref]) {
228  if (header->is_rot_zoom[ref]) {
230  } else {
231  type = header->is_translation[ref] ? AV1_WARP_MODEL_TRANSLATION
233  }
234  } else {
236  }
237  s->cur_frame.gm_type[ref] = type;
238 
239  if (type >= AV1_WARP_MODEL_ROTZOOM) {
240  read_global_param(s, type, ref, 2);
241  read_global_param(s, type, ref, 3);
242  if (type == AV1_WARP_MODEL_AFFINE) {
243  read_global_param(s, type, ref, 4);
244  read_global_param(s, type, ref, 5);
245  } else {
246  s->cur_frame.gm_params[ref][4] = -s->cur_frame.gm_params[ref][3];
247  s->cur_frame.gm_params[ref][5] = s->cur_frame.gm_params[ref][2];
248  }
249  }
251  read_global_param(s, type, ref, 0);
252  read_global_param(s, type, ref, 1);
253  }
254  if (type <= AV1_WARP_MODEL_AFFINE) {
255  s->cur_frame.gm_invalid[ref] = !get_shear_params_valid(s, ref);
256  }
257  }
258 }
259 
261  unsigned int a, unsigned int b)
262 {
263  unsigned int diff = a - b;
264  unsigned int m = 1 << seq->order_hint_bits_minus_1;
265  return (diff & (m - 1)) - (diff & m);
266 }
267 
269 {
270  const AV1RawFrameHeader *header = s->raw_frame_header;
271  const AV1RawSequenceHeader *seq = s->raw_seq;
272 
273  int forward_idx, backward_idx;
274  int forward_hint, backward_hint;
275  int second_forward_idx, second_forward_hint;
276  int ref_hint, dist, i;
277 
278  if (header->frame_type == AV1_FRAME_KEY ||
279  header->frame_type == AV1_FRAME_INTRA_ONLY ||
280  !header->reference_select || !seq->enable_order_hint)
281  return;
282 
283  forward_idx = -1;
284  backward_idx = -1;
285  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
286  if (!s->ref[header->ref_frame_idx[i]].raw_frame_header)
287  return;
288  ref_hint = s->ref[header->ref_frame_idx[i]].raw_frame_header->order_hint;
289  dist = get_relative_dist(seq, ref_hint, header->order_hint);
290  if (dist < 0) {
291  if (forward_idx < 0 ||
292  get_relative_dist(seq, ref_hint, forward_hint) > 0) {
293  forward_idx = i;
294  forward_hint = ref_hint;
295  }
296  } else if (dist > 0) {
297  if (backward_idx < 0 ||
298  get_relative_dist(seq, ref_hint, backward_hint) < 0) {
299  backward_idx = i;
300  backward_hint = ref_hint;
301  }
302  }
303  }
304 
305  if (forward_idx < 0) {
306  return;
307  } else if (backward_idx >= 0) {
308  s->cur_frame.skip_mode_frame_idx[0] =
309  AV1_REF_FRAME_LAST + FFMIN(forward_idx, backward_idx);
310  s->cur_frame.skip_mode_frame_idx[1] =
311  AV1_REF_FRAME_LAST + FFMAX(forward_idx, backward_idx);
312  return;
313  }
314 
315  second_forward_idx = -1;
316  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
317  ref_hint = s->ref[header->ref_frame_idx[i]].raw_frame_header->order_hint;
318  if (get_relative_dist(seq, ref_hint, forward_hint) < 0) {
319  if (second_forward_idx < 0 ||
320  get_relative_dist(seq, ref_hint, second_forward_hint) > 0) {
321  second_forward_idx = i;
322  second_forward_hint = ref_hint;
323  }
324  }
325  }
326 
327  if (second_forward_idx < 0)
328  return;
329 
330  s->cur_frame.skip_mode_frame_idx[0] =
331  AV1_REF_FRAME_LAST + FFMIN(forward_idx, second_forward_idx);
332  s->cur_frame.skip_mode_frame_idx[1] =
333  AV1_REF_FRAME_LAST + FFMAX(forward_idx, second_forward_idx);
334 }
335 
337 {
338  const AV1RawFrameHeader *header = s->raw_frame_header;
339  int i;
340 
341  if (header->delta_q_y_dc || header->delta_q_u_ac ||
342  header->delta_q_u_dc || header->delta_q_v_ac ||
343  header->delta_q_v_dc) {
344  s->cur_frame.coded_lossless = 0;
345  return;
346  }
347 
348  s->cur_frame.coded_lossless = 1;
349  for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
350  int qindex;
351  if (header->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) {
352  qindex = (header->base_q_idx +
353  header->feature_value[i][AV1_SEG_LVL_ALT_Q]);
354  } else {
355  qindex = header->base_q_idx;
356  }
357  qindex = av_clip_uintp2(qindex, 8);
358 
359  if (qindex) {
360  s->cur_frame.coded_lossless = 0;
361  return;
362  }
363  }
364 }
365 
367 {
368  const AV1RawFrameHeader *header = s->raw_frame_header;
369  const AV1RawSequenceHeader *seq = s->raw_seq;
370  AV1Frame *frame = &s->cur_frame;
371 
372  frame->order_hint = header->order_hint;
373 
374  for (int i = 0; i < AV1_REFS_PER_FRAME; i++) {
375  int ref_name = i + AV1_REF_FRAME_LAST;
376  int ref_slot = header->ref_frame_idx[i];
377  int ref_order_hint = s->ref[ref_slot].order_hint;
378 
379  frame->order_hints[ref_name] = ref_order_hint;
380  if (!seq->enable_order_hint) {
381  frame->ref_frame_sign_bias[ref_name] = 0;
382  } else {
383  frame->ref_frame_sign_bias[ref_name] =
384  get_relative_dist(seq, ref_order_hint,
385  frame->order_hint) > 0;
386  }
387  }
388 }
389 
391 {
392  const AV1RawFrameHeader *header = s->raw_frame_header;
393  const AV1RawFilmGrainParams *film_grain = &header->film_grain, *src;
394  AV1RawFilmGrainParams *dst = &s->cur_frame.film_grain;
395 
396  if (!film_grain->apply_grain)
397  return;
398 
399  if (film_grain->update_grain) {
400  memcpy(dst, film_grain, sizeof(*dst));
401  return;
402  }
403 
404  src = &s->ref[film_grain->film_grain_params_ref_idx].film_grain;
405 
406  memcpy(dst, src, sizeof(*dst));
407  dst->grain_seed = film_grain->grain_seed;
408 }
409 
411 
412 {
413  int cur_tile_num =
414  s->raw_frame_header->tile_cols * s->raw_frame_header->tile_rows;
415  if (s->tile_num < cur_tile_num) {
416  int ret = av_reallocp_array(&s->tile_group_info, cur_tile_num,
417  sizeof(TileGroupInfo));
418  if (ret < 0) {
419  s->tile_num = 0;
420  return ret;
421  }
422  }
423  s->tile_num = cur_tile_num;
424 
425  return 0;
426 }
427 
428 static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_group)
429 {
430  AV1DecContext *s = avctx->priv_data;
431  GetByteContext gb;
432  uint16_t tile_num, tile_row, tile_col;
433  uint32_t size = 0, size_bytes = 0;
434 
435  bytestream2_init(&gb, tile_group->tile_data.data,
436  tile_group->tile_data.data_size);
437  s->tg_start = tile_group->tg_start;
438  s->tg_end = tile_group->tg_end;
439 
440  for (tile_num = tile_group->tg_start; tile_num <= tile_group->tg_end; tile_num++) {
441  tile_row = tile_num / s->raw_frame_header->tile_cols;
442  tile_col = tile_num % s->raw_frame_header->tile_cols;
443 
444  if (tile_num == tile_group->tg_end) {
445  s->tile_group_info[tile_num].tile_size = bytestream2_get_bytes_left(&gb);
446  s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
447  s->tile_group_info[tile_num].tile_row = tile_row;
448  s->tile_group_info[tile_num].tile_column = tile_col;
449  return 0;
450  }
451  size_bytes = s->raw_frame_header->tile_size_bytes_minus1 + 1;
452  if (bytestream2_get_bytes_left(&gb) < size_bytes)
453  return AVERROR_INVALIDDATA;
454  size = 0;
455  for (int i = 0; i < size_bytes; i++)
456  size |= bytestream2_get_byteu(&gb) << 8 * i;
457  if (bytestream2_get_bytes_left(&gb) <= size)
458  return AVERROR_INVALIDDATA;
459  size++;
460 
461  s->tile_group_info[tile_num].tile_size = size;
462  s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
463  s->tile_group_info[tile_num].tile_row = tile_row;
464  s->tile_group_info[tile_num].tile_column = tile_col;
465 
466  bytestream2_skipu(&gb, size);
467  }
468 
469  return 0;
470 
471 }
472 
473 static enum AVPixelFormat get_sw_pixel_format(void *logctx,
474  const AV1RawSequenceHeader *seq)
475 {
476  int bit_depth;
478 
479  if (seq->seq_profile == 2 && seq->color_config.high_bitdepth)
480  bit_depth = seq->color_config.twelve_bit ? 12 : 10;
481  else if (seq->seq_profile <= 2)
482  bit_depth = seq->color_config.high_bitdepth ? 10 : 8;
483  else {
484  av_log(logctx, AV_LOG_ERROR,
485  "Unknown AV1 profile %d.\n", seq->seq_profile);
486  return AV_PIX_FMT_NONE;
487  }
488 
489  if (!seq->color_config.mono_chrome) {
490  // 4:4:4 x:0 y:0, 4:2:2 x:1 y:0, 4:2:0 x:1 y:1
491  if (seq->color_config.subsampling_x == 0 &&
492  seq->color_config.subsampling_y == 0) {
493  if (bit_depth == 8)
495  else if (bit_depth == 10)
497  else if (bit_depth == 12)
499  else
500  av_assert0(0);
501  } else if (seq->color_config.subsampling_x == 1 &&
502  seq->color_config.subsampling_y == 0) {
503  if (bit_depth == 8)
505  else if (bit_depth == 10)
507  else if (bit_depth == 12)
509  else
510  av_assert0(0);
511  } else if (seq->color_config.subsampling_x == 1 &&
512  seq->color_config.subsampling_y == 1) {
513  if (bit_depth == 8)
515  else if (bit_depth == 10)
517  else if (bit_depth == 12)
519  else
520  av_assert0(0);
521  }
522  } else {
523  if (bit_depth == 8)
525  else if (bit_depth == 10)
527  else if (bit_depth == 12)
529  else
530  av_assert0(0);
531  }
532 
533  return pix_fmt;
534 }
535 
537 {
538  AV1DecContext *s = avctx->priv_data;
539  const AV1RawSequenceHeader *seq = s->raw_seq;
540  int ret;
541  enum AVPixelFormat pix_fmt = get_sw_pixel_format(avctx, seq);
542 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
543  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
544  CONFIG_AV1_D3D12VA_HWACCEL + \
545  CONFIG_AV1_NVDEC_HWACCEL + \
546  CONFIG_AV1_VAAPI_HWACCEL + \
547  CONFIG_AV1_VDPAU_HWACCEL + \
548  CONFIG_AV1_VIDEOTOOLBOX_HWACCEL + \
549  CONFIG_AV1_VULKAN_HWACCEL)
550  enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
551 
552  if (pix_fmt == AV_PIX_FMT_NONE)
553  return -1;
554 
555  switch (pix_fmt) {
556  case AV_PIX_FMT_YUV420P:
557 #if CONFIG_AV1_DXVA2_HWACCEL
558  *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
559 #endif
560 #if CONFIG_AV1_D3D11VA_HWACCEL
561  *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
562  *fmtp++ = AV_PIX_FMT_D3D11;
563 #endif
564 #if CONFIG_AV1_D3D12VA_HWACCEL
565  *fmtp++ = AV_PIX_FMT_D3D12;
566 #endif
567 #if CONFIG_AV1_NVDEC_HWACCEL
568  *fmtp++ = AV_PIX_FMT_CUDA;
569 #endif
570 #if CONFIG_AV1_VAAPI_HWACCEL
571  *fmtp++ = AV_PIX_FMT_VAAPI;
572 #endif
573 #if CONFIG_AV1_VDPAU_HWACCEL
574  *fmtp++ = AV_PIX_FMT_VDPAU;
575 #endif
576 #if CONFIG_AV1_VIDEOTOOLBOX_HWACCEL
577  *fmtp++ = AV_PIX_FMT_VIDEOTOOLBOX;
578 #endif
579 #if CONFIG_AV1_VULKAN_HWACCEL
580  *fmtp++ = AV_PIX_FMT_VULKAN;
581 #endif
582  break;
584 #if CONFIG_AV1_DXVA2_HWACCEL
585  *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
586 #endif
587 #if CONFIG_AV1_D3D11VA_HWACCEL
588  *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
589  *fmtp++ = AV_PIX_FMT_D3D11;
590 #endif
591 #if CONFIG_AV1_D3D12VA_HWACCEL
592  *fmtp++ = AV_PIX_FMT_D3D12;
593 #endif
594 #if CONFIG_AV1_NVDEC_HWACCEL
595  *fmtp++ = AV_PIX_FMT_CUDA;
596 #endif
597 #if CONFIG_AV1_VAAPI_HWACCEL
598  *fmtp++ = AV_PIX_FMT_VAAPI;
599 #endif
600 #if CONFIG_AV1_VDPAU_HWACCEL
601  *fmtp++ = AV_PIX_FMT_VDPAU;
602 #endif
603 #if CONFIG_AV1_VIDEOTOOLBOX_HWACCEL
604  *fmtp++ = AV_PIX_FMT_VIDEOTOOLBOX;
605 #endif
606 #if CONFIG_AV1_VULKAN_HWACCEL
607  *fmtp++ = AV_PIX_FMT_VULKAN;
608 #endif
609  break;
611 #if CONFIG_AV1_VULKAN_HWACCEL
612  *fmtp++ = AV_PIX_FMT_VULKAN;
613 #endif
614  break;
615  case AV_PIX_FMT_YUV422P:
616 #if CONFIG_AV1_VULKAN_HWACCEL
617  *fmtp++ = AV_PIX_FMT_VULKAN;
618 #endif
619  break;
621 #if CONFIG_AV1_VULKAN_HWACCEL
622  *fmtp++ = AV_PIX_FMT_VULKAN;
623 #endif
624  break;
626 #if CONFIG_AV1_VULKAN_HWACCEL
627  *fmtp++ = AV_PIX_FMT_VULKAN;
628 #endif
629  break;
630  case AV_PIX_FMT_YUV444P:
631 #if CONFIG_AV1_VULKAN_HWACCEL
632  *fmtp++ = AV_PIX_FMT_VULKAN;
633 #endif
634  break;
636 #if CONFIG_AV1_VULKAN_HWACCEL
637  *fmtp++ = AV_PIX_FMT_VULKAN;
638 #endif
639  break;
641 #if CONFIG_AV1_VULKAN_HWACCEL
642  *fmtp++ = AV_PIX_FMT_VULKAN;
643 #endif
644  break;
645  case AV_PIX_FMT_GRAY8:
646 #if CONFIG_AV1_NVDEC_HWACCEL
647  *fmtp++ = AV_PIX_FMT_CUDA;
648 #endif
649  break;
650  case AV_PIX_FMT_GRAY10:
651 #if CONFIG_AV1_NVDEC_HWACCEL
652  *fmtp++ = AV_PIX_FMT_CUDA;
653 #endif
654  break;
655  }
656 
657  *fmtp++ = pix_fmt;
658  *fmtp = AV_PIX_FMT_NONE;
659 
660  for (int i = 0; pix_fmts[i] != pix_fmt; i++)
661  if (pix_fmts[i] == avctx->pix_fmt) {
662  s->pix_fmt = pix_fmt;
663  return 1;
664  }
665 
666  ret = ff_get_format(avctx, pix_fmts);
667 
668  /**
669  * check if the HW accel is inited correctly. If not, return un-implemented.
670  * Since now the av1 decoder doesn't support native decode, if it will be
671  * implemented in the future, need remove this check.
672  */
673  if (!avctx->hwaccel) {
674  av_log(avctx, AV_LOG_ERROR, "Your platform doesn't support"
675  " hardware accelerated AV1 decoding.\n");
676  avctx->pix_fmt = AV_PIX_FMT_NONE;
677  return AVERROR(ENOSYS);
678  }
679 
680  s->pix_fmt = pix_fmt;
681  avctx->pix_fmt = ret;
682 
683  av_log(avctx, AV_LOG_DEBUG, "AV1 decode get format: %s.\n",
684  av_get_pix_fmt_name(avctx->pix_fmt));
685 
686  return 0;
687 }
688 
690 {
692  av_refstruct_unref(&f->hwaccel_picture_private);
693  av_refstruct_unref(&f->header_ref);
694  f->raw_frame_header = NULL;
695  f->spatial_id = f->temporal_id = 0;
696  memset(f->skip_mode_frame_idx, 0,
697  2 * sizeof(uint8_t));
698  memset(&f->film_grain, 0, sizeof(f->film_grain));
699  f->coded_lossless = 0;
700 }
701 
703 {
704  av_assert1(dst != src);
705 
706  av_refstruct_replace(&dst->header_ref, src->header_ref);
707 
708  dst->raw_frame_header = src->raw_frame_header;
709 
710  ff_progress_frame_replace(&dst->pf, &src->pf);
711 
712  av_refstruct_replace(&dst->hwaccel_picture_private,
713  src->hwaccel_picture_private);
714 
715  dst->spatial_id = src->spatial_id;
716  dst->temporal_id = src->temporal_id;
717  memcpy(dst->gm_invalid,
718  src->gm_invalid,
719  AV1_NUM_REF_FRAMES * sizeof(uint8_t));
720  memcpy(dst->gm_type,
721  src->gm_type,
722  AV1_NUM_REF_FRAMES * sizeof(uint8_t));
723  memcpy(dst->gm_params,
724  src->gm_params,
725  AV1_NUM_REF_FRAMES * 6 * sizeof(int32_t));
726  memcpy(dst->skip_mode_frame_idx,
727  src->skip_mode_frame_idx,
728  2 * sizeof(uint8_t));
729  memcpy(&dst->film_grain,
730  &src->film_grain,
731  sizeof(dst->film_grain));
732  dst->coded_lossless = src->coded_lossless;
733 
734  dst->order_hint = src->order_hint;
735  memcpy(dst->ref_frame_sign_bias, src->ref_frame_sign_bias,
736  sizeof(dst->ref_frame_sign_bias));
737  memcpy(dst->order_hints, src->order_hints,
738  sizeof(dst->order_hints));
739 
740  dst->force_integer_mv = src->force_integer_mv;
741 }
742 
744 {
745  AV1DecContext *s = avctx->priv_data;
746  AV1RawMetadataITUTT35 itut_t35;
747 
748  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++)
749  av1_frame_unref(&s->ref[i]);
750  av1_frame_unref(&s->cur_frame);
751  av_buffer_unref(&s->seq_data_ref);
752  av_refstruct_unref(&s->seq_ref);
753  av_refstruct_unref(&s->header_ref);
754  av_refstruct_unref(&s->cll_ref);
755  av_refstruct_unref(&s->mdcv_ref);
756  av_freep(&s->tile_group_info);
757 
758  while (s->itut_t35_fifo && av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0)
759  av_buffer_unref(&itut_t35.payload_ref);
760  av_fifo_freep2(&s->itut_t35_fifo);
761 
762  ff_cbs_fragment_free(&s->current_obu);
763  ff_cbs_close(&s->cbc);
764  ff_dovi_ctx_unref(&s->dovi);
765 
766  return 0;
767 }
768 
770  const AV1RawSequenceHeader *seq)
771 {
772  int width = seq->max_frame_width_minus_1 + 1;
773  int height = seq->max_frame_height_minus_1 + 1;
774 
775  avctx->profile = seq->seq_profile;
776  avctx->level = seq->seq_level_idx[0];
777 
779  avctx->color_range =
784  }
785 
786  switch (seq->color_config.chroma_sample_position) {
787  case AV1_CSP_VERTICAL:
789  break;
790  case AV1_CSP_COLOCATED:
792  break;
793  }
794 
795  if (avctx->width != width || avctx->height != height) {
796  int ret = ff_set_dimensions(avctx, width, height);
797  if (ret < 0)
798  return ret;
799  }
800 
801  if (seq->timing_info_present_flag)
804  seq->timing_info.time_scale);
805 
806  if (avctx->pix_fmt == AV_PIX_FMT_NONE)
807  avctx->pix_fmt = get_sw_pixel_format(avctx, seq);
808 
809  return 0;
810 }
811 
813  const AV1RawFrameHeader *header)
814 {
815  AVRational aspect_ratio;
816  int width = header->frame_width_minus_1 + 1;
817  int height = header->frame_height_minus_1 + 1;
818  int r_width = header->render_width_minus_1 + 1;
819  int r_height = header->render_height_minus_1 + 1;
820  int ret;
821 
822  if (avctx->width != width || avctx->height != height) {
823  ret = ff_set_dimensions(avctx, width, height);
824  if (ret < 0)
825  return ret;
826  }
827 
828  av_reduce(&aspect_ratio.num, &aspect_ratio.den,
829  (int64_t)height * r_width,
830  (int64_t)width * r_height,
831  INT_MAX);
832 
833  if (av_cmp_q(avctx->sample_aspect_ratio, aspect_ratio)) {
834  ret = ff_set_sar(avctx, aspect_ratio);
835  if (ret < 0)
836  return ret;
837  }
838 
839  return 0;
840 }
841 
850 };
851 
853 {
854  AV1DecContext *s = avctx->priv_data;
856  const AVPacketSideData *sd;
857  int ret;
858 
859  s->avctx = avctx;
860  s->pkt = avctx->internal->in_pkt;
861  s->pix_fmt = AV_PIX_FMT_NONE;
862 
863  ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, avctx);
864  if (ret < 0)
865  return ret;
866 
867  s->cbc->decompose_unit_types = decompose_unit_types;
868  s->cbc->nb_decompose_unit_types = FF_ARRAY_ELEMS(decompose_unit_types);
869 
870  s->itut_t35_fifo = av_fifo_alloc2(1, sizeof(AV1RawMetadataITUTT35),
872  if (!s->itut_t35_fifo)
873  return AVERROR(ENOMEM);
874 
875  av_opt_set_int(s->cbc->priv_data, "operating_point", s->operating_point, 0);
876 
877  if (avctx->extradata && avctx->extradata_size) {
878  ret = ff_cbs_read_extradata_from_codec(s->cbc,
879  &s->current_obu,
880  avctx);
881  if (ret < 0) {
882  av_log(avctx, AV_LOG_WARNING, "Failed to read extradata.\n");
883  goto end;
884  }
885 
886  seq = ((CodedBitstreamAV1Context *)(s->cbc->priv_data))->sequence_header;
887  if (!seq) {
888  if (!(avctx->extradata[0] & 0x80))
889  av_log(avctx, AV_LOG_WARNING, "No sequence header available in extradata.\n");
890  goto end;
891  }
892 
893  ret = set_context_with_sequence(avctx, seq);
894  if (ret < 0) {
895  av_log(avctx, AV_LOG_WARNING, "Failed to set decoder context.\n");
896  goto end;
897  }
898 
899  end:
900  ff_cbs_fragment_reset(&s->current_obu);
901  }
902 
903  s->dovi.logctx = avctx;
904  s->dovi.cfg.dv_profile = 10; // default for AV1
906  if (sd && sd->size >= sizeof(s->dovi.cfg))
907  s->dovi.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data;
908 
909  return ret;
910 }
911 
913 {
914  AV1DecContext *s = avctx->priv_data;
915  AV1RawFrameHeader *header= s->raw_frame_header;
916  AVFrame *frame;
917  int ret;
918 
920  if (ret < 0) {
921  av_log(avctx, AV_LOG_ERROR, "Failed to update context with frame header\n");
922  return ret;
923  }
924 
926  if (ret < 0)
927  goto fail;
928 
929  frame = f->f;
930  if (header->frame_type == AV1_FRAME_KEY)
931  frame->flags |= AV_FRAME_FLAG_KEY;
932  else
933  frame->flags &= ~AV_FRAME_FLAG_KEY;
934 
935  switch (header->frame_type) {
936  case AV1_FRAME_KEY:
938  frame->pict_type = AV_PICTURE_TYPE_I;
939  break;
940  case AV1_FRAME_INTER:
941  frame->pict_type = AV_PICTURE_TYPE_P;
942  break;
943  case AV1_FRAME_SWITCH:
944  frame->pict_type = AV_PICTURE_TYPE_SP;
945  break;
946  }
947 
948  ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private);
949  if (ret < 0)
950  goto fail;
951 
952  return 0;
953 
954 fail:
956  return ret;
957 }
958 
960  const AV1RawMetadataITUTT35 *itut_t35)
961 {
962  AV1DecContext *s = avctx->priv_data;
963  FFITUTT35 itut35 = { .country_code = itut_t35->itu_t_t35_country_code };
964  FFITUTT35Aux aux = { .dovi = &s->dovi };
965  int ret;
966 
967  ret = ff_itut_t35_parse_buffer(&itut35, itut_t35->payload, itut_t35->payload_size,
969  if (ret <= 0)
970  return ret;
971 
972  ret = ff_itut_t35_parse_payload_to_frame(&itut35, &aux, avctx, frame);
973  if (ret < 0)
974  return ret;
975 
976  return 0;
977 }
978 
980 {
981  AV1DecContext *s = avctx->priv_data;
982  AV1RawMetadataITUTT35 itut_t35;
983  int ret = 0;
984 
985  if (s->mdcv) {
986  AVMasteringDisplayMetadata *mastering;
987 
988  ret = ff_decode_mastering_display_new(avctx, frame, &mastering);
989  if (ret < 0)
990  return ret;
991 
992  if (mastering) {
993  for (int i = 0; i < 3; i++) {
994  mastering->display_primaries[i][0] = av_make_q(s->mdcv->primary_chromaticity_x[i], 1 << 16);
995  mastering->display_primaries[i][1] = av_make_q(s->mdcv->primary_chromaticity_y[i], 1 << 16);
996  }
997  mastering->white_point[0] = av_make_q(s->mdcv->white_point_chromaticity_x, 1 << 16);
998  mastering->white_point[1] = av_make_q(s->mdcv->white_point_chromaticity_y, 1 << 16);
999 
1000  mastering->max_luminance = av_make_q(s->mdcv->luminance_max, 1 << 8);
1001  mastering->min_luminance = av_make_q(s->mdcv->luminance_min, 1 << 14);
1002 
1003  mastering->has_primaries = 1;
1004  mastering->has_luminance = 1;
1005  }
1006  }
1007 
1008  if (s->cll) {
1009  AVContentLightMetadata *light;
1010 
1011  ret = ff_decode_content_light_new(avctx, frame, &light);
1012  if (ret < 0)
1013  return ret;
1014 
1015  if (light) {
1016  light->MaxCLL = s->cll->max_cll;
1017  light->MaxFALL = s->cll->max_fall;
1018  }
1019  }
1020 
1021  while (av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0) {
1022  if (ret >= 0)
1023  ret = export_itut_t35(avctx, frame, &itut_t35);
1024  av_buffer_unref(&itut_t35.payload_ref);
1025  }
1026 
1027  return ret;
1028 }
1029 
1031 {
1032  AV1DecContext *s = avctx->priv_data;
1033  const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
1034  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(frame->format);
1035  AVFilmGrainParams *fgp;
1036  AVFilmGrainAOMParams *aom;
1037 
1038  av_assert0(pixdesc);
1039  if (!film_grain->apply_grain)
1040  return 0;
1041 
1043  if (!fgp)
1044  return AVERROR(ENOMEM);
1045 
1047  fgp->seed = film_grain->grain_seed;
1048  fgp->width = frame->width;
1049  fgp->height = frame->height;
1050  fgp->color_range = frame->color_range;
1051  fgp->color_primaries = frame->color_primaries;
1052  fgp->color_trc = frame->color_trc;
1053  fgp->color_space = frame->colorspace;
1054  fgp->subsampling_x = pixdesc->log2_chroma_w;
1055  fgp->subsampling_y = pixdesc->log2_chroma_h;
1056 
1057  aom = &fgp->codec.aom;
1059  aom->scaling_shift = film_grain->grain_scaling_minus_8 + 8;
1060  aom->ar_coeff_lag = film_grain->ar_coeff_lag;
1061  aom->ar_coeff_shift = film_grain->ar_coeff_shift_minus_6 + 6;
1062  aom->grain_scale_shift = film_grain->grain_scale_shift;
1063  aom->overlap_flag = film_grain->overlap_flag;
1064  aom->limit_output_range = film_grain->clip_to_restricted_range;
1065 
1066  aom->num_y_points = film_grain->num_y_points;
1067  for (int i = 0; i < film_grain->num_y_points; i++) {
1068  aom->y_points[i][0] = film_grain->point_y_value[i];
1069  aom->y_points[i][1] = film_grain->point_y_scaling[i];
1070  }
1071  aom->num_uv_points[0] = film_grain->num_cb_points;
1072  for (int i = 0; i < film_grain->num_cb_points; i++) {
1073  aom->uv_points[0][i][0] = film_grain->point_cb_value[i];
1074  aom->uv_points[0][i][1] = film_grain->point_cb_scaling[i];
1075  }
1076  aom->num_uv_points[1] = film_grain->num_cr_points;
1077  for (int i = 0; i < film_grain->num_cr_points; i++) {
1078  aom->uv_points[1][i][0] = film_grain->point_cr_value[i];
1079  aom->uv_points[1][i][1] = film_grain->point_cr_scaling[i];
1080  }
1081 
1082  for (int i = 0; i < 24; i++) {
1083  aom->ar_coeffs_y[i] = film_grain->ar_coeffs_y_plus_128[i] - 128;
1084  }
1085  for (int i = 0; i < 25; i++) {
1086  aom->ar_coeffs_uv[0][i] = film_grain->ar_coeffs_cb_plus_128[i] - 128;
1087  aom->ar_coeffs_uv[1][i] = film_grain->ar_coeffs_cr_plus_128[i] - 128;
1088  }
1089 
1090  aom->uv_mult[0] = film_grain->cb_mult;
1091  aom->uv_mult[1] = film_grain->cr_mult;
1092  aom->uv_mult_luma[0] = film_grain->cb_luma_mult;
1093  aom->uv_mult_luma[1] = film_grain->cr_luma_mult;
1094  aom->uv_offset[0] = film_grain->cb_offset;
1095  aom->uv_offset[1] = film_grain->cr_offset;
1096 
1097  return 0;
1098 }
1099 
1101 {
1102  AV1DecContext *s = avctx->priv_data;
1103  const AVFrame *srcframe = s->cur_frame.f;
1104  AVPacket *pkt = s->pkt;
1105  int ret;
1106 
1107  // TODO: all layers
1108  if (s->operating_point_idc &&
1109  av_log2(s->operating_point_idc >> 8) > s->cur_frame.spatial_id)
1110  return 0;
1111 
1112  ret = av_frame_ref(frame, srcframe);
1113  if (ret < 0)
1114  return ret;
1115 
1116  ret = export_metadata(avctx, frame);
1117  if (ret < 0) {
1119  return ret;
1120  }
1121 
1123  ret = export_film_grain(avctx, frame);
1124  if (ret < 0) {
1126  return ret;
1127  }
1128  }
1129 
1130  frame->pts = pkt->pts;
1131  frame->pkt_dts = pkt->dts;
1132 
1134 
1135  return 0;
1136 }
1137 
1139 {
1140  AV1DecContext *s = avctx->priv_data;
1141  const AV1RawFrameHeader *header = s->raw_frame_header;
1142 
1143  for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1144  if (header->refresh_frame_flags & (1 << i))
1145  av1_frame_replace(&s->ref[i], &s->cur_frame);
1146  }
1147 }
1148 
1150 {
1151  AV1DecContext *s = avctx->priv_data;
1152  int ret;
1153 
1154  av1_frame_unref(&s->cur_frame);
1155 
1156  s->cur_frame.header_ref = av_refstruct_ref(s->header_ref);
1157 
1158  s->cur_frame.raw_frame_header = s->raw_frame_header;
1159 
1160  ret = init_tile_data(s);
1161  if (ret < 0) {
1162  av_log(avctx, AV_LOG_ERROR, "Failed to init tile data.\n");
1163  return ret;
1164  }
1165 
1166  if ((avctx->skip_frame >= AVDISCARD_NONINTRA &&
1167  (s->raw_frame_header->frame_type != AV1_FRAME_KEY &&
1168  s->raw_frame_header->frame_type != AV1_FRAME_INTRA_ONLY)) ||
1169  (avctx->skip_frame >= AVDISCARD_NONKEY &&
1170  s->raw_frame_header->frame_type != AV1_FRAME_KEY) ||
1171  avctx->skip_frame >= AVDISCARD_ALL)
1172  return 0;
1173 
1174  if (s->pix_fmt == AV_PIX_FMT_NONE) {
1175  ret = get_pixel_format(avctx);
1176  if (ret < 0) {
1177  av_log(avctx, AV_LOG_ERROR, "Failed to get pixel format.\n");
1178  return ret;
1179  }
1180 
1181  if (!ret && FF_HW_HAS_CB(avctx, decode_params)) {
1182  ret = FF_HW_CALL(avctx, decode_params, AV1_OBU_SEQUENCE_HEADER,
1183  s->seq_data_ref->data, s->seq_data_ref->size);
1184  if (ret < 0) {
1185  av_log(avctx, AV_LOG_ERROR, "HW accel decode params fail.\n");
1186  return ret;
1187  }
1188  }
1189  }
1190 
1191  ret = av1_frame_alloc(avctx, &s->cur_frame);
1192  if (ret < 0) {
1193  av_log(avctx, AV_LOG_ERROR,
1194  "Failed to allocate space for current frame.\n");
1195  return ret;
1196  }
1197 
1201  order_hint_info(s);
1203 
1204  s->cur_frame.force_integer_mv =
1205  s->raw_frame_header->force_integer_mv ||
1206  s->raw_frame_header->frame_type == AV1_FRAME_KEY ||
1207  s->raw_frame_header->frame_type == AV1_FRAME_INTRA_ONLY;
1208 
1209  return ret;
1210 }
1211 
1213 {
1214  AV1DecContext *s = avctx->priv_data;
1215  AV1RawTileGroup *raw_tile_group = NULL;
1216  int i = 0, ret;
1217 
1218  for (i = s->nb_unit; i < s->current_obu.nb_units; i++) {
1219  CodedBitstreamUnit *unit = &s->current_obu.units[i];
1220  AV1RawOBU *obu = unit->content;
1221  const AV1RawOBUHeader *header;
1222 
1223  av_log(avctx, AV_LOG_DEBUG, "OBU idx:%d, type:%d, content available:%d.\n", i, unit->type, !!obu);
1224 
1225  if (unit->type == AV1_OBU_TILE_LIST) {
1226  av_log(avctx, AV_LOG_ERROR, "Large scale tile decoding is unsupported.\n");
1228  goto end;
1229  }
1230 
1231  if (!obu)
1232  continue;
1233 
1234  header = &obu->header;
1235 
1236  switch (unit->type) {
1238  ret = av_buffer_replace(&s->seq_data_ref, unit->data_ref);
1239  if (ret < 0)
1240  goto end;
1241 
1242  s->seq_data_ref->data = unit->data;
1243  s->seq_data_ref->size = unit->data_size;
1244  av_refstruct_replace(&s->seq_ref, unit->content_ref);
1245 
1246  s->raw_seq = &obu->obu.sequence_header;
1247  s->raw_frame_header = NULL;
1248  raw_tile_group = NULL;
1249 
1250  ret = set_context_with_sequence(avctx, s->raw_seq);
1251  if (ret < 0) {
1252  av_log(avctx, AV_LOG_ERROR, "Failed to set context.\n");
1253  s->raw_seq = NULL;
1254  goto end;
1255  }
1256 
1257  s->operating_point_idc = s->raw_seq->operating_point_idc[s->operating_point];
1258 
1259  s->pix_fmt = AV_PIX_FMT_NONE;
1260 
1261  if (FF_HW_HAS_CB(avctx, decode_params)) {
1262  ret = FF_HW_CALL(avctx, decode_params, AV1_OBU_SEQUENCE_HEADER,
1263  s->seq_data_ref->data, s->seq_data_ref->size);
1264  if (ret < 0) {
1265  av_log(avctx, AV_LOG_ERROR, "HW accel decode params fail.\n");
1266  return ret;
1267  }
1268  }
1269 
1270  break;
1272  if (s->raw_frame_header)
1273  break;
1275  case AV1_OBU_FRAME:
1276  case AV1_OBU_FRAME_HEADER:
1277  if (!s->raw_seq) {
1278  av_log(avctx, AV_LOG_ERROR, "Missing Sequence Header.\n");
1280  goto end;
1281  }
1282 
1283  av_refstruct_replace(&s->header_ref, unit->content_ref);
1284 
1285  raw_tile_group = NULL;
1286 
1287  if (unit->type == AV1_OBU_FRAME)
1288  s->raw_frame_header = &obu->obu.frame.header;
1289  else
1290  s->raw_frame_header = &obu->obu.frame_header;
1291 
1292  if (s->raw_frame_header->show_existing_frame) {
1293  av1_frame_replace(&s->cur_frame,
1294  &s->ref[s->raw_frame_header->frame_to_show_map_idx]);
1295 
1296  update_reference_list(avctx);
1297 
1298  if (s->cur_frame.f) {
1299  ret = set_output_frame(avctx, frame);
1300  if (ret < 0) {
1301  av_log(avctx, AV_LOG_ERROR, "Set output frame error.\n");
1302  goto end;
1303  }
1304  }
1305 
1306  s->raw_frame_header = NULL;
1307  i++;
1308  ret = 0;
1309 
1310  goto end;
1311  }
1312 
1313  ret = get_current_frame(avctx);
1314  if (ret < 0) {
1315  av_log(avctx, AV_LOG_ERROR, "Get current frame error\n");
1316  goto end;
1317  }
1318 
1319  s->cur_frame.spatial_id = header->spatial_id;
1320  s->cur_frame.temporal_id = header->temporal_id;
1321 
1322  if (avctx->hwaccel && s->cur_frame.f) {
1323  ret = FF_HW_CALL(avctx, start_frame, s->pkt->buf,
1324  unit->data, unit->data_size);
1325  if (ret < 0) {
1326  av_log(avctx, AV_LOG_ERROR, "HW accel start frame fail.\n");
1327  goto end;
1328  }
1329  }
1330  if (unit->type != AV1_OBU_FRAME)
1331  break;
1333  case AV1_OBU_TILE_GROUP:
1334  if (!s->raw_frame_header) {
1335  av_log(avctx, AV_LOG_ERROR, "Missing Frame Header.\n");
1337  goto end;
1338  }
1339 
1340  if (unit->type == AV1_OBU_FRAME)
1341  raw_tile_group = &obu->obu.frame.tile_group;
1342  else
1343  raw_tile_group = &obu->obu.tile_group;
1344 
1345  ret = get_tiles_info(avctx, raw_tile_group);
1346  if (ret < 0)
1347  goto end;
1348 
1349  if (avctx->hwaccel && s->cur_frame.f) {
1350  ret = FF_HW_CALL(avctx, decode_slice, raw_tile_group->tile_data.data,
1351  raw_tile_group->tile_data.data_size);
1352  if (ret < 0) {
1353  av_log(avctx, AV_LOG_ERROR,
1354  "HW accel decode slice fail.\n");
1355  goto end;
1356  }
1357  }
1358  break;
1360  s->raw_frame_header = NULL;
1361  raw_tile_group = NULL;
1362  break;
1363  case AV1_OBU_TILE_LIST:
1364  case AV1_OBU_PADDING:
1365  break;
1366  case AV1_OBU_METADATA:
1367  switch (obu->obu.metadata.metadata_type) {
1369  av_refstruct_replace(&s->cll_ref, unit->content_ref);
1370  s->cll = &obu->obu.metadata.metadata.hdr_cll;
1371  break;
1373  av_refstruct_replace(&s->mdcv_ref, unit->content_ref);
1374  s->mdcv = &obu->obu.metadata.metadata.hdr_mdcv;
1375  break;
1377  AV1RawMetadataITUTT35 itut_t35;
1378  memcpy(&itut_t35, &obu->obu.metadata.metadata.itut_t35, sizeof(itut_t35));
1380  if (!itut_t35.payload_ref) {
1381  ret = AVERROR(ENOMEM);
1382  goto end;
1383  }
1384  ret = av_fifo_write(s->itut_t35_fifo, &itut_t35, 1);
1385  if (ret < 0) {
1386  av_buffer_unref(&itut_t35.payload_ref);
1387  goto end;
1388  }
1389  break;
1390  }
1391  default:
1392  break;
1393  }
1394  break;
1395  default:
1396  av_log(avctx, AV_LOG_DEBUG,
1397  "Unknown obu type: %d (%zu bits).\n",
1398  unit->type, unit->data_size);
1399  }
1400 
1401  if (raw_tile_group && (s->tile_num == raw_tile_group->tg_end + 1)) {
1402  int show_frame = s->raw_frame_header->show_frame;
1403  // Set nb_unit to point at the next OBU, to indicate which
1404  // OBUs have been processed for this current frame. (If this
1405  // frame gets output, we set nb_unit to this value later too.)
1406  s->nb_unit = i + 1;
1407  if (avctx->hwaccel && s->cur_frame.f) {
1408  ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
1409  if (ret < 0) {
1410  av_log(avctx, AV_LOG_ERROR, "HW accel end frame fail.\n");
1411  goto end;
1412  }
1413  }
1414 
1415  update_reference_list(avctx);
1416 
1417  // Set start_unit to indicate the first OBU of the next frame.
1418  s->start_unit = s->nb_unit;
1419  raw_tile_group = NULL;
1420  s->raw_frame_header = NULL;
1421 
1422  if (show_frame) {
1423  // cur_frame.f needn't exist due to skip_frame.
1424  if (s->cur_frame.f) {
1425  ret = set_output_frame(avctx, frame);
1426  if (ret < 0) {
1427  av_log(avctx, AV_LOG_ERROR, "Set output frame error\n");
1428  goto end;
1429  }
1430  }
1431  i++;
1432  ret = 0;
1433  goto end;
1434  }
1435  }
1436  }
1437 
1438  ret = AVERROR(EAGAIN);
1439 end:
1440  av_assert0(i <= s->current_obu.nb_units);
1441  s->nb_unit = i;
1442 
1443  if ((ret < 0 && ret != AVERROR(EAGAIN)) || s->current_obu.nb_units == i) {
1444  if (ret < 0)
1445  s->raw_frame_header = NULL;
1446  av_packet_unref(s->pkt);
1447  ff_cbs_fragment_reset(&s->current_obu);
1448  s->nb_unit = s->start_unit = 0;
1449  }
1450  if (!ret && !frame->buf[0])
1451  ret = AVERROR(EAGAIN);
1452 
1453  return ret;
1454 }
1455 
1457 {
1458  AV1DecContext *s = avctx->priv_data;
1459  int ret;
1460 
1461  do {
1462  if (!s->current_obu.nb_units) {
1463  ret = ff_decode_get_packet(avctx, s->pkt);
1464  if (ret < 0)
1465  return ret;
1466 
1467  ret = ff_cbs_read_packet(s->cbc, &s->current_obu, s->pkt);
1468  if (ret < 0) {
1469  ff_cbs_fragment_reset(&s->current_obu);
1470  av_packet_unref(s->pkt);
1471  av_log(avctx, AV_LOG_ERROR, "Failed to read packet.\n");
1472  return ret;
1473  }
1474 
1475  s->nb_unit = s->start_unit = 0;
1476  av_log(avctx, AV_LOG_DEBUG, "Total OBUs on this packet: %d.\n",
1477  s->current_obu.nb_units);
1478  }
1479 
1481  } while (ret == AVERROR(EAGAIN));
1482 
1483  return ret;
1484 }
1485 
1487 {
1488  AV1DecContext *s = avctx->priv_data;
1489  AV1RawMetadataITUTT35 itut_t35;
1490 
1491  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++)
1492  av1_frame_unref(&s->ref[i]);
1493 
1494  av1_frame_unref(&s->cur_frame);
1495  s->operating_point_idc = 0;
1496  s->nb_unit = s->start_unit = 0;
1497  s->raw_frame_header = NULL;
1498  s->raw_seq = NULL;
1499  s->cll = NULL;
1500  s->mdcv = NULL;
1501  while (av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0)
1502  av_buffer_unref(&itut_t35.payload_ref);
1503 
1504  ff_cbs_fragment_reset(&s->current_obu);
1505  ff_cbs_flush(s->cbc);
1506 
1507  if (FF_HW_HAS_CB(avctx, flush))
1508  FF_HW_SIMPLE_CALL(avctx, flush);
1509 }
1510 
1511 #define OFFSET(x) offsetof(AV1DecContext, x)
1512 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1513 static const AVOption av1_options[] = {
1514  { "operating_point", "Select an operating point of the scalable bitstream",
1515  OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, AV1_MAX_OPERATING_POINTS - 1, VD },
1516  { NULL }
1517 };
1518 
1519 static const AVClass av1_class = {
1520  .class_name = "AV1 decoder",
1521  .item_name = av_default_item_name,
1522  .option = av1_options,
1523  .version = LIBAVUTIL_VERSION_INT,
1524 };
1525 
1527  .p.name = "av1",
1528  CODEC_LONG_NAME("Alliance for Open Media AV1"),
1529  .p.type = AVMEDIA_TYPE_VIDEO,
1530  .p.id = AV_CODEC_ID_AV1,
1531  .priv_data_size = sizeof(AV1DecContext),
1532  .init = av1_decode_init,
1535  .p.capabilities = AV_CODEC_CAP_DR1,
1536  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1539  .flush = av1_decode_flush,
1540  .p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
1541  .p.priv_class = &av1_class,
1542  .hw_configs = (const AVCodecHWConfigInternal *const []) {
1543 #if CONFIG_AV1_DXVA2_HWACCEL
1544  HWACCEL_DXVA2(av1),
1545 #endif
1546 #if CONFIG_AV1_D3D11VA_HWACCEL
1547  HWACCEL_D3D11VA(av1),
1548 #endif
1549 #if CONFIG_AV1_D3D11VA2_HWACCEL
1550  HWACCEL_D3D11VA2(av1),
1551 #endif
1552 #if CONFIG_AV1_D3D12VA_HWACCEL
1553  HWACCEL_D3D12VA(av1),
1554 #endif
1555 #if CONFIG_AV1_NVDEC_HWACCEL
1556  HWACCEL_NVDEC(av1),
1557 #endif
1558 #if CONFIG_AV1_VAAPI_HWACCEL
1559  HWACCEL_VAAPI(av1),
1560 #endif
1561 #if CONFIG_AV1_VDPAU_HWACCEL
1562  HWACCEL_VDPAU(av1),
1563 #endif
1564 #if CONFIG_AV1_VIDEOTOOLBOX_HWACCEL
1565  HWACCEL_VIDEOTOOLBOX(av1),
1566 #endif
1567 #if CONFIG_AV1_VULKAN_HWACCEL
1568  HWACCEL_VULKAN(av1),
1569 #endif
1570 
1571  NULL
1572  },
1573 };
update_reference_list
static void update_reference_list(AVCodecContext *avctx)
Definition: av1dec.c:1138
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:1372
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:68
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:434
AV1RawTimingInfo::time_scale
uint32_t time_scale
Definition: cbs_av1.h:69
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1423
AV1_DIV_LUT_PREC_BITS
@ AV1_DIV_LUT_PREC_BITS
Definition: av1.h:121
FFITUTT35::country_code
int country_code
Definition: itut35.h:51
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:254
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
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:119
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AV1RawColorConfig::color_primaries
uint8_t color_primaries
Definition: cbs_av1.h:56
AV1_METADATA_TYPE_ITUT_T35
@ AV1_METADATA_TYPE_ITUT_T35
Definition: av1.h:47
av1_decode_init
static av_cold int av1_decode_init(AVCodecContext *avctx)
Definition: av1dec.c:852
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:43
AV1RawSequenceHeader::seq_level_idx
uint8_t seq_level_idx[AV1_MAX_OPERATING_POINTS]
Definition: cbs_av1.h:96
r
const char * r
Definition: vf_curves.c:127
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
decode_slice
static int decode_slice(AVCodecContext *c, void *arg)
Definition: ffv1dec.c:447
AV1RawFilmGrainParams::clip_to_restricted_range
uint8_t clip_to_restricted_range
Definition: cbs_av1.h:171
opt.h
ff_dovi_ctx_unref
void ff_dovi_ctx_unref(DOVIContext *s)
Completely reset a DOVIContext, preserving only logctx.
Definition: dovi_rpu.c:30
AV1_GM_ABS_TRANS_ONLY_BITS
@ AV1_GM_ABS_TRANS_ONLY_BITS
Definition: av1.h:108
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
Definition: bytestream.h:158
AV1RawFilmGrainParams::grain_seed
uint16_t grain_seed
Definition: cbs_av1.h:144
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:671
AV1RawSequenceHeader::timing_info_present_flag
uint8_t timing_info_present_flag
Definition: cbs_av1.h:87
AV1RawSequenceHeader
Definition: cbs_av1.h:82
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1223
order_hint_info
static void order_hint_info(AV1DecContext *s)
Definition: av1dec.c:366
AV1RawColorConfig::color_range
uint8_t color_range
Definition: cbs_av1.h:60
coded_lossless_param
static void coded_lossless_param(AV1DecContext *s)
Definition: av1dec.c:336
GetByteContext
Definition: bytestream.h:33
bytestream2_tell
static av_always_inline int bytestream2_tell(const GetByteContext *g)
Definition: bytestream.h:192
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
av1_frame_alloc
static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f)
Definition: av1dec.c:912
AV1_FRAME_SWITCH
@ AV1_FRAME_SWITCH
Definition: av1.h:56
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:124
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:152
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:114
AV1RawFilmGrainParams::apply_grain
uint8_t apply_grain
Definition: cbs_av1.h:143
bytestream2_skipu
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:174
AV1_MAX_OPERATING_POINTS
@ AV1_MAX_OPERATING_POINTS
Definition: av1.h:74
av_cold
#define av_cold
Definition: attributes.h:119
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
get_current_frame
static int get_current_frame(AVCodecContext *avctx)
Definition: av1dec.c:1149
FF_ITUT_T35_FLAG_COUNTRY_CODE
#define FF_ITUT_T35_FLAG_COUNTRY_CODE
country_code is assumed to not be the first byte of the buffer and must be set by the caller beforeha...
Definition: itut35.h:83
AV1_REFS_PER_FRAME
@ AV1_REFS_PER_FRAME
Definition: av1.h:85
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
AVFilmGrainParams::aom
AVFilmGrainAOMParams aom
Definition: film_grain_params.h:247
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
pixdesc.h
AV1_GM_ABS_TRANS_BITS
@ AV1_GM_ABS_TRANS_BITS
Definition: av1.h:110
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:664
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:424
set_context_with_sequence
static int set_context_with_sequence(AVCodecContext *avctx, const AV1RawSequenceHeader *seq)
Definition: av1dec.c:769
HWACCEL_DXVA2
#define HWACCEL_DXVA2(codec)
Definition: hwconfig.h:64
AV1RawFilmGrainParams::point_y_value
uint8_t point_y_value[14]
Definition: cbs_av1.h:148
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:777
internal.h
AVOption
AVOption.
Definition: opt.h:428
HWACCEL_D3D11VA2
#define HWACCEL_D3D11VA2(codec)
Definition: hwconfig.h:66
b
#define b
Definition: input.c:43
ff_progress_frame_get_buffer
int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
Wrapper around ff_progress_frame_alloc() and ff_thread_get_buffer().
Definition: decode.c:1933
AV1RawSequenceHeader::timing_info
AV1RawTimingInfo timing_info
Definition: cbs_av1.h:92
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:539
high
int high
Definition: dovi_rpuenc.c:39
AVFilmGrainParams::color_space
enum AVColorSpace color_space
Definition: film_grain_params.h:233
AV1RawTileGroup::tg_end
uint16_t tg_end
Definition: cbs_av1.h:313
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:81
FF_HW_SIMPLE_CALL
#define FF_HW_SIMPLE_CALL(avctx, function)
Definition: hwaccel_internal.h:176
decompose_unit_types
static const CodedBitstreamUnitType decompose_unit_types[]
Definition: av1dec.c:842
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
AVFilmGrainParams::codec
union AVFilmGrainParams::@531 codec
Additional fields may be added both here and in any structure included.
AV1RawTileData::data
uint8_t * data
Definition: cbs_av1.h:301
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
get_relative_dist
static int get_relative_dist(const AV1RawSequenceHeader *seq, unsigned int a, unsigned int b)
Definition: av1dec.c:260
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition: utils.c:91
AV1RawOBU::header
AV1RawOBUHeader header
Definition: cbs_av1.h:414
av1_frame_replace
static void av1_frame_replace(AV1Frame *dst, const AV1Frame *src)
Definition: av1dec.c:702
AVFilmGrainParams::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: film_grain_params.h:232
AVFilmGrainParams::seed
uint64_t seed
Seed to use for the synthesis process, if the codec allows for it.
Definition: film_grain_params.h:213
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:83
AV1RawMetadata::itut_t35
AV1RawMetadataITUTT35 itut_t35
Definition: cbs_av1.h:400
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:77
AV1RawColorConfig::subsampling_y
uint8_t subsampling_y
Definition: cbs_av1.h:62
round_two
static uint64_t round_two(uint64_t x, uint16_t n)
Definition: av1dec.c:143
AV1_DIV_LUT_BITS
@ AV1_DIV_LUT_BITS
Definition: av1.h:120
AV1RawFrame::header
AV1RawFrameHeader header
Definition: cbs_av1.h:319
AV1RawFilmGrainParams::cr_mult
uint8_t cr_mult
Definition: cbs_av1.h:167
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
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:280
AV1RawFilmGrainParams::chroma_scaling_from_luma
uint8_t chroma_scaling_from_luma
Definition: cbs_av1.h:150
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:563
close
static av_cold void close(AVCodecParserContext *s)
Definition: apv_parser.c:197
AVPacketSideData::size
size_t size
Definition: packet.h:426
AV1RawFilmGrainParams::ar_coeffs_cr_plus_128
uint8_t ar_coeffs_cr_plus_128[25]
Definition: cbs_av1.h:161
AV1_WARPEDMODEL_PREC_BITS
@ AV1_WARPEDMODEL_PREC_BITS
Definition: av1.h:112
av1_parse.h
mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
Definition: dsp.h:57
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AV1_FRAME_KEY
@ AV1_FRAME_KEY
Definition: av1.h:53
av1_options
static const AVOption av1_options[]
Definition: av1dec.c:1513
AVCodecContext::skip_frame
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:1667
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:156
AV1RawMetadataITUTT35::payload_size
size_t payload_size
Definition: cbs_av1.h:369
inverse_recenter
static uint32_t inverse_recenter(int r, uint32_t v)
Definition: av1dec.c:73
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:162
CodedBitstreamUnit::data
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
Definition: cbs.h:88
AV1RawFilmGrainParams::num_y_points
uint8_t num_y_points
Definition: cbs_av1.h:147
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
AV1_SEG_LVL_ALT_Q
@ AV1_SEG_LVL_ALT_Q
Definition: av1.h:92
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:150
AVRational::num
int num
Numerator.
Definition: rational.h:59
progressframe.h
refstruct.h
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:151
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:542
AV1RawFilmGrainParams::cb_luma_mult
uint8_t cb_luma_mult
Definition: cbs_av1.h:165
AV1Frame
Definition: av1dec.h:37
AV1RawFilmGrainParams::overlap_flag
uint8_t overlap_flag
Definition: cbs_av1.h:170
FF_CODEC_CAP_USES_PROGRESSFRAMES
#define FF_CODEC_CAP_USES_PROGRESSFRAMES
The decoder might make use of the ProgressFrame API.
Definition: codec_internal.h:69
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:657
show_frame
static void show_frame(AVTextFormatContext *tfc, AVFrame *frame, AVStream *stream, AVFormatContext *fmt_ctx)
Definition: ffprobe.c:1509
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
film_grain_params.h
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
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:220
AV1RawFilmGrainParams::grain_scaling_minus_8
uint8_t grain_scaling_minus_8
Definition: cbs_av1.h:157
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:681
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:211
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:527
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:2330
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
AV1_CSP_VERTICAL
@ AV1_CSP_VERTICAL
Definition: av1.h:134
AV1RawMetadata::metadata
union AV1RawMetadata::@83 metadata
AV1_METADATA_TYPE_HDR_MDCV
@ AV1_METADATA_TYPE_HDR_MDCV
Definition: av1.h:45
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:415
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:33
av1_decode_free
static av_cold int av1_decode_free(AVCodecContext *avctx)
Definition: av1dec.c:743
AV1RawMetadata::hdr_cll
AV1RawMetadataHDRCLL hdr_cll
Definition: cbs_av1.h:397
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:296
CodedBitstreamUnitType
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:54
init_tile_data
static int init_tile_data(AV1DecContext *s)
Definition: av1dec.c:410
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
AVPacketSideData::data
uint8_t * data
Definition: packet.h:425
ff_progress_frame_unref
void ff_progress_frame_unref(ProgressFrame *f)
Give up a reference to the underlying frame contained in a ProgressFrame and reset the ProgressFrame,...
Definition: decode.c:1956
decode.h
ff_av1_profiles
const AVProfile ff_av1_profiles[]
Definition: profiles.c:163
AV1_PRIMARY_REF_NONE
@ AV1_PRIMARY_REF_NONE
Definition: av1.h:87
get_sw_pixel_format
static enum AVPixelFormat get_sw_pixel_format(void *logctx, const AV1RawSequenceHeader *seq)
Definition: av1dec.c:473
AV1RawColorConfig::transfer_characteristics
uint8_t transfer_characteristics
Definition: cbs_av1.h:57
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
AV1_FRAME_INTER
@ AV1_FRAME_INTER
Definition: av1.h:54
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:428
export_itut_t35
static int export_itut_t35(AVCodecContext *avctx, AVFrame *frame, const AV1RawMetadataITUTT35 *itut_t35)
Definition: av1dec.c:959
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:349
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:2257
load_grain_params
static void load_grain_params(AV1DecContext *s)
Definition: av1dec.c:390
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:519
ff_av1_decoder
const FFCodec ff_av1_decoder
Definition: av1dec.c:1526
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:232
fail
#define fail
Definition: test.h:478
AVFilmGrainAOMParams::uv_mult_luma
int uv_mult_luma[2]
Definition: film_grain_params.h:106
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AV1_WARP_MODEL_TRANSLATION
@ AV1_WARP_MODEL_TRANSLATION
Definition: av1.h:115
AV1RawOBU
Definition: cbs_av1.h:413
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
AV1_REF_FRAME_ALTREF
@ AV1_REF_FRAME_ALTREF
Definition: av1.h:69
av_clip_int16
#define av_clip_int16
Definition: common.h:115
HWACCEL_MAX
#define HWACCEL_MAX
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AV1RawFilmGrainParams::cb_mult
uint8_t cb_mult
Definition: cbs_av1.h:164
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:681
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
FFITUTT35
Definition: itut35.h:50
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:275
hwaccel_internal.h
AV1RawFrameHeader
Definition: cbs_av1.h:174
AVCHROMA_LOC_LEFT
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:798
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:800
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:478
ff_itut_t35_parse_buffer
int ff_itut_t35_parse_buffer(FFITUTT35 *const itut_t35, const uint8_t *buf, size_t buf_size, int flags)
Parse a raw ITU-T T35 buffer to get the country code, provider code, and set them plus the pointer an...
Definition: itut35.c:34
AV1_DIV_LUT_NUM
@ AV1_DIV_LUT_NUM
Definition: av1.h:122
av_fallthrough
#define av_fallthrough
Definition: attributes.h:67
AV1RawTileData::data_size
size_t data_size
Definition: cbs_av1.h:303
av1_frame_unref
static void av1_frame_unref(AV1Frame *f)
Definition: av1dec.c:689
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
AV1RawColorConfig::chroma_sample_position
uint8_t chroma_sample_position
Definition: cbs_av1.h:63
profiles.h
AV1_MAX_SEGMENTS
@ AV1_MAX_SEGMENTS
Definition: av1.h:89
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:93
ff_set_sar
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition: utils.c:106
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:581
AV1_OBU_TILE_GROUP
@ AV1_OBU_TILE_GROUP
Definition: av1.h:33
AV1_GM_ABS_ALPHA_BITS
@ AV1_GM_ABS_ALPHA_BITS
Definition: av1.h:106
update_context_with_frame_header
static int update_context_with_frame_header(AVCodecContext *avctx, const AV1RawFrameHeader *header)
Definition: av1dec.c:812
abs
#define abs(x)
Definition: cuda_runtime.h:35
attributes.h
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:540
skip_mode_params
static void skip_mode_params(AV1DecContext *s)
Definition: av1dec.c:268
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:225
FF_HW_HAS_CB
#define FF_HW_HAS_CB(avctx, function)
Definition: hwaccel_internal.h:179
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1646
AV_PICTURE_TYPE_SP
@ AV_PICTURE_TYPE_SP
Switching Predicted.
Definition: avutil.h:283
av_opt_set_int
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:869
AV1_WARP_MODEL_IDENTITY
@ AV1_WARP_MODEL_IDENTITY
Definition: av1.h:114
AV1RawSequenceHeader::max_frame_height_minus_1
uint16_t max_frame_height_minus_1
Definition: cbs_av1.h:108
ff_itut_t35_parse_payload_to_frame
int ff_itut_t35_parse_payload_to_frame(FFITUTT35 *const itut_t35, FFITUTT35Aux *const aux, AVCodecContext *const avctx, AVFrame *const frame)
Parse a pre-processed ITU-T T35 payload to fill a frame's side data.
Definition: itut35.c:322
resolve_divisor
static int16_t resolve_divisor(uint32_t d, uint16_t *shift)
Resolve divisor process.
Definition: av1dec.c:159
AV1_METADATA_TYPE_HDR_CLL
@ AV1_METADATA_TYPE_HDR_CLL
Definition: av1.h:44
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
AV1RawFilmGrainParams::point_cr_value
uint8_t point_cr_value[10]
Definition: cbs_av1.h:155
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:231
f
f
Definition: af_crystalizer.c:122
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:579
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:49
AV1RawFilmGrainParams::cb_offset
uint16_t cb_offset
Definition: cbs_av1.h:166
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:88
height
#define height
Definition: dsp.h:89
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:278
decode_unsigned_subexp_with_ref
static uint32_t decode_unsigned_subexp_with_ref(uint32_t sub_exp, int mx, int r)
Definition: av1dec.c:83
codec_internal.h
AV1RawTimingInfo::num_ticks_per_picture_minus_1
uint32_t num_ticks_per_picture_minus_1
Definition: cbs_av1.h:72
shift
static int shift(int a, int b)
Definition: bonk.c:261
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
AV1_CSP_COLOCATED
@ AV1_CSP_COLOCATED
Definition: av1.h:135
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:544
av1_decode_flush
static av_cold void av1_decode_flush(AVCodecContext *avctx)
Definition: av1dec.c:1486
size
int size
Definition: twinvq_data.h:10344
AV1DecContext
Definition: av1dec.h:85
AV1RawOBU::sequence_header
AV1RawSequenceHeader sequence_header
Definition: cbs_av1.h:419
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
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:55
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:546
AVFilmGrainParams
This structure describes how to handle film grain synthesis in video for specific codecs.
Definition: film_grain_params.h:201
AV1_OBU_SEQUENCE_HEADER
@ AV1_OBU_SEQUENCE_HEADER
Definition: av1.h:30
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
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:166
AV1RawColorConfig::color_description_present_flag
uint8_t color_description_present_flag
Definition: cbs_av1.h:55
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:602
av_refstruct_ref
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition: refstruct.c:140
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:225
VD
#define VD
Definition: av1dec.c:1512
HWACCEL_D3D11VA
#define HWACCEL_D3D11VA(codec)
Definition: hwconfig.h:78
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:163
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
AV1_REF_FRAME_LAST
@ AV1_REF_FRAME_LAST
Definition: av1.h:63
AV1RawOBU::frame_header
AV1RawFrameHeader frame_header
Definition: cbs_av1.h:420
av1_receive_frame
static int av1_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:1456
av_refstruct_unref
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
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:427
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:305
AV1RawMetadata::metadata_type
uint64_t metadata_type
Definition: cbs_av1.h:395
export_film_grain
static int export_film_grain(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:1030
AV1_OBU_PADDING
@ AV1_OBU_PADDING
Definition: av1.h:39
AVFilmGrainParams::color_primaries
enum AVColorPrimaries color_primaries
Definition: film_grain_params.h:231
AVDISCARD_NONINTRA
@ AVDISCARD_NONINTRA
discard all non intra frames
Definition: defs.h:230
CodedBitstreamUnit::data_ref
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:105
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:596
AV1_GM_ALPHA_PREC_BITS
@ AV1_GM_ALPHA_PREC_BITS
Definition: av1.h:107
round
static av_always_inline av_const double round(double x)
Definition: libm.h:446
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:526
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:46
AV1RawMetadata::hdr_mdcv
AV1RawMetadataHDRMDCV hdr_mdcv
Definition: cbs_av1.h:398
AVFilmGrainParams::subsampling_y
int subsampling_y
Definition: film_grain_params.h:225
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:83
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:58
delta
float delta
Definition: vorbis_enc_data.h:430
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:496
AV1RawSequenceHeader::max_frame_width_minus_1
uint16_t max_frame_width_minus_1
Definition: cbs_av1.h:107
AV1RawSequenceHeader::color_config
AV1RawColorConfig color_config
Definition: cbs_av1.h:137
AV1RawMetadataITUTT35::payload
uint8_t * payload
Definition: cbs_av1.h:367
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:176
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:688
AV1RawTileGroup::tg_start
uint16_t tg_start
Definition: cbs_av1.h:312
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:122
AVCodecContext::height
int height
Definition: avcodec.h:604
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:643
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:760
AV1RawMetadataITUTT35::payload_ref
AVBufferRef * payload_ref
Definition: cbs_av1.h:368
HWACCEL_VIDEOTOOLBOX
#define HWACCEL_VIDEOTOOLBOX(codec)
Definition: hwconfig.h:74
AV1RawOBU::tile_group
AV1RawTileGroup tile_group
Definition: cbs_av1.h:422
AV1RawFilmGrainParams::update_grain
uint8_t update_grain
Definition: cbs_av1.h:145
avcodec.h
AV1RawTileGroup::tile_data
AV1RawTileData tile_data
Definition: cbs_av1.h:315
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:1519
AVFilmGrainParams::height
int height
Definition: film_grain_params.h:220
ret
ret
Definition: filter_design.txt:187
AV1RawColorConfig::subsampling_x
uint8_t subsampling_x
Definition: cbs_av1.h:61
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:81
AV1_OBU_TILE_LIST
@ AV1_OBU_TILE_LIST
Definition: av1.h:37
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
atsc_a53.h
AV1RawColorConfig::high_bitdepth
uint8_t high_bitdepth
Definition: cbs_av1.h:51
AV1RawFilmGrainParams::cr_luma_mult
uint8_t cr_luma_mult
Definition: cbs_av1.h:168
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:2302
AV1RawFilmGrainParams::film_grain_params_ref_idx
uint8_t film_grain_params_ref_idx
Definition: cbs_av1.h:146
read_global_param
static void read_global_param(AV1DecContext *s, int type, int ref, int idx)
Definition: av1dec.c:100
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:543
ff_progress_frame_replace
void ff_progress_frame_replace(ProgressFrame *dst, const ProgressFrame *src)
Do nothing if dst and src already refer to the same AVFrame; otherwise unreference dst and if src is ...
Definition: decode.c:1963
HWACCEL_VULKAN
#define HWACCEL_VULKAN(codec)
Definition: hwconfig.h:76
AV1RawMetadataITUTT35
Definition: cbs_av1.h:363
AVCodecContext
main external API structure.
Definition: avcodec.h:443
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:179
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:372
AVFilmGrainAOMParams::y_points
uint8_t y_points[14][2]
Definition: film_grain_params.h:50
AVFilmGrainAOMParams::uv_offset
int uv_offset[2]
Offset used for component scaling function.
Definition: film_grain_params.h:112
av_refstruct_replace
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition: refstruct.c:160
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:173
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:258
FFITUTT35Aux::dovi
DOVIContext * dovi
A DOVIContext.
Definition: itut35.h:76
AV1RawFilmGrainParams::ar_coeff_lag
uint8_t ar_coeff_lag
Definition: cbs_av1.h:158
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1636
AV1RawColorConfig::mono_chrome
uint8_t mono_chrome
Definition: cbs_av1.h:53
export_metadata
static int export_metadata(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:979
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:117
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:1779
AV1RawFilmGrainParams::ar_coeffs_cb_plus_128
uint8_t ar_coeffs_cb_plus_128[25]
Definition: cbs_av1.h:160
AV1RawFilmGrainParams::ar_coeffs_y_plus_128
uint8_t ar_coeffs_y_plus_128[24]
Definition: cbs_av1.h:159
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
AV1RawSequenceHeader::order_hint_bits_minus_1
uint8_t order_hint_bits_minus_1
Definition: cbs_av1.h:131
AV1RawColorConfig::matrix_coefficients
uint8_t matrix_coefficients
Definition: cbs_av1.h:58
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:306
AVFilmGrainParams::color_range
enum AVColorRange color_range
Intended video signal characteristics.
Definition: film_grain_params.h:230
AV1RawFilmGrainParams::cr_offset
uint16_t cr_offset
Definition: cbs_av1.h:169
AV1RawFilmGrainParams::point_y_scaling
uint8_t point_y_scaling[14]
Definition: cbs_av1.h:149
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:279
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
AV1RawOBU::frame
AV1RawFrame frame
Definition: cbs_av1.h:421
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
mem.h
AV1RawFilmGrainParams::point_cb_scaling
uint8_t point_cb_scaling[10]
Definition: cbs_av1.h:153
AV1RawMetadataITUTT35::itu_t_t35_country_code
uint8_t itu_t_t35_country_code
Definition: cbs_av1.h:364
mastering_display_metadata.h
AV1RawFrame::tile_group
AV1RawTileGroup tile_group
Definition: cbs_av1.h:320
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:93
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
w
uint8_t w
Definition: llvidencdsp.c:39
AV1RawColorConfig::twelve_bit
uint8_t twelve_bit
Definition: cbs_av1.h:52
AV1_WARP_MODEL_AFFINE
@ AV1_WARP_MODEL_AFFINE
Definition: av1.h:117
get_pixel_format
static int get_pixel_format(AVCodecContext *avctx)
Definition: av1dec.c:536
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:580
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:470
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
OFFSET
#define OFFSET(x)
Definition: av1dec.c:1511
AV1_GM_TRANS_ONLY_PREC_BITS
@ AV1_GM_TRANS_ONLY_PREC_BITS
Definition: av1.h:109
AV1RawOBU::obu
union AV1RawOBU::@84 obu
HWACCEL_VAAPI
#define HWACCEL_VAAPI(codec)
Definition: hwconfig.h:70
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:604
TileGroupInfo
Definition: av1dec.h:78
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
FFITUTT35Aux
Definition: itut35.h:71
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:142
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
av_fifo_freep2
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition: fifo.c:286
AV1_GM_TRANS_PREC_BITS
@ AV1_GM_TRANS_PREC_BITS
Definition: av1.h:111
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AV1_WARP_PARAM_REDUCE_BITS
@ AV1_WARP_PARAM_REDUCE_BITS
Definition: av1.h:118
av1_receive_frame_internal
static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:1212
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
width
#define width
Definition: dsp.h:89
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:520
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
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:38
AV1_FRAME_INTRA_ONLY
@ AV1_FRAME_INTRA_ONLY
Definition: av1.h:55
AVFilmGrainParams::type
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
Definition: film_grain_params.h:205
set_output_frame
static int set_output_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:1100
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:154
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:628
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
src
#define src
Definition: vp8dsp.c:248
AV_CODEC_EXPORT_DATA_FILM_GRAIN
#define AV_CODEC_EXPORT_DATA_FILM_GRAIN
Decoding only.
Definition: avcodec.h:404
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:63
AV1_WARP_MODEL_ROTZOOM
@ AV1_WARP_MODEL_ROTZOOM
Definition: av1.h:116
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:3376
AV1_NUM_REF_FRAMES
@ AV1_NUM_REF_FRAMES
Definition: av1.h:84
AVDOVIDecoderConfigurationRecord
Definition: dovi_meta.h:55
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:457