]> git.sesse.net Git - mlt/commitdiff
let melt be stopped gracefully by signal
authorDan Dennedy <dan@dennedy.org>
Sun, 19 Aug 2012 19:49:11 +0000 (12:49 -0700)
committerDan Dennedy <dan@dennedy.org>
Sun, 19 Aug 2012 19:49:11 +0000 (12:49 -0700)
src/melt/melt.c

index b784cf00de5a7841e64e8477bfc6f201b0007741..6cc0107071c5dc9b439f6ed29ef5e750725f06b0 100644 (file)
@@ -29,6 +29,7 @@
 #include <libgen.h>
 #include <limits.h>
 #include <unistd.h>
+#include <signal.h>
 
 #include <framework/mlt.h>
 
 
 #include "io.h"
 
+static mlt_producer melt = NULL;
+
+static void stop_handler(int signum)
+{
+       if ( melt )
+       {
+               mlt_properties properties = MLT_PRODUCER_PROPERTIES( melt );
+               mlt_properties_set_int( properties, "done", 1 );
+       }
+}
+
 static void transport_action( mlt_producer producer, char *value )
 {
        mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
@@ -662,7 +674,6 @@ int main( int argc, char **argv )
 {
        int i;
        mlt_consumer consumer = NULL;
-       mlt_producer melt = NULL;
        FILE *store = NULL;
        char *name = NULL;
        mlt_profile profile = NULL;
@@ -907,6 +918,12 @@ query_all:
                        mlt_events_listen( properties, consumer, "consumer-fatal-error", ( mlt_listener )on_fatal_error );
                        if ( mlt_consumer_start( consumer ) == 0 )
                        {
+                               // Try to exit gracefully upon these signals
+                               signal( SIGHUP, stop_handler );
+                               signal( SIGINT, stop_handler );
+                               signal( SIGPIPE, stop_handler );
+                               signal( SIGTERM, stop_handler );
+
                                // Transport functionality
                                transport( melt, consumer );