FFmpeg  4.4.7
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  ref_hint = s->ref[header->ref_frame_idx[i]].raw_frame_header->order_hint;
271  dist = get_relative_dist(seq, ref_hint, header->order_hint);
272  if (dist < 0) {
273  if (forward_idx < 0 ||
274  get_relative_dist(seq, ref_hint, forward_hint) > 0) {
275  forward_idx = i;
276  forward_hint = ref_hint;
277  }
278  } else if (dist > 0) {
279  if (backward_idx < 0 ||
280  get_relative_dist(seq, ref_hint, backward_hint) < 0) {
281  backward_idx = i;
282  backward_hint = ref_hint;
283  }
284  }
285  }
286 
287  if (forward_idx < 0) {
288  return;
289  } else if (backward_idx >= 0) {
290  s->cur_frame.skip_mode_frame_idx[0] =
291  AV1_REF_FRAME_LAST + FFMIN(forward_idx, backward_idx);
292  s->cur_frame.skip_mode_frame_idx[1] =
293  AV1_REF_FRAME_LAST + FFMAX(forward_idx, backward_idx);
294  return;
295  }
296 
297  second_forward_idx = -1;
298  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
299  ref_hint = s->ref[header->ref_frame_idx[i]].raw_frame_header->order_hint;
300  if (get_relative_dist(seq, ref_hint, forward_hint) < 0) {
301  if (second_forward_idx < 0 ||
302  get_relative_dist(seq, ref_hint, second_forward_hint) > 0) {
303  second_forward_idx = i;
304  second_forward_hint = ref_hint;
305  }
306  }
307  }
308 
309  if (second_forward_idx < 0)
310  return;
311 
312  s->cur_frame.skip_mode_frame_idx[0] =
313  AV1_REF_FRAME_LAST + FFMIN(forward_idx, second_forward_idx);
314  s->cur_frame.skip_mode_frame_idx[1] =
315  AV1_REF_FRAME_LAST + FFMAX(forward_idx, second_forward_idx);
316 }
317 
319 {
320  const AV1RawFrameHeader *header = s->raw_frame_header;
321  int i;
322 
323  if (header->delta_q_y_dc || header->delta_q_u_ac ||
324  header->delta_q_u_dc || header->delta_q_v_ac ||
325  header->delta_q_v_dc) {
326  s->cur_frame.coded_lossless = 0;
327  return;
328  }
329 
330  s->cur_frame.coded_lossless = 1;
331  for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
332  int qindex;
333  if (header->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) {
334  qindex = (header->base_q_idx +
335  header->feature_value[i][AV1_SEG_LVL_ALT_Q]);
336  } else {
337  qindex = header->base_q_idx;
338  }
339  qindex = av_clip_uintp2(qindex, 8);
340 
341  if (qindex) {
342  s->cur_frame.coded_lossless = 0;
343  return;
344  }
345  }
346 }
347 
349 {
350  const AV1RawFrameHeader *header = s->raw_frame_header;
351  const AV1RawFilmGrainParams *film_grain = &header->film_grain, *src;
352  AV1RawFilmGrainParams *dst = &s->cur_frame.film_grain;
353 
354  if (!film_grain->apply_grain)
355  return;
356 
357  if (film_grain->update_grain) {
358  memcpy(dst, film_grain, sizeof(*dst));
359  return;
360  }
361 
362  src = &s->ref[film_grain->film_grain_params_ref_idx].film_grain;
363 
364  memcpy(dst, src, sizeof(*dst));
365  dst->grain_seed = film_grain->grain_seed;
366 }
367 
369 
370 {
371  int cur_tile_num =
372  s->raw_frame_header->tile_cols * s->raw_frame_header->tile_rows;
373  if (s->tile_num < cur_tile_num) {
374  int ret = av_reallocp_array(&s->tile_group_info, cur_tile_num,
375  sizeof(TileGroupInfo));
376  if (ret < 0) {
377  s->tile_num = 0;
378  return ret;
379  }
380  }
381  s->tile_num = cur_tile_num;
382 
383  return 0;
384 }
385 
386 static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_group)
387 {
388  AV1DecContext *s = avctx->priv_data;
389  GetByteContext gb;
390  uint16_t tile_num, tile_row, tile_col;
391  uint32_t size = 0, size_bytes = 0;
392 
393  bytestream2_init(&gb, tile_group->tile_data.data,
394  tile_group->tile_data.data_size);
395  s->tg_start = tile_group->tg_start;
396  s->tg_end = tile_group->tg_end;
397 
398  for (tile_num = tile_group->tg_start; tile_num <= tile_group->tg_end; tile_num++) {
399  tile_row = tile_num / s->raw_frame_header->tile_cols;
400  tile_col = tile_num % s->raw_frame_header->tile_cols;
401 
402  if (tile_num == tile_group->tg_end) {
403  s->tile_group_info[tile_num].tile_size = bytestream2_get_bytes_left(&gb);
404  s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
405  s->tile_group_info[tile_num].tile_row = tile_row;
406  s->tile_group_info[tile_num].tile_column = tile_col;
407  return 0;
408  }
409  size_bytes = s->raw_frame_header->tile_size_bytes_minus1 + 1;
410  if (bytestream2_get_bytes_left(&gb) < size_bytes)
411  return AVERROR_INVALIDDATA;
412  size = 0;
413  for (int i = 0; i < size_bytes; i++)
414  size |= bytestream2_get_byteu(&gb) << 8 * i;
415  if (bytestream2_get_bytes_left(&gb) <= size)
416  return AVERROR_INVALIDDATA;
417  size++;
418 
419  s->tile_group_info[tile_num].tile_size = size;
420  s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
421  s->tile_group_info[tile_num].tile_row = tile_row;
422  s->tile_group_info[tile_num].tile_column = tile_col;
423 
424  bytestream2_skipu(&gb, size);
425  }
426 
427  return 0;
428 
429 }
430 
432 {
433  AV1DecContext *s = avctx->priv_data;
434  const AV1RawSequenceHeader *seq = s->raw_seq;
436  int ret;
438 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
439  CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
440  CONFIG_AV1_NVDEC_HWACCEL + \
441  CONFIG_AV1_VAAPI_HWACCEL)
442  enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
443 
444  if (seq->seq_profile == 2 && seq->color_config.high_bitdepth)
445  bit_depth = seq->color_config.twelve_bit ? 12 : 10;
446  else if (seq->seq_profile <= 2)
447  bit_depth = seq->color_config.high_bitdepth ? 10 : 8;
448  else {
449  av_log(avctx, AV_LOG_ERROR,
450  "Unknown AV1 profile %d.\n", seq->seq_profile);
451  return -1;
452  }
453 
454  if (!seq->color_config.mono_chrome) {
455  // 4:4:4 x:0 y:0, 4:2:2 x:1 y:0, 4:2:0 x:1 y:1
456  if (seq->color_config.subsampling_x == 0 &&
457  seq->color_config.subsampling_y == 0) {
458  if (bit_depth == 8)
460  else if (bit_depth == 10)
462  else if (bit_depth == 12)
464  else
465  av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
466  } else if (seq->color_config.subsampling_x == 1 &&
467  seq->color_config.subsampling_y == 0) {
468  if (bit_depth == 8)
470  else if (bit_depth == 10)
472  else if (bit_depth == 12)
474  else
475  av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
476  } else if (seq->color_config.subsampling_x == 1 &&
477  seq->color_config.subsampling_y == 1) {
478  if (bit_depth == 8)
480  else if (bit_depth == 10)
482  else if (bit_depth == 12)
484  else
485  av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
486  }
487  } else {
488  if (bit_depth == 8)
490  else if (bit_depth == 10)
492  else if (bit_depth == 12)
494  else
495  av_log(avctx, AV_LOG_WARNING, "Unknown AV1 pixel format.\n");
496  }
497 
498  av_log(avctx, AV_LOG_DEBUG, "AV1 decode get format: %s.\n",
500 
501  if (pix_fmt == AV_PIX_FMT_NONE)
502  return -1;
503  s->pix_fmt = pix_fmt;
504 
505  switch (s->pix_fmt) {
506  case AV_PIX_FMT_YUV420P:
507 #if CONFIG_AV1_DXVA2_HWACCEL
508  *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
509 #endif
510 #if CONFIG_AV1_D3D11VA_HWACCEL
511  *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
512  *fmtp++ = AV_PIX_FMT_D3D11;
513 #endif
514 #if CONFIG_AV1_NVDEC_HWACCEL
515  *fmtp++ = AV_PIX_FMT_CUDA;
516 #endif
517 #if CONFIG_AV1_VAAPI_HWACCEL
518  *fmtp++ = AV_PIX_FMT_VAAPI;
519 #endif
520  break;
522 #if CONFIG_AV1_DXVA2_HWACCEL
523  *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
524 #endif
525 #if CONFIG_AV1_D3D11VA_HWACCEL
526  *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
527  *fmtp++ = AV_PIX_FMT_D3D11;
528 #endif
529 #if CONFIG_AV1_NVDEC_HWACCEL
530  *fmtp++ = AV_PIX_FMT_CUDA;
531 #endif
532 #if CONFIG_AV1_VAAPI_HWACCEL
533  *fmtp++ = AV_PIX_FMT_VAAPI;
534 #endif
535  break;
536  case AV_PIX_FMT_GRAY8:
537 #if CONFIG_AV1_NVDEC_HWACCEL
538  *fmtp++ = AV_PIX_FMT_CUDA;
539 #endif
540  break;
541  case AV_PIX_FMT_GRAY10:
542 #if CONFIG_AV1_NVDEC_HWACCEL
543  *fmtp++ = AV_PIX_FMT_CUDA;
544 #endif
545  break;
546  }
547 
548  *fmtp++ = s->pix_fmt;
549  *fmtp = AV_PIX_FMT_NONE;
550 
551  ret = ff_thread_get_format(avctx, pix_fmts);
552  if (ret < 0)
553  return ret;
554 
555  /**
556  * check if the HW accel is inited correctly. If not, return un-implemented.
557  * Since now the av1 decoder doesn't support native decode, if it will be
558  * implemented in the future, need remove this check.
559  */
560  if (!avctx->hwaccel) {
561  av_log(avctx, AV_LOG_ERROR, "Your platform doesn't suppport"
562  " hardware accelerated AV1 decoding.\n");
563  return AVERROR(ENOSYS);
564  }
565 
566  avctx->pix_fmt = ret;
567 
568  return 0;
569 }
570 
572 {
573  ff_thread_release_buffer(avctx, &f->tf);
574  av_buffer_unref(&f->hwaccel_priv_buf);
575  f->hwaccel_picture_private = NULL;
576  av_buffer_unref(&f->header_ref);
577  f->raw_frame_header = NULL;
578  f->spatial_id = f->temporal_id = 0;
579  memset(f->skip_mode_frame_idx, 0,
580  2 * sizeof(uint8_t));
581  memset(&f->film_grain, 0, sizeof(f->film_grain));
582  f->coded_lossless = 0;
583 }
584 
585 static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src)
586 {
587  int ret;
588 
589  ret = ff_thread_ref_frame(&dst->tf, &src->tf);
590  if (ret < 0)
591  return ret;
592 
593  dst->header_ref = av_buffer_ref(src->header_ref);
594  if (!dst->header_ref)
595  goto fail;
596 
597  dst->raw_frame_header = src->raw_frame_header;
598 
599  if (src->hwaccel_picture_private) {
600  dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);
601  if (!dst->hwaccel_priv_buf)
602  goto fail;
604  }
605 
606  dst->spatial_id = src->spatial_id;
607  dst->temporal_id = src->temporal_id;
608  memcpy(dst->gm_invalid,
609  src->gm_invalid,
610  AV1_NUM_REF_FRAMES * sizeof(uint8_t));
611  memcpy(dst->gm_type,
612  src->gm_type,
613  AV1_NUM_REF_FRAMES * sizeof(uint8_t));
614  memcpy(dst->gm_params,
615  src->gm_params,
616  AV1_NUM_REF_FRAMES * 6 * sizeof(int32_t));
617  memcpy(dst->skip_mode_frame_idx,
618  src->skip_mode_frame_idx,
619  2 * sizeof(uint8_t));
620  memcpy(&dst->film_grain,
621  &src->film_grain,
622  sizeof(dst->film_grain));
623  dst->coded_lossless = src->coded_lossless;
624 
625  return 0;
626 
627 fail:
628  av1_frame_unref(avctx, dst);
629  return AVERROR(ENOMEM);
630 }
631 
633 {
634  AV1DecContext *s = avctx->priv_data;
635 
636  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) {
637  av1_frame_unref(avctx, &s->ref[i]);
638  av_frame_free(&s->ref[i].tf.f);
639  }
640  av1_frame_unref(avctx, &s->cur_frame);
641  av_frame_free(&s->cur_frame.tf.f);
642 
643  av_buffer_unref(&s->seq_ref);
644  av_buffer_unref(&s->header_ref);
645  av_freep(&s->tile_group_info);
646 
647  ff_cbs_fragment_free(&s->current_obu);
648  ff_cbs_close(&s->cbc);
649 
650  return 0;
651 }
652 
654  const AV1RawSequenceHeader *seq)
655 {
656  int width = seq->max_frame_width_minus_1 + 1;
657  int height = seq->max_frame_height_minus_1 + 1;
658 
659  avctx->profile = seq->seq_profile;
660  avctx->level = seq->seq_level_idx[0];
661 
662  avctx->color_range =
667 
668  switch (seq->color_config.chroma_sample_position) {
669  case AV1_CSP_VERTICAL:
671  break;
672  case AV1_CSP_COLOCATED:
674  break;
675  }
676 
677  if (avctx->width != width || avctx->height != height) {
678  int ret = ff_set_dimensions(avctx, width, height);
679  if (ret < 0)
680  return ret;
681  }
682  avctx->sample_aspect_ratio = (AVRational) { 1, 1 };
683 
685  seq->timing_info.time_scale) {
686  av_reduce(&avctx->framerate.den, &avctx->framerate.num,
688  seq->timing_info.time_scale,
689  INT_MAX);
692  }
693 
694  return 0;
695 }
696 
698  const AV1RawFrameHeader *header)
699 {
700  AVRational aspect_ratio;
701  int width = header->frame_width_minus_1 + 1;
702  int height = header->frame_height_minus_1 + 1;
703  int r_width = header->render_width_minus_1 + 1;
704  int r_height = header->render_height_minus_1 + 1;
705  int ret;
706 
707  if (avctx->width != width || avctx->height != height) {
708  ret = ff_set_dimensions(avctx, width, height);
709  if (ret < 0)
710  return ret;
711  }
712 
713  av_reduce(&aspect_ratio.num, &aspect_ratio.den,
714  (int64_t)height * r_width,
715  (int64_t)width * r_height,
716  INT_MAX);
717 
718  if (av_cmp_q(avctx->sample_aspect_ratio, aspect_ratio)) {
719  ret = ff_set_sar(avctx, aspect_ratio);
720  if (ret < 0)
721  return ret;
722  }
723 
724  return 0;
725 }
726 
728 {
729  AV1DecContext *s = avctx->priv_data;
731  int ret;
732 
733  s->avctx = avctx;
734  s->pix_fmt = AV_PIX_FMT_NONE;
735 
736  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) {
737  s->ref[i].tf.f = av_frame_alloc();
738  if (!s->ref[i].tf.f) {
739  av_log(avctx, AV_LOG_ERROR,
740  "Failed to allocate reference frame buffer %d.\n", i);
741  return AVERROR(ENOMEM);
742  }
743  }
744 
745  s->cur_frame.tf.f = av_frame_alloc();
746  if (!s->cur_frame.tf.f) {
747  av_log(avctx, AV_LOG_ERROR,
748  "Failed to allocate current frame buffer.\n");
749  return AVERROR(ENOMEM);
750  }
751 
752  ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, avctx);
753  if (ret < 0)
754  return ret;
755 
756  av_opt_set_int(s->cbc->priv_data, "operating_point", s->operating_point, 0);
757 
758  if (avctx->extradata && avctx->extradata_size) {
760  &s->current_obu,
761  avctx);
762  if (ret < 0) {
763  av_log(avctx, AV_LOG_WARNING, "Failed to read extradata.\n");
764  return ret;
765  }
766 
767  seq = ((CodedBitstreamAV1Context *)(s->cbc->priv_data))->sequence_header;
768  if (!seq) {
769  av_log(avctx, AV_LOG_WARNING, "No sequence header available.\n");
770  goto end;
771  }
772 
773  ret = set_context_with_sequence(avctx, seq);
774  if (ret < 0) {
775  av_log(avctx, AV_LOG_WARNING, "Failed to set decoder context.\n");
776  goto end;
777  }
778 
779  end:
780  ff_cbs_fragment_reset(&s->current_obu);
781  }
782 
783  return ret;
784 }
785 
787 {
788  AV1DecContext *s = avctx->priv_data;
789  AV1RawFrameHeader *header= s->raw_frame_header;
790  AVFrame *frame;
791  int ret;
792 
794  if (ret < 0) {
795  av_log(avctx, AV_LOG_ERROR, "Failed to update context with frame header\n");
796  return ret;
797  }
798 
799  f->header_ref = av_buffer_ref(s->header_ref);
800  if (!f->header_ref)
801  return AVERROR(ENOMEM);
802 
803  f->raw_frame_header = s->raw_frame_header;
804 
805  if ((ret = ff_thread_get_buffer(avctx, &f->tf, AV_GET_BUFFER_FLAG_REF)) < 0)
806  goto fail;
807 
808  frame = f->tf.f;
809  frame->key_frame = header->frame_type == AV1_FRAME_KEY;
810 
811  switch (header->frame_type) {
812  case AV1_FRAME_KEY:
815  break;
816  case AV1_FRAME_INTER:
818  break;
819  case AV1_FRAME_SWITCH:
821  break;
822  }
823 
824  if (avctx->hwaccel) {
825  const AVHWAccel *hwaccel = avctx->hwaccel;
826  if (hwaccel->frame_priv_data_size) {
827  f->hwaccel_priv_buf =
829  if (!f->hwaccel_priv_buf) {
830  ret = AVERROR(ENOMEM);
831  goto fail;
832  }
833  f->hwaccel_picture_private = f->hwaccel_priv_buf->data;
834  }
835  }
836  return 0;
837 
838 fail:
839  av1_frame_unref(avctx, f);
840  return ret;
841 }
842 
844 {
845  AV1DecContext *s = avctx->priv_data;
846  const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
847  AVFilmGrainParams *fgp;
849 
850  if (!film_grain->apply_grain)
851  return 0;
852 
854  if (!fgp)
855  return AVERROR(ENOMEM);
856 
858  fgp->seed = film_grain->grain_seed;
859 
860  aom = &fgp->codec.aom;
862  aom->scaling_shift = film_grain->grain_scaling_minus_8 + 8;
863  aom->ar_coeff_lag = film_grain->ar_coeff_lag;
864  aom->ar_coeff_shift = film_grain->ar_coeff_shift_minus_6 + 6;
865  aom->grain_scale_shift = film_grain->grain_scale_shift;
866  aom->overlap_flag = film_grain->overlap_flag;
867  aom->limit_output_range = film_grain->clip_to_restricted_range;
868 
869  aom->num_y_points = film_grain->num_y_points;
870  for (int i = 0; i < film_grain->num_y_points; i++) {
871  aom->y_points[i][0] = film_grain->point_y_value[i];
872  aom->y_points[i][1] = film_grain->point_y_scaling[i];
873  }
874  aom->num_uv_points[0] = film_grain->num_cb_points;
875  for (int i = 0; i < film_grain->num_cb_points; i++) {
876  aom->uv_points[0][i][0] = film_grain->point_cb_value[i];
877  aom->uv_points[0][i][1] = film_grain->point_cb_scaling[i];
878  }
879  aom->num_uv_points[1] = film_grain->num_cr_points;
880  for (int i = 0; i < film_grain->num_cr_points; i++) {
881  aom->uv_points[1][i][0] = film_grain->point_cr_value[i];
882  aom->uv_points[1][i][1] = film_grain->point_cr_scaling[i];
883  }
884 
885  for (int i = 0; i < 24; i++) {
886  aom->ar_coeffs_y[i] = film_grain->ar_coeffs_y_plus_128[i] - 128;
887  }
888  for (int i = 0; i < 25; i++) {
889  aom->ar_coeffs_uv[0][i] = film_grain->ar_coeffs_cb_plus_128[i] - 128;
890  aom->ar_coeffs_uv[1][i] = film_grain->ar_coeffs_cr_plus_128[i] - 128;
891  }
892 
893  aom->uv_mult[0] = film_grain->cb_mult;
894  aom->uv_mult[1] = film_grain->cr_mult;
895  aom->uv_mult_luma[0] = film_grain->cb_luma_mult;
896  aom->uv_mult_luma[1] = film_grain->cr_luma_mult;
897  aom->uv_offset[0] = film_grain->cb_offset;
898  aom->uv_offset[1] = film_grain->cr_offset;
899 
900  return 0;
901 }
902 
904  const AVPacket *pkt, int *got_frame)
905 {
906  AV1DecContext *s = avctx->priv_data;
907  const AVFrame *srcframe = s->cur_frame.tf.f;
908  int ret;
909 
910  // TODO: all layers
911  if (s->operating_point_idc &&
912  av_log2(s->operating_point_idc >> 8) > s->cur_frame.spatial_id)
913  return 0;
914 
915  ret = av_frame_ref(frame, srcframe);
916  if (ret < 0)
917  return ret;
918 
920  ret = export_film_grain(avctx, frame);
921  if (ret < 0) {
923  return ret;
924  }
925  }
926 
927  frame->pts = pkt->pts;
928  frame->pkt_dts = pkt->dts;
929  frame->pkt_size = pkt->size;
930 
931  *got_frame = 1;
932 
933  return 0;
934 }
935 
937 {
938  AV1DecContext *s = avctx->priv_data;
939  const AV1RawFrameHeader *header = s->raw_frame_header;
940  int ret;
941 
942  for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
943  if (header->refresh_frame_flags & (1 << i)) {
944  if (s->ref[i].tf.f->buf[0])
945  av1_frame_unref(avctx, &s->ref[i]);
946  if ((ret = av1_frame_ref(avctx, &s->ref[i], &s->cur_frame)) < 0) {
947  av_log(avctx, AV_LOG_ERROR,
948  "Failed to update frame %d in reference list\n", i);
949  return ret;
950  }
951  }
952  }
953  return 0;
954 }
955 
957 {
958  AV1DecContext *s = avctx->priv_data;
959  int ret;
960 
961  if (s->cur_frame.tf.f->buf[0])
962  av1_frame_unref(avctx, &s->cur_frame);
963 
964  ret = av1_frame_alloc(avctx, &s->cur_frame);
965  if (ret < 0) {
966  av_log(avctx, AV_LOG_ERROR,
967  "Failed to allocate space for current frame.\n");
968  return ret;
969  }
970 
971  ret = init_tile_data(s);
972  if (ret < 0) {
973  av_log(avctx, AV_LOG_ERROR, "Failed to init tile data.\n");
974  return ret;
975  }
976 
981 
982  return ret;
983 }
984 
985 static int av1_decode_frame(AVCodecContext *avctx, void *frame,
986  int *got_frame, AVPacket *pkt)
987 {
988  AV1DecContext *s = avctx->priv_data;
989  AV1RawTileGroup *raw_tile_group = NULL;
990  int ret;
991 
992  ret = ff_cbs_read_packet(s->cbc, &s->current_obu, pkt);
993  if (ret < 0) {
994  av_log(avctx, AV_LOG_ERROR, "Failed to read packet.\n");
995  goto end;
996  }
997  av_log(avctx, AV_LOG_DEBUG, "Total obu for this frame:%d.\n",
998  s->current_obu.nb_units);
999 
1000  for (int i = 0; i < s->current_obu.nb_units; i++) {
1001  CodedBitstreamUnit *unit = &s->current_obu.units[i];
1002  AV1RawOBU *obu = unit->content;
1003  const AV1RawOBUHeader *header;
1004 
1005  if (!obu)
1006  continue;
1007 
1008  header = &obu->header;
1009  av_log(avctx, AV_LOG_DEBUG, "Obu idx:%d, obu type:%d.\n", i, unit->type);
1010 
1011  switch (unit->type) {
1013  av_buffer_unref(&s->seq_ref);
1014  s->seq_ref = av_buffer_ref(unit->content_ref);
1015  if (!s->seq_ref) {
1016  ret = AVERROR(ENOMEM);
1017  goto end;
1018  }
1019 
1020  s->raw_seq = &obu->obu.sequence_header;
1021  s->raw_frame_header = NULL;
1022  raw_tile_group = NULL;
1023 
1024  ret = set_context_with_sequence(avctx, s->raw_seq);
1025  if (ret < 0) {
1026  av_log(avctx, AV_LOG_ERROR, "Failed to set context.\n");
1027  s->raw_seq = NULL;
1028  goto end;
1029  }
1030 
1031  s->operating_point_idc = s->raw_seq->operating_point_idc[s->operating_point];
1032 
1033  if (s->pix_fmt == AV_PIX_FMT_NONE) {
1034  ret = get_pixel_format(avctx);
1035  if (ret < 0) {
1036  av_log(avctx, AV_LOG_ERROR,
1037  "Failed to get pixel format.\n");
1038  s->raw_seq = NULL;
1039  goto end;
1040  }
1041  }
1042 
1043  if (avctx->hwaccel && avctx->hwaccel->decode_params) {
1044  ret = avctx->hwaccel->decode_params(avctx, unit->type, unit->data,
1045  unit->data_size);
1046  if (ret < 0) {
1047  av_log(avctx, AV_LOG_ERROR, "HW accel decode params fail.\n");
1048  s->raw_seq = NULL;
1049  goto end;
1050  }
1051  }
1052  break;
1054  if (s->raw_frame_header)
1055  break;
1056  // fall-through
1057  case AV1_OBU_FRAME:
1058  case AV1_OBU_FRAME_HEADER:
1059  if (!s->raw_seq) {
1060  av_log(avctx, AV_LOG_ERROR, "Missing Sequence Header.\n");
1061  ret = AVERROR_INVALIDDATA;
1062  goto end;
1063  }
1064 
1065  av_buffer_unref(&s->header_ref);
1066  s->header_ref = av_buffer_ref(unit->content_ref);
1067  if (!s->header_ref) {
1068  ret = AVERROR(ENOMEM);
1069  goto end;
1070  }
1071 
1072  raw_tile_group = NULL;
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");
1128  ret = AVERROR_INVALIDDATA;
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;
1153  s->raw_frame_header = NULL;
1154  raw_tile_group = NULL;
1155  // fall-through
1156  case AV1_OBU_TILE_LIST:
1157  case AV1_OBU_PADDING:
1158  case AV1_OBU_METADATA:
1159  break;
1160  default:
1161  av_log(avctx, AV_LOG_DEBUG,
1162  "Unknown obu type: %d (%"SIZE_SPECIFIER" bits).\n",
1163  unit->type, unit->data_size);
1164  }
1165 
1166  if (raw_tile_group && (s->tile_num == raw_tile_group->tg_end + 1)) {
1167  if (avctx->hwaccel) {
1168  ret = avctx->hwaccel->end_frame(avctx);
1169  if (ret < 0) {
1170  av_log(avctx, AV_LOG_ERROR, "HW accel end frame fail.\n");
1171  goto end;
1172  }
1173  }
1174 
1175  ret = update_reference_list(avctx);
1176  if (ret < 0) {
1177  av_log(avctx, AV_LOG_ERROR, "Failed to update reference list.\n");
1178  goto end;
1179  }
1180 
1181  if (s->raw_frame_header->show_frame) {
1182  ret = set_output_frame(avctx, frame, pkt, got_frame);
1183  if (ret < 0) {
1184  av_log(avctx, AV_LOG_ERROR, "Set output frame error\n");
1185  goto end;
1186  }
1187  }
1188  raw_tile_group = NULL;
1189  s->raw_frame_header = NULL;
1190  }
1191  }
1192 
1193 end:
1194  ff_cbs_fragment_reset(&s->current_obu);
1195  if (ret < 0)
1196  s->raw_frame_header = NULL;
1197  return ret;
1198 }
1199 
1201 {
1202  AV1DecContext *s = avctx->priv_data;
1203 
1204  for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++)
1205  av1_frame_unref(avctx, &s->ref[i]);
1206 
1207  av1_frame_unref(avctx, &s->cur_frame);
1208  s->operating_point_idc = 0;
1209  s->raw_frame_header = NULL;
1210  s->raw_seq = NULL;
1211 
1212  ff_cbs_flush(s->cbc);
1213 }
1214 
1215 #define OFFSET(x) offsetof(AV1DecContext, x)
1216 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1217 static const AVOption av1_options[] = {
1218  { "operating_point", "Select an operating point of the scalable bitstream",
1219  OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, AV1_MAX_OPERATING_POINTS - 1, VD },
1220  { NULL }
1221 };
1222 
1223 static const AVClass av1_class = {
1224  .class_name = "AV1 decoder",
1225  .item_name = av_default_item_name,
1226  .option = av1_options,
1227  .version = LIBAVUTIL_VERSION_INT,
1228 };
1229 
1231  .name = "av1",
1232  .long_name = NULL_IF_CONFIG_SMALL("Alliance for Open Media AV1"),
1233  .type = AVMEDIA_TYPE_VIDEO,
1234  .id = AV_CODEC_ID_AV1,
1235  .priv_data_size = sizeof(AV1DecContext),
1236  .init = av1_decode_init,
1237  .close = av1_decode_free,
1239  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_AVOID_PROBING,
1240  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
1245  .priv_class = &av1_class,
1246  .hw_configs = (const AVCodecHWConfigInternal *const []) {
1247 #if CONFIG_AV1_DXVA2_HWACCEL
1248  HWACCEL_DXVA2(av1),
1249 #endif
1250 #if CONFIG_AV1_D3D11VA_HWACCEL
1251  HWACCEL_D3D11VA(av1),
1252 #endif
1253 #if CONFIG_AV1_D3D11VA2_HWACCEL
1254  HWACCEL_D3D11VA2(av1),
1255 #endif
1256 #if CONFIG_AV1_NVDEC_HWACCEL
1257  HWACCEL_NVDEC(av1),
1258 #endif
1259 #if CONFIG_AV1_VAAPI_HWACCEL
1260  HWACCEL_VAAPI(av1),
1261 #endif
1262  NULL
1263  },
1264 };
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:586
#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:1217
static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src)
Definition: av1dec.c:585
static void av1_decode_flush(AVCodecContext *avctx)
Definition: av1dec.c:1200
static void coded_lossless_param(AV1DecContext *s)
Definition: av1dec.c:318
static int export_film_grain(AVCodecContext *avctx, AVFrame *frame)
Definition: av1dec.c:843
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:368
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:985
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:936
static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f)
Definition: av1dec.c:786
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:727
#define HWACCEL_MAX
static int get_pixel_format(AVCodecContext *avctx)
Definition: av1dec.c:431
static int update_context_with_frame_header(AVCodecContext *avctx, const AV1RawFrameHeader *header)
Definition: av1dec.c:697
static int get_current_frame(AVCodecContext *avctx)
Definition: av1dec.c:956
static int set_output_frame(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt, int *got_frame)
Definition: av1dec.c:903
#define VD
Definition: av1dec.c:1216
static int set_context_with_sequence(AVCodecContext *avctx, const AV1RawSequenceHeader *seq)
Definition: av1dec.c:653
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:348
static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_group)
Definition: av1dec.c:386
static const AVClass av1_class
Definition: av1dec.c:1223
#define OFFSET(x)
Definition: av1dec.c:1215
AVCodec ff_av1_decoder
Definition: av1dec.c:1230
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:571
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:632
#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:943
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:398
AV1RawOBUHeader header
Definition: cbs_av1.h:392
AV1RawTileGroup tile_group
Definition: cbs_av1.h:400
AV1RawSequenceHeader sequence_header
Definition: cbs_av1.h:397
AV1RawFrame frame
Definition: cbs_av1.h:399
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.
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.
union AVFilmGrainParams::@294 codec
Additional fields may be added both here and in any structure included.
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:118
const char * r
Definition: vf_curves.c:116
static av_always_inline int diff(const uint32_t a, const uint32_t b)
float delta