]> git.sesse.net Git - mlt/blob - src/framework/mlt_factory.c
unique ids
[mlt] / src / framework / mlt_factory.c
1 /*
2  * mlt_factory.c -- the factory method interfaces
3  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4  * Author: Charles Yates <charles.yates@pandora.be>
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #include "config.h"
22 #include "mlt.h"
23 #include "mlt_repository.h"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 /** Singleton repositories
30 */
31
32 static char *mlt_prefix = NULL;
33 static mlt_properties object_list = NULL;
34 static mlt_repository producers = NULL;
35 static mlt_repository filters = NULL;
36 static mlt_repository transitions = NULL;
37 static mlt_repository consumers = NULL;
38 static int unique_id = 0;
39
40 /** Construct the factories.
41 */
42
43 int mlt_factory_init( char *prefix )
44 {
45         // Only initialise once
46         if ( mlt_prefix == NULL )
47         {
48                 // If no directory is specified, default to install directory
49                 if ( prefix == NULL )
50                         prefix = PREFIX_DATA;
51
52                 // Store the prefix for later retrieval
53                 mlt_prefix = strdup( prefix );
54
55                 // Initialise the pool
56                 mlt_pool_init( );
57
58                 // Create the object list.
59                 object_list = mlt_properties_new( );
60
61                 // Create a repository for each service type
62                 producers = mlt_repository_init( object_list, prefix, "producers.dat", "mlt_create_producer" );
63                 filters = mlt_repository_init( object_list, prefix, "filters.dat", "mlt_create_filter" );
64                 transitions = mlt_repository_init( object_list, prefix, "transitions.dat", "mlt_create_transition" );
65                 consumers = mlt_repository_init( object_list, prefix, "consumers.dat", "mlt_create_consumer" );
66         }
67
68         return 0;
69 }
70
71 /** Fetch the prefix used in this instance.
72 */
73
74 const char *mlt_factory_prefix( )
75 {
76         return mlt_prefix;
77 }
78
79 /** Fetch a producer from the repository.
80 */
81
82 mlt_producer mlt_factory_producer( char *service, void *input )
83 {
84         mlt_producer obj = mlt_repository_fetch( producers, service, input );
85         if ( obj != NULL )
86         {
87                 mlt_properties properties = mlt_producer_properties( obj );
88                 mlt_properties_set_int( properties, "_unique_id", ++ unique_id );
89                 mlt_properties_set( properties, "mlt_type", "producer" );
90                 if ( mlt_properties_get_int( properties, "_mlt_service_hidden" ) == 0 )
91                         mlt_properties_set( properties, "mlt_service", service );
92         }
93         return obj;
94 }
95
96 /** Fetch a filter from the repository.
97 */
98
99 mlt_filter mlt_factory_filter( char *service, void *input )
100 {
101         mlt_filter obj = mlt_repository_fetch( filters, service, input );
102         if ( obj != NULL )
103         {
104                 mlt_properties properties = mlt_filter_properties( obj );
105                 mlt_properties_set_int( properties, "_unique_id", ++ unique_id );
106                 mlt_properties_set( properties, "mlt_type", "filter" );
107                 mlt_properties_set( properties, "mlt_service", service );
108         }
109         return obj;
110 }
111
112 /** Fetch a transition from the repository.
113 */
114
115 mlt_transition mlt_factory_transition( char *service, void *input )
116 {
117         mlt_transition obj = mlt_repository_fetch( transitions, service, input );
118         if ( obj != NULL )
119         {
120                 mlt_properties properties = mlt_transition_properties( obj );
121                 mlt_properties_set_int( properties, "_unique_id", ++ unique_id );
122                 mlt_properties_set( properties, "mlt_type", "transition" );
123                 mlt_properties_set( properties, "mlt_service", service );
124         }
125         return obj;
126 }
127
128 /** Fetch a consumer from the repository
129 */
130
131 mlt_consumer mlt_factory_consumer( char *service, void *input )
132 {
133         mlt_consumer obj = mlt_repository_fetch( consumers, service, input );
134         if ( obj != NULL )
135         {
136                 mlt_properties properties = mlt_consumer_properties( obj );
137                 mlt_properties_set_int( properties, "_unique_id", ++ unique_id );
138                 mlt_properties_set( properties, "mlt_type", "consumer" );
139                 mlt_properties_set( properties, "mlt_service", service );
140         }
141         return obj;
142 }
143
144 /** Close the factory.
145 */
146
147 void mlt_factory_close( )
148 {
149         if ( mlt_prefix != NULL )
150         {
151                 mlt_repository_close( producers );
152                 mlt_repository_close( filters );
153                 mlt_repository_close( transitions );
154                 mlt_repository_close( consumers );
155                 mlt_properties_close( object_list );
156                 free( mlt_prefix );
157                 mlt_prefix = NULL;
158                 mlt_pool_close( );
159         }
160 }
161