Skip to content

Commit ca44546

Browse files
committed
Add close file when inactive
1 parent cae418f commit ca44546

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

data/locale/en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ SubtitleEnabled="Subtitles Enabled"
2020
SubtitleTrack="Subtitle Track"
2121
SelectFile="Select File"
2222
NoFileSelected="No File Selected"
23+
CloseFileWhenInactive="Close file when inactive"
24+
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."
2325
CurrentFileName="Current File"
2426
VoskFilter="Vosk Speech Recognition"
2527

src/media-playlist-source.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
3535
#define S_FFMPEG_LOCAL_FILE "local_file"
3636
#define S_FFMPEG_INPUT "input"
3737
#define S_FFMPEG_IS_LOCAL_FILE "is_local_file"
38+
#define S_FFMPEG_CLOSE_WHEN_INACTIVE "close_when_inactive"
3839

3940
#define T_(text) obs_module_text(text)
4041
#define T_PLAYLIST T_("Playlist")
@@ -51,6 +52,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>
5152
#define T_CURRENT_FILE_NAME T_("CurrentFileName")
5253
#define T_SELECT_FILE T_("SelectFile")
5354
#define T_NO_FILE_SELECTED T_("NoFileSelected")
55+
#define T_FFMPEG_CLOSE_WHEN_INACTIVE T_("CloseFileWhenInactive")
56+
#define T_FFMPEG_CLOSE_WHEN_INACTIVE_TOOLTIP T_("CloseFileWhenInactive.Tooltip")
5457

5558
#define T_PLAY_PAUSE T_("PlayPause")
5659
#define T_RESTART T_("Restart")
@@ -1041,6 +1044,11 @@ static obs_properties_t *mps_properties(void *data)
10411044
obs_property_list_add_int(p, T_RESTART_BEHAVIOR_FIRST_FILE,
10421045
RESTART_BEHAVIOR_FIRST_FILE);
10431046

1047+
p = obs_properties_add_bool(props, S_FFMPEG_CLOSE_WHEN_INACTIVE,
1048+
T_FFMPEG_CLOSE_WHEN_INACTIVE);
1049+
obs_property_set_long_description(p,
1050+
T_FFMPEG_CLOSE_WHEN_INACTIVE_TOOLTIP);
1051+
10441052
dstr_copy(&filter, obs_module_text("MediaFileFilter.AllMediaFiles"));
10451053
dstr_cat(&filter, media_filter);
10461054
dstr_cat(&filter, obs_module_text("MediaFileFilter.VideoFiles"));
@@ -1160,8 +1168,6 @@ static void mps_update(void *data, obs_data_t *settings)
11601168
DARRAY(struct media_file_data) new_files;
11611169
DARRAY(struct media_file_data) old_files;
11621170
struct media_playlist_source *mps = data;
1163-
obs_data_t *media_source_settings =
1164-
obs_source_get_settings(mps->current_media_source);
11651171
obs_data_array_t *array;
11661172
size_t count;
11671173
bool shuffle = false;
@@ -1185,6 +1191,15 @@ static void mps_update(void *data, obs_data_t *settings)
11851191
mps->loop = obs_data_get_bool(settings, S_LOOP);
11861192
shuffler_set_loop(&mps->shuffler, mps->loop);
11871193

1194+
/* Internal media source settings */
1195+
mps->close_when_inactive =
1196+
obs_data_get_bool(settings, S_FFMPEG_CLOSE_WHEN_INACTIVE);
1197+
obs_data_t *media_source_settings = obs_data_create();
1198+
obs_data_set_bool(media_source_settings, S_FFMPEG_CLOSE_WHEN_INACTIVE,
1199+
mps->close_when_inactive);
1200+
obs_source_update(mps->current_media_source, media_source_settings);
1201+
obs_data_release(media_source_settings);
1202+
11881203
array = obs_data_get_array(settings, S_PLAYLIST);
11891204
count = obs_data_array_count(array);
11901205

@@ -1334,7 +1349,6 @@ static void mps_update(void *data, obs_data_t *settings)
13341349

13351350
// obs_source_media_started(mps->source);
13361351
//}
1337-
obs_data_release(media_source_settings);
13381352
obs_data_array_release(array);
13391353
}
13401354

src/media-playlist-source.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct media_playlist_source {
5252
bool loop;
5353
bool paused;
5454
bool user_stopped;
55+
bool close_when_inactive;
5556
pthread_mutex_t mutex;
5657
DARRAY(struct media_file_data) files;
5758
struct media_file_data *current_media; // only for file/folder in the list

0 commit comments

Comments
 (0)