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"
47 #include "mwindow.inc"
48 #include "packagedispatcher.inc"
49 #include "preferences.inc"
50 #include "renderfarm.inc"
52 #include "bctimer.inc"
60 class BRender
: public Thread
63 BRender(MWindow
*mwindow
);
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
69 void restart(EDL
*edl
);
70 // Stop background rendering for a foreground render. This blocks until
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
);
93 // Simple map of finished chunks
98 // Status of each map entry. This way we get the last contiguous as well as the
99 // ones which are actually rendered.
107 // Invalidate the map until reallocation when a new edit operation is performed.
110 // Constantly recalculate this after every frame instead of searching
113 // Wait until stop commands are finished
114 Condition
*completion_lock
;
115 BRenderThread
*thread
;
116 // PID of master node for killing.
119 char socket_path
[BCTEXTLEN
];
120 // Arguments for execvp
131 // Transfers EDL pointer but doesn't create a new EDL.
132 void copy_from(BRenderCommand
*command
);
134 void copy_edl(EDL
*edl
);
144 // The location of the last change.
146 // The earliest point to include in background rendering would be stored in the
150 class BRenderThread
: public Thread
153 BRenderThread(MWindow
*mwindow
, BRender
*brender
);
156 int is_done(int do_lock
);
157 void send_command(BRenderCommand
*command
);
165 BRenderCommand
*command_queue
;
166 BRenderCommand
*command
;
167 Condition
*input_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.
178 int64_t total_frames
;
179 Mutex
*total_frames_lock
;