diff options
author | wm4 <wm4@nowhere> | 2016-05-17 11:57:28 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-05-17 11:59:54 +0200 |
commit | a02d77ba0df747b60ffad7d2a5eacfc6528aabef (patch) | |
tree | 6e2187738fba74cb68c082cfe23663ac8d120c96 /video/decode/dxva2.c | |
parent | 39b64fb176bf90d7146cf7f20c61ab3e7def4191 (diff) | |
download | mpv-a02d77ba0df747b60ffad7d2a5eacfc6528aabef.tar.bz2 mpv-a02d77ba0df747b60ffad7d2a5eacfc6528aabef.tar.xz |
d3d: simplify DLL loading
For some reason, the d3d9/dxva2/d3d11 DLLs are still optional. But we
don't need to try so hard to keep exact references. In fact, there's no
reason to unload them at all.
So load them once in a central place. For simplicity, the d3d9/d3d11
backends both load all DLLs. (They will error out only if the required
DLLs could not be loaded.)
In theory, we could just call LoadLibrary multiple times (without
calling FreeLibrary), but I'm slightly worried that this could be
detected as a "bug", or that the reference count could even have a low
static limit that could be hit soon.
Diffstat (limited to 'video/decode/dxva2.c')
-rw-r--r-- | video/decode/dxva2.c | 38 |
1 files changed, 7 insertions, 31 deletions
diff --git a/video/decode/dxva2.c b/video/decode/dxva2.c index 829d77ccbf..489f580fc0 100644 --- a/video/decode/dxva2.c +++ b/video/decode/dxva2.c @@ -39,8 +39,6 @@ struct priv { struct mp_log *log; - HMODULE d3d9_dll; - HMODULE dxva2_dll; IDirect3D9 *d3d9; IDirect3DDevice9 *device; HANDLE device_handle; @@ -53,9 +51,6 @@ struct priv { }; struct dxva2_surface { - HMODULE d3dlib; - HMODULE dxva2lib; - IDirectXVideoDecoder *decoder; IDirect3DSurface9 *surface; }; @@ -69,12 +64,6 @@ static void dxva2_release_img(void *arg) if (surface->decoder) IDirectXVideoDecoder_Release(surface->decoder); - if (surface->dxva2lib) - FreeLibrary(surface->dxva2lib); - - if (surface->d3dlib) - FreeLibrary(surface->d3dlib); - talloc_free(surface); } @@ -86,13 +75,6 @@ static struct mp_image *dxva2_new_ref(IDirectXVideoDecoder *decoder, return NULL; struct dxva2_surface *surface = talloc_zero(NULL, struct dxva2_surface); - // Add additional references to the libraries which might otherwise be freed - // before the surface, which is observed to lead to bad behaviour - surface->d3dlib = LoadLibrary(L"d3d9.dll"); - surface->dxva2lib = LoadLibrary(L"dxva2.dll"); - if (!surface->d3dlib || !surface->dxva2lib) - goto fail; - surface->surface = d3d9_surface; IDirect3DSurface9_AddRef(surface->surface); surface->decoder = decoder; @@ -368,25 +350,20 @@ static void destroy_device(struct lavc_ctx *s) if (p->d3d9) IDirect3D9_Release(p->d3d9); - - if (p->d3d9_dll) - FreeLibrary(p->d3d9_dll); - - if (p->dxva2_dll) - FreeLibrary(p->dxva2_dll); } static bool create_device(struct lavc_ctx *s) { struct priv *p = s->hwdec_priv; - p->d3d9_dll = LoadLibrary(L"d3d9.dll"); - if (!p->d3d9_dll) { + + d3d_load_dlls(); + if (!d3d9_dll) { MP_ERR(p, "Failed to load D3D9 library\n"); return false; } IDirect3D9* (WINAPI *Direct3DCreate9)(UINT) = - (void *)GetProcAddress(p->d3d9_dll, "Direct3DCreate9"); + (void *)GetProcAddress(d3d9_dll, "Direct3DCreate9"); if (!Direct3DCreate9) { MP_ERR(p, "Failed to locate Direct3DCreate9\n"); return false; @@ -477,15 +454,14 @@ static int dxva2_init(struct lavc_ctx *s) goto fail; } - p->dxva2_dll = LoadLibrary(L"dxva2.dll"); - if (!p->dxva2_dll) { + d3d_load_dlls(); + if (!dxva2_dll) { MP_ERR(p, "Failed to load DXVA2 library\n"); goto fail; } HRESULT (WINAPI *CreateDeviceManager9)(UINT *, IDirect3DDeviceManager9 **) = - (void *)GetProcAddress(p->dxva2_dll, - "DXVA2CreateDirect3DDeviceManager9"); + (void *)GetProcAddress(dxva2_dll, "DXVA2CreateDirect3DDeviceManager9"); if (!CreateDeviceManager9) { MP_ERR(p, "Failed to locate DXVA2CreateDirect3DDeviceManager9\n"); goto fail; |