Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/LAVFilters.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHendrik Leppkes <h.leppkes@gmail.com>2017-08-12 22:51:54 +0300
committerHendrik Leppkes <h.leppkes@gmail.com>2017-08-12 22:53:02 +0300
commite3c6f38a1b7a9f721227b7d0fd362ea4247a7bce (patch)
treec0ac71b26e47158b90f97c34811281240e04b9f1
parentfefbb9fdcfe88c2e9185356d2d17a23d969e68da (diff)
d3d11: factor device creation into its own function
-rw-r--r--decoder/LAVVideo/decoders/d3d11va.cpp89
-rw-r--r--decoder/LAVVideo/decoders/d3d11va.h1
2 files changed, 53 insertions, 37 deletions
diff --git a/decoder/LAVVideo/decoders/d3d11va.cpp b/decoder/LAVVideo/decoders/d3d11va.cpp
index 43985f8b..fa806086 100644
--- a/decoder/LAVVideo/decoders/d3d11va.cpp
+++ b/decoder/LAVVideo/decoders/d3d11va.cpp
@@ -157,36 +157,14 @@ STDMETHODIMP CDecD3D11::InitAllocator(IMemAllocator **ppAlloc)
return m_pAllocator->QueryInterface(__uuidof(IMemAllocator), (void **)ppAlloc);
}
-STDMETHODIMP CDecD3D11::PostConnect(IPin *pPin)
+STDMETHODIMP CDecD3D11::CreateD3D11Device(UINT nDeviceIndex, ID3D11Device **ppDevice, DXGI_ADAPTER_DESC *pDesc)
{
- DbgLog((LOG_TRACE, 10, L"CDecD3D11::PostConnect()"));
- HRESULT hr = S_OK;
-
- ID3D11DecoderConfiguration *pD3D11DecoderConfiguration = nullptr;
- hr = pPin->QueryInterface(&pD3D11DecoderConfiguration);
- if (FAILED(hr)) {
- DbgLog((LOG_ERROR, 10, L"-> ID3D11DecoderConfiguration not available, using fallback mode"));
- }
-
- // Release old D3D resources, we're about to re-init
- m_pCallback->ReleaseAllDXVAResources();
-
- // free the decoder to force a re-init down the line
- SafeRelease(&m_pDecoder);
-
- // and the old device
- av_buffer_unref(&m_pDevCtx);
-
- // device id (hwcontext API wants a string)
- UINT nDevice = pD3D11DecoderConfiguration ? pD3D11DecoderConfiguration->GetD3D11AdapterIndex() : 0;
-
- // get adapter
- IDXGIAdapter *pDXGIAdapter = nullptr;
ID3D11Device *pD3D11Device = nullptr;
// create DXGI factory
+ IDXGIAdapter *pDXGIAdapter = nullptr;
IDXGIFactory1 *pDXGIFactory = nullptr;
- hr = dx.mCreateDXGIFactory1(IID_IDXGIFactory1, (void **)&pDXGIFactory);
+ HRESULT hr = dx.mCreateDXGIFactory1(IID_IDXGIFactory1, (void **)&pDXGIFactory);
if (FAILED(hr))
{
DbgLog((LOG_ERROR, 10, L"-> DXGIFactory creation failed"));
@@ -195,13 +173,13 @@ STDMETHODIMP CDecD3D11::PostConnect(IPin *pPin)
// find the adapter
enum_adapter:
- hr = pDXGIFactory->EnumAdapters(nDevice, &pDXGIAdapter);
+ hr = pDXGIFactory->EnumAdapters(nDeviceIndex, &pDXGIAdapter);
if (FAILED(hr))
{
- if (nDevice != 0)
+ if (nDeviceIndex != 0)
{
- DbgLog((LOG_ERROR, 10, L"-> Requested DXGI device %d not available, falling back to default", nDevice));
- nDevice = 0;
+ DbgLog((LOG_ERROR, 10, L"-> Requested DXGI device %d not available, falling back to default", nDeviceIndex));
+ nDeviceIndex = 0;
hr = pDXGIFactory->EnumAdapters(0, &pDXGIAdapter);
}
@@ -215,11 +193,11 @@ enum_adapter:
hr = dx.mD3D11CreateDevice(pDXGIAdapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, D3D11_CREATE_DEVICE_VIDEO_SUPPORT, nullptr, 0, D3D11_SDK_VERSION, &pD3D11Device, nullptr, nullptr);
if (FAILED(hr))
{
- if (nDevice != 0)
+ if (nDeviceIndex != 0)
{
- DbgLog((LOG_ERROR, 10, L"-> Failed to create a D3D11 device with video support on requested device %d, re-trying with default", nDevice));
+ DbgLog((LOG_ERROR, 10, L"-> Failed to create a D3D11 device with video support on requested device %d, re-trying with default", nDeviceIndex));
SafeRelease(&pDXGIAdapter);
- nDevice = 0;
+ nDeviceIndex = 0;
goto enum_adapter;
}
@@ -228,12 +206,51 @@ enum_adapter:
}
// store adapter info
- ZeroMemory(&m_AdapterDesc, sizeof(m_AdapterDesc));
- pDXGIAdapter->GetDesc(&m_AdapterDesc);
+ if (pDesc)
+ {
+ ZeroMemory(pDesc, sizeof(*pDesc));
+ pDXGIAdapter->GetDesc(pDesc);
+ }
- // done with the DXGI interface
+ // return device
+ *ppDevice = pD3D11Device;
+
+fail:
SafeRelease(&pDXGIFactory);
SafeRelease(&pDXGIAdapter);
+ return hr;
+}
+
+STDMETHODIMP CDecD3D11::PostConnect(IPin *pPin)
+{
+ DbgLog((LOG_TRACE, 10, L"CDecD3D11::PostConnect()"));
+ HRESULT hr = S_OK;
+
+ ID3D11DecoderConfiguration *pD3D11DecoderConfiguration = nullptr;
+ hr = pPin->QueryInterface(&pD3D11DecoderConfiguration);
+ if (FAILED(hr)) {
+ DbgLog((LOG_ERROR, 10, L"-> ID3D11DecoderConfiguration not available, using fallback mode"));
+ }
+
+ // Release old D3D resources, we're about to re-init
+ m_pCallback->ReleaseAllDXVAResources();
+
+ // free the decoder to force a re-init down the line
+ SafeRelease(&m_pDecoder);
+
+ // and the old device
+ av_buffer_unref(&m_pDevCtx);
+
+ // device id
+ UINT nDevice = pD3D11DecoderConfiguration ? pD3D11DecoderConfiguration->GetD3D11AdapterIndex() : 0;
+
+ // create the device
+ ID3D11Device *pD3D11Device = nullptr;
+ hr = CreateD3D11Device(nDevice, &pD3D11Device, &m_AdapterDesc);
+ if (FAILED(hr))
+ {
+ goto fail;
+ }
// allocate and fill device context
m_pDevCtx = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_D3D11VA);
@@ -302,8 +319,6 @@ enum_adapter:
fail:
SafeRelease(&pD3D11DecoderConfiguration);
- SafeRelease(&pDXGIFactory);
- SafeRelease(&pDXGIAdapter);
return E_FAIL;
}
diff --git a/decoder/LAVVideo/decoders/d3d11va.h b/decoder/LAVVideo/decoders/d3d11va.h
index b20570fb..a63a3e77 100644
--- a/decoder/LAVVideo/decoders/d3d11va.h
+++ b/decoder/LAVVideo/decoders/d3d11va.h
@@ -74,6 +74,7 @@ private:
STDMETHODIMP ReInitD3D11Decoder(AVCodecContext *c);
+ STDMETHODIMP CreateD3D11Device(UINT nDeviceIndex, ID3D11Device **ppDevice, DXGI_ADAPTER_DESC *pDesc);
STDMETHODIMP CreateD3D11Decoder();
STDMETHODIMP AllocateFramesContext(int width, int height, AVPixelFormat format, int nSurfaces, AVBufferRef **pFramesCtx);