Skip to content

Commit

Permalink
stinger for dual output
Browse files Browse the repository at this point in the history
  • Loading branch information
summeroff committed Aug 1, 2023
1 parent 2c58e64 commit fc5629b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 29 deletions.
1 change: 0 additions & 1 deletion libobs/obs-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,6 @@ struct obs_source {
enum obs_transition_mode transition_mode;
enum obs_transition_scale_type transition_scale_type;
struct matrix4 transition_matrices[2];
struct obs_video_info *transition_output;

/* color space */
gs_texrender_t *color_space_texrender;
Expand Down
23 changes: 0 additions & 23 deletions libobs/obs-source-transition.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ bool obs_transition_init(obs_source_t *transition)
gs_texrender_create(GS_RGBA, GS_ZS_NONE);
transition->transition_source_active[0] = true;

transition->transition_duration = 0;

return transition->transition_texrender[0] != NULL &&
transition->transition_texrender[1] != NULL;
}
Expand Down Expand Up @@ -363,27 +361,6 @@ static inline bool transition_active(obs_source_t *transition)
transition->transitioning_video;
}

void obs_transition_set_output(obs_source_t *transition,
struct obs_video_info *transition_output)
{
if (!transition_valid(transition, "obs_transition_set_output"))
return;

transition->transition_output = transition_output;
}

bool transition_skip_for_output(obs_source_t *transition)
{
if (!transition_valid(transition, "transition_skip_for_output"))
return true;
if (transition->transition_output == NULL)
return;

if (transition->transition_output == obs_get_video_rendering_canvas())
return false;
return true;
}

bool obs_transition_start(obs_source_t *transition,
enum obs_transition_mode mode, uint32_t duration_ms,
obs_source_t *dest)
Expand Down
3 changes: 0 additions & 3 deletions libobs/obs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1718,9 +1718,6 @@ EXPORT void obs_transition_set_size(obs_source_t *transition, uint32_t cx,
EXPORT void obs_transition_get_size(const obs_source_t *transition,
uint32_t *cx, uint32_t *cy);

EXPORT void obs_transition_set_output(obs_source_t *transition,
struct obs_video_info *transition_output);
EXPORT bool transition_skip_for_output(obs_source_t *transition);
/* function used by transitions */

/**
Expand Down
5 changes: 5 additions & 0 deletions plugins/obs-transitions/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ TrackMatteLayoutMask="Mask only"
AudioFadeStyle="Audio Fade Style"
AudioFadeStyle.FadeOutFadeIn="Fade out to transition point then fade in"
AudioFadeStyle.CrossFade="Crossfade"
FitStyle="Fit in output"
FitStyle.FitHeight="Fit by height"
FitStyle.FitWidth="Fit by width"
FitStyle.Stretch="Stretch to output"
FitStyle.OnlyPerfect="Show only if similar aspect ratio"
SwitchPoint="Peak Color Point"
LumaWipeTransition="Luma Wipe"
LumaWipe.Image="Image"
Expand Down
55 changes: 53 additions & 2 deletions plugins/obs-transitions/transition-stinger.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ enum matte_layout {
MATTE_LAYOUT_MASK,
};

enum fit_style {
FIT_STYLE_STRETCH,
FIT_STYLE_BY_HEIGHT,
FIT_STYLE_BY_WIDTH,
FIT_STYLE_ONLY_PERFECT
};

enum fade_style { FADE_STYLE_FADE_OUT_FADE_IN, FADE_STYLE_CROSS_FADE };

struct stinger_info {
Expand All @@ -31,6 +38,7 @@ struct stinger_info {
bool transition_point_is_frame;
int monitoring_type;
enum fade_style fade_style;
enum fit_style fit_style;

bool track_matte_enabled;
int matte_layout;
Expand Down Expand Up @@ -151,6 +159,10 @@ static void stinger_update(void *data, obs_data_t *settings)
break;
}

s->fit_style = (enum fit_style)obs_data_get_int(settings, "fit_style");
if (s->track_matte_enabled)
s->fit_style = FIT_STYLE_STRETCH;

if (s->track_matte_enabled != track_matte_was_enabled) {
obs_enter_graphics();

Expand Down Expand Up @@ -421,12 +433,31 @@ static void stinger_video_render(void *data, gs_effect_t *effect)

float source_cxf = (float)source_cx;
float source_cyf = (float)source_cy;
float shift_xf = 0.0f;
float shift_yf = 0.0f;

if (!media_cx || !media_cy)
return;

if (transition_skip_for_output(s->source))
return;
switch (s->fit_style) {
case FIT_STYLE_STRETCH:
break;
case FIT_STYLE_BY_HEIGHT:
source_cxf =
(float)source_cy * (float)media_cx / (float)media_cy;
shift_xf = ((float)source_cx - source_cxf) / 2.0f;
break;
case FIT_STYLE_BY_WIDTH:
source_cyf =
(float)source_cx * (float)media_cy / (float)media_cx;
shift_yf = ((float)source_cy - source_cyf) / 2.0f;
break;
case FIT_STYLE_ONLY_PERFECT:
if (fabsf((float)source_cx / (float)source_cy -
(float)media_cx / (float)media_cy) > 0.01f)
return;
break;
}

if (s->do_texrender) {
const enum gs_color_space space =
Expand Down Expand Up @@ -456,6 +487,7 @@ static void stinger_video_render(void *data, gs_effect_t *effect)
} else {
const bool previous = gs_set_linear_srgb(true);
gs_matrix_push();
gs_matrix_translate3f(shift_xf, shift_yf, 0.0f);
gs_matrix_scale3f(source_cxf / (float)media_cx,
source_cyf / (float)media_cy, 1.0f);
obs_source_video_render(s->media_source);
Expand Down Expand Up @@ -738,6 +770,9 @@ static bool track_matte_enabled_modified(obs_properties_t *ppts,
obs_properties_get(ppts, "invert_matte");
obs_property_set_visible(prop_matte_invert, track_matte_enabled);

obs_property_t *prop_fit_style = obs_properties_get(ppts, "fit_style");
obs_property_set_visible(prop_fit_style, !track_matte_enabled);

UNUSED_PARAMETER(p);
return true;
}
Expand Down Expand Up @@ -853,6 +888,22 @@ static obs_properties_t *stinger_properties(void *data)
obs_module_text("AudioFadeStyle.CrossFade"),
FADE_STYLE_CROSS_FADE);

obs_property_t *fit_style = obs_properties_add_list(
ppts, "fit_style", obs_module_text("FitStyle"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
obs_property_list_add_int(fit_style,
obs_module_text("FitStyle.FitHeight"),
FIT_STYLE_BY_HEIGHT);
obs_property_list_add_int(fit_style,
obs_module_text("FitStyle.FitWidth"),
FIT_STYLE_BY_WIDTH);
obs_property_list_add_int(fit_style,
obs_module_text("FitStyle.Stretch"),
FIT_STYLE_STRETCH);
obs_property_list_add_int(fit_style,
obs_module_text("FitStyle.OnlyPerfect"),
FIT_STYLE_ONLY_PERFECT);

UNUSED_PARAMETER(data);
return ppts;
}
Expand Down

0 comments on commit fc5629b

Please sign in to comment.