ntsc fixes and service doco for discussion
[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_factory.h"
23 #include "mlt_repository.h"
24 #include "mlt_properties.h"
25
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
39 /** Construct the factories.
40 */
41
42 int mlt_factory_init( char *prefix )
43 {
44 // If no directory is specified, default to install directory
45 if ( prefix == NULL )
46 prefix = PREFIX_DATA;
47
48 // Store the prefix for later retrieval
49 mlt_prefix = strdup( prefix );
50
51 // Create the object list.
52 object_list = calloc( sizeof( struct mlt_properties_s ), 1 );
53 mlt_properties_init( object_list, NULL );
54
55 // Create a repository for each service type
56 producers = mlt_repository_init( object_list, prefix, "producers.dat", "mlt_create_producer" );
57 filters = mlt_repository_init( object_list, prefix, "filters.dat", "mlt_create_filter" );
58 transitions = mlt_repository_init( object_list, prefix, "transitions.dat", "mlt_create_transition" );
59 consumers = mlt_repository_init( object_list, prefix, "consumers.dat", "mlt_create_consumer" );
60
61 return 0;
62 }
63
64 /** Fetch the prefix used in this instance.
65 */
66
67 const char *mlt_factory_prefix( )
68 {
69 return mlt_prefix;
70 }
71
72 /** Fetch a producer from the repository.
73 */
74
75 mlt_producer mlt_factory_producer( char *service, void *input )
76 {
77 return ( mlt_producer )mlt_repository_fetch( producers, service, input );
78 }
79
80 /** Fetch a filter from the repository.
81 */
82
83 mlt_filter mlt_factory_filter( char *service, void *input )
84 {
85 return ( mlt_filter )mlt_repository_fetch( filters, service, input );
86 }
87
88 /** Fetch a transition from the repository.
89 */
90
91 mlt_transition mlt_factory_transition( char *service, void *input )
92 {
93 return ( mlt_transition )mlt_repository_fetch( transitions, service, input );
94 }
95
96 /** Fetch a consumer from the repository
97 */
98
99 mlt_consumer mlt_factory_consumer( char *service, void *input )
100 {
101 return ( mlt_consumer )mlt_repository_fetch( consumers, service, input );
102 }
103
104 /** Close the factory.
105 */
106
107 void mlt_factory_close( )
108 {
109 mlt_repository_close( producers );
110 mlt_repository_close( filters );
111 mlt_repository_close( transitions );
112 mlt_repository_close( consumers );
113 mlt_properties_close( object_list );
114 free( mlt_prefix );
115 free( object_list );
116 }
117