[vlc-commits] dxva: merge the video service handling in the device creation callbacks
Steve Lhomme
git at videolan.org
Mon Sep 2 15:43:11 CEST 2019
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Sep 2 08:54:55 2019 +0200| [ec672df04107614ec29fe6d2814170f05896c1d7] | committer: Steve Lhomme
dxva: merge the video service handling in the device creation callbacks
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ec672df04107614ec29fe6d2814170f05896c1d7
---
modules/codec/avcodec/d3d11va.c | 73 ++++++++++-------------------
modules/codec/avcodec/dxva2.c | 44 +++++------------
modules/codec/avcodec/va_surface.c | 11 +----
modules/codec/avcodec/va_surface_internal.h | 3 --
4 files changed, 38 insertions(+), 93 deletions(-)
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index f496b6c2eb..d9a56aae25 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -128,8 +128,6 @@ struct vlc_va_sys_t
static int D3dCreateDevice(vlc_va_t *);
static void D3dDestroyDevice(vlc_va_t *);
-static int DxCreateVideoService(vlc_va_t *);
-static void DxDestroyVideoService(vlc_va_t *);
static int DxGetInputList(vlc_va_t *, input_list_t *);
static int DxSetupOutput(vlc_va_t *, const GUID *, const video_format_t *);
@@ -382,8 +380,6 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
static const struct va_pool_cfg pool_cfg = {
D3dCreateDevice,
D3dDestroyDevice,
- DxCreateVideoService,
- DxDestroyVideoService,
DxCreateDecoderSurfaces,
DxDestroySurfaces,
SetupAVCodecContext,
@@ -430,27 +426,26 @@ static int D3dCreateDevice(vlc_va_t *va)
if (sys->d3d_dev.d3ddevice && sys->d3d_dev.d3dcontext) {
msg_Dbg(va, "Reusing Direct3D11 device");
ID3D11DeviceContext_AddRef(sys->d3d_dev.d3dcontext);
- return VLC_SUCCESS;
}
-
-#if VLC_WINSTORE_APP
- if (sys->d3d_dev.d3dcontext == NULL)
- sys->d3d_dev.d3dcontext = var_InheritInteger(va, "winrt-d3dcontext"); /* LEGACY */
-#endif
- if (sys->d3d_dev.d3dcontext != NULL)
- {
- ID3D11DeviceContext_GetDevice(sys->d3d_dev.d3dcontext, &sys->d3d_dev.d3ddevice);
- ID3D11DeviceContext_AddRef(sys->d3d_dev.d3dcontext);
- ID3D11Device_Release(sys->d3d_dev.d3ddevice);
- }
-
- /* */
else
{
- hr = D3D11_CreateDevice(va, &sys->hd3d, NULL, true, &sys->d3d_dev);
- if (FAILED(hr)) {
- msg_Err(va, "D3D11CreateDevice failed. (hr=0x%lX)", hr);
- return VLC_EGENERIC;
+#if VLC_WINSTORE_APP
+ if (sys->d3d_dev.d3dcontext == NULL)
+ sys->d3d_dev.d3dcontext = var_InheritInteger(va, "winrt-d3dcontext"); /* LEGACY */
+#endif
+ if (sys->d3d_dev.d3dcontext != NULL)
+ {
+ ID3D11DeviceContext_GetDevice(sys->d3d_dev.d3dcontext, &sys->d3d_dev.d3ddevice);
+ ID3D11DeviceContext_AddRef(sys->d3d_dev.d3dcontext);
+ ID3D11Device_Release(sys->d3d_dev.d3ddevice);
+ }
+ else
+ {
+ hr = D3D11_CreateDevice(va, &sys->hd3d, NULL, true, &sys->d3d_dev);
+ if (FAILED(hr)) {
+ msg_Err(va, "D3D11CreateDevice failed. (hr=0x%lX)", hr);
+ return VLC_EGENERIC;
+ }
}
}
@@ -464,47 +459,31 @@ static int D3dCreateDevice(vlc_va_t *va)
}
sys->d3dvidctx = d3dvidctx;
- 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;
- if (sys->d3dvidctx)
- ID3D11VideoContext_Release(sys->d3dvidctx);
- D3D11_ReleaseDevice( &sys->d3d_dev );
-}
-
-/**
- * It creates a DirectX video service
- */
-static int DxCreateVideoService(vlc_va_t *va)
-{
- vlc_va_sys_t *sys = va->sys;
- directx_sys_t *dx_sys = &sys->dx_sys;
-
void *d3dviddev = NULL;
- HRESULT hr = ID3D11Device_QueryInterface(sys->d3d_dev.d3ddevice, &IID_ID3D11VideoDevice, &d3dviddev);
+ hr = ID3D11Device_QueryInterface(sys->d3d_dev.d3ddevice, &IID_ID3D11VideoDevice, &d3dviddev);
if (FAILED(hr)) {
msg_Err(va, "Could not Query ID3D11VideoDevice Interface. (hr=0x%lX)", hr);
+ ID3D11DeviceContext_Release(sys->d3d_dev.d3dcontext);
+ ID3D11Device_Release(sys->d3d_dev.d3ddevice);
+ ID3D11VideoContext_Release(sys->d3dvidctx);
return VLC_EGENERIC;
}
+ directx_sys_t *dx_sys = &sys->dx_sys;
dx_sys->d3ddec = d3dviddev;
return VLC_SUCCESS;
}
/**
- * It destroys a DirectX video service
+ * It releases a Direct3D device and its resources.
*/
-static void DxDestroyVideoService(vlc_va_t *va)
+static void D3dDestroyDevice(vlc_va_t *va)
{
vlc_va_sys_t *sys = va->sys;
directx_sys_t *dx_sys = &sys->dx_sys;
ID3D11VideoDevice_Release(dx_sys->d3ddec);
+ ID3D11VideoContext_Release(sys->d3dvidctx);
+ D3D11_ReleaseDevice( &sys->d3d_dev );
}
static void ReleaseInputList(input_list_t *p_list)
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 9457884507..e09fe7d37e 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -137,8 +137,6 @@ struct vlc_va_sys_t
static int D3dCreateDevice(vlc_va_t *);
static void D3dDestroyDevice(vlc_va_t *);
-static int DxCreateVideoService(vlc_va_t *);
-static void DxDestroyVideoService(vlc_va_t *);
static int DxGetInputList(vlc_va_t *, input_list_t *);
static int DxSetupOutput(vlc_va_t *, const GUID *, const video_format_t *);
@@ -303,8 +301,6 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
static const struct va_pool_cfg pool_cfg = {
D3dCreateDevice,
D3dDestroyDevice,
- DxCreateVideoService,
- DxDestroyVideoService,
DxCreateVideoDecoder,
DxDestroyVideoDecoder,
SetupAVCodecContext,
@@ -386,54 +382,33 @@ static int D3dCreateDevice(vlc_va_t *va)
IDirect3DDeviceManager9_Release(sys->devmng);
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;
- if (sys->devmng)
- IDirect3DDeviceManager9_Release(sys->devmng);
- D3D9_ReleaseDevice(&sys->d3d_dev);
- D3D9_Destroy( &sys->hd3d );
-}
-/**
- * It creates a DirectX video service
- */
-static int DxCreateVideoService(vlc_va_t *va)
-{
- vlc_va_sys_t *sys = va->sys;
- directx_sys_t *dx_sys = &sys->dx_sys;
- HRESULT hr;
-
- HANDLE device;
- hr = IDirect3DDeviceManager9_OpenDeviceHandle(sys->devmng, &device);
+ hr = IDirect3DDeviceManager9_OpenDeviceHandle(sys->devmng, &sys->device);
if (FAILED(hr)) {
msg_Err(va, "OpenDeviceHandle failed");
+ IDirect3DDeviceManager9_Release(sys->devmng);
return VLC_EGENERIC;
}
- sys->device = device;
void *pv;
- hr = IDirect3DDeviceManager9_GetVideoService(sys->devmng, device,
+ hr = IDirect3DDeviceManager9_GetVideoService(sys->devmng, sys->device,
&IID_IDirectXVideoDecoderService, &pv);
if (FAILED(hr)) {
msg_Err(va, "GetVideoService failed");
+ IDirect3DDeviceManager9_CloseDeviceHandle(sys->devmng, sys->device);
+ IDirect3DDeviceManager9_Release(sys->devmng);
return VLC_EGENERIC;
}
+ directx_sys_t *dx_sys = &sys->dx_sys;
dx_sys->d3ddec = pv;
return VLC_SUCCESS;
}
/**
- * It destroys a DirectX video service
+ * It releases a Direct3D device and its resources.
*/
-static void DxDestroyVideoService(vlc_va_t *va)
+static void D3dDestroyDevice(vlc_va_t *va)
{
vlc_va_sys_t *sys = va->sys;
directx_sys_t *dx_sys = &sys->dx_sys;
@@ -441,6 +416,9 @@ static void DxDestroyVideoService(vlc_va_t *va)
if (FAILED(hr))
msg_Warn(va, "Failed to release device handle 0x%p. (hr=0x%lX)", sys->device, hr);
IDirectXVideoDecoderService_Release(dx_sys->d3ddec);
+ IDirect3DDeviceManager9_Release(sys->devmng);
+ D3D9_ReleaseDevice(&sys->d3d_dev);
+ D3D9_Destroy( &sys->hd3d );
}
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 4b0cd13f9e..88fe55ba90 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -191,7 +191,6 @@ void va_surface_Release(vlc_va_surface_t *surface)
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);
va_pool->callbacks->pf_destroy_device(va);
}
@@ -200,20 +199,12 @@ int va_pool_Open(vlc_va_t *va, const struct va_pool_cfg *cbs, va_pool_t *va_pool
/* */
if (cbs->pf_create_device(va)) {
msg_Err(va, "Failed to create device");
- goto error;
+ return VLC_EGENERIC;
}
msg_Dbg(va, "CreateDevice succeed");
- if (cbs->pf_create_video_service(va)) {
- msg_Err(va, "CreateVideoService failed");
- goto error;
- }
-
va_pool->callbacks = cbs;
return VLC_SUCCESS;
-
-error:
- return VLC_EGENERIC;
}
diff --git a/modules/codec/avcodec/va_surface_internal.h b/modules/codec/avcodec/va_surface_internal.h
index b7810fb5a8..ed379901cf 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_video_service)(vlc_va_t *);
- void (*pf_destroy_video_service)(vlc_va_t *);
-
/**
* Create the DirectX surfaces in hw_surface and the decoder in decoder
*/
More information about the vlc-commits
mailing list