diff --git a/host/Capture/DXGI.cpp b/host/Capture/DXGI.cpp index c8877b6f..5e67aea8 100644 --- a/host/Capture/DXGI.cpp +++ b/host/Capture/DXGI.cpp @@ -72,6 +72,16 @@ DXGI::~DXGI() { } +bool DXGI::CanInitialize() +{ + HDESK desktop = OpenInputDesktop(0, TRUE, GENERIC_READ); + if (!desktop) + return false; + + CloseDesktop(desktop); + return true; +} + bool DXGI::Initialize(CaptureOptions * options) { if (m_initialized) @@ -580,20 +590,6 @@ STDMETHODIMP Capture::DXGI::Invoke(IMFAsyncResult * pAsyncResult) return status; } -void DXGI::WaitForDesktop() -{ - HDESK desktop; - do - { - desktop = OpenInputDesktop(0, TRUE, GENERIC_READ); - if (desktop) - break; - Sleep(100); - } - while (!desktop); - CloseDesktop(desktop); -} - GrabStatus Capture::DXGI::GrabFrameTexture(struct FrameInfo & frame, struct CursorInfo & cursor, ID3D11Texture2DPtr & texture, bool & timeout) { if (!m_initialized) @@ -705,7 +701,6 @@ GrabStatus Capture::DXGI::GrabFrameTexture(struct FrameInfo & frame, struct Curs // desktop switch, mode change, switch DWM on or off or Secure Desktop case DXGI_ERROR_ACCESS_LOST: case WAIT_ABANDONED: - WaitForDesktop(); return GRAB_STATUS_REINIT; default: @@ -752,7 +747,6 @@ GrabStatus Capture::DXGI::ReleaseFrame() case WAIT_ABANDONED: case DXGI_ERROR_ACCESS_LOST: - WaitForDesktop(); return GRAB_STATUS_REINIT; } diff --git a/host/Capture/DXGI.h b/host/Capture/DXGI.h index 146172ae..d9f61bc2 100644 --- a/host/Capture/DXGI.h +++ b/host/Capture/DXGI.h @@ -62,6 +62,7 @@ namespace Capture const char * GetName() { return "DXGI"; } + bool CanInitialize(); bool Initialize(CaptureOptions * options); void DeInitialize(); @@ -120,9 +121,6 @@ namespace Capture GrabStatus GrabFrameRaw (struct FrameInfo & frame, struct CursorInfo & cursor); GrabStatus GrabFrameH264 (struct FrameInfo & frame, struct CursorInfo & cursor); - void WaitForDesktop(); - - long m_cRef; CaptureOptions * m_options; diff --git a/host/ICapture.h b/host/ICapture.h index 465577e6..97813135 100644 --- a/host/ICapture.h +++ b/host/ICapture.h @@ -64,6 +64,7 @@ class ICapture public: virtual const char * GetName() = 0; + virtual bool CanInitialize() = 0; virtual bool Initialize(CaptureOptions * options) = 0; virtual void DeInitialize() = 0; virtual bool ReInitialize() = 0; diff --git a/host/Service.cpp b/host/Service.cpp index a53284c3..0c9098ad 100644 --- a/host/Service.cpp +++ b/host/Service.cpp @@ -238,15 +238,18 @@ bool Service::Process() case GRAB_STATUS_REINIT: DEBUG_INFO("ReInitialize Requested"); + + *flags |= KVMFR_HEADER_FLAG_PAUSED; if(WTSGetActiveConsoleSessionId() != m_consoleSessionID) { DEBUG_INFO("User switch detected, waiting to regain control"); - *flags |= KVMFR_HEADER_FLAG_PAUSED; while (WTSGetActiveConsoleSessionId() != m_consoleSessionID) Sleep(100); - *flags &= ~KVMFR_HEADER_FLAG_PAUSED; } + while (!m_capture->CanInitialize()) + Sleep(100); + if (!m_capture->ReInitialize()) { DEBUG_ERROR("ReInitialize Failed"); @@ -259,6 +262,8 @@ bool Service::Process() return false; } + *flags &= ~KVMFR_HEADER_FLAG_PAUSED; + // re-init request should not count towards a failure to capture --i; continue;