mlt_repository.[hc]:
[melted] / src / framework / mlt_factory.c
index 0b4508c..ec885b6 100644 (file)
@@ -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"
 
 #include <stdlib.h>
 #include <string.h>
 
+#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,10 +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" );
+               mlt_properties_set_or_default( global_properties, "MLT_DATA", getenv( "MLT_DATA" ), PREFIX_DATA );
        }
 
 
-       return 0;
+       return repository;
 }
 
 /** Fetch the events object.
@@ -139,7 +132,10 @@ 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.
@@ -180,7 +176,7 @@ mlt_producer mlt_factory_producer( mlt_profile profile, const char *service, voi
        // Try to instantiate via the specified service
        if ( obj == NULL )
        {
-               obj = mlt_repository_fetch( producers, profile, producer_type, 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 )
                {
@@ -203,7 +199,7 @@ mlt_filter mlt_factory_filter( mlt_profile profile, const char *service, void *i
 
        if ( obj == NULL )
        {
-               obj = mlt_repository_fetch( filters, profile, filter_type, service, input );
+               obj = mlt_repository_fetch( repository, profile, filter_type, service, input );
                mlt_events_fire( event_object, "filter-create-done", service, input, obj, NULL );
        }
 
@@ -227,7 +223,7 @@ mlt_transition mlt_factory_transition( mlt_profile profile, const char *service,
 
        if ( obj == NULL )
        {
-               obj = mlt_repository_fetch( transitions, profile, filter_type, service, input );
+               obj = mlt_repository_fetch( repository, profile, transition_type, service, input );
                mlt_events_fire( event_object, "transition-create-done", service, input, obj, NULL );
        }
 
@@ -254,7 +250,7 @@ mlt_consumer mlt_factory_consumer( mlt_profile profile, const char *service, voi
 
        if ( obj == NULL )
        {
-               obj = mlt_repository_fetch( consumers, profile, consumer_type, service, input );
+               obj = mlt_repository_fetch( repository, profile, consumer_type, service, input );
                mlt_events_fire( event_object, "consumer-create-done", service, input, obj, NULL );
        }
 
@@ -284,12 +280,8 @@ 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( );