2 * mlt_factory.c -- the factory method interfaces
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "mlt_repository.h"
29 /** Singleton repositories
32 static char *mlt_prefix
= NULL
;
33 static mlt_properties global_properties
= NULL
;
34 static mlt_properties object_list
= NULL
;
35 static mlt_repository producers
= NULL
;
36 static mlt_repository filters
= NULL
;
37 static mlt_repository transitions
= NULL
;
38 static mlt_repository consumers
= NULL
;
39 static int unique_id
= 0;
41 /** Construct the factories.
44 int mlt_factory_init( char *prefix
)
46 // Only initialise once
47 if ( mlt_prefix
== NULL
)
49 // If no directory is specified, default to install directory
53 // Store the prefix for later retrieval
54 mlt_prefix
= strdup( prefix
);
56 // Initialise the pool
59 // Create the global properties
60 global_properties
= mlt_properties_new( );
61 mlt_properties_set( global_properties
, "MLT_NORMALISATION", getenv( "MLT_NORMALISATION" ) );
63 // Create the object list.
64 object_list
= mlt_properties_new( );
66 // Create a repository for each service type
67 producers
= mlt_repository_init( object_list
, prefix
, "producers.dat", "mlt_create_producer" );
68 filters
= mlt_repository_init( object_list
, prefix
, "filters.dat", "mlt_create_filter" );
69 transitions
= mlt_repository_init( object_list
, prefix
, "transitions.dat", "mlt_create_transition" );
70 consumers
= mlt_repository_init( object_list
, prefix
, "consumers.dat", "mlt_create_consumer" );
76 /** Fetch the prefix used in this instance.
79 const char *mlt_factory_prefix( )
84 /** Get a value from the environment.
87 char *mlt_environment( char *name
)
89 return mlt_properties_get( global_properties
, name
);
92 /** Fetch a producer from the repository.
95 mlt_producer
mlt_factory_producer( char *service
, void *input
)
97 mlt_producer obj
= mlt_repository_fetch( producers
, service
, input
);
100 mlt_properties properties
= mlt_producer_properties( obj
);
101 mlt_properties_set_int( properties
, "_unique_id", ++ unique_id
);
102 mlt_properties_set( properties
, "mlt_type", "producer" );
103 if ( mlt_properties_get_int( properties
, "_mlt_service_hidden" ) == 0 )
104 mlt_properties_set( properties
, "mlt_service", service
);
109 /** Fetch a filter from the repository.
112 mlt_filter
mlt_factory_filter( char *service
, void *input
)
114 mlt_filter obj
= mlt_repository_fetch( filters
, service
, input
);
117 mlt_properties properties
= mlt_filter_properties( obj
);
118 mlt_properties_set_int( properties
, "_unique_id", ++ unique_id
);
119 mlt_properties_set( properties
, "mlt_type", "filter" );
120 mlt_properties_set( properties
, "mlt_service", service
);
125 /** Fetch a transition from the repository.
128 mlt_transition
mlt_factory_transition( char *service
, void *input
)
130 mlt_transition obj
= mlt_repository_fetch( transitions
, service
, input
);
133 mlt_properties properties
= mlt_transition_properties( obj
);
134 mlt_properties_set_int( properties
, "_unique_id", ++ unique_id
);
135 mlt_properties_set( properties
, "mlt_type", "transition" );
136 mlt_properties_set( properties
, "mlt_service", service
);
141 /** Fetch a consumer from the repository
144 mlt_consumer
mlt_factory_consumer( char *service
, void *input
)
146 mlt_consumer obj
= mlt_repository_fetch( consumers
, service
, input
);
149 mlt_properties properties
= mlt_consumer_properties( obj
);
150 mlt_properties_set_int( properties
, "_unique_id", ++ unique_id
);
151 mlt_properties_set( properties
, "mlt_type", "consumer" );
152 mlt_properties_set( properties
, "mlt_service", service
);
157 /** Close the factory.
160 void mlt_factory_close( )
162 if ( mlt_prefix
!= NULL
)
164 mlt_repository_close( producers
);
165 mlt_repository_close( filters
);
166 mlt_repository_close( transitions
);
167 mlt_repository_close( consumers
);
168 mlt_properties_close( object_list
);
169 mlt_properties_close( global_properties
);