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();
133 case CAPTURE_JPEG_WEBCAM:
134 case CAPTURE_YUYV_WEBCAM:
137 case VIDEO4LINUX2JPEG:
138 create_v4l2jpeg_objs();
140 case VIDEO4LINUX2MPEG:
141 create_v4l2mpeg_objs();
144 create_screencap_objs();
147 case PLAYBACK_X11_XV:
148 case PLAYBACK_X11_GL:
151 case PLAYBACK_DV1394:
152 case PLAYBACK_FIREWIRE:
153 case PLAYBACK_IEC61883:
154 case CAPTURE_FIREWIRE:
155 case CAPTURE_IEC61883:
156 create_firewire_objs();
165 // Update driver dependancies in file format
166 if(mode == MODERECORD && dialog && !creation)
168 RecordPrefs *record_prefs = (RecordPrefs*)dialog;
169 record_prefs->recording_format->update_driver(this->driver);
175 int VDevicePrefs::delete_objects()
178 delete channel_picker;
181 delete dvb_adapter_device;
182 delete follow_video_config;
183 delete dvb_adapter_title;
184 delete use_direct_x11;
188 if(firewire_port) delete firewire_port;
189 if(channel_title) delete channel_title;
190 if(firewire_channel) delete firewire_channel;
191 if(firewire_path) delete firewire_path;
192 if(syt_title) delete syt_title;
193 if(firewire_syt) delete firewire_syt;
194 if(fields_title) delete fields_title;
195 if(device_fields) delete device_fields;
202 int VDevicePrefs::get_h()
204 int margin = pwindow->mwindow->theme->widget_border;
205 return BC_Title::calculate_h(dialog, "X", MEDIUMFONT) + margin +
206 BC_TextBox::calculate_h(dialog, MEDIUMFONT, 1, 1);
209 void VDevicePrefs::create_dvb_objs()
211 int x1 = x + menu->get_w() + xS(30);
213 char *output_char = in_config->dvb_in_adapter;
214 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - yS(5);
215 BC_Resources *resources = BC_WindowBase::get_resources();
216 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
217 MEDIUMFONT, resources->text_default);
218 dialog->add_subwindow(dvb_adapter_title);
219 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
220 int x2 = x1 + device_text->get_w() + xS(5);
221 device_title = new BC_Title(x2, y2, _("dev:"),
222 MEDIUMFONT, resources->text_default);
223 dialog->add_subwindow(device_title);
224 int *output_int = &in_config->dvb_in_device;
225 dvb_adapter_device = new VDeviceTumbleBox(this, x2, y1, output_int, 0, 9, xS(20));
226 dvb_adapter_device->create_objects();
227 x1 += xS(64); y1 += device_text->get_h() + yS(5);
228 follow_video_config = new BC_CheckBox(x1, y1,
229 &in_config->follow_video, _("Follow video config"));
230 dialog->add_subwindow(follow_video_config);
233 int VDevicePrefs::create_firewire_objs()
235 int xs5 = xS(5), ys20 = yS(20);
237 char *output_char = 0;
238 int x1 = x + menu->get_w() + xS(5);
239 BC_Resources *resources = BC_WindowBase::get_resources();
245 if(driver == PLAYBACK_DV1394)
246 output_char = out_config->dv1394_path;
248 if(driver == PLAYBACK_FIREWIRE)
249 output_char = out_config->firewire_path;
252 if(driver == CAPTURE_FIREWIRE)
253 output_char = in_config->firewire_path;
259 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
260 dialog->add_subwindow(firewire_path = new VDeviceTextBox(x1, y + ys20, output_char));
261 x1 += firewire_path->get_w() + xs5;
268 if(driver == PLAYBACK_DV1394)
269 output_int = &out_config->dv1394_port;
271 output_int = &out_config->firewire_port;
274 output_int = &in_config->firewire_port;
277 dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, resources->text_default));
278 dialog->add_subwindow(firewire_port = new VDeviceIntBox(x1, y + ys20, output_int));
279 x1 += firewire_port->get_w() + xs5;
285 if(driver == PLAYBACK_DV1394)
286 output_int = &out_config->dv1394_channel;
288 output_int = &out_config->firewire_channel;
291 output_int = &in_config->firewire_channel;
295 dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, resources->text_default));
296 dialog->add_subwindow(firewire_channel = new VDeviceIntBox(x1, y + ys20, output_int));
297 x1 += firewire_channel->get_w() + xs5;
304 if(driver == PLAYBACK_DV1394)
305 output_int = &out_config->dv1394_syt;
307 if(driver == PLAYBACK_FIREWIRE)
308 output_int = &out_config->firewire_syt;
318 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, resources->text_default));
319 dialog->add_subwindow(firewire_syt = new VDeviceIntBox(x1, y + ys20, output_int));
325 int VDevicePrefs::create_v4l2_objs()
327 int xs5 = xS(5), ys20 = yS(20);
329 BC_Resources *resources = BC_WindowBase::get_resources();
330 int x1 = x + menu->get_w() + xs5;
331 output_char = pwindow->thread->edl->session->vconfig_in->v4l2_in_device;
332 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
333 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + ys20, output_char));
338 int VDevicePrefs::create_v4l2jpeg_objs()
340 int xs5 = xS(5), ys20 = yS(20);
341 BC_Resources *resources = BC_WindowBase::get_resources();
342 int x1 = x + menu->get_w() + xs5;
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 + ys20, output_char));
346 x1 += bmax(device_title->get_w(),device_text->get_w()) + xs5;
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 + ys20, output_int, 1, 2, xS(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() + xS(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 += xS(64); y1 += device_text->get_h() + yS(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() + xS(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 + yS(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() + xS(10);
399 int y1 = menu->get_y();
400 if( driver == PLAYBACK_X11 ) y1 -= yS(10);
401 dialog->add_subwindow(device_title = new BC_Title(x1, y1+yS(4), x11_display,
402 MEDIUMFONT, resources->text_default));
403 int x2 = x1 + device_title->get_w() + xS(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, int y,
420 VDevicePrefs *device_prefs, int do_input, int *output)
421 : BC_PopupMenu(x, y, xS(200), driver_to_string(*output))
423 this->output = output;
424 this->do_input = do_input;
425 this->device_prefs = device_prefs;
428 VDriverMenu::~VDriverMenu()
432 char* VDriverMenu::driver_to_string(int driver)
437 sprintf(string, DEV_UNKNOWN_TITLE);
440 sprintf(string, VIDEO4LINUX2_TITLE);
442 case CAPTURE_JPEG_WEBCAM:
443 sprintf(string, CAPTURE_JPEG_WEBCAM_TITLE);
445 case CAPTURE_YUYV_WEBCAM:
446 sprintf(string, CAPTURE_YUYV_WEBCAM_TITLE);
448 case VIDEO4LINUX2JPEG:
449 sprintf(string, VIDEO4LINUX2JPEG_TITLE);
451 case VIDEO4LINUX2MPEG:
452 sprintf(string, VIDEO4LINUX2MPEG_TITLE);
455 sprintf(string, SCREENCAPTURE_TITLE);
458 case CAPTURE_FIREWIRE:
459 sprintf(string, CAPTURE_FIREWIRE_TITLE);
461 case CAPTURE_IEC61883:
462 sprintf(string, CAPTURE_IEC61883_TITLE);
466 sprintf(string, CAPTURE_DVB_TITLE);
469 sprintf(string, PLAYBACK_X11_TITLE);
471 case PLAYBACK_X11_XV:
472 sprintf(string, PLAYBACK_X11_XV_TITLE);
474 case PLAYBACK_X11_GL:
475 sprintf(string, PLAYBACK_X11_GL_TITLE);
478 case PLAYBACK_FIREWIRE:
479 sprintf(string, PLAYBACK_FIREWIRE_TITLE);
481 case PLAYBACK_DV1394:
482 sprintf(string, PLAYBACK_DV1394_TITLE);
484 case PLAYBACK_IEC61883:
485 sprintf(string, PLAYBACK_IEC61883_TITLE);
494 void VDriverMenu::create_objects()
498 #ifdef HAVE_VIDEO4LINUX2
499 add_item(new VDriverItem(this, VIDEO4LINUX2_TITLE, VIDEO4LINUX2));
500 add_item(new VDriverItem(this, CAPTURE_JPEG_WEBCAM_TITLE, CAPTURE_JPEG_WEBCAM));
501 add_item(new VDriverItem(this, CAPTURE_YUYV_WEBCAM_TITLE, CAPTURE_YUYV_WEBCAM));
502 add_item(new VDriverItem(this, VIDEO4LINUX2JPEG_TITLE, VIDEO4LINUX2JPEG));
503 add_item(new VDriverItem(this, VIDEO4LINUX2MPEG_TITLE, VIDEO4LINUX2MPEG));
506 add_item(new VDriverItem(this, SCREENCAPTURE_TITLE, SCREENCAPTURE));
508 add_item(new VDriverItem(this, CAPTURE_FIREWIRE_TITLE, CAPTURE_FIREWIRE));
509 add_item(new VDriverItem(this, CAPTURE_IEC61883_TITLE, CAPTURE_IEC61883));
512 add_item(new VDriverItem(this, CAPTURE_DVB_TITLE, CAPTURE_DVB));
517 add_item(new VDriverItem(this, PLAYBACK_X11_TITLE, PLAYBACK_X11));
519 add_item(new VDriverItem(this, PLAYBACK_X11_XV_TITLE, PLAYBACK_X11_XV));
522 // Check runtime glx version. pbuffer needs >= 1.3
523 if(get_opengl_server_version() >= 103)
524 add_item(new VDriverItem(this, PLAYBACK_X11_GL_TITLE, PLAYBACK_X11_GL));
527 add_item(new VDriverItem(this, PLAYBACK_FIREWIRE_TITLE, PLAYBACK_FIREWIRE));
528 add_item(new VDriverItem(this, PLAYBACK_DV1394_TITLE, PLAYBACK_DV1394));
529 add_item(new VDriverItem(this, PLAYBACK_IEC61883_TITLE, PLAYBACK_IEC61883));
535 VDriverItem::VDriverItem(VDriverMenu *popup, const char *text, int driver)
539 this->driver = driver;
542 VDriverItem::~VDriverItem()
546 int VDriverItem::handle_event()
548 popup->set_text(get_text());
549 *(popup->output) = driver;
550 popup->device_prefs->initialize(0);
551 popup->device_prefs->pwindow->show_dialog();
558 VDeviceTextBox::VDeviceTextBox(int x, int y, char *output)
559 : BC_TextBox(x, y, xS(200), 1, output)
561 this->output = output;
564 int VDeviceTextBox::handle_event()
567 calculate_suggestions(0);
569 strcpy(output, get_text());
573 VDeviceTumbleBox::VDeviceTumbleBox(VDevicePrefs *prefs,
574 int x, int y, int *output, int min, int max, int text_w)
575 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
577 this->output = output;
580 int VDeviceTumbleBox::handle_event()
582 *output = atol(get_text());
591 VDeviceIntBox::VDeviceIntBox(int x, int y, int *output)
592 : BC_TextBox(x, y, xS(60), 1, *output)
594 this->output = output;
597 int VDeviceIntBox::handle_event()
599 *output = atol(get_text());
607 VDeviceCheckBox::VDeviceCheckBox(int x, int y, int *output, char *text)
608 : BC_CheckBox(x, y, *output, text)
610 this->output = output;
612 int VDeviceCheckBox::handle_event()
614 *output = get_value();
621 VScalingItem::VScalingItem(VScalingEquation *popup, int interpolation)
622 : BC_MenuItem(popup->interpolation_to_string(interpolation))
625 this->interpolation = interpolation;
628 VScalingItem::~VScalingItem()
632 int VScalingItem::handle_event()
634 popup->set_text(get_text());
635 *(popup->output) = interpolation;
640 VScalingEquation::VScalingEquation(int x, int y, int *output)
641 : BC_PopupMenu(x, y, xS(240), interpolation_to_string(*output))
643 this->output = output;
646 VScalingEquation::~VScalingEquation()
650 const char *VScalingEquation::interpolation_to_string(int type)
653 case NEAREST_NEIGHBOR: return _("Nearest Neighbor");
654 case CUBIC_CUBIC: return _("BiCubic / BiCubic");
655 case CUBIC_LINEAR: return _("BiCubic / BiLinear");
656 case LINEAR_LINEAR: return _("BiLinear / BiLinear");
657 case LANCZOS_LANCZOS: return _("Lanczos / Lanczos");
662 void VScalingEquation::create_objects()
664 add_item(new VScalingItem(this, NEAREST_NEIGHBOR));
665 add_item(new VScalingItem(this, CUBIC_CUBIC));
666 add_item(new VScalingItem(this, CUBIC_LINEAR));
667 add_item(new VScalingItem(this, LINEAR_LINEAR));
668 add_item(new VScalingItem(this, LANCZOS_LANCZOS));