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