aboutsummaryrefslogtreecommitdiffstats
path: root/utils/qv4l2/capture-win.h
blob: c16fa7cea1cd05512e5259e2b7f6ce9096158113 (plain)
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
/* qv4l2: a control panel controlling v4l2 devices.
 *
 * Copyright (C) 2006 Hans Verkuil <hverkuil@xs4all.nl>
 *
 * 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 CAPTURE_WIN_H
#define CAPTURE_WIN_H

#include "qv4l2.h"

#include <QWidget>
#include <QShortcut>
#include <QLabel>
#include <QPushButton>
#include <QMenu>

enum CropMethod {
	// Crop Height
	QV4L2_CROP_NONE,
	QV4L2_CROP_W149,
	QV4L2_CROP_W169,
	QV4L2_CROP_C185,
	QV4L2_CROP_C239,
	QV4L2_CROP_TB,

	// Crop Width
	QV4L2_CROP_P43,
};

struct frame {
	__u32 format;
	QSize size;        // int   frameHeight; int   frameWidth;
	unsigned char *planeData[3];
	bool updated;
};

struct crop {              // cropInfo
	QSize delta;       // int cropH; int cropW;
	QSize size;        // int height; int width;
	bool updated;
};

class ApplicationWindow;

class CaptureWin : public QWidget
{
	Q_OBJECT

public:
	CaptureWin(ApplicationWindow *aw);
	~CaptureWin();

	void setWindowSize(QSize size);
	void enableScaling(bool enable);
	void setPixelAspectRatio(double ratio);
	float getHorScaleFactor();
	float getVertScaleFactor();
	virtual void setColorspace(unsigned colorspace, unsigned xfer_func,
			unsigned ycbcr_enc, unsigned quantization, bool is_sdtv) = 0;
	virtual void setField(unsigned field) = 0;
	virtual void setBlending(bool enable) = 0;
	virtual void setLinearFilter(bool enable) = 0;
	void setCropMethod(CropMethod crop);
	void makeFullScreen(bool);
	QAction *m_exitFullScreen;
	QAction *m_enterFullScreen;

	/**
	 * @brief Set a frame into the capture window.
	 *
	 * When called the capture stream is
	 * either already running or starting for the first time.
	 *
	 * @param width Frame width in pixels
	 * @param height Frame height in pixels
	 * @param format The frame's format, given as a V4L2_PIX_FMT.
	 * @param data The frame data.
	 * @param info A string containing capture information.
	 */
	void setFrame(int width, int height, __u32 format,
		      unsigned char *data, unsigned char *data2, unsigned char *data3);

	/**
	 * @brief Called when the capture stream is stopped.
	 */
	virtual void stop() = 0;

	/**
	 * @brief Queries the current capture window for its supported formats.
	 *
	 * Unsupported formats are converted by v4lconvert_convert().
	 *
	 * @param format The frame format question, given as a V4L2_PIX_FMT.
	 * @return true if the format is supported, false if not.
	 */
	virtual bool hasNativeFormat(__u32 format) = 0;

	/**
	 * @brief Defines wether a capture window is supported.
	 *
	 * By default nothing is supported, but derived classes can override this.
	 *
	 * @return true if the capture window is supported on the system, false if not.
	 */
	static bool isSupported() { return false; }

	/**
	 * @brief Return the scaled size.
	 *
	 * Scales a frame to fit inside a given window. Preserves aspect ratio.
	 *
	 * @param window The window the frame shall scale into
	 * @param frame The frame to scale
	 * @return The scaledsizes to use for the frame
	 */
	static QSize scaleFrameSize(QSize window, QSize frame);

	/**
	 * @brief Crop size
	 *
	 * Reduces size width or height according to m_cropMethod
	 *
	 * @param size Input size
	 * @return Cropped size
	 *
	 */
	static QSize cropSize(QSize size);

	/**
	 * @brief Get the frame size when aspect ratio is applied and increases size.
	 *
	 * @param size The original frame size.
	 * @return The new size with aspect ratio correction (scaling must be enabled).
	 */
	static QSize pixelAspectFrameSize(QSize size);

public slots:
	void resetSize();
	void customMenuRequested(QPoint pos);

private slots:
	void escape();
	void fullScreen();

protected:
	void closeEvent(QCloseEvent *event);
	void mouseDoubleClickEvent(QMouseEvent *e);

	/**
	 * @brief Get the amount of space outside the video frame.
	 *
	 * The margins are that of the window that encloses the displaying
	 * video frame. The sizes are total in both width and height.
	 *
	 * @return The margins around the video frame.
	 */
	QSize getMargins();

	/**
	 * @brief Creates the content of the window.
	 *
	 * Construct the new window layout and adds the video display surface.
	 * @param videoSurface The widget that contains the renderer.
	 */
	void buildWindow(QWidget *videoSurface);

	/**
	 * @brief Calculate source size after pixel aspect scaling and cropping
	 *
	 */
	void updateSize();

	/**
	 * @brief Frame information.
	 *
	 * @note Set and accessed from derived render dependent classes.
	 */
	struct frame m_frame;
	struct crop  m_crop;
	QSize m_origFrameSize;  // int m_sourceWinWidth; int m_sourceWinHeight;
	QSize m_windowSize;     // int m_curWinWidth; int m_curWinHeight;
	QSize m_scaledSize;

	/**
	 * @brief Update frame information to renderer.
	 *
	 * @note Must be implemented by derived render dependent classes.
	 */
	virtual void setRenderFrame() = 0;

	/**
	 * @brief Determines if scaling is to be applied to video frame.
	 */
	static bool m_enableScaling;

signals:
	void close();

private:
	ApplicationWindow *m_appWin;
	static double m_pixelAspectRatio;
	static CropMethod m_cropMethod;
	QShortcut *m_hotkeyClose;
	QShortcut *m_hotkeyScaleReset;
	QShortcut *m_hotkeyExitFullscreen;
	QShortcut *m_hotkeyToggleFullscreen;
	QVBoxLayout *m_vboxLayout;
	unsigned m_vboxSpacing;
};
#endif

Privacy Policy