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

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/filters/renderer')
-rw-r--r--src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.cpp22
-rw-r--r--src/filters/renderer/SyncClock/SyncClock.cpp10
-rw-r--r--src/filters/renderer/SyncClock/SyncClock.vcxproj2
-rw-r--r--src/filters/renderer/VideoRenderers/D3DFont.cpp4
-rw-r--r--src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.cpp90
-rw-r--r--src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.cpp94
-rw-r--r--src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.h13
-rw-r--r--src/filters/renderer/VideoRenderers/DX9RenderingEngine.cpp10
-rw-r--r--src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.cpp2
-rw-r--r--src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.cpp53
-rw-r--r--src/filters/renderer/VideoRenderers/IPinHook.cpp361
-rw-r--r--src/filters/renderer/VideoRenderers/PixelShaderCompiler.cpp4
-rw-r--r--src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.cpp2
-rw-r--r--src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.cpp2
-rw-r--r--src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.cpp2
-rw-r--r--src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.cpp2
-rw-r--r--src/filters/renderer/VideoRenderers/SyncRenderer.cpp84
-rw-r--r--src/filters/renderer/VideoRenderers/VideoRenderers.vcxproj2
-rw-r--r--src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.cpp2
19 files changed, 409 insertions, 352 deletions
diff --git a/src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.cpp b/src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.cpp
index 432b2a5fc..6d7498e21 100644
--- a/src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.cpp
+++ b/src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.cpp
@@ -90,28 +90,27 @@ bool CALLBACK DSEnumProc2(LPGUID lpGUID,
CMpcAudioRenderer::CMpcAudioRenderer(LPUNKNOWN punk, HRESULT* phr)
: CBaseRenderer(__uuidof(this), MpcAudioRendererName, punk, phr)
- , m_pDSBuffer(nullptr)
- , m_pSoundTouch(nullptr)
, m_pDS(nullptr)
+ , m_pDSBuffer(nullptr)
, m_dwDSWriteOff(0)
+ , m_pWaveFileFormat(nullptr)
, m_nDSBufSize(0)
- , m_dRate(1.0)
, m_pReferenceClock(nullptr)
- , m_pWaveFileFormat(nullptr)
+ , m_dRate(1.0)
+ , m_lVolume(DSBVOLUME_MIN)
+ , m_pSoundTouch(nullptr)
+ , m_useWASAPI(true)
+ , m_bMuteFastForward(false)
, m_pMMDevice(nullptr)
, m_pAudioClient(nullptr)
, m_pRenderClient(nullptr)
- , m_useWASAPI(true)
- , m_bMuteFastForward(false)
- , m_csSound_Device(_T(""))
, m_nFramesInBuffer(0)
, m_hnsPeriod(0)
+ , m_hnsActualDuration(0)
, m_hTask(nullptr)
, m_bufferSize(0)
, m_isAudioClientStarted(false)
, m_lastBufferTime(0)
- , m_hnsActualDuration(0)
- , m_lVolume(DSBVOLUME_MIN)
, m_pfAvSetMmThreadCharacteristicsW(nullptr)
, m_pfAvRevertMmThreadCharacteristics(nullptr)
{
@@ -1195,9 +1194,8 @@ HRESULT CMpcAudioRenderer::GetBufferSize(WAVEFORMATEX* pWaveFormatEx, REFERENCE_
return S_OK;
}
- *pHnsBufferPeriod = (REFERENCE_TIME)((REFERENCE_TIME)m_bufferSize * 10000 * 8 / ((REFERENCE_TIME)pWaveFormatEx->nChannels * pWaveFormatEx->wBitsPerSample *
- 1.0 * pWaveFormatEx->nSamplesPerSec) /*+ 0.5*/);
- *pHnsBufferPeriod *= 1000;
+ const double dBitrate = (double)pWaveFormatEx->nChannels * pWaveFormatEx->wBitsPerSample * pWaveFormatEx->nSamplesPerSec;
+ *pHnsBufferPeriod = REFERENCE_TIME(m_bufferSize * 10000000i64 * 8 / dBitrate);
TRACE(_T("CMpcAudioRenderer::GetBufferSize set a %I64d period for a %ld buffer size\n"), *pHnsBufferPeriod, m_bufferSize);
diff --git a/src/filters/renderer/SyncClock/SyncClock.cpp b/src/filters/renderer/SyncClock/SyncClock.cpp
index ff4406f32..6b2356c0c 100644
--- a/src/filters/renderer/SyncClock/SyncClock.cpp
+++ b/src/filters/renderer/SyncClock/SyncClock.cpp
@@ -1,5 +1,5 @@
/*
- * (C) 2010-2013 see Authors.txt
+ * (C) 2010-2014 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -82,13 +82,13 @@ CBasePin* CSyncClockFilter::GetPin(int i)
// CSyncClock methods
CSyncClock::CSyncClock(LPUNKNOWN pUnk, HRESULT* phr)
: CBaseReferenceClock(NAME("SyncClock"), pUnk, phr)
- , m_pCurrentRefClock(0)
- , m_pPrevRefClock(0)
- , m_rtPrivateTime(GetTicks100ns())
- , m_rtPrevTime(m_rtPrivateTime)
, adjustment(1.0)
, bias(1.0)
+ , m_rtPrivateTime(GetTicks100ns())
, m_llPerfFrequency(0)
+ , m_rtPrevTime(m_rtPrivateTime)
+ , m_pCurrentRefClock(0)
+ , m_pPrevRefClock(0)
{
QueryPerformanceFrequency((LARGE_INTEGER*)&m_llPerfFrequency);
}
diff --git a/src/filters/renderer/SyncClock/SyncClock.vcxproj b/src/filters/renderer/SyncClock/SyncClock.vcxproj
index e2fc21f68..131e1b69e 100644
--- a/src/filters/renderer/SyncClock/SyncClock.vcxproj
+++ b/src/filters/renderer/SyncClock/SyncClock.vcxproj
@@ -66,8 +66,6 @@
<Import Project="..\..\..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
- <PropertyGroup>
- </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>..\..\..\..\include;..\..\..\thirdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
diff --git a/src/filters/renderer/VideoRenderers/D3DFont.cpp b/src/filters/renderer/VideoRenderers/D3DFont.cpp
index d9ca233ec..406a3ea15 100644
--- a/src/filters/renderer/VideoRenderers/D3DFont.cpp
+++ b/src/filters/renderer/VideoRenderers/D3DFont.cpp
@@ -356,8 +356,8 @@ HRESULT CD3DFont::RestoreDeviceObjects()
// Create vertex buffer for the letters
UINT vertexSize = std::max<UINT>(sizeof(FONT2DVERTEX), sizeof(FONT3DVERTEX));
if (FAILED(hr = m_pd3dDevice->CreateVertexBuffer(MAX_NUM_VERTICES * vertexSize,
- D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0,
- D3DPOOL_DEFAULT, &m_pVB, nullptr))) {
+ D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0,
+ D3DPOOL_DEFAULT, &m_pVB, nullptr))) {
return hr;
}
diff --git a/src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.cpp
index 6790d7e0c..f13c1a472 100644
--- a/src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.cpp
@@ -253,6 +253,8 @@ HRESULT CDX7AllocatorPresenter::AllocSurfaces()
{
CAutoLock cAutoLock(this);
+ CheckPointer(m_pDD, E_POINTER);
+
const CRenderersSettings& r = GetRenderersSettings();
m_pVideoTexture = nullptr;
@@ -347,42 +349,37 @@ STDMETHODIMP_(bool) CDX7AllocatorPresenter::Paint(bool bAll)
CRect rSrcPri(CPoint(0, 0), m_windowRect.Size());
CRect rDstPri(m_windowRect);
- if (bAll) {
- // clear the backbuffer
-
- CRect rl(0, 0, rDstVid.left, rSrcPri.bottom);
- CRect rr(rDstVid.right, 0, rSrcPri.right, rSrcPri.bottom);
- CRect rt(0, 0, rSrcPri.right, rDstVid.top);
- CRect rb(0, rDstVid.bottom, rSrcPri.right, rSrcPri.bottom);
-
- DDBLTFX fx;
- INITDDSTRUCT(fx);
- fx.dwFillColor = 0;
- hr = m_pBackBuffer->Blt(nullptr, nullptr, nullptr, DDBLT_WAIT | DDBLT_COLORFILL, &fx);
-
- // paint the video on the backbuffer
-
- if (!rDstVid.IsRectEmpty()) {
- if (m_pVideoTexture) {
- Vector v[4];
- Transform(rDstVid, v);
- hr = TextureBlt(m_pD3DDev, m_pVideoTexture, v, rSrcVid);
- } else {
- hr = m_pBackBuffer->Blt(rDstVid, m_pVideoSurface, rSrcVid, DDBLT_WAIT, nullptr);
- }
- }
+ // clear the backbuffer
+ CRect rl(0, 0, rDstVid.left, rSrcPri.bottom);
+ CRect rr(rDstVid.right, 0, rSrcPri.right, rSrcPri.bottom);
+ CRect rt(0, 0, rSrcPri.right, rDstVid.top);
+ CRect rb(0, rDstVid.bottom, rSrcPri.right, rSrcPri.bottom);
- // paint the text on the backbuffer
-
- AlphaBltSubPic(rDstPri, rDstVid);
+ DDBLTFX fx;
+ INITDDSTRUCT(fx);
+ fx.dwFillColor = 0;
+ hr = m_pBackBuffer->Blt(nullptr, nullptr, nullptr, DDBLT_WAIT | DDBLT_COLORFILL, &fx);
+
+ // paint the video on the backbuffer
+ if (!rDstVid.IsRectEmpty()) {
+ if (m_pVideoTexture) {
+ Vector v[4];
+ Transform(rDstVid, v);
+ hr = TextureBlt(m_pD3DDev, m_pVideoTexture, v, rSrcVid);
+ } else {
+ hr = m_pBackBuffer->Blt(rDstVid, m_pVideoSurface, rSrcVid, DDBLT_WAIT, nullptr);
+ }
}
- // wait vsync
+ // paint the text on the backbuffer
+ AlphaBltSubPic(rDstPri, rDstVid);
- m_pDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, nullptr);
+ // wait vsync
+ if (bAll) {
+ m_pDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, nullptr);
+ }
// blt to the primary surface
-
MapWindowRect(m_hWnd, HWND_DESKTOP, &rDstPri);
hr = m_pPrimary->Blt(rDstPri, m_pBackBuffer, rSrcPri, DDBLT_WAIT, nullptr);
@@ -428,11 +425,20 @@ STDMETHODIMP CDX7AllocatorPresenter::GetDIB(BYTE* lpDib, DWORD* size)
{
CheckPointer(size, E_POINTER);
+ // Keep a reference so that we can safely work on the surface
+ // without having to lock everything
+ CComPtr<IDirectDrawSurface7> pVideoSurface;
+ {
+ CAutoLock cAutoLock(this);
+ CheckPointer(m_pVideoSurface, E_FAIL);
+ pVideoSurface = m_pVideoSurface;
+ }
+
HRESULT hr;
DDSURFACEDESC2 ddsd;
INITDDSTRUCT(ddsd);
- if (FAILED(m_pVideoSurface->GetSurfaceDesc(&ddsd))) {
+ if (FAILED(pVideoSurface->GetSurfaceDesc(&ddsd))) {
return E_FAIL;
}
@@ -451,8 +457,7 @@ STDMETHODIMP CDX7AllocatorPresenter::GetDIB(BYTE* lpDib, DWORD* size)
*size = required;
INITDDSTRUCT(ddsd);
- if (FAILED(hr = m_pVideoSurface->Lock(nullptr, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR | DDLOCK_READONLY | DDLOCK_NOSYSLOCK, nullptr))) {
- // TODO
+ if (FAILED(hr = pVideoSurface->Lock(nullptr, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR | DDLOCK_READONLY | DDLOCK_NOSYSLOCK, nullptr))) {
return hr;
}
@@ -465,22 +470,11 @@ STDMETHODIMP CDX7AllocatorPresenter::GetDIB(BYTE* lpDib, DWORD* size)
bih->biPlanes = 1;
bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount >> 3;
- BitBltFromRGBToRGB(
- bih->biWidth, bih->biHeight,
- (BYTE*)(bih + 1), bih->biWidth * bih->biBitCount >> 3, bih->biBitCount,
- (BYTE*)ddsd.lpSurface + ddsd.lPitch * (ddsd.dwHeight - 1), -(int)ddsd.lPitch, ddsd.ddpfPixelFormat.dwRGBBitCount);
+ BitBltFromRGBToRGB(bih->biWidth, bih->biHeight,
+ (BYTE*)(bih + 1), bih->biWidth * bih->biBitCount >> 3, bih->biBitCount,
+ (BYTE*)ddsd.lpSurface + ddsd.lPitch * (ddsd.dwHeight - 1), -(int)ddsd.lPitch, ddsd.ddpfPixelFormat.dwRGBBitCount);
- m_pVideoSurface->Unlock(nullptr);
-
- /*
- BitBltFromRGBToRGB(
- w, h,
- (BYTE*)ddsd.lpSurface, ddsd.lPitch, ddsd.ddpfPixelFormat.dwRGBBitCount,
- (BYTE*)bm.bmBits, bm.bmWidthBytes, bm.bmBitsPixel);
- m_pVideoSurfaceOff->Unlock(nullptr);
- fOk = true;
- }
- */
+ pVideoSurface->Unlock(nullptr);
return S_OK;
}
diff --git a/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.cpp
index d036648c2..4a1bb1da5 100644
--- a/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.cpp
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2014 see Authors.txt
+ * (C) 2006-2015 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -55,9 +55,21 @@ CDX9AllocatorPresenter::CDX9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
, m_bIsFullscreen(bFullscreen)
, m_bNeedCheckSample(true)
, m_MainThreadId(0)
+ , m_bIsRendering(false)
+ , m_hDWMAPI(nullptr)
+ , m_hD3D9(nullptr)
+ , m_pDwmIsCompositionEnabled(nullptr)
+ , m_pDwmEnableComposition(nullptr)
+ , m_pDirect3DCreate9Ex(nullptr)
+ , m_pDirectDraw(nullptr)
, m_LastAdapterCheck(0)
, m_nTearingPos(0)
, m_VMR9AlphaBitmapWidthBytes(0)
+ , m_pD3DXLoadSurfaceFromMemory(nullptr)
+ , m_pD3DXLoadSurfaceFromSurface(nullptr)
+ , m_pD3DXCreateLine(nullptr)
+ , m_pD3DXCreateFont(nullptr)
+ , m_pD3DXCreateSprite(nullptr)
, m_nVMR9Surfaces(0)
, m_iVMR9Surface(0)
, m_nUsedBuffer(0)
@@ -132,18 +144,6 @@ CDX9AllocatorPresenter::CDX9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
, m_LastFrameDuration(0)
, m_LastSampleTime(0)
, m_FocusThread(nullptr)
- , m_pDirectDraw(nullptr)
- , m_hDWMAPI(nullptr)
- , m_hD3D9(nullptr)
- , m_pD3DXLoadSurfaceFromMemory(nullptr)
- , m_pD3DXLoadSurfaceFromSurface(nullptr)
- , m_pD3DXCreateLine(nullptr)
- , m_pD3DXCreateFont(nullptr)
- , m_pD3DXCreateSprite(nullptr)
- , m_pDwmIsCompositionEnabled(nullptr)
- , m_pDwmEnableComposition(nullptr)
- , m_pDirect3DCreate9Ex(nullptr)
- , m_bIsRendering(false)
{
ZeroMemory(&m_VMR9AlphaBitmap, sizeof(m_VMR9AlphaBitmap));
@@ -792,22 +792,19 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString& _Error)
m_BackbufferType = pp.BackBufferFormat;
}
- while (hr == D3DERR_DEVICELOST) {
- TRACE(_T("D3DERR_DEVICELOST. Trying to Reset.\n"));
- hr = m_pD3DDev->TestCooperativeLevel();
- }
- if (hr == D3DERR_DEVICENOTRESET) {
- TRACE(_T("D3DERR_DEVICENOTRESET\n"));
- hr = m_pD3DDev->Reset(&pp);
- }
-
- TRACE(_T("CreateDevice: %ld\n"), (LONG)hr);
- ASSERT(SUCCEEDED(hr));
-
- m_MainThreadId = GetCurrentThreadId();
+ if (m_pD3DDev) {
+ while (hr == D3DERR_DEVICELOST) {
+ TRACE(_T("D3DERR_DEVICELOST. Trying to Reset.\n"));
+ hr = m_pD3DDev->TestCooperativeLevel();
+ }
+ if (hr == D3DERR_DEVICENOTRESET) {
+ TRACE(_T("D3DERR_DEVICENOTRESET\n"));
+ hr = m_pD3DDev->Reset(&pp);
+ }
- if (m_pD3DDevEx) {
- m_pD3DDevEx->SetGPUThreadPriority(7);
+ if (m_pD3DDevEx) {
+ m_pD3DDevEx->SetGPUThreadPriority(7);
+ }
}
if (FAILED(hr)) {
@@ -819,6 +816,10 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString& _Error)
return hr;
}
+ ASSERT(m_pD3DDev);
+
+ m_MainThreadId = GetCurrentThreadId();
+
// Get the device caps
ZeroMemory(&m_Caps, sizeof(m_Caps));
m_pD3DDev->GetDeviceCaps(&m_Caps);
@@ -841,7 +842,7 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString& _Error)
hr = S_OK;
if (!m_pSubPicQueue) {
- CAutoLock(this);
+ CAutoLock cAutoLock(this);
m_pSubPicQueue = r.subPicQueueSettings.nSize > 0
? (ISubPicQueue*)DEBUG_NEW CSubPicQueue(r.subPicQueueSettings, m_pAllocator, &hr)
: (ISubPicQueue*)DEBUG_NEW CSubPicQueueNoThread(r.subPicQueueSettings, m_pAllocator, &hr);
@@ -1412,8 +1413,8 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool bAll)
if ((m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_DISABLE) == 0 && (BYTE*)m_VMR9AlphaBitmapData) {
if ((m_pD3DXLoadSurfaceFromMemory != nullptr) &&
SUCCEEDED(hr = m_pD3DDev->CreateTexture(rcSrc.Width(), rcSrc.Height(), 1,
- D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
- D3DPOOL_DEFAULT, &m_pOSDTexture, nullptr))) {
+ D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
+ D3DPOOL_DEFAULT, &m_pOSDTexture, nullptr))) {
if (SUCCEEDED(hr = m_pOSDTexture->GetSurfaceLevel(0, &m_pOSDSurface))) {
hr = m_pD3DXLoadSurfaceFromMemory(m_pOSDSurface,
nullptr,
@@ -1908,7 +1909,12 @@ void CDX9AllocatorPresenter::DrawStats()
OffsetRect(&rc, 0, TextHeight);
if (m_bIsEVR) {
- strText.Format(L"Refresh rate : %.05f Hz SL: %4d (%3u Hz) Last Duration: %10.6f Corrected Frame Time: %s", m_DetectedRefreshRate, int(m_DetectedScanlinesPerFrame + 0.5), m_refreshRate, double(m_LastFrameDuration) / 10000.0, m_bCorrectedFrameTime ? L"Yes" : L"No");
+ if (r.m_AdvRendSets.bVMR9VSync) {
+ strText.Format(L"Refresh rate : %.05f Hz SL: %4d (%3u Hz) ", m_DetectedRefreshRate, int(m_DetectedScanlinesPerFrame + 0.5), m_refreshRate);
+ } else {
+ strText.Format(L"Refresh rate : %3u Hz ", m_refreshRate);
+ }
+ strText.AppendFormat(L"Last Duration: %10.6f Corrected Frame Time: %s", double(m_LastFrameDuration) / 10000.0, m_bCorrectedFrameTime ? L"Yes" : L"No");
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
}
@@ -2128,11 +2134,22 @@ STDMETHODIMP CDX9AllocatorPresenter::GetDIB(BYTE* lpDib, DWORD* size)
{
CheckPointer(size, E_POINTER);
+ // Keep a reference so that we can safely work on the surface
+ // without having to lock everything
+ CComPtr<IDirect3DSurface9> pVideoSurface;
+ {
+ CAutoLock cAutoLock(this);
+ CheckPointer(m_pVideoSurface[m_nCurSurface], E_FAIL);
+ pVideoSurface = m_pVideoSurface[m_nCurSurface];
+ }
+
HRESULT hr;
D3DSURFACE_DESC desc;
ZeroMemory(&desc, sizeof(desc));
- m_pVideoSurface[m_nCurSurface]->GetDesc(&desc);
+ if (FAILED(hr = pVideoSurface->GetDesc(&desc))) {
+ return hr;
+ }
DWORD required = sizeof(BITMAPINFOHEADER) + (desc.Width * desc.Height * 32 >> 3);
if (!lpDib) {
@@ -2148,11 +2165,11 @@ STDMETHODIMP CDX9AllocatorPresenter::GetDIB(BYTE* lpDib, DWORD* size)
// Convert to 8-bit when using 10-bit or full/half processing modes
if (desc.Format != D3DFMT_X8R8G8B8) {
if (FAILED(hr = m_pD3DDev->CreateOffscreenPlainSurface(desc.Width, desc.Height, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pSurface, nullptr))
- || FAILED(hr = m_pD3DXLoadSurfaceFromSurface(pSurface, nullptr, nullptr, m_pVideoSurface[m_nCurSurface], nullptr, nullptr, D3DX_DEFAULT, 0))) {
+ || FAILED(hr = m_pD3DXLoadSurfaceFromSurface(pSurface, nullptr, nullptr, pVideoSurface, nullptr, nullptr, D3DX_DEFAULT, 0))) {
return hr;
}
} else {
- pSurface = m_pVideoSurface[m_nCurSurface];
+ pSurface = pVideoSurface;
}
D3DLOCKED_RECT r;
if (FAILED(hr = pSurface->LockRect(&r, nullptr, D3DLOCK_READONLY))) {
@@ -2175,10 +2192,9 @@ STDMETHODIMP CDX9AllocatorPresenter::GetDIB(BYTE* lpDib, DWORD* size)
bih->biPlanes = 1;
bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount >> 3;
- BitBltFromRGBToRGB(
- bih->biWidth, bih->biHeight,
- (BYTE*)(bih + 1), bih->biWidth * bih->biBitCount >> 3, bih->biBitCount,
- (BYTE*)r.pBits + r.Pitch * (desc.Height - 1), -(int)r.Pitch, 32);
+ BitBltFromRGBToRGB(bih->biWidth, bih->biHeight,
+ (BYTE*)(bih + 1), bih->biWidth * bih->biBitCount >> 3, bih->biBitCount,
+ (BYTE*)r.pBits + r.Pitch * (desc.Height - 1), -(int)r.Pitch, 32);
pSurface->UnlockRect();
diff --git a/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.h b/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.h
index cb4db14b5..6dd983bd9 100644
--- a/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.h
@@ -56,13 +56,12 @@ namespace DSObjects
CRenderersSettings::CAdvRendererSettings m_LastRendererSettings;
- HRESULT(__stdcall* m_pDwmIsCompositionEnabled)(__out BOOL* pfEnabled);
- HRESULT(__stdcall* m_pDwmEnableComposition)(UINT uCompositionAction);
-
HMODULE m_hDWMAPI;
+ HMODULE m_hD3D9;
+ HRESULT(__stdcall* m_pDwmIsCompositionEnabled)(__out BOOL* pfEnabled);
+ HRESULT(__stdcall* m_pDwmEnableComposition)(UINT uCompositionAction);
HRESULT(__stdcall* m_pDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex**);
- HMODULE m_hD3D9;
CCritSec m_RenderLock;
CComPtr<IDirectDraw> m_pDirectDraw;
@@ -174,9 +173,9 @@ namespace DSObjects
int m_VMR9AlphaBitmapWidthBytes;
D3DXLoadSurfaceFromMemoryPtr m_pD3DXLoadSurfaceFromMemory;
- D3DXLoadSurfaceFromSurfacePtr m_pD3DXLoadSurfaceFromSurface;
- D3DXCreateLinePtr m_pD3DXCreateLine;
- D3DXCreateFontPtr m_pD3DXCreateFont;
+ D3DXLoadSurfaceFromSurfacePtr m_pD3DXLoadSurfaceFromSurface;
+ D3DXCreateLinePtr m_pD3DXCreateLine;
+ D3DXCreateFontPtr m_pD3DXCreateFont;
HRESULT(__stdcall* m_pD3DXCreateSprite)(LPDIRECT3DDEVICE9 pDevice, LPD3DXSPRITE* ppSprite);
diff --git a/src/filters/renderer/VideoRenderers/DX9RenderingEngine.cpp b/src/filters/renderer/VideoRenderers/DX9RenderingEngine.cpp
index 4a755fea1..2890ac870 100644
--- a/src/filters/renderer/VideoRenderers/DX9RenderingEngine.cpp
+++ b/src/filters/renderer/VideoRenderers/DX9RenderingEngine.cpp
@@ -140,12 +140,12 @@ using namespace DSObjects;
CDX9RenderingEngine::CDX9RenderingEngine(HWND hWnd, HRESULT& hr, CString* _pError)
: CSubPicAllocatorPresenterImpl(hWnd, hr, _pError)
- , m_ScreenSize(0, 0)
- , m_nNbDXSurface(1)
- , m_nCurSurface(0)
, m_CurrentAdapter(UINT_ERROR)
, m_BackbufferType(D3DFMT_UNKNOWN)
, m_DisplayType(D3DFMT_UNKNOWN)
+ , m_ScreenSize(0, 0)
+ , m_nNbDXSurface(1)
+ , m_nCurSurface(0)
, m_bHighColorResolution(false)
, m_bForceInputHighColorResolution(false)
, m_RenderingPath(RENDERING_PATH_DRAW)
@@ -227,6 +227,8 @@ HRESULT CDX9RenderingEngine::CreateVideoSurfaces()
m_pTemporaryVideoTextures[i] = nullptr;
}
+ CheckPointer(m_pD3DDev, E_POINTER);
+
if (r.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE2D || r.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D) {
int nTexturesNeeded = r.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D ? m_nNbDXSurface : 1;
@@ -581,7 +583,7 @@ HRESULT CDX9RenderingEngine::InitTemporaryScreenSpaceTextures(int count)
for (int i = 0; i < count; i++) {
if (m_pTemporaryScreenSpaceTextures[i] == nullptr) {
m_TemporaryScreenSpaceTextureSize = CSize(std::min(m_ScreenSize.cx, (long)m_Caps.MaxTextureWidth),
- std::min(std::max(m_ScreenSize.cy, m_nativeVideoSize.cy), (long)m_Caps.MaxTextureHeight));
+ std::min(std::max(m_ScreenSize.cy, m_nativeVideoSize.cy), (long)m_Caps.MaxTextureHeight));
hr = m_pD3DDev->CreateTexture(
m_TemporaryScreenSpaceTextureSize.cx,
m_TemporaryScreenSpaceTextureSize.cy,
diff --git a/src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.cpp
index 3eeef0130..248e4f863 100644
--- a/src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.cpp
@@ -96,7 +96,7 @@ HRESULT CDXRAllocatorPresenter::SetDevice(IDirect3DDevice9* pD3DDev)
HRESULT hr = S_OK;
if (!m_pSubPicQueue) {
- CAutoLock(this);
+ CAutoLock cAutoLock(this);
m_pSubPicQueue = r.subPicQueueSettings.nSize > 0
? (ISubPicQueue*)DEBUG_NEW CSubPicQueue(r.subPicQueueSettings, m_pAllocator, &hr)
: (ISubPicQueue*)DEBUG_NEW CSubPicQueueNoThread(r.subPicQueueSettings, m_pAllocator, &hr);
diff --git a/src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.cpp
index 4e0ce31ea..cdc4e7749 100644
--- a/src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.cpp
@@ -67,44 +67,44 @@ using namespace DSObjects;
CEVRAllocatorPresenter::CEVRAllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, CString& _Error)
: CDX9AllocatorPresenter(hWnd, bFullscreen, hr, true, _Error)
- , m_hDXVA2Lib(nullptr)
- , m_hEVRLib(nullptr)
- , m_hAVRTLib(nullptr)
- , m_nResetToken(0)
- , m_hThread(nullptr)
- , m_hGetMixerThread(nullptr)
- , m_hVSyncThread(nullptr)
- , m_hEvtFlush(nullptr)
- , m_hEvtQuit(nullptr)
- , m_bEvtQuit(0)
- , m_bEvtFlush(0)
, m_ModeratedTime(0)
, m_ModeratedTimeLast(-1)
, m_ModeratedClockLast(-1)
, m_ModeratedTimer(0)
, m_LastClockState(MFCLOCK_STATE_INVALID)
- , m_nRenderState(Shutdown)
+ , m_pOuterEVR(nullptr)
+ , m_dwVideoAspectRatioMode(MFVideoARMode_PreservePicture)
+ , m_dwVideoRenderPrefs((MFVideoRenderPrefs)0)
+ , m_BorderColor(RGB(0, 0, 0))
+ , m_hEvtQuit(nullptr)
+ , m_bEvtQuit(0)
+ , m_hEvtFlush(nullptr)
+ , m_bEvtFlush(0)
, m_fUseInternalTimer(false)
, m_LastSetOutputRange(-1)
, m_bPendingRenegotiate(false)
, m_bPendingMediaFinished(false)
- , m_bWaitingSample(false)
+ , m_hThread(nullptr)
+ , m_hGetMixerThread(nullptr)
+ , m_hVSyncThread(nullptr)
+ , m_nRenderState(Shutdown)
, m_pCurrentDisplaydSample(nullptr)
- , m_nStepCount(0)
- , m_dwVideoAspectRatioMode(MFVideoARMode_PreservePicture)
- , m_dwVideoRenderPrefs((MFVideoRenderPrefs)0)
- , m_BorderColor(RGB(0, 0, 0))
- , m_bSignaledStarvation(false)
- , m_StarvationClock(0)
- , m_pOuterEVR(nullptr)
+ , m_bWaitingSample(false)
+ , m_bLastSampleOffsetValid(false)
, m_LastScheduledSampleTime(-1)
+ , m_LastScheduledSampleTimeFP(-1)
, m_LastScheduledUncorrectedSampleTime(-1)
, m_MaxSampleDuration(0)
, m_LastSampleOffset(0)
, m_LastPredictedSync(0)
, m_VSyncOffsetHistoryPos(0)
- , m_bLastSampleOffsetValid(false)
- , m_LastScheduledSampleTimeFP(-1)
+ , m_nResetToken(0)
+ , m_nStepCount(0)
+ , m_bSignaledStarvation(false)
+ , m_StarvationClock(0)
+ , m_hDXVA2Lib(nullptr)
+ , m_hEVRLib(nullptr)
+ , m_hAVRTLib(nullptr)
, pfDXVA2CreateDirect3DDeviceManager9(nullptr)
, pfMFCreateDXSurfaceBuffer(nullptr)
, pfMFCreateVideoSampleFromSurface(nullptr)
@@ -1236,8 +1236,8 @@ STDMETHODIMP CEVRAllocatorPresenter::GetDeviceID(/* [out] */ __out IID* pDevice
// IMFGetService
STDMETHODIMP CEVRAllocatorPresenter::GetService(/* [in] */ __RPC__in REFGUID guidService,
- /* [in] */ __RPC__in REFIID riid,
- /* [iid_is][out] */ __RPC__deref_out_opt LPVOID* ppvObject)
+ /* [in] */ __RPC__in REFIID riid,
+ /* [iid_is][out] */ __RPC__deref_out_opt LPVOID* ppvObject)
{
if (guidService == MR_VIDEO_RENDER_SERVICE) {
return NonDelegatingQueryInterface(riid, ppvObject);
@@ -2550,7 +2550,7 @@ HRESULT CEVRAllocatorPresenter::GetFreeSample(IMFSample** ppSample)
HRESULT hr = S_OK;
if (m_FreeSamples.GetCount() > 1) { // <= Cannot use first free buffer (can be currently displayed)
- InterlockedIncrement(&m_nUsedBuffer);
+ m_nUsedBuffer++;
*ppSample = m_FreeSamples.RemoveHead().Detach();
} else {
hr = MF_E_SAMPLEALLOCATOR_EMPTY;
@@ -2578,7 +2578,8 @@ HRESULT CEVRAllocatorPresenter::GetScheduledSample(IMFSample** ppSample, int& _C
void CEVRAllocatorPresenter::MoveToFreeList(IMFSample* pSample, bool bTail)
{
CAutoLock lock(&m_SampleQueueLock);
- InterlockedDecrement(&m_nUsedBuffer);
+
+ m_nUsedBuffer--;
if (m_bPendingMediaFinished && m_nUsedBuffer == 0) {
m_bPendingMediaFinished = false;
m_pSink->Notify(EC_COMPLETE, 0, 0);
diff --git a/src/filters/renderer/VideoRenderers/IPinHook.cpp b/src/filters/renderer/VideoRenderers/IPinHook.cpp
index 1c44e264a..3dc19a98e 100644
--- a/src/filters/renderer/VideoRenderers/IPinHook.cpp
+++ b/src/filters/renderer/VideoRenderers/IPinHook.cpp
@@ -30,7 +30,7 @@
#include "AllocatorCommon.h"
#define DXVA_LOGFILE_A 0 // set to 1 for logging DXVA data to a file
-#define LOG_BITSTREAM 0 // set to 1 for logging DXVA bistream data to a file
+#define LOG_BITSTREAM 0 // set to 1 for logging DXVA bitstream data to a file
#define LOG_MATRIX 0 // set to 1 for logging DXVA matrix data to a file
#if defined(_DEBUG) && DXVA_LOGFILE_A
@@ -209,20 +209,29 @@ void HookWorkAroundNVIDIADriverBug(IBaseFilter* pBF)
{
DWORD flOldProtect = 0;
+ // Unhook previous VTable
if (g_pPinCVtbl) {
- VirtualProtect(g_pPinCVtbl, sizeof(IPinCVtbl), PAGE_WRITECOPY, &flOldProtect);
- UnhookWorkAroundNVIDIADriverBug();
- VirtualProtect(g_pPinCVtbl, sizeof(IPinCVtbl), flOldProtect, &flOldProtect);
+ if (VirtualProtect(g_pPinCVtbl, sizeof(IPinCVtbl), PAGE_WRITECOPY, &flOldProtect)) {
+ UnhookWorkAroundNVIDIADriverBug();
+ VirtualProtect(g_pPinCVtbl, sizeof(IPinCVtbl), flOldProtect, &flOldProtect);
+ g_pPinCVtbl = nullptr;
+ } else {
+ TRACE(_T("HookWorkAroundNVIDIADriverBug: Could not unhook previous VTable"));
+ ASSERT(FALSE);
+ }
}
if (CComPtr<IPin> pPin = GetFirstPin(pBF)) {
IPinC* pPinC = (IPinC*)(IPin*)pPin;
- VirtualProtect(pPinC->lpVtbl, sizeof(IPinCVtbl), PAGE_WRITECOPY, &flOldProtect);
- HookWorkAroundNVIDIADriverBug(pPinC);
- VirtualProtect(pPinC->lpVtbl, sizeof(IPinCVtbl), flOldProtect, &flOldProtect);
-
- g_pPinCVtbl = pPinC->lpVtbl;
+ if (VirtualProtect(pPinC->lpVtbl, sizeof(IPinCVtbl), PAGE_WRITECOPY, &flOldProtect)) {
+ HookWorkAroundNVIDIADriverBug(pPinC);
+ VirtualProtect(pPinC->lpVtbl, sizeof(IPinCVtbl), flOldProtect, &flOldProtect);
+ g_pPinCVtbl = pPinC->lpVtbl;
+ } else {
+ TRACE(_T("HookWorkAroundNVIDIADriverBug: Could not hook the VTable"));
+ ASSERT(FALSE);
+ }
}
}
@@ -230,25 +239,34 @@ void UnhookNewSegmentAndReceive()
{
DWORD flOldProtect = 0;
- // Casimir666 : unhook previous VTables
- if (g_pPinCVtbl && g_pMemInputPinCVtbl) {
- VirtualProtect(g_pPinCVtbl, sizeof(IPinCVtbl), PAGE_WRITECOPY, &flOldProtect);
- if (g_pPinCVtbl->NewSegment == NewSegmentMine) {
- g_pPinCVtbl->NewSegment = NewSegmentOrg;
+ // Unhook previous VTables
+ if (g_pPinCVtbl) {
+ if (VirtualProtect(g_pPinCVtbl, sizeof(IPinCVtbl), PAGE_WRITECOPY, &flOldProtect)) {
+ if (g_pPinCVtbl->NewSegment == NewSegmentMine) {
+ g_pPinCVtbl->NewSegment = NewSegmentOrg;
+ }
+ UnhookWorkAroundNVIDIADriverBug();
+ VirtualProtect(g_pPinCVtbl, sizeof(IPinCVtbl), flOldProtect, &flOldProtect);
+ g_pPinCVtbl = nullptr;
+ NewSegmentOrg = nullptr;
+ } else {
+ TRACE(_T("UnhookNewSegmentAndReceive: Could not unhook g_pPinCVtbl VTable"));
+ ASSERT(FALSE);
}
- UnhookWorkAroundNVIDIADriverBug();
- VirtualProtect(g_pPinCVtbl, sizeof(IPinCVtbl), flOldProtect, &flOldProtect);
+ }
- VirtualProtect(g_pMemInputPinCVtbl, sizeof(IMemInputPinCVtbl), PAGE_WRITECOPY, &flOldProtect);
- if (g_pMemInputPinCVtbl->Receive == ReceiveMine) {
- g_pMemInputPinCVtbl->Receive = ReceiveOrg;
+ if (g_pMemInputPinCVtbl) {
+ if (VirtualProtect(g_pMemInputPinCVtbl, sizeof(IMemInputPinCVtbl), PAGE_WRITECOPY, &flOldProtect)) {
+ if (g_pMemInputPinCVtbl->Receive == ReceiveMine) {
+ g_pMemInputPinCVtbl->Receive = ReceiveOrg;
+ }
+ VirtualProtect(g_pMemInputPinCVtbl, sizeof(IMemInputPinCVtbl), flOldProtect, &flOldProtect);
+ g_pMemInputPinCVtbl = nullptr;
+ ReceiveOrg = nullptr;
+ } else {
+ TRACE(_T("UnhookNewSegmentAndReceive: Could not unhook g_pMemInputPinCVtbl VTable"));
+ ASSERT(FALSE);
}
- VirtualProtect(g_pMemInputPinCVtbl, sizeof(IMemInputPinCVtbl), flOldProtect, &flOldProtect);
-
- g_pPinCVtbl = nullptr;
- g_pMemInputPinCVtbl = nullptr;
- NewSegmentOrg = nullptr;
- ReceiveOrg = nullptr;
}
}
@@ -260,29 +278,39 @@ bool HookNewSegmentAndReceive(IPinC* pPinC, IMemInputPinC* pMemInputPinC)
g_tSegmentStart = 0;
g_tSampleStart = 0;
- DWORD flOldProtect = 0;
UnhookNewSegmentAndReceive();
- // Casimir666 : change sizeof(IPinC) to sizeof(IPinCVtbl) to fix crash with EVR hack on Vista!
- VirtualProtect(pPinC->lpVtbl, sizeof(IPinCVtbl), PAGE_WRITECOPY, &flOldProtect);
- if (NewSegmentOrg == nullptr) {
- NewSegmentOrg = pPinC->lpVtbl->NewSegment;
- }
- pPinC->lpVtbl->NewSegment = NewSegmentMine; // Function sets global variable(s)
- HookWorkAroundNVIDIADriverBug(pPinC);
- VirtualProtect(pPinC->lpVtbl, sizeof(IPinCVtbl), flOldProtect, &flOldProtect);
-
- // Casimir666 : change sizeof(IMemInputPinC) to sizeof(IMemInputPinCVtbl) to fix crash with EVR hack on Vista!
- VirtualProtect(pMemInputPinC->lpVtbl, sizeof(IMemInputPinCVtbl), PAGE_WRITECOPY, &flOldProtect);
- if (ReceiveOrg == nullptr) {
- ReceiveOrg = pMemInputPinC->lpVtbl->Receive;
+ DWORD flOldProtect = 0;
+
+ if (!g_pPinCVtbl) {
+ if (VirtualProtect(pPinC->lpVtbl, sizeof(IPinCVtbl), PAGE_WRITECOPY, &flOldProtect)) {
+ if (NewSegmentOrg == nullptr) {
+ NewSegmentOrg = pPinC->lpVtbl->NewSegment;
+ }
+ pPinC->lpVtbl->NewSegment = NewSegmentMine; // Function sets global variable(s)
+ HookWorkAroundNVIDIADriverBug(pPinC);
+ VirtualProtect(pPinC->lpVtbl, sizeof(IPinCVtbl), flOldProtect, &flOldProtect);
+ g_pPinCVtbl = pPinC->lpVtbl;
+ } else {
+ TRACE(_T("HookNewSegmentAndReceive: Could not unhook g_pPinCVtbl VTable"));
+ ASSERT(FALSE);
+ }
}
- pMemInputPinC->lpVtbl->Receive = ReceiveMine; // Function sets global variable(s)
- VirtualProtect(pMemInputPinC->lpVtbl, sizeof(IMemInputPinCVtbl), flOldProtect, &flOldProtect);
- g_pPinCVtbl = pPinC->lpVtbl;
- g_pMemInputPinCVtbl = pMemInputPinC->lpVtbl;
+ if (!g_pMemInputPinCVtbl) {
+ if (VirtualProtect(pMemInputPinC->lpVtbl, sizeof(IMemInputPinCVtbl), PAGE_WRITECOPY, &flOldProtect)) {
+ if (ReceiveOrg == nullptr) {
+ ReceiveOrg = pMemInputPinC->lpVtbl->Receive;
+ }
+ pMemInputPinC->lpVtbl->Receive = ReceiveMine; // Function sets global variable(s)
+ VirtualProtect(pMemInputPinC->lpVtbl, sizeof(IMemInputPinCVtbl), flOldProtect, &flOldProtect);
+ g_pMemInputPinCVtbl = pMemInputPinC->lpVtbl;
+ } else {
+ TRACE(_T("HookNewSegmentAndReceive: Could not unhook g_pMemInputPinCVtbl VTable"));
+ ASSERT(FALSE);
+ }
+ }
return true;
}
@@ -292,7 +320,7 @@ bool HookNewSegmentAndReceive(IPinC* pPinC, IMemInputPinC* pMemInputPinC)
#ifdef _DEBUG
#define MAX_BUFFER_TYPE 15
-BYTE* g_ppBuffer[MAX_BUFFER_TYPE]; // Only used for debug logging
+BYTE* g_ppBuffer[MAX_BUFFER_TYPE]; // Only used for debug logging
static HRESULT(STDMETHODCALLTYPE* GetVideoAcceleratorGUIDsOrg)(IAMVideoAcceleratorC* This,/* [out][in] */ LPDWORD pdwNumGuidsSupported,/* [out][in] */ LPGUID pGuidsSupported) = nullptr;
static HRESULT(STDMETHODCALLTYPE* GetUncompFormatsSupportedOrg)(IAMVideoAcceleratorC* This,/* [in] */ const GUID* pGuid,/* [out][in] */ LPDWORD pdwNumFormatsSupported,/* [out][in] */ LPDDPIXELFORMAT pFormatsSupported) = nullptr;
@@ -463,25 +491,24 @@ static void LogDXVA_PicParams_H264(DXVA_PicParams_H264* pPic)
strRes.AppendFormat(_T("%d,"), pPic->slice_group_change_rate_minus1);
- //for (int i=0; i<810; i++)
- // strRes.AppendFormat(_T("%d,"), pPic->SliceGroupMap[i]);
- // strRes.AppendFormat(_T("%d,"), pPic->SliceGroupMap[810]);
+ //for (int i=0; i<810; i++) {
+ // strRes.AppendFormat(_T("%d,"), pPic->SliceGroupMap[i]);
+ //}
+ //strRes.AppendFormat(_T("%d"), pPic->SliceGroupMap[810]);
// SABOTAGE !!!
- //for (int i=0; i<16; i++)
- //{
- // pPic->FieldOrderCntList[i][0] = pPic->FieldOrderCntList[i][1] = 0;
- // pPic->RefFrameList[i].AssociatedFlag = 1;
- // pPic->RefFrameList[i].bPicEntry = 255;
- // pPic->RefFrameList[i].Index7Bits = 127;
+ //for (int i=0; i<16; i++) {
+ // pPic->FieldOrderCntList[i][0] = pPic->FieldOrderCntList[i][1] = 0;
+ // pPic->RefFrameList[i].AssociatedFlag = 1;
+ // pPic->RefFrameList[i].bPicEntry = 255;
+ // pPic->RefFrameList[i].Index7Bits = 127;
//}
// === Dump PicParams!
//static FILE* hPict = nullptr;
- //if (!hPict) hPict = fopen ("PicParam.bin", "wb");
- //if (hPict)
- //{
- // fwrite (pPic, sizeof (DXVA_PicParams_H264), 1, hPict);
+ //if (!hPict) { hPict = fopen ("PicParam.bin", "wb") };
+ //if (hPict) {
+ // fwrite (pPic, sizeof (DXVA_PicParams_H264), 1, hPict);
//}
LOG_TOFILE(LOG_FILE_PICTURE, strRes);
@@ -806,14 +833,12 @@ static HRESULT STDMETHODCALLTYPE GetCompBufferInfoMine(IAMVideoAcceleratorC* Thi
LOG(_T("hr = %08x"), hr);
- //if (pdwNumTypesCompBuffers)
- //{
- // LOG(_T("[out] *pdwNumTypesCompBuffers = %d"), *pdwNumTypesCompBuffers);
-
- // if (pamvaUncompDataInfo)
- // {
- // LOGUDI(_T("[out] pamvaUncompDataInfo"), pamvaUncompDataInfo, *pdwNumTypesCompBuffers);
- // }
+ //if (pdwNumTypesCompBuffers) {
+ // LOG(_T("[out] *pdwNumTypesCompBuffers = %d"), *pdwNumTypesCompBuffers);
+ //
+ // if (pamvaUncompDataInfo) {
+ // LOGUDI(_T("[out] pamvaUncompDataInfo"), pamvaUncompDataInfo, *pdwNumTypesCompBuffers);
+ // }
//}
return hr;
@@ -905,7 +930,7 @@ static HRESULT STDMETHODCALLTYPE ReleaseBufferMine(IAMVideoAcceleratorC* This, D
}
static HRESULT STDMETHODCALLTYPE ExecuteMine(IAMVideoAcceleratorC* This, DWORD dwFunction, LPVOID lpPrivateInputData, DWORD cbPrivateInputData,
- LPVOID lpPrivateOutputData, DWORD cbPrivateOutputData, DWORD dwNumBuffers, const AMVABUFFERINFO* pamvaBufferInfo)
+ LPVOID lpPrivateOutputData, DWORD cbPrivateOutputData, DWORD dwNumBuffers, const AMVABUFFERINFO* pamvaBufferInfo)
{
#ifdef _DEBUG
LOG(_T("\nExecute"));
@@ -1034,73 +1059,77 @@ void HookAMVideoAccelerator(IAMVideoAcceleratorC* pAMVideoAcceleratorC)
g_nDXVAVersion = 0;
DWORD flOldProtect = 0;
- VirtualProtect(pAMVideoAcceleratorC->lpVtbl, sizeof(IAMVideoAcceleratorC), PAGE_WRITECOPY, &flOldProtect);
+ if (VirtualProtect(pAMVideoAcceleratorC->lpVtbl, sizeof(IAMVideoAcceleratorC), PAGE_WRITECOPY, &flOldProtect)) {
#ifdef _DEBUG
- if (GetVideoAcceleratorGUIDsOrg == nullptr) {
- GetVideoAcceleratorGUIDsOrg = pAMVideoAcceleratorC->lpVtbl->GetVideoAcceleratorGUIDs;
- }
- if (GetUncompFormatsSupportedOrg == nullptr) {
- GetUncompFormatsSupportedOrg = pAMVideoAcceleratorC->lpVtbl->GetUncompFormatsSupported;
- }
- if (GetInternalMemInfoOrg == nullptr) {
- GetInternalMemInfoOrg = pAMVideoAcceleratorC->lpVtbl->GetInternalMemInfo;
- }
+ if (GetVideoAcceleratorGUIDsOrg == nullptr) {
+ GetVideoAcceleratorGUIDsOrg = pAMVideoAcceleratorC->lpVtbl->GetVideoAcceleratorGUIDs;
+ }
+ if (GetUncompFormatsSupportedOrg == nullptr) {
+ GetUncompFormatsSupportedOrg = pAMVideoAcceleratorC->lpVtbl->GetUncompFormatsSupported;
+ }
+ if (GetInternalMemInfoOrg == nullptr) {
+ GetInternalMemInfoOrg = pAMVideoAcceleratorC->lpVtbl->GetInternalMemInfo;
+ }
#endif
- if (GetCompBufferInfoOrg == nullptr) {
- GetCompBufferInfoOrg = pAMVideoAcceleratorC->lpVtbl->GetCompBufferInfo;
- }
+ if (GetCompBufferInfoOrg == nullptr) {
+ GetCompBufferInfoOrg = pAMVideoAcceleratorC->lpVtbl->GetCompBufferInfo;
+ }
#ifdef _DEBUG
- if (GetInternalCompBufferInfoOrg == nullptr) {
- GetInternalCompBufferInfoOrg = pAMVideoAcceleratorC->lpVtbl->GetInternalCompBufferInfo;
- }
- if (BeginFrameOrg == nullptr) {
- BeginFrameOrg = pAMVideoAcceleratorC->lpVtbl->BeginFrame;
- }
- if (EndFrameOrg == nullptr) {
- EndFrameOrg = pAMVideoAcceleratorC->lpVtbl->EndFrame;
- }
- if (GetBufferOrg == nullptr) {
- GetBufferOrg = pAMVideoAcceleratorC->lpVtbl->GetBuffer;
- }
- if (ReleaseBufferOrg == nullptr) {
- ReleaseBufferOrg = pAMVideoAcceleratorC->lpVtbl->ReleaseBuffer;
- }
- if (ExecuteOrg == nullptr) {
- ExecuteOrg = pAMVideoAcceleratorC->lpVtbl->Execute;
- }
- if (QueryRenderStatusOrg == nullptr) {
- QueryRenderStatusOrg = pAMVideoAcceleratorC->lpVtbl->QueryRenderStatus;
- }
- if (DisplayFrameOrg == nullptr) {
- DisplayFrameOrg = pAMVideoAcceleratorC->lpVtbl->DisplayFrame;
- }
+ if (GetInternalCompBufferInfoOrg == nullptr) {
+ GetInternalCompBufferInfoOrg = pAMVideoAcceleratorC->lpVtbl->GetInternalCompBufferInfo;
+ }
+ if (BeginFrameOrg == nullptr) {
+ BeginFrameOrg = pAMVideoAcceleratorC->lpVtbl->BeginFrame;
+ }
+ if (EndFrameOrg == nullptr) {
+ EndFrameOrg = pAMVideoAcceleratorC->lpVtbl->EndFrame;
+ }
+ if (GetBufferOrg == nullptr) {
+ GetBufferOrg = pAMVideoAcceleratorC->lpVtbl->GetBuffer;
+ }
+ if (ReleaseBufferOrg == nullptr) {
+ ReleaseBufferOrg = pAMVideoAcceleratorC->lpVtbl->ReleaseBuffer;
+ }
+ if (ExecuteOrg == nullptr) {
+ ExecuteOrg = pAMVideoAcceleratorC->lpVtbl->Execute;
+ }
+ if (QueryRenderStatusOrg == nullptr) {
+ QueryRenderStatusOrg = pAMVideoAcceleratorC->lpVtbl->QueryRenderStatus;
+ }
+ if (DisplayFrameOrg == nullptr) {
+ DisplayFrameOrg = pAMVideoAcceleratorC->lpVtbl->DisplayFrame;
+ }
- pAMVideoAcceleratorC->lpVtbl->GetVideoAcceleratorGUIDs = GetVideoAcceleratorGUIDsMine;
- pAMVideoAcceleratorC->lpVtbl->GetUncompFormatsSupported = GetUncompFormatsSupportedMine;
- pAMVideoAcceleratorC->lpVtbl->GetInternalMemInfo = GetInternalMemInfoMine;
+ pAMVideoAcceleratorC->lpVtbl->GetVideoAcceleratorGUIDs = GetVideoAcceleratorGUIDsMine;
+ pAMVideoAcceleratorC->lpVtbl->GetUncompFormatsSupported = GetUncompFormatsSupportedMine;
+ pAMVideoAcceleratorC->lpVtbl->GetInternalMemInfo = GetInternalMemInfoMine;
#endif
- pAMVideoAcceleratorC->lpVtbl->GetCompBufferInfo = GetCompBufferInfoMine; // Function sets global variable(s)
+ pAMVideoAcceleratorC->lpVtbl->GetCompBufferInfo = GetCompBufferInfoMine; // Function sets global variable(s)
#ifdef _DEBUG
- pAMVideoAcceleratorC->lpVtbl->GetInternalCompBufferInfo = GetInternalCompBufferInfoMine;
- pAMVideoAcceleratorC->lpVtbl->BeginFrame = BeginFrameMine;
- pAMVideoAcceleratorC->lpVtbl->EndFrame = EndFrameMine;
- pAMVideoAcceleratorC->lpVtbl->GetBuffer = GetBufferMine;
- pAMVideoAcceleratorC->lpVtbl->ReleaseBuffer = ReleaseBufferMine;
- pAMVideoAcceleratorC->lpVtbl->Execute = ExecuteMine;
- pAMVideoAcceleratorC->lpVtbl->QueryRenderStatus = QueryRenderStatusMine;
- pAMVideoAcceleratorC->lpVtbl->DisplayFrame = DisplayFrameMine;
-
- VirtualProtect(pAMVideoAcceleratorC->lpVtbl, sizeof(IAMVideoAcceleratorC), PAGE_EXECUTE, &flOldProtect);
-
-#if DXVA_LOGFILE_A
+ pAMVideoAcceleratorC->lpVtbl->GetInternalCompBufferInfo = GetInternalCompBufferInfoMine;
+ pAMVideoAcceleratorC->lpVtbl->BeginFrame = BeginFrameMine;
+ pAMVideoAcceleratorC->lpVtbl->EndFrame = EndFrameMine;
+ pAMVideoAcceleratorC->lpVtbl->GetBuffer = GetBufferMine;
+ pAMVideoAcceleratorC->lpVtbl->ReleaseBuffer = ReleaseBufferMine;
+ pAMVideoAcceleratorC->lpVtbl->Execute = ExecuteMine;
+ pAMVideoAcceleratorC->lpVtbl->QueryRenderStatus = QueryRenderStatusMine;
+ pAMVideoAcceleratorC->lpVtbl->DisplayFrame = DisplayFrameMine;
+#endif
+
+ VirtualProtect(pAMVideoAcceleratorC->lpVtbl, sizeof(IAMVideoAcceleratorC), PAGE_EXECUTE, &flOldProtect);
+ } else {
+ TRACE(_T("HookAMVideoAccelerator: Could not hook the VTable"));
+ ASSERT(FALSE);
+ }
+
+#if defined(_DEBUG) && DXVA_LOGFILE_A
::DeleteFile(LOG_FILE_DXVA);
::DeleteFile(LOG_FILE_PICTURE);
::DeleteFile(LOG_FILE_SLICELONG);
::DeleteFile(LOG_FILE_SLICESHORT);
::DeleteFile(LOG_FILE_BITSTREAM);
#endif
-#endif
}
@@ -1200,10 +1229,10 @@ public:
CString strBuffer;
LogDecodeBufferDesc(&pExecuteParams->pCompressedBuffers[i]);
- /*
- for (int j=0; j<4000 && j<pExecuteParams->pCompressedBuffers[i].DataSize; j++)
- strBuffer.AppendFormat (_T("%02x "), m_ppBuffer[pExecuteParams->pCompressedBuffers[i].CompressedBufferType][j]);
+ /*for (int j=0; j<4000 && j<pExecuteParams->pCompressedBuffers[i].DataSize; j++) {
+ strBuffer.AppendFormat (_T("%02x "), m_ppBuffer[pExecuteParams->pCompressedBuffers[i].CompressedBufferType][j]);
+ }
LOG (_T(" - Buffer type=%d, offset=%d, size=%d"),
pExecuteParams->pCompressedBuffers[i].CompressedBufferType,
pExecuteParams->pCompressedBuffers[i].DataOffset,
@@ -1350,11 +1379,11 @@ interface IDirectXVideoDecoderServiceC {
IDirectXVideoDecoderServiceCVtbl* g_pIDirectXVideoDecoderServiceCVtbl = nullptr;
static HRESULT(STDMETHODCALLTYPE* CreateVideoDecoderOrg)(IDirectXVideoDecoderServiceC* pThis,
- __in REFGUID Guid,
- __in const DXVA2_VideoDesc* pVideoDesc,
- __in const DXVA2_ConfigPictureDecode* pConfig,
- __in_ecount(NumRenderTargets)
- IDirect3DSurface9** ppDecoderRenderTargets, __in UINT NumRenderTargets, __deref_out IDirectXVideoDecoder** ppDecode) = nullptr;
+ __in REFGUID Guid,
+ __in const DXVA2_VideoDesc* pVideoDesc,
+ __in const DXVA2_ConfigPictureDecode* pConfig,
+ __in_ecount(NumRenderTargets)
+ IDirect3DSurface9** ppDecoderRenderTargets, __in UINT NumRenderTargets, __deref_out IDirectXVideoDecoder** ppDecode) = nullptr;
#ifdef _DEBUG
static HRESULT(STDMETHODCALLTYPE* GetDecoderDeviceGuidsOrg)(IDirectXVideoDecoderServiceC* pThis, __out UINT* pCount, __deref_out_ecount_opt(*pCount) GUID** pGuids) = nullptr;
static HRESULT(STDMETHODCALLTYPE* GetDecoderConfigurationsOrg)(IDirectXVideoDecoderServiceC* pThis, __in REFGUID Guid, __in const DXVA2_VideoDesc* pVideoDesc, __reserved void* pReserved, __out UINT* pCount, __deref_out_ecount_opt(*pCount) DXVA2_ConfigPictureDecode** ppConfigs) = nullptr;
@@ -1460,8 +1489,8 @@ static HRESULT STDMETHODCALLTYPE CreateVideoDecoderMine(
__in UINT NumRenderTargets,
__deref_out IDirectXVideoDecoder** ppDecode)
{
- // DebugBreak();
- // ((DXVA2_VideoDesc*)pVideoDesc)->Format = (D3DFORMAT)0x3231564E;
+ // DebugBreak();
+ // ((DXVA2_VideoDesc*)pVideoDesc)->Format = (D3DFORMAT)0x3231564E;
g_guidDXVADecoder = Guid;
g_nDXVAVersion = 2;
@@ -1504,8 +1533,8 @@ static HRESULT STDMETHODCALLTYPE CreateVideoDecoderMine(
#ifdef _DEBUG
static HRESULT STDMETHODCALLTYPE GetDecoderDeviceGuidsMine(IDirectXVideoDecoderServiceC* pThis,
- __out UINT* pCount,
- __deref_out_ecount_opt(*pCount) GUID** pGuids)
+ __out UINT* pCount,
+ __deref_out_ecount_opt(*pCount) GUID** pGuids)
{
HRESULT hr = GetDecoderDeviceGuidsOrg(pThis, pCount, pGuids);
LOG(_T("IDirectXVideoDecoderService::GetDecoderDeviceGuids hr = %08x\n"), hr);
@@ -1514,16 +1543,16 @@ static HRESULT STDMETHODCALLTYPE GetDecoderDeviceGuidsMine(IDirectXVideoDecoderS
}
static HRESULT STDMETHODCALLTYPE GetDecoderConfigurationsMine(IDirectXVideoDecoderServiceC* pThis,
- __in REFGUID Guid,
- __in const DXVA2_VideoDesc* pVideoDesc,
- __reserved void* pReserved,
- __out UINT* pCount,
- __deref_out_ecount_opt(*pCount) DXVA2_ConfigPictureDecode** ppConfigs)
+ __in REFGUID Guid,
+ __in const DXVA2_VideoDesc* pVideoDesc,
+ __reserved void* pReserved,
+ __out UINT* pCount,
+ __deref_out_ecount_opt(*pCount) DXVA2_ConfigPictureDecode** ppConfigs)
{
HRESULT hr = GetDecoderConfigurationsOrg(pThis, Guid, pVideoDesc, pReserved, pCount, ppConfigs);
// Force LongSlice decoding !
- // memcpy (&(*ppConfigs)[1], &(*ppConfigs)[0], sizeof(DXVA2_ConfigPictureDecode));
+ // memcpy (&(*ppConfigs)[1], &(*ppConfigs)[0], sizeof(DXVA2_ConfigPictureDecode));
return hr;
}
@@ -1535,29 +1564,35 @@ void HookDirectXVideoDecoderService(void* pIDirectXVideoDecoderService)
DWORD flOldProtect = 0;
- // Casimir666 : unhook previous VTables
+ // Unhook previous VTable
if (g_pIDirectXVideoDecoderServiceCVtbl) {
- VirtualProtect(g_pIDirectXVideoDecoderServiceCVtbl, sizeof(IDirectXVideoDecoderServiceCVtbl), PAGE_WRITECOPY, &flOldProtect);
- if (g_pIDirectXVideoDecoderServiceCVtbl->CreateVideoDecoder == CreateVideoDecoderMine) {
- g_pIDirectXVideoDecoderServiceCVtbl->CreateVideoDecoder = CreateVideoDecoderOrg;
- }
+ if (VirtualProtect(g_pIDirectXVideoDecoderServiceCVtbl, sizeof(IDirectXVideoDecoderServiceCVtbl), PAGE_WRITECOPY, &flOldProtect)) {
+ if (g_pIDirectXVideoDecoderServiceCVtbl->CreateVideoDecoder == CreateVideoDecoderMine) {
+ g_pIDirectXVideoDecoderServiceCVtbl->CreateVideoDecoder = CreateVideoDecoderOrg;
+ }
#ifdef _DEBUG
- if (g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderConfigurations == GetDecoderConfigurationsMine) {
- g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderConfigurations = GetDecoderConfigurationsOrg;
- }
+ if (g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderConfigurations == GetDecoderConfigurationsMine) {
+ g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderConfigurations = GetDecoderConfigurationsOrg;
+ }
- //if (g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderDeviceGuids == GetDecoderDeviceGuidsMine)
- // g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderDeviceGuids = GetDecoderDeviceGuidsOrg;
+ //if (g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderDeviceGuids == GetDecoderDeviceGuidsMine) {
+ // g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderDeviceGuids = GetDecoderDeviceGuidsOrg;
+ //}
#endif
- VirtualProtect(g_pIDirectXVideoDecoderServiceCVtbl, sizeof(IDirectXVideoDecoderServiceCVtbl), flOldProtect, &flOldProtect);
+ VirtualProtect(g_pIDirectXVideoDecoderServiceCVtbl, sizeof(IDirectXVideoDecoderServiceCVtbl), flOldProtect, &flOldProtect);
- g_pIDirectXVideoDecoderServiceCVtbl = nullptr;
- CreateVideoDecoderOrg = nullptr;
+ g_pIDirectXVideoDecoderServiceCVtbl = nullptr;
+ CreateVideoDecoderOrg = nullptr;
#ifdef _DEBUG
- GetDecoderConfigurationsOrg = nullptr;
+ GetDecoderConfigurationsOrg = nullptr;
#endif
+ } else {
+ TRACE(_T("HookDirectXVideoDecoderService: Could not unhook the VTable"));
+ ASSERT(FALSE);
+ }
+
g_guidDXVADecoder = GUID_NULL;
g_nDXVAVersion = 0;
}
@@ -1569,21 +1604,25 @@ void HookDirectXVideoDecoderService(void* pIDirectXVideoDecoderService)
#endif
if (!g_pIDirectXVideoDecoderServiceCVtbl && pIDirectXVideoDecoderService) {
- VirtualProtect(pIDirectXVideoDecoderServiceC->lpVtbl, sizeof(IDirectXVideoDecoderServiceCVtbl), PAGE_WRITECOPY, &flOldProtect);
+ if (VirtualProtect(pIDirectXVideoDecoderServiceC->lpVtbl, sizeof(IDirectXVideoDecoderServiceCVtbl), PAGE_WRITECOPY, &flOldProtect)) {
- CreateVideoDecoderOrg = pIDirectXVideoDecoderServiceC->lpVtbl->CreateVideoDecoder;
- pIDirectXVideoDecoderServiceC->lpVtbl->CreateVideoDecoder = CreateVideoDecoderMine;
+ CreateVideoDecoderOrg = pIDirectXVideoDecoderServiceC->lpVtbl->CreateVideoDecoder;
+ pIDirectXVideoDecoderServiceC->lpVtbl->CreateVideoDecoder = CreateVideoDecoderMine;
#ifdef _DEBUG
- GetDecoderConfigurationsOrg = pIDirectXVideoDecoderServiceC->lpVtbl->GetDecoderConfigurations;
- pIDirectXVideoDecoderServiceC->lpVtbl->GetDecoderConfigurations = GetDecoderConfigurationsMine;
+ GetDecoderConfigurationsOrg = pIDirectXVideoDecoderServiceC->lpVtbl->GetDecoderConfigurations;
+ pIDirectXVideoDecoderServiceC->lpVtbl->GetDecoderConfigurations = GetDecoderConfigurationsMine;
- //GetDecoderDeviceGuidsOrg = pIDirectXVideoDecoderServiceC->lpVtbl->GetDecoderDeviceGuids;
- //pIDirectXVideoDecoderServiceC->lpVtbl->GetDecoderDeviceGuids = GetDecoderDeviceGuidsMine;
+ //GetDecoderDeviceGuidsOrg = pIDirectXVideoDecoderServiceC->lpVtbl->GetDecoderDeviceGuids;
+ //pIDirectXVideoDecoderServiceC->lpVtbl->GetDecoderDeviceGuids = GetDecoderDeviceGuidsMine;
#endif
- VirtualProtect(pIDirectXVideoDecoderServiceC->lpVtbl, sizeof(IDirectXVideoDecoderServiceCVtbl), flOldProtect, &flOldProtect);
+ VirtualProtect(pIDirectXVideoDecoderServiceC->lpVtbl, sizeof(IDirectXVideoDecoderServiceCVtbl), flOldProtect, &flOldProtect);
- g_pIDirectXVideoDecoderServiceCVtbl = pIDirectXVideoDecoderServiceC->lpVtbl;
+ g_pIDirectXVideoDecoderServiceCVtbl = pIDirectXVideoDecoderServiceC->lpVtbl;
+ } else {
+ TRACE(_T("HookDirectXVideoDecoderService: Could not hook the VTable"));
+ ASSERT(FALSE);
+ }
}
}
diff --git a/src/filters/renderer/VideoRenderers/PixelShaderCompiler.cpp b/src/filters/renderer/VideoRenderers/PixelShaderCompiler.cpp
index cafe9d121..0a3caaf96 100644
--- a/src/filters/renderer/VideoRenderers/PixelShaderCompiler.cpp
+++ b/src/filters/renderer/VideoRenderers/PixelShaderCompiler.cpp
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
- * (C) 2006-2013 see Authors.txt
+ * (C) 2006-2014 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -26,9 +26,9 @@
CPixelShaderCompiler::CPixelShaderCompiler(IDirect3DDevice9* pD3DDev, bool fStaySilent)
: m_hDll(nullptr)
- , m_pD3DDev(pD3DDev)
, m_pD3DCompile(nullptr)
, m_pD3DDisassemble(nullptr)
+ , m_pD3DDev(pD3DDev)
{
m_hDll = LoadLibrary(D3DCOMPILER_DLL);
diff --git a/src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.cpp
index 612ef7e11..fe149a963 100644
--- a/src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.cpp
@@ -46,6 +46,8 @@ HRESULT CQT7AllocatorPresenter::AllocSurfaces()
{
CAutoLock cAutoLock(this);
+ CheckPointer(m_pDD, E_POINTER);
+
m_pVideoSurfaceOff = nullptr;
DDSURFACEDESC2 ddsd;
diff --git a/src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.cpp
index 3324f44a8..e39af0c01 100644
--- a/src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.cpp
@@ -43,6 +43,8 @@ STDMETHODIMP CQT9AllocatorPresenter::NonDelegatingQueryInterface(REFIID riid, vo
HRESULT CQT9AllocatorPresenter::AllocSurfaces()
{
+ CheckPointer(m_pD3DDev, E_POINTER);
+
HRESULT hr;
m_pVideoSurfaceOff = nullptr;
diff --git a/src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.cpp
index d568696a2..879103f88 100644
--- a/src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.cpp
@@ -48,6 +48,8 @@ HRESULT CRM7AllocatorPresenter::AllocSurfaces()
{
CAutoLock cAutoLock(this);
+ CheckPointer(m_pDD, E_POINTER);
+
m_pVideoSurfaceOff = nullptr;
m_pVideoSurfaceYUY2 = nullptr;
diff --git a/src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.cpp
index f7469f1e6..b3c1ead15 100644
--- a/src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.cpp
@@ -48,6 +48,8 @@ HRESULT CRM9AllocatorPresenter::AllocSurfaces()
CAutoLock cAutoLock(this);
CAutoLock cRenderLock(&m_RenderLock);
+ CheckPointer(m_pD3DDev, E_POINTER);
+
m_pVideoSurfaceOff = nullptr;
m_pVideoSurfaceYUY2 = nullptr;
diff --git a/src/filters/renderer/VideoRenderers/SyncRenderer.cpp b/src/filters/renderer/VideoRenderers/SyncRenderer.cpp
index f5bd188b4..cc25407b7 100644
--- a/src/filters/renderer/VideoRenderers/SyncRenderer.cpp
+++ b/src/filters/renderer/VideoRenderers/SyncRenderer.cpp
@@ -529,12 +529,9 @@ HRESULT CBaseAP::CreateDXDevice(CString& _Error)
}
}
if (!bTryToReset) {
- if (FAILED(hr = m_pD3DEx->CreateDeviceEx(m_CurrentAdapter, D3DDEVTYPE_HAL, m_FocusThread->GetFocusWindow(),
- D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED | D3DCREATE_ENABLE_PRESENTSTATS | D3DCREATE_NOWINDOWCHANGES,
- &pp, &DisplayMode, &m_pD3DDevEx))) {
- _Error += GetWindowsErrorMessage(hr, m_hD3D9);
- return hr;
- }
+ hr = m_pD3DEx->CreateDeviceEx(m_CurrentAdapter, D3DDEVTYPE_HAL, m_FocusThread->GetFocusWindow(),
+ D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED | D3DCREATE_ENABLE_PRESENTSTATS | D3DCREATE_NOWINDOWCHANGES,
+ &pp, &DisplayMode, &m_pD3DDevEx);
}
if (m_pD3DDevEx) {
@@ -549,12 +546,9 @@ HRESULT CBaseAP::CreateDXDevice(CString& _Error)
}
}
if (!bTryToReset) {
- if (FAILED(hr = m_pD3D->CreateDevice(m_CurrentAdapter, D3DDEVTYPE_HAL, m_FocusThread->GetFocusWindow(),
- D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED | D3DCREATE_NOWINDOWCHANGES,
- &pp, &m_pD3DDev))) {
- _Error += GetWindowsErrorMessage(hr, m_hD3D9);
- return hr;
- }
+ hr = m_pD3D->CreateDevice(m_CurrentAdapter, D3DDEVTYPE_HAL, m_FocusThread->GetFocusWindow(),
+ D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED | D3DCREATE_NOWINDOWCHANGES,
+ &pp, &m_pD3DDev);
}
TRACE(_T("Created full-screen device\n"));
if (m_pD3DDev) {
@@ -602,10 +596,6 @@ HRESULT CBaseAP::CreateDXDevice(CString& _Error)
hr = m_pD3DEx->CreateDeviceEx(m_CurrentAdapter, D3DDEVTYPE_HAL, m_hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED | D3DCREATE_ENABLE_PRESENTSTATS,
&pp, nullptr, &m_pD3DDevEx);
- if (FAILED(hr) && hr != D3DERR_DEVICELOST && hr != D3DERR_DEVICENOTRESET) {
- _Error += GetWindowsErrorMessage(hr, m_hD3D9);
- return hr;
- }
}
if (m_pD3DDevEx) {
@@ -621,29 +611,30 @@ HRESULT CBaseAP::CreateDXDevice(CString& _Error)
hr = m_pD3D->CreateDevice(m_CurrentAdapter, D3DDEVTYPE_HAL, m_hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED,
&pp, &m_pD3DDev);
- if (FAILED(hr) && hr != D3DERR_DEVICELOST && hr != D3DERR_DEVICENOTRESET) {
- _Error += GetWindowsErrorMessage(hr, m_hD3D9);
- return hr;
- }
}
TRACE(_T("Created windowed device\n"));
}
}
- while (hr == D3DERR_DEVICELOST) {
- TRACE(_T("D3DERR_DEVICELOST. Trying to Reset.\n"));
- hr = m_pD3DDev->TestCooperativeLevel();
- }
- if (hr == D3DERR_DEVICENOTRESET) {
- TRACE(_T("D3DERR_DEVICENOTRESET\n"));
- hr = m_pD3DDev->Reset(&pp);
+ if (m_pD3DDev) {
+ while (hr == D3DERR_DEVICELOST) {
+ TRACE(_T("D3DERR_DEVICELOST. Trying to Reset.\n"));
+ hr = m_pD3DDev->TestCooperativeLevel();
+ }
+ if (hr == D3DERR_DEVICENOTRESET) {
+ TRACE(_T("D3DERR_DEVICENOTRESET\n"));
+ hr = m_pD3DDev->Reset(&pp);
+ }
+
+ if (m_pD3DDevEx) {
+ m_pD3DDevEx->SetGPUThreadPriority(7);
+ }
}
- TRACE(_T("CreateDevice: %ld\n"), (LONG)hr);
- ASSERT(SUCCEEDED(hr));
+ if (FAILED(hr)) {
+ _Error.AppendFormat(_T("CreateDevice failed: %s\n"), GetWindowsErrorMessage(hr, m_hD3D9));
- if (m_pD3DDevEx) {
- m_pD3DDevEx->SetGPUThreadPriority(7);
+ return hr;
}
m_pPSC.Attach(DEBUG_NEW CPixelShaderCompiler(m_pD3DDev, true));
@@ -946,6 +937,8 @@ HRESULT CBaseAP::AllocSurfaces(D3DFORMAT Format)
CAutoLock cAutoLock(this);
CAutoLock cRenderLock(&m_allocatorLock);
+ CheckPointer(m_pD3DDev, E_POINTER);
+
const CRenderersSettings& r = GetRenderersSettings();
for (int i = 0; i < m_nDXSurface + 2; i++) {
@@ -2308,11 +2301,22 @@ STDMETHODIMP CBaseAP::GetDIB(BYTE* lpDib, DWORD* size)
{
CheckPointer(size, E_POINTER);
+ // Keep a reference so that we can safely work on the surface
+ // without having to lock everything
+ CComPtr<IDirect3DSurface9> pVideoSurface;
+ {
+ CAutoLock cAutoLock(this);
+ CheckPointer(m_pVideoSurface[m_nCurSurface], E_FAIL);
+ pVideoSurface = m_pVideoSurface[m_nCurSurface];
+ }
+
HRESULT hr;
D3DSURFACE_DESC desc;
ZeroMemory(&desc, sizeof(desc));
- m_pVideoSurface[m_nCurSurface]->GetDesc(&desc);
+ if (FAILED(hr = pVideoSurface->GetDesc(&desc))) {
+ return hr;
+ }
DWORD required = sizeof(BITMAPINFOHEADER) + (desc.Width * desc.Height * 32 >> 3);
if (!lpDib) {
@@ -2324,12 +2328,12 @@ STDMETHODIMP CBaseAP::GetDIB(BYTE* lpDib, DWORD* size)
}
*size = required;
- CComPtr<IDirect3DSurface9> pSurface = m_pVideoSurface[m_nCurSurface];
+ CComPtr<IDirect3DSurface9> pSurface = pVideoSurface;
D3DLOCKED_RECT r;
if (FAILED(hr = pSurface->LockRect(&r, nullptr, D3DLOCK_READONLY))) {
pSurface = nullptr;
if (FAILED(hr = m_pD3DDev->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pSurface, nullptr))
- || FAILED(hr = m_pD3DDev->GetRenderTargetData(m_pVideoSurface[m_nCurSurface], pSurface))
+ || FAILED(hr = m_pD3DDev->GetRenderTargetData(pVideoSurface, pSurface))
|| FAILED(hr = pSurface->LockRect(&r, nullptr, D3DLOCK_READONLY))) {
return hr;
}
@@ -2344,10 +2348,9 @@ STDMETHODIMP CBaseAP::GetDIB(BYTE* lpDib, DWORD* size)
bih->biPlanes = 1;
bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount >> 3;
- BitBltFromRGBToRGB(
- bih->biWidth, bih->biHeight,
- (BYTE*)(bih + 1), bih->biWidth * bih->biBitCount >> 3, bih->biBitCount,
- (BYTE*)r.pBits + r.Pitch * (desc.Height - 1), -(int)r.Pitch, 32);
+ BitBltFromRGBToRGB(bih->biWidth, bih->biHeight,
+ (BYTE*)(bih + 1), bih->biWidth * bih->biBitCount >> 3, bih->biBitCount,
+ (BYTE*)r.pBits + r.Pitch * (desc.Height - 1), -(int)r.Pitch, 32);
pSurface->UnlockRect();
@@ -3859,7 +3862,7 @@ HRESULT CSyncAP::GetFreeSample(IMFSample** ppSample)
HRESULT hr = S_OK;
if (m_FreeSamples.GetCount() > 1) { // Cannot use first free buffer (can be currently displayed)
- InterlockedIncrement(&m_nUsedBuffer);
+ m_nUsedBuffer++;
*ppSample = m_FreeSamples.RemoveHead().Detach();
} else {
hr = MF_E_SAMPLEALLOCATOR_EMPTY;
@@ -3887,7 +3890,8 @@ HRESULT CSyncAP::GetScheduledSample(IMFSample** ppSample, int& _Count)
void CSyncAP::MoveToFreeList(IMFSample* pSample, bool bTail)
{
CAutoLock lock(&m_SampleQueueLock);
- InterlockedDecrement(&m_nUsedBuffer);
+
+ m_nUsedBuffer--;
if (m_bPendingMediaFinished && m_nUsedBuffer == 0) {
m_bPendingMediaFinished = false;
m_pSink->Notify(EC_COMPLETE, 0, 0);
diff --git a/src/filters/renderer/VideoRenderers/VideoRenderers.vcxproj b/src/filters/renderer/VideoRenderers/VideoRenderers.vcxproj
index 017d4186e..c709d4564 100644
--- a/src/filters/renderer/VideoRenderers/VideoRenderers.vcxproj
+++ b/src/filters/renderer/VideoRenderers/VideoRenderers.vcxproj
@@ -66,8 +66,6 @@
<Import Project="..\..\..\common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
- <PropertyGroup>
- </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>..\..\..\..\include;..\..\..\thirdparty;$(DXSDK_DIR)Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
diff --git a/src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.cpp
index 899aeba1e..0124367e6 100644
--- a/src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.cpp
@@ -107,7 +107,7 @@ HRESULT CmadVRAllocatorPresenter::SetDevice(IDirect3DDevice9* pD3DDev)
HRESULT hr = S_OK;
if (!m_pSubPicQueue) {
- CAutoLock(this);
+ CAutoLock cAutoLock(this);
m_pSubPicQueue = r.subPicQueueSettings.nSize > 0
? (ISubPicQueue*)DEBUG_NEW CSubPicQueue(r.subPicQueueSettings, m_pAllocator, &hr)
: (ISubPicQueue*)DEBUG_NEW CSubPicQueueNoThread(r.subPicQueueSettings, m_pAllocator, &hr);