]> git.sesse.net Git - mlt/blobdiff - src/framework/mlt_factory.c
consumer avformat added, various cleanups and consumer realtime switching
[mlt] / src / framework / mlt_factory.c
index cbd41e9521156902688e5eb4745aa0302e655c0b..4b92fe412eab40ffb6a715ab66686fa085387e65 100644 (file)
 */
 
 static char *mlt_prefix = NULL;
+static mlt_properties global_properties = NULL;
 static mlt_properties object_list = NULL;
 static mlt_repository producers = NULL;
 static mlt_repository filters = NULL;
 static mlt_repository transitions = NULL;
 static mlt_repository consumers = NULL;
+static int unique_id = 0;
 
 /** Construct the factories.
 */
@@ -44,6 +46,10 @@ int mlt_factory_init( char *prefix )
        // Only initialise once
        if ( mlt_prefix == NULL )
        {
+               // Allow user over rides
+               if ( prefix == NULL )
+                       prefix = getenv( "MLT_REPOSITORY" );
+
                // If no directory is specified, default to install directory
                if ( prefix == NULL )
                        prefix = PREFIX_DATA;
@@ -54,6 +60,12 @@ int mlt_factory_init( char *prefix )
                // Initialise the pool
                mlt_pool_init( );
 
+               // Create the global properties
+               global_properties = mlt_properties_new( );
+               mlt_properties_set_or_default( global_properties, "MLT_NORMALISATION", getenv( "MLT_NORMALISATION" ), "PAL" );
+               mlt_properties_set_or_default( global_properties, "MLT_PRODUCER", getenv( "MLT_PRODUCER" ), "fezzik" );
+               mlt_properties_set_or_default( global_properties, "MLT_CONSUMER", getenv( "MLT_CONSUMER" ), "sdl" );
+
                // Create the object list.
                object_list = mlt_properties_new( );
 
@@ -75,15 +87,32 @@ const char *mlt_factory_prefix( )
        return mlt_prefix;
 }
 
+/** Get a value from the environment.
+*/
+
+char *mlt_environment( char *name )
+{
+       return mlt_properties_get( global_properties, name );
+}
+
 /** Fetch a producer from the repository.
 */
 
 mlt_producer mlt_factory_producer( char *service, void *input )
 {
-       mlt_producer obj = mlt_repository_fetch( producers, service, input );
+       mlt_producer obj = NULL;
+
+       // Pick up the default normalising producer if necessary
+       if ( service == NULL )
+               service = mlt_environment( "MLT_PRODUCER" );
+
+       // Try to instantiate via the specified service
+       obj = mlt_repository_fetch( producers, service, input );
+
        if ( obj != NULL )
        {
                mlt_properties properties = mlt_producer_properties( obj );
+               mlt_properties_set_int( properties, "_unique_id", ++ unique_id );
                mlt_properties_set( properties, "mlt_type", "producer" );
                if ( mlt_properties_get_int( properties, "_mlt_service_hidden" ) == 0 )
                        mlt_properties_set( properties, "mlt_service", service );
@@ -100,6 +129,7 @@ mlt_filter mlt_factory_filter( char *service, void *input )
        if ( obj != NULL )
        {
                mlt_properties properties = mlt_filter_properties( obj );
+               mlt_properties_set_int( properties, "_unique_id", ++ unique_id );
                mlt_properties_set( properties, "mlt_type", "filter" );
                mlt_properties_set( properties, "mlt_service", service );
        }
@@ -115,6 +145,7 @@ mlt_transition mlt_factory_transition( char *service, void *input )
        if ( obj != NULL )
        {
                mlt_properties properties = mlt_transition_properties( obj );
+               mlt_properties_set_int( properties, "_unique_id", ++ unique_id );
                mlt_properties_set( properties, "mlt_type", "transition" );
                mlt_properties_set( properties, "mlt_service", service );
        }
@@ -126,16 +157,33 @@ mlt_transition mlt_factory_transition( char *service, void *input )
 
 mlt_consumer mlt_factory_consumer( char *service, void *input )
 {
-       mlt_consumer obj = mlt_repository_fetch( consumers, service, input );
+       mlt_consumer obj = NULL;
+
+       if ( service == NULL )
+               service = mlt_environment( "MLT_CONSUMER" );
+
+       obj = mlt_repository_fetch( consumers, service, input );
+
        if ( obj != NULL )
        {
                mlt_properties properties = mlt_consumer_properties( obj );
+               mlt_properties_set_int( properties, "_unique_id", ++ unique_id );
                mlt_properties_set( properties, "mlt_type", "consumer" );
                mlt_properties_set( properties, "mlt_service", service );
        }
        return obj;
 }
 
+/** Register an object for clean up.
+*/
+
+void mlt_factory_register_for_clean_up( void *ptr, mlt_destructor destructor )
+{
+       char unique[ 256 ];
+       sprintf( unique, "%08d", mlt_properties_count( global_properties ) );
+       mlt_properties_set_data( global_properties, unique, ptr, 0, destructor, NULL );
+}
+
 /** Close the factory.
 */
 
@@ -147,6 +195,7 @@ void mlt_factory_close( )
                mlt_repository_close( filters );
                mlt_repository_close( transitions );
                mlt_repository_close( consumers );
+               mlt_properties_close( global_properties );
                mlt_properties_close( object_list );
                free( mlt_prefix );
                mlt_prefix = NULL;