Removed ATL dependencies

master
palana 2013-09-25 22:40:03 +02:00
parent 134a13c80d
commit 9eef86e1d2
5 changed files with 146 additions and 37 deletions

102
QSVHelper/ComPtr.hpp Normal file
View File

@ -0,0 +1,102 @@
/******************************************************************************
Copyright (c) 2013 by Hugh Bailey <obs.jim@gmail.com>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
******************************************************************************/
#pragma once
template<typename T> class ComPtr {
T *ptr;
inline void Kill()
{
if (ptr)
ptr->Release();
}
inline void Replace(T *p)
{
if (ptr != p) {
if (p) p->AddRef();
if (ptr) ptr->Release();
ptr = p;
}
}
public:
inline ComPtr() : ptr(NULL) {}
inline ComPtr(T *p) : ptr(p) {if (ptr) ptr->AddRef();}
inline ComPtr(const ComPtr &c) : ptr(c.ptr) {if (ptr) ptr->AddRef();}
inline ComPtr(ComPtr &&c) : ptr(c.ptr) {c.ptr = NULL;}
inline ~ComPtr() {Kill();}
inline void Clear()
{
if (ptr) {
ptr->Release();
ptr = NULL;
}
}
inline ComPtr &operator=(T *p)
{
Replace(p);
return *this;
}
inline ComPtr &operator=(const ComPtr &c)
{
Replace(c.ptr);
return *this;
}
inline ComPtr &operator=(ComPtr &&c)
{
if (this != &c) {
Kill();
ptr = c.ptr;
c.ptr = NULL;
}
return *this;
}
template <typename U> inline ComPtr &operator=(const ComPtr<U> &c)
{
if(!!c)
{
Kill();
c->QueryInterface(__uuidof(T), (void **)&ptr);
}
return *this;
}
inline T **Assign() {Clear(); return &ptr;}
inline void Set(T *p) {Kill(); ptr = p;}
inline operator T*() const {return ptr;}
inline T *operator->() const {return ptr;}
inline bool operator==(T *p) const {return ptr == p;}
inline bool operator!=(T *p) const {return ptr != p;}
inline bool operator!() const {return !ptr;}
};

View File

@ -18,6 +18,8 @@ Copyright(c) 2011 - 2012 Intel Corporation. All Rights Reserved.
#include <d3d11.h>
#include <atlbase.h>
#include "../../ComPtr.hpp"
#include <dxgi1_2.h>
class CD3D11Device: public CHWDevice
@ -38,29 +40,29 @@ protected:
virtual mfxStatus FillSCD(mfxHDL hWindow, DXGI_SWAP_CHAIN_DESC& scd);
mfxStatus CreateVideoProcessor(mfxFrameSurface1 * pSrf);
CComPtr<ID3D11Device> m_pD3D11Device;
CComPtr<ID3D11DeviceContext> m_pD3D11Ctx;
CComQIPtr<ID3D11VideoDevice> m_pDX11VideoDevice;
CComQIPtr<ID3D11VideoContext> m_pVideoContext;
CComPtr<ID3D11VideoProcessorEnumerator> m_VideoProcessorEnum;
ComPtr<ID3D11Device> m_pD3D11Device;
ComPtr<ID3D11DeviceContext> m_pD3D11Ctx;
ComPtr<ID3D11VideoDevice> m_pDX11VideoDevice; //QI
ComPtr<ID3D11VideoContext> m_pVideoContext; //QI
ComPtr<ID3D11VideoProcessorEnumerator> m_VideoProcessorEnum;
CComQIPtr<IDXGIDevice1> m_pDXGIDev;
CComQIPtr<IDXGIAdapter> m_pAdapter;
ComPtr<IDXGIDevice1> m_pDXGIDev;
ComPtr<IDXGIAdapter> m_pAdapter;
CComPtr<IDXGIFactory2> m_pDXGIFactory;
ComPtr<IDXGIFactory2> m_pDXGIFactory;
CComPtr<IDXGISwapChain1> m_pSwapChain;
CComPtr<ID3D11VideoProcessor> m_pVideoProcessor;
ComPtr<IDXGISwapChain1> m_pSwapChain;
ComPtr<ID3D11VideoProcessor> m_pVideoProcessor;
private:
CComPtr<ID3D11VideoProcessorInputView> m_pInputViewLeft;
CComPtr<ID3D11VideoProcessorInputView> m_pInputViewRight;
CComPtr<ID3D11VideoProcessorOutputView> m_pOutputView;
ComPtr<ID3D11VideoProcessorInputView> m_pInputViewLeft;
ComPtr<ID3D11VideoProcessorInputView> m_pInputViewRight;
ComPtr<ID3D11VideoProcessorOutputView> m_pOutputView;
CComPtr<ID3D11Texture2D> m_pDXGIBackBuffer;
CComPtr<ID3D11Texture2D> m_pTempTexture;
CComPtr<IDXGIDisplayControl> m_pDisplayControl;
CComPtr<IDXGIOutput> m_pDXGIOutput;
ComPtr<ID3D11Texture2D> m_pDXGIBackBuffer;
ComPtr<ID3D11Texture2D> m_pTempTexture;
ComPtr<IDXGIDisplayControl> m_pDisplayControl;
ComPtr<IDXGIOutput> m_pDXGIOutput;
mfxU16 m_nViews;
BOOL m_bDefaultStereoEnabled;
};

View File

@ -55,13 +55,13 @@ mfxStatus CD3D11Device::Init(
};
D3D_FEATURE_LEVEL pFeatureLevelsOut;
hres = CreateDXGIFactory(__uuidof(IDXGIFactory2), (void**)(&m_pDXGIFactory) );
hres = CreateDXGIFactory(__uuidof(IDXGIFactory2), (void**)(m_pDXGIFactory.Assign()) );
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
if (m_nViews == 2 && hWindow)
{
hres = m_pDXGIFactory->QueryInterface(__uuidof(IDXGIDisplayControl), (void **)&m_pDisplayControl);
hres = m_pDXGIFactory->QueryInterface(__uuidof(IDXGIDisplayControl), (void **)m_pDisplayControl.Assign());
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
m_bDefaultStereoEnabled = m_pDisplayControl->IsStereoEnabled();
@ -69,7 +69,7 @@ mfxStatus CD3D11Device::Init(
m_pDisplayControl->SetStereoEnabled(TRUE);
}
hres = m_pDXGIFactory->EnumAdapters(nAdapterNum,&m_pAdapter);
hres = m_pDXGIFactory->EnumAdapters(nAdapterNum, m_pAdapter.Assign());
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
@ -80,9 +80,9 @@ mfxStatus CD3D11Device::Init(
FeatureLevels,
MSDK_ARRAY_LEN(FeatureLevels),
D3D11_SDK_VERSION,
&m_pD3D11Device,
m_pD3D11Device.Assign(),
&pFeatureLevelsOut,
&m_pD3D11Ctx);
m_pD3D11Ctx.Assign());
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
@ -91,12 +91,13 @@ mfxStatus CD3D11Device::Init(
m_pDX11VideoDevice = m_pD3D11Device;
m_pVideoContext = m_pD3D11Ctx;
MSDK_CHECK_POINTER(m_pDXGIDev.p, MFX_ERR_NULL_PTR);
MSDK_CHECK_POINTER(m_pDX11VideoDevice.p, MFX_ERR_NULL_PTR);
MSDK_CHECK_POINTER(m_pVideoContext.p, MFX_ERR_NULL_PTR);
MSDK_CHECK_POINTER(!!m_pDXGIDev, MFX_ERR_NULL_PTR);
MSDK_CHECK_POINTER(!!m_pDX11VideoDevice, MFX_ERR_NULL_PTR);
MSDK_CHECK_POINTER(!!m_pVideoContext, MFX_ERR_NULL_PTR);
// turn on multithreading for the Context
CComQIPtr<ID3D10Multithread> p_mt(m_pVideoContext);
ComPtr<ID3D10Multithread> p_mt;
p_mt = m_pVideoContext;
if (p_mt)
p_mt->SetMultithreadProtected(true);
@ -111,7 +112,7 @@ mfxStatus CD3D11Device::Init(
sts = FillSCD(hWindow, scd);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
MSDK_CHECK_POINTER (m_pDXGIFactory.p, MFX_ERR_NULL_PTR);
MSDK_CHECK_POINTER (!!m_pDXGIFactory, MFX_ERR_NULL_PTR);
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
swapChainDesc.Width = 0; // Use automatic sizing.
swapChainDesc.Height = 0;
@ -141,7 +142,7 @@ mfxStatus CD3D11Device::CreateVideoProcessor(mfxFrameSurface1 * pSrf)
{
HRESULT hres = S_OK;
if (m_VideoProcessorEnum.p || NULL == pSrf)
if (!!m_VideoProcessorEnum || NULL == pSrf)
return MFX_ERR_NONE;
//create video processor
@ -160,11 +161,11 @@ mfxStatus CD3D11Device::CreateVideoProcessor(mfxFrameSurface1 * pSrf)
ContentDesc.Usage = D3D11_VIDEO_USAGE_PLAYBACK_NORMAL;
hres = m_pDX11VideoDevice->CreateVideoProcessorEnumerator( &ContentDesc, &m_VideoProcessorEnum );
hres = m_pDX11VideoDevice->CreateVideoProcessorEnumerator( &ContentDesc, m_VideoProcessorEnum.Assign() );
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
hres = m_pDX11VideoDevice->CreateVideoProcessor( m_VideoProcessorEnum, 0, &m_pVideoProcessor );
hres = m_pDX11VideoDevice->CreateVideoProcessor( m_VideoProcessorEnum, 0, m_pVideoProcessor.Assign() );
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
@ -183,7 +184,7 @@ mfxStatus CD3D11Device::GetHandle(mfxHandleType type, mfxHDL *pHdl)
{
if (MFX_HANDLE_D3D11_DEVICE == type)
{
*pHdl = m_pD3D11Device.p;
*pHdl = *m_pD3D11Device.Assign();
return MFX_ERR_NONE;
}
return MFX_ERR_UNSUPPORTED;
@ -202,7 +203,7 @@ mfxStatus CD3D11Device::RenderFrame(mfxFrameSurface1 * pSrf, mfxFrameAllocator *
sts = CreateVideoProcessor(pSrf);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
hres = m_pSwapChain->GetBuffer(0, __uuidof( ID3D11Texture2D ), (void**)&m_pDXGIBackBuffer.p);
hres = m_pSwapChain->GetBuffer(0, __uuidof( ID3D11Texture2D ), (void**)m_pDXGIBackBuffer.Assign());
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
@ -230,7 +231,7 @@ mfxStatus CD3D11Device::RenderFrame(mfxFrameSurface1 * pSrf, mfxFrameAllocator *
m_pDXGIBackBuffer,
m_VideoProcessorEnum,
&OutputViewDesc,
&m_pOutputView.p );
m_pOutputView.Assign() );
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
}
@ -251,7 +252,7 @@ mfxStatus CD3D11Device::RenderFrame(mfxFrameSurface1 * pSrf, mfxFrameAllocator *
if(!m_pTempTexture && m_nViews == 2)
{
pRTTexture2D->GetDesc(&RTTexture2DDesc);
hres = m_pD3D11Device->CreateTexture2D(&RTTexture2DDesc,NULL,&m_pTempTexture.p);
hres = m_pD3D11Device->CreateTexture2D(&RTTexture2DDesc,NULL, m_pTempTexture.Assign());
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
}
@ -263,7 +264,7 @@ mfxStatus CD3D11Device::RenderFrame(mfxFrameSurface1 * pSrf, mfxFrameAllocator *
pRTTexture2D,
m_VideoProcessorEnum,
&InputViewDesc,
&m_pInputViewLeft.p );
m_pInputViewLeft.Assign() );
}
else if (2 == m_nViews && 0 == pSrf->Info.FrameId.ViewId)
@ -273,7 +274,7 @@ mfxStatus CD3D11Device::RenderFrame(mfxFrameSurface1 * pSrf, mfxFrameAllocator *
m_pTempTexture,
m_VideoProcessorEnum,
&InputViewDesc,
&m_pInputViewLeft.p );
m_pInputViewLeft.Assign() );
}
else
{
@ -281,7 +282,7 @@ mfxStatus CD3D11Device::RenderFrame(mfxFrameSurface1 * pSrf, mfxFrameAllocator *
pRTTexture2D,
m_VideoProcessorEnum,
&InputViewDesc,
&m_pInputViewRight.p );
m_pInputViewRight.Assign() );
}
if (FAILED(hres))

View File

@ -104,6 +104,7 @@
<ClCompile Include="QSVHelper.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ComPtr.hpp" />
<ClInclude Include="Encoder.h" />
<ClInclude Include="IntelSupport\include\base_allocator.h" />
<ClInclude Include="IntelSupport\include\current_date.h" />

View File

@ -83,5 +83,8 @@
<ClInclude Include="IntelSupport\include\vm\time_defs.h">
<Filter>IntelSupport\Headers</Filter>
</ClInclude>
<ClInclude Include="ComPtr.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>