Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

renderfarm.h

Go to the documentation of this file.
00001 #ifndef RENDERFARM_H
00002 #define RENDERFARM_H
00003 
00004 
00005 #include "arraylist.h"
00006 #include "asset.inc"
00007 #include "brender.inc"
00008 #include "defaults.inc"
00009 #include "edl.inc"
00010 #include "mutex.inc"
00011 #include "mwindow.inc"
00012 #include "packagedispatcher.inc"
00013 #include "pluginserver.inc"
00014 #include "preferences.inc"
00015 #include "render.inc"
00016 #include "renderfarm.inc"
00017 #include "renderfarmclient.inc"
00018 //#include "renderfarmfsserver.inc"
00019 #include "thread.h"
00020 
00021 #include <stdint.h>
00022 
00023 // Request format
00024 // 1 byte -> request code
00025 // 4 bytes -> size of packet exclusive
00026 // size of packet -> data
00027 
00028 
00029 
00030 // General reply format
00031 // 4 bytes -> size of packet exclusive
00032 // size of packet -> data
00033 
00034 #define STORE_INT32(value) \
00035         datagram[i++] = (((uint32_t)(value)) >> 24) & 0xff; \
00036         datagram[i++] = (((uint32_t)(value)) >> 16) & 0xff; \
00037         datagram[i++] = (((uint32_t)(value)) >> 8) & 0xff; \
00038         datagram[i++] = ((uint32_t)(value)) & 0xff;
00039 
00040 #define STORE_INT64(value) \
00041         datagram[i++] = (((uint64_t)(value)) >> 56) & 0xff; \
00042         datagram[i++] = (((uint64_t)(value)) >> 48) & 0xff; \
00043         datagram[i++] = (((uint64_t)(value)) >> 40) & 0xff; \
00044         datagram[i++] = (((uint64_t)(value)) >> 32) & 0xff; \
00045         datagram[i++] = (((uint64_t)(value)) >> 24) & 0xff; \
00046         datagram[i++] = (((uint64_t)(value)) >> 16) & 0xff; \
00047         datagram[i++] = (((uint64_t)(value)) >> 8) & 0xff; \
00048         datagram[i++] = ((uint64_t)(value)) & 0xff;
00049 
00050 #define READ_INT32(data) \
00051         ((((uint32_t)(data)[0]) << 24) |  \
00052         (((uint32_t)(data)[1]) << 16) |  \
00053         (((uint32_t)(data)[2]) << 8) |  \
00054         ((uint32_t)(data)[3]))
00055 
00056 #define READ_INT64(data) \
00057         ((((uint64_t)(data)[0]) << 56) |  \
00058         (((uint64_t)(data)[1]) << 48) |  \
00059         (((uint64_t)(data)[2]) << 40) |  \
00060         (((uint64_t)(data)[3]) << 32) |  \
00061         (((uint64_t)(data)[4]) << 24) |  \
00062         (((uint64_t)(data)[5]) << 16) |  \
00063         (((uint64_t)(data)[6]) << 8) |  \
00064         ((uint64_t)(data)[7]))
00065 
00066 
00067 // Request codes to be used in both client and server.
00068 enum
00069 {
00070         RENDERFARM_PREFERENCES,  // 0 Get preferences on startup
00071         RENDERFARM_ASSET,        // Get output format on startup
00072         RENDERFARM_EDL,          // Get EDL on startup
00073         RENDERFARM_PACKAGE,      // Get one package after another to render
00074         RENDERFARM_PROGRESS,     // Update completion total
00075         RENDERFARM_SET_RESULT,   // Update error status
00076         RENDERFARM_GET_RESULT,   // Retrieve error status
00077         RENDERFARM_DONE,         // Quit
00078         RENDERFARM_SET_VMAP,     // 8 Update video map in background rendering
00079 
00080 // VFS commands
00081         RENDERFARM_FOPEN,      // 9
00082         RENDERFARM_FCLOSE,
00083         RENDERFARM_REMOVE,
00084         RENDERFARM_RENAME,
00085         RENDERFARM_FGETC,
00086         RENDERFARM_FPUTC,
00087         RENDERFARM_FREAD,      // 15
00088         RENDERFARM_FWRITE,
00089         RENDERFARM_FSEEK,
00090         RENDERFARM_FTELL,
00091         RENDERFARM_STAT,
00092         RENDERFARM_STAT64,     // 20
00093         RENDERFARM_FGETS,      // 21
00094         RENDERFARM_FILENO
00095 };
00096 
00097 
00098 class RenderFarmServer
00099 {
00100 public:
00101 // MWindow is required to get the plugindb to save the EDL.
00102         RenderFarmServer(ArrayList<PluginServer*> *plugindb, 
00103                 PackageDispatcher *packages,
00104                 Preferences *preferences,
00105                 int use_local_rate,
00106                 int *result_return,
00107                 int64_t *total_return,
00108                 Mutex *total_return_lock,
00109                 Asset *default_asset,
00110                 EDL *edl,
00111                 BRender *brender);
00112         virtual ~RenderFarmServer();
00113 
00114 
00115 // Open connections to clients.
00116         int start_clients();
00117 // The render farm must wait for all the clients to finish.
00118         int wait_clients();
00119 
00120 // Likewise the render farm must check the internal render loop before 
00121 // dispatching the next job and whenever a client queries for errors.
00122 
00123 
00124         ArrayList<RenderFarmServerThread*> clients;
00125         ArrayList<PluginServer*> *plugindb;
00126 //      MWindow *mwindow;
00127         PackageDispatcher *packages;
00128         Preferences *preferences;
00129 // Use master node's framerate
00130         int use_local_rate;
00131         int *result_return;
00132         int64_t *total_return;
00133         Mutex *total_return_lock;
00134         Asset *default_asset;
00135         EDL *edl;
00136         Mutex *client_lock;
00137         BRender *brender;
00138 };
00139 
00140 
00141 // Waits for requests from every client.
00142 // Joins when the client is finished.
00143 class RenderFarmServerThread : public Thread
00144 {
00145 public:
00146         RenderFarmServerThread(ArrayList<PluginServer*> *plugindb, 
00147                 RenderFarmServer *server, 
00148                 int number);
00149         ~RenderFarmServerThread();
00150         
00151         static int read_socket(int socket_fd, char *data, int len, int timeout);
00152         static int write_socket(int socket_fd, char *data, int len, int timeout);
00153 // Inserts header and writes string to socket
00154         static int write_string(int socket_fd, char *string);
00155 
00156 
00157 
00158 
00159         int read_socket(char *data, int len, int timeout);
00160         int write_socket(char *data, int len, int timeout);
00161         int start_loop();
00162         void send_preferences();
00163         void send_asset();
00164         void send_edl();
00165         void send_package(unsigned char *buffer);
00166         void set_progress(unsigned char *buffer);
00167         int set_video_map(unsigned char *buffer);
00168         void set_result(unsigned char *buffer);
00169         void get_result();
00170         void reallocate_buffer(int size);
00171 
00172         
00173         void run();
00174         
00175 //      MWindow *mwindow;
00176         ArrayList<PluginServer*> *plugindb;
00177         RenderFarmServer *server;
00178 //      RenderFarmFSServer *fs_server;
00179         int socket_fd;
00180         int number;
00181 // Rate of last job or 0
00182         double frames_per_second;
00183 // Pointer to default asset
00184         Asset *default_asset;
00185         unsigned char *buffer;
00186         int64_t buffer_allocated;
00187 };
00188 
00189 
00190 
00191 
00192 
00193 
00194 #endif

Generated on Sun Jan 8 13:39:00 2006 for Cinelerra-svn by  doxygen 1.4.4