X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_factory.c;h=552b8ce30304ce78715f211b1ec6008b8cc6a35e;hb=f4963a6aa07644399b273b5d2b1f9299c9047414;hp=709dc5ebfa09d1033e08ee2d92f5e86205a63b9a;hpb=d57832919959e117a68d856b172c090746fc3399;p=melted diff --git a/src/framework/mlt_factory.c b/src/framework/mlt_factory.c index 709dc5e..552b8ce 100644 --- a/src/framework/mlt_factory.c +++ b/src/framework/mlt_factory.c @@ -1,7 +1,9 @@ -/* - * mlt_factory.c -- the factory method interfaces - * Copyright (C) 2003-2004 Ushodaya Enterprises Limited - * Author: Charles Yates +/** + * \file mlt_factory.c + * \brief the factory method interfaces + * + * Copyright (C) 2003-2009 Ushodaya Enterprises Limited + * \author Charles Yates * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,7 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "config.h" #include "mlt.h" #include "mlt_repository.h" @@ -26,21 +27,32 @@ #include #include -/** Singleton repositories -*/ +/** the default subdirectory of the libdir for holding modules (plugins) */ +#define PREFIX_LIB LIBDIR "/mlt" +/** the default subdirectory of the install prefix for holding module (plugin) data */ +#define PREFIX_DATA PREFIX "/share/mlt" + -static char *mlt_prefix = NULL; +/** holds the full path to the modules directory - initialized and retained for the entire session */ +static char *mlt_directory = NULL; +/** a global properties list for holding environment config data and things needing session-oriented cleanup */ 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; +/** the global repository singleton */ +static mlt_repository repository = NULL; +/** the events object for the factory events */ static mlt_properties event_object = NULL; +/** for tracking the unique_id set on each constructed service */ static int unique_id = 0; -/** Event transmitters. -*/ +/* Event transmitters. */ + +/** the -create-request event transmitter + * + * \param listener + * \param owner + * \param this + * \param args + */ static void mlt_factory_create_request( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ) { @@ -48,30 +60,54 @@ static void mlt_factory_create_request( mlt_listener listener, mlt_properties ow listener( owner, this, ( char * )args[ 0 ], ( char * )args[ 1 ], ( mlt_service * )args[ 2 ] ); } +/** the -create-done event transmitter + * + * \param listener + * \param owner + * \param this + * \param args + */ + static void mlt_factory_create_done( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ) { if ( listener != NULL ) listener( owner, this, ( char * )args[ 0 ], ( char * )args[ 1 ], ( mlt_service )args[ 2 ] ); } -/** Construct the factories. -*/ +/** Construct the repository and factories. + * + * The environment variable MLT_PRODUCER is the name of a default producer often used by other services, defaults to "fezzil". + * + * The environment variable MLT_CONSUMER is the name of a default consumer, defaults to "sdl". + * + * The environment variable MLT_TEST_CARD is the name of a producer or file to be played when nothing is available (all tracks blank). + * + * The environment variable MLT_DATA overrides the default full path to the MLT and module supplemental data files, defaults to \p PREFIX_DATA. + * + * The environment variable MLT_PROFILE defaults to "dv_pal." + * + * The environment variable MLT_REPOSITORY overrides the default location of the plugin modules, defaults to \p PREFIX_LIB. + * + * \param directory an optional full path to a directory containing the modules that overrides the default and + * the MLT_REPOSITORY environment variable + * \return the repository + */ -int mlt_factory_init( const char *prefix ) +mlt_repository mlt_factory_init( const char *directory ) { // Only initialise once - if ( mlt_prefix == NULL ) + if ( mlt_directory == NULL ) { // Allow user over rides - if ( prefix == NULL || !strcmp( prefix, "" ) ) - prefix = getenv( "MLT_REPOSITORY" ); + if ( directory == NULL || !strcmp( directory, "" ) ) + directory = getenv( "MLT_REPOSITORY" ); // If no directory is specified, default to install directory - if ( prefix == NULL ) - prefix = PREFIX_DATA; + if ( directory == NULL ) + directory = PREFIX_LIB; // Store the prefix for later retrieval - mlt_prefix = strdup( prefix ); + mlt_directory = strdup( directory ); // Initialise the pool mlt_pool_init( ); @@ -91,14 +127,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( directory ); // Force a clean up when app closes atexit( mlt_factory_close ); @@ -112,61 +142,91 @@ 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" ); + mlt_properties_set_or_default( global_properties, "MLT_DATA", getenv( "MLT_DATA" ), PREFIX_DATA ); } - return 0; + return repository; } /** Fetch the events object. -*/ + * + * \return the global factory event object + */ mlt_properties mlt_factory_event_object( ) { return event_object; } -/** Fetch the prefix used in this instance. -*/ +/** Fetch the module directory used in this instance. + * + * \return the full path to the module directory that this session is using + */ -const char *mlt_factory_prefix( ) +const char *mlt_factory_directory( ) { - return mlt_prefix; + return mlt_directory; } /** Get a value from the environment. -*/ + * + * \param name the name of a MLT (runtime configuration) environment variable + * \return the value of the variable + */ 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. -*/ + * + * \param name the name of a MLT environment variable + * \param value the value of the variable + * \return true on error + */ int mlt_environment_set( const char *name, const char *value ) { - return mlt_properties_set( global_properties, name, value ); + if ( global_properties ) + return mlt_properties_set( global_properties, name, value ); + else + return -1; +} + +/** Set some properties common to all services. + * + * This sets _unique_id, \p mlt_type, \p mlt_service (unless _mlt_service_hidden), and _profile. + * + * \param properties a service's properties list + * \param profile the \p mlt_profile supplied to the factory function + * \param type the MLT service class + * \param service the name of the service + */ + +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. -*/ + * + * \param profile the \p mlt_profile to use + * \param service the name of the producer (optional, defaults to MLT_PRODUCER) + * \param input an optional argument to the producer constructor, typically a string + * \return a new producer + */ -mlt_producer mlt_factory_producer( const char *service, void *input ) +mlt_producer mlt_factory_producer( mlt_profile profile, const char *service, const void *input ) { mlt_producer obj = NULL; @@ -180,24 +240,26 @@ 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_create( 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; } /** Fetch a filter from the repository. -*/ + * + * \param profile the \p mlt_profile to use + * \param service the name of the filter + * \param input an optional argument to the filter constructor, typically a string + * \return a new filter + */ -mlt_filter mlt_factory_filter( const char *service, void *input ) +mlt_filter mlt_factory_filter( mlt_profile profile, const char *service, const void *input ) { mlt_filter obj = NULL; @@ -206,24 +268,27 @@ mlt_filter mlt_factory_filter( const char *service, void *input ) if ( obj == NULL ) { - obj = mlt_repository_fetch( filters, service, input ); + obj = mlt_repository_create( 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; } /** Fetch a transition from the repository. -*/ + * + * \param profile the \p mlt_profile to use + * \param service the name of the transition + * \param input an optional argument to the transition constructor, typically a string + * \return a new transition + */ -mlt_transition mlt_factory_transition( const char *service, void *input ) +mlt_transition mlt_factory_transition( mlt_profile profile, const char *service, const void *input ) { mlt_transition obj = NULL; @@ -232,24 +297,27 @@ mlt_transition mlt_factory_transition( const char *service, void *input ) if ( obj == NULL ) { - obj = mlt_repository_fetch( transitions, service, input ); + obj = mlt_repository_create( 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; } -/** Fetch a consumer from the repository -*/ +/** Fetch a consumer from the repository. + * + * \param profile the \p mlt_profile to use + * \param service the name of the consumer (optional, defaults to MLT_CONSUMER) + * \param input an optional argument to the consumer constructor, typically a string + * \return a new consumer + */ -mlt_consumer mlt_factory_consumer( const char *service, void *input ) +mlt_consumer mlt_factory_consumer( mlt_profile profile, const char *service, const void *input ) { mlt_consumer obj = NULL; @@ -261,22 +329,23 @@ mlt_consumer mlt_factory_consumer( const char *service, void *input ) if ( obj == NULL ) { - obj = mlt_repository_fetch( consumers, service, input ); + obj = mlt_repository_create( 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; } /** Register an object for clean up. -*/ + * + * \param ptr an opaque pointer to anything allocated on the heap + * \param destructor the function pointer of the deallocation subroutine (e.g., free or \p mlt_pool_release) + */ void mlt_factory_register_for_clean_up( void *ptr, mlt_destructor destructor ) { @@ -286,22 +355,24 @@ void mlt_factory_register_for_clean_up( void *ptr, mlt_destructor destructor ) } /** Close the factory. -*/ + * + * Cleanup all resources for the session. + */ void mlt_factory_close( ) { - if ( mlt_prefix != NULL ) + if ( mlt_directory != 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 ); - free( mlt_prefix ); - mlt_prefix = NULL; + mlt_repository_close( repository ); + free( mlt_directory ); + mlt_directory = NULL; mlt_pool_close( ); - mlt_profile_close(); } } + +mlt_properties mlt_global_properties( ) +{ + return global_properties; +}