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 if (!plginfo
|| !param_info
) {
78 mlt_properties metadata
= mlt_properties_new();
79 f0r_plugin_info_t info
;
84 snprintf ( string
, sizeof(string
) , "%d.%d" , info
.major_version
, info
.minor_version
);
85 mlt_properties_set ( metadata
, "schema_version" , "0.1" );
86 mlt_properties_set ( metadata
, "title" , info
.name
);
87 mlt_properties_set ( metadata
, "version", string
);
88 mlt_properties_set ( metadata
, "identifier" , service_name
);
89 mlt_properties_set ( metadata
, "description" , info
.explanation
);
90 mlt_properties_set ( metadata
, "creator" , info
.author
);
93 mlt_properties_set ( metadata
, "type" , "producer" );
96 mlt_properties_set ( metadata
, "type" , "filter" );
99 mlt_properties_set ( metadata
, "type" , "transition" );
105 mlt_properties parameter
= mlt_properties_new ( );
106 mlt_properties_set_data ( metadata
, "parameters" , parameter
, 0 , ( mlt_destructor
)mlt_properties_close
, NULL
);
107 mlt_properties tags
= mlt_properties_new ( );
108 mlt_properties_set_data ( metadata
, "tags" , tags
, 0 , ( mlt_destructor
)mlt_properties_close
, NULL
);
109 mlt_properties_set ( tags
, "0" , "Video" );
111 for (j
=0;j
<info
.num_params
;j
++){
112 snprintf ( string
, sizeof(string
), "%d" , j
);
113 mlt_properties pnum
= mlt_properties_new ( );
114 mlt_properties_set_data ( parameter
, string
, pnum
, 0 , ( mlt_destructor
)mlt_properties_close
, NULL
);
115 f0r_param_info_t paraminfo
;
116 param_info(¶minfo
,j
);
117 mlt_properties_set ( pnum
, "identifier" , paraminfo
.name
);
118 mlt_properties_set ( pnum
, "title" , paraminfo
.name
);
119 mlt_properties_set ( pnum
, "description" , paraminfo
.explanation
);
120 if ( paraminfo
.type
== F0R_PARAM_DOUBLE
){
121 mlt_properties_set ( pnum
, "type" , "float" );
122 mlt_properties_set ( pnum
, "minimum" , "0" );
123 mlt_properties_set ( pnum
, "maximum" , "1" );
124 mlt_properties_set ( pnum
, "readonly" , "no" );
125 mlt_properties_set ( pnum
, "widget" , "spinner" );
127 if ( paraminfo
.type
== F0R_PARAM_BOOL
){
128 mlt_properties_set ( pnum
, "type" , "boolean" );
129 mlt_properties_set ( pnum
, "minimum" , "0" );
130 mlt_properties_set ( pnum
, "maximum" , "1" );
131 mlt_properties_set ( pnum
, "readonly" , "no" );
133 if ( paraminfo
.type
== F0R_PARAM_COLOR
){
134 mlt_properties_set ( pnum
, "type" , "color" );
135 mlt_properties_set ( pnum
, "readonly" , "no" );
137 if ( paraminfo
.type
== F0R_PARAM_STRING
){
138 mlt_properties_set ( pnum
, "type" , "string" );
139 mlt_properties_set ( pnum
, "readonly" , "no" );
148 static void * load_lib( mlt_profile profile
, mlt_service_type type
, void* handle
){
151 void (*f0r_get_plugin_info
)(f0r_plugin_info_t
*),
152 *f0r_construct
, *f0r_update
, *f0r_destruct
,
153 (*f0r_get_param_info
)(f0r_param_info_t
* info
, int param_index
),
154 (*f0r_init
)(void) , *f0r_deinit
,
155 (*f0r_set_param_value
)(f0r_instance_t instance
, f0r_param_t param
, int param_index
),
156 (*f0r_get_param_value
)(f0r_instance_t instance
, f0r_param_t param
, int param_index
),
157 (*f0r_update2
) (f0r_instance_t instance
, double time
, const uint32_t* inframe1
,
158 const uint32_t* inframe2
,const uint32_t* inframe3
, uint32_t* outframe
);
160 if ( ( f0r_construct
= dlsym(handle
, "f0r_construct") ) &&
161 (f0r_update
= dlsym(handle
,"f0r_update") ) &&
162 (f0r_destruct
= dlsym(handle
,"f0r_destruct") ) &&
163 (f0r_get_plugin_info
= dlsym(handle
,"f0r_get_plugin_info") ) &&
164 (f0r_get_param_info
= dlsym(handle
,"f0r_get_param_info") ) &&
165 (f0r_set_param_value
= dlsym(handle
,"f0r_set_param_value" ) ) &&
166 (f0r_get_param_value
= dlsym(handle
,"f0r_get_param_value" ) ) &&
167 (f0r_init
= dlsym(handle
,"f0r_init" ) ) &&
168 (f0r_deinit
= dlsym(handle
,"f0r_deinit" ) )
171 f0r_update2
=dlsym(handle
,"f0r_update2");
173 f0r_plugin_info_t info
;
174 f0r_get_plugin_info(&info
);
177 mlt_properties properties
=NULL
;
179 if (type
== producer_type
&& info
.plugin_type
== F0R_PLUGIN_TYPE_SOURCE
){
180 mlt_producer
this = mlt_producer_new( );
183 this->get_frame
= producer_get_frame
;
184 this->close
= ( mlt_destructor
)producer_close
;
186 properties
=MLT_PRODUCER_PROPERTIES ( this );
188 for (i
=0;i
<info
.num_params
;i
++){
189 f0r_param_info_t pinfo
;
190 f0r_get_param_info(&pinfo
,i
);
196 } else if (type
== filter_type
&& info
.plugin_type
== F0R_PLUGIN_TYPE_FILTER
){
197 mlt_filter
this = mlt_filter_new( );
200 this->process
= filter_process
;
201 this->close
= filter_close
;
203 properties
=MLT_FILTER_PROPERTIES ( this );
205 for (i
=0;i
<info
.num_params
;i
++){
206 f0r_param_info_t pinfo
;
207 f0r_get_param_info(&pinfo
,i
);
213 }else if (type
== transition_type
&& info
.plugin_type
== F0R_PLUGIN_TYPE_MIXER2
){
214 mlt_transition transition
= mlt_transition_new( );
215 if ( transition
!= NULL
)
217 transition
->process
= transition_process
;
218 transition
->close
= transition_close
;
219 properties
=MLT_TRANSITION_PROPERTIES( transition
);
220 mlt_properties_set_int(properties
, "_transition_type", 1 );
225 mlt_properties_set_data(properties
, "_dlclose_handle", handle
, sizeof (void*) , NULL
, NULL
);
226 mlt_properties_set_data(properties
, "_dlclose", dlclose
, sizeof (void*) , NULL
, NULL
);
227 mlt_properties_set_data(properties
, "f0r_construct", f0r_construct
, sizeof(void*),NULL
,NULL
);
228 mlt_properties_set_data(properties
, "f0r_update", f0r_update
, sizeof(void*),NULL
,NULL
);
230 mlt_properties_set_data(properties
, "f0r_update2", f0r_update2
, sizeof(void*),NULL
,NULL
);
231 mlt_properties_set_data(properties
, "f0r_destruct", f0r_destruct
, sizeof(void*),NULL
,NULL
);
232 mlt_properties_set_data(properties
, "f0r_get_plugin_info", f0r_get_plugin_info
, sizeof(void*),NULL
,NULL
);
233 mlt_properties_set_data(properties
, "f0r_get_param_info", f0r_get_param_info
, sizeof(void*),NULL
,NULL
);
234 mlt_properties_set_data(properties
, "f0r_set_param_value", f0r_set_param_value
, sizeof(void*),NULL
,NULL
);
235 mlt_properties_set_data(properties
, "f0r_get_param_value", f0r_get_param_value
, sizeof(void*),NULL
,NULL
);
240 printf("some was wrong\n");
246 static void * create_frei0r_item ( mlt_profile profile
, mlt_service_type type
, const char *id
, void *arg
){
248 mlt_tokeniser tokeniser
= mlt_tokeniser_init ( );
249 int dircount
=mlt_tokeniser_parse_new (
251 getenv("MLT_FREI0R_PLUGIN_PATH") ?
getenv("MLT_FREI0R_PLUGIN_PATH") : FREI0R_PLUGIN_PATH
,
256 char soname
[1024]="";
258 char *save_firstptr
= NULL
;
259 char *firstname
=strtok_r(strdup(id
),".",&save_firstptr
);
261 firstname
=strtok_r(NULL
,".",&save_firstptr
);
262 sprintf(soname
,"%s/%s.so", mlt_tokeniser_get_string( tokeniser
, dircount
) , firstname
);
266 void* handle
=dlopen(soname
,RTLD_LAZY
);
269 ret
=load_lib ( profile
, type
, handle
);
275 mlt_tokeniser_close ( tokeniser
);
283 mlt_tokeniser tokeniser
= mlt_tokeniser_init ( );
284 int dircount
=mlt_tokeniser_parse_new (
286 getenv("MLT_FREI0R_PLUGIN_PATH") ?
getenv("MLT_FREI0R_PLUGIN_PATH") : FREI0R_PLUGIN_PATH
,
292 mlt_properties direntries
= mlt_properties_new();
293 char* dirname
= mlt_tokeniser_get_string ( tokeniser
, dircount
) ;
294 mlt_properties_dir_list(direntries
, dirname
,"*.so",1);
296 for (i
=0;i
<mlt_properties_count(direntries
);i
++){
297 char* name
=mlt_properties_get_value(direntries
,i
);
298 char* shortname
=name
+strlen(dirname
)+1;
301 strcat(fname
,dirname
);
302 strcat(fname
,shortname
);
304 char *save_firstptr
= NULL
;
305 char pluginname
[1024]="frei0r.";
306 char* firstname
= strtok_r ( shortname
, "." , &save_firstptr
);
307 strcat(pluginname
,firstname
);
309 void* handle
=dlopen(strcat(name
,".so"),RTLD_LAZY
);
311 void (*plginfo
)(f0r_plugin_info_t
*)=dlsym(handle
,"f0r_get_plugin_info");
314 f0r_plugin_info_t info
;
316 if (firstname
&& info
.plugin_type
==F0R_PLUGIN_TYPE_SOURCE
){
317 MLT_REGISTER( producer_type
, pluginname
, create_frei0r_item
);
318 MLT_REGISTER_METADATA( producer_type
, pluginname
, fill_param_info
, strdup(name
) );
320 else if (firstname
&& info
.plugin_type
==F0R_PLUGIN_TYPE_FILTER
){
321 MLT_REGISTER( filter_type
, pluginname
, create_frei0r_item
);
322 MLT_REGISTER_METADATA( filter_type
, pluginname
, fill_param_info
, strdup(name
) );
324 else if (firstname
&& info
.plugin_type
==F0R_PLUGIN_TYPE_MIXER2
){
325 MLT_REGISTER( transition_type
, pluginname
, create_frei0r_item
);
326 MLT_REGISTER_METADATA( transition_type
, pluginname
, fill_param_info
, strdup(name
) );
332 mlt_properties_close(direntries
);
334 mlt_tokeniser_close ( tokeniser
);