4 * Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "bcsignals.h"
24 #include "channeldb.h"
25 #include "channelpicker.h"
28 #include "edlsession.h"
29 #include "formattools.h"
32 #include "mainsession.h"
33 #include "vdeviceprefs.h"
34 #include "videoconfig.h"
35 #include "videodevice.inc"
36 #include "overlayframe.inc"
37 #include "playbackconfig.h"
38 #include "preferences.h"
39 #include "preferencesthread.h"
40 #include "recordconfig.h"
41 #include "recordprefs.h"
46 VDevicePrefs::VDevicePrefs(int x,
48 PreferencesWindow *pwindow,
49 PreferencesDialog *dialog,
50 VideoOutConfig *out_config,
51 VideoInConfig *in_config,
54 this->pwindow = pwindow;
55 this->dialog = dialog;
56 this->driver = DEV_UNKNOWN;
58 this->out_config = out_config;
59 this->in_config = in_config;
67 VDevicePrefs::~VDevicePrefs()
72 switch( pwindow->thread->current_dialog ) {
73 case PreferencesThread::PLAYBACK_A: config = 0; break;
74 case PreferencesThread::PLAYBACK_B: config = 1; break;
77 pwindow->mwindow->session->save_x11_host(config, out_config->x11_host);
81 void VDevicePrefs::reset_objects()
85 follow_video_config = 0;
86 dvb_adapter_title = 0;
87 dvb_adapter_device = 0;
95 firewire_channels = 0;
105 int VDevicePrefs::initialize(int creation)
113 driver = &out_config->driver;
117 driver = &in_config->driver;
120 this->driver = *driver;
124 dialog->add_subwindow(menu = new VDriverMenu(x, y + yS(10),
125 this, (mode == MODERECORD), driver));
126 menu->create_objects();
127 menu->context_help_set_keyword("Video Out section");
135 case CAPTURE_JPEG_WEBCAM:
136 case CAPTURE_YUYV_WEBCAM:
139 case VIDEO4LINUX2JPEG:
140 create_v4l2jpeg_objs();
142 case VIDEO4LINUX2MPEG:
143 create_v4l2mpeg_objs();
146 create_screencap_objs();
149 case PLAYBACK_X11_XV:
150 case PLAYBACK_X11_GL:
153 case PLAYBACK_DV1394:
154 case PLAYBACK_FIREWIRE:
155 case PLAYBACK_IEC61883:
156 case CAPTURE_FIREWIRE:
157 case CAPTURE_IEC61883:
158 create_firewire_objs();
167 // Update driver dependancies in file format
168 if(mode == MODERECORD && dialog && !creation)
170 RecordPrefs *record_prefs = (RecordPrefs*)dialog;
171 record_prefs->recording_format->update_driver(this->driver);
177 int VDevicePrefs::delete_objects()
180 delete channel_picker;
183 delete dvb_adapter_device;
184 delete follow_video_config;
185 delete dvb_adapter_title;
186 delete use_direct_x11;
190 if(firewire_port) delete firewire_port;
191 if(channel_title) delete channel_title;
192 if(firewire_channel) delete firewire_channel;
193 if(firewire_path) delete firewire_path;
194 if(syt_title) delete syt_title;
195 if(firewire_syt) delete firewire_syt;
196 if(fields_title) delete fields_title;
197 if(device_fields) delete device_fields;
204 int VDevicePrefs::get_h()
206 int margin = pwindow->mwindow->theme->widget_border;
207 return BC_Title::calculate_h(dialog, "X", MEDIUMFONT) + margin +
208 BC_TextBox::calculate_h(dialog, MEDIUMFONT, 1, 1);
211 void VDevicePrefs::create_dvb_objs()
213 int x1 = x + menu->get_w() + xS(30);
215 char *output_char = in_config->dvb_in_adapter;
216 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - yS(5);
217 BC_Resources *resources = BC_WindowBase::get_resources();
218 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
219 MEDIUMFONT, resources->text_default);
220 dialog->add_subwindow(dvb_adapter_title);
221 dvb_adapter_title->context_help_set_keyword("Video Out section");
222 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
223 device_text->context_help_set_keyword("Video Out section");
224 int x2 = x1 + device_text->get_w() + xS(5);
225 device_title = new BC_Title(x2, y2, _("dev:"),
226 MEDIUMFONT, resources->text_default);
227 dialog->add_subwindow(device_title);
228 device_title->context_help_set_keyword("Video Out section");
229 int *output_int = &in_config->dvb_in_device;
230 dvb_adapter_device = new VDeviceTumbleBox(this, x2, y1, output_int, 0, 9, xS(20));
231 dvb_adapter_device->create_objects();
232 x1 += xS(64); y1 += device_text->get_h() + yS(5);
233 follow_video_config = new BC_CheckBox(x1, y1,
234 &in_config->follow_video, _("Follow video config"));
235 dialog->add_subwindow(follow_video_config);
236 follow_video_config->context_help_set_keyword("Video Out section");
239 int VDevicePrefs::create_firewire_objs()
241 int xs5 = xS(5), ys20 = yS(20);
243 char *output_char = 0;
244 int x1 = x + menu->get_w() + xS(5);
245 BC_Resources *resources = BC_WindowBase::get_resources();
251 if(driver == PLAYBACK_DV1394)
252 output_char = out_config->dv1394_path;
254 if(driver == PLAYBACK_FIREWIRE)
255 output_char = out_config->firewire_path;
258 if(driver == CAPTURE_FIREWIRE)
259 output_char = in_config->firewire_path;
265 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
266 device_title->context_help_set_keyword("Video Out section");
267 dialog->add_subwindow(firewire_path = new VDeviceTextBox(x1, y + ys20, output_char));
268 firewire_path->context_help_set_keyword("Video Out section");
269 x1 += firewire_path->get_w() + xs5;
276 if(driver == PLAYBACK_DV1394)
277 output_int = &out_config->dv1394_port;
279 output_int = &out_config->firewire_port;
282 output_int = &in_config->firewire_port;
285 dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, resources->text_default));
286 port_title->context_help_set_keyword("Video Out section");
287 dialog->add_subwindow(firewire_port = new VDeviceIntBox(x1, y + ys20, output_int));
288 firewire_port->context_help_set_keyword("Video Out section");
289 x1 += firewire_port->get_w() + xs5;
295 if(driver == PLAYBACK_DV1394)
296 output_int = &out_config->dv1394_channel;
298 output_int = &out_config->firewire_channel;
301 output_int = &in_config->firewire_channel;
305 dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, resources->text_default));
306 channel_title->context_help_set_keyword("Video Out section");
307 dialog->add_subwindow(firewire_channel = new VDeviceIntBox(x1, y + ys20, output_int));
308 firewire_channel->context_help_set_keyword("Video Out section");
309 x1 += firewire_channel->get_w() + xs5;
316 if(driver == PLAYBACK_DV1394)
317 output_int = &out_config->dv1394_syt;
319 if(driver == PLAYBACK_FIREWIRE)
320 output_int = &out_config->firewire_syt;
330 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, resources->text_default));
331 syt_title->context_help_set_keyword("Video Out section");
332 dialog->add_subwindow(firewire_syt = new VDeviceIntBox(x1, y + ys20, output_int));
333 firewire_syt->context_help_set_keyword("Video Out section");
339 int VDevicePrefs::create_v4l2_objs()
341 int xs5 = xS(5), ys20 = yS(20);
343 BC_Resources *resources = BC_WindowBase::get_resources();
344 int x1 = x + menu->get_w() + xs5;
345 output_char = pwindow->thread->edl->session->vconfig_in->v4l2_in_device;
346 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
347 device_title->context_help_set_keyword("Video Out section");
348 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + ys20, output_char));
349 device_text->context_help_set_keyword("Video Out section");
354 int VDevicePrefs::create_v4l2jpeg_objs()
356 int xs5 = xS(5), ys20 = yS(20);
357 BC_Resources *resources = BC_WindowBase::get_resources();
358 int x1 = x + menu->get_w() + xs5;
359 char *output_char = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_device[0];
360 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
361 device_title->context_help_set_keyword("Video Out section");
362 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + ys20, output_char));
363 device_text->context_help_set_keyword("Video Out section");
364 x1 += bmax(device_title->get_w(),device_text->get_w()) + xs5;
365 int *output_int = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_fields;
366 fields_title = new BC_Title(x1, y, _("Fields:"), MEDIUMFONT, resources->text_default);
367 dialog->add_subwindow(fields_title);
368 fields_title->context_help_set_keyword("Video Out section");
369 device_fields = new VDeviceTumbleBox(this, x1, y + ys20, output_int, 1, 2, xS(20));
370 device_fields->create_objects();
374 int VDevicePrefs::create_v4l2mpeg_objs()
377 BC_Resources *resources = BC_WindowBase::get_resources();
378 int x1 = x + menu->get_w() + xS(5);
379 output_char = pwindow->thread->edl->session->vconfig_in->v4l2mpeg_in_device;
380 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
381 device_title->context_help_set_keyword("Video Out section");
383 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
384 device_text->context_help_set_keyword("Video Out section");
385 x1 += xS(64); y1 += device_text->get_h() + yS(5);
386 follow_video_config = new BC_CheckBox(x1, y1,
387 &in_config->follow_video, _("Follow video config"));
388 dialog->add_subwindow(follow_video_config);
389 follow_video_config->context_help_set_keyword("Video Out section");
394 int VDevicePrefs::create_screencap_objs()
397 BC_Resources *resources = BC_WindowBase::get_resources();
398 int x1 = x + menu->get_w() + xS(5);
399 output_char = pwindow->thread->edl->session->vconfig_in->screencapture_display;
400 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display:"), MEDIUMFONT, resources->text_default));
401 device_title->context_help_set_keyword("Video Out section");
402 dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + yS(20), output_char));
403 device_text->context_help_set_keyword("Video Out section");
407 int VDevicePrefs::create_x11_objs()
410 BC_Resources *resources = BC_WindowBase::get_resources();
411 output_char = out_config->x11_host;
412 const char *x11_display;
413 switch( pwindow->thread->current_dialog ) {
415 case PreferencesThread::PLAYBACK_A:
416 x11_display = _("Default A Display:"); break;
418 case PreferencesThread::PLAYBACK_B:
419 x11_display = _("Default B Display:"); break;
422 int x1 = menu->get_x() + menu->get_w() + xS(10);
423 int y1 = menu->get_y();
424 if( driver == PLAYBACK_X11 ) y1 -= yS(10);
425 dialog->add_subwindow(device_title = new BC_Title(x1, y1+yS(4), x11_display,
426 MEDIUMFONT, resources->text_default));
427 device_title->context_help_set_keyword("Video Out section");
428 int x2 = x1 + device_title->get_w() + xS(10), dy = device_title->get_h();
429 dialog->add_subwindow(device_text = new VDeviceTextBox(x2, y1, output_char));
430 device_text->context_help_set_keyword("Video Out section");
431 if( driver == PLAYBACK_X11 ) {
432 int y2 = device_text->get_h();
433 if( dy < y2 ) dy = y2;
435 use_direct_x11 = new BC_CheckBox(x1, y1,
436 &out_config->use_direct_x11, _("use direct x11 render if possible"));
437 dialog->add_subwindow(use_direct_x11);
438 use_direct_x11->context_help_set_keyword("Video Out section");
446 VDriverMenu::VDriverMenu(int x, int y,
447 VDevicePrefs *device_prefs, int do_input, int *output)
448 : BC_PopupMenu(x, y, xS(200), driver_to_string(*output))
450 this->output = output;
451 this->do_input = do_input;
452 this->device_prefs = device_prefs;
455 VDriverMenu::~VDriverMenu()
459 char* VDriverMenu::driver_to_string(int driver)
464 sprintf(string, DEV_UNKNOWN_TITLE);
467 sprintf(string, VIDEO4LINUX2_TITLE);
469 case CAPTURE_JPEG_WEBCAM:
470 sprintf(string, CAPTURE_JPEG_WEBCAM_TITLE);
472 case CAPTURE_YUYV_WEBCAM:
473 sprintf(string, CAPTURE_YUYV_WEBCAM_TITLE);
475 case VIDEO4LINUX2JPEG:
476 sprintf(string, VIDEO4LINUX2JPEG_TITLE);
478 case VIDEO4LINUX2MPEG:
479 sprintf(string, VIDEO4LINUX2MPEG_TITLE);
482 sprintf(string, SCREENCAPTURE_TITLE);
485 case CAPTURE_FIREWIRE:
486 sprintf(string, CAPTURE_FIREWIRE_TITLE);
488 case CAPTURE_IEC61883:
489 sprintf(string, CAPTURE_IEC61883_TITLE);
493 sprintf(string, CAPTURE_DVB_TITLE);
496 sprintf(string, PLAYBACK_X11_TITLE);
498 case PLAYBACK_X11_XV:
499 sprintf(string, PLAYBACK_X11_XV_TITLE);
501 case PLAYBACK_X11_GL:
502 sprintf(string, PLAYBACK_X11_GL_TITLE);
505 case PLAYBACK_FIREWIRE:
506 sprintf(string, PLAYBACK_FIREWIRE_TITLE);
508 case PLAYBACK_DV1394:
509 sprintf(string, PLAYBACK_DV1394_TITLE);
511 case PLAYBACK_IEC61883:
512 sprintf(string, PLAYBACK_IEC61883_TITLE);
521 void VDriverMenu::create_objects()
525 #ifdef HAVE_VIDEO4LINUX2
526 add_item(new VDriverItem(this, VIDEO4LINUX2_TITLE, VIDEO4LINUX2));
527 add_item(new VDriverItem(this, CAPTURE_JPEG_WEBCAM_TITLE, CAPTURE_JPEG_WEBCAM));
528 add_item(new VDriverItem(this, CAPTURE_YUYV_WEBCAM_TITLE, CAPTURE_YUYV_WEBCAM));
529 add_item(new VDriverItem(this, VIDEO4LINUX2JPEG_TITLE, VIDEO4LINUX2JPEG));
530 add_item(new VDriverItem(this, VIDEO4LINUX2MPEG_TITLE, VIDEO4LINUX2MPEG));
533 add_item(new VDriverItem(this, SCREENCAPTURE_TITLE, SCREENCAPTURE));
535 add_item(new VDriverItem(this, CAPTURE_FIREWIRE_TITLE, CAPTURE_FIREWIRE));
536 add_item(new VDriverItem(this, CAPTURE_IEC61883_TITLE, CAPTURE_IEC61883));
539 add_item(new VDriverItem(this, CAPTURE_DVB_TITLE, CAPTURE_DVB));
544 add_item(new VDriverItem(this, PLAYBACK_X11_TITLE, PLAYBACK_X11));
546 add_item(new VDriverItem(this, PLAYBACK_X11_XV_TITLE, PLAYBACK_X11_XV));
549 // Check runtime glx version. pbuffer needs >= 1.3
550 if(get_opengl_server_version() >= 103)
551 add_item(new VDriverItem(this, PLAYBACK_X11_GL_TITLE, PLAYBACK_X11_GL));
554 add_item(new VDriverItem(this, PLAYBACK_FIREWIRE_TITLE, PLAYBACK_FIREWIRE));
555 add_item(new VDriverItem(this, PLAYBACK_DV1394_TITLE, PLAYBACK_DV1394));
556 add_item(new VDriverItem(this, PLAYBACK_IEC61883_TITLE, PLAYBACK_IEC61883));
562 VDriverItem::VDriverItem(VDriverMenu *popup, const char *text, int driver)
566 this->driver = driver;
569 VDriverItem::~VDriverItem()
573 int VDriverItem::handle_event()
575 popup->set_text(get_text());
576 *(popup->output) = driver;
577 popup->device_prefs->initialize(0);
578 popup->device_prefs->pwindow->show_dialog();
585 VDeviceTextBox::VDeviceTextBox(int x, int y, char *output)
586 : BC_TextBox(x, y, xS(200), 1, output)
588 this->output = output;
591 int VDeviceTextBox::handle_event()
594 calculate_suggestions(0);
596 strcpy(output, get_text());
600 VDeviceTumbleBox::VDeviceTumbleBox(VDevicePrefs *prefs,
601 int x, int y, int *output, int min, int max, int text_w)
602 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
604 this->output = output;
607 int VDeviceTumbleBox::handle_event()
609 *output = atol(get_text());
618 VDeviceIntBox::VDeviceIntBox(int x, int y, int *output)
619 : BC_TextBox(x, y, xS(60), 1, *output)
621 this->output = output;
624 int VDeviceIntBox::handle_event()
626 *output = atol(get_text());
634 VDeviceCheckBox::VDeviceCheckBox(int x, int y, int *output, char *text)
635 : BC_CheckBox(x, y, *output, text)
637 this->output = output;
639 int VDeviceCheckBox::handle_event()
641 *output = get_value();
648 VScalingItem::VScalingItem(VScalingEquation *popup, int interpolation)
649 : BC_MenuItem(popup->interpolation_to_string(interpolation))
652 this->interpolation = interpolation;
655 VScalingItem::~VScalingItem()
659 int VScalingItem::handle_event()
661 popup->set_text(get_text());
662 *(popup->output) = interpolation;
667 VScalingEquation::VScalingEquation(int x, int y, int *output)
668 : BC_PopupMenu(x, y, xS(240), interpolation_to_string(*output))
670 this->output = output;
673 VScalingEquation::~VScalingEquation()
677 const char *VScalingEquation::interpolation_to_string(int type)
680 case NEAREST_NEIGHBOR: return _("Nearest Neighbor");
681 case CUBIC_CUBIC: return _("BiCubic / BiCubic");
682 case CUBIC_LINEAR: return _("BiCubic / BiLinear");
683 case LINEAR_LINEAR: return _("BiLinear / BiLinear");
684 case LANCZOS_LANCZOS: return _("Lanczos / Lanczos");
689 void VScalingEquation::create_objects()
691 add_item(new VScalingItem(this, NEAREST_NEIGHBOR));
692 add_item(new VScalingItem(this, CUBIC_CUBIC));
693 add_item(new VScalingItem(this, CUBIC_LINEAR));
694 add_item(new VScalingItem(this, LINEAR_LINEAR));
695 add_item(new VScalingItem(this, LANCZOS_LANCZOS));