Browse Source

libobs: Prevent video cache clear on first frame

Fix a bug where when a source first starts up its async cache, it
unintentionally resets its cache, which means that the first few frames
would be lost.
jp9000 10 năm trước cách đây
mục cha
commit
ebee67097a
1 tập tin đã thay đổi với 7 bổ sung1 xóa
  1. 7 1
      libobs/obs-source.c

+ 7 - 1
libobs/obs-source.c

@@ -196,6 +196,9 @@ obs_source_t *obs_source_create(enum obs_source_type type, const char *id,
 
 	source->flags = source->default_flags;
 
+	/* prevents the source from clearing the cache on the first frame */
+	source->async_reset_texture = true;
+
 	if (info && info->type == OBS_SOURCE_TYPE_TRANSITION)
 		os_atomic_inc_long(&obs->data.active_transitions);
 	return source;
@@ -1474,11 +1477,14 @@ static inline struct obs_source_frame *cache_video(struct obs_source *source,
 	pthread_mutex_lock(&source->async_mutex);
 
 	if (async_texture_changed(source, frame)) {
+		/* prevents the cache from being freed on the first frame */
+		if (!source->async_reset_texture)
+			free_async_cache(source);
+
 		source->async_width         = frame->width;
 		source->async_height        = frame->height;
 		source->async_format        = frame->format;
 		source->async_reset_texture = true;
-		free_async_cache(source);
 	}
 
 	for (size_t i = 0; i < source->async_cache.num; i++) {