[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.
This commit is contained in:
Quantum 2021-02-26 23:35:20 -05:00 committed by Geoffrey McRae
parent 54da11a206
commit f2c0b8c0b4
5 changed files with 39 additions and 1 deletions

View File

@ -89,6 +89,7 @@ typedef void (*CapturePostPointerBuffer)(CapturePointer pointer);
typedef struct CaptureInterface typedef struct CaptureInterface
{ {
const char *shortName;
const char * (*getName )(); const char * (*getName )();
void (*initOptions )(); void (*initOptions )();

View File

@ -235,6 +235,7 @@ static CaptureResult xcb_getFrame(FrameBuffer * frame)
struct CaptureInterface Capture_XCB = struct CaptureInterface Capture_XCB =
{ {
.shortName = "XCB",
.getName = xcb_getName, .getName = xcb_getName,
.create = xcb_create, .create = xcb_create,
.init = xcb_init, .init = xcb_init,

View File

@ -1023,6 +1023,7 @@ static CaptureResult dxgi_releaseFrame(void)
struct CaptureInterface Capture_DXGI = struct CaptureInterface Capture_DXGI =
{ {
.shortName = "DXGI",
.getName = dxgi_getName, .getName = dxgi_getName,
.initOptions = dxgi_initOptions, .initOptions = dxgi_initOptions,
.create = dxgi_create, .create = dxgi_create,

View File

@ -427,6 +427,7 @@ static int pointerThread(void * unused)
struct CaptureInterface Capture_NVFBC = struct CaptureInterface Capture_NVFBC =
{ {
.shortName = "NvFBC",
.getName = nvfbc_getName, .getName = nvfbc_getName,
.initOptions = nvfbc_initOptions, .initOptions = nvfbc_initOptions,

View File

@ -97,6 +97,31 @@ struct app
static struct app 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) static bool lgmpTimer(void * opaque)
{ {
LGMP_STATUS status; LGMP_STATUS status;
@ -407,6 +432,8 @@ int app_main(int argc, char * argv[])
if (CaptureInterfaces[i]->initOptions) if (CaptureInterfaces[i]->initOptions)
CaptureInterfaces[i]->initOptions(); CaptureInterfaces[i]->initOptions();
option_register(options);
// try load values from a config file // try load values from a config file
const char * dataPath = os_getDataPath(); const char * dataPath = os_getDataPath();
if (!dataPath) if (!dataPath)
@ -528,10 +555,14 @@ int app_main(int argc, char * argv[])
} }
} }
const char * ifaceName = option_get_string("app", "capture");
CaptureInterface * iface = NULL; CaptureInterface * iface = NULL;
for(int i = 0; CaptureInterfaces[i]; ++i) for(int i = 0; CaptureInterfaces[i]; ++i)
{ {
iface = CaptureInterfaces[i]; iface = CaptureInterfaces[i];
if (*ifaceName && strcasecmp(ifaceName, iface->shortName))
continue;
DEBUG_INFO("Trying : %s", iface->getName()); DEBUG_INFO("Trying : %s", iface->getName());
if (!iface->create(captureGetPointerBuffer, capturePostPointerBuffer)) if (!iface->create(captureGetPointerBuffer, capturePostPointerBuffer))
@ -549,7 +580,10 @@ int app_main(int argc, char * argv[])
if (!iface) 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; exitcode = LG_HOST_EXIT_FAILED;
goto fail_lgmp; goto fail_lgmp;
} }