fix plugin probe when LANG != en
[goodguy/history.git] / cinelerra-5.0 / cinelerra / pluginserver.C
index 17e1b17e7afdd34b023f9be5fbb73785e071b82e..25573cf4b95986e61e61ae4ec3af2af501f73567 100644 (file)
@@ -30,6 +30,7 @@
 #include "edl.h"
 #include "edlsession.h"
 #include "floatautos.h"
+#include "format.inc"
 #include "keyframes.h"
 #include "localsession.h"
 #include "mainerror.h"
@@ -50,6 +51,7 @@
 #include "samples.h"
 #include "sema.h"
 #include "mainsession.h"
+#include "theme.h"
 #include "trackcanvas.h"
 #include "transportque.h"
 #include "vdevicex11.h"
@@ -74,6 +76,7 @@ void PluginServer::init()
 {
        reset_parameters();
        this->plugin_type = PLUGIN_TYPE_UNKNOWN;
+       plugin_obj = new PluginObj();
        modules = new ArrayList<Module*>;
        nodes = new ArrayList<VirtualNode*>;
 }
@@ -101,6 +104,8 @@ PluginServer::PluginServer(PluginServer &that)
 {
        reset_parameters();
        plugin_type = that.plugin_type;
+       plugin_obj = that.plugin_obj;
+       plugin_obj->add_user();
        title = !that.title ? 0 : cstrdup(that.title);
        path = !that.path ? 0 : cstrdup(that.path);
        ff_name = !that.ff_name ? 0 : cstrdup(that.ff_name);
@@ -135,6 +140,7 @@ PluginServer::~PluginServer()
        delete modules;
        delete nodes;
        delete picon;
+       plugin_obj->remove_user();
 }
 
 // Done only once at creation
@@ -146,7 +152,6 @@ int PluginServer::reset_parameters()
        cleanup_plugin();
        autos = 0;
        edl = 0;
-       dlobj = 0;
        preferences = 0;
        title = 0;
        path = 0;
@@ -265,34 +270,36 @@ void PluginServer::generate_display_title(char *string)
                strcpy(string, ltitle);
 }
 
-void *PluginServer::load_obj()
+void *PluginObj::load(const char *plugin_dir, const char *path)
 {
-       if( !dlobj ) {
-               char dlpath[BCTEXTLEN], *dp = dlpath;
-               char *cp = path;
-               if( *cp != '/' ) {
-                       char *bp = preferences->plugin_dir;
-                       while( *bp ) *dp++ = *bp++;
-                       *dp++ = '/';
-               }
-               while( *cp ) *dp++ = *cp++;
-               *dp = 0;
-               dlobj = load(dlpath);
+       char dlpath[BCTEXTLEN], *dp = dlpath;
+       const char *cp = path;
+       if( *cp != '/' ) {
+               const char *bp = plugin_dir;
+               while( *bp ) *dp++ = *bp++;
+               *dp++ = '/';
        }
-       return dlobj;
+       while( *cp ) *dp++ = *cp++;
+       *dp = 0;
+       return dlobj = load(dlpath);
+}
+
+int PluginServer::load_obj()
+{
+       void *obj = plugin_obj->obj();
+       if( !obj ) obj =plugin_obj->load(preferences->plugin_dir, path);
+       return obj ? 1 : 0;
 }
 
-void PluginServer::unload_obj()
+const char *PluginServer::load_error()
 {
-       if( !dlobj ) return;
-       unload(dlobj);  dlobj = 0;
+       return plugin_obj->load_error();
 }
 
-void PluginServer::delete_this()
+void *PluginServer::get_sym(const char *sym)
 {
-       void *obj = dlobj;
-       delete this;
-       if( obj ) unload(obj);
+       if( !plugin_obj->obj() ) return 0;
+       return plugin_obj->load_sym(sym);
 }
 
 // Open plugin for signal processing
@@ -307,31 +314,23 @@ int PluginServer::open_plugin(int master,
        this->plugin = plugin;
        this->edl = edl;
        if( plugin_type != PLUGIN_TYPE_FFMPEG && plugin_type != PLUGIN_TYPE_EXECUTABLE && !load_obj() ) {
-// If the load failed it may still be an executable tool for a specific
-// file format, in which case we just store the path.
-               set_title(path);
-               char string[BCTEXTLEN];
-               strcpy(string, load_error());
-               if( !strstr(string, "executable") ) {
-                       eprintf("PluginServer::open_plugin: load_obj failure = %s\n", string);
-                       return PLUGINSERVER_NOT_RECOGNIZED;
-               }
-               plugin_type = PLUGIN_TYPE_EXECUTABLE;
+// If the load failed, can't use error to detect executable
+//  because locale and language selection change the load_error()
+//     if( !strstr(string, "executable") ) { set_title(path); plugin_type = PLUGIN_TYPE_EXECUTABLE; }
+               eprintf("PluginServer::open_plugin: load_obj %s = %s\n", path, load_error());
+               return PLUGINSERVER_NOT_RECOGNIZED;
        }
        if( plugin_type == PLUGIN_TYPE_UNKNOWN || plugin_type == PLUGIN_TYPE_BUILTIN ) {
                new_plugin =
-                       (PluginClient* (*)(PluginServer*)) load_sym("new_plugin");
+                       (PluginClient* (*)(PluginServer*)) get_sym("new_plugin");
                if( new_plugin )
                        plugin_type = PLUGIN_TYPE_BUILTIN;
        }
        if( plugin_type == PLUGIN_TYPE_UNKNOWN || plugin_type == PLUGIN_TYPE_LADSPA ) {
                lad_descriptor_function =
-                       (LADSPA_Descriptor_Function) load_sym("ladspa_descriptor");
+                       (LADSPA_Descriptor_Function) get_sym("ladspa_descriptor");
                if( lad_descriptor_function ) {
-                       if( lad_index < 0 ) {
-                               unload_obj();
-                               return PLUGINSERVER_IS_LAD;
-                       }
+                       if( lad_index < 0 ) return PLUGINSERVER_IS_LAD;
                        lad_descriptor = lad_descriptor_function(lad_index);
                        if( !lad_descriptor )
                                return PLUGINSERVER_NOT_RECOGNIZED;
@@ -341,10 +340,11 @@ int PluginServer::open_plugin(int master,
        if( plugin_type == PLUGIN_TYPE_UNKNOWN ) {
                fprintf(stderr, "PluginServer::open_plugin "
                        " %d: plugin undefined in %s\n", __LINE__, path);
-               unload_obj();
                return PLUGINSERVER_NOT_RECOGNIZED;
        }
        switch( plugin_type ) {
+       case PLUGIN_TYPE_EXECUTABLE:
+               return PLUGINSERVER_OK;
        case PLUGIN_TYPE_BUILTIN:
                client = new_plugin(this);
                break;
@@ -422,29 +422,29 @@ void PluginServer::render_stop()
                client->render_stop();
 }
 
-void PluginServer::write_table(FILE *fp, int idx)
+void PluginServer::write_table(FILE *fp, const char *path, int idx, int64_t mtime)
 {
        if(!fp) return;
-       fprintf(fp, "%d \"%s\" \"%s\" %d %d %d %d %d %d %d %d %d %d %d\n",
-               plugin_type, path, title, idx, audio, video, theme, realtime,
+       fprintf(fp, "%d \"%s\" \"%s\" " _LD " %d %d %d %d %d %d %d %d %d %d %d\n",
+               plugin_type, path, title, mtime, idx, audio, video, theme, realtime,
                fileio, uses_gui, multichannel, synthesis, transition, lad_index);
 }
 
-int PluginServer::scan_table(char *text, int &type, char *path, char *title)
+int PluginServer::scan_table(char *text, int &type, char *path, char *title, int64_t &mtime)
 {
-       int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\"", &type, path, title);
-       return n < 3 ? 1 : 0;
+       int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\" " _LD "", &type, path, title, &mtime);
+       return n < 4 ? 1 : 0;
 }
 
 int PluginServer::read_table(char *text)
 {
        char path[BCTEXTLEN], title[BCTEXTLEN];
-       int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\" %d %d %d %d %d %d %d %d %d %d %d",
-               &plugin_type, path, title, &dir_idx, &audio, &video, &theme, &realtime,
+       int64_t mtime;
+       int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\" " _LD " %d %d %d %d %d %d %d %d %d %d %d",
+               &plugin_type, path, title, &mtime, &dir_idx, &audio, &video, &theme, &realtime,
                &fileio, &uses_gui, &multichannel, &synthesis, &transition, &lad_index);
-       if( n != 14 ) return 1;
-       this->path = cstrdup(path);
-       this->title = cstrdup(title);
+       if( n != 15 ) return 1;
+       set_title(title);
        return 0;
 }
 
@@ -1207,38 +1207,60 @@ Theme* PluginServer::get_theme()
 }
 
 
-char *PluginServer::get_plugin_png_path(char *png_path)
+int PluginServer::get_theme_png_path(char *png_path, const char *theme_dir)
 {
-       char *bp = strrchr(path, '/'), *cp = png_path;
+       char *bp = strrchr(path, '/');
        if( !bp ) bp = path; else ++bp;
        char *sp = strrchr(bp,'.');
        if( !sp || ( strcmp(sp, ".plugin") && strcmp(sp,".so") ) ) return 0;
-       cp += sprintf(cp,"%s/picons/", mwindow->preferences->plugin_dir);
-       while( bp < sp ) *cp++ = *bp++;
+       char *cp = png_path, *dp = bp;
+       cp += sprintf(cp,"%s/%s/", mwindow->preferences->plugin_dir, theme_dir);
+       while( dp < sp ) *cp++ = *dp++;
        strcpy(cp, ".png");
-       return png_path;
+       struct stat st;
+       if( stat(png_path, &st) ) return 0;
+       if( !S_ISREG(st.st_mode) ) return 0;
+       if( st.st_size == 0 ) return 0;
+       return st.st_size;
+}
+
+int PluginServer::get_theme_png_path(char *png_path, Theme *theme)
+{
+       char *bp = strrchr(theme->path, '/');
+       if( !bp ) bp = theme->path; else ++bp;
+       char *sp = strrchr(bp,'.');
+       if( !sp || ( strcmp(sp, ".plugin") && strcmp(sp,".so") ) ) return 0;
+       char theme_dir[BCTEXTLEN], *cp = theme_dir;
+       while( bp < sp ) *cp++ = *bp++;
+       *cp = 0;
+       return get_theme_png_path(png_path, theme_dir);
+}
+
+int PluginServer::get_plugin_png_path(char *png_path)
+{
+       int len = get_theme_png_path(png_path, mwindow->theme);
+       if( !len )
+               len = get_theme_png_path(png_path, "picon");
+       return len;
 }
 
 VFrame *PluginServer::get_plugin_images()
 {
        char png_path[BCTEXTLEN];
-       if( !get_plugin_png_path(png_path) ) return 0;
-       struct stat st;
-       if( stat(png_path, &st) ) return 0;
-       if( !S_ISREG(st.st_mode) ) return 0;
-       if( st.st_size == 0 ) return 0;
-       unsigned len = st.st_size;
+       int len = get_plugin_png_path(png_path);
+       if( !len ) return 0;
        int ret = 0, w = 0, h = 0;
-       uint8_t *bfr = 0;
+       unsigned char *bfr = 0;
        int fd = ::open(png_path, O_RDONLY);
        if( fd < 0 ) ret = 1;
        if( !ret ) {
-               bfr = (uint8_t*) ::mmap (NULL, len, PROT_READ, MAP_SHARED, fd, 0); 
+               bfr = (unsigned char *) ::mmap (NULL, len, PROT_READ, MAP_SHARED, fd, 0); 
                if( bfr == MAP_FAILED ) ret = 1;
        }
        VFrame *vframe = 0;
        if( !ret ) {
-               vframe = new VFrame(bfr, st.st_size);
+               double scale = BC_WindowBase::get_resources()->icon_scale;
+               vframe = new VFramePng(bfr, len, scale, scale);
                if( (w=vframe->get_w()) <= 0 || (h=vframe->get_h()) <= 0 ||
                    vframe->get_data() == 0 ) ret = 1;
        }