FFmpeg  4.4.9
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  int primary_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  abs_bits = AV1_GM_ABS_ALPHA_BITS;
94  prec_bits = AV1_GM_ALPHA_PREC_BITS;
95 
96  /* setup_past_independence() sets PrevGmParams to default values. We can
97  * simply point to the current's frame gm_params as they will be initialized
98  * with defaults at this point.
99  */
100  if (s->raw_frame_header->primary_ref_frame == AV1_PRIMARY_REF_NONE)
101  prev_gm_param = s->cur_frame.gm_params[ref][idx];
102  else {
103  int prev_frame = s->raw_frame_header->ref_frame_idx[primary_frame];
104  prev_gm_param = s->ref[prev_frame].gm_params[ref][idx];
105  }
106 
107  if (idx < 2) {
109  abs_bits = AV1_GM_ABS_TRANS_ONLY_BITS -
110  !s->raw_frame_header->allow_high_precision_mv;
111  prec_bits = AV1_GM_TRANS_ONLY_PREC_BITS -
112  !s->raw_frame_header->allow_high_precision_mv;
113  } else {
114  abs_bits = AV1_GM_ABS_TRANS_BITS;
115  prec_bits = AV1_GM_TRANS_PREC_BITS;
116  }
117  }
118  round = (idx % 3) == 2 ? (1 << AV1_WARPEDMODEL_PREC_BITS) : 0;
119  prec_diff = AV1_WARPEDMODEL_PREC_BITS - prec_bits;
120  sub = (idx % 3) == 2 ? (1 << prec_bits) : 0;
121  mx = 1 << abs_bits;
122  r = (prev_gm_param >> prec_diff) - sub;
123 
124  s->cur_frame.gm_params[ref][idx] =
125  (decode_signed_subexp_with_ref(s->raw_frame_header->gm_params[ref][idx],
126  -mx, mx + 1, r) << prec_diff) + round;
127 }
128 
129 static uint64_t round_two(uint64_t x, uint16_t n)
130 {
131  if (n == 0)
132  return x;
133  return ((x + ((uint64_t)1 << (n - 1))) >> n);
134 }
135 
136 static int64_t round_two_signed(int64_t x, uint16_t n)
137 {
138  return ((x<0) ? -((int64_t)round_two(-x, n)) : (int64_t)round_two(x, n));
139 }
140 
141 /**
142  * Resolve divisor process.
143  * see spec 7.11.3.7
144  */
145 static int16_t resolve_divisor(uint32_t d, uint16_t *shift)
146 {
147  int32_t e, f;
148 
149  *shift = av_log2(d);
150  e = d - (1 << (*shift));
151  if (*shift > AV1_DIV_LUT_BITS)
153  else
154  f = e << (AV1_DIV_LUT_BITS - (*shift));
155 
157 
158  return div_lut[f];
159 }
160 
161 /**
162  * check if global motion params is valid.
163  * see spec 7.11.3.6
164  */
166 {
167  int16_t alpha, beta, gamma, delta, divf, divs;
168  int64_t v, w;
169  int32_t *param = &s->cur_frame.gm_params[idx][0];
170  if (param[2] <= 0)
171  return 0;
172 
173  alpha = av_clip_int16(param[2] - (1 << AV1_WARPEDMODEL_PREC_BITS));
174  beta = av_clip_int16(param[3]);
175  divf = resolve_divisor(abs(param[2]), &divs);
176  v = (int64_t)param[4] * (1 << AV1_WARPEDMODEL_PREC_BITS);
177  w = (int64_t)param[3] * param[4];
178  gamma = av_clip_int16((int)round_two_signed((v * divf), divs));
179  delta = av_clip_int16(param[5] - (int)round_two_signed((w * divf), divs) - (1 << AV1_WARPEDMODEL_PREC_BITS));
180 
185 
186  if ((4 * abs(alpha) + 7 * abs(beta)) >= (1 << AV1_WARPEDMODEL_PREC_BITS) ||
187  (4 * abs(gamma) + 4 * abs(delta)) >= (1 << AV1_WARPEDMODEL_PREC_BITS))
188  return 0;
189 
190  return 1;
191 }
192 
193 /**
194 * update gm type/params, since cbs already implemented part of this funcation,
195 * so we don't need to full implement spec.
196 */
198 {
199  const AV1RawFrameHeader *header = s->raw_frame_header;
200  int type, ref;
201 
203  s->cur_frame.gm_type[ref] = AV1_WARP_MODEL_IDENTITY;
204  for (int i = 0; i < 6; i++)
205  s->cur_frame.gm_params[ref][i] = (i % 3 == 2) ?
206  1 << AV1_WARPEDMODEL_PREC_BITS : 0;
207  }
208  if (header->frame_type == AV1_FRAME_KEY ||
209  header->frame_type == AV1_FRAME_INTRA_ONLY)
210  return;
211 
213  if (header->is_global[ref]) {
214  if (header->is_rot_zoom[ref]) {
216  } else {
217  type = header->is_translation[ref] ? AV1_WARP_MODEL_TRANSLATION
219  }
220  } else {
222  }
223  s->cur_frame.gm_type[ref] = type;
224 
225  if (type >= AV1_WARP_MODEL_ROTZOOM) {
226  read_global_param(s, type, ref, 2);
227  read_global_param(s, type, ref, 3);
228  if (type == AV1_WARP_MODEL_AFFINE) {
229  read_global_param(s, type, ref, 4);
230  read_global_param(s, type, ref, 5);
231  } else {
232  s->cur_frame.gm_params[ref][4] = -s->cur_frame.gm_params[ref][3];
233  s->cur_frame.gm_params[ref][5] = s->cur_frame.gm_params[ref][2];
234  }
235  }
237  read_global_param(s, type, ref, 0);
238  read_global_param(s, type, ref, 1);
239  }
240  if (type <= AV1_WARP_MODEL_AFFINE) {
241  s->cur_frame.gm_invalid[ref] = !get_shear_params_valid(s, ref);
242  }
243  }
244 }
245 
247  unsigned int a, unsigned int b)
248 {
249  unsigned int diff = a - b;
250  unsigned int m = 1 << seq->order_hint_bits_minus_1;
251  return (diff & (m - 1)) - (diff & m);
252 }
253 
255 {
256  const AV1RawFrameHeader *header = s->raw_frame_header;
257  const AV1RawSequenceHeader *seq = s->raw_seq;
258 
259  int forward_idx, backward_idx;
260  int forward_hint, backward_hint;
261  int second_forward_idx, second_forward_hint;
262  int ref_hint, dist, i;
263 
264  if (!header->skip_mode_present)
265  return;
266 
267  forward_idx = -1;
268  backward_idx = -1;
269  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
270  if (!s->ref[header->ref_frame_idx[i]].raw_frame_header)
271  return;
272  ref_hint = s->ref[header->ref_frame_idx[i]].raw_frame_header->order_hint;
273  dist = get_relative_dist(seq, ref_hint, header->order_hint);
274  if (dist < 0) {
275  if (forward_idx < 0 ||
276  get_relative_dist(seq, ref_hint, forward_hint) > 0) {
277  forward_idx = i;
278  forward_hint = ref_hint;
279  }
280  } else if (dist > 0) {
281  if (backward_idx < 0 ||
282  get_relative_dist(seq, ref_hint, backward_hint) < 0) {
283  backward_idx = i;
284  backward_hint = ref_hint;
285  }
286  }
287  }
288 
289  if (forward_idx < 0) {
290  return;
291  } else if (backward_idx >= 0) {
292  s->cur_frame.skip_mode_frame_idx[0] =
293  AV1_REF_FRAME_LAST + FFMIN(forward_idx, backward_idx);
294  s->cur_frame.skip_mode_frame_idx[1] =
295  AV1_REF_FRAME_LAST + FFMAX(forward_idx, backward_idx);
296  return;
297  }
298 
299  second_forward_idx = -1;
300  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
301  ref_hint = s->ref[header->ref_frame_idx[i]].raw_frame_header->order_hint;
302  if (get_relative_dist(seq, ref_hint, forward_hint) < 0) {
303  if (second_forward_idx < 0 ||
304  get_relative_dist(seq, ref_hint, second_forward_hint) > 0) {
305  second_forward_idx = i;
306  second_forward_hint = ref_hint;
307  }
308  }
309  }
310 
311  if (second_forward_idx < 0)
312  return;
313 
314  s->cur_frame.skip_mode_frame_idx[0] =
315  AV1_REF_FRAME_LAST + FFMIN(forward_idx, second_forward_idx);
316  s->cur_frame.skip_mode_frame_idx[1] =
317  AV1_REF_FRAME_LAST + FFMAX(forward_idx, second_forward_idx);
318 }
319 
321 {
322  const AV1RawFrameHeader *header = s->raw_frame_header;
323  int i;
324 
325  if (header->delta_q_y_dc || header->delta_q_u_ac ||
326  header->delta_q_u_dc || header->delta_q_v_ac ||
327  header->delta_q_v_dc) {
328  s->cur_frame.coded_lossless = 0;
329  return;
330  }
331 
332  s->cur_frame.coded_lossless = 1;
333  for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
334  int qindex;
335  if (header->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) {
336  qindex = (header->base_q_idx +
337  header->feature_value[i][AV1_SEG_LVL_ALT_Q]);
338  } else {
339  qindex = header->base_q_idx;
340  }
341  qindex = av_clip_uintp2(qindex, 8);
342 
343  if (qindex) {
344  s->cur_frame.coded_lossless = 0;
345  return;
346  }
347  }
348 }
349 
351 {
352  const AV1RawFrameHeader *header = s->raw_frame_header;
353  const AV1RawFilmGrainParams *film_grain = &header->film_grain, *src;
354  AV1RawFilmGrainParams *dst = &s->cur_frame.film_grain;
355 
356  if (!film_grain->apply_grain)
357  return;
358 
359  if (film_grain->update_grain) {
360  memcpy(dst, film_grain, sizeof(*dst));
361  return;
362  }
363 
364  src = &s->ref[film_grain->film_grain_params_ref_idx].film_grain;
365 
366  memcpy(dst, src, sizeof(*dst));
367  dst->grain_seed = film_grain->grain_seed;
368 }
369 
371 
372 {
373  int cur_tile_num =
374  s->raw_frame_header->tile_cols * s->raw_frame_header->tile_rows;
375  if (s->tile_num < cur_tile_num) {
376  int ret = av_reallocp_array(&s->tile_group_info, cur_tile_num,
377  sizeof(TileGroupInfo));
378  if (ret < 0) {
379  s->tile_num = 0;
380  return ret;
381  }
382  }
383  s->tile_num = cur_tile_num;
384 
385  return 0;
386 }
387 
388 static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_group)
389 {
390  AV1DecContext *s = avctx->priv_data;
391  GetByteContext gb;
392  uint16_t tile_num, tile_row, tile_col;
393  uint32_t size = 0, size_bytes = 0;
394 
395  bytestream2_init(&gb, tile_group->tile_data.data,
396  tile_group->tile_data.data_size);
397  s->tg_start = tile_group->tg_start;
398  s->tg_end = tile_group->tg_end;
399 
400  if (tile_group->tg_end >= s->raw_frame_header->tile_cols * s->raw_frame_header->tile_rows)
401  return AVERROR_INVALIDDATA;
402 
403  for (tile_num = tile_group->tg_start; tile_num <= tile_group->tg_end; tile_num++) {
404  tile_row = tile_num / s->raw_frame_header->tile_cols;
405  tile_col = tile_num % s->raw_frame_header->tile_cols;
406 
407  if (tile_num == tile_group->tg_end) {
408  s->tile_group_info[tile_num].tile_size = bytestream2_get_bytes_left(&gb);
409  s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
410  s->tile_group_info[tile_num].tile_row = tile_row;
411  s->tile_group_info[tile_num].tile_column = tile_col;
412  return 0;
413  }
414  size_bytes = s->raw_frame_header->tile_size_bytes_minus1 + 1;
415  if (bytestream2_get_bytes_left(&gb) < size_bytes)
416  return AVERROR_INVALIDDATA;
417  size = 0;
418  for (int i = 0; i < size_bytes; i++)
419  size |= bytestream2_get_byteu(&gb) << 8 * i;
420  if (bytestream2_get_bytes_left(&gb) <= size)
421  return AVERROR_INVALIDDATA;
422  size++;
423 
424  s->tile_group_info[tile_num].tile_size = size;
425  s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
426  s->tile_group_info[tile_num].tile_row = tile_row;
427  s->tile_group_info[tile_num].tile_column = tile_col;
428 
429  bytestream2_skipu(&gb, size);
430  }
431 
432  return 0;
433 
434 }
435 
437 {
438  AV1DecContext *s = avctx->priv_data;
439  const AV1RawSequenceHeader *seq = s->raw_seq;
441  int ret;
443 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
444  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
445  CONFIG_AV1_NVDEC_HWACCEL + \
446  CONFIG_AV1_VAAPI_HWACCEL)
447  enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
448 
449  if (seq->seq_profile == 2 && seq->color_config.high_bitdepth)
450  bit_depth = seq->color_config.twelve_bit ? 12 : 10;
451  else if (seq->seq_profile <= 2)
452  bit_depth = seq->color_config.high_bitdepth ? 10 : 8;
453  else {
454  av_log(avctx, AV_LOG_ERROR,
455  "Unknown AV1 profile %d.\n", seq->seq_profile);
456  return -1;
457  }
458 
459  if (!seq->color_config.mono_chrome) {
460  // 4:4:4 x:0 y:0, 4:2:2 x:1 y:0, 4:2:0 x:1 y:1
461  if (seq->color_config.subsampling_x == 0 &&
462  seq->color_config.subsampling_y == 0) {
463  if (bit_depth == 8)
465  else if (bit_depth == 10)
467  else if (bit_depth == 12)
469  else
470  av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
471  } else if (seq->color_config.subsampling_x == 1 &&
472  seq->color_config.subsampling_y == 0) {
473  if (bit_depth == 8)
475  else if (bit_depth == 10)
477  else if (bit_depth == 12)
479  else
480  av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
481  } else if (seq->color_config.subsampling_x == 1 &&
482  seq->color_config.subsampling_y == 1) {
483  if (bit_depth == 8)
485  else if (bit_depth == 10)
487  else if (bit_depth == 12)
489  else
490  av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
491  }
492  } else {
493  if (bit_depth == 8)
495  else if (bit_depth == 10)
497  else if (bit_depth == 12)
499  else
500  av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
501  }
502 
503  av_log(avctx, AV_LOG_DEBUG, "AV1 decode get format: %s.\n",
505 
506  if (pix_fmt == AV_PIX_FMT_NONE)
507  return -1;
508 
509  switch (pix_fmt) {
510  case AV_PIX_FMT_YUV420P:
511 #if CONFIG_AV1_DXVA2_HWACCEL
512  *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
513 #endif
514 #if CONFIG_AV1_D3D11VA_HWACCEL
515  *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
516  *fmtp++ = AV_PIX_FMT_D3D11;
517 #endif
518 #if CONFIG_AV1_NVDEC_HWACCEL
519  *fmtp++ = AV_PIX_FMT_CUDA;
520 #endif
521 #if CONFIG_AV1_VAAPI_HWACCEL
522  *fmtp++ = AV_PIX_FMT_VAAPI;
523 #endif
524  break;
526 #if CONFIG_AV1_DXVA2_HWACCEL
527  *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
528 #endif
529 #if CONFIG_AV1_D3D11VA_HWACCEL
530  *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
531  *fmtp++ = AV_PIX_FMT_D3D11;
532 #endif
533 #if CONFIG_AV1_NVDEC_HWACCEL
534  *fmtp++ = AV_PIX_FMT_CUDA;
535 #endif
536 #if CONFIG_AV1_VAAPI_HWACCEL
537  *fmtp++ = AV_PIX_FMT_VAAPI;
538 #endif
539  break;
540  case AV_PIX_FMT_GRAY8:
541 #if CONFIG_AV1_NVDEC_HWACCEL
542  *fmtp++ = AV_PIX_FMT_CUDA;
543 #endif
544  break;
545  case AV_PIX_FMT_GRAY10:
546 #if CONFIG_AV1_NVDEC_HWACCEL
547  *fmtp++ = AV_PIX_FMT_CUDA;
548 #endif
549  break;
550  }
551 
552  *fmtp++ = pix_fmt;
553  *fmtp = AV_PIX_FMT_NONE;
554 
555  ret = ff_thread_get_format(avctx, pix_fmts);
556  if (ret < 0)
557  return ret;
558 
559  /**
560  * check if the HW accel is inited correctly. If not, return un-implemented.
561  * Since now the av1 decoder doesn't support native decode, if it will be
562  * implemented in the future, need remove this check.
563  */
564  if (!avctx->hwaccel) {
565  av_log(avctx, AV_LOG_ERROR, "Your platform doesn't suppport"
566  " hardware accelerated AV1 decoding.\n");
567  return AVERROR(ENOSYS);
568  }
569 
570  s->pix_fmt = pix_fmt;
571  avctx->pix_fmt = ret;
572 
573  return 0;
574 }
575 
577 {
578  ff_thread_release_buffer(avctx, &f->tf);
579  av_buffer_unref(&f->hwaccel_priv_buf);
580  f->hwaccel_picture_private = NULL;
581  av_buffer_unref(&f->header_ref);
582  f->raw_frame_header = NULL;
583  f->spatial_id = f->temporal_id = 0;
584  memset(f->skip_mode_frame_idx, 0,
585  2 * sizeof(uint8_t));
586  memset(&f->film_grain, 0, sizeof(f->film_grain));
587  f->coded_lossless = 0;
588 }
589 
590 static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src)
591 {
592  int ret;
593 
594  ret = ff_thread_ref_frame(&dst->tf, &src->tf);
595  if (ret < 0)
596  return ret;
597 
598  dst->header_ref = av_buffer_ref(src->header_ref);
599  if (!dst->header_ref)
600  goto fail;
601 
602  dst->raw_frame_header = src->raw_frame_header;
603 
604  if (src->hwaccel_picture_private) {
605  dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);
606  if (!dst->hwaccel_priv_buf)
607  goto fail;
609  }
610 
611  dst->spatial_id = src->spatial_id;
612  dst->temporal_id = src->temporal_id;
613  memcpy(dst->gm_invalid,
614  src->gm_invalid,
615  AV1_NUM_REF_FRAMES * sizeof(uint8_t));
616  memcpy(dst->gm_type,
617  src->gm_type,
618  AV1_NUM_REF_FRAMES * sizeof(uint8_t));
619  memcpy(dst->gm_params,
620  src->gm_params,
621  AV1_NUM_REF_FRAMES * 6 * sizeof(int32_t));
622  memcpy(dst->skip_mode_frame_idx,
623  src->skip_mode_frame_idx,
624  2 * sizeof(uint8_t));
625  memcpy(&dst->film_grain,
626  &src->film_grain,
627  sizeof(dst->film_grain));
628  dst->coded_lossless = src->coded_lossless;
629 
630  return 0;
631 
632 fail:
633  av1_frame_unref(avctx, dst);
634  return AVERROR(ENOMEM);
635 }
636 
638 {
639  AV1DecContext *s = avctx->priv_data;
640 
641  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) {
642  av1_frame_unref(avctx, &s->ref[i]);
643  av_frame_free(&s->ref[i].tf.f);
644  }
645  av1_frame_unref(avctx, &s->cur_frame);
646  av_frame_free(&s->cur_frame.tf.f);
647 
648  av_buffer_unref(&s->seq_ref);
649  av_buffer_unref(&s->header_ref);
650  av_freep(&s->tile_group_info);
651 
652  ff_cbs_fragment_free(&s->current_obu);
653  ff_cbs_close(&s->cbc);
654 
655  return 0;
656 }
657 
659  const AV1RawSequenceHeader *seq)
660 {
661  int width = seq->max_frame_width_minus_1 + 1;
662  int height = seq->max_frame_height_minus_1 + 1;
663 
664  avctx->profile = seq->seq_profile;
665  avctx->level = seq->seq_level_idx[0];
666 
667  avctx->color_range =
672 
673  switch (seq->color_config.chroma_sample_position) {
674  case AV1_CSP_VERTICAL:
676  break;
677  case AV1_CSP_COLOCATED:
679  break;
680  }
681 
682  if (avctx->width != width || avctx->height != height) {
683  int ret = ff_set_dimensions(avctx, width, height);
684  if (ret < 0)
685  return ret;
686  }
687  avctx->sample_aspect_ratio = (AVRational) { 1, 1 };
688 
690  seq->timing_info.time_scale) {
691  av_reduce(&avctx->framerate.den, &avctx->framerate.num,
693  seq->timing_info.time_scale,
694  INT_MAX);
697  }
698 
699  return 0;
700 }
701 
703  const AV1RawFrameHeader *header)
704 {
705  AVRational aspect_ratio;
706  int width = header->frame_width_minus_1 + 1;
707  int height = header->frame_height_minus_1 + 1;
708  int r_width = header->render_width_minus_1 + 1;
709  int r_height = header->render_height_minus_1 + 1;
710  int ret;
711 
712  if (avctx->width != width || avctx->height != height) {
713  ret = ff_set_dimensions(avctx, width, height);
714  if (ret < 0)
715  return ret;
716  }
717 
718  av_reduce(&aspect_ratio.num, &aspect_ratio.den,
719  (int64_t)height * r_width,
720  (int64_t)width * r_height,
721  INT_MAX);
722 
723  if (av_cmp_q(avctx->sample_aspect_ratio, aspect_ratio)) {
724  ret = ff_set_sar(avctx, aspect_ratio);
725  if (ret < 0)
726  return ret;
727  }
728 
729  return 0;
730 }
731 
733 {
734  AV1DecContext *s = avctx->priv_data;
736  int ret;
737 
738  s->avctx = avctx;
739  s->pix_fmt = AV_PIX_FMT_NONE;
740 
741  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) {
742  s->ref[i].tf.f = av_frame_alloc();
743  if (!s->ref[i].tf.f) {
744  av_log(avctx, AV_LOG_ERROR,
745  "Failed to allocate reference frame buffer %d.\n", i);
746  return AVERROR(ENOMEM);
747  }
748  }
749 
750  s->cur_frame.tf.f = av_frame_alloc();
751  if (!s->cur_frame.tf.f) {
752  av_log(avctx, AV_LOG_ERROR,
753  "Failed to allocate current frame buffer.\n");
754  return AVERROR(ENOMEM);
755  }
756 
757  ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, avctx);
758  if (ret < 0)
759  return ret;
760 
761  av_opt_set_int(s->cbc->priv_data, "operating_point", s->operating_point, 0);
762 
763  if (avctx->extradata && avctx->extradata_size) {
765  &s->current_obu,
766  avctx);
767  if (ret < 0) {
768  av_log(avctx, AV_LOG_WARNING, "Failed to read extradata.\n");
769  return ret;
770  }
771 
772  seq = ((CodedBitstreamAV1Context *)(s->cbc->priv_data))->sequence_header;
773  if (!seq) {
774  av_log(avctx, AV_LOG_WARNING, "No sequence header available.\n");
775  goto end;
776  }
777 
778  ret = set_context_with_sequence(avctx, seq);
779  if (ret < 0) {
780  av_log(avctx, AV_LOG_WARNING, "Failed to set decoder context.\n");
781  goto end;
782  }
783 
784  end:
785  ff_cbs_fragment_reset(&s->current_obu);
786  }
787 
788  return ret;
789 }
790 
792 {
793  AV1DecContext *s = avctx->priv_data;
794  AV1RawFrameHeader *header= s->raw_frame_header;
795  AVFrame *frame;
796  int ret;
797 
799  if (ret < 0) {
800  av_log(avctx, AV_LOG_ERROR, "Failed to update context with frame header\n");
801  return ret;
802  }
803 
804  f->header_ref = av_buffer_ref(s->header_ref);
805  if (!f->header_ref)
806  return AVERROR(ENOMEM);
807 
808  f->raw_frame_header = s->raw_frame_header;
809 
810  if ((ret = ff_thread_get_buffer(avctx, &f->tf, AV_GET_BUFFER_FLAG_REF)) < 0)
811  goto fail;
812 
813  frame = f->tf.f;
814  frame->key_frame = header->frame_type == AV1_FRAME_KEY;
815 
816  switch (header->frame_type) {
817  case AV1_FRAME_KEY:
820  break;
821  case AV1_FRAME_INTER:
823  break;
824  case AV1_FRAME_SWITCH:
826  break;
827  }
828 
829  if (avctx->hwaccel) {
830  const AVHWAccel *hwaccel = avctx->hwaccel;
831  if (hwaccel->frame_priv_data_size) {
832  f->hwaccel_priv_buf =
834  if (!f->hwaccel_priv_buf) {
835  ret = AVERROR(ENOMEM);
836  goto fail;
837  }
838  f->hwaccel_picture_private = f->hwaccel_priv_buf->data;
839  }
840  }
841  return 0;
842 
843 fail:
844  av1_frame_unref(avctx, f);
845  return ret;
846 }
847 
849 {
850  AV1DecContext *s = avctx->priv_data;
851  const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
852  AVFilmGrainParams *fgp;
854 
855  if (!film_grain->apply_grain)
856  return 0;
857 
859  if (!fgp)
860  return AVERROR(ENOMEM);
861 
863  fgp->seed = film_grain->grain_seed;
864 
865  aom = &fgp->codec.aom;
867  aom->scaling_shift = film_grain->grain_scaling_minus_8 + 8;
868  aom->ar_coeff_lag = film_grain->ar_coeff_lag;
869  aom->ar_coeff_shift = film_grain->ar_coeff_shift_minus_6 + 6;
870  aom->grain_scale_shift = film_grain->grain_scale_shift;
871  aom->overlap_flag = film_grain->overlap_flag;
872  aom->limit_output_range = film_grain->clip_to_restricted_range;
873 
874  aom->num_y_points = film_grain->num_y_points;
875  for (int i = 0; i < film_grain->num_y_points; i++) {
876  aom->y_points[i][0] = film_grain->point_y_value[i];
877  aom->y_points[i][1] = film_grain->point_y_scaling[i];
878  }
879  aom->num_uv_points[0] = film_grain->num_cb_points;
880  for (int i = 0; i < film_grain->num_cb_points; i++) {
881  aom->uv_points[0][i][0] = film_grain->point_cb_value[i];
882  aom->uv_points[0][i][1] = film_grain->point_cb_scaling[i];
883  }
884  aom->num_uv_points[1] = film_grain->num_cr_points;
885  for (int i = 0; i < film_grain->num_cr_points; i++) {
886  aom->uv_points[1][i][0] = film_grain->point_cr_value[i];
887  aom->uv_points[1][i][1] = film_grain->point_cr_scaling[i];
888  }
889 
890  for (int i = 0; i < 24; i++) {
891  aom->ar_coeffs_y[i] = film_grain->ar_coeffs_y_plus_128[i] - 128;
892  }
893  for (int i = 0; i < 25; i++) {
894  aom->ar_coeffs_uv[0][i] = film_grain->ar_coeffs_cb_plus_128[i] - 128;
895  aom->ar_coeffs_uv[1][i] = film_grain->ar_coeffs_cr_plus_128[i] - 128;
896  }
897 
898  aom->uv_mult[0] = film_grain->cb_mult - 128;
899  aom->uv_mult[1] = film_grain->cr_mult - 128;
900  aom->uv_mult_luma[0] = film_grain->cb_luma_mult - 128;
901  aom->uv_mult_luma[1] = film_grain->cr_luma_mult - 128;
902  aom->uv_offset[0] = film_grain->cb_offset - 256;
903  aom->uv_offset[1] = film_grain->cr_offset - 256;
904 
905  return 0;
906 }
907 
909  const AVPacket *pkt, int *got_frame)
910 {
911  AV1DecContext *s = avctx->priv_data;
912  const AVFrame *srcframe = s->cur_frame.tf.f;
913  int ret;
914 
915  // TODO: all layers
916  if (s->operating_point_idc &&
917  av_log2(s->operating_point_idc >> 8) > s->cur_frame.spatial_id)
918  return 0;
919 
920  ret = av_frame_ref(frame, srcframe);
921  if (ret < 0)
922  return ret;
923 
925  ret = export_film_grain(avctx, frame);
926  if (ret < 0) {
928  return ret;
929  }
930  }
931 
932  frame->pts = pkt->pts;
933  frame->pkt_dts = pkt->dts;
934  frame->pkt_size = pkt->size;
935 
936  *got_frame = 1;
937 
938  return 0;
939 }
940 
942 {
943  AV1DecContext *s = avctx->priv_data;
944  const AV1RawFrameHeader *header = s->raw_frame_header;
945  int ret;
946 
947  for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
948  if (header->refresh_frame_flags & (1 << i)) {
949  if (s->ref[i].tf.f->buf[0])
950  av1_frame_unref(avctx, &s->ref[i]);
951  if ((ret = av1_frame_ref(avctx, &s->ref[i], &s->cur_frame)) < 0) {
952  av_log(avctx, AV_LOG_ERROR,
953  "Failed to update frame %d in reference list\n", i);
954  return ret;
955  }
956  }
957  }
958  return 0;
959 }
960 
962 {
963  AV1DecContext *s = avctx->priv_data;
964  int ret;
965 
966  if (s->cur_frame.tf.f->buf[0])
967  av1_frame_unref(avctx, &s->cur_frame);
968 
969  ret = av1_frame_alloc(avctx, &s->cur_frame);
970  if (ret < 0) {
971  av_log(avctx, AV_LOG_ERROR,
972  "Failed to allocate space for current frame.\n");
973  return ret;
974  }
975 
976  ret = init_tile_data(s);
977  if (ret < 0) {
978  av_log(avctx, AV_LOG_ERROR, "Failed to init tile data.\n");
979  return ret;
980  }
981 
986 
987  return ret;
988 }
989 
990 static int av1_decode_frame(AVCodecContext *avctx, void *frame,
991  int *got_frame, AVPacket *pkt)
992 {
993  AV1DecContext *s = avctx->priv_data;
994  AV1RawTileGroup *raw_tile_group = NULL;
995  int ret;
996 
997  ret = ff_cbs_read_packet(s->cbc, &s->current_obu, pkt);
998  if (ret < 0) {
999  av_log(avctx, AV_LOG_ERROR, "Failed to read packet.\n");
1000  goto end;
1001  }
1002  av_log(avctx, AV_LOG_DEBUG, "Total obu for this frame:%d.\n",
1003  s->current_obu.nb_units);
1004 
1005  for (int i = 0; i < s->current_obu.nb_units; i++) {
1006  CodedBitstreamUnit *unit = &s->current_obu.units[i];
1007  AV1RawOBU *obu = unit->content;
1008  const AV1RawOBUHeader *header;
1009 
1010  if (!obu)
1011  continue;
1012 
1013  header = &obu->header;
1014  av_log(avctx, AV_LOG_DEBUG, "Obu idx:%d, obu type:%d.\n", i, unit->type);
1015 
1016  switch (unit->type) {
1018  av_buffer_unref(&s->seq_ref);
1019  s->seq_ref = av_buffer_ref(unit->content_ref);
1020  if (!s->seq_ref) {
1021  ret = AVERROR(ENOMEM);
1022  goto end;
1023  }
1024 
1025  s->raw_seq = &obu->obu.sequence_header;
1026  s->raw_frame_header = NULL;
1027  raw_tile_group = NULL;
1028 
1029  ret = set_context_with_sequence(avctx, s->raw_seq);
1030  if (ret < 0) {
1031  av_log(avctx, AV_LOG_ERROR, "Failed to set context.\n");
1032  s->raw_seq = NULL;
1033  goto end;
1034  }
1035 
1036  s->operating_point_idc = s->raw_seq->operating_point_idc[s->operating_point];
1037 
1038  if (s->pix_fmt == AV_PIX_FMT_NONE) {
1039  ret = get_pixel_format(avctx);
1040  if (ret < 0) {
1041  av_log(avctx, AV_LOG_ERROR,
1042  "Failed to get pixel format.\n");
1043  s->raw_seq = NULL;
1044  goto end;
1045  }
1046  }
1047 
1048  if (avctx->hwaccel && avctx->hwaccel->decode_params) {
1049  ret = avctx->hwaccel->decode_params(avctx, unit->type, unit->data,
1050  unit->data_size);
1051  if (ret < 0) {
1052  av_log(avctx, AV_LOG_ERROR, "HW accel decode params fail.\n");
1053  s->raw_seq = NULL;
1054  goto end;
1055  }
1056  }
1057  break;
1059  if (s->raw_frame_header)
1060  break;
1061  // fall-through
1062  case AV1_OBU_FRAME:
1063  case AV1_OBU_FRAME_HEADER:
1064  if (!s->raw_seq) {
1065  av_log(avctx, AV_LOG_ERROR, "Missing Sequence Header.\n");
1066  ret = AVERROR_INVALIDDATA;
1067  goto end;
1068  }
1069 
1070  av_buffer_unref(&s->header_ref);
1071  s->header_ref = av_buffer_ref(unit->content_ref);
1072  if (!s->header_ref) {
1073  ret = AVERROR(ENOMEM);
1074  goto end;
1075  }
1076 
1077  raw_tile_group = NULL;
1078 
1079  if (unit->type == AV1_OBU_FRAME)
1080  s->raw_frame_header = &obu->obu.frame.header;
1081  else
1082  s->raw_frame_header = &obu->obu.frame_header;
1083 
1084  if (s->raw_frame_header->show_existing_frame) {
1085  if (s->cur_frame.tf.f->buf[0])
1086  av1_frame_unref(avctx, &s->cur_frame);
1087 
1088  ret = av1_frame_ref(avctx, &s->cur_frame,
1089  &s->ref[s->raw_frame_header->frame_to_show_map_idx]);
1090  if (ret < 0) {
1091  av_log(avctx, AV_LOG_ERROR, "Failed to get reference frame.\n");
1092  goto end;
1093  }
1094 
1095  ret = update_reference_list(avctx);
1096  if (ret < 0) {
1097  av_log(avctx, AV_LOG_ERROR, "Failed to update reference list.\n");
1098  goto end;
1099  }
1100 
1101  ret = set_output_frame(avctx, frame, pkt, got_frame);
1102  if (ret < 0)
1103  av_log(avctx, AV_LOG_ERROR, "Set output frame error.\n");
1104 
1105  s->raw_frame_header = NULL;
1106 
1107  goto end;
1108  }
1109 
1110  ret = get_current_frame(avctx);
1111  if (ret < 0) {
1112  av_log(avctx, AV_LOG_ERROR, "Get current frame error\n");
1113  goto end;
1114  }
1115 
1116  s->cur_frame.spatial_id = header->spatial_id;
1117  s->cur_frame.temporal_id = header->temporal_id;
1118 
1119  if (avctx->hwaccel) {
1120  ret = avctx->hwaccel->start_frame(avctx, unit->data,
1121  unit->data_size);
1122  if (ret < 0) {
1123  av_log(avctx, AV_LOG_ERROR, "HW accel start frame fail.\n");
1124  goto end;
1125  }
1126  }
1127  if (unit->type != AV1_OBU_FRAME)
1128  break;
1129  // fall-through
1130  case AV1_OBU_TILE_GROUP:
1131  if (!s->raw_frame_header) {
1132  av_log(avctx, AV_LOG_ERROR, "Missing Frame Header.\n");
1133  ret = AVERROR_INVALIDDATA;
1134  goto end;
1135  }
1136 
1137  if (unit->type == AV1_OBU_FRAME)
1138  raw_tile_group = &obu->obu.frame.tile_group;
1139  else
1140  raw_tile_group = &obu->obu.tile_group;
1141 
1142  ret = get_tiles_info(avctx, raw_tile_group);
1143  if (ret < 0)
1144  goto end;
1145 
1146  if (avctx->hwaccel) {
1147  ret = avctx->hwaccel->decode_slice(avctx,
1148  raw_tile_group->tile_data.data,
1149  raw_tile_group->tile_data.data_size);
1150  if (ret < 0) {
1151  av_log(avctx, AV_LOG_ERROR,
1152  "HW accel decode slice fail.\n");
1153  goto end;
1154  }
1155  }
1156  break;
1158  s->raw_frame_header = NULL;
1159  raw_tile_group = NULL;
1160  // fall-through
1161  case AV1_OBU_TILE_LIST:
1162  case AV1_OBU_PADDING:
1163  case AV1_OBU_METADATA:
1164  break;
1165  default:
1166  av_log(avctx, AV_LOG_DEBUG,
1167  "Unknown obu type: %d (%"SIZE_SPECIFIER" bits).\n",
1168  unit->type, unit->data_size);
1169  }
1170 
1171  if (raw_tile_group && (s->tile_num == raw_tile_group->tg_end + 1)) {
1172  if (avctx->hwaccel) {
1173  ret = avctx->hwaccel->end_frame(avctx);
1174  if (ret < 0) {
1175  av_log(avctx, AV_LOG_ERROR, "HW accel end frame fail.\n");
1176  goto end;
1177  }
1178  }
1179 
1180  ret = update_reference_list(avctx);
1181  if (ret < 0) {
1182  av_log(avctx, AV_LOG_ERROR, "Failed to update reference list.\n");
1183  goto end;
1184  }
1185 
1186  if (s->raw_frame_header->show_frame) {
1187  ret = set_output_frame(avctx, frame, pkt, got_frame);
1188  if (ret < 0) {
1189  av_log(avctx, AV_LOG_ERROR, "Set output frame error\n");
1190  goto end;
1191  }
1192  }
1193  raw_tile_group = NULL;
1194  s->raw_frame_header = NULL;
1195  }
1196  }
1197 
1198 end:
1199  ff_cbs_fragment_reset(&s->current_obu);
1200  if (ret < 0)
1201  s->raw_frame_header = NULL;
1202  return ret;
1203 }
1204 
1206 {
1207  AV1DecContext *s = avctx->priv_data;
1208 
1209  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++)
1210  av1_frame_unref(avctx, &s->ref[i]);
1211 
1212  av1_frame_unref(avctx, &s->cur_frame);
1213  s->operating_point_idc = 0;
1214  s->raw_frame_header = NULL;
1215  s->raw_seq = NULL;
1216 
1217  ff_cbs_flush(s->cbc);
1218 }
1219 
1220 #define OFFSET(x) offsetof(AV1DecContext, x)
1221 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1222 static const AVOption av1_options[] = {
1223  { "operating_point", "Select an operating point of the scalable bitstream",
1224  OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, AV1_MAX_OPERATING_POINTS - 1, VD },
1225  { NULL }
1226 };
1227 
1228 static const AVClass av1_class = {
1229  .class_name = "AV1 decoder",
1230  .item_name = av_default_item_name,
1231  .option = av1_options,
1232  .version = LIBAVUTIL_VERSION_INT,
1233 };
1234 
1236  .name = "av1",
1237  .long_name = NULL_IF_CONFIG_SMALL("Alliance for Open Media AV1"),
1238  .type = AVMEDIA_TYPE_VIDEO,
1239  .id = AV_CODEC_ID_AV1,
1240  .priv_data_size = sizeof(AV1DecContext),
1241  .init = av1_decode_init,
1242  .close = av1_decode_free,
1244  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_AVOID_PROBING,
1245  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
1250  .priv_class = &av1_class,
1251  .hw_configs = (const AVCodecHWConfigInternal *const []) {
1252 #if CONFIG_AV1_DXVA2_HWACCEL
1253  HWACCEL_DXVA2(av1),
1254 #endif
1255 #if CONFIG_AV1_D3D11VA_HWACCEL
1256  HWACCEL_D3D11VA(av1),
1257 #endif
1258 #if CONFIG_AV1_D3D11VA2_HWACCEL
1259  HWACCEL_D3D11VA2(av1),
1260 #endif
1261 #if CONFIG_AV1_NVDEC_HWACCEL
1262  HWACCEL_NVDEC(av1),
1263 #endif
1264 #if CONFIG_AV1_VAAPI_HWACCEL
1265  HWACCEL_VAAPI(av1),
1266 #endif
1267  NULL
1268  },
1269 };
static void flush(AVCodecContext *avctx)
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:254
#define av_cold
Definition: attributes.h:88
uint8_t
int32_t
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:174
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:192
int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx)
Read the extradata bitstream found in a codec context into a fragment, then split into units and deco...
Definition: cbs.c:279
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:126
void ff_cbs_flush(CodedBitstreamContext *ctx)
Reset all internal state in a context.
Definition: cbs.c:120
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:156
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:288
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:75
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:170
static int FUNC() sequence_header(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawSequenceHeader *current)
#define s(width, name)
Definition: cbs_vp9.c:257
#define f(width, name)
Definition: cbs_vp9.c:255
#define fail()
Definition: checkasm.h:133
#define FFMIN(a, b)
Definition: common.h:105
#define av_clip_int16
Definition: common.h:137
#define FFMAX(a, b)
Definition: common.h:103
#define av_clip_uintp2
Definition: common.h:146
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
#define abs(x)
Definition: cuda_runtime.h:35
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
static enum AVPixelFormat pix_fmt
static AVFrame * frame
static float sub(float src0, float src1)
AVFilmGrainParams * av_film_grain_params_create_side_data(AVFrame *frame)
Allocate a complete AVFilmGrainParams and add it to the frame.
@ AV_FILM_GRAIN_PARAMS_AV1
The union is valid when interpreted as AVFilmGrainAOMParams (codec.aom)
@ AV_OPT_TYPE_INT
Definition: opt.h:225
#define AV_CODEC_CAP_AVOID_PROBING
Decoder is not a preferred choice for probing.
Definition: codec.h:139
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:514
#define AV_CODEC_EXPORT_DATA_FILM_GRAIN
Decoding only.
Definition: avcodec.h:417
@ AV_CODEC_ID_AV1
Definition: codec_id.h:279
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:125
AVBufferRef * av_buffer_allocz(buffer_size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:83
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:553
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:443
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
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
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
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:206
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
@ AV_PICTURE_TYPE_SP
Switching Predicted.
Definition: avutil.h:279
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:596
#define HWACCEL_DXVA2(codec)
Definition: hwconfig.h:67
#define HWACCEL_NVDEC(codec)
Definition: hwconfig.h:71
#define HWACCEL_VAAPI(codec)
Definition: hwconfig.h:73
#define HWACCEL_D3D11VA(codec)
Definition: hwconfig.h:79
#define HWACCEL_D3D11VA2(codec)
Definition: hwconfig.h:69
cl_device_type type
static const int16_t alpha[]
Definition: ilbcdata.h:55
int i
Definition: input.c:407
#define av_log2
Definition: intmath.h:83
@ AV1_OBU_TILE_LIST
Definition: av1.h:37
@ AV1_OBU_TEMPORAL_DELIMITER
Definition: av1.h:31
@ AV1_OBU_METADATA
Definition: av1.h:34
@ AV1_OBU_TILE_GROUP
Definition: av1.h:33
@ AV1_OBU_REDUNDANT_FRAME_HEADER
Definition: av1.h:36
@ AV1_OBU_FRAME_HEADER
Definition: av1.h:32
@ AV1_OBU_PADDING
Definition: av1.h:39
@ AV1_OBU_FRAME
Definition: av1.h:35
@ AV1_OBU_SEQUENCE_HEADER
Definition: av1.h:30
@ AV1_REF_FRAME_LAST
Definition: av1.h:62
@ AV1_REF_FRAME_ALTREF
Definition: av1.h:68
@ AV1_FRAME_KEY
Definition: av1.h:53
@ AV1_FRAME_INTER
Definition: av1.h:54
@ AV1_FRAME_INTRA_ONLY
Definition: av1.h:55
@ AV1_FRAME_SWITCH
Definition: av1.h:56
@ AV1_CSP_COLOCATED
Definition: av1.h:134
@ AV1_CSP_VERTICAL
Definition: av1.h:133
@ AV1_WARP_MODEL_ROTZOOM
Definition: av1.h:115
@ AV1_GM_TRANS_ONLY_PREC_BITS
Definition: av1.h:108
@ AV1_WARP_MODEL_IDENTITY
Definition: av1.h:113
@ AV1_DIV_LUT_PREC_BITS
Definition: av1.h:120
@ AV1_PRIMARY_REF_NONE
Definition: av1.h:86
@ AV1_DIV_LUT_BITS
Definition: av1.h:119
@ AV1_MAX_OPERATING_POINTS
Definition: av1.h:73
@ AV1_NUM_REF_FRAMES
Definition: av1.h:83
@ AV1_GM_ALPHA_PREC_BITS
Definition: av1.h:106
@ AV1_WARPEDMODEL_PREC_BITS
Definition: av1.h:111
@ AV1_MAX_SEGMENTS
Definition: av1.h:88
@ AV1_WARP_PARAM_REDUCE_BITS
Definition: av1.h:117
@ AV1_GM_ABS_ALPHA_BITS
Definition: av1.h:105
@ AV1_REFS_PER_FRAME
Definition: av1.h:84
@ AV1_DIV_LUT_NUM
Definition: av1.h:121
@ AV1_WARP_MODEL_TRANSLATION
Definition: av1.h:114
@ AV1_SEG_LVL_ALT_Q
Definition: av1.h:91
@ AV1_GM_ABS_TRANS_BITS
Definition: av1.h:109
@ AV1_GM_ABS_TRANS_ONLY_BITS
Definition: av1.h:107
@ AV1_WARP_MODEL_AFFINE
Definition: av1.h:116
@ AV1_GM_TRANS_PREC_BITS
Definition: av1.h:110
static uint32_t decode_unsigned_subexp_with_ref(uint32_t sub_exp, int mx, int r)
Definition: av1dec.c:69
static uint64_t round_two(uint64_t x, uint16_t n)
Definition: av1dec.c:129
static const AVOption av1_options[]
Definition: av1dec.c:1222
static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src)
Definition: av1dec.c:590
static void av1_decode_flush(AVCodecContext *avctx)
Definition: av1dec.c:1205
static void coded_lossless_param(AV1DecContext *s)
Definition: av1dec.c:320
static int export_film_grain(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:848
static int get_relative_dist(const AV1RawSequenceHeader *seq, unsigned int a, unsigned int b)
Definition: av1dec.c:246
static uint8_t get_shear_params_valid(AV1DecContext *s, int idx)
check if global motion params is valid.
Definition: av1dec.c:165
static int32_t decode_signed_subexp_with_ref(uint32_t sub_exp, int low, int high, int r)
Definition: av1dec.c:79
static int init_tile_data(AV1DecContext *s)
Definition: av1dec.c:370
static uint32_t inverse_recenter(int r, uint32_t v)
Definition: av1dec.c:59
static int av1_decode_frame(AVCodecContext *avctx, void *frame, int *got_frame, AVPacket *pkt)
Definition: av1dec.c:990
static void skip_mode_params(AV1DecContext *s)
Definition: av1dec.c:254
static void read_global_param(AV1DecContext *s, int type, int ref, int idx)
Definition: av1dec.c:86
static int update_reference_list(AVCodecContext *avctx)
Definition: av1dec.c:941
static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f)
Definition: av1dec.c:791
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:197
static av_cold int av1_decode_init(AVCodecContext *avctx)
Definition: av1dec.c:732
#define HWACCEL_MAX
static int get_pixel_format(AVCodecContext *avctx)
Definition: av1dec.c:436
static int update_context_with_frame_header(AVCodecContext *avctx, const AV1RawFrameHeader *header)
Definition: av1dec.c:702
static int get_current_frame(AVCodecContext *avctx)
Definition: av1dec.c:961
static int set_output_frame(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt, int *got_frame)
Definition: av1dec.c:908
#define VD
Definition: av1dec.c:1221
static int set_context_with_sequence(AVCodecContext *avctx, const AV1RawSequenceHeader *seq)
Definition: av1dec.c:658
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
static void load_grain_params(AV1DecContext *s)
Definition: av1dec.c:350
static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_group)
Definition: av1dec.c:388
static const AVClass av1_class
Definition: av1dec.c:1228
#define OFFSET(x)
Definition: av1dec.c:1220
AVCodec ff_av1_decoder
Definition: av1dec.c:1235
static int16_t resolve_divisor(uint32_t d, uint16_t *shift)
Resolve divisor process.
Definition: av1dec.c:145
static void av1_frame_unref(AVCodecContext *avctx, AV1Frame *f)
Definition: av1dec.c:576
static int64_t round_two_signed(int64_t x, uint16_t n)
Definition: av1dec.c:136
static av_cold int av1_decode_free(AVCodecContext *avctx)
Definition: av1dec.c:637
#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:56
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:99
#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:41
#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:49
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:84
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
Definition: utils.c:960
common internal API header
#define SIZE_SPECIFIER
Definition: internal.h:193
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
static const AVProfile profiles[]
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
static av_always_inline av_const double round(double x)
Definition: libm.h:444
uint8_t w
Definition: llviddspenc.c:39
AVOptions.
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:2489
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition: pixfmt.h:609
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:607
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:569
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:586
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:403
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:404
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:381
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
Definition: pixfmt.h:137
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:235
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition: pixfmt.h:313
@ AV_PIX_FMT_D3D11VA_VLD
HW decoding through Direct3D11 via old API, Picture.data[3] contains a ID3D11VideoDecoderOutputView p...
Definition: pixfmt.h:229
@ AV_PIX_FMT_VAAPI
Definition: pixfmt.h:122
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:380
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
const AVProfile ff_av1_profiles[]
Definition: profiles.c:147
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
FF_DISABLE_DEPRECATION_WARNINGS enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
static const uint8_t header[24]
Definition: sdr2.c:67
#define FF_ARRAY_ELEMS(a)
static int shift(int a, int b)
Definition: sonic.c:82
uint8_t gm_invalid[AV1_NUM_REF_FRAMES]
Definition: av1dec.h:45
AV1RawFrameHeader * raw_frame_header
Definition: av1dec.h:40
uint8_t coded_lossless
Definition: av1dec.h:53
int spatial_id
Definition: av1dec.h:43
AVBufferRef * hwaccel_priv_buf
Definition: av1dec.h:36
AVBufferRef * header_ref
Definition: av1dec.h:39
uint8_t skip_mode_frame_idx[2]
Definition: av1dec.h:49
int32_t gm_params[AV1_NUM_REF_FRAMES][6]
Definition: av1dec.h:47
void * hwaccel_picture_private
Definition: av1dec.h:37
AV1RawFilmGrainParams film_grain
Definition: av1dec.h:51
ThreadFrame tf
Definition: av1dec.h:34
int temporal_id
Definition: av1dec.h:42
uint8_t gm_type[AV1_NUM_REF_FRAMES]
Definition: av1dec.h:46
uint8_t twelve_bit
Definition: cbs_av1.h:43
uint8_t matrix_coefficients
Definition: cbs_av1.h:49
uint8_t subsampling_x
Definition: cbs_av1.h:52
uint8_t chroma_sample_position
Definition: cbs_av1.h:54
uint8_t high_bitdepth
Definition: cbs_av1.h:42
uint8_t mono_chrome
Definition: cbs_av1.h:44
uint8_t color_range
Definition: cbs_av1.h:51
uint8_t transfer_characteristics
Definition: cbs_av1.h:48
uint8_t subsampling_y
Definition: cbs_av1.h:53
uint8_t color_primaries
Definition: cbs_av1.h:47
uint16_t cr_offset
Definition: cbs_av1.h:160
uint8_t ar_coeffs_y_plus_128[24]
Definition: cbs_av1.h:150
uint16_t cb_offset
Definition: cbs_av1.h:157
uint8_t cr_luma_mult
Definition: cbs_av1.h:159
uint8_t ar_coeff_shift_minus_6
Definition: cbs_av1.h:153
uint8_t point_y_value[14]
Definition: cbs_av1.h:139
uint8_t grain_scale_shift
Definition: cbs_av1.h:154
uint8_t point_cb_scaling[10]
Definition: cbs_av1.h:144
uint8_t film_grain_params_ref_idx
Definition: cbs_av1.h:137
uint8_t point_cr_scaling[10]
Definition: cbs_av1.h:147
uint16_t grain_seed
Definition: cbs_av1.h:135
uint8_t ar_coeffs_cr_plus_128[25]
Definition: cbs_av1.h:152
uint8_t num_cr_points
Definition: cbs_av1.h:145
uint8_t update_grain
Definition: cbs_av1.h:136
uint8_t ar_coeff_lag
Definition: cbs_av1.h:149
uint8_t num_y_points
Definition: cbs_av1.h:138
uint8_t cb_luma_mult
Definition: cbs_av1.h:156
uint8_t clip_to_restricted_range
Definition: cbs_av1.h:162
uint8_t point_cr_value[10]
Definition: cbs_av1.h:146
uint8_t point_cb_value[10]
Definition: cbs_av1.h:143
uint8_t chroma_scaling_from_luma
Definition: cbs_av1.h:141
uint8_t grain_scaling_minus_8
Definition: cbs_av1.h:148
uint8_t point_y_scaling[14]
Definition: cbs_av1.h:140
uint8_t ar_coeffs_cb_plus_128[25]
Definition: cbs_av1.h:151
uint8_t overlap_flag
Definition: cbs_av1.h:161
uint8_t num_cb_points
Definition: cbs_av1.h:142
AV1RawTileGroup tile_group
Definition: cbs_av1.h:305
AV1RawFrameHeader header
Definition: cbs_av1.h:304
AV1RawFrameHeader frame_header
Definition: cbs_av1.h:405
AV1RawOBUHeader header
Definition: cbs_av1.h:399
AV1RawTileGroup tile_group
Definition: cbs_av1.h:407
AV1RawSequenceHeader sequence_header
Definition: cbs_av1.h:404
AV1RawFrame frame
Definition: cbs_av1.h:406
union AV1RawOBU::@25 obu
uint16_t max_frame_height_minus_1
Definition: cbs_av1.h:99
uint8_t seq_profile
Definition: cbs_av1.h:74
AV1RawColorConfig color_config
Definition: cbs_av1.h:128
uint8_t order_hint_bits_minus_1
Definition: cbs_av1.h:122
AV1RawTimingInfo timing_info
Definition: cbs_av1.h:83
uint8_t seq_level_idx[AV1_MAX_OPERATING_POINTS]
Definition: cbs_av1.h:87
uint16_t max_frame_width_minus_1
Definition: cbs_av1.h:98
uint8_t * data
Definition: cbs_av1.h:290
size_t data_size
Definition: cbs_av1.h:292
uint16_t tg_start
Definition: cbs_av1.h:297
AV1RawTileData tile_data
Definition: cbs_av1.h:300
uint16_t tg_end
Definition: cbs_av1.h:298
uint32_t time_scale
Definition: cbs_av1.h:60
uint32_t num_units_in_display_tick
Definition: cbs_av1.h:59
uint32_t num_ticks_per_picture_minus_1
Definition: cbs_av1.h:63
uint8_t equal_picture_interval
Definition: cbs_av1.h:62
uint8_t * data
The data buffer.
Definition: buffer.h:92
Describe the class of an AVClass context structure.
Definition: log.h:67
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:72
main external API structure.
Definition: avcodec.h:536
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:746
int width
picture width / height.
Definition: avcodec.h:709
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1171
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1150
AVRational framerate
Definition: avcodec.h:2075
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:915
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:668
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1684
int level
level
Definition: avcodec.h:1988
int profile
profile
Definition: avcodec.h:1862
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame,...
Definition: avcodec.h:2350
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1164
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1157
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:637
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:1178
int extradata_size
Definition: avcodec.h:638
void * priv_data
Definition: avcodec.h:563
AVCodec.
Definition: codec.h:197
const char * name
Name of the codec implementation.
Definition: codec.h:204
This structure describes how to handle film grain synthesis for AOM codecs.
int chroma_scaling_from_luma
Signals whether to derive the chroma scaling function from the luma.
int limit_output_range
Signals to clip to limited color levels after film grain application.
int scaling_shift
Specifies the shift applied to the chroma components.
int grain_scale_shift
Signals the down shift applied to the generated gaussian numbers during synthesis.
int num_uv_points[2]
If chroma_scaling_from_luma is set to 0, signals the chroma scaling function parameters.
int overlap_flag
Signals whether to overlap film grain blocks.
int ar_coeff_lag
Specifies the auto-regression lag.
int uv_offset[2]
Offset used for component scaling function.
int ar_coeff_shift
Specifies the range of the auto-regressive coefficients.
uint8_t uv_points[2][10][2]
int8_t ar_coeffs_uv[2][25]
Chroma auto-regression coefficients.
int uv_mult[2]
Specifies the luma/chroma multipliers for the index to the component scaling function.
uint8_t y_points[14][2]
int8_t ar_coeffs_y[24]
Luma auto-regression coefficients.
int num_y_points
Number of points, and the scale and value for each point of the piecewise linear scaling function for...
This structure describes how to handle film grain synthesis in video for specific codecs.
union AVFilmGrainParams::@295 codec
Additional fields may be added both here and in any structure included.
AVFilmGrainAOMParams aom
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
uint64_t seed
Seed to use for the synthesis process, if the codec allows for it.
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:411
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:396
int pkt_size
size of the corresponding packet containing the compressed frame.
Definition: frame.h:633
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:427
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:401
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:2504
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
Definition: avcodec.h:2532
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:2518
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
Definition: avcodec.h:2543
int frame_priv_data_size
Size of per-frame hardware accelerator private data.
Definition: avcodec.h:2552
AVOption.
Definition: opt.h:248
This structure stores compressed data.
Definition: packet.h:346
int size
Definition: packet.h:370
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:368
Rational number (pair of numerator and denominator).
Definition: rational.h:58
int num
Numerator.
Definition: rational.h:59
int den
Denominator.
Definition: rational.h:60
Coded bitstream unit structure.
Definition: cbs.h:66
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:103
AVBufferRef * content_ref
If content is reference counted, a reference to the buffer containing content.
Definition: cbs.h:108
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
Definition: cbs.h:77
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:70
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
Definition: cbs.h:82
#define av_freep(p)
#define av_log(a,...)
#define src
Definition: vp8dsp.c:255
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
AVPacket * pkt
Definition: movenc.c:59
#define height
#define width
int size
const char * b
Definition: vf_curves.c:119
const char * r
Definition: vf_curves.c:117
static av_always_inline int diff(const uint32_t a, const uint32_t b)
float delta