Skip to content

Commit 5fe1f87

Browse files
committed
obs-ffmpeg: Add pause visibility behaviour
based on PR 6112 by dcmouser Replace for local file checkbox "restart playback..." by a combobox with same mode than slideshow/vlc source visibility behaviour
1 parent 9b09ad9 commit 5fe1f87

2 files changed

Lines changed: 101 additions & 2 deletions

File tree

plugins/obs-ffmpeg/data/locale/en-US.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ HardwareDecode="Use hardware decoding when available"
4343
ClearOnMediaEnd="Show nothing when playback ends"
4444
Advanced="Advanced"
4545
RestartWhenActivated="Restart playback when source becomes active"
46+
PlaybackBehavior="Visibility Behavior"
47+
PlaybackBehavior.StopRestart="Stop when not visible, restart when visible"
48+
PlaybackBehavior.PauseUnpause="Pause when not visible, unpause when visible"
49+
PlaybackBehavior.AlwaysPlay="Always play even when not visible"
4650
CloseFileWhenInactive="Close file when inactive"
4751
CloseFileWhenInactive.ToolTip="Closes the file when the source is not being displayed on the stream or\nrecording. This allows the file to be changed when the source isn't active,\nbut there may be some startup delay when the source reactivates."
4852
ColorRange="YUV Color Range"

plugins/obs-ffmpeg/obs-ffmpeg-source.c

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct ffmpeg_source {
5757
bool is_hw_decoding;
5858
bool is_clear_on_media_end;
5959
bool restart_on_activate;
60+
bool pause_on_deactivate;
6061
bool close_when_inactive;
6162
bool seekable;
6263

@@ -87,6 +88,10 @@ static bool is_local_file_modified(obs_properties_t *props,
8788
obs_property_t *input_format =
8889
obs_properties_get(props, "input_format");
8990
obs_property_t *local_file = obs_properties_get(props, "local_file");
91+
obs_property_t *visibility_behaviour =
92+
obs_properties_get(props, "visibility_behaviour");
93+
obs_property_t *restart =
94+
obs_properties_get(props, "restart_on_activate");
9095
obs_property_t *looping = obs_properties_get(props, "looping");
9196
obs_property_t *buffering = obs_properties_get(props, "buffering_mb");
9297
obs_property_t *seekable = obs_properties_get(props, "seekable");
@@ -97,6 +102,8 @@ static bool is_local_file_modified(obs_properties_t *props,
97102
obs_property_set_visible(input_format, !enabled);
98103
obs_property_set_visible(buffering, !enabled);
99104
obs_property_set_visible(local_file, enabled);
105+
obs_property_set_visible(restart, !enabled);
106+
obs_property_set_visible(visibility_behaviour, enabled);
100107
obs_property_set_visible(looping, enabled);
101108
obs_property_set_visible(speed, enabled);
102109
obs_property_set_visible(seekable, !enabled);
@@ -105,12 +112,70 @@ static bool is_local_file_modified(obs_properties_t *props,
105112
return true;
106113
}
107114

115+
static bool is_visibility_behaviour_modified(obs_properties_t *props,
116+
obs_property_t *prop,
117+
obs_data_t *settings)
118+
{
119+
UNUSED_PARAMETER(prop);
120+
UNUSED_PARAMETER(props);
121+
122+
int visibility_behaviour =
123+
obs_data_get_int(settings, "visibility_behaviour");
124+
bool restart = true;
125+
bool pause = false;
126+
127+
if (visibility_behaviour == 1) { //Pause
128+
restart = false;
129+
pause = true;
130+
} else if (visibility_behaviour == 2) { //Continue
131+
restart = false;
132+
pause = false;
133+
}
134+
135+
obs_data_set_bool(settings, "restart_on_activate", restart);
136+
obs_data_set_bool(settings, "pause_on_deactivate", pause);
137+
138+
return true;
139+
}
140+
141+
static void update_visibility_behaviour_property_list(obs_data_t *settings)
142+
{
143+
144+
bool restart_on_activate =
145+
obs_data_get_bool(settings, "restart_on_activate");
146+
bool pause_on_deactivate =
147+
obs_data_get_bool(settings, "pause_on_deactivate");
148+
int visibility_behaviour = 2;
149+
150+
if (restart_on_activate == true) {
151+
visibility_behaviour = 0;
152+
} else if (pause_on_deactivate == true) {
153+
visibility_behaviour = 1;
154+
}
155+
156+
obs_data_set_int(settings, "visibility_behaviour",
157+
visibility_behaviour);
158+
}
159+
160+
static bool is_restart_on_activate_modified(obs_properties_t *props,
161+
obs_property_t *prop,
162+
obs_data_t *settings)
163+
{
164+
UNUSED_PARAMETER(prop);
165+
UNUSED_PARAMETER(props);
166+
167+
update_visibility_behaviour_property_list(settings);
168+
169+
return true;
170+
}
171+
108172
static void ffmpeg_source_defaults(obs_data_t *settings)
109173
{
110174
obs_data_set_default_bool(settings, "is_local_file", true);
111175
obs_data_set_default_bool(settings, "looping", false);
112176
obs_data_set_default_bool(settings, "clear_on_media_end", true);
113177
obs_data_set_default_bool(settings, "restart_on_activate", true);
178+
obs_data_set_default_bool(settings, "pause_on_deactivate", false);
114179
obs_data_set_default_bool(settings, "linear_alpha", false);
115180
obs_data_set_default_int(settings, "reconnect_delay_sec", 10);
116181
obs_data_set_default_int(settings, "buffering_mb", 2);
@@ -166,10 +231,29 @@ static obs_properties_t *ffmpeg_source_getproperties(void *data)
166231
dstr_free(&filter);
167232
dstr_free(&path);
168233

234+
prop = obs_properties_add_list(props, "visibility_behaviour",
235+
obs_module_text("PlaybackBehavior"),
236+
OBS_COMBO_TYPE_LIST,
237+
OBS_COMBO_FORMAT_INT);
238+
obs_property_list_add_int(
239+
prop, obs_module_text("PlaybackBehavior.StopRestart"), 0);
240+
obs_property_list_add_int(
241+
prop, obs_module_text("PlaybackBehavior.PauseUnpause"), 1);
242+
obs_property_list_add_int(
243+
prop, obs_module_text("PlaybackBehavior.AlwaysPlay"), 2);
244+
obs_property_set_modified_callback(prop,
245+
is_visibility_behaviour_modified);
246+
169247
obs_properties_add_bool(props, "looping", obs_module_text("Looping"));
170248

171-
obs_properties_add_bool(props, "restart_on_activate",
172-
obs_module_text("RestartWhenActivated"));
249+
prop = obs_properties_add_bool(props, "restart_on_activate",
250+
obs_module_text("RestartWhenActivated"));
251+
obs_property_set_modified_callback(prop,
252+
is_restart_on_activate_modified);
253+
254+
prop = obs_properties_add_bool(props, "pause_on_deactivate",
255+
"pause_on_deactivate");
256+
obs_property_set_visible(prop, false);
173257

174258
prop = obs_properties_add_int_slider(props, "buffering_mb",
175259
obs_module_text("BufferingMB"), 0,
@@ -244,6 +328,7 @@ static void dump_source_info(struct ffmpeg_source *s, const char *input,
244328
"\tis_hw_decoding: %s\n"
245329
"\tis_clear_on_media_end: %s\n"
246330
"\trestart_on_activate: %s\n"
331+
"\tpause_on_deactivate: %s\n"
247332
"\tclose_when_inactive: %s\n"
248333
"\tffmpeg_options: %s",
249334
input ? input : "(null)",
@@ -252,6 +337,7 @@ static void dump_source_info(struct ffmpeg_source *s, const char *input,
252337
s->is_hw_decoding ? "yes" : "no",
253338
s->is_clear_on_media_end ? "yes" : "no",
254339
s->restart_on_activate ? "yes" : "no",
340+
s->pause_on_deactivate ? "yes" : "no",
255341
s->close_when_inactive ? "yes" : "no", s->ffmpeg_options);
256342
}
257343

@@ -410,6 +496,8 @@ static void ffmpeg_source_update(void *data, obs_data_t *settings)
410496

411497
bool is_local_file = obs_data_get_bool(settings, "is_local_file");
412498

499+
update_visibility_behaviour_property_list(settings);
500+
413501
const char *input;
414502
const char *input_format;
415503
const char *ffmpeg_options;
@@ -457,6 +545,8 @@ static void ffmpeg_source_update(void *data, obs_data_t *settings)
457545
!astrcmpi_n(input, RIST_PROTO, sizeof(RIST_PROTO) - 1)
458546
? false
459547
: obs_data_get_bool(settings, "restart_on_activate");
548+
s->pause_on_deactivate =
549+
obs_data_get_bool(settings, "pause_on_deactivate");
460550
s->range = (enum video_range_type)obs_data_get_int(settings,
461551
"color_range");
462552
s->is_linear_alpha = obs_data_get_bool(settings, "linear_alpha");
@@ -670,6 +760,8 @@ static void ffmpeg_source_activate(void *data)
670760

671761
if (s->restart_on_activate)
672762
obs_source_media_restart(s->source);
763+
else if (s->pause_on_deactivate && s->state == OBS_MEDIA_STATE_PAUSED)
764+
obs_source_media_play_pause(s->source, false);
673765
}
674766

675767
static void ffmpeg_source_deactivate(void *data)
@@ -683,6 +775,9 @@ static void ffmpeg_source_deactivate(void *data)
683775
if (s->is_clear_on_media_end)
684776
obs_source_output_video(s->source, NULL);
685777
}
778+
} else if (s->pause_on_deactivate &&
779+
s->state == OBS_MEDIA_STATE_PLAYING) {
780+
obs_source_media_play_pause(s->source, true);
686781
}
687782
}
688783

0 commit comments

Comments
 (0)