8 #include "defaults.inc"
11 #include "mwindow.inc"
12 #include "packagedispatcher.inc"
13 #include "preferences.inc"
15 #include "renderfarm.inc"
16 #include "renderfarmclient.inc"
17 #include "renderfarmfsserver.inc"
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.
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
80 RENDERFARM_FOPEN
, // 9
86 RENDERFARM_FREAD
, // 15
91 RENDERFARM_STAT64
, // 20
92 RENDERFARM_FGETS
// 21
96 class RenderFarmServer
99 // MWindow is required to get the plugindb to save the EDL.
100 RenderFarmServer(MWindow
*mwindow
,
101 PackageDispatcher
*packages
,
102 Preferences
*preferences
,
105 int64_t *total_return
,
106 Mutex
*total_return_lock
,
107 Asset
*default_asset
,
110 virtual ~RenderFarmServer();
113 // Open connections to clients.
115 // The render farm must wait for all the clients to finish.
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
;
124 PackageDispatcher
*packages
;
125 Preferences
*preferences
;
126 // Use master node's framerate
129 int64_t *total_return
;
130 Mutex
*total_return_lock
;
131 Asset
*default_asset
;
138 // Waits for requests from every client.
139 // Joins when the client is finished.
140 class RenderFarmServerThread
: public Thread
143 RenderFarmServerThread(MWindow
*mwindow
,
144 RenderFarmServer
*server
,
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
);
159 void send_preferences();
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
);
167 void reallocate_buffer(int size
);
173 RenderFarmServer
*server
;
174 RenderFarmFSServer
*fs_server
;
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
;