From 88c2e55acf36a7d84f8445d12ecc0debe5b910fc Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 4 Mar 2019 17:55:45 +1100 Subject: [PATCH] [c-host] change getFrame/Pointer to return a real status --- c-host/app.c | 14 +++++++++++--- c-host/capture/interface.h | 11 +++++------ c-host/windows/capture/dxgi.c | 30 +++++++++++++++++++++++------- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/c-host/app.c b/c-host/app.c index 50d75cd3..0bee72a0 100644 --- a/c-host/app.c +++ b/c-host/app.c @@ -86,12 +86,20 @@ static int frameThread(void * opaque) while(app.running) { - CaptureFrame frame; + CaptureResult result; + CaptureFrame frame; + frame.data = app.frame[frameIndex]; - if (!app.iface->getFrame(&frame)) + result = app.iface->getFrame(&frame); + if (result == CAPTURE_RESULT_REINIT) + { + app.reinit = true; + break; + } + + if (result == CAPTURE_RESULT_ERROR) { DEBUG_ERROR("Failed to get the frame"); - app.reinit = true; break; } diff --git a/c-host/capture/interface.h b/c-host/capture/interface.h index 4cc9d174..920ecf45 100644 --- a/c-host/capture/interface.h +++ b/c-host/capture/interface.h @@ -24,8 +24,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA typedef enum CaptureResult { - CAPTURE_RESULT_OK, - CAPTURE_RESULT_REINIT, + CAPTURE_RESULT_OK , + CAPTURE_RESULT_REINIT , CAPTURE_RESULT_TIMEOUT, CAPTURE_RESULT_ERROR } @@ -78,9 +78,8 @@ typedef struct CaptureInterface void (*free )(); unsigned int (*getMaxFrameSize)(); - CaptureResult (*capture)(); - - bool (*getFrame )(CaptureFrame * frame ); - bool (*getPointer)(CapturePointer * pointer); + CaptureResult (*capture )(); + CaptureResult (*getFrame )(CaptureFrame * frame ); + CaptureResult (*getPointer)(CapturePointer * pointer); } CaptureInterface; \ No newline at end of file diff --git a/c-host/windows/capture/dxgi.c b/c-host/windows/capture/dxgi.c index 14870710..683f1c49 100644 --- a/c-host/windows/capture/dxgi.c +++ b/c-host/windows/capture/dxgi.c @@ -579,22 +579,22 @@ static CaptureResult dxgi_capture(bool * hasFrameUpdate, bool * hasPointerUpdate return result; } -static bool dxgi_getFrame(CaptureFrame * frame) +static CaptureResult dxgi_getFrame(CaptureFrame * frame) { assert(this); assert(this->initialized); if (this->reinit) - return true; + return CAPTURE_RESULT_REINIT; if (!os_waitEvent(this->frameEvent, TIMEOUT_INFINITE)) { DEBUG_ERROR("Failed to wait on the frame event"); - return false; + return CAPTURE_RESULT_ERROR; } if (this->reinit) - return true; + return CAPTURE_RESULT_REINIT; Texture * tex = &this->texture[this->texRIndex]; @@ -610,12 +610,28 @@ static bool dxgi_getFrame(CaptureFrame * frame) if (++this->texRIndex == MAX_TEXTURES) this->texRIndex = 0; - return true; + return CAPTURE_RESULT_OK; } -static bool dxgi_getPointer(CapturePointer * pointer) +static CaptureResult dxgi_getPointer(CapturePointer * pointer) { - return false; + assert(this); + assert(this->initialized); + + if (this->reinit) + return CAPTURE_RESULT_REINIT; + + if (!os_waitEvent(this->pointerEvent, TIMEOUT_INFINITE)) + { + DEBUG_ERROR("Failed to wait on the pointer event"); + return CAPTURE_RESULT_ERROR; + } + + if (this->reinit) + return CAPTURE_RESULT_REINIT; + + + return CAPTURE_RESULT_OK; } static CaptureResult dxgi_releaseFrame()