Commit ec672df0 authored by Steve Lhomme's avatar Steve Lhomme

dxva: merge the video service handling in the device creation callbacks

parent 1d0bca7f
......@@ -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)
......
......@@ -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)
......
......@@ -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;
}
......@@ -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
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment