/*
* melt.c -- MLT command line utility
- * Copyright (C) 2002-2011 Ushodaya Enterprises Limited
+ * Copyright (C) 2002-2013 Ushodaya Enterprises Limited
* Authors: Charles Yates <charles.yates@pandora.be>
* Dan Dennedy <dan@dennedy.org>
*
#include <libgen.h>
#include <limits.h>
#include <unistd.h>
+#include <signal.h>
#include <framework/mlt.h>
-#if defined(__DARWIN__) || defined(WIN32)
+#if (defined(__DARWIN__) || defined(WIN32)) && !defined(MELT_NOSDL)
#include <SDL.h>
#endif
#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 abnormal_exit_handler(int signum)
+{
+ // The process is going down hard. Restore the terminal first.
+ term_exit();
+ // Reset the default handler so the core gets dumped.
+ signal( signum, SIG_DFL );
+ raise( signum );
+}
+
static void transport_action( mlt_producer producer, char *value )
{
mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
mlt_multitrack multitrack = mlt_properties_get_data( properties, "multitrack", NULL );
mlt_consumer consumer = mlt_properties_get_data( properties, "transport_consumer", NULL );
mlt_properties jack = mlt_properties_get_data( MLT_CONSUMER_PROPERTIES( consumer ), "jack_filter", NULL );
- mlt_position position = mlt_producer_position( producer );
+ mlt_position position = producer? mlt_producer_position( producer ) : 0;
mlt_properties_set_int( properties, "stats_off", 1 );
case '5':
mlt_producer_set_speed( producer, 0 );
mlt_consumer_purge( consumer );
+ mlt_producer_seek( producer, mlt_consumer_position( consumer ) + 1 );
mlt_events_fire( jack, "jack-stop", NULL );
break;
case '6':
static void load_consumer( mlt_consumer *consumer, mlt_profile profile, int argc, char **argv )
{
int i;
- for ( i = 1; i < argc; i ++ )
+ int multi = 0;
+ int qglsl = 0;
+
+ for ( i = 1; i < argc; i ++ ) {
+ // See if we need multi consumer.
+ multi += !strcmp( argv[i], "-consumer" );
+ // Seee if we need the qglsl variant of multi consumer.
+ if ( !strncmp( argv[i], "glsl.", 5 ) || !strncmp( argv[i], "movit.", 6 ) )
+ qglsl = 1;
+ }
+ // Disable qglsl if xgl is being used!
+ for ( i = 1; qglsl && i < argc; i ++ )
+ if ( !strcmp( argv[i], "xgl" ) )
+ qglsl = 0;
+
+ if ( multi > 1 || qglsl )
+ {
+ // If there is more than one -consumer use the 'multi' consumer.
+ int k = 0;
+ char key[20];
+
+ if ( *consumer )
+ mlt_consumer_close( *consumer );
+ *consumer = create_consumer( profile, ( qglsl? "qglsl" : "multi" ) );
+ mlt_properties properties = MLT_CONSUMER_PROPERTIES( *consumer );
+ for ( i = 1; i < argc; i ++ )
+ {
+ if ( !strcmp( argv[ i ], "-consumer" ) && argv[ i + 1 ])
+ {
+ // Create a properties object for each sub-consumer
+ mlt_properties new_props = mlt_properties_new();
+ snprintf( key, sizeof(key), "%d", k++ );
+ mlt_properties_set_data( properties, key, new_props, 0,
+ (mlt_destructor) mlt_properties_close, NULL );
+ if ( strchr( argv[i + 1], ':' ) )
+ {
+ char *temp = strdup( argv[++i] );
+ char *service = temp;
+ char *target = strchr( temp, ':' );
+ *target++ = 0;
+ mlt_properties_set( new_props, "mlt_service", service );
+ mlt_properties_set( new_props, "target", target );
+ }
+ else
+ {
+ mlt_properties_set( new_props, "mlt_service", argv[ ++i ] );
+ }
+ while ( argv[ i + 1 ] && strchr( argv[ i + 1 ], '=' ) )
+ mlt_properties_parse( new_props, argv[ ++ i ] );
+ }
+ }
+ }
+ else for ( i = 1; i < argc; i ++ )
{
if ( !strcmp( argv[ i ], "-consumer" ) )
{
if ( *consumer )
{
mlt_properties properties = MLT_CONSUMER_PROPERTIES( *consumer );
- while ( argv[ i + 1 ] != NULL && strstr( argv[ i + 1 ], "=" ) )
+ while ( argv[ i + 1 ] != NULL && strchr( argv[ i + 1 ], '=' ) )
mlt_properties_parse( properties, argv[ ++ i ] );
}
}
}
}
-#if defined(__DARWIN__) || defined(WIN32)
+#if (defined(__DARWIN__) || defined(WIN32)) && !defined(MELT_NOSDL)
static void event_handling( mlt_producer producer, mlt_consumer consumer )
{
mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
int silent = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "silent" );
int progress = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "progress" );
- struct timespec tm = { 0, 40000 };
+ struct timespec tm = { 0, 40000000 };
int total_length = mlt_producer_get_length( producer );
int last_position = 0;
transport_action( producer, string );
}
-#if defined(__DARWIN__) || defined(WIN32)
+#if (defined(__DARWIN__) || defined(WIN32)) && !defined(MELT_NOSDL)
event_handling( producer, consumer );
#endif
{
fprintf( stderr, "Current Position: %10d\r", (int)mlt_consumer_position( consumer ) );
}
+ fflush( stderr );
}
if ( silent || progress )
static void on_fatal_error( mlt_properties owner, mlt_consumer consumer )
{
- mlt_consumer_stop( consumer );
- exit( EXIT_FAILURE );
+ mlt_properties_set_int( MLT_CONSUMER_PROPERTIES(consumer), "done", 1 );
}
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;
int is_silent = 0;
mlt_profile backup_profile;
+ // Handle abnormal exit situations.
+ signal( SIGSEGV, abnormal_exit_handler );
+ signal( SIGILL, abnormal_exit_handler );
+ signal( SIGABRT, abnormal_exit_handler );
+
// Construct the factory
mlt_repository repo = mlt_factory_init( NULL );
-#ifdef WIN32
+#if defined(WIN32) && !defined(MELT_NOSDL)
is_silent = 1;
#endif
}
else if ( !strcmp( argv[ i ], "-version" ) || !strcmp( argv[ i ], "--version" ) )
{
- fprintf( stdout, "MLT %s " VERSION "\n"
- "Copyright (C) 2002-2011 Ushodaya Enterprises Limited\n"
+ fprintf( stdout, "%s " VERSION "\n"
+ "Copyright (C) 2002-2013 Ushodaya Enterprises Limited\n"
"<http://www.mltframework.org/>\n"
"This is free software; see the source for copying conditions. There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
mlt_log_set_level( MLT_LOG_DEBUG );
}
}
- if ( !is_silent && !isatty( STDIN_FILENO ) )
+ if ( !is_silent && !isatty( STDIN_FILENO ) && !is_progress )
is_progress = 1;
// Create profile if not set explicitly
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( SIGINT, stop_handler );
+ signal( SIGTERM, stop_handler );
+#ifndef WIN32
+ signal( SIGHUP, stop_handler );
+ signal( SIGPIPE, stop_handler );
+#endif
+
// Transport functionality
transport( melt, consumer );
// Disconnect producer from consumer to prevent ref cycles from closing services
if ( consumer )
+ {
mlt_consumer_connect( consumer, NULL );
+ mlt_events_fire( MLT_CONSUMER_PROPERTIES(consumer), "consumer-cleanup", NULL);
+ }
// Close the producer
if ( melt != NULL )
mlt_profile_close( profile );
exit_factory:
-
+
+// Workaround qmelt on OS X from crashing at exit.
+#if !defined(__MACH__) || !defined(QT_GUI_LIB)
mlt_factory_close( );
+#endif
return 0;
}