00001 #include "arraylist.h"
00002 #include "batchrender.h"
00003 #include "bcsignals.h"
00004 #include "edl.h"
00005 #include "filexml.h"
00006 #include "filesystem.h"
00007 #include "garbage.h"
00008 #include "language.h"
00009 #include "loadfile.inc"
00010 #include "mainmenu.h"
00011 #include "mutex.h"
00012 #include "mwindow.h"
00013 #include "mwindowgui.h"
00014 #include "pluginserver.h"
00015 #include "preferences.h"
00016 #include "renderfarmclient.h"
00017 #include "versioninfo.h"
00018
00019 #include <locale.h>
00020 #include <stdlib.h>
00021 #include <string.h>
00022
00023 #include <locale.h>
00024
00025 #define PACKAGE "cinelerra"
00026 #define LOCALEDIR "/usr/share/locale"
00027
00028
00029 enum
00030 {
00031 DO_GUI,
00032 DO_DEAMON,
00033 DO_DEAMON_FG,
00034 DO_BRENDER,
00035 DO_USAGE,
00036 DO_BATCHRENDER
00037 };
00038
00039 #include "thread.h"
00040
00041 int main(int argc, char *argv[])
00042 {
00043
00044 srand(time(0));
00045 ArrayList<char*> filenames;
00046 FileSystem fs;
00047
00048 int operation = DO_GUI;
00049 int deamon_port = DEAMON_PORT;
00050 char deamon_path[BCTEXTLEN];
00051 char config_path[BCTEXTLEN];
00052 char batch_path[BCTEXTLEN];
00053 int nice_value = 20;
00054 config_path[0] = 0;
00055 batch_path[0] = 0;
00056 deamon_path[0] = 0;
00057 Garbage::garbage = new Garbage;
00058 EDL::id_lock = new Mutex("EDL::id_lock");
00059
00060
00061
00062
00063 char *s, *language;
00064
00065
00066 if ((s = getenv("LC_ALL")) ||
00067 (s = getenv("LC_MESSAGES")) ||
00068 (s = getenv("LC_CTYPE")) ||
00069 (s = getenv ("LANG")))
00070 {
00071
00072 if (strstr(s, ".UTF-8"))
00073 {
00074
00075 language = strtok (s, ".@");
00076
00077 setenv("LANG", language, 1);
00078 }
00079 }
00080
00081
00082
00083
00084
00085 bindtextdomain (PACKAGE, LOCALEDIR);
00086 textdomain (PACKAGE);
00087 setlocale (LC_MESSAGES, "");
00088 setlocale (LC_CTYPE, "");
00089
00090 for(int i = 1; i < argc; i++)
00091 {
00092 if(!strcmp(argv[i], "-h"))
00093 {
00094 operation = DO_USAGE;
00095 }
00096 else
00097 if(!strcmp(argv[i], "-r"))
00098 {
00099 operation = DO_BATCHRENDER;
00100 if(argc > i + 1)
00101 {
00102 if(argv[i + 1][0] != '-')
00103 {
00104 strcpy(batch_path, argv[i + 1]);
00105 i++;
00106 }
00107 }
00108 }
00109 else
00110 if(!strcmp(argv[i], "-c"))
00111 {
00112 if(argc > i + 1)
00113 {
00114 strcpy(config_path, argv[i + 1]);
00115 i++;
00116 }
00117 else
00118 {
00119 fprintf(stderr, "%s: -c needs a filename.\n", argv[0]);
00120 }
00121 }
00122 else
00123 if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "-f"))
00124 {
00125 if(!strcmp(argv[i], "-d"))
00126 operation = DO_DEAMON;
00127 else
00128 operation = DO_DEAMON_FG;
00129
00130 if(argc > i + 1)
00131 {
00132 if(atol(argv[i + 1]) > 0)
00133 {
00134 deamon_port = atol(argv[i + 1]);
00135 i++;
00136 }
00137 }
00138 }
00139 else
00140 if(!strcmp(argv[i], "-b"))
00141 {
00142 operation = DO_BRENDER;
00143 if(i > argc - 2)
00144 {
00145 fprintf(stderr, "-b may not be used by the user.\n");
00146 exit(1);
00147 }
00148 else
00149 strcpy(deamon_path, argv[i + 1]);
00150 }
00151 else
00152 if(!strcmp(argv[i], "-n"))
00153 {
00154 if(argc > i + 1)
00155 {
00156 nice_value = atol(argv[i + 1]);
00157 i++;
00158 }
00159 }
00160 else
00161 {
00162 char *new_filename;
00163 new_filename = new char[1024];
00164 strcpy(new_filename, argv[i]);
00165 fs.complete_path(new_filename);
00166
00167 filenames.append(new_filename);
00168 }
00169 }
00170
00171
00172
00173
00174 if(operation == DO_GUI ||
00175 operation == DO_DEAMON ||
00176 operation == DO_DEAMON_FG ||
00177 operation == DO_USAGE ||
00178 operation == DO_BATCHRENDER)
00179 fprintf(stderr,
00180 PROGRAM_NAME " "
00181 CINELERRA_VERSION " "
00182 REPOMAINTXT
00183 "\n\n"
00184
00185 PROGRAM_NAME " is free software, covered by the GNU General Public License,\n"
00186 "and you are welcome to change it and/or distribute copies of it under\n"
00187 "certain conditions. There is absolutely no warranty for " PROGRAM_NAME ".\n");
00188
00189
00190
00191
00192
00193 switch(operation)
00194 {
00195 case DO_USAGE:
00196 printf(_("\nUsage:\n"));
00197 printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
00198 printf(_("-d = Run in the background as renderfarm client. The port (400) is optional.\n"));
00199 printf(_("-f = Run in the foreground as renderfarm client. Substitute for -d.\n"));
00200 printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
00201 printf(_("-c = Configuration file to use instead of %s%s.\n"),
00202 BCASTDIR,
00203 CONFIG_FILE);
00204 printf(_("-r = batch render the contents of the batch file (%s%s) with no GUI. batch file is optional.\n"),
00205 BCASTDIR,
00206 BATCH_PATH);
00207 printf(_("filenames = files to load\n\n\n"));
00208 exit(0);
00209 break;
00210
00211 case DO_DEAMON:
00212 case DO_DEAMON_FG:
00213 {
00214 if(operation == DO_DEAMON)
00215 {
00216 int pid = fork();
00217
00218 if(pid)
00219 {
00220
00221 _exit(0);
00222 }
00223 }
00224
00225 RenderFarmClient client(deamon_port,
00226 0,
00227 nice_value,
00228 config_path);
00229 client.main_loop();
00230 break;
00231 }
00232
00233
00234 case DO_BRENDER:
00235 {
00236 RenderFarmClient client(0,
00237 deamon_path,
00238 20,
00239 config_path);
00240 client.main_loop();
00241 break;
00242 }
00243
00244 case DO_BATCHRENDER:
00245 {
00246 BatchRenderThread *thread = new BatchRenderThread;
00247 thread->start_rendering(config_path,
00248 batch_path);
00249 break;
00250 }
00251
00252 case DO_GUI:
00253 {
00254 MWindow mwindow;
00255 mwindow.create_objects(1,
00256 !filenames.total,
00257 config_path);
00258
00259
00260 if(filenames.total)
00261 {
00262 mwindow.gui->lock_window("main");
00263 mwindow.load_filenames(&filenames, LOAD_REPLACE);
00264 if(filenames.total == 1)
00265 mwindow.gui->mainmenu->add_load(filenames.values[0]);
00266 mwindow.gui->unlock_window();
00267 }
00268
00269
00270 mwindow.start();
00271 mwindow.save_defaults();
00272 DISABLE_BUFFER
00273 break;
00274 }
00275 }
00276
00277 filenames.remove_all_objects();
00278 return 0;
00279 }
00280