remove Features5, rework gradient plugin, fix paste_edl track title bug, gl_probe...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / pluginserver.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifndef PLUGINSERVER_H
23 #define PLUGINSERVER_H
24
25 // inherited by plugins
26
27
28 #include <stdio.h>
29 #include <stdint.h>
30 #include <string.h>
31 #include <unistd.h>
32
33 #include "arraylist.h"
34 #include "attachmentpoint.inc"
35 #include "edl.inc"
36 #include "floatauto.inc"
37 #include "floatautos.inc"
38 #include "garbage.h"
39 #include "keyframe.inc"
40 #include "ladspa.h"
41 #include "mainprogress.inc"
42 #include "maxbuffers.h"
43 #include "menueffects.inc"
44 #include "module.inc"
45 #include "mwindow.inc"
46 #include "plugin.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"
53 #include "theme.inc"
54 #include "thread.h"
55 #include "track.inc"
56 #include "vframe.inc"
57 #include "videodevice.inc"
58 #include "virtualnode.inc"
59
60 #include <dlfcn.h>
61
62 class PluginObj : public Garbage {
63         void *dlobj;
64 public:
65
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; }
72
73         PluginObj() : Garbage("PluginObj:Garbage") { dlobj = 0; }
74         ~PluginObj() { if( dlobj ) unload(dlobj); }
75 };
76
77 class PluginServer
78 {
79         PluginObj *plugin_obj;
80         int load_obj();
81         const char *load_error();
82         void *get_sym(const char *sym);
83
84         int reset_parameters();
85         void init();
86         int cleanup_plugin();
87
88 // Base class created by client
89         PluginClient *client;
90 // If no path, this is going to be set to a function which
91 // instantiates the plugin.
92         PluginClient* (*new_plugin)(PluginServer*);
93
94 // LAD support
95         int lad_index;
96         LADSPA_Descriptor_Function lad_descriptor_function;
97         const LADSPA_Descriptor *lad_descriptor;
98
99         int use_opengl;
100 // FFMPEG support
101         const char *ff_name;
102 // Driver for opengl calls.
103         VideoDevice *vdevice;
104 public:
105         PluginServer();
106         PluginServer(MWindow *mwindow, const char *path, int type);
107         PluginServer(PluginServer &);
108         virtual ~PluginServer();
109
110         friend class PluginAClientLAD;
111         friend class PluginAClientConfig;
112         friend class PluginAClientWindow;
113
114         friend class PluginFClient;
115         friend class PluginFAClient;
116         friend class PluginFVClient;
117         friend class PluginFClientConfig;
118         friend class PluginFClientWindow;
119
120 // open a plugin and wait for commands
121 // Get information for plugindb if master.
122 #define PLUGINSERVER_IS_LAD 2
123 #define PLUGINSERVER_NOT_RECOGNIZED 1
124 #define PLUGINSERVER_OK 0
125         int open_plugin(int master, Preferences *preferences,
126                         EDL *edl, Plugin *plugin);
127 // close the plugin
128         int close_plugin();
129         void get_plugin_png_name(char *png_name);
130         int get_plugin_png_path(char *png_path, const char *plugin_icons);
131         int get_plugin_png_path(char *png_path);
132         void dump(FILE *fp=stdout);
133 // Release any objects which are required after playback stops.
134         void render_stop();
135 // Write entry into plugin table
136         void write_table(FILE *fp, const char *path, int idx, int64_t mtime);
137         static int scan_table(char *text, int &type, char *path, char *title, int64_t &mtime);
138         int read_table(char *text);
139 // queries
140         void set_title(const char *string);
141 // Generate title for display
142         void generate_display_title(char *string);
143 // Get keyframes for configuration.  Position is always relative to EDL rate.
144         KeyFrame* get_prev_keyframe(int64_t position);
145         KeyFrame* get_next_keyframe(int64_t position);
146 // get camera and projector positions
147         void get_camera(float *x, float *y, float *z,
148                         int64_t position, int direction);
149         void get_projector(float *x, float *y, float *z,
150                         int64_t position, int direction);
151 // Get interpolation used by EDL
152         int get_interpolation_type();
153 // plugin position or -1 if no plugin
154         int64_t get_startproject();
155         int64_t get_endproject();
156 // Get or create keyframe for writing, depending on whether auto keyframes
157 // is enabled.  Called by PluginClient::send_configure_change
158         KeyFrame* get_keyframe();
159 // Apply new settings from the plugin GUI.  Called by PluginClient::send_configure_change
160 // Used in keyframe spanning mode.
161         void apply_keyframe(KeyFrame *src);
162
163 // Create new theme object.  Used by theme plugins.
164         Theme* new_theme();
165 // Get theme being used by Cinelerra currently.  Used by all plugins.
166         Theme* get_theme();
167 // Get picon png vframe image
168         VFrame *get_picon();
169         VFrame *get_plugin_images();
170
171         int is_unknown();
172         int is_executable();
173         int is_builtin();
174 // ffmpeg
175         int is_ffmpeg();
176         PluginClient *new_ffmpeg_plugin();
177 // ladspa
178         void set_lad_index(int i);
179         int get_lad_index();
180         int is_ladspa();
181 // lv2
182         int is_lv2();
183         PluginClient *new_lv2_plugin();
184 // =============================== for realtime plugins
185 // save configuration of plugin
186         void save_data(KeyFrame *keyframe);
187 // Update EDL and playback engines to reflect changes
188         void sync_parameters();
189 // set for realtime processor usage
190         int set_realtime_sched();
191         int get_gui_status();
192 // Raise the GUI
193         void raise_window();
194 // cause the plugin to show the GUI
195 // Called by MWindow::show_plugin
196         void show_gui();
197         void hide_gui();
198 // Update GUI with keyframe settings
199         void update_gui();
200         void update_title();
201         void client_side_close();
202 // Set to 1 before every process call if the user supports OpenGL buffers.
203 // Also provides the driver location.
204         void set_use_opengl(int value, VideoDevice *vdevice);
205 // Plugin must call this before performing OpenGL operations.
206         int get_use_opengl();
207
208 // Called from plugin client
209 // Returns 1 if a GUI is open so OpenGL routines can determine if
210 // they can run.
211         int gui_open();
212 // Called by plugin client to request synchronous routine.
213         void run_opengl(PluginClient *plugin_client);
214
215 // set the string that appears on the plugin title
216         int set_string(char *string);
217 // give the buffers and sizes and prepare processing realtime data
218         int init_realtime(int realtime_sched,
219                 int total_in_buffers,
220                 int buffer_size);
221 // process the data in the buffers
222 // input - the current edit's data
223 // output - the previous edit's data and the destination of the transition output
224 // current_position - Position from start of the transition and
225 //     relative to the transition.
226 // total_len - total len for transition
227         void process_transition(VFrame *input,
228                 VFrame *output,
229                 int64_t current_position,
230                 int64_t total_len);
231         void process_transition(Samples *input,
232                 Samples *output,
233                 int64_t current_position,
234                 int64_t fragment_size,
235                 int64_t total_len);
236
237 // Process using pull method.
238 // current_position - start of region if forward, end of region if reverse
239 //     relative to requested rate
240 // fragment_size - amount of data to put in buffer relative to requested rate
241 // sample_rate - sample rate of requested output
242 // frame_rate - frame rate of requested output
243 // total_len - length of plugin in track units relative to the EDL rate
244 // Units are kept relative to the EDL rate so plugins don't need to convert rates
245 // to get the keyframes.
246         void process_buffer(VFrame **frame,
247                 int64_t current_position,
248                 double frame_rate,
249                 int64_t total_len,
250                 int direction);
251         void process_buffer(Samples **buffer,
252                 int64_t current_position,
253                 int64_t fragment_size,
254                 int64_t sample_rate,
255                 int64_t total_len,
256                 int direction);
257
258 // Called by rendering client to cause the GUI to display something with the data.
259         void send_render_gui(void *data);
260         void send_render_gui(void *data, int size);
261 // Called by MWindow to cause GUI to display
262         void render_gui(void *data);
263         void render_gui(void *data, int size);
264
265 // Send the boundary autos of the next fragment
266         int set_automation(FloatAutos *autos, FloatAuto **start_auto, FloatAuto **end_auto, int reverse);
267
268
269
270 // set the fragment position of a buffer before rendering
271         int arm_buffer(int buffer_number,
272                                 int64_t in_fragment_position,
273                                 int64_t out_fragment_position,
274                                 int double_buffer_in,
275                                 int double_buffer_out);
276 // Detach all the shared buffers.
277         int detach_buffers();
278
279         int send_buffer_info();
280
281
282 // ============================ for non realtime plugins
283 // start processing data in plugin
284         int start_loop(int64_t start, int64_t end, int64_t buffer_size, int total_buffers);
285 // Do one iteration of a nonrealtime plugin and return if finished
286         int process_loop(VFrame **buffers, int64_t &write_length);
287         int process_loop(Samples **buffers, int64_t &write_length);
288         int stop_loop();
289
290
291 // Called by client to read data in non-realtime effect
292         int read_frame(VFrame *buffer,
293                 int channel,
294                 int64_t start_position);
295         int read_samples(Samples *buffer,
296                 int channel,
297                 int64_t start_position,
298                 int64_t len);
299
300
301 // Called by client to read data in realtime effect.
302 // Returns -1 if error or 0 if success.
303         int read_frame(VFrame *buffer,
304                 int channel,
305                 int64_t start_position,
306                 double frame_rate,
307 // Set to 1 if the reader can use OpenGL objects.
308                 int use_opengl = 0);
309         int read_samples(Samples *buffer,
310                 int channel,
311                 int64_t sample_rate,
312                 int64_t start_position,
313                 int64_t len);
314
315 // For non realtime, prompt user for parameters, waits for plugin to finish and returns a result
316         int get_parameters(int64_t start, int64_t end, int channels);
317         int get_samplerate();      // get samplerate produced by plugin
318         double get_framerate();     // get framerate produced by plugin
319         int get_project_samplerate();            // get samplerate of project data before processing
320         double get_project_framerate();         // get framerate of project data before processing
321         void set_path(const char *path);        // required first
322         char *get_path();
323         int get_synthesis();
324         void get_defaults_path(char *path);
325         void save_defaults();
326 // Used by PluginArray and MenuEffects to get user parameters and progress bar.
327 // Set pointer to mwindow for opening GUI and reconfiguring EDL.
328         void set_mwindow(MWindow *mwindow);
329 // Used in VirtualConsole
330 // Set pointer to AttachmentPoint to render GUI.
331         void set_attachmentpoint(AttachmentPoint *attachmentpoint);
332 // Set pointer to a default keyframe when there is no plugin
333         void set_keyframe(KeyFrame *keyframe);
334 // Set pointer to menueffect window
335         void set_prompt(MenuEffectPrompt *prompt);
336         int set_interactive();             // make this the master plugin for progress bars
337         int set_error();         // flag to send plugin an error on next request
338         MainProgressBar* start_progress(char *string, int64_t length);
339
340 // add track to the list of affected tracks for a non realtime plugin
341         void append_module(Module *module);
342 // add node for realtime plugin
343         void append_node(VirtualNode *node);
344 // reset node table after virtual console reconfiguration
345         void reset_nodes();
346
347         int64_t get_written_samples();   // after samples are written, get the number written
348         int64_t get_written_frames();   // after frames are written, get the number written
349
350 // client origin
351         int plugin_type;
352
353 // buffers
354         int64_t out_buffer_size;   // size of a send buffer to the plugin
355         int64_t in_buffer_size;    // size of a receive buffer from the plugin
356         int total_in_buffers;
357         int total_out_buffers;
358
359 // number of double buffers for each channel
360         ArrayList<int> ring_buffers_in;
361         ArrayList<int> ring_buffers_out;
362 // Parameters for automation.  Setting autos to 0 disables automation.
363         FloatAuto **start_auto, **end_auto;
364         FloatAutos *autos;
365         int reverse;
366
367 // size of each buffer
368         ArrayList<int64_t> realtime_in_size;
369         ArrayList<int64_t> realtime_out_size;
370
371 // When arming buffers need to know the offsets in all the buffers and which
372 // double buffers for each channel before rendering.
373         ArrayList<int64_t> offset_in_render;
374         ArrayList<int64_t> offset_out_render;
375         ArrayList<int64_t> double_buffer_in_render;
376         ArrayList<int64_t> double_buffer_out_render;
377
378 // don't delete buffers if they belong to a virtual module
379         int shared_buffers;
380 // Send new buffer information for next render
381         int new_buffers;
382
383
384         int plugin_open;                 // Whether or not the plugin is open.
385 // Specifies what type of plugin.
386         int realtime, multichannel, fileio;
387 // Plugin generates media
388         int synthesis;
389 // What data types the plugin can handle.  One of these is set.
390         int audio, video, theme;
391 // Can display a GUI
392         int uses_gui;
393 // Plugin is a transition
394         int transition;
395 // name/tip of plugin
396         char *title, *tip;
397         int64_t written_samples, written_frames;
398         char *path;           // location of plugin on disk
399         char *data_text;      // pointer to the data that was requested by a save_data command
400         char *args[4];
401         int total_args;
402         int error_flag;       // send plugin an error code on next request
403         int dir_idx;          // directory id, for icon visibility grouping
404 // Pointers to tracks affected by this plugin during a non realtime operation.
405 // Allows read functions to read data.
406         ArrayList<Module*> *modules;
407 // Used by realtime read functions to get data.  Corresponds to the buffer table in the
408 // attachment point.
409         ArrayList<VirtualNode*> *nodes;
410         AttachmentPoint *attachmentpoint;
411         MWindow *mwindow;
412 // Pointer to keyframe when plugin is not available
413         KeyFrame *keyframe;
414         AttachmentPoint *attachment;
415 // Storage of keyframes and GUI status
416         Plugin *plugin;
417
418 // Storage of session parameters
419         EDL *edl;
420         Preferences *preferences;
421         MenuEffectPrompt *prompt;
422         int gui_on;
423
424         VFrame *temp_frame;
425
426 // Icon for tracking update
427         VFrame *picon;
428 };
429
430
431 #endif