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