]> git.sesse.net Git - nageru/blob - main.cpp
Update the queue length metric after trimming, not before.
[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         if (!global_share_widget->isValid()) {
56                 fprintf(stderr, "Failed to initialize OpenGL. Nageru needs at least OpenGL 3.1 to function properly.\n");
57                 exit(1);
58         }
59
60         MainWindow mainWindow;
61         mainWindow.resize(QSize(1500, 850));
62         mainWindow.show();
63
64         app.installEventFilter(&mainWindow);  // For white balance color picking.
65
66         // Even on an otherwise unloaded system, it would seem writing the recording
67         // to disk (potentially terabytes of data as time goes by) causes Nageru
68         // to be pushed out of RAM. If we have the right privileges, simply lock us
69         // into memory for better realtime behavior.
70         if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
71                 perror("mlockall()");
72                 fprintf(stderr, "Failed to lock Nageru into RAM. You probably want to\n");
73                 fprintf(stderr, "increase \"memlock\" for your user in limits.conf\n");
74                 fprintf(stderr, "for better realtime behavior.\n");
75                 uses_mlock = false;
76         } else {
77                 uses_mlock = true;
78         }
79
80         int rc = app.exec();
81         global_mixer->quit();
82         mainWindow.mixer_shutting_down();
83         delete global_mixer;
84         ImageInput::shutdown_updaters();
85         return rc;
86 }