From 8962899b77d6c9309ca80b0cdc06c8c9959a2cac Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 10 May 2017 19:53:03 -0700 Subject: [PATCH] obs-ffmpeg: Add signal/proc to restart media playback A convenient feature if the user wants to trigger the media to play back on the fly for whatever reason. --- plugins/obs-ffmpeg/data/locale/en-US.ini | 2 +- plugins/obs-ffmpeg/obs-ffmpeg-source.c | 30 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/plugins/obs-ffmpeg/data/locale/en-US.ini b/plugins/obs-ffmpeg/data/locale/en-US.ini index 3fc078840..468cd0c21 100644 --- a/plugins/obs-ffmpeg/data/locale/en-US.ini +++ b/plugins/obs-ffmpeg/data/locale/en-US.ini @@ -33,7 +33,7 @@ ColorRange="YUV Color Range" ColorRange.Auto="Auto" ColorRange.Partial="Partial" ColorRange.Full="Full" - +RestartMedia="Restart Media" MediaFileFilter.AllMediaFiles="All Media Files" MediaFileFilter.VideoFiles="Video Files" diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-source.c b/plugins/obs-ffmpeg/obs-ffmpeg-source.c index 8f58c1978..e59359a99 100644 --- a/plugins/obs-ffmpeg/obs-ffmpeg-source.c +++ b/plugins/obs-ffmpeg/obs-ffmpeg-source.c @@ -47,6 +47,7 @@ struct ffmpeg_source { int sws_linesize; enum video_range_type range; obs_source_t *source; + obs_hotkey_id hotkey; char *input; char *input_format; @@ -314,6 +315,25 @@ static const char *ffmpeg_source_getname(void *unused) return obs_module_text("FFMpegSource"); } +static bool restart_hotkey(void *data, obs_hotkey_id id, + obs_hotkey_t *hotkey, bool pressed) +{ + UNUSED_PARAMETER(id); + UNUSED_PARAMETER(hotkey); + UNUSED_PARAMETER(pressed); + + struct ffmpeg_source *s = data; + if (obs_source_active(s->source)) + ffmpeg_source_start(s); + return true; +} + +static void restart_proc(void *data, calldata_t *cd) +{ + restart_hotkey(data, 0, NULL, true); + UNUSED_PARAMETER(cd); +} + static void *ffmpeg_source_create(obs_data_t *settings, obs_source_t *source) { UNUSED_PARAMETER(settings); @@ -321,6 +341,14 @@ static void *ffmpeg_source_create(obs_data_t *settings, obs_source_t *source) struct ffmpeg_source *s = bzalloc(sizeof(struct ffmpeg_source)); s->source = source; + s->hotkey = obs_hotkey_register_source(source, + "MediaSource.Restart", + obs_module_text("RestartMedia"), + restart_hotkey, s); + + proc_handler_t *ph = obs_source_get_proc_handler(source); + proc_handler_add(ph, "void restart()", restart_proc, s); + ffmpeg_source_update(s, settings); return s; } @@ -329,6 +357,8 @@ static void ffmpeg_source_destroy(void *data) { struct ffmpeg_source *s = data; + if (s->hotkey) + obs_hotkey_unregister(s->hotkey); if (s->media_valid) mp_media_free(&s->media);