1 #include "attachmentpoint.h"
4 #include "edlsession.h"
7 #include "pluginserver.h"
8 #include "renderengine.h"
9 #include "transportque.h"
10 #include "virtualnode.h"
14 AttachmentPoint::AttachmentPoint(RenderEngine *renderengine, Plugin *plugin)
17 this->plugin = plugin;
18 this->renderengine = renderengine;
19 plugin_server = renderengine->scan_plugindb(plugin->title);
20 //printf("AttachmentPoint::AttachmentPoint %s %p\n", plugin->title, plugin_server);
23 AttachmentPoint::~AttachmentPoint()
25 delete_buffer_vectors();
26 plugin_servers.remove_all_objects();
30 int AttachmentPoint::reset_parameters()
36 new_total_input_buffers = 0;
37 total_input_buffers = 0;
41 int AttachmentPoint::render_init()
43 //printf("AttachmentPoint::render_init 1\n");
44 if(plugin_server && plugin->on)
46 // Start new plugins or continue existing plugins
47 // Create new plugin servers
48 //printf("AttachmentPoint::render_init 2 %d %d\n", virtual_plugins.total, new_virtual_plugins.total);
49 if(virtual_plugins.total != new_virtual_plugins.total)
51 //printf("AttachmentPoint::render_init 3\n");
52 plugin_servers.remove_all_objects();
53 //printf("AttachmentPoint::render_init 4\n");
54 for(int i = 0; i < new_virtual_plugins.total; i++)
56 //printf("AttachmentPoint::render_init 5\n");
57 if(i == 0 || !plugin_server->multichannel)
59 //printf("AttachmentPoint::render_init 5.1\n");
60 PluginServer *new_server;
61 plugin_servers.append(new_server = new PluginServer(*plugin_server));
62 new_server->set_attachmentpoint(this);
63 //printf("AttachmentPoint::render_init 5.2 %p %p\n", plugin_servers.values[i], plugin);
64 plugin_servers.values[i]->open_plugin(0, renderengine->edl, plugin);
65 //printf("AttachmentPoint::render_init 5.3\n");
66 plugin_servers.values[i]->init_realtime(
67 renderengine->edl->session->real_time_playback &&
68 renderengine->command->realtime,
69 new_total_input_buffers,
71 //printf("AttachmentPoint::render_init 5.4\n");
73 //printf("AttachmentPoint::render_init 6\n");
78 //printf("AttachmentPoint::render_init 7\n");
79 virtual_plugins.remove_all();
80 for(int i = 0; i < new_virtual_plugins.total; i++)
81 virtual_plugins.append(new_virtual_plugins.values[i]);
82 new_virtual_plugins.remove_all();
83 //printf("AttachmentPoint::render_init 8\n");
85 total_input_buffers = new_total_input_buffers;
86 new_total_input_buffers = 0;
87 //printf("AttachmentPoint::render_init 9\n");
89 delete_buffer_vectors();
91 //printf("AttachmentPoint::render_init 10\n");
95 int AttachmentPoint::render_stop(int duplicate)
98 // Can't use the on value here because it may have changed.
99 //printf("AttachmentPoint::render_stop 1\n");
100 if(plugin_server && plugin->on && virtual_plugins.total && !duplicate)
102 // close the plugins if not shared
103 for(int i = 0; i < virtual_plugins.total; i++)
105 if(i == 0 || !plugin_server->multichannel)
107 //printf("AttachmentPoint::render_stop 2\n");
108 plugin_servers.values[i]->close_plugin();
111 //printf("AttachmentPoint::render_stop 3\n");
112 plugin_servers.remove_all_objects();
117 int AttachmentPoint::attach_virtual_plugin(VirtualNode *virtual_plugin)
119 int in_buffer_number = 0;
121 // add virtual plugin to list of new virtual plugins
122 new_virtual_plugins.append(virtual_plugin);
124 // Increment input buffer counter
125 if(plugin_server && plugin->on)
127 in_buffer_number = new_total_input_buffers++;
129 //printf("AttachmentPoint::attach_virtual_plugin %p %d %d %d\n", plugin_server, plugin->on, in_buffer_number, new_total_input_buffers);
131 return in_buffer_number;
134 int AttachmentPoint::sort(VirtualNode *virtual_plugin)
138 for(int i = 0; i < new_virtual_plugins.total && !result; i++)
140 // if no virtual plugins attached to this are waiting return 1
141 if(!new_virtual_plugins.values[i]->waiting_real_plugin) result = 1;
147 int AttachmentPoint::multichannel_shared(int search_new)
151 if(new_virtual_plugins.total &&
153 plugin_server->multichannel) return 1;
157 if(virtual_plugins.total &&
159 plugin_server->multichannel) return 1;
164 int AttachmentPoint::singlechannel()
166 if(plugin_server && !plugin_server->multichannel) return 1;
170 void AttachmentPoint::render(long current_position, long fragment_size)
172 // All buffers must be armed before proceeding
173 //printf("AttachmentPoint::render 1 %p %s\n", plugin_server, plugin_server->title);
176 if(current_buffer == total_input_buffers - 1 ||
177 !plugin_server->multichannel)
179 dispatch_plugin_server(current_buffer,
186 if(current_buffer >= total_input_buffers) current_buffer = 0;
187 //printf("AttachmentPoint::render 10\n");
191 void AttachmentPoint::render_gui(void *data)
193 //printf("AttachmentPoint::render_gui 1 %p %p\n", renderengine, renderengine->mwindow);
194 if(renderengine && renderengine->mwindow)
195 renderengine->mwindow->render_plugin_gui(data, plugin);
198 void AttachmentPoint::render_gui(void *data, int size)
200 if(renderengine && renderengine->mwindow)
201 renderengine->mwindow->render_plugin_gui(data, size, plugin);
216 int AttachmentPoint::dump()
218 printf(" Attachmentpoint %x\n", this);
219 if(plugin_server) plugin_server->dump();