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"
57 class CommandLineThread : public Thread
60 CommandLineThread(ArrayList<char*> *filenames,
63 this->filenames = filenames;
64 this->mwindow = mwindow;
75 mwindow->gui->lock_window("main");
77 mwindow->load_filenames(filenames, LOADMODE_REPLACE);
79 if(filenames->size() == 1)
80 mwindow->gui->mainmenu->add_load(filenames->get(0));
82 mwindow->gui->unlock_window();
87 ArrayList<char*> *filenames;
91 int main(int argc, char *argv[])
93 // handle command line arguments first
95 ArrayList<char*> filenames;
99 int operation = DO_GUI;
100 int deamon_port = DEAMON_PORT;
101 char deamon_path[BCTEXTLEN];
102 char config_path[BCTEXTLEN];
103 char batch_path[BCTEXTLEN];
108 EDL::id_lock = new Mutex("EDL::id_lock");
110 File::init_cin_path();
111 const char *locale_path = File::get_locale_path();
112 const char *cin = File::get_cin();
114 bindtextdomain(cin, locale_path);
116 setlocale(LC_MESSAGES, "");
118 #ifdef X_HAVE_UTF8_STRING
119 char *loc = setlocale(LC_CTYPE, "");
121 strcpy(BC_Resources::encoding, nl_langinfo(CODESET));
122 BC_Resources::locale_utf8 = !strcmp(BC_Resources::encoding, "UTF-8");
124 // Extract from locale language & region
127 if((p = strchr(loc, '.')) != 0 && (p - loc) < (int)sizeof(locbuf)-1) {
128 strncpy(locbuf, loc, p - loc);
131 else if(strlen(loc) < sizeof(locbuf)-1)
134 // Locale 'C' does not give useful language info - assume en
135 if(!locbuf[0] || locbuf[0] == 'C')
136 strcpy(locbuf, "en");
138 if((p = strchr(locbuf, '_')) && p - locbuf < LEN_LANG) {
140 strcpy(BC_Resources::language, locbuf);
141 if(strlen(p) < LEN_LANG)
142 strcpy(BC_Resources::region, p);
144 else if(strlen(locbuf) < LEN_LANG)
145 strcpy(BC_Resources::language, locbuf);
148 printf(_(PROGRAM_NAME ": Could not set locale.\n"));
150 setlocale(LC_CTYPE, "");
155 int start_remote_control = 0;
157 for(int i = 1; i < argc; i++)
159 if(!strcmp(argv[i], "-h"))
161 operation = DO_USAGE;
164 if(!strcmp(argv[i], "-z"))
166 start_remote_control = 1;
169 if(!strcmp(argv[i], "-r"))
171 operation = DO_BATCHRENDER;
174 if(argv[i + 1][0] != '-')
176 strcpy(batch_path, argv[i + 1]);
182 if(!strcmp(argv[i], "-c"))
186 strcpy(config_path, argv[i + 1]);
191 fprintf(stderr, _("%s: -c needs a filename.\n"), argv[0]);
195 if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "-f"))
197 if(!strcmp(argv[i], "-d"))
198 operation = DO_DEAMON;
200 operation = DO_DEAMON_FG;
204 if(atol(argv[i + 1]) > 0)
206 deamon_port = atol(argv[i + 1]);
212 if(!strcmp(argv[i], "-b"))
214 operation = DO_BRENDER;
217 fprintf(stderr, _("-b may not be used by the user.\n"));
221 strcpy(deamon_path, argv[i + 1]);
224 if(!strcmp(argv[i], "-n"))
228 nice_value = atol(argv[i + 1]);
233 if(!strcmp(argv[i], "-x"))
240 new_filename = new char[BCTEXTLEN];
241 strcpy(new_filename, argv[i]);
242 fs.complete_path(new_filename);
243 filenames.append(new_filename);
249 if(operation == DO_GUI ||
250 operation == DO_DEAMON ||
251 operation == DO_DEAMON_FG ||
252 operation == DO_USAGE ||
253 operation == DO_BATCHRENDER) {
255 fprintf(stderr, PROGRAM_NAME " " CINELERRA_VERSION);
257 #define REPOMAINTXT ""
259 #ifndef COPYRIGHTTEXT1
260 #define COPYRIGHTTEXT1 ""
262 #ifndef COPYRIGHTTEXT2
263 #define COPYRIGHTTEXT2 ""
266 #define COMPILEDATE ""
268 fprintf(stderr, REPOMAINTXT COPYRIGHTTEXT1 COPYRIGHTTEXT2 COMPILEDATE
269 PROGRAM_NAME " is free software, covered by the GNU General Public License,\n"
270 "and you are welcome to change it and/or distribute copies of it under\n"
271 "certain conditions. There is absolutely no warranty for " PROGRAM_NAME ".\n\n");
277 printf(_("\nUsage:\n"));
278 printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
279 printf(_("-d = Run in the background as renderfarm client. The port (400) is optional.\n"));
280 printf(_("-f = Run in the foreground as renderfarm client. Substitute for -d.\n"));
281 printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
282 printf(_("-c = Configuration file to use instead of %s/%s.\n"),
283 File::get_config_path(), CONFIG_FILE);
284 printf(_("-r = batch render the contents of the batch file (%s/%s) with no GUI. batch file is optional.\n"),
285 File::get_config_path(), BATCH_PATH);
286 printf(_("filenames = files to load\n\n\n"));
293 if(operation == DO_DEAMON)
299 // Redhat 9 requires _exit instead of exit here.
304 RenderFarmClient client(deamon_port,
312 // Same thing without detachment
315 RenderFarmClient client(0,
325 BatchRenderThread *thread = new BatchRenderThread;
326 thread->start_rendering(config_path,
333 int restart = 0, done = 0;
335 BC_WindowBase::get_resources()->vframe_shm = 0;
337 mwindow.create_objects(1, !filenames.total, config_path);
338 CommandLineThread *thread = 0;
340 // load the initial files on seperate tracks
341 // use a new thread so it doesn't block the GUI
342 if( filenames.total ) {
343 thread = new CommandLineThread(&filenames, &mwindow);
349 mwindow.gui->lock_window("main");
350 mwindow.load_backup();
351 mwindow.gui->unlock_window();
353 if( start_remote_control ) {
354 start_remote_control = 0;
355 mwindow.gui->remote_control->activate();
362 restart = mwindow.restart();
364 mwindow.save_backup();
366 start_remote_control =
367 mwindow.gui->remote_control->is_active();
372 mwindow.save_defaults();
374 filenames.remove_all_objects();
379 char exe_path[BCTEXTLEN];
380 int len = readlink("/proc/self/exe", exe_path, sizeof(exe_path)-1);
383 char *av[4] = { 0, }; int ac = 0;
385 if( load_backup ) av[ac++] = (char*) "-x";
386 if( start_remote_control ) av[ac++] = (char*) "-z";
396 filenames.remove_all_objects();
397 delete EDL::id_lock; EDL::id_lock = 0;