瀏覽代碼

libobs: Update async texture when showing preloaded video

The previous preloaded video behavior updated the texture on preload
rather than when the video was shown, during which time the texture may
have been modified by other processes, resulting in the wrong frame
being displayed.
Richard Stanway 5 年之前
父節點
當前提交
4f7767111a
共有 1 個文件被更改,包括 10 次插入7 次删除
  1. 10 7
      libobs/obs-source.c

+ 10 - 7
libobs/obs-source.c

@@ -2888,8 +2888,6 @@ obs_source_preload_video_internal(obs_source_t *source,
 	if (!frame)
 	if (!frame)
 		return;
 		return;
 
 
-	obs_enter_graphics();
-
 	if (preload_frame_changed(source, frame)) {
 	if (preload_frame_changed(source, frame)) {
 		obs_source_frame_destroy(source->async_preload_frame);
 		obs_source_frame_destroy(source->async_preload_frame);
 		source->async_preload_frame = obs_source_frame_create(
 		source->async_preload_frame = obs_source_frame_create(
@@ -2897,13 +2895,8 @@ obs_source_preload_video_internal(obs_source_t *source,
 	}
 	}
 
 
 	copy_frame_data(source->async_preload_frame, frame);
 	copy_frame_data(source->async_preload_frame, frame);
-	set_async_texture_size(source, source->async_preload_frame);
-	update_async_textures(source, source->async_preload_frame,
-			      source->async_textures, source->async_texrender);
 
 
 	source->last_frame_ts = frame->timestamp;
 	source->last_frame_ts = frame->timestamp;
-
-	obs_leave_graphics();
 }
 }
 
 
 void obs_source_preload_video(obs_source_t *source,
 void obs_source_preload_video(obs_source_t *source,
@@ -2962,8 +2955,18 @@ void obs_source_show_preloaded_video(obs_source_t *source)
 	if (!obs_source_valid(source, "obs_source_show_preloaded_video"))
 	if (!obs_source_valid(source, "obs_source_show_preloaded_video"))
 		return;
 		return;
 
 
+	if (!source->async_preload_frame)
+		return;
+
+	obs_enter_graphics();
+
+	set_async_texture_size(source, source->async_preload_frame);
+	update_async_textures(source, source->async_preload_frame,
+			      source->async_textures, source->async_texrender);
 	source->async_active = true;
 	source->async_active = true;
 
 
+	obs_leave_graphics();
+
 	pthread_mutex_lock(&source->audio_buf_mutex);
 	pthread_mutex_lock(&source->audio_buf_mutex);
 	sys_ts = (source->monitoring_type != OBS_MONITORING_TYPE_MONITOR_ONLY)
 	sys_ts = (source->monitoring_type != OBS_MONITORING_TYPE_MONITOR_ONLY)
 			 ? os_gettime_ns()
 			 ? os_gettime_ns()