FFmpeg
Loading...
Searching...
No Matches
dxva2_internal.h
Go to the documentation of this file.
1/*
2 * DXVA2 HW acceleration
3 *
4 * copyright (c) 2010 Laurent Aimar
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#ifndef AVCODEC_DXVA2_INTERNAL_H
24#define AVCODEC_DXVA2_INTERNAL_H
25
26#define COBJMACROS
27
28#include "config.h"
29#include "config_components.h"
30
31/* define the proper COM entries before forcing desktop APIs */
32#include <objbase.h>
33
34#define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for DXVA2/Direct3D11 and old UVD/UVD+ ATI video cards
35#define FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO 2 ///< Work around for DXVA2/Direct3D11 and old Intel GPUs with ClearVideo interface
36
37#if CONFIG_DXVA2
38#include "dxva2.h"
40#define DXVA2_VAR(ctx, var) ctx->dxva2.var
41#else
42#define DXVA2_VAR(ctx, var) 0
43#endif
44
45#if CONFIG_D3D11VA
46#include "d3d11va.h"
48#define D3D11VA_VAR(ctx, var) ctx->d3d11va.var
49#else
50#define D3D11VA_VAR(ctx, var) 0
51#endif
52
53#if CONFIG_D3D12VA
54#include "d3d12va_decode.h"
55#endif
56
57#if HAVE_DXVA_H
58/* When targeting WINAPI_FAMILY_PHONE_APP or WINAPI_FAMILY_APP, dxva.h
59 * defines nothing. Force the struct definitions to be visible. */
60#undef WINAPI_FAMILY
61#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP
62#undef _CRT_BUILD_DESKTOP_APP
63#define _CRT_BUILD_DESKTOP_APP 0
64#include <dxva.h>
65#endif
66
67#include "libavutil/hwcontext.h"
68
69#include "avcodec.h"
70#include "internal.h"
71
73
74typedef union {
75#if CONFIG_D3D11VA
76 struct AVD3D11VAContext d3d11va;
77#endif
78#if CONFIG_DXVA2
79 struct dxva_context dxva2;
80#endif
81#if CONFIG_D3D12VA
82 struct D3D12VADecodeContext d3d12va;
83#endif
85
86typedef struct FFDXVASharedContext {
88
89 // FF_DXVA2_WORKAROUND_* flags
90 uint64_t workaround;
91
92 // E.g. AV_PIX_FMT_D3D11 (same as AVCodecContext.pix_fmt, except during init)
94
96
97#if CONFIG_D3D11VA
98 ID3D11VideoDecoder *d3d11_decoder;
99 D3D11_VIDEO_DECODER_CONFIG d3d11_config;
100 ID3D11VideoDecoderOutputView **d3d11_views;
101 int nb_d3d11_views;
102 ID3D11Texture2D *d3d11_texture;
103#endif
104
105#if CONFIG_DXVA2
106 IDirectXVideoDecoder *dxva2_decoder;
107 IDirectXVideoDecoderService *dxva2_service;
108 DXVA2_ConfigPictureDecode dxva2_config;
109#endif
110
111 // Legacy (but used by code outside of setup)
112 // In generic mode, DXVA_CONTEXT() will return a pointer to this.
115
116#define DXVA_SHARED_CONTEXT(avctx) ((FFDXVASharedContext *)((avctx)->internal->hwaccel_priv_data))
117
118#define DXVA_CONTEXT(avctx) (AVDXVAContext *)((avctx)->hwaccel_context ? (avctx)->hwaccel_context : (&(DXVA_SHARED_CONTEXT(avctx)->ctx)))
119
120#define D3D11VA_CONTEXT(ctx) (&ctx->d3d11va)
121#define DXVA2_CONTEXT(ctx) (&ctx->dxva2)
122
123#define DXVA2_CONTEXT_VAR(avctx, ctx, var) (avctx->pix_fmt == AV_PIX_FMT_D3D12 ? 0 : (ff_dxva2_is_d3d11(avctx) ? D3D11VA_VAR(ctx, var) : DXVA2_VAR(ctx, var)))
124
125#define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*ff_dxva2_get_report_id(avctx, ctx))
126#define DXVA_CONTEXT_WORKAROUND(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, workaround)
127#define DXVA_CONTEXT_COUNT(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, surface_count)
128#define DXVA_CONTEXT_DECODER(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D12 ? 0 : (ff_dxva2_is_d3d11(avctx) ? (void *)D3D11VA_VAR(ctx, decoder) : (void *)DXVA2_VAR(ctx, decoder)))
129#define DXVA_CONTEXT_CFG(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D12 ? 0 : (ff_dxva2_is_d3d11(avctx) ? (void *)D3D11VA_VAR(ctx, cfg) : (void *)DXVA2_VAR(ctx, cfg)))
130#define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, cfg->ConfigBitstreamRaw)
131#define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, cfg->ConfigIntraResidUnsigned)
132#define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) DXVA2_CONTEXT_VAR(avctx, ctx, cfg->ConfigResidDiffAccelerator)
133#define DXVA_CONTEXT_VALID(avctx, ctx) (DXVA_CONTEXT_DECODER(avctx, ctx) && \
134 DXVA_CONTEXT_CFG(avctx, ctx) && \
135 (ff_dxva2_is_d3d11(avctx) || DXVA2_VAR(ctx, surface_count)))
136
137#if CONFIG_D3D12VA
138unsigned ff_d3d12va_get_surface_index(const AVCodecContext *avctx,
140 int curr);
141#endif
142
143unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
144 AVDXVAContext *, const AVFrame *frame, int curr);
145
148 unsigned type, const void *data, unsigned size,
149 unsigned mb_count);
150
151
153 const void *pp, unsigned pp_size,
154 const void *qm, unsigned qm_size,
155 int (*commit_bs_si)(AVCodecContext *,
157 DECODER_BUFFER_DESC *slice));
158
160
162
164 AVBufferRef *hw_frames_ctx);
165
166int ff_dxva2_is_d3d11(const AVCodecContext *avctx);
167
169
170void ff_dxva2_h264_fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PicParams_H264 *pp);
171
172void ff_dxva2_h264_fill_scaling_lists(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_Qmatrix_H264 *qm);
173
174#if CONFIG_HEVC_D3D12VA_HWACCEL || CONFIG_HEVC_D3D11VA_HWACCEL || CONFIG_HEVC_D3D11VA2_HWACCEL || CONFIG_HEVC_DXVA2_HWACCEL
175void ff_dxva2_hevc_fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PicParams_HEVC *pp);
176
177void ff_dxva2_hevc_fill_scaling_lists(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_Qmatrix_HEVC *qm);
178#endif
179
180#if CONFIG_VP9_D3D12VA_HWACCEL || CONFIG_VP9_D3D11VA_HWACCEL || CONFIG_VP9_D3D11VA2_HWACCEL || CONFIG_VP9_DXVA2_HWACCEL
181int ff_dxva2_vp9_fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PicParams_VP9 *pp);
182#endif
183
184#if CONFIG_AV1_D3D12VA_HWACCEL || CONFIG_AV1_D3D11VA_HWACCEL || CONFIG_AV1_D3D11VA2_HWACCEL || CONFIG_AV1_DXVA2_HWACCEL
185int ff_dxva2_av1_fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PicParams_AV1 *pp);
186#endif
187
188void ff_dxva2_mpeg2_fill_picture_parameters(AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PictureParameters *pp);
189
191
192void ff_dxva2_mpeg2_fill_slice(AVCodecContext *avctx, DXVA_SliceInfo *slice, unsigned position, const uint8_t *buffer, unsigned size);
193
194void ff_dxva2_vc1_fill_picture_parameters(AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PictureParameters *pp);
195
196void ff_dxva2_vc1_fill_slice(AVCodecContext *avctx, DXVA_SliceInfo *slice, unsigned position, unsigned size);
197
198#endif /* AVCODEC_DXVA2_INTERNAL_H */
static AVFormatContext * ctx
Libavcodec external API header.
Public libavcodec D3D11VA header.
unsigned ff_d3d12va_get_surface_index(const AVCodecContext *avctx, D3D12VADecodeContext *ctx, const AVFrame *frame, int curr)
static AVFrame * frame
Public libavcodec DXVA2 header.
int ff_dxva2_av1_fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PicParams_AV1 *pp)
Definition dxva2_av1.c:60
void ff_dxva2_hevc_fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PicParams_HEVC *pp)
Definition dxva2_hevc.c:60
void ff_dxva2_hevc_fill_scaling_lists(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_Qmatrix_HEVC *qm)
Definition dxva2_hevc.c:205
int ff_dxva2_is_d3d11(const AVCodecContext *avctx)
Definition dxva2.c:1068
void ff_dxva2_h264_fill_scaling_lists(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_Qmatrix_H264 *qm)
Definition dxva2_h264.c:168
int ff_dxva2_common_end_frame(AVCodecContext *, AVFrame *, 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:903
void ff_dxva2_mpeg2_fill_quantization_matrices(AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_QmatrixData *qm)
unsigned * ff_dxva2_get_report_id(const AVCodecContext *avctx, AVDXVAContext *ctx)
Definition dxva2.c:1077
int ff_dxva2_decode_init(AVCodecContext *avctx)
Definition dxva2.c:668
void ff_dxva2_mpeg2_fill_picture_parameters(AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PictureParameters *pp)
Definition dxva2_mpeg2.c:43
void ff_dxva2_h264_fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PicParams_H264 *pp)
Definition dxva2_h264.c:51
int ff_dxva2_decode_uninit(AVCodecContext *avctx)
Definition dxva2.c:743
unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx, AVDXVAContext *, const AVFrame *frame, int curr)
Definition dxva2.c:783
void ff_dxva2_mpeg2_fill_slice(AVCodecContext *avctx, DXVA_SliceInfo *slice, unsigned position, const uint8_t *buffer, unsigned size)
int ff_dxva2_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Definition dxva2.c:602
int ff_dxva2_commit_buffer(AVCodecContext *, AVDXVAContext *, DECODER_BUFFER_DESC *, unsigned type, const void *data, unsigned size, unsigned mb_count)
Definition dxva2.c:814
void ff_dxva2_vc1_fill_picture_parameters(AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PictureParameters *pp)
Definition dxva2_vc1.c:43
void ff_dxva2_vc1_fill_slice(AVCodecContext *avctx, DXVA_SliceInfo *slice, unsigned position, unsigned size)
Definition dxva2_vc1.c:167
void DECODER_BUFFER_DESC
int ff_dxva2_vp9_fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PicParams_VP9 *pp)
Definition dxva2_vp9.c:46
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
cl_device_type type
common internal api header.
const char data[16]
Definition mxf.c:149
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
A reference to a data buffer.
Definition buffer.h:82
main external API structure.
Definition avcodec.h:443
This structure is used to provides the necessary configurations and data to the Direct3D11 FFmpeg HWA...
Definition d3d11va.h:56
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
This structure is used to provide the necessary configurations and data to the FFmpeg Direct3D 12 HWA...
AVHWDeviceContext * device_ctx
enum AVPixelFormat pix_fmt
AVBufferRef * decoder_ref
This structure is used to provides the necessary configurations and data to the DXVA2 FFmpeg HWAccel ...
Definition dxva2.h:54
static char buffer[20]
Definition seek.c:32
int size