From 0eafa7de5d47fcee1b919f16ed8a18747a062a4a Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 11 Jan 2020 21:51:59 +1100 Subject: [PATCH] [c-host] update NvFBC to use new capture interface --- VERSION | 2 +- .../Windows/capture/NVFBC/src/nvfbc.c | 99 +++++++++++++------ 2 files changed, 69 insertions(+), 32 deletions(-) diff --git a/VERSION b/VERSION index 2de33bcb..8b2d8e44 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -B1-80-g5e915dd1ff+1 \ No newline at end of file +B1-81-ge554635e48+1 \ No newline at end of file diff --git a/c-host/platform/Windows/capture/NVFBC/src/nvfbc.c b/c-host/platform/Windows/capture/NVFBC/src/nvfbc.c index a63adccc..9bf2e963 100644 --- a/c-host/platform/Windows/capture/NVFBC/src/nvfbc.c +++ b/c-host/platform/Windows/capture/NVFBC/src/nvfbc.c @@ -24,6 +24,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include "common/option.h" #include "common/framebuffer.h" #include "common/event.h" +#include "common/thread.h" #include #include #include @@ -36,9 +37,11 @@ struct iface bool stop; NvFBCHandle nvfbc; - bool seperateCursor; - void * pointerShape; - unsigned int pointerSize; + bool seperateCursor; + CaptureGetPointerBuffer getPointerBufferFn; + CapturePostPointerBuffer postPointerBufferFn; + LGThread * pointerThread; + unsigned int maxWidth, maxHeight; unsigned int width , height; @@ -56,6 +59,7 @@ struct iface static struct iface * this = NULL; static void nvfbc_free(); +static int pointerThread(void * unused); static void getDesktopSize(unsigned int * width, unsigned int * height) { @@ -148,11 +152,13 @@ static bool nvfbc_create() return true; } -static bool nvfbc_init(void * pointerShape, const unsigned int pointerSize) +static bool nvfbc_init( + CaptureGetPointerBuffer getPointerBufferFn, + CapturePostPointerBuffer postPointerBufferFn) { - this->stop = false; - this->pointerShape = pointerShape; - this->pointerSize = pointerSize; + this->stop = false; + this->getPointerBufferFn = getPointerBufferFn; + this->postPointerBufferFn = postPointerBufferFn; getDesktopSize(&this->width, &this->height); lgResetEvent(this->frameEvent); @@ -183,6 +189,13 @@ static bool nvfbc_init(void * pointerShape, const unsigned int pointerSize) DEBUG_INFO("Cursor mode : %s", this->seperateCursor ? "decoupled" : "integrated"); Sleep(100); + + if (!lgCreateThread("NvFBCPointer", pointerThread, NULL, &this->pointerThread)) + { + DEBUG_ERROR("Failed to create the NvFBCPointer thread"); + return false; + } + return true; } @@ -191,6 +204,12 @@ static void nvfbc_stop() this->stop = true; lgSignalEvent(this->cursorEvents[0]); lgSignalEvent(this->frameEvent); + + if (this->pointerThread) + { + lgJoinThread(this->pointerThread, NULL); + this->pointerThread = NULL; + } } static bool nvfbc_deinit() @@ -280,32 +299,51 @@ static CaptureResult nvfbc_getFrame(FrameBuffer frame) return CAPTURE_RESULT_OK; } -static CaptureResult nvfbc_getPointer(CapturePointer * pointer) +static int pointerThread(void * unused) { - LGEvent * events[2]; - memcpy(&events, &this->cursorEvents, sizeof(LGEvent *) * 2); - if (!lgWaitEvents(events, this->seperateCursor ? 2 : 1, false, 1000)) - return CAPTURE_RESULT_TIMEOUT; - - if (this->stop) - return CAPTURE_RESULT_REINIT; - - CaptureResult result; - pointer->shapeUpdate = false; - if (this->seperateCursor && events[1]) + while(!this->stop) { - result = NvFBCToSysGetCursor(this->nvfbc, pointer, this->pointerShape, this->pointerSize); - this->mouseVisible = pointer->visible; - this->mouseHotX = pointer->x; - this->mouseHotY = pointer->y; - if (result != CAPTURE_RESULT_OK) - return result; + LGEvent * events[2]; + memcpy(&events, &this->cursorEvents, sizeof(LGEvent *) * 2); + if (!lgWaitEvents(events, this->seperateCursor ? 2 : 1, false, 1000)) + continue; + + if (this->stop) + break; + + CaptureResult result; + CapturePointer pointer = { 0 }; + pointer.shapeUpdate = false; + if (this->seperateCursor && events[1]) + { + void * data; + uint32_t size; + if (!this->getPointerBufferFn(&data, &size)) + { + DEBUG_WARN("failed to get a pointer buffer"); + continue; + } + + result = NvFBCToSysGetCursor(this->nvfbc, &pointer, data, size); + if (result != CAPTURE_RESULT_OK) + { + DEBUG_WARN("NvFBCToSysGetCursor failed"); + continue; + } + + this->mouseVisible = pointer.visible; + this->mouseHotX = pointer.x; + this->mouseHotY = pointer.y; + } + + pointer.visible = this->mouseVisible; + pointer.x = this->mouseX - this->mouseHotX; + pointer.y = this->mouseY - this->mouseHotY; + + this->postPointerBufferFn(pointer); } - pointer->visible = this->mouseVisible; - pointer->x = this->mouseX - this->mouseHotX; - pointer->y = this->mouseY - this->mouseHotY; - return CAPTURE_RESULT_OK; + return 0; } struct CaptureInterface Capture_NVFBC = @@ -321,6 +359,5 @@ struct CaptureInterface Capture_NVFBC = .getMaxFrameSize = nvfbc_getMaxFrameSize, .capture = nvfbc_capture, .waitFrame = nvfbc_waitFrame, - .getFrame = nvfbc_getFrame, - .getPointer = nvfbc_getPointer + .getFrame = nvfbc_getFrame }; \ No newline at end of file