From b277f2b737024d7db53fe6877e8ef66383308f1a Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sat, 3 Jan 2015 22:39:21 -0800 Subject: [PATCH] Don't update video of sources if not displaying This is a bit of an optimization to reduce load a little bit if any of the video capture sources are not currently being displayed on the screen. They will simply not capture or update their texture data if they are not currently being shown anywhere. The mac and window game capture sources don't really apply due to the fact that their textures aren't updated on the source's end (they update inside of the hooks). --- plugins/linux-capture/xcompcap-main.cpp | 3 +++ plugins/linux-capture/xshm-input.c | 2 ++ plugins/mac-capture/mac-display-capture.m | 2 ++ plugins/mac-capture/mac-window-capture.m | 5 +++++ plugins/win-capture/monitor-capture.c | 3 +++ plugins/win-capture/window-capture.c | 3 +++ 6 files changed, 18 insertions(+) diff --git a/plugins/linux-capture/xcompcap-main.cpp b/plugins/linux-capture/xcompcap-main.cpp index ebbc73e57..89da595e8 100644 --- a/plugins/linux-capture/xcompcap-main.cpp +++ b/plugins/linux-capture/xcompcap-main.cpp @@ -443,6 +443,9 @@ void XCompcapMain::tick(float seconds) { UNUSED_PARAMETER(seconds); + if (!obs_source_showing(p->source)) + return; + PLock lock(&p->lock, true); if (!lock.isLocked()) diff --git a/plugins/linux-capture/xshm-input.c b/plugins/linux-capture/xshm-input.c index 39aa43a52..eee1d4327 100644 --- a/plugins/linux-capture/xshm-input.c +++ b/plugins/linux-capture/xshm-input.c @@ -392,6 +392,8 @@ static void xshm_video_tick(void *vptr, float seconds) if (!data->texture) return; + if (!obs_source_showing(data->source)) + return; xcb_shm_get_image_cookie_t img_c; xcb_shm_get_image_reply_t *img_r; diff --git a/plugins/mac-capture/mac-display-capture.m b/plugins/mac-capture/mac-display-capture.m index 4cc0bcc98..92227b1d0 100644 --- a/plugins/mac-capture/mac-display-capture.m +++ b/plugins/mac-capture/mac-display-capture.m @@ -328,6 +328,8 @@ static void display_capture_video_tick(void *data, float seconds) if (!dc->current) return; + if (!obs_source_showing(dc->source)) + return; IOSurfaceRef prev_prev = dc->prev; if (pthread_mutex_lock(&dc->mutex)) diff --git a/plugins/mac-capture/mac-window-capture.m b/plugins/mac-capture/mac-window-capture.m index d2d1a8beb..800bfd459 100644 --- a/plugins/mac-capture/mac-window-capture.m +++ b/plugins/mac-capture/mac-window-capture.m @@ -200,6 +200,11 @@ static inline void window_capture_tick_internal(struct window_capture *wc, static void window_capture_tick(void *data, float seconds) { + struct window_capture *wc = data; + + if (!obs_source_showing(wc->source)) + return; + @autoreleasepool { return window_capture_tick_internal(data, seconds); } diff --git a/plugins/win-capture/monitor-capture.c b/plugins/win-capture/monitor-capture.c index 31e6ef9e8..89308599b 100644 --- a/plugins/win-capture/monitor-capture.c +++ b/plugins/win-capture/monitor-capture.c @@ -143,6 +143,9 @@ static void monitor_capture_tick(void *data, float seconds) { struct monitor_capture *capture = data; + if (!obs_source_showing(capture->source)) + return; + obs_enter_graphics(); dc_capture_capture(&capture->data, NULL); obs_leave_graphics(); diff --git a/plugins/win-capture/window-capture.c b/plugins/win-capture/window-capture.c index 951e18be0..89875b5a8 100644 --- a/plugins/win-capture/window-capture.c +++ b/plugins/win-capture/window-capture.c @@ -149,6 +149,9 @@ static void wc_tick(void *data, float seconds) RECT rect; bool reset_capture = false; + if (!obs_source_showing(wc->source)) + return; + if (!wc->window || !IsWindow(wc->window)) { if (!wc->title && !wc->class) return;