FFmpeg
Loading...
Searching...
No Matches
vaapi_encode_av1.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Intel Corporation
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 <va/va.h>
22#include <va/va_enc_av1.h>
23
24#include "libavutil/pixdesc.h"
25#include "libavutil/opt.h"
27
28#include "cbs_av1.h"
29#include "put_bits.h"
30#include "codec_internal.h"
31#include "av1_levels.h"
32#include "vaapi_encode.h"
33
34#define AV1_MAX_QUANT 255
35
40
41typedef struct VAAPIEncodeAV1Context {
43 AV1RawOBU sh; /**< sequence header.*/
44 AV1RawOBU fh; /**< frame header.*/
45 AV1RawOBU mh[4]; /**< metadata header.*/
46 int nb_mh;
49 VAConfigAttribValEncAV1 attr;
50 VAConfigAttribValEncAV1Ext1 attr_ext1;
51 VAConfigAttribValEncAV1Ext2 attr_ext2;
52
53 char sh_data[MAX_PARAM_BUFFER_SIZE]; /**< coded sequence header data. */
54 size_t sh_data_len; /**< bit length of sh_data. */
55 char fh_data[MAX_PARAM_BUFFER_SIZE]; /**< coded frame header data. */
56 size_t fh_data_len; /**< bit length of fh_data. */
57
58 uint8_t uniform_tile;
68
73
77
78 /** bit positions in current frame header */
83
84 /** user options */
86 int level;
87 int tier;
91
93 PutBitContext *pbc, int length,
94 const char *str, const int *subscripts,
96{
98 int position;
99
100 position = put_bits_count(pbc);
101 av_assert0(position >= length);
102
103 if (!strcmp(str, "base_q_idx"))
104 priv->qindex_offset = position - length;
105 else if (!strcmp(str, "loop_filter_level[0]"))
106 priv->loopfilter_offset = position - length;
107 else if (!strcmp(str, "cdef_damping_minus_3"))
108 priv->cdef_start_offset = position - length;
109 else if (!strcmp(str, "cdef_uv_sec_strength[i]"))
110 priv->cdef_param_size = position - priv->cdef_start_offset;
111}
112
114{
115 FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
116 VAAPIEncodeAV1Context *priv = avctx->priv_data;
117
118 // Surfaces must be aligned to superblock boundaries.
119 base_ctx->surface_width = FFALIGN(avctx->width, priv->use_128x128_superblock ? 128 : 64);
120 base_ctx->surface_height = FFALIGN(avctx->height, priv->use_128x128_superblock ? 128 : 64);
121
122 return 0;
123}
124
126{
128 VAAPIEncodeAV1Context *priv = avctx->priv_data;
129 int ret;
130
131 ret = ff_cbs_init(&priv->cbc, AV_CODEC_ID_AV1, avctx);
132 if (ret < 0)
133 return ret;
134 priv->cbc->trace_enable = 1;
136 priv->cbc->trace_context = ctx;
138
139 if (ctx->rc_mode->quality) {
140 priv->q_idx_p = av_clip(ctx->rc_quality, 0, AV1_MAX_QUANT);
141 if (fabs(avctx->i_quant_factor) > 0.0)
142 priv->q_idx_idr =
143 av_clip((fabs(avctx->i_quant_factor) * priv->q_idx_p +
144 avctx->i_quant_offset) + 0.5,
145 0, AV1_MAX_QUANT);
146 else
147 priv->q_idx_idr = priv->q_idx_p;
148
149 if (fabs(avctx->b_quant_factor) > 0.0)
150 priv->q_idx_b =
151 av_clip((fabs(avctx->b_quant_factor) * priv->q_idx_p +
152 avctx->b_quant_offset) + 0.5,
153 0, AV1_MAX_QUANT);
154 else
155 priv->q_idx_b = priv->q_idx_p;
156 } else {
157 /** Arbitrary value */
158 priv->q_idx_idr = priv->q_idx_p = priv->q_idx_b = 128;
159 }
160
161 ctx->roi_quant_range = AV1_MAX_QUANT;
162
163 return 0;
164}
165
168 uint8_t type,
169 void *obu_unit)
170{
171 int ret;
172
173 ret = ff_cbs_insert_unit_content(au, -1,
174 type, obu_unit, NULL);
175 if (ret < 0) {
176 av_log(avctx, AV_LOG_ERROR, "Failed to add OBU unit: "
177 "type = %d.\n", type);
178 return ret;
179 }
180
181 return 0;
182}
183
185 char *data, size_t *data_len,
187{
188 VAAPIEncodeAV1Context *priv = avctx->priv_data;
189 int ret;
190
191 ret = ff_cbs_write_fragment_data(priv->cbc, bs);
192 if (ret < 0) {
193 av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
194 return ret;
195 }
196
197 if ((size_t)8 * MAX_PARAM_BUFFER_SIZE < 8 * bs->data_size - bs->data_bit_padding) {
198 av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
199 "%zu < %zu.\n", (size_t)8 * MAX_PARAM_BUFFER_SIZE,
200 8 * bs->data_size - bs->data_bit_padding);
201 return AVERROR(ENOSPC);
202 }
203
204 memcpy(data, bs->data, bs->data_size);
205 *data_len = 8 * bs->data_size - bs->data_bit_padding;
206
207 return 0;
208}
209
210static int tile_log2(int blkSize, int target) {
211 int k;
212 for (k = 0; (blkSize << k) < target; k++);
213 return k;
214}
215
217{
218 VAAPIEncodeAV1Context *priv = avctx->priv_data;
219 int mi_cols, mi_rows, sb_shift, sb_size;
220 int max_tile_area_sb, max_tile_area_sb_varied;
221 int tile_width_sb, tile_height_sb, widest_tile_sb;
222 int tile_cols, tile_rows;
223 int min_log2_tiles;
224 int i;
225
226 if (priv->tile_cols > AV1_MAX_TILE_COLS ||
228 av_log(avctx, AV_LOG_ERROR, "Invalid tile number %dx%d, should less than %dx%d.\n",
230 return AVERROR(EINVAL);
231 }
232
233 mi_cols = 2 * ((avctx->width + 7) >> 3);
234 mi_rows = 2 * ((avctx->height + 7) >> 3);
235 priv->sb_cols = priv->use_128x128_superblock ?
236 ((mi_cols + 31) >> 5) : ((mi_cols + 15) >> 4);
237 priv->sb_rows = priv->use_128x128_superblock ?
238 ((mi_rows + 31) >> 5) : ((mi_rows + 15) >> 4);
239 sb_shift = priv->use_128x128_superblock ? 5 : 4;
240 sb_size = sb_shift + 2;
241 priv->max_tile_width_sb = AV1_MAX_TILE_WIDTH >> sb_size;
242 max_tile_area_sb = AV1_MAX_TILE_AREA >> (2 * sb_size);
243
247 min_log2_tiles = FFMAX(priv->min_log2_tile_cols,
248 tile_log2(max_tile_area_sb, priv->sb_rows * priv->sb_cols));
249
250 tile_cols = av_clip(priv->tile_cols, (priv->sb_cols + priv->max_tile_width_sb - 1) / priv->max_tile_width_sb, priv->sb_cols);
251
252 if (!priv->tile_cols)
253 priv->tile_cols = tile_cols;
254 else if (priv->tile_cols != tile_cols){
255 av_log(avctx, AV_LOG_ERROR, "Invalid tile cols %d, should be in range of %d~%d\n",
256 priv->tile_cols,
257 (priv->sb_cols + priv->max_tile_width_sb - 1) / priv->max_tile_width_sb,
258 priv->sb_cols);
259 return AVERROR(EINVAL);
260 }
261
262 priv->tile_cols_log2 = tile_log2(1, priv->tile_cols);
263 tile_width_sb = (priv->sb_cols + (1 << priv->tile_cols_log2) - 1) >>
264 priv->tile_cols_log2;
265
266 if (priv->tile_rows > priv->sb_rows) {
267 av_log(avctx, AV_LOG_ERROR, "Invalid tile rows %d, should be less than %d.\n",
268 priv->tile_rows, priv->sb_rows);
269 return AVERROR(EINVAL);
270 }
271
272 /** Try user setting tile rows number first. */
273 tile_rows = priv->tile_rows ? priv->tile_rows : 1;
274 for (; tile_rows <= priv->sb_rows && tile_rows <= AV1_MAX_TILE_ROWS; tile_rows++) {
275 /** try uniformed tile. */
277 if ((priv->sb_cols + tile_width_sb - 1) / tile_width_sb == priv->tile_cols) {
278 for (i = 0; i < priv->tile_cols - 1; i++)
279 priv->width_in_sbs_minus_1[i] = tile_width_sb - 1;
280 priv->width_in_sbs_minus_1[i] = priv->sb_cols - (priv->tile_cols - 1) * tile_width_sb - 1;
281
282 tile_height_sb = (priv->sb_rows + (1 << priv->tile_rows_log2) - 1) >>
283 priv->tile_rows_log2;
284
285 if ((priv->sb_rows + tile_height_sb - 1) / tile_height_sb == tile_rows &&
286 tile_height_sb <= max_tile_area_sb / tile_width_sb) {
287 for (i = 0; i < tile_rows - 1; i++)
288 priv->height_in_sbs_minus_1[i] = tile_height_sb - 1;
289 priv->height_in_sbs_minus_1[i] = priv->sb_rows - (tile_rows - 1) * tile_height_sb - 1;
290
291 priv->uniform_tile = 1;
292 priv->min_log2_tile_rows = FFMAX(min_log2_tiles - priv->tile_cols_log2, 0);
293
294 break;
295 }
296 }
297
298 /** try non-uniformed tile. */
299 widest_tile_sb = 0;
300 for (i = 0; i < priv->tile_cols; i++) {
301 priv->width_in_sbs_minus_1[i] = (i + 1) * priv->sb_cols / priv->tile_cols - i * priv->sb_cols / priv->tile_cols - 1;
302 widest_tile_sb = FFMAX(widest_tile_sb, priv->width_in_sbs_minus_1[i] + 1);
303 }
304
305 if (min_log2_tiles)
306 max_tile_area_sb_varied = (priv->sb_rows * priv->sb_cols) >> (min_log2_tiles + 1);
307 else
308 max_tile_area_sb_varied = priv->sb_rows * priv->sb_cols;
309 priv->max_tile_height_sb = FFMAX(1, max_tile_area_sb_varied / widest_tile_sb);
310
311 if (tile_rows == av_clip(tile_rows, (priv->sb_rows + priv->max_tile_height_sb - 1) / priv->max_tile_height_sb, priv->sb_rows)) {
312 for (i = 0; i < tile_rows; i++)
313 priv->height_in_sbs_minus_1[i] = (i + 1) * priv->sb_rows / tile_rows - i * priv->sb_rows / tile_rows - 1;
314
315 break;
316 }
317
318 /** Return invalid parameter if explicit tile rows is set. */
319 if (priv->tile_rows) {
320 av_log(avctx, AV_LOG_ERROR, "Invalid tile rows %d.\n", priv->tile_rows);
321 return AVERROR(EINVAL);
322 }
323 }
324
325 priv->tile_rows = tile_rows;
326 av_log(avctx, AV_LOG_DEBUG, "Setting tile cols/rows to %d/%d.\n",
327 priv->tile_cols, priv->tile_rows);
328
329 /** check if tile cols/rows is supported by driver. */
330 if (priv->attr_ext2.bits.max_tile_num_minus1) {
331 if ((priv->tile_cols * priv->tile_rows - 1) > priv->attr_ext2.bits.max_tile_num_minus1) {
332 av_log(avctx, AV_LOG_ERROR, "Unsupported tile num %d * %d = %d by driver, "
333 "should be at most %d.\n", priv->tile_cols, priv->tile_rows,
334 priv->tile_cols * priv->tile_rows,
335 priv->attr_ext2.bits.max_tile_num_minus1 + 1);
336 return AVERROR(EINVAL);
337 }
338 }
339
340 /** check if tile group numbers is valid. */
341 if (priv->tile_groups > priv->tile_cols * priv->tile_rows) {
342 av_log(avctx, AV_LOG_WARNING, "Invalid tile groups number %d, "
343 "correct to %d.\n", priv->tile_groups, priv->tile_cols * priv->tile_rows);
344 priv->tile_groups = priv->tile_cols * priv->tile_rows;
345 }
346
347 return 0;
348}
349
351 char *data, size_t *data_len)
352{
353 VAAPIEncodeAV1Context *priv = avctx->priv_data;
354
355 memcpy(data, &priv->sh_data, MAX_PARAM_BUFFER_SIZE * sizeof(char));
356 *data_len = priv->sh_data_len;
357
358 return 0;
359}
360
362{
363 FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
365 VAAPIEncodeAV1Context *priv = avctx->priv_data;
366 AV1RawOBU *sh_obu = &priv->sh;
368 VAEncSequenceParameterBufferAV1 *vseq = ctx->codec_sequence_params;
371 int ret;
372
373 memset(sh_obu, 0, sizeof(*sh_obu));
375
378
379 sh->seq_profile = avctx->profile;
384 sh->max_frame_width_minus_1 = avctx->width - 1;
385 sh->max_frame_height_minus_1 = avctx->height - 1;
386 sh->seq_tier[0] = priv->tier;
387 /** enable order hint and reserve maximum 8 bits for it by default. */
388 sh->enable_order_hint = 1;
390
392 .high_bitdepth = desc->comp[0].depth == 8 ? 0 : 1,
393 .color_primaries = avctx->color_primaries,
394 .transfer_characteristics = avctx->color_trc,
395 .matrix_coefficients = avctx->colorspace,
396 .color_description_present_flag = (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
400 .subsampling_x = desc->log2_chroma_w,
401 .subsampling_y = desc->log2_chroma_h,
402 };
403
404 switch (avctx->chroma_sample_location) {
407 break;
410 break;
411 default:
413 break;
414 }
415
416 if (avctx->level != AV_LEVEL_UNKNOWN) {
417 sh->seq_level_idx[0] = avctx->level;
418 } else {
420 float framerate;
421
422 if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
423 framerate = avctx->framerate.num / avctx->framerate.den;
424 else
425 framerate = 0;
426
427 level = ff_av1_guess_level(avctx->bit_rate, priv->tier,
428 base_ctx->surface_width, base_ctx->surface_height,
429 priv->tile_rows * priv->tile_cols,
430 priv->tile_cols, framerate);
431 if (level) {
432 av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name);
433 sh->seq_level_idx[0] = level->level_idx;
434 } else {
435 av_log(avctx, AV_LOG_VERBOSE, "Stream will not conform to "
436 "any normal level, using maximum parameters level by default.\n");
437 sh->seq_level_idx[0] = 31;
438 sh->seq_tier[0] = 1;
439 }
440 }
441 vseq->seq_profile = sh->seq_profile;
442 vseq->seq_level_idx = sh->seq_level_idx[0];
443 vseq->seq_tier = sh->seq_tier[0];
444 vseq->order_hint_bits_minus_1 = sh->order_hint_bits_minus_1;
445 vseq->intra_period = base_ctx->gop_size;
446 vseq->ip_period = base_ctx->b_per_p + 1;
447
448 vseq->seq_fields.bits.enable_order_hint = sh->enable_order_hint;
449 vseq->seq_fields.bits.enable_cdef = sh->enable_cdef = 1;
450
451 if (!(ctx->va_rc_mode & VA_RC_CQP))
452 vseq->bits_per_second = ctx->va_bit_rate;
453
455 if (ret < 0)
456 goto end;
457
458 ret = vaapi_encode_av1_write_obu(avctx, priv->sh_data, &priv->sh_data_len, obu);
459 if (ret < 0)
460 goto end;
461
462end:
463 ff_cbs_fragment_reset(obu);
464 return ret;
465}
466
467/**
468 * With VA_RC_CQP the driver does not patch the packed frame header, so
469 * choose the in-loop filter parameters here from base_q_idx and pass the
470 * same values in the picture parameters, keeping the two in sync for
471 * drivers which use the application-provided header. Drivers which
472 * generate the frame header themselves may choose their own values. In
473 * other modes the driver writes them into the header at the bit offsets
474 * we pass.
475 */
477 VAEncPictureParameterBufferAV1 *vpic)
478{
479 const int q = fh->base_q_idx;
480 /*
481 * Deblocking thresholds scale with the filter level, and the
482 * blocking to remove scales with the quantizer step size, which
483 * grows faster than linearly with base_q_idx, so use a quadratic
484 * of base_q_idx. It reaches the maximum level 63 at 224.
485 */
486 const int level = q > 32 ? FFMIN((q - 32) * (q - 32) * 7 >> 12, 63) : 0;
487 const int pri = q >> 5;
488 /*
489 * Four { primary strength, secondary strength code } CDEF candidates;
490 * the hardware picks one per 64x64 block. Put the main candidate
491 * first, and "off" keeps fine texture from being smoothed.
492 */
493 const int cdef[4][2] = {
494 { pri, 1 },
495 { 0, 0 },
496 { pri >> 1, 1 },
497 { pri << 1, 2 },
498 };
499
500 fh->loop_filter_level[0] = vpic->filter_level[0] = level;
501 fh->loop_filter_level[1] = vpic->filter_level[1] = level;
502 fh->loop_filter_level[2] = vpic->filter_level_u = (level + 1) >> 1;
503 fh->loop_filter_level[3] = vpic->filter_level_v = (level + 1) >> 1;
504
505 /* low base_q_idx: CDEF gains little, keep strengths at 0 */
506 if (!pri)
507 return;
508
509 fh->cdef_damping_minus_3 = vpic->cdef_damping_minus_3 = q >> 6;
510 fh->cdef_bits = vpic->cdef_bits = 2;
511 /* iHD rejects different luma and chroma CDEF strengths on DG2 */
512 for (int i = 0; i < 4; i++) {
513 fh->cdef_y_pri_strength[i] = fh->cdef_uv_pri_strength[i] = cdef[i][0];
514 fh->cdef_y_sec_strength[i] = fh->cdef_uv_sec_strength[i] = cdef[i][1];
515 vpic->cdef_y_strengths[i] = vpic->cdef_uv_strengths[i] =
516 (cdef[i][0] << 2) | cdef[i][1];
517 }
518}
519
522{
524 VAAPIEncodeAV1Context *priv = avctx->priv_data;
525 VAAPIEncodePicture *vaapi_pic = pic->priv;
527 AV1RawOBU *fh_obu = &priv->fh;
528 AV1RawFrameHeader *fh = &fh_obu->obu.frame.header;
529 VAEncPictureParameterBufferAV1 *vpic = vaapi_pic->codec_picture_params;
531 CodedBitstreamAV1Context *cbctx = priv->cbc->priv_data;
534 int slot, i;
535 int ret;
536 static const int8_t default_loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME] =
537 { 1, 0, 0, 0, -1, 0, -1, -1 };
538
539 memset(fh_obu, 0, sizeof(*fh_obu));
540 vaapi_pic->nb_slices = priv->tile_groups;
541 vaapi_pic->non_independent_frame = pic->encode_order < pic->display_order;
543 fh_obu->header.obu_has_size_field = 1;
544
545 switch (pic->type) {
547 av_assert0(pic->nb_refs[0] == 0 || pic->nb_refs[1]);
549 fh->refresh_frame_flags = 0xFF;
550 fh->base_q_idx = priv->q_idx_idr;
551 hpic->slot = 0;
552 hpic->last_idr_frame = pic->display_order;
553 break;
555 av_assert0(pic->nb_refs[0]);
557 fh->base_q_idx = priv->q_idx_p;
558 ref = pic->refs[0][pic->nb_refs[0] - 1];
559 href = ref->codec_priv;
560 hpic->slot = !href->slot;
561 hpic->last_idr_frame = href->last_idr_frame;
562 fh->refresh_frame_flags = 1 << hpic->slot;
563
564 /** set the nearest frame in L0 as all reference frame. */
565 for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
566 fh->ref_frame_idx[i] = href->slot;
567 }
568 fh->primary_ref_frame = href->slot;
569 fh->ref_order_hint[href->slot] = ref->display_order - href->last_idr_frame;
570 vpic->ref_frame_ctrl_l0.fields.search_idx0 = AV1_REF_FRAME_LAST;
571
572 /** set the 2nd nearest frame in L0 as Golden frame. */
573 if (pic->nb_refs[0] > 1) {
574 ref = pic->refs[0][pic->nb_refs[0] - 2];
575 href = ref->codec_priv;
576 fh->ref_frame_idx[3] = href->slot;
577 fh->ref_order_hint[href->slot] = ref->display_order - href->last_idr_frame;
578 vpic->ref_frame_ctrl_l0.fields.search_idx1 = AV1_REF_FRAME_GOLDEN;
579 } else {
580 fh->ref_order_hint[!href->slot] = cbctx->ref[!href->slot].order_hint;
581 }
582 break;
584 av_assert0(pic->nb_refs[0] && pic->nb_refs[1]);
586 fh->base_q_idx = priv->q_idx_b;
587 fh->refresh_frame_flags = 0x0;
588 fh->reference_select = 1;
589
590 /** B frame will not be referenced, disable its recon frame. */
591 vpic->picture_flags.bits.disable_frame_recon = 1;
592
593 /** Use LAST_FRAME and BWDREF_FRAME for reference. */
594 vpic->ref_frame_ctrl_l0.fields.search_idx0 = AV1_REF_FRAME_LAST;
595 vpic->ref_frame_ctrl_l1.fields.search_idx0 = AV1_REF_FRAME_BWDREF;
596
597 ref = pic->refs[0][pic->nb_refs[0] - 1];
598 href = ref->codec_priv;
599 hpic->last_idr_frame = href->last_idr_frame;
600 fh->primary_ref_frame = href->slot;
601 fh->ref_order_hint[href->slot] = ref->display_order - href->last_idr_frame;
602 for (i = 0; i < AV1_REF_FRAME_GOLDEN; i++) {
603 fh->ref_frame_idx[i] = href->slot;
604 }
605
606 ref = pic->refs[1][pic->nb_refs[1] - 1];
607 href = ref->codec_priv;
608 fh->ref_order_hint[href->slot] = ref->display_order - href->last_idr_frame;
610 fh->ref_frame_idx[i] = href->slot;
611 }
612 break;
613 default:
614 av_assert0(0 && "invalid picture type");
615 }
616
617 fh->show_frame = pic->display_order <= pic->encode_order;
619 fh->frame_width_minus_1 = avctx->width - 1;
620 fh->frame_height_minus_1 = avctx->height - 1;
623 fh->order_hint = pic->display_order - hpic->last_idr_frame;
624 fh->tile_cols = priv->tile_cols;
625 fh->tile_rows = priv->tile_rows;
626 fh->tile_cols_log2 = priv->tile_cols_log2;
627 fh->tile_rows_log2 = priv->tile_rows_log2;
629 fh->tile_size_bytes_minus1 = priv->attr_ext2.bits.tile_size_bytes_minus1;
630
631 /** ignore ONLY_4x4 mode for codedlossless is not fully implemented. */
632 if (priv->attr_ext2.bits.tx_mode_support & 0x04)
634 else if (priv->attr_ext2.bits.tx_mode_support & 0x02)
636 else {
637 av_log(avctx, AV_LOG_ERROR, "No available tx mode found.\n");
638 return AVERROR(EINVAL);
639 }
640
641 for (i = 0; i < fh->tile_cols; i++)
642 fh->width_in_sbs_minus_1[i] = vpic->width_in_sbs_minus_1[i] = priv->width_in_sbs_minus_1[i];
643
644 for (i = 0; i < fh->tile_rows; i++)
645 fh->height_in_sbs_minus_1[i] = vpic->height_in_sbs_minus_1[i] = priv->height_in_sbs_minus_1[i];
646
647 memcpy(fh->loop_filter_ref_deltas, default_loop_filter_ref_deltas,
648 AV1_TOTAL_REFS_PER_FRAME * sizeof(int8_t));
649
650 if (fh->frame_type == AV1_FRAME_KEY && fh->show_frame) {
651 fh->error_resilient_mode = 1;
652 }
653
656
657 if (ctx->va_rc_mode & VA_RC_CQP)
659
660 vpic->base_qindex = fh->base_q_idx;
661 vpic->frame_width_minus_1 = fh->frame_width_minus_1;
662 vpic->frame_height_minus_1 = fh->frame_height_minus_1;
663 vpic->primary_ref_frame = fh->primary_ref_frame;
664 vpic->reconstructed_frame = vaapi_pic->recon_surface;
665 vpic->coded_buf = vaapi_pic->output_buffer;
666 vpic->tile_cols = fh->tile_cols;
667 vpic->tile_rows = fh->tile_rows;
668 vpic->order_hint = fh->order_hint;
669#if VA_CHECK_VERSION(1, 15, 0)
670 vpic->refresh_frame_flags = fh->refresh_frame_flags;
671#endif
672
673 vpic->picture_flags.bits.enable_frame_obu = 0;
674 vpic->picture_flags.bits.frame_type = fh->frame_type;
675 vpic->picture_flags.bits.reduced_tx_set = fh->reduced_tx_set;
676 vpic->picture_flags.bits.error_resilient_mode = fh->error_resilient_mode;
677
678 /** let driver decide to use single or compound reference prediction mode. */
679 vpic->mode_control_flags.bits.reference_mode = fh->reference_select ? 2 : 0;
680 vpic->mode_control_flags.bits.tx_mode = fh->tx_mode;
681
682 vpic->tile_group_obu_hdr_info.bits.obu_has_size_field = 1;
683
684 /** set reference. */
685 for (i = 0; i < AV1_REFS_PER_FRAME; i++)
686 vpic->ref_frame_idx[i] = fh->ref_frame_idx[i];
687
688 for (i = 0; i < FF_ARRAY_ELEMS(vpic->reference_frames); i++)
689 vpic->reference_frames[i] = VA_INVALID_SURFACE;
690
691 for (i = 0; i < MAX_REFERENCE_LIST_NUM; i++) {
692 for (int j = 0; j < pic->nb_refs[i]; j++) {
693 FFHWBaseEncodePicture *ref_pic = pic->refs[i][j];
694
695 slot = ((VAAPIEncodeAV1Picture*)ref_pic->codec_priv)->slot;
696 av_assert0(vpic->reference_frames[slot] == VA_INVALID_SURFACE);
697
698 vpic->reference_frames[slot] = ((VAAPIEncodePicture *)ref_pic->priv)->recon_surface;
699 }
700 }
701
703 if (ret < 0)
704 goto end;
705
706 ret = vaapi_encode_av1_write_obu(avctx, priv->fh_data, &priv->fh_data_len, obu);
707 if (ret < 0)
708 goto end;
709
710 if (!(ctx->va_rc_mode & VA_RC_CQP)) {
711 vpic->min_base_qindex = av_clip(avctx->qmin, 1, AV1_MAX_QUANT);
712 vpic->max_base_qindex = av_clip(avctx->qmax, 1, AV1_MAX_QUANT);
713
714 vpic->bit_offset_qindex = priv->qindex_offset;
715 vpic->bit_offset_loopfilter_params = priv->loopfilter_offset;
716 vpic->bit_offset_cdef_params = priv->cdef_start_offset;
717 vpic->size_in_bits_cdef_params = priv->cdef_param_size;
718 vpic->size_in_bits_frame_hdr_obu = priv->fh_data_len;
719 vpic->byte_offset_frame_hdr_obu_size = (((pic->type == FF_HW_PICTURE_TYPE_IDR) ?
720 priv->sh_data_len / 8 : 0) +
721 (fh_obu->header.obu_extension_flag ?
722 2 : 1));
723 }
724
725 priv->nb_mh = 0;
726
727 if (pic->type == FF_HW_PICTURE_TYPE_IDR) {
728 AVFrameSideData *sd =
731 if (sd) {
734 if (mdm->has_primaries && mdm->has_luminance) {
735 AV1RawOBU *obu = &priv->mh[priv->nb_mh++];
736 AV1RawMetadata *md = &obu->obu.metadata;
737 AV1RawMetadataHDRMDCV *mdcv = &md->metadata.hdr_mdcv;
738 const int chroma_den = 1 << 16;
739 const int max_luma_den = 1 << 8;
740 const int min_luma_den = 1 << 14;
741
742 memset(obu, 0, sizeof(*obu));
744 md->metadata_type = AV1_METADATA_TYPE_HDR_MDCV;
745
746 for (i = 0; i < 3; i++) {
748 av_rescale(mdm->display_primaries[i][0].num, chroma_den,
749 mdm->display_primaries[i][0].den);
751 av_rescale(mdm->display_primaries[i][1].num, chroma_den,
752 mdm->display_primaries[i][1].den);
753 }
754
756 av_rescale(mdm->white_point[0].num, chroma_den,
757 mdm->white_point[0].den);
759 av_rescale(mdm->white_point[1].num, chroma_den,
760 mdm->white_point[1].den);
761
762 mdcv->luminance_max =
763 av_rescale(mdm->max_luminance.num, max_luma_den,
764 mdm->max_luminance.den);
765 mdcv->luminance_min =
766 av_rescale(mdm->min_luminance.num, min_luma_den,
767 mdm->min_luminance.den);
768 }
769 }
770
773 if (sd) {
775 AV1RawOBU *obu = &priv->mh[priv->nb_mh++];
776 AV1RawMetadata *md = &obu->obu.metadata;
777 AV1RawMetadataHDRCLL *cll = &md->metadata.hdr_cll;
778
779 memset(obu, 0, sizeof(*obu));
781 md->metadata_type = AV1_METADATA_TYPE_HDR_CLL;
782 cll->max_cll = cllm->MaxCLL;
783 cll->max_fall = cllm->MaxFALL;
784 }
785 }
786
787end:
788 ff_cbs_fragment_reset(obu);
789 return ret;
790}
791
794 VAAPIEncodeSlice *slice)
795{
796 VAAPIEncodeAV1Context *priv = avctx->priv_data;
797 VAEncTileGroupBufferAV1 *vslice = slice->codec_slice_params;
798 CodedBitstreamAV1Context *cbctx = priv->cbc->priv_data;
799 int div;
800
801 /** Set tile group info. */
802 div = priv->tile_cols * priv->tile_rows / priv->tile_groups;
803 vslice->tg_start = slice->index * div;
804 if (slice->index == (priv->tile_groups - 1)) {
805 vslice->tg_end = priv->tile_cols * priv->tile_rows - 1;
806 cbctx->seen_frame_header = 0;
807 } else {
808 vslice->tg_end = (slice->index + 1) * div - 1;
809 }
810
811 return 0;
812}
813
816 char *data, size_t *data_len)
817{
818 VAAPIEncodeAV1Context *priv = avctx->priv_data;
820 CodedBitstreamAV1Context *cbctx = priv->cbc->priv_data;
821 AV1RawOBU *fh_obu = &priv->fh;
822 AV1RawFrameHeader *rep_fh = &fh_obu->obu.frame_header;
823 VAAPIEncodePicture *vaapi_pic = pic->priv;
825 int ret = 0;
826
827 vaapi_pic->tail_size = 0;
828 /** Pack repeat frame header. */
829 if (pic->display_order > pic->encode_order) {
830 memset(fh_obu, 0, sizeof(*fh_obu));
831 href = pic->refs[0][pic->nb_refs[0] - 1]->codec_priv;
833 fh_obu->header.obu_has_size_field = 1;
834
835 rep_fh->show_existing_frame = 1;
836 rep_fh->frame_to_show_map_idx = href->slot == 0;
837 rep_fh->frame_type = AV1_FRAME_INTER;
838 rep_fh->frame_width_minus_1 = avctx->width - 1;
839 rep_fh->frame_height_minus_1 = avctx->height - 1;
842
843 cbctx->seen_frame_header = 0;
844
846 if (ret < 0)
847 goto end;
848
849 ret = vaapi_encode_av1_write_obu(avctx, vaapi_pic->tail_data, &vaapi_pic->tail_size, obu);
850 if (ret < 0)
851 goto end;
852
853 vaapi_pic->tail_size /= 8;
854 }
855
856 memcpy(data, &priv->fh_data, MAX_PARAM_BUFFER_SIZE * sizeof(char));
857 *data_len = priv->fh_data_len;
858
859end:
860 ff_cbs_fragment_reset(obu);
861 return ret;
862}
863
865 FFHWBaseEncodePicture *base_pic,
866 int index, int *type,
867 char *data, size_t *data_len)
868{
869 VAAPIEncodeAV1Context *priv = avctx->priv_data;
871 AV1RawOBU *mh_obu;
872 char mh_data[MAX_PARAM_BUFFER_SIZE];
873 size_t mh_data_len;
874 int ret = 0;
875
876 if (index >= priv->nb_mh)
877 return AVERROR_EOF;
878
879 mh_obu = &priv->mh[index];
880 ret = vaapi_encode_av1_add_obu(avctx, obu, AV1_OBU_METADATA, mh_obu);
881 if (ret < 0)
882 goto end;
883
884 ret = vaapi_encode_av1_write_obu(avctx, mh_data, &mh_data_len, obu);
885 if (ret < 0)
886 goto end;
887
888 memcpy(data, mh_data, MAX_PARAM_BUFFER_SIZE * sizeof(char));
889 *data_len = mh_data_len;
890 *type = VAEncPackedHeaderRawData;
891
892end:
893 ff_cbs_fragment_reset(obu);
894 return ret;
895}
896
898 { AV_PROFILE_AV1_MAIN, 8, 3, 1, 1, VAProfileAV1Profile0 },
899 { AV_PROFILE_AV1_MAIN, 10, 3, 1, 1, VAProfileAV1Profile0 },
901};
902
904 .profiles = vaapi_encode_av1_profiles,
906 .default_quality = 25,
907
908 .get_encoder_caps = &vaapi_encode_av1_get_encoder_caps,
909 .configure = &vaapi_encode_av1_configure,
910
911 .sequence_header_type = VAEncPackedHeaderSequence,
912 .sequence_params_size = sizeof(VAEncSequenceParameterBufferAV1),
913 .init_sequence_params = &vaapi_encode_av1_init_sequence_params,
915
916 .picture_priv_data_size = sizeof(VAAPIEncodeAV1Picture),
917 .picture_header_type = VAEncPackedHeaderPicture,
918 .picture_params_size = sizeof(VAEncPictureParameterBufferAV1),
919 .init_picture_params = &vaapi_encode_av1_init_picture_params,
920 .write_picture_header = &vaapi_encode_av1_write_picture_header,
921
922 .slice_params_size = sizeof(VAEncTileGroupBufferAV1),
923 .init_slice_params = &vaapi_encode_av1_init_slice_params,
924
925 .write_extra_header = &vaapi_encode_av1_write_extra_header,
926};
927
929{
931 VAAPIEncodeAV1Context *priv = avctx->priv_data;
932 VAConfigAttrib attr;
933 VAStatus vas;
934 int ret;
935
936 ctx->codec = &vaapi_encode_type_av1;
937
938 ctx->desired_packed_headers =
939 VA_ENC_PACKED_HEADER_SEQUENCE |
940 VA_ENC_PACKED_HEADER_PICTURE |
941 VA_ENC_PACKED_HEADER_MISC; // Metadata
942
943 if (avctx->profile == AV_PROFILE_UNKNOWN)
944 avctx->profile = priv->profile;
945 if (avctx->level == AV_LEVEL_UNKNOWN)
946 avctx->level = priv->level;
947
948 if (avctx->level != AV_LEVEL_UNKNOWN && avctx->level & ~0x1f) {
949 av_log(avctx, AV_LOG_ERROR, "Invalid level %d\n", avctx->level);
950 return AVERROR(EINVAL);
951 }
952
953 ret = ff_vaapi_encode_init(avctx);
954 if (ret < 0)
955 return ret;
956
957 attr.type = VAConfigAttribEncAV1;
958 vas = vaGetConfigAttributes(ctx->hwctx->display,
959 ctx->va_profile,
960 ctx->va_entrypoint,
961 &attr, 1);
962 if (vas != VA_STATUS_SUCCESS) {
963 av_log(avctx, AV_LOG_ERROR, "Failed to query "
964 "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
965 return AVERROR_EXTERNAL;
966 } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
967 priv->attr.value = 0;
968 av_log(avctx, AV_LOG_WARNING, "Attribute type:%d is not "
969 "supported.\n", attr.type);
970 } else {
971 priv->attr.value = attr.value;
972 }
973
974 attr.type = VAConfigAttribEncAV1Ext1;
975 vas = vaGetConfigAttributes(ctx->hwctx->display,
976 ctx->va_profile,
977 ctx->va_entrypoint,
978 &attr, 1);
979 if (vas != VA_STATUS_SUCCESS) {
980 av_log(avctx, AV_LOG_ERROR, "Failed to query "
981 "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
982 return AVERROR_EXTERNAL;
983 } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
984 priv->attr_ext1.value = 0;
985 av_log(avctx, AV_LOG_WARNING, "Attribute type:%d is not "
986 "supported.\n", attr.type);
987 } else {
988 priv->attr_ext1.value = attr.value;
989 }
990
991 /** This attr provides essential indicators, return error if not support. */
992 attr.type = VAConfigAttribEncAV1Ext2;
993 vas = vaGetConfigAttributes(ctx->hwctx->display,
994 ctx->va_profile,
995 ctx->va_entrypoint,
996 &attr, 1);
997 if (vas != VA_STATUS_SUCCESS || attr.value == VA_ATTRIB_NOT_SUPPORTED) {
998 av_log(avctx, AV_LOG_ERROR, "Failed to query "
999 "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
1000 return AVERROR_EXTERNAL;
1001 } else {
1002 priv->attr_ext2.value = attr.value;
1003 }
1004
1005 av_opt_set_int(priv->cbc->priv_data, "fixed_obu_size_length",
1006 priv->attr_ext2.bits.obu_size_bytes_minus1 + 1, 0);
1007
1009 if (ret < 0)
1010 return ret;
1011
1012 return 0;
1013}
1014
1016{
1017 VAAPIEncodeAV1Context *priv = avctx->priv_data;
1018
1019 ff_cbs_fragment_free(&priv->current_obu);
1020 ff_cbs_close(&priv->cbc);
1021
1022 return ff_vaapi_encode_close(avctx);
1023}
1024
1025#define OFFSET(x) offsetof(VAAPIEncodeAV1Context, x)
1026#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1027
1032 { "profile", "Set profile (seq_profile)",
1034 { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xff, FLAGS, .unit = "profile" },
1035
1036#define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1037 { .i64 = value }, 0, 0, FLAGS, .unit = "profile"
1038 { PROFILE("main", AV_PROFILE_AV1_MAIN) },
1039 { PROFILE("high", AV_PROFILE_AV1_HIGH) },
1040 { PROFILE("professional", AV_PROFILE_AV1_PROFESSIONAL) },
1041#undef PROFILE
1042
1043 { "tier", "Set tier (seq_tier)",
1044 OFFSET(tier), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS, .unit = "tier" },
1045 { "main", NULL, 0, AV_OPT_TYPE_CONST,
1046 { .i64 = 0 }, 0, 0, FLAGS, .unit = "tier" },
1047 { "high", NULL, 0, AV_OPT_TYPE_CONST,
1048 { .i64 = 1 }, 0, 0, FLAGS, .unit = "tier" },
1049 { "level", "Set level (seq_level_idx)",
1051 { .i64 = AV_LEVEL_UNKNOWN }, AV_LEVEL_UNKNOWN, 0x1f, FLAGS, .unit = "level" },
1052
1053#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1054 { .i64 = value }, 0, 0, FLAGS, .unit = "level"
1055 { LEVEL("2.0", 0) },
1056 { LEVEL("2.1", 1) },
1057 { LEVEL("3.0", 4) },
1058 { LEVEL("3.1", 5) },
1059 { LEVEL("4.0", 8) },
1060 { LEVEL("4.1", 9) },
1061 { LEVEL("5.0", 12) },
1062 { LEVEL("5.1", 13) },
1063 { LEVEL("5.2", 14) },
1064 { LEVEL("5.3", 15) },
1065 { LEVEL("6.0", 16) },
1066 { LEVEL("6.1", 17) },
1067 { LEVEL("6.2", 18) },
1068 { LEVEL("6.3", 19) },
1069#undef LEVEL
1070
1071 { "tiles", "Tile columns x rows (Use minimal tile column/row number automatically by default)",
1072 OFFSET(tile_cols), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, FLAGS },
1073 { "tile_groups", "Number of tile groups for encoding",
1074 OFFSET(tile_groups), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, AV1_MAX_TILE_ROWS * AV1_MAX_TILE_COLS, FLAGS },
1075
1076 { NULL },
1077};
1078
1080 { "b", "0" },
1081 { "bf", "2" },
1082 { "g", "120" },
1083 { "qmin", "1" },
1084 { "qmax", "255" },
1085 { "refs", "0" },
1086 { NULL },
1087};
1088
1090 .class_name = "av1_vaapi",
1091 .item_name = av_default_item_name,
1092 .option = vaapi_encode_av1_options,
1093 .version = LIBAVUTIL_VERSION_INT,
1094};
1095
1097 .p.name = "av1_vaapi",
1098 CODEC_LONG_NAME("AV1 (VAAPI)"),
1099 .p.type = AVMEDIA_TYPE_VIDEO,
1100 .p.id = AV_CODEC_ID_AV1,
1101 .priv_data_size = sizeof(VAAPIEncodeAV1Context),
1104 .close = &vaapi_encode_av1_close,
1105 .p.priv_class = &vaapi_encode_av1_class,
1106 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
1108 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
1110 .defaults = vaapi_encode_av1_defaults,
1112 .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
1113 .hw_configs = ff_vaapi_encode_hw_configs,
1114 .p.wrapper_name = "vaapi",
1115};
const FFCodec ff_av1_vaapi_encoder
static AVFormatContext * ctx
const AV1LevelDescriptor * ff_av1_guess_level(int64_t bitrate, int tier, int width, int height, int tiles, int tile_cols, float fps)
Guess the level of a stream from some parameters.
Definition av1_levels.c:48
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define FLAGS
Definition cmdutils.c:596
#define CODEC_PIXFMTS(...)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_RECEIVE_PACKET_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define av_clip
Definition common.h:100
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static __device__ float fabs(float a)
#define MAX_PARAM_BUFFER_SIZE
#define AV_PROFILE_AV1_HIGH
Definition defs.h:184
#define AV_PROFILE_UNKNOWN
Definition defs.h:65
#define AV_LEVEL_UNKNOWN
Definition defs.h:225
#define AV_PROFILE_AV1_MAIN
Definition defs.h:183
#define AV_PROFILE_AV1_PROFESSIONAL
Definition defs.h:185
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:613
double value
Definition eval.c:102
int ret
Definition ffplay.c:391
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
Definition opt.h:302
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition codec.h:147
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition codec.h:79
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition codec.h:133
@ AV_CODEC_ID_AV1
Definition codec_id.h:275
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition error.h:59
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:662
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition frame.h:137
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition frame.h:120
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition opt.c:951
int index
Definition gxfenc.c:90
int tile_rows
#define HW_BASE_ENCODE_COMMON_OPTIONS
@ FF_HW_FLAG_TIMESTAMP_NO_DELAY
@ FF_HW_FLAG_B_PICTURES
@ FF_HW_PICTURE_TYPE_P
@ FF_HW_PICTURE_TYPE_B
@ FF_HW_PICTURE_TYPE_IDR
#define MAX_REFERENCE_LIST_NUM
#define av_log2
Definition intmath.h:84
enum MPFType type
Definition jpegmpfenc.c:55
@ AV1_METADATA_TYPE_HDR_MDCV
Definition av1.h:45
@ AV1_METADATA_TYPE_HDR_CLL
Definition av1.h:44
@ AV1_TX_MODE_LARGEST
Definition av1.h:182
@ AV1_TX_MODE_SELECT
Definition av1.h:183
@ AV1_REF_FRAME_LAST
Definition av1.h:63
@ AV1_REF_FRAME_BWDREF
Definition av1.h:67
@ AV1_REF_FRAME_GOLDEN
Definition av1.h:66
@ AV1_OBU_METADATA
Definition av1.h:34
@ AV1_OBU_FRAME_HEADER
Definition av1.h:32
@ AV1_OBU_SEQUENCE_HEADER
Definition av1.h:30
@ AV1_FRAME_KEY
Definition av1.h:53
@ AV1_FRAME_INTER
Definition av1.h:54
@ AV1_CSP_COLOCATED
Definition av1.h:135
@ AV1_CSP_VERTICAL
Definition av1.h:134
@ AV1_CSP_UNKNOWN
Definition av1.h:133
@ AV1_MAX_TILE_WIDTH
Definition av1.h:79
@ AV1_PRIMARY_REF_NONE
Definition av1.h:87
@ AV1_MAX_TILE_COLS
Definition av1.h:82
@ AV1_SELECT_INTEGER_MV
Definition av1.h:99
@ AV1_REFS_PER_FRAME
Definition av1.h:85
@ AV1_TOTAL_REFS_PER_FRAME
Definition av1.h:86
@ AV1_MAX_TILE_ROWS
Definition av1.h:81
@ AV1_MAX_TILE_AREA
Definition av1.h:80
const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[]
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
#define av_cold
Definition attributes.h:117
const char * desc
Definition libsvtav1.c:83
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
const char data[16]
Definition mxf.c:149
int profile
Definition mxfenc.c:2300
AVOptions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition pixfmt.h:815
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition pixfmt.h:813
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:775
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:792
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition pixfmt.h:126
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:650
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:680
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:714
bitstream writer API
static int put_bits_count(PutBitContext *s)
Definition put_bits.h:90
#define FF_ARRAY_ELEMS(a)
uint8_t chroma_sample_position
Definition cbs_av1.h:63
uint8_t frame_type
Definition cbs_av1.h:180
uint8_t base_q_idx
Definition cbs_av1.h:239
uint8_t cdef_uv_pri_strength[8]
Definition cbs_av1.h:277
uint16_t render_height_minus_1
Definition cbs_av1.h:203
uint8_t height_in_sbs_minus_1[AV1_MAX_TILE_ROWS]
Definition cbs_av1.h:230
uint8_t tile_rows_log2
Definition cbs_av1.h:226
uint8_t loop_filter_level[4]
Definition cbs_av1.h:264
int8_t ref_frame_idx[AV1_REFS_PER_FRAME]
Definition cbs_av1.h:213
uint8_t cdef_y_pri_strength[8]
Definition cbs_av1.h:275
uint8_t tx_mode
Definition cbs_av1.h:284
uint16_t tile_rows
Definition cbs_av1.h:237
uint8_t showable_frame
Definition cbs_av1.h:182
uint16_t tile_cols
Definition cbs_av1.h:236
uint8_t reference_select
Definition cbs_av1.h:285
uint8_t tile_size_bytes_minus1
Definition cbs_av1.h:232
uint8_t uniform_tile_spacing_flag
Definition cbs_av1.h:224
uint8_t frame_to_show_map_idx
Definition cbs_av1.h:176
uint8_t cdef_bits
Definition cbs_av1.h:274
uint16_t render_width_minus_1
Definition cbs_av1.h:202
uint8_t cdef_damping_minus_3
Definition cbs_av1.h:273
uint8_t reduced_tx_set
Definition cbs_av1.h:289
uint16_t frame_height_minus_1
Definition cbs_av1.h:198
int8_t loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME]
Definition cbs_av1.h:269
uint8_t refresh_frame_flags
Definition cbs_av1.h:207
uint8_t ref_order_hint[AV1_NUM_REF_FRAMES]
Definition cbs_av1.h:209
uint8_t show_existing_frame
Definition cbs_av1.h:175
uint8_t show_frame
Definition cbs_av1.h:181
uint8_t primary_ref_frame
Definition cbs_av1.h:196
uint8_t error_resilient_mode
Definition cbs_av1.h:184
uint8_t order_hint
Definition cbs_av1.h:191
uint16_t frame_width_minus_1
Definition cbs_av1.h:197
uint8_t cdef_uv_sec_strength[8]
Definition cbs_av1.h:278
uint8_t tile_cols_log2
Definition cbs_av1.h:225
uint8_t width_in_sbs_minus_1[AV1_MAX_TILE_COLS]
Definition cbs_av1.h:229
uint8_t cdef_y_sec_strength[8]
Definition cbs_av1.h:276
AV1RawFrameHeader header
Definition cbs_av1.h:319
uint16_t white_point_chromaticity_y
Definition cbs_av1.h:340
uint16_t white_point_chromaticity_x
Definition cbs_av1.h:339
uint32_t luminance_max
Definition cbs_av1.h:341
uint16_t primary_chromaticity_y[3]
Definition cbs_av1.h:338
uint32_t luminance_min
Definition cbs_av1.h:342
uint16_t primary_chromaticity_x[3]
Definition cbs_av1.h:337
uint8_t obu_extension_flag
Definition cbs_av1.h:41
uint8_t obu_has_size_field
Definition cbs_av1.h:42
uint8_t obu_type
Definition cbs_av1.h:40
AV1RawFrameHeader frame_header
Definition cbs_av1.h:420
AV1RawOBUHeader header
Definition cbs_av1.h:414
AV1RawSequenceHeader sequence_header
Definition cbs_av1.h:419
AV1RawFrame frame
Definition cbs_av1.h:421
union AV1RawOBU::@016362317061177152367125047142162076164261250366 obu
uint16_t max_frame_height_minus_1
Definition cbs_av1.h:108
uint8_t seq_force_integer_mv
Definition cbs_av1.h:129
uint8_t seq_profile
Definition cbs_av1.h:83
AV1RawColorConfig color_config
Definition cbs_av1.h:137
uint8_t frame_height_bits_minus_1
Definition cbs_av1.h:106
uint8_t order_hint_bits_minus_1
Definition cbs_av1.h:131
uint8_t frame_width_bits_minus_1
Definition cbs_av1.h:105
uint8_t seq_tier[AV1_MAX_OPERATING_POINTS]
Definition cbs_av1.h:97
uint8_t seq_level_idx[AV1_MAX_OPERATING_POINTS]
Definition cbs_av1.h:96
uint16_t max_frame_width_minus_1
Definition cbs_av1.h:107
uint8_t enable_order_hint
Definition cbs_av1.h:122
uint8_t seq_force_screen_content_tools
Definition cbs_av1.h:127
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
int width
picture width / height.
Definition avcodec.h:605
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:685
float b_quant_offset
qscale offset between IP and B-frames
Definition avcodec.h:801
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:658
int qmin
minimum quantizer
Definition avcodec.h:1257
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
Definition avcodec.h:794
AVRational framerate
Definition avcodec.h:563
int level
Encoding level descriptor.
Definition avcodec.h:1656
int64_t bit_rate
the average bitrate
Definition avcodec.h:493
int profile
profile
Definition avcodec.h:1646
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:672
int qmax
maximum quantizer
Definition avcodec.h:1264
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:665
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition avcodec.h:692
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
Definition avcodec.h:810
void * priv_data
Definition avcodec.h:470
float i_quant_offset
qscale offset between P and I-frames
Definition avcodec.h:817
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
unsigned MaxFALL
Max average light level per frame (cd/m^2).
unsigned MaxCLL
Max content light level (cd/m^2).
Structure to hold side data for an AVFrame.
Definition frame.h:334
uint8_t * data
Definition frame.h:336
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition hwcontext.h:213
Mastering display metadata capable of representing the color volume of the display used to master the...
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
AV1ReferenceFrameState ref[AV1_NUM_REF_FRAMES]
Definition cbs_av1.h:491
Context structure for coded bitstream operations.
Definition cbs.h:226
int trace_enable
Enable trace output during read/write operations.
Definition cbs.h:264
void * trace_context
User context pointer to pass to trace callbacks.
Definition cbs.h:274
int trace_level
Log level to use for default trace output.
Definition cbs.h:270
void * priv_data
Internal codec-specific data.
Definition cbs.h:247
CBSTraceWriteCallback trace_write_callback
Callback for write tracing.
Definition cbs.h:288
Coded bitstream fragment structure, combining one or more units.
Definition cbs.h:129
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition cbs.h:146
size_t data_size
The number of bytes in the bitstream.
Definition cbs.h:142
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition cbs.h:135
AVHWFramesContext * input_frames
int nb_refs[MAX_REFERENCE_LIST_NUM]
struct FFHWBaseEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
size_t fh_data_len
bit length of fh_data.
CodedBitstreamFragment current_obu
VAConfigAttribValEncAV1Ext1 attr_ext1
char fh_data[MAX_PARAM_BUFFER_SIZE]
coded frame header data.
VAConfigAttribValEncAV1 attr
int qindex_offset
bit positions in current frame header
size_t sh_data_len
bit length of sh_data.
VAAPIEncodeContext common
char sh_data[MAX_PARAM_BUFFER_SIZE]
coded sequence header data.
int profile
user options
CodedBitstreamContext * cbc
uint8_t height_in_sbs_minus_1[AV1_MAX_TILE_ROWS]
AV1RawOBU fh
frame header.
uint8_t width_in_sbs_minus_1[AV1_MAX_TILE_COLS]
AV1RawOBU sh
sequence header.
VAConfigAttribValEncAV1Ext2 attr_ext2
AV1RawOBU mh[4]
metadata header.
void * codec_picture_params
int non_independent_frame
indicate if current frame is an independent frame that the coded data can be pushed to downstream dir...
size_t tail_size
Byte length of tail_data.
char tail_data[MAX_PARAM_BUFFER_SIZE]
Tail data of current pic, used only for repeat header of AV1.
VASurfaceID recon_surface
VABufferID output_buffer
void * codec_slice_params
uint8_t level
Definition svq3.c:208
#define av_log(a,...)
float framerate
Definition av1_levels.c:29
int tier
Definition av1_levels.c:48
int tile_cols
Definition av1_levels.c:73
static int ref[MAX_W *MAX_W]
#define VAAPI_ENCODE_COMMON_OPTIONS
#define VAAPI_ENCODE_RC_OPTIONS
static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
static av_cold int vaapi_encode_av1_close(AVCodecContext *avctx)
static int vaapi_encode_av1_write_extra_header(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic, int index, int *type, char *data, size_t *data_len)
static av_cold int vaapi_encode_av1_init(AVCodecContext *avctx)
static const FFCodecDefault vaapi_encode_av1_defaults[]
static const VAAPIEncodeProfile vaapi_encode_av1_profiles[]
static int vaapi_encode_av1_add_obu(AVCodecContext *avctx, CodedBitstreamFragment *au, uint8_t type, void *obu_unit)
#define AV1_MAX_QUANT
static const VAAPIEncodeType vaapi_encode_type_av1
static void vaapi_encode_av1_trace_write_log(void *ctx, PutBitContext *pbc, int length, const char *str, const int *subscripts, int64_t value)
static int tile_log2(int blkSize, int target)
static int vaapi_encode_av1_init_sequence_params(AVCodecContext *avctx)
static const AVClass vaapi_encode_av1_class
#define LEVEL(name, value)
static const AVOption vaapi_encode_av1_options[]
static int vaapi_encode_av1_write_picture_header(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, char *data, size_t *data_len)
static int vaapi_encode_av1_init_slice_params(AVCodecContext *avctx, FFHWBaseEncodePicture *base, VAAPIEncodeSlice *slice)
#define PROFILE(name, value)
static void vaapi_encode_av1_set_cqp_filters(AV1RawFrameHeader *fh, VAEncPictureParameterBufferAV1 *vpic)
With VA_RC_CQP the driver does not patch the packed frame header, so choose the in-loop filter parame...
static int vaapi_encode_av1_write_obu(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *bs)
static av_cold int vaapi_encode_av1_configure(AVCodecContext *avctx)
#define OFFSET(x)
static int vaapi_encode_av1_set_tile(AVCodecContext *avctx)
static int vaapi_encode_av1_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
static av_cold int vaapi_encode_av1_get_encoder_caps(AVCodecContext *avctx)
#define md
color_range
uint8_t base
Definition vp3data.h:128
static int write_sequence_header(AVCodecContext *avctx, FFHWBaseEncodePicture *base_pic, uint8_t *data, size_t *data_len)