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 printf("==new %jd from %p\n", n, __builtin_return_address(0));
46 void *operator new(size_t n) { STRC void *vp = malloc(n); bzero(vp,n); return vp; }
47 void operator delete(void *t) { free(t); }
48 void operator delete(void *t,size_t n) { free(t); }
49 void *operator new[](size_t n) { STRC void *vp = malloc(n); bzero(vp,n); return vp; }
50 void operator delete[](void *t) { free(t); }
51 void operator delete[](void *t,size_t n) { free(t); }
67 class CommandLineThread : public Thread
70 CommandLineThread(ArrayList<char*> *filenames,
73 this->filenames = filenames;
74 this->mwindow = mwindow;
85 mwindow->gui->lock_window("main");
87 mwindow->load_filenames(filenames, LOADMODE_REPLACE);
89 if(filenames->size() == 1)
90 mwindow->gui->mainmenu->add_load(filenames->get(0));
92 mwindow->gui->unlock_window();
97 ArrayList<char*> *filenames;
101 int main(int argc, char *argv[])
103 // handle command line arguments first
105 ArrayList<char*> filenames;
109 int operation = DO_GUI;
110 int deamon_port = DEAMON_PORT;
111 char deamon_path[BCTEXTLEN];
112 char config_path[BCTEXTLEN];
113 char batch_path[BCTEXTLEN];
118 EDL::id_lock = new Mutex("EDL::id_lock");
120 File::init_cin_path();
121 const char *locale_path = File::get_locale_path();
122 const char *cin = File::get_cin();
124 bindtextdomain(cin, locale_path);
126 setlocale(LC_MESSAGES, "");
128 #ifdef X_HAVE_UTF8_STRING
129 char *loc = setlocale(LC_CTYPE, "");
131 strcpy(BC_Resources::encoding, nl_langinfo(CODESET));
132 BC_Resources::locale_utf8 = !strcmp(BC_Resources::encoding, "UTF-8");
134 // Extract from locale language & region
137 if((p = strchr(loc, '.')) != 0 && (p - loc) < (int)sizeof(locbuf)-1) {
138 strncpy(locbuf, loc, p - loc);
141 else if(strlen(loc) < sizeof(locbuf)-1)
144 // Locale 'C' does not give useful language info - assume en
145 if(!locbuf[0] || locbuf[0] == 'C')
146 strcpy(locbuf, "en");
148 if((p = strchr(locbuf, '_')) && p - locbuf < LEN_LANG) {
150 strcpy(BC_Resources::language, locbuf);
151 if(strlen(p) < LEN_LANG)
152 strcpy(BC_Resources::region, p);
154 else if(strlen(locbuf) < LEN_LANG)
155 strcpy(BC_Resources::language, locbuf);
158 printf(_(PROGRAM_NAME ": Could not set locale.\n"));
160 setlocale(LC_CTYPE, "");
165 int start_remote_control = 0;
167 for(int i = 1; i < argc; i++)
169 if(!strcmp(argv[i], "-h"))
171 operation = DO_USAGE;
174 if(!strcmp(argv[i], "-z"))
176 start_remote_control = 1;
179 if(!strcmp(argv[i], "-r"))
181 operation = DO_BATCHRENDER;
184 if(argv[i + 1][0] != '-')
186 strcpy(batch_path, argv[i + 1]);
192 if(!strcmp(argv[i], "-c"))
196 strcpy(config_path, argv[i + 1]);
201 fprintf(stderr, _("%s: -c needs a filename.\n"), argv[0]);
205 if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "-f"))
207 if(!strcmp(argv[i], "-d"))
208 operation = DO_DEAMON;
210 operation = DO_DEAMON_FG;
214 if(atol(argv[i + 1]) > 0)
216 deamon_port = atol(argv[i + 1]);
222 if(!strcmp(argv[i], "-b"))
224 operation = DO_BRENDER;
227 fprintf(stderr, _("-b may not be used by the user.\n"));
231 strcpy(deamon_path, argv[i + 1]);
234 if(!strcmp(argv[i], "-n"))
238 nice_value = atol(argv[i + 1]);
243 if(!strcmp(argv[i], "-x"))
250 new_filename = new char[BCTEXTLEN];
251 strcpy(new_filename, argv[i]);
252 fs.complete_path(new_filename);
253 filenames.append(new_filename);
259 if(operation == DO_GUI ||
260 operation == DO_DEAMON ||
261 operation == DO_DEAMON_FG ||
262 operation == DO_USAGE ||
263 operation == DO_BATCHRENDER) {
265 fprintf(stderr, PROGRAM_NAME " " CINELERRA_VERSION);
267 #define REPOMAINTXT ""
269 #ifndef COPYRIGHTTEXT1
270 #define COPYRIGHTTEXT1 ""
272 #ifndef COPYRIGHTTEXT2
273 #define COPYRIGHTTEXT2 ""
276 #define COMPILEDATE ""
278 fprintf(stderr, REPOMAINTXT COPYRIGHTTEXT1 COPYRIGHTTEXT2 COMPILEDATE
279 PROGRAM_NAME " is free software, covered by the GNU General Public License,\n"
280 "and you are welcome to change it and/or distribute copies of it under\n"
281 "certain conditions. There is absolutely no warranty for " PROGRAM_NAME ".\n\n");
287 printf(_("\nUsage:\n"));
288 printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
289 printf(_("-d = Run in the background as renderfarm client. The port (400) is optional.\n"));
290 printf(_("-f = Run in the foreground as renderfarm client. Substitute for -d.\n"));
291 printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
292 printf(_("-c = Configuration file to use instead of %s/%s.\n"),
293 File::get_config_path(), CONFIG_FILE);
294 printf(_("-r = batch render the contents of the batch file (%s/%s) with no GUI. batch file is optional.\n"),
295 File::get_config_path(), BATCH_PATH);
296 printf(_("filenames = files to load\n\n\n"));
303 if(operation == DO_DEAMON)
309 // Redhat 9 requires _exit instead of exit here.
314 RenderFarmClient client(deamon_port,
322 // Same thing without detachment
325 RenderFarmClient client(0,
335 BatchRenderThread *thread = new BatchRenderThread;
336 thread->start_rendering(config_path,
343 int restart = 0, done = 0;
345 BC_WindowBase::get_resources()->vframe_shm = 0;
347 mwindow.create_objects(1, !filenames.total, config_path);
348 CommandLineThread *thread = 0;
350 // load the initial files on seperate tracks
351 // use a new thread so it doesn't block the GUI
352 if( filenames.total ) {
353 thread = new CommandLineThread(&filenames, &mwindow);
359 mwindow.gui->lock_window("main");
360 mwindow.load_backup();
361 mwindow.gui->unlock_window();
363 if( start_remote_control ) {
364 start_remote_control = 0;
365 mwindow.gui->remote_control->activate();
372 restart = mwindow.restart();
374 mwindow.save_backup();
376 start_remote_control =
377 mwindow.gui->remote_control->is_active();
382 mwindow.save_defaults();
384 filenames.remove_all_objects();
389 char exe_path[BCTEXTLEN];
390 int len = readlink("/proc/self/exe", exe_path, sizeof(exe_path)-1);
393 char *av[4] = { 0, }; int ac = 0;
395 if( load_backup ) av[ac++] = (char*) "-x";
396 if( start_remote_control ) av[ac++] = (char*) "-z";
406 filenames.remove_all_objects();
407 delete EDL::id_lock; EDL::id_lock = 0;