21 #define DXVA2API_USE_BITFIELDS
42 #define FF_D3DCREATE_FLAGS (D3DCREATE_SOFTWARE_VERTEXPROCESSING | \
43 D3DCREATE_MULTITHREADED | \
44 D3DCREATE_FPU_PRESERVE)
48 .BackBufferWidth = 640,
49 .BackBufferHeight = 480,
51 .SwapEffect = D3DSWAPEFFECT_DISCARD,
52 .Flags = D3DPRESENTFLAG_VIDEO,
64 IDirectXVideoAccelerationService *
service;
88 DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
89 DEFINE_GUID(video_processor_service, 0xfc51a552, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
101 if (
s->surfaces_internal) {
103 if (
s->surfaces_internal[
i])
104 IDirect3DSurface9_Release(
s->surfaces_internal[
i]);
110 IDirectXVideoAccelerationService_Release(
s->service);
114 if (
s->device_handle != INVALID_HANDLE_VALUE) {
115 IDirect3DDeviceManager9_CloseDeviceHandle(device_hwctx->
devmgr,
s->device_handle);
116 s->device_handle = INVALID_HANDLE_VALUE;
134 s->nb_surfaces_used++;
152 if (
ctx->initial_pool_size <= 0)
155 hr = IDirect3DDeviceManager9_OpenDeviceHandle(device_hwctx->
devmgr, &
s->device_handle);
161 hr = IDirect3DDeviceManager9_GetVideoService(device_hwctx->
devmgr,
163 decode ? &video_decoder_service : &video_processor_service,
164 (
void **)&
s->service);
183 sizeof(*
s->surfaces_internal));
184 if (!
s->surfaces_internal)
187 hr = IDirectXVideoAccelerationService_CreateSurface(
s->service,
189 ctx->initial_pool_size - 1,
190 s->format, D3DPOOL_DEFAULT, 0,
192 s->surfaces_internal,
NULL);
203 frames_hwctx->
surfaces =
s->surfaces_internal;
215 if (hwctx->
surface_type != DXVA2_VideoDecoderRenderTarget &&
216 hwctx->
surface_type != DXVA2_VideoProcessorRenderTarget) {
222 s->device_handle = INVALID_HANDLE_VALUE;
260 fmts[0] =
ctx->sw_format;
270 IDirect3DSurface9 *surface = (IDirect3DSurface9*)hwmap->
source->
data[3];
271 IDirect3DSurface9_UnlockRect(surface);
278 IDirect3DSurface9 *surface = (IDirect3DSurface9*)
src->data[3];
280 D3DSURFACE_DESC surfaceDesc;
281 D3DLOCKED_RECT LockedRect;
283 int i, err, nb_planes;
288 hr = IDirect3DSurface9_GetDesc(surface, &surfaceDesc);
295 lock_flags |= D3DLOCK_READONLY;
297 lock_flags |= D3DLOCK_DISCARD;
299 hr = IDirect3DSurface9_LockRect(surface, &LockedRect,
NULL, lock_flags);
318 for (
i = 0;
i < nb_planes;
i++)
329 IDirect3DSurface9_UnlockRect(surface);
339 if (
src->format !=
ctx->sw_format)
352 ctx->sw_format,
src->width,
src->height);
363 ptrdiff_t src_linesize[4], dst_linesize[4];
378 for (
i = 0;
i < 4;
i++) {
380 src_linesize[
i] =
map->linesize[
i];
383 ctx->sw_format,
src->width,
src->height);
418 IDirect3DDeviceManager9_Release(hwctx->
devmgr);
424 IDirect3D9_Release(priv->
d3d9);
439 D3DDISPLAYMODE d3ddm;
447 priv->
d3d9 = createD3D(D3D_SDK_VERSION);
453 IDirect3D9_GetAdapterDisplayMode(priv->
d3d9, adapter, &d3ddm);
455 d3dpp.BackBufferFormat = d3ddm.Format;
457 hr = IDirect3D9_CreateDevice(priv->
d3d9, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
472 D3DDISPLAYMODEEX modeex = {0};
473 IDirect3D9Ex *d3d9ex =
NULL;
474 IDirect3DDevice9Ex *exdev =
NULL;
480 hr = createD3DEx(D3D_SDK_VERSION, &d3d9ex);
484 modeex.Size =
sizeof(D3DDISPLAYMODEEX);
485 hr = IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, adapter, &modeex,
NULL);
487 IDirect3D9Ex_Release(d3d9ex);
491 d3dpp.BackBufferFormat = modeex.Format;
493 hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
495 &d3dpp,
NULL, &exdev);
497 IDirect3D9Ex_Release(d3d9ex);
502 priv->
d3d9 = (IDirect3D9 *)d3d9ex;
513 unsigned resetToken = 0;
514 UINT adapter = D3DADAPTER_DEFAULT;
519 adapter = atoi(device);
525 ctx->user_opaque = priv;
530 priv->
d3dlib = dlopen(
"d3d9.dll", 0);
535 priv->
dxva2lib = dlopen(
"dxva2.dll", 0);
542 "DXVA2CreateDirect3DDeviceManager9");
543 if (!createDeviceManager) {
555 hr = createDeviceManager(&resetToken, &hwctx->
devmgr);
561 hr = IDirect3DDeviceManager9_ResetDevice(hwctx->
devmgr, priv->
d3d9device, resetToken);
simple assert() macros that are a bit more flexible than ISO C assert().
#define flags(name, subs,...)
common internal and external API header
#define MKTAG(a, b, c, d)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
AVBufferRef * av_buffer_create(uint8_t *data, buffer_size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
AVBufferPool * av_buffer_pool_init2(buffer_size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, buffer_size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
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 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.
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.
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
AVHWFrameTransferDirection
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
@ AV_HWFRAME_MAP_OVERWRITE
The mapped frame will be overwritten completely in subsequent operations, so the current frame data n...
IDirect3D9 *WINAPI pDirect3DCreate9(UINT)
static int dxva2_device_create9ex(AVHWDeviceContext *ctx, UINT adapter)
static void dxva2_unmap_frame(AVHWFramesContext *ctx, HWMapDescriptor *hwmap)
#define FF_D3DCREATE_FLAGS
static int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter)
static void dxva2_device_free(AVHWDeviceContext *ctx)
static int dxva2_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
const HWContextType ff_hwcontext_type_dxva2
static void dxva2_frames_uninit(AVHWFramesContext *ctx)
DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02)
static const D3DPRESENT_PARAMETERS dxva2_present_params
static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
static int dxva2_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **)
enum AVPixelFormat pix_fmt
static int dxva2_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
static int dxva2_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
static AVBufferRef * dxva2_pool_alloc(void *opaque, buffer_size_t size)
static int dxva2_map_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
static int dxva2_init_pool(AVHWFramesContext *ctx)
HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **)
static const struct @300 supported_formats[]
static int dxva2_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
static int dxva2_frames_init(AVHWFramesContext *ctx)
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
const VDPAUPixFmtMap * map
static enum AVPixelFormat pix_fmts[]
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
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.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
This struct is allocated as AVHWDeviceContext.hwctx.
IDirect3DDeviceManager9 * devmgr
This struct is allocated as AVHWFramesContext.hwctx.
IDirect3DSurface9 ** surfaces
The surface pool.
DWORD surface_type
The surface type (e.g.
IDirectXVideoDecoder * decoder_to_release
Certain drivers require the decoder to be destroyed before the surfaces.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
This struct describes a set or pool of "hardware" frames (i.e.
IDirect3DDevice9 * d3d9device
IDirectXVideoAccelerationService * service
IDirect3DSurface9 ** surfaces_internal
uint32_t palette_dummy[256]
void * priv
Hardware-specific private data associated with the mapping.
AVFrame * source
A reference to the original source of the mapping.
#define av_malloc_array(a, b)