r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / renderfarm.h
blob6f0a59a268b2accc8f71c463a759f50dc585f0d1
1 #ifndef RENDERFARM_H
2 #define RENDERFARM_H
5 #include "arraylist.h"
6 #include "assets.inc"
7 #include "brender.inc"
8 #include "defaults.inc"
9 #include "edl.inc"
10 #include "mutex.inc"
11 #include "mwindow.inc"
12 #include "packagedispatcher.inc"
13 #include "preferences.inc"
14 #include "render.inc"
15 #include "renderfarm.inc"
16 #include "renderfarmclient.inc"
17 #include "renderfarmfsserver.inc"
18 #include "thread.h"
20 #include <stdint.h>
22 // Request format
23 // 1 byte -> request code
24 // 4 bytes -> size of packet exclusive
25 // size of packet -> data
29 // General reply format
30 // 4 bytes -> size of packet exclusive
31 // size of packet -> data
33 #define STORE_INT32(value) \
34 datagram[i++] = (((uint32_t)(value)) >> 24) & 0xff; \
35 datagram[i++] = (((uint32_t)(value)) >> 16) & 0xff; \
36 datagram[i++] = (((uint32_t)(value)) >> 8) & 0xff; \
37 datagram[i++] = ((uint32_t)(value)) & 0xff;
39 #define STORE_INT64(value) \
40 datagram[i++] = (((uint64_t)(value)) >> 56) & 0xff; \
41 datagram[i++] = (((uint64_t)(value)) >> 48) & 0xff; \
42 datagram[i++] = (((uint64_t)(value)) >> 40) & 0xff; \
43 datagram[i++] = (((uint64_t)(value)) >> 32) & 0xff; \
44 datagram[i++] = (((uint64_t)(value)) >> 24) & 0xff; \
45 datagram[i++] = (((uint64_t)(value)) >> 16) & 0xff; \
46 datagram[i++] = (((uint64_t)(value)) >> 8) & 0xff; \
47 datagram[i++] = ((uint64_t)(value)) & 0xff;
49 #define READ_INT32(data) \
50 ((((uint32_t)(data)[0]) << 24) | \
51 (((uint32_t)(data)[1]) << 16) | \
52 (((uint32_t)(data)[2]) << 8) | \
53 ((uint32_t)(data)[3]))
55 #define READ_INT64(data) \
56 ((((uint64_t)(data)[0]) << 56) | \
57 (((uint64_t)(data)[1]) << 48) | \
58 (((uint64_t)(data)[2]) << 40) | \
59 (((uint64_t)(data)[3]) << 32) | \
60 (((uint64_t)(data)[4]) << 24) | \
61 (((uint64_t)(data)[5]) << 16) | \
62 (((uint64_t)(data)[6]) << 8) | \
63 ((uint64_t)(data)[7]))
66 // Request codes to be used in both client and server.
67 enum
69 RENDERFARM_PREFERENCES, // 0 Get preferences on startup
70 RENDERFARM_ASSET, // Get output format on startup
71 RENDERFARM_EDL, // Get EDL on startup
72 RENDERFARM_PACKAGE, // Get one package after another to render
73 RENDERFARM_PROGRESS, // Update completion total
74 RENDERFARM_SET_RESULT, // Update error status
75 RENDERFARM_GET_RESULT, // Retrieve error status
76 RENDERFARM_DONE, // Quit
77 RENDERFARM_SET_VMAP, // 8 Update video map in background rendering
79 // VFS commands
80 RENDERFARM_FOPEN, // 9
81 RENDERFARM_FCLOSE,
82 RENDERFARM_REMOVE,
83 RENDERFARM_RENAME,
84 RENDERFARM_FGETC,
85 RENDERFARM_FPUTC,
86 RENDERFARM_FREAD, // 15
87 RENDERFARM_FWRITE,
88 RENDERFARM_FSEEK,
89 RENDERFARM_FTELL,
90 RENDERFARM_STAT,
91 RENDERFARM_STAT64, // 20
92 RENDERFARM_FGETS // 21
96 class RenderFarmServer
98 public:
99 // MWindow is required to get the plugindb to save the EDL.
100 RenderFarmServer(MWindow *mwindow,
101 PackageDispatcher *packages,
102 Preferences *preferences,
103 int use_local_rate,
104 int *result_return,
105 int64_t *total_return,
106 Mutex *total_return_lock,
107 Asset *default_asset,
108 EDL *edl,
109 BRender *brender);
110 virtual ~RenderFarmServer();
113 // Open connections to clients.
114 int start_clients();
115 // The render farm must wait for all the clients to finish.
116 int wait_clients();
118 // Likewise the render farm must check the internal render loop before
119 // dispatching the next job and whenever a client queries for errors.
122 ArrayList<RenderFarmServerThread*> clients;
123 MWindow *mwindow;
124 PackageDispatcher *packages;
125 Preferences *preferences;
126 // Use master node's framerate
127 int use_local_rate;
128 int *result_return;
129 int64_t *total_return;
130 Mutex *total_return_lock;
131 Asset *default_asset;
132 EDL *edl;
133 Mutex *client_lock;
134 BRender *brender;
138 // Waits for requests from every client.
139 // Joins when the client is finished.
140 class RenderFarmServerThread : public Thread
142 public:
143 RenderFarmServerThread(MWindow *mwindow,
144 RenderFarmServer *server,
145 int number);
146 ~RenderFarmServerThread();
148 static int read_socket(int socket_fd, char *data, int len, int timeout);
149 static int write_socket(int socket_fd, char *data, int len, int timeout);
150 // Inserts header and writes string to socket
151 static int write_string(int socket_fd, char *string);
156 int read_socket(char *data, int len, int timeout);
157 int write_socket(char *data, int len, int timeout);
158 int start_loop();
159 void send_preferences();
160 void send_asset();
161 void send_edl();
162 void send_package(unsigned char *buffer);
163 void set_progress(unsigned char *buffer);
164 void set_video_map(unsigned char *buffer);
165 void set_result(unsigned char *buffer);
166 void get_result();
167 void reallocate_buffer(int size);
170 void run();
172 MWindow *mwindow;
173 RenderFarmServer *server;
174 RenderFarmFSServer *fs_server;
175 int socket_fd;
176 int number;
177 // Rate of last job or 0
178 double frames_per_second;
179 // Pointer to default asset
180 Asset *default_asset;
181 unsigned char *buffer;
182 int64_t buffer_allocated;
190 #endif