Debian Codegraph @

utils/qvidcap/capture.h

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
4 */
5
6 #ifndef CAPTURE_WIN_GL_H
7 #define CAPTURE_WIN_GL_H
8
9 #define GL_GLEXT_PROTOTYPES 1
10 #define QT_NO_OPENGL_ES_2
11
12 #include <QOpenGLWidget>
13 #include <QOpenGLFunctions>
14 #include <QFile>
15 #include <QMenu>
16 #include <QAction>
17 #include <QActionGroup>
18 #include <QScrollArea>
19 #if QT_VERSION < 0x060000
20 #include <QtGui/QOpenGLShaderProgram>
21 #else
22 #include <QOpenGLShaderProgram>
23 #endif
24
25 #include "qvidcap.h"
26
27 extern "C" {
28 #include "v4l2-tpg.h"
29 #include "v4l-stream.h"
30 }
31
32 extern const __u32 formats[];
33 extern const __u32 fields[];
34 extern const __u32 colorspaces[];
35 extern const __u32 xfer_funcs[];
36 extern const __u32 ycbcr_encs[];
37 extern const __u32 hsv_encs[];
38 extern const __u32 quantizations[];
39
40 class QOpenGLPaintDevice;
41
42 enum AppMode {
43 AppModeV4L2,
44 AppModeFile,
45 AppModeSocket,
46 AppModeTPG,
47 AppModeTest
48 };
49
50 #define FMT_MASK (1 << 0)
51 #define FIELD_MASK (1 << 1)
52 #define COLORSPACE_MASK (1 << 2)
53 #define XFER_FUNC_MASK (1 << 3)
54 #define YCBCR_HSV_ENC_MASK (1 << 4)
55 #define QUANT_MASK (1 << 5)
56
57 struct TestState {
58 unsigned fmt_idx;
59 unsigned field_idx;
60 unsigned colorspace_idx;
61 unsigned xfer_func_idx;
62 unsigned ycbcr_enc_idx;
63 unsigned hsv_enc_idx;
64 unsigned quant_idx;
65 unsigned mask;
66 };
67
68 // This must be equal to the max number of textures that any shader uses
69 #define MAX_TEXTURES_NEEDED 3
70
71 class CaptureWin : public QOpenGLWidget, protected QOpenGLFunctions
72 {
73 Q_OBJECT
74 public:
75 explicit CaptureWin(QScrollArea *sa, QWidget *parent = 0);
76 ~CaptureWin();
77
78 void setModeV4L2(cv4l_fd *fd);
79 void setModeSocket(int sock, int port);
80 void setModeFile(const QString &filename);
81 void setModeTPG();
82 void setModeTest(unsigned cnt);
83 void setQueue(cv4l_queue *q);
84 bool setV4LFormat(cv4l_fmt &fmt);
85 void setPixelAspect(const v4l2_fract &pixelaspect);
86 bool updateV4LFormat(const cv4l_fmt &fmt);
87 void setOverrideWidth(__u32 w);
88 void setOverrideHeight(__u32 h);
89 void setOverrideHorPadding(__u32 p);
90 void setCount(unsigned cnt) { m_cnt = cnt; }
91 void setReportTimings(bool report) { m_reportTimings = report; }
92 void setVerbose(bool verbose) { m_verbose = verbose; }
93 void setNoLoop(bool no_loop) { m_no_loop = no_loop; }
94 void setFromFrame(unsigned from_frame) { m_fromFrame = from_frame; }
95 void setOverridePixelFormat(__u32 fmt) { m_overridePixelFormat = fmt; }
96 void setOverrideField(__u32 field) { m_overrideField = field; }
97 void setOverrideColorspace(__u32 colsp) { m_overrideColorspace = colsp; }
98 void setOverrideYCbCrEnc(__u32 ycbcr) { m_overrideYCbCrEnc = ycbcr; }
99 void setOverrideHSVEnc(__u32 hsv) { m_overrideHSVEnc = hsv; }
100 void setOverrideXferFunc(__u32 xfer_func) { m_overrideXferFunc = xfer_func; }
101 void setOverrideQuantization(__u32 quant) { m_overrideQuantization = quant; }
102 void setFps(double fps) { m_fps = fps; }
103 void setSingleStepStart(unsigned start) { m_singleStep = true; m_singleStepStart = start; }
104 void setTestState(const TestState &state) { m_testState = state; }
105 QSize correctAspect(const QSize &s) const;
106 void startTimer();
107 struct tpg_data *getTPG() { return &m_tpg; }
108
109 private slots:
110 void v4l2ReadEvent();
111 void v4l2ExceptionEvent();
112 void sockReadEvent();
113 void tpgUpdateFrame();
114
115 void restoreAll(bool checked);
116 void restoreSize(bool checked = false);
117 void fmtChanged(QAction *a);
118 void fieldChanged(QAction *a);
119 void colorspaceChanged(QAction *a);
120 void xferFuncChanged(QAction *a);
121 void ycbcrEncChanged(QAction *a);
122 void hsvEncChanged(QAction *a);
123 void quantChanged(QAction *a);
124 void windowScalingChanged(QAction *a);
125 void resolutionOverrideChanged(bool);
126 void toggleFullScreen(bool b = false);
127
128 private:
129 void resizeEvent(QResizeEvent *event);
130 void paintGL();
131 void initializeGL();
132 void resizeGL(int w, int h);
133 void contextMenuEvent(QContextMenuEvent *event);
134 void keyPressEvent(QKeyEvent *event);
135 void mouseDoubleClickEvent(QMouseEvent * e);
136 void listenForNewConnection();
137 int read_u32(__u32 &v);
138 void showCurrentOverrides();
139 void cycleMenu(__u32 &overrideVal, __u32 origVal,
140 const __u32 values[], bool hasShift, bool hasCtrl);
141
142 bool supportedFmt(__u32 fmt);
143 void checkError(const char *msg);
144 void configureTexture(size_t idx);
145 void initImageFormat();
146 void updateOrigValues();
147 void updateShader();
148 void changeShader();
149
150 // Colorspace conversion shaders
151 void shader_YUV();
152 void shader_NV12();
153 void shader_NV16();
154 void shader_NV24();
155 void shader_RGB();
156 void shader_Bayer();
157 void shader_YUV_packed();
158 void shader_YUY2();
159
160 // Colorspace conversion render
161 void render_RGB(__u32 format);
162 void render_Bayer(__u32 format);
163 void render_YUY2(__u32 format);
164 void render_YUV(__u32 format);
165 void render_YUV_packed(__u32 format);
166 void render_NV12(__u32 format);
167 void render_NV16(__u32 format);
168 void render_NV24(__u32 format);
169
170 enum AppMode m_mode;
171 cv4l_fd *m_fd;
172 int m_sock;
173 int m_port;
174 QFile m_file;
175 bool m_v4l2;
176 cv4l_fmt m_v4l_fmt;
177 v4l2_fract m_pixelaspect;
178 cv4l_queue *m_v4l_queue;
179 unsigned m_cnt;
180 unsigned m_frame;
181 unsigned m_test;
182 TestState m_testState;
183 unsigned m_imageSize;
184 bool m_verbose;
185 bool m_no_loop;
186 bool m_pause;
187 unsigned m_fromFrame;
188 bool m_reportTimings;
189 bool m_is_sdtv;
190 v4l2_std_id m_std;
191 bool m_is_rgb;
192 bool m_is_hsv;
193 bool m_is_bayer;
194 bool m_uses_gl_red;
195 bool m_accepts_srgb;
196 bool m_haveSwapBytes;
197 bool m_updateShader;
198 QSize m_viewSize;
199 bool m_canOverrideResolution;
200 codec_ctx *m_ctx;
201
202 __u32 m_overridePixelFormat;
203 __u32 m_overrideWidth;
204 __u32 m_overrideHeight;
205 __u32 m_overrideHorPadding;
206 __u32 m_overrideField;
207 __u32 m_overrideColorspace;
208 __u32 m_overrideYCbCrEnc;
209 __u32 m_overrideHSVEnc;
210 __u32 m_overrideXferFunc;
211 __u32 m_overrideQuantization;
212 __u32 m_origPixelFormat;
213 __u32 m_origWidth;
214 __u32 m_origHeight;
215 __u32 m_origField;
216 __u32 m_origColorspace;
217 __u32 m_origYCbCrEnc;
218 __u32 m_origHSVEnc;
219 __u32 m_origXferFunc;
220 __u32 m_origQuantization;
221 double m_fps;
222 bool m_singleStep;
223 unsigned m_singleStepStart;
224 bool m_singleStepNext;
225
226 QTimer *m_timer;
227 int m_screenTextureCount;
228 GLuint m_screenTexture[MAX_TEXTURES_NEEDED];
229 QOpenGLShaderProgram *m_program;
230 __u8 *m_curData[MAX_TEXTURES_NEEDED];
231 unsigned m_curSize[MAX_TEXTURES_NEEDED];
232 __u8 *m_nextData[MAX_TEXTURES_NEEDED];
233 unsigned m_nextSize[MAX_TEXTURES_NEEDED];
234 int m_curIndex;
235 int m_nextIndex;
236 struct tpg_data m_tpg;
237
238 QScrollArea *m_scrollArea;
239 QAction *m_resolutionOverride;
240 QAction *m_exitFullScreen;
241 QAction *m_enterFullScreen;
242 QMenu *m_fmtMenu;
243 QMenu *m_fieldMenu;
244 QMenu *m_colorspaceMenu;
245 QMenu *m_xferFuncMenu;
246 QMenu *m_ycbcrEncMenu;
247 QMenu *m_hsvEncMenu;
248 QMenu *m_quantMenu;
249 QMenu *m_displayMenu;
250 };
251
252 #endif