Keep/turn the display on during streaming
IDXGIDuplication::DuplicateOutput() may fail with 0x80070005 if the display is off and cause streaming to fail
This commit is contained in:
@@ -110,6 +110,15 @@ namespace platf::dxgi {
|
||||
CloseHandle(timer);
|
||||
});
|
||||
|
||||
// Keep the display awake during capture. If the display goes to sleep during
|
||||
// capture, best case is that capture stops until it powers back on. However,
|
||||
// worst case it will trigger us to reinit DD, waking the display back up in
|
||||
// a neverending cycle of waking and sleeping the display of an idle machine.
|
||||
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
|
||||
auto clear_display_required = util::fail_guard([]() {
|
||||
SetThreadExecutionState(ES_CONTINUOUS);
|
||||
});
|
||||
|
||||
while (true) {
|
||||
// This will return false if the HDR state changes or for any number of other
|
||||
// display or GPU changes. We should reinit to examine the updated state of
|
||||
@@ -342,6 +351,7 @@ namespace platf::dxgi {
|
||||
auto output_name = converter.from_bytes(display_name);
|
||||
|
||||
adapter_t::pointer adapter_p;
|
||||
for (int tries = 0; tries < 2; ++tries) {
|
||||
for (int x = 0; factory->EnumAdapters1(x, &adapter_p) != DXGI_ERROR_NOT_FOUND; ++x) {
|
||||
dxgi::adapter_t adapter_tmp { adapter_p };
|
||||
|
||||
@@ -384,6 +394,17 @@ namespace platf::dxgi {
|
||||
}
|
||||
}
|
||||
|
||||
if (output) {
|
||||
break;
|
||||
}
|
||||
|
||||
// If we made it here without finding an output, try to power on the display and retry.
|
||||
if (tries == 0) {
|
||||
SetThreadExecutionState(ES_DISPLAY_REQUIRED);
|
||||
Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
if (!output) {
|
||||
BOOST_LOG(error) << "Failed to locate an output device"sv;
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user