diff --git a/GraphicsCapture/GlobalCaptureStuff.h b/GraphicsCapture/GlobalCaptureStuff.h index 80467f78..1ec58110 100644 --- a/GraphicsCapture/GlobalCaptureStuff.h +++ b/GraphicsCapture/GlobalCaptureStuff.h @@ -36,6 +36,8 @@ #define INFO_MEMORY TEXT("Local\\OBSInfoMemory") #define TEXTURE_MEMORY TEXT("Local\\OBSTextureMemory") +#define OBS_KEEPALIVE_EVENT TEXT("OBS_KeepAlive") + #define CAPTURETYPE_MEMORY 1 #define CAPTURETYPE_SHAREDTEX 2 diff --git a/GraphicsCapture/GraphicsCaptureHook/D3D10.1Capture.cpp b/GraphicsCapture/GraphicsCaptureHook/D3D10.1Capture.cpp index 3a5fd694..73532d69 100644 --- a/GraphicsCapture/GraphicsCaptureHook/D3D10.1Capture.cpp +++ b/GraphicsCapture/GraphicsCaptureHook/D3D10.1Capture.cpp @@ -200,6 +200,22 @@ void DoD3D101Capture(IDXGISwapChain *swap) if(bHasTextures) { + //check keep alive state, dumb but effective + if(bCapturing) + { + LONGLONG curTime = OSGetTimeMicroseconds(); + if((curTime-keepAliveTime) > 3000000) + { + HANDLE hKeepAlive = OpenEvent(EVENT_ALL_ACCESS, FALSE, strKeepAlive.c_str()); + if(hKeepAlive) + CloseHandle(hKeepAlive); + else + ClearD3D101Data(); + + keepAliveTime = curTime; + } + } + LONGLONG frameTime; if(bCapturing) { diff --git a/GraphicsCapture/GraphicsCaptureHook/D3D10Capture.cpp b/GraphicsCapture/GraphicsCaptureHook/D3D10Capture.cpp index a7b691b1..35a32d63 100644 --- a/GraphicsCapture/GraphicsCaptureHook/D3D10Capture.cpp +++ b/GraphicsCapture/GraphicsCaptureHook/D3D10Capture.cpp @@ -201,6 +201,22 @@ void DoD3D10Capture(IDXGISwapChain *swap) if(bHasTextures) { + //check keep alive state, dumb but effective + if(bCapturing) + { + LONGLONG curTime = OSGetTimeMicroseconds(); + if((curTime-keepAliveTime) > 3000000) + { + HANDLE hKeepAlive = OpenEvent(EVENT_ALL_ACCESS, FALSE, strKeepAlive.c_str()); + if(hKeepAlive) + CloseHandle(hKeepAlive); + else + ClearD3D10Data(); + + keepAliveTime = curTime; + } + } + LONGLONG frameTime; if(bCapturing) { diff --git a/GraphicsCapture/GraphicsCaptureHook/D3D11Capture.cpp b/GraphicsCapture/GraphicsCaptureHook/D3D11Capture.cpp index 9eb52335..b6ea01f9 100644 --- a/GraphicsCapture/GraphicsCaptureHook/D3D11Capture.cpp +++ b/GraphicsCapture/GraphicsCaptureHook/D3D11Capture.cpp @@ -234,6 +234,22 @@ void DoD3D11Capture(IDXGISwapChain *swap) if(bHasTextures) { + //check keep alive state, dumb but effective + if(bCapturing) + { + LONGLONG curTime = OSGetTimeMicroseconds(); + if((curTime-keepAliveTime) > 3000000) + { + HANDLE hKeepAlive = OpenEvent(EVENT_ALL_ACCESS, FALSE, strKeepAlive.c_str()); + if(hKeepAlive) + CloseHandle(hKeepAlive); + else + ClearD3D11Data(); + + keepAliveTime = curTime; + } + } + LONGLONG frameTime; if(bCapturing) { diff --git a/GraphicsCapture/GraphicsCaptureHook/D3D9Capture.cpp b/GraphicsCapture/GraphicsCaptureHook/D3D9Capture.cpp index 804dc0f2..7e6dac0e 100644 --- a/GraphicsCapture/GraphicsCaptureHook/D3D9Capture.cpp +++ b/GraphicsCapture/GraphicsCaptureHook/D3D9Capture.cpp @@ -611,6 +611,22 @@ void DoD3D9DrawStuff(IDirect3DDevice9 *device) if(bHasTextures) { + //check keep alive state, dumb but effective + if(bCapturing) + { + LONGLONG curTime = OSGetTimeMicroseconds(); + if((curTime-keepAliveTime) > 3000000) + { + HANDLE hKeepAlive = OpenEvent(EVENT_ALL_ACCESS, FALSE, strKeepAlive.c_str()); + if(hKeepAlive) + CloseHandle(hKeepAlive); + else + ClearD3D9Data(); + + keepAliveTime = curTime; + } + } + LONGLONG frameTime; if(bCapturing) { diff --git a/GraphicsCapture/GraphicsCaptureHook/GraphicsCaptureHook.cpp b/GraphicsCapture/GraphicsCaptureHook/GraphicsCaptureHook.cpp index 71b540cd..b4cae7d3 100644 --- a/GraphicsCapture/GraphicsCaptureHook/GraphicsCaptureHook.cpp +++ b/GraphicsCapture/GraphicsCaptureHook/GraphicsCaptureHook.cpp @@ -42,12 +42,17 @@ LARGE_INTEGER clockFreq, startTime; LONGLONG prevElapsedTime; DWORD startTick; +wstring strKeepAlive; +LONGLONG keepAliveTime = 0; + + void WINAPI OSInitializeTimer() { QueryPerformanceFrequency(&clockFreq); QueryPerformanceCounter(&startTime); startTick = GetTickCount(); prevElapsedTime = 0; + keepAliveTime = 0; } LONGLONG WINAPI OSGetTimeMicroseconds() @@ -262,6 +267,10 @@ DWORD WINAPI CaptureThread(HANDLE hDllMainThread) if(!logOutput.is_open()) logOutput.open(lpLogPath, ios_base::in | ios_base::out | ios_base::trunc); + wstringstream str; + str << OBS_KEEPALIVE_EVENT << int(GetCurrentProcessId()); + strKeepAlive = str.str(); + WNDCLASS wc; ZeroMemory(&wc, sizeof(wc)); wc.hInstance = hinstMain; diff --git a/GraphicsCapture/GraphicsCaptureHook/GraphicsCaptureHook.h b/GraphicsCapture/GraphicsCaptureHook/GraphicsCaptureHook.h index d9f03baa..acf7f4b5 100644 --- a/GraphicsCapture/GraphicsCaptureHook/GraphicsCaptureHook.h +++ b/GraphicsCapture/GraphicsCaptureHook/GraphicsCaptureHook.h @@ -225,6 +225,9 @@ extern CaptureInfo *infoMem; extern fstream logOutput; +extern wstring strKeepAlive; +extern LONGLONG keepAliveTime; + void WINAPI OSInitializeTimer(); LONGLONG WINAPI OSGetTimeMicroseconds(); diff --git a/GraphicsCapture/GraphicsCaptureSource.cpp b/GraphicsCapture/GraphicsCaptureSource.cpp index d82a5946..0f39dc06 100644 --- a/GraphicsCapture/GraphicsCaptureSource.cpp +++ b/GraphicsCapture/GraphicsCaptureSource.cpp @@ -241,6 +241,8 @@ void GraphicsCaptureSource::EndCapture() capture = NULL; } + if(hOBSIsAlive) + CloseHandle(hOBSIsAlive); if(hSignalRestart) CloseHandle(hSignalRestart); if(hSignalEnd) @@ -250,7 +252,7 @@ void GraphicsCaptureSource::EndCapture() if(hSignalExit) CloseHandle(hSignalExit); - hSignalRestart = hSignalEnd = hSignalReady = hSignalExit = NULL; + hSignalRestart = hSignalEnd = hSignalReady = hSignalExit = hOBSIsAlive = NULL; bErrorAcquiring = false; @@ -344,6 +346,13 @@ void GraphicsCaptureSource::AttemptCapture() HANDLE hProcess = (*pOpenProcess)(PROCESS_ALL_ACCESS, FALSE, targetProcessID); if(hProcess) { + //------------------------------------------- + // load keepalive event + + hOBSIsAlive = CreateEvent(NULL, FALSE, FALSE, String() << OBS_KEEPALIVE_EVENT << int(targetProcessID)); + + //------------------------------------------- + hwndCapture = hwndTarget; hSignalRestart = OpenEvent(EVENT_ALL_ACCESS, FALSE, String() << RESTART_CAPTURE_EVENT << int(targetProcessID)); @@ -456,6 +465,12 @@ void GraphicsCaptureSource::AttemptCapture() CloseHandle(hProcess); hProcess = NULL; + + if (!bCapturing) + { + CloseHandle(hOBSIsAlive); + hOBSIsAlive = NULL; + } } else {