2 * producer_fezzik.c -- a normalising filter
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.
21 #include "producer_fezzik.h"
29 #include <framework/mlt.h>
31 static mlt_properties dictionary
= NULL
;
32 static mlt_properties normalisers
= NULL
;
34 static mlt_producer
create_from( char *file
, char *services
)
36 mlt_producer producer
= NULL
;
37 char *temp
= strdup( services
);
41 char *p
= strchr( service
, ',' );
44 producer
= mlt_factory_producer( service
, file
);
47 while ( producer
== NULL
&& service
!= NULL
);
52 static mlt_producer
create_producer( char *file
)
54 mlt_producer result
= NULL
;
56 // 1st Line - check for service:resource handling
57 if ( strchr( file
, ':' ) )
59 char *temp
= strdup( file
);
61 char *resource
= strchr( temp
, ':' );
63 result
= mlt_factory_producer( service
, resource
);
67 // 2nd Line preferences
71 char *lookup
= strdup( file
);
74 // We only need to load the dictionary once
75 if ( dictionary
== NULL
)
78 sprintf( temp
, "%s/fezzik.dict", mlt_factory_prefix( ) );
79 dictionary
= mlt_properties_load( temp
);
80 mlt_factory_register_for_clean_up( dictionary
, ( mlt_destructor
)mlt_properties_close
);
83 // Convert the lookup string to lower case
90 // Iterate through the dictionary
91 for ( i
= 0; result
== NULL
&& i
< mlt_properties_count( dictionary
); i
++ )
93 char *name
= mlt_properties_get_name( dictionary
, i
);
94 if ( fnmatch( name
, lookup
, 0 ) == 0 )
95 result
= create_from( file
, mlt_properties_get_value( dictionary
, i
) );
101 // Finally, try just loading as service
102 if ( result
== NULL
)
103 result
= mlt_factory_producer( file
, NULL
);
108 static void create_filter( mlt_producer producer
, char *effect
, int *created
)
110 char *id
= strdup( effect
);
111 char *arg
= strchr( id
, ':' );
114 mlt_filter filter
= mlt_factory_filter( id
, arg
);
115 if ( filter
!= NULL
)
117 mlt_properties_set_int( mlt_filter_properties( filter
), "_fezzik", 1 );
118 mlt_producer_attach( producer
, filter
);
119 mlt_filter_close( filter
);
125 static void attach_normalisers( mlt_producer producer
)
131 mlt_tokeniser tokeniser
= mlt_tokeniser_init( );
133 // We only need to load the normalising properties once
134 if ( normalisers
== NULL
)
137 sprintf( temp
, "%s/fezzik.ini", mlt_factory_prefix( ) );
138 normalisers
= mlt_properties_load( temp
);
139 mlt_factory_register_for_clean_up( normalisers
, ( mlt_destructor
)mlt_properties_close
);
143 for ( i
= 0; i
< mlt_properties_count( normalisers
); i
++ )
147 char *value
= mlt_properties_get_value( normalisers
, i
);
148 mlt_tokeniser_parse_new( tokeniser
, value
, "," );
149 for ( j
= 0; !created
&& j
< mlt_tokeniser_count( tokeniser
); j
++ )
150 create_filter( producer
, mlt_tokeniser_get_string( tokeniser
, j
), &created
);
153 // Close the tokeniser
154 mlt_tokeniser_close( tokeniser
);
157 mlt_producer
producer_fezzik_init( char *arg
)
159 // Create the producer
160 mlt_producer producer
= NULL
;
161 mlt_properties properties
= NULL
;
164 producer
= create_producer( arg
);
166 if ( producer
!= NULL
)
167 properties
= mlt_producer_properties( producer
);
169 // Attach filters if we have a producer and it isn't already westley'd :-)
170 if ( producer
!= NULL
&& mlt_properties_get( properties
, "westley" ) == NULL
)
171 attach_normalisers( producer
);
173 // Now make sure we don't lose our identity
174 if ( properties
!= NULL
)
175 mlt_properties_set_int( properties
, "_mlt_service_hidden", 1 );
177 // Return the producer