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>
27 #include "basic_stats.h"
29 #include "nageru_cef_app.h"
31 #include "shared/context.h"
33 #include "mainwindow.h"
35 #include "quicksync_encoder.h"
38 CefRefPtr<NageruCefApp> cef_app;
41 int main(int argc, char *argv[])
44 // Let CEF have first priority on parsing the command line, because we might be
45 // launched as a CEF sub-process.
46 CefMainArgs main_args(argc, argv);
47 cef_app = CefRefPtr<NageruCefApp>(new NageruCefApp());
48 int err = CefExecuteProcess(main_args, cef_app.get(), nullptr);
53 // CEF wants to use GLib for its main loop, which interferes with Qt's use of it.
54 // The alternative is trying to integrate CEF into Qt's main loop, but that requires
55 // fairly extensive cross-thread communication and that parts of CEF runs on Qt's UI
57 setenv("QT_NO_GLIB", "1", 0);
60 parse_flags(PROGRAM_NAGERU, argc, argv);
62 if (global_flags.va_display.empty() && !global_flags.x264_video_to_disk) {
63 // The user didn't specify a VA-API display, but we need one.
64 // See if the default works, and if not, let's try to help
65 // the user by seeing if there's any that would work automatically.
66 global_flags.va_display = QuickSyncEncoder::get_usable_va_display();
69 // The OpenGL widgets do not work well with the native Wayland integration.
70 setenv("QT_QPA_PLATFORM", "xcb", 0);
72 if ((global_flags.va_display.empty() ||
73 global_flags.va_display[0] != '/') && !global_flags.x264_video_to_disk) {
74 // We normally use EGL for zerocopy, but if we use VA against DRM
75 // instead of against X11, we turn it off, and then don't need EGL.
76 setenv("QT_XCB_GL_INTEGRATION", "xcb_egl", 0);
79 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58, 9, 100)
84 if (global_flags.srt_port >= 0 || !global_flags.srt_destination_host.empty()) {
89 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
92 fmt.setDepthBufferSize(0);
93 fmt.setStencilBufferSize(0);
94 fmt.setProfile(QSurfaceFormat::CoreProfile);
95 fmt.setMajorVersion(3);
96 fmt.setMinorVersion(1);
98 // Turn off vsync, since Qt generally gives us at most frame rate
99 // (display frequency) / (number of QGLWidgets active).
100 fmt.setSwapInterval(0);
102 QSurfaceFormat::setDefaultFormat(fmt);
104 QGLFormat::setDefaultFormat(QGLFormat::fromSurfaceFormat(fmt));
106 QApplication app(argc, argv);
107 global_share_widget = new QGLWidget();
108 if (!global_share_widget->isValid()) {
109 fprintf(stderr, "Failed to initialize OpenGL. Nageru needs at least OpenGL 3.1 to function properly.\n");
113 MainWindow mainWindow;
114 mainWindow.resize(QSize(1500, 910));
117 app.installEventFilter(&mainWindow); // For white balance color picking.
119 // Even on an otherwise unloaded system, it would seem writing the recording
120 // to disk (potentially terabytes of data as time goes by) causes Nageru
121 // to be pushed out of RAM. If we have the right privileges, simply lock us
122 // into memory for better realtime behavior.
123 if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
124 perror("mlockall()");
125 fprintf(stderr, "Failed to lock Nageru into RAM. You probably want to\n");
126 fprintf(stderr, "increase \"memlock\" for your user in limits.conf\n");
127 fprintf(stderr, "for better realtime behavior.\n");
136 if (global_flags.srt_port >= 0) {