Skip to content

Commit 89f193e

Browse files
Bing SongGStreamer Marge Bot
Bing Song
authored and
GStreamer Marge Bot
committed
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>
1 parent 3730ea3 commit 89f193e

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tools/gst-transcoder.c

+56
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
#include "utils.h"
2424
#include <gst/transcoder/gsttranscoder.h>
25+
#ifdef G_OS_UNIX
26+
#include <glib-unix.h>
27+
#endif
2528

2629
static const gchar *HELP_SUMMARY =
2730
"gst-transcoder-1.0 transcodes a stream defined by its first <input-uri>\n"
@@ -65,6 +68,45 @@ typedef struct
6568
gchar *framerate;
6669
} Settings;
6770

71+
#ifdef G_OS_UNIX
72+
static guint signal_watch_hup_id;
73+
static guint signal_watch_intr_id;
74+
75+
static gboolean
76+
intr_handler (gpointer user_data)
77+
{
78+
GstTranscoder *self = GST_TRANSCODER (user_data);
79+
GstElement *pipeline = gst_transcoder_get_pipeline (self);
80+
81+
g_print ("handling interrupt.\n");
82+
83+
if (pipeline) {
84+
gst_element_send_event (pipeline, gst_event_new_eos ());
85+
g_object_unref (pipeline);
86+
}
87+
88+
signal_watch_intr_id = 0;
89+
return G_SOURCE_REMOVE;
90+
}
91+
92+
static gboolean
93+
hup_handler (gpointer user_data)
94+
{
95+
GstTranscoder *self = GST_TRANSCODER (user_data);
96+
GstElement *pipeline = gst_transcoder_get_pipeline (self);
97+
98+
g_print ("handling hang up.\n");
99+
100+
if (pipeline) {
101+
gst_element_send_event (pipeline, gst_event_new_eos ());
102+
g_object_unref (pipeline);
103+
}
104+
105+
signal_watch_intr_id = 0;
106+
return G_SOURCE_REMOVE;
107+
}
108+
#endif /* G_OS_UNIX */
109+
68110
static void
69111
position_updated_cb (GstTranscoder * transcoder, GstClockTime pos)
70112
{
@@ -385,12 +427,26 @@ main (int argc, char *argv[])
385427
transcoder);
386428

387429

430+
#ifdef G_OS_UNIX
431+
signal_watch_intr_id =
432+
g_unix_signal_add (SIGINT, (GSourceFunc) intr_handler, transcoder);
433+
signal_watch_hup_id =
434+
g_unix_signal_add (SIGHUP, (GSourceFunc) hup_handler, transcoder);
435+
#endif
436+
388437
ok ("Starting transcoding...");
389438
gst_transcoder_run (transcoder, &err);
390439
g_object_unref (signal_adapter);
391440
if (!err)
392441
ok ("\nDONE.");
393442

443+
#ifdef G_OS_UNIX
444+
if (signal_watch_intr_id > 0)
445+
g_source_remove (signal_watch_intr_id);
446+
if (signal_watch_hup_id > 0)
447+
g_source_remove (signal_watch_hup_id);
448+
#endif
449+
394450
done:
395451
g_free (settings.dest_uri);
396452
g_free (settings.src_uri);

0 commit comments

Comments
 (0)