f8968ff43c2793f6b684e1a4ec6ab8b7e3d5026a
[goodguy/history.git] / cinelerra-5.1 / cinelerra / renderengine.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 RENDERENGINE_H
23 #define RENDERENGINE_H
24
25
26 class RenderEngine;
27
28 #include "arender.inc"
29 #include "audiodevice.inc"
30 #include "cache.inc"
31 #include "canvas.inc"
32 #include "channel.inc"
33 #include "channeldb.inc"
34 #include "condition.inc"
35 #include "mutex.inc"
36 #include "mwindow.inc"
37 #include "playbackengine.inc"
38 #include "pluginserver.inc"
39 #include "preferences.inc"
40 #include "thread.h"
41 #include "transportque.inc"
42 #include "videodevice.inc"
43 #include "vrender.inc"
44
45 class RenderEngine : public Thread
46 {
47 public:
48         RenderEngine(PlaybackEngine *playback_engine,
49                 Preferences *preferences,
50                 Canvas *output,
51                 int is_nested);
52         ~RenderEngine();
53
54         void get_duty();
55         void create_render_threads();
56         void arm_render_threads();
57         void start_render_threads();
58         void wait_render_threads();
59         void interrupt_playback();
60         int get_output_w();
61         int get_output_h();
62         int brender_available(int position, int direction);
63         double get_tracking_position();
64         CICache* get_acache();
65         CICache* get_vcache();
66         void set_acache(CICache *cache);
67         void set_vcache(CICache *cache);
68 // Get levels for tracking
69         void get_output_levels(double *levels, int64_t position);
70         void get_module_levels(ArrayList<double> *module_levels, int64_t position);
71         EDL* get_edl();
72
73         void run();
74 // Sends the command sequence, compensating for network latency
75         int arm_command(TransportCommand *command);
76 // Start the command
77         int start_command();
78
79         int open_output();
80         int close_output();
81 // return position to synchronize video against
82         int64_t sync_position();
83 // Called by VRender to reset the timers once the first frame is done.
84         void reset_sync_position();
85 // return samples since start of playback
86         int64_t session_position();
87
88 // Update preferences window
89         void update_framerate(float framerate);
90
91 // Copy of command
92         TransportCommand *command;
93 // Pointer to playback config for one head
94         PlaybackConfig *config;
95 // Defined only for the master render engine
96         PlaybackEngine *playback_engine;
97 // Copy of preferences
98         Preferences *preferences;
99 // Canvas if being used for CWindow
100         Canvas *output;
101
102
103 // Lock out new commands until completion
104         Condition *input_lock;
105 // Lock out interrupts until started
106         Condition *start_lock;
107         Condition *output_lock;
108 // Lock out audio and synchronization timers until first frame is done
109         Condition *first_frame_lock;
110 // Lock out interrupts before and after renderengine is active
111         Mutex *interrupt_lock;
112
113 // Show the timecode on the video
114         int show_tc;
115
116         int done;
117         int is_nested;
118 // If nested, the devices are owned by someone else
119         AudioDevice *audio;
120         VideoDevice *video;
121         ARender *arender;
122         VRender *vrender;
123         int do_audio;
124         int do_video;
125 // Timer for synchronization without audio
126         Timer timer;
127 // If the termination came from interrupt or end of selection
128         int interrupted;
129
130 // Samples in audio buffer to process
131         int64_t fragment_len;
132 // Samples to send to audio device after speed adjustment
133         int64_t adjusted_fragment_len;
134 // CICaches for use if no playbackengine exists
135         CICache *audio_cache, *video_cache;
136
137
138 // constructing with an audio device forces output buffer allocation
139 // constructing without an audio device puts in one buffer at a time mode
140         RenderEngine(MWindow *mwindow,
141                 AudioDevice *audio = 0,
142                 VideoDevice *video = 0,
143                 PlaybackEngine *playbackengine = 0);
144
145         void reset_parameters();
146
147 // buffersize is in samples
148         void arm_playback_audio(int64_t input_length,
149                         int64_t amodule_render_fragment,
150                         int64_t playback_buffer,
151                         int64_t output_length);
152
153         void arm_playback_video(int every_frame,
154                         int64_t read_length,
155                         int64_t output_length,
156                         int track_w,
157                         int track_h,
158                         int output_w,
159                         int output_h);
160
161 // start video since vrender is the master
162         void start_video();
163
164
165 // information for playback
166         int follow_loop;       // loop if mwindow is looped
167         int infinite;          // don't stop rendering at the end of the range or loops
168
169         int64_t start_position;      // lowest numbered sample in playback range
170         int64_t end_position;        // highest numbered sample in playback range
171         int64_t current_sample;
172         int every_frame;
173 // This is created in the first arm_command and not changed until deletion.
174 // The EDL in the command changes & pointers in it should not be referenced.
175         EDL *edl;
176
177         MWindow *mwindow;
178 };
179
180
181
182
183
184
185
186
187 #endif