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)
118 int margin = mwindow->theme->widget_border;
120 this->locked_compressor = locked_compressor;
121 this->recording = recording;
122 this->use_brender = brender;
123 this->do_audio = do_audio;
124 this->do_video = do_video;
125 this->prompt_audio = prompt_audio;
126 this->prompt_audio_channels = prompt_audio_channels;
127 this->prompt_video = prompt_video;
128 this->prompt_video_compression = prompt_video_compression;
129 this->file_per_label = file_per_label;
131 //printf("FormatTools::create_objects 1\n");
136 window->add_subwindow(path_textbox = new FormatPathText(px, y, this));
137 px += path_textbox->get_w() + 5;
138 path_recent = new BC_RecentList("PATH", mwindow->defaults,
139 path_textbox, 10, px, y, 300, 100);
140 window->add_subwindow(path_recent);
141 path_recent->load_items(File::formattostr(asset->format));
142 px += path_recent->get_w();
143 window->add_subwindow(path_button = new BrowseButton(
144 mwindow->theme, window, path_textbox, px, y, asset->path,
145 _("Output to file"), _("Select a file to write to:"), 0));
149 y += path_textbox->get_h() + 10;
158 window->add_subwindow(format_title = new BC_Title(x, y, _("File Format:")));
159 x += format_title->get_w() + margin;
160 window->add_subwindow(format_text = new BC_TextBox(x, y, 160, 1,
161 File::formattostr(asset->format)));
162 x += format_text->get_w() + margin;
163 //printf("FormatTools::create_objects %d %p\n", __LINE__, window);
164 window->add_subwindow(format_button = new FormatFormat(x, y, this));
165 format_button->create_objects();
166 x += format_button->get_w() + 5;
167 window->add_subwindow(ffmpeg_type = new FFMpegType(x, y, 70, 1, asset->fformat));
168 FFMPEG::set_asset_format(asset, mwindow->edl, asset->fformat);
169 x += ffmpeg_type->get_w();
170 window->add_subwindow(format_ffmpeg = new FormatFFMPEG(x, y, this));
171 format_ffmpeg->create_objects();
173 y += format_button->get_h() + 10;
175 window->add_subwindow(audio_title = new BC_Title(x, y, _("Audio:"), LARGEFONT,
176 BC_WindowBase::get_resources()->audiovideo_color));
177 x += audio_title->get_w() + margin;
178 window->add_subwindow(aparams_button = new FormatAParams(mwindow, this, x, y));
179 x += aparams_button->get_w() + margin;
181 window->add_subwindow(audio_switch = new FormatAudio(x, y, this, asset->audio_data));
185 y += aparams_button->get_h() + 10;
187 //printf("FormatTools::create_objects 6\n");
188 aparams_thread = new FormatAThread(this);
191 //printf("FormatTools::create_objects 7\n");
193 if( horizontal_layout && do_audio ) {
198 //printf("FormatTools::create_objects 8\n");
199 window->add_subwindow(video_title = new BC_Title(x, y, _("Video:"), LARGEFONT,
200 BC_WindowBase::get_resources()->audiovideo_color));
201 x += video_title->get_w() + margin;
202 if(prompt_video_compression) {
203 window->add_subwindow(vparams_button = new FormatVParams(mwindow, this, x, y));
204 x += vparams_button->get_w() + margin;
207 //printf("FormatTools::create_objects 9\n");
209 window->add_subwindow(video_switch = new FormatVideo(x, y, this, asset->video_data));
210 y += video_switch->get_h();
213 y += vparams_button->get_h();
216 //printf("FormatTools::create_objects 10\n");
218 vparams_thread = new FormatVThread(this);
221 //printf("FormatTools::create_objects 11\n");
224 if( file_per_label ) {
225 labeled_files = new FormatFilePerLabel(this, x, y, file_per_label);
226 window->add_subwindow(labeled_files);
227 y += labeled_files->get_h() + 10;
230 //printf("FormatTools::create_objects 12\n");
236 void FormatTools::update_driver(int driver)
238 this->video_driver = driver;
240 locked_compressor = 0;
244 case VIDEO4LINUX2MPEG:
245 // Just give the user information about how the stream is going to be
246 // stored but don't change the asset.
247 // Want to be able to revert to user settings.
248 if(asset->format == FILE_MPEG) break;
249 asset->format = FILE_MPEG;
250 format_text->update(File::formattostr(asset->format));
251 asset->audio_data = 1;
252 asset->video_data = 1;
253 audio_switch->update(1);
254 video_switch->update(1);
257 case CAPTURE_IEC61883:
258 case CAPTURE_FIREWIRE:
259 case VIDEO4LINUX2JPEG:
260 case CAPTURE_JPEG_WEBCAM:
261 asset->format = FILE_FFMPEG;
262 format_text->update(File::formattostr(asset->format));
266 case CAPTURE_IEC61883:
267 case CAPTURE_FIREWIRE:
268 locked_compressor = (char*)CODEC_TAG_DVSD;
271 case VIDEO4LINUX2JPEG:
272 locked_compressor = (char*)CODEC_TAG_MJPEG;
275 case CAPTURE_JPEG_WEBCAM:
276 locked_compressor = (char*)CODEC_TAG_JPEG;
279 if( locked_compressor )
280 strcpy(asset->vcodec, locked_compressor);
282 audio_switch->update(asset->audio_data);
283 video_switch->update(asset->video_data);
287 format_text->update(File::formattostr(asset->format));
288 audio_switch->update(asset->audio_data);
289 video_switch->update(asset->video_data);
292 close_format_windows();
296 void FormatTools::update_format()
298 if( do_audio && prompt_audio && audio_switch ) {
299 audio_switch->update(asset->audio_data);
300 if( File::renders_audio(asset) )
301 audio_switch->enable();
303 audio_switch->disable();
305 if( do_video && prompt_video && video_switch ) {
306 video_switch->update(asset->video_data);
307 if( File::renders_video(asset) )
308 video_switch->enable();
310 video_switch->disable();
312 if( asset->format == FILE_FFMPEG ) {
314 format_ffmpeg->show();
318 format_ffmpeg->hide();
322 int FormatTools::handle_event()
327 Asset* FormatTools::get_asset()
332 void FormatTools::update_extension()
334 const char *extension = File::get_tag(asset->format);
335 // split multiple extensions
336 ArrayList<const char*> extensions;
337 int len = !extension ? -1 : strlen(extension);
338 const char *extension_ptr = extension;
339 for(int i = 0; i <= len; i++)
341 if(extension[i] == '/' || extension[i] == 0)
343 extensions.append(extension_ptr);
344 extension_ptr = extension + i + 1;
348 if(extensions.size())
350 char *ptr = strrchr(asset->path, '.');
353 ptr = asset->path + strlen(asset->path);
358 // test for equivalent extension
359 int need_extension = 1;
360 //int extension_len = 0;
361 for(int i = 0; i < extensions.size() && need_extension; i++)
364 extension_ptr = extensions.get(i);
367 while(*ptr1 != 0 && *extension_ptr != 0 && *extension_ptr != '/')
369 if(tolower(*ptr1) != tolower(*extension_ptr))
379 *extension_ptr != 0 &&
380 *extension_ptr != '/')
384 //printf("FormatTools::update_extension %d %d\n", __LINE__, need_extension);
389 extension_ptr = asset->format != FILE_FFMPEG ?
390 extensions.get(0) : asset->fformat;
391 while(*extension_ptr != 0 && *extension_ptr != '/')
392 *ptr1++ = *extension_ptr++;
396 int character1 = ptr - asset->path;
397 int character2 = strlen(asset->path);
398 // *(asset->path + character2) = 0;
401 path_textbox->update(asset->path);
402 path_textbox->set_selection(character1, character2, character2);
407 void FormatTools::update(Asset *asset, int *file_per_label)
410 this->file_per_label = file_per_label;
411 if( file_per_label ) labeled_files->update(file_per_label);
412 if( path_textbox ) path_textbox->update(asset->path);
413 format_text->update(File::formattostr(asset->format));
415 close_format_windows();
418 void FormatTools::close_format_windows()
420 // This is done in ~file
421 if( aparams_thread ) {
422 if( aparams_thread->running() )
423 aparams_thread->file->close_window();
424 aparams_thread->join();
426 if( vparams_thread ) {
427 if( vparams_thread->running() )
428 vparams_thread->file->close_window();
429 vparams_thread->join();
433 int FormatTools::get_w()
435 return asset->format != FILE_FFMPEG ? w :
436 format_ffmpeg->get_x() + format_ffmpeg->get_w();
439 void FormatTools::set_w(int w)
444 void FormatTools::reposition_window(int &init_x, int &init_y)
452 path_textbox->reposition_window(px, y);
453 px += path_textbox->get_w() + 5;
454 path_recent->reposition_window(px, y);
455 px += path_recent->get_w() + 8;
456 path_button->reposition_window(px, y);
457 y += path_textbox->get_h() + 10;
460 format_title->reposition_window(x, y);
462 format_text->reposition_window(x, y);
463 x += format_text->get_w();
464 format_button->reposition_window(x, y);
467 y += format_button->get_h() + 10;
471 audio_title->reposition_window(x, y);
473 aparams_button->reposition_window(x, y);
474 x += aparams_button->get_w() + 10;
475 if(prompt_audio) audio_switch->reposition_window(x, y);
478 y += aparams_button->get_h() + 10;
484 video_title->reposition_window(x, y);
486 if(prompt_video_compression)
488 vparams_button->reposition_window(x, y);
489 x += vparams_button->get_w() + 10;
494 video_switch->reposition_window(x, y);
495 y += video_switch->get_h();
499 y += vparams_button->get_h();
506 if( file_per_label ) {
507 labeled_files->reposition_window(x, y);
508 y += labeled_files->get_h() + 10;
515 int FormatTools::set_audio_options()
517 // if(video_driver == CAPTURE_DVB)
522 if(!aparams_thread->running())
524 aparams_thread->start();
528 aparams_thread->file->raise_window();
533 int FormatTools::set_video_options()
535 // if(video_driver == CAPTURE_DVB)
540 if(!vparams_thread->running())
542 vparams_thread->start();
546 vparams_thread->file->raise_window();
556 FormatAParams::FormatAParams(MWindow *mwindow, FormatTools *format, int x, int y)
557 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
559 this->format = format;
560 set_tooltip(_("Configure audio compression"));
563 FormatAParams::~FormatAParams()
567 int FormatAParams::handle_event()
569 format->set_audio_options();
570 format->handle_event();
578 FormatVParams::FormatVParams(MWindow *mwindow, FormatTools *format, int x, int y)
579 : BC_Button(x, y, mwindow->theme->get_image_set("wrench"))
581 this->format = format;
582 set_tooltip(_("Configure video compression"));
585 FormatVParams::~FormatVParams()
589 int FormatVParams::handle_event()
591 format->set_video_options();
592 format->handle_event();
600 FormatAThread::FormatAThread(FormatTools *format)
603 this->format = format;
608 FormatAThread::~FormatAThread()
610 delete file; file = 0;
614 void FormatAThread::start()
622 void FormatAThread::run()
624 file->get_options(format, 1, 0);
630 FormatVThread::FormatVThread(FormatTools *format)
633 this->format = format;
638 FormatVThread::~FormatVThread()
640 delete file; file = 0;
644 void FormatVThread::start()
651 void FormatVThread::run()
653 file->get_options(format, 0, 1);
660 FormatPathText::FormatPathText(int x, int y, FormatTools *format)
661 : BC_TextBox(x, y, format->w - x -
662 2*format->mwindow->theme->get_image_set("wrench")[0]->get_w() - 20, 1,
665 this->format = format;
668 FormatPathText::~FormatPathText()
671 int FormatPathText::handle_event()
673 calculate_suggestions();
674 strcpy(format->asset->path, get_text());
675 format->handle_event();
682 FormatAudio::FormatAudio(int x, int y, FormatTools *format, int default_)
686 (char*)(format->recording ? _("Record audio tracks") : _("Render audio tracks")))
688 this->format = format;
691 FormatAudio::~FormatAudio() {}
692 int FormatAudio::handle_event()
694 format->asset->audio_data = get_value();
695 format->handle_event();
700 FormatVideo::FormatVideo(int x, int y, FormatTools *format, int default_)
704 (char*)(format->recording ? _("Record video tracks") : _("Render video tracks")))
706 this->format = format;
709 FormatVideo::~FormatVideo() {}
710 int FormatVideo::handle_event()
712 format->asset->video_data = get_value();
713 format->handle_event();
720 FormatFormat::FormatFormat(int x, int y, FormatTools *format)
721 : FormatPopup(x, y, format->do_audio, format->do_video, format->use_brender)
723 this->format = format;
726 FormatFormat::~FormatFormat()
730 int FormatFormat::handle_event()
732 BC_ListBoxItem *selection = get_selection(0, 0);
734 int new_format = File::strtoformat(get_selection(0, 0)->get_text());
735 // if(new_format != format->asset->format)
737 Asset *asset = format->asset;
738 asset->format = new_format;
739 asset->audio_data = File::renders_audio(asset);
740 asset->video_data = File::renders_video(asset);
741 asset->ff_audio_options[0] = 0;
742 asset->ff_video_options[0] = 0;
743 format->format_text->update(selection->get_text());
744 if( !format->use_brender )
745 format->update_extension();
746 format->close_format_windows();
747 if (format->path_recent) format->path_recent->
748 load_items(File::formattostr(format->asset->format));
749 format->update_format();
751 format->handle_event();
757 FormatFFMPEG::FormatFFMPEG(int x, int y, FormatTools *format)
760 this->format = format;
763 FormatFFMPEG::~FormatFFMPEG()
767 int FormatFFMPEG::handle_event()
769 BC_ListBoxItem *selection = get_selection(0, 0);
771 char *text = get_selection(0, 0)->get_text();
772 format->ffmpeg_type->update(text);
773 format->asset->ff_audio_options[0] = 0;
774 format->asset->ff_video_options[0] = 0;
775 FFMPEG::set_asset_format(format->asset, format->mwindow->edl, text);
776 format->update_extension();
777 format->close_format_windows();
778 format->update_format();
779 format->handle_event();
785 FormatFilePerLabel::FormatFilePerLabel(FormatTools *format,
786 int x, int y, int *output)
787 : BC_CheckBox(x, y, *output, _("Create new file at each label"))
789 this->format = format;
790 this->output = output;
793 FormatFilePerLabel::~FormatFilePerLabel()
797 int FormatFilePerLabel::handle_event()
799 *output = get_value();
800 format->handle_event();
804 void FormatFilePerLabel::update(int *output)
806 this->output = output;
807 set_value(*output ? 1 : 0);