X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fframework%2Fmlt_factory.c;h=b49f16b4b4dc1e19fe0efb6530a48096f28a12d2;hb=7a813d44afa9d1d1639b64610f7b28156c13c595;hp=d7c6f000254dccf53b7324b84057aa619d3bf6b6;hpb=6967e58ddd118f3fd0e071cfaeff89c56fd612c5;p=mlt diff --git a/src/framework/mlt_factory.c b/src/framework/mlt_factory.c index d7c6f000..b49f16b4 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 @@ -24,39 +26,117 @@ #include #include #include - -#define PREFIX_LIB LIBDIR "/mlt" -#define PREFIX_DATA PREFIX "/share/mlt" - -/** Singleton repositories -*/ - +#include +#include + +#ifdef WIN32 +#include +/** the default subdirectory of the libdir for holding modules (plugins) */ +#define PREFIX_LIB "\\lib\\mlt" +/** the default subdirectory of the install prefix for holding module (plugin) data */ +#define PREFIX_DATA "\\share\\mlt" +#elif defined(__DARWIN__) && defined(RELOCATABLE) +#include +/** the default subdirectory of the libdir for holding modules (plugins) */ +#define PREFIX_LIB "/lib/mlt" +/** the default subdirectory of the install prefix for holding module (plugin) data */ +#define PREFIX_DATA "/share/mlt" +#endif + +/** 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; +/** 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 self + * \param args + */ -static void mlt_factory_create_request( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ) +static void mlt_factory_create_request( mlt_listener listener, mlt_properties owner, mlt_service self, void **args ) { if ( listener != NULL ) - listener( owner, this, ( char * )args[ 0 ], ( char * )args[ 1 ], ( mlt_service * )args[ 2 ] ); + listener( owner, self, ( char * )args[ 0 ], ( char * )args[ 1 ], ( mlt_service * )args[ 2 ] ); } -static void mlt_factory_create_done( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ) +/** the -create-done event transmitter + * + * \param listener + * \param owner + * \param self + * \param args + */ + +static void mlt_factory_create_done( mlt_listener listener, mlt_properties owner, mlt_service self, void **args ) { if ( listener != NULL ) - listener( owner, this, ( char * )args[ 0 ], ( char * )args[ 1 ], ( mlt_service )args[ 2 ] ); + listener( owner, self, ( 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 "loader". + * + * 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 + */ mlt_repository mlt_factory_init( const char *directory ) { + // Load the system locales + setlocale( LC_ALL, "" ); + + if ( ! global_properties ) + global_properties = mlt_properties_new( ); + + // Allow property refresh on a subsequent initialisation + if ( global_properties ) + { + 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" ), "loader" ); + 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" ); + mlt_properties_set_or_default( global_properties, "MLT_DATA", getenv( "MLT_DATA" ), PREFIX_DATA ); +#if defined(WIN32) + char path[1024]; + DWORD size = sizeof( path ); + GetModuleFileName( NULL, path, size ); +#elif defined(__DARWIN__) && defined(RELOCATABLE) + char path[1024]; + uint32_t size = sizeof( path ); + _NSGetExecutablePath( path, &size ); +#endif +#if defined(WIN32) || (defined(__DARWIN__) && defined(RELOCATABLE)) + char *path2 = strdup( path ); + char *appdir = dirname( path2 ); + mlt_properties_set( global_properties, "MLT_APPDIR", appdir ); + free( path2 ); +#endif + } + // Only initialise once if ( mlt_directory == NULL ) { @@ -69,8 +149,24 @@ mlt_repository mlt_factory_init( const char *directory ) directory = PREFIX_LIB; // Store the prefix for later retrieval +#if defined(WIN32) || (defined(__DARWIN__) && defined(RELOCATABLE)) + char *exedir = mlt_environment( "MLT_APPDIR" ); + size_t size = strlen( exedir ); + if ( global_properties && !getenv( "MLT_DATA" ) ) + { + mlt_directory = calloc( 1, size + strlen( PREFIX_DATA ) + 1 ); + strcpy( mlt_directory, exedir ); + strcat( mlt_directory, PREFIX_DATA ); + mlt_properties_set( global_properties, "MLT_DATA", mlt_directory ); + free( mlt_directory ); + } + mlt_directory = calloc( 1, size + strlen( directory ) + 1 ); + strcpy( mlt_directory, exedir ); + strcat( mlt_directory, directory ); +#else mlt_directory = strdup( directory ); - +#endif + // Initialise the pool mlt_pool_init( ); @@ -86,33 +182,20 @@ mlt_repository mlt_factory_init( const char *directory ) mlt_events_register( event_object, "consumer-create-request", ( mlt_transmitter )mlt_factory_create_request ); mlt_events_register( event_object, "consumer-create-done", ( mlt_transmitter )mlt_factory_create_done ); - // Create the global properties - global_properties = mlt_properties_new( ); - // Create the repository of services - repository = mlt_repository_init( directory ); + repository = mlt_repository_init( mlt_directory ); // Force a clean up when app closes atexit( mlt_factory_close ); } - // Allow property refresh on a subsequent initialisation - if ( global_properties != NULL ) - { - 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" ); - 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" ); - mlt_properties_set_or_default( global_properties, "MLT_DATA", getenv( "MLT_DATA" ), PREFIX_DATA ); - } - - return repository; } /** Fetch the events object. -*/ + * + * \return the global factory event object + */ mlt_properties mlt_factory_event_object( ) { @@ -120,7 +203,9 @@ mlt_properties mlt_factory_event_object( ) } /** 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_directory( ) { @@ -128,7 +213,10 @@ const char *mlt_factory_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 ) { @@ -139,7 +227,11 @@ char *mlt_environment( const char *name ) } /** 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 ) { @@ -149,6 +241,16 @@ int mlt_environment_set( const char *name, const char *value ) 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 ); @@ -160,9 +262,14 @@ static void set_common_properties( mlt_properties properties, mlt_profile profil } /** 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( mlt_profile profile, const char *service, void *input ) +mlt_producer mlt_factory_producer( mlt_profile profile, const char *service, const void *input ) { mlt_producer obj = NULL; @@ -188,9 +295,14 @@ mlt_producer mlt_factory_producer( mlt_profile profile, const char *service, voi } /** 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( mlt_profile profile, const char *service, void *input ) +mlt_filter mlt_factory_filter( mlt_profile profile, const char *service, const void *input ) { mlt_filter obj = NULL; @@ -212,9 +324,14 @@ mlt_filter mlt_factory_filter( mlt_profile profile, const char *service, void *i } /** 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( mlt_profile profile, const char *service, void *input ) +mlt_transition mlt_factory_transition( mlt_profile profile, const char *service, const void *input ) { mlt_transition obj = NULL; @@ -235,10 +352,15 @@ mlt_transition mlt_factory_transition( mlt_profile profile, const char *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( mlt_profile profile, const char *service, void *input ) +mlt_consumer mlt_factory_consumer( mlt_profile profile, const char *service, const void *input ) { mlt_consumer obj = NULL; @@ -263,7 +385,10 @@ mlt_consumer mlt_factory_consumer( mlt_profile profile, const char *service, voi } /** 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 ) { @@ -273,17 +398,34 @@ 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_directory != NULL ) { mlt_properties_close( event_object ); + event_object = NULL; +#if !defined(WIN32) + // XXX something in here is causing Shotcut/Win32 to not exit completely + // under certain conditions: e.g. play a playlist. mlt_properties_close( global_properties ); - mlt_repository_close( repository ); + global_properties = NULL; +#endif + if ( repository ) + { + mlt_repository_close( repository ); + repository = NULL; + } free( mlt_directory ); mlt_directory = NULL; mlt_pool_close( ); } } + +mlt_properties mlt_global_properties( ) +{ + return global_properties; +}