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