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"
30 #include "mainsession.h"
31 #include "vdeviceprefs.h"
32 #include "videoconfig.h"
33 #include "videodevice.inc"
34 #include "overlayframe.inc"
35 #include "playbackconfig.h"
36 #include "preferences.h"
37 #include "preferencesthread.h"
38 #include "recordconfig.h"
39 #include "recordprefs.h"
43 VDevicePrefs::VDevicePrefs(int x,
45 PreferencesWindow *pwindow,
46 PreferencesDialog *dialog,
47 VideoOutConfig *out_config,
48 VideoInConfig *in_config,
51 this->pwindow = pwindow;
52 this->dialog = dialog;
55 this->out_config = out_config;
56 this->in_config = in_config;
64 VDevicePrefs::~VDevicePrefs()
69 switch( pwindow->thread->current_dialog ) {
70 case PreferencesThread::PLAYBACK_A: config = 0; break;
71 case PreferencesThread::PLAYBACK_B: config = 1; break;
74 pwindow->mwindow->session->save_x11_host(config, out_config->x11_host);
75 pwindow->mwindow->channeldb_buz->save("channeldb_buz");
79 void VDevicePrefs::reset_objects()
83 follow_video_config = 0;
84 dvb_adapter_title = 0;
85 dvb_adapter_device = 0;
93 firewire_channels = 0;
99 buz_swap_channels = 0;
103 int VDevicePrefs::initialize(int creation)
111 driver = &out_config->driver;
115 driver = &in_config->driver;
118 this->driver = *driver;
122 dialog->add_subwindow(menu = new VDriverMenu(x,
125 (mode == MODERECORD),
127 menu->create_objects();
136 case CAPTURE_JPEG_WEBCAM:
137 case CAPTURE_YUYV_WEBCAM:
140 case VIDEO4LINUX2JPEG:
141 create_v4l2jpeg_objs();
143 case VIDEO4LINUX2MPEG:
144 create_v4l2mpeg_objs();
147 create_screencap_objs();
157 case PLAYBACK_X11_XV:
158 case PLAYBACK_X11_GL:
161 case PLAYBACK_DV1394:
162 case PLAYBACK_FIREWIRE:
163 case PLAYBACK_IEC61883:
164 case CAPTURE_FIREWIRE:
165 case CAPTURE_IEC61883:
166 create_firewire_objs();
175 // Update driver dependancies in file format
176 if(mode == MODERECORD && dialog && !creation)
178 RecordPrefs *record_prefs = (RecordPrefs*)dialog;
179 record_prefs->recording_format->update_driver(this->driver);
185 int VDevicePrefs::delete_objects()
188 delete channel_picker;
189 delete buz_swap_channels;
192 delete dvb_adapter_device;
193 delete follow_video_config;
194 delete dvb_adapter_title;
198 if(firewire_port) delete firewire_port;
199 if(channel_title) delete channel_title;
200 if(firewire_channel) delete firewire_channel;
201 if(firewire_path) delete firewire_path;
202 if(syt_title) delete syt_title;
203 if(firewire_syt) delete firewire_syt;
204 if(fields_title) delete fields_title;
205 if(device_fields) delete device_fields;
212 void VDevicePrefs::create_dvb_objs()
214 int x1 = x + menu->get_w() + 30;
216 char *output_char = in_config->dvb_in_adapter;
217 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - 5;
218 BC_Resources *resources = BC_WindowBase::get_resources();
219 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
220 MEDIUMFONT, resources->text_default);
221 dialog->add_subwindow(dvb_adapter_title);
222 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
223 int x2 = x1 + device_text->get_w() + 5;
224 device_title = new BC_Title(x2, y2, _("dev:"),
225 MEDIUMFONT, resources->text_default);
226 dialog->add_subwindow(device_title);
227 int *output_int = &in_config->dvb_in_device;
228 dvb_adapter_device = new VDeviceTumbleBox(this, x2, y1, output_int, 0, 9, 20);
229 dvb_adapter_device->create_objects();
230 x1 += 64; y1 += device_text->get_h() + 5;
231 follow_video_config = new BC_CheckBox(x1, y1,
232 &in_config->follow_video, _("Follow video config"));
233 dialog->add_subwindow(follow_video_config);
236 int VDevicePrefs::create_lml_objs()
238 char *output_char = 0;
239 int x1 = x + menu->get_w() + 5;
240 BC_Resources *resources = BC_WindowBase::get_resources();
245 output_char = out_config->lml_out_device;
248 output_char = in_config->lml_in_device;
251 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
252 x1 += device_title->get_w() + 10;
253 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
257 int VDevicePrefs::create_buz_objs()
259 #ifdef HAVE_VIDEO4LINUX
262 char *output_char = 0;
263 int x1 = x + menu->get_w() + 5;
266 BC_Resources *resources = BC_WindowBase::get_resources();
271 output_char = out_config->buz_out_device;
274 output_char = in_config->buz_in_device;
277 dialog->add_subwindow(device_title = new BC_Title(x1, y1, _("Device path:"), MEDIUMFONT, resources->text_default));
280 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
282 if(driver == PLAYBACK_BUZ)
284 dialog->add_subwindow(buz_swap_channels =
285 new VDeviceCheckBox(x2, y1, &out_config->buz_swap_fields, _("Swap fields")));
288 if(driver == PLAYBACK_BUZ)
290 dialog->add_subwindow(output_title = new BC_Title(x1, y1, _("Output channel:")));
292 channel_picker = new PrefsChannelPicker(pwindow->mwindow,
294 pwindow->mwindow->channeldb_buz,
297 channel_picker->create_objects();
299 #endif // HAVE_VIDEO4LINUX
304 int VDevicePrefs::create_firewire_objs()
307 char *output_char = 0;
308 int x1 = x + menu->get_w() + 5;
309 BC_Resources *resources = BC_WindowBase::get_resources();
315 if(driver == PLAYBACK_DV1394)
316 output_char = out_config->dv1394_path;
318 if(driver == PLAYBACK_FIREWIRE)
319 output_char = out_config->firewire_path;
322 if(driver == CAPTURE_FIREWIRE)
323 output_char = in_config->firewire_path;
329 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
330 dialog->add_subwindow(firewire_path = new VDeviceTextBox(x1, y + 20, output_char));
331 x1 += firewire_path->get_w() + 5;
338 if(driver == PLAYBACK_DV1394)
339 output_int = &out_config->dv1394_port;
341 output_int = &out_config->firewire_port;
344 output_int = &in_config->firewire_port;
347 dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, resources->text_default));
348 dialog->add_subwindow(firewire_port = new VDeviceIntBox(x1, y + 20, output_int));
349 x1 += firewire_port->get_w() + 5;
355 if(driver == PLAYBACK_DV1394)
356 output_int = &out_config->dv1394_channel;
358 output_int = &out_config->firewire_channel;
361 output_int = &in_config->firewire_channel;
365 dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, resources->text_default));
366 dialog->add_subwindow(firewire_channel = new VDeviceIntBox(x1, y + 20, output_int));
367 x1 += firewire_channel->get_w() + 5;
374 if(driver == PLAYBACK_DV1394)
375 output_int = &out_config->dv1394_syt;
377 if(driver == PLAYBACK_FIREWIRE)
378 output_int = &out_config->firewire_syt;
388 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, resources->text_default));
389 dialog->add_subwindow(firewire_syt = new VDeviceIntBox(x1, y + 20, output_int));
395 int VDevicePrefs::create_v4l_objs()
397 #ifdef HAVE_VIDEO4LINUX
401 BC_Resources *resources = BC_WindowBase::get_resources();
402 int x1 = x + menu->get_w() + 5;
403 output_char = pwindow->thread->edl->session->vconfig_in->v4l_in_device;
404 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
405 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
408 #endif // HAVE_VIDEO4LINUX
412 int VDevicePrefs::create_v4l2_objs()
415 BC_Resources *resources = BC_WindowBase::get_resources();
416 int x1 = x + menu->get_w() + 5;
417 output_char = pwindow->thread->edl->session->vconfig_in->v4l2_in_device;
418 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
419 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
424 int VDevicePrefs::create_v4l2jpeg_objs()
426 BC_Resources *resources = BC_WindowBase::get_resources();
427 int x1 = x + menu->get_w() + 5;
428 char *output_char = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_device[0];
429 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
430 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
431 x1 += max(device_title->get_w(),device_text->get_w()) + 5;
432 int *output_int = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_fields;
433 fields_title = new BC_Title(x1, y, _("Fields:"), MEDIUMFONT, resources->text_default);
434 dialog->add_subwindow(fields_title);
435 device_fields = new VDeviceTumbleBox(this, x1, y + 20, output_int, 1, 2, 20);
436 device_fields->create_objects();
440 int VDevicePrefs::create_v4l2mpeg_objs()
443 BC_Resources *resources = BC_WindowBase::get_resources();
444 int x1 = x + menu->get_w() + 5;
445 output_char = pwindow->thread->edl->session->vconfig_in->v4l2mpeg_in_device;
446 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
448 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
449 x1 += 64; y1 += device_text->get_h() + 5;
450 follow_video_config = new BC_CheckBox(x1, y1,
451 &in_config->follow_video, _("Follow video config"));
452 dialog->add_subwindow(follow_video_config);
457 int VDevicePrefs::create_screencap_objs()
460 BC_Resources *resources = BC_WindowBase::get_resources();
461 int x1 = x + menu->get_w() + 5;
462 output_char = pwindow->thread->edl->session->vconfig_in->screencapture_display;
463 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display:"), MEDIUMFONT, resources->text_default));
464 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
468 int VDevicePrefs::create_x11_objs()
471 BC_Resources *resources = BC_WindowBase::get_resources();
472 int x1 = x + menu->get_w() + 5;
473 output_char = out_config->x11_host;
474 const char *x11_display;
475 switch( pwindow->thread->current_dialog ) {
477 case PreferencesThread::PLAYBACK_A:
478 x11_display = _("Default A Display:"); break;
480 case PreferencesThread::PLAYBACK_B:
481 x11_display = _("Default B Display:"); break;
484 dialog->add_subwindow(device_title = new BC_Title(x1, y, x11_display,
485 MEDIUMFONT, resources->text_default));
486 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
493 VDriverMenu::VDriverMenu(int x,
495 VDevicePrefs *device_prefs,
498 : BC_PopupMenu(x, y, 200, driver_to_string(*output))
500 this->output = output;
501 this->do_input = do_input;
502 this->device_prefs = device_prefs;
505 VDriverMenu::~VDriverMenu()
509 char* VDriverMenu::driver_to_string(int driver)
514 sprintf(string, VIDEO4LINUX_TITLE);
517 sprintf(string, VIDEO4LINUX2_TITLE);
519 case CAPTURE_JPEG_WEBCAM:
520 sprintf(string, CAPTURE_JPEG_WEBCAM_TITLE);
522 case CAPTURE_YUYV_WEBCAM:
523 sprintf(string, CAPTURE_YUYV_WEBCAM_TITLE);
525 case VIDEO4LINUX2JPEG:
526 sprintf(string, VIDEO4LINUX2JPEG_TITLE);
528 case VIDEO4LINUX2MPEG:
529 sprintf(string, VIDEO4LINUX2MPEG_TITLE);
532 sprintf(string, SCREENCAPTURE_TITLE);
535 sprintf(string, CAPTURE_BUZ_TITLE);
538 sprintf(string, CAPTURE_LML_TITLE);
541 case CAPTURE_FIREWIRE:
542 sprintf(string, CAPTURE_FIREWIRE_TITLE);
544 case CAPTURE_IEC61883:
545 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);
567 case PLAYBACK_FIREWIRE:
568 sprintf(string, PLAYBACK_FIREWIRE_TITLE);
570 case PLAYBACK_DV1394:
571 sprintf(string, PLAYBACK_DV1394_TITLE);
573 case PLAYBACK_IEC61883:
574 sprintf(string, PLAYBACK_IEC61883_TITLE);
583 void VDriverMenu::create_objects()
587 #ifdef HAVE_VIDEO4LINUX
588 add_item(new VDriverItem(this, VIDEO4LINUX_TITLE, VIDEO4LINUX));
591 #ifdef HAVE_VIDEO4LINUX2
592 add_item(new VDriverItem(this, VIDEO4LINUX2_TITLE, VIDEO4LINUX2));
593 add_item(new VDriverItem(this, CAPTURE_JPEG_WEBCAM_TITLE, CAPTURE_JPEG_WEBCAM));
594 add_item(new VDriverItem(this, CAPTURE_YUYV_WEBCAM_TITLE, CAPTURE_YUYV_WEBCAM));
595 add_item(new VDriverItem(this, VIDEO4LINUX2JPEG_TITLE, VIDEO4LINUX2JPEG));
596 add_item(new VDriverItem(this, VIDEO4LINUX2MPEG_TITLE, VIDEO4LINUX2MPEG));
599 add_item(new VDriverItem(this, SCREENCAPTURE_TITLE, SCREENCAPTURE));
600 #ifdef HAVE_VIDEO4LINUX
601 add_item(new VDriverItem(this, CAPTURE_BUZ_TITLE, CAPTURE_BUZ));
604 add_item(new VDriverItem(this, CAPTURE_FIREWIRE_TITLE, CAPTURE_FIREWIRE));
605 add_item(new VDriverItem(this, CAPTURE_IEC61883_TITLE, CAPTURE_IEC61883));
607 add_item(new VDriverItem(this, CAPTURE_DVB_TITLE, CAPTURE_DVB));
611 add_item(new VDriverItem(this, PLAYBACK_X11_TITLE, PLAYBACK_X11));
612 add_item(new VDriverItem(this, PLAYBACK_X11_XV_TITLE, PLAYBACK_X11_XV));
614 // Check runtime glx version. pbuffer needs >= 1.3
615 if(get_opengl_server_version() >= 103)
616 add_item(new VDriverItem(this, PLAYBACK_X11_GL_TITLE, PLAYBACK_X11_GL));
618 add_item(new VDriverItem(this, PLAYBACK_BUZ_TITLE, PLAYBACK_BUZ));
620 add_item(new VDriverItem(this, PLAYBACK_FIREWIRE_TITLE, PLAYBACK_FIREWIRE));
621 add_item(new VDriverItem(this, PLAYBACK_DV1394_TITLE, PLAYBACK_DV1394));
622 add_item(new VDriverItem(this, PLAYBACK_IEC61883_TITLE, PLAYBACK_IEC61883));
628 VDriverItem::VDriverItem(VDriverMenu *popup, const char *text, int driver)
632 this->driver = driver;
635 VDriverItem::~VDriverItem()
639 int VDriverItem::handle_event()
641 popup->set_text(get_text());
642 *(popup->output) = driver;
643 popup->device_prefs->initialize(0);
644 popup->device_prefs->pwindow->show_dialog();
651 VDeviceTextBox::VDeviceTextBox(int x, int y, char *output)
652 : BC_TextBox(x, y, 200, 1, output)
654 this->output = output;
657 int VDeviceTextBox::handle_event()
660 calculate_suggestions(0);
662 strcpy(output, get_text());
666 VDeviceTumbleBox::VDeviceTumbleBox(VDevicePrefs *prefs,
667 int x, int y, int *output, int min, int max, int text_w)
668 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
670 this->output = output;
673 int VDeviceTumbleBox::handle_event()
675 *output = atol(get_text());
684 VDeviceIntBox::VDeviceIntBox(int x, int y, int *output)
685 : BC_TextBox(x, y, 60, 1, *output)
687 this->output = output;
690 int VDeviceIntBox::handle_event()
692 *output = atol(get_text());
700 VDeviceCheckBox::VDeviceCheckBox(int x, int y, int *output, char *text)
701 : BC_CheckBox(x, y, *output, text)
703 this->output = output;
705 int VDeviceCheckBox::handle_event()
707 *output = get_value();
714 VScalingItem::VScalingItem(VScalingEquation *popup, int interpolation)
715 : BC_MenuItem(popup->interpolation_to_string(interpolation))
718 this->interpolation = interpolation;
721 VScalingItem::~VScalingItem()
725 int VScalingItem::handle_event()
727 popup->set_text(get_text());
728 *(popup->output) = interpolation;
733 VScalingEquation::VScalingEquation(int x, int y, int *output)
734 : BC_PopupMenu(x, y, 175, interpolation_to_string(*output))
736 this->output = output;
739 VScalingEquation::~VScalingEquation()
743 const char *VScalingEquation::interpolation_to_string(int type)
746 case NEAREST_NEIGHBOR: return _("Nearest Neighbor");
747 case CUBIC_CUBIC: return _("BiCubic / BiCubic");
748 case CUBIC_LINEAR: return _("BiCubic / BiLinear");
749 case LINEAR_LINEAR: return _("BiLinear / BiLinear");
750 case LANCZOS_LANCZOS: return _("Lanczos / Lanczos");
755 void VScalingEquation::create_objects()
757 add_item(new VScalingItem(this, NEAREST_NEIGHBOR));
758 add_item(new VScalingItem(this, CUBIC_CUBIC));
759 add_item(new VScalingItem(this, CUBIC_LINEAR));
760 add_item(new VScalingItem(this, LINEAR_LINEAR));
761 add_item(new VScalingItem(this, LANCZOS_LANCZOS));