[vlc-devel] [PATCH 17/20] hw:d3d11: make use of D3D11_FilterHoldInstance()
Steve Lhomme
robux4 at videolabs.io
Wed Nov 22 18:18:36 CET 2017
---
modules/hw/d3d11/d3d11_deinterlace.c | 25 ++++++++-----------------
modules/hw/d3d11/d3d11_filters.c | 25 ++++++++-----------------
modules/hw/d3d11/d3d11_surface.c | 16 +++++-----------
3 files changed, 21 insertions(+), 45 deletions(-)
diff --git a/modules/hw/d3d11/d3d11_deinterlace.c b/modules/hw/d3d11/d3d11_deinterlace.c
index 9d466ef78e..f0b087af40 100644
--- a/modules/hw/d3d11/d3d11_deinterlace.c
+++ b/modules/hw/d3d11/d3d11_deinterlace.c
@@ -298,21 +298,15 @@ int D3D11OpenDeinterlace(vlc_object_t *obj)
return VLC_ENOMEM;
memset(sys, 0, sizeof (*sys));
- picture_t *dst = filter_NewPicture(filter);
- if (dst == NULL)
- return VLC_EGENERIC;
- if (!dst->p_sys)
+ D3D11_TEXTURE2D_DESC dstDesc;
+ D3D11_FilterHoldInstance(filter, &sys->d3d_dev, &dstDesc);
+ if (unlikely(sys->d3d_dev.d3dcontext==NULL))
{
- msg_Dbg(filter, "D3D11 opaque without a texture");
- picture_Release(dst);
- return VLC_EGENERIC;
+ msg_Dbg(filter, "Filter without a context");
+ free(sys);
+ return VLC_ENOOBJ;
}
- D3D11_TEXTURE2D_DESC dstDesc;
- ID3D11Texture2D_GetDesc(dst->p_sys->texture[KNOWN_DXGI_INDEX], &dstDesc);
- sys->d3d_dev.d3dcontext = dst->p_sys->context;
- ID3D11DeviceContext_GetDevice(sys->d3d_dev.d3dcontext, &sys->d3d_dev.d3ddevice);
-
hr = ID3D11Device_QueryInterface(sys->d3d_dev.d3ddevice, &IID_ID3D11VideoDevice, (void **)&sys->d3dviddev);
if (FAILED(hr)) {
msg_Err(filter, "Could not Query ID3D11VideoDevice Interface. (hr=0x%lX)", hr);
@@ -493,11 +487,8 @@ int D3D11OpenDeinterlace(vlc_object_t *obj)
filter->pf_flush = Flush;
filter->p_sys = sys;
- picture_Release(dst);
return VLC_SUCCESS;
error:
- picture_Release(dst);
-
if (sys->outTexture)
ID3D11Texture2D_Release(sys->outTexture);
if (sys->videoProcessor)
@@ -509,7 +500,7 @@ error:
if (sys->d3dviddev)
ID3D11VideoDevice_Release(sys->d3dviddev);
if (sys->d3d_dev.d3dcontext)
- D3D11_ReleaseDevice(&sys->d3d_dev);
+ D3D11_FilterReleaseInstance(&sys->d3d_dev);
return VLC_EGENERIC;
}
@@ -525,7 +516,7 @@ void D3D11CloseDeinterlace(vlc_object_t *obj)
ID3D11VideoProcessorEnumerator_Release(sys->procEnumerator);
ID3D11VideoContext_Release(sys->d3dvidctx);
ID3D11VideoDevice_Release(sys->d3dviddev);
- D3D11_ReleaseDevice(&sys->d3d_dev);
+ D3D11_FilterReleaseInstance(&sys->d3d_dev);
free(sys);
}
diff --git a/modules/hw/d3d11/d3d11_filters.c b/modules/hw/d3d11/d3d11_filters.c
index de97ee2582..8b5a448ce0 100644
--- a/modules/hw/d3d11/d3d11_filters.c
+++ b/modules/hw/d3d11/d3d11_filters.c
@@ -342,21 +342,15 @@ static int D3D11OpenAdjust(vlc_object_t *obj)
return VLC_ENOMEM;
memset(sys, 0, sizeof (*sys));
- picture_t *dst = filter_NewPicture(filter);
- if (dst == NULL)
- return VLC_EGENERIC;
- if (!dst->p_sys)
+ D3D11_TEXTURE2D_DESC dstDesc;
+ D3D11_FilterHoldInstance(filter, &sys->d3d_dev, &dstDesc);
+ if (unlikely(sys->d3d_dev.d3dcontext==NULL))
{
- msg_Dbg(filter, "D3D11 opaque without a texture");
- picture_Release(dst);
- return VLC_EGENERIC;
+ msg_Dbg(filter, "Filter without a context");
+ free(sys);
+ return VLC_ENOOBJ;
}
- D3D11_TEXTURE2D_DESC dstDesc;
- ID3D11Texture2D_GetDesc(dst->p_sys->texture[KNOWN_DXGI_INDEX], &dstDesc);
- sys->d3d_dev.d3dcontext = dst->p_sys->context;
- ID3D11DeviceContext_GetDevice(sys->d3d_dev.d3dcontext, &sys->d3d_dev.d3ddevice);
-
hr = ID3D11Device_QueryInterface(sys->d3d_dev.d3ddevice, &IID_ID3D11VideoDevice, (void **)&sys->d3dviddev);
if (FAILED(hr)) {
msg_Err(filter, "Could not Query ID3D11VideoDevice Interface. (hr=0x%lX)", hr);
@@ -556,11 +550,8 @@ static int D3D11OpenAdjust(vlc_object_t *obj)
filter->pf_video_filter = Filter;
filter->p_sys = sys;
- picture_Release(dst);
return VLC_SUCCESS;
error:
- picture_Release(dst);
-
for (int i=0; i<PROCESSOR_SLICES; i++)
{
if (sys->procInput[i])
@@ -582,7 +573,7 @@ error:
if (sys->d3dviddev)
ID3D11VideoDevice_Release(sys->d3dviddev);
if (sys->d3d_dev.d3dcontext)
- D3D11_ReleaseDevice(&sys->d3d_dev);
+ D3D11_FilterReleaseInstance(&sys->d3d_dev);
return VLC_EGENERIC;
}
@@ -612,7 +603,7 @@ static void D3D11CloseAdjust(vlc_object_t *obj)
ID3D11VideoContext_Release(sys->d3dvidctx);
ID3D11VideoDevice_Release(sys->d3dviddev);
- D3D11_ReleaseDevice(&sys->d3d_dev);
+ D3D11_FilterReleaseInstance(&sys->d3d_dev);
free(sys);
}
diff --git a/modules/hw/d3d11/d3d11_surface.c b/modules/hw/d3d11/d3d11_surface.c
index b946c3acbb..73a5d7c786 100644
--- a/modules/hw/d3d11/d3d11_surface.c
+++ b/modules/hw/d3d11/d3d11_surface.c
@@ -701,19 +701,15 @@ int D3D11OpenCPUConverter( vlc_object_t *obj )
d3d11_device_t d3d_dev;
D3D11_TEXTURE2D_DESC texDesc;
- picture_t *peek = filter_NewPicture(p_filter);
- if (peek == NULL)
- return VLC_EGENERIC;
- if (!peek->p_sys)
+ D3D11_FilterHoldInstance(p_filter, &d3d_dev, &texDesc);
+ if (unlikely(!d3d_dev.d3dcontext))
{
msg_Dbg(p_filter, "D3D11 opaque without a texture");
- picture_Release(peek);
return VLC_EGENERIC;
}
video_format_Init(&fmt_staging, 0);
- ID3D11Texture2D_GetDesc( peek->p_sys->texture[KNOWN_DXGI_INDEX], &texDesc);
vlc_fourcc_t d3d_fourcc = DxgiFormatFourcc(texDesc.Format);
if (d3d_fourcc == 0)
goto done;
@@ -725,7 +721,7 @@ int D3D11OpenCPUConverter( vlc_object_t *obj )
err = VLC_ENOMEM;
goto done;
}
- res.p_sys->context = d3d_dev.d3dcontext = peek->p_sys->context;
+ res.p_sys->context = d3d_dev.d3dcontext;
res.p_sys->formatTexture = texDesc.Format;
video_format_Copy(&fmt_staging, &p_filter->fmt_out.video);
@@ -749,7 +745,6 @@ int D3D11OpenCPUConverter( vlc_object_t *obj )
texDesc.BindFlags = 0;
texDesc.Height = p_dst->format.i_height; /* make sure we match picture_Setup() */
- ID3D11DeviceContext_GetDevice(peek->p_sys->context, &d3d_dev.d3ddevice);
HRESULT hr = ID3D11Device_CreateTexture2D( d3d_dev.d3ddevice, &texDesc, NULL, &texture);
if (FAILED(hr)) {
msg_Err(p_filter, "Failed to create a %s staging texture to extract surface pixels (hr=0x%0lx)", DxgiFormatToStr(texDesc.Format), hr );
@@ -785,14 +780,13 @@ int D3D11OpenCPUConverter( vlc_object_t *obj )
done:
video_format_Clean(&fmt_staging);
- picture_Release(peek);
if (err != VLC_SUCCESS)
{
if (p_cpu_filter)
DeleteFilter( p_cpu_filter );
if (texture)
ID3D11Texture2D_Release(texture);
- D3D11_ReleaseDevice(&d3d_dev);
+ D3D11_FilterReleaseInstance(&p_sys->d3d_dev);
free(p_sys);
}
else
@@ -820,7 +814,7 @@ void D3D11CloseConverter( vlc_object_t *obj )
vlc_mutex_destroy(&p_sys->staging_lock);
if (p_sys->staging)
ID3D11Texture2D_Release(p_sys->staging);
- D3D11_ReleaseDevice(&p_sys->d3d_dev);
+ D3D11_FilterReleaseInstance(&p_sys->d3d_dev);
D3D11_Destroy(&p_sys->hd3d);
free( p_sys );
p_filter->p_sys = NULL;
--
2.14.2
More information about the vlc-devel
mailing list