2 #include <libavformat/avformat.h>
8 #include <epoxy/gl.h> // IWYU pragma: keep
9 #include <QApplication>
10 #include <QCoreApplication>
13 #include <QSurfaceFormat>
18 #include <cef_browser.h>
19 #include <cef_client.h>
20 #include <cef_version.h>
23 #include "basic_stats.h"
25 #include "nageru_cef_app.h"
29 #include "image_input.h"
30 #include "mainwindow.h"
34 CefRefPtr<NageruCefApp> cef_app;
37 int main(int argc, char *argv[])
40 // Let CEF have first priority on parsing the command line, because we might be
41 // launched as a CEF sub-process.
42 CefMainArgs main_args(argc, argv);
43 cef_app = CefRefPtr<NageruCefApp>(new NageruCefApp());
44 int err = CefExecuteProcess(main_args, cef_app.get(), nullptr);
49 // CEF wants to use GLib for its main loop, which interferes with Qt's use of it.
50 // The alternative is trying to integrate CEF into Qt's main loop, but that requires
51 // fairly extensive cross-thread communication and that parts of CEF runs on Qt's UI
53 setenv("QT_NO_GLIB", "1", 0);
56 parse_flags(PROGRAM_NAGERU, argc, argv);
58 if (global_flags.va_display.empty() ||
59 global_flags.va_display[0] != '/') {
60 // We normally use EGL for zerocopy, but if we use VA against DRM
61 // instead of against X11, we turn it off, and then don't need EGL.
62 setenv("QT_XCB_GL_INTEGRATION", "xcb_egl", 0);
68 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
71 fmt.setDepthBufferSize(0);
72 fmt.setStencilBufferSize(0);
73 fmt.setProfile(QSurfaceFormat::CoreProfile);
74 fmt.setMajorVersion(3);
75 fmt.setMinorVersion(1);
77 // Turn off vsync, since Qt generally gives us at most frame rate
78 // (display frequency) / (number of QGLWidgets active).
79 fmt.setSwapInterval(0);
81 QSurfaceFormat::setDefaultFormat(fmt);
83 QGLFormat::setDefaultFormat(QGLFormat::fromSurfaceFormat(fmt));
85 QApplication app(argc, argv);
86 global_share_widget = new QGLWidget();
87 if (!global_share_widget->isValid()) {
88 fprintf(stderr, "Failed to initialize OpenGL. Nageru needs at least OpenGL 3.1 to function properly.\n");
92 MainWindow mainWindow;
93 mainWindow.resize(QSize(1500, 850));
96 app.installEventFilter(&mainWindow); // For white balance color picking.
98 // Even on an otherwise unloaded system, it would seem writing the recording
99 // to disk (potentially terabytes of data as time goes by) causes Nageru
100 // to be pushed out of RAM. If we have the right privileges, simply lock us
101 // into memory for better realtime behavior.
102 if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
103 perror("mlockall()");
104 fprintf(stderr, "Failed to lock Nageru into RAM. You probably want to\n");
105 fprintf(stderr, "increase \"memlock\" for your user in limits.conf\n");
106 fprintf(stderr, "for better realtime behavior.\n");
113 global_mixer->quit();
114 mainWindow.mixer_shutting_down();
116 ImageInput::shutdown_updaters();