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, y + yS(10),
124 this, (mode == MODERECORD), driver));
125 menu->create_objects();
126 menu->context_help_set_keyword("Video Out section");
134 case CAPTURE_JPEG_WEBCAM:
135 case CAPTURE_YUYV_WEBCAM:
138 case VIDEO4LINUX2JPEG:
139 create_v4l2jpeg_objs();
141 case VIDEO4LINUX2MPEG:
142 create_v4l2mpeg_objs();
145 create_screencap_objs();
148 case PLAYBACK_X11_XV:
149 case PLAYBACK_X11_GL:
152 case PLAYBACK_DV1394:
153 case PLAYBACK_FIREWIRE:
154 case PLAYBACK_IEC61883:
155 case CAPTURE_FIREWIRE:
156 case CAPTURE_IEC61883:
157 create_firewire_objs();
166 // Update driver dependancies in file format
167 if(mode == MODERECORD && dialog && !creation)
169 RecordPrefs *record_prefs = (RecordPrefs*)dialog;
170 record_prefs->recording_format->update_driver(this->driver);
176 int VDevicePrefs::delete_objects()
179 delete channel_picker;
182 delete dvb_adapter_device;
183 delete follow_video_config;
184 delete dvb_adapter_title;
185 delete use_direct_x11;
189 if(firewire_port) delete firewire_port;
190 if(channel_title) delete channel_title;
191 if(firewire_channel) delete firewire_channel;
192 if(firewire_path) delete firewire_path;
193 if(syt_title) delete syt_title;
194 if(firewire_syt) delete firewire_syt;
195 if(fields_title) delete fields_title;
196 if(device_fields) delete device_fields;
203 int VDevicePrefs::get_h()
205 int margin = pwindow->mwindow->theme->widget_border;
206 return BC_Title::calculate_h(dialog, "X", MEDIUMFONT) + margin +
207 BC_TextBox::calculate_h(dialog, MEDIUMFONT, 1, 1);
210 void VDevicePrefs::create_dvb_objs()
212 int x1 = x + menu->get_w() + xS(30);
214 char *output_char = in_config->dvb_in_adapter;
215 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - yS(5);
216 BC_Resources *resources = BC_WindowBase::get_resources();
217 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
218 MEDIUMFONT, resources->text_default);
219 dialog->add_subwindow(dvb_adapter_title);
220 dvb_adapter_title->context_help_set_keyword("Video Out section");
221 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
222 device_text->context_help_set_keyword("Video Out section");
223 int x2 = x1 + device_text->get_w() + xS(5);
224 device_title = new BC_Title(x2, y2, _("dev:"),
225 MEDIUMFONT, resources->text_default);
226 dialog->add_subwindow(device_title);
227 device_title->context_help_set_keyword("Video Out section");
228 int *output_int = &in_config->dvb_in_device;
229 dvb_adapter_device = new VDeviceTumbleBox(this, x2, y1, output_int, 0, 9, xS(20));
230 dvb_adapter_device->create_objects();
231 x1 += xS(64); y1 += device_text->get_h() + yS(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);
235 follow_video_config->context_help_set_keyword("Video Out section");
238 int VDevicePrefs::create_firewire_objs()
240 int xs5 = xS(5), ys20 = yS(20);
242 char *output_char = 0;
243 int x1 = x + menu->get_w() + xS(5);
244 BC_Resources *resources = BC_WindowBase::get_resources();
250 if(driver == PLAYBACK_DV1394)
251 output_char = out_config->dv1394_path;
253 if(driver == PLAYBACK_FIREWIRE)
254 output_char = out_config->firewire_path;
257 if(driver == CAPTURE_FIREWIRE)
258 output_char = in_config->firewire_path;
264 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
265 device_title->context_help_set_keyword("Video Out section");
266 dialog->add_subwindow(firewire_path = new VDeviceTextBox(x1, y + ys20, output_char));
267 firewire_path->context_help_set_keyword("Video Out section");
268 x1 += firewire_path->get_w() + xs5;
275 if(driver == PLAYBACK_DV1394)
276 output_int = &out_config->dv1394_port;
278 output_int = &out_config->firewire_port;
281 output_int = &in_config->firewire_port;
284 dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, resources->text_default));
285 port_title->context_help_set_keyword("Video Out section");
286 dialog->add_subwindow(firewire_port = new VDeviceIntBox(x1, y + ys20, output_int));
287 firewire_port->context_help_set_keyword("Video Out section");
288 x1 += firewire_port->get_w() + xs5;
294 if(driver == PLAYBACK_DV1394)
295 output_int = &out_config->dv1394_channel;
297 output_int = &out_config->firewire_channel;
300 output_int = &in_config->firewire_channel;
304 dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, resources->text_default));
305 channel_title->context_help_set_keyword("Video Out section");
306 dialog->add_subwindow(firewire_channel = new VDeviceIntBox(x1, y + ys20, output_int));
307 firewire_channel->context_help_set_keyword("Video Out section");
308 x1 += firewire_channel->get_w() + xs5;
315 if(driver == PLAYBACK_DV1394)
316 output_int = &out_config->dv1394_syt;
318 if(driver == PLAYBACK_FIREWIRE)
319 output_int = &out_config->firewire_syt;
329 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, resources->text_default));
330 syt_title->context_help_set_keyword("Video Out section");
331 dialog->add_subwindow(firewire_syt = new VDeviceIntBox(x1, y + ys20, output_int));
332 firewire_syt->context_help_set_keyword("Video Out section");
338 int VDevicePrefs::create_v4l2_objs()
340 int xs5 = xS(5), ys20 = yS(20);
342 BC_Resources *resources = BC_WindowBase::get_resources();
343 int x1 = x + menu->get_w() + xs5;
344 output_char = pwindow->thread->edl->session->vconfig_in->v4l2_in_device;
345 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
346 device_title->context_help_set_keyword("Video Out section");
347 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + ys20, output_char));
348 device_text->context_help_set_keyword("Video Out section");
353 int VDevicePrefs::create_v4l2jpeg_objs()
355 int xs5 = xS(5), ys20 = yS(20);
356 BC_Resources *resources = BC_WindowBase::get_resources();
357 int x1 = x + menu->get_w() + xs5;
358 char *output_char = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_device[0];
359 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
360 device_title->context_help_set_keyword("Video Out section");
361 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + ys20, output_char));
362 device_text->context_help_set_keyword("Video Out section");
363 x1 += bmax(device_title->get_w(),device_text->get_w()) + xs5;
364 int *output_int = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_fields;
365 fields_title = new BC_Title(x1, y, _("Fields:"), MEDIUMFONT, resources->text_default);
366 dialog->add_subwindow(fields_title);
367 fields_title->context_help_set_keyword("Video Out section");
368 device_fields = new VDeviceTumbleBox(this, x1, y + ys20, output_int, 1, 2, xS(20));
369 device_fields->create_objects();
373 int VDevicePrefs::create_v4l2mpeg_objs()
376 BC_Resources *resources = BC_WindowBase::get_resources();
377 int x1 = x + menu->get_w() + xS(5);
378 output_char = pwindow->thread->edl->session->vconfig_in->v4l2mpeg_in_device;
379 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
380 device_title->context_help_set_keyword("Video Out section");
382 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
383 device_text->context_help_set_keyword("Video Out section");
384 x1 += xS(64); y1 += device_text->get_h() + yS(5);
385 follow_video_config = new BC_CheckBox(x1, y1,
386 &in_config->follow_video, _("Follow video config"));
387 dialog->add_subwindow(follow_video_config);
388 follow_video_config->context_help_set_keyword("Video Out section");
393 int VDevicePrefs::create_screencap_objs()
396 BC_Resources *resources = BC_WindowBase::get_resources();
397 int x1 = x + menu->get_w() + xS(5);
398 output_char = pwindow->thread->edl->session->vconfig_in->screencapture_display;
399 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display:"), MEDIUMFONT, resources->text_default));
400 device_title->context_help_set_keyword("Video Out section");
401 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + yS(20), output_char));
402 device_text->context_help_set_keyword("Video Out section");
406 int VDevicePrefs::create_x11_objs()
409 BC_Resources *resources = BC_WindowBase::get_resources();
410 output_char = out_config->x11_host;
411 const char *x11_display;
412 switch( pwindow->thread->current_dialog ) {
414 case PreferencesThread::PLAYBACK_A:
415 x11_display = _("Default A Display:"); break;
417 case PreferencesThread::PLAYBACK_B:
418 x11_display = _("Default B Display:"); break;
421 int x1 = menu->get_x() + menu->get_w() + xS(10);
422 int y1 = menu->get_y();
423 if( driver == PLAYBACK_X11 ) y1 -= yS(10);
424 dialog->add_subwindow(device_title = new BC_Title(x1, y1+yS(4), x11_display,
425 MEDIUMFONT, resources->text_default));
426 device_title->context_help_set_keyword("Video Out section");
427 int x2 = x1 + device_title->get_w() + xS(10), dy = device_title->get_h();
428 dialog->add_subwindow(device_text = new VDeviceTextBox(x2, y1, output_char));
429 device_text->context_help_set_keyword("Video Out section");
430 if( driver == PLAYBACK_X11 ) {
431 int y2 = device_text->get_h();
432 if( dy < y2 ) dy = y2;
434 use_direct_x11 = new BC_CheckBox(x1, y1,
435 &out_config->use_direct_x11, _("use direct x11 render if possible"));
436 dialog->add_subwindow(use_direct_x11);
437 use_direct_x11->context_help_set_keyword("Video Out section");
445 VDriverMenu::VDriverMenu(int x, int y,
446 VDevicePrefs *device_prefs, int do_input, int *output)
447 : BC_PopupMenu(x, y, xS(200), driver_to_string(*output))
449 this->output = output;
450 this->do_input = do_input;
451 this->device_prefs = device_prefs;
454 VDriverMenu::~VDriverMenu()
458 char* VDriverMenu::driver_to_string(int driver)
463 sprintf(string, DEV_UNKNOWN_TITLE);
466 sprintf(string, VIDEO4LINUX2_TITLE);
468 case CAPTURE_JPEG_WEBCAM:
469 sprintf(string, CAPTURE_JPEG_WEBCAM_TITLE);
471 case CAPTURE_YUYV_WEBCAM:
472 sprintf(string, CAPTURE_YUYV_WEBCAM_TITLE);
474 case VIDEO4LINUX2JPEG:
475 sprintf(string, VIDEO4LINUX2JPEG_TITLE);
477 case VIDEO4LINUX2MPEG:
478 sprintf(string, VIDEO4LINUX2MPEG_TITLE);
481 sprintf(string, SCREENCAPTURE_TITLE);
484 case CAPTURE_FIREWIRE:
485 sprintf(string, CAPTURE_FIREWIRE_TITLE);
487 case CAPTURE_IEC61883:
488 sprintf(string, CAPTURE_IEC61883_TITLE);
492 sprintf(string, CAPTURE_DVB_TITLE);
495 sprintf(string, PLAYBACK_X11_TITLE);
497 case PLAYBACK_X11_XV:
498 sprintf(string, PLAYBACK_X11_XV_TITLE);
500 case PLAYBACK_X11_GL:
501 sprintf(string, PLAYBACK_X11_GL_TITLE);
504 case PLAYBACK_FIREWIRE:
505 sprintf(string, PLAYBACK_FIREWIRE_TITLE);
507 case PLAYBACK_DV1394:
508 sprintf(string, PLAYBACK_DV1394_TITLE);
510 case PLAYBACK_IEC61883:
511 sprintf(string, PLAYBACK_IEC61883_TITLE);
520 void VDriverMenu::create_objects()
524 #ifdef HAVE_VIDEO4LINUX2
525 add_item(new VDriverItem(this, VIDEO4LINUX2_TITLE, VIDEO4LINUX2));
526 add_item(new VDriverItem(this, CAPTURE_JPEG_WEBCAM_TITLE, CAPTURE_JPEG_WEBCAM));
527 add_item(new VDriverItem(this, CAPTURE_YUYV_WEBCAM_TITLE, CAPTURE_YUYV_WEBCAM));
528 add_item(new VDriverItem(this, VIDEO4LINUX2JPEG_TITLE, VIDEO4LINUX2JPEG));
529 add_item(new VDriverItem(this, VIDEO4LINUX2MPEG_TITLE, VIDEO4LINUX2MPEG));
532 add_item(new VDriverItem(this, SCREENCAPTURE_TITLE, SCREENCAPTURE));
534 add_item(new VDriverItem(this, CAPTURE_FIREWIRE_TITLE, CAPTURE_FIREWIRE));
535 add_item(new VDriverItem(this, CAPTURE_IEC61883_TITLE, CAPTURE_IEC61883));
538 add_item(new VDriverItem(this, CAPTURE_DVB_TITLE, CAPTURE_DVB));
543 add_item(new VDriverItem(this, PLAYBACK_X11_TITLE, PLAYBACK_X11));
545 add_item(new VDriverItem(this, PLAYBACK_X11_XV_TITLE, PLAYBACK_X11_XV));
548 // Check runtime glx version. pbuffer needs >= 1.3
549 if(get_opengl_server_version() >= 103)
550 add_item(new VDriverItem(this, PLAYBACK_X11_GL_TITLE, PLAYBACK_X11_GL));
553 add_item(new VDriverItem(this, PLAYBACK_FIREWIRE_TITLE, PLAYBACK_FIREWIRE));
554 add_item(new VDriverItem(this, PLAYBACK_DV1394_TITLE, PLAYBACK_DV1394));
555 add_item(new VDriverItem(this, PLAYBACK_IEC61883_TITLE, PLAYBACK_IEC61883));
561 VDriverItem::VDriverItem(VDriverMenu *popup, const char *text, int driver)
565 this->driver = driver;
568 VDriverItem::~VDriverItem()
572 int VDriverItem::handle_event()
574 popup->set_text(get_text());
575 *(popup->output) = driver;
576 popup->device_prefs->initialize(0);
577 popup->device_prefs->pwindow->show_dialog();
584 VDeviceTextBox::VDeviceTextBox(int x, int y, char *output)
585 : BC_TextBox(x, y, xS(200), 1, output)
587 this->output = output;
590 int VDeviceTextBox::handle_event()
593 calculate_suggestions(0);
595 strcpy(output, get_text());
599 VDeviceTumbleBox::VDeviceTumbleBox(VDevicePrefs *prefs,
600 int x, int y, int *output, int min, int max, int text_w)
601 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
603 this->output = output;
606 int VDeviceTumbleBox::handle_event()
608 *output = atol(get_text());
617 VDeviceIntBox::VDeviceIntBox(int x, int y, int *output)
618 : BC_TextBox(x, y, xS(60), 1, *output)
620 this->output = output;
623 int VDeviceIntBox::handle_event()
625 *output = atol(get_text());
633 VDeviceCheckBox::VDeviceCheckBox(int x, int y, int *output, char *text)
634 : BC_CheckBox(x, y, *output, text)
636 this->output = output;
638 int VDeviceCheckBox::handle_event()
640 *output = get_value();
647 VScalingItem::VScalingItem(VScalingEquation *popup, int interpolation)
648 : BC_MenuItem(popup->interpolation_to_string(interpolation))
651 this->interpolation = interpolation;
654 VScalingItem::~VScalingItem()
658 int VScalingItem::handle_event()
660 popup->set_text(get_text());
661 *(popup->output) = interpolation;
666 VScalingEquation::VScalingEquation(int x, int y, int *output)
667 : BC_PopupMenu(x, y, xS(240), interpolation_to_string(*output))
669 this->output = output;
672 VScalingEquation::~VScalingEquation()
676 const char *VScalingEquation::interpolation_to_string(int type)
679 case NEAREST_NEIGHBOR: return _("Nearest Neighbor");
680 case CUBIC_CUBIC: return _("BiCubic / BiCubic");
681 case CUBIC_LINEAR: return _("BiCubic / BiLinear");
682 case LINEAR_LINEAR: return _("BiLinear / BiLinear");
683 case LANCZOS_LANCZOS: return _("Lanczos / Lanczos");
688 void VScalingEquation::create_objects()
690 add_item(new VScalingItem(this, NEAREST_NEIGHBOR));
691 add_item(new VScalingItem(this, CUBIC_CUBIC));
692 add_item(new VScalingItem(this, CUBIC_LINEAR));
693 add_item(new VScalingItem(this, LINEAR_LINEAR));
694 add_item(new VScalingItem(this, LANCZOS_LANCZOS));