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 
22 #include "libavutil/pixdesc.h"
23 #include "libavutil/opt.h"
24 #include "avcodec.h"
25 #include "av1dec.h"
26 #include "bytestream.h"
27 #include "hwconfig.h"
28 #include "internal.h"
29 #include "profiles.h"
30 
31 /**< same with Div_Lut defined in spec 7.11.3.7 */
32 static const uint16_t div_lut[AV1_DIV_LUT_NUM] = {
33  16384, 16320, 16257, 16194, 16132, 16070, 16009, 15948, 15888, 15828, 15768,
34  15709, 15650, 15592, 15534, 15477, 15420, 15364, 15308, 15252, 15197, 15142,
35  15087, 15033, 14980, 14926, 14873, 14821, 14769, 14717, 14665, 14614, 14564,
36  14513, 14463, 14413, 14364, 14315, 14266, 14218, 14170, 14122, 14075, 14028,
37  13981, 13935, 13888, 13843, 13797, 13752, 13707, 13662, 13618, 13574, 13530,
38  13487, 13443, 13400, 13358, 13315, 13273, 13231, 13190, 13148, 13107, 13066,
39  13026, 12985, 12945, 12906, 12866, 12827, 12788, 12749, 12710, 12672, 12633,
40  12596, 12558, 12520, 12483, 12446, 12409, 12373, 12336, 12300, 12264, 12228,
41  12193, 12157, 12122, 12087, 12053, 12018, 11984, 11950, 11916, 11882, 11848,
42  11815, 11782, 11749, 11716, 11683, 11651, 11619, 11586, 11555, 11523, 11491,
43  11460, 11429, 11398, 11367, 11336, 11305, 11275, 11245, 11215, 11185, 11155,
44  11125, 11096, 11067, 11038, 11009, 10980, 10951, 10923, 10894, 10866, 10838,
45  10810, 10782, 10755, 10727, 10700, 10673, 10645, 10618, 10592, 10565, 10538,
46  10512, 10486, 10460, 10434, 10408, 10382, 10356, 10331, 10305, 10280, 10255,
47  10230, 10205, 10180, 10156, 10131, 10107, 10082, 10058, 10034, 10010, 9986,
48  9963, 9939, 9916, 9892, 9869, 9846, 9823, 9800, 9777, 9754, 9732,
49  9709, 9687, 9664, 9642, 9620, 9598, 9576, 9554, 9533, 9511, 9489,
50  9468, 9447, 9425, 9404, 9383, 9362, 9341, 9321, 9300, 9279, 9259,
51  9239, 9218, 9198, 9178, 9158, 9138, 9118, 9098, 9079, 9059, 9039,
52  9020, 9001, 8981, 8962, 8943, 8924, 8905, 8886, 8867, 8849, 8830,
53  8812, 8793, 8775, 8756, 8738, 8720, 8702, 8684, 8666, 8648, 8630,
54  8613, 8595, 8577, 8560, 8542, 8525, 8508, 8490, 8473, 8456, 8439,
55  8422, 8405, 8389, 8372, 8355, 8339, 8322, 8306, 8289, 8273, 8257,
56  8240, 8224, 8208, 8192
57 };
58 
59 static uint32_t inverse_recenter(int r, uint32_t v)
60 {
61  if (v > 2 * r)
62  return v;
63  else if (v & 1)
64  return r - ((v + 1) >> 1);
65  else
66  return r + (v >> 1);
67 }
68 
69 static uint32_t decode_unsigned_subexp_with_ref(uint32_t sub_exp,
70  int mx, int r)
71 {
72  if ((r << 1) <= mx) {
73  return inverse_recenter(r, sub_exp);
74  } else {
75  return mx - 1 - inverse_recenter(mx - 1 - r, sub_exp);
76  }
77 }
78 
79 static int32_t decode_signed_subexp_with_ref(uint32_t sub_exp, int low,
80  int high, int r)
81 {
82  int32_t x = decode_unsigned_subexp_with_ref(sub_exp, high - low, r - low);
83  return x + low;
84 }
85 
86 static void read_global_param(AV1DecContext *s, int type, int ref, int idx)
87 {
88  uint8_t primary_frame, prev_frame;
89  uint32_t abs_bits, prec_bits, round, prec_diff, sub, mx;
90  int32_t r, prev_gm_param;
91 
92  primary_frame = s->raw_frame_header->primary_ref_frame;
93  prev_frame = s->raw_frame_header->ref_frame_idx[primary_frame];
94  abs_bits = AV1_GM_ABS_ALPHA_BITS;
95  prec_bits = AV1_GM_ALPHA_PREC_BITS;
96 
97  /* setup_past_independence() sets PrevGmParams to default values. We can
98  * simply point to the current's frame gm_params as they will be initialized
99  * with defaults at this point.
100  */
101  if (s->raw_frame_header->primary_ref_frame == AV1_PRIMARY_REF_NONE)
102  prev_gm_param = s->cur_frame.gm_params[ref][idx];
103  else
104  prev_gm_param = s->ref[prev_frame].gm_params[ref][idx];
105 
106  if (idx < 2) {
108  abs_bits = AV1_GM_ABS_TRANS_ONLY_BITS -
109  !s->raw_frame_header->allow_high_precision_mv;
110  prec_bits = AV1_GM_TRANS_ONLY_PREC_BITS -
111  !s->raw_frame_header->allow_high_precision_mv;
112  } else {
113  abs_bits = AV1_GM_ABS_TRANS_BITS;
114  prec_bits = AV1_GM_TRANS_PREC_BITS;
115  }
116  }
117  round = (idx % 3) == 2 ? (1 << AV1_WARPEDMODEL_PREC_BITS) : 0;
118  prec_diff = AV1_WARPEDMODEL_PREC_BITS - prec_bits;
119  sub = (idx % 3) == 2 ? (1 << prec_bits) : 0;
120  mx = 1 << abs_bits;
121  r = (prev_gm_param >> prec_diff) - sub;
122 
123  s->cur_frame.gm_params[ref][idx] =
124  (decode_signed_subexp_with_ref(s->raw_frame_header->gm_params[ref][idx],
125  -mx, mx + 1, r) << prec_diff) + round;
126 }
127 
128 static uint64_t round_two(uint64_t x, uint16_t n)
129 {
130  if (n == 0)
131  return x;
132  return ((x + ((uint64_t)1 << (n - 1))) >> n);
133 }
134 
135 static int64_t round_two_signed(int64_t x, uint16_t n)
136 {
137  return ((x<0) ? -((int64_t)round_two(-x, n)) : (int64_t)round_two(x, n));
138 }
139 
140 /**
141  * Resolve divisor process.
142  * see spec 7.11.3.7
143  */
144 static int16_t resolve_divisor(uint32_t d, uint16_t *shift)
145 {
146  int32_t e, f;
147 
148  *shift = av_log2(d);
149  e = d - (1 << (*shift));
150  if (*shift > AV1_DIV_LUT_BITS)
152  else
153  f = e << (AV1_DIV_LUT_BITS - (*shift));
154 
156 
157  return div_lut[f];
158 }
159 
160 /**
161  * check if global motion params is valid.
162  * see spec 7.11.3.6
163  */
164 static uint8_t get_shear_params_valid(AV1DecContext *s, int idx)
165 {
166  int16_t alpha, beta, gamma, delta, divf, divs;
167  int64_t v, w;
168  int32_t *param = &s->cur_frame.gm_params[idx][0];
169  if (param[2] < 0)
170  return 0;
171 
172  alpha = av_clip_int16(param[2] - (1 << AV1_WARPEDMODEL_PREC_BITS));
173  beta = av_clip_int16(param[3]);
174  divf = resolve_divisor(abs(param[2]), &divs);
175  v = (int64_t)param[4] * (1 << AV1_WARPEDMODEL_PREC_BITS);
176  w = (int64_t)param[3] * param[4];
177  gamma = av_clip_int16((int)round_two_signed((v * divf), divs));
178  delta = av_clip_int16(param[5] - (int)round_two_signed((w * divf), divs) - (1 << AV1_WARPEDMODEL_PREC_BITS));
179 
184 
185  if ((4 * abs(alpha) + 7 * abs(beta)) >= (1 << AV1_WARPEDMODEL_PREC_BITS) ||
186  (4 * abs(gamma) + 4 * abs(delta)) >= (1 << AV1_WARPEDMODEL_PREC_BITS))
187  return 0;
188 
189  return 1;
190 }
191 
192 /**
193 * update gm type/params, since cbs already implemented part of this funcation,
194 * so we don't need to full implement spec.
195 */
197 {
198  const AV1RawFrameHeader *header = s->raw_frame_header;
199  int type, ref;
200 
202  s->cur_frame.gm_type[ref] = AV1_WARP_MODEL_IDENTITY;
203  for (int i = 0; i < 6; i++)
204  s->cur_frame.gm_params[ref][i] = (i % 3 == 2) ?
205  1 << AV1_WARPEDMODEL_PREC_BITS : 0;
206  }
207  if (header->frame_type == AV1_FRAME_KEY ||
208  header->frame_type == AV1_FRAME_INTRA_ONLY)
209  return;
210 
212  if (header->is_global[ref]) {
213  if (header->is_rot_zoom[ref]) {
215  } else {
216  type = header->is_translation[ref] ? AV1_WARP_MODEL_TRANSLATION
218  }
219  } else {
221  }
222  s->cur_frame.gm_type[ref] = type;
223 
224  if (type >= AV1_WARP_MODEL_ROTZOOM) {
225  read_global_param(s, type, ref, 2);
226  read_global_param(s, type, ref, 3);
227  if (type == AV1_WARP_MODEL_AFFINE) {
228  read_global_param(s, type, ref, 4);
229  read_global_param(s, type, ref, 5);
230  } else {
231  s->cur_frame.gm_params[ref][4] = -s->cur_frame.gm_params[ref][3];
232  s->cur_frame.gm_params[ref][5] = s->cur_frame.gm_params[ref][2];
233  }
234  }
236  read_global_param(s, type, ref, 0);
237  read_global_param(s, type, ref, 1);
238  }
239  if (type <= AV1_WARP_MODEL_AFFINE) {
240  s->cur_frame.gm_invalid[ref] = !get_shear_params_valid(s, ref);
241  }
242  }
243 }
244 
246  unsigned int a, unsigned int b)
247 {
248  unsigned int diff = a - b;
249  unsigned int m = 1 << seq->order_hint_bits_minus_1;
250  return (diff & (m - 1)) - (diff & m);
251 }
252 
254 {
255  const AV1RawFrameHeader *header = s->raw_frame_header;
256  const AV1RawSequenceHeader *seq = s->raw_seq;
257 
258  int forward_idx, backward_idx;
259  int forward_hint, backward_hint;
260  int second_forward_idx, second_forward_hint;
261  int ref_hint, dist, i;
262 
263  if (!header->skip_mode_present)
264  return;
265 
266  forward_idx = -1;
267  backward_idx = -1;
268  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
269  ref_hint = s->ref[header->ref_frame_idx[i]].raw_frame_header->order_hint;
270  dist = get_relative_dist(seq, ref_hint, header->order_hint);
271  if (dist < 0) {
272  if (forward_idx < 0 ||
273  get_relative_dist(seq, ref_hint, forward_hint) > 0) {
274  forward_idx = i;
275  forward_hint = ref_hint;
276  }
277  } else if (dist > 0) {
278  if (backward_idx < 0 ||
279  get_relative_dist(seq, ref_hint, backward_hint) < 0) {
280  backward_idx = i;
281  backward_hint = ref_hint;
282  }
283  }
284  }
285 
286  if (forward_idx < 0) {
287  return;
288  } else if (backward_idx >= 0) {
289  s->cur_frame.skip_mode_frame_idx[0] =
290  AV1_REF_FRAME_LAST + FFMIN(forward_idx, backward_idx);
291  s->cur_frame.skip_mode_frame_idx[1] =
292  AV1_REF_FRAME_LAST + FFMAX(forward_idx, backward_idx);
293  return;
294  }
295 
296  second_forward_idx = -1;
297  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
298  ref_hint = s->ref[header->ref_frame_idx[i]].raw_frame_header->order_hint;
299  if (get_relative_dist(seq, ref_hint, forward_hint) < 0) {
300  if (second_forward_idx < 0 ||
301  get_relative_dist(seq, ref_hint, second_forward_hint) > 0) {
302  second_forward_idx = i;
303  second_forward_hint = ref_hint;
304  }
305  }
306  }
307 
308  if (second_forward_idx < 0)
309  return;
310 
311  s->cur_frame.skip_mode_frame_idx[0] =
312  AV1_REF_FRAME_LAST + FFMIN(forward_idx, second_forward_idx);
313  s->cur_frame.skip_mode_frame_idx[1] =
314  AV1_REF_FRAME_LAST + FFMAX(forward_idx, second_forward_idx);
315 }
316 
318 {
319  const AV1RawFrameHeader *header = s->raw_frame_header;
320  int i;
321 
322  if (header->delta_q_y_dc || header->delta_q_u_ac ||
323  header->delta_q_u_dc || header->delta_q_v_ac ||
324  header->delta_q_v_dc) {
325  s->cur_frame.coded_lossless = 0;
326  return;
327  }
328 
329  s->cur_frame.coded_lossless = 1;
330  for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
331  int qindex;
332  if (header->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) {
333  qindex = (header->base_q_idx +
334  header->feature_value[i][AV1_SEG_LVL_ALT_Q]);
335  } else {
336  qindex = header->base_q_idx;
337  }
338  qindex = av_clip_uintp2(qindex, 8);
339 
340  if (qindex) {
341  s->cur_frame.coded_lossless = 0;
342  return;
343  }
344  }
345 }
346 
348 {
349  const AV1RawFrameHeader *header = s->raw_frame_header;
350  const AV1RawFilmGrainParams *film_grain = &header->film_grain, *src;
351  AV1RawFilmGrainParams *dst = &s->cur_frame.film_grain;
352 
353  if (!film_grain->apply_grain)
354  return;
355 
356  if (film_grain->update_grain) {
357  memcpy(dst, film_grain, sizeof(*dst));
358  return;
359  }
360 
361  src = &s->ref[film_grain->film_grain_params_ref_idx].film_grain;
362 
363  memcpy(dst, src, sizeof(*dst));
364  dst->grain_seed = film_grain->grain_seed;
365 }
366 
368 
369 {
370  int cur_tile_num =
371  s->raw_frame_header->tile_cols * s->raw_frame_header->tile_rows;
372  if (s->tile_num < cur_tile_num) {
373  int ret = av_reallocp_array(&s->tile_group_info, cur_tile_num,
374  sizeof(TileGroupInfo));
375  if (ret < 0) {
376  s->tile_num = 0;
377  return ret;
378  }
379  }
380  s->tile_num = cur_tile_num;
381 
382  return 0;
383 }
384 
385 static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_group)
386 {
387  AV1DecContext *s = avctx->priv_data;
388  GetByteContext gb;
389  uint16_t tile_num, tile_row, tile_col;
390  uint32_t size = 0, size_bytes = 0;
391 
392  bytestream2_init(&gb, tile_group->tile_data.data,
393  tile_group->tile_data.data_size);
394  s->tg_start = tile_group->tg_start;
395  s->tg_end = tile_group->tg_end;
396 
397  for (tile_num = tile_group->tg_start; tile_num <= tile_group->tg_end; tile_num++) {
398  tile_row = tile_num / s->raw_frame_header->tile_cols;
399  tile_col = tile_num % s->raw_frame_header->tile_cols;
400 
401  if (tile_num == tile_group->tg_end) {
402  s->tile_group_info[tile_num].tile_size = bytestream2_get_bytes_left(&gb);
403  s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
404  s->tile_group_info[tile_num].tile_row = tile_row;
405  s->tile_group_info[tile_num].tile_column = tile_col;
406  return 0;
407  }
408  size_bytes = s->raw_frame_header->tile_size_bytes_minus1 + 1;
409  if (bytestream2_get_bytes_left(&gb) < size_bytes)
410  return AVERROR_INVALIDDATA;
411  size = 0;
412  for (int i = 0; i < size_bytes; i++)
413  size |= bytestream2_get_byteu(&gb) << 8 * i;
414  if (bytestream2_get_bytes_left(&gb) <= size)
415  return AVERROR_INVALIDDATA;
416  size++;
417 
418  s->tile_group_info[tile_num].tile_size = size;
419  s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
420  s->tile_group_info[tile_num].tile_row = tile_row;
421  s->tile_group_info[tile_num].tile_column = tile_col;
422 
423  bytestream2_skipu(&gb, size);
424  }
425 
426  return 0;
427 
428 }
429 
431 {
432  AV1DecContext *s = avctx->priv_data;
433  const AV1RawSequenceHeader *seq = s->raw_seq;
434  uint8_t bit_depth;
435  int ret;
437 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
438  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
439  CONFIG_AV1_NVDEC_HWACCEL + \
440  CONFIG_AV1_VAAPI_HWACCEL)
441  enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
442 
443  if (seq->seq_profile == 2 && seq->color_config.high_bitdepth)
444  bit_depth = seq->color_config.twelve_bit ? 12 : 10;
445  else if (seq->seq_profile <= 2)
446  bit_depth = seq->color_config.high_bitdepth ? 10 : 8;
447  else {
448  av_log(avctx, AV_LOG_ERROR,
449  "Unknown AV1 profile %d.\n", seq->seq_profile);
450  return -1;
451  }
452 
453  if (!seq->color_config.mono_chrome) {
454  // 4:4:4 x:0 y:0, 4:2:2 x:1 y:0, 4:2:0 x:1 y:1
455  if (seq->color_config.subsampling_x == 0 &&
456  seq->color_config.subsampling_y == 0) {
457  if (bit_depth == 8)
459  else if (bit_depth == 10)
461  else if (bit_depth == 12)
463  else
464  av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
465  } else if (seq->color_config.subsampling_x == 1 &&
466  seq->color_config.subsampling_y == 0) {
467  if (bit_depth == 8)
469  else if (bit_depth == 10)
471  else if (bit_depth == 12)
473  else
474  av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
475  } else if (seq->color_config.subsampling_x == 1 &&
476  seq->color_config.subsampling_y == 1) {
477  if (bit_depth == 8)
479  else if (bit_depth == 10)
481  else if (bit_depth == 12)
483  else
484  av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
485  }
486  } else {
487  if (bit_depth == 8)
489  else if (bit_depth == 10)
491  else if (bit_depth == 12)
493  else
494  av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
495  }
496 
497  av_log(avctx, AV_LOG_DEBUG, "AV1 decode get format: %s.\n",
499 
500  if (pix_fmt == AV_PIX_FMT_NONE)
501  return -1;
502 
503  switch (pix_fmt) {
504  case AV_PIX_FMT_YUV420P:
505 #if CONFIG_AV1_DXVA2_HWACCEL
506  *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
507 #endif
508 #if CONFIG_AV1_D3D11VA_HWACCEL
509  *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
510  *fmtp++ = AV_PIX_FMT_D3D11;
511 #endif
512 #if CONFIG_AV1_NVDEC_HWACCEL
513  *fmtp++ = AV_PIX_FMT_CUDA;
514 #endif
515 #if CONFIG_AV1_VAAPI_HWACCEL
516  *fmtp++ = AV_PIX_FMT_VAAPI;
517 #endif
518  break;
520 #if CONFIG_AV1_DXVA2_HWACCEL
521  *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
522 #endif
523 #if CONFIG_AV1_D3D11VA_HWACCEL
524  *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
525  *fmtp++ = AV_PIX_FMT_D3D11;
526 #endif
527 #if CONFIG_AV1_NVDEC_HWACCEL
528  *fmtp++ = AV_PIX_FMT_CUDA;
529 #endif
530 #if CONFIG_AV1_VAAPI_HWACCEL
531  *fmtp++ = AV_PIX_FMT_VAAPI;
532 #endif
533  break;
534  case AV_PIX_FMT_GRAY8:
535 #if CONFIG_AV1_NVDEC_HWACCEL
536  *fmtp++ = AV_PIX_FMT_CUDA;
537 #endif
538  break;
539  case AV_PIX_FMT_GRAY10:
540 #if CONFIG_AV1_NVDEC_HWACCEL
541  *fmtp++ = AV_PIX_FMT_CUDA;
542 #endif
543  break;
544  }
545 
546  *fmtp++ = pix_fmt;
547  *fmtp = AV_PIX_FMT_NONE;
548 
550  if (ret < 0)
551  return ret;
552 
553  /**
554  * check if the HW accel is inited correctly. If not, return un-implemented.
555  * Since now the av1 decoder doesn't support native decode, if it will be
556  * implemented in the future, need remove this check.
557  */
558  if (!avctx->hwaccel) {
559  av_log(avctx, AV_LOG_ERROR, "Your platform doesn't suppport"
560  " hardware accelerated AV1 decoding.\n");
561  return AVERROR(ENOSYS);
562  }
563 
564  s->pix_fmt = pix_fmt;
565  avctx->pix_fmt = ret;
566 
567  return 0;
568 }
569 
571 {
572  ff_thread_release_buffer(avctx, &f->tf);
573  av_buffer_unref(&f->hwaccel_priv_buf);
574  f->hwaccel_picture_private = NULL;
575  av_buffer_unref(&f->header_ref);
576  f->raw_frame_header = NULL;
577  f->spatial_id = f->temporal_id = 0;
578  memset(f->skip_mode_frame_idx, 0,
579  2 * sizeof(uint8_t));
580  memset(&f->film_grain, 0, sizeof(f->film_grain));
581  f->coded_lossless = 0;
582 }
583 
584 static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src)
585 {
586  int ret;
587 
588  ret = ff_thread_ref_frame(&dst->tf, &src->tf);
589  if (ret < 0)
590  return ret;
591 
592  dst->header_ref = av_buffer_ref(src->header_ref);
593  if (!dst->header_ref)
594  goto fail;
595 
596  dst->raw_frame_header = src->raw_frame_header;
597 
598  if (src->hwaccel_picture_private) {
599  dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);
600  if (!dst->hwaccel_priv_buf)
601  goto fail;
603  }
604 
605  dst->spatial_id = src->spatial_id;
606  dst->temporal_id = src->temporal_id;
607  memcpy(dst->gm_invalid,
608  src->gm_invalid,
609  AV1_NUM_REF_FRAMES * sizeof(uint8_t));
610  memcpy(dst->gm_type,
611  src->gm_type,
612  AV1_NUM_REF_FRAMES * sizeof(uint8_t));
613  memcpy(dst->gm_params,
614  src->gm_params,
615  AV1_NUM_REF_FRAMES * 6 * sizeof(int32_t));
616  memcpy(dst->skip_mode_frame_idx,
617  src->skip_mode_frame_idx,
618  2 * sizeof(uint8_t));
619  memcpy(&dst->film_grain,
620  &src->film_grain,
621  sizeof(dst->film_grain));
622  dst->coded_lossless = src->coded_lossless;
623 
624  return 0;
625 
626 fail:
627  av1_frame_unref(avctx, dst);
628  return AVERROR(ENOMEM);
629 }
630 
632 {
633  AV1DecContext *s = avctx->priv_data;
634 
635  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) {
636  av1_frame_unref(avctx, &s->ref[i]);
637  av_frame_free(&s->ref[i].tf.f);
638  }
639  av1_frame_unref(avctx, &s->cur_frame);
640  av_frame_free(&s->cur_frame.tf.f);
641 
642  av_buffer_unref(&s->seq_ref);
643  av_buffer_unref(&s->header_ref);
644  av_freep(&s->tile_group_info);
645 
646  ff_cbs_fragment_free(&s->current_obu);
647  ff_cbs_close(&s->cbc);
648 
649  return 0;
650 }
651 
653  const AV1RawSequenceHeader *seq)
654 {
655  int width = seq->max_frame_width_minus_1 + 1;
656  int height = seq->max_frame_height_minus_1 + 1;
657 
658  avctx->profile = seq->seq_profile;
659  avctx->level = seq->seq_level_idx[0];
660 
661  avctx->color_range =
666 
667  switch (seq->color_config.chroma_sample_position) {
668  case AV1_CSP_VERTICAL:
670  break;
671  case AV1_CSP_COLOCATED:
673  break;
674  }
675 
676  if (seq->film_grain_params_present)
678  else
680 
681  if (avctx->width != width || avctx->height != height) {
682  int ret = ff_set_dimensions(avctx, width, height);
683  if (ret < 0)
684  return ret;
685  }
686  avctx->sample_aspect_ratio = (AVRational) { 1, 1 };
687 
689  seq->timing_info.time_scale) {
690  av_reduce(&avctx->framerate.den, &avctx->framerate.num,
692  seq->timing_info.time_scale,
693  INT_MAX);
696  }
697 
698  return 0;
699 }
700 
702  const AV1RawFrameHeader *header)
703 {
704  AVRational aspect_ratio;
705  int width = header->frame_width_minus_1 + 1;
706  int height = header->frame_height_minus_1 + 1;
707  int r_width = header->render_width_minus_1 + 1;
708  int r_height = header->render_height_minus_1 + 1;
709  int ret;
710 
711  if (avctx->width != width || avctx->height != height) {
712  ret = ff_set_dimensions(avctx, width, height);
713  if (ret < 0)
714  return ret;
715  }
716 
717  av_reduce(&aspect_ratio.num, &aspect_ratio.den,
718  (int64_t)height * r_width,
719  (int64_t)width * r_height,
720  INT_MAX);
721 
722  if (av_cmp_q(avctx->sample_aspect_ratio, aspect_ratio)) {
723  ret = ff_set_sar(avctx, aspect_ratio);
724  if (ret < 0)
725  return ret;
726  }
727 
728  return 0;
729 }
730 
732 {
733  AV1DecContext *s = avctx->priv_data;
735  int ret;
736 
737  s->avctx = avctx;
738  s->pix_fmt = AV_PIX_FMT_NONE;
739 
740  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) {
741  s->ref[i].tf.f = av_frame_alloc();
742  if (!s->ref[i].tf.f) {
743  av_log(avctx, AV_LOG_ERROR,
744  "Failed to allocate reference frame buffer %d.\n", i);
745  return AVERROR(ENOMEM);
746  }
747  }
748 
749  s->cur_frame.tf.f = av_frame_alloc();
750  if (!s->cur_frame.tf.f) {
751  av_log(avctx, AV_LOG_ERROR,
752  "Failed to allocate current frame buffer.\n");
753  return AVERROR(ENOMEM);
754  }
755 
756  ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, avctx);
757  if (ret < 0)
758  return ret;
759 
760  av_opt_set_int(s->cbc->priv_data, "operating_point", s->operating_point, 0);
761 
762  if (avctx->extradata && avctx->extradata_size) {
764  &s->current_obu,
765  avctx);
766  if (ret < 0) {
767  av_log(avctx, AV_LOG_WARNING, "Failed to read extradata.\n");
768  return ret;
769  }
770 
771  seq = ((CodedBitstreamAV1Context *)(s->cbc->priv_data))->sequence_header;
772  if (!seq) {
773  av_log(avctx, AV_LOG_WARNING, "No sequence header available.\n");
774  goto end;
775  }
776 
777  ret = set_context_with_sequence(avctx, seq);
778  if (ret < 0) {
779  av_log(avctx, AV_LOG_WARNING, "Failed to set decoder context.\n");
780  goto end;
781  }
782 
783  end:
784  ff_cbs_fragment_reset(&s->current_obu);
785  }
786 
787  return ret;
788 }
789 
791 {
792  AV1DecContext *s = avctx->priv_data;
793  AV1RawFrameHeader *header= s->raw_frame_header;
794  AVFrame *frame;
795  int ret;
796 
798  if (ret < 0) {
799  av_log(avctx, AV_LOG_ERROR, "Failed to update context with frame header\n");
800  return ret;
801  }
802 
803  f->header_ref = av_buffer_ref(s->header_ref);
804  if (!f->header_ref)
805  return AVERROR(ENOMEM);
806 
807  f->raw_frame_header = s->raw_frame_header;
808 
809  if ((ret = ff_thread_get_buffer(avctx, &f->tf, AV_GET_BUFFER_FLAG_REF)) < 0)
810  goto fail;
811 
812  frame = f->tf.f;
813  frame->key_frame = header->frame_type == AV1_FRAME_KEY;
814 
815  switch (header->frame_type) {
816  case AV1_FRAME_KEY:
818  frame->pict_type = AV_PICTURE_TYPE_I;
819  break;
820  case AV1_FRAME_INTER:
821  frame->pict_type = AV_PICTURE_TYPE_P;
822  break;
823  case AV1_FRAME_SWITCH:
824  frame->pict_type = AV_PICTURE_TYPE_SP;
825  break;
826  }
827 
828  if (avctx->hwaccel) {
829  const AVHWAccel *hwaccel = avctx->hwaccel;
830  if (hwaccel->frame_priv_data_size) {
831  f->hwaccel_priv_buf =
833  if (!f->hwaccel_priv_buf) {
834  ret = AVERROR(ENOMEM);
835  goto fail;
836  }
837  f->hwaccel_picture_private = f->hwaccel_priv_buf->data;
838  }
839  }
840  return 0;
841 
842 fail:
843  av1_frame_unref(avctx, f);
844  return ret;
845 }
846 
848 {
849  AV1DecContext *s = avctx->priv_data;
850  const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
851  AVFilmGrainParams *fgp;
853 
854  if (!film_grain->apply_grain)
855  return 0;
856 
858  if (!fgp)
859  return AVERROR(ENOMEM);
860 
862  fgp->seed = film_grain->grain_seed;
863 
864  aom = &fgp->codec.aom;
866  aom->scaling_shift = film_grain->grain_scaling_minus_8 + 8;
867  aom->ar_coeff_lag = film_grain->ar_coeff_lag;
868  aom->ar_coeff_shift = film_grain->ar_coeff_shift_minus_6 + 6;
869  aom->grain_scale_shift = film_grain->grain_scale_shift;
870  aom->overlap_flag = film_grain->overlap_flag;
871  aom->limit_output_range = film_grain->clip_to_restricted_range;
872 
873  aom->num_y_points = film_grain->num_y_points;
874  for (int i = 0; i < film_grain->num_y_points; i++) {
875  aom->y_points[i][0] = film_grain->point_y_value[i];
876  aom->y_points[i][1] = film_grain->point_y_scaling[i];
877  }
878  aom->num_uv_points[0] = film_grain->num_cb_points;
879  for (int i = 0; i < film_grain->num_cb_points; i++) {
880  aom->uv_points[0][i][0] = film_grain->point_cb_value[i];
881  aom->uv_points[0][i][1] = film_grain->point_cb_scaling[i];
882  }
883  aom->num_uv_points[1] = film_grain->num_cr_points;
884  for (int i = 0; i < film_grain->num_cr_points; i++) {
885  aom->uv_points[1][i][0] = film_grain->point_cr_value[i];
886  aom->uv_points[1][i][1] = film_grain->point_cr_scaling[i];
887  }
888 
889  for (int i = 0; i < 24; i++) {
890  aom->ar_coeffs_y[i] = film_grain->ar_coeffs_y_plus_128[i] - 128;
891  }
892  for (int i = 0; i < 25; i++) {
893  aom->ar_coeffs_uv[0][i] = film_grain->ar_coeffs_cb_plus_128[i] - 128;
894  aom->ar_coeffs_uv[1][i] = film_grain->ar_coeffs_cr_plus_128[i] - 128;
895  }
896 
897  aom->uv_mult[0] = film_grain->cb_mult;
898  aom->uv_mult[1] = film_grain->cr_mult;
899  aom->uv_mult_luma[0] = film_grain->cb_luma_mult;
900  aom->uv_mult_luma[1] = film_grain->cr_luma_mult;
901  aom->uv_offset[0] = film_grain->cb_offset;
902  aom->uv_offset[1] = film_grain->cr_offset;
903 
904  return 0;
905 }
906 
908  const AVPacket *pkt, int *got_frame)
909 {
910  AV1DecContext *s = avctx->priv_data;
911  const AVFrame *srcframe = s->cur_frame.tf.f;
912  int ret;
913 
914  // TODO: all layers
915  if (s->operating_point_idc &&
916  av_log2(s->operating_point_idc >> 8) > s->cur_frame.spatial_id)
917  return 0;
918 
919  ret = av_frame_ref(frame, srcframe);
920  if (ret < 0)
921  return ret;
922 
924  ret = export_film_grain(avctx, frame);
925  if (ret < 0) {
927  return ret;
928  }
929  }
930 
931  frame->pts = pkt->pts;
932  frame->pkt_dts = pkt->dts;
933  frame->pkt_size = pkt->size;
934 
935  *got_frame = 1;
936 
937  return 0;
938 }
939 
941 {
942  AV1DecContext *s = avctx->priv_data;
943  const AV1RawFrameHeader *header = s->raw_frame_header;
944  int ret;
945 
946  for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
947  if (header->refresh_frame_flags & (1 << i)) {
948  if (s->ref[i].tf.f->buf[0])
949  av1_frame_unref(avctx, &s->ref[i]);
950  if ((ret = av1_frame_ref(avctx, &s->ref[i], &s->cur_frame)) < 0) {
951  av_log(avctx, AV_LOG_ERROR,
952  "Failed to update frame %d in reference list\n", i);
953  return ret;
954  }
955  }
956  }
957  return 0;
958 }
959 
961 {
962  AV1DecContext *s = avctx->priv_data;
963  int ret;
964 
965  if (s->cur_frame.tf.f->buf[0])
966  av1_frame_unref(avctx, &s->cur_frame);
967 
968  ret = av1_frame_alloc(avctx, &s->cur_frame);
969  if (ret < 0) {
970  av_log(avctx, AV_LOG_ERROR,
971  "Failed to allocate space for current frame.\n");
972  return ret;
973  }
974 
975  ret = init_tile_data(s);
976  if (ret < 0) {
977  av_log(avctx, AV_LOG_ERROR, "Failed to init tile data.\n");
978  return ret;
979  }
980 
985 
986  return ret;
987 }
988 
989 static int av1_decode_frame(AVCodecContext *avctx, void *frame,
990  int *got_frame, AVPacket *pkt)
991 {
992  AV1DecContext *s = avctx->priv_data;
993  AV1RawTileGroup *raw_tile_group = NULL;
994  int ret;
995 
996  ret = ff_cbs_read_packet(s->cbc, &s->current_obu, pkt);
997  if (ret < 0) {
998  av_log(avctx, AV_LOG_ERROR, "Failed to read packet.\n");
999  goto end;
1000  }
1001  av_log(avctx, AV_LOG_DEBUG, "Total obu for this frame:%d.\n",
1002  s->current_obu.nb_units);
1003 
1004  for (int i = 0; i < s->current_obu.nb_units; i++) {
1005  CodedBitstreamUnit *unit = &s->current_obu.units[i];
1006  AV1RawOBU *obu = unit->content;
1007  const AV1RawOBUHeader *header;
1008 
1009  if (!obu)
1010  continue;
1011 
1012  header = &obu->header;
1013  av_log(avctx, AV_LOG_DEBUG, "Obu idx:%d, obu type:%d.\n", i, unit->type);
1014 
1015  switch (unit->type) {
1017  av_buffer_unref(&s->seq_ref);
1018  s->seq_ref = av_buffer_ref(unit->content_ref);
1019  if (!s->seq_ref) {
1020  ret = AVERROR(ENOMEM);
1021  goto end;
1022  }
1023 
1024  s->raw_seq = &obu->obu.sequence_header;
1025 
1026  ret = set_context_with_sequence(avctx, s->raw_seq);
1027  if (ret < 0) {
1028  av_log(avctx, AV_LOG_ERROR, "Failed to set context.\n");
1029  s->raw_seq = NULL;
1030  goto end;
1031  }
1032 
1033  s->operating_point_idc = s->raw_seq->operating_point_idc[s->operating_point];
1034 
1035  if (s->pix_fmt == AV_PIX_FMT_NONE) {
1036  ret = get_pixel_format(avctx);
1037  if (ret < 0) {
1038  av_log(avctx, AV_LOG_ERROR,
1039  "Failed to get pixel format.\n");
1040  s->raw_seq = NULL;
1041  goto end;
1042  }
1043  }
1044 
1045  if (avctx->hwaccel && avctx->hwaccel->decode_params) {
1046  ret = avctx->hwaccel->decode_params(avctx, unit->type, unit->data,
1047  unit->data_size);
1048  if (ret < 0) {
1049  av_log(avctx, AV_LOG_ERROR, "HW accel decode params fail.\n");
1050  s->raw_seq = NULL;
1051  goto end;
1052  }
1053  }
1054  break;
1056  if (s->raw_frame_header)
1057  break;
1058  // fall-through
1059  case AV1_OBU_FRAME:
1060  case AV1_OBU_FRAME_HEADER:
1061  if (!s->raw_seq) {
1062  av_log(avctx, AV_LOG_ERROR, "Missing Sequence Header.\n");
1064  goto end;
1065  }
1066 
1067  av_buffer_unref(&s->header_ref);
1068  s->header_ref = av_buffer_ref(unit->content_ref);
1069  if (!s->header_ref) {
1070  ret = AVERROR(ENOMEM);
1071  goto end;
1072  }
1073 
1074  if (unit->type == AV1_OBU_FRAME)
1075  s->raw_frame_header = &obu->obu.frame.header;
1076  else
1077  s->raw_frame_header = &obu->obu.frame_header;
1078 
1079  if (s->raw_frame_header->show_existing_frame) {
1080  if (s->cur_frame.tf.f->buf[0])
1081  av1_frame_unref(avctx, &s->cur_frame);
1082 
1083  ret = av1_frame_ref(avctx, &s->cur_frame,
1084  &s->ref[s->raw_frame_header->frame_to_show_map_idx]);
1085  if (ret < 0) {
1086  av_log(avctx, AV_LOG_ERROR, "Failed to get reference frame.\n");
1087  goto end;
1088  }
1089 
1090  ret = update_reference_list(avctx);
1091  if (ret < 0) {
1092  av_log(avctx, AV_LOG_ERROR, "Failed to update reference list.\n");
1093  goto end;
1094  }
1095 
1096  ret = set_output_frame(avctx, frame, pkt, got_frame);
1097  if (ret < 0)
1098  av_log(avctx, AV_LOG_ERROR, "Set output frame error.\n");
1099 
1100  s->raw_frame_header = NULL;
1101 
1102  goto end;
1103  }
1104 
1105  ret = get_current_frame(avctx);
1106  if (ret < 0) {
1107  av_log(avctx, AV_LOG_ERROR, "Get current frame error\n");
1108  goto end;
1109  }
1110 
1111  s->cur_frame.spatial_id = header->spatial_id;
1112  s->cur_frame.temporal_id = header->temporal_id;
1113 
1114  if (avctx->hwaccel) {
1115  ret = avctx->hwaccel->start_frame(avctx, unit->data,
1116  unit->data_size);
1117  if (ret < 0) {
1118  av_log(avctx, AV_LOG_ERROR, "HW accel start frame fail.\n");
1119  goto end;
1120  }
1121  }
1122  if (unit->type != AV1_OBU_FRAME)
1123  break;
1124  // fall-through
1125  case AV1_OBU_TILE_GROUP:
1126  if (!s->raw_frame_header) {
1127  av_log(avctx, AV_LOG_ERROR, "Missing Frame Header.\n");
1129  goto end;
1130  }
1131 
1132  if (unit->type == AV1_OBU_FRAME)
1133  raw_tile_group = &obu->obu.frame.tile_group;
1134  else
1135  raw_tile_group = &obu->obu.tile_group;
1136 
1137  ret = get_tiles_info(avctx, raw_tile_group);
1138  if (ret < 0)
1139  goto end;
1140 
1141  if (avctx->hwaccel) {
1142  ret = avctx->hwaccel->decode_slice(avctx,
1143  raw_tile_group->tile_data.data,
1144  raw_tile_group->tile_data.data_size);
1145  if (ret < 0) {
1146  av_log(avctx, AV_LOG_ERROR,
1147  "HW accel decode slice fail.\n");
1148  goto end;
1149  }
1150  }
1151  break;
1152  case AV1_OBU_TILE_LIST:
1154  case AV1_OBU_PADDING:
1155  case AV1_OBU_METADATA:
1156  break;
1157  default:
1158  av_log(avctx, AV_LOG_DEBUG,
1159  "Unknown obu type: %d (%"SIZE_SPECIFIER" bits).\n",
1160  unit->type, unit->data_size);
1161  }
1162 
1163  if (raw_tile_group && (s->tile_num == raw_tile_group->tg_end + 1)) {
1164  if (avctx->hwaccel) {
1165  ret = avctx->hwaccel->end_frame(avctx);
1166  if (ret < 0) {
1167  av_log(avctx, AV_LOG_ERROR, "HW accel end frame fail.\n");
1168  goto end;
1169  }
1170  }
1171 
1172  ret = update_reference_list(avctx);
1173  if (ret < 0) {
1174  av_log(avctx, AV_LOG_ERROR, "Failed to update reference list.\n");
1175  goto end;
1176  }
1177 
1178  if (s->raw_frame_header->show_frame) {
1179  ret = set_output_frame(avctx, frame, pkt, got_frame);
1180  if (ret < 0) {
1181  av_log(avctx, AV_LOG_ERROR, "Set output frame error\n");
1182  goto end;
1183  }
1184  }
1185  raw_tile_group = NULL;
1186  s->raw_frame_header = NULL;
1187  }
1188  }
1189 
1190 end:
1191  ff_cbs_fragment_reset(&s->current_obu);
1192  if (ret < 0)
1193  s->raw_frame_header = NULL;
1194  return ret;
1195 }
1196 
1198 {
1199  AV1DecContext *s = avctx->priv_data;
1200 
1201  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++)
1202  av1_frame_unref(avctx, &s->ref[i]);
1203 
1204  av1_frame_unref(avctx, &s->cur_frame);
1205  s->operating_point_idc = 0;
1206  s->raw_frame_header = NULL;
1207  s->raw_seq = NULL;
1208 
1209  ff_cbs_flush(s->cbc);
1210 }
1211 
1212 #define OFFSET(x) offsetof(AV1DecContext, x)
1213 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1214 static const AVOption av1_options[] = {
1215  { "operating_point", "Select an operating point of the scalable bitstream",
1216  OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, AV1_MAX_OPERATING_POINTS - 1, VD },
1217  { NULL }
1218 };
1219 
1220 static const AVClass av1_class = {
1221  .class_name = "AV1 decoder",
1222  .item_name = av_default_item_name,
1223  .option = av1_options,
1224  .version = LIBAVUTIL_VERSION_INT,
1225 };
1226 
1228  .name = "av1",
1229  .long_name = NULL_IF_CONFIG_SMALL("Alliance for Open Media AV1"),
1230  .type = AVMEDIA_TYPE_VIDEO,
1231  .id = AV_CODEC_ID_AV1,
1232  .priv_data_size = sizeof(AV1DecContext),
1233  .init = av1_decode_init,
1234  .close = av1_decode_free,
1236  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_AVOID_PROBING,
1237  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
1242  .priv_class = &av1_class,
1243  .bsfs = "av1_frame_split",
1244  .hw_configs = (const AVCodecHWConfigInternal *const []) {
1245 #if CONFIG_AV1_DXVA2_HWACCEL
1246  HWACCEL_DXVA2(av1),
1247 #endif
1248 #if CONFIG_AV1_D3D11VA_HWACCEL
1249  HWACCEL_D3D11VA(av1),
1250 #endif
1251 #if CONFIG_AV1_D3D11VA2_HWACCEL
1252  HWACCEL_D3D11VA2(av1),
1253 #endif
1254 #if CONFIG_AV1_NVDEC_HWACCEL
1255  HWACCEL_NVDEC(av1),
1256 #endif
1257 #if CONFIG_AV1_VAAPI_HWACCEL
1258  HWACCEL_VAAPI(av1),
1259 #endif
1260  NULL
1261  },
1262 };
hwconfig.h
AV1RawTimingInfo::num_units_in_display_tick
uint32_t num_units_in_display_tick
Definition: cbs_av1.h:59
AV1RawTimingInfo::time_scale
uint32_t time_scale
Definition: cbs_av1.h:60
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1359
AVCodec
AVCodec.
Definition: codec.h:202
bit_depth
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:226
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:42
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:225
AV1_REFS_PER_FRAME
@ AV1_REFS_PER_FRAME
Definition: av1.h:84
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
FF_CODEC_CAP_SETS_PKT_DTS
#define FF_CODEC_CAP_SETS_PKT_DTS
Decoders marked with FF_CODEC_CAP_SETS_PKT_DTS want to set AVFrame.pkt_dts manually.
Definition: internal.h:57
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:731
AV1_OBU_REDUNDANT_FRAME_HEADER
@ AV1_OBU_REDUNDANT_FRAME_HEADER
Definition: av1.h:36
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:116
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
AV1RawFilmGrainParams::clip_to_restricted_range
uint8_t clip_to_restricted_range
Definition: cbs_av1.h:162
opt.h
AV1RawFilmGrainParams::grain_seed
uint16_t grain_seed
Definition: cbs_av1.h:135
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:960
AV1RawSequenceHeader
Definition: cbs_av1.h:73
ff_thread_ref_frame
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
Definition: utils.c:866
AV1_WARP_PARAM_REDUCE_BITS
@ AV1_WARP_PARAM_REDUCE_BITS
Definition: av1.h:117
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:317
GetByteContext
Definition: bytestream.h:33
sub
static float sub(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:31
av1_frame_alloc
static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f)
Definition: av1dec.c:790
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:120
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:106
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
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:960
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:109
AVFilmGrainParams::aom
AVFilmGrainAOMParams aom
Definition: film_grain_params.h:236
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
pixdesc.h
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:953
set_context_with_sequence
static int set_context_with_sequence(AVCodecContext *avctx, const AV1RawSequenceHeader *seq)
Definition: av1dec.c:652
w
uint8_t w
Definition: llviddspenc.c:38
HWACCEL_DXVA2
#define HWACCEL_DXVA2(codec)
Definition: hwconfig.h:67
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:597
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:157
internal.h
AV1Frame::raw_frame_header
AV1RawFrameHeader * raw_frame_header
Definition: av1dec.h:40
ff_cbs_close
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:127
AVOption
AVOption.
Definition: opt.h:247
HWACCEL_D3D11VA2
#define HWACCEL_D3D11VA2(codec)
Definition: hwconfig.h:69
b
#define b
Definition: input.c:40
AV1RawSequenceHeader::timing_info
AV1RawTimingInfo timing_info
Definition: cbs_av1.h:83
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:404
AV1RawTileGroup::tg_end
uint16_t tg_end
Definition: cbs_av1.h:298
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:219
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:73
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:290
get_relative_dist
static int get_relative_dist(const AV1RawSequenceHeader *seq, unsigned int a, unsigned int b)
Definition: av1dec.c:245
AV1RawOBU::header
AV1RawOBUHeader header
Definition: cbs_av1.h:392
AV1_MAX_OPERATING_POINTS
@ AV1_MAX_OPERATING_POINTS
Definition: av1.h:73
AVFilmGrainParams::seed
uint64_t seed
Seed to use for the synthesis process, if the codec allows for it.
Definition: film_grain_params.h:228
ff_cbs_fragment_free
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:171
AV1RawSequenceHeader::seq_profile
uint8_t seq_profile
Definition: cbs_av1.h:74
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:69
AV1RawColorConfig::subsampling_y
uint8_t subsampling_y
Definition: cbs_av1.h:53
AV1_GM_TRANS_ONLY_PREC_BITS
@ AV1_GM_TRANS_ONLY_PREC_BITS
Definition: av1.h:108
AV1_WARP_MODEL_ROTZOOM
@ AV1_WARP_MODEL_ROTZOOM
Definition: av1.h:115
round_two
static uint64_t round_two(uint64_t x, uint16_t n)
Definition: av1dec.c:128
AV1RawFrame::header
AV1RawFrameHeader header
Definition: cbs_av1.h:304
AV1RawFilmGrainParams::cr_mult
uint8_t cr_mult
Definition: cbs_av1.h:158
init
static int init
Definition: av_tx.c:47
AV1RawFilmGrainParams::chroma_scaling_from_luma
uint8_t chroma_scaling_from_luma
Definition: cbs_av1.h:141
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1710
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
AVHWAccel
Definition: avcodec.h:2039
AV1_FRAME_SWITCH
@ AV1_FRAME_SWITCH
Definition: av1.h:56
av1_options
static const AVOption av1_options[]
Definition: av1dec.c:1214
ff_cbs_flush
void ff_cbs_flush(CodedBitstreamContext *ctx)
Reset all internal state in a context.
Definition: cbs.c:121
av1_frame_ref
static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src)
Definition: av1dec.c:584
fail
#define fail()
Definition: checkasm.h:127
AV1_OBU_FRAME_HEADER
@ AV1_OBU_FRAME_HEADER
Definition: av1.h:32
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
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 AVCodec caps_internal and use ff_thread_get_buffer() to allocate frames. The frames must then be freed with ff_thread_release_buffer(). 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
inverse_recenter
static uint32_t inverse_recenter(int r, uint32_t v)
Definition: av1dec.c:59
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:80
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:135
AVRational::num
int num
Numerator.
Definition: rational.h:59
AV1_WARPEDMODEL_PREC_BITS
@ AV1_WARPEDMODEL_PREC_BITS
Definition: av1.h:111
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:97
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:407
AV1RawFilmGrainParams::cb_luma_mult
uint8_t cb_luma_mult
Definition: cbs_av1.h:156
AV1Frame
Definition: av1dec.h:33
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:946
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
AV1_WARP_MODEL_AFFINE
@ AV1_WARP_MODEL_AFFINE
Definition: av1.h:116
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
AV1RawFilmGrainParams::grain_scaling_minus_8
uint8_t grain_scaling_minus_8
Definition: cbs_av1.h:148
AV1_GM_ABS_TRANS_BITS
@ AV1_GM_ABS_TRANS_BITS
Definition: av1.h:109
set_output_frame
static int set_output_frame(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt, int *got_frame)
Definition: av1dec.c:907
global_motion_params
static void global_motion_params(AV1DecContext *s)
update gm type/params, since cbs already implemented part of this funcation, so we don't need to full...
Definition: av1dec.c:196
AV1_CSP_VERTICAL
@ AV1_CSP_VERTICAL
Definition: av1.h:133
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:485
AV1Frame::spatial_id
int spatial_id
Definition: av1dec.h:43
width
#define width
AV_PIX_FMT_DXVA2_VLD
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
Definition: pixfmt.h:127
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV1_DIV_LUT_BITS
@ AV1_DIV_LUT_BITS
Definition: av1.h:119
AV1_PRIMARY_REF_NONE
@ AV1_PRIMARY_REF_NONE
Definition: av1.h:86
AV1Frame::hwaccel_priv_buf
AVBufferRef * hwaccel_priv_buf
Definition: av1dec.h:36
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:361
AVCodecContext::ticks_per_frame
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:515
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:31
AV1Frame::film_grain
AV1RawFilmGrainParams film_grain
Definition: av1dec.h:51
av1_decode_free
static av_cold int av1_decode_free(AVCodecContext *avctx)
Definition: av1dec.c:631
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:296
init_tile_data
static int init_tile_data(AV1DecContext *s)
Definition: av1dec.c:367
AV1_GM_ALPHA_PREC_BITS
@ AV1_GM_ALPHA_PREC_BITS
Definition: av1.h:106
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
update_reference_list
static int update_reference_list(AVCodecContext *avctx)
Definition: av1dec.c:940
ff_av1_profiles
const AVProfile ff_av1_profiles[]
Definition: profiles.c:147
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demuxing_decoding.c:41
av1_frame_unref
static void av1_frame_unref(AVCodecContext *avctx, AV1Frame *f)
Definition: av1dec.c:570
AV1RawColorConfig::transfer_characteristics
uint8_t transfer_characteristics
Definition: cbs_av1.h:48
av1_decode_frame
static int av1_decode_frame(AVCodecContext *avctx, void *frame, int *got_frame, AVPacket *pkt)
Definition: av1dec.c:989
AVHWAccel::decode_params
int(* decode_params)(AVCodecContext *avctx, int type, const uint8_t *buf, uint32_t buf_size)
Callback for parameter data (SPS/PPS/VPS etc).
Definition: avcodec.h:2115
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:66
av1dec.h
get_tiles_info
static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_group)
Definition: av1dec.c:385
AV1_GM_ABS_ALPHA_BITS
@ AV1_GM_ABS_ALPHA_BITS
Definition: av1.h:105
f
#define f(width, name)
Definition: cbs_vp9.c:255
AV1_REF_FRAME_ALTREF
@ AV1_REF_FRAME_ALTREF
Definition: av1.h:68
AV1_MAX_SEGMENTS
@ AV1_MAX_SEGMENTS
Definition: av1.h:88
AV1_WARP_MODEL_TRANSLATION
@ AV1_WARP_MODEL_TRANSLATION
Definition: av1.h:114
FF_CODEC_PROPERTY_FILM_GRAIN
#define FF_CODEC_PROPERTY_FILM_GRAIN
Definition: avcodec.h:1825
load_grain_params
static void load_grain_params(AV1DecContext *s)
Definition: av1dec.c:347
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:385
AVFilmGrainAOMParams::uv_mult_luma
int uv_mult_luma[2]
Definition: film_grain_params.h:106
AV1RawOBU::obu
union AV1RawOBU::@25 obu
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AV1RawOBU
Definition: cbs_av1.h:391
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
av_clip_int16
#define av_clip_int16
Definition: common.h:111
HWACCEL_MAX
#define HWACCEL_MAX
AV1_REF_FRAME_LAST
@ AV1_REF_FRAME_LAST
Definition: av1.h:62
flush
static void flush(AVCodecContext *avctx)
Definition: aacdec_template.c:593
NULL
#define NULL
Definition: coverity.c:32
AV1Frame::gm_params
int32_t gm_params[AV1_NUM_REF_FRAMES][6]
Definition: av1dec.h:47
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:967
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:279
AV1RawFrameHeader
Definition: cbs_av1.h:165
AVCHROMA_LOC_LEFT
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:618
AV1_GM_TRANS_PREC_BITS
@ AV1_GM_TRANS_PREC_BITS
Definition: av1.h:110
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:620
AV1RawTileData::data_size
size_t data_size
Definition: cbs_av1.h:292
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
AVHWAccel::end_frame
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
Definition: avcodec.h:2140
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
AV1RawColorConfig::chroma_sample_position
uint8_t chroma_sample_position
Definition: cbs_av1.h:54
profiles.h
src
#define src
Definition: vp8dsp.c:255
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:85
AV1_OBU_TILE_GROUP
@ AV1_OBU_TILE_GROUP
Definition: av1.h:33
update_context_with_frame_header
static int update_context_with_frame_header(AVCodecContext *avctx, const AV1RawFrameHeader *header)
Definition: av1dec.c:701
abs
#define abs(x)
Definition: cuda_runtime.h:35
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:405
skip_mode_params
static void skip_mode_params(AV1DecContext *s)
Definition: av1dec.c:253
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
AV1_DIV_LUT_PREC_BITS
@ AV1_DIV_LUT_PREC_BITS
Definition: av1.h:120
AVCodecContext::level
int level
level
Definition: avcodec.h:1651
AV_PICTURE_TYPE_SP
@ AV_PICTURE_TYPE_SP
Switching Predicted.
Definition: avutil.h:279
av_opt_set_int
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:589
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
ff_thread_release_buffer
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: pthread_frame.c:1056
resolve_divisor
static int16_t resolve_divisor(uint32_t d, uint16_t *shift)
Resolve divisor process.
Definition: av1dec.c:144
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
AV1Frame::tf
ThreadFrame tf
Definition: av1dec.h:34
AV1RawFilmGrainParams::point_cr_value
uint8_t point_cr_value[10]
Definition: cbs_av1.h:146
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:374
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:117
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:325
decode_unsigned_subexp_with_ref
static uint32_t decode_unsigned_subexp_with_ref(uint32_t sub_exp, int mx, int r)
Definition: av1dec.c:69
AV1RawTimingInfo::num_ticks_per_picture_minus_1
uint32_t num_ticks_per_picture_minus_1
Definition: cbs_av1.h:63
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:409
size
int size
Definition: twinvq_data.h:10344
AV1DecContext
Definition: av1dec.h:63
AV1RawOBU::sequence_header
AV1RawSequenceHeader sequence_header
Definition: cbs_av1.h:397
AV1Frame::skip_mode_frame_idx
uint8_t skip_mode_frame_idx[2]
Definition: av1dec.h:49
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:411
AVFilmGrainParams
This structure describes how to handle film grain synthesis in video for specific codecs.
Definition: film_grain_params.h:216
AV1_GM_ABS_TRANS_ONLY_BITS
@ AV1_GM_ABS_TRANS_ONLY_BITS
Definition: av1.h:107
AV1_OBU_SEQUENCE_HEADER
@ AV1_OBU_SEQUENCE_HEADER
Definition: av1.h:30
AVCodecHWConfigInternal
Definition: hwconfig.h:29
header
static const uint8_t header[24]
Definition: sdr2.c:67
AV1_FRAME_INTRA_ONLY
@ AV1_FRAME_INTRA_ONLY
Definition: 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:372
AV1_FRAME_KEY
@ AV1_FRAME_KEY
Definition: av1.h:53
height
#define height
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
av_reallocp_array
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
Definition: mem.c:232
VD
#define VD
Definition: av1dec.c:1213
HWACCEL_D3D11VA
#define HWACCEL_D3D11VA(codec)
Definition: hwconfig.h:79
AV_PIX_FMT_D3D11
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition: pixfmt.h:303
AV1RawFilmGrainParams::grain_scale_shift
uint8_t grain_scale_shift
Definition: cbs_av1.h:154
HWACCEL_NVDEC
#define HWACCEL_NVDEC(codec)
Definition: hwconfig.h:71
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:119
AV1RawOBU::frame_header
AV1RawFrameHeader frame_header
Definition: cbs_av1.h:398
ff_cbs_read_extradata_from_codec
int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx)
Definition: cbs.c:280
av1_decode_flush
static void av1_decode_flush(AVCodecContext *avctx)
Definition: av1dec.c:1197
AV1_NUM_REF_FRAMES
@ AV1_NUM_REF_FRAMES
Definition: av1.h:83
export_film_grain
static int export_film_grain(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:847
AV1_OBU_PADDING
@ AV1_OBU_PADDING
Definition: av1.h:39
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:366
AVCodecContext::properties
unsigned properties
Properties of the stream that gets decoded.
Definition: avcodec.h:1822
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:484
AVHWAccel::decode_slice
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
Definition: avcodec.h:2129
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: internal.h:50
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:32
AV1Frame::hwaccel_picture_private
void * hwaccel_picture_private
Definition: av1dec.h:37
AV1RawTimingInfo::equal_picture_interval
uint8_t equal_picture_interval
Definition: cbs_av1.h:62
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:435
AV1RawSequenceHeader::max_frame_width_minus_1
uint16_t max_frame_width_minus_1
Definition: cbs_av1.h:98
AV1RawSequenceHeader::color_config
AV1RawColorConfig color_config
Definition: cbs_av1.h:128
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:209
AVCodecContext::chroma_sample_location
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:974
AV1RawTileGroup::tg_start
uint16_t tg_start
Definition: cbs_av1.h:297
AVCodecContext::height
int height
Definition: avcodec.h:556
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:593
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:580
AV1RawOBU::tile_group
AV1RawTileGroup tile_group
Definition: cbs_av1.h:400
AV1RawFilmGrainParams::update_grain
uint8_t update_grain
Definition: cbs_av1.h:136
avcodec.h
AV1RawTileGroup::tile_data
AV1RawTileData tile_data
Definition: cbs_av1.h:300
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:1220
CodedBitstreamUnit::content_ref
AVBufferRef * content_ref
If content is reference counted, a reference to the buffer containing content.
Definition: cbs.h:111
av_buffer_allocz
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:93
ret
ret
Definition: filter_design.txt:187
AV1RawColorConfig::subsampling_x
uint8_t subsampling_x
Definition: cbs_av1.h:52
ff_av1_decoder
const AVCodec ff_av1_decoder
Definition: av1dec.c:1227
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
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AV1_DIV_LUT_NUM
@ AV1_DIV_LUT_NUM
Definition: av1.h:121
AV1Frame::gm_invalid
uint8_t gm_invalid[AV1_NUM_REF_FRAMES]
Definition: av1dec.h:45
ff_cbs_init
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:76
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
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:86
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:408
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:193
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:101
AVCodecContext
main external API structure.
Definition: avcodec.h:383
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:164
AVFilmGrainAOMParams::ar_coeff_lag
int ar_coeff_lag
Specifies the auto-regression lag.
Definition: film_grain_params.h:74
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
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AVHWAccel::frame_priv_data_size
int frame_priv_data_size
Size of per-frame hardware accelerator private data.
Definition: avcodec.h:2149
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
AV1RawFilmGrainParams::ar_coeff_lag
uint8_t ar_coeff_lag
Definition: cbs_av1.h:149
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1525
AV1RawColorConfig::mono_chrome
uint8_t mono_chrome
Definition: cbs_av1.h:44
ff_thread_get_format
FF_DISABLE_DEPRECATION_WARNINGS enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
Definition: pthread_frame.c:1020
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
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
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:1984
profiles
static const AVProfile profiles[]
Definition: libfdk-aacenc.c:429
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
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:289
AV1RawSequenceHeader::order_hint_bits_minus_1
uint8_t order_hint_bits_minus_1
Definition: cbs_av1.h:122
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:71
AV1RawTileGroup
Definition: cbs_av1.h:295
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
AVHWAccel::start_frame
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
Definition: avcodec.h:2101
shift
static int shift(int a, int b)
Definition: sonic.c:83
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:275
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV1RawOBU::frame
AV1RawFrame frame
Definition: cbs_av1.h:399
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:70
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:86
AV1RawFilmGrainParams::point_cb_scaling
uint8_t point_cb_scaling[10]
Definition: cbs_av1.h:144
AV1RawFrame::tile_group
AV1RawTileGroup tile_group
Definition: cbs_av1.h:305
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:79
AV1Frame::temporal_id
int temporal_id
Definition: av1dec.h:42
diff
static av_always_inline int diff(const uint32_t a, const uint32_t b)
Definition: vf_palettegen.c:139
AV1RawColorConfig::twelve_bit
uint8_t twelve_bit
Definition: cbs_av1.h:43
get_pixel_format
static int get_pixel_format(AVCodecContext *avctx)
Definition: av1dec.c:430
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AVFilmGrainParams::codec
union AVFilmGrainParams::@294 codec
Additional fields may be added both here and in any structure included.
AVPacket
This structure stores compressed data.
Definition: packet.h:350
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:410
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
OFFSET
#define OFFSET(x)
Definition: av1dec.c:1212
HWACCEL_VAAPI
#define HWACCEL_VAAPI(codec)
Definition: hwconfig.h:73
AV1Frame::header_ref
AVBufferRef * header_ref
Definition: av1dec.h:39
d
d
Definition: ffmpeg_filter.c:153
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:556
TileGroupInfo
Definition: av1dec.h:56
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
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:28
AV1_WARP_MODEL_IDENTITY
@ AV1_WARP_MODEL_IDENTITY
Definition: av1.h:113
AV_CODEC_CAP_AVOID_PROBING
#define AV_CODEC_CAP_AVOID_PROBING
Decoder is not a preferred choice for probing.
Definition: codec.h:144
AV1_SEG_LVL_ALT_Q
@ AV1_SEG_LVL_ALT_Q
Definition: av1.h:91
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AV1_FRAME_INTER
@ AV1_FRAME_INTER
Definition: av1.h:54
AV1Frame::coded_lossless
uint8_t coded_lossless
Definition: av1dec.h:53
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:386
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
AV1Frame::gm_type
uint8_t gm_type[AV1_NUM_REF_FRAMES]
Definition: av1dec.h:46
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:220
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
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:753
AV_CODEC_EXPORT_DATA_FILM_GRAIN
#define AV_CODEC_EXPORT_DATA_FILM_GRAIN
Decoding only.
Definition: avcodec.h:356
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:2580
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:427
AV1_CSP_COLOCATED
@ AV1_CSP_COLOCATED
Definition: av1.h:134