4 * Copyright (C) 2011 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
22 #include "bcsignals.h"
23 #include "channeldb.h"
24 #include "channelpicker.h"
26 #include "edlsession.h"
27 #include "formattools.h"
28 #include "../hvirtual_config.h"
31 #include "mainsession.h"
32 #include "vdeviceprefs.h"
33 #include "videoconfig.h"
34 #include "videodevice.inc"
35 #include "overlayframe.inc"
36 #include "playbackconfig.h"
37 #include "preferences.h"
38 #include "preferencesthread.h"
39 #include "recordconfig.h"
40 #include "recordprefs.h"
44 VDevicePrefs::VDevicePrefs(int x,
46 PreferencesWindow *pwindow,
47 PreferencesDialog *dialog,
48 VideoOutConfig *out_config,
49 VideoInConfig *in_config,
52 this->pwindow = pwindow;
53 this->dialog = dialog;
56 this->out_config = out_config;
57 this->in_config = in_config;
65 VDevicePrefs::~VDevicePrefs()
70 switch( pwindow->thread->current_dialog ) {
71 case PreferencesThread::PLAYBACK_A: config = 0; break;
72 case PreferencesThread::PLAYBACK_B: config = 1; break;
75 pwindow->mwindow->session->save_x11_host(config, out_config->x11_host);
76 pwindow->mwindow->channeldb_buz->save("channeldb_buz");
80 void VDevicePrefs::reset_objects()
84 follow_video_config = 0;
85 dvb_adapter_title = 0;
86 dvb_adapter_device = 0;
94 firewire_channels = 0;
100 buz_swap_channels = 0;
104 int VDevicePrefs::initialize(int creation)
112 driver = &out_config->driver;
116 driver = &in_config->driver;
119 this->driver = *driver;
123 dialog->add_subwindow(menu = new VDriverMenu(x,
126 (mode == MODERECORD),
128 menu->create_objects();
137 case CAPTURE_JPEG_WEBCAM:
138 case CAPTURE_YUYV_WEBCAM:
141 case VIDEO4LINUX2JPEG:
142 create_v4l2jpeg_objs();
144 case VIDEO4LINUX2MPEG:
145 create_v4l2mpeg_objs();
148 create_screencap_objs();
158 case PLAYBACK_X11_XV:
159 case PLAYBACK_X11_GL:
162 case PLAYBACK_DV1394:
163 case PLAYBACK_FIREWIRE:
164 case PLAYBACK_IEC61883:
165 case CAPTURE_FIREWIRE:
166 case CAPTURE_IEC61883:
167 create_firewire_objs();
176 // Update driver dependancies in file format
177 if(mode == MODERECORD && dialog && !creation)
179 RecordPrefs *record_prefs = (RecordPrefs*)dialog;
180 record_prefs->recording_format->update_driver(this->driver);
186 int VDevicePrefs::delete_objects()
189 delete channel_picker;
190 delete buz_swap_channels;
193 delete dvb_adapter_device;
194 delete follow_video_config;
195 delete dvb_adapter_title;
199 if(firewire_port) delete firewire_port;
200 if(channel_title) delete channel_title;
201 if(firewire_channel) delete firewire_channel;
202 if(firewire_path) delete firewire_path;
203 if(syt_title) delete syt_title;
204 if(firewire_syt) delete firewire_syt;
205 if(fields_title) delete fields_title;
206 if(device_fields) delete device_fields;
213 int VDevicePrefs::create_dvb_objs()
215 int x1 = x + menu->get_w() + 30;
217 char *output_char = in_config->dvb_in_adapter;
218 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - 5;
219 BC_Resources *resources = BC_WindowBase::get_resources();
220 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
221 MEDIUMFONT, resources->text_default);
222 dialog->add_subwindow(dvb_adapter_title);
223 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
224 int x2 = x1 + device_text->get_w() + 5;
225 device_title = new BC_Title(x2, y2, _("dev:"),
226 MEDIUMFONT, resources->text_default);
227 dialog->add_subwindow(device_title);
228 int *output_int = &in_config->dvb_in_device;
229 dvb_adapter_device = new VDeviceTumbleBox(this, x2, y1, output_int, 0, 9, 20);
230 dvb_adapter_device->create_objects();
231 x1 += 64; y1 += device_text->get_h() + 5;
232 follow_video_config = new BC_CheckBox(x1, y1,
233 &in_config->follow_video, _("Follow video config"));
234 dialog->add_subwindow(follow_video_config);
238 int VDevicePrefs::create_lml_objs()
240 char *output_char = 0;
241 int x1 = x + menu->get_w() + 5;
242 BC_Resources *resources = BC_WindowBase::get_resources();
247 output_char = out_config->lml_out_device;
250 output_char = in_config->lml_in_device;
253 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
254 x1 += device_title->get_w() + 10;
255 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
259 int VDevicePrefs::create_buz_objs()
261 #ifdef HAVE_VIDEO4LINUX
264 char *output_char = 0;
265 int x1 = x + menu->get_w() + 5;
268 BC_Resources *resources = BC_WindowBase::get_resources();
273 output_char = out_config->buz_out_device;
276 output_char = in_config->buz_in_device;
279 dialog->add_subwindow(device_title = new BC_Title(x1, y1, _("Device path:"), MEDIUMFONT, resources->text_default));
282 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
284 if(driver == PLAYBACK_BUZ)
286 dialog->add_subwindow(buz_swap_channels =
287 new VDeviceCheckBox(x2, y1, &out_config->buz_swap_fields, _("Swap fields")));
290 if(driver == PLAYBACK_BUZ)
292 dialog->add_subwindow(output_title = new BC_Title(x1, y1, _("Output channel:")));
294 channel_picker = new PrefsChannelPicker(pwindow->mwindow,
296 pwindow->mwindow->channeldb_buz,
299 channel_picker->create_objects();
301 #endif // HAVE_VIDEO4LINUX
306 int VDevicePrefs::create_firewire_objs()
309 char *output_char = 0;
310 int x1 = x + menu->get_w() + 5;
311 BC_Resources *resources = BC_WindowBase::get_resources();
317 if(driver == PLAYBACK_DV1394)
318 output_char = out_config->dv1394_path;
320 if(driver == PLAYBACK_FIREWIRE)
321 output_char = out_config->firewire_path;
324 // Our version of raw1394 doesn't support changing the input path
331 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
332 dialog->add_subwindow(firewire_path = new VDeviceTextBox(x1, y + 20, output_char));
333 x1 += firewire_path->get_w() + 5;
340 if(driver == PLAYBACK_DV1394)
341 output_int = &out_config->dv1394_port;
343 output_int = &out_config->firewire_port;
346 output_int = &in_config->firewire_port;
349 dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, resources->text_default));
350 dialog->add_subwindow(firewire_port = new VDeviceIntBox(x1, y + 20, output_int));
351 x1 += firewire_port->get_w() + 5;
357 if(driver == PLAYBACK_DV1394)
358 output_int = &out_config->dv1394_channel;
360 output_int = &out_config->firewire_channel;
363 output_int = &in_config->firewire_channel;
367 dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, resources->text_default));
368 dialog->add_subwindow(firewire_channel = new VDeviceIntBox(x1, y + 20, output_int));
369 x1 += firewire_channel->get_w() + 5;
376 if(driver == PLAYBACK_DV1394)
377 output_int = &out_config->dv1394_syt;
379 if(driver == PLAYBACK_FIREWIRE)
380 output_int = &out_config->firewire_syt;
390 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, resources->text_default));
391 dialog->add_subwindow(firewire_syt = new VDeviceIntBox(x1, y + 20, output_int));
397 int VDevicePrefs::create_v4l_objs()
399 #ifdef HAVE_VIDEO4LINUX
403 BC_Resources *resources = BC_WindowBase::get_resources();
404 int x1 = x + menu->get_w() + 5;
405 output_char = pwindow->thread->edl->session->vconfig_in->v4l_in_device;
406 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
407 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
410 #endif // HAVE_VIDEO4LINUX
414 int VDevicePrefs::create_v4l2_objs()
417 BC_Resources *resources = BC_WindowBase::get_resources();
418 int x1 = x + menu->get_w() + 5;
419 output_char = pwindow->thread->edl->session->vconfig_in->v4l2_in_device;
420 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
421 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
426 int VDevicePrefs::create_v4l2jpeg_objs()
428 BC_Resources *resources = BC_WindowBase::get_resources();
429 int x1 = x + menu->get_w() + 5;
430 char *output_char = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_device[0];
431 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
432 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
433 x1 += max(device_title->get_w(),device_text->get_w()) + 5;
434 int *output_int = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_fields;
435 fields_title = new BC_Title(x1, y, _("Fields:"), MEDIUMFONT, resources->text_default);
436 dialog->add_subwindow(fields_title);
437 device_fields = new VDeviceTumbleBox(this, x1, y + 20, output_int, 1, 2, 20);
438 device_fields->create_objects();
442 int VDevicePrefs::create_v4l2mpeg_objs()
445 BC_Resources *resources = BC_WindowBase::get_resources();
446 int x1 = x + menu->get_w() + 5;
447 output_char = pwindow->thread->edl->session->vconfig_in->v4l2mpeg_in_device;
448 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
450 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
451 x1 += 64; y1 += device_text->get_h() + 5;
452 follow_video_config = new BC_CheckBox(x1, y1,
453 &in_config->follow_video, _("Follow video config"));
454 dialog->add_subwindow(follow_video_config);
459 int VDevicePrefs::create_screencap_objs()
462 BC_Resources *resources = BC_WindowBase::get_resources();
463 int x1 = x + menu->get_w() + 5;
464 output_char = pwindow->thread->edl->session->vconfig_in->screencapture_display;
465 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display:"), MEDIUMFONT, resources->text_default));
466 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
470 int VDevicePrefs::create_x11_objs()
473 BC_Resources *resources = BC_WindowBase::get_resources();
474 int x1 = x + menu->get_w() + 5;
475 output_char = out_config->x11_host;
476 const char *x11_display;
477 switch( pwindow->thread->current_dialog ) {
479 case PreferencesThread::PLAYBACK_A:
480 x11_display = _("Default A Display:"); break;
482 case PreferencesThread::PLAYBACK_B:
483 x11_display = _("Default B Display:"); break;
486 dialog->add_subwindow(device_title = new BC_Title(x1, y, x11_display,
487 MEDIUMFONT, resources->text_default));
488 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
495 VDriverMenu::VDriverMenu(int x,
497 VDevicePrefs *device_prefs,
500 : BC_PopupMenu(x, y, 200, driver_to_string(*output))
502 this->output = output;
503 this->do_input = do_input;
504 this->device_prefs = device_prefs;
507 VDriverMenu::~VDriverMenu()
511 char* VDriverMenu::driver_to_string(int driver)
516 sprintf(string, VIDEO4LINUX_TITLE);
519 sprintf(string, VIDEO4LINUX2_TITLE);
521 case CAPTURE_JPEG_WEBCAM:
522 sprintf(string, CAPTURE_JPEG_WEBCAM_TITLE);
524 case CAPTURE_YUYV_WEBCAM:
525 sprintf(string, CAPTURE_YUYV_WEBCAM_TITLE);
527 case VIDEO4LINUX2JPEG:
528 sprintf(string, VIDEO4LINUX2JPEG_TITLE);
530 case VIDEO4LINUX2MPEG:
531 sprintf(string, VIDEO4LINUX2MPEG_TITLE);
534 sprintf(string, SCREENCAPTURE_TITLE);
537 sprintf(string, CAPTURE_BUZ_TITLE);
540 sprintf(string, CAPTURE_LML_TITLE);
542 case CAPTURE_FIREWIRE:
543 sprintf(string, CAPTURE_FIREWIRE_TITLE);
545 case CAPTURE_IEC61883:
546 sprintf(string, CAPTURE_IEC61883_TITLE);
549 sprintf(string, CAPTURE_DVB_TITLE);
552 sprintf(string, PLAYBACK_X11_TITLE);
554 case PLAYBACK_X11_XV:
555 sprintf(string, PLAYBACK_X11_XV_TITLE);
557 case PLAYBACK_X11_GL:
558 sprintf(string, PLAYBACK_X11_GL_TITLE);
561 sprintf(string, PLAYBACK_LML_TITLE);
564 sprintf(string, PLAYBACK_BUZ_TITLE);
566 case PLAYBACK_FIREWIRE:
567 sprintf(string, PLAYBACK_FIREWIRE_TITLE);
569 case PLAYBACK_DV1394:
570 sprintf(string, PLAYBACK_DV1394_TITLE);
572 case PLAYBACK_IEC61883:
573 sprintf(string, PLAYBACK_IEC61883_TITLE);
582 void VDriverMenu::create_objects()
586 #ifdef HAVE_VIDEO4LINUX
587 add_item(new VDriverItem(this, VIDEO4LINUX_TITLE, VIDEO4LINUX));
590 #ifdef HAVE_VIDEO4LINUX2
591 add_item(new VDriverItem(this, VIDEO4LINUX2_TITLE, VIDEO4LINUX2));
592 add_item(new VDriverItem(this, CAPTURE_JPEG_WEBCAM_TITLE, CAPTURE_JPEG_WEBCAM));
593 add_item(new VDriverItem(this, CAPTURE_YUYV_WEBCAM_TITLE, CAPTURE_YUYV_WEBCAM));
594 add_item(new VDriverItem(this, VIDEO4LINUX2JPEG_TITLE, VIDEO4LINUX2JPEG));
595 add_item(new VDriverItem(this, VIDEO4LINUX2MPEG_TITLE, VIDEO4LINUX2MPEG));
598 add_item(new VDriverItem(this, SCREENCAPTURE_TITLE, SCREENCAPTURE));
599 #ifdef HAVE_VIDEO4LINUX
600 add_item(new VDriverItem(this, CAPTURE_BUZ_TITLE, CAPTURE_BUZ));
602 add_item(new VDriverItem(this, CAPTURE_FIREWIRE_TITLE, CAPTURE_FIREWIRE));
603 add_item(new VDriverItem(this, CAPTURE_IEC61883_TITLE, CAPTURE_IEC61883));
604 add_item(new VDriverItem(this, CAPTURE_DVB_TITLE, CAPTURE_DVB));
608 add_item(new VDriverItem(this, PLAYBACK_X11_TITLE, PLAYBACK_X11));
609 add_item(new VDriverItem(this, PLAYBACK_X11_XV_TITLE, PLAYBACK_X11_XV));
611 add_item(new VDriverItem(this, PLAYBACK_X11_GL_TITLE, PLAYBACK_X11_GL));
613 add_item(new VDriverItem(this, PLAYBACK_BUZ_TITLE, PLAYBACK_BUZ));
614 add_item(new VDriverItem(this, PLAYBACK_FIREWIRE_TITLE, PLAYBACK_FIREWIRE));
615 add_item(new VDriverItem(this, PLAYBACK_DV1394_TITLE, PLAYBACK_DV1394));
616 add_item(new VDriverItem(this, PLAYBACK_IEC61883_TITLE, PLAYBACK_IEC61883));
621 VDriverItem::VDriverItem(VDriverMenu *popup, const char *text, int driver)
625 this->driver = driver;
628 VDriverItem::~VDriverItem()
632 int VDriverItem::handle_event()
634 popup->set_text(get_text());
635 *(popup->output) = driver;
636 popup->device_prefs->initialize(0);
637 popup->device_prefs->pwindow->show_dialog();
644 VDeviceTextBox::VDeviceTextBox(int x, int y, char *output)
645 : BC_TextBox(x, y, 200, 1, output)
647 this->output = output;
650 int VDeviceTextBox::handle_event()
653 calculate_suggestions(0);
655 strcpy(output, get_text());
659 VDeviceTumbleBox::VDeviceTumbleBox(VDevicePrefs *prefs,
660 int x, int y, int *output, int min, int max, int text_w)
661 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
663 this->output = output;
666 int VDeviceTumbleBox::handle_event()
668 *output = atol(get_text());
677 VDeviceIntBox::VDeviceIntBox(int x, int y, int *output)
678 : BC_TextBox(x, y, 60, 1, *output)
680 this->output = output;
683 int VDeviceIntBox::handle_event()
685 *output = atol(get_text());
693 VDeviceCheckBox::VDeviceCheckBox(int x, int y, int *output, char *text)
694 : BC_CheckBox(x, y, *output, text)
696 this->output = output;
698 int VDeviceCheckBox::handle_event()
700 *output = get_value();
707 VScalingItem::VScalingItem(VScalingEquation *popup, int interpolation)
708 : BC_MenuItem(popup->interpolation_to_string(interpolation))
711 this->interpolation = interpolation;
714 VScalingItem::~VScalingItem()
718 int VScalingItem::handle_event()
720 popup->set_text(get_text());
721 *(popup->output) = interpolation;
726 VScalingEquation::VScalingEquation(int x, int y, int *output)
727 : BC_PopupMenu(x, y, 175, interpolation_to_string(*output))
729 this->output = output;
732 VScalingEquation::~VScalingEquation()
736 const char *VScalingEquation::interpolation_to_string(int type)
739 case NEAREST_NEIGHBOR: return _("Nearest Neighbor");
740 case CUBIC_CUBIC: return _("BiCubic / BiCubic");
741 case CUBIC_LINEAR: return _("BiCubic / BiLinear");
742 case LINEAR_LINEAR: return _("BiLinear / BiLinear");
743 case LANCZOS_LANCZOS: return _("Lanczos / Lanczos");
748 void VScalingEquation::create_objects()
750 add_item(new VScalingItem(this, NEAREST_NEIGHBOR));
751 add_item(new VScalingItem(this, CUBIC_CUBIC));
752 add_item(new VScalingItem(this, CUBIC_LINEAR));
753 add_item(new VScalingItem(this, LINEAR_LINEAR));
754 add_item(new VScalingItem(this, LANCZOS_LANCZOS));