21 #if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600
23 #define _WIN32_WINNT 0x0600
25 #define DXVA2API_USE_BITFIELDS
49 IDirectXVideoAccelerationService *
service;
72 DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
73 DEFINE_GUID(video_processor_service, 0xfc51a552, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
94 IDirectXVideoAccelerationService_Release(s->
service);
138 hr = IDirect3DDeviceManager9_GetVideoService(device_hwctx->
devmgr,
140 decode ? &video_decoder_service : &video_processor_service,
164 hr = IDirectXVideoAccelerationService_CreateSurface(s->
service,
167 s->
format, D3DPOOL_DEFAULT, 0,
192 if (hwctx->
surface_type != DXVA2_VideoDecoderRenderTarget &&
193 hwctx->
surface_type != DXVA2_VideoProcessorRenderTarget) {
248 IDirect3DSurface9 *surface;
249 D3DSURFACE_DESC surfaceDesc;
250 D3DLOCKED_RECT LockedRect;
254 int bytes_per_component;
258 bytes_per_component = 1;
261 bytes_per_component = 2;
267 surface = (IDirect3DSurface9*)(download ? src->
data[3] : dst->
data[3]);
269 hr = IDirect3DSurface9_GetDesc(surface, &surfaceDesc);
275 hr = IDirect3DSurface9_LockRect(surface, &LockedRect,
NULL,
276 download ? D3DLOCK_READONLY : D3DLOCK_DISCARD);
284 (
uint8_t*)LockedRect.pBits, LockedRect.Pitch,
287 (
uint8_t*)LockedRect.pBits + LockedRect.Pitch * surfaceDesc.Height,
288 LockedRect.Pitch, src->
width * bytes_per_component, src->
height / 2);
295 src->
width * bytes_per_component, src->
height / 2);
298 IDirect3DSurface9_UnlockRect(surface);
312 IDirect3DDeviceManager9_Release(hwctx->
devmgr);
318 IDirect3D9_Release(priv->
d3d9);
337 D3DPRESENT_PARAMETERS d3dpp = {0};
338 D3DDISPLAYMODE d3ddm;
339 unsigned resetToken = 0;
340 UINT adapter = D3DADAPTER_DEFAULT;
344 adapter = atoi(device);
372 "DXVA2CreateDirect3DDeviceManager9");
373 if (!createDeviceManager) {
378 priv->
d3d9 = createD3D(D3D_SDK_VERSION);
384 IDirect3D9_GetAdapterDisplayMode(priv->
d3d9, adapter, &d3ddm);
385 d3dpp.Windowed =
TRUE;
386 d3dpp.BackBufferWidth = 640;
387 d3dpp.BackBufferHeight = 480;
388 d3dpp.BackBufferCount = 0;
389 d3dpp.BackBufferFormat = d3ddm.Format;
390 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
391 d3dpp.Flags = D3DPRESENTFLAG_VIDEO;
393 hr = IDirect3D9_CreateDevice(priv->
d3d9, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
394 D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
401 hr = createDeviceManager(&resetToken, &hwctx->
devmgr);
407 hr = IDirect3DDeviceManager9_ResetDevice(hwctx->
devmgr, priv->
d3d9device, resetToken);
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
This structure describes decoded (raw) audio or video data.
This struct is allocated as AVHWFramesContext.hwctx.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
static enum AVSampleFormat formats[]
int width
The allocated dimensions of the frames in this pool.
static int dxva2_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
AVBufferPool * pool_internal
static const struct @217 supported_formats[]
enum AVPixelFormat pix_fmt
DWORD surface_type
The surface type (e.g.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
IDirect3D9 *WINAPI pDirect3DCreate9(UINT)
static AVBufferRef * dxva2_pool_alloc(void *opaque, int size)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int dxva2_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
IDirectXVideoDecoder * decoder_to_release
Certain drivers require the decoder to be destroyed before the surfaces.
void(* free)(struct AVHWDeviceContext *ctx)
This field may be set by the caller before calling av_hwdevice_ctx_init().
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
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
int initial_pool_size
Initial size of the frame pool.
IDirect3DDevice9 * d3d9device
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
static int dxva2_frames_init(AVHWFramesContext *ctx)
IDirectXVideoAccelerationService * service
AVBufferPool * av_buffer_pool_init2(int size, void *opaque, AVBufferRef *(*alloc)(void *opaque, int size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
#define FF_ARRAY_ELEMS(a)
static void dxva2_frames_uninit(AVHWFramesContext *ctx)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
uint8_t * data
The data buffer.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **)
DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02)
static int dxva2_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
This struct describes a set or pool of "hardware" frames (i.e.
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
AVHWFramesInternal * internal
Private data used internally by libavutil.
static enum AVPixelFormat pix_fmts[]
static void dxva2_device_free(AVHWDeviceContext *ctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void * user_opaque
Arbitrary user data, to be used e.g.
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
A reference to a data buffer.
IDirect3DSurface9 ** surfaces_internal
common internal and external API header
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
IDirect3DSurface9 ** surfaces
The surface pool.
AVHWFrameTransferDirection
AVBufferPool * pool
A pool from which the frames are allocated by av_hwframe_get_buffer().
This struct is allocated as AVHWDeviceContext.hwctx.
static void * av_mallocz_array(size_t nmemb, size_t size)
static int dxva2_init_pool(AVHWFramesContext *ctx)
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
#define av_malloc_array(a, b)
#define INVALID_HANDLE_VALUE
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
#define MKTAG(a, b, c, d)
const HWContextType ff_hwcontext_type_dxva2
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...