Debian Codegraph @

utils/qv4l2/capture-win.h

raw
1 /* qv4l2: a control panel controlling v4l2 devices.
2 *
3 * Copyright (C) 2006 Hans Verkuil <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #ifndef CAPTURE_WIN_H
21 #define CAPTURE_WIN_H
22
23 #include "qv4l2.h"
24
25 #include <QWidget>
26 #include <QShortcut>
27 #include <QLabel>
28 #include <QPushButton>
29 #include <QMenu>
30
31 enum CropMethod {
32 // Crop Height
33 QV4L2_CROP_NONE,
34 QV4L2_CROP_W149,
35 QV4L2_CROP_W169,
36 QV4L2_CROP_C185,
37 QV4L2_CROP_C239,
38 QV4L2_CROP_TB,
39
40 // Crop Width
41 QV4L2_CROP_P43,
42 };
43
44 struct frame {
45 __u32 format;
46 QSize size; // int frameHeight; int frameWidth;
47 unsigned char *planeData[3];
48 bool updated;
49 };
50
51 struct crop { // cropInfo
52 QSize delta; // int cropH; int cropW;
53 QSize size; // int height; int width;
54 bool updated;
55 };
56
57 class ApplicationWindow;
58
59 class CaptureWin : public QWidget
60 {
61 Q_OBJECT
62
63 public:
64 CaptureWin(ApplicationWindow *aw);
65 ~CaptureWin();
66
67 void setWindowSize(QSize size);
68 void enableScaling(bool enable);
69 void setPixelAspectRatio(double ratio);
70 float getHorScaleFactor();
71 float getVertScaleFactor();
72 virtual void setColorspace(unsigned colorspace, unsigned xfer_func,
73 unsigned ycbcr_enc, unsigned quantization, bool is_sdtv) = 0;
74 virtual void setField(unsigned field) = 0;
75 virtual void setBlending(bool enable) = 0;
76 virtual void setLinearFilter(bool enable) = 0;
77 void setCropMethod(CropMethod crop);
78 void makeFullScreen(bool);
79 QAction *m_exitFullScreen;
80 QAction *m_enterFullScreen;
81 QAction *m_closeWindowAct;
82
83 /**
84 * @brief Set a frame into the capture window.
85 *
86 * When called the capture stream is
87 * either already running or starting for the first time.
88 *
89 * @param width Frame width in pixels
90 * @param height Frame height in pixels
91 * @param format The frame's format, given as a V4L2_PIX_FMT.
92 * @param data The frame data.
93 * @param info A string containing capture information.
94 */
95 void setFrame(int width, int height, __u32 format,
96 unsigned char *data, unsigned char *data2, unsigned char *data3);
97
98 /**
99 * @brief Called when the capture stream is stopped.
100 */
101 virtual void stop() = 0;
102
103 /**
104 * @brief Queries the current capture window for its supported formats.
105 *
106 * Unsupported formats are converted by v4lconvert_convert().
107 *
108 * @param format The frame format question, given as a V4L2_PIX_FMT.
109 * @return true if the format is supported, false if not.
110 */
111 virtual bool hasNativeFormat(__u32 format) = 0;
112
113 /**
114 * @brief Defines wether a capture window is supported.
115 *
116 * By default nothing is supported, but derived classes can override this.
117 *
118 * @return true if the capture window is supported on the system, false if not.
119 */
120 static bool isSupported() { return false; }
121
122 /**
123 * @brief Return the scaled size.
124 *
125 * Scales a frame to fit inside a given window. Preserves aspect ratio.
126 *
127 * @param window The window the frame shall scale into
128 * @param frame The frame to scale
129 * @return The scaledsizes to use for the frame
130 */
131 static QSize scaleFrameSize(QSize window, QSize frame);
132
133 /**
134 * @brief Crop size
135 *
136 * Reduces size width or height according to m_cropMethod
137 *
138 * @param size Input size
139 * @return Cropped size
140 *
141 */
142 static QSize cropSize(QSize size);
143
144 /**
145 * @brief Get the frame size when aspect ratio is applied and increases size.
146 *
147 * @param size The original frame size.
148 * @return The new size with aspect ratio correction (scaling must be enabled).
149 */
150 static QSize pixelAspectFrameSize(QSize size);
151
152 public slots:
153 void resetSize();
154 void customMenuRequested(QPoint pos);
155
156 private slots:
157 void escape();
158 void fullScreen();
159
160 protected:
161 void closeEvent(QCloseEvent *event);
162 void mouseDoubleClickEvent(QMouseEvent *e);
163
164 /**
165 * @brief Get the amount of space outside the video frame.
166 *
167 * The margins are that of the window that encloses the displaying
168 * video frame. The sizes are total in both width and height.
169 *
170 * @return The margins around the video frame.
171 */
172 QSize getMargins();
173
174 /**
175 * @brief Creates the content of the window.
176 *
177 * Construct the new window layout and adds the video display surface.
178 * @param videoSurface The widget that contains the renderer.
179 */
180 void buildWindow(QWidget *videoSurface);
181
182 /**
183 * @brief Calculate source size after pixel aspect scaling and cropping
184 *
185 */
186 void updateSize();
187
188 /**
189 * @brief Frame information.
190 *
191 * @note Set and accessed from derived render dependent classes.
192 */
193 struct frame m_frame;
194 struct crop m_crop;
195 QSize m_origFrameSize; // int m_sourceWinWidth; int m_sourceWinHeight;
196 QSize m_windowSize; // int m_curWinWidth; int m_curWinHeight;
197 QSize m_scaledSize;
198
199 /**
200 * @brief Update frame information to renderer.
201 *
202 * @note Must be implemented by derived render dependent classes.
203 */
204 virtual void setRenderFrame() = 0;
205
206 /**
207 * @brief Determines if scaling is to be applied to video frame.
208 */
209 static bool m_enableScaling;
210
211 signals:
212 void close();
213
214 private:
215 ApplicationWindow *m_appWin;
216 static double m_pixelAspectRatio;
217 static CropMethod m_cropMethod;
218 QShortcut *m_hotkeyScaleReset;
219 QShortcut *m_hotkeyExitFullscreen;
220 QShortcut *m_hotkeyToggleFullscreen;
221 QVBoxLayout *m_vboxLayout;
222 unsigned m_vboxSpacing;
223 };
224 #endif