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"
46 #include "mwindow.inc"
47 #include "packagedispatcher.inc"
48 #include "preferences.inc"
49 #include "renderfarm.inc"
59 class BRender
: public Thread
62 BRender(MWindow
*mwindow
);
65 // Give the last position of the EDL which hasn't changed.
66 // We copy the EDL and restart rendering at the lesser of position and
68 void restart(EDL
*edl
);
69 // Stop background rendering for a foreground render. This blocks until
74 // Get last contiguous frame from map, with locking.
75 // Only needed by BRenderThread::start but nothing really uses it.
76 int get_last_contiguous(int64_t brender_start
);
77 // Allocate map with locking
78 void allocate_map(int64_t brender_start
, int64_t start
, int64_t end
);
79 // Mark a frame as finished
80 void set_video_map(int64_t position
, int value
);
92 // Simple map of finished chunks
97 // Status of each map entry. This way we get the last contiguous as well as the
98 // ones which are actually rendered.
106 // Invalidate the map until reallocation when a new edit operation is performed.
109 // Constantly recalculate this after every frame instead of searching
112 // Wait until stop commands are finished
113 Mutex
*completion_lock
;
114 BRenderThread
*thread
;
115 // PID of master node for killing.
118 char socket_path
[BCTEXTLEN
];
119 // Arguments for execvp
130 // Transfers EDL pointer but doesn't create a new EDL.
131 void copy_from(BRenderCommand
*command
);
133 void copy_edl(EDL
*edl
);
143 // The location of the last change.
145 // The earliest point to include in background rendering would be stored in the
149 class BRenderThread
: public Thread
152 BRenderThread(MWindow
*mwindow
, BRender
*brender
);
155 int is_done(int do_lock
);
156 void send_command(BRenderCommand
*command
);
164 BRenderCommand
*command_queue
;
165 BRenderCommand
*command
;
168 // Render farm server. Deleted when stopped. Created when restarted.
169 RenderFarmServer
*farm_server
;
170 PackageDispatcher
*packages
;
171 // Copy of preferences with modified render farm.
172 Preferences
*preferences
;
173 // Render farm polls these.
177 int64_t total_frames
;
178 Mutex
*total_frames_lock
;