Merge ../mlt
[melted] / src / modules / frei0r / factory.c
index e51e258..8e2ab99 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>
+
+#define FREI0R_PLUGIN_PATH "/usr/lib/frei0r-1:/usr/local/lib/frei0r-1:/usr/lib64/frei0r-1:/opt/local/lib/frei0r-1"
 
 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 );
 extern void filter_close( mlt_filter this );
+extern int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index );
+extern void producer_close( mlt_producer this );
 extern void transition_close( mlt_transition this );
 extern mlt_frame transition_process( mlt_transition transition, mlt_frame a_frame, mlt_frame b_frame );
 
 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;
+
+       switch ( type ) {
+               case producer_type:
+                       strcpy ( servicetype , "producer" );
+                       break;
+               case filter_type:
+                       strcpy ( servicetype , "filter" );
+                       break;
+               case transition_type:
+                       strcpy ( servicetype , "transition" ) ;
+                       break;
+               default:
+                       strcpy ( servicetype , "" );
+       };
+
+       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 );
+       }
+
        void* handle=dlopen(name,RTLD_LAZY);
        if (!handle) return NULL;
        void (*plginfo)(f0r_plugin_info_t*)=dlsym(handle,"f0r_get_plugin_info");
@@ -58,6 +89,9 @@ static mlt_properties fill_param_info ( mlt_service_type type, const char *servi
        mlt_properties_set ( metadata, "description" , info.explanation );
        mlt_properties_set ( metadata, "creator" , info.author );
        switch (type){
+               case producer_type:
+                       mlt_properties_set ( metadata, "type" , "producer" );
+                       break;
                case filter_type:
                        mlt_properties_set ( metadata, "type" , "filter" );
                        break;
@@ -67,13 +101,13 @@ static mlt_properties fill_param_info ( mlt_service_type type, const char *servi
                default:
                        break;
        }
-       
+
        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 ( string , sizeof(string), "%d" , j );
                mlt_properties pnum = mlt_properties_new ( );
@@ -84,9 +118,9 @@ static mlt_properties fill_param_info ( mlt_service_type type, const char *servi
                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
@@ -96,6 +130,10 @@ static mlt_properties fill_param_info ( mlt_service_type type, const char *servi
                        mlt_properties_set ( pnum , "maximum" , "1" );
                        mlt_properties_set ( pnum , "readonly" , "no" );
                }else
+               if ( paraminfo.type == F0R_PARAM_COLOR ){
+                       mlt_properties_set ( pnum , "type" , "color" );
+                       mlt_properties_set ( pnum , "readonly" , "no" );
+               }else
                if ( paraminfo.type == F0R_PARAM_STRING ){
                        mlt_properties_set ( pnum , "type" , "string" );
                        mlt_properties_set ( pnum , "readonly" , "no" );
@@ -108,7 +146,7 @@ static mlt_properties fill_param_info ( mlt_service_type type, const char *servi
 }
 
 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*),
                *f0r_construct , *f0r_update , *f0r_destruct,
@@ -118,41 +156,58 @@ static void * load_lib(  mlt_profile profile, mlt_service_type type , void* hand
                (*f0r_get_param_value)(f0r_instance_t instance, f0r_param_t param, int param_index),
                (*f0r_update2) (f0r_instance_t instance, double time,   const uint32_t* inframe1,
                  const uint32_t* inframe2,const uint32_t* inframe3, uint32_t* outframe);
-                               
-       if ( ( f0r_construct = dlsym(handle, "f0r_construct") ) && 
-                               (f0r_update = dlsym(handle,"f0r_update") ) && 
-                               (f0r_destruct = dlsym(handle,"f0r_destruct") ) && 
-                               (f0r_get_plugin_info = dlsym(handle,"f0r_get_plugin_info") ) && 
-                               (f0r_get_param_info = dlsym(handle,"f0r_get_param_info") ) && 
+
+       if ( ( f0r_construct = dlsym(handle, "f0r_construct") ) &&
+                               (f0r_update = dlsym(handle,"f0r_update") ) &&
+                               (f0r_destruct = dlsym(handle,"f0r_destruct") ) &&
+                               (f0r_get_plugin_info = dlsym(handle,"f0r_get_plugin_info") ) &&
+                               (f0r_get_param_info = dlsym(handle,"f0r_get_param_info") ) &&
                                (f0r_set_param_value= dlsym(handle,"f0r_set_param_value" ) ) &&
                                (f0r_get_param_value= dlsym(handle,"f0r_get_param_value" ) ) &&
                                (f0r_init= dlsym(handle,"f0r_init" ) ) &&
-                               (f0r_deinit= dlsym(handle,"f0r_deinit" ) ) 
+                               (f0r_deinit= dlsym(handle,"f0r_deinit" ) )
                ){
-       
+
                f0r_update2=dlsym(handle,"f0r_update2");
-               
+
                f0r_plugin_info_t info;
                f0r_get_plugin_info(&info);
-               
-               void* ret=NULL; 
+
+               void* ret=NULL;
                mlt_properties properties=NULL;
-               
-               if (type == filter_type && info.plugin_type == F0R_PLUGIN_TYPE_FILTER ){
+
+               if (type == producer_type && info.plugin_type == F0R_PLUGIN_TYPE_SOURCE ){
+                       mlt_producer this = mlt_producer_new( );
+                       if ( this != NULL )
+                       {
+                               this->get_frame = producer_get_frame;
+                               this->close = ( mlt_destructor )producer_close;
+                               f0r_init();
+                               properties=MLT_PRODUCER_PROPERTIES ( this );
+
+                               for (i=0;i<info.num_params;i++){
+                                       f0r_param_info_t pinfo;
+                                       f0r_get_param_info(&pinfo,i);
+
+                               }
+
+                               ret=this;
+                       }
+               } else if (type == filter_type && info.plugin_type == F0R_PLUGIN_TYPE_FILTER ){
                        mlt_filter this = mlt_filter_new( );
                        if ( this != NULL )
                        {
                                this->process = filter_process;
-                               this->close = filter_close;                     
+                               this->close = filter_close;
                                f0r_init();
                                properties=MLT_FILTER_PROPERTIES ( this );
-                                                       
+
                                for (i=0;i<info.num_params;i++){
                                        f0r_param_info_t pinfo;
                                        f0r_get_param_info(&pinfo,i);
-                                       
+
                                }
-                               
+
                                ret=this;
                        }
                }else if (type == transition_type && info.plugin_type == F0R_PLUGIN_TYPE_MIXER2){
@@ -178,8 +233,8 @@ static void * load_lib(  mlt_profile profile, mlt_service_type type , void* hand
                mlt_properties_set_data(properties, "f0r_get_param_info", f0r_get_param_info , sizeof(void*),NULL,NULL);
                mlt_properties_set_data(properties, "f0r_set_param_value", f0r_set_param_value , sizeof(void*),NULL,NULL);
                mlt_properties_set_data(properties, "f0r_get_param_value", f0r_get_param_value , sizeof(void*),NULL,NULL);
-               
-               
+
+
                return ret;
        }else{
                printf("some was wrong\n");
@@ -192,24 +247,24 @@ static void * create_frei0r_item ( mlt_profile profile, mlt_service_type type, c
 
        mlt_tokeniser tokeniser = mlt_tokeniser_init ( );
        int dircount=mlt_tokeniser_parse_new (
-               tokeniser ,
-               getenv("MLT_FREI0R_PLUGIN_PATH") ? getenv("MLT_FREI0R_PLUGIN_PATH") : "/usr/lib/frei0r-1" ,
+               tokeniser,
+               getenv("MLT_FREI0R_PLUGIN_PATH") ? getenv("MLT_FREI0R_PLUGIN_PATH") : FREI0R_PLUGIN_PATH,
                 ":"
        );
        void* ret=NULL;
        while (dircount--){
                char soname[1024]="";
-               
+
                char *save_firstptr = NULL;
                char *firstname=strtok_r(strdup(id),".",&save_firstptr);
-               
+
                firstname=strtok_r(NULL,".",&save_firstptr);
                sprintf(soname,"%s/%s.so", mlt_tokeniser_get_string( tokeniser , dircount ) , firstname );
 
                if (firstname){
-                       
+
                        void* handle=dlopen(soname,RTLD_LAZY);
-                       
+
                        if (handle ){
                                ret=load_lib ( profile , type , handle );
                        }else{
@@ -228,38 +283,41 @@ MLT_REPOSITORY
        mlt_tokeniser tokeniser = mlt_tokeniser_init ( );
        int dircount=mlt_tokeniser_parse_new (
                tokeniser ,
-       getenv("MLT_FREI0R_PLUGIN_PATH") ? getenv("MLT_FREI0R_PLUGIN_PATH") : "/usr/lib/frei0r-1" ,
+       getenv("MLT_FREI0R_PLUGIN_PATH") ? getenv("MLT_FREI0R_PLUGIN_PATH") : FREI0R_PLUGIN_PATH,
                ":"
        );
-       
+
        while (dircount--){
-               
+
                mlt_properties direntries = mlt_properties_new();
                char* dirname = mlt_tokeniser_get_string ( tokeniser , dircount ) ;
                mlt_properties_dir_list(direntries, dirname ,"*.so",1);
-       
+
                for (i=0;i<mlt_properties_count(direntries);i++){
-                       char* name=mlt_properties_get_value(direntries,i);      
+                       char* name=mlt_properties_get_value(direntries,i);
                        char* shortname=name+strlen(dirname)+1;
                        char fname[1024]="";
-                       
+
                        strcat(fname,dirname);
                        strcat(fname,shortname);
-                       
+
                        char *save_firstptr = NULL;
                        char pluginname[1024]="frei0r.";
                        char* firstname = strtok_r ( shortname , "." , &save_firstptr );
                        strcat(pluginname,firstname);
-       
+
                        void* handle=dlopen(strcat(name,".so"),RTLD_LAZY);
                        if (handle){
                                void (*plginfo)(f0r_plugin_info_t*)=dlsym(handle,"f0r_get_plugin_info");
-                               
+
                                if (plginfo){
                                        f0r_plugin_info_t info;
                                        plginfo(&info);
-                                       
-                                       if (firstname && info.plugin_type==F0R_PLUGIN_TYPE_FILTER){
+                                       if (firstname && info.plugin_type==F0R_PLUGIN_TYPE_SOURCE){
+                                               MLT_REGISTER( producer_type, pluginname, create_frei0r_item );
+                                               MLT_REGISTER_METADATA( producer_type, pluginname, fill_param_info, strdup(name) );
+                                       }
+                                       else if (firstname && info.plugin_type==F0R_PLUGIN_TYPE_FILTER){
                                                MLT_REGISTER( filter_type, pluginname, create_frei0r_item );
                                                MLT_REGISTER_METADATA( filter_type, pluginname, fill_param_info, strdup(name) );
                                        }