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