From f2c0b8c0b4705f2ae0fe300abfb8965f4e262082 Mon Sep 17 00:00:00 2001 From: Quantum Date: Fri, 26 Feb 2021 23:35:20 -0500 Subject: [PATCH] [host] allow user to select capture backend This commit introduces a new option, app:capture, which can be set to either DXGI or NvFBC to force the host application to use that backend. This is very useful for testing DXGI on Quadro cards, which would default to running with NvFBC. --- host/include/interface/capture.h | 1 + host/platform/Linux/capture/XCB/src/xcb.c | 1 + host/platform/Windows/capture/DXGI/src/dxgi.c | 1 + .../Windows/capture/NVFBC/src/nvfbc.c | 1 + host/src/app.c | 36 ++++++++++++++++++- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/host/include/interface/capture.h b/host/include/interface/capture.h index c207dde9..f5d107a9 100644 --- a/host/include/interface/capture.h +++ b/host/include/interface/capture.h @@ -89,6 +89,7 @@ typedef void (*CapturePostPointerBuffer)(CapturePointer pointer); typedef struct CaptureInterface { + const char *shortName; const char * (*getName )(); void (*initOptions )(); diff --git a/host/platform/Linux/capture/XCB/src/xcb.c b/host/platform/Linux/capture/XCB/src/xcb.c index 438859d0..89c28bb1 100644 --- a/host/platform/Linux/capture/XCB/src/xcb.c +++ b/host/platform/Linux/capture/XCB/src/xcb.c @@ -235,6 +235,7 @@ static CaptureResult xcb_getFrame(FrameBuffer * frame) struct CaptureInterface Capture_XCB = { + .shortName = "XCB", .getName = xcb_getName, .create = xcb_create, .init = xcb_init, diff --git a/host/platform/Windows/capture/DXGI/src/dxgi.c b/host/platform/Windows/capture/DXGI/src/dxgi.c index 0a4014e5..365a94aa 100644 --- a/host/platform/Windows/capture/DXGI/src/dxgi.c +++ b/host/platform/Windows/capture/DXGI/src/dxgi.c @@ -1023,6 +1023,7 @@ static CaptureResult dxgi_releaseFrame(void) struct CaptureInterface Capture_DXGI = { + .shortName = "DXGI", .getName = dxgi_getName, .initOptions = dxgi_initOptions, .create = dxgi_create, diff --git a/host/platform/Windows/capture/NVFBC/src/nvfbc.c b/host/platform/Windows/capture/NVFBC/src/nvfbc.c index 562bfdd3..3c0f0c01 100644 --- a/host/platform/Windows/capture/NVFBC/src/nvfbc.c +++ b/host/platform/Windows/capture/NVFBC/src/nvfbc.c @@ -427,6 +427,7 @@ static int pointerThread(void * unused) struct CaptureInterface Capture_NVFBC = { + .shortName = "NvFBC", .getName = nvfbc_getName, .initOptions = nvfbc_initOptions, diff --git a/host/src/app.c b/host/src/app.c index 534869b4..fdc752e7 100644 --- a/host/src/app.c +++ b/host/src/app.c @@ -97,6 +97,31 @@ struct app static struct app app; +static bool validateCaptureBackend(struct Option * opt, const char ** error) +{ + if (!*opt->value.x_string) + return true; + + for (int i = 0; CaptureInterfaces[i]; ++i) + if (!strcasecmp(opt->value.x_string, CaptureInterfaces[i]->shortName)) + return true; + + return false; +} + +static struct Option options[] = +{ + { + .module = "app", + .name = "capture", + .description = "Select the capture backend", + .type = OPTION_TYPE_STRING, + .value.x_string = "", + .validator = validateCaptureBackend, + }, + {0} +}; + static bool lgmpTimer(void * opaque) { LGMP_STATUS status; @@ -407,6 +432,8 @@ int app_main(int argc, char * argv[]) if (CaptureInterfaces[i]->initOptions) CaptureInterfaces[i]->initOptions(); + option_register(options); + // try load values from a config file const char * dataPath = os_getDataPath(); if (!dataPath) @@ -528,10 +555,14 @@ int app_main(int argc, char * argv[]) } } + const char * ifaceName = option_get_string("app", "capture"); CaptureInterface * iface = NULL; for(int i = 0; CaptureInterfaces[i]; ++i) { iface = CaptureInterfaces[i]; + if (*ifaceName && strcasecmp(ifaceName, iface->shortName)) + continue; + DEBUG_INFO("Trying : %s", iface->getName()); if (!iface->create(captureGetPointerBuffer, capturePostPointerBuffer)) @@ -549,7 +580,10 @@ int app_main(int argc, char * argv[]) if (!iface) { - DEBUG_ERROR("Failed to find a supported capture interface"); + if (*ifaceName) + DEBUG_ERROR("Specified capture interface not supported"); + else + DEBUG_ERROR("Failed to find a supported capture interface"); exitcode = LG_HOST_EXIT_FAILED; goto fail_lgmp; }