]> git.sesse.net Git - ffmpeg/blob - libavcodec/dxva2_av1.c
tests: drop api-codec-param test
[ffmpeg] / libavcodec / dxva2_av1.c
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 "libavutil/avassert.h"
24 #include "libavutil/pixdesc.h"
25
26 #include "dxva2_internal.h"
27 #include "av1dec.h"
28
29 #define MAX_TILES 256
30
31 struct AV1DXVAContext {
32     FFDXVASharedContext shared;
33
34     unsigned int bitstream_allocated;
35     uint8_t *bitstream_cache;
36 };
37
38 struct av1_dxva2_picture_context {
39     DXVA_PicParams_AV1    pp;
40     unsigned              tile_count;
41     DXVA_Tile_AV1         tiles[MAX_TILES];
42     uint8_t              *bitstream;
43     unsigned              bitstream_size;
44 };
45
46 static int get_bit_depth_from_seq(const AV1RawSequenceHeader *seq)
47 {
48     if (seq->seq_profile == 2 && seq->color_config.high_bitdepth)
49         return seq->color_config.twelve_bit ? 12 : 10;
50     else if (seq->seq_profile <= 2 && seq->color_config.high_bitdepth)
51         return 10;
52     else
53         return 8;
54 }
55
56 static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, const AV1DecContext *h,
57                                     DXVA_PicParams_AV1 *pp)
58 {
59     int i,j, uses_lr;
60     const AV1RawSequenceHeader *seq = h->raw_seq;
61     const AV1RawFrameHeader *frame_header = h->raw_frame_header;
62     const AV1RawFilmGrainParams *film_grain = &h->cur_frame.film_grain;
63
64     unsigned char remap_lr_type[4] = { AV1_RESTORE_NONE, AV1_RESTORE_SWITCHABLE, AV1_RESTORE_WIENER, AV1_RESTORE_SGRPROJ };
65
66     memset(pp, 0, sizeof(*pp));
67
68     pp->width  = avctx->width;
69     pp->height = avctx->height;
70
71     pp->max_width  = seq->max_frame_width_minus_1 + 1;
72     pp->max_height = seq->max_frame_height_minus_1 + 1;
73
74     pp->CurrPicTextureIndex = ff_dxva2_get_surface_index(avctx, ctx, h->cur_frame.tf.f);
75     pp->superres_denom      = frame_header->use_superres ? frame_header->coded_denom : AV1_SUPERRES_NUM;
76     pp->bitdepth            = get_bit_depth_from_seq(seq);
77     pp->seq_profile         = seq->seq_profile;
78
79     /* Tiling info */
80     pp->tiles.cols = frame_header->tile_cols;
81     pp->tiles.rows = frame_header->tile_rows;
82     pp->tiles.context_update_id = frame_header->context_update_tile_id;
83
84     for (i = 0; i < pp->tiles.cols; i++)
85         pp->tiles.widths[i] = frame_header->width_in_sbs_minus_1[i] + 1;
86
87     for (i = 0; i < pp->tiles.rows; i++)
88         pp->tiles.heights[i] = frame_header->height_in_sbs_minus_1[i] + 1;
89
90     /* Coding tools */
91     pp->coding.use_128x128_superblock       = seq->use_128x128_superblock;
92     pp->coding.intra_edge_filter            = seq->enable_intra_edge_filter;
93     pp->coding.interintra_compound          = seq->enable_interintra_compound;
94     pp->coding.masked_compound              = seq->enable_masked_compound;
95     pp->coding.warped_motion                = frame_header->allow_warped_motion;
96     pp->coding.dual_filter                  = seq->enable_dual_filter;
97     pp->coding.jnt_comp                     = seq->enable_jnt_comp;
98     pp->coding.screen_content_tools         = frame_header->allow_screen_content_tools;
99     pp->coding.integer_mv                   = frame_header->force_integer_mv || !(frame_header->frame_type & 1);
100     pp->coding.cdef                         = seq->enable_cdef;
101     pp->coding.restoration                  = seq->enable_restoration;
102     pp->coding.film_grain                   = seq->film_grain_params_present;
103     pp->coding.intrabc                      = frame_header->allow_intrabc;
104     pp->coding.high_precision_mv            = frame_header->allow_high_precision_mv;
105     pp->coding.switchable_motion_mode       = frame_header->is_motion_mode_switchable;
106     pp->coding.filter_intra                 = seq->enable_filter_intra;
107     pp->coding.disable_frame_end_update_cdf = frame_header->disable_frame_end_update_cdf;
108     pp->coding.disable_cdf_update           = frame_header->disable_cdf_update;
109     pp->coding.reference_mode               = frame_header->reference_select;
110     pp->coding.skip_mode                    = frame_header->skip_mode_present;
111     pp->coding.reduced_tx_set               = frame_header->reduced_tx_set;
112     pp->coding.superres                     = frame_header->use_superres;
113     pp->coding.tx_mode                      = frame_header->tx_mode;
114     pp->coding.use_ref_frame_mvs            = frame_header->use_ref_frame_mvs;
115     pp->coding.enable_ref_frame_mvs         = seq->enable_ref_frame_mvs;
116     pp->coding.reference_frame_update       = 1; // 0 for show_existing_frame with key frames, but those are not passed to the hwaccel
117
118     /* Format & Picture Info flags */
119     pp->format.frame_type     = frame_header->frame_type;
120     pp->format.show_frame     = frame_header->show_frame;
121     pp->format.showable_frame = frame_header->showable_frame;
122     pp->format.subsampling_x  = seq->color_config.subsampling_x;
123     pp->format.subsampling_y  = seq->color_config.subsampling_y;
124     pp->format.mono_chrome    = seq->color_config.mono_chrome;
125
126     /* References */
127     pp->primary_ref_frame = frame_header->primary_ref_frame;
128     pp->order_hint        = frame_header->order_hint;
129     pp->order_hint_bits   = seq->enable_order_hint ? seq->order_hint_bits_minus_1 + 1 : 0;
130
131     memset(pp->RefFrameMapTextureIndex, 0xFF, sizeof(pp->RefFrameMapTextureIndex));
132     for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
133         int8_t ref_idx = frame_header->ref_frame_idx[i];
134         AVFrame *ref_frame = h->ref[ref_idx].tf.f;
135
136         pp->frame_refs[i].width  = ref_frame->width;
137         pp->frame_refs[i].height = ref_frame->height;
138         pp->frame_refs[i].Index  = ref_frame->buf[0] ? ref_idx : 0xFF;
139
140         /* Global Motion */
141         pp->frame_refs[i].wminvalid = (h->cur_frame.gm_type[AV1_REF_FRAME_LAST + i] == AV1_WARP_MODEL_IDENTITY);
142         pp->frame_refs[i].wmtype    = h->cur_frame.gm_type[AV1_REF_FRAME_LAST + i];
143         for (j = 0; j < 6; ++j) {
144              pp->frame_refs[i].wmmat[j] = h->cur_frame.gm_params[AV1_REF_FRAME_LAST + i][j];
145         }
146     }
147     for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
148         AVFrame *ref_frame = h->ref[i].tf.f;
149         if (ref_frame->buf[0])
150             pp->RefFrameMapTextureIndex[i] = ff_dxva2_get_surface_index(avctx, ctx, ref_frame);
151     }
152
153     /* Loop filter parameters */
154     pp->loop_filter.filter_level[0]        = frame_header->loop_filter_level[0];
155     pp->loop_filter.filter_level[1]        = frame_header->loop_filter_level[1];
156     pp->loop_filter.filter_level_u         = frame_header->loop_filter_level[2];
157     pp->loop_filter.filter_level_v         = frame_header->loop_filter_level[3];
158     pp->loop_filter.sharpness_level        = frame_header->loop_filter_sharpness;
159     pp->loop_filter.mode_ref_delta_enabled = frame_header->loop_filter_delta_enabled;
160     pp->loop_filter.mode_ref_delta_update  = frame_header->loop_filter_delta_update;
161     pp->loop_filter.delta_lf_multi         = frame_header->delta_lf_multi;
162     pp->loop_filter.delta_lf_present       = frame_header->delta_lf_present;
163     pp->loop_filter.delta_lf_res           = frame_header->delta_lf_res;
164
165     for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) {
166         pp->loop_filter.ref_deltas[i] = frame_header->loop_filter_ref_deltas[i];
167     }
168
169     pp->loop_filter.mode_deltas[0]                = frame_header->loop_filter_mode_deltas[0];
170     pp->loop_filter.mode_deltas[1]                = frame_header->loop_filter_mode_deltas[1];
171     pp->loop_filter.frame_restoration_type[0]     = remap_lr_type[frame_header->lr_type[0]];
172     pp->loop_filter.frame_restoration_type[1]     = remap_lr_type[frame_header->lr_type[1]];
173     pp->loop_filter.frame_restoration_type[2]     = remap_lr_type[frame_header->lr_type[2]];
174     uses_lr = frame_header->lr_type[0] || frame_header->lr_type[1] || frame_header->lr_type[2];
175     pp->loop_filter.log2_restoration_unit_size[0] = uses_lr ? (6 + frame_header->lr_unit_shift) : 8;
176     pp->loop_filter.log2_restoration_unit_size[1] = uses_lr ? (6 + frame_header->lr_unit_shift - frame_header->lr_uv_shift) : 8;
177     pp->loop_filter.log2_restoration_unit_size[2] = uses_lr ? (6 + frame_header->lr_unit_shift - frame_header->lr_uv_shift) : 8;
178
179     /* Quantization */
180     pp->quantization.delta_q_present = frame_header->delta_q_present;
181     pp->quantization.delta_q_res     = frame_header->delta_q_res;
182     pp->quantization.base_qindex     = frame_header->base_q_idx;
183     pp->quantization.y_dc_delta_q    = frame_header->delta_q_y_dc;
184     pp->quantization.u_dc_delta_q    = frame_header->delta_q_u_dc;
185     pp->quantization.v_dc_delta_q    = frame_header->delta_q_v_dc;
186     pp->quantization.u_ac_delta_q    = frame_header->delta_q_u_ac;
187     pp->quantization.v_ac_delta_q    = frame_header->delta_q_v_ac;
188     pp->quantization.qm_y            = frame_header->using_qmatrix ? frame_header->qm_y : 0xFF;
189     pp->quantization.qm_u            = frame_header->using_qmatrix ? frame_header->qm_u : 0xFF;
190     pp->quantization.qm_v            = frame_header->using_qmatrix ? frame_header->qm_v : 0xFF;
191
192     /* Cdef parameters */
193     pp->cdef.damping = frame_header->cdef_damping_minus_3;
194     pp->cdef.bits    = frame_header->cdef_bits;
195     for (i = 0; i < 8; i++) {
196         pp->cdef.y_strengths[i].primary    = frame_header->cdef_y_pri_strength[i];
197         pp->cdef.y_strengths[i].secondary  = frame_header->cdef_y_sec_strength[i];
198         pp->cdef.uv_strengths[i].primary   = frame_header->cdef_uv_pri_strength[i];
199         pp->cdef.uv_strengths[i].secondary = frame_header->cdef_uv_sec_strength[i];
200     }
201
202     /* Misc flags */
203     pp->interp_filter = frame_header->interpolation_filter;
204
205     /* Segmentation */
206     pp->segmentation.enabled         = frame_header->segmentation_enabled;
207     pp->segmentation.update_map      = frame_header->segmentation_update_map;
208     pp->segmentation.update_data     = frame_header->segmentation_update_data;
209     pp->segmentation.temporal_update = frame_header->segmentation_temporal_update;
210     for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
211         for (j = 0; j < AV1_SEG_LVL_MAX; j++) {
212             pp->segmentation.feature_mask[i].mask |= frame_header->feature_enabled[i][j] << j;
213             pp->segmentation.feature_data[i][j]    = frame_header->feature_value[i][j];
214         }
215     }
216
217     /* Film grain */
218     if (film_grain->apply_grain) {
219         pp->film_grain.apply_grain              = 1;
220         pp->film_grain.scaling_shift_minus8     = film_grain->grain_scaling_minus_8;
221         pp->film_grain.chroma_scaling_from_luma = film_grain->chroma_scaling_from_luma;
222         pp->film_grain.ar_coeff_lag             = film_grain->ar_coeff_lag;
223         pp->film_grain.ar_coeff_shift_minus6    = film_grain->ar_coeff_shift_minus_6;
224         pp->film_grain.grain_scale_shift        = film_grain->grain_scale_shift;
225         pp->film_grain.overlap_flag             = film_grain->overlap_flag;
226         pp->film_grain.clip_to_restricted_range = film_grain->clip_to_restricted_range;
227         pp->film_grain.matrix_coeff_is_identity = (seq->color_config.matrix_coefficients == AVCOL_SPC_RGB);
228
229         pp->film_grain.grain_seed               = film_grain->grain_seed;
230         pp->film_grain.num_y_points             = film_grain->num_y_points;
231         for (i = 0; i < film_grain->num_y_points; i++) {
232             pp->film_grain.scaling_points_y[i][0] = film_grain->point_y_value[i];
233             pp->film_grain.scaling_points_y[i][1] = film_grain->point_y_scaling[i];
234         }
235         pp->film_grain.num_cb_points            = film_grain->num_cb_points;
236         for (i = 0; i < film_grain->num_cb_points; i++) {
237             pp->film_grain.scaling_points_cb[i][0] = film_grain->point_cb_value[i];
238             pp->film_grain.scaling_points_cb[i][1] = film_grain->point_cb_scaling[i];
239         }
240         pp->film_grain.num_cr_points            = film_grain->num_cr_points;
241         for (i = 0; i < film_grain->num_cr_points; i++) {
242             pp->film_grain.scaling_points_cr[i][0] = film_grain->point_cr_value[i];
243             pp->film_grain.scaling_points_cr[i][1] = film_grain->point_cr_scaling[i];
244         }
245         for (i = 0; i < 24; i++) {
246             pp->film_grain.ar_coeffs_y[i] = film_grain->ar_coeffs_y_plus_128[i];
247         }
248         for (i = 0; i < 25; i++) {
249             pp->film_grain.ar_coeffs_cb[i] = film_grain->ar_coeffs_cb_plus_128[i];
250             pp->film_grain.ar_coeffs_cr[i] = film_grain->ar_coeffs_cr_plus_128[i];
251         }
252         pp->film_grain.cb_mult      = film_grain->cb_mult;
253         pp->film_grain.cb_luma_mult = film_grain->cb_luma_mult;
254         pp->film_grain.cr_mult      = film_grain->cr_mult;
255         pp->film_grain.cr_luma_mult = film_grain->cr_luma_mult;
256         pp->film_grain.cb_offset    = film_grain->cb_offset;
257         pp->film_grain.cr_offset    = film_grain->cr_offset;
258         pp->film_grain.cr_offset    = film_grain->cr_offset;
259     }
260
261     // XXX: Setting the StatusReportFeedbackNumber breaks decoding on some drivers (tested on NVIDIA 457.09)
262     // Status Reporting is not used by FFmpeg, hence not providing a number does not cause any issues
263     //pp->StatusReportFeedbackNumber = 1 + DXVA_CONTEXT_REPORT_ID(avctx, ctx)++;
264     return 0;
265 }
266
267 static int dxva2_av1_start_frame(AVCodecContext *avctx,
268                                  av_unused const uint8_t *buffer,
269                                  av_unused uint32_t size)
270 {
271     const AV1DecContext *h = avctx->priv_data;
272     AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
273     struct av1_dxva2_picture_context *ctx_pic = h->cur_frame.hwaccel_picture_private;
274
275     if (!DXVA_CONTEXT_VALID(avctx, ctx))
276         return -1;
277     av_assert0(ctx_pic);
278
279     /* Fill up DXVA_PicParams_AV1 */
280     if (fill_picture_parameters(avctx, ctx, h, &ctx_pic->pp) < 0)
281         return -1;
282
283     ctx_pic->bitstream_size = 0;
284     ctx_pic->bitstream      = NULL;
285     return 0;
286 }
287
288 static int dxva2_av1_decode_slice(AVCodecContext *avctx,
289                                   const uint8_t *buffer,
290                                   uint32_t size)
291 {
292     const AV1DecContext *h = avctx->priv_data;
293     const AV1RawFrameHeader *frame_header = h->raw_frame_header;
294     struct av1_dxva2_picture_context *ctx_pic = h->cur_frame.hwaccel_picture_private;
295     struct AV1DXVAContext *ctx = avctx->internal->hwaccel_priv_data;
296     void *tmp;
297
298     ctx_pic->tile_count = frame_header->tile_cols * frame_header->tile_rows;
299
300     /* too many tiles, exceeding all defined levels in the AV1 spec */
301     if (ctx_pic->tile_count > MAX_TILES)
302         return AVERROR(ENOSYS);
303
304     /* Shortcut if all tiles are in the same buffer */
305     if (ctx_pic->tile_count == h->tg_end - h->tg_start + 1) {
306         ctx_pic->bitstream = (uint8_t *)buffer;
307         ctx_pic->bitstream_size = size;
308
309         for (uint32_t tile_num = 0; tile_num < ctx_pic->tile_count; tile_num++) {
310             ctx_pic->tiles[tile_num].DataOffset   = h->tile_group_info[tile_num].tile_offset;
311             ctx_pic->tiles[tile_num].DataSize     = h->tile_group_info[tile_num].tile_size;
312             ctx_pic->tiles[tile_num].row          = h->tile_group_info[tile_num].tile_row;
313             ctx_pic->tiles[tile_num].column       = h->tile_group_info[tile_num].tile_column;
314             ctx_pic->tiles[tile_num].anchor_frame = 0xFF;
315         }
316
317         return 0;
318     }
319
320     /* allocate an internal buffer */
321     tmp = av_fast_realloc(ctx->bitstream_cache, &ctx->bitstream_allocated,
322                           ctx_pic->bitstream_size + size);
323     if (!tmp) {
324         return AVERROR(ENOMEM);
325     }
326     ctx_pic->bitstream = ctx->bitstream_cache = tmp;
327
328     memcpy(ctx_pic->bitstream + ctx_pic->bitstream_size, buffer, size);
329
330     for (uint32_t tile_num = h->tg_start; tile_num <= h->tg_end; tile_num++) {
331         ctx_pic->tiles[tile_num].DataOffset   = ctx_pic->bitstream_size + h->tile_group_info[tile_num].tile_offset;
332         ctx_pic->tiles[tile_num].DataSize     = h->tile_group_info[tile_num].tile_size;
333         ctx_pic->tiles[tile_num].row          = h->tile_group_info[tile_num].tile_row;
334         ctx_pic->tiles[tile_num].column       = h->tile_group_info[tile_num].tile_column;
335         ctx_pic->tiles[tile_num].anchor_frame = 0xFF;
336     }
337
338     ctx_pic->bitstream_size += size;
339
340     return 0;
341 }
342
343 static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
344                                              DECODER_BUFFER_DESC *bs,
345                                              DECODER_BUFFER_DESC *sc)
346 {
347     const AV1DecContext *h = avctx->priv_data;
348     AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
349     struct av1_dxva2_picture_context *ctx_pic = h->cur_frame.hwaccel_picture_private;
350     void     *dxva_data_ptr;
351     uint8_t  *dxva_data;
352     unsigned dxva_size;
353     unsigned padding;
354     unsigned type;
355
356 #if CONFIG_D3D11VA
357     if (ff_dxva2_is_d3d11(avctx)) {
358         type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
359         if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context,
360                                                        D3D11VA_CONTEXT(ctx)->decoder,
361                                                        type,
362                                                        &dxva_size, &dxva_data_ptr)))
363             return -1;
364     }
365 #endif
366 #if CONFIG_DXVA2
367     if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {
368         type = DXVA2_BitStreamDateBufferType;
369         if (FAILED(IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(ctx)->decoder,
370                                                   type,
371                                                   &dxva_data_ptr, &dxva_size)))
372             return -1;
373     }
374 #endif
375
376     dxva_data = dxva_data_ptr;
377
378     if (ctx_pic->bitstream_size > dxva_size) {
379         av_log(avctx, AV_LOG_ERROR, "Bitstream size exceeds hardware buffer");
380         return -1;
381     }
382
383     memcpy(dxva_data, ctx_pic->bitstream, ctx_pic->bitstream_size);
384
385     padding = FFMIN(128 - ((ctx_pic->bitstream_size) & 127), dxva_size - ctx_pic->bitstream_size);
386     if (padding > 0) {
387         memset(dxva_data + ctx_pic->bitstream_size, 0, padding);
388         ctx_pic->bitstream_size += padding;
389     }
390
391 #if CONFIG_D3D11VA
392     if (ff_dxva2_is_d3d11(avctx))
393         if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type)))
394             return -1;
395 #endif
396 #if CONFIG_DXVA2
397     if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
398         if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(ctx)->decoder, type)))
399             return -1;
400 #endif
401
402 #if CONFIG_D3D11VA
403     if (ff_dxva2_is_d3d11(avctx)) {
404         D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs;
405         memset(dsc11, 0, sizeof(*dsc11));
406         dsc11->BufferType           = type;
407         dsc11->DataSize             = ctx_pic->bitstream_size;
408         dsc11->NumMBsInBuffer       = 0;
409
410         type = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
411     }
412 #endif
413 #if CONFIG_DXVA2
414     if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {
415         DXVA2_DecodeBufferDesc *dsc2 = bs;
416         memset(dsc2, 0, sizeof(*dsc2));
417         dsc2->CompressedBufferType = type;
418         dsc2->DataSize             = ctx_pic->bitstream_size;
419         dsc2->NumMBsInBuffer       = 0;
420
421         type = DXVA2_SliceControlBufferType;
422     }
423 #endif
424
425     return ff_dxva2_commit_buffer(avctx, ctx, sc, type,
426                                   ctx_pic->tiles, sizeof(*ctx_pic->tiles) * ctx_pic->tile_count, 0);
427 }
428
429 static int dxva2_av1_end_frame(AVCodecContext *avctx)
430 {
431     const AV1DecContext *h = avctx->priv_data;
432     struct av1_dxva2_picture_context *ctx_pic = h->cur_frame.hwaccel_picture_private;
433     int ret;
434
435     if (ctx_pic->bitstream_size <= 0)
436         return -1;
437
438     ret = ff_dxva2_common_end_frame(avctx, h->cur_frame.tf.f,
439                                     &ctx_pic->pp, sizeof(ctx_pic->pp),
440                                     NULL, 0,
441                                     commit_bitstream_and_slice_buffer);
442
443     return ret;
444 }
445
446 static int dxva2_av1_uninit(AVCodecContext *avctx)
447 {
448     struct AV1DXVAContext *ctx = avctx->internal->hwaccel_priv_data;
449
450     av_freep(&ctx->bitstream_cache);
451     ctx->bitstream_allocated = 0;
452
453     return ff_dxva2_decode_uninit(avctx);
454 }
455
456 #if CONFIG_AV1_DXVA2_HWACCEL
457 const AVHWAccel ff_av1_dxva2_hwaccel = {
458     .name           = "av1_dxva2",
459     .type           = AVMEDIA_TYPE_VIDEO,
460     .id             = AV_CODEC_ID_AV1,
461     .pix_fmt        = AV_PIX_FMT_DXVA2_VLD,
462     .init           = ff_dxva2_decode_init,
463     .uninit         = dxva2_av1_uninit,
464     .start_frame    = dxva2_av1_start_frame,
465     .decode_slice   = dxva2_av1_decode_slice,
466     .end_frame      = dxva2_av1_end_frame,
467     .frame_params   = ff_dxva2_common_frame_params,
468     .frame_priv_data_size = sizeof(struct av1_dxva2_picture_context),
469     .priv_data_size = sizeof(struct AV1DXVAContext),
470 };
471 #endif
472
473 #if CONFIG_AV1_D3D11VA_HWACCEL
474 const AVHWAccel ff_av1_d3d11va_hwaccel = {
475     .name           = "av1_d3d11va",
476     .type           = AVMEDIA_TYPE_VIDEO,
477     .id             = AV_CODEC_ID_AV1,
478     .pix_fmt        = AV_PIX_FMT_D3D11VA_VLD,
479     .init           = ff_dxva2_decode_init,
480     .uninit         = dxva2_av1_uninit,
481     .start_frame    = dxva2_av1_start_frame,
482     .decode_slice   = dxva2_av1_decode_slice,
483     .end_frame      = dxva2_av1_end_frame,
484     .frame_params   = ff_dxva2_common_frame_params,
485     .frame_priv_data_size = sizeof(struct av1_dxva2_picture_context),
486     .priv_data_size = sizeof(struct AV1DXVAContext),
487 };
488 #endif
489
490 #if CONFIG_AV1_D3D11VA2_HWACCEL
491 const AVHWAccel ff_av1_d3d11va2_hwaccel = {
492     .name           = "av1_d3d11va2",
493     .type           = AVMEDIA_TYPE_VIDEO,
494     .id             = AV_CODEC_ID_AV1,
495     .pix_fmt        = AV_PIX_FMT_D3D11,
496     .init           = ff_dxva2_decode_init,
497     .uninit         = dxva2_av1_uninit,
498     .start_frame    = dxva2_av1_start_frame,
499     .decode_slice   = dxva2_av1_decode_slice,
500     .end_frame      = dxva2_av1_end_frame,
501     .frame_params   = ff_dxva2_common_frame_params,
502     .frame_priv_data_size = sizeof(struct av1_dxva2_picture_context),
503     .priv_data_size = sizeof(struct AV1DXVAContext),
504 };
505 #endif