File: qv4l2.h

package info (click to toggle)
v4l-utils 1.32.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,276 kB
  • sloc: ansic: 85,528; cpp: 69,473; perl: 11,915; sh: 1,333; python: 883; php: 119; makefile: 39
file content (317 lines) | stat: -rw-r--r-- 7,783 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/* qv4l2: a control panel controlling v4l2 devices.
 *
 * Copyright (C) 2006 Hans Verkuil <hverkuil@kernel.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef QV4L2_H
#define QV4L2_H

#include <QMainWindow>
#include <QTabWidget>
#include <QSignalMapper>
#include <QLabel>
#include <QGridLayout>
#include <QSocketNotifier>
#include <QImage>
#include <QFileDialog>
#include <map>
#include <vector>

// Must come before cv4l-helpers.h
#include <libv4l2.h>

extern "C" {
#include <v4l2-tpg.h>
}
#include "cv4l-helpers.h"
#include "raw2sliced.h"
#include "capture-win.h"

class QComboBox;
class QSpinBox;
class QCheckBox;
class GeneralTab;
class VbiTab;
class QCloseEvent;
class CaptureWin;

using ClassIDVec = std::vector<unsigned>;
using ClassMap = std::map<unsigned, ClassIDVec>;
using CtrlMap = std::map<unsigned, v4l2_query_ext_ctrl>;
using WidgetMap = std::map<unsigned, QWidget *>;

enum {
	CTRL_UPDATE_ON_CHANGE = 0x10,
	CTRL_DEFAULTS,
	CTRL_REFRESH,
	CTRL_UPDATE
};

enum CapMethod {
	methodRead,
	methodMmap,
	methodUser
};

enum RenderMethod {
	QV4L2_RENDER_GL,
	QV4L2_RENDER_QT
};

struct buffer {
	unsigned planes;
	void   *start[VIDEO_MAX_PLANES];
	size_t  length[VIDEO_MAX_PLANES];
	bool clear;
};

#define CTRL_FLAG_DISABLED	(V4L2_CTRL_FLAG_READ_ONLY | \
				 V4L2_CTRL_FLAG_INACTIVE | \
				 V4L2_CTRL_FLAG_GRABBED)

class CaptureWin;

class ApplicationWindow: public QMainWindow, cv4l_fd
{
	Q_OBJECT

	friend class CaptureWin;
public:
	ApplicationWindow();
	virtual ~ApplicationWindow();

private slots:
	void closeDevice();
	void closeCaptureWin();

public:
	void setDevice(const QString &device, bool rawOpen);

	// capturing
private:
	CaptureWin *m_capture;

	bool startStreaming();
	void stopStreaming();
	void newCaptureWin();
	void startAudio();
	void stopAudio();
	bool startOutput();
	void stopOutput();

	bool m_clear[64];
	cv4l_fmt m_capSrcFormat;
	cv4l_fmt m_capDestFormat;
	unsigned char *m_frameData;
	unsigned m_nbuffers;
	struct v4lconvert_data *m_convertData;
	bool m_mustConvert;
	CapMethod m_capMethod;
	bool m_makeSnapshot;
	bool m_singleStep;
	RenderMethod m_renderMethod;
	int m_overrideColorspace;
	int m_overrideXferFunc;
	int m_overrideYCbCrEnc;
	int m_overrideQuantization;

private slots:
	void capStart(bool);
	void capStep(bool);
	void outStart(bool);
	void makeFullScreen(bool);
	void capFrame();
	void outFrame();
	void ctrlEvent();
	void snapshot();
	void capVbiFrame();
	void capSdrFrame();
	void saveRaw(bool);
	void setRenderMethod(bool);
	void setBlending(bool);
	void setLinearFilter(bool);
	void traceIoctls(bool);
	void changeAudioDevice();

	// gui
private slots:
	void opendev();
	void openrawdev();
	void ctrlAction(int);
	void openRawFile(const QString &s);
	void rejectedRawFile();
	void setAudioBufferSize();
	void enableScaling(bool enable);
	void updatePixelAspectRatio();
	void updateCropping();
	void clearBuffers();
	void about();
	void overrideColorspaceChanged(QAction *a);
	void overrideXferFuncChanged(QAction *a);
	void overrideYCbCrEncChanged(QAction *a);
	void overrideQuantChanged(QAction *a);

	// tpg
private slots:
	void testPatternChanged(int val);
	void horMovementChanged(int val);
	void vertMovementChanged(int val);
	void showBorderChanged(int val);
	void showSquareChanged(int val);
	void insSAVChanged(int val);
	void insEAVChanged(int val);
	void videoAspectRatioChanged(int val);
	void limRGBRangeChanged(int val);
	void fillPercentageChanged(int val);
	void alphaComponentChanged(int val);
	void applyToRedChanged(int val);
	__u32 tpgDefaultColorspace();
	void tpgColorspaceChanged();

public:
	virtual void error(const QString &text);
	void error(int err);
	void errorCtrl(unsigned id, int err);
	void errorCtrl(unsigned id, int err, long long v);
	void errorCtrl(unsigned id, int err, const QString &v);
	void info(const QString &info);
	virtual void closeEvent(QCloseEvent *event);
	void updateLimRGBRange();
	void updateColorspace();
	QAction *m_resetScalingAct;
	QAction *m_useBlendingAct;
	QAction *m_useLinearAct;
	QAction *m_snapshotAct;
	QAction *m_showFramesAct;
	QMenu *m_overrideColorspaceMenu;
	QMenu *m_overrideXferFuncMenu;
	QMenu *m_overrideYCbCrEncMenu;
	QMenu *m_overrideQuantizationMenu;

private:
	void addWidget(QGridLayout *grid, QWidget *w, Qt::Alignment align = Qt::AlignLeft);
	void addLabel(QGridLayout *grid, const QString &text, Qt::Alignment align = Qt::AlignLeft)
	{
		addWidget(grid, new QLabel(text, parentWidget()), align);
	}
	void fixWidth(QGridLayout *grid);
	void addTabs(int m_winWidth);
	void addTpgTab(int m_winWidth);
	void finishGrid(QGridLayout *grid, unsigned which);
	void addCtrl(QGridLayout *grid, const struct v4l2_query_ext_ctrl &qec);
	void updateCtrl(unsigned id);
	void updateCtrlRange(unsigned id, __s32 val);
	void subscribeCtrlEvents();
	void refresh(unsigned which);
	void refresh();
	void calculateFps();
	void makeSnapshot(unsigned char *buf, unsigned size);
	void setDefaults(unsigned which);
	int getVal(unsigned id);
	long long getVal64(unsigned id);
	QString getString(unsigned id);
	void setVal(unsigned id, int v);
	void setVal64(unsigned id, long long v);
	void setString(unsigned id, const QString &v);
	QString getCtrlFlags(unsigned flags);
	void setWhat(QWidget *w, unsigned id, const QString &v);
	void setWhat(QWidget *w, unsigned id, long long v);
	void updateVideoInput();
	void updateVideoOutput();
	void updateAudioInput();
	void updateAudioOutput();
	void updateStandard();
	void updateFreq();
	void updateFreqChannel();
	bool showFrames();

	// tpg
	struct tpg_data m_tpg;
	v4l2_std_id m_tpgStd;
	unsigned m_tpgField;
	bool m_tpgFieldAlt;
	unsigned m_tpgSizeImage;
	QComboBox *m_tpgColorspace;
	QComboBox *m_tpgXferFunc;
	QComboBox *m_tpgYCbCrEnc;
	QComboBox *m_tpgQuantRange;
	bool m_useTpg;
	QCheckBox *m_tpgLimRGBRange;

	cv4l_queue m_queue;

	const double m_pxw;
	const int m_minWidth;
	const int m_vMargin;
	const int m_hMargin;
	int m_maxw[4];
	int m_increment;
	GeneralTab *m_genTab;
	VbiTab *m_vbiTab;
	QMenu *m_capMenu;
	QAction *m_capStartAct;
	QAction *m_capStepAct;
	QAction *m_saveRawAct;
	QAction *m_useGLAct;
	QAction *m_audioBufferAct;
	QAction *m_scalingAct;
	QAction *m_makeFullScreenAct;
	QString m_filename;
	QSignalMapper *m_sigMapper;
	QTabWidget *m_tabs;
	QSocketNotifier *m_capNotifier;
	QSocketNotifier *m_outNotifier;
	QSocketNotifier *m_ctrlNotifier;
	QImage *m_capImage;
	int m_row, m_col, m_cols;
	CtrlMap m_ctrlMap;
	WidgetMap m_widgetMap;
	WidgetMap m_sliderMap;
	ClassMap m_classMap;
	int m_vbiSize;
	unsigned m_vbiWidth;
	unsigned m_vbiHeight;
	struct vbi_handle m_vbiHandle;
	int m_sdrSize;
	unsigned m_frame;
	double m_fps;
	struct timespec m_startTimestamp;
	struct timeval m_totalAudioLatency;
	QFile m_saveRaw;
};

extern ApplicationWindow *g_mw;

class SaveDialog : public QFileDialog
{
	Q_OBJECT

public:
	SaveDialog(QWidget *parent, const QString &caption) :
		QFileDialog(parent, caption), m_buf(NULL) {}
	virtual ~SaveDialog() {}
	bool setBuffer(unsigned char *buf, unsigned size);

public slots:
	void selected(const QString &s);

private:
	unsigned char *m_buf;
	unsigned m_size;
};

#endif