Skip to content

Commit aee7323

Browse files
committed
Add Speed option
Media Source restarts when speed is modified so we have to add such warning. We have to disable refreshing properties on settings update because it will refresh while dragging the speed slider, making it almost impossible to use it. Thus we also add a button to refresh the current filename.
1 parent ca44546 commit aee7323

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

data/locale/en-US.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ SubtitleTrack="Subtitle Track"
2121
SelectFile="Select File"
2222
NoFileSelected="No File Selected"
2323
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."
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."
2525
CurrentFileName="Current File"
2626
VoskFilter="Vosk Speech Recognition"
27+
Speed="Speed"
28+
SpeedWarning="Changing the speed WILL restart the video"
29+
RefreshFilename="Refresh Filename"
2730

2831
MediaFileFilter.AllMediaFiles="All Media Files"
2932
MediaFileFilter.VideoFiles="Video Files"

src/media-playlist-source.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>
3030
#define S_CURRENT_FOLDER_ITEM_FILENAME "current_folder_item_filename"
3131
#define S_ID "id"
3232
#define S_IS_URL "is_url"
33+
#define S_SPEED "speed_percent"
34+
#define S_REFRESH_FILENAME "refresh_filename"
3335

3436
/* Media Source Settings */
3537
#define S_FFMPEG_LOCAL_FILE "local_file"
@@ -54,6 +56,9 @@ with this program. If not, see <https://www.gnu.org/licenses/>
5456
#define T_NO_FILE_SELECTED T_("NoFileSelected")
5557
#define T_FFMPEG_CLOSE_WHEN_INACTIVE T_("CloseFileWhenInactive")
5658
#define T_FFMPEG_CLOSE_WHEN_INACTIVE_TOOLTIP T_("CloseFileWhenInactive.Tooltip")
59+
#define T_SPEED T_("Speed")
60+
#define T_SPEED_WARNING T_("SpeedWarning")
61+
#define T_REFRESH_FILENAME T_("RefreshFilename")
5762

5863
#define T_PLAY_PAUSE T_("PlayPause")
5964
#define T_RESTART T_("Restart")
@@ -213,6 +218,7 @@ static void update_media_source(void *data, bool forced)
213218
!mps->actual_media->is_url);
214219
obs_data_set_string(settings, path_setting,
215220
mps->actual_media->path);
221+
obs_data_set_int(settings, S_SPEED, mps->speed);
216222
obs_source_update(media_source, settings);
217223
mps->user_stopped = false;
218224
}
@@ -413,6 +419,19 @@ static bool play_selected_clicked(obs_properties_t *props,
413419
return true;
414420
}
415421

422+
static bool refresh_filename_clicked(obs_properties_t *props,
423+
obs_property_t *property, void *data)
424+
{
425+
UNUSED_PARAMETER(props);
426+
UNUSED_PARAMETER(property);
427+
struct media_playlist_source *mps = data;
428+
obs_data_t *settings = obs_source_get_settings(mps->source);
429+
update_current_filename_setting(mps, settings);
430+
obs_source_update_properties(mps->source);
431+
obs_data_release(settings);
432+
return true;
433+
}
434+
416435
/* ------------------------------------------------------------------------- */
417436

418437
static const char *mps_getname(void *unused)
@@ -947,6 +966,7 @@ static void mps_defaults(obs_data_t *settings)
947966
obs_data_set_default_int(settings, S_RESTART_BEHAVIOR,
948967
RESTART_BEHAVIOR_CURRENT_FILE);
949968
obs_data_set_default_string(settings, S_CURRENT_FILE_NAME, " ");
969+
obs_data_set_default_int(settings, S_SPEED, 100);
950970
}
951971

952972
static void add_media_to_selection(obs_property_t *list,
@@ -1073,6 +1093,8 @@ static obs_properties_t *mps_properties(void *data)
10731093
"Due to OBS limitations, this will only update if any settings"
10741094
" are changed, the selected file is played, or the Properties "
10751095
"window is reopened. It will not update when the video ends.");
1096+
obs_properties_add_button(props, S_REFRESH_FILENAME, T_REFRESH_FILENAME,
1097+
refresh_filename_clicked);
10761098
//update_current_filename_property(mps, p);
10771099

10781100
p = obs_properties_add_list(props, S_SELECT_FILE, T_SELECT_FILE,
@@ -1088,6 +1110,11 @@ static obs_properties_t *mps_properties(void *data)
10881110
obs_properties_add_button(props, "play_selected", "Play Selected File",
10891111
play_selected_clicked);
10901112

1113+
p = obs_properties_add_int_slider(props, S_SPEED, T_SPEED, 1, 200, 1);
1114+
obs_property_int_set_suffix(p, "%");
1115+
p = obs_properties_add_text(props, "", T_SPEED_WARNING, OBS_TEXT_INFO);
1116+
obs_property_text_set_info_type(p, OBS_TEXT_INFO_WARNING);
1117+
10911118
obs_data_array_release(array);
10921119
obs_data_release(settings);
10931120

@@ -1175,6 +1202,7 @@ static void mps_update(void *data, obs_data_t *settings)
11751202
bool item_edited = false;
11761203
bool first_update = false;
11771204
const char *old_media_path = NULL;
1205+
long long new_speed;
11781206
//const char *mode;
11791207

11801208
/* ------------------------------------- */
@@ -1190,13 +1218,19 @@ static void mps_update(void *data, obs_data_t *settings)
11901218
mps->shuffle = shuffle;
11911219
mps->loop = obs_data_get_bool(settings, S_LOOP);
11921220
shuffler_set_loop(&mps->shuffler, mps->loop);
1221+
new_speed = obs_data_get_int(settings, S_SPEED);
1222+
if (mps->speed != new_speed) {
1223+
mps->user_stopped = true;
1224+
}
1225+
mps->speed = new_speed;
11931226

11941227
/* Internal media source settings */
11951228
mps->close_when_inactive =
11961229
obs_data_get_bool(settings, S_FFMPEG_CLOSE_WHEN_INACTIVE);
11971230
obs_data_t *media_source_settings = obs_data_create();
11981231
obs_data_set_bool(media_source_settings, S_FFMPEG_CLOSE_WHEN_INACTIVE,
11991232
mps->close_when_inactive);
1233+
obs_data_set_int(media_source_settings, S_SPEED, mps->speed);
12001234
obs_source_update(mps->current_media_source, media_source_settings);
12011235
obs_data_release(media_source_settings);
12021236

@@ -1336,7 +1370,6 @@ static void mps_update(void *data, obs_data_t *settings)
13361370

13371371
/* So Current File Name is updated */
13381372
update_current_filename_setting(mps, settings);
1339-
obs_source_update_properties(mps->source);
13401373
/* ------------------------- */
13411374

13421375
//if (mps->files.num) {

src/media-playlist-source.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct media_playlist_source {
6262
// to know if current_folder_item_index will be used, check if current file is a folder
6363
size_t current_folder_item_index;
6464
size_t last_id_count;
65+
long long speed;
6566

6667
obs_hotkey_id play_pause_hotkey;
6768
obs_hotkey_id restart_hotkey;

0 commit comments

Comments
 (0)