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 "aboutprefs.h"
22 #include "arraylist.h"
23 #include "batchrender.h"
24 #include "bcsignals.h"
28 #include "filesystem.h"
31 #include "loadfile.inc"
35 #include "mwindowgui.h"
36 #include "pluginserver.h"
37 #include "preferences.h"
38 #include "renderfarmclient.h"
40 #include "versioninfo.h"
47 #define STRC(v) printf("==new %p from %p sz %jd\n", v, __builtin_return_address(0), n)
48 #define STRD(v) printf("==del %p from %p\n", v, __builtin_return_address(0))
49 void *operator new(size_t n) { void *vp = malloc(n); STRC(vp); bzero(vp,n); return vp; }
50 void operator delete(void *t) { STRD(t); free(t); }
51 void operator delete(void *t,size_t n) { STRD(t); free(t); }
52 void *operator new[](size_t n) { void *vp = malloc(n); STRC(vp); bzero(vp,n); return vp; }
53 void operator delete[](void *t) { STRD(t); free(t); }
54 void operator delete[](void *t,size_t n) { STRD(t); free(t); }
70 class CommandLineThread : public Thread
73 CommandLineThread(ArrayList<char*> *filenames,
76 this->filenames = filenames;
77 this->mwindow = mwindow;
88 mwindow->gui->lock_window("main");
90 mwindow->load_filenames(filenames, LOADMODE_REPLACE);
92 if(filenames->size() == 1)
93 mwindow->gui->mainmenu->add_load(filenames->get(0));
95 mwindow->gui->unlock_window();
100 ArrayList<char*> *filenames;
104 int main(int argc, char *argv[])
106 // handle command line arguments first
108 ArrayList<char*> filenames;
112 int operation = DO_GUI;
113 int deamon_port = DEAMON_PORT;
114 char deamon_path[BCTEXTLEN];
115 char config_path[BCTEXTLEN];
116 char batch_path[BCTEXTLEN];
121 EDL::id_lock = new Mutex("EDL::id_lock");
124 File::init_cin_path();
125 const char *locale_path = File::get_locale_path();
126 const char *cin = File::get_cin();
128 bindtextdomain(cin, locale_path);
130 setlocale(LC_MESSAGES, "");
132 #ifdef X_HAVE_UTF8_STRING
133 char *loc = setlocale(LC_CTYPE, "");
135 strcpy(BC_Resources::encoding, nl_langinfo(CODESET));
136 BC_Resources::locale_utf8 = !strcmp(BC_Resources::encoding, "UTF-8");
138 // Extract from locale language & region
141 if((p = strchr(loc, '.')) != 0 && (p - loc) < (int)sizeof(locbuf)-1) {
142 strncpy(locbuf, loc, p - loc);
145 else if(strlen(loc) < sizeof(locbuf)-1)
148 // Locale 'C' does not give useful language info - assume en
149 if(!locbuf[0] || locbuf[0] == 'C')
150 strcpy(locbuf, "en");
152 if((p = strchr(locbuf, '_')) && p - locbuf < LEN_LANG) {
154 strcpy(BC_Resources::language, locbuf);
155 if(strlen(p) < LEN_LANG)
156 strcpy(BC_Resources::region, p);
158 else if(strlen(locbuf) < LEN_LANG)
159 strcpy(BC_Resources::language, locbuf);
162 printf(_(PROGRAM_NAME ": Could not set locale.\n"));
164 setlocale(LC_CTYPE, "");
169 int start_remote_control = 0;
171 for(int i = 1; i < argc; i++)
173 if(!strcmp(argv[i], "-h"))
175 operation = DO_USAGE;
178 if(!strcmp(argv[i], "-z"))
180 start_remote_control = 1;
183 if(!strcmp(argv[i], "-r"))
185 operation = DO_BATCHRENDER;
188 if(argv[i + 1][0] != '-')
190 strcpy(batch_path, argv[i + 1]);
196 if(!strcmp(argv[i], "-c"))
200 strcpy(config_path, argv[i + 1]);
205 fprintf(stderr, _("%s: -c needs a filename.\n"), argv[0]);
209 if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "-f"))
211 if(!strcmp(argv[i], "-d"))
212 operation = DO_DEAMON;
214 operation = DO_DEAMON_FG;
218 if(atol(argv[i + 1]) > 0)
220 deamon_port = atol(argv[i + 1]);
226 if(!strcmp(argv[i], "-b"))
228 operation = DO_BRENDER;
231 fprintf(stderr, _("-b may not be used by the user.\n"));
235 strcpy(deamon_path, argv[i + 1]);
238 if(!strcmp(argv[i], "-n"))
242 nice_value = atol(argv[i + 1]);
247 if(!strcmp(argv[i], "-x"))
254 new_filename = new char[BCTEXTLEN];
255 strcpy(new_filename, argv[i]);
256 fs.complete_path(new_filename);
257 filenames.append(new_filename);
263 if(operation == DO_GUI ||
264 operation == DO_DEAMON ||
265 operation == DO_DEAMON_FG ||
266 operation == DO_USAGE ||
267 operation == DO_BATCHRENDER) {
270 #define REPOMAINTXT ""
272 #ifndef COPYRIGHTTEXT1
273 #define COPYRIGHTTEXT1 ""
275 #ifndef COPYRIGHTTEXT2
276 #define COPYRIGHTTEXT2 ""
278 fprintf(stderr, "%s %s - %s\n%s",
279 PROGRAM_NAME,CINELERRA_VERSION, AboutPrefs::build_timestamp,
280 REPOMAINTXT COPYRIGHTTEXT1 COPYRIGHTTEXT2);
281 fprintf(stderr, "%s is free software, covered by the GNU General Public License,\n"
282 "and you are welcome to change it and/or distribute copies of it under\n"
283 "certain conditions. There is absolutely no warranty for %s.\n\n",
284 PROGRAM_NAME, PROGRAM_NAME);
290 printf(_("\nUsage:\n"));
291 printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
292 printf(_("-d = Run in the background as renderfarm client. The port (400) is optional.\n"));
293 printf(_("-f = Run in the foreground as renderfarm client. Substitute for -d.\n"));
294 printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
295 printf(_("-c = Configuration file to use instead of %s/%s.\n"),
296 File::get_config_path(), CONFIG_FILE);
297 printf(_("-r = batch render the contents of the batch file (%s/%s) with no GUI. batch file is optional.\n"),
298 File::get_config_path(), BATCH_PATH);
299 printf(_("filenames = files to load\n\n\n"));
306 if(operation == DO_DEAMON)
312 // Redhat 9 requires _exit instead of exit here.
317 RenderFarmClient client(deamon_port,
325 // Same thing without detachment
328 RenderFarmClient client(0,
338 BatchRenderThread *thread = new BatchRenderThread;
339 thread->start_rendering(config_path,
346 int restart = 0, done = 0;
348 BC_WindowBase::get_resources()->vframe_shm = 0;
350 mwindow.create_objects(1, !filenames.total, config_path);
351 CommandLineThread *thread = 0;
353 // load the initial files on seperate tracks
354 // use a new thread so it doesn't block the GUI
355 if( filenames.total ) {
356 thread = new CommandLineThread(&filenames, &mwindow);
362 mwindow.gui->lock_window("main");
363 mwindow.load_backup();
364 mwindow.gui->unlock_window();
366 if( start_remote_control ) {
367 start_remote_control = 0;
368 mwindow.gui->remote_control->activate();
375 restart = mwindow.restart();
377 mwindow.save_backup();
379 start_remote_control =
380 mwindow.gui->remote_control->is_active();
385 mwindow.save_defaults();
387 filenames.remove_all_objects();
392 char exe_path[BCTEXTLEN];
393 int len = readlink("/proc/self/exe", exe_path, sizeof(exe_path)-1);
396 char *av[4] = { 0, }; int ac = 0;
398 if( load_backup ) av[ac++] = (char*) "-x";
399 if( start_remote_control ) av[ac++] = (char*) "-z";
409 filenames.remove_all_objects();
410 delete EDL::id_lock; EDL::id_lock = 0;