24 #define _WIN32_WINNT 0x0600
25 #define DXVA2API_USE_BITFIELDS
49 DEFINE_GUID(IID_IDirectXVideoDecoderService, 0xfc51a551,0xd5e7,0x11d9,0xaf,0x55,0x00,0x05,0x4e,0x43,0xff,0x02);
51 DEFINE_GUID(DXVA2_ModeMPEG2_VLD, 0xee27417f, 0x5e28,0x4e65,0xbe,0xea,0x1d,0x26,0xb5,0x08,0xad,0xc9);
52 DEFINE_GUID(DXVA2_ModeMPEG2and1_VLD, 0x86695f12, 0x340e,0x4f04,0x9f,0xd3,0x92,0x53,0xdd,0x32,0x74,0x60);
53 DEFINE_GUID(DXVA2_ModeH264_E, 0x1b81be68, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
54 DEFINE_GUID(DXVA2_ModeH264_F, 0x1b81be69, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
55 DEFINE_GUID(DXVADDI_Intel_ModeH264_E, 0x604F8E68, 0x4951,0x4C54,0x88,0xFE,0xAB,0xD2,0x5C,0x15,0xB3,0xD6);
56 DEFINE_GUID(DXVA2_ModeVC1_D, 0x1b81beA3, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
57 DEFINE_GUID(DXVA2_ModeVC1_D2010, 0x1b81beA4, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
58 DEFINE_GUID(DXVA2_ModeHEVC_VLD_Main, 0x5b11d51b, 0x2f4c,0x4452,0xbc,0xc3,0x09,0xf2,0xa1,0x16,0x0c,0xc0);
59 DEFINE_GUID(DXVA2_ModeHEVC_VLD_Main10,0x107af0e0, 0xef1a,0x4d19,0xab,0xa8,0x67,0xa1,0x63,0x07,0x3d,0x13);
60 DEFINE_GUID(DXVA2_ModeVP9_VLD_Profile0, 0x463707f8, 0xa1d0,0x4585,0x87,0x6d,0x83,0xaa,0x6d,0x60,0xb8,0x9e);
61 DEFINE_GUID(DXVA2_NoEncrypt, 0x1b81beD0, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
62 DEFINE_GUID(GUID_NULL, 0x00000000, 0x0000,0x0000,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
186 device_hwctx = device_ctx->
hwctx;
188 hr = IDirect3DDeviceManager9_OpenDeviceHandle(device_hwctx->
devmgr,
191 av_log(
NULL, loglevel,
"Failed to open a device handle\n");
195 hr = IDirect3DDeviceManager9_GetVideoService(device_hwctx->
devmgr, device_handle,
196 &IID_IDirectXVideoDecoderService,
198 IDirect3DDeviceManager9_CloseDeviceHandle(device_hwctx->
devmgr, device_handle);
200 av_log(
NULL, loglevel,
"Failed to create IDirectXVideoDecoderService\n");
219 const DXVA2_VideoDesc *
desc,
220 DXVA2_ConfigPictureDecode *
config)
225 unsigned cfg_count = 0, best_score = 0;
226 DXVA2_ConfigPictureDecode *cfg_list =
NULL;
227 DXVA2_ConfigPictureDecode best_cfg = {{0}};
231 hr = IDirectXVideoDecoderService_GetDecoderConfigurations(ctx->
decoder_service, device_guid, desc,
NULL, &cfg_count, &cfg_list);
233 av_log(
NULL, loglevel,
"Unable to retrieve decoder configurations\n");
237 for (i = 0; i < cfg_count; i++) {
238 DXVA2_ConfigPictureDecode *cfg = &cfg_list[i];
241 if (cfg->ConfigBitstreamRaw == 1)
247 if (IsEqualGUID(&cfg->guidConfigBitstreamEncryption, &DXVA2_NoEncrypt))
249 if (score > best_score) {
254 CoTaskMemFree(cfg_list);
257 av_log(
NULL, loglevel,
"No valid decoder configuration available\n");
272 unsigned guid_count = 0, i, j;
273 GUID device_guid = GUID_NULL;
275 D3DFORMAT target_format = 0;
276 DXVA2_VideoDesc
desc = { 0 };
277 DXVA2_ConfigPictureDecode
config;
279 int surface_alignment, num_surfaces;
285 hr = IDirectXVideoDecoderService_GetDecoderDeviceGuids(ctx->
decoder_service, &guid_count, &guid_list);
287 av_log(
NULL, loglevel,
"Failed to retrieve decoder device GUIDs\n");
291 for (i = 0; dxva2_modes[i].
guid; i++) {
292 D3DFORMAT *target_list =
NULL;
293 unsigned target_count = 0;
298 for (j = 0; j < guid_count; j++) {
299 if (IsEqualGUID(mode->
guid, &guid_list[j]))
305 hr = IDirectXVideoDecoderService_GetDecoderRenderTargets(ctx->
decoder_service, mode->
guid, &target_count, &target_list);
309 for (j = 0; j < target_count; j++) {
310 const D3DFORMAT
format = target_list[j];
311 if (format == surface_format) {
316 CoTaskMemFree(target_list);
318 device_guid = *mode->
guid;
322 CoTaskMemFree(guid_list);
324 if (IsEqualGUID(&device_guid, &GUID_NULL)) {
325 av_log(
NULL, loglevel,
"No decoder device for codec found\n");
331 desc.Format = target_format;
341 surface_alignment = 32;
345 surface_alignment = 128;
347 surface_alignment = 16;
368 frames_hwctx = frames_ctx->
hwctx;
376 frames_hwctx->
surface_type = DXVA2_VideoDecoderRenderTarget;
380 av_log(
NULL, loglevel,
"Failed to initialize the HW frames context\n");
384 hr = IDirectXVideoDecoderService_CreateVideoDecoder(ctx->
decoder_service, &device_guid,
385 &desc, &config, frames_hwctx->
surfaces,
388 av_log(
NULL, loglevel,
"Failed to create DXVA2 video decoder\n");
400 if (IsEqualGUID(&ctx->
decoder_guid, &DXVADDI_Intel_ModeH264_E))
425 av_log(
NULL, loglevel,
"Unsupported H.264 profile for DXVA2 HWAccel: %d\n", s->
profile);
431 av_log(
NULL, loglevel,
"Unsupported HEVC profile for DXVA2 HWAccel: %d\n", s->
profile);
439 av_log(
NULL, loglevel,
"Error creating the DXVA2 decoder\n");
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
This structure describes decoded (raw) audio or video data.
int coded_width
Bitstream width / height, may be different from width/height e.g.
This struct is allocated as AVHWFramesContext.hwctx.
static int dxva2_create_decoder(AVCodecContext *s)
static FFServerConfig config
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
static void dxva2_uninit(AVCodecContext *s)
int width
The allocated dimensions of the frames in this pool.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
LPDIRECT3DSURFACE9 * surface
The array of Direct3D surfaces used to create the decoder.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const DXVA2_ConfigPictureDecode * cfg
DXVA2 configuration used to create the decoder.
unsigned surface_count
The number of surface in the surface array.
int dxva2_init(AVCodecContext *s)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
void * hwaccel_context
Hardware accelerator context.
DWORD surface_type
The surface type (e.g.
#define FF_PROFILE_HEVC_MAIN
static int dxva2_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
#define AV_LOG_VERBOSE
Detailed information.
#define FF_PROFILE_HEVC_MAIN_10
static const dxva2_mode dxva2_modes[]
uint64_t workaround
A bit field configuring the workarounds needed for using the decoder.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
IDirectXVideoDecoder * decoder_to_release
Certain drivers require the decoder to be destroyed before the surfaces.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int active_thread_type
Which multithreading methods are in use by the codec.
#define FF_PROFILE_H264_HIGH
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
simple assert() macros that are a bit more flexible than ISO C assert().
IDirect3DDeviceManager9 * devmgr
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
reference-counted frame API
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
int initial_pool_size
Initial size of the frame pool.
DXVA2_ConfigPictureDecode decoder_config
#define FF_THREAD_FRAME
Decode more than one frame at once.
#define FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO
Work around for Direct3D11 and old Intel GPUs with ClearVideo interface.
preferred ID for MPEG-1/2 video decoding
static int dxva2_get_decoder_configuration(AVCodecContext *s, const GUID *device_guid, const DXVA2_VideoDesc *desc, DXVA2_ConfigPictureDecode *config)
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Public libavcodec DXVA2 header.
main external API structure.
uint8_t * data
The data buffer.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
#define AV_PIX_FMT_YUV420P10
static const char * format
This struct describes a set or pool of "hardware" frames (i.e.
refcounted data buffer API
IDirectXVideoDecoder * decoder
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
AVBufferRef * hw_device_ctx
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
A reference to a data buffer.
static int dxva2_alloc(AVCodecContext *s)
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
DEFINE_GUID(IID_IDirectXVideoDecoderService, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02)
IDirect3DSurface9 ** surfaces
The surface pool.
static int dxva2_retrieve_data(AVCodecContext *s, AVFrame *frame)
IDirectXVideoDecoderService * decoder_service
This struct is allocated as AVHWDeviceContext.hwctx.
AVBufferRef * hw_frames_ctx
IDirectXVideoDecoder * decoder
DXVA2 decoder object.
#define FF_PROFILE_H264_CONSTRAINED
#define MKTAG(a, b, c, d)
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
mode
Use these values in ebur128_init (or'ed).
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
void * opaque
Private data of the user, can be used to carry app specific stuff.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
This structure is used to provides the necessary configurations and data to the DXVA2 FFmpeg HWAccel ...