r999: maintainers added to README_en.
[cinelerra_cv/mob.git] / cinelerra / brender.h
blob61cc703f75ecaa4740b64e41d5942d3f3446ed3b
1 #ifndef BRENDER_H
2 #define BRENDER_H
6 // The master node of the background renderer needs a separate memory space
7 // because few of the codecs are reentrant.
9 // To solve the problem, the master node forks itself and treats the forked
10 // master node as the first node of a renderfarm. There is no real master node
11 // of the renderfarm. The BRender object is a thread in order to
12 // join the forked master node.
14 // If renderfarm is enabled, the extra renderfarm nodes are treated normally.
15 // Unfortunately because of the codec problem, only one copy of Cinelerra
16 // can be running on a single renderfarm. This means either background
17 // rendering or foreground rendering can be happening but not both.
19 // A BRenderThread client runs in the background and a BRender object
20 // interfaces the main window. The BRender client recieves commands to
21 // restart, start, and stop background rendering on its own time to avoid
22 // interrupting the main window.
24 // Whenever a change happens to the timeline, we calculate the last position
25 // which hasn't changed and the end of the contiguous renderfarm output.
26 // Then we restart the background renderfarm at the
27 // lesser of the positions. You can't conditionally restart only
28 // if one of the current jobs was after the position because you need a new EDL.
30 // The two problems to emerge are which job is the last job in the contiguous
31 // set of finished jobs and if position of change is before the last job,
32 // how to truncate and restart the output file.
34 // It's easy to use image sequences as the output file to solve the
35 // file truncation problem.
36 // Figuring out the end of the contiguous output means recording the
37 // state of every output file and constructing a kind of EDL for the
38 // background output as certain output files cluster together.
39 // This is needed anyway for playback.
41 #include "arraylist.h"
42 #include "bcwindowbase.inc"
43 #include "brender.inc"
44 #include "condition.inc"
45 #include "edl.inc"
46 #include "mutex.inc"
47 #include "mwindow.inc"
48 #include "packagedispatcher.inc"
49 #include "preferences.inc"
50 #include "renderfarm.inc"
51 #include "thread.h"
52 #include "bctimer.inc"
60 class BRender : public Thread
62 public:
63 BRender(MWindow *mwindow);
64 ~BRender();
66 // Give the last position of the EDL which hasn't changed.
67 // We copy the EDL and restart rendering at the lesser of position and
68 // our position.
69 void restart(EDL *edl);
70 // Stop background rendering for a foreground render. This blocks until
71 // it really stops.
72 void stop();
75 // Get last contiguous frame from map, with locking.
76 // Only needed by BRenderThread::start but nothing really uses it.
77 int get_last_contiguous(int64_t brender_start);
78 // Allocate map with locking
79 void allocate_map(int64_t brender_start, int64_t start, int64_t end);
80 // Mark a frame as finished
81 int set_video_map(int64_t position, int value);
83 void initialize();
84 void run();
88 MWindow *mwindow;
93 // Simple map of finished chunks
94 unsigned char *map;
95 int64_t map_size;
96 Mutex *map_lock;
98 // Status of each map entry. This way we get the last contiguous as well as the
99 // ones which are actually rendered.
100 enum
102 NOT_SCANNED,
103 SCANNED,
104 RENDERED
107 // Invalidate the map until reallocation when a new edit operation is performed.
108 int map_valid;
110 // Constantly recalculate this after every frame instead of searching
111 int last_contiguous;
113 // Wait until stop commands are finished
114 Condition *completion_lock;
115 BRenderThread *thread;
116 // PID of master node for killing.
117 int master_pid;
118 // Path of socket
119 char socket_path[BCTEXTLEN];
120 // Arguments for execvp
121 char *arguments[4];
122 Timer *timer;
125 class BRenderCommand
127 public:
128 BRenderCommand();
129 ~BRenderCommand();
131 // Transfers EDL pointer but doesn't create a new EDL.
132 void copy_from(BRenderCommand *command);
133 // Make new EDL
134 void copy_edl(EDL *edl);
136 EDL *edl;
137 enum
139 BRENDER_NONE,
140 BRENDER_RESTART,
141 BRENDER_STOP
143 int command;
144 // The location of the last change.
145 double position;
146 // The earliest point to include in background rendering would be stored in the
147 // EDL.
150 class BRenderThread : public Thread
152 public:
153 BRenderThread(MWindow *mwindow, BRender *brender);
154 ~BRenderThread();
156 int is_done(int do_lock);
157 void send_command(BRenderCommand *command);
158 void run();
159 void stop();
160 void start();
161 void initialize();
163 MWindow *mwindow;
164 BRender *brender;
165 BRenderCommand *command_queue;
166 BRenderCommand *command;
167 Condition *input_lock;
168 Mutex *thread_lock;
169 // Render farm server. Deleted when stopped. Created when restarted.
170 RenderFarmServer *farm_server;
171 PackageDispatcher *packages;
172 // Copy of preferences with modified render farm.
173 Preferences *preferences;
174 // Render farm polls these.
175 int farm_result;
176 double fps_result;
177 // Not used
178 int64_t total_frames;
179 Mutex *total_frames_lock;
180 int done;
189 #endif