From 8b065fd068a4f48992247df46f32bd08bb44f10b Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sat, 3 Jan 2015 20:47:29 -0800 Subject: [PATCH] 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. --- libobs/obs-internal.h | 1 + libobs/obs-source.c | 11 ++++++++--- libobs/obs.h | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index 13d4b387a..e222f5426 100644 --- a/libobs/obs-internal.h +++ b/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; diff --git a/libobs/obs-source.c b/libobs/obs-source.c index ba5a95c28..ac66cd3b7 100644 --- a/libobs/obs-source.c +++ b/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; } } diff --git a/libobs/obs.h b/libobs/obs.h index dfd6294ff..8933d4399 100644 --- a/libobs/obs.h +++ b/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);