浏览代码

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.
jp9000 8 年之前
父节点
当前提交
8962899b77
共有 2 个文件被更改,包括 31 次插入1 次删除
  1. 1 1
      plugins/obs-ffmpeg/data/locale/en-US.ini
  2. 30 0
      plugins/obs-ffmpeg/obs-ffmpeg-source.c

+ 1 - 1
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"

+ 30 - 0
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);