Browse Source

Merge pull request #3245 from e00E/fix-defer-update

libobs: Fix deferred update sometimes using stale data
Jim 5 years ago
parent
commit
53b65bb5fd
2 changed files with 8 additions and 6 deletions
  1. 1 1
      libobs/obs-internal.h
  2. 7 5
      libobs/obs-source.c

+ 1 - 1
libobs/obs-internal.h

@@ -601,7 +601,7 @@ struct obs_source {
 	bool owns_info_id;
 	bool owns_info_id;
 
 
 	/* signals to call the source update in the video thread */
 	/* signals to call the source update in the video thread */
-	bool defer_update;
+	long defer_update_count;
 
 
 	/* ensures show/hide are only called once */
 	/* ensures show/hide are only called once */
 	volatile long show_refs;
 	volatile long show_refs;

+ 7 - 5
libobs/obs-source.c

@@ -860,11 +860,13 @@ uint32_t obs_get_source_output_flags(const char *id)
 
 
 static void obs_source_deferred_update(obs_source_t *source)
 static void obs_source_deferred_update(obs_source_t *source)
 {
 {
-	if (source->context.data && source->info.update)
+	if (source->context.data && source->info.update) {
+		long count = os_atomic_load_long(&source->defer_update_count);
 		source->info.update(source->context.data,
 		source->info.update(source->context.data,
 				    source->context.settings);
 				    source->context.settings);
-
-	source->defer_update = false;
+		os_atomic_compare_swap_long(&source->defer_update_count, count,
+					    0);
+	}
 }
 }
 
 
 void obs_source_update(obs_source_t *source, obs_data_t *settings)
 void obs_source_update(obs_source_t *source, obs_data_t *settings)
@@ -876,7 +878,7 @@ void obs_source_update(obs_source_t *source, obs_data_t *settings)
 		obs_data_apply(source->context.settings, settings);
 		obs_data_apply(source->context.settings, settings);
 
 
 	if (source->info.output_flags & OBS_SOURCE_VIDEO) {
 	if (source->info.output_flags & OBS_SOURCE_VIDEO) {
-		source->defer_update = true;
+		os_atomic_inc_long(&source->defer_update_count);
 	} else if (source->context.data && source->info.update) {
 	} else if (source->context.data && source->info.update) {
 		source->info.update(source->context.data,
 		source->info.update(source->context.data,
 				    source->context.settings);
 				    source->context.settings);
@@ -1101,7 +1103,7 @@ void obs_source_video_tick(obs_source_t *source, float seconds)
 	if ((source->info.output_flags & OBS_SOURCE_ASYNC) != 0)
 	if ((source->info.output_flags & OBS_SOURCE_ASYNC) != 0)
 		async_tick(source);
 		async_tick(source);
 
 
-	if (source->defer_update)
+	if (os_atomic_load_long(&source->defer_update_count) > 0)
 		obs_source_deferred_update(source);
 		obs_source_deferred_update(source);
 
 
 	/* reset the filter render texture information once every frame */
 	/* reset the filter render texture information once every frame */