27 #if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600
29 #define _WIN32_WINNT 0x0600
38 #include <dxgidebug.h>
65 d3dlib = LoadLibrary(
"d3d11.dll");
66 dxgilib = LoadLibrary(
"dxgi.dll");
67 if (!d3dlib || !dxgilib)
70 mD3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE) GetProcAddress(d3dlib,
"D3D11CreateDevice");
101 WaitForSingleObjectEx(ctx, INFINITE,
FALSE);
115 ID3D11Texture2D_Release(frames_hwctx->
texture);
125 ID3D11Texture2D_Release((ID3D11Texture2D *)opaque);
133 ID3D11Texture2D_Release(tex);
142 ID3D11Texture2D_Release(tex);
156 ID3D11Texture2D *tex;
157 D3D11_TEXTURE2D_DESC texDesc = {
162 .SampleDesc = { .Count = 1 },
164 .Usage = D3D11_USAGE_DEFAULT,
169 hr = ID3D11Device_CreateTexture2D(device_hwctx->
device, &texDesc,
NULL, &tex);
183 D3D11_TEXTURE2D_DESC texDesc;
188 ID3D11Texture2D_GetDesc(hwctx->
texture, &texDesc);
195 ID3D11Texture2D_AddRef(hwctx->
texture);
207 D3D11_TEXTURE2D_DESC texDesc;
221 texDesc = (D3D11_TEXTURE2D_DESC){
226 .SampleDesc = { .Count = 1 },
228 .Usage = D3D11_USAGE_DEFAULT,
234 D3D11_TEXTURE2D_DESC texDesc2;
235 ID3D11Texture2D_GetDesc(hwctx->
texture, &texDesc2);
237 if (texDesc.Width != texDesc2.Width ||
238 texDesc.Height != texDesc2.Height ||
239 texDesc.Format != texDesc2.Format) {
243 }
else if (texDesc.ArraySize > 0) {
244 hr = ID3D11Device_CreateTexture2D(device_hwctx->
device, &texDesc,
NULL, &hwctx->
texture);
293 if (s->
format == DXGI_FORMAT_420_OPAQUE)
306 D3D11_TEXTURE2D_DESC texDesc = {
311 .SampleDesc = { .Count = 1 },
313 .Usage = D3D11_USAGE_STAGING,
314 .CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE,
328 D3D11_TEXTURE2D_DESC *
desc,
329 D3D11_MAPPED_SUBRESOURCE *
map)
333 for (i = 0; i < 4; i++)
334 linesize[i] = map->RowPitch;
337 (
uint8_t*)map->pData, linesize);
349 ID3D11Resource *texture = (ID3D11Resource *)(ID3D11Texture2D *)frame->
data[0];
351 ID3D11Resource *staging;
356 D3D11_TEXTURE2D_DESC
desc;
357 D3D11_MAPPED_SUBRESOURCE
map;
376 ID3D11DeviceContext_CopySubresourceRegion(device_hwctx->
device_context,
378 texture, index,
NULL);
381 staging, 0, D3D11_MAP_READ, 0, &map);
390 ID3D11DeviceContext_Unmap(device_hwctx->
device_context, staging, 0);
393 staging, 0, D3D11_MAP_WRITE, 0, &map);
402 ID3D11DeviceContext_Unmap(device_hwctx->
device_context, staging, 0);
404 ID3D11DeviceContext_CopySubresourceRegion(device_hwctx->
device_context,
405 texture, index, 0, 0, 0,
423 if (!device_hwctx->
lock) {
440 hr = ID3D11DeviceContext_QueryInterface(device_hwctx->
device, &IID_ID3D11VideoDevice,
447 hr = ID3D11DeviceContext_QueryInterface(device_hwctx->
device_context, &IID_ID3D11VideoContext,
461 ID3D11Device_Release(device_hwctx->
device);
473 CloseHandle(device_hwctx->
lock_ctx);
482 IDXGIAdapter *pAdapter =
NULL;
483 ID3D10Multithread *pMultithread;
484 UINT creationFlags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
490 if (!LoadLibrary(
"d3d11_1sdklayers.dll"))
495 creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
505 IDXGIFactory2 *pDXGIFactory;
508 int adapter = atoi(device);
509 if (
FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter, &pAdapter)))
511 IDXGIFactory2_Release(pDXGIFactory);
515 hr =
mD3D11CreateDevice(pAdapter, pAdapter ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE,
NULL, creationFlags,
NULL, 0,
518 IDXGIAdapter_Release(pAdapter);
524 hr = ID3D11Device_QueryInterface(device_hwctx->
device, &IID_ID3D10Multithread, (
void **)&pMultithread);
526 ID3D10Multithread_SetMultithreadProtected(pMultithread,
TRUE);
527 ID3D10Multithread_Release(pMultithread);
530 #if !HAVE_UWP && HAVE_DXGIDEBUG_H
532 HANDLE dxgidebug_dll = LoadLibrary(
"dxgidebug.dll");
534 HRESULT (WINAPI * pf_DXGIGetDebugInterface)(
const GUID *riid,
void **ppDebug)
535 = (
void *)GetProcAddress(dxgidebug_dll,
"DXGIGetDebugInterface");
536 if (pf_DXGIGetDebugInterface) {
537 IDXGIDebug *dxgi_debug =
NULL;
538 hr = pf_DXGIGetDebugInterface(&IID_IDXGIDebug, (
void**)&dxgi_debug);
540 IDXGIDebug_ReportLiveObjects(dxgi_debug, DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL);
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
static AVOnce functions_loaded
static int d3d11va_create_staging_texture(AVHWFramesContext *ctx)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
static int device_init(AVFormatContext *ctx, int *width, int *height, uint32_t pixelformat)
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
static void d3d11va_device_uninit(AVHWDeviceContext *hwdev)
static int d3d11va_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
static AVBufferRef * d3d11va_alloc_single(AVHWFramesContext *ctx)
int width
The allocated dimensions of the frames in this pool.
static void d3d11va_frames_uninit(AVHWFramesContext *ctx)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
enum AVPixelFormat pix_fmt
ID3D11Texture2D * texture
The texture in which the frame is located.
UINT MiscFlags
D3D11_TEXTURE2D_DESC.MiscFlags used for texture creation.
UINT BindFlags
D3D11_TEXTURE2D_DESC.BindFlags used for texture creation.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
AVBufferPool * pool_internal
static int d3d11va_device_init(AVHWDeviceContext *hwdev)
static int d3d11va_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
ID3D11Device * device
Device used for texture creation and access.
D3D11 frame descriptor for pool allocation.
HRESULT(WINAPI * PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void d3d11va_default_unlock(void *ctx)
static PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice
static int d3d11va_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
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().
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 av_cold void load_functions(void)
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 d3d11va_frames_init(AVHWFramesContext *ctx)
ID3D11VideoContext * video_context
If unset, this will be set from the device_context field on init.
static void d3d11va_default_lock(void *ctx)
int initial_pool_size
Initial size of the frame pool.
static void free_texture(void *opaque, uint8_t *data)
ID3D11VideoDevice * video_device
If unset, this will be set from the device field on init.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
intptr_t index
The index into the array texture element representing the frame, or 0 if the texture is not an array ...
static AVBufferRef * d3d11va_pool_alloc(void *opaque, int size)
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)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
void(* unlock)(void *lock_ctx)
static const struct @242 supported_formats[]
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.
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.
ID3D11Texture2D * texture
The canonical texture used for pool allocation.
static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
This struct describes a set or pool of "hardware" frames (i.e.
const VDPAUPixFmtMap * map
AVHWFramesInternal * internal
Private data used internally by libavutil.
static enum AVPixelFormat pix_fmts[]
This struct is allocated as AVHWFramesContext.hwctx.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Hardware surfaces for Direct3D11.
ID3D11Texture2D * staging_texture
A reference to a data buffer.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
static AVBufferRef * wrap_texture_buf(ID3D11Texture2D *tex, int index)
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
AVHWFrameTransferDirection
AVBufferPool * pool
A pool from which the frames are allocated by av_hwframe_get_buffer().
static int ff_thread_once(char *control, void(*routine)(void))
This struct is allocated as AVHWDeviceContext.hwctx.
void(* lock)(void *lock_ctx)
Callbacks for locking.
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
static void fill_texture_ptrs(uint8_t *data[4], int linesize[4], AVHWFramesContext *ctx, D3D11_TEXTURE2D_DESC *desc, D3D11_MAPPED_SUBRESOURCE *map)
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.
const HWContextType ff_hwcontext_type_d3d11va
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
static PFN_CREATE_DXGI_FACTORY mCreateDXGIFactory
ID3D11DeviceContext * device_context
If unset, this will be set from the device field on init.