]> git.sesse.net Git - nageru/blob - main.cpp
If EGL initialization fails, print a friendlier error message.
[nageru] / main.cpp
1 extern "C" {
2 #include <libavformat/avformat.h>
3 }
4 #include <stdbool.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/mman.h>
8 #include <epoxy/gl.h>  // IWYU pragma: keep
9 #include <QApplication>
10 #include <QCoreApplication>
11 #include <QGL>
12 #include <QSize>
13 #include <QSurfaceFormat>
14 #include <string>
15
16 #include "context.h"
17 #include "flags.h"
18 #include "image_input.h"
19 #include "mainwindow.h"
20 #include "mixer.h"
21
22 int main(int argc, char *argv[])
23 {
24         parse_flags(argc, argv);
25
26         if (global_flags.va_display.empty() ||
27             global_flags.va_display[0] != '/') {
28                 // We normally use EGL for zerocopy, but if we use VA against DRM
29                 // instead of against X11, we turn it off, and then don't need EGL.
30                 setenv("QT_XCB_GL_INTEGRATION", "xcb_egl", 0);
31                 using_egl = true;
32         }
33         setlinebuf(stdout);
34         av_register_all();
35
36         QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
37         QApplication app(argc, argv);
38
39         QSurfaceFormat fmt;
40         fmt.setDepthBufferSize(0);
41         fmt.setStencilBufferSize(0);
42         fmt.setProfile(QSurfaceFormat::CoreProfile);
43         fmt.setMajorVersion(3);
44         fmt.setMinorVersion(1);
45
46         // Turn off vsync, since Qt generally gives us at most frame rate
47         // (display frequency) / (number of QGLWidgets active).
48         fmt.setSwapInterval(0);
49
50         QSurfaceFormat::setDefaultFormat(fmt);
51
52         QGLFormat::setDefaultFormat(QGLFormat::fromSurfaceFormat(fmt));
53
54         global_share_widget = new QGLWidget();
55
56         MainWindow mainWindow;
57         mainWindow.resize(QSize(1500, 850));
58         mainWindow.show();
59
60         app.installEventFilter(&mainWindow);  // For white balance color picking.
61
62         // Even on an otherwise unloaded system, it would seem writing the recording
63         // to disk (potentially terabytes of data as time goes by) causes Nageru
64         // to be pushed out of RAM. If we have the right privileges, simply lock us
65         // into memory for better realtime behavior.
66         if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
67                 perror("mlockall()");
68                 fprintf(stderr, "Failed to lock Nageru into RAM. You probably want to\n");
69                 fprintf(stderr, "increase \"memlock\" for your user in limits.conf\n");
70                 fprintf(stderr, "for better realtime behavior.\n");
71                 uses_mlock = false;
72         } else {
73                 uses_mlock = true;
74         }
75
76         int rc = app.exec();
77         global_mixer->quit();
78         mainWindow.mixer_shutting_down();
79         delete global_mixer;
80         ImageInput::shutdown_updaters();
81         return rc;
82 }