summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/gst-transcoder.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/gst-transcoder.c b/tools/gst-transcoder.c
index 37bbe413f..9fcac13e6 100644
--- a/tools/gst-transcoder.c
+++ b/tools/gst-transcoder.c
@@ -22,6 +22,9 @@
#include "utils.h"
#include <gst/transcoder/gsttranscoder.h>
+#ifdef G_OS_UNIX
+#include <glib-unix.h>
+#endif
static const gchar *HELP_SUMMARY =
"gst-transcoder-1.0 transcodes a stream defined by its first <input-uri>\n"
@@ -65,6 +68,45 @@ typedef struct
gchar *framerate;
} Settings;
+#ifdef G_OS_UNIX
+static guint signal_watch_hup_id;
+static guint signal_watch_intr_id;
+
+static gboolean
+intr_handler (gpointer user_data)
+{
+ GstTranscoder *self = GST_TRANSCODER (user_data);
+ GstElement *pipeline = gst_transcoder_get_pipeline (self);
+
+ g_print ("handling interrupt.\n");
+
+ if (pipeline) {
+ gst_element_send_event (pipeline, gst_event_new_eos ());
+ g_object_unref (pipeline);
+ }
+
+ signal_watch_intr_id = 0;
+ return G_SOURCE_REMOVE;
+}
+
+static gboolean
+hup_handler (gpointer user_data)
+{
+ GstTranscoder *self = GST_TRANSCODER (user_data);
+ GstElement *pipeline = gst_transcoder_get_pipeline (self);
+
+ g_print ("handling hang up.\n");
+
+ if (pipeline) {
+ gst_element_send_event (pipeline, gst_event_new_eos ());
+ g_object_unref (pipeline);
+ }
+
+ signal_watch_intr_id = 0;
+ return G_SOURCE_REMOVE;
+}
+#endif /* G_OS_UNIX */
+
static void
position_updated_cb (GstTranscoder * transcoder, GstClockTime pos)
{
@@ -385,12 +427,26 @@ main (int argc, char *argv[])
transcoder);
+#ifdef G_OS_UNIX
+ signal_watch_intr_id =
+ g_unix_signal_add (SIGINT, (GSourceFunc) intr_handler, transcoder);
+ signal_watch_hup_id =
+ g_unix_signal_add (SIGHUP, (GSourceFunc) hup_handler, transcoder);
+#endif
+
ok ("Starting transcoding...");
gst_transcoder_run (transcoder, &err);
g_object_unref (signal_adapter);
if (!err)
ok ("\nDONE.");
+#ifdef G_OS_UNIX
+ if (signal_watch_intr_id > 0)
+ g_source_remove (signal_watch_intr_id);
+ if (signal_watch_hup_id > 0)
+ g_source_remove (signal_watch_hup_id);
+#endif
+
done:
g_free (settings.dest_uri);
g_free (settings.src_uri);