11 #include "mwindow.inc"
12 #include "packagedispatcher.inc"
13 #include "pluginserver.inc"
14 #include "preferences.inc"
16 #include "renderfarm.inc"
17 #include "renderfarmclient.inc"
18 //#include "renderfarmfsserver.inc"
24 // 1 byte -> request code
25 // 4 bytes -> size of packet exclusive
26 // size of packet -> data
30 // General reply format
31 // 4 bytes -> size of packet exclusive
32 // size of packet -> data
34 #define STORE_INT32(value) \
35 datagram[i++] = (((uint32_t)(value)) >> 24) & 0xff; \
36 datagram[i++] = (((uint32_t)(value)) >> 16) & 0xff; \
37 datagram[i++] = (((uint32_t)(value)) >> 8) & 0xff; \
38 datagram[i++] = ((uint32_t)(value)) & 0xff;
40 #define STORE_INT64(value) \
41 datagram[i++] = (((uint64_t)(value)) >> 56) & 0xff; \
42 datagram[i++] = (((uint64_t)(value)) >> 48) & 0xff; \
43 datagram[i++] = (((uint64_t)(value)) >> 40) & 0xff; \
44 datagram[i++] = (((uint64_t)(value)) >> 32) & 0xff; \
45 datagram[i++] = (((uint64_t)(value)) >> 24) & 0xff; \
46 datagram[i++] = (((uint64_t)(value)) >> 16) & 0xff; \
47 datagram[i++] = (((uint64_t)(value)) >> 8) & 0xff; \
48 datagram[i++] = ((uint64_t)(value)) & 0xff;
50 #define READ_INT32(data) \
51 ((((uint32_t)(data)[0]) << 24) | \
52 (((uint32_t)(data)[1]) << 16) | \
53 (((uint32_t)(data)[2]) << 8) | \
54 ((uint32_t)(data)[3]))
56 #define READ_INT64(data) \
57 ((((uint64_t)(data)[0]) << 56) | \
58 (((uint64_t)(data)[1]) << 48) | \
59 (((uint64_t)(data)[2]) << 40) | \
60 (((uint64_t)(data)[3]) << 32) | \
61 (((uint64_t)(data)[4]) << 24) | \
62 (((uint64_t)(data)[5]) << 16) | \
63 (((uint64_t)(data)[6]) << 8) | \
64 ((uint64_t)(data)[7]))
67 // Request codes to be used in both client and server.
70 RENDERFARM_PREFERENCES
, // 0 Get preferences on startup
71 RENDERFARM_ASSET
, // Get output format on startup
72 RENDERFARM_EDL
, // Get EDL on startup
73 RENDERFARM_PACKAGE
, // Get one package after another to render
74 RENDERFARM_PROGRESS
, // Update completion total
75 RENDERFARM_SET_RESULT
, // Update error status
76 RENDERFARM_GET_RESULT
, // Retrieve error status
77 RENDERFARM_DONE
, // Quit
78 RENDERFARM_SET_VMAP
, // 8 Update video map in background rendering
98 class RenderFarmServer
101 // MWindow is required to get the plugindb to save the EDL.
102 RenderFarmServer(ArrayList
<PluginServer
*> *plugindb
,
103 PackageDispatcher
*packages
,
104 Preferences
*preferences
,
107 int64_t *total_return
,
108 Mutex
*total_return_lock
,
109 Asset
*default_asset
,
112 virtual ~RenderFarmServer();
115 // Open connections to clients.
117 // The render farm must wait for all the clients to finish.
120 // Likewise the render farm must check the internal render loop before
121 // dispatching the next job and whenever a client queries for errors.
124 ArrayList
<RenderFarmServerThread
*> clients
;
125 ArrayList
<PluginServer
*> *plugindb
;
127 PackageDispatcher
*packages
;
128 Preferences
*preferences
;
129 // Use master node's framerate
132 int64_t *total_return
;
133 Mutex
*total_return_lock
;
134 Asset
*default_asset
;
141 class RenderFarmServerThread
: public Thread
144 RenderFarmServerThread(ArrayList
<PluginServer
*> *plugindb
,
145 RenderFarmServer
*server
,
147 ~RenderFarmServerThread();
149 static int read_socket(int socket_fd
, char *data
, int len
, int timeout
);
150 static int write_socket(int socket_fd
, char *data
, int len
, int timeout
);
151 // Inserts header and writes string to socket
152 static int write_string(int socket_fd
, char *string
);
153 static int open_client(char *hostname
, int port
);
157 int read_socket(char *data
, int len
, int timeout
);
158 int write_socket(char *data
, int len
, int timeout
);
160 void send_preferences();
163 void send_package(unsigned char *buffer
);
164 void set_progress(unsigned char *buffer
);
165 int set_video_map(unsigned char *buffer
);
166 void set_result(unsigned char *buffer
);
168 void reallocate_buffer(int size
);
174 ArrayList
<PluginServer
*> *plugindb
;
175 RenderFarmServer
*server
;
178 // Rate of last job or 0
179 double frames_per_second
;
180 // Pointer to default asset
181 Asset
*default_asset
;
182 unsigned char *buffer
;
183 int64_t buffer_allocated
;