[vlc-commits] dxva: merge the device manager in the device creation callback
Steve Lhomme
git at videolan.org
Mon Sep 2 15:43:10 CEST 2019
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Sep 2 08:43:52 2019 +0200| [1d0bca7fead4c83545099ead85cfe0eaf3085829] | committer: Steve Lhomme
dxva: merge the device manager in the device creation callback
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1d0bca7fead4c83545099ead85cfe0eaf3085829
---
modules/codec/avcodec/d3d11va.c | 4 +-
modules/codec/avcodec/dxva2.c | 75 +++++++++--------------------
modules/codec/avcodec/va_surface.c | 8 ---
modules/codec/avcodec/va_surface_internal.h | 3 --
4 files changed, 25 insertions(+), 65 deletions(-)
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index a607628bba..f496b6c2eb 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -382,7 +382,6 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
static const struct va_pool_cfg pool_cfg = {
D3dCreateDevice,
D3dDestroyDevice,
- NULL, NULL,
DxCreateVideoService,
DxDestroyVideoService,
DxCreateDecoderSurfaces,
@@ -505,8 +504,7 @@ static void DxDestroyVideoService(vlc_va_t *va)
{
vlc_va_sys_t *sys = va->sys;
directx_sys_t *dx_sys = &sys->dx_sys;
- if (dx_sys->d3ddec)
- ID3D11VideoDevice_Release(dx_sys->d3ddec);
+ ID3D11VideoDevice_Release(dx_sys->d3ddec);
}
static void ReleaseInputList(input_list_t *p_list)
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index db2d0076f1..9457884507 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -137,9 +137,6 @@ struct vlc_va_sys_t
static int D3dCreateDevice(vlc_va_t *);
static void D3dDestroyDevice(vlc_va_t *);
-static int D3dCreateDeviceManager(vlc_va_t *);
-static void D3dDestroyDeviceManager(vlc_va_t *);
-
static int DxCreateVideoService(vlc_va_t *);
static void DxDestroyVideoService(vlc_va_t *);
static int DxGetInputList(vlc_va_t *, input_list_t *);
@@ -306,8 +303,6 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
static const struct va_pool_cfg pool_cfg = {
D3dCreateDevice,
D3dDestroyDevice,
- D3dCreateDeviceManager,
- D3dDestroyDeviceManager,
DxCreateVideoService,
DxDestroyVideoService,
DxCreateVideoDecoder,
@@ -355,38 +350,17 @@ static int D3dCreateDevice(vlc_va_t *va)
{
vlc_va_sys_t *sys = va->sys;
- if (sys->d3d_dev.dev) {
+ if (!sys->d3d_dev.dev) {
+ HRESULT hr = D3D9_CreateDevice(va, &sys->hd3d, -1, &sys->d3d_dev);
+ if (FAILED(hr))
+ {
+ msg_Err(va, "IDirect3D9_CreateDevice failed");
+ return VLC_EGENERIC;
+ }
+ } else {
msg_Dbg(va, "Reusing Direct3D9 device");
- return VLC_SUCCESS;
- }
-
- HRESULT hr = D3D9_CreateDevice(va, &sys->hd3d, -1, &sys->d3d_dev);
- if (FAILED(hr))
- {
- msg_Err(va, "IDirect3D9_CreateDevice failed");
- return VLC_EGENERIC;
}
- return VLC_SUCCESS;
-}
-
-/**
- * It releases a Direct3D device and its resources.
- */
-static void D3dDestroyDevice(vlc_va_t *va)
-{
- vlc_va_sys_t *sys = va->sys;
- D3D9_ReleaseDevice(&sys->d3d_dev);
- D3D9_Destroy( &sys->hd3d );
-}
-
-/**
- * It creates a Direct3D device manager
- */
-static int D3dCreateDeviceManager(vlc_va_t *va)
-{
- vlc_va_sys_t *sys = va->sys;
-
HRESULT (WINAPI *CreateDeviceManager9)(UINT *pResetToken,
IDirect3DDeviceManager9 **);
CreateDeviceManager9 =
@@ -400,28 +374,31 @@ static int D3dCreateDeviceManager(vlc_va_t *va)
msg_Dbg(va, "got CreateDeviceManager9");
UINT token;
- IDirect3DDeviceManager9 *devmng;
- if (FAILED(CreateDeviceManager9(&token, &devmng))) {
+ if (FAILED(CreateDeviceManager9(&token, &sys->devmng))) {
msg_Err(va, " OurDirect3DCreateDeviceManager9 failed");
return VLC_EGENERIC;
}
- sys->devmng = devmng;
msg_Dbg(va, "obtained IDirect3DDeviceManager9");
- HRESULT hr = IDirect3DDeviceManager9_ResetDevice(devmng, sys->d3d_dev.dev, token);
+ HRESULT hr = IDirect3DDeviceManager9_ResetDevice(sys->devmng, sys->d3d_dev.dev, token);
if (FAILED(hr)) {
- msg_Err(va, "IDirect3DDeviceManager9_ResetDevice failed: %08x", (unsigned)hr);
+ msg_Err(va, "IDirect3DDeviceManager9_ResetDevice failed: 0x%lX)", hr);
+ IDirect3DDeviceManager9_Release(sys->devmng);
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
+
/**
- * It destroys a Direct3D device manager
+ * It releases a Direct3D device and its resources.
*/
-static void D3dDestroyDeviceManager(vlc_va_t *va)
+static void D3dDestroyDevice(vlc_va_t *va)
{
- if (va->sys->devmng)
- IDirect3DDeviceManager9_Release(va->sys->devmng);
+ vlc_va_sys_t *sys = va->sys;
+ if (sys->devmng)
+ IDirect3DDeviceManager9_Release(sys->devmng);
+ D3D9_ReleaseDevice(&sys->d3d_dev);
+ D3D9_Destroy( &sys->hd3d );
}
/**
@@ -460,14 +437,10 @@ static void DxDestroyVideoService(vlc_va_t *va)
{
vlc_va_sys_t *sys = va->sys;
directx_sys_t *dx_sys = &sys->dx_sys;
- if (sys->device)
- {
- HRESULT hr = IDirect3DDeviceManager9_CloseDeviceHandle(sys->devmng, sys->device);
- if (FAILED(hr))
- msg_Warn(va, "Failed to release device handle 0x%p. (hr=0x%lX)", sys->device, hr);
- }
- if (dx_sys->d3ddec)
- IDirectXVideoDecoderService_Release(dx_sys->d3ddec);
+ HRESULT hr = IDirect3DDeviceManager9_CloseDeviceHandle(sys->devmng, sys->device);
+ if (FAILED(hr))
+ msg_Warn(va, "Failed to release device handle 0x%p. (hr=0x%lX)", sys->device, hr);
+ IDirectXVideoDecoderService_Release(dx_sys->d3ddec);
}
static void ReleaseInputList(input_list_t *p_list)
diff --git a/modules/codec/avcodec/va_surface.c b/modules/codec/avcodec/va_surface.c
index 27684e9db3..4b0cd13f9e 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -192,8 +192,6 @@ void va_pool_Close(vlc_va_t *va, va_pool_t *va_pool)
{
DestroyVideoDecoder(va->sys, va_pool);
va_pool->callbacks->pf_destroy_video_service(va);
- if (va_pool->callbacks->pf_destroy_device_manager)
- va_pool->callbacks->pf_destroy_device_manager(va);
va_pool->callbacks->pf_destroy_device(va);
}
@@ -206,12 +204,6 @@ int va_pool_Open(vlc_va_t *va, const struct va_pool_cfg *cbs, va_pool_t *va_pool
}
msg_Dbg(va, "CreateDevice succeed");
- if (cbs->pf_create_device_manager &&
- cbs->pf_create_device_manager(va) != VLC_SUCCESS) {
- msg_Err(va, "CreateDeviceManager failed");
- goto error;
- }
-
if (cbs->pf_create_video_service(va)) {
msg_Err(va, "CreateVideoService failed");
goto error;
diff --git a/modules/codec/avcodec/va_surface_internal.h b/modules/codec/avcodec/va_surface_internal.h
index 5e19e765a9..b7810fb5a8 100644
--- a/modules/codec/avcodec/va_surface_internal.h
+++ b/modules/codec/avcodec/va_surface_internal.h
@@ -51,9 +51,6 @@ struct va_pool_cfg {
int (*pf_create_device)(vlc_va_t *);
void (*pf_destroy_device)(vlc_va_t *);
- int (*pf_create_device_manager)(vlc_va_t *);
- void (*pf_destroy_device_manager)(vlc_va_t *);
-
int (*pf_create_video_service)(vlc_va_t *);
void (*pf_destroy_video_service)(vlc_va_t *);
More information about the vlc-commits
mailing list