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;
53 this->driver = DEV_UNKNOWN;
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);
78 void VDevicePrefs::reset_objects()
82 follow_video_config = 0;
83 dvb_adapter_title = 0;
84 dvb_adapter_device = 0;
92 firewire_channels = 0;
101 int VDevicePrefs::initialize(int creation)
109 driver = &out_config->driver;
113 driver = &in_config->driver;
116 this->driver = *driver;
120 dialog->add_subwindow(menu = new VDriverMenu(x,
123 (mode == MODERECORD),
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;
187 if(firewire_port) delete firewire_port;
188 if(channel_title) delete channel_title;
189 if(firewire_channel) delete firewire_channel;
190 if(firewire_path) delete firewire_path;
191 if(syt_title) delete syt_title;
192 if(firewire_syt) delete firewire_syt;
193 if(fields_title) delete fields_title;
194 if(device_fields) delete device_fields;
201 void VDevicePrefs::create_dvb_objs()
203 int x1 = x + menu->get_w() + 30;
205 char *output_char = in_config->dvb_in_adapter;
206 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - 5;
207 BC_Resources *resources = BC_WindowBase::get_resources();
208 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
209 MEDIUMFONT, resources->text_default);
210 dialog->add_subwindow(dvb_adapter_title);
211 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
212 int x2 = x1 + device_text->get_w() + 5;
213 device_title = new BC_Title(x2, y2, _("dev:"),
214 MEDIUMFONT, resources->text_default);
215 dialog->add_subwindow(device_title);
216 int *output_int = &in_config->dvb_in_device;
217 dvb_adapter_device = new VDeviceTumbleBox(this, x2, y1, output_int, 0, 9, 20);
218 dvb_adapter_device->create_objects();
219 x1 += 64; y1 += device_text->get_h() + 5;
220 follow_video_config = new BC_CheckBox(x1, y1,
221 &in_config->follow_video, _("Follow video config"));
222 dialog->add_subwindow(follow_video_config);
225 int VDevicePrefs::create_firewire_objs()
228 char *output_char = 0;
229 int x1 = x + menu->get_w() + 5;
230 BC_Resources *resources = BC_WindowBase::get_resources();
236 if(driver == PLAYBACK_DV1394)
237 output_char = out_config->dv1394_path;
239 if(driver == PLAYBACK_FIREWIRE)
240 output_char = out_config->firewire_path;
243 if(driver == CAPTURE_FIREWIRE)
244 output_char = in_config->firewire_path;
250 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
251 dialog->add_subwindow(firewire_path = new VDeviceTextBox(x1, y + 20, output_char));
252 x1 += firewire_path->get_w() + 5;
259 if(driver == PLAYBACK_DV1394)
260 output_int = &out_config->dv1394_port;
262 output_int = &out_config->firewire_port;
265 output_int = &in_config->firewire_port;
268 dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, resources->text_default));
269 dialog->add_subwindow(firewire_port = new VDeviceIntBox(x1, y + 20, output_int));
270 x1 += firewire_port->get_w() + 5;
276 if(driver == PLAYBACK_DV1394)
277 output_int = &out_config->dv1394_channel;
279 output_int = &out_config->firewire_channel;
282 output_int = &in_config->firewire_channel;
286 dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, resources->text_default));
287 dialog->add_subwindow(firewire_channel = new VDeviceIntBox(x1, y + 20, output_int));
288 x1 += firewire_channel->get_w() + 5;
295 if(driver == PLAYBACK_DV1394)
296 output_int = &out_config->dv1394_syt;
298 if(driver == PLAYBACK_FIREWIRE)
299 output_int = &out_config->firewire_syt;
309 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, resources->text_default));
310 dialog->add_subwindow(firewire_syt = new VDeviceIntBox(x1, y + 20, output_int));
316 int VDevicePrefs::create_v4l2_objs()
319 BC_Resources *resources = BC_WindowBase::get_resources();
320 int x1 = x + menu->get_w() + 5;
321 output_char = pwindow->thread->edl->session->vconfig_in->v4l2_in_device;
322 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
323 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
328 int VDevicePrefs::create_v4l2jpeg_objs()
330 BC_Resources *resources = BC_WindowBase::get_resources();
331 int x1 = x + menu->get_w() + 5;
332 char *output_char = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_device[0];
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));
335 x1 += max(device_title->get_w(),device_text->get_w()) + 5;
336 int *output_int = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_fields;
337 fields_title = new BC_Title(x1, y, _("Fields:"), MEDIUMFONT, resources->text_default);
338 dialog->add_subwindow(fields_title);
339 device_fields = new VDeviceTumbleBox(this, x1, y + 20, output_int, 1, 2, 20);
340 device_fields->create_objects();
344 int VDevicePrefs::create_v4l2mpeg_objs()
347 BC_Resources *resources = BC_WindowBase::get_resources();
348 int x1 = x + menu->get_w() + 5;
349 output_char = pwindow->thread->edl->session->vconfig_in->v4l2mpeg_in_device;
350 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
352 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
353 x1 += 64; y1 += device_text->get_h() + 5;
354 follow_video_config = new BC_CheckBox(x1, y1,
355 &in_config->follow_video, _("Follow video config"));
356 dialog->add_subwindow(follow_video_config);
361 int VDevicePrefs::create_screencap_objs()
364 BC_Resources *resources = BC_WindowBase::get_resources();
365 int x1 = x + menu->get_w() + 5;
366 output_char = pwindow->thread->edl->session->vconfig_in->screencapture_display;
367 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display:"), MEDIUMFONT, resources->text_default));
368 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
372 int VDevicePrefs::create_x11_objs()
375 BC_Resources *resources = BC_WindowBase::get_resources();
376 int x1 = x + menu->get_w() + 5;
377 output_char = out_config->x11_host;
378 const char *x11_display;
379 switch( pwindow->thread->current_dialog ) {
381 case PreferencesThread::PLAYBACK_A:
382 x11_display = _("Default A Display:"); break;
384 case PreferencesThread::PLAYBACK_B:
385 x11_display = _("Default B Display:"); break;
388 dialog->add_subwindow(device_title = new BC_Title(x1, y, x11_display,
389 MEDIUMFONT, resources->text_default));
390 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
397 VDriverMenu::VDriverMenu(int x,
399 VDevicePrefs *device_prefs,
402 : BC_PopupMenu(x, y, 200, driver_to_string(*output))
404 this->output = output;
405 this->do_input = do_input;
406 this->device_prefs = device_prefs;
409 VDriverMenu::~VDriverMenu()
413 char* VDriverMenu::driver_to_string(int driver)
418 sprintf(string, DEV_UNKNOWN_TITLE);
421 sprintf(string, VIDEO4LINUX2_TITLE);
423 case CAPTURE_JPEG_WEBCAM:
424 sprintf(string, CAPTURE_JPEG_WEBCAM_TITLE);
426 case CAPTURE_YUYV_WEBCAM:
427 sprintf(string, CAPTURE_YUYV_WEBCAM_TITLE);
429 case VIDEO4LINUX2JPEG:
430 sprintf(string, VIDEO4LINUX2JPEG_TITLE);
432 case VIDEO4LINUX2MPEG:
433 sprintf(string, VIDEO4LINUX2MPEG_TITLE);
436 sprintf(string, SCREENCAPTURE_TITLE);
439 case CAPTURE_FIREWIRE:
440 sprintf(string, CAPTURE_FIREWIRE_TITLE);
442 case CAPTURE_IEC61883:
443 sprintf(string, CAPTURE_IEC61883_TITLE);
447 sprintf(string, CAPTURE_DVB_TITLE);
450 sprintf(string, PLAYBACK_X11_TITLE);
452 case PLAYBACK_X11_XV:
453 sprintf(string, PLAYBACK_X11_XV_TITLE);
455 case PLAYBACK_X11_GL:
456 sprintf(string, PLAYBACK_X11_GL_TITLE);
459 case PLAYBACK_FIREWIRE:
460 sprintf(string, PLAYBACK_FIREWIRE_TITLE);
462 case PLAYBACK_DV1394:
463 sprintf(string, PLAYBACK_DV1394_TITLE);
465 case PLAYBACK_IEC61883:
466 sprintf(string, PLAYBACK_IEC61883_TITLE);
475 void VDriverMenu::create_objects()
479 #ifdef HAVE_VIDEO4LINUX2
480 add_item(new VDriverItem(this, VIDEO4LINUX2_TITLE, VIDEO4LINUX2));
481 add_item(new VDriverItem(this, CAPTURE_JPEG_WEBCAM_TITLE, CAPTURE_JPEG_WEBCAM));
482 add_item(new VDriverItem(this, CAPTURE_YUYV_WEBCAM_TITLE, CAPTURE_YUYV_WEBCAM));
483 add_item(new VDriverItem(this, VIDEO4LINUX2JPEG_TITLE, VIDEO4LINUX2JPEG));
484 add_item(new VDriverItem(this, VIDEO4LINUX2MPEG_TITLE, VIDEO4LINUX2MPEG));
487 add_item(new VDriverItem(this, SCREENCAPTURE_TITLE, SCREENCAPTURE));
489 add_item(new VDriverItem(this, CAPTURE_FIREWIRE_TITLE, CAPTURE_FIREWIRE));
490 add_item(new VDriverItem(this, CAPTURE_IEC61883_TITLE, CAPTURE_IEC61883));
493 add_item(new VDriverItem(this, CAPTURE_DVB_TITLE, CAPTURE_DVB));
498 add_item(new VDriverItem(this, PLAYBACK_X11_TITLE, PLAYBACK_X11));
499 add_item(new VDriverItem(this, PLAYBACK_X11_XV_TITLE, PLAYBACK_X11_XV));
501 // Check runtime glx version. pbuffer needs >= 1.3
502 if(get_opengl_server_version() >= 103)
503 add_item(new VDriverItem(this, PLAYBACK_X11_GL_TITLE, PLAYBACK_X11_GL));
506 add_item(new VDriverItem(this, PLAYBACK_FIREWIRE_TITLE, PLAYBACK_FIREWIRE));
507 add_item(new VDriverItem(this, PLAYBACK_DV1394_TITLE, PLAYBACK_DV1394));
508 add_item(new VDriverItem(this, PLAYBACK_IEC61883_TITLE, PLAYBACK_IEC61883));
514 VDriverItem::VDriverItem(VDriverMenu *popup, const char *text, int driver)
518 this->driver = driver;
521 VDriverItem::~VDriverItem()
525 int VDriverItem::handle_event()
527 popup->set_text(get_text());
528 *(popup->output) = driver;
529 popup->device_prefs->initialize(0);
530 popup->device_prefs->pwindow->show_dialog();
537 VDeviceTextBox::VDeviceTextBox(int x, int y, char *output)
538 : BC_TextBox(x, y, 200, 1, output)
540 this->output = output;
543 int VDeviceTextBox::handle_event()
546 calculate_suggestions(0);
548 strcpy(output, get_text());
552 VDeviceTumbleBox::VDeviceTumbleBox(VDevicePrefs *prefs,
553 int x, int y, int *output, int min, int max, int text_w)
554 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
556 this->output = output;
559 int VDeviceTumbleBox::handle_event()
561 *output = atol(get_text());
570 VDeviceIntBox::VDeviceIntBox(int x, int y, int *output)
571 : BC_TextBox(x, y, 60, 1, *output)
573 this->output = output;
576 int VDeviceIntBox::handle_event()
578 *output = atol(get_text());
586 VDeviceCheckBox::VDeviceCheckBox(int x, int y, int *output, char *text)
587 : BC_CheckBox(x, y, *output, text)
589 this->output = output;
591 int VDeviceCheckBox::handle_event()
593 *output = get_value();
600 VScalingItem::VScalingItem(VScalingEquation *popup, int interpolation)
601 : BC_MenuItem(popup->interpolation_to_string(interpolation))
604 this->interpolation = interpolation;
607 VScalingItem::~VScalingItem()
611 int VScalingItem::handle_event()
613 popup->set_text(get_text());
614 *(popup->output) = interpolation;
619 VScalingEquation::VScalingEquation(int x, int y, int *output)
620 : BC_PopupMenu(x, y, 175, interpolation_to_string(*output))
622 this->output = output;
625 VScalingEquation::~VScalingEquation()
629 const char *VScalingEquation::interpolation_to_string(int type)
632 case NEAREST_NEIGHBOR: return _("Nearest Neighbor");
633 case CUBIC_CUBIC: return _("BiCubic / BiCubic");
634 case CUBIC_LINEAR: return _("BiCubic / BiLinear");
635 case LINEAR_LINEAR: return _("BiLinear / BiLinear");
636 case LANCZOS_LANCZOS: return _("Lanczos / Lanczos");
641 void VScalingEquation::create_objects()
643 add_item(new VScalingItem(this, NEAREST_NEIGHBOR));
644 add_item(new VScalingItem(this, CUBIC_CUBIC));
645 add_item(new VScalingItem(this, CUBIC_LINEAR));
646 add_item(new VScalingItem(this, LINEAR_LINEAR));
647 add_item(new VScalingItem(this, LANCZOS_LANCZOS));