Debian Codegraph @

src/bino.hpp

raw
1 /*
2 * This file is part of Bino, a 3D video player.
3 *
4 * Copyright (C) 2022, 2023, 2024, 2025
5 * Martin Lambers <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #pragma once
22
23 #include <QOpenGLExtraFunctions>
24 #include <QOpenGLShaderProgram>
25 #include <QAudioDevice>
26 #include <QCameraDevice>
27 #include <QAudioOutput>
28 #include <QAudioInput>
29 #include <QCamera>
30 #include <QMediaPlayer>
31 #include <QMediaCaptureSession>
32 #include <QKeyEvent>
33 #include <QScreenCapture>
34 #include <QWindowCapture>
35
36 #include "screen.hpp"
37 #include "videosink.hpp"
38 #include "playlist.hpp"
39
40
41 class Bino : public QObject, QOpenGLExtraFunctions
42 {
43 Q_OBJECT
44
45 public:
46 enum ScreenType {
47 ScreenUnited, // global 2D united screen given by QVR
48 ScreenIntersected, // global 2D intersected screen given by QVR
49 ScreenGeometry // explicit geometry stored in _screen
50 };
51
52 private:
53 /* Data not directly relevant for rendering */
54 bool _wantExit;
55 VideoSink* _videoSink;
56 QAudioOutput* _audioOutput;
57 // for playing a play list:
58 QMediaPlayer* _player;
59 // for capturing audio/video:
60 QAudioInput* _audioInput;
61 QCamera* _videoInput;
62 QScreenCapture* _screenInput;
63 QWindowCapture* _windowInput;
64 QMediaCaptureSession* _captureSession;
65 // for rendering subtitles:
66 QImage _subtitleImg;
67 QString _subtitleImgString;
68 // for updating the GUI if necessary
69 InputMode _lastFrameInputMode;
70 SurroundMode _lastFrameSurroundMode;
71
72 /* Static data for rendering, initialized on the main process */
73 ScreenType _screenType;
74 Screen _screen;
75
76 /* Static data for rendering, initialized in initProcess() */
77 unsigned int _depthTex;
78 unsigned int _frameFbo;
79 unsigned int _viewFbo;
80 unsigned int _quadVao;
81 unsigned int _cubeVao;
82 unsigned int _planeTexs[3];
83 unsigned int _frameTex;
84 unsigned int _extFrameTex;
85 unsigned int _subtitleTex;
86 unsigned int _screenVao, _positionBuf, _texcoordBuf, _indexBuf;
87 QOpenGLShaderProgram _colorPrg;
88 int _colorPrgPlaneFormat;
89 bool _colorPrgColorRangeSmall;
90 int _colorPrgColorSpace;
91 int _colorPrgColorTransfer;
92 QOpenGLShaderProgram _viewPrg;
93 SurroundMode _viewPrgSurroundMode;
94 bool _viewPrgNonlinearOutput;
95
96 /* Dynamic data for rendering */
97 VideoFrame _frame;
98 VideoFrame _extFrame; // for alternating stereo
99 bool _frameIsNew;
100 bool _frameWasSerialized;
101 bool _swapEyes;
102
103 void startCaptureMode(bool withAudioInput, const QAudioDevice& audioInputDevice, InputMode inputMode);
104 void rebuildColorPrgIfNecessary(int planeFormat, bool colorRangeSmall, int colorSpace, int colorTransfer);
105 void rebuildViewPrgIfNecessary(SurroundMode surroundMode, bool nonLinearOutput);
106 bool drawSubtitleToImage(int w, int h, const QString& string);
107 void convertFrameToTexture(const VideoFrame& frame, unsigned int frameTex);
108
109 public:
110 Bino(ScreenType screenType, const Screen& screen, bool swapEyes);
111 virtual ~Bino();
112
113 static Bino* instance();
114
115 /* Initialization functions, to be called by main() before
116 * starting either GUI or VR mode */
117 void initializeOutput(const QAudioDevice& audioOutputDevice);
118 void startPlaylistMode();
119 void stopPlaylistMode();
120 void startCaptureModeCamera(
121 bool withAudioInput,
122 const QAudioDevice& audioInputDevice,
123 const QCameraDevice& videoInputDevice,
124 InputMode inputMode);
125 void startCaptureModeScreen(
126 bool withAudioInput,
127 const QAudioDevice& audioInputDevice,
128 QScreen* screenInputDevice,
129 InputMode inputMode);
130 void startCaptureModeWindow(
131 bool withAudioInput,
132 const QAudioDevice& audioInputDevice,
133 const QCapturableWindow& windowInputDevice,
134 InputMode inputMode);
135 void stopCaptureMode();
136 bool playlistMode() const;
137 bool captureMode() const;
138
139 /* Interaction functions, can be called while in GUI or VR mode */
140 void quit();
141 void seek(qint64 milliseconds);
142 void setPosition(float pos);
143 void togglePause();
144 void pause();
145 void play();
146 void stop();
147 void setMute(bool m);
148 void toggleMute();
149 void setVolume(float vol);
150 void changeVolume(float offset);
151 void setSwapEyes(bool s);
152 void toggleSwapEyes();
153 void setVideoTrack(int i);
154 void setAudioTrack(int i);
155 void setSubtitleTrack(int i);
156 void setInputMode(InputMode mode);
157 void setSurroundMode(SurroundMode mode);
158
159 /* Functions necessary for GUI mode */
160 bool swapEyes() const;
161 bool muted() const;
162 bool paused() const;
163 bool playing() const;
164 bool stopped() const;
165 QUrl url() const;
166 int videoTrack() const;
167 int audioTrack() const;
168 int subtitleTrack() const;
169 InputMode inputMode() const; // this might be unknown
170 InputMode assumeInputMode() const; // this is never unknown
171 bool assumeStereoInputMode() const; // is the assumed mode stereo?
172 SurroundMode surroundMode() const; // this might be unknown
173 SurroundMode assumeSurroundMode() const; // this is never unknown
174
175 /* Functions necessary for VR mode */
176 void serializeStaticData(QDataStream& ds) const;
177 void deserializeStaticData(QDataStream& ds);
178 void serializeDynamicData(QDataStream& ds);
179 void deserializeDynamicData(QDataStream& ds);
180 bool wantExit() const;
181
182 /* Functions shared by GUI and VR mode */
183 bool initProcess();
184 void preRenderProcess(
185 int screenWidth = 0,
186 int screenHeight = 0,
187 int* viewCount = nullptr,
188 int* viewWidth = nullptr,
189 int* viewHeight = nullptr,
190 float* frameDisplayAspectRatio = nullptr,
191 bool* surround = nullptr);
192 void render(
193 const QVector3D& unitedScreenBottomLeft, const QVector3D& unitedScreenBottomRight, const QVector3D& unitedScreenTopLeft,
194 const QVector3D& intersectedScreenBottomLeft, const QVector3D& intersectedScreenBottomRight, const QVector3D& intersectedScreenTopLeft,
195 const QMatrix4x4& projectionMatrix,
196 const QMatrix4x4& orientationMatrix,
197 const QMatrix4x4& viewMatrix,
198 int view, // 0 = left, 1 = right
199 int texWidth, int texHeight, unsigned int texture);
200 void keyPressEvent(QKeyEvent* event);
201
202 public slots:
203 void mediaChanged(PlaylistEntry entry);
204
205 signals:
206 void newVideoFrame();
207 void toggleFullscreen();
208 void stateChanged();
209 void wantQuit();
210 };