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"
27 #include "shared/context.h"
29 #include "image_input.h"
30 #include "mainwindow.h"
32 #include "quicksync_encoder.h"
35 CefRefPtr<NageruCefApp> cef_app;
38 int main(int argc, char *argv[])
41 // Let CEF have first priority on parsing the command line, because we might be
42 // launched as a CEF sub-process.
43 CefMainArgs main_args(argc, argv);
44 cef_app = CefRefPtr<NageruCefApp>(new NageruCefApp());
45 int err = CefExecuteProcess(main_args, cef_app.get(), nullptr);
50 // CEF wants to use GLib for its main loop, which interferes with Qt's use of it.
51 // The alternative is trying to integrate CEF into Qt's main loop, but that requires
52 // fairly extensive cross-thread communication and that parts of CEF runs on Qt's UI
54 setenv("QT_NO_GLIB", "1", 0);
57 parse_flags(PROGRAM_NAGERU, argc, argv);
59 if (global_flags.va_display.empty() && !global_flags.x264_video_to_disk) {
60 // The user didn't specify a VA-API display, but we need one.
61 // See if the default works, and if not, let's try to help
62 // the user by seeing if there's any that would work automatically.
63 global_flags.va_display = QuickSyncEncoder::get_usable_va_display();
66 if ((global_flags.va_display.empty() ||
67 global_flags.va_display[0] != '/') && !global_flags.x264_video_to_disk) {
68 // We normally use EGL for zerocopy, but if we use VA against DRM
69 // instead of against X11, we turn it off, and then don't need EGL.
70 setenv("QT_XCB_GL_INTEGRATION", "xcb_egl", 0);
73 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58, 9, 100)
77 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
80 fmt.setDepthBufferSize(0);
81 fmt.setStencilBufferSize(0);
82 fmt.setProfile(QSurfaceFormat::CoreProfile);
83 fmt.setMajorVersion(3);
84 fmt.setMinorVersion(1);
86 // Turn off vsync, since Qt generally gives us at most frame rate
87 // (display frequency) / (number of QGLWidgets active).
88 fmt.setSwapInterval(0);
90 QSurfaceFormat::setDefaultFormat(fmt);
92 QGLFormat::setDefaultFormat(QGLFormat::fromSurfaceFormat(fmt));
94 QApplication app(argc, argv);
95 global_share_widget = new QGLWidget();
96 if (!global_share_widget->isValid()) {
97 fprintf(stderr, "Failed to initialize OpenGL. Nageru needs at least OpenGL 3.1 to function properly.\n");
101 MainWindow mainWindow;
102 mainWindow.resize(QSize(1500, 910));
105 app.installEventFilter(&mainWindow); // For white balance color picking.
107 // Even on an otherwise unloaded system, it would seem writing the recording
108 // to disk (potentially terabytes of data as time goes by) causes Nageru
109 // to be pushed out of RAM. If we have the right privileges, simply lock us
110 // into memory for better realtime behavior.
111 if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
112 perror("mlockall()");
113 fprintf(stderr, "Failed to lock Nageru into RAM. You probably want to\n");
114 fprintf(stderr, "increase \"memlock\" for your user in limits.conf\n");
115 fprintf(stderr, "for better realtime behavior.\n");
123 ImageInput::shutdown_updaters();