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(int &init_x,
108 int do_audio, // Include support for audio
109 int do_video, // Include support for video
110 int prompt_audio, // Include checkbox for audio
112 int prompt_audio_channels,
113 int prompt_video_compression,
114 const char *locked_compressor,
118 int horizontal_layout)
124 this->locked_compressor = locked_compressor;
125 this->recording = recording;
126 this->use_brender = brender;
127 this->do_audio = do_audio;
128 this->do_video = do_video;
129 this->prompt_audio = prompt_audio;
130 this->prompt_audio_channels = prompt_audio_channels;
131 this->prompt_video = prompt_video;
132 this->prompt_video_compression = prompt_video_compression;
133 this->strategy = strategy;
135 //printf("FormatTools::create_objects 1\n");
137 // Modify strategy depending on render farm
140 if(mwindow->preferences->use_renderfarm)
142 if(*strategy == FILE_PER_LABEL)
143 *strategy = FILE_PER_LABEL_FARM;
145 if(*strategy == SINGLE_PASS)
146 *strategy = SINGLE_PASS_FARM;
150 if(*strategy == FILE_PER_LABEL_FARM)
151 *strategy = FILE_PER_LABEL;
153 if(*strategy == SINGLE_PASS_FARM)
154 *strategy = SINGLE_PASS;
161 window->add_subwindow(path_textbox = new FormatPathText(px, y, this));
162 px += path_textbox->get_w() + 5;
163 path_recent = new BC_RecentList("PATH", mwindow->defaults,
164 path_textbox, 10, px, y, 300, 100);
165 window->add_subwindow(path_recent);
166 path_recent->load_items(File::formattostr(asset->format));
167 px += path_recent->get_w();
168 window->add_subwindow(path_button = new BrowseButton(
169 mwindow->theme, window, path_textbox, px, y, asset->path,
170 _("Output to file"), _("Select a file to write to:"), 0));
174 y += path_textbox->get_h() + 10;
183 window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
185 window->add_subwindow(format_text = new BC_TextBox(x, y, 160, 1,
186 File::formattostr(asset->format)));
187 x += format_text->get_w();
188 //printf("FormatTools::create_objects %d %p\n", __LINE__, window);
189 window->add_subwindow(format_button = new FormatFormat(x, y, this));
190 format_button->create_objects();
191 x += format_button->get_w() + 5;
192 window->add_subwindow(ffmpeg_type = new FFMpegType(x, y, 64, 1, asset->fformat));
193 FFMPEG::set_asset_format(asset, asset->fformat);
194 x += ffmpeg_type->get_w();
195 window->add_subwindow(format_ffmpeg = new FormatFFMPEG(x, y, this));
196 format_ffmpeg->create_objects();
198 y += format_button->get_h() + 10;
201 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT, BC_WindowBase::get_resources()->audiovideo_color));
203 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
204 x += aparams_button->get_w() + 10;
207 window->add_subwindow(audio_switch = new FormatAudio(x, y, this, asset->audio_data));
211 y += aparams_button->get_h() + 10;
213 // Audio channels only used for recording.
214 // if(prompt_audio_channels)
216 // window->add_subwindow(channels_title = new BC_Title(x, y, _("Number of audio channels to record:")));
218 // window->add_subwindow(channels_button = new FormatChannels(x, y, this));
219 // x += channels_button->get_w() + 5;
220 // window->add_subwindow(channels_tumbler = new BC_ITumbler(channels_button, 1, MAXCHANNELS, x, y));
221 // y += channels_button->get_h() + 20;
225 //printf("FormatTools::create_objects 6\n");
226 aparams_thread = new FormatAThread(this);
229 //printf("FormatTools::create_objects 7\n");
232 if(horizontal_layout && do_audio){
237 //printf("FormatTools::create_objects 8\n");
238 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT, BC_WindowBase::get_resources()->audiovideo_color));
240 if(prompt_video_compression)
242 window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
243 x += vparams_button->get_w() + 10;
246 //printf("FormatTools::create_objects 9\n");
249 window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
250 y += video_switch->get_h();
254 y += vparams_button->get_h();
257 //printf("FormatTools::create_objects 10\n");
259 vparams_thread = new FormatVThread(this);
262 //printf("FormatTools::create_objects 11\n");
267 window->add_subwindow(multiple_files = new FormatMultiple(mwindow, x, y, strategy));
268 y += multiple_files->get_h() + 10;
271 //printf("FormatTools::create_objects 12\n");
277 void FormatTools::update_driver(int driver)
279 this->video_driver = driver;
281 locked_compressor = 0;
285 case VIDEO4LINUX2MPEG:
286 // Just give the user information about how the stream is going to be
287 // stored but don't change the asset.
288 // Want to be able to revert to user settings.
289 if(asset->format == FILE_MPEG) break;
290 asset->format = FILE_MPEG;
291 format_text->update(File::formattostr(asset->format));
292 asset->audio_data = 1;
293 asset->video_data = 1;
294 audio_switch->update(1);
295 video_switch->update(1);
298 case CAPTURE_IEC61883:
299 case CAPTURE_FIREWIRE:
300 case VIDEO4LINUX2JPEG:
301 case CAPTURE_JPEG_WEBCAM:
302 asset->format = FILE_FFMPEG;
303 format_text->update(File::formattostr(asset->format));
306 case CAPTURE_IEC61883:
307 case CAPTURE_FIREWIRE:
308 locked_compressor = (char*)CODEC_TAG_DVSD;
311 case VIDEO4LINUX2JPEG:
312 locked_compressor = (char*)CODEC_TAG_MJPEG;
315 case CAPTURE_JPEG_WEBCAM:
316 locked_compressor = (char*)CODEC_TAG_JPEG;
319 if( locked_compressor )
320 strcpy(asset->vcodec, locked_compressor);
322 audio_switch->update(asset->audio_data);
323 video_switch->update(asset->video_data);
327 format_text->update(File::formattostr(asset->format));
328 audio_switch->update(asset->audio_data);
329 video_switch->update(asset->video_data);
332 close_format_windows();
336 void FormatTools::update_format()
338 if( do_audio && prompt_audio && audio_switch ) {
339 audio_switch->update(asset->audio_data);
340 if( File::renders_audio(asset) )
341 audio_switch->enable();
343 audio_switch->disable();
345 if( do_video && prompt_video && video_switch ) {
346 video_switch->update(asset->video_data);
347 if( File::renders_video(asset) )
348 video_switch->enable();
350 video_switch->disable();
352 if( asset->format == FILE_FFMPEG ) {
354 format_ffmpeg->show();
358 format_ffmpeg->hide();
362 int FormatTools::handle_event()
367 Asset* FormatTools::get_asset()
372 void FormatTools::update_extension()
374 const char *extension = File::get_tag(asset->format);
375 // split multiple extensions
376 ArrayList<const char*> extensions;
377 int len = !extension ? -1 : strlen(extension);
378 const char *extension_ptr = extension;
379 for(int i = 0; i <= len; i++)
381 if(extension[i] == '/' || extension[i] == 0)
383 extensions.append(extension_ptr);
384 extension_ptr = extension + i + 1;
388 if(extensions.size())
390 char *ptr = strrchr(asset->path, '.');
393 ptr = asset->path + strlen(asset->path);
398 // test for equivalent extension
399 int need_extension = 1;
400 //int extension_len = 0;
401 for(int i = 0; i < extensions.size() && need_extension; i++)
404 extension_ptr = extensions.get(i);
407 while(*ptr1 != 0 && *extension_ptr != 0 && *extension_ptr != '/')
409 if(tolower(*ptr1) != tolower(*extension_ptr))
419 *extension_ptr != 0 &&
420 *extension_ptr != '/')
424 //printf("FormatTools::update_extension %d %d\n", __LINE__, need_extension);
429 extension_ptr = asset->format != FILE_FFMPEG ?
430 extensions.get(0) : asset->fformat;
431 while(*extension_ptr != 0 && *extension_ptr != '/')
432 *ptr1++ = *extension_ptr++;
436 int character1 = ptr - asset->path;
437 int character2 = strlen(asset->path);
438 // *(asset->path + character2) = 0;
441 path_textbox->update(asset->path);
442 path_textbox->set_selection(character1, character2, character2);
447 void FormatTools::update(Asset *asset, int *strategy)
450 this->strategy = strategy;
453 path_textbox->update(asset->path);
454 format_text->update(File::formattostr(asset->format));
458 multiple_files->update(strategy);
460 close_format_windows();
463 void FormatTools::close_format_windows()
465 // This is done in ~file
466 if( aparams_thread ) {
467 if( aparams_thread->running() )
468 aparams_thread->file->close_window();
469 aparams_thread->join();
471 if( vparams_thread ) {
472 if( vparams_thread->running() )
473 vparams_thread->file->close_window();
474 vparams_thread->join();
478 int FormatTools::get_w()
480 return asset->format != FILE_FFMPEG ? w :
481 format_ffmpeg->get_x() + format_ffmpeg->get_w();
484 void FormatTools::set_w(int w)
489 void FormatTools::reposition_window(int &init_x, int &init_y)
497 path_textbox->reposition_window(px, y);
498 px += path_textbox->get_w() + 5;
499 path_recent->reposition_window(px, y);
500 px += path_recent->get_w() + 8;
501 path_button->reposition_window(px, y);
502 y += path_textbox->get_h() + 10;
505 format_title->reposition_window(x, y);
507 format_text->reposition_window(x, y);
508 x += format_text->get_w();
509 format_button->reposition_window(x, y);
512 y += format_button->get_h() + 10;
516 audio_title->reposition_window(x, y);
518 aparams_button->reposition_window(x, y);
519 x += aparams_button->get_w() + 10;
520 if(prompt_audio) audio_switch->reposition_window(x, y);
523 y += aparams_button->get_h() + 10;
524 if(prompt_audio_channels)
526 channels_title->reposition_window(x, y);
528 channels_button->reposition_window(x, y);
529 x += channels_button->get_w() + 5;
530 channels_tumbler->reposition_window(x, y);
531 y += channels_button->get_h() + 20;
539 video_title->reposition_window(x, y);
541 if(prompt_video_compression)
543 vparams_button->reposition_window(x, y);
544 x += vparams_button->get_w() + 10;
549 video_switch->reposition_window(x, y);
550 y += video_switch->get_h();
554 y += vparams_button->get_h();
563 multiple_files->reposition_window(x, y);
564 y += multiple_files->get_h() + 10;
571 int FormatTools::set_audio_options()
573 // if(video_driver == CAPTURE_DVB)
578 if(!aparams_thread->running())
580 aparams_thread->start();
584 aparams_thread->file->raise_window();
589 int FormatTools::set_video_options()
591 // if(video_driver == CAPTURE_DVB)
596 if(!vparams_thread->running())
598 vparams_thread->start();
602 vparams_thread->file->raise_window();
612 FormatAParams::FormatAParams(MWindow *mwindow, FormatTools *format, int x, int y)
613 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
615 this->format = format;
616 set_tooltip(_("Configure audio compression"));
619 FormatAParams::~FormatAParams()
623 int FormatAParams::handle_event()
625 format->set_audio_options();
633 FormatVParams::FormatVParams(MWindow *mwindow, FormatTools *format, int x, int y)
634 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
636 this->format = format;
637 set_tooltip(_("Configure video compression"));
640 FormatVParams::~FormatVParams()
644 int FormatVParams::handle_event()
646 format->set_video_options();
654 FormatAThread::FormatAThread(FormatTools *format)
657 this->format = format;
662 FormatAThread::~FormatAThread()
664 delete file; file = 0;
668 void FormatAThread::start()
676 void FormatAThread::run()
678 file->get_options(format, 1, 0);
684 FormatVThread::FormatVThread(FormatTools *format)
687 this->format = format;
692 FormatVThread::~FormatVThread()
694 delete file; file = 0;
698 void FormatVThread::start()
705 void FormatVThread::run()
707 file->get_options(format, 0, 1);
714 FormatPathText::FormatPathText(int x, int y, FormatTools *format)
715 : BC_TextBox(x, y, format->w - x -
716 2*format->mwindow->theme->get_image_set("wrench")[0]->get_w() - 20, 1,
719 this->format = format;
722 FormatPathText::~FormatPathText()
725 int FormatPathText::handle_event()
727 calculate_suggestions();
728 strcpy(format->asset->path, get_text());
729 format->handle_event();
736 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
740 (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
742 this->format = format;
745 FormatAudio::~FormatAudio() {}
746 int FormatAudio::handle_event()
748 format->asset->audio_data = get_value();
753 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
757 (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
759 this->format = format;
762 FormatVideo::~FormatVideo() {}
763 int FormatVideo::handle_event()
765 format->asset->video_data = get_value();
772 FormatFormat::FormatFormat(int x, int y, FormatTools *format)
773 : FormatPopup(format->plugindb, x, y, format->use_brender)
775 this->format = format;
778 FormatFormat::~FormatFormat()
782 int FormatFormat::handle_event()
784 BC_ListBoxItem *selection = get_selection(0, 0);
786 int new_format = File::strtoformat(get_selection(0, 0)->get_text());
787 // if(new_format != format->asset->format)
789 Asset *asset = format->asset;
790 asset->format = new_format;
791 asset->audio_data = File::renders_audio(asset);
792 asset->video_data = File::renders_video(asset);
793 asset->ff_audio_options[0] = 0;
794 asset->ff_video_options[0] = 0;
795 format->format_text->update(selection->get_text());
796 format->update_extension();
797 format->close_format_windows();
798 if (format->path_recent) format->path_recent->
799 load_items(File::formattostr(format->asset->format));
800 format->update_format();
807 FormatFFMPEG::FormatFFMPEG(int x, int y, FormatTools *format)
808 : FFMPEGPopup(format->plugindb, x, y)
810 this->format = format;
813 FormatFFMPEG::~FormatFFMPEG()
817 int FormatFFMPEG::handle_event()
819 BC_ListBoxItem *selection = get_selection(0, 0);
821 char *text = get_selection(0, 0)->get_text();
822 format->ffmpeg_type->update(text);
823 format->asset->ff_audio_options[0] = 0;
824 format->asset->ff_video_options[0] = 0;
825 FFMPEG::set_asset_format(format->asset, text);
826 format->update_extension();
827 format->close_format_windows();
828 format->update_format();
836 FormatChannels::FormatChannels(int x, int y, FormatTools *format)
837 : BC_TextBox(x, y, 100, 1, format->asset->channels)
839 this->format = format;
842 FormatChannels::~FormatChannels()
846 int FormatChannels::handle_event()
848 format->asset->channels = atol(get_text());
853 FormatToTracks::FormatToTracks(int x, int y, int *output)
854 : BC_CheckBox(x, y, *output, _("Overwrite project with output"))
856 this->output = output;
859 FormatToTracks::~FormatToTracks()
863 int FormatToTracks::handle_event()
865 *output = get_value();
870 FormatMultiple::FormatMultiple(MWindow *mwindow, int x, int y, int *output)
873 (*output == FILE_PER_LABEL) || (*output == FILE_PER_LABEL_FARM),
874 _("Create new file at each label"))
876 this->output = output;
877 this->mwindow = mwindow;
880 FormatMultiple::~FormatMultiple()
884 int FormatMultiple::handle_event()
888 if(mwindow->preferences->use_renderfarm)
889 *output = FILE_PER_LABEL_FARM;
891 *output = FILE_PER_LABEL;
895 if(mwindow->preferences->use_renderfarm)
896 *output = SINGLE_PASS_FARM;
898 *output = SINGLE_PASS;
903 void FormatMultiple::update(int *output)
905 this->output = output;
906 if(*output == FILE_PER_LABEL_FARM ||
907 *output ==FILE_PER_LABEL)