From 52e08249f1cf2f6adfb562daf502e78f8af1ac76 Mon Sep 17 00:00:00 2001
From: jp9000 <obs.jim@gmail.com>
Date: Fri, 12 Sep 2014 00:35:21 -0700
Subject: [PATCH] Only render async frames to texture once per frame

This prevents multiple needless calls to obs_source_get_frame and other
functions.  If the texture has already been processed, then just render
it as-is in any subsequent calls to obs_source_video_render.
---
 libobs/obs-internal.h |  1 +
 libobs/obs-source.c   | 22 ++++++++++++++--------
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h
index 3fe9a9d00..080afa8d3 100644
--- a/libobs/obs-internal.h
+++ b/libobs/obs-internal.h
@@ -293,6 +293,7 @@ struct obs_source {
 	uint64_t                        next_audio_ts_min;
 	uint64_t                        last_frame_ts;
 	uint64_t                        last_sys_timestamp;
+	bool                            async_rendered;
 
 	/* audio */
 	bool                            audio_failed;
diff --git a/libobs/obs-source.c b/libobs/obs-source.c
index 9816d5e9b..875197acc 100644
--- a/libobs/obs-source.c
+++ b/libobs/obs-source.c
@@ -503,6 +503,8 @@ void obs_source_video_tick(obs_source_t source, float seconds)
 
 	if (source->context.data && source->info.video_tick)
 		source->info.video_tick(source->context.data, seconds);
+
+	source->async_rendered = false;
 }
 
 /* unless the value is 3+ hours worth of frames, this won't overflow */
@@ -1031,18 +1033,22 @@ static void obs_source_draw_async_texture(struct obs_source *source)
 
 static void obs_source_render_async_video(obs_source_t source)
 {
-	struct obs_source_frame *frame = obs_source_get_frame(source);
-	if (frame) {
-		if (!set_async_texture_size(source, frame))
-			return;
-		if (!update_async_texture(source, frame))
-			return;
+	if (!source->async_rendered) {
+		struct obs_source_frame *frame = obs_source_get_frame(source);
+
+		source->async_rendered = true;
+		if (frame) {
+			if (!set_async_texture_size(source, frame))
+				return;
+			if (!update_async_texture(source, frame))
+				return;
+		}
+
+		obs_source_release_frame(source, frame);
 	}
 
 	if (source->async_texture)
 		obs_source_draw_async_texture(source);
-
-	obs_source_release_frame(source, frame);
 }
 
 static inline void obs_source_render_filters(obs_source_t source)
-- 
GitLab