21 #if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600
23 #define _WIN32_WINNT 0x0600
25 #define DXVA2API_USE_BITFIELDS
46 #define FF_D3DCREATE_FLAGS (D3DCREATE_SOFTWARE_VERTEXPROCESSING | \
47 D3DCREATE_MULTITHREADED | \
48 D3DCREATE_FPU_PRESERVE)
52 .BackBufferWidth = 640,
53 .BackBufferHeight = 480,
55 .SwapEffect = D3DSWAPEFFECT_DISCARD,
56 .Flags = D3DPRESENTFLAG_VIDEO,
68 IDirectXVideoAccelerationService *
service;
92 DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
93 DEFINE_GUID(video_processor_service, 0xfc51a552, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
114 IDirectXVideoAccelerationService_Release(s->
service);
165 hr = IDirect3DDeviceManager9_GetVideoService(device_hwctx->
devmgr,
167 decode ? &video_decoder_service : &video_processor_service,
191 hr = IDirectXVideoAccelerationService_CreateSurface(s->
service,
194 s->
format, D3DPOOL_DEFAULT, 0,
219 if (hwctx->
surface_type != DXVA2_VideoDecoderRenderTarget &&
220 hwctx->
surface_type != DXVA2_VideoProcessorRenderTarget) {
274 IDirect3DSurface9 *surface = (IDirect3DSurface9*)hwmap->
source->
data[3];
275 IDirect3DSurface9_UnlockRect(surface);
282 IDirect3DSurface9 *surface = (IDirect3DSurface9*)src->
data[3];
284 D3DSURFACE_DESC surfaceDesc;
285 D3DLOCKED_RECT LockedRect;
287 int i, err, nb_planes;
292 hr = IDirect3DSurface9_GetDesc(surface, &surfaceDesc);
299 lock_flags |= D3DLOCK_READONLY;
301 lock_flags |= D3DLOCK_DISCARD;
303 hr = IDirect3DSurface9_LockRect(surface, &LockedRect,
NULL, lock_flags);
320 for (i = 0; i < nb_planes; i++)
321 dst->
linesize[i] = LockedRect.Pitch;
331 IDirect3DSurface9_UnlockRect(surface);
365 ptrdiff_t src_linesize[4], dst_linesize[4];
380 for (i = 0; i < 4; i++) {
420 IDirect3DDeviceManager9_Release(hwctx->
devmgr);
426 IDirect3D9_Release(priv->
d3d9);
441 D3DDISPLAYMODE d3ddm;
449 priv->
d3d9 = createD3D(D3D_SDK_VERSION);
455 IDirect3D9_GetAdapterDisplayMode(priv->
d3d9, adapter, &d3ddm);
457 d3dpp.BackBufferFormat = d3ddm.Format;
459 hr = IDirect3D9_CreateDevice(priv->
d3d9, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
474 D3DDISPLAYMODEEX modeex = {0};
475 IDirect3D9Ex *d3d9ex =
NULL;
476 IDirect3DDevice9Ex *exdev =
NULL;
482 hr = createD3DEx(D3D_SDK_VERSION, &d3d9ex);
486 IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, adapter, &modeex,
NULL);
488 d3dpp.BackBufferFormat = modeex.Format;
490 hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
492 &d3dpp,
NULL, &exdev);
494 IDirect3D9Ex_Release(d3d9ex);
499 priv->
d3d9 = (IDirect3D9 *)d3d9ex;
510 unsigned resetToken = 0;
511 UINT adapter = D3DADAPTER_DEFAULT;
516 adapter = atoi(device);
527 priv->
d3dlib = dlopen(
"d3d9.dll", 0);
532 priv->
dxva2lib = dlopen(
"dxva2.dll", 0);
539 "DXVA2CreateDirect3DDeviceManager9");
540 if (!createDeviceManager) {
552 hr = createDeviceManager(&resetToken, &hwctx->
devmgr);
558 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.
ptrdiff_t const GLvoid * data
The mapped frame will be overwritten completely in subsequent operations, so the current frame data n...
The mapping must be writeable.
This struct is allocated as AVHWFramesContext.hwctx.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
static int dxva2_map_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
int width
The allocated dimensions of the frames in this pool.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
AVBufferPool * pool_internal
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
enum AVPixelFormat pix_fmt
8 bits with AV_PIX_FMT_RGB32 palette
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 void dxva2_unmap_frame(AVHWFramesContext *ctx, HWMapDescriptor *hwmap)
#define AV_LOG_VERBOSE
Detailed information.
static const struct @238 supported_formats[]
static AVBufferRef * dxva2_pool_alloc(void *opaque, int size)
static int dxva2_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
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().
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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 void * av_mallocz_array(size_t nmemb, size_t size)
static int dxva2_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
int initial_pool_size
Initial size of the frame pool.
AVFrame * source
A reference to the original source of the mapping.
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)
static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height, uint8_t *ptr, const int linesizes[4])
Fill plane data pointers for an image with pixel format pix_fmt and height height.
void * priv
Hardware-specific private data associated with the mapping.
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)
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
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.
HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **)
const VDPAUPixFmtMap * map
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
AVHWFramesInternal * internal
Private data used internally by libavutil.
static enum AVPixelFormat pix_fmts[]
The mapping must be readable.
static void dxva2_device_free(AVHWDeviceContext *ctx)
static int dxva2_device_create9ex(AVHWDeviceContext *ctx, UINT adapter)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void * user_opaque
Arbitrary user data, to be used e.g.
#define FF_D3DCREATE_FLAGS
A reference to a data buffer.
static int dxva2_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
IDirect3DSurface9 ** surfaces_internal
common internal and external API header
void av_image_copy_uc_from(uint8_t *dst_data[4], const ptrdiff_t dst_linesizes[4], const uint8_t *src_data[4], const ptrdiff_t src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image data located in uncacheable (e.g.
uint32_t palette_dummy[256]
#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 int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter)
static const D3DPRESENT_PARAMETERS dxva2_present_params
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
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
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.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.