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"
27 #include "edlsession.h"
28 #include "formattools.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"
45 VDevicePrefs::VDevicePrefs(int x,
47 PreferencesWindow *pwindow,
48 PreferencesDialog *dialog,
49 VideoOutConfig *out_config,
50 VideoInConfig *in_config,
53 this->pwindow = pwindow;
54 this->dialog = dialog;
55 this->driver = DEV_UNKNOWN;
57 this->out_config = out_config;
58 this->in_config = in_config;
66 VDevicePrefs::~VDevicePrefs()
71 switch( pwindow->thread->current_dialog ) {
72 case PreferencesThread::PLAYBACK_A: config = 0; break;
73 case PreferencesThread::PLAYBACK_B: config = 1; break;
76 pwindow->mwindow->session->save_x11_host(config, out_config->x11_host);
80 void VDevicePrefs::reset_objects()
84 follow_video_config = 0;
85 dvb_adapter_title = 0;
86 dvb_adapter_device = 0;
94 firewire_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();
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();
150 case PLAYBACK_X11_XV:
151 case PLAYBACK_X11_GL:
154 case PLAYBACK_DV1394:
155 case PLAYBACK_FIREWIRE:
156 case PLAYBACK_IEC61883:
157 case CAPTURE_FIREWIRE:
158 case CAPTURE_IEC61883:
159 create_firewire_objs();
168 // Update driver dependancies in file format
169 if(mode == MODERECORD && dialog && !creation)
171 RecordPrefs *record_prefs = (RecordPrefs*)dialog;
172 record_prefs->recording_format->update_driver(this->driver);
178 int VDevicePrefs::delete_objects()
181 delete channel_picker;
184 delete dvb_adapter_device;
185 delete follow_video_config;
186 delete dvb_adapter_title;
187 delete use_direct_x11;
191 if(firewire_port) delete firewire_port;
192 if(channel_title) delete channel_title;
193 if(firewire_channel) delete firewire_channel;
194 if(firewire_path) delete firewire_path;
195 if(syt_title) delete syt_title;
196 if(firewire_syt) delete firewire_syt;
197 if(fields_title) delete fields_title;
198 if(device_fields) delete device_fields;
205 int VDevicePrefs::get_h()
207 int margin = pwindow->mwindow->theme->widget_border;
208 return BC_Title::calculate_h(dialog, "X", MEDIUMFONT) + margin +
209 BC_TextBox::calculate_h(dialog, MEDIUMFONT, 1, 1);
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_firewire_objs()
239 char *output_char = 0;
240 int x1 = x + menu->get_w() + 5;
241 BC_Resources *resources = BC_WindowBase::get_resources();
247 if(driver == PLAYBACK_DV1394)
248 output_char = out_config->dv1394_path;
250 if(driver == PLAYBACK_FIREWIRE)
251 output_char = out_config->firewire_path;
254 if(driver == CAPTURE_FIREWIRE)
255 output_char = in_config->firewire_path;
261 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
262 dialog->add_subwindow(firewire_path = new VDeviceTextBox(x1, y + 20, output_char));
263 x1 += firewire_path->get_w() + 5;
270 if(driver == PLAYBACK_DV1394)
271 output_int = &out_config->dv1394_port;
273 output_int = &out_config->firewire_port;
276 output_int = &in_config->firewire_port;
279 dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, resources->text_default));
280 dialog->add_subwindow(firewire_port = new VDeviceIntBox(x1, y + 20, output_int));
281 x1 += firewire_port->get_w() + 5;
287 if(driver == PLAYBACK_DV1394)
288 output_int = &out_config->dv1394_channel;
290 output_int = &out_config->firewire_channel;
293 output_int = &in_config->firewire_channel;
297 dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, resources->text_default));
298 dialog->add_subwindow(firewire_channel = new VDeviceIntBox(x1, y + 20, output_int));
299 x1 += firewire_channel->get_w() + 5;
306 if(driver == PLAYBACK_DV1394)
307 output_int = &out_config->dv1394_syt;
309 if(driver == PLAYBACK_FIREWIRE)
310 output_int = &out_config->firewire_syt;
320 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, resources->text_default));
321 dialog->add_subwindow(firewire_syt = new VDeviceIntBox(x1, y + 20, output_int));
327 int VDevicePrefs::create_v4l2_objs()
330 BC_Resources *resources = BC_WindowBase::get_resources();
331 int x1 = x + menu->get_w() + 5;
332 output_char = pwindow->thread->edl->session->vconfig_in->v4l2_in_device;
333 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
334 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
339 int VDevicePrefs::create_v4l2jpeg_objs()
341 BC_Resources *resources = BC_WindowBase::get_resources();
342 int x1 = x + menu->get_w() + 5;
343 char *output_char = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_device[0];
344 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
345 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
346 x1 += bmax(device_title->get_w(),device_text->get_w()) + 5;
347 int *output_int = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_fields;
348 fields_title = new BC_Title(x1, y, _("Fields:"), MEDIUMFONT, resources->text_default);
349 dialog->add_subwindow(fields_title);
350 device_fields = new VDeviceTumbleBox(this, x1, y + 20, output_int, 1, 2, 20);
351 device_fields->create_objects();
355 int VDevicePrefs::create_v4l2mpeg_objs()
358 BC_Resources *resources = BC_WindowBase::get_resources();
359 int x1 = x + menu->get_w() + 5;
360 output_char = pwindow->thread->edl->session->vconfig_in->v4l2mpeg_in_device;
361 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
363 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
364 x1 += 64; y1 += device_text->get_h() + 5;
365 follow_video_config = new BC_CheckBox(x1, y1,
366 &in_config->follow_video, _("Follow video config"));
367 dialog->add_subwindow(follow_video_config);
372 int VDevicePrefs::create_screencap_objs()
375 BC_Resources *resources = BC_WindowBase::get_resources();
376 int x1 = x + menu->get_w() + 5;
377 output_char = pwindow->thread->edl->session->vconfig_in->screencapture_display;
378 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display:"), MEDIUMFONT, resources->text_default));
379 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
383 int VDevicePrefs::create_x11_objs()
386 BC_Resources *resources = BC_WindowBase::get_resources();
387 output_char = out_config->x11_host;
388 const char *x11_display;
389 switch( pwindow->thread->current_dialog ) {
391 case PreferencesThread::PLAYBACK_A:
392 x11_display = _("Default A Display:"); break;
394 case PreferencesThread::PLAYBACK_B:
395 x11_display = _("Default B Display:"); break;
398 int x1 = menu->get_x() + menu->get_w() + 10;
399 int y1 = menu->get_y();
400 if( driver == PLAYBACK_X11 ) y1 -= 10;
401 dialog->add_subwindow(device_title = new BC_Title(x1, y1+4, x11_display,
402 MEDIUMFONT, resources->text_default));
403 int x2 = x1 + device_title->get_w() + 10, dy = device_title->get_h();
404 dialog->add_subwindow(device_text = new VDeviceTextBox(x2, y1, output_char));
405 if( driver == PLAYBACK_X11 ) {
406 int y2 = device_text->get_h();
407 if( dy < y2 ) dy = y2;
409 use_direct_x11 = new BC_CheckBox(x1, y1,
410 &out_config->use_direct_x11, _("use direct x11 render if possible"));
411 dialog->add_subwindow(use_direct_x11);
419 VDriverMenu::VDriverMenu(int x,
421 VDevicePrefs *device_prefs,
424 : BC_PopupMenu(x, y, 200, driver_to_string(*output))
426 this->output = output;
427 this->do_input = do_input;
428 this->device_prefs = device_prefs;
431 VDriverMenu::~VDriverMenu()
435 char* VDriverMenu::driver_to_string(int driver)
440 sprintf(string, DEV_UNKNOWN_TITLE);
443 sprintf(string, VIDEO4LINUX2_TITLE);
445 case CAPTURE_JPEG_WEBCAM:
446 sprintf(string, CAPTURE_JPEG_WEBCAM_TITLE);
448 case CAPTURE_YUYV_WEBCAM:
449 sprintf(string, CAPTURE_YUYV_WEBCAM_TITLE);
451 case VIDEO4LINUX2JPEG:
452 sprintf(string, VIDEO4LINUX2JPEG_TITLE);
454 case VIDEO4LINUX2MPEG:
455 sprintf(string, VIDEO4LINUX2MPEG_TITLE);
458 sprintf(string, SCREENCAPTURE_TITLE);
461 case CAPTURE_FIREWIRE:
462 sprintf(string, CAPTURE_FIREWIRE_TITLE);
464 case CAPTURE_IEC61883:
465 sprintf(string, CAPTURE_IEC61883_TITLE);
469 sprintf(string, CAPTURE_DVB_TITLE);
472 sprintf(string, PLAYBACK_X11_TITLE);
474 case PLAYBACK_X11_XV:
475 sprintf(string, PLAYBACK_X11_XV_TITLE);
477 case PLAYBACK_X11_GL:
478 sprintf(string, PLAYBACK_X11_GL_TITLE);
481 case PLAYBACK_FIREWIRE:
482 sprintf(string, PLAYBACK_FIREWIRE_TITLE);
484 case PLAYBACK_DV1394:
485 sprintf(string, PLAYBACK_DV1394_TITLE);
487 case PLAYBACK_IEC61883:
488 sprintf(string, PLAYBACK_IEC61883_TITLE);
497 void VDriverMenu::create_objects()
501 #ifdef HAVE_VIDEO4LINUX2
502 add_item(new VDriverItem(this, VIDEO4LINUX2_TITLE, VIDEO4LINUX2));
503 add_item(new VDriverItem(this, CAPTURE_JPEG_WEBCAM_TITLE, CAPTURE_JPEG_WEBCAM));
504 add_item(new VDriverItem(this, CAPTURE_YUYV_WEBCAM_TITLE, CAPTURE_YUYV_WEBCAM));
505 add_item(new VDriverItem(this, VIDEO4LINUX2JPEG_TITLE, VIDEO4LINUX2JPEG));
506 add_item(new VDriverItem(this, VIDEO4LINUX2MPEG_TITLE, VIDEO4LINUX2MPEG));
509 add_item(new VDriverItem(this, SCREENCAPTURE_TITLE, SCREENCAPTURE));
511 add_item(new VDriverItem(this, CAPTURE_FIREWIRE_TITLE, CAPTURE_FIREWIRE));
512 add_item(new VDriverItem(this, CAPTURE_IEC61883_TITLE, CAPTURE_IEC61883));
515 add_item(new VDriverItem(this, CAPTURE_DVB_TITLE, CAPTURE_DVB));
520 add_item(new VDriverItem(this, PLAYBACK_X11_TITLE, PLAYBACK_X11));
521 add_item(new VDriverItem(this, PLAYBACK_X11_XV_TITLE, PLAYBACK_X11_XV));
523 // Check runtime glx version. pbuffer needs >= 1.3
524 if(get_opengl_server_version() >= 103)
525 add_item(new VDriverItem(this, PLAYBACK_X11_GL_TITLE, PLAYBACK_X11_GL));
528 add_item(new VDriverItem(this, PLAYBACK_FIREWIRE_TITLE, PLAYBACK_FIREWIRE));
529 add_item(new VDriverItem(this, PLAYBACK_DV1394_TITLE, PLAYBACK_DV1394));
530 add_item(new VDriverItem(this, PLAYBACK_IEC61883_TITLE, PLAYBACK_IEC61883));
536 VDriverItem::VDriverItem(VDriverMenu *popup, const char *text, int driver)
540 this->driver = driver;
543 VDriverItem::~VDriverItem()
547 int VDriverItem::handle_event()
549 popup->set_text(get_text());
550 *(popup->output) = driver;
551 popup->device_prefs->initialize(0);
552 popup->device_prefs->pwindow->show_dialog();
559 VDeviceTextBox::VDeviceTextBox(int x, int y, char *output)
560 : BC_TextBox(x, y, 200, 1, output)
562 this->output = output;
565 int VDeviceTextBox::handle_event()
568 calculate_suggestions(0);
570 strcpy(output, get_text());
574 VDeviceTumbleBox::VDeviceTumbleBox(VDevicePrefs *prefs,
575 int x, int y, int *output, int min, int max, int text_w)
576 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
578 this->output = output;
581 int VDeviceTumbleBox::handle_event()
583 *output = atol(get_text());
592 VDeviceIntBox::VDeviceIntBox(int x, int y, int *output)
593 : BC_TextBox(x, y, 60, 1, *output)
595 this->output = output;
598 int VDeviceIntBox::handle_event()
600 *output = atol(get_text());
608 VDeviceCheckBox::VDeviceCheckBox(int x, int y, int *output, char *text)
609 : BC_CheckBox(x, y, *output, text)
611 this->output = output;
613 int VDeviceCheckBox::handle_event()
615 *output = get_value();
622 VScalingItem::VScalingItem(VScalingEquation *popup, int interpolation)
623 : BC_MenuItem(popup->interpolation_to_string(interpolation))
626 this->interpolation = interpolation;
629 VScalingItem::~VScalingItem()
633 int VScalingItem::handle_event()
635 popup->set_text(get_text());
636 *(popup->output) = interpolation;
641 VScalingEquation::VScalingEquation(int x, int y, int *output)
642 : BC_PopupMenu(x, y, 240, interpolation_to_string(*output))
644 this->output = output;
647 VScalingEquation::~VScalingEquation()
651 const char *VScalingEquation::interpolation_to_string(int type)
654 case NEAREST_NEIGHBOR: return _("Nearest Neighbor");
655 case CUBIC_CUBIC: return _("BiCubic / BiCubic");
656 case CUBIC_LINEAR: return _("BiCubic / BiLinear");
657 case LINEAR_LINEAR: return _("BiLinear / BiLinear");
658 case LANCZOS_LANCZOS: return _("Lanczos / Lanczos");
663 void VScalingEquation::create_objects()
665 add_item(new VScalingItem(this, NEAREST_NEIGHBOR));
666 add_item(new VScalingItem(this, CUBIC_CUBIC));
667 add_item(new VScalingItem(this, CUBIC_LINEAR));
668 add_item(new VScalingItem(this, LINEAR_LINEAR));
669 add_item(new VScalingItem(this, LANCZOS_LANCZOS));