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"
34 #include "maxchannels.h"
36 #include "preferences.h"
38 #include "videodevice.inc"
44 FormatTools::FormatTools(MWindow *mwindow,
45 BC_WindowBase *window,
48 this->mwindow = mwindow;
49 this->window = window;
74 prompt_audio_channels = 0;
76 prompt_video_compression = 0;
78 locked_compressor = 0;
82 FormatTools::~FormatTools()
93 if(aparams_button) delete aparams_button;
95 if(vparams_button) delete vparams_button;
97 if(aparams_thread) delete aparams_thread;
99 if(vparams_thread) delete vparams_thread;
103 void FormatTools::create_objects(
104 int &init_x, int &init_y,
105 int do_audio, int do_video, // Include support for audio, video
106 int prompt_audio, int prompt_video, // Include checkbox for audio, video
107 int prompt_audio_channels,
108 int prompt_video_compression,
109 const char *locked_compressor,
113 int horizontal_layout)
119 int margin = mwindow->theme->widget_border;
121 this->locked_compressor = locked_compressor;
122 this->recording = recording;
123 this->use_brender = brender;
124 this->do_audio = do_audio;
125 this->do_video = do_video;
126 this->prompt_audio = prompt_audio;
127 this->prompt_audio_channels = prompt_audio_channels;
128 this->prompt_video = prompt_video;
129 this->prompt_video_compression = prompt_video_compression;
130 this->file_per_label = file_per_label;
132 //printf("FormatTools::create_objects 1\n");
137 window->add_subwindow(path_textbox = new FormatPathText(px, y, this));
138 px += path_textbox->get_w() + 5;
139 path_recent = new BC_RecentList("PATH", mwindow->defaults,
140 path_textbox, 10, px, y, xS(300), yS(100));
141 window->add_subwindow(path_recent);
142 path_recent->load_items(File::formattostr(asset->format));
143 px += path_recent->get_w();
144 window->add_subwindow(path_button = new BrowseButton(
145 mwindow->theme, window, path_textbox, px, y, asset->path,
146 _("Output to file"), _("Select a file to write to:"), 0));
150 y += path_textbox->get_h() + ys10;
159 window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
160 x += format_title->get_w() + margin;
161 window->add_subwindow(format_text = new BC_TextBox(x, y, xS(160), 1,
162 File::formattostr(asset->format)));
163 x += format_text->get_w() + margin;
164 //printf("FormatTools::create_objects %d %p\n", __LINE__, window);
165 window->add_subwindow(format_button = new FormatFormat(x, y, this));
166 format_button->create_objects();
167 x += format_button->get_w() + 5;
168 window->add_subwindow(ffmpeg_type = new FFMpegType(x, y, xS(70), 1, asset->fformat));
169 FFMPEG::set_asset_format(asset, mwindow->edl, asset->fformat);
170 x += ffmpeg_type->get_w();
171 window->add_subwindow(format_ffmpeg = new FormatFFMPEG(x, y, this));
172 format_ffmpeg->create_objects();
174 y += format_button->get_h() + ys10;
176 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT,
177 BC_WindowBase::get_resources()->audiovideo_color));
178 x += audio_title->get_w() + margin;
179 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
180 x += aparams_button->get_w() + margin;
182 window->add_subwindow(audio_switch = new FormatAudio(x, y, this, asset->audio_data));
186 y += aparams_button->get_h() + ys10;
188 //printf("FormatTools::create_objects 6\n");
189 aparams_thread = new FormatAThread(this);
192 //printf("FormatTools::create_objects 7\n");
194 if( horizontal_layout && do_audio ) {
199 //printf("FormatTools::create_objects 8\n");
200 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT,
201 BC_WindowBase::get_resources()->audiovideo_color));
202 x += video_title->get_w() + margin;
203 if(prompt_video_compression) {
204 window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
205 x += vparams_button->get_w() + margin;
208 //printf("FormatTools::create_objects 9\n");
210 window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
211 y += video_switch->get_h();
214 y += vparams_button->get_h();
217 //printf("FormatTools::create_objects 10\n");
219 vparams_thread = new FormatVThread(this);
222 //printf("FormatTools::create_objects 11\n");
225 if( file_per_label ) {
226 labeled_files = new FormatFilePerLabel(this, x, y, file_per_label);
227 window->add_subwindow(labeled_files);
228 y += labeled_files->get_h() + ys10;
231 //printf("FormatTools::create_objects 12\n");
237 void FormatTools::update_driver(int driver)
239 this->video_driver = driver;
241 locked_compressor = 0;
245 case VIDEO4LINUX2MPEG:
246 // Just give the user information about how the stream is going to be
247 // stored but don't change the asset.
248 // Want to be able to revert to user settings.
249 if(asset->format == FILE_MPEG) break;
250 asset->format = FILE_MPEG;
251 format_text->update(File::formattostr(asset->format));
252 asset->audio_data = 1;
253 asset->video_data = 1;
254 audio_switch->update(1);
255 video_switch->update(1);
258 case CAPTURE_IEC61883:
259 case CAPTURE_FIREWIRE:
260 case VIDEO4LINUX2JPEG:
261 case CAPTURE_JPEG_WEBCAM:
262 asset->format = FILE_FFMPEG;
263 format_text->update(File::formattostr(asset->format));
267 case CAPTURE_IEC61883:
268 case CAPTURE_FIREWIRE:
269 locked_compressor = (char*)CODEC_TAG_DVSD;
272 case VIDEO4LINUX2JPEG:
273 locked_compressor = (char*)CODEC_TAG_MJPEG;
276 case CAPTURE_JPEG_WEBCAM:
277 locked_compressor = (char*)CODEC_TAG_JPEG;
280 if( locked_compressor )
281 strcpy(asset->vcodec, locked_compressor);
283 audio_switch->update(asset->audio_data);
284 video_switch->update(asset->video_data);
288 format_text->update(File::formattostr(asset->format));
289 audio_switch->update(asset->audio_data);
290 video_switch->update(asset->video_data);
293 close_format_windows();
297 void FormatTools::update_format()
299 if( do_audio && prompt_audio && audio_switch ) {
300 audio_switch->update(asset->audio_data);
301 if( File::renders_audio(asset) )
302 audio_switch->enable();
304 audio_switch->disable();
306 if( do_video && prompt_video && video_switch ) {
307 video_switch->update(asset->video_data);
308 if( File::renders_video(asset) )
309 video_switch->enable();
311 video_switch->disable();
313 if( asset->format == FILE_FFMPEG ) {
315 format_ffmpeg->show();
319 format_ffmpeg->hide();
323 int FormatTools::handle_event()
328 Asset* FormatTools::get_asset()
333 void FormatTools::update_extension()
335 const char *extension = File::get_tag(asset->format);
336 // split multiple extensions
337 ArrayList<const char*> extensions;
338 int len = !extension ? -1 : strlen(extension);
339 const char *extension_ptr = extension;
340 for(int i = 0; i <= len; i++)
342 if(extension[i] == '/' || extension[i] == 0)
344 extensions.append(extension_ptr);
345 extension_ptr = extension + i + 1;
349 if(extensions.size())
351 char *ptr = strrchr(asset->path, '.');
354 ptr = asset->path + strlen(asset->path);
359 // test for equivalent extension
360 int need_extension = 1;
361 //int extension_len = 0;
362 for(int i = 0; i < extensions.size() && need_extension; i++)
365 extension_ptr = extensions.get(i);
368 while(*ptr1 != 0 && *extension_ptr != 0 && *extension_ptr != '/')
370 if(tolower(*ptr1) != tolower(*extension_ptr))
379 if( (!*ptr1 && (*extension_ptr && *extension_ptr != '/')) ||
380 (*ptr1 && (!*extension_ptr || *extension_ptr == '/')) )
384 //printf("FormatTools::update_extension %d %d\n", __LINE__, need_extension);
389 // change "qt" to "mov" since ffmpeg does not know qt
390 extension_ptr = asset->format != FILE_FFMPEG ? extensions.get(0) :
391 !strcmp(asset->fformat, "qt" ) ||
392 !strcmp(asset->fformat, "pro" ) ? "mov" : asset->fformat ;
393 while(*extension_ptr != 0 && *extension_ptr != '/')
394 *ptr1++ = *extension_ptr++;
398 int character1 = ptr - asset->path;
399 int character2 = strlen(asset->path);
400 // *(asset->path + character2) = 0;
403 path_textbox->update(asset->path);
404 path_textbox->set_selection(character1, character2, character2);
409 void FormatTools::update(Asset *asset, int *file_per_label)
412 this->file_per_label = file_per_label;
413 if( file_per_label ) labeled_files->update(file_per_label);
414 if( path_textbox ) path_textbox->update(asset->path);
415 format_text->update(File::formattostr(asset->format));
417 close_format_windows();
420 void FormatTools::close_format_windows()
422 // This is done in ~file
423 if( aparams_thread ) {
424 if( aparams_thread->running() )
425 aparams_thread->file->close_window();
426 aparams_thread->join();
428 if( vparams_thread ) {
429 if( vparams_thread->running() )
430 vparams_thread->file->close_window();
431 vparams_thread->join();
435 int FormatTools::get_w()
437 return asset->format != FILE_FFMPEG ? w :
438 format_ffmpeg->get_x() + format_ffmpeg->get_w();
441 void FormatTools::set_w(int w)
446 void FormatTools::reposition_window(int &init_x, int &init_y)
448 int xs10 = xS(10), xs80 = xS(80);
456 path_textbox->reposition_window(px, y);
457 px += path_textbox->get_w() + xS(5);
458 path_recent->reposition_window(px, y);
459 px += path_recent->get_w() + xS(8);
460 path_button->reposition_window(px, y);
461 y += path_textbox->get_h() + ys10;
464 format_title->reposition_window(x, y);
466 format_text->reposition_window(x, y);
467 x += format_text->get_w();
468 format_button->reposition_window(x, y);
471 y += format_button->get_h() + ys10;
475 audio_title->reposition_window(x, y);
477 aparams_button->reposition_window(x, y);
478 x += aparams_button->get_w() + xs10;
479 if(prompt_audio) audio_switch->reposition_window(x, y);
482 y += aparams_button->get_h() + ys10;
488 video_title->reposition_window(x, y);
490 if(prompt_video_compression)
492 vparams_button->reposition_window(x, y);
493 x += vparams_button->get_w() + xs10;
498 video_switch->reposition_window(x, y);
499 y += video_switch->get_h();
503 y += vparams_button->get_h();
510 if( file_per_label ) {
511 labeled_files->reposition_window(x, y);
512 y += labeled_files->get_h() + ys10;
519 int FormatTools::set_audio_options()
521 // if(video_driver == CAPTURE_DVB)
526 if(!aparams_thread->running())
528 aparams_thread->start();
532 aparams_thread->file->raise_window();
537 int FormatTools::set_video_options()
539 // if(video_driver == CAPTURE_DVB)
544 if(!vparams_thread->running())
546 vparams_thread->start();
550 vparams_thread->file->raise_window();
560 FormatAParams::FormatAParams(MWindow *mwindow, FormatTools *format, int x, int y)
561 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
563 this->format = format;
564 set_tooltip(_("Configure audio compression"));
567 FormatAParams::~FormatAParams()
571 int FormatAParams::handle_event()
573 format->set_audio_options();
574 format->handle_event();
582 FormatVParams::FormatVParams(MWindow *mwindow, FormatTools *format, int x, int y)
583 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
585 this->format = format;
586 set_tooltip(_("Configure video compression"));
589 FormatVParams::~FormatVParams()
593 int FormatVParams::handle_event()
595 format->set_video_options();
596 format->handle_event();
604 FormatAThread::FormatAThread(FormatTools *format)
607 this->format = format;
612 FormatAThread::~FormatAThread()
614 delete file; file = 0;
618 void FormatAThread::start()
626 void FormatAThread::run()
628 file->get_options(format, 1, 0);
634 FormatVThread::FormatVThread(FormatTools *format)
637 this->format = format;
642 FormatVThread::~FormatVThread()
644 delete file; file = 0;
648 void FormatVThread::start()
655 void FormatVThread::run()
657 file->get_options(format, 0, 1);
664 FormatPathText::FormatPathText(int x, int y, FormatTools *format)
665 : BC_TextBox(x, y, format->w - x -
666 2*format->mwindow->theme->get_image_set("wrench")[0]->get_w() - xS(20), 1,
669 this->format = format;
672 FormatPathText::~FormatPathText()
675 int FormatPathText::handle_event()
677 calculate_suggestions();
678 strcpy(format->asset->path, get_text());
679 format->handle_event();
686 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
690 (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
692 this->format = format;
695 FormatAudio::~FormatAudio() {}
696 int FormatAudio::handle_event()
698 format->asset->audio_data = get_value();
699 format->handle_event();
704 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
708 (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
710 this->format = format;
713 FormatVideo::~FormatVideo() {}
714 int FormatVideo::handle_event()
716 format->asset->video_data = get_value();
717 format->handle_event();
724 FormatFormat::FormatFormat(int x, int y, FormatTools *format)
725 : FormatPopup(x, y, format->do_audio, format->do_video, format->use_brender)
727 this->format = format;
730 FormatFormat::~FormatFormat()
734 int FormatFormat::handle_event()
736 BC_ListBoxItem *selection = get_selection(0, 0);
738 int new_format = File::strtoformat(get_selection(0, 0)->get_text());
739 // if(new_format != format->asset->format)
741 Asset *asset = format->asset;
742 asset->format = new_format;
743 asset->audio_data = File::renders_audio(asset);
744 asset->video_data = File::renders_video(asset);
745 asset->ff_audio_options[0] = 0;
746 asset->ff_video_options[0] = 0;
747 format->format_text->update(selection->get_text());
748 if( !format->use_brender )
749 format->update_extension();
750 format->close_format_windows();
751 if (format->path_recent) format->path_recent->
752 load_items(File::formattostr(format->asset->format));
753 format->update_format();
755 format->handle_event();
761 FormatFFMPEG::FormatFFMPEG(int x, int y, FormatTools *format)
764 this->format = format;
767 FormatFFMPEG::~FormatFFMPEG()
771 int FormatFFMPEG::handle_event()
773 BC_ListBoxItem *selection = get_selection(0, 0);
775 const char *text = get_selection(0, 0)->get_text();
776 format->ffmpeg_type->update(text);
777 format->asset->ff_audio_options[0] = 0;
778 format->asset->ff_video_options[0] = 0;
779 FFMPEG::set_asset_format(format->asset, format->mwindow->edl, text);
780 format->update_extension();
781 format->close_format_windows();
782 format->update_format();
783 format->handle_event();
789 FormatFilePerLabel::FormatFilePerLabel(FormatTools *format,
790 int x, int y, int *output)
791 : BC_CheckBox(x, y, *output, _("Create new file at each label"))
793 this->format = format;
794 this->output = output;
797 FormatFilePerLabel::~FormatFilePerLabel()
801 int FormatFilePerLabel::handle_event()
803 *output = get_value();
804 format->handle_event();
808 void FormatFilePerLabel::update(int *output)
810 this->output = output;
811 set_value(*output ? 1 : 0);