diff options
author | wm4 <wm4@nowhere> | 2017-12-01 08:08:46 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-12-01 08:10:31 +0100 |
commit | b89f5084cc58362f53220b8135808bf6b1048962 (patch) | |
tree | 6b542154d7c23b5dff124a646d986e58696a7a9e /video/decode | |
parent | a0d9e15342ad48f51841d4fbfe3ae47e10e45592 (diff) |
hw_dxva2: move dxva2 code to d3d.c
This source file will disappear, so just collect the leftovers in d3d.c.
Diffstat (limited to 'video/decode')
-rw-r--r-- | video/decode/d3d.c | 126 | ||||
-rw-r--r-- | video/decode/hw_dxva2.c | 117 |
2 files changed, 126 insertions, 117 deletions
diff --git a/video/decode/d3d.c b/video/decode/d3d.c index a9b67eb0a9..6cc5018333 100644 --- a/video/decode/d3d.c +++ b/video/decode/d3d.c @@ -159,3 +159,129 @@ const struct hwcontext_fns hwcontext_fns_d3d11 = { .refine_hwframes = d3d11_refine_hwframes, .create_dev = d3d11_create_standalone, }; + +#if HAVE_D3D9_HWACCEL + +#define DXVA2API_USE_BITFIELDS +#include <libavutil/common.h> + +#include <libavutil/hwcontext_dxva2.h> + +static void d3d9_free_av_device_ref(AVHWDeviceContext *ctx) +{ + AVDXVA2DeviceContext *hwctx = ctx->hwctx; + + if (hwctx->devmgr) + IDirect3DDeviceManager9_Release(hwctx->devmgr); +} + +AVBufferRef *d3d9_wrap_device_ref(IDirect3DDevice9 *device) +{ + HRESULT hr; + + d3d_load_dlls(); + if (!dxva2_dll) + return NULL; + + HRESULT (WINAPI *DXVA2CreateDirect3DDeviceManager9)(UINT *, IDirect3DDeviceManager9 **) = + (void *)GetProcAddress(dxva2_dll, "DXVA2CreateDirect3DDeviceManager9"); + if (!DXVA2CreateDirect3DDeviceManager9) + return NULL; + + AVBufferRef *device_ref = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_DXVA2); + if (!device_ref) + return NULL; + + AVHWDeviceContext *ctx = (void *)device_ref->data; + AVDXVA2DeviceContext *hwctx = ctx->hwctx; + + UINT reset_token = 0; + hr = DXVA2CreateDirect3DDeviceManager9(&reset_token, &hwctx->devmgr); + if (FAILED(hr)) + goto fail; + + IDirect3DDeviceManager9_ResetDevice(hwctx->devmgr, device, reset_token); + if (FAILED(hr)) + goto fail; + + ctx->free = d3d9_free_av_device_ref; + + if (av_hwdevice_ctx_init(device_ref) < 0) + goto fail; + + return device_ref; + +fail: + d3d9_free_av_device_ref(ctx); + av_buffer_unref(&device_ref); + return NULL; +} + +static struct AVBufferRef *d3d9_create_standalone(struct mpv_global *global, + struct mp_log *plog, struct hwcontext_create_dev_params *params) +{ + d3d_load_dlls(); + if (!d3d9_dll || !dxva2_dll) { + mp_err(plog, "Failed to load D3D9 library\n"); + return NULL; + } + + HRESULT (WINAPI *Direct3DCreate9Ex)(UINT, IDirect3D9Ex **) = + (void *)GetProcAddress(d3d9_dll, "Direct3DCreate9Ex"); + if (!Direct3DCreate9Ex) { + mp_err(plog, "Failed to locate Direct3DCreate9Ex\n"); + return NULL; + } + + IDirect3D9Ex *d3d9ex = NULL; + HRESULT hr = Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex); + if (FAILED(hr)) { + mp_err(plog, "Failed to create IDirect3D9Ex object\n"); + return NULL; + } + + UINT adapter = D3DADAPTER_DEFAULT; + D3DDISPLAYMODEEX modeex = {0}; + IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, adapter, &modeex, NULL); + + D3DPRESENT_PARAMETERS present_params = { + .Windowed = TRUE, + .BackBufferWidth = 640, + .BackBufferHeight = 480, + .BackBufferCount = 0, + .BackBufferFormat = modeex.Format, + .SwapEffect = D3DSWAPEFFECT_DISCARD, + .Flags = D3DPRESENTFLAG_VIDEO, + }; + + IDirect3DDevice9Ex *exdev = NULL; + hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, adapter, + D3DDEVTYPE_HAL, + GetShellWindow(), + D3DCREATE_SOFTWARE_VERTEXPROCESSING | + D3DCREATE_MULTITHREADED | + D3DCREATE_FPU_PRESERVE, + &present_params, + NULL, + &exdev); + IDirect3D9_Release(d3d9ex); + if (FAILED(hr)) { + mp_err(plog, "Failed to create Direct3D device: %s\n", + mp_HRESULT_to_str(hr)); + return NULL; + } + + AVBufferRef *avref = d3d9_wrap_device_ref((IDirect3DDevice9 *)exdev); + IDirect3DDevice9Ex_Release(exdev); + if (!avref) + mp_err(plog, "Failed to allocate AVHWDeviceContext.\n"); + + return avref; +} + +const struct hwcontext_fns hwcontext_fns_dxva2 = { + .av_hwdevice_type = AV_HWDEVICE_TYPE_DXVA2, + .create_dev = d3d9_create_standalone, +}; + +#endif /* HAVE_D3D9_HWACCEL */ diff --git a/video/decode/hw_dxva2.c b/video/decode/hw_dxva2.c index ede494ff4f..4d372dd2fb 100644 --- a/video/decode/hw_dxva2.c +++ b/video/decode/hw_dxva2.c @@ -38,123 +38,6 @@ #include <libavutil/hwcontext.h> #include <libavutil/hwcontext_dxva2.h> -static void d3d9_free_av_device_ref(AVHWDeviceContext *ctx) -{ - AVDXVA2DeviceContext *hwctx = ctx->hwctx; - - if (hwctx->devmgr) - IDirect3DDeviceManager9_Release(hwctx->devmgr); -} - -AVBufferRef *d3d9_wrap_device_ref(IDirect3DDevice9 *device) -{ - HRESULT hr; - - d3d_load_dlls(); - if (!dxva2_dll) - return NULL; - - HRESULT (WINAPI *DXVA2CreateDirect3DDeviceManager9)(UINT *, IDirect3DDeviceManager9 **) = - (void *)GetProcAddress(dxva2_dll, "DXVA2CreateDirect3DDeviceManager9"); - if (!DXVA2CreateDirect3DDeviceManager9) - return NULL; - - AVBufferRef *device_ref = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_DXVA2); - if (!device_ref) - return NULL; - - AVHWDeviceContext *ctx = (void *)device_ref->data; - AVDXVA2DeviceContext *hwctx = ctx->hwctx; - - UINT reset_token = 0; - hr = DXVA2CreateDirect3DDeviceManager9(&reset_token, &hwctx->devmgr); - if (FAILED(hr)) - goto fail; - - IDirect3DDeviceManager9_ResetDevice(hwctx->devmgr, device, reset_token); - if (FAILED(hr)) - goto fail; - - ctx->free = d3d9_free_av_device_ref; - - if (av_hwdevice_ctx_init(device_ref) < 0) - goto fail; - - return device_ref; - -fail: - d3d9_free_av_device_ref(ctx); - av_buffer_unref(&device_ref); - return NULL; -} - -static struct AVBufferRef *d3d9_create_standalone(struct mpv_global *global, - struct mp_log *plog, struct hwcontext_create_dev_params *params) -{ - d3d_load_dlls(); - if (!d3d9_dll || !dxva2_dll) { - mp_err(plog, "Failed to load D3D9 library\n"); - return NULL; - } - - HRESULT (WINAPI *Direct3DCreate9Ex)(UINT, IDirect3D9Ex **) = - (void *)GetProcAddress(d3d9_dll, "Direct3DCreate9Ex"); - if (!Direct3DCreate9Ex) { - mp_err(plog, "Failed to locate Direct3DCreate9Ex\n"); - return NULL; - } - - IDirect3D9Ex *d3d9ex = NULL; - HRESULT hr = Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex); - if (FAILED(hr)) { - mp_err(plog, "Failed to create IDirect3D9Ex object\n"); - return NULL; - } - - UINT adapter = D3DADAPTER_DEFAULT; - D3DDISPLAYMODEEX modeex = {0}; - IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, adapter, &modeex, NULL); - - D3DPRESENT_PARAMETERS present_params = { - .Windowed = TRUE, - .BackBufferWidth = 640, - .BackBufferHeight = 480, - .BackBufferCount = 0, - .BackBufferFormat = modeex.Format, - .SwapEffect = D3DSWAPEFFECT_DISCARD, - .Flags = D3DPRESENTFLAG_VIDEO, - }; - - IDirect3DDevice9Ex *exdev = NULL; - hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, adapter, - D3DDEVTYPE_HAL, - GetShellWindow(), - D3DCREATE_SOFTWARE_VERTEXPROCESSING | - D3DCREATE_MULTITHREADED | - D3DCREATE_FPU_PRESERVE, - &present_params, - NULL, - &exdev); - IDirect3D9_Release(d3d9ex); - if (FAILED(hr)) { - mp_err(plog, "Failed to create Direct3D device: %s\n", - mp_HRESULT_to_str(hr)); - return NULL; - } - - AVBufferRef *avref = d3d9_wrap_device_ref((IDirect3DDevice9 *)exdev); - IDirect3DDevice9Ex_Release(exdev); - if (!avref) - mp_err(plog, "Failed to allocate AVHWDeviceContext.\n"); - - return avref; -} - -const struct hwcontext_fns hwcontext_fns_dxva2 = { - .av_hwdevice_type = AV_HWDEVICE_TYPE_DXVA2, - .create_dev = d3d9_create_standalone, -}; - const struct vd_lavc_hwdec mp_vd_lavc_dxva2 = { .type = HWDEC_DXVA2, .image_format = IMGFMT_DXVA2, |