FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/av1dec.c
Date: 2024-05-26 22:00:00
Exec Total Coverage
Lines: 268 878 30.5%
Functions: 12 34 35.3%
Branches: 104 480 21.7%

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/hdr_dynamic_metadata.h"
24 #include "libavutil/film_grain_params.h"
25 #include "libavutil/mastering_display_metadata.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/pixdesc.h"
28 #include "libavutil/opt.h"
29 #include "avcodec.h"
30 #include "av1_parse.h"
31 #include "av1dec.h"
32 #include "atsc_a53.h"
33 #include "bytestream.h"
34 #include "codec_internal.h"
35 #include "decode.h"
36 #include "hwaccel_internal.h"
37 #include "internal.h"
38 #include "itut35.h"
39 #include "hwconfig.h"
40 #include "profiles.h"
41 #include "progressframe.h"
42 #include "refstruct.h"
43
44 /**< same with Div_Lut defined in spec 7.11.3.7 */
45 static const uint16_t div_lut[AV1_DIV_LUT_NUM] = {
46 16384, 16320, 16257, 16194, 16132, 16070, 16009, 15948, 15888, 15828, 15768,
47 15709, 15650, 15592, 15534, 15477, 15420, 15364, 15308, 15252, 15197, 15142,
48 15087, 15033, 14980, 14926, 14873, 14821, 14769, 14717, 14665, 14614, 14564,
49 14513, 14463, 14413, 14364, 14315, 14266, 14218, 14170, 14122, 14075, 14028,
50 13981, 13935, 13888, 13843, 13797, 13752, 13707, 13662, 13618, 13574, 13530,
51 13487, 13443, 13400, 13358, 13315, 13273, 13231, 13190, 13148, 13107, 13066,
52 13026, 12985, 12945, 12906, 12866, 12827, 12788, 12749, 12710, 12672, 12633,
53 12596, 12558, 12520, 12483, 12446, 12409, 12373, 12336, 12300, 12264, 12228,
54 12193, 12157, 12122, 12087, 12053, 12018, 11984, 11950, 11916, 11882, 11848,
55 11815, 11782, 11749, 11716, 11683, 11651, 11619, 11586, 11555, 11523, 11491,
56 11460, 11429, 11398, 11367, 11336, 11305, 11275, 11245, 11215, 11185, 11155,
57 11125, 11096, 11067, 11038, 11009, 10980, 10951, 10923, 10894, 10866, 10838,
58 10810, 10782, 10755, 10727, 10700, 10673, 10645, 10618, 10592, 10565, 10538,
59 10512, 10486, 10460, 10434, 10408, 10382, 10356, 10331, 10305, 10280, 10255,
60 10230, 10205, 10180, 10156, 10131, 10107, 10082, 10058, 10034, 10010, 9986,
61 9963, 9939, 9916, 9892, 9869, 9846, 9823, 9800, 9777, 9754, 9732,
62 9709, 9687, 9664, 9642, 9620, 9598, 9576, 9554, 9533, 9511, 9489,
63 9468, 9447, 9425, 9404, 9383, 9362, 9341, 9321, 9300, 9279, 9259,
64 9239, 9218, 9198, 9178, 9158, 9138, 9118, 9098, 9079, 9059, 9039,
65 9020, 9001, 8981, 8962, 8943, 8924, 8905, 8886, 8867, 8849, 8830,
66 8812, 8793, 8775, 8756, 8738, 8720, 8702, 8684, 8666, 8648, 8630,
67 8613, 8595, 8577, 8560, 8542, 8525, 8508, 8490, 8473, 8456, 8439,
68 8422, 8405, 8389, 8372, 8355, 8339, 8322, 8306, 8289, 8273, 8257,
69 8240, 8224, 8208, 8192
70 };
71
72 static uint32_t inverse_recenter(int r, uint32_t v)
73 {
74 if (v > 2 * r)
75 return v;
76 else if (v & 1)
77 return r - ((v + 1) >> 1);
78 else
79 return r + (v >> 1);
80 }
81
82 static uint32_t decode_unsigned_subexp_with_ref(uint32_t sub_exp,
83 int mx, int r)
84 {
85 if ((r << 1) <= mx) {
86 return inverse_recenter(r, sub_exp);
87 } else {
88 return mx - 1 - inverse_recenter(mx - 1 - r, sub_exp);
89 }
90 }
91
92 static int32_t decode_signed_subexp_with_ref(uint32_t sub_exp, int low,
93 int high, int r)
94 {
95 int32_t x = decode_unsigned_subexp_with_ref(sub_exp, high - low, r - low);
96 return x + low;
97 }
98
99 static void read_global_param(AV1DecContext *s, int type, int ref, int idx)
100 {
101 uint8_t primary_frame, prev_frame;
102 uint32_t abs_bits, prec_bits, round, prec_diff, sub, mx;
103 int32_t r, prev_gm_param;
104
105 primary_frame = s->raw_frame_header->primary_ref_frame;
106 prev_frame = s->raw_frame_header->ref_frame_idx[primary_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 prev_gm_param = s->ref[prev_frame].gm_params[ref][idx];
118
119 if (idx < 2) {
120 if (type == AV1_WARP_MODEL_TRANSLATION) {
121 abs_bits = AV1_GM_ABS_TRANS_ONLY_BITS -
122 !s->raw_frame_header->allow_high_precision_mv;
123 prec_bits = AV1_GM_TRANS_ONLY_PREC_BITS -
124 !s->raw_frame_header->allow_high_precision_mv;
125 } else {
126 abs_bits = AV1_GM_ABS_TRANS_BITS;
127 prec_bits = AV1_GM_TRANS_PREC_BITS;
128 }
129 }
130 round = (idx % 3) == 2 ? (1 << AV1_WARPEDMODEL_PREC_BITS) : 0;
131 prec_diff = AV1_WARPEDMODEL_PREC_BITS - prec_bits;
132 sub = (idx % 3) == 2 ? (1 << prec_bits) : 0;
133 mx = 1 << abs_bits;
134 r = (prev_gm_param >> prec_diff) - sub;
135
136 s->cur_frame.gm_params[ref][idx] =
137 (decode_signed_subexp_with_ref(s->raw_frame_header->gm_params[ref][idx],
138 -mx, mx + 1, r) << prec_diff) + round;
139 }
140
141 static uint64_t round_two(uint64_t x, uint16_t n)
142 {
143 if (n == 0)
144 return x;
145 return ((x + ((uint64_t)1 << (n - 1))) >> n);
146 }
147
148 static int64_t round_two_signed(int64_t x, uint16_t n)
149 {
150 return ((x<0) ? -((int64_t)round_two(-x, n)) : (int64_t)round_two(x, n));
151 }
152
153 /**
154 * Resolve divisor process.
155 * see spec 7.11.3.7
156 */
157 static int16_t resolve_divisor(uint32_t d, uint16_t *shift)
158 {
159 int32_t e, f;
160
161 *shift = av_log2(d);
162 e = d - (1 << (*shift));
163 if (*shift > AV1_DIV_LUT_BITS)
164 f = round_two(e, *shift - AV1_DIV_LUT_BITS);
165 else
166 f = e << (AV1_DIV_LUT_BITS - (*shift));
167
168 *shift += AV1_DIV_LUT_PREC_BITS;
169
170 return div_lut[f];
171 }
172
173 /**
174 * check if global motion params is valid.
175 * see spec 7.11.3.6
176 */
177 static uint8_t get_shear_params_valid(AV1DecContext *s, int idx)
178 {
179 int16_t alpha, beta, gamma, delta, divf, divs;
180 int64_t v, w;
181 int32_t *param = &s->cur_frame.gm_params[idx][0];
182 if (param[2] <= 0)
183 return 0;
184
185 alpha = av_clip_int16(param[2] - (1 << AV1_WARPEDMODEL_PREC_BITS));
186 beta = av_clip_int16(param[3]);
187 divf = resolve_divisor(abs(param[2]), &divs);
188 v = (int64_t)param[4] * (1 << AV1_WARPEDMODEL_PREC_BITS);
189 w = (int64_t)param[3] * param[4];
190 gamma = av_clip_int16((int)round_two_signed((v * divf), divs));
191 delta = av_clip_int16(param[5] - (int)round_two_signed((w * divf), divs) - (1 << AV1_WARPEDMODEL_PREC_BITS));
192
193 alpha = round_two_signed(alpha, AV1_WARP_PARAM_REDUCE_BITS) << AV1_WARP_PARAM_REDUCE_BITS;
194 beta = round_two_signed(beta, AV1_WARP_PARAM_REDUCE_BITS) << AV1_WARP_PARAM_REDUCE_BITS;
195 gamma = round_two_signed(gamma, AV1_WARP_PARAM_REDUCE_BITS) << AV1_WARP_PARAM_REDUCE_BITS;
196 delta = round_two_signed(delta, AV1_WARP_PARAM_REDUCE_BITS) << AV1_WARP_PARAM_REDUCE_BITS;
197
198 if ((4 * abs(alpha) + 7 * abs(beta)) >= (1 << AV1_WARPEDMODEL_PREC_BITS) ||
199 (4 * abs(gamma) + 4 * abs(delta)) >= (1 << AV1_WARPEDMODEL_PREC_BITS))
200 return 0;
201
202 return 1;
203 }
204
205 /**
206 * update gm type/params, since cbs already implemented part of this function,
207 * so we don't need to full implement spec.
208 */
209 static void global_motion_params(AV1DecContext *s)
210 {
211 const AV1RawFrameHeader *header = s->raw_frame_header;
212 int type, ref;
213
214 for (ref = AV1_REF_FRAME_LAST; ref <= AV1_REF_FRAME_ALTREF; ref++) {
215 s->cur_frame.gm_type[ref] = AV1_WARP_MODEL_IDENTITY;
216 for (int i = 0; i < 6; i++)
217 s->cur_frame.gm_params[ref][i] = (i % 3 == 2) ?
218 1 << AV1_WARPEDMODEL_PREC_BITS : 0;
219 }
220 if (header->frame_type == AV1_FRAME_KEY ||
221 header->frame_type == AV1_FRAME_INTRA_ONLY)
222 return;
223
224 for (ref = AV1_REF_FRAME_LAST; ref <= AV1_REF_FRAME_ALTREF; ref++) {
225 if (header->is_global[ref]) {
226 if (header->is_rot_zoom[ref]) {
227 type = AV1_WARP_MODEL_ROTZOOM;
228 } else {
229 type = header->is_translation[ref] ? AV1_WARP_MODEL_TRANSLATION
230 : AV1_WARP_MODEL_AFFINE;
231 }
232 } else {
233 type = AV1_WARP_MODEL_IDENTITY;
234 }
235 s->cur_frame.gm_type[ref] = type;
236
237 if (type >= AV1_WARP_MODEL_ROTZOOM) {
238 read_global_param(s, type, ref, 2);
239 read_global_param(s, type, ref, 3);
240 if (type == AV1_WARP_MODEL_AFFINE) {
241 read_global_param(s, type, ref, 4);
242 read_global_param(s, type, ref, 5);
243 } else {
244 s->cur_frame.gm_params[ref][4] = -s->cur_frame.gm_params[ref][3];
245 s->cur_frame.gm_params[ref][5] = s->cur_frame.gm_params[ref][2];
246 }
247 }
248 if (type >= AV1_WARP_MODEL_TRANSLATION) {
249 read_global_param(s, type, ref, 0);
250 read_global_param(s, type, ref, 1);
251 }
252 if (type <= AV1_WARP_MODEL_AFFINE) {
253 s->cur_frame.gm_invalid[ref] = !get_shear_params_valid(s, ref);
254 }
255 }
256 }
257
258 static int get_relative_dist(const AV1RawSequenceHeader *seq,
259 unsigned int a, unsigned int b)
260 {
261 unsigned int diff = a - b;
262 unsigned int m = 1 << seq->order_hint_bits_minus_1;
263 return (diff & (m - 1)) - (diff & m);
264 }
265
266 static void skip_mode_params(AV1DecContext *s)
267 {
268 const AV1RawFrameHeader *header = s->raw_frame_header;
269 const AV1RawSequenceHeader *seq = s->raw_seq;
270
271 int forward_idx, backward_idx;
272 int forward_hint, backward_hint;
273 int second_forward_idx, second_forward_hint;
274 int ref_hint, dist, i;
275
276 if (header->frame_type == AV1_FRAME_KEY ||
277 header->frame_type == AV1_FRAME_INTRA_ONLY ||
278 !header->reference_select || !seq->enable_order_hint)
279 return;
280
281 forward_idx = -1;
282 backward_idx = -1;
283 for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
284 ref_hint = s->ref[header->ref_frame_idx[i]].raw_frame_header->order_hint;
285 dist = get_relative_dist(seq, ref_hint, header->order_hint);
286 if (dist < 0) {
287 if (forward_idx < 0 ||
288 get_relative_dist(seq, ref_hint, forward_hint) > 0) {
289 forward_idx = i;
290 forward_hint = ref_hint;
291 }
292 } else if (dist > 0) {
293 if (backward_idx < 0 ||
294 get_relative_dist(seq, ref_hint, backward_hint) < 0) {
295 backward_idx = i;
296 backward_hint = ref_hint;
297 }
298 }
299 }
300
301 if (forward_idx < 0) {
302 return;
303 } else if (backward_idx >= 0) {
304 s->cur_frame.skip_mode_frame_idx[0] =
305 AV1_REF_FRAME_LAST + FFMIN(forward_idx, backward_idx);
306 s->cur_frame.skip_mode_frame_idx[1] =
307 AV1_REF_FRAME_LAST + FFMAX(forward_idx, backward_idx);
308 return;
309 }
310
311 second_forward_idx = -1;
312 for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
313 ref_hint = s->ref[header->ref_frame_idx[i]].raw_frame_header->order_hint;
314 if (get_relative_dist(seq, ref_hint, forward_hint) < 0) {
315 if (second_forward_idx < 0 ||
316 get_relative_dist(seq, ref_hint, second_forward_hint) > 0) {
317 second_forward_idx = i;
318 second_forward_hint = ref_hint;
319 }
320 }
321 }
322
323 if (second_forward_idx < 0)
324 return;
325
326 s->cur_frame.skip_mode_frame_idx[0] =
327 AV1_REF_FRAME_LAST + FFMIN(forward_idx, second_forward_idx);
328 s->cur_frame.skip_mode_frame_idx[1] =
329 AV1_REF_FRAME_LAST + FFMAX(forward_idx, second_forward_idx);
330 }
331
332 static void coded_lossless_param(AV1DecContext *s)
333 {
334 const AV1RawFrameHeader *header = s->raw_frame_header;
335 int i;
336
337 if (header->delta_q_y_dc || header->delta_q_u_ac ||
338 header->delta_q_u_dc || header->delta_q_v_ac ||
339 header->delta_q_v_dc) {
340 s->cur_frame.coded_lossless = 0;
341 return;
342 }
343
344 s->cur_frame.coded_lossless = 1;
345 for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
346 int qindex;
347 if (header->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) {
348 qindex = (header->base_q_idx +
349 header->feature_value[i][AV1_SEG_LVL_ALT_Q]);
350 } else {
351 qindex = header->base_q_idx;
352 }
353 qindex = av_clip_uintp2(qindex, 8);
354
355 if (qindex) {
356 s->cur_frame.coded_lossless = 0;
357 return;
358 }
359 }
360 }
361
362 static void order_hint_info(AV1DecContext *s)
363 {
364 const AV1RawFrameHeader *header = s->raw_frame_header;
365 const AV1RawSequenceHeader *seq = s->raw_seq;
366 AV1Frame *frame = &s->cur_frame;
367
368 frame->order_hint = header->order_hint;
369
370 for (int i = 0; i < AV1_REFS_PER_FRAME; i++) {
371 int ref_name = i + AV1_REF_FRAME_LAST;
372 int ref_slot = header->ref_frame_idx[i];
373 int ref_order_hint = s->ref[ref_slot].order_hint;
374
375 frame->order_hints[ref_name] = ref_order_hint;
376 if (!seq->enable_order_hint) {
377 frame->ref_frame_sign_bias[ref_name] = 0;
378 } else {
379 frame->ref_frame_sign_bias[ref_name] =
380 get_relative_dist(seq, ref_order_hint,
381 frame->order_hint) > 0;
382 }
383 }
384 }
385
386 static void load_grain_params(AV1DecContext *s)
387 {
388 const AV1RawFrameHeader *header = s->raw_frame_header;
389 const AV1RawFilmGrainParams *film_grain = &header->film_grain, *src;
390 AV1RawFilmGrainParams *dst = &s->cur_frame.film_grain;
391
392 if (!film_grain->apply_grain)
393 return;
394
395 if (film_grain->update_grain) {
396 memcpy(dst, film_grain, sizeof(*dst));
397 return;
398 }
399
400 src = &s->ref[film_grain->film_grain_params_ref_idx].film_grain;
401
402 memcpy(dst, src, sizeof(*dst));
403 dst->grain_seed = film_grain->grain_seed;
404 }
405
406 24 static int init_tile_data(AV1DecContext *s)
407
408 {
409 24 int cur_tile_num =
410 24 s->raw_frame_header->tile_cols * s->raw_frame_header->tile_rows;
411
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (s->tile_num < cur_tile_num) {
412 24 int ret = av_reallocp_array(&s->tile_group_info, cur_tile_num,
413 sizeof(TileGroupInfo));
414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (ret < 0) {
415 s->tile_num = 0;
416 return ret;
417 }
418 }
419 24 s->tile_num = cur_tile_num;
420
421 24 return 0;
422 }
423
424 32 static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_group)
425 {
426 32 AV1DecContext *s = avctx->priv_data;
427 GetByteContext gb;
428 uint16_t tile_num, tile_row, tile_col;
429 32 uint32_t size = 0, size_bytes = 0;
430
431 32 bytestream2_init(&gb, tile_group->tile_data.data,
432 32 tile_group->tile_data.data_size);
433 32 s->tg_start = tile_group->tg_start;
434 32 s->tg_end = tile_group->tg_end;
435
436
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++) {
437 47 tile_row = tile_num / s->raw_frame_header->tile_cols;
438 47 tile_col = tile_num % s->raw_frame_header->tile_cols;
439
440
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 15 times.
47 if (tile_num == tile_group->tg_end) {
441 32 s->tile_group_info[tile_num].tile_size = bytestream2_get_bytes_left(&gb);
442 32 s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
443 32 s->tile_group_info[tile_num].tile_row = tile_row;
444 32 s->tile_group_info[tile_num].tile_column = tile_col;
445 32 return 0;
446 }
447 15 size_bytes = s->raw_frame_header->tile_size_bytes_minus1 + 1;
448
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
15 if (bytestream2_get_bytes_left(&gb) < size_bytes)
449 return AVERROR_INVALIDDATA;
450 15 size = 0;
451
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 15 times.
53 for (int i = 0; i < size_bytes; i++)
452 38 size |= bytestream2_get_byteu(&gb) << 8 * i;
453
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
15 if (bytestream2_get_bytes_left(&gb) <= size)
454 return AVERROR_INVALIDDATA;
455 15 size++;
456
457 15 s->tile_group_info[tile_num].tile_size = size;
458 15 s->tile_group_info[tile_num].tile_offset = bytestream2_tell(&gb);
459 15 s->tile_group_info[tile_num].tile_row = tile_row;
460 15 s->tile_group_info[tile_num].tile_column = tile_col;
461
462 15 bytestream2_skipu(&gb, size);
463 }
464
465 return 0;
466
467 }
468
469 25 static enum AVPixelFormat get_sw_pixel_format(void *logctx,
470 const AV1RawSequenceHeader *seq)
471 {
472 int bit_depth;
473 25 enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
474
475
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
25 if (seq->seq_profile == 2 && seq->color_config.high_bitdepth)
476 bit_depth = seq->color_config.twelve_bit ? 12 : 10;
477
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 else if (seq->seq_profile <= 2)
478
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 24 times.
25 bit_depth = seq->color_config.high_bitdepth ? 10 : 8;
479 else {
480 av_log(logctx, AV_LOG_ERROR,
481 "Unknown AV1 profile %d.\n", seq->seq_profile);
482 return AV_PIX_FMT_NONE;
483 }
484
485
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 if (!seq->color_config.mono_chrome) {
486 // 4:4:4 x:0 y:0, 4:2:2 x:1 y:0, 4:2:0 x:1 y:1
487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if (seq->color_config.subsampling_x == 0 &&
488 seq->color_config.subsampling_y == 0) {
489 if (bit_depth == 8)
490 pix_fmt = AV_PIX_FMT_YUV444P;
491 else if (bit_depth == 10)
492 pix_fmt = AV_PIX_FMT_YUV444P10;
493 else if (bit_depth == 12)
494 pix_fmt = AV_PIX_FMT_YUV444P12;
495 else
496 av_assert0(0);
497
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 } else if (seq->color_config.subsampling_x == 1 &&
498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 seq->color_config.subsampling_y == 0) {
499 if (bit_depth == 8)
500 pix_fmt = AV_PIX_FMT_YUV422P;
501 else if (bit_depth == 10)
502 pix_fmt = AV_PIX_FMT_YUV422P10;
503 else if (bit_depth == 12)
504 pix_fmt = AV_PIX_FMT_YUV422P12;
505 else
506 av_assert0(0);
507
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 } else if (seq->color_config.subsampling_x == 1 &&
508
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 seq->color_config.subsampling_y == 1) {
509
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (bit_depth == 8)
510 24 pix_fmt = AV_PIX_FMT_YUV420P;
511
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 else if (bit_depth == 10)
512 1 pix_fmt = AV_PIX_FMT_YUV420P10;
513 else if (bit_depth == 12)
514 pix_fmt = AV_PIX_FMT_YUV420P12;
515 else
516 av_assert0(0);
517 }
518 } else {
519 if (bit_depth == 8)
520 pix_fmt = AV_PIX_FMT_GRAY8;
521 else if (bit_depth == 10)
522 pix_fmt = AV_PIX_FMT_GRAY10;
523 else if (bit_depth == 12)
524 pix_fmt = AV_PIX_FMT_GRAY12;
525 else
526 av_assert0(0);
527 }
528
529 25 return pix_fmt;
530 }
531
532 static int get_pixel_format(AVCodecContext *avctx)
533 {
534 AV1DecContext *s = avctx->priv_data;
535 const AV1RawSequenceHeader *seq = s->raw_seq;
536 int ret;
537 enum AVPixelFormat pix_fmt = get_sw_pixel_format(avctx, seq);
538 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
539 CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
540 CONFIG_AV1_D3D12VA_HWACCEL + \
541 CONFIG_AV1_NVDEC_HWACCEL + \
542 CONFIG_AV1_VAAPI_HWACCEL + \
543 CONFIG_AV1_VDPAU_HWACCEL + \
544 CONFIG_AV1_VULKAN_HWACCEL)
545 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
546
547 if (pix_fmt == AV_PIX_FMT_NONE)
548 return -1;
549
550 switch (pix_fmt) {
551 case AV_PIX_FMT_YUV420P:
552 #if CONFIG_AV1_DXVA2_HWACCEL
553 *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
554 #endif
555 #if CONFIG_AV1_D3D11VA_HWACCEL
556 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
557 *fmtp++ = AV_PIX_FMT_D3D11;
558 #endif
559 #if CONFIG_AV1_D3D12VA_HWACCEL
560 *fmtp++ = AV_PIX_FMT_D3D12;
561 #endif
562 #if CONFIG_AV1_NVDEC_HWACCEL
563 *fmtp++ = AV_PIX_FMT_CUDA;
564 #endif
565 #if CONFIG_AV1_VAAPI_HWACCEL
566 *fmtp++ = AV_PIX_FMT_VAAPI;
567 #endif
568 #if CONFIG_AV1_VDPAU_HWACCEL
569 *fmtp++ = AV_PIX_FMT_VDPAU;
570 #endif
571 #if CONFIG_AV1_VULKAN_HWACCEL
572 *fmtp++ = AV_PIX_FMT_VULKAN;
573 #endif
574 break;
575 case AV_PIX_FMT_YUV420P10:
576 #if CONFIG_AV1_DXVA2_HWACCEL
577 *fmtp++ = AV_PIX_FMT_DXVA2_VLD;
578 #endif
579 #if CONFIG_AV1_D3D11VA_HWACCEL
580 *fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
581 *fmtp++ = AV_PIX_FMT_D3D11;
582 #endif
583 #if CONFIG_AV1_D3D12VA_HWACCEL
584 *fmtp++ = AV_PIX_FMT_D3D12;
585 #endif
586 #if CONFIG_AV1_NVDEC_HWACCEL
587 *fmtp++ = AV_PIX_FMT_CUDA;
588 #endif
589 #if CONFIG_AV1_VAAPI_HWACCEL
590 *fmtp++ = AV_PIX_FMT_VAAPI;
591 #endif
592 #if CONFIG_AV1_VDPAU_HWACCEL
593 *fmtp++ = AV_PIX_FMT_VDPAU;
594 #endif
595 #if CONFIG_AV1_VULKAN_HWACCEL
596 *fmtp++ = AV_PIX_FMT_VULKAN;
597 #endif
598 break;
599 case AV_PIX_FMT_YUV420P12:
600 #if CONFIG_AV1_VULKAN_HWACCEL
601 *fmtp++ = AV_PIX_FMT_VULKAN;
602 #endif
603 break;
604 case AV_PIX_FMT_YUV422P:
605 #if CONFIG_AV1_VULKAN_HWACCEL
606 *fmtp++ = AV_PIX_FMT_VULKAN;
607 #endif
608 break;
609 case AV_PIX_FMT_YUV422P10:
610 #if CONFIG_AV1_VULKAN_HWACCEL
611 *fmtp++ = AV_PIX_FMT_VULKAN;
612 #endif
613 break;
614 case AV_PIX_FMT_YUV422P12:
615 #if CONFIG_AV1_VULKAN_HWACCEL
616 *fmtp++ = AV_PIX_FMT_VULKAN;
617 #endif
618 break;
619 case AV_PIX_FMT_YUV444P:
620 #if CONFIG_AV1_VULKAN_HWACCEL
621 *fmtp++ = AV_PIX_FMT_VULKAN;
622 #endif
623 break;
624 case AV_PIX_FMT_YUV444P10:
625 #if CONFIG_AV1_VULKAN_HWACCEL
626 *fmtp++ = AV_PIX_FMT_VULKAN;
627 #endif
628 break;
629 case AV_PIX_FMT_YUV444P12:
630 #if CONFIG_AV1_VULKAN_HWACCEL
631 *fmtp++ = AV_PIX_FMT_VULKAN;
632 #endif
633 break;
634 case AV_PIX_FMT_GRAY8:
635 #if CONFIG_AV1_NVDEC_HWACCEL
636 *fmtp++ = AV_PIX_FMT_CUDA;
637 #endif
638 break;
639 case AV_PIX_FMT_GRAY10:
640 #if CONFIG_AV1_NVDEC_HWACCEL
641 *fmtp++ = AV_PIX_FMT_CUDA;
642 #endif
643 break;
644 }
645
646 *fmtp++ = pix_fmt;
647 *fmtp = AV_PIX_FMT_NONE;
648
649 for (int i = 0; pix_fmts[i] != pix_fmt; i++)
650 if (pix_fmts[i] == avctx->pix_fmt) {
651 s->pix_fmt = pix_fmt;
652 return 1;
653 }
654
655 ret = ff_get_format(avctx, pix_fmts);
656
657 /**
658 * check if the HW accel is inited correctly. If not, return un-implemented.
659 * Since now the av1 decoder doesn't support native decode, if it will be
660 * implemented in the future, need remove this check.
661 */
662 if (!avctx->hwaccel) {
663 av_log(avctx, AV_LOG_ERROR, "Your platform doesn't support"
664 " hardware accelerated AV1 decoding.\n");
665 avctx->pix_fmt = AV_PIX_FMT_NONE;
666 return AVERROR(ENOSYS);
667 }
668
669 s->pix_fmt = pix_fmt;
670 avctx->pix_fmt = ret;
671
672 av_log(avctx, AV_LOG_DEBUG, "AV1 decode get format: %s.\n",
673 av_get_pix_fmt_name(avctx->pix_fmt));
674
675 return 0;
676 }
677
678 249 static void av1_frame_unref(AV1Frame *f)
679 {
680 249 ff_progress_frame_unref(&f->pf);
681 249 ff_refstruct_unref(&f->hwaccel_picture_private);
682 249 ff_refstruct_unref(&f->header_ref);
683 249 f->raw_frame_header = NULL;
684 249 f->spatial_id = f->temporal_id = 0;
685 249 memset(f->skip_mode_frame_idx, 0,
686 2 * sizeof(uint8_t));
687 249 memset(&f->film_grain, 0, sizeof(f->film_grain));
688 249 f->coded_lossless = 0;
689 249 }
690
691 178 static void av1_frame_replace(AV1Frame *dst, const AV1Frame *src)
692 {
693 av_assert1(dst != src);
694
695 178 ff_refstruct_replace(&dst->header_ref, src->header_ref);
696
697 178 dst->raw_frame_header = src->raw_frame_header;
698
699 178 ff_progress_frame_replace(&dst->pf, &src->pf);
700
701 178 ff_refstruct_replace(&dst->hwaccel_picture_private,
702 178 src->hwaccel_picture_private);
703
704 178 dst->spatial_id = src->spatial_id;
705 178 dst->temporal_id = src->temporal_id;
706 178 memcpy(dst->gm_invalid,
707 178 src->gm_invalid,
708 AV1_NUM_REF_FRAMES * sizeof(uint8_t));
709 178 memcpy(dst->gm_type,
710 178 src->gm_type,
711 AV1_NUM_REF_FRAMES * sizeof(uint8_t));
712 178 memcpy(dst->gm_params,
713 178 src->gm_params,
714 AV1_NUM_REF_FRAMES * 6 * sizeof(int32_t));
715 178 memcpy(dst->skip_mode_frame_idx,
716 178 src->skip_mode_frame_idx,
717 2 * sizeof(uint8_t));
718 178 memcpy(&dst->film_grain,
719 178 &src->film_grain,
720 sizeof(dst->film_grain));
721 178 dst->coded_lossless = src->coded_lossless;
722
723 178 dst->order_hint = src->order_hint;
724 178 memcpy(dst->ref_frame_sign_bias, src->ref_frame_sign_bias,
725 sizeof(dst->ref_frame_sign_bias));
726 178 memcpy(dst->order_hints, src->order_hints,
727 sizeof(dst->order_hints));
728
729 178 dst->force_integer_mv = src->force_integer_mv;
730 178 }
731
732 25 static av_cold int av1_decode_free(AVCodecContext *avctx)
733 {
734 25 AV1DecContext *s = avctx->priv_data;
735 AV1RawMetadataITUTT35 itut_t35;
736
737
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 25 times.
225 for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++)
738 200 av1_frame_unref(&s->ref[i]);
739 25 av1_frame_unref(&s->cur_frame);
740 25 av_buffer_unref(&s->seq_data_ref);
741 25 ff_refstruct_unref(&s->seq_ref);
742 25 ff_refstruct_unref(&s->header_ref);
743 25 ff_refstruct_unref(&s->cll_ref);
744 25 ff_refstruct_unref(&s->mdcv_ref);
745 25 av_freep(&s->tile_group_info);
746
747
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
25 while (s->itut_t35_fifo && av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0)
748 av_buffer_unref(&itut_t35.payload_ref);
749 25 av_fifo_freep2(&s->itut_t35_fifo);
750
751 25 ff_cbs_fragment_free(&s->current_obu);
752 25 ff_cbs_close(&s->cbc);
753 25 ff_dovi_ctx_unref(&s->dovi);
754
755 25 return 0;
756 }
757
758 25 static int set_context_with_sequence(AVCodecContext *avctx,
759 const AV1RawSequenceHeader *seq)
760 {
761 25 int width = seq->max_frame_width_minus_1 + 1;
762 25 int height = seq->max_frame_height_minus_1 + 1;
763
764 25 avctx->profile = seq->seq_profile;
765 25 avctx->level = seq->seq_level_idx[0];
766
767 25 avctx->color_range =
768
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 seq->color_config.color_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
769 25 avctx->color_primaries = seq->color_config.color_primaries;
770 25 avctx->colorspace = seq->color_config.matrix_coefficients;
771 25 avctx->color_trc = seq->color_config.transfer_characteristics;
772
773
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
25 switch (seq->color_config.chroma_sample_position) {
774 case AV1_CSP_VERTICAL:
775 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
776 break;
777 case AV1_CSP_COLOCATED:
778 avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
779 break;
780 }
781
782
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 23 times.
25 if (seq->film_grain_params_present)
783 2 avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
784 else
785 23 avctx->properties &= ~FF_CODEC_PROPERTY_FILM_GRAIN;
786
787
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
25 if (avctx->width != width || avctx->height != height) {
788 1 int ret = ff_set_dimensions(avctx, width, height);
789
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
790 return ret;
791 }
792
793
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 21 times.
25 if (seq->timing_info_present_flag)
794 4 avctx->framerate = ff_av1_framerate(1LL + seq->timing_info.num_ticks_per_picture_minus_1,
795 4 seq->timing_info.num_units_in_display_tick,
796 4 seq->timing_info.time_scale);
797
798
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 if (avctx->pix_fmt == AV_PIX_FMT_NONE)
799 25 avctx->pix_fmt = get_sw_pixel_format(avctx, seq);
800
801 25 return 0;
802 }
803
804 static int update_context_with_frame_header(AVCodecContext *avctx,
805 const AV1RawFrameHeader *header)
806 {
807 AVRational aspect_ratio;
808 int width = header->frame_width_minus_1 + 1;
809 int height = header->frame_height_minus_1 + 1;
810 int r_width = header->render_width_minus_1 + 1;
811 int r_height = header->render_height_minus_1 + 1;
812 int ret;
813
814 if (avctx->width != width || avctx->height != height) {
815 ret = ff_set_dimensions(avctx, width, height);
816 if (ret < 0)
817 return ret;
818 }
819
820 av_reduce(&aspect_ratio.num, &aspect_ratio.den,
821 (int64_t)height * r_width,
822 (int64_t)width * r_height,
823 INT_MAX);
824
825 if (av_cmp_q(avctx->sample_aspect_ratio, aspect_ratio)) {
826 ret = ff_set_sar(avctx, aspect_ratio);
827 if (ret < 0)
828 return ret;
829 }
830
831 return 0;
832 }
833
834 static const CodedBitstreamUnitType decompose_unit_types[] = {
835 AV1_OBU_FRAME,
836 AV1_OBU_FRAME_HEADER,
837 AV1_OBU_METADATA,
838 AV1_OBU_REDUNDANT_FRAME_HEADER,
839 AV1_OBU_SEQUENCE_HEADER,
840 AV1_OBU_TEMPORAL_DELIMITER,
841 AV1_OBU_TILE_GROUP,
842 };
843
844 25 static av_cold int av1_decode_init(AVCodecContext *avctx)
845 {
846 25 AV1DecContext *s = avctx->priv_data;
847 AV1RawSequenceHeader *seq;
848 const AVPacketSideData *sd;
849 int ret;
850
851 25 s->avctx = avctx;
852 25 s->pkt = avctx->internal->in_pkt;
853 25 s->pix_fmt = AV_PIX_FMT_NONE;
854
855 25 ret = ff_cbs_init(&s->cbc, AV_CODEC_ID_AV1, avctx);
856
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if (ret < 0)
857 return ret;
858
859 25 s->cbc->decompose_unit_types = decompose_unit_types;
860 25 s->cbc->nb_decompose_unit_types = FF_ARRAY_ELEMS(decompose_unit_types);
861
862 25 s->itut_t35_fifo = av_fifo_alloc2(1, sizeof(AV1RawMetadataITUTT35),
863 AV_FIFO_FLAG_AUTO_GROW);
864
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if (!s->itut_t35_fifo)
865 return AVERROR(ENOMEM);
866
867 25 av_opt_set_int(s->cbc->priv_data, "operating_point", s->operating_point, 0);
868
869
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
25 if (avctx->extradata && avctx->extradata_size) {
870 5 ret = ff_cbs_read_extradata_from_codec(s->cbc,
871 &s->current_obu,
872 avctx);
873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (ret < 0) {
874 av_log(avctx, AV_LOG_WARNING, "Failed to read extradata.\n");
875 goto end;
876 }
877
878 5 seq = ((CodedBitstreamAV1Context *)(s->cbc->priv_data))->sequence_header;
879
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (!seq) {
880 2 av_log(avctx, AV_LOG_WARNING, "No sequence header available.\n");
881 2 goto end;
882 }
883
884 3 ret = set_context_with_sequence(avctx, seq);
885
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (ret < 0) {
886 av_log(avctx, AV_LOG_WARNING, "Failed to set decoder context.\n");
887 goto end;
888 }
889
890 3 end:
891 5 ff_cbs_fragment_reset(&s->current_obu);
892 }
893
894 25 s->dovi.logctx = avctx;
895 25 s->dovi.cfg.dv_profile = 10; // default for AV1
896 25 sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF);
897
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
25 if (sd && sd->size >= sizeof(s->dovi.cfg))
898 s->dovi.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data;
899
900 25 return ret;
901 }
902
903 static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f)
904 {
905 AV1DecContext *s = avctx->priv_data;
906 AV1RawFrameHeader *header= s->raw_frame_header;
907 AVFrame *frame;
908 int ret;
909
910 ret = update_context_with_frame_header(avctx, header);
911 if (ret < 0) {
912 av_log(avctx, AV_LOG_ERROR, "Failed to update context with frame header\n");
913 return ret;
914 }
915
916 ret = ff_progress_frame_get_buffer(avctx, &f->pf, AV_GET_BUFFER_FLAG_REF);
917 if (ret < 0)
918 goto fail;
919
920 frame = f->f;
921 if (header->frame_type == AV1_FRAME_KEY)
922 frame->flags |= AV_FRAME_FLAG_KEY;
923 else
924 frame->flags &= ~AV_FRAME_FLAG_KEY;
925
926 switch (header->frame_type) {
927 case AV1_FRAME_KEY:
928 case AV1_FRAME_INTRA_ONLY:
929 frame->pict_type = AV_PICTURE_TYPE_I;
930 break;
931 case AV1_FRAME_INTER:
932 frame->pict_type = AV_PICTURE_TYPE_P;
933 break;
934 case AV1_FRAME_SWITCH:
935 frame->pict_type = AV_PICTURE_TYPE_SP;
936 break;
937 }
938
939 ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private);
940 if (ret < 0)
941 goto fail;
942
943 return 0;
944
945 fail:
946 av1_frame_unref(f);
947 return ret;
948 }
949
950 static int export_itut_t35(AVCodecContext *avctx, AVFrame *frame,
951 const AV1RawMetadataITUTT35 *itut_t35)
952 {
953 GetByteContext gb;
954 AV1DecContext *s = avctx->priv_data;
955 int ret, provider_code;
956
957 bytestream2_init(&gb, itut_t35->payload, itut_t35->payload_size);
958
959 provider_code = bytestream2_get_be16(&gb);
960 switch (provider_code) {
961 case ITU_T_T35_PROVIDER_CODE_ATSC: {
962 uint32_t user_identifier = bytestream2_get_be32(&gb);
963 switch (user_identifier) {
964 case MKBETAG('G', 'A', '9', '4'): { // closed captions
965 AVBufferRef *buf = NULL;
966
967 ret = ff_parse_a53_cc(&buf, gb.buffer, bytestream2_get_bytes_left(&gb));
968 if (ret < 0)
969 return ret;
970 if (!ret)
971 break;
972
973 ret = ff_frame_new_side_data_from_buf(avctx, frame, AV_FRAME_DATA_A53_CC, &buf, NULL);
974 if (ret < 0)
975 return ret;
976
977 avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
978 break;
979 }
980 default: // ignore unsupported identifiers
981 break;
982 }
983 break;
984 }
985 case ITU_T_T35_PROVIDER_CODE_SMTPE: {
986 AVDynamicHDRPlus *hdrplus;
987 int provider_oriented_code = bytestream2_get_be16(&gb);
988 int application_identifier = bytestream2_get_byte(&gb);
989
990 if (itut_t35->itu_t_t35_country_code != ITU_T_T35_COUNTRY_CODE_US ||
991 provider_oriented_code != 1 || application_identifier != 4)
992 break;
993
994 hdrplus = av_dynamic_hdr_plus_create_side_data(frame);
995 if (!hdrplus)
996 return AVERROR(ENOMEM);
997
998 ret = av_dynamic_hdr_plus_from_t35(hdrplus, gb.buffer,
999 bytestream2_get_bytes_left(&gb));
1000 if (ret < 0)
1001 return ret;
1002 break;
1003 }
1004 case ITU_T_T35_PROVIDER_CODE_DOLBY: {
1005 int provider_oriented_code = bytestream2_get_be32(&gb);
1006 if (itut_t35->itu_t_t35_country_code != ITU_T_T35_COUNTRY_CODE_US ||
1007 provider_oriented_code != 0x800)
1008 break;
1009
1010 ret = ff_dovi_rpu_parse(&s->dovi, gb.buffer, gb.buffer_end - gb.buffer,
1011 avctx->err_recognition);
1012 if (ret < 0) {
1013 av_log(avctx, AV_LOG_WARNING, "Error parsing DOVI OBU.\n");
1014 break; // ignore
1015 }
1016
1017 ret = ff_dovi_attach_side_data(&s->dovi, frame);
1018 if (ret < 0)
1019 return ret;
1020 break;
1021 }
1022 default: // ignore unsupported provider codes
1023 break;
1024 }
1025
1026 return 0;
1027 }
1028
1029 static int export_metadata(AVCodecContext *avctx, AVFrame *frame)
1030 {
1031 AV1DecContext *s = avctx->priv_data;
1032 AV1RawMetadataITUTT35 itut_t35;
1033 int ret = 0;
1034
1035 if (s->mdcv) {
1036 AVMasteringDisplayMetadata *mastering;
1037
1038 ret = ff_decode_mastering_display_new(avctx, frame, &mastering);
1039 if (ret < 0)
1040 return ret;
1041
1042 if (mastering) {
1043 for (int i = 0; i < 3; i++) {
1044 mastering->display_primaries[i][0] = av_make_q(s->mdcv->primary_chromaticity_x[i], 1 << 16);
1045 mastering->display_primaries[i][1] = av_make_q(s->mdcv->primary_chromaticity_y[i], 1 << 16);
1046 }
1047 mastering->white_point[0] = av_make_q(s->mdcv->white_point_chromaticity_x, 1 << 16);
1048 mastering->white_point[1] = av_make_q(s->mdcv->white_point_chromaticity_y, 1 << 16);
1049
1050 mastering->max_luminance = av_make_q(s->mdcv->luminance_max, 1 << 8);
1051 mastering->min_luminance = av_make_q(s->mdcv->luminance_min, 1 << 14);
1052
1053 mastering->has_primaries = 1;
1054 mastering->has_luminance = 1;
1055 }
1056 }
1057
1058 if (s->cll) {
1059 AVContentLightMetadata *light;
1060
1061 ret = ff_decode_content_light_new(avctx, frame, &light);
1062 if (ret < 0)
1063 return ret;
1064
1065 if (light) {
1066 light->MaxCLL = s->cll->max_cll;
1067 light->MaxFALL = s->cll->max_fall;
1068 }
1069 }
1070
1071 while (av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0) {
1072 if (ret >= 0)
1073 ret = export_itut_t35(avctx, frame, &itut_t35);
1074 av_buffer_unref(&itut_t35.payload_ref);
1075 }
1076
1077 return ret;
1078 }
1079
1080 static int export_film_grain(AVCodecContext *avctx, AVFrame *frame)
1081 {
1082 AV1DecContext *s = avctx->priv_data;
1083 const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
1084 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(frame->format);
1085 AVFilmGrainParams *fgp;
1086 AVFilmGrainAOMParams *aom;
1087
1088 av_assert0(pixdesc);
1089 if (!film_grain->apply_grain)
1090 return 0;
1091
1092 fgp = av_film_grain_params_create_side_data(frame);
1093 if (!fgp)
1094 return AVERROR(ENOMEM);
1095
1096 fgp->type = AV_FILM_GRAIN_PARAMS_AV1;
1097 fgp->seed = film_grain->grain_seed;
1098 fgp->width = frame->width;
1099 fgp->height = frame->height;
1100 fgp->color_range = frame->color_range;
1101 fgp->color_primaries = frame->color_primaries;
1102 fgp->color_trc = frame->color_trc;
1103 fgp->color_space = frame->colorspace;
1104 fgp->subsampling_x = pixdesc->log2_chroma_w;
1105 fgp->subsampling_y = pixdesc->log2_chroma_h;
1106
1107 aom = &fgp->codec.aom;
1108 aom->chroma_scaling_from_luma = film_grain->chroma_scaling_from_luma;
1109 aom->scaling_shift = film_grain->grain_scaling_minus_8 + 8;
1110 aom->ar_coeff_lag = film_grain->ar_coeff_lag;
1111 aom->ar_coeff_shift = film_grain->ar_coeff_shift_minus_6 + 6;
1112 aom->grain_scale_shift = film_grain->grain_scale_shift;
1113 aom->overlap_flag = film_grain->overlap_flag;
1114 aom->limit_output_range = film_grain->clip_to_restricted_range;
1115
1116 aom->num_y_points = film_grain->num_y_points;
1117 for (int i = 0; i < film_grain->num_y_points; i++) {
1118 aom->y_points[i][0] = film_grain->point_y_value[i];
1119 aom->y_points[i][1] = film_grain->point_y_scaling[i];
1120 }
1121 aom->num_uv_points[0] = film_grain->num_cb_points;
1122 for (int i = 0; i < film_grain->num_cb_points; i++) {
1123 aom->uv_points[0][i][0] = film_grain->point_cb_value[i];
1124 aom->uv_points[0][i][1] = film_grain->point_cb_scaling[i];
1125 }
1126 aom->num_uv_points[1] = film_grain->num_cr_points;
1127 for (int i = 0; i < film_grain->num_cr_points; i++) {
1128 aom->uv_points[1][i][0] = film_grain->point_cr_value[i];
1129 aom->uv_points[1][i][1] = film_grain->point_cr_scaling[i];
1130 }
1131
1132 for (int i = 0; i < 24; i++) {
1133 aom->ar_coeffs_y[i] = film_grain->ar_coeffs_y_plus_128[i] - 128;
1134 }
1135 for (int i = 0; i < 25; i++) {
1136 aom->ar_coeffs_uv[0][i] = film_grain->ar_coeffs_cb_plus_128[i] - 128;
1137 aom->ar_coeffs_uv[1][i] = film_grain->ar_coeffs_cr_plus_128[i] - 128;
1138 }
1139
1140 aom->uv_mult[0] = film_grain->cb_mult;
1141 aom->uv_mult[1] = film_grain->cr_mult;
1142 aom->uv_mult_luma[0] = film_grain->cb_luma_mult;
1143 aom->uv_mult_luma[1] = film_grain->cr_luma_mult;
1144 aom->uv_offset[0] = film_grain->cb_offset;
1145 aom->uv_offset[1] = film_grain->cr_offset;
1146
1147 return 0;
1148 }
1149
1150 static int set_output_frame(AVCodecContext *avctx, AVFrame *frame)
1151 {
1152 AV1DecContext *s = avctx->priv_data;
1153 const AVFrame *srcframe = s->cur_frame.f;
1154 AVPacket *pkt = s->pkt;
1155 int ret;
1156
1157 // TODO: all layers
1158 if (s->operating_point_idc &&
1159 av_log2(s->operating_point_idc >> 8) > s->cur_frame.spatial_id)
1160 return 0;
1161
1162 ret = av_frame_ref(frame, srcframe);
1163 if (ret < 0)
1164 return ret;
1165
1166 ret = export_metadata(avctx, frame);
1167 if (ret < 0) {
1168 av_frame_unref(frame);
1169 return ret;
1170 }
1171
1172 if (avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) {
1173 ret = export_film_grain(avctx, frame);
1174 if (ret < 0) {
1175 av_frame_unref(frame);
1176 return ret;
1177 }
1178 }
1179
1180 frame->pts = pkt->pts;
1181 frame->pkt_dts = pkt->dts;
1182 #if FF_API_FRAME_PKT
1183 FF_DISABLE_DEPRECATION_WARNINGS
1184 frame->pkt_size = pkt->size;
1185 frame->pkt_pos = pkt->pos;
1186 FF_ENABLE_DEPRECATION_WARNINGS
1187 #endif
1188
1189 av_packet_unref(pkt);
1190
1191 return 0;
1192 }
1193
1194 24 static void update_reference_list(AVCodecContext *avctx)
1195 {
1196 24 AV1DecContext *s = avctx->priv_data;
1197 24 const AV1RawFrameHeader *header = s->raw_frame_header;
1198
1199
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 24 times.
216 for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
1200
2/2
✓ Branch 0 taken 178 times.
✓ Branch 1 taken 14 times.
192 if (header->refresh_frame_flags & (1 << i))
1201 178 av1_frame_replace(&s->ref[i], &s->cur_frame);
1202 }
1203 24 }
1204
1205 24 static int get_current_frame(AVCodecContext *avctx)
1206 {
1207 24 AV1DecContext *s = avctx->priv_data;
1208 int ret;
1209
1210 24 av1_frame_unref(&s->cur_frame);
1211
1212 24 s->cur_frame.header_ref = ff_refstruct_ref(s->header_ref);
1213
1214 24 s->cur_frame.raw_frame_header = s->raw_frame_header;
1215
1216 24 ret = init_tile_data(s);
1217
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (ret < 0) {
1218 av_log(avctx, AV_LOG_ERROR, "Failed to init tile data.\n");
1219 return ret;
1220 }
1221
1222
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if ((avctx->skip_frame >= AVDISCARD_NONINTRA &&
1223
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 22 times.
24 (s->raw_frame_header->frame_type != AV1_FRAME_KEY &&
1224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 s->raw_frame_header->frame_type != AV1_FRAME_INTRA_ONLY)) ||
1225
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 (avctx->skip_frame >= AVDISCARD_NONKEY &&
1226
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 s->raw_frame_header->frame_type != AV1_FRAME_KEY) ||
1227
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 avctx->skip_frame >= AVDISCARD_ALL)
1228 24 return 0;
1229
1230 if (s->pix_fmt == AV_PIX_FMT_NONE) {
1231 ret = get_pixel_format(avctx);
1232 if (ret < 0) {
1233 av_log(avctx, AV_LOG_ERROR, "Failed to get pixel format.\n");
1234 return ret;
1235 }
1236
1237 if (!ret && FF_HW_HAS_CB(avctx, decode_params)) {
1238 ret = FF_HW_CALL(avctx, decode_params, AV1_OBU_SEQUENCE_HEADER,
1239 s->seq_data_ref->data, s->seq_data_ref->size);
1240 if (ret < 0) {
1241 av_log(avctx, AV_LOG_ERROR, "HW accel decode params fail.\n");
1242 return ret;
1243 }
1244 }
1245 }
1246
1247 ret = av1_frame_alloc(avctx, &s->cur_frame);
1248 if (ret < 0) {
1249 av_log(avctx, AV_LOG_ERROR,
1250 "Failed to allocate space for current frame.\n");
1251 return ret;
1252 }
1253
1254 global_motion_params(s);
1255 skip_mode_params(s);
1256 coded_lossless_param(s);
1257 order_hint_info(s);
1258 load_grain_params(s);
1259
1260 s->cur_frame.force_integer_mv =
1261 s->raw_frame_header->force_integer_mv ||
1262 s->raw_frame_header->frame_type == AV1_FRAME_KEY ||
1263 s->raw_frame_header->frame_type == AV1_FRAME_INTRA_ONLY;
1264
1265 return ret;
1266 }
1267
1268 24 static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
1269 {
1270 24 AV1DecContext *s = avctx->priv_data;
1271 24 AV1RawTileGroup *raw_tile_group = NULL;
1272 24 int i = 0, ret;
1273
1274
1/2
✓ Branch 0 taken 83 times.
✗ Branch 1 not taken.
83 for (i = s->nb_unit; i < s->current_obu.nb_units; i++) {
1275 83 CodedBitstreamUnit *unit = &s->current_obu.units[i];
1276 83 AV1RawOBU *obu = unit->content;
1277 const AV1RawOBUHeader *header;
1278
1279 83 av_log(avctx, AV_LOG_DEBUG, "OBU idx:%d, type:%d, content available:%d.\n", i, unit->type, !!obu);
1280
1281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
83 if (unit->type == AV1_OBU_TILE_LIST) {
1282 av_log(avctx, AV_LOG_ERROR, "Large scale tile decoding is unsupported.\n");
1283 ret = AVERROR_PATCHWELCOME;
1284 goto end;
1285 }
1286
1287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
83 if (!obu)
1288 continue;
1289
1290 83 header = &obu->header;
1291
1292
5/7
✓ 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 taken 4 times.
✗ Branch 6 not taken.
83 switch (unit->type) {
1293 22 case AV1_OBU_SEQUENCE_HEADER:
1294 22 ret = av_buffer_replace(&s->seq_data_ref, unit->data_ref);
1295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (ret < 0)
1296 goto end;
1297
1298 22 s->seq_data_ref->data = unit->data;
1299 22 s->seq_data_ref->size = unit->data_size;
1300 22 ff_refstruct_replace(&s->seq_ref, unit->content_ref);
1301
1302 22 s->raw_seq = &obu->obu.sequence_header;
1303
1304 22 ret = set_context_with_sequence(avctx, s->raw_seq);
1305
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (ret < 0) {
1306 av_log(avctx, AV_LOG_ERROR, "Failed to set context.\n");
1307 s->raw_seq = NULL;
1308 goto end;
1309 }
1310
1311 22 s->operating_point_idc = s->raw_seq->operating_point_idc[s->operating_point];
1312
1313 22 s->pix_fmt = AV_PIX_FMT_NONE;
1314
1315 22 break;
1316 case AV1_OBU_REDUNDANT_FRAME_HEADER:
1317 if (s->raw_frame_header)
1318 break;
1319 // fall-through
1320 case AV1_OBU_FRAME:
1321 case AV1_OBU_FRAME_HEADER:
1322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (!s->raw_seq) {
1323 av_log(avctx, AV_LOG_ERROR, "Missing Sequence Header.\n");
1324 ret = AVERROR_INVALIDDATA;
1325 goto end;
1326 }
1327
1328 24 ff_refstruct_replace(&s->header_ref, unit->content_ref);
1329
1330
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 5 times.
24 if (unit->type == AV1_OBU_FRAME)
1331 19 s->raw_frame_header = &obu->obu.frame.header;
1332 else
1333 5 s->raw_frame_header = &obu->obu.frame_header;
1334
1335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (s->raw_frame_header->show_existing_frame) {
1336 av1_frame_replace(&s->cur_frame,
1337 &s->ref[s->raw_frame_header->frame_to_show_map_idx]);
1338
1339 update_reference_list(avctx);
1340
1341 if (s->cur_frame.f) {
1342 ret = set_output_frame(avctx, frame);
1343 if (ret < 0) {
1344 av_log(avctx, AV_LOG_ERROR, "Set output frame error.\n");
1345 goto end;
1346 }
1347 }
1348
1349 s->raw_frame_header = NULL;
1350 i++;
1351 ret = 0;
1352
1353 goto end;
1354 }
1355
1356 24 ret = get_current_frame(avctx);
1357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (ret < 0) {
1358 av_log(avctx, AV_LOG_ERROR, "Get current frame error\n");
1359 goto end;
1360 }
1361
1362 24 s->cur_frame.spatial_id = header->spatial_id;
1363 24 s->cur_frame.temporal_id = header->temporal_id;
1364
1365
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) {
1366 ret = FF_HW_CALL(avctx, start_frame, 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
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 19 times.
24 if (unit->type != AV1_OBU_FRAME)
1373 5 break;
1374 // fall-through
1375 case AV1_OBU_TILE_GROUP:
1376
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 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
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 13 times.
32 if (unit->type == AV1_OBU_FRAME)
1383 19 raw_tile_group = &obu->obu.frame.tile_group;
1384 else
1385 13 raw_tile_group = &obu->obu.tile_group;
1386
1387 32 ret = get_tiles_info(avctx, raw_tile_group);
1388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if (ret < 0)
1389 goto end;
1390
1391
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) {
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 32 break;
1401 20 case AV1_OBU_TILE_LIST:
1402 case AV1_OBU_TEMPORAL_DELIMITER:
1403 case AV1_OBU_PADDING:
1404 20 break;
1405 4 case AV1_OBU_METADATA:
1406
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) {
1407 2 case AV1_METADATA_TYPE_HDR_CLL:
1408 2 ff_refstruct_replace(&s->cll_ref, unit->content_ref);
1409 2 s->cll = &obu->obu.metadata.metadata.hdr_cll;
1410 2 break;
1411 2 case AV1_METADATA_TYPE_HDR_MDCV:
1412 2 ff_refstruct_replace(&s->mdcv_ref, unit->content_ref);
1413 2 s->mdcv = &obu->obu.metadata.metadata.hdr_mdcv;
1414 2 break;
1415 case AV1_METADATA_TYPE_ITUT_T35: {
1416 AV1RawMetadataITUTT35 itut_t35;
1417 memcpy(&itut_t35, &obu->obu.metadata.metadata.itut_t35, sizeof(itut_t35));
1418 itut_t35.payload_ref = av_buffer_ref(obu->obu.metadata.metadata.itut_t35.payload_ref);
1419 if (!itut_t35.payload_ref) {
1420 ret = AVERROR(ENOMEM);
1421 goto end;
1422 }
1423 ret = av_fifo_write(s->itut_t35_fifo, &itut_t35, 1);
1424 if (ret < 0) {
1425 av_buffer_unref(&itut_t35.payload_ref);
1426 goto end;
1427 }
1428 break;
1429 }
1430 default:
1431 break;
1432 }
1433 4 break;
1434 default:
1435 av_log(avctx, AV_LOG_DEBUG,
1436 "Unknown obu type: %d (%"SIZE_SPECIFIER" bits).\n",
1437 unit->type, unit->data_size);
1438 }
1439
1440
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)) {
1441 24 int show_frame = s->raw_frame_header->show_frame;
1442
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) {
1443 ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
1444 if (ret < 0) {
1445 av_log(avctx, AV_LOG_ERROR, "HW accel end frame fail.\n");
1446 goto end;
1447 }
1448 }
1449
1450 24 update_reference_list(avctx);
1451
1452 24 raw_tile_group = NULL;
1453 24 s->raw_frame_header = NULL;
1454
1455
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (show_frame) {
1456 // cur_frame.f needn't exist due to skip_frame.
1457
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (s->cur_frame.f) {
1458 ret = set_output_frame(avctx, frame);
1459 if (ret < 0) {
1460 av_log(avctx, AV_LOG_ERROR, "Set output frame error\n");
1461 goto end;
1462 }
1463 }
1464 24 i++;
1465 24 ret = 0;
1466 24 goto end;
1467 }
1468 }
1469 }
1470
1471 ret = AVERROR(EAGAIN);
1472 24 end:
1473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 av_assert0(i <= s->current_obu.nb_units);
1474 24 s->nb_unit = i;
1475
1476
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) {
1477
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (ret < 0)
1478 s->raw_frame_header = NULL;
1479 22 av_packet_unref(s->pkt);
1480 22 ff_cbs_fragment_reset(&s->current_obu);
1481 22 s->nb_unit = 0;
1482 }
1483
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])
1484 24 ret = AVERROR(EAGAIN);
1485
1486 24 return ret;
1487 }
1488
1489 44 static int av1_receive_frame(AVCodecContext *avctx, AVFrame *frame)
1490 {
1491 44 AV1DecContext *s = avctx->priv_data;
1492 int ret;
1493
1494 do {
1495
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 2 times.
68 if (!s->current_obu.nb_units) {
1496 66 ret = ff_decode_get_packet(avctx, s->pkt);
1497
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 22 times.
66 if (ret < 0)
1498 44 return ret;
1499
1500 22 ret = ff_cbs_read_packet(s->cbc, &s->current_obu, s->pkt);
1501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (ret < 0) {
1502 ff_cbs_fragment_reset(&s->current_obu);
1503 av_packet_unref(s->pkt);
1504 av_log(avctx, AV_LOG_ERROR, "Failed to read packet.\n");
1505 return ret;
1506 }
1507
1508 22 s->nb_unit = 0;
1509 22 av_log(avctx, AV_LOG_DEBUG, "Total OBUs on this packet: %d.\n",
1510 s->current_obu.nb_units);
1511 }
1512
1513 24 ret = av1_receive_frame_internal(avctx, frame);
1514
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 } while (ret == AVERROR(EAGAIN));
1515
1516 return ret;
1517 }
1518
1519 static void av1_decode_flush(AVCodecContext *avctx)
1520 {
1521 AV1DecContext *s = avctx->priv_data;
1522 AV1RawMetadataITUTT35 itut_t35;
1523
1524 for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++)
1525 av1_frame_unref(&s->ref[i]);
1526
1527 av1_frame_unref(&s->cur_frame);
1528 s->operating_point_idc = 0;
1529 s->nb_unit = 0;
1530 s->raw_frame_header = NULL;
1531 s->raw_seq = NULL;
1532 s->cll = NULL;
1533 s->mdcv = NULL;
1534 while (av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0)
1535 av_buffer_unref(&itut_t35.payload_ref);
1536
1537 ff_cbs_fragment_reset(&s->current_obu);
1538 ff_cbs_flush(s->cbc);
1539
1540 if (FF_HW_HAS_CB(avctx, flush))
1541 FF_HW_SIMPLE_CALL(avctx, flush);
1542 }
1543
1544 #define OFFSET(x) offsetof(AV1DecContext, x)
1545 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1546 static const AVOption av1_options[] = {
1547 { "operating_point", "Select an operating point of the scalable bitstream",
1548 OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, AV1_MAX_OPERATING_POINTS - 1, VD },
1549 { NULL }
1550 };
1551
1552 static const AVClass av1_class = {
1553 .class_name = "AV1 decoder",
1554 .item_name = av_default_item_name,
1555 .option = av1_options,
1556 .version = LIBAVUTIL_VERSION_INT,
1557 };
1558
1559 const FFCodec ff_av1_decoder = {
1560 .p.name = "av1",
1561 CODEC_LONG_NAME("Alliance for Open Media AV1"),
1562 .p.type = AVMEDIA_TYPE_VIDEO,
1563 .p.id = AV_CODEC_ID_AV1,
1564 .priv_data_size = sizeof(AV1DecContext),
1565 .init = av1_decode_init,
1566 .close = av1_decode_free,
1567 FF_CODEC_RECEIVE_FRAME_CB(av1_receive_frame),
1568 .p.capabilities = AV_CODEC_CAP_DR1,
1569 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1570 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
1571 FF_CODEC_CAP_USES_PROGRESSFRAMES,
1572 .flush = av1_decode_flush,
1573 .p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
1574 .p.priv_class = &av1_class,
1575 .hw_configs = (const AVCodecHWConfigInternal *const []) {
1576 #if CONFIG_AV1_DXVA2_HWACCEL
1577 HWACCEL_DXVA2(av1),
1578 #endif
1579 #if CONFIG_AV1_D3D11VA_HWACCEL
1580 HWACCEL_D3D11VA(av1),
1581 #endif
1582 #if CONFIG_AV1_D3D11VA2_HWACCEL
1583 HWACCEL_D3D11VA2(av1),
1584 #endif
1585 #if CONFIG_AV1_D3D12VA_HWACCEL
1586 HWACCEL_D3D12VA(av1),
1587 #endif
1588 #if CONFIG_AV1_NVDEC_HWACCEL
1589 HWACCEL_NVDEC(av1),
1590 #endif
1591 #if CONFIG_AV1_VAAPI_HWACCEL
1592 HWACCEL_VAAPI(av1),
1593 #endif
1594 #if CONFIG_AV1_VDPAU_HWACCEL
1595 HWACCEL_VDPAU(av1),
1596 #endif
1597 #if CONFIG_AV1_VULKAN_HWACCEL
1598 HWACCEL_VULKAN(av1),
1599 #endif
1600
1601 NULL
1602 },
1603 };
1604