4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "attachmentpoint.h"
26 #include "bcsignals.h"
27 #include "cplayback.h"
31 #include "edlsession.h"
32 #include "floatautos.h"
33 #include "keyframes.h"
34 #include "localsession.h"
35 #include "mainerror.h"
36 #include "mainprogress.h"
37 #include "menueffects.h"
39 #include "mwindowgui.h"
40 #include "playbackengine.h"
42 #include "pluginaclient.h"
43 #include "pluginaclientlad.h"
44 #include "pluginfclient.h"
45 #include "pluginclient.h"
46 #include "plugincommands.h"
47 #include "pluginserver.h"
48 #include "pluginvclient.h"
49 #include "preferences.h"
52 #include "mainsession.h"
54 #include "trackcanvas.h"
55 #include "transportque.h"
56 #include "vdevicex11.h"
58 #include "videodevice.h"
59 #include "virtualanode.h"
60 #include "virtualvnode.h"
68 #include <sys/types.h>
74 void PluginServer::init()
77 this->plugin_type = PLUGIN_TYPE_UNKNOWN;
78 plugin_obj = new PluginObj();
79 modules = new ArrayList<Module*>;
80 nodes = new ArrayList<VirtualNode*>;
83 PluginServer::PluginServer()
88 PluginServer::PluginServer(MWindow *mwindow, char *path, int type)
90 char fpath[BCTEXTLEN];
92 this->plugin_type = type;
93 this->mwindow = mwindow;
94 if( type == PLUGIN_TYPE_FFMPEG ) {
95 ff_name = cstrdup(path);
96 sprintf(fpath, "ff_%s", path);
102 PluginServer::PluginServer(PluginServer &that)
105 plugin_type = that.plugin_type;
106 plugin_obj = that.plugin_obj;
107 plugin_obj->add_user();
108 title = !that.title ? 0 : cstrdup(that.title);
109 path = !that.path ? 0 : cstrdup(that.path);
110 ff_name = !that.ff_name ? 0 : cstrdup(that.ff_name);
111 modules = new ArrayList<Module*>;
112 nodes = new ArrayList<VirtualNode*>;
114 attachment = that.attachment;
115 realtime = that.realtime;
116 multichannel = that.multichannel;
117 preferences = that.preferences;
118 synthesis = that.synthesis;
122 fileio = that.fileio;
123 uses_gui = that.uses_gui;
124 mwindow = that.mwindow;
125 keyframe = that.keyframe;
126 new_plugin = that.new_plugin;
128 lad_descriptor = that.lad_descriptor;
129 lad_descriptor_function = that.lad_descriptor_function;
130 lad_index = that.lad_index;
133 PluginServer::~PluginServer()
142 plugin_obj->remove_user();
145 // Done only once at creation
146 int PluginServer::reset_parameters()
158 audio = video = theme = 0;
161 realtime = multichannel = fileio = 0;
163 start_auto = end_auto = 0;
174 lad_descriptor_function = 0;
179 // Done every time the plugin is opened or closed
180 int PluginServer::cleanup_plugin()
182 in_buffer_size = out_buffer_size = 0;
183 total_in_buffers = total_out_buffers = 0;
188 written_samples = written_frames = 0;
195 void PluginServer::set_mwindow(MWindow *mwindow)
197 this->mwindow = mwindow;
200 void PluginServer::set_attachmentpoint(AttachmentPoint *attachmentpoint)
202 this->attachmentpoint = attachmentpoint;
205 void PluginServer::set_keyframe(KeyFrame *keyframe)
207 this->keyframe = keyframe;
210 void PluginServer::set_prompt(MenuEffectPrompt *prompt)
212 this->prompt = prompt;
215 void PluginServer::set_lad_index(int i)
220 int PluginServer::get_lad_index()
222 return this->lad_index;
225 int PluginServer::is_ladspa()
227 return plugin_type == PLUGIN_TYPE_LADSPA ? 1 : 0;
230 int PluginServer::is_ffmpeg()
232 return plugin_type == PLUGIN_TYPE_FFMPEG ? 1 : 0;
235 void PluginServer::set_path(const char *path)
237 delete [] this->path;
238 this->path = cstrdup(path);
241 char* PluginServer::get_path()
246 int PluginServer::get_synthesis()
252 void PluginServer::set_title(const char *string)
254 if(title) delete [] title;
255 title = cstrdup(string);
258 void PluginServer::generate_display_title(char *string)
260 char ltitle[BCTEXTLEN];
261 if(BC_Resources::locale_utf8)
262 strcpy(ltitle, _(title));
264 BC_Resources::encode(BC_Resources::encoding, 0,
265 _(title),strlen(title)+1, ltitle,BCTEXTLEN);
266 if(plugin && plugin->track)
267 sprintf(string, "%s: %s", plugin->track->title, ltitle);
269 strcpy(string, ltitle);
272 void *PluginObj::load(const char *plugin_dir, const char *path)
274 char dlpath[BCTEXTLEN], *dp = dlpath;
275 const char *cp = path;
277 const char *bp = plugin_dir;
278 while( *bp ) *dp++ = *bp++;
281 while( *cp ) *dp++ = *cp++;
283 return dlobj = load(dlpath);
286 int PluginServer::load_obj()
288 void *obj = plugin_obj->obj();
289 if( !obj ) obj =plugin_obj->load(preferences->plugin_dir, path);
293 const char *PluginServer::load_error()
295 return plugin_obj->load_error();
298 void *PluginServer::get_sym(const char *sym)
300 if( !plugin_obj->obj() ) return 0;
301 return plugin_obj->load_sym(sym);
304 // Open plugin for signal processing
305 int PluginServer::open_plugin(int master,
306 Preferences *preferences,
310 if(plugin_open) return 0;
312 this->preferences = preferences;
313 this->plugin = plugin;
315 if( plugin_type != PLUGIN_TYPE_FFMPEG && plugin_type != PLUGIN_TYPE_EXECUTABLE && !load_obj() ) {
316 // If the load failed, can't use error to detect executable
317 // because locale and language selection change the load_error()
318 // if( !strstr(string, "executable") ) { set_title(path); plugin_type = PLUGIN_TYPE_EXECUTABLE; }
319 eprintf("PluginServer::open_plugin: load_obj %s = %s\n", path, load_error());
320 return PLUGINSERVER_NOT_RECOGNIZED;
322 if( plugin_type == PLUGIN_TYPE_UNKNOWN || plugin_type == PLUGIN_TYPE_BUILTIN ) {
324 (PluginClient* (*)(PluginServer*)) get_sym("new_plugin");
326 plugin_type = PLUGIN_TYPE_BUILTIN;
328 if( plugin_type == PLUGIN_TYPE_UNKNOWN || plugin_type == PLUGIN_TYPE_LADSPA ) {
329 lad_descriptor_function =
330 (LADSPA_Descriptor_Function) get_sym("ladspa_descriptor");
331 if( lad_descriptor_function ) {
332 if( lad_index < 0 ) return PLUGINSERVER_IS_LAD;
333 lad_descriptor = lad_descriptor_function(lad_index);
334 if( !lad_descriptor )
335 return PLUGINSERVER_NOT_RECOGNIZED;
336 plugin_type = PLUGIN_TYPE_LADSPA;
339 if( plugin_type == PLUGIN_TYPE_UNKNOWN ) {
340 fprintf(stderr, "PluginServer::open_plugin "
341 " %d: plugin undefined in %s\n", __LINE__, path);
342 return PLUGINSERVER_NOT_RECOGNIZED;
344 switch( plugin_type ) {
345 case PLUGIN_TYPE_EXECUTABLE:
346 return PLUGINSERVER_OK;
347 case PLUGIN_TYPE_BUILTIN:
348 client = new_plugin(this);
350 case PLUGIN_TYPE_LADSPA:
351 client = new PluginAClientLAD(this);
353 case PLUGIN_TYPE_FFMPEG:
354 client = new_ffmpeg_plugin();
361 return PLUGINSERVER_NOT_RECOGNIZED;
363 // Run initialization functions
364 realtime = client->is_realtime();
365 // Don't load defaults when probing the directory.
368 client->load_defaults_xml();
370 client->load_defaults();
372 audio = client->is_audio();
373 video = client->is_video();
374 theme = client->is_theme();
375 fileio = client->is_fileio();
376 uses_gui = client->uses_gui();
377 multichannel = client->is_multichannel();
378 synthesis = client->is_synthesis();
379 transition = client->is_transition();
380 set_title(client->plugin_title());
382 //printf("PluginServer::open_plugin 2\n");
384 return PLUGINSERVER_OK;
387 int PluginServer::close_plugin()
389 if(!plugin_open) return 0;
393 // Defaults are saved in the thread.
394 // if(client->defaults) client->save_defaults();
398 // shared object is persistent since plugin deletion would unlink its own object
404 void PluginServer::client_side_close()
406 // Last command executed in client thread
408 mwindow->hide_plugin(plugin, 1);
412 prompt->lock_window();
414 prompt->unlock_window();
418 void PluginServer::render_stop()
421 client->render_stop();
424 void PluginServer::write_table(FILE *fp, const char *path, int idx, int64_t mtime)
427 fprintf(fp, "%d \"%s\" \"%s\" %jd %d %d %d %d %d %d %d %d %d %d %d\n",
428 plugin_type, path, title, mtime, idx, audio, video, theme, realtime,
429 fileio, uses_gui, multichannel, synthesis, transition, lad_index);
432 int PluginServer::scan_table(char *text, int &type, char *path, char *title, int64_t &mtime)
434 int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\" %jd", &type, path, title, &mtime);
435 return n < 4 ? 1 : 0;
438 int PluginServer::read_table(char *text)
440 char path[BCTEXTLEN], title[BCTEXTLEN];
442 int n = sscanf(text, "%d \"%[^\"]\" \"%[^\"]\" %jd %d %d %d %d %d %d %d %d %d %d %d",
443 &plugin_type, path, title, &mtime, &dir_idx, &audio, &video, &theme, &realtime,
444 &fileio, &uses_gui, &multichannel, &synthesis, &transition, &lad_index);
445 if( n != 15 ) return 1;
450 int PluginServer::init_realtime(int realtime_sched,
451 int total_in_buffers,
455 if(!plugin_open) return 0;
457 // set for realtime priority
459 // Call start_realtime
460 this->total_in_buffers = this->total_out_buffers = total_in_buffers;
461 client->plugin_init_realtime(realtime_sched,
469 // Replaced by pull method but still needed for transitions
470 void PluginServer::process_transition(VFrame *input,
472 int64_t current_position,
475 if(!plugin_open) return;
476 PluginVClient *vclient = (PluginVClient*)client;
478 vclient->source_position = current_position;
479 vclient->source_start = 0;
480 vclient->total_len = total_len;
482 vclient->input = new VFrame*[1];
483 vclient->output = new VFrame*[1];
485 vclient->input[0] = input;
486 vclient->output[0] = output;
488 vclient->process_realtime(input, output);
490 delete [] vclient->input;
491 delete [] vclient->output;
495 void PluginServer::process_transition(Samples *input,
497 int64_t current_position,
498 int64_t fragment_size,
501 if(!plugin_open) return;
502 PluginAClient *aclient = (PluginAClient*)client;
504 aclient->source_position = current_position;
505 aclient->total_len = total_len;
506 aclient->source_start = 0;
507 aclient->process_realtime(fragment_size,
513 void PluginServer::process_buffer(VFrame **frame,
514 int64_t current_position,
519 if(!plugin_open) return;
520 PluginVClient *vclient = (PluginVClient*)client;
522 vclient->source_position = current_position;
523 vclient->total_len = total_len;
524 vclient->frame_rate = frame_rate;
525 vclient->input = new VFrame*[total_in_buffers];
526 vclient->output = new VFrame*[total_in_buffers];
527 for(int i = 0; i < total_in_buffers; i++)
529 vclient->input[i] = frame[i];
530 vclient->output[i] = frame[i];
535 vclient->source_start = (int64_t)plugin->startproject *
537 vclient->project_frame_rate;
539 vclient->direction = direction;
543 //printf("plugin=%p source_start=%ld\n", plugin, vclient->source_start);
545 vclient->begin_process_buffer();
548 vclient->process_buffer(frame, current_position, frame_rate);
552 vclient->process_buffer(frame[0], current_position, frame_rate);
554 vclient->end_process_buffer();
556 for(int i = 0; i < total_in_buffers; i++)
557 frame[i]->push_prev_effect(title);
559 delete [] vclient->input;
560 delete [] vclient->output;
566 void PluginServer::process_buffer(Samples **buffer,
567 int64_t current_position,
568 int64_t fragment_size,
573 if(!plugin_open) return;
574 PluginAClient *aclient = (PluginAClient*)client;
576 aclient->source_position = current_position;
577 aclient->total_len = total_len;
578 aclient->sample_rate = sample_rate;
581 aclient->source_start = plugin->startproject *
583 aclient->project_sample_rate;
585 aclient->direction = direction;
586 aclient->begin_process_buffer();
589 aclient->process_buffer(fragment_size,
596 aclient->process_buffer(fragment_size,
601 aclient->end_process_buffer();
605 void PluginServer::send_render_gui(void *data)
607 //printf("PluginServer::send_render_gui 1 %p\n", attachmentpoint);
608 if(attachmentpoint) attachmentpoint->render_gui(data, this);
611 void PluginServer::send_render_gui(void *data, int size)
613 //printf("PluginServer::send_render_gui 1 %p\n", attachmentpoint);
614 if(attachmentpoint) attachmentpoint->render_gui(data, size, this);
617 void PluginServer::render_gui(void *data)
619 if(client) client->plugin_render_gui(data);
622 void PluginServer::render_gui(void *data, int size)
624 if(client) client->plugin_render_gui(data, size);
627 MainProgressBar* PluginServer::start_progress(char *string, int64_t length)
629 mwindow->gui->lock_window();
630 MainProgressBar *result = mwindow->mainprogress->start_progress(string, length);
631 mwindow->gui->unlock_window();
635 int64_t PluginServer::get_written_samples()
637 if(!plugin_open) return 0;
638 return written_samples;
641 int64_t PluginServer::get_written_frames()
643 if(!plugin_open) return 0;
644 return written_frames;
656 // ======================= Non-realtime plugin
658 int PluginServer::get_parameters(int64_t start, int64_t end, int channels)
660 if(!plugin_open) return 0;
662 client->start = start;
664 client->source_start = start;
665 client->total_len = end - start;
666 client->total_in_buffers = channels;
669 //printf(" source_start=%ld total_len=%ld\n", client->source_start, client->total_len);
671 return client->plugin_get_parameters();
674 int PluginServer::set_interactive()
676 if(!plugin_open) return 0;
677 client->set_interactive();
681 void PluginServer::append_module(Module *module)
683 modules->append(module);
686 void PluginServer::append_node(VirtualNode *node)
691 void PluginServer::reset_nodes()
696 int PluginServer::set_error()
702 int PluginServer::set_realtime_sched()
704 //struct sched_param params;
705 //params.sched_priority = 1;
706 //sched_setscheduler(0, SCHED_RR, ¶m);
711 int PluginServer::process_loop(VFrame **buffers, int64_t &write_length)
713 if(!plugin_open) return 1;
714 return client->plugin_process_loop(buffers, write_length);
717 int PluginServer::process_loop(Samples **buffers, int64_t &write_length)
719 if(!plugin_open) return 1;
720 return client->plugin_process_loop(buffers, write_length);
724 int PluginServer::start_loop(int64_t start,
729 if(!plugin_open) return 0;
730 client->plugin_start_loop(start, end, buffer_size, total_buffers);
734 int PluginServer::stop_loop()
736 if(!plugin_open) return 0;
737 return client->plugin_stop_loop();
740 int PluginServer::read_frame(VFrame *buffer,
742 int64_t start_position)
744 ((VModule*)modules->values[channel])->render(buffer,
747 mwindow->edl->session->frame_rate,
753 int PluginServer::read_samples(Samples *buffer,
756 int64_t start_position,
759 // len is now in buffer
760 if(!multichannel) channel = 0;
762 if(nodes->total > channel)
763 return ((VirtualANode*)nodes->values[channel])->read_data(buffer,
768 if(modules->total > channel)
769 return ((AModule*)modules->values[channel])->render(buffer,
777 printf("PluginServer::read_samples no object available for channel=%d\n",
785 int PluginServer::read_samples(Samples *buffer,
787 int64_t start_position,
790 // total_samples is now set in buffer
791 ((AModule*)modules->values[channel])->render(buffer,
795 mwindow->edl->session->sample_rate,
800 int PluginServer::read_frame(VFrame *buffer,
802 int64_t start_position,
806 // Data source depends on whether we're part of a virtual console or a
810 // If we're a VirtualNode, read_data in the virtual plugin node handles
811 // backward propogation and produces the data.
812 // If we're a Module, render in the module produces the data.
816 if(!multichannel) channel = 0;
818 // Push our name on the next effect stack
819 buffer->push_next_effect(title);
820 //printf("PluginServer::read_frame %p\n", buffer);
821 //buffer->dump_stacks();
823 if(nodes->total > channel)
825 //printf("PluginServer::read_frame %d\n", __LINE__);
826 result = ((VirtualVNode*)nodes->values[channel])->read_data(buffer,
832 if(modules->total > channel)
834 //printf("PluginServer::read_frame %d\n", __LINE__);
835 result = ((VModule*)modules->values[channel])->render(buffer,
846 printf("PluginServer::read_frame no object available for channel=%d\n",
850 // Pop our name from the next effect stack
851 buffer->pop_next_effect();
876 int PluginServer::get_gui_status()
879 return plugin->show ? GUI_ON : GUI_OFF;
884 void PluginServer::raise_window()
886 if(!plugin_open) return;
887 client->raise_window();
890 void PluginServer::show_gui()
892 if(!plugin_open) return;
893 if(plugin) client->total_len = plugin->length;
894 if(plugin) client->source_start = plugin->startproject;
897 client->source_position = Units::to_int64(
898 mwindow->edl->local_session->get_selectionstart(1) *
899 mwindow->edl->session->frame_rate);
904 client->source_position = Units::to_int64(
905 mwindow->edl->local_session->get_selectionstart(1) *
906 mwindow->edl->session->sample_rate);
909 client->update_display_title();
913 void PluginServer::hide_gui()
915 if(!plugin_open) return;
916 if(client->defaults) client->save_defaults();
920 void PluginServer::update_gui()
922 if(!plugin_open || !plugin) return;
924 client->total_len = plugin->length;
925 client->source_start = plugin->startproject;
929 client->source_position = Units::to_int64(
930 mwindow->edl->local_session->get_selectionstart(1) *
931 mwindow->edl->session->frame_rate);
936 client->source_position = Units::to_int64(
937 mwindow->edl->local_session->get_selectionstart(1) *
938 mwindow->edl->session->sample_rate);
941 client->plugin_update_gui();
944 void PluginServer::update_title()
946 if(!plugin_open) return;
948 client->update_display_title();
952 int PluginServer::set_string(char *string)
954 if(!plugin_open) return 0;
956 client->set_string_client(string);
960 int PluginServer::gui_open()
962 if(attachmentpoint) return attachmentpoint->gui_open();
966 void PluginServer::set_use_opengl(int value, VideoDevice *vdevice)
968 this->use_opengl = value;
969 this->vdevice = vdevice;
972 int PluginServer::get_use_opengl()
978 void PluginServer::run_opengl(PluginClient *plugin_client)
981 ((VDeviceX11*)vdevice->get_output_base())->run_plugin(plugin_client);
984 // ============================= queries
986 void PluginServer::get_defaults_path(char *path)
988 // Get plugin name from path
989 char *ptr1 = strrchr(get_path(), '/');
990 char *ptr2 = strrchr(get_path(), '.');
991 if(!ptr1) ptr1 = get_path();
992 if(!ptr2) ptr2 = get_path() + strlen(get_path());
993 char string2[BCTEXTLEN];
994 char *ptr3 = string2;
1000 sprintf(path, "%s%s.xml", BCASTDIR, string2);
1003 void PluginServer::save_defaults()
1005 if(client) client->save_defaults();
1008 int PluginServer::get_samplerate()
1010 if(!plugin_open) return 0;
1013 return client->get_samplerate();
1017 return mwindow->edl->session->sample_rate;
1020 printf("PluginServer::get_samplerate audio and mwindow == NULL\n");
1026 double PluginServer::get_framerate()
1028 if(!plugin_open) return 0;
1031 return client->get_framerate();
1035 return mwindow->edl->session->frame_rate;
1038 printf("PluginServer::get_framerate video and mwindow == NULL\n");
1043 int PluginServer::get_project_samplerate()
1046 return mwindow->edl->session->sample_rate;
1049 return edl->session->sample_rate;
1052 printf("PluginServer::get_project_samplerate mwindow and edl are NULL.\n");
1057 double PluginServer::get_project_framerate()
1060 return mwindow->edl->session->frame_rate;
1063 return edl->session->frame_rate;
1066 printf("PluginServer::get_project_framerate mwindow and edl are NULL.\n");
1073 int PluginServer::detach_buffers()
1075 ring_buffers_out.remove_all();
1076 offset_out_render.remove_all();
1077 double_buffer_out_render.remove_all();
1078 realtime_out_size.remove_all();
1080 ring_buffers_in.remove_all();
1081 offset_in_render.remove_all();
1082 double_buffer_in_render.remove_all();
1083 realtime_in_size.remove_all();
1085 out_buffer_size = 0;
1087 total_out_buffers = 0;
1089 total_in_buffers = 0;
1093 int PluginServer::arm_buffer(int buffer_number,
1096 int double_buffer_in,
1097 int double_buffer_out)
1099 offset_in_render.values[buffer_number] = offset_in;
1100 offset_out_render.values[buffer_number] = offset_out;
1101 double_buffer_in_render.values[buffer_number] = double_buffer_in;
1102 double_buffer_out_render.values[buffer_number] = double_buffer_out;
1107 int PluginServer::set_automation(FloatAutos *autos, FloatAuto **start_auto, FloatAuto **end_auto, int reverse)
1109 this->autos = autos;
1110 this->start_auto = start_auto;
1111 this->end_auto = end_auto;
1112 this->reverse = reverse;
1118 void PluginServer::save_data(KeyFrame *keyframe)
1120 if(!plugin_open) return;
1121 client->save_data(keyframe);
1124 KeyFrame* PluginServer::get_prev_keyframe(int64_t position)
1126 KeyFrame *result = 0;
1128 result = plugin->get_prev_keyframe(position, client->direction);
1134 KeyFrame* PluginServer::get_next_keyframe(int64_t position)
1136 KeyFrame *result = 0;
1138 result = plugin->get_next_keyframe(position, client->direction);
1145 KeyFrame* PluginServer::get_keyframe()
1148 // Realtime plugin case
1149 return plugin->get_keyframe();
1151 // Rendered plugin case
1156 void PluginServer::apply_keyframe(KeyFrame *src)
1160 keyframe->copy_data(src);
1165 plugin->keyframes->update_parameter(src);
1173 void PluginServer::get_camera(float *x, float *y, float *z,
1174 int64_t position, int direction)
1176 plugin->track->automation->get_camera(x, y, z, position, direction);
1179 void PluginServer::get_projector(float *x, float *y, float *z,
1180 int64_t position, int direction)
1182 plugin->track->automation->get_projector(x, y, z, position, direction);
1186 int PluginServer::get_interpolation_type()
1188 return plugin->edl->session->interpolation_type;
1191 Theme* PluginServer::new_theme()
1195 return client->new_theme();
1201 Theme* PluginServer::get_theme()
1203 if(mwindow) return mwindow->theme;
1204 printf("PluginServer::get_theme mwindow not set\n");
1209 int PluginServer::get_theme_png_path(char *png_path, const char *theme_dir)
1211 char *bp = strrchr(path, '/');
1212 if( !bp ) bp = path; else ++bp;
1213 char *sp = strrchr(bp,'.');
1214 if( !sp || ( strcmp(sp, ".plugin") && strcmp(sp,".so") ) ) return 0;
1215 char *cp = png_path, *dp = bp;
1216 cp += sprintf(cp,"%s/%s/", mwindow->preferences->plugin_dir, theme_dir);
1217 while( dp < sp ) *cp++ = *dp++;
1220 if( stat(png_path, &st) ) return 0;
1221 if( !S_ISREG(st.st_mode) ) return 0;
1222 if( st.st_size == 0 ) return 0;
1226 int PluginServer::get_theme_png_path(char *png_path, Theme *theme)
1228 char *bp = strrchr(theme->path, '/');
1229 if( !bp ) bp = theme->path; else ++bp;
1230 char *sp = strrchr(bp,'.');
1231 if( !sp || ( strcmp(sp, ".plugin") && strcmp(sp,".so") ) ) return 0;
1232 char theme_dir[BCTEXTLEN], *cp = theme_dir;
1233 while( bp < sp ) *cp++ = *bp++;
1235 return get_theme_png_path(png_path, theme_dir);
1238 int PluginServer::get_plugin_png_path(char *png_path)
1240 int len = get_theme_png_path(png_path, mwindow->theme);
1242 len = get_theme_png_path(png_path, "picon");
1246 VFrame *PluginServer::get_plugin_images()
1248 char png_path[BCTEXTLEN];
1249 int len = get_plugin_png_path(png_path);
1250 if( !len ) return 0;
1251 int ret = 0, w = 0, h = 0;
1252 unsigned char *bfr = 0;
1253 int fd = ::open(png_path, O_RDONLY);
1254 if( fd < 0 ) ret = 1;
1256 bfr = (unsigned char *) ::mmap (NULL, len, PROT_READ, MAP_SHARED, fd, 0);
1257 if( bfr == MAP_FAILED ) ret = 1;
1261 double scale = BC_WindowBase::get_resources()->icon_scale;
1262 vframe = new VFramePng(bfr, len, scale, scale);
1263 if( (w=vframe->get_w()) <= 0 || (h=vframe->get_h()) <= 0 ||
1264 vframe->get_data() == 0 ) ret = 1;
1266 if( bfr && bfr != MAP_FAILED ) ::munmap(bfr, len);
1267 if( fd >= 0 ) ::close(fd);
1268 if( ret ) { delete vframe; vframe = 0; }
1272 VFrame *PluginServer::get_picon()
1275 picon = get_plugin_images();
1279 // Called when plugin interface is tweeked
1280 void PluginServer::sync_parameters()
1282 if(video) mwindow->restart_brender();
1283 mwindow->sync_parameters();
1284 mwindow->update_keyframe_guis();
1285 if(mwindow->edl->session->auto_conf->plugins)
1287 mwindow->gui->lock_window("PluginServer::sync_parameters");
1288 mwindow->gui->draw_overlays(1);
1289 mwindow->gui->unlock_window();
1295 void PluginServer::dump(FILE *fp)
1297 fprintf(fp," PluginServer %d %p %s %s %d\n",
1298 __LINE__, this, path, title, realtime);