Go to the documentation of this file.
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;
89 DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
90 DEFINE_GUID(video_processor_service, 0xfc51a552, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
102 if (
s->surfaces_internal) {
104 if (
s->surfaces_internal[
i])
105 IDirect3DSurface9_Release(
s->surfaces_internal[
i]);
111 IDirectXVideoAccelerationService_Release(
s->service);
115 if (
s->device_handle != INVALID_HANDLE_VALUE) {
116 IDirect3DDeviceManager9_CloseDeviceHandle(device_hwctx->
devmgr,
s->device_handle);
117 s->device_handle = INVALID_HANDLE_VALUE;
135 s->nb_surfaces_used++;
153 if (
ctx->initial_pool_size <= 0)
156 hr = IDirect3DDeviceManager9_OpenDeviceHandle(device_hwctx->
devmgr, &
s->device_handle);
162 hr = IDirect3DDeviceManager9_GetVideoService(device_hwctx->
devmgr,
164 decode ? &video_decoder_service : &video_processor_service,
165 (
void **)&
s->service);
184 sizeof(*
s->surfaces_internal));
185 if (!
s->surfaces_internal)
188 hr = IDirectXVideoAccelerationService_CreateSurface(
s->service,
190 ctx->initial_pool_size - 1,
191 s->format, D3DPOOL_DEFAULT, 0,
193 s->surfaces_internal,
NULL);
201 if (!
ctx->internal->pool_internal)
204 frames_hwctx->
surfaces =
s->surfaces_internal;
216 if (hwctx->
surface_type != DXVA2_VideoDecoderRenderTarget &&
217 hwctx->
surface_type != DXVA2_VideoProcessorRenderTarget) {
223 s->device_handle = INVALID_HANDLE_VALUE;
261 fmts[0] =
ctx->sw_format;
271 IDirect3DSurface9 *surface = (IDirect3DSurface9*)hwmap->
source->
data[3];
272 IDirect3DSurface9_UnlockRect(surface);
279 IDirect3DSurface9 *surface = (IDirect3DSurface9*)
src->data[3];
281 D3DSURFACE_DESC surfaceDesc;
282 D3DLOCKED_RECT LockedRect;
284 int i, err, nb_planes;
289 hr = IDirect3DSurface9_GetDesc(surface, &surfaceDesc);
296 lock_flags |= D3DLOCK_READONLY;
298 lock_flags |= D3DLOCK_DISCARD;
300 hr = IDirect3DSurface9_LockRect(surface, &LockedRect,
NULL, lock_flags);
319 for (
i = 0;
i < nb_planes;
i++)
323 (uint8_t*)LockedRect.pBits, dst->
linesize);
326 dst->
data[1] = (uint8_t*)
map->palette_dummy;
330 IDirect3DSurface9_UnlockRect(surface);
340 if (
src->format !=
ctx->sw_format)
353 ctx->sw_format,
src->width,
src->height);
364 ptrdiff_t src_linesize[4], dst_linesize[4];
379 for (
i = 0;
i < 4;
i++) {
381 src_linesize[
i] =
map->linesize[
i];
384 ctx->sw_format,
src->width,
src->height);
419 IDirect3DDeviceManager9_Release(hwctx->
devmgr);
425 IDirect3D9_Release(priv->
d3d9);
440 D3DDISPLAYMODE d3ddm;
448 priv->
d3d9 = createD3D(D3D_SDK_VERSION);
454 IDirect3D9_GetAdapterDisplayMode(priv->
d3d9, adapter, &d3ddm);
456 d3dpp.BackBufferFormat = d3ddm.Format;
458 hr = IDirect3D9_CreateDevice(priv->
d3d9, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
473 D3DDISPLAYMODEEX modeex = {0};
474 IDirect3D9Ex *d3d9ex =
NULL;
475 IDirect3DDevice9Ex *exdev =
NULL;
481 hr = createD3DEx(D3D_SDK_VERSION, &d3d9ex);
485 modeex.Size =
sizeof(D3DDISPLAYMODEEX);
486 hr = IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, adapter, &modeex,
NULL);
488 IDirect3D9Ex_Release(d3d9ex);
492 d3dpp.BackBufferFormat = modeex.Format;
494 hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
496 &d3dpp,
NULL, &exdev);
498 IDirect3D9Ex_Release(d3d9ex);
503 priv->
d3d9 = (IDirect3D9 *)d3d9ex;
514 unsigned resetToken = 0;
515 UINT adapter = D3DADAPTER_DEFAULT;
520 adapter = atoi(device);
526 ctx->user_opaque = priv;
531 priv->
d3dlib = dlopen(
"d3d9.dll", 0);
536 priv->
dxva2lib = dlopen(
"dxva2.dll", 0);
543 "DXVA2CreateDirect3DDeviceManager9");
544 if (!createDeviceManager) {
556 hr = createDeviceManager(&resetToken, &hwctx->
devmgr);
562 hr = IDirect3DDeviceManager9_ResetDevice(hwctx->
devmgr, priv->
d3d9device, resetToken);
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static AVBufferRef * dxva2_pool_alloc(void *opaque, size_t size)
AVFrame * source
A reference to the original source of the mapping.
static int dxva2_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
static int dxva2_device_create9ex(AVHWDeviceContext *ctx, UINT adapter)
static int dxva2_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
This struct is allocated as AVHWFramesContext.hwctx.
static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
#define FF_D3DCREATE_FLAGS
IDirect3DDeviceManager9 * devmgr
#define AV_LOG_VERBOSE
Detailed information.
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
static int dxva2_frames_init(AVHWFramesContext *ctx)
void * priv
Hardware-specific private data associated with the mapping.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static int dxva2_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
IDirect3D9 *WINAPI pDirect3DCreate9(UINT)
static int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter)
AVBufferPool * av_buffer_pool_init2(size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
static void dxva2_device_free(AVHWDeviceContext *ctx)
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.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const HWContextType ff_hwcontext_type_dxva2
#define FF_ARRAY_ELEMS(a)
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02)
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
static enum AVPixelFormat pix_fmts[]
static const D3DPRESENT_PARAMETERS dxva2_present_params
IDirect3DSurface9 ** surfaces_internal
static void dxva2_frames_uninit(AVHWFramesContext *ctx)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **)
IDirectXVideoDecoder * decoder_to_release
Certain drivers require the decoder to be destroyed before the surfaces.
uint32_t palette_dummy[256]
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
enum AVPixelFormat pix_fmt
static int dxva2_init_pool(AVHWFramesContext *ctx)
static int dxva2_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
static void dxva2_unmap_frame(AVHWFramesContext *ctx, HWMapDescriptor *hwmap)
DWORD surface_type
The surface type (e.g.
IDirectXVideoAccelerationService * service
static int dxva2_map_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
static int dxva2_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
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.
#define i(width, name, range_min, range_max)
This struct is allocated as AVHWDeviceContext.hwctx.
#define av_malloc_array(a, b)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
IDirect3DSurface9 ** surfaces
The surface pool.
void * av_calloc(size_t nmemb, size_t size)
AVHWFrameTransferDirection
This struct describes a set or pool of "hardware" frames (i.e.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
@ 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...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
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.
A reference to a data buffer.
@ AV_HWFRAME_MAP_OVERWRITE
The mapped frame will be overwritten completely in subsequent operations, so the current frame data n...
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
const VDPAUPixFmtMap * map
HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **)
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
static const struct @325 supported_formats[]
#define MKTAG(a, b, c, d)
IDirect3DDevice9 * d3d9device
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.