obs-amf-test: Add 2.5 second timeout for AMF test process

If the test process freezes for whatever reason, OBS would block
indefinitely on reading the pipe. This commit adds a 2.5 second timeout
on the AMF test process after which it will self-terminate.
This commit is contained in:
Richard Stanway 2022-08-01 21:58:34 +02:00 committed by Jim
parent 68415fa08f
commit 8ab6fffec4

View File

@ -85,12 +85,35 @@ static bool get_adapter_caps(IDXGIFactory *factory, uint32_t adapter_idx)
return true;
}
DWORD WINAPI TimeoutThread(LPVOID param)
{
HANDLE hMainThread = (HANDLE)param;
DWORD ret = WaitForSingleObject(hMainThread, 2500);
if (ret == WAIT_TIMEOUT)
TerminateProcess(GetCurrentProcess(), STATUS_TIMEOUT);
CloseHandle(hMainThread);
return 0;
}
int main(void)
try {
ComPtr<IDXGIFactory> factory;
AMF_RESULT res;
HRESULT hr;
HANDLE hMainThread;
DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
GetCurrentProcess(), &hMainThread, 0, FALSE,
DUPLICATE_SAME_ACCESS);
DWORD threadId;
HANDLE hThread;
hThread =
CreateThread(NULL, 0, TimeoutThread, hMainThread, 0, &threadId);
CloseHandle(hThread);
/* --------------------------------------------------------- */
/* try initializing amf, I guess */