4 * Copyright (C) 2008 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
22 #ifndef PLUGINSERVER_H
23 #define PLUGINSERVER_H
25 // inherited by plugins
33 #include "arraylist.h"
34 #include "attachmentpoint.inc"
36 #include "floatauto.inc"
37 #include "floatautos.inc"
39 #include "keyframe.inc"
41 #include "mainprogress.inc"
42 #include "maxbuffers.h"
43 #include "menueffects.inc"
45 #include "mwindow.inc"
47 #include "pluginaclientlad.inc"
48 #include "pluginfclient.inc"
49 #include "pluginclient.inc"
50 #include "pluginserver.inc"
51 #include "preferences.inc"
52 #include "samples.inc"
57 #include "videodevice.inc"
58 #include "virtualnode.inc"
62 class PluginObj : public Garbage {
66 void *load(const char *dlp) { return dlobj = dlopen(dlp, RTLD_NOW); }
67 void *load(const char *plugin_dir, const char *path);
68 void unload(void *obj) { dlclose(obj); }
69 void *load_sym(const char *sym) { return dlsym(dlobj, sym); }
70 const char *load_error() { return dlerror(); }
71 void *obj() { return dlobj; }
73 PluginObj() : Garbage("PluginObj:Garbage") { dlobj = 0; }
74 ~PluginObj() { if( dlobj ) unload(dlobj); }
79 PluginObj *plugin_obj;
81 const char *load_error();
82 void *get_sym(const char *sym);
84 int reset_parameters();
88 // Base class created by client
90 // If no path, this is going to be set to a function which
91 // instantiates the plugin.
92 PluginClient* (*new_plugin)(PluginServer*);
96 LADSPA_Descriptor_Function lad_descriptor_function;
97 const LADSPA_Descriptor *lad_descriptor;
101 // Driver for opengl calls.
102 VideoDevice *vdevice;
105 PluginServer(MWindow *mwindow, char *path, int type);
106 PluginServer(PluginServer &);
107 virtual ~PluginServer();
109 friend class PluginAClientLAD;
110 friend class PluginAClientConfig;
111 friend class PluginAClientWindow;
113 friend class PluginFClient;
114 friend class PluginFAClient;
115 friend class PluginFVClient;
116 friend class PluginFClientConfig;
117 friend class PluginFClientWindow;
119 // open a plugin and wait for commands
120 // Get information for plugindb if master.
121 #define PLUGINSERVER_IS_LAD 2
122 #define PLUGINSERVER_NOT_RECOGNIZED 1
123 #define PLUGINSERVER_OK 0
124 int open_plugin(int master, Preferences *preferences,
125 EDL *edl, Plugin *plugin);
128 char *get_plugin_png_path(char *png_path);
129 void dump(FILE *fp=stdout);
130 // Release any objects which are required after playback stops.
132 // Write entry into plugin table
133 void write_table(FILE *fp, int idx);
134 static int scan_table(char *text, int &type, char *path, char *title);
135 int read_table(char *text);
137 void set_title(const char *string);
138 // Generate title for display
139 void generate_display_title(char *string);
140 // Get keyframes for configuration. Position is always relative to EDL rate.
141 KeyFrame* get_prev_keyframe(int64_t position);
142 KeyFrame* get_next_keyframe(int64_t position);
143 // get camera and projector positions
144 void get_camera(float *x, float *y, float *z,
145 int64_t position, int direction);
146 void get_projector(float *x, float *y, float *z,
147 int64_t position, int direction);
148 // Get interpolation used by EDL
149 int get_interpolation_type();
150 // Get or create keyframe for writing, depending on whether auto keyframes
151 // is enabled. Called by PluginClient::send_configure_change
152 KeyFrame* get_keyframe();
153 // Apply new settings from the plugin GUI. Called by PluginClient::send_configure_change
154 // Used in keyframe spanning mode.
155 void apply_keyframe(KeyFrame *src);
157 // Create new theme object. Used by theme plugins.
159 // Get theme being used by Cinelerra currently. Used by all plugins.
161 // Get picon png vframe image
163 VFrame *get_plugin_images();
166 void set_lad_index(int i);
171 PluginClient *new_ffmpeg_plugin();
172 // =============================== for realtime plugins
173 // save configuration of plugin
174 void save_data(KeyFrame *keyframe);
175 // Update EDL and playback engines to reflect changes
176 void sync_parameters();
177 // set for realtime processor usage
178 int set_realtime_sched();
179 int get_gui_status();
182 // cause the plugin to show the GUI
183 // Called by MWindow::show_plugin
186 // Update GUI with keyframe settings
189 void client_side_close();
190 // Set to 1 before every process call if the user supports OpenGL buffers.
191 // Also provides the driver location.
192 void set_use_opengl(int value, VideoDevice *vdevice);
193 // Plugin must call this before performing OpenGL operations.
194 int get_use_opengl();
196 // Called from plugin client
197 // Returns 1 if a GUI is open so OpenGL routines can determine if
200 // Called by plugin client to request synchronous routine.
201 void run_opengl(PluginClient *plugin_client);
203 // set the string that appears on the plugin title
204 int set_string(char *string);
205 // give the buffers and sizes and prepare processing realtime data
206 int init_realtime(int realtime_sched,
207 int total_in_buffers,
209 // process the data in the buffers
210 // input - the current edit's data
211 // output - the previous edit's data and the destination of the transition output
212 // current_position - Position from start of the transition and
213 // relative to the transition.
214 // total_len - total len for transition
215 void process_transition(VFrame *input,
217 int64_t current_position,
219 void process_transition(Samples *input,
221 int64_t current_position,
222 int64_t fragment_size,
225 // Process using pull method.
226 // current_position - start of region if forward, end of region if reverse
227 // relative to requested rate
228 // fragment_size - amount of data to put in buffer relative to requested rate
229 // sample_rate - sample rate of requested output
230 // frame_rate - frame rate of requested output
231 // total_len - length of plugin in track units relative to the EDL rate
232 // Units are kept relative to the EDL rate so plugins don't need to convert rates
233 // to get the keyframes.
234 void process_buffer(VFrame **frame,
235 int64_t current_position,
239 void process_buffer(Samples **buffer,
240 int64_t current_position,
241 int64_t fragment_size,
246 // Called by rendering client to cause the GUI to display something with the data.
247 void send_render_gui(void *data);
248 void send_render_gui(void *data, int size);
249 // Called by MWindow to cause GUI to display
250 void render_gui(void *data);
251 void render_gui(void *data, int size);
253 // Send the boundary autos of the next fragment
254 int set_automation(FloatAutos *autos, FloatAuto **start_auto, FloatAuto **end_auto, int reverse);
258 // set the fragment position of a buffer before rendering
259 int arm_buffer(int buffer_number,
260 int64_t in_fragment_position,
261 int64_t out_fragment_position,
262 int double_buffer_in,
263 int double_buffer_out);
264 // Detach all the shared buffers.
265 int detach_buffers();
267 int send_buffer_info();
270 // ============================ for non realtime plugins
271 // start processing data in plugin
272 int start_loop(int64_t start, int64_t end, int64_t buffer_size, int total_buffers);
273 // Do one iteration of a nonrealtime plugin and return if finished
274 int process_loop(VFrame **buffers, int64_t &write_length);
275 int process_loop(Samples **buffers, int64_t &write_length);
279 // Called by client to read data in non-realtime effect
280 int read_frame(VFrame *buffer,
282 int64_t start_position);
283 int read_samples(Samples *buffer,
285 int64_t start_position,
289 // Called by client to read data in realtime effect.
290 // Returns -1 if error or 0 if success.
291 int read_frame(VFrame *buffer,
293 int64_t start_position,
295 // Set to 1 if the reader can use OpenGL objects.
297 int read_samples(Samples *buffer,
300 int64_t start_position,
303 // For non realtime, prompt user for parameters, waits for plugin to finish and returns a result
304 int get_parameters(int64_t start, int64_t end, int channels);
305 int get_samplerate(); // get samplerate produced by plugin
306 double get_framerate(); // get framerate produced by plugin
307 int get_project_samplerate(); // get samplerate of project data before processing
308 double get_project_framerate(); // get framerate of project data before processing
309 void set_path(const char *path); // required first
312 void get_defaults_path(char *path);
313 void save_defaults();
314 // Used by PluginArray and MenuEffects to get user parameters and progress bar.
315 // Set pointer to mwindow for opening GUI and reconfiguring EDL.
316 void set_mwindow(MWindow *mwindow);
317 // Used in VirtualConsole
318 // Set pointer to AttachmentPoint to render GUI.
319 void set_attachmentpoint(AttachmentPoint *attachmentpoint);
320 // Set pointer to a default keyframe when there is no plugin
321 void set_keyframe(KeyFrame *keyframe);
322 // Set pointer to menueffect window
323 void set_prompt(MenuEffectPrompt *prompt);
324 int set_interactive(); // make this the master plugin for progress bars
325 int set_error(); // flag to send plugin an error on next request
326 MainProgressBar* start_progress(char *string, int64_t length);
328 // add track to the list of affected tracks for a non realtime plugin
329 void append_module(Module *module);
330 // add node for realtime plugin
331 void append_node(VirtualNode *node);
332 // reset node table after virtual console reconfiguration
335 int64_t get_written_samples(); // after samples are written, get the number written
336 int64_t get_written_frames(); // after frames are written, get the number written
342 int64_t out_buffer_size; // size of a send buffer to the plugin
343 int64_t in_buffer_size; // size of a recieve buffer from the plugin
344 int total_in_buffers;
345 int total_out_buffers;
347 // number of double buffers for each channel
348 ArrayList<int> ring_buffers_in;
349 ArrayList<int> ring_buffers_out;
350 // Parameters for automation. Setting autos to 0 disables automation.
351 FloatAuto **start_auto, **end_auto;
355 // size of each buffer
356 ArrayList<int64_t> realtime_in_size;
357 ArrayList<int64_t> realtime_out_size;
359 // When arming buffers need to know the offsets in all the buffers and which
360 // double buffers for each channel before rendering.
361 ArrayList<int64_t> offset_in_render;
362 ArrayList<int64_t> offset_out_render;
363 ArrayList<int64_t> double_buffer_in_render;
364 ArrayList<int64_t> double_buffer_out_render;
366 // don't delete buffers if they belong to a virtual module
368 // Send new buffer information for next render
372 int plugin_open; // Whether or not the plugin is open.
373 // Specifies what type of plugin.
374 int realtime, multichannel, fileio;
375 // Plugin generates media
377 // What data types the plugin can handle. One of these is set.
378 int audio, video, theme;
381 // Plugin is a transition
383 // name of plugin in english.
384 // Compared against the title value in the plugin for resolving symbols.
386 int64_t written_samples, written_frames;
387 char *path; // location of plugin on disk
388 char *data_text; // pointer to the data that was requested by a save_data command
391 int error_flag; // send plugin an error code on next request
392 int dir_idx; // directory id, for icon visibility grouping
393 // Pointers to tracks affected by this plugin during a non realtime operation.
394 // Allows read functions to read data.
395 ArrayList<Module*> *modules;
396 // Used by realtime read functions to get data. Corresponds to the buffer table in the
398 ArrayList<VirtualNode*> *nodes;
399 AttachmentPoint *attachmentpoint;
401 // Pointer to keyframe when plugin is not available
403 AttachmentPoint *attachment;
404 // Storage of keyframes and GUI status
407 // Storage of session parameters
409 Preferences *preferences;
410 MenuEffectPrompt *prompt;
415 // Icon for tracking update