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)
121 int margin = mwindow->theme->widget_border;
123 this->locked_compressor = locked_compressor;
124 this->recording = recording;
125 this->use_brender = brender;
126 this->do_audio = do_audio;
127 this->do_video = do_video;
128 this->prompt_audio = prompt_audio;
129 this->prompt_audio_channels = prompt_audio_channels;
130 this->prompt_video = prompt_video;
131 this->prompt_video_compression = prompt_video_compression;
132 this->strategy = strategy;
134 //printf("FormatTools::create_objects 1\n");
136 // Modify strategy depending on render farm
139 if(mwindow->preferences->use_renderfarm)
141 if(*strategy == FILE_PER_LABEL)
142 *strategy = FILE_PER_LABEL_FARM;
144 if(*strategy == SINGLE_PASS)
145 *strategy = SINGLE_PASS_FARM;
149 if(*strategy == FILE_PER_LABEL_FARM)
150 *strategy = FILE_PER_LABEL;
152 if(*strategy == SINGLE_PASS_FARM)
153 *strategy = SINGLE_PASS;
160 window->add_subwindow(path_textbox = new FormatPathText(px, y, this));
161 px += path_textbox->get_w() + 5;
162 path_recent = new BC_RecentList("PATH", mwindow->defaults,
163 path_textbox, 10, px, y, 300, 100);
164 window->add_subwindow(path_recent);
165 path_recent->load_items(File::formattostr(asset->format));
166 px += path_recent->get_w();
167 window->add_subwindow(path_button = new BrowseButton(
168 mwindow->theme, window, path_textbox, px, y, asset->path,
169 _("Output to file"), _("Select a file to write to:"), 0));
173 y += path_textbox->get_h() + 10;
182 window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
183 x += format_title->get_w() + margin;
184 window->add_subwindow(format_text = new BC_TextBox(x, y, 160, 1,
185 File::formattostr(asset->format)));
186 x += format_text->get_w() + margin;
187 //printf("FormatTools::create_objects %d %p\n", __LINE__, window);
188 window->add_subwindow(format_button = new FormatFormat(x, y, this));
189 format_button->create_objects();
190 x += format_button->get_w() + 5;
191 window->add_subwindow(ffmpeg_type = new FFMpegType(x, y, 64, 1, asset->fformat));
192 FFMPEG::set_asset_format(asset, asset->fformat);
193 x += ffmpeg_type->get_w();
194 window->add_subwindow(format_ffmpeg = new FormatFFMPEG(x, y, this));
195 format_ffmpeg->create_objects();
197 y += format_button->get_h() + 10;
199 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT,
200 BC_WindowBase::get_resources()->audiovideo_color));
201 x += audio_title->get_w() + margin;
202 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
203 x += aparams_button->get_w() + margin;
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");
229 if( horizontal_layout && do_audio ) {
234 //printf("FormatTools::create_objects 8\n");
235 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT,
236 BC_WindowBase::get_resources()->audiovideo_color));
237 x += video_title->get_w() + margin;
238 if(prompt_video_compression) {
239 window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
240 x += vparams_button->get_w() + margin;
243 //printf("FormatTools::create_objects 9\n");
245 window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
246 y += video_switch->get_h();
249 y += vparams_button->get_h();
252 //printf("FormatTools::create_objects 10\n");
254 vparams_thread = new FormatVThread(this);
257 //printf("FormatTools::create_objects 11\n");
262 window->add_subwindow(multiple_files = new FormatMultiple(mwindow, x, y, strategy));
263 y += multiple_files->get_h() + 10;
266 //printf("FormatTools::create_objects 12\n");
272 void FormatTools::update_driver(int driver)
274 this->video_driver = driver;
276 locked_compressor = 0;
280 case VIDEO4LINUX2MPEG:
281 // Just give the user information about how the stream is going to be
282 // stored but don't change the asset.
283 // Want to be able to revert to user settings.
284 if(asset->format == FILE_MPEG) break;
285 asset->format = FILE_MPEG;
286 format_text->update(File::formattostr(asset->format));
287 asset->audio_data = 1;
288 asset->video_data = 1;
289 audio_switch->update(1);
290 video_switch->update(1);
293 case CAPTURE_IEC61883:
294 case CAPTURE_FIREWIRE:
295 case VIDEO4LINUX2JPEG:
296 case CAPTURE_JPEG_WEBCAM:
297 asset->format = FILE_FFMPEG;
298 format_text->update(File::formattostr(asset->format));
301 case CAPTURE_IEC61883:
302 case CAPTURE_FIREWIRE:
303 locked_compressor = (char*)CODEC_TAG_DVSD;
306 case VIDEO4LINUX2JPEG:
307 locked_compressor = (char*)CODEC_TAG_MJPEG;
310 case CAPTURE_JPEG_WEBCAM:
311 locked_compressor = (char*)CODEC_TAG_JPEG;
314 if( locked_compressor )
315 strcpy(asset->vcodec, locked_compressor);
317 audio_switch->update(asset->audio_data);
318 video_switch->update(asset->video_data);
322 format_text->update(File::formattostr(asset->format));
323 audio_switch->update(asset->audio_data);
324 video_switch->update(asset->video_data);
327 close_format_windows();
331 void FormatTools::update_format()
333 if( do_audio && prompt_audio && audio_switch ) {
334 audio_switch->update(asset->audio_data);
335 if( File::renders_audio(asset) )
336 audio_switch->enable();
338 audio_switch->disable();
340 if( do_video && prompt_video && video_switch ) {
341 video_switch->update(asset->video_data);
342 if( File::renders_video(asset) )
343 video_switch->enable();
345 video_switch->disable();
347 if( asset->format == FILE_FFMPEG ) {
349 format_ffmpeg->show();
353 format_ffmpeg->hide();
357 int FormatTools::handle_event()
362 Asset* FormatTools::get_asset()
367 void FormatTools::update_extension()
369 const char *extension = File::get_tag(asset->format);
370 // split multiple extensions
371 ArrayList<const char*> extensions;
372 int len = !extension ? -1 : strlen(extension);
373 const char *extension_ptr = extension;
374 for(int i = 0; i <= len; i++)
376 if(extension[i] == '/' || extension[i] == 0)
378 extensions.append(extension_ptr);
379 extension_ptr = extension + i + 1;
383 if(extensions.size())
385 char *ptr = strrchr(asset->path, '.');
388 ptr = asset->path + strlen(asset->path);
393 // test for equivalent extension
394 int need_extension = 1;
395 //int extension_len = 0;
396 for(int i = 0; i < extensions.size() && need_extension; i++)
399 extension_ptr = extensions.get(i);
402 while(*ptr1 != 0 && *extension_ptr != 0 && *extension_ptr != '/')
404 if(tolower(*ptr1) != tolower(*extension_ptr))
414 *extension_ptr != 0 &&
415 *extension_ptr != '/')
419 //printf("FormatTools::update_extension %d %d\n", __LINE__, need_extension);
424 extension_ptr = asset->format != FILE_FFMPEG ?
425 extensions.get(0) : asset->fformat;
426 while(*extension_ptr != 0 && *extension_ptr != '/')
427 *ptr1++ = *extension_ptr++;
431 int character1 = ptr - asset->path;
432 int character2 = strlen(asset->path);
433 // *(asset->path + character2) = 0;
436 path_textbox->update(asset->path);
437 path_textbox->set_selection(character1, character2, character2);
442 void FormatTools::update(Asset *asset, int *strategy)
445 this->strategy = strategy;
448 path_textbox->update(asset->path);
449 format_text->update(File::formattostr(asset->format));
453 multiple_files->update(strategy);
455 close_format_windows();
458 void FormatTools::close_format_windows()
460 // This is done in ~file
461 if( aparams_thread ) {
462 if( aparams_thread->running() )
463 aparams_thread->file->close_window();
464 aparams_thread->join();
466 if( vparams_thread ) {
467 if( vparams_thread->running() )
468 vparams_thread->file->close_window();
469 vparams_thread->join();
473 int FormatTools::get_w()
475 return asset->format != FILE_FFMPEG ? w :
476 format_ffmpeg->get_x() + format_ffmpeg->get_w();
479 void FormatTools::set_w(int w)
484 void FormatTools::reposition_window(int &init_x, int &init_y)
492 path_textbox->reposition_window(px, y);
493 px += path_textbox->get_w() + 5;
494 path_recent->reposition_window(px, y);
495 px += path_recent->get_w() + 8;
496 path_button->reposition_window(px, y);
497 y += path_textbox->get_h() + 10;
500 format_title->reposition_window(x, y);
502 format_text->reposition_window(x, y);
503 x += format_text->get_w();
504 format_button->reposition_window(x, y);
507 y += format_button->get_h() + 10;
511 audio_title->reposition_window(x, y);
513 aparams_button->reposition_window(x, y);
514 x += aparams_button->get_w() + 10;
515 if(prompt_audio) audio_switch->reposition_window(x, y);
518 y += aparams_button->get_h() + 10;
519 if(prompt_audio_channels)
521 channels_title->reposition_window(x, y);
523 channels_button->reposition_window(x, y);
524 x += channels_button->get_w() + 5;
525 channels_tumbler->reposition_window(x, y);
526 y += channels_button->get_h() + 20;
534 video_title->reposition_window(x, y);
536 if(prompt_video_compression)
538 vparams_button->reposition_window(x, y);
539 x += vparams_button->get_w() + 10;
544 video_switch->reposition_window(x, y);
545 y += video_switch->get_h();
549 y += vparams_button->get_h();
558 multiple_files->reposition_window(x, y);
559 y += multiple_files->get_h() + 10;
566 int FormatTools::set_audio_options()
568 // if(video_driver == CAPTURE_DVB)
573 if(!aparams_thread->running())
575 aparams_thread->start();
579 aparams_thread->file->raise_window();
584 int FormatTools::set_video_options()
586 // if(video_driver == CAPTURE_DVB)
591 if(!vparams_thread->running())
593 vparams_thread->start();
597 vparams_thread->file->raise_window();
607 FormatAParams::FormatAParams(MWindow *mwindow, FormatTools *format, int x, int y)
608 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
610 this->format = format;
611 set_tooltip(_("Configure audio compression"));
614 FormatAParams::~FormatAParams()
618 int FormatAParams::handle_event()
620 format->set_audio_options();
628 FormatVParams::FormatVParams(MWindow *mwindow, FormatTools *format, int x, int y)
629 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
631 this->format = format;
632 set_tooltip(_("Configure video compression"));
635 FormatVParams::~FormatVParams()
639 int FormatVParams::handle_event()
641 format->set_video_options();
649 FormatAThread::FormatAThread(FormatTools *format)
652 this->format = format;
657 FormatAThread::~FormatAThread()
659 delete file; file = 0;
663 void FormatAThread::start()
671 void FormatAThread::run()
673 file->get_options(format, 1, 0);
679 FormatVThread::FormatVThread(FormatTools *format)
682 this->format = format;
687 FormatVThread::~FormatVThread()
689 delete file; file = 0;
693 void FormatVThread::start()
700 void FormatVThread::run()
702 file->get_options(format, 0, 1);
709 FormatPathText::FormatPathText(int x, int y, FormatTools *format)
710 : BC_TextBox(x, y, format->w - x -
711 2*format->mwindow->theme->get_image_set("wrench")[0]->get_w() - 20, 1,
714 this->format = format;
717 FormatPathText::~FormatPathText()
720 int FormatPathText::handle_event()
722 calculate_suggestions();
723 strcpy(format->asset->path, get_text());
724 format->handle_event();
731 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
735 (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
737 this->format = format;
740 FormatAudio::~FormatAudio() {}
741 int FormatAudio::handle_event()
743 format->asset->audio_data = get_value();
748 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
752 (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
754 this->format = format;
757 FormatVideo::~FormatVideo() {}
758 int FormatVideo::handle_event()
760 format->asset->video_data = get_value();
767 FormatFormat::FormatFormat(int x, int y, FormatTools *format)
768 : FormatPopup(x, y, format->do_audio, format->do_video, format->use_brender)
770 this->format = format;
773 FormatFormat::~FormatFormat()
777 int FormatFormat::handle_event()
779 BC_ListBoxItem *selection = get_selection(0, 0);
781 int new_format = File::strtoformat(get_selection(0, 0)->get_text());
782 // if(new_format != format->asset->format)
784 Asset *asset = format->asset;
785 asset->format = new_format;
786 asset->audio_data = File::renders_audio(asset);
787 asset->video_data = File::renders_video(asset);
788 asset->ff_audio_options[0] = 0;
789 asset->ff_video_options[0] = 0;
790 format->format_text->update(selection->get_text());
791 if( !format->use_brender )
792 format->update_extension();
793 format->close_format_windows();
794 if (format->path_recent) format->path_recent->
795 load_items(File::formattostr(format->asset->format));
796 format->update_format();
803 FormatFFMPEG::FormatFFMPEG(int x, int y, FormatTools *format)
804 : FFMPEGPopup(format->plugindb, x, y)
806 this->format = format;
809 FormatFFMPEG::~FormatFFMPEG()
813 int FormatFFMPEG::handle_event()
815 BC_ListBoxItem *selection = get_selection(0, 0);
817 char *text = get_selection(0, 0)->get_text();
818 format->ffmpeg_type->update(text);
819 format->asset->ff_audio_options[0] = 0;
820 format->asset->ff_video_options[0] = 0;
821 FFMPEG::set_asset_format(format->asset, text);
822 format->update_extension();
823 format->close_format_windows();
824 format->update_format();
832 FormatChannels::FormatChannels(int x, int y, FormatTools *format)
833 : BC_TextBox(x, y, 100, 1, format->asset->channels)
835 this->format = format;
838 FormatChannels::~FormatChannels()
842 int FormatChannels::handle_event()
844 format->asset->channels = atol(get_text());
849 FormatToTracks::FormatToTracks(int x, int y, int *output)
850 : BC_CheckBox(x, y, *output, _("Overwrite project with output"))
852 this->output = output;
855 FormatToTracks::~FormatToTracks()
859 int FormatToTracks::handle_event()
861 *output = get_value();
866 FormatMultiple::FormatMultiple(MWindow *mwindow, int x, int y, int *output)
869 (*output == FILE_PER_LABEL) || (*output == FILE_PER_LABEL_FARM),
870 _("Create new file at each label"))
872 this->output = output;
873 this->mwindow = mwindow;
876 FormatMultiple::~FormatMultiple()
880 int FormatMultiple::handle_event()
884 if(mwindow->preferences->use_renderfarm)
885 *output = FILE_PER_LABEL_FARM;
887 *output = FILE_PER_LABEL;
891 if(mwindow->preferences->use_renderfarm)
892 *output = SINGLE_PASS_FARM;
894 *output = SINGLE_PASS;
899 void FormatMultiple::update(int *output)
901 this->output = output;
902 if(*output == FILE_PER_LABEL_FARM ||
903 *output ==FILE_PER_LABEL)