X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_factory.c;h=4b92fe412eab40ffb6a715ab66686fa085387e65;hb=8de8411c3af4b5746e9040a67e928364be9ac058;hp=85da14847e0f866bc350c1fc15ec45c2262c7c3d;hpb=7fc1fe0a1e996da9ec4b7ff410a16c3560d60982;p=melted diff --git a/src/framework/mlt_factory.c b/src/framework/mlt_factory.c index 85da148..4b92fe4 100644 --- a/src/framework/mlt_factory.c +++ b/src/framework/mlt_factory.c @@ -30,11 +30,13 @@ */ 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; @@ -51,6 +57,15 @@ int mlt_factory_init( char *prefix ) // Store the prefix for later retrieval mlt_prefix = strdup( 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( ); @@ -72,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 ); @@ -97,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 ); } @@ -112,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 ); } @@ -123,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. */ @@ -144,9 +195,11 @@ 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; + mlt_pool_close( ); } }