X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_factory.c;h=ec885b6e79478a732a7e4485a03600b0f7ad7aaf;hb=16b6d374cf80004b192aae74a55b0452c7ee809d;hp=124526575533c3242c31c14734cf2b1f7999243a;hpb=40b169c095486ba1b868486eb98a47c41f36ce8c;p=melted diff --git a/src/framework/mlt_factory.c b/src/framework/mlt_factory.c index 1245265..ec885b6 100644 --- a/src/framework/mlt_factory.c +++ b/src/framework/mlt_factory.c @@ -18,7 +18,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "config.h" #include "mlt.h" #include "mlt_repository.h" @@ -26,16 +25,15 @@ #include #include +#define PREFIX_LIB LIBDIR "/mlt" +#define PREFIX_DATA PREFIX "/share/mlt" + /** Singleton repositories */ 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 mlt_repository repository = NULL; static mlt_properties event_object = NULL; static int unique_id = 0; @@ -57,7 +55,7 @@ static void mlt_factory_create_done( mlt_listener listener, mlt_properties owner /** Construct the factories. */ -int mlt_factory_init( const char *prefix ) +mlt_repository mlt_factory_init( const char *prefix ) { // Only initialise once if ( mlt_prefix == NULL ) @@ -68,7 +66,7 @@ int mlt_factory_init( const char *prefix ) // If no directory is specified, default to install directory if ( prefix == NULL ) - prefix = PREFIX_DATA; + prefix = PREFIX_LIB; // Store the prefix for later retrieval mlt_prefix = strdup( prefix ); @@ -91,14 +89,8 @@ int mlt_factory_init( const char *prefix ) // Create the global properties global_properties = mlt_properties_new( ); - // Create the object list. - object_list = mlt_properties_new( ); - - // Create a repository for each service type - producers = mlt_repository_init( object_list, prefix, "producers", "mlt_create_producer" ); - filters = mlt_repository_init( object_list, prefix, "filters", "mlt_create_filter" ); - transitions = mlt_repository_init( object_list, prefix, "transitions", "mlt_create_transition" ); - consumers = mlt_repository_init( object_list, prefix, "consumers", "mlt_create_consumer" ); + // Create the repository of services + repository = mlt_repository_init( prefix ); // Force a clean up when app closes atexit( mlt_factory_close ); @@ -112,37 +104,11 @@ int mlt_factory_init( const char *prefix ) mlt_properties_set_or_default( global_properties, "MLT_CONSUMER", getenv( "MLT_CONSUMER" ), "sdl" ); mlt_properties_set( global_properties, "MLT_TEST_CARD", getenv( "MLT_TEST_CARD" ) ); mlt_properties_set_or_default( global_properties, "MLT_PROFILE", getenv( "MLT_PROFILE" ), "dv_pal" ); - - // Load the most appropriate profile - // MLT_PROFILE preferred - if ( getenv( "MLT_PROFILE" ) ) - { - if ( !mlt_profile_select( mlt_environment( "MLT_PROFILE" ) ) ) - mlt_profile_load_file( mlt_environment( "MLT_PROFILE" ) ); - } - // MLT_NORMALISATION backwards compatibility - else if ( strcmp( mlt_environment( "MLT_NORMALISATION" ), "PAL" ) ) - mlt_profile_select( "dv_ntsc" ); - else - mlt_profile_select( "dv_pal" ); - - // destroy an invalid profile so it can be constructed from hard defauls - if ( mlt_profile_get()->width == 0 ) - mlt_profile_close(); - - // Set MLT_NORMALISATION to appease legacy modules - if ( !getenv( "MLT_NORMALISATION" ) ) - { - const char *profile = mlt_profile_get()->name; - if ( strstr( profile, "_ntsc" ) || strstr( profile, "_atsc" ) ) - setenv( "MLT_NORMALISATION", "NTSC", 1 ); - else if ( strstr( profile, "_pal" ) ) - setenv( "MLT_NORMALISATION", "PAL", 1 ); - } + mlt_properties_set_or_default( global_properties, "MLT_DATA", getenv( "MLT_DATA" ), PREFIX_DATA ); } - return 0; + return repository; } /** Fetch the events object. @@ -166,13 +132,37 @@ const char *mlt_factory_prefix( ) char *mlt_environment( const char *name ) { - return mlt_properties_get( global_properties, name ); + if ( global_properties ) + return mlt_properties_get( global_properties, name ); + else + return NULL; +} + +/** Set a value in the environment. +*/ + +int mlt_environment_set( const char *name, const char *value ) +{ + if ( global_properties ) + return mlt_properties_set( global_properties, name, value ); + else + return -1; +} + +static void set_common_properties( mlt_properties properties, mlt_profile profile, const char *type, const char *service ) +{ + mlt_properties_set_int( properties, "_unique_id", ++ unique_id ); + mlt_properties_set( properties, "mlt_type", type ); + if ( mlt_properties_get_int( properties, "_mlt_service_hidden" ) == 0 ) + mlt_properties_set( properties, "mlt_service", service ); + if ( profile != NULL ) + mlt_properties_set_data( properties, "_profile", profile, 0, NULL, NULL ); } /** Fetch a producer from the repository. */ -mlt_producer mlt_factory_producer( const char *service, void *input ) +mlt_producer mlt_factory_producer( mlt_profile profile, const char *service, void *input ) { mlt_producer obj = NULL; @@ -186,15 +176,12 @@ mlt_producer mlt_factory_producer( const char *service, void *input ) // Try to instantiate via the specified service if ( obj == NULL ) { - obj = mlt_repository_fetch( producers, service, input ); + obj = mlt_repository_fetch( repository, profile, producer_type, service, input ); mlt_events_fire( event_object, "producer-create-done", service, input, obj, NULL ); 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 ); + set_common_properties( properties, profile, "producer", service ); } } return obj; @@ -203,7 +190,7 @@ mlt_producer mlt_factory_producer( const char *service, void *input ) /** Fetch a filter from the repository. */ -mlt_filter mlt_factory_filter( const char *service, void *input ) +mlt_filter mlt_factory_filter( mlt_profile profile, const char *service, void *input ) { mlt_filter obj = NULL; @@ -212,16 +199,14 @@ mlt_filter mlt_factory_filter( const char *service, void *input ) if ( obj == NULL ) { - obj = mlt_repository_fetch( filters, service, input ); + obj = mlt_repository_fetch( repository, profile, filter_type, service, input ); mlt_events_fire( event_object, "filter-create-done", service, input, obj, NULL ); } 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 ); + set_common_properties( properties, profile, "filter", service ); } return obj; } @@ -229,7 +214,7 @@ mlt_filter mlt_factory_filter( const char *service, void *input ) /** Fetch a transition from the repository. */ -mlt_transition mlt_factory_transition( const char *service, void *input ) +mlt_transition mlt_factory_transition( mlt_profile profile, const char *service, void *input ) { mlt_transition obj = NULL; @@ -238,16 +223,14 @@ mlt_transition mlt_factory_transition( const char *service, void *input ) if ( obj == NULL ) { - obj = mlt_repository_fetch( transitions, service, input ); + obj = mlt_repository_fetch( repository, profile, transition_type, service, input ); mlt_events_fire( event_object, "transition-create-done", service, input, obj, NULL ); } 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 ); + set_common_properties( properties, profile, "transition", service ); } return obj; } @@ -255,7 +238,7 @@ mlt_transition mlt_factory_transition( const char *service, void *input ) /** Fetch a consumer from the repository */ -mlt_consumer mlt_factory_consumer( const char *service, void *input ) +mlt_consumer mlt_factory_consumer( mlt_profile profile, const char *service, void *input ) { mlt_consumer obj = NULL; @@ -267,16 +250,14 @@ mlt_consumer mlt_factory_consumer( const char *service, void *input ) if ( obj == NULL ) { - obj = mlt_repository_fetch( consumers, service, input ); + obj = mlt_repository_fetch( repository, profile, consumer_type, service, input ); mlt_events_fire( event_object, "consumer-create-done", service, input, obj, NULL ); } 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 ); + set_common_properties( properties, profile, "consumer", service ); } return obj; } @@ -299,15 +280,10 @@ void mlt_factory_close( ) if ( mlt_prefix != NULL ) { mlt_properties_close( event_object ); - mlt_repository_close( producers ); - mlt_repository_close( filters ); - mlt_repository_close( transitions ); - mlt_repository_close( consumers ); mlt_properties_close( global_properties ); - mlt_properties_close( object_list ); + mlt_repository_close( repository ); free( mlt_prefix ); mlt_prefix = NULL; mlt_pool_close( ); - mlt_profile_close(); } }