2 * factory.c -- the factory method interfaces
3 * Copyright (c) 2008 Marco Gittler <g.marco@freenet.de>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <framework/mlt.h>
27 #include <sys/types.h>
33 #define FREI0R_PLUGIN_PATH "/usr/lib/frei0r-1:/usr/local/lib/frei0r-1:/usr/lib64/frei0r-1:/opt/local/lib/frei0r-1"
35 extern mlt_filter filter_frei0r_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
36 extern mlt_frame filter_process( mlt_filter this, mlt_frame frame );
37 extern void filter_close( mlt_filter this );
38 extern int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index );
39 extern void producer_close( mlt_producer this );
40 extern void transition_close( mlt_transition this );
41 extern mlt_frame transition_process( mlt_transition transition, mlt_frame a_frame, mlt_frame b_frame );
43 static mlt_properties fill_param_info ( mlt_service_type type, const char *service_name, char *name )
45 char file[ PATH_MAX ];
46 char servicetype[ 1024 ]="";
47 struct stat stat_buff;
51 strcpy ( servicetype , "producer" );
54 strcpy ( servicetype , "filter" );
57 strcpy ( servicetype , "transition" ) ;
60 strcpy ( servicetype , "" );
63 snprintf( file, PATH_MAX, "%s/frei0r/%s_%s.yml", mlt_environment( "MLT_DATA" ), servicetype, service_name );
64 stat(file,&stat_buff);
66 if (S_ISREG(stat_buff.st_mode)){
67 return mlt_properties_parse_yaml( file );
70 void* handle=dlopen(name,RTLD_LAZY);
71 if (!handle) return NULL;
72 void (*plginfo)(f0r_plugin_info_t*)=dlsym(handle,"f0r_get_plugin_info");
73 void (*param_info)(f0r_param_info_t*,int param_index)=dlsym(handle,"f0r_get_param_info");
74 void (*f0r_init)(void)=dlsym(handle,"f0r_init");
75 void (*f0r_deinit)(void)=dlsym(handle,"f0r_deinit");
76 if (!plginfo || !param_info) {
80 mlt_properties metadata = mlt_properties_new();
81 f0r_plugin_info_t info;
87 snprintf ( string, sizeof(string) , "%d.%d" , info.major_version , info.minor_version );
88 mlt_properties_set ( metadata, "schema_version" , "0.1" );
89 mlt_properties_set ( metadata, "title" , info.name );
90 mlt_properties_set ( metadata, "version", string );
91 mlt_properties_set ( metadata, "identifier" , service_name );
92 mlt_properties_set ( metadata, "description" , info.explanation );
93 mlt_properties_set ( metadata, "creator" , info.author );
96 mlt_properties_set ( metadata, "type" , "producer" );
99 mlt_properties_set ( metadata, "type" , "filter" );
101 case transition_type:
102 mlt_properties_set ( metadata, "type" , "transition" );
108 mlt_properties parameter = mlt_properties_new ( );
109 mlt_properties_set_data ( metadata , "parameters" , parameter , 0 , ( mlt_destructor )mlt_properties_close, NULL );
110 mlt_properties tags = mlt_properties_new ( );
111 mlt_properties_set_data ( metadata , "tags" , tags , 0 , ( mlt_destructor )mlt_properties_close, NULL );
112 mlt_properties_set ( tags , "0" , "Video" );
114 for (j=0;j<info.num_params;j++){
115 snprintf ( string , sizeof(string), "%d" , j );
116 mlt_properties pnum = mlt_properties_new ( );
117 mlt_properties_set_data ( parameter , string , pnum , 0 , ( mlt_destructor )mlt_properties_close, NULL );
118 f0r_param_info_t paraminfo;
119 param_info(¶minfo,j);
120 mlt_properties_set ( pnum , "identifier" , paraminfo.name );
121 mlt_properties_set ( pnum , "title" , paraminfo.name );
122 mlt_properties_set ( pnum , "description" , paraminfo.explanation);
123 if ( paraminfo.type == F0R_PARAM_DOUBLE ){
124 mlt_properties_set ( pnum , "type" , "float" );
125 mlt_properties_set ( pnum , "minimum" , "0" );
126 mlt_properties_set ( pnum , "maximum" , "1" );
127 mlt_properties_set ( pnum , "readonly" , "no" );
128 mlt_properties_set ( pnum , "widget" , "spinner" );
130 if ( paraminfo.type == F0R_PARAM_BOOL ){
131 mlt_properties_set ( pnum , "type" , "boolean" );
132 mlt_properties_set ( pnum , "minimum" , "0" );
133 mlt_properties_set ( pnum , "maximum" , "1" );
134 mlt_properties_set ( pnum , "readonly" , "no" );
136 if ( paraminfo.type == F0R_PARAM_COLOR ){
137 mlt_properties_set ( pnum , "type" , "color" );
138 mlt_properties_set ( pnum , "readonly" , "no" );
140 if ( paraminfo.type == F0R_PARAM_STRING ){
141 mlt_properties_set ( pnum , "type" , "string" );
142 mlt_properties_set ( pnum , "readonly" , "no" );
152 static void * load_lib( mlt_profile profile, mlt_service_type type , void* handle){
155 void (*f0r_get_plugin_info)(f0r_plugin_info_t*),
156 *f0r_construct , *f0r_update , *f0r_destruct,
157 (*f0r_get_param_info)(f0r_param_info_t* info, int param_index),
158 (*f0r_init)(void) , *f0r_deinit ,
159 (*f0r_set_param_value)(f0r_instance_t instance, f0r_param_t param, int param_index),
160 (*f0r_get_param_value)(f0r_instance_t instance, f0r_param_t param, int param_index),
161 (*f0r_update2) (f0r_instance_t instance, double time, const uint32_t* inframe1,
162 const uint32_t* inframe2,const uint32_t* inframe3, uint32_t* outframe);
164 if ( ( f0r_construct = dlsym(handle, "f0r_construct") ) &&
165 (f0r_update = dlsym(handle,"f0r_update") ) &&
166 (f0r_destruct = dlsym(handle,"f0r_destruct") ) &&
167 (f0r_get_plugin_info = dlsym(handle,"f0r_get_plugin_info") ) &&
168 (f0r_get_param_info = dlsym(handle,"f0r_get_param_info") ) &&
169 (f0r_set_param_value= dlsym(handle,"f0r_set_param_value" ) ) &&
170 (f0r_get_param_value= dlsym(handle,"f0r_get_param_value" ) ) &&
171 (f0r_init= dlsym(handle,"f0r_init" ) ) &&
172 (f0r_deinit= dlsym(handle,"f0r_deinit" ) )
175 f0r_update2=dlsym(handle,"f0r_update2");
177 f0r_plugin_info_t info;
178 f0r_get_plugin_info(&info);
181 mlt_properties properties=NULL;
183 if (type == producer_type && info.plugin_type == F0R_PLUGIN_TYPE_SOURCE ){
184 mlt_producer this = mlt_producer_new( );
187 this->get_frame = producer_get_frame;
188 this->close = ( mlt_destructor )producer_close;
190 properties=MLT_PRODUCER_PROPERTIES ( this );
192 for (i=0;i<info.num_params;i++){
193 f0r_param_info_t pinfo;
194 f0r_get_param_info(&pinfo,i);
200 } else if (type == filter_type && info.plugin_type == F0R_PLUGIN_TYPE_FILTER ){
201 mlt_filter this = mlt_filter_new( );
204 this->process = filter_process;
205 this->close = filter_close;
207 properties=MLT_FILTER_PROPERTIES ( this );
209 for (i=0;i<info.num_params;i++){
210 f0r_param_info_t pinfo;
211 f0r_get_param_info(&pinfo,i);
217 }else if (type == transition_type && info.plugin_type == F0R_PLUGIN_TYPE_MIXER2){
218 mlt_transition transition = mlt_transition_new( );
219 if ( transition != NULL )
221 transition->process = transition_process;
222 transition->close = transition_close;
223 properties=MLT_TRANSITION_PROPERTIES( transition );
224 mlt_properties_set_int(properties, "_transition_type", 1 );
229 mlt_properties_set_data(properties, "_dlclose_handle", handle , sizeof (void*) , NULL , NULL );
230 mlt_properties_set_data(properties, "_dlclose", dlclose , sizeof (void*) , NULL , NULL );
231 mlt_properties_set_data(properties, "f0r_construct", f0r_construct , sizeof(void*),NULL,NULL);
232 mlt_properties_set_data(properties, "f0r_update", f0r_update , sizeof(void*),NULL,NULL);
234 mlt_properties_set_data(properties, "f0r_update2", f0r_update2 , sizeof(void*),NULL,NULL);
235 mlt_properties_set_data(properties, "f0r_destruct", f0r_destruct , sizeof(void*),NULL,NULL);
236 mlt_properties_set_data(properties, "f0r_get_plugin_info", f0r_get_plugin_info , sizeof(void*),NULL,NULL);
237 mlt_properties_set_data(properties, "f0r_get_param_info", f0r_get_param_info , sizeof(void*),NULL,NULL);
238 mlt_properties_set_data(properties, "f0r_set_param_value", f0r_set_param_value , sizeof(void*),NULL,NULL);
239 mlt_properties_set_data(properties, "f0r_get_param_value", f0r_get_param_value , sizeof(void*),NULL,NULL);
244 printf("some was wrong\n");
250 static void * create_frei0r_item ( mlt_profile profile, mlt_service_type type, const char *id, void *arg){
252 mlt_tokeniser tokeniser = mlt_tokeniser_init ( );
253 int dircount=mlt_tokeniser_parse_new (
255 getenv("MLT_FREI0R_PLUGIN_PATH") ? getenv("MLT_FREI0R_PLUGIN_PATH") : FREI0R_PLUGIN_PATH,
260 char soname[1024]="";
262 char *save_firstptr = NULL;
263 char *firstname=strtok_r(strdup(id),".",&save_firstptr);
265 firstname=strtok_r(NULL,".",&save_firstptr);
266 sprintf(soname,"%s/%s.so", mlt_tokeniser_get_string( tokeniser , dircount ) , firstname );
270 void* handle=dlopen(soname,RTLD_LAZY);
273 ret=load_lib ( profile , type , handle );
279 mlt_tokeniser_close ( tokeniser );
287 mlt_tokeniser tokeniser = mlt_tokeniser_init ( );
288 int dircount=mlt_tokeniser_parse_new (
290 getenv("MLT_FREI0R_PLUGIN_PATH") ? getenv("MLT_FREI0R_PLUGIN_PATH") : FREI0R_PLUGIN_PATH,
294 sprintf( temp, "%s/frei0r/blacklist.txt", mlt_environment( "MLT_DATA" ) );
295 mlt_properties blacklist = mlt_properties_load( temp );
299 mlt_properties direntries = mlt_properties_new();
300 char* dirname = mlt_tokeniser_get_string ( tokeniser , dircount ) ;
301 mlt_properties_dir_list(direntries, dirname ,"*.so",1);
303 for (i=0; i<mlt_properties_count(direntries);i++){
304 char* name=mlt_properties_get_value(direntries,i);
305 char* shortname=name+strlen(dirname)+1;
308 strcat(fname,dirname);
309 strcat(fname,shortname);
311 char *save_firstptr = NULL;
312 char pluginname[1024]="frei0r.";
313 char* firstname = strtok_r ( shortname , "." , &save_firstptr );
314 strcat(pluginname,firstname);
316 if ( mlt_properties_get( blacklist, firstname ) )
319 void* handle=dlopen(strcat(name,".so"),RTLD_LAZY);
321 void (*plginfo)(f0r_plugin_info_t*)=dlsym(handle,"f0r_get_plugin_info");
324 f0r_plugin_info_t info;
326 if (firstname && info.plugin_type==F0R_PLUGIN_TYPE_SOURCE){
327 MLT_REGISTER( producer_type, pluginname, create_frei0r_item );
328 MLT_REGISTER_METADATA( producer_type, pluginname, fill_param_info, strdup(name) );
330 else if (firstname && info.plugin_type==F0R_PLUGIN_TYPE_FILTER){
331 MLT_REGISTER( filter_type, pluginname, create_frei0r_item );
332 MLT_REGISTER_METADATA( filter_type, pluginname, fill_param_info, strdup(name) );
334 else if (firstname && info.plugin_type==F0R_PLUGIN_TYPE_MIXER2 ){
335 MLT_REGISTER( transition_type, pluginname, create_frei0r_item );
336 MLT_REGISTER_METADATA( transition_type, pluginname, fill_param_info, strdup(name) );
342 mlt_properties_close(direntries);
344 mlt_tokeniser_close ( tokeniser );
345 mlt_properties_close( blacklist );