r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / brender.h
blobfdc1bc4bcf9dc0df432c7ec656a0a04091374824
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 "edl.inc"
45 #include "mutex.inc"
46 #include "mwindow.inc"
47 #include "packagedispatcher.inc"
48 #include "preferences.inc"
49 #include "renderfarm.inc"
50 #include "thread.h"
51 #include "timer.inc"
59 class BRender : public Thread
61 public:
62 BRender(MWindow *mwindow);
63 ~BRender();
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
67 // our position.
68 void restart(EDL *edl);
69 // Stop background rendering for a foreground render. This blocks until
70 // it really stops.
71 void stop();
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);
82 void initialize();
83 void run();
87 MWindow *mwindow;
92 // Simple map of finished chunks
93 unsigned char *map;
94 int64_t map_size;
95 Mutex *map_lock;
97 // Status of each map entry. This way we get the last contiguous as well as the
98 // ones which are actually rendered.
99 enum
101 NOT_SCANNED,
102 SCANNED,
103 RENDERED
106 // Invalidate the map until reallocation when a new edit operation is performed.
107 int map_valid;
109 // Constantly recalculate this after every frame instead of searching
110 int last_contiguous;
112 // Wait until stop commands are finished
113 Mutex *completion_lock;
114 BRenderThread *thread;
115 // PID of master node for killing.
116 int master_pid;
117 // Path of socket
118 char socket_path[BCTEXTLEN];
119 // Arguments for execvp
120 char *arguments[4];
121 Timer *timer;
124 class BRenderCommand
126 public:
127 BRenderCommand();
128 ~BRenderCommand();
130 // Transfers EDL pointer but doesn't create a new EDL.
131 void copy_from(BRenderCommand *command);
132 // Make new EDL
133 void copy_edl(EDL *edl);
135 EDL *edl;
136 enum
138 BRENDER_NONE,
139 BRENDER_RESTART,
140 BRENDER_STOP
142 int command;
143 // The location of the last change.
144 double position;
145 // The earliest point to include in background rendering would be stored in the
146 // EDL.
149 class BRenderThread : public Thread
151 public:
152 BRenderThread(MWindow *mwindow, BRender *brender);
153 ~BRenderThread();
155 int is_done(int do_lock);
156 void send_command(BRenderCommand *command);
157 void run();
158 void stop();
159 void start();
160 void initialize();
162 MWindow *mwindow;
163 BRender *brender;
164 BRenderCommand *command_queue;
165 BRenderCommand *command;
166 Mutex *input_lock;
167 Mutex *thread_lock;
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.
174 int farm_result;
175 double fps_result;
176 // Not used
177 int64_t total_frames;
178 Mutex *total_frames_lock;
179 int done;
188 #endif