[c-host] update NvFBC to use new capture interface

This commit is contained in:
Geoffrey McRae 2020-01-11 21:51:59 +11:00
parent e554635e48
commit 0eafa7de5d
2 changed files with 69 additions and 32 deletions

View File

@ -1 +1 @@
B1-80-g5e915dd1ff+1
B1-81-ge554635e48+1

View File

@ -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 <assert.h>
#include <stdlib.h>
#include <windows.h>
@ -37,8 +38,10 @@ struct iface
NvFBCHandle nvfbc;
bool seperateCursor;
void * pointerShape;
unsigned int pointerSize;
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->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)
{
while(!this->stop)
{
LGEvent * events[2];
memcpy(&events, &this->cursorEvents, sizeof(LGEvent *) * 2);
if (!lgWaitEvents(events, this->seperateCursor ? 2 : 1, false, 1000))
return CAPTURE_RESULT_TIMEOUT;
continue;
if (this->stop)
return CAPTURE_RESULT_REINIT;
break;
CaptureResult result;
pointer->shapeUpdate = false;
CapturePointer pointer = { 0 };
pointer.shapeUpdate = false;
if (this->seperateCursor && events[1])
{
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;
void * data;
uint32_t size;
if (!this->getPointerBufferFn(&data, &size))
{
DEBUG_WARN("failed to get a pointer buffer");
continue;
}
pointer->visible = this->mouseVisible;
pointer->x = this->mouseX - this->mouseHotX;
pointer->y = this->mouseY - this->mouseHotY;
return CAPTURE_RESULT_OK;
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);
}
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
};