mirror of https://github.com/mpv-player/mpv
dxva2: move device creation code
Preparation for the following commit.
This commit is contained in:
parent
cc51dafa96
commit
b6dc11810b
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue