3 * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "arraylist.h"
22 #include "batchrender.h"
23 #include "bcsignals.h"
27 #include "filesystem.h"
30 #include "loadfile.inc"
34 #include "mwindowgui.h"
35 #include "pluginserver.h"
36 #include "preferences.h"
37 #include "renderfarmclient.h"
38 #include "versioninfo.h"
45 #define STRC(v) printf("==new %p from %p sz %jd\n", v, __builtin_return_address(0), n)
46 #define STRD(v) printf("==del %p from %p\n", v, __builtin_return_address(0))
47 void *operator new(size_t n) { void *vp = malloc(n); STRC(vp); bzero(vp,n); return vp; }
48 void operator delete(void *t) { STRD(t); free(t); }
49 void operator delete(void *t,size_t n) { STRD(t); free(t); }
50 void *operator new[](size_t n) { void *vp = malloc(n); STRC(vp); bzero(vp,n); return vp; }
51 void operator delete[](void *t) { STRD(t); free(t); }
52 void operator delete[](void *t,size_t n) { STRD(t); free(t); }
68 class CommandLineThread : public Thread
71 CommandLineThread(ArrayList<char*> *filenames,
74 this->filenames = filenames;
75 this->mwindow = mwindow;
86 mwindow->gui->lock_window("main");
88 mwindow->load_filenames(filenames, LOADMODE_REPLACE);
90 if(filenames->size() == 1)
91 mwindow->gui->mainmenu->add_load(filenames->get(0));
93 mwindow->gui->unlock_window();
98 ArrayList<char*> *filenames;
102 int main(int argc, char *argv[])
104 // handle command line arguments first
106 ArrayList<char*> filenames;
110 int operation = DO_GUI;
111 int deamon_port = DEAMON_PORT;
112 char deamon_path[BCTEXTLEN];
113 char config_path[BCTEXTLEN];
114 char batch_path[BCTEXTLEN];
119 EDL::id_lock = new Mutex("EDL::id_lock");
121 File::init_cin_path();
122 const char *locale_path = File::get_locale_path();
123 const char *cin = File::get_cin();
125 bindtextdomain(cin, locale_path);
127 setlocale(LC_MESSAGES, "");
129 #ifdef X_HAVE_UTF8_STRING
130 char *loc = setlocale(LC_CTYPE, "");
132 strcpy(BC_Resources::encoding, nl_langinfo(CODESET));
133 BC_Resources::locale_utf8 = !strcmp(BC_Resources::encoding, "UTF-8");
135 // Extract from locale language & region
138 if((p = strchr(loc, '.')) != 0 && (p - loc) < (int)sizeof(locbuf)-1) {
139 strncpy(locbuf, loc, p - loc);
142 else if(strlen(loc) < sizeof(locbuf)-1)
145 // Locale 'C' does not give useful language info - assume en
146 if(!locbuf[0] || locbuf[0] == 'C')
147 strcpy(locbuf, "en");
149 if((p = strchr(locbuf, '_')) && p - locbuf < LEN_LANG) {
151 strcpy(BC_Resources::language, locbuf);
152 if(strlen(p) < LEN_LANG)
153 strcpy(BC_Resources::region, p);
155 else if(strlen(locbuf) < LEN_LANG)
156 strcpy(BC_Resources::language, locbuf);
159 printf(_(PROGRAM_NAME ": Could not set locale.\n"));
161 setlocale(LC_CTYPE, "");
166 int start_remote_control = 0;
168 for(int i = 1; i < argc; i++)
170 if(!strcmp(argv[i], "-h"))
172 operation = DO_USAGE;
175 if(!strcmp(argv[i], "-z"))
177 start_remote_control = 1;
180 if(!strcmp(argv[i], "-r"))
182 operation = DO_BATCHRENDER;
185 if(argv[i + 1][0] != '-')
187 strcpy(batch_path, argv[i + 1]);
193 if(!strcmp(argv[i], "-c"))
197 strcpy(config_path, argv[i + 1]);
202 fprintf(stderr, _("%s: -c needs a filename.\n"), argv[0]);
206 if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "-f"))
208 if(!strcmp(argv[i], "-d"))
209 operation = DO_DEAMON;
211 operation = DO_DEAMON_FG;
215 if(atol(argv[i + 1]) > 0)
217 deamon_port = atol(argv[i + 1]);
223 if(!strcmp(argv[i], "-b"))
225 operation = DO_BRENDER;
228 fprintf(stderr, _("-b may not be used by the user.\n"));
232 strcpy(deamon_path, argv[i + 1]);
235 if(!strcmp(argv[i], "-n"))
239 nice_value = atol(argv[i + 1]);
244 if(!strcmp(argv[i], "-x"))
251 new_filename = new char[BCTEXTLEN];
252 strcpy(new_filename, argv[i]);
253 fs.complete_path(new_filename);
254 filenames.append(new_filename);
260 if(operation == DO_GUI ||
261 operation == DO_DEAMON ||
262 operation == DO_DEAMON_FG ||
263 operation == DO_USAGE ||
264 operation == DO_BATCHRENDER) {
266 fprintf(stderr, PROGRAM_NAME " " CINELERRA_VERSION);
268 #define REPOMAINTXT ""
270 #ifndef COPYRIGHTTEXT1
271 #define COPYRIGHTTEXT1 ""
273 #ifndef COPYRIGHTTEXT2
274 #define COPYRIGHTTEXT2 ""
277 #define COMPILEDATE ""
279 fprintf(stderr, REPOMAINTXT COPYRIGHTTEXT1 COPYRIGHTTEXT2 COMPILEDATE
280 PROGRAM_NAME " is free software, covered by the GNU General Public License,\n"
281 "and you are welcome to change it and/or distribute copies of it under\n"
282 "certain conditions. There is absolutely no warranty for " PROGRAM_NAME ".\n\n");
288 printf(_("\nUsage:\n"));
289 printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
290 printf(_("-d = Run in the background as renderfarm client. The port (400) is optional.\n"));
291 printf(_("-f = Run in the foreground as renderfarm client. Substitute for -d.\n"));
292 printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
293 printf(_("-c = Configuration file to use instead of %s/%s.\n"),
294 File::get_config_path(), CONFIG_FILE);
295 printf(_("-r = batch render the contents of the batch file (%s/%s) with no GUI. batch file is optional.\n"),
296 File::get_config_path(), BATCH_PATH);
297 printf(_("filenames = files to load\n\n\n"));
304 if(operation == DO_DEAMON)
310 // Redhat 9 requires _exit instead of exit here.
315 RenderFarmClient client(deamon_port,
323 // Same thing without detachment
326 RenderFarmClient client(0,
336 BatchRenderThread *thread = new BatchRenderThread;
337 thread->start_rendering(config_path,
344 int restart = 0, done = 0;
346 BC_WindowBase::get_resources()->vframe_shm = 0;
348 mwindow.create_objects(1, !filenames.total, config_path);
349 CommandLineThread *thread = 0;
351 // load the initial files on seperate tracks
352 // use a new thread so it doesn't block the GUI
353 if( filenames.total ) {
354 thread = new CommandLineThread(&filenames, &mwindow);
360 mwindow.gui->lock_window("main");
361 mwindow.load_backup();
362 mwindow.gui->unlock_window();
364 if( start_remote_control ) {
365 start_remote_control = 0;
366 mwindow.gui->remote_control->activate();
373 restart = mwindow.restart();
375 mwindow.save_backup();
377 start_remote_control =
378 mwindow.gui->remote_control->is_active();
383 mwindow.save_defaults();
385 filenames.remove_all_objects();
390 char exe_path[BCTEXTLEN];
391 int len = readlink("/proc/self/exe", exe_path, sizeof(exe_path)-1);
394 char *av[4] = { 0, }; int ac = 0;
396 if( load_backup ) av[ac++] = (char*) "-x";
397 if( start_remote_control ) av[ac++] = (char*) "-z";
407 filenames.remove_all_objects();
408 delete EDL::id_lock; EDL::id_lock = 0;