Skip to content

Commit

Permalink
Add no filter option for not async sources
Browse files Browse the repository at this point in the history
  • Loading branch information
exeldro committed Feb 14, 2024
1 parent 87fe272 commit c22a6f3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 6 deletions.
1 change: 1 addition & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ CloneType="Clone type"
Source="Source"
CurrentScene="Current scene"
PreviousScene="Previous scene"
NoFilters="No filters"
62 changes: 56 additions & 6 deletions source-clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ void source_clone_update(void *data, obs_data_t *settings)
bool audio_enabled = obs_data_get_bool(settings, "audio");
bool active_clone = obs_data_get_bool(settings, "active_clone");
context->clone_type = obs_data_get_int(settings, "clone_type");
bool async = true;
if (context->clone_type == CLONE_SOURCE) {
const char *source_name =
obs_data_get_string(settings, "clone");
Expand All @@ -173,6 +174,8 @@ void source_clone_update(void *data, obs_data_t *settings)
source = NULL;
}
if (source) {
async = (obs_source_get_output_flags(source) &
OBS_SOURCE_ASYNC) != 0;
if (!obs_weak_source_references_source(context->clone,
source) ||
context->audio_enabled != audio_enabled ||
Expand All @@ -189,6 +192,8 @@ void source_clone_update(void *data, obs_data_t *settings)
context->num_channels = audio_output_get_channels(obs_get_audio());
context->buffer_frame =
(uint8_t)obs_data_get_int(settings, "buffer_frame");
context->no_filter = obs_data_get_bool(settings, "no_filters") &&
!async;
}

void source_clone_defaults(obs_data_t *settings)
Expand Down Expand Up @@ -223,6 +228,29 @@ bool source_clone_type_changed(void *priv, obs_properties_t *props,
return true;
}

bool source_clone_source_changed(void *priv, obs_properties_t *props,
obs_property_t *property, obs_data_t *settings)
{
UNUSED_PARAMETER(property);
struct source_clone *context = priv;
const char *source_name = obs_data_get_string(settings, "clone");
bool async = true;
obs_source_t *source = obs_get_source_by_name(source_name);
if (source == context->source) {
obs_source_release(source);
source = NULL;
}
if (source) {
async = (obs_source_get_output_flags(source) &
OBS_SOURCE_ASYNC) != 0;
obs_source_release(source);
}

obs_property_t *no_filters = obs_properties_get(props, "no_filters");
obs_property_set_visible(no_filters, !async);
return true;
}

obs_properties_t *source_clone_properties(void *data)
{
obs_properties_t *props = obs_properties_create();
Expand Down Expand Up @@ -251,6 +279,7 @@ obs_properties_t *source_clone_properties(void *data)
source_clone_list_add_source(p, s);
obs_source_release(s);
}
obs_property_set_modified_callback2(p, source_clone_source_changed, data);
obs_properties_add_bool(props, "audio", obs_module_text("Audio"));
p = obs_properties_add_list(props, "buffer_frame",
obs_module_text("VideoBuffer"),
Expand All @@ -264,6 +293,9 @@ obs_properties_t *source_clone_properties(void *data)
obs_properties_add_bool(props, "active_clone",
obs_module_text("ActiveClone"));

obs_properties_add_bool(props, "no_filters",
obs_module_text("NoFilters"));

obs_properties_add_text(
props, "plugin_info",
"<a href=\"https://obsproject.com/forum/resources/source-clone.1632/\">Source Clone</a> (" PROJECT_VERSION
Expand Down Expand Up @@ -365,7 +397,11 @@ void source_clone_video_render(void *data, gs_effect_t *effect)
return;
}
if (context->buffer_frame == 0) {
obs_source_video_render(source);
if (context->no_filter) {
obs_source_default_render(source);
} else {
obs_source_video_render(source);
}
obs_source_release(source);
context->rendering = false;
return;
Expand Down Expand Up @@ -405,7 +441,11 @@ void source_clone_video_render(void *data, gs_effect_t *effect)
if (context->source_cx && context->source_cy) {
gs_ortho(0.0f, (float)context->source_cx, 0.0f,
(float)context->source_cy, -100.0f, 100.0f);
obs_source_video_render(source);
if (context->no_filter) {
obs_source_default_render(source);
} else {
obs_source_video_render(source);
}
}
gs_texrender_end(context->render);

Expand All @@ -430,7 +470,8 @@ uint32_t source_clone_get_width(void *data)
obs_source_t *source = obs_weak_source_get_source(context->clone);
if (!source)
return 1;
uint32_t width = obs_source_get_width(source);
uint32_t width = context->no_filter ? obs_source_get_base_width(source)
: obs_source_get_width(source);
obs_source_release(source);
if (context->buffer_frame > 1)
width /= context->buffer_frame;
Expand All @@ -447,7 +488,9 @@ uint32_t source_clone_get_height(void *data)
obs_source_t *source = obs_weak_source_get_source(context->clone);
if (!source)
return 1;
uint32_t height = obs_source_get_height(source);
uint32_t height = context->no_filter
? obs_source_get_base_height(source)
: obs_source_get_height(source);
obs_source_release(source);
if (context->buffer_frame > 1)
height /= context->buffer_frame;
Expand Down Expand Up @@ -553,8 +596,15 @@ void source_clone_video_tick(void *data, float seconds)
obs_source_t *s =
obs_weak_source_get_source(context->clone);
if (s) {
context->source_cx = obs_source_get_width(s);
context->source_cy = obs_source_get_height(s);
context->source_cx =
context->no_filter
? obs_source_get_base_width(s)
: obs_source_get_width(s);
context->source_cy =
context->no_filter
? obs_source_get_base_height(s)
: obs_source_get_height(s);

cx = context->source_cx;
cy = context->source_cy;
obs_source_release(s);
Expand Down
20 changes: 20 additions & 0 deletions source-clone.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@
#include <obs-module.h>
#include "version.h"
#include <util/threading.h>
#if LIBOBS_API_VER >= MAKE_SEMANTIC_VERSION(30, 1, 0)
#include <util/deque.h>
#define circlebuf_peek_front deque_peek_front
#define circlebuf_peek_back deque_peek_back
#define circlebuf_push_front deque_push_front
#define circlebuf_push_back deque_push_back
#define circlebuf_pop_front deque_pop_front
#define circlebuf_pop_back deque_pop_back
#define circlebuf_init deque_init
#define circlebuf_free deque_free
#define circlebuf_data deque_data
#else
#include <util/circlebuf.h>
#endif

enum clone_type {
CLONE_SOURCE,
Expand All @@ -17,9 +30,15 @@ struct source_clone {
obs_weak_source_t *clone;
obs_weak_source_t *current_scene;
struct audio_wrapper_info *audio_wrapper;
#if LIBOBS_API_VER >= MAKE_SEMANTIC_VERSION(30, 1, 0)
struct deque audio_data[MAX_AUDIO_CHANNELS];
struct deque audio_frames;
struct deque audio_timestamps;
#else
struct circlebuf audio_data[MAX_AUDIO_CHANNELS];
struct circlebuf audio_frames;
struct circlebuf audio_timestamps;
#endif
uint64_t audio_ts;
size_t num_channels;
pthread_mutex_t audio_mutex;
Expand All @@ -34,4 +53,5 @@ struct source_clone {
enum gs_color_space space;
bool rendering;
bool active_clone;
bool no_filter;
};

0 comments on commit c22a6f3

Please sign in to comment.