diff options
author | wm4 <wm4@nowhere> | 2015-07-03 15:42:52 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-07-03 15:42:52 +0200 |
commit | b6dc11810b78953d95a75d745d7327a796f0b462 (patch) | |
tree | e4b8d72dbd31cfd8400d57f6323e0ce3433ad61d /video/decode | |
parent | cc51dafa9632fa9f4f8dd6902f3cfd5a5d628ac7 (diff) | |
download | mpv-b6dc11810b78953d95a75d745d7327a796f0b462.tar.bz2 mpv-b6dc11810b78953d95a75d745d7327a796f0b462.tar.xz |
dxva2: move device creation code
Preparation for the following commit.
Diffstat (limited to 'video/decode')
-rw-r--r-- | video/decode/dxva2.c | 84 |
1 files changed, 50 insertions, 34 deletions
diff --git a/video/decode/dxva2.c b/video/decode/dxva2.c index 97612a4c82..852319611d 100644 --- a/video/decode/dxva2.c +++ b/video/decode/dxva2.c @@ -332,58 +332,26 @@ static struct mp_image *dxva2_retrieve_image(struct lavc_ctx *s, return sw_img; } -static int dxva2_init(struct lavc_ctx *s) +static int create_device(struct lavc_ctx *s) { - DXVA2Context *ctx; + DXVA2Context *ctx = s->hwdec_priv; pDirect3DCreate9 *createD3D = NULL; - pCreateDeviceManager9 *createDeviceManager = NULL; HRESULT hr; D3DPRESENT_PARAMETERS d3dpp = {0}; D3DDISPLAYMODE d3ddm; - unsigned resetToken = 0; UINT adapter = D3DADAPTER_DEFAULT; - ctx = talloc_zero(NULL, DXVA2Context); - if (!ctx) - return -1; - s->hwdec_priv = ctx; - - ctx->log = mp_log_new(s, s->log, "dxva2"); - ctx->sw_pool = talloc_steal(ctx, mp_image_pool_new(17)); - - if (av_get_cpu_flags() & AV_CPU_FLAG_SSE4) { - // Use a memcpy implementation optimised for copying from GPU memory - MP_DBG(ctx, "Using SSE4 memcpy\n"); - ctx->copy_nv12 = copy_nv12_gpu_sse4; - } else { - // Use the CRT memcpy. This can be slower than software decoding. - MP_WARN(ctx, "Using fallback memcpy (slow)\n"); - ctx->copy_nv12 = copy_nv12_fallback; - } - - ctx->deviceHandle = INVALID_HANDLE_VALUE; - ctx->d3dlib = LoadLibrary(L"d3d9.dll"); if (!ctx->d3dlib) { MP_ERR(ctx, "Failed to load D3D9 library\n"); goto fail; } - ctx->dxva2lib = LoadLibrary(L"dxva2.dll"); - if (!ctx->dxva2lib) { - MP_ERR(ctx, "Failed to load DXVA2 library\n"); - goto fail; - } createD3D = (pDirect3DCreate9 *)GetProcAddress(ctx->d3dlib, "Direct3DCreate9"); if (!createD3D) { MP_ERR(ctx, "Failed to locate Direct3DCreate9\n"); goto fail; } - createDeviceManager = (pCreateDeviceManager9 *)GetProcAddress(ctx->dxva2lib, "DXVA2CreateDirect3DDeviceManager9"); - if (!createDeviceManager) { - MP_ERR(ctx, "Failed to locate DXVA2CreateDirect3DDeviceManager9\n"); - goto fail; - } ctx->d3d9 = createD3D(D3D_SDK_VERSION); if (!ctx->d3d9) { @@ -408,6 +376,54 @@ static int dxva2_init(struct lavc_ctx *s) goto fail; } + return 0; + +fail: + return -1; +} + +static int dxva2_init(struct lavc_ctx *s) +{ + DXVA2Context *ctx; + pCreateDeviceManager9 *createDeviceManager = NULL; + HRESULT hr; + unsigned resetToken = 0; + + ctx = talloc_zero(NULL, DXVA2Context); + if (!ctx) + return -1; + s->hwdec_priv = ctx; + + ctx->log = mp_log_new(s, s->log, "dxva2"); + ctx->sw_pool = talloc_steal(ctx, mp_image_pool_new(17)); + + if (av_get_cpu_flags() & AV_CPU_FLAG_SSE4) { + // Use a memcpy implementation optimised for copying from GPU memory + MP_DBG(ctx, "Using SSE4 memcpy\n"); + ctx->copy_nv12 = copy_nv12_gpu_sse4; + } else { + // Use the CRT memcpy. This can be slower than software decoding. + MP_WARN(ctx, "Using fallback memcpy (slow)\n"); + ctx->copy_nv12 = copy_nv12_fallback; + } + + ctx->deviceHandle = INVALID_HANDLE_VALUE; + + ctx->dxva2lib = LoadLibrary(L"dxva2.dll"); + if (!ctx->dxva2lib) { + MP_ERR(ctx, "Failed to load DXVA2 library\n"); + goto fail; + } + + if (create_device(s) < 0) + goto fail; + + createDeviceManager = (pCreateDeviceManager9 *)GetProcAddress(ctx->dxva2lib, "DXVA2CreateDirect3DDeviceManager9"); + if (!createDeviceManager) { + MP_ERR(ctx, "Failed to locate DXVA2CreateDirect3DDeviceManager9\n"); + goto fail; + } + hr = createDeviceManager(&resetToken, &ctx->d3d9devmgr); if (FAILED(hr)) { MP_ERR(ctx, "Failed to create Direct3D device manager\n"); |