FFmpeg
dxva2_av1.c
Go to the documentation of this file.
1 /*
2  * DXVA2 AV1 HW acceleration.
3  *
4  * copyright (c) 2020 Hendrik Leppkes
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "config_components.h"
24 
25 #include "libavutil/avassert.h"
26 #include "libavutil/pixdesc.h"
27 
28 #include "dxva2_internal.h"
29 #include "av1dec.h"
30 #include "hwaccel_internal.h"
31 
32 #define MAX_TILES 256
33 
36 
37  unsigned int bitstream_allocated;
38  uint8_t *bitstream_cache;
39 };
40 
42  DXVA_PicParams_AV1 pp;
43  unsigned tile_count;
44  DXVA_Tile_AV1 tiles[MAX_TILES];
45  uint8_t *bitstream;
46  unsigned bitstream_size;
47 };
48 
50 {
51  if (seq->seq_profile == 2 && seq->color_config.high_bitdepth)
52  return seq->color_config.twelve_bit ? 12 : 10;
53  else if (seq->seq_profile <= 2 && seq->color_config.high_bitdepth)
54  return 10;
55  else
56  return 8;
57 }
58 
60  DXVA_PicParams_AV1 *pp)
61 {
62  int i,j, uses_lr;
63  const AV1RawSequenceHeader *seq = h->raw_seq;
64  const AV1RawFrameHeader *frame_header = h->raw_frame_header;
65  const AV1RawFilmGrainParams *film_grain = &h->cur_frame.film_grain;
66 
67  unsigned char remap_lr_type[4] = { AV1_RESTORE_NONE, AV1_RESTORE_SWITCHABLE, AV1_RESTORE_WIENER, AV1_RESTORE_SGRPROJ };
68  int apply_grain = !(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && film_grain->apply_grain;
69 
70  memset(pp, 0, sizeof(*pp));
71 
72  pp->width = avctx->width;
73  pp->height = avctx->height;
74 
75  pp->max_width = seq->max_frame_width_minus_1 + 1;
76  pp->max_height = seq->max_frame_height_minus_1 + 1;
77 
78  pp->CurrPicTextureIndex = ff_dxva2_get_surface_index(avctx, ctx, h->cur_frame.f);
79  pp->superres_denom = frame_header->use_superres ? frame_header->coded_denom + AV1_SUPERRES_DENOM_MIN : AV1_SUPERRES_NUM;
80  pp->bitdepth = get_bit_depth_from_seq(seq);
81  pp->seq_profile = seq->seq_profile;
82 
83  /* Tiling info */
84  pp->tiles.cols = frame_header->tile_cols;
85  pp->tiles.rows = frame_header->tile_rows;
86  pp->tiles.context_update_id = frame_header->context_update_tile_id;
87 
88  for (i = 0; i < pp->tiles.cols; i++)
89  pp->tiles.widths[i] = frame_header->width_in_sbs_minus_1[i] + 1;
90 
91  for (i = 0; i < pp->tiles.rows; i++)
92  pp->tiles.heights[i] = frame_header->height_in_sbs_minus_1[i] + 1;
93 
94  /* Coding tools */
95  pp->coding.use_128x128_superblock = seq->use_128x128_superblock;
96  pp->coding.intra_edge_filter = seq->enable_intra_edge_filter;
97  pp->coding.interintra_compound = seq->enable_interintra_compound;
98  pp->coding.masked_compound = seq->enable_masked_compound;
99  pp->coding.warped_motion = frame_header->allow_warped_motion;
100  pp->coding.dual_filter = seq->enable_dual_filter;
101  pp->coding.jnt_comp = seq->enable_jnt_comp;
102  pp->coding.screen_content_tools = frame_header->allow_screen_content_tools;
103  pp->coding.integer_mv = frame_header->force_integer_mv || !(frame_header->frame_type & 1);
104  pp->coding.cdef = seq->enable_cdef;
105  pp->coding.restoration = seq->enable_restoration;
106  pp->coding.film_grain = seq->film_grain_params_present && !(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN);
107  pp->coding.intrabc = frame_header->allow_intrabc;
108  pp->coding.high_precision_mv = frame_header->allow_high_precision_mv;
109  pp->coding.switchable_motion_mode = frame_header->is_motion_mode_switchable;
110  pp->coding.filter_intra = seq->enable_filter_intra;
111  pp->coding.disable_frame_end_update_cdf = frame_header->disable_frame_end_update_cdf;
112  pp->coding.disable_cdf_update = frame_header->disable_cdf_update;
113  pp->coding.reference_mode = frame_header->reference_select;
114  pp->coding.skip_mode = frame_header->skip_mode_present;
115  pp->coding.reduced_tx_set = frame_header->reduced_tx_set;
116  pp->coding.superres = frame_header->use_superres;
117  pp->coding.tx_mode = frame_header->tx_mode;
118  pp->coding.use_ref_frame_mvs = frame_header->use_ref_frame_mvs;
119  pp->coding.enable_ref_frame_mvs = seq->enable_ref_frame_mvs;
120  pp->coding.reference_frame_update = 1; // 0 for show_existing_frame with key frames, but those are not passed to the hwaccel
121 
122  /* Format & Picture Info flags */
123  pp->format.frame_type = frame_header->frame_type;
124  pp->format.show_frame = frame_header->show_frame;
125  pp->format.showable_frame = frame_header->showable_frame;
126  pp->format.subsampling_x = seq->color_config.subsampling_x;
127  pp->format.subsampling_y = seq->color_config.subsampling_y;
128  pp->format.mono_chrome = seq->color_config.mono_chrome;
129 
130  /* References */
131  pp->primary_ref_frame = frame_header->primary_ref_frame;
132  pp->order_hint = frame_header->order_hint;
133  pp->order_hint_bits = seq->enable_order_hint ? seq->order_hint_bits_minus_1 + 1 : 0;
134 
135  memset(pp->RefFrameMapTextureIndex, 0xFF, sizeof(pp->RefFrameMapTextureIndex));
136  for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
137  int8_t ref_idx = frame_header->ref_frame_idx[i];
138  AVFrame *ref_frame = h->ref[ref_idx].f;
139 
140  pp->frame_refs[i].width = ref_frame->width;
141  pp->frame_refs[i].height = ref_frame->height;
142  pp->frame_refs[i].Index = ref_frame->buf[0] ? ref_idx : 0xFF;
143 
144  /* Global Motion */
145  pp->frame_refs[i].wminvalid = h->cur_frame.gm_invalid[AV1_REF_FRAME_LAST + i];
146  pp->frame_refs[i].wmtype = h->cur_frame.gm_type[AV1_REF_FRAME_LAST + i];
147  for (j = 0; j < 6; ++j) {
148  pp->frame_refs[i].wmmat[j] = h->cur_frame.gm_params[AV1_REF_FRAME_LAST + i][j];
149  }
150  }
151  for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
152  AVFrame *ref_frame = h->ref[i].f;
153  if (ref_frame->buf[0])
154  pp->RefFrameMapTextureIndex[i] = ff_dxva2_get_surface_index(avctx, ctx, ref_frame);
155  }
156 
157  /* Loop filter parameters */
158  pp->loop_filter.filter_level[0] = frame_header->loop_filter_level[0];
159  pp->loop_filter.filter_level[1] = frame_header->loop_filter_level[1];
160  pp->loop_filter.filter_level_u = frame_header->loop_filter_level[2];
161  pp->loop_filter.filter_level_v = frame_header->loop_filter_level[3];
162  pp->loop_filter.sharpness_level = frame_header->loop_filter_sharpness;
163  pp->loop_filter.mode_ref_delta_enabled = frame_header->loop_filter_delta_enabled;
164  pp->loop_filter.mode_ref_delta_update = frame_header->loop_filter_delta_update;
165  pp->loop_filter.delta_lf_multi = frame_header->delta_lf_multi;
166  pp->loop_filter.delta_lf_present = frame_header->delta_lf_present;
167  pp->loop_filter.delta_lf_res = frame_header->delta_lf_res;
168 
169  for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) {
170  pp->loop_filter.ref_deltas[i] = frame_header->loop_filter_ref_deltas[i];
171  }
172 
173  pp->loop_filter.mode_deltas[0] = frame_header->loop_filter_mode_deltas[0];
174  pp->loop_filter.mode_deltas[1] = frame_header->loop_filter_mode_deltas[1];
175  pp->loop_filter.frame_restoration_type[0] = remap_lr_type[frame_header->lr_type[0]];
176  pp->loop_filter.frame_restoration_type[1] = remap_lr_type[frame_header->lr_type[1]];
177  pp->loop_filter.frame_restoration_type[2] = remap_lr_type[frame_header->lr_type[2]];
178  uses_lr = frame_header->lr_type[0] || frame_header->lr_type[1] || frame_header->lr_type[2];
179  pp->loop_filter.log2_restoration_unit_size[0] = uses_lr ? (6 + frame_header->lr_unit_shift) : 8;
180  pp->loop_filter.log2_restoration_unit_size[1] = uses_lr ? (6 + frame_header->lr_unit_shift - frame_header->lr_uv_shift) : 8;
181  pp->loop_filter.log2_restoration_unit_size[2] = uses_lr ? (6 + frame_header->lr_unit_shift - frame_header->lr_uv_shift) : 8;
182 
183  /* Quantization */
184  pp->quantization.delta_q_present = frame_header->delta_q_present;
185  pp->quantization.delta_q_res = frame_header->delta_q_res;
186  pp->quantization.base_qindex = frame_header->base_q_idx;
187  pp->quantization.y_dc_delta_q = frame_header->delta_q_y_dc;
188  pp->quantization.u_dc_delta_q = frame_header->delta_q_u_dc;
189  pp->quantization.v_dc_delta_q = frame_header->delta_q_v_dc;
190  pp->quantization.u_ac_delta_q = frame_header->delta_q_u_ac;
191  pp->quantization.v_ac_delta_q = frame_header->delta_q_v_ac;
192  pp->quantization.qm_y = frame_header->using_qmatrix ? frame_header->qm_y : 0xFF;
193  pp->quantization.qm_u = frame_header->using_qmatrix ? frame_header->qm_u : 0xFF;
194  pp->quantization.qm_v = frame_header->using_qmatrix ? frame_header->qm_v : 0xFF;
195 
196  /* Cdef parameters */
197  pp->cdef.damping = frame_header->cdef_damping_minus_3;
198  pp->cdef.bits = frame_header->cdef_bits;
199  for (i = 0; i < 8; i++) {
200  pp->cdef.y_strengths[i].primary = frame_header->cdef_y_pri_strength[i];
201  pp->cdef.y_strengths[i].secondary = frame_header->cdef_y_sec_strength[i];
202  pp->cdef.uv_strengths[i].primary = frame_header->cdef_uv_pri_strength[i];
203  pp->cdef.uv_strengths[i].secondary = frame_header->cdef_uv_sec_strength[i];
204  }
205 
206  /* Misc flags */
207  pp->interp_filter = frame_header->interpolation_filter;
208 
209  /* Segmentation */
210  pp->segmentation.enabled = frame_header->segmentation_enabled;
211  pp->segmentation.update_map = frame_header->segmentation_update_map;
212  pp->segmentation.update_data = frame_header->segmentation_update_data;
213  pp->segmentation.temporal_update = frame_header->segmentation_temporal_update;
214  for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
215  for (j = 0; j < AV1_SEG_LVL_MAX; j++) {
216  pp->segmentation.feature_mask[i].mask |= frame_header->feature_enabled[i][j] << j;
217  pp->segmentation.feature_data[i][j] = frame_header->feature_value[i][j];
218  }
219  }
220 
221  /* Film grain */
222  if (apply_grain) {
223  pp->film_grain.apply_grain = 1;
224  pp->film_grain.scaling_shift_minus8 = film_grain->grain_scaling_minus_8;
225  pp->film_grain.chroma_scaling_from_luma = film_grain->chroma_scaling_from_luma;
226  pp->film_grain.ar_coeff_lag = film_grain->ar_coeff_lag;
227  pp->film_grain.ar_coeff_shift_minus6 = film_grain->ar_coeff_shift_minus_6;
228  pp->film_grain.grain_scale_shift = film_grain->grain_scale_shift;
229  pp->film_grain.overlap_flag = film_grain->overlap_flag;
230  pp->film_grain.clip_to_restricted_range = film_grain->clip_to_restricted_range;
231  pp->film_grain.matrix_coeff_is_identity = (seq->color_config.matrix_coefficients == AVCOL_SPC_RGB);
232 
233  pp->film_grain.grain_seed = film_grain->grain_seed;
234  pp->film_grain.num_y_points = film_grain->num_y_points;
235  for (i = 0; i < film_grain->num_y_points; i++) {
236  pp->film_grain.scaling_points_y[i][0] = film_grain->point_y_value[i];
237  pp->film_grain.scaling_points_y[i][1] = film_grain->point_y_scaling[i];
238  }
239  pp->film_grain.num_cb_points = film_grain->num_cb_points;
240  for (i = 0; i < film_grain->num_cb_points; i++) {
241  pp->film_grain.scaling_points_cb[i][0] = film_grain->point_cb_value[i];
242  pp->film_grain.scaling_points_cb[i][1] = film_grain->point_cb_scaling[i];
243  }
244  pp->film_grain.num_cr_points = film_grain->num_cr_points;
245  for (i = 0; i < film_grain->num_cr_points; i++) {
246  pp->film_grain.scaling_points_cr[i][0] = film_grain->point_cr_value[i];
247  pp->film_grain.scaling_points_cr[i][1] = film_grain->point_cr_scaling[i];
248  }
249  for (i = 0; i < 24; i++) {
250  pp->film_grain.ar_coeffs_y[i] = film_grain->ar_coeffs_y_plus_128[i];
251  }
252  for (i = 0; i < 25; i++) {
253  pp->film_grain.ar_coeffs_cb[i] = film_grain->ar_coeffs_cb_plus_128[i];
254  pp->film_grain.ar_coeffs_cr[i] = film_grain->ar_coeffs_cr_plus_128[i];
255  }
256  pp->film_grain.cb_mult = film_grain->cb_mult;
257  pp->film_grain.cb_luma_mult = film_grain->cb_luma_mult;
258  pp->film_grain.cr_mult = film_grain->cr_mult;
259  pp->film_grain.cr_luma_mult = film_grain->cr_luma_mult;
260  pp->film_grain.cb_offset = film_grain->cb_offset;
261  pp->film_grain.cr_offset = film_grain->cr_offset;
262  pp->film_grain.cr_offset = film_grain->cr_offset;
263  }
264 
265  // XXX: Setting the StatusReportFeedbackNumber breaks decoding on some drivers (tested on NVIDIA 457.09)
266  // Status Reporting is not used by FFmpeg, hence not providing a number does not cause any issues
267  //pp->StatusReportFeedbackNumber = 1 + DXVA_CONTEXT_REPORT_ID(avctx, ctx)++;
268  return 0;
269 }
270 
272  av_unused const uint8_t *buffer,
273  av_unused uint32_t size)
274 {
275  const AV1DecContext *h = avctx->priv_data;
276  AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
277  struct av1_dxva2_picture_context *ctx_pic = h->cur_frame.hwaccel_picture_private;
278 
279  if (!DXVA_CONTEXT_VALID(avctx, ctx))
280  return -1;
281  av_assert0(ctx_pic);
282 
283  /* Fill up DXVA_PicParams_AV1 */
284  if (fill_picture_parameters(avctx, ctx, h, &ctx_pic->pp) < 0)
285  return -1;
286 
287  ctx_pic->bitstream_size = 0;
288  ctx_pic->bitstream = NULL;
289  return 0;
290 }
291 
293  const uint8_t *buffer,
294  uint32_t size)
295 {
296  const AV1DecContext *h = avctx->priv_data;
297  const AV1RawFrameHeader *frame_header = h->raw_frame_header;
298  struct av1_dxva2_picture_context *ctx_pic = h->cur_frame.hwaccel_picture_private;
299  struct AV1DXVAContext *ctx = avctx->internal->hwaccel_priv_data;
300  void *tmp;
301 
302  ctx_pic->tile_count = frame_header->tile_cols * frame_header->tile_rows;
303 
304  /* too many tiles, exceeding all defined levels in the AV1 spec */
305  if (ctx_pic->tile_count > MAX_TILES)
306  return AVERROR(ENOSYS);
307 
308  /* Shortcut if all tiles are in the same buffer */
309  if (ctx_pic->tile_count == h->tg_end - h->tg_start + 1) {
310  ctx_pic->bitstream = (uint8_t *)buffer;
311  ctx_pic->bitstream_size = size;
312 
313  for (uint32_t tile_num = 0; tile_num < ctx_pic->tile_count; tile_num++) {
314  ctx_pic->tiles[tile_num].DataOffset = h->tile_group_info[tile_num].tile_offset;
315  ctx_pic->tiles[tile_num].DataSize = h->tile_group_info[tile_num].tile_size;
316  ctx_pic->tiles[tile_num].row = h->tile_group_info[tile_num].tile_row;
317  ctx_pic->tiles[tile_num].column = h->tile_group_info[tile_num].tile_column;
318  ctx_pic->tiles[tile_num].anchor_frame = 0xFF;
319  }
320 
321  return 0;
322  }
323 
324  /* allocate an internal buffer */
325  tmp = av_fast_realloc(ctx->bitstream_cache, &ctx->bitstream_allocated,
326  ctx_pic->bitstream_size + size);
327  if (!tmp) {
328  return AVERROR(ENOMEM);
329  }
330  ctx_pic->bitstream = ctx->bitstream_cache = tmp;
331 
332  memcpy(ctx_pic->bitstream + ctx_pic->bitstream_size, buffer, size);
333 
334  for (uint32_t tile_num = h->tg_start; tile_num <= h->tg_end; tile_num++) {
335  ctx_pic->tiles[tile_num].DataOffset = ctx_pic->bitstream_size + h->tile_group_info[tile_num].tile_offset;
336  ctx_pic->tiles[tile_num].DataSize = h->tile_group_info[tile_num].tile_size;
337  ctx_pic->tiles[tile_num].row = h->tile_group_info[tile_num].tile_row;
338  ctx_pic->tiles[tile_num].column = h->tile_group_info[tile_num].tile_column;
339  ctx_pic->tiles[tile_num].anchor_frame = 0xFF;
340  }
341 
342  ctx_pic->bitstream_size += size;
343 
344  return 0;
345 }
346 
350 {
351  const AV1DecContext *h = avctx->priv_data;
352  AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
353  struct av1_dxva2_picture_context *ctx_pic = h->cur_frame.hwaccel_picture_private;
354  void *dxva_data_ptr;
355  uint8_t *dxva_data;
356  unsigned dxva_size;
357  unsigned padding;
358  unsigned type;
359 
360 #if CONFIG_D3D11VA
361  if (ff_dxva2_is_d3d11(avctx)) {
362  type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
363  if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context,
365  type,
366  &dxva_size, &dxva_data_ptr)))
367  return -1;
368  }
369 #endif
370 #if CONFIG_DXVA2
371  if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {
372  type = DXVA2_BitStreamDateBufferType;
373  if (FAILED(IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(ctx)->decoder,
374  type,
375  &dxva_data_ptr, &dxva_size)))
376  return -1;
377  }
378 #endif
379 
380  dxva_data = dxva_data_ptr;
381 
382  if (ctx_pic->bitstream_size > dxva_size) {
383  av_log(avctx, AV_LOG_ERROR, "Bitstream size exceeds hardware buffer");
384  return -1;
385  }
386 
387  memcpy(dxva_data, ctx_pic->bitstream, ctx_pic->bitstream_size);
388 
389  padding = FFMIN(128 - ((ctx_pic->bitstream_size) & 127), dxva_size - ctx_pic->bitstream_size);
390  if (padding > 0) {
391  memset(dxva_data + ctx_pic->bitstream_size, 0, padding);
392  ctx_pic->bitstream_size += padding;
393  }
394 
395 #if CONFIG_D3D11VA
396  if (ff_dxva2_is_d3d11(avctx))
397  if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type)))
398  return -1;
399 #endif
400 #if CONFIG_DXVA2
401  if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
402  if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(ctx)->decoder, type)))
403  return -1;
404 #endif
405 
406 #if CONFIG_D3D11VA
407  if (ff_dxva2_is_d3d11(avctx)) {
408  D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs;
409  memset(dsc11, 0, sizeof(*dsc11));
410  dsc11->BufferType = type;
411  dsc11->DataSize = ctx_pic->bitstream_size;
412  dsc11->NumMBsInBuffer = 0;
413 
414  type = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
415  }
416 #endif
417 #if CONFIG_DXVA2
418  if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {
419  DXVA2_DecodeBufferDesc *dsc2 = bs;
420  memset(dsc2, 0, sizeof(*dsc2));
421  dsc2->CompressedBufferType = type;
422  dsc2->DataSize = ctx_pic->bitstream_size;
423  dsc2->NumMBsInBuffer = 0;
424 
425  type = DXVA2_SliceControlBufferType;
426  }
427 #endif
428 
429  return ff_dxva2_commit_buffer(avctx, ctx, sc, type,
430  ctx_pic->tiles, sizeof(*ctx_pic->tiles) * ctx_pic->tile_count, 0);
431 }
432 
434 {
435  const AV1DecContext *h = avctx->priv_data;
436  struct av1_dxva2_picture_context *ctx_pic = h->cur_frame.hwaccel_picture_private;
437  int ret;
438 
439  if (ctx_pic->bitstream_size <= 0)
440  return -1;
441 
442  ret = ff_dxva2_common_end_frame(avctx, h->cur_frame.f,
443  &ctx_pic->pp, sizeof(ctx_pic->pp),
444  NULL, 0,
446 
447  return ret;
448 }
449 
451 {
452  struct AV1DXVAContext *ctx = avctx->internal->hwaccel_priv_data;
453 
454  av_freep(&ctx->bitstream_cache);
455  ctx->bitstream_allocated = 0;
456 
457  return ff_dxva2_decode_uninit(avctx);
458 }
459 
460 #if CONFIG_AV1_DXVA2_HWACCEL
462  .p.name = "av1_dxva2",
463  .p.type = AVMEDIA_TYPE_VIDEO,
464  .p.id = AV_CODEC_ID_AV1,
465  .p.pix_fmt = AV_PIX_FMT_DXVA2_VLD,
466  .init = ff_dxva2_decode_init,
467  .uninit = dxva2_av1_uninit,
468  .start_frame = dxva2_av1_start_frame,
469  .decode_slice = dxva2_av1_decode_slice,
470  .end_frame = dxva2_av1_end_frame,
471  .frame_params = ff_dxva2_common_frame_params,
472  .frame_priv_data_size = sizeof(struct av1_dxva2_picture_context),
473  .priv_data_size = sizeof(struct AV1DXVAContext),
474 };
475 #endif
476 
477 #if CONFIG_AV1_D3D11VA_HWACCEL
479  .p.name = "av1_d3d11va",
480  .p.type = AVMEDIA_TYPE_VIDEO,
481  .p.id = AV_CODEC_ID_AV1,
482  .p.pix_fmt = AV_PIX_FMT_D3D11VA_VLD,
483  .init = ff_dxva2_decode_init,
484  .uninit = dxva2_av1_uninit,
485  .start_frame = dxva2_av1_start_frame,
486  .decode_slice = dxva2_av1_decode_slice,
487  .end_frame = dxva2_av1_end_frame,
488  .frame_params = ff_dxva2_common_frame_params,
489  .frame_priv_data_size = sizeof(struct av1_dxva2_picture_context),
490  .priv_data_size = sizeof(struct AV1DXVAContext),
491 };
492 #endif
493 
494 #if CONFIG_AV1_D3D11VA2_HWACCEL
496  .p.name = "av1_d3d11va2",
497  .p.type = AVMEDIA_TYPE_VIDEO,
498  .p.id = AV_CODEC_ID_AV1,
499  .p.pix_fmt = AV_PIX_FMT_D3D11,
500  .init = ff_dxva2_decode_init,
501  .uninit = dxva2_av1_uninit,
502  .start_frame = dxva2_av1_start_frame,
503  .decode_slice = dxva2_av1_decode_slice,
504  .end_frame = dxva2_av1_end_frame,
505  .frame_params = ff_dxva2_common_frame_params,
506  .frame_priv_data_size = sizeof(struct av1_dxva2_picture_context),
507  .priv_data_size = sizeof(struct AV1DXVAContext),
508 };
509 #endif
fill_picture_parameters
static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, const AV1DecContext *h, DXVA_PicParams_AV1 *pp)
Definition: dxva2_av1.c:59
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AV1RawFilmGrainParams::clip_to_restricted_range
uint8_t clip_to_restricted_range
Definition: cbs_av1.h:162
ff_av1_d3d11va2_hwaccel
const struct FFHWAccel ff_av1_d3d11va2_hwaccel
AV1RawFilmGrainParams::grain_seed
uint16_t grain_seed
Definition: cbs_av1.h:135
AV1RawSequenceHeader
Definition: cbs_av1.h:73
AV1_SUPERRES_NUM
@ AV1_SUPERRES_NUM
Definition: av1.h:100
AV1RawFilmGrainParams::point_cb_value
uint8_t point_cb_value[10]
Definition: cbs_av1.h:143
AV1RawFilmGrainParams::apply_grain
uint8_t apply_grain
Definition: cbs_av1.h:134
get_bit_depth_from_seq
static int get_bit_depth_from_seq(const AV1RawSequenceHeader *seq)
Definition: dxva2_av1.c:49
av_unused
#define av_unused
Definition: attributes.h:131
AV1_RESTORE_SWITCHABLE
@ AV1_RESTORE_SWITCHABLE
Definition: av1.h:175
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
pixdesc.h
AVFrame::width
int width
Definition: frame.h:412
AV1RawFilmGrainParams::point_y_value
uint8_t point_y_value[14]
Definition: cbs_av1.h:139
ff_dxva2_common_end_frame
int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, const void *pp, unsigned pp_size, const void *qm, unsigned qm_size, int(*commit_bs_si)(AVCodecContext *, DECODER_BUFFER_DESC *bs, DECODER_BUFFER_DESC *slice))
Definition: dxva2.c:886
AV_PIX_FMT_D3D11VA_VLD
@ AV_PIX_FMT_D3D11VA_VLD
HW decoding through Direct3D11 via old API, Picture.data[3] contains a ID3D11VideoDecoderOutputView p...
Definition: pixfmt.h:247
AVCOL_SPC_RGB
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition: pixfmt.h:600
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:590
dxva2_av1_start_frame
static int dxva2_av1_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition: dxva2_av1.c:271
AV1RawSequenceHeader::seq_profile
uint8_t seq_profile
Definition: cbs_av1.h:74
AV1RawColorConfig::subsampling_y
uint8_t subsampling_y
Definition: cbs_av1.h:53
AV1RawFilmGrainParams::cr_mult
uint8_t cr_mult
Definition: cbs_av1.h:158
AV1DXVAContext::shared
FFDXVASharedContext shared
Definition: dxva2_av1.c:35
av1_dxva2_picture_context::bitstream
uint8_t * bitstream
Definition: dxva2_av1.c:45
commit_bitstream_and_slice_buffer
static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, DECODER_BUFFER_DESC *bs, DECODER_BUFFER_DESC *sc)
Definition: dxva2_av1.c:347
AV1RawFilmGrainParams::chroma_scaling_from_luma
uint8_t chroma_scaling_from_luma
Definition: cbs_av1.h:141
AV1RawFilmGrainParams::ar_coeffs_cr_plus_128
uint8_t ar_coeffs_cr_plus_128[25]
Definition: cbs_av1.h:152
AV1RawSequenceHeader::film_grain_params_present
uint8_t film_grain_params_present
Definition: cbs_av1.h:130
decoder
static const chunk_decoder decoder[8]
Definition: dfa.c:331
dxva2_av1_end_frame
static int dxva2_av1_end_frame(AVCodecContext *avctx)
Definition: dxva2_av1.c:433
FFHWAccel
Definition: hwaccel_internal.h:34
AV1_MAX_SEGMENTS
@ AV1_MAX_SEGMENTS
Definition: av1.h:88
AV1RawSequenceHeader::enable_ref_frame_mvs
uint8_t enable_ref_frame_mvs
Definition: cbs_av1.h:115
AV1RawSequenceHeader::enable_filter_intra
uint8_t enable_filter_intra
Definition: cbs_av1.h:106
AV1RawFilmGrainParams::point_cr_scaling
uint8_t point_cr_scaling[10]
Definition: cbs_av1.h:147
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AV1RawFilmGrainParams::ar_coeff_shift_minus_6
uint8_t ar_coeff_shift_minus_6
Definition: cbs_av1.h:153
AV1RawFilmGrainParams::num_y_points
uint8_t num_y_points
Definition: cbs_av1.h:138
AV1RawFilmGrainParams::num_cb_points
uint8_t num_cb_points
Definition: cbs_av1.h:142
AV1RawFilmGrainParams::cb_luma_mult
uint8_t cb_luma_mult
Definition: cbs_av1.h:156
avassert.h
AV1RawFilmGrainParams::overlap_flag
uint8_t overlap_flag
Definition: cbs_av1.h:161
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AV1RawSequenceHeader::enable_masked_compound
uint8_t enable_masked_compound
Definition: cbs_av1.h:109
AV1_REF_FRAME_LAST
@ AV1_REF_FRAME_LAST
Definition: av1.h:62
DXVA2_CONTEXT
#define DXVA2_CONTEXT(ctx)
Definition: dxva2_internal.h:102
AV1RawFilmGrainParams::grain_scaling_minus_8
uint8_t grain_scaling_minus_8
Definition: cbs_av1.h:148
av_fast_realloc
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
Definition: mem.c:495
ref_frame
static const AVFrame * ref_frame(const struct pl_frame_mix *mix)
Definition: vf_libplacebo.c:783
AV_PIX_FMT_DXVA2_VLD
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
Definition: pixfmt.h:127
AV1DXVAContext::bitstream_cache
uint8_t * bitstream_cache
Definition: dxva2_av1.c:38
AV1_NUM_REF_FRAMES
@ AV1_NUM_REF_FRAMES
Definition: av1.h:83
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
DXVA_CONTEXT
#define DXVA_CONTEXT(avctx)
Definition: dxva2_internal.h:99
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av1_dxva2_picture_context::tile_count
unsigned tile_count
Definition: dxva2_av1.c:43
av1dec.h
dxva2_internal.h
NULL
#define NULL
Definition: coverity.c:32
ff_dxva2_decode_init
int ff_dxva2_decode_init(AVCodecContext *avctx)
Definition: dxva2.c:655
AV1RawFilmGrainParams::cb_mult
uint8_t cb_mult
Definition: cbs_av1.h:155
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:283
hwaccel_internal.h
AV1RawFrameHeader
Definition: cbs_av1.h:165
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:476
FFDXVASharedContext
Definition: dxva2_internal.h:67
AV1RawSequenceHeader::enable_jnt_comp
uint8_t enable_jnt_comp
Definition: cbs_av1.h:114
MAX_TILES
#define MAX_TILES
Definition: dxva2_av1.c:32
av1_dxva2_picture_context::tiles
DXVA_Tile_AV1 tiles[MAX_TILES]
Definition: dxva2_av1.c:44
ff_av1_dxva2_hwaccel
const struct FFHWAccel ff_av1_dxva2_hwaccel
dxva2_av1_decode_slice
static int dxva2_av1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: dxva2_av1.c:292
dxva2_av1_uninit
static int dxva2_av1_uninit(AVCodecContext *avctx)
Definition: dxva2_av1.c:450
AV1RawSequenceHeader::max_frame_height_minus_1
uint16_t max_frame_height_minus_1
Definition: cbs_av1.h:99
AV1_RESTORE_NONE
@ AV1_RESTORE_NONE
Definition: av1.h:172
AV1RawFilmGrainParams::point_cr_value
uint8_t point_cr_value[10]
Definition: cbs_av1.h:146
AV1RawFilmGrainParams::cb_offset
uint16_t cb_offset
Definition: cbs_av1.h:157
AV1DXVAContext
Definition: dxva2_av1.c:34
AVCodecInternal::hwaccel_priv_data
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:124
AV1DXVAContext::bitstream_allocated
unsigned int bitstream_allocated
Definition: dxva2_av1.c:37
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
size
int size
Definition: twinvq_data.h:10344
AV1DecContext
Definition: av1dec.h:63
AV1RawSequenceHeader::use_128x128_superblock
uint8_t use_128x128_superblock
Definition: cbs_av1.h:105
av1_dxva2_picture_context::bitstream_size
unsigned bitstream_size
Definition: dxva2_av1.c:46
AVDXVAContext
Definition: dxva2_internal.h:58
DECODER_BUFFER_DESC
void DECODER_BUFFER_DESC
Definition: dxva2_internal.h:56
AV_PIX_FMT_D3D11
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition: pixfmt.h:333
AV1RawFilmGrainParams::grain_scale_shift
uint8_t grain_scale_shift
Definition: cbs_av1.h:154
AV1RawSequenceHeader::enable_interintra_compound
uint8_t enable_interintra_compound
Definition: cbs_av1.h:108
av1_dxva2_picture_context
Definition: dxva2_av1.c:41
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2135
D3D11VA_CONTEXT
#define D3D11VA_CONTEXT(ctx)
Definition: dxva2_internal.h:101
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AV1RawSequenceHeader::enable_dual_filter
uint8_t enable_dual_filter
Definition: cbs_av1.h:111
AV1RawSequenceHeader::enable_intra_edge_filter
uint8_t enable_intra_edge_filter
Definition: cbs_av1.h:107
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV1_SUPERRES_DENOM_MIN
@ AV1_SUPERRES_DENOM_MIN
Definition: av1.h:101
AV1RawSequenceHeader::max_frame_width_minus_1
uint16_t max_frame_width_minus_1
Definition: cbs_av1.h:98
AV1RawSequenceHeader::color_config
AV1RawColorConfig color_config
Definition: cbs_av1.h:128
ff_dxva2_commit_buffer
int ff_dxva2_commit_buffer(AVCodecContext *avctx, AVDXVAContext *ctx, DECODER_BUFFER_DESC *dsc, unsigned type, const void *data, unsigned size, unsigned mb_count)
Definition: dxva2.c:797
AV1_RESTORE_WIENER
@ AV1_RESTORE_WIENER
Definition: av1.h:173
AV1RawSequenceHeader::enable_order_hint
uint8_t enable_order_hint
Definition: cbs_av1.h:113
AVCodecContext::height
int height
Definition: avcodec.h:621
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:658
AV1_RESTORE_SGRPROJ
@ AV1_RESTORE_SGRPROJ
Definition: av1.h:174
ff_dxva2_get_surface_index
unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx, const AVDXVAContext *ctx, const AVFrame *frame)
Definition: dxva2.c:770
AV1_TOTAL_REFS_PER_FRAME
@ AV1_TOTAL_REFS_PER_FRAME
Definition: av1.h:85
ff_dxva2_common_frame_params
int ff_dxva2_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition: dxva2.c:592
AV1_REFS_PER_FRAME
@ AV1_REFS_PER_FRAME
Definition: av1.h:84
ret
ret
Definition: filter_design.txt:187
AV1RawColorConfig::subsampling_x
uint8_t subsampling_x
Definition: cbs_av1.h:52
AV1RawColorConfig::high_bitdepth
uint8_t high_bitdepth
Definition: cbs_av1.h:42
AV1RawFilmGrainParams::cr_luma_mult
uint8_t cr_luma_mult
Definition: cbs_av1.h:159
AVCodecContext
main external API structure.
Definition: avcodec.h:441
AVFrame::height
int height
Definition: frame.h:412
AV1_SEG_LVL_MAX
@ AV1_SEG_LVL_MAX
Definition: av1.h:89
frame_header
Definition: truemotion1.c:88
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
ff_dxva2_is_d3d11
int ff_dxva2_is_d3d11(const AVCodecContext *avctx)
Definition: dxva2.c:1051
av1_dxva2_picture_context::pp
DXVA_PicParams_AV1 pp
Definition: dxva2_av1.c:42
AV1RawFilmGrainParams::ar_coeff_lag
uint8_t ar_coeff_lag
Definition: cbs_av1.h:149
AV1RawColorConfig::mono_chrome
uint8_t mono_chrome
Definition: cbs_av1.h:44
AVCodecContext::export_side_data
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame,...
Definition: avcodec.h:2057
AV1RawFilmGrainParams::ar_coeffs_cb_plus_128
uint8_t ar_coeffs_cb_plus_128[25]
Definition: cbs_av1.h:151
AV1RawFilmGrainParams::ar_coeffs_y_plus_128
uint8_t ar_coeffs_y_plus_128[24]
Definition: cbs_av1.h:150
AV1RawSequenceHeader::order_hint_bits_minus_1
uint8_t order_hint_bits_minus_1
Definition: cbs_av1.h:122
AV1RawColorConfig::matrix_coefficients
uint8_t matrix_coefficients
Definition: cbs_av1.h:49
AV1RawFilmGrainParams::cr_offset
uint16_t cr_offset
Definition: cbs_av1.h:160
AV1RawFilmGrainParams::point_y_scaling
uint8_t point_y_scaling[14]
Definition: cbs_av1.h:140
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
ff_dxva2_decode_uninit
int ff_dxva2_decode_uninit(AVCodecContext *avctx)
Definition: dxva2.c:730
AV1RawFilmGrainParams::point_cb_scaling
uint8_t point_cb_scaling[10]
Definition: cbs_av1.h:144
AV1RawSequenceHeader::enable_restoration
uint8_t enable_restoration
Definition: cbs_av1.h:126
AV1RawColorConfig::twelve_bit
uint8_t twelve_bit
Definition: cbs_av1.h:43
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:468
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AV1RawSequenceHeader::enable_cdef
uint8_t enable_cdef
Definition: cbs_av1.h:125
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:621
AV1RawFilmGrainParams
Definition: cbs_av1.h:133
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2038
AV1RawFilmGrainParams::num_cr_points
uint8_t num_cr_points
Definition: cbs_av1.h:145
AV_CODEC_EXPORT_DATA_FILM_GRAIN
#define AV_CODEC_EXPORT_DATA_FILM_GRAIN
Decoding only.
Definition: avcodec.h:416
ff_av1_d3d11va_hwaccel
const struct FFHWAccel ff_av1_d3d11va_hwaccel