Skip to content

Commit

Permalink
[host] d12: allow specifying adapter and output to capture
Browse files Browse the repository at this point in the history
  • Loading branch information
gnif committed Feb 22, 2024
1 parent b131398 commit 055d552
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions host/platform/Windows/capture/D12/d12.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ static void d12_initOptions(void)
{
struct Option options[] =
{
{
.module = "d12",
.name = "adapter",
.description = "The name of the adapter to capture",
.type = OPTION_TYPE_STRING,
.value.x_string = NULL
},
{
.module = "d12",
.name = "output",
.description = "The name of the adapter's output to capture",
.type = OPTION_TYPE_STRING,
.value.x_string = NULL
},
{
.module = "d12",
.name = "allowRGB24",
Expand Down Expand Up @@ -557,6 +571,23 @@ static bool d12_enumerateDevices(
DXGI_ADAPTER_DESC1 adapterDesc;
DXGI_OUTPUT_DESC outputDesc;

const char * _optAdapter = option_get_string("d12", "adapter");
const char * _optOutput = option_get_string("d12", "output" );

wchar_t * optAdapter = NULL;
wchar_t * optOutput = NULL;
if (_optAdapter)
{
optAdapter = malloc((strlen(_optAdapter) + 1) * 2);
mbstowcs(optAdapter, _optAdapter, strlen(_optAdapter));
}

if (_optOutput)
{
optOutput = malloc((strlen(_optOutput) + 1) * 2);
mbstowcs(optOutput, _optOutput, strlen(_optOutput));
}

for(
int i = 0;
IDXGIFactory2_EnumAdapters1(*factory, i, adapter)
Expand Down Expand Up @@ -595,15 +626,33 @@ static bool d12_enumerateDevices(
if (skip)
continue;

// FIXME: Allow specifying the specific adapter
if (optAdapter)
{
if (wcsstr(adapterDesc.Description, optAdapter) == NULL)
{
DEBUG_INFO("Not using adapter: %ls", adapterDesc.Description);
continue;
}
DEBUG_INFO("Adapter matched, trying: %ls", adapterDesc.Description);
}

for(
int n = 0;
IDXGIAdapter1_EnumOutputs(*adapter, n, output) != DXGI_ERROR_NOT_FOUND;
++n, comRef_release(output))
{
IDXGIOutput_GetDesc(*output, &outputDesc);
// FIXME: Allow specifying the specific output

if (optOutput)
{
if (wcsstr(outputDesc.DeviceName, optOutput) == NULL)
{
DEBUG_INFO("Not using adapter output: %ls", outputDesc.DeviceName);
continue;
}

DEBUG_INFO("Adapter output matched, trying: %ls", outputDesc.DeviceName);
}

if (outputDesc.AttachedToDesktop)
break;
Expand All @@ -613,6 +662,9 @@ static bool d12_enumerateDevices(
break;
}

free(optAdapter);
free(optOutput );

if (!*output)
{
DEBUG_ERROR("Failed to locate a valid output device");
Expand Down

0 comments on commit 055d552

Please sign in to comment.