win-capture: Use window for keepalive check
To check to make sure game capture is still active in the capture program, it currently uses a named event, and then it checks to see if that named event exists. However with UWP programs, you can't open a named event outside of the UWP process. FindWindow on the other hand does work, so instead of checking to see if a named kernel object exists, create a window and check to see if that window exists.
This commit is contained in:
@@ -39,7 +39,7 @@ static volatile bool stop_loop = false;
|
||||
static HANDLE capture_thread = NULL;
|
||||
char system_path[MAX_PATH] = {0};
|
||||
char process_name[MAX_PATH] = {0};
|
||||
char keepalive_name[64] = {0};
|
||||
wchar_t keepalive_name[64] = {0};
|
||||
HWND dummy_window = NULL;
|
||||
|
||||
static unsigned int shmem_id_counter = 0;
|
||||
@@ -234,8 +234,8 @@ static inline bool init_hook(HANDLE thread_handle)
|
||||
{
|
||||
wait_for_dll_main_finish(thread_handle);
|
||||
|
||||
sprintf(keepalive_name, "%s%lu", EVENT_HOOK_KEEPALIVE,
|
||||
GetCurrentProcessId());
|
||||
_snwprintf(keepalive_name, sizeof(keepalive_name), L"%s%lu",
|
||||
WINDOW_HOOK_KEEPALIVE, GetCurrentProcessId());
|
||||
|
||||
init_pipe();
|
||||
if (!init_signals()) {
|
||||
|
@@ -98,7 +98,7 @@ extern HANDLE signal_exit;
|
||||
extern HANDLE tex_mutexes[2];
|
||||
extern char system_path[MAX_PATH];
|
||||
extern char process_name[MAX_PATH];
|
||||
extern char keepalive_name[64];
|
||||
extern wchar_t keepalive_name[64];
|
||||
extern HWND dummy_window;
|
||||
extern volatile bool active;
|
||||
|
||||
@@ -143,13 +143,7 @@ static inline HMODULE load_system_library(const char *name)
|
||||
|
||||
static inline bool capture_alive(void)
|
||||
{
|
||||
HANDLE event = OpenEventA(GC_EVENT_FLAGS, false, keepalive_name);
|
||||
if (event) {
|
||||
CloseHandle(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return !!FindWindowW(keepalive_name, NULL);
|
||||
}
|
||||
|
||||
static inline bool capture_active(void)
|
||||
@@ -198,8 +192,18 @@ static inline bool capture_should_stop(void)
|
||||
{
|
||||
bool stop_requested = false;
|
||||
|
||||
if (capture_active())
|
||||
stop_requested = capture_stopped() || !capture_alive();
|
||||
if (capture_active()) {
|
||||
static uint64_t last_keepalive_check = 0;
|
||||
uint64_t cur_time = os_gettime_ns();
|
||||
bool alive = true;
|
||||
|
||||
if (cur_time - last_keepalive_check > 5000000000) {
|
||||
alive = capture_alive();
|
||||
last_keepalive_check = cur_time;
|
||||
}
|
||||
|
||||
stop_requested = capture_stopped() || !alive;
|
||||
}
|
||||
|
||||
return stop_requested;
|
||||
}
|
||||
|
Reference in New Issue
Block a user