win-capture: Defer hook offset loading to separate thread
Boosts startup time significantly to defer this to a separate thread.
This commit is contained in:
parent
35285a26b7
commit
eaa32c20be
@ -452,9 +452,14 @@ static void game_capture_update(void *data, obs_data_t *settings)
|
||||
}
|
||||
}
|
||||
|
||||
extern void wait_for_hook_initialization(void);
|
||||
|
||||
static void *game_capture_create(obs_data_t *settings, obs_source_t *source)
|
||||
{
|
||||
struct game_capture *gc = bzalloc(sizeof(*gc));
|
||||
|
||||
wait_for_hook_initialization();
|
||||
|
||||
gc->source = source;
|
||||
gc->initial_config = true;
|
||||
gc->retry_interval = DEFAULT_RETRY_INTERVAL;
|
||||
|
@ -11,6 +11,8 @@ extern struct obs_source_info monitor_capture_info;
|
||||
extern struct obs_source_info window_capture_info;
|
||||
extern struct obs_source_info game_capture_info;
|
||||
|
||||
static HANDLE init_hooks_thread = NULL;
|
||||
|
||||
extern bool cached_versions_match(void);
|
||||
extern bool load_cached_graphics_offsets(bool is32bit);
|
||||
extern bool load_graphics_offsets(bool is32bit);
|
||||
@ -25,6 +27,37 @@ extern bool load_graphics_offsets(bool is32bit);
|
||||
|
||||
#define USE_HOOK_ADDRESS_CACHE false
|
||||
|
||||
static DWORD WINAPI init_hooks(LPVOID unused)
|
||||
{
|
||||
if (USE_HOOK_ADDRESS_CACHE &&
|
||||
cached_versions_match() &&
|
||||
load_cached_graphics_offsets(IS32BIT)) {
|
||||
|
||||
load_cached_graphics_offsets(!IS32BIT);
|
||||
obs_register_source(&game_capture_info);
|
||||
|
||||
} else if (load_graphics_offsets(IS32BIT)) {
|
||||
load_graphics_offsets(!IS32BIT);
|
||||
}
|
||||
|
||||
UNUSED_PARAMETER(unused);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wait_for_hook_initialization(void)
|
||||
{
|
||||
static bool initialized = false;
|
||||
|
||||
if (!initialized) {
|
||||
if (init_hooks_thread) {
|
||||
WaitForSingleObject(init_hooks_thread, INFINITE);
|
||||
CloseHandle(init_hooks_thread);
|
||||
init_hooks_thread = NULL;
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool obs_module_load(void)
|
||||
{
|
||||
struct win_version_info ver;
|
||||
@ -52,17 +85,13 @@ bool obs_module_load(void)
|
||||
|
||||
obs_register_source(&window_capture_info);
|
||||
|
||||
if (USE_HOOK_ADDRESS_CACHE &&
|
||||
cached_versions_match() &&
|
||||
load_cached_graphics_offsets(IS32BIT)) {
|
||||
|
||||
load_cached_graphics_offsets(!IS32BIT);
|
||||
obs_register_source(&game_capture_info);
|
||||
|
||||
} else if (load_graphics_offsets(IS32BIT)) {
|
||||
load_graphics_offsets(!IS32BIT);
|
||||
obs_register_source(&game_capture_info);
|
||||
}
|
||||
init_hooks_thread = CreateThread(NULL, 0, init_hooks, NULL, 0, NULL);
|
||||
obs_register_source(&game_capture_info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void obs_module_unload(void)
|
||||
{
|
||||
wait_for_hook_initialization();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user