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