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