|
22 | 22 |
|
23 | 23 | #include "utils.h"
|
24 | 24 | #include <gst/transcoder/gsttranscoder.h>
|
| 25 | +#ifdef G_OS_UNIX |
| 26 | +#include <glib-unix.h> |
| 27 | +#endif |
25 | 28 |
|
26 | 29 | static const gchar *HELP_SUMMARY =
|
27 | 30 | "gst-transcoder-1.0 transcodes a stream defined by its first <input-uri>\n"
|
@@ -65,6 +68,45 @@ typedef struct
|
65 | 68 | gchar *framerate;
|
66 | 69 | } Settings;
|
67 | 70 |
|
| 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 | + |
68 | 110 | static void
|
69 | 111 | position_updated_cb (GstTranscoder * transcoder, GstClockTime pos)
|
70 | 112 | {
|
@@ -385,12 +427,26 @@ main (int argc, char *argv[])
|
385 | 427 | transcoder);
|
386 | 428 |
|
387 | 429 |
|
| 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 | + |
388 | 437 | ok ("Starting transcoding...");
|
389 | 438 | gst_transcoder_run (transcoder, &err);
|
390 | 439 | g_object_unref (signal_adapter);
|
391 | 440 | if (!err)
|
392 | 441 | ok ("\nDONE.");
|
393 | 442 |
|
| 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 | + |
394 | 450 | done:
|
395 | 451 | g_free (settings.dest_uri);
|
396 | 452 | g_free (settings.src_uri);
|
|
0 commit comments