filter_dust.yml: apply description fix patch from Mads Dydensborg.
[melted] / src / modules / frei0r / factory.c
index 52eb9bb..4cd8485 100644 (file)
 
 #include <stddef.h>
 #include <stdio.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <dirent.h>
 #include <dlfcn.h>
 #include <stdlib.h>
+#include <limits.h>
 
 extern mlt_filter filter_frei0r_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
 extern mlt_frame filter_process( mlt_filter this, mlt_frame frame );
@@ -34,63 +36,81 @@ extern void filter_close( mlt_filter this );
 extern void transition_close( mlt_transition this );
 extern mlt_frame transition_process( mlt_transition transition, mlt_frame a_frame, mlt_frame b_frame );
 
-void fill_param_info ( mlt_repository repository , void* handle, f0r_plugin_info_t* info , mlt_service_type type , char* name ) {
+static mlt_properties fill_param_info ( mlt_service_type type, const char *service_name, char *name )
+{
+       char file[ PATH_MAX ];
+       char servicetype[ 1024 ]="";
+       struct stat stat_buff;
        
-       int j=0;
-       void (*param_info)(f0r_param_info_t*,int param_index)=dlsym(handle,"f0r_get_param_info");
-       mlt_properties metadata_properties=NULL;
-       switch (type){
+       switch ( type ) {
                case filter_type:
-                       metadata_properties=mlt_repository_filters(repository);
+                       strcpy ( servicetype , "filter" );
+                       break;
+               case transition_type:
+                       strcpy ( servicetype , "transition" ) ;
                        break;
                default:
-                       metadata_properties=NULL;
-       }
+                       strcpy ( servicetype , "" );
+       };
        
-       if (!metadata_properties){
-               return;
+       snprintf( file, PATH_MAX, "%s/frei0r/%s_%s.yml", mlt_environment( "MLT_DATA" ), servicetype, service_name );
+       stat(file,&stat_buff);
+
+       if (S_ISREG(stat_buff.st_mode)){
+               return mlt_properties_parse_yaml( file );
        }
-       
-       mlt_properties this_item_properties = mlt_properties_get_data( metadata_properties , name , NULL );
-       mlt_properties metadata = mlt_properties_get_data( this_item_properties , "metadata" , NULL );
-       if (!metadata){
-               metadata = mlt_properties_new( );
-               mlt_properties_set_data( this_item_properties , "metadata" , metadata , 0 , NULL, NULL );
+               
+       void* handle=dlopen(name,RTLD_LAZY);
+       if (!handle) return NULL;
+       void (*plginfo)(f0r_plugin_info_t*)=dlsym(handle,"f0r_get_plugin_info");
+       void (*param_info)(f0r_param_info_t*,int param_index)=dlsym(handle,"f0r_get_param_info");
+       if (!plginfo || !param_info) {
+               dlclose(handle);
+               return NULL;
        }
-       char descstr[2048];
-       snprintf ( descstr, 2048 , "%s (Version: %d.%d)" , info->explanation , info->major_version , info->minor_version );
-       mlt_properties_set ( metadata, "title" , info->name );
-       mlt_properties_set ( metadata, "identifier" , name );
-       mlt_properties_set ( metadata, "description" , descstr );
-       mlt_properties_set ( metadata, "creator" , info->author );
-       
-       mlt_properties parameter = mlt_properties_get_data( metadata , "parameters" , NULL );
-       
-       if (!parameter){
-               parameter = mlt_properties_new ( );
-               mlt_properties_set_data ( metadata , "parameters" , parameter , 0 , NULL, NULL );
+       mlt_properties metadata = mlt_properties_new();
+       f0r_plugin_info_t info;
+       char string[48];
+       int j=0;
+
+       plginfo(&info);
+       snprintf ( string, sizeof(string) , "%d.%d" , info.major_version , info.minor_version );
+       mlt_properties_set ( metadata, "schema_version" , "0.1" );
+       mlt_properties_set ( metadata, "title" , info.name );
+       mlt_properties_set ( metadata, "version", string );
+       mlt_properties_set ( metadata, "identifier" , service_name );
+       mlt_properties_set ( metadata, "description" , info.explanation );
+       mlt_properties_set ( metadata, "creator" , info.author );
+       switch (type){
+               case filter_type:
+                       mlt_properties_set ( metadata, "type" , "filter" );
+                       break;
+               case transition_type:
+                       mlt_properties_set ( metadata, "type" , "transition" );
+                       break;
+               default:
+                       break;
        }
        
-       char numstr[512];
+       mlt_properties parameter = mlt_properties_new ( );
+       mlt_properties_set_data ( metadata , "parameters" , parameter , 0 , ( mlt_destructor )mlt_properties_close, NULL );
+       mlt_properties tags = mlt_properties_new ( );
+       mlt_properties_set_data ( metadata , "tags" , tags , 0 , ( mlt_destructor )mlt_properties_close, NULL );
+       mlt_properties_set ( tags , "0" , "Video" );
        
-       for (j=0;j<info->num_params;j++){
-               snprintf ( numstr , 512 , "%d" , j );
-               mlt_properties pnum = mlt_properties_get_data( metadata , numstr , NULL );
-               if (!pnum){
-                       pnum = mlt_properties_new ( );
-                       mlt_properties_set_data ( parameter , numstr , pnum , 0 , NULL, NULL );
-               }
-               
+       for (j=0;j<info.num_params;j++){
+               snprintf ( string , sizeof(string), "%d" , j );
+               mlt_properties pnum = mlt_properties_new ( );
+               mlt_properties_set_data ( parameter , string , pnum , 0 , ( mlt_destructor )mlt_properties_close, NULL );
                f0r_param_info_t paraminfo;
                param_info(&paraminfo,j);
                mlt_properties_set ( pnum , "identifier" , paraminfo.name );
                mlt_properties_set ( pnum , "title" , paraminfo.name );
                mlt_properties_set ( pnum , "description" , paraminfo.explanation);
-               
                if ( paraminfo.type == F0R_PARAM_DOUBLE ){
-                       mlt_properties_set ( pnum , "type" , "integer" );
+                       mlt_properties_set ( pnum , "type" , "float" );
                        mlt_properties_set ( pnum , "minimum" , "0" );
-                       mlt_properties_set ( pnum , "maximum" , "1000" );
+                       mlt_properties_set ( pnum , "maximum" , "1" );
                        mlt_properties_set ( pnum , "readonly" , "no" );
                        mlt_properties_set ( pnum , "widget" , "spinner" );
                }else
@@ -105,9 +125,13 @@ void fill_param_info ( mlt_repository repository , void* handle, f0r_plugin_info
                        mlt_properties_set ( pnum , "readonly" , "no" );
                }
        }
+       dlclose(handle);
+       free(name);
+
+       return metadata;
 }
 
-void * load_lib(  mlt_profile profile, mlt_service_type type , void* handle){
+static void * load_lib(  mlt_profile profile, mlt_service_type type , void* handle){
        
        int i=0;
        void (*f0r_get_plugin_info)(f0r_plugin_info_t*),
@@ -188,7 +212,7 @@ void * load_lib(  mlt_profile profile, mlt_service_type type , void* handle){
        return NULL;
 }
 
-void * create_frei0r_item ( mlt_profile profile, mlt_service_type type, const char *id, void *arg){
+static void * create_frei0r_item ( mlt_profile profile, mlt_service_type type, const char *id, void *arg){
 
        mlt_tokeniser tokeniser = mlt_tokeniser_init ( );
        int dircount=mlt_tokeniser_parse_new (
@@ -200,7 +224,7 @@ void * create_frei0r_item ( mlt_profile profile, mlt_service_type type, const ch
        while (dircount--){
                char soname[1024]="";
                
-               char *save_firstptr;
+               char *save_firstptr = NULL;
                char *firstname=strtok_r(strdup(id),".",&save_firstptr);
                
                firstname=strtok_r(NULL,".",&save_firstptr);
@@ -246,7 +270,7 @@ MLT_REPOSITORY
                        strcat(fname,dirname);
                        strcat(fname,shortname);
                        
-                       char *save_firstptr;
+                       char *save_firstptr = NULL;
                        char pluginname[1024]="frei0r.";
                        char* firstname = strtok_r ( shortname , "." , &save_firstptr );
                        strcat(pluginname,firstname);
@@ -261,11 +285,11 @@ MLT_REPOSITORY
                                        
                                        if (firstname && info.plugin_type==F0R_PLUGIN_TYPE_FILTER){
                                                MLT_REGISTER( filter_type, pluginname, create_frei0r_item );
-                                               fill_param_info ( repository , handle, &info , filter_type , pluginname );
+                                               MLT_REGISTER_METADATA( filter_type, pluginname, fill_param_info, strdup(name) );
                                        }
                                        else if (firstname && info.plugin_type==F0R_PLUGIN_TYPE_MIXER2 ){
                                                MLT_REGISTER( transition_type, pluginname, create_frei0r_item );
-                                               fill_param_info ( repository , handle, &info , transition_type , pluginname );
+                                               MLT_REGISTER_METADATA( transition_type, pluginname, fill_param_info, strdup(name) );
                                        }
                                }
                                dlclose(handle);