Removal of timecodes, consumer libdv, serialisation of inigo
[melted] / 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 <stdlib.h>
26 #include <string.h>
27
28 /** Singleton repositories
29 */
30
31 static char *mlt_prefix = NULL;
32 static mlt_properties object_list = NULL;
33 static mlt_repository producers = NULL;
34 static mlt_repository filters = NULL;
35 static mlt_repository transitions = NULL;
36 static mlt_repository consumers = NULL;
37
38 /** Construct the factories.
39 */
40
41 int mlt_factory_init( char *prefix )
42 {
43 // Only initialise once
44 if ( mlt_prefix == NULL )
45 {
46 // If no directory is specified, default to install directory
47 if ( prefix == NULL )
48 prefix = PREFIX_DATA;
49
50 // Store the prefix for later retrieval
51 mlt_prefix = strdup( prefix );
52
53 // Create the object list.
54 object_list = calloc( sizeof( struct mlt_properties_s ), 1 );
55 mlt_properties_init( object_list, NULL );
56
57 // Create a repository for each service type
58 producers = mlt_repository_init( object_list, prefix, "producers.dat", "mlt_create_producer" );
59 filters = mlt_repository_init( object_list, prefix, "filters.dat", "mlt_create_filter" );
60 transitions = mlt_repository_init( object_list, prefix, "transitions.dat", "mlt_create_transition" );
61 consumers = mlt_repository_init( object_list, prefix, "consumers.dat", "mlt_create_consumer" );
62 }
63
64 return 0;
65 }
66
67 /** Fetch the prefix used in this instance.
68 */
69
70 const char *mlt_factory_prefix( )
71 {
72 return mlt_prefix;
73 }
74
75 /** Fetch a producer from the repository.
76 */
77
78 mlt_producer mlt_factory_producer( char *service, void *input )
79 {
80 mlt_producer obj = mlt_repository_fetch( producers, service, input );
81 if ( obj != NULL )
82 {
83 mlt_properties properties = mlt_producer_properties( obj );
84 mlt_properties_set( properties, "mlt_type", "producer" );
85 mlt_properties_set( properties, "mlt_service", service );
86 }
87 return obj;
88 }
89
90 /** Fetch a filter from the repository.
91 */
92
93 mlt_filter mlt_factory_filter( char *service, void *input )
94 {
95 mlt_filter obj = mlt_repository_fetch( filters, service, input );
96 if ( obj != NULL )
97 {
98 mlt_properties properties = mlt_filter_properties( obj );
99 mlt_properties_set( properties, "mlt_type", "filter" );
100 mlt_properties_set( properties, "mlt_service", service );
101 }
102 return obj;
103 }
104
105 /** Fetch a transition from the repository.
106 */
107
108 mlt_transition mlt_factory_transition( char *service, void *input )
109 {
110 mlt_transition obj = mlt_repository_fetch( transitions, service, input );
111 if ( obj != NULL )
112 {
113 mlt_properties properties = mlt_transition_properties( obj );
114 mlt_properties_set( properties, "mlt_type", "transition" );
115 mlt_properties_set( properties, "mlt_service", service );
116 }
117 return obj;
118 }
119
120 /** Fetch a consumer from the repository
121 */
122
123 mlt_consumer mlt_factory_consumer( char *service, void *input )
124 {
125 mlt_consumer obj = mlt_repository_fetch( consumers, service, input );
126 if ( obj != NULL )
127 {
128 mlt_properties properties = mlt_consumer_properties( obj );
129 mlt_properties_set( properties, "mlt_type", "consumer" );
130 mlt_properties_set( properties, "mlt_service", service );
131 }
132 return obj;
133 }
134
135 /** Close the factory.
136 */
137
138 void mlt_factory_close( )
139 {
140 if ( mlt_prefix != NULL )
141 {
142 mlt_repository_close( producers );
143 mlt_repository_close( filters );
144 mlt_repository_close( transitions );
145 mlt_repository_close( consumers );
146 mlt_properties_close( object_list );
147 free( mlt_prefix );
148 free( object_list );
149 mlt_prefix = NULL;
150 }
151 }
152