Jelajahi Sumber

libobs: Allow disabling of async video texture

If an async video source stops video for whatever reason, it would get
stuck on the last frame that was played.  This was particularly awkward
when I wanted to give the user the ability to deactivate a source such
as a webcam because it would get stuck on the last frame.
jp9000 10 tahun lalu
induk
melakukan
8b065fd068
3 mengubah file dengan 10 tambahan dan 4 penghapusan
  1. 1 0
      libobs/obs-internal.h
  2. 8 3
      libobs/obs-source.c
  3. 1 1
      libobs/obs.h

+ 1 - 0
libobs/obs-internal.h

@@ -333,6 +333,7 @@ struct obs_source {
 	float                           async_color_range_max[3];
 	int                             async_plane_offset[2];
 	bool                            async_flip;
+	bool                            async_active;
 	DARRAY(struct obs_source_frame*)video_frames;
 	pthread_mutex_t                 video_mutex;
 	uint32_t                        async_width;

+ 8 - 3
libobs/obs-source.c

@@ -1091,7 +1091,7 @@ static void obs_source_render_async_video(obs_source_t *source)
 		obs_source_release_frame(source, frame);
 	}
 
-	if (source->async_texture)
+	if (source->async_texture && source->async_active)
 		obs_source_draw_async_texture(source);
 }
 
@@ -1381,10 +1381,10 @@ static inline void cycle_frames(struct obs_source *source)
 void obs_source_output_video(obs_source_t *source,
 		const struct obs_source_frame *frame)
 {
-	if (!source || !frame)
+	if (!source)
 		return;
 
-	struct obs_source_frame *output = cache_video(frame);
+	struct obs_source_frame *output = !!frame ? cache_video(frame) : NULL;
 
 	pthread_mutex_lock(&source->filter_mutex);
 	output = filter_async_video(source, output);
@@ -1395,6 +1395,11 @@ void obs_source_output_video(obs_source_t *source,
 		cycle_frames(source);
 		da_push_back(source->video_frames, &output);
 		pthread_mutex_unlock(&source->video_mutex);
+		source->async_active = true;
+	} else {
+		source->async_active = false;
+		source->async_width = 0;
+		source->async_height = 0;
 	}
 }
 

+ 1 - 1
libobs/obs.h

@@ -802,7 +802,7 @@ EXPORT void obs_source_draw_set_color_matrix(
 EXPORT void obs_source_draw(gs_texture_t *image, int x, int y,
 		uint32_t cx, uint32_t cy, bool flip);
 
-/** Outputs asynchronous video data */
+/** Outputs asynchronous video data.  Set to NULL to deactivate the texture */
 EXPORT void obs_source_output_video(obs_source_t *source,
 		const struct obs_source_frame *frame);