From 2707f05c460b02973f67d127e91cc94ebde2e7a9 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 13 May 2016 04:21:39 -0700 Subject: [PATCH] Revert "win-capture: Allow window capturing of current process" This reverts commit 8d520b970d3552417005f6dab4f0892485cd14ce. This can actually cause a hard lock due to the windows API when destroying window capture. When the graphics thread locks the source list for doing tick or render, and then the UI thread tries to destroy a source, the UI thread will wait for the graphics thread to complete rendering/ticking of sources. The video_tick of window capture would then check windows in the same process and try to query the window's name via GetWindowText. However, GetWindowText is synchronous, and will not return until the window event has been processed by the UI thread, so it will perpetually lock because the two threads are waiting for each other to finish. --- plugins/win-capture/game-capture.c | 2 +- plugins/win-capture/window-capture.c | 2 +- plugins/win-capture/window-helpers.c | 29 ++++------------------------ plugins/win-capture/window-helpers.h | 3 +-- 4 files changed, 7 insertions(+), 29 deletions(-) diff --git a/plugins/win-capture/game-capture.c b/plugins/win-capture/game-capture.c index 65c6380c1..c5b474d4b 100644 --- a/plugins/win-capture/game-capture.c +++ b/plugins/win-capture/game-capture.c @@ -1579,7 +1579,7 @@ static obs_properties_t *game_capture_properties(void *data) p = obs_properties_add_list(ppts, SETTING_CAPTURE_WINDOW, TEXT_WINDOW, OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING); obs_property_list_add_string(p, "", ""); - fill_window_list(p, INCLUDE_MINIMIZED, false); + fill_window_list(p, INCLUDE_MINIMIZED); obs_property_set_modified_callback(p, window_changed_callback); diff --git a/plugins/win-capture/window-capture.c b/plugins/win-capture/window-capture.c index 38c1e1e4e..697b602bc 100644 --- a/plugins/win-capture/window-capture.c +++ b/plugins/win-capture/window-capture.c @@ -118,7 +118,7 @@ static obs_properties_t *wc_properties(void *unused) p = obs_properties_add_list(ppts, "window", TEXT_WINDOW, OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING); - fill_window_list(p, EXCLUDE_MINIMIZED, true); + fill_window_list(p, EXCLUDE_MINIMIZED); p = obs_properties_add_list(ppts, "priority", TEXT_MATCH_PRIORITY, OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); diff --git a/plugins/win-capture/window-helpers.c b/plugins/win-capture/window-helpers.c index b22431374..fddba8b0f 100644 --- a/plugins/win-capture/window-helpers.c +++ b/plugins/win-capture/window-helpers.c @@ -1,7 +1,6 @@ #define PSAPI_VERSION 1 #include #include -#include #include #include @@ -68,13 +67,6 @@ static inline HANDLE open_process(DWORD desired_access, bool inherit_handle, return open_process_proc(desired_access, inherit_handle, process_id); } -static inline bool is_self(HWND window) -{ - DWORD id; - GetWindowThreadProcessId(window, &id); - return id == GetCurrentProcessId(); -} - bool get_window_exe(struct dstr *name, HWND window) { wchar_t wname[MAX_PATH]; @@ -85,6 +77,8 @@ bool get_window_exe(struct dstr *name, HWND window) DWORD id; GetWindowThreadProcessId(window, &id); + if (id == GetCurrentProcessId()) + return false; process = open_process(PROCESS_QUERY_LIMITED_INFORMATION, false, id); if (!process) @@ -210,29 +204,14 @@ static inline HWND first_window(enum window_search_mode mode) return window; } -void fill_window_list(obs_property_t *p, enum window_search_mode mode, - bool allow_self) +void fill_window_list(obs_property_t *p, enum window_search_mode mode) { HWND window = first_window(mode); - DARRAY(HWND) process_windows; - - da_init(process_windows); while (window) { - if (is_self(window)) - da_push_back(process_windows, &window); - else - add_window(p, window); - + add_window(p, window); window = next_window(window, mode); } - - if (allow_self) { - for (size_t i = 0; i < process_windows.num; i++) - add_window(p, process_windows.array[i]); - } - - da_free(process_windows); } static int window_rating(HWND window, diff --git a/plugins/win-capture/window-helpers.h b/plugins/win-capture/window-helpers.h index 5f25e1985..2f8bc34e5 100644 --- a/plugins/win-capture/window-helpers.h +++ b/plugins/win-capture/window-helpers.h @@ -15,8 +15,7 @@ enum window_search_mode { extern bool get_window_exe(struct dstr *name, HWND window); -extern void fill_window_list(obs_property_t *p, enum window_search_mode mode, - bool allow_self); +extern void fill_window_list(obs_property_t *p, enum window_search_mode mode); extern void build_window_strings(const char *str, char **class,