FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/av1dec.c
Date: 2026-06-16 12:54:33
Exec Total Coverage
Lines: 275 856 32.1%
Functions: 12 34 35.3%
Branches: 108 469 23.0%

Line Branch Exec Source
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
23 #include "libavutil/attributes.h"
24 #include "libavutil/hdr_dynamic_metadata.h"
25 #include "libavutil/film_grain_params.h"
26 #include "libavutil/mastering_display_metadata.h"
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 */
46 static 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
73 static 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
83 static 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
93 static 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
100 static 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) {
122 if (type == AV1_WARP_MODEL_TRANSLATION) {
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
143 static 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
150 static 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 */
159 static 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)
166 f = round_two(e, *shift - AV1_DIV_LUT_BITS);
167 else
168 f = e << (AV1_DIV_LUT_BITS - (*shift));
169
170 *shift += AV1_DIV_LUT_PREC_BITS;
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 */
179 static 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
195 alpha = round_two_signed(alpha, AV1_WARP_PARAM_REDUCE_BITS) << AV1_WARP_PARAM_REDUCE_BITS;
196 beta = round_two_signed(beta, AV1_WARP_PARAM_REDUCE_BITS) << AV1_WARP_PARAM_REDUCE_BITS;
197 gamma = round_two_signed(gamma, AV1_WARP_PARAM_REDUCE_BITS) << AV1_WARP_PARAM_REDUCE_BITS;
198 delta = round_two_signed(delta, AV1_WARP_PARAM_REDUCE_BITS) << AV1_WARP_PARAM_REDUCE_BITS;
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 */
211 static void global_motion_params(AV1DecContext *s)
212 {
213 const AV1RawFrameHeader *header = s->raw_frame_header;
214 int type, ref;
215
216 for (ref = AV1_REF_FRAME_LAST; ref <= AV1_REF_FRAME_ALTREF; ref++) {
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) ?
220 1 << AV1_WARPEDMODEL_PREC_BITS : 0;
221 }
222 if (header->frame_type == AV1_FRAME_KEY ||
223 header->frame_type == AV1_FRAME_INTRA_ONLY)
224 return;
225
226 for (ref = AV1_REF_FRAME_LAST; ref <= AV1_REF_FRAME_ALTREF; ref++) {
227 if (header->is_global[ref]) {
228 if (header->is_rot_zoom[ref]) {
229 type = AV1_WARP_MODEL_ROTZOOM;
230 } else {
231 type = header->is_translation[ref] ? AV1_WARP_MODEL_TRANSLATION
232 : AV1_WARP_MODEL_AFFINE;
233 }
234 } else {
235 type = AV1_WARP_MODEL_IDENTITY;
236 }
237 s->cur_frame.gm_type[ref] = type;
238
239 if (type >= AV1_WARP_MODEL_ROTZOOM) {
240 read_global_param(s, type, ref, 2);
241 read_global_param(s, type, ref, 3);
242 if (type == AV1_WARP_MODEL_AFFINE) {
243 read_global_param(s, type, ref, 4);
244 read_global_param(s, type, ref, 5);
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 }
250 if (type >= AV1_WARP_MODEL_TRANSLATION) {
251 read_global_param(s, type, ref, 0);
252 read_global_param(s, type, ref, 1);
253 }
254 if (type <= AV1_WARP_MODEL_AFFINE) {
255 s->cur_frame.gm_invalid[ref] = !get_shear_params_valid(s, ref);
256 }
257 }
258 }
259
260 static int get_relative_dist(const AV1RawSequenceHeader *seq,
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
268 static void skip_mode_params(AV1DecContext *s)
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
336 static void coded_lossless_param(AV1DecContext *s)
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
366 static void order_hint_info(AV1DecContext *s)
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
390 static void load_grain_params(AV1DecContext *s)
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
410 24 static int init_tile_data(AV1DecContext *s)
411
412 {
413 24 int cur_tile_num =
414 24 s->raw_frame_header->tile_cols * s->raw_frame_header->tile_rows;
415
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (s->tile_num < cur_tile_num) {
416 24 int ret = av_reallocp_array(&s->tile_group_info, cur_tile_num,
417 sizeof(TileGroupInfo));
418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (ret < 0) {
419 s->tile_num = 0;
420 return ret;
421 }
422 }
423 24 s->tile_num = cur_tile_num;
424
425 24 return 0;
426 }
427
428 32 static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_group)
429 {
430 32 AV1DecContext *s = avctx->priv_data;
431 GetByteContext gb;
432 uint16_t tile_num, tile_row, tile_col;
433 32 uint32_t size = 0, size_bytes = 0;
434
435 32 bytestream2_init(&gb, tile_group->tile_data.data,
436 32 tile_group->tile_data.data_size);
437 32 s->tg_start = tile_group->tg_start;
438 32 s->tg_end = tile_group->tg_end;
439
440
1/2
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
47 for (tile_num = tile_group->tg_start; tile_num <= tile_group->tg_end; tile_num++) {
441 47 tile_row = tile_num / s->raw_frame_header->tile_cols;
442 47 tile_col = tile_num % s->raw_frame_header->tile_cols;
443
444
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 15 times.
47 if (tile_num == tile_group->tg_end) {
445 32 s->tile_group_info[tile_num].tile_size = bytestream2_get_bytes_left(&gb);
446 32 s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
447 32 s->tile_group_info[tile_num].tile_row = tile_row;
448 32 s->tile_group_info[tile_num].tile_column = tile_col;
449 32 return 0;
450 }
451 15 size_bytes = s->raw_frame_header->tile_size_bytes_minus1 + 1;
452
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
15 if (bytestream2_get_bytes_left(&gb) < size_bytes)
453 return AVERROR_INVALIDDATA;
454 15 size = 0;
455
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 15 times.
53 for (int i = 0; i < size_bytes; i++)
456 38 size |= bytestream2_get_byteu(&gb) << 8 * i;
457
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
15 if (bytestream2_get_bytes_left(&gb) <= size)
458 return AVERROR_INVALIDDATA;
459 15 size++;
460
461 15 s->tile_group_info[tile_num].tile_size = size;
462 15 s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
463 15 s->tile_group_info[tile_num].tile_row = tile_row;
464 15 s->tile_group_info[tile_num].tile_column = tile_col;
465
466 15 bytestream2_skipu(&gb, size);
467 }
468
469 return 0;
470
471 }
472
473 28 static enum AVPixelFormat get_sw_pixel_format(void *logctx,
474 const AV1RawSequenceHeader *seq)
475 {
476 int bit_depth;
477 28 enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
478
479
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
28 if (seq->seq_profile == 2 && seq->color_config.high_bitdepth)
480 bit_depth = seq->color_config.twelve_bit ? 12 : 10;
481
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 else if (seq->seq_profile <= 2)
482
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 27 times.
28 bit_depth = seq->color_config.high_bitdepth ? 10 : 8;
483 else {
484 av_log(logctx, AV_LOG_ERROR,
485 "Unknown AV1 profile %d.\n", seq->seq_profile);
486 return AV_PIX_FMT_NONE;
487 }
488
489
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if (!seq->color_config.mono_chrome) {
490 // 4:4:4 x:0 y:0, 4:2:2 x:1 y:0, 4:2:0 x:1 y:1
491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if (seq->color_config.subsampling_x == 0 &&
492 seq->color_config.subsampling_y == 0) {
493 if (bit_depth == 8)
494 pix_fmt = AV_PIX_FMT_YUV444P;
495 else if (bit_depth == 10)
496 pix_fmt = AV_PIX_FMT_YUV444P10;
497 else if (bit_depth == 12)
498 pix_fmt = AV_PIX_FMT_YUV444P12;
499 else
500 av_assert0(0);
501
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 } else if (seq->color_config.subsampling_x == 1 &&
502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 seq->color_config.subsampling_y == 0) {
503 if (bit_depth == 8)
504 pix_fmt = AV_PIX_FMT_YUV422P;
505 else if (bit_depth == 10)
506 pix_fmt = AV_PIX_FMT_YUV422P10;
507 else if (bit_depth == 12)
508 pix_fmt = AV_PIX_FMT_YUV422P12;
509 else
510 av_assert0(0);
511
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 } else if (seq->color_config.subsampling_x == 1 &&
512
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 seq->color_config.subsampling_y == 1) {
513
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 1 times.
28 if (bit_depth == 8)
514 27 pix_fmt = AV_PIX_FMT_YUV420P;
515
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 else if (bit_depth == 10)
516 1 pix_fmt = AV_PIX_FMT_YUV420P10;
517 else if (bit_depth == 12)
518 pix_fmt = AV_PIX_FMT_YUV420P12;
519 else
520 av_assert0(0);
521 }
522 } else {
523 if (bit_depth == 8)
524 pix_fmt = AV_PIX_FMT_GRAY8;
525 else if (bit_depth == 10)
526 pix_fmt = AV_PIX_FMT_GRAY10;
527 else if (bit_depth == 12)
528 pix_fmt = AV_PIX_FMT_GRAY12;
529 else
530 av_assert0(0);
531 }
532
533 28 return pix_fmt;
534 }
535
536 static int get_pixel_format(AVCodecContext *avctx)
537 {
538 AV1DecContext *s = avctx->priv_data;
539 const AV1RawSequenceHeader *seq = s->raw_seq;
540 int ret;
541 enum AVPixelFormat pix_fmt = get_sw_pixel_format(avctx, seq);
542 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
543 CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
544 CONFIG_AV1_D3D12VA_HWACCEL + \
545 CONFIG_AV1_NVDEC_HWACCEL + \
546 CONFIG_AV1_VAAPI_HWACCEL + \
547 CONFIG_AV1_VDPAU_HWACCEL + \
548 CONFIG_AV1_VIDEOTOOLBOX_HWACCEL + \
549 CONFIG_AV1_VULKAN_HWACCEL)
550 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
551
552 if (pix_fmt == AV_PIX_FMT_NONE)
553 return -1;
554
555 switch (pix_fmt) {
556 case AV_PIX_FMT_YUV420P:
557 #if CONFIG_AV1_DXVA2_HWACCEL
558 *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
559 #endif
560 #if CONFIG_AV1_D3D11VA_HWACCEL
561 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
562 *fmtp++ = AV_PIX_FMT_D3D11;
563 #endif
564 #if CONFIG_AV1_D3D12VA_HWACCEL
565 *fmtp++ = AV_PIX_FMT_D3D12;
566 #endif
567 #if CONFIG_AV1_NVDEC_HWACCEL
568 *fmtp++ = AV_PIX_FMT_CUDA;
569 #endif
570 #if CONFIG_AV1_VAAPI_HWACCEL
571 *fmtp++ = AV_PIX_FMT_VAAPI;
572 #endif
573 #if CONFIG_AV1_VDPAU_HWACCEL
574 *fmtp++ = AV_PIX_FMT_VDPAU;
575 #endif
576 #if CONFIG_AV1_VIDEOTOOLBOX_HWACCEL
577 *fmtp++ = AV_PIX_FMT_VIDEOTOOLBOX;
578 #endif
579 #if CONFIG_AV1_VULKAN_HWACCEL
580 *fmtp++ = AV_PIX_FMT_VULKAN;
581 #endif
582 break;
583 case AV_PIX_FMT_YUV420P10:
584 #if CONFIG_AV1_DXVA2_HWACCEL
585 *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
586 #endif
587 #if CONFIG_AV1_D3D11VA_HWACCEL
588 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
589 *fmtp++ = AV_PIX_FMT_D3D11;
590 #endif
591 #if CONFIG_AV1_D3D12VA_HWACCEL
592 *fmtp++ = AV_PIX_FMT_D3D12;
593 #endif
594 #if CONFIG_AV1_NVDEC_HWACCEL
595 *fmtp++ = AV_PIX_FMT_CUDA;
596 #endif
597 #if CONFIG_AV1_VAAPI_HWACCEL
598 *fmtp++ = AV_PIX_FMT_VAAPI;
599 #endif
600 #if CONFIG_AV1_VDPAU_HWACCEL
601 *fmtp++ = AV_PIX_FMT_VDPAU;
602 #endif
603 #if CONFIG_AV1_VIDEOTOOLBOX_HWACCEL
604 *fmtp++ = AV_PIX_FMT_VIDEOTOOLBOX;
605 #endif
606 #if CONFIG_AV1_VULKAN_HWACCEL
607 *fmtp++ = AV_PIX_FMT_VULKAN;
608 #endif
609 break;
610 case AV_PIX_FMT_YUV420P12:
611 #if CONFIG_AV1_VULKAN_HWACCEL
612 *fmtp++ = AV_PIX_FMT_VULKAN;
613 #endif
614 break;
615 case AV_PIX_FMT_YUV422P:
616 #if CONFIG_AV1_VULKAN_HWACCEL
617 *fmtp++ = AV_PIX_FMT_VULKAN;
618 #endif
619 break;
620 case AV_PIX_FMT_YUV422P10:
621 #if CONFIG_AV1_VULKAN_HWACCEL
622 *fmtp++ = AV_PIX_FMT_VULKAN;
623 #endif
624 break;
625 case AV_PIX_FMT_YUV422P12:
626 #if CONFIG_AV1_VULKAN_HWACCEL
627 *fmtp++ = AV_PIX_FMT_VULKAN;
628 #endif
629 break;
630 case AV_PIX_FMT_YUV444P:
631 #if CONFIG_AV1_VULKAN_HWACCEL
632 *fmtp++ = AV_PIX_FMT_VULKAN;
633 #endif
634 break;
635 case AV_PIX_FMT_YUV444P10:
636 #if CONFIG_AV1_VULKAN_HWACCEL
637 *fmtp++ = AV_PIX_FMT_VULKAN;
638 #endif
639 break;
640 case AV_PIX_FMT_YUV444P12:
641 #if CONFIG_AV1_VULKAN_HWACCEL
642 *fmtp++ = AV_PIX_FMT_VULKAN;
643 #endif
644 break;
645 case AV_PIX_FMT_GRAY8:
646 #if CONFIG_AV1_NVDEC_HWACCEL
647 *fmtp++ = AV_PIX_FMT_CUDA;
648 #endif
649 break;
650 case AV_PIX_FMT_GRAY10:
651 #if CONFIG_AV1_NVDEC_HWACCEL
652 *fmtp++ = AV_PIX_FMT_CUDA;
653 #endif
654 break;
655 }
656
657 *fmtp++ = pix_fmt;
658 *fmtp = AV_PIX_FMT_NONE;
659
660 for (int i = 0; pix_fmts[i] != pix_fmt; i++)
661 if (pix_fmts[i] == avctx->pix_fmt) {
662 s->pix_fmt = pix_fmt;
663 return 1;
664 }
665
666 ret = ff_get_format(avctx, pix_fmts);
667
668 /**
669 * check if the HW accel is inited correctly. If not, return un-implemented.
670 * Since now the av1 decoder doesn't support native decode, if it will be
671 * implemented in the future, need remove this check.
672 */
673 if (!avctx->hwaccel) {
674 av_log(avctx, AV_LOG_ERROR, "Your platform doesn't support"
675 " hardware accelerated AV1 decoding.\n");
676 avctx->pix_fmt = AV_PIX_FMT_NONE;
677 return AVERROR(ENOSYS);
678 }
679
680 s->pix_fmt = pix_fmt;
681 avctx->pix_fmt = ret;
682
683 av_log(avctx, AV_LOG_DEBUG, "AV1 decode get format: %s.\n",
684 av_get_pix_fmt_name(avctx->pix_fmt));
685
686 return 0;
687 }
688
689 285 static void av1_frame_unref(AV1Frame *f)
690 {
691 285 ff_progress_frame_unref(&f->pf);
692 285 av_refstruct_unref(&f->hwaccel_picture_private);
693 285 av_refstruct_unref(&f->header_ref);
694 285 f->raw_frame_header = NULL;
695 285 f->spatial_id = f->temporal_id = 0;
696 285 memset(f->skip_mode_frame_idx, 0,
697 2 * sizeof(uint8_t));
698 285 memset(&f->film_grain, 0, sizeof(f->film_grain));
699 285 f->coded_lossless = 0;
700 285 }
701
702 178 static void av1_frame_replace(AV1Frame *dst, const AV1Frame *src)
703 {
704 av_assert1(dst != src);
705
706 178 av_refstruct_replace(&dst->header_ref, src->header_ref);
707
708 178 dst->raw_frame_header = src->raw_frame_header;
709
710 178 ff_progress_frame_replace(&dst->pf, &src->pf);
711
712 178 av_refstruct_replace(&dst->hwaccel_picture_private,
713 178 src->hwaccel_picture_private);
714
715 178 dst->spatial_id = src->spatial_id;
716 178 dst->temporal_id = src->temporal_id;
717 178 memcpy(dst->gm_invalid,
718 178 src->gm_invalid,
719 AV1_NUM_REF_FRAMES * sizeof(uint8_t));
720 178 memcpy(dst->gm_type,
721 178 src->gm_type,
722 AV1_NUM_REF_FRAMES * sizeof(uint8_t));
723 178 memcpy(dst->gm_params,
724 178 src->gm_params,
725 AV1_NUM_REF_FRAMES * 6 * sizeof(int32_t));
726 178 memcpy(dst->skip_mode_frame_idx,
727 178 src->skip_mode_frame_idx,
728 2 * sizeof(uint8_t));
729 178 memcpy(&dst->film_grain,
730 178 &src->film_grain,
731 sizeof(dst->film_grain));
732 178 dst->coded_lossless = src->coded_lossless;
733
734 178 dst->order_hint = src->order_hint;
735 178 memcpy(dst->ref_frame_sign_bias, src->ref_frame_sign_bias,
736 sizeof(dst->ref_frame_sign_bias));
737 178 memcpy(dst->order_hints, src->order_hints,
738 sizeof(dst->order_hints));
739
740 178 dst->force_integer_mv = src->force_integer_mv;
741 178 }
742
743 29 static av_cold int av1_decode_free(AVCodecContext *avctx)
744 {
745 29 AV1DecContext *s = avctx->priv_data;
746 AV1RawMetadataITUTT35 itut_t35;
747
748
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 29 times.
261 for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++)
749 232 av1_frame_unref(&s->ref[i]);
750 29 av1_frame_unref(&s->cur_frame);
751 29 av_buffer_unref(&s->seq_data_ref);
752 29 av_refstruct_unref(&s->seq_ref);
753 29 av_refstruct_unref(&s->header_ref);
754 29 av_refstruct_unref(&s->cll_ref);
755 29 av_refstruct_unref(&s->mdcv_ref);
756 29 av_freep(&s->tile_group_info);
757
758
2/4
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 29 times.
29 while (s->itut_t35_fifo && av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0)
759 av_buffer_unref(&itut_t35.payload_ref);
760 29 av_fifo_freep2(&s->itut_t35_fifo);
761
762 29 ff_cbs_fragment_free(&s->current_obu);
763 29 ff_cbs_close(&s->cbc);
764 29 ff_dovi_ctx_unref(&s->dovi);
765
766 29 return 0;
767 }
768
769 29 static int set_context_with_sequence(AVCodecContext *avctx,
770 const AV1RawSequenceHeader *seq)
771 {
772 29 int width = seq->max_frame_width_minus_1 + 1;
773 29 int height = seq->max_frame_height_minus_1 + 1;
774
775 29 avctx->profile = seq->seq_profile;
776 29 avctx->level = seq->seq_level_idx[0];
777
778
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
29 if (seq->color_config.color_description_present_flag) {
779 avctx->color_range =
780 seq->color_config.color_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
781 avctx->color_primaries = seq->color_config.color_primaries;
782 avctx->colorspace = seq->color_config.matrix_coefficients;
783 avctx->color_trc = seq->color_config.transfer_characteristics;
784 }
785
786
2/3
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
29 switch (seq->color_config.chroma_sample_position) {
787 4 case AV1_CSP_VERTICAL:
788 4 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
789 4 break;
790 case AV1_CSP_COLOCATED:
791 avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
792 break;
793 }
794
795 #if FF_API_CODEC_PROPS
796 FF_DISABLE_DEPRECATION_WARNINGS
797
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 27 times.
29 if (seq->film_grain_params_present)
798 2 avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
799 else
800 27 avctx->properties &= ~FF_CODEC_PROPERTY_FILM_GRAIN;
801 FF_ENABLE_DEPRECATION_WARNINGS
802 #endif
803
804
3/4
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 25 times.
29 if (avctx->width != width || avctx->height != height) {
805 4 int ret = ff_set_dimensions(avctx, width, height);
806
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ret < 0)
807 return ret;
808 }
809
810
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 25 times.
29 if (seq->timing_info_present_flag)
811 4 avctx->framerate = ff_av1_framerate(1LL + seq->timing_info.num_ticks_per_picture_minus_1,
812 4 seq->timing_info.num_units_in_display_tick,
813 4 seq->timing_info.time_scale);
814
815
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 1 times.
29 if (avctx->pix_fmt == AV_PIX_FMT_NONE)
816 28 avctx->pix_fmt = get_sw_pixel_format(avctx, seq);
817
818 29 return 0;
819 }
820
821 static int update_context_with_frame_header(AVCodecContext *avctx,
822 const AV1RawFrameHeader *header)
823 {
824 AVRational aspect_ratio;
825 int width = header->frame_width_minus_1 + 1;
826 int height = header->frame_height_minus_1 + 1;
827 int r_width = header->render_width_minus_1 + 1;
828 int r_height = header->render_height_minus_1 + 1;
829 int ret;
830
831 if (avctx->width != width || avctx->height != height) {
832 ret = ff_set_dimensions(avctx, width, height);
833 if (ret < 0)
834 return ret;
835 }
836
837 av_reduce(&aspect_ratio.num, &aspect_ratio.den,
838 (int64_t)height * r_width,
839 (int64_t)width * r_height,
840 INT_MAX);
841
842 if (av_cmp_q(avctx->sample_aspect_ratio, aspect_ratio)) {
843 ret = ff_set_sar(avctx, aspect_ratio);
844 if (ret < 0)
845 return ret;
846 }
847
848 return 0;
849 }
850
851 static const CodedBitstreamUnitType decompose_unit_types[] = {
852 AV1_OBU_FRAME,
853 AV1_OBU_FRAME_HEADER,
854 AV1_OBU_METADATA,
855 AV1_OBU_REDUNDANT_FRAME_HEADER,
856 AV1_OBU_SEQUENCE_HEADER,
857 AV1_OBU_TEMPORAL_DELIMITER,
858 AV1_OBU_TILE_GROUP,
859 };
860
861 29 static av_cold int av1_decode_init(AVCodecContext *avctx)
862 {
863 29 AV1DecContext *s = avctx->priv_data;
864 AV1RawSequenceHeader *seq;
865 const AVPacketSideData *sd;
866 int ret;
867
868 29 s->avctx = avctx;
869 29 s->pkt = avctx->internal->in_pkt;
870 29 s->pix_fmt = AV_PIX_FMT_NONE;
871
872 29 ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, avctx);
873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
29 if (ret < 0)
874 return ret;
875
876 29 s->cbc->decompose_unit_types = decompose_unit_types;
877 29 s->cbc->nb_decompose_unit_types = FF_ARRAY_ELEMS(decompose_unit_types);
878
879 29 s->itut_t35_fifo = av_fifo_alloc2(1, sizeof(AV1RawMetadataITUTT35),
880 AV_FIFO_FLAG_AUTO_GROW);
881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
29 if (!s->itut_t35_fifo)
882 return AVERROR(ENOMEM);
883
884 29 av_opt_set_int(s->cbc->priv_data, "operating_point", s->operating_point, 0);
885
886
3/4
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
29 if (avctx->extradata && avctx->extradata_size) {
887 9 ret = ff_cbs_read_extradata_from_codec(s->cbc,
888 &s->current_obu,
889 avctx);
890
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ret < 0) {
891 av_log(avctx, AV_LOG_WARNING, "Failed to read extradata.\n");
892 goto end;
893 }
894
895 9 seq = ((CodedBitstreamAV1Context *)(s->cbc->priv_data))->sequence_header;
896
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
9 if (!seq) {
897
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!(avctx->extradata[0] & 0x80))
898 av_log(avctx, AV_LOG_WARNING, "No sequence header available in extradata.\n");
899 2 goto end;
900 }
901
902 7 ret = set_context_with_sequence(avctx, seq);
903
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (ret < 0) {
904 av_log(avctx, AV_LOG_WARNING, "Failed to set decoder context.\n");
905 goto end;
906 }
907
908 7 end:
909 9 ff_cbs_fragment_reset(&s->current_obu);
910 }
911
912 29 s->dovi.logctx = avctx;
913 29 s->dovi.cfg.dv_profile = 10; // default for AV1
914 29 sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF);
915
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
29 if (sd && sd->size >= sizeof(s->dovi.cfg))
916 s->dovi.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data;
917
918 29 return ret;
919 }
920
921 static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f)
922 {
923 AV1DecContext *s = avctx->priv_data;
924 AV1RawFrameHeader *header= s->raw_frame_header;
925 AVFrame *frame;
926 int ret;
927
928 ret = update_context_with_frame_header(avctx, header);
929 if (ret < 0) {
930 av_log(avctx, AV_LOG_ERROR, "Failed to update context with frame header\n");
931 return ret;
932 }
933
934 ret = ff_progress_frame_get_buffer(avctx, &f->pf, AV_GET_BUFFER_FLAG_REF);
935 if (ret < 0)
936 goto fail;
937
938 frame = f->f;
939 if (header->frame_type == AV1_FRAME_KEY)
940 frame->flags |= AV_FRAME_FLAG_KEY;
941 else
942 frame->flags &= ~AV_FRAME_FLAG_KEY;
943
944 switch (header->frame_type) {
945 case AV1_FRAME_KEY:
946 case AV1_FRAME_INTRA_ONLY:
947 frame->pict_type = AV_PICTURE_TYPE_I;
948 break;
949 case AV1_FRAME_INTER:
950 frame->pict_type = AV_PICTURE_TYPE_P;
951 break;
952 case AV1_FRAME_SWITCH:
953 frame->pict_type = AV_PICTURE_TYPE_SP;
954 break;
955 }
956
957 ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private);
958 if (ret < 0)
959 goto fail;
960
961 return 0;
962
963 fail:
964 av1_frame_unref(f);
965 return ret;
966 }
967
968 static int export_itut_t35(AVCodecContext *avctx, AVFrame *frame,
969 const AV1RawMetadataITUTT35 *itut_t35)
970 {
971 AV1DecContext *s = avctx->priv_data;
972 FFITUTT35 itut35 = { .country_code = itut_t35->itu_t_t35_country_code };
973 FFITUTT35Aux aux = { .dovi = &s->dovi };
974 int ret;
975
976 ret = ff_itut_t35_parse_buffer(&itut35, itut_t35->payload, itut_t35->payload_size,
977 FF_ITUT_T35_FLAG_COUNTRY_CODE);
978 if (ret <= 0)
979 return ret;
980
981 ret = ff_itut_t35_parse_payload_to_frame(&itut35, &aux, avctx, frame);
982 if (ret < 0)
983 return ret;
984
985 return 0;
986 }
987
988 static int export_metadata(AVCodecContext *avctx, AVFrame *frame)
989 {
990 AV1DecContext *s = avctx->priv_data;
991 AV1RawMetadataITUTT35 itut_t35;
992 int ret = 0;
993
994 if (s->mdcv) {
995 AVMasteringDisplayMetadata *mastering;
996
997 ret = ff_decode_mastering_display_new(avctx, frame, &mastering);
998 if (ret < 0)
999 return ret;
1000
1001 if (mastering) {
1002 for (int i = 0; i < 3; i++) {
1003 mastering->display_primaries[i][0] = av_make_q(s->mdcv->primary_chromaticity_x[i], 1 << 16);
1004 mastering->display_primaries[i][1] = av_make_q(s->mdcv->primary_chromaticity_y[i], 1 << 16);
1005 }
1006 mastering->white_point[0] = av_make_q(s->mdcv->white_point_chromaticity_x, 1 << 16);
1007 mastering->white_point[1] = av_make_q(s->mdcv->white_point_chromaticity_y, 1 << 16);
1008
1009 mastering->max_luminance = av_make_q(s->mdcv->luminance_max, 1 << 8);
1010 mastering->min_luminance = av_make_q(s->mdcv->luminance_min, 1 << 14);
1011
1012 mastering->has_primaries = 1;
1013 mastering->has_luminance = 1;
1014 }
1015 }
1016
1017 if (s->cll) {
1018 AVContentLightMetadata *light;
1019
1020 ret = ff_decode_content_light_new(avctx, frame, &light);
1021 if (ret < 0)
1022 return ret;
1023
1024 if (light) {
1025 light->MaxCLL = s->cll->max_cll;
1026 light->MaxFALL = s->cll->max_fall;
1027 }
1028 }
1029
1030 while (av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0) {
1031 if (ret >= 0)
1032 ret = export_itut_t35(avctx, frame, &itut_t35);
1033 av_buffer_unref(&itut_t35.payload_ref);
1034 }
1035
1036 return ret;
1037 }
1038
1039 static int export_film_grain(AVCodecContext *avctx, AVFrame *frame)
1040 {
1041 AV1DecContext *s = avctx->priv_data;
1042 const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
1043 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(frame->format);
1044 AVFilmGrainParams *fgp;
1045 AVFilmGrainAOMParams *aom;
1046
1047 av_assert0(pixdesc);
1048 if (!film_grain->apply_grain)
1049 return 0;
1050
1051 fgp = av_film_grain_params_create_side_data(frame);
1052 if (!fgp)
1053 return AVERROR(ENOMEM);
1054
1055 fgp->type = AV_FILM_GRAIN_PARAMS_AV1;
1056 fgp->seed = film_grain->grain_seed;
1057 fgp->width = frame->width;
1058 fgp->height = frame->height;
1059 fgp->color_range = frame->color_range;
1060 fgp->color_primaries = frame->color_primaries;
1061 fgp->color_trc = frame->color_trc;
1062 fgp->color_space = frame->colorspace;
1063 fgp->subsampling_x = pixdesc->log2_chroma_w;
1064 fgp->subsampling_y = pixdesc->log2_chroma_h;
1065
1066 aom = &fgp->codec.aom;
1067 aom->chroma_scaling_from_luma = film_grain->chroma_scaling_from_luma;
1068 aom->scaling_shift = film_grain->grain_scaling_minus_8 + 8;
1069 aom->ar_coeff_lag = film_grain->ar_coeff_lag;
1070 aom->ar_coeff_shift = film_grain->ar_coeff_shift_minus_6 + 6;
1071 aom->grain_scale_shift = film_grain->grain_scale_shift;
1072 aom->overlap_flag = film_grain->overlap_flag;
1073 aom->limit_output_range = film_grain->clip_to_restricted_range;
1074
1075 aom->num_y_points = film_grain->num_y_points;
1076 for (int i = 0; i < film_grain->num_y_points; i++) {
1077 aom->y_points[i][0] = film_grain->point_y_value[i];
1078 aom->y_points[i][1] = film_grain->point_y_scaling[i];
1079 }
1080 aom->num_uv_points[0] = film_grain->num_cb_points;
1081 for (int i = 0; i < film_grain->num_cb_points; i++) {
1082 aom->uv_points[0][i][0] = film_grain->point_cb_value[i];
1083 aom->uv_points[0][i][1] = film_grain->point_cb_scaling[i];
1084 }
1085 aom->num_uv_points[1] = film_grain->num_cr_points;
1086 for (int i = 0; i < film_grain->num_cr_points; i++) {
1087 aom->uv_points[1][i][0] = film_grain->point_cr_value[i];
1088 aom->uv_points[1][i][1] = film_grain->point_cr_scaling[i];
1089 }
1090
1091 for (int i = 0; i < 24; i++) {
1092 aom->ar_coeffs_y[i] = film_grain->ar_coeffs_y_plus_128[i] - 128;
1093 }
1094 for (int i = 0; i < 25; i++) {
1095 aom->ar_coeffs_uv[0][i] = film_grain->ar_coeffs_cb_plus_128[i] - 128;
1096 aom->ar_coeffs_uv[1][i] = film_grain->ar_coeffs_cr_plus_128[i] - 128;
1097 }
1098
1099 aom->uv_mult[0] = film_grain->cb_mult;
1100 aom->uv_mult[1] = film_grain->cr_mult;
1101 aom->uv_mult_luma[0] = film_grain->cb_luma_mult;
1102 aom->uv_mult_luma[1] = film_grain->cr_luma_mult;
1103 aom->uv_offset[0] = film_grain->cb_offset;
1104 aom->uv_offset[1] = film_grain->cr_offset;
1105
1106 return 0;
1107 }
1108
1109 static int set_output_frame(AVCodecContext *avctx, AVFrame *frame)
1110 {
1111 AV1DecContext *s = avctx->priv_data;
1112 const AVFrame *srcframe = s->cur_frame.f;
1113 AVPacket *pkt = s->pkt;
1114 int ret;
1115
1116 // TODO: all layers
1117 if (s->operating_point_idc &&
1118 av_log2(s->operating_point_idc >> 8) > s->cur_frame.spatial_id)
1119 return 0;
1120
1121 ret = av_frame_ref(frame, srcframe);
1122 if (ret < 0)
1123 return ret;
1124
1125 ret = export_metadata(avctx, frame);
1126 if (ret < 0) {
1127 av_frame_unref(frame);
1128 return ret;
1129 }
1130
1131 if (avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) {
1132 ret = export_film_grain(avctx, frame);
1133 if (ret < 0) {
1134 av_frame_unref(frame);
1135 return ret;
1136 }
1137 }
1138
1139 frame->pts = pkt->pts;
1140 frame->pkt_dts = pkt->dts;
1141
1142 av_packet_unref(pkt);
1143
1144 return 0;
1145 }
1146
1147 24 static void update_reference_list(AVCodecContext *avctx)
1148 {
1149 24 AV1DecContext *s = avctx->priv_data;
1150 24 const AV1RawFrameHeader *header = s->raw_frame_header;
1151
1152
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 24 times.
216 for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1153
2/2
✓ Branch 0 taken 178 times.
✓ Branch 1 taken 14 times.
192 if (header->refresh_frame_flags & (1 << i))
1154 178 av1_frame_replace(&s->ref[i], &s->cur_frame);
1155 }
1156 24 }
1157
1158 24 static int get_current_frame(AVCodecContext *avctx)
1159 {
1160 24 AV1DecContext *s = avctx->priv_data;
1161 int ret;
1162
1163 24 av1_frame_unref(&s->cur_frame);
1164
1165 24 s->cur_frame.header_ref = av_refstruct_ref(s->header_ref);
1166
1167 24 s->cur_frame.raw_frame_header = s->raw_frame_header;
1168
1169 24 ret = init_tile_data(s);
1170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (ret < 0) {
1171 av_log(avctx, AV_LOG_ERROR, "Failed to init tile data.\n");
1172 return ret;
1173 }
1174
1175
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if ((avctx->skip_frame >= AVDISCARD_NONINTRA &&
1176
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 22 times.
24 (s->raw_frame_header->frame_type != AV1_FRAME_KEY &&
1177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 s->raw_frame_header->frame_type != AV1_FRAME_INTRA_ONLY)) ||
1178
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 (avctx->skip_frame >= AVDISCARD_NONKEY &&
1179
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 s->raw_frame_header->frame_type != AV1_FRAME_KEY) ||
1180
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 avctx->skip_frame >= AVDISCARD_ALL)
1181 24 return 0;
1182
1183 if (s->pix_fmt == AV_PIX_FMT_NONE) {
1184 ret = get_pixel_format(avctx);
1185 if (ret < 0) {
1186 av_log(avctx, AV_LOG_ERROR, "Failed to get pixel format.\n");
1187 return ret;
1188 }
1189
1190 if (!ret && FF_HW_HAS_CB(avctx, decode_params)) {
1191 ret = FF_HW_CALL(avctx, decode_params, AV1_OBU_SEQUENCE_HEADER,
1192 s->seq_data_ref->data, s->seq_data_ref->size);
1193 if (ret < 0) {
1194 av_log(avctx, AV_LOG_ERROR, "HW accel decode params fail.\n");
1195 return ret;
1196 }
1197 }
1198 }
1199
1200 ret = av1_frame_alloc(avctx, &s->cur_frame);
1201 if (ret < 0) {
1202 av_log(avctx, AV_LOG_ERROR,
1203 "Failed to allocate space for current frame.\n");
1204 return ret;
1205 }
1206
1207 global_motion_params(s);
1208 skip_mode_params(s);
1209 coded_lossless_param(s);
1210 order_hint_info(s);
1211 load_grain_params(s);
1212
1213 s->cur_frame.force_integer_mv =
1214 s->raw_frame_header->force_integer_mv ||
1215 s->raw_frame_header->frame_type == AV1_FRAME_KEY ||
1216 s->raw_frame_header->frame_type == AV1_FRAME_INTRA_ONLY;
1217
1218 return ret;
1219 }
1220
1221 24 static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
1222 {
1223 24 AV1DecContext *s = avctx->priv_data;
1224 24 AV1RawTileGroup *raw_tile_group = NULL;
1225 24 int i = 0, ret;
1226
1227
1/2
✓ Branch 0 taken 83 times.
✗ Branch 1 not taken.
83 for (i = s->nb_unit; i < s->current_obu.nb_units; i++) {
1228 83 CodedBitstreamUnit *unit = &s->current_obu.units[i];
1229 83 AV1RawOBU *obu = unit->content;
1230 const AV1RawOBUHeader *header;
1231
1232 83 av_log(avctx, AV_LOG_DEBUG, "OBU idx:%d, type:%d, content available:%d.\n", i, unit->type, !!obu);
1233
1234
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
83 if (unit->type == AV1_OBU_TILE_LIST) {
1235 av_log(avctx, AV_LOG_ERROR, "Large scale tile decoding is unsupported.\n");
1236 ret = AVERROR_PATCHWELCOME;
1237 goto end;
1238 }
1239
1240
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
83 if (!obu)
1241 continue;
1242
1243 83 header = &obu->header;
1244
1245
5/8
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
83 switch (unit->type) {
1246 22 case AV1_OBU_SEQUENCE_HEADER:
1247 22 ret = av_buffer_replace(&s->seq_data_ref, unit->data_ref);
1248
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (ret < 0)
1249 goto end;
1250
1251 22 s->seq_data_ref->data = unit->data;
1252 22 s->seq_data_ref->size = unit->data_size;
1253 22 av_refstruct_replace(&s->seq_ref, unit->content_ref);
1254
1255 22 s->raw_seq = &obu->obu.sequence_header;
1256 22 s->raw_frame_header = NULL;
1257 22 raw_tile_group = NULL;
1258
1259 22 ret = set_context_with_sequence(avctx, s->raw_seq);
1260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (ret < 0) {
1261 av_log(avctx, AV_LOG_ERROR, "Failed to set context.\n");
1262 s->raw_seq = NULL;
1263 goto end;
1264 }
1265
1266 22 s->operating_point_idc = s->raw_seq->operating_point_idc[s->operating_point];
1267
1268 22 s->pix_fmt = AV_PIX_FMT_NONE;
1269
1270
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
22 if (FF_HW_HAS_CB(avctx, decode_params)) {
1271 ret = FF_HW_CALL(avctx, decode_params, AV1_OBU_SEQUENCE_HEADER,
1272 s->seq_data_ref->data, s->seq_data_ref->size);
1273 if (ret < 0) {
1274 av_log(avctx, AV_LOG_ERROR, "HW accel decode params fail.\n");
1275 return ret;
1276 }
1277 }
1278
1279 22 break;
1280 case AV1_OBU_REDUNDANT_FRAME_HEADER:
1281 if (s->raw_frame_header)
1282 break;
1283 av_fallthrough;
1284 case AV1_OBU_FRAME:
1285 case AV1_OBU_FRAME_HEADER:
1286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (!s->raw_seq) {
1287 av_log(avctx, AV_LOG_ERROR, "Missing Sequence Header.\n");
1288 ret = AVERROR_INVALIDDATA;
1289 goto end;
1290 }
1291
1292 24 av_refstruct_replace(&s->header_ref, unit->content_ref);
1293
1294 24 raw_tile_group = NULL;
1295
1296
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 5 times.
24 if (unit->type == AV1_OBU_FRAME)
1297 19 s->raw_frame_header = &obu->obu.frame.header;
1298 else
1299 5 s->raw_frame_header = &obu->obu.frame_header;
1300
1301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (s->raw_frame_header->show_existing_frame) {
1302 av1_frame_replace(&s->cur_frame,
1303 &s->ref[s->raw_frame_header->frame_to_show_map_idx]);
1304
1305 update_reference_list(avctx);
1306
1307 if (s->cur_frame.f) {
1308 ret = set_output_frame(avctx, frame);
1309 if (ret < 0) {
1310 av_log(avctx, AV_LOG_ERROR, "Set output frame error.\n");
1311 goto end;
1312 }
1313 }
1314
1315 s->raw_frame_header = NULL;
1316 i++;
1317 ret = 0;
1318
1319 goto end;
1320 }
1321
1322 24 ret = get_current_frame(avctx);
1323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (ret < 0) {
1324 av_log(avctx, AV_LOG_ERROR, "Get current frame error\n");
1325 goto end;
1326 }
1327
1328 24 s->cur_frame.spatial_id = header->spatial_id;
1329 24 s->cur_frame.temporal_id = header->temporal_id;
1330
1331
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 if (avctx->hwaccel && s->cur_frame.f) {
1332 ret = FF_HW_CALL(avctx, start_frame, s->pkt->buf,
1333 unit->data, unit->data_size);
1334 if (ret < 0) {
1335 av_log(avctx, AV_LOG_ERROR, "HW accel start frame fail.\n");
1336 goto end;
1337 }
1338 }
1339
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 19 times.
24 if (unit->type != AV1_OBU_FRAME)
1340 5 break;
1341 av_fallthrough;
1342 case AV1_OBU_TILE_GROUP:
1343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (!s->raw_frame_header) {
1344 av_log(avctx, AV_LOG_ERROR, "Missing Frame Header.\n");
1345 ret = AVERROR_INVALIDDATA;
1346 goto end;
1347 }
1348
1349
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 13 times.
32 if (unit->type == AV1_OBU_FRAME)
1350 19 raw_tile_group = &obu->obu.frame.tile_group;
1351 else
1352 13 raw_tile_group = &obu->obu.tile_group;
1353
1354 32 ret = get_tiles_info(avctx, raw_tile_group);
1355
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
1356 goto end;
1357
1358
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
32 if (avctx->hwaccel && s->cur_frame.f) {
1359 ret = FF_HW_CALL(avctx, decode_slice, raw_tile_group->tile_data.data,
1360 raw_tile_group->tile_data.data_size);
1361 if (ret < 0) {
1362 av_log(avctx, AV_LOG_ERROR,
1363 "HW accel decode slice fail.\n");
1364 goto end;
1365 }
1366 }
1367 32 break;
1368 20 case AV1_OBU_TEMPORAL_DELIMITER:
1369 20 s->raw_frame_header = NULL;
1370 20 raw_tile_group = NULL;
1371 20 break;
1372 case AV1_OBU_TILE_LIST:
1373 case AV1_OBU_PADDING:
1374 break;
1375 4 case AV1_OBU_METADATA:
1376
2/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4 switch (obu->obu.metadata.metadata_type) {
1377 2 case AV1_METADATA_TYPE_HDR_CLL:
1378 2 av_refstruct_replace(&s->cll_ref, unit->content_ref);
1379 2 s->cll = &obu->obu.metadata.metadata.hdr_cll;
1380 2 break;
1381 2 case AV1_METADATA_TYPE_HDR_MDCV:
1382 2 av_refstruct_replace(&s->mdcv_ref, unit->content_ref);
1383 2 s->mdcv = &obu->obu.metadata.metadata.hdr_mdcv;
1384 2 break;
1385 case AV1_METADATA_TYPE_ITUT_T35: {
1386 AV1RawMetadataITUTT35 itut_t35;
1387 memcpy(&itut_t35, &obu->obu.metadata.metadata.itut_t35, sizeof(itut_t35));
1388 itut_t35.payload_ref = av_buffer_ref(obu->obu.metadata.metadata.itut_t35.payload_ref);
1389 if (!itut_t35.payload_ref) {
1390 ret = AVERROR(ENOMEM);
1391 goto end;
1392 }
1393 ret = av_fifo_write(s->itut_t35_fifo, &itut_t35, 1);
1394 if (ret < 0) {
1395 av_buffer_unref(&itut_t35.payload_ref);
1396 goto end;
1397 }
1398 break;
1399 }
1400 default:
1401 break;
1402 }
1403 4 break;
1404 default:
1405 av_log(avctx, AV_LOG_DEBUG,
1406 "Unknown obu type: %d (%zu bits).\n",
1407 unit->type, unit->data_size);
1408 }
1409
1410
4/4
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 51 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 8 times.
83 if (raw_tile_group && (s->tile_num == raw_tile_group->tg_end + 1)) {
1411 24 int show_frame = s->raw_frame_header->show_frame;
1412 // Set nb_unit to point at the next OBU, to indicate which
1413 // OBUs have been processed for this current frame. (If this
1414 // frame gets output, we set nb_unit to this value later too.)
1415 24 s->nb_unit = i + 1;
1416
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 if (avctx->hwaccel && s->cur_frame.f) {
1417 ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
1418 if (ret < 0) {
1419 av_log(avctx, AV_LOG_ERROR, "HW accel end frame fail.\n");
1420 goto end;
1421 }
1422 }
1423
1424 24 update_reference_list(avctx);
1425
1426 // Set start_unit to indicate the first OBU of the next frame.
1427 24 s->start_unit = s->nb_unit;
1428 24 raw_tile_group = NULL;
1429 24 s->raw_frame_header = NULL;
1430
1431
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (show_frame) {
1432 // cur_frame.f needn't exist due to skip_frame.
1433
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (s->cur_frame.f) {
1434 ret = set_output_frame(avctx, frame);
1435 if (ret < 0) {
1436 av_log(avctx, AV_LOG_ERROR, "Set output frame error\n");
1437 goto end;
1438 }
1439 }
1440 24 i++;
1441 24 ret = 0;
1442 24 goto end;
1443 }
1444 }
1445 }
1446
1447 ret = AVERROR(EAGAIN);
1448 24 end:
1449
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 av_assert0(i <= s->current_obu.nb_units);
1450 24 s->nb_unit = i;
1451
1452
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 2 times.
24 if ((ret < 0 && ret != AVERROR(EAGAIN)) || s->current_obu.nb_units == i) {
1453
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (ret < 0)
1454 s->raw_frame_header = NULL;
1455 22 av_packet_unref(s->pkt);
1456 22 ff_cbs_fragment_reset(&s->current_obu);
1457 22 s->nb_unit = s->start_unit = 0;
1458 }
1459
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 if (!ret && !frame->buf[0])
1460 24 ret = AVERROR(EAGAIN);
1461
1462 24 return ret;
1463 }
1464
1465 44 static int av1_receive_frame(AVCodecContext *avctx, AVFrame *frame)
1466 {
1467 44 AV1DecContext *s = avctx->priv_data;
1468 int ret;
1469
1470 do {
1471
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 2 times.
68 if (!s->current_obu.nb_units) {
1472 66 ret = ff_decode_get_packet(avctx, s->pkt);
1473
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 22 times.
66 if (ret < 0)
1474 44 return ret;
1475
1476 22 ret = ff_cbs_read_packet(s->cbc, &s->current_obu, s->pkt);
1477
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (ret < 0) {
1478 ff_cbs_fragment_reset(&s->current_obu);
1479 av_packet_unref(s->pkt);
1480 av_log(avctx, AV_LOG_ERROR, "Failed to read packet.\n");
1481 return ret;
1482 }
1483
1484 22 s->nb_unit = s->start_unit = 0;
1485 22 av_log(avctx, AV_LOG_DEBUG, "Total OBUs on this packet: %d.\n",
1486 s->current_obu.nb_units);
1487 }
1488
1489 24 ret = av1_receive_frame_internal(avctx, frame);
1490
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 } while (ret == AVERROR(EAGAIN));
1491
1492 return ret;
1493 }
1494
1495 static av_cold void av1_decode_flush(AVCodecContext *avctx)
1496 {
1497 AV1DecContext *s = avctx->priv_data;
1498 AV1RawMetadataITUTT35 itut_t35;
1499
1500 for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++)
1501 av1_frame_unref(&s->ref[i]);
1502
1503 av1_frame_unref(&s->cur_frame);
1504 s->operating_point_idc = 0;
1505 s->nb_unit = s->start_unit = 0;
1506 s->raw_frame_header = NULL;
1507 s->raw_seq = NULL;
1508 s->cll = NULL;
1509 s->mdcv = NULL;
1510 while (av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0)
1511 av_buffer_unref(&itut_t35.payload_ref);
1512
1513 ff_cbs_fragment_reset(&s->current_obu);
1514 ff_cbs_flush(s->cbc);
1515
1516 if (FF_HW_HAS_CB(avctx, flush))
1517 FF_HW_SIMPLE_CALL(avctx, flush);
1518 }
1519
1520 #define OFFSET(x) offsetof(AV1DecContext, x)
1521 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1522 static const AVOption av1_options[] = {
1523 { "operating_point", "Select an operating point of the scalable bitstream",
1524 OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, AV1_MAX_OPERATING_POINTS - 1, VD },
1525 { NULL }
1526 };
1527
1528 static const AVClass av1_class = {
1529 .class_name = "AV1 decoder",
1530 .item_name = av_default_item_name,
1531 .option = av1_options,
1532 .version = LIBAVUTIL_VERSION_INT,
1533 };
1534
1535 const FFCodec ff_av1_decoder = {
1536 .p.name = "av1",
1537 CODEC_LONG_NAME("Alliance for Open Media AV1"),
1538 .p.type = AVMEDIA_TYPE_VIDEO,
1539 .p.id = AV_CODEC_ID_AV1,
1540 .priv_data_size = sizeof(AV1DecContext),
1541 .init = av1_decode_init,
1542 .close = av1_decode_free,
1543 FF_CODEC_RECEIVE_FRAME_CB(av1_receive_frame),
1544 .p.capabilities = AV_CODEC_CAP_DR1,
1545 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1546 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
1547 FF_CODEC_CAP_USES_PROGRESSFRAMES,
1548 .flush = av1_decode_flush,
1549 .p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
1550 .p.priv_class = &av1_class,
1551 .hw_configs = (const AVCodecHWConfigInternal *const []) {
1552 #if CONFIG_AV1_DXVA2_HWACCEL
1553 HWACCEL_DXVA2(av1),
1554 #endif
1555 #if CONFIG_AV1_D3D11VA_HWACCEL
1556 HWACCEL_D3D11VA(av1),
1557 #endif
1558 #if CONFIG_AV1_D3D11VA2_HWACCEL
1559 HWACCEL_D3D11VA2(av1),
1560 #endif
1561 #if CONFIG_AV1_D3D12VA_HWACCEL
1562 HWACCEL_D3D12VA(av1),
1563 #endif
1564 #if CONFIG_AV1_NVDEC_HWACCEL
1565 HWACCEL_NVDEC(av1),
1566 #endif
1567 #if CONFIG_AV1_VAAPI_HWACCEL
1568 HWACCEL_VAAPI(av1),
1569 #endif
1570 #if CONFIG_AV1_VDPAU_HWACCEL
1571 HWACCEL_VDPAU(av1),
1572 #endif
1573 #if CONFIG_AV1_VIDEOTOOLBOX_HWACCEL
1574 HWACCEL_VIDEOTOOLBOX(av1),
1575 #endif
1576 #if CONFIG_AV1_VULKAN_HWACCEL
1577 HWACCEL_VULKAN(av1),
1578 #endif
1579
1580 NULL
1581 },
1582 };
1583