diff options
author | Bing Song <bing.song@nxp.com> | 2021-01-27 10:55:13 +0800 |
---|---|---|
committer | GStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2021-03-04 14:04:43 +0000 |
commit | 89f193e1eb1a80dd859f28c89e2ba65e93b1277f (patch) | |
tree | 157079c05d3fc3e2ecf37f31607b9e515a546517 /tools | |
parent | 3730ea33660a56537998e8e061d91f4b4b4b18ef (diff) | |
download | gstreamer-plugins-bad-89f193e1eb1a80dd859f28c89e2ba65e93b1277f.tar.gz |
transcoder: handle SIGINT and SIGHUP
Handle SIGINT and SIGHUP in transcoder. Or the output file maybe corrupt.
Fixes #1507
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1987>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gst-transcoder.c | 56 |
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); |