4 * Copyright (C) 2010-2013 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "bcsignals.h"
27 #include "filesystem.h"
28 #include "formattools.h"
32 #include "maxchannels.h"
34 #include "preferences.h"
36 #include "videodevice.inc"
42 FormatTools::FormatTools(MWindow *mwindow,
43 BC_WindowBase *window,
46 this->mwindow = mwindow;
47 this->window = window;
49 this->plugindb = mwindow->plugindb;
76 prompt_audio_channels = 0;
78 prompt_video_compression = 0;
80 locked_compressor = 0;
84 FormatTools::~FormatTools()
95 if(aparams_button) delete aparams_button;
97 if(vparams_button) delete vparams_button;
99 if(aparams_thread) delete aparams_thread;
101 if(vparams_thread) delete vparams_thread;
103 if(channels_tumbler) delete channels_tumbler;
106 void FormatTools::create_objects(
107 int &init_x, int &init_y,
108 int do_audio, int do_video, // Include support for audio, video
109 int prompt_audio, int prompt_video, // Include checkbox for audio, video
110 int prompt_audio_channels,
111 int prompt_video_compression,
112 const char *locked_compressor,
116 int horizontal_layout)
122 this->locked_compressor = locked_compressor;
123 this->recording = recording;
124 this->use_brender = brender;
125 this->do_audio = do_audio;
126 this->do_video = do_video;
127 this->prompt_audio = prompt_audio;
128 this->prompt_audio_channels = prompt_audio_channels;
129 this->prompt_video = prompt_video;
130 this->prompt_video_compression = prompt_video_compression;
131 this->strategy = strategy;
133 //printf("FormatTools::create_objects 1\n");
135 // Modify strategy depending on render farm
138 if(mwindow->preferences->use_renderfarm)
140 if(*strategy == FILE_PER_LABEL)
141 *strategy = FILE_PER_LABEL_FARM;
143 if(*strategy == SINGLE_PASS)
144 *strategy = SINGLE_PASS_FARM;
148 if(*strategy == FILE_PER_LABEL_FARM)
149 *strategy = FILE_PER_LABEL;
151 if(*strategy == SINGLE_PASS_FARM)
152 *strategy = SINGLE_PASS;
159 window->add_subwindow(path_textbox = new FormatPathText(px, y, this));
160 px += path_textbox->get_w() + 5;
161 path_recent = new BC_RecentList("PATH", mwindow->defaults,
162 path_textbox, 10, px, y, 300, 100);
163 window->add_subwindow(path_recent);
164 path_recent->load_items(File::formattostr(asset->format));
165 px += path_recent->get_w();
166 window->add_subwindow(path_button = new BrowseButton(
167 mwindow->theme, window, path_textbox, px, y, asset->path,
168 _("Output to file"), _("Select a file to write to:"), 0));
172 y += path_textbox->get_h() + 10;
181 window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
183 window->add_subwindow(format_text = new BC_TextBox(x, y, 160, 1,
184 File::formattostr(asset->format)));
185 x += format_text->get_w();
186 //printf("FormatTools::create_objects %d %p\n", __LINE__, window);
187 window->add_subwindow(format_button = new FormatFormat(x, y, this));
188 format_button->create_objects();
189 x += format_button->get_w() + 5;
190 window->add_subwindow(ffmpeg_type = new FFMpegType(x, y, 64, 1, asset->fformat));
191 FFMPEG::set_asset_format(asset, asset->fformat);
192 x += ffmpeg_type->get_w();
193 window->add_subwindow(format_ffmpeg = new FormatFFMPEG(x, y, this));
194 format_ffmpeg->create_objects();
196 y += format_button->get_h() + 10;
199 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT, BC_WindowBase::get_resources()->audiovideo_color));
201 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
202 x += aparams_button->get_w() + 10;
205 window->add_subwindow(audio_switch = new FormatAudio(x, y, this, asset->audio_data));
209 y += aparams_button->get_h() + 10;
211 // Audio channels only used for recording.
212 // if(prompt_audio_channels)
214 // window->add_subwindow(channels_title = new BC_Title(x, y, _("Number of audio channels to record:")));
216 // window->add_subwindow(channels_button = new FormatChannels(x, y, this));
217 // x += channels_button->get_w() + 5;
218 // window->add_subwindow(channels_tumbler = new BC_ITumbler(channels_button, 1, MAXCHANNELS, x, y));
219 // y += channels_button->get_h() + 20;
223 //printf("FormatTools::create_objects 6\n");
224 aparams_thread = new FormatAThread(this);
227 //printf("FormatTools::create_objects 7\n");
230 if(horizontal_layout && do_audio){
235 //printf("FormatTools::create_objects 8\n");
236 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT, BC_WindowBase::get_resources()->audiovideo_color));
238 if(prompt_video_compression)
240 window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
241 x += vparams_button->get_w() + 10;
244 //printf("FormatTools::create_objects 9\n");
247 window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
248 y += video_switch->get_h();
252 y += vparams_button->get_h();
255 //printf("FormatTools::create_objects 10\n");
257 vparams_thread = new FormatVThread(this);
260 //printf("FormatTools::create_objects 11\n");
265 window->add_subwindow(multiple_files = new FormatMultiple(mwindow, x, y, strategy));
266 y += multiple_files->get_h() + 10;
269 //printf("FormatTools::create_objects 12\n");
275 void FormatTools::update_driver(int driver)
277 this->video_driver = driver;
279 locked_compressor = 0;
283 case VIDEO4LINUX2MPEG:
284 // Just give the user information about how the stream is going to be
285 // stored but don't change the asset.
286 // Want to be able to revert to user settings.
287 if(asset->format == FILE_MPEG) break;
288 asset->format = FILE_MPEG;
289 format_text->update(File::formattostr(asset->format));
290 asset->audio_data = 1;
291 asset->video_data = 1;
292 audio_switch->update(1);
293 video_switch->update(1);
296 case CAPTURE_IEC61883:
297 case CAPTURE_FIREWIRE:
298 case VIDEO4LINUX2JPEG:
299 case CAPTURE_JPEG_WEBCAM:
300 asset->format = FILE_FFMPEG;
301 format_text->update(File::formattostr(asset->format));
304 case CAPTURE_IEC61883:
305 case CAPTURE_FIREWIRE:
306 locked_compressor = (char*)CODEC_TAG_DVSD;
309 case VIDEO4LINUX2JPEG:
310 locked_compressor = (char*)CODEC_TAG_MJPEG;
313 case CAPTURE_JPEG_WEBCAM:
314 locked_compressor = (char*)CODEC_TAG_JPEG;
317 if( locked_compressor )
318 strcpy(asset->vcodec, locked_compressor);
320 audio_switch->update(asset->audio_data);
321 video_switch->update(asset->video_data);
325 format_text->update(File::formattostr(asset->format));
326 audio_switch->update(asset->audio_data);
327 video_switch->update(asset->video_data);
330 close_format_windows();
334 void FormatTools::update_format()
336 if( do_audio && prompt_audio && audio_switch ) {
337 audio_switch->update(asset->audio_data);
338 if( File::renders_audio(asset) )
339 audio_switch->enable();
341 audio_switch->disable();
343 if( do_video && prompt_video && video_switch ) {
344 video_switch->update(asset->video_data);
345 if( File::renders_video(asset) )
346 video_switch->enable();
348 video_switch->disable();
350 if( asset->format == FILE_FFMPEG ) {
352 format_ffmpeg->show();
356 format_ffmpeg->hide();
360 int FormatTools::handle_event()
365 Asset* FormatTools::get_asset()
370 void FormatTools::update_extension()
372 const char *extension = File::get_tag(asset->format);
373 // split multiple extensions
374 ArrayList<const char*> extensions;
375 int len = !extension ? -1 : strlen(extension);
376 const char *extension_ptr = extension;
377 for(int i = 0; i <= len; i++)
379 if(extension[i] == '/' || extension[i] == 0)
381 extensions.append(extension_ptr);
382 extension_ptr = extension + i + 1;
386 if(extensions.size())
388 char *ptr = strrchr(asset->path, '.');
391 ptr = asset->path + strlen(asset->path);
396 // test for equivalent extension
397 int need_extension = 1;
398 //int extension_len = 0;
399 for(int i = 0; i < extensions.size() && need_extension; i++)
402 extension_ptr = extensions.get(i);
405 while(*ptr1 != 0 && *extension_ptr != 0 && *extension_ptr != '/')
407 if(tolower(*ptr1) != tolower(*extension_ptr))
417 *extension_ptr != 0 &&
418 *extension_ptr != '/')
422 //printf("FormatTools::update_extension %d %d\n", __LINE__, need_extension);
427 extension_ptr = asset->format != FILE_FFMPEG ?
428 extensions.get(0) : asset->fformat;
429 while(*extension_ptr != 0 && *extension_ptr != '/')
430 *ptr1++ = *extension_ptr++;
434 int character1 = ptr - asset->path;
435 int character2 = strlen(asset->path);
436 // *(asset->path + character2) = 0;
439 path_textbox->update(asset->path);
440 path_textbox->set_selection(character1, character2, character2);
445 void FormatTools::update(Asset *asset, int *strategy)
448 this->strategy = strategy;
451 path_textbox->update(asset->path);
452 format_text->update(File::formattostr(asset->format));
456 multiple_files->update(strategy);
458 close_format_windows();
461 void FormatTools::close_format_windows()
463 // This is done in ~file
464 if( aparams_thread ) {
465 if( aparams_thread->running() )
466 aparams_thread->file->close_window();
467 aparams_thread->join();
469 if( vparams_thread ) {
470 if( vparams_thread->running() )
471 vparams_thread->file->close_window();
472 vparams_thread->join();
476 int FormatTools::get_w()
478 return asset->format != FILE_FFMPEG ? w :
479 format_ffmpeg->get_x() + format_ffmpeg->get_w();
482 void FormatTools::set_w(int w)
487 void FormatTools::reposition_window(int &init_x, int &init_y)
495 path_textbox->reposition_window(px, y);
496 px += path_textbox->get_w() + 5;
497 path_recent->reposition_window(px, y);
498 px += path_recent->get_w() + 8;
499 path_button->reposition_window(px, y);
500 y += path_textbox->get_h() + 10;
503 format_title->reposition_window(x, y);
505 format_text->reposition_window(x, y);
506 x += format_text->get_w();
507 format_button->reposition_window(x, y);
510 y += format_button->get_h() + 10;
514 audio_title->reposition_window(x, y);
516 aparams_button->reposition_window(x, y);
517 x += aparams_button->get_w() + 10;
518 if(prompt_audio) audio_switch->reposition_window(x, y);
521 y += aparams_button->get_h() + 10;
522 if(prompt_audio_channels)
524 channels_title->reposition_window(x, y);
526 channels_button->reposition_window(x, y);
527 x += channels_button->get_w() + 5;
528 channels_tumbler->reposition_window(x, y);
529 y += channels_button->get_h() + 20;
537 video_title->reposition_window(x, y);
539 if(prompt_video_compression)
541 vparams_button->reposition_window(x, y);
542 x += vparams_button->get_w() + 10;
547 video_switch->reposition_window(x, y);
548 y += video_switch->get_h();
552 y += vparams_button->get_h();
561 multiple_files->reposition_window(x, y);
562 y += multiple_files->get_h() + 10;
569 int FormatTools::set_audio_options()
571 // if(video_driver == CAPTURE_DVB)
576 if(!aparams_thread->running())
578 aparams_thread->start();
582 aparams_thread->file->raise_window();
587 int FormatTools::set_video_options()
589 // if(video_driver == CAPTURE_DVB)
594 if(!vparams_thread->running())
596 vparams_thread->start();
600 vparams_thread->file->raise_window();
610 FormatAParams::FormatAParams(MWindow *mwindow, FormatTools *format, int x, int y)
611 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
613 this->format = format;
614 set_tooltip(_("Configure audio compression"));
617 FormatAParams::~FormatAParams()
621 int FormatAParams::handle_event()
623 format->set_audio_options();
631 FormatVParams::FormatVParams(MWindow *mwindow, FormatTools *format, int x, int y)
632 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
634 this->format = format;
635 set_tooltip(_("Configure video compression"));
638 FormatVParams::~FormatVParams()
642 int FormatVParams::handle_event()
644 format->set_video_options();
652 FormatAThread::FormatAThread(FormatTools *format)
655 this->format = format;
660 FormatAThread::~FormatAThread()
662 delete file; file = 0;
666 void FormatAThread::start()
674 void FormatAThread::run()
676 file->get_options(format, 1, 0);
682 FormatVThread::FormatVThread(FormatTools *format)
685 this->format = format;
690 FormatVThread::~FormatVThread()
692 delete file; file = 0;
696 void FormatVThread::start()
703 void FormatVThread::run()
705 file->get_options(format, 0, 1);
712 FormatPathText::FormatPathText(int x, int y, FormatTools *format)
713 : BC_TextBox(x, y, format->w - x -
714 2*format->mwindow->theme->get_image_set("wrench")[0]->get_w() - 20, 1,
717 this->format = format;
720 FormatPathText::~FormatPathText()
723 int FormatPathText::handle_event()
725 calculate_suggestions();
726 strcpy(format->asset->path, get_text());
727 format->handle_event();
734 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
738 (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
740 this->format = format;
743 FormatAudio::~FormatAudio() {}
744 int FormatAudio::handle_event()
746 format->asset->audio_data = get_value();
751 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
755 (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
757 this->format = format;
760 FormatVideo::~FormatVideo() {}
761 int FormatVideo::handle_event()
763 format->asset->video_data = get_value();
770 FormatFormat::FormatFormat(int x, int y, FormatTools *format)
771 : FormatPopup(x, y, format->do_audio, format->do_video, format->use_brender)
773 this->format = format;
776 FormatFormat::~FormatFormat()
780 int FormatFormat::handle_event()
782 BC_ListBoxItem *selection = get_selection(0, 0);
784 int new_format = File::strtoformat(get_selection(0, 0)->get_text());
785 // if(new_format != format->asset->format)
787 Asset *asset = format->asset;
788 asset->format = new_format;
789 asset->audio_data = File::renders_audio(asset);
790 asset->video_data = File::renders_video(asset);
791 asset->ff_audio_options[0] = 0;
792 asset->ff_video_options[0] = 0;
793 format->format_text->update(selection->get_text());
794 if( !format->use_brender )
795 format->update_extension();
796 format->close_format_windows();
797 if (format->path_recent) format->path_recent->
798 load_items(File::formattostr(format->asset->format));
799 format->update_format();
806 FormatFFMPEG::FormatFFMPEG(int x, int y, FormatTools *format)
807 : FFMPEGPopup(format->plugindb, x, y)
809 this->format = format;
812 FormatFFMPEG::~FormatFFMPEG()
816 int FormatFFMPEG::handle_event()
818 BC_ListBoxItem *selection = get_selection(0, 0);
820 char *text = get_selection(0, 0)->get_text();
821 format->ffmpeg_type->update(text);
822 format->asset->ff_audio_options[0] = 0;
823 format->asset->ff_video_options[0] = 0;
824 FFMPEG::set_asset_format(format->asset, text);
825 format->update_extension();
826 format->close_format_windows();
827 format->update_format();
835 FormatChannels::FormatChannels(int x, int y, FormatTools *format)
836 : BC_TextBox(x, y, 100, 1, format->asset->channels)
838 this->format = format;
841 FormatChannels::~FormatChannels()
845 int FormatChannels::handle_event()
847 format->asset->channels = atol(get_text());
852 FormatToTracks::FormatToTracks(int x, int y, int *output)
853 : BC_CheckBox(x, y, *output, _("Overwrite project with output"))
855 this->output = output;
858 FormatToTracks::~FormatToTracks()
862 int FormatToTracks::handle_event()
864 *output = get_value();
869 FormatMultiple::FormatMultiple(MWindow *mwindow, int x, int y, int *output)
872 (*output == FILE_PER_LABEL) || (*output == FILE_PER_LABEL_FARM),
873 _("Create new file at each label"))
875 this->output = output;
876 this->mwindow = mwindow;
879 FormatMultiple::~FormatMultiple()
883 int FormatMultiple::handle_event()
887 if(mwindow->preferences->use_renderfarm)
888 *output = FILE_PER_LABEL_FARM;
890 *output = FILE_PER_LABEL;
894 if(mwindow->preferences->use_renderfarm)
895 *output = SINGLE_PASS_FARM;
897 *output = SINGLE_PASS;
902 void FormatMultiple::update(int *output)
904 this->output = output;
905 if(*output == FILE_PER_LABEL_FARM ||
906 *output ==FILE_PER_LABEL)