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