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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
/*
videodevice.cpp - Kopete Video Device Low-level Support
Copyright (c) 2005-2006 by Cláudio da Silveira Pinheiro <taupter@gmail.com>
Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
*************************************************************************
*/
#ifndef KOPETE_AVVIDEODEVICELISTITEM_H
#define KOPETE_AVVIDEODEVICELISTITEM_H
#define ENABLE_AV
#if defined HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#if (defined(__linux__) || defined(__FreeBSD__)) && defined(ENABLE_AV)
#if defined HAVE_LINUX_VIDEODEV_H
#include <linux/videodev.h>
#endif
#if defined(__linux__)
#include <asm/types.h>
#endif
#undef __STRICT_ANSI__
#ifndef __u64 //required by videodev.h
#define __u64 unsigned long long
#endif // __u64
#ifndef __s64 //required by videodev.h
#define __s64 long long
#endif // __s64
#ifndef pgoff_t
#define pgoff_t unsigned long
#endif
#if defined(__linux__)
#include <linux/fs.h>
#include <linux/kernel.h>
#endif
#if defined(HAVE_LIBV4L1_VIDEODEV_H)
#include <libv4l1-videodev.h>
#elif defined(HAVE_LINUX_VIDEODEV_H)
#include <linux/videodev.h>
#else
#undef ENABLE_AV
#endif
#define VIDEO_MODE_PAL_Nc 3
#define VIDEO_MODE_PAL_M 4
#define VIDEO_MODE_PAL_N 5
#define VIDEO_MODE_NTSC_JP 6
#define __STRICT_ANSI__
#endif // __linux__
#include <tqstring.h>
#include <tqfile.h>
#include <tqimage.h>
#include <tqvaluevector.h>
#include <kcombobox.h>
#include "videoinput.h"
#include "videocontrol.h"
namespace Kopete {
namespace AV {
/**
@author Kopete Developers
*/
typedef enum
{
VIDEODEV_DRIVER_NONE
#if (defined(__linux__) || defined(__FreeBSD__)) && defined(ENABLE_AV)
,
VIDEODEV_DRIVER_V4L
#ifdef V4L2_CAP_VIDEO_CAPTURE
,
VIDEODEV_DRIVER_V4L2
#endif
#endif
} videodev_driver;
typedef enum
{
// Packed RGB formats
PIXELFORMAT_NONE = 0,
PIXELFORMAT_GREY = (1 << 0),
PIXELFORMAT_RGB332 = (1 << 1),
PIXELFORMAT_RGB444 = (1 << 2),
PIXELFORMAT_RGB555 = (1 << 3),
PIXELFORMAT_RGB565 = (1 << 4),
PIXELFORMAT_RGB555X = (1 << 5),
PIXELFORMAT_RGB565X = (1 << 6),
PIXELFORMAT_BGR24 = (1 << 7),
PIXELFORMAT_RGB24 = (1 << 8),
PIXELFORMAT_BGR32 = (1 << 9),
PIXELFORMAT_RGB32 = (1 << 10),
// Bayer RGB format
PIXELFORMAT_SBGGR8 = (1 << 11),
// YUV formats
PIXELFORMAT_YUYV = (1 << 12),
PIXELFORMAT_UYVY = (1 << 13),
PIXELFORMAT_YUV420P = (1 << 14),
PIXELFORMAT_YUV422P = (1 << 15),
// Compressed formats
PIXELFORMAT_JPEG = (1 << 16),
PIXELFORMAT_MPEG = (1 << 17),
// Reserved formats
PIXELFORMAT_DV = (1 << 18),
PIXELFORMAT_ET61X251 = (1 << 19),
PIXELFORMAT_HI240 = (1 << 20),
PIXELFORMAT_HM12 = (1 << 21),
PIXELFORMAT_MJPEG = (1 << 22),
PIXELFORMAT_PWC1 = (1 << 23),
PIXELFORMAT_PWC2 = (1 << 24),
PIXELFORMAT_SN9C10X = (1 << 25),
PIXELFORMAT_WNVA = (1 << 26),
PIXELFORMAT_YYUV = (1 << 27)
// PIXELFORMAT_ALL = 0x00003FFF
} pixel_format;
typedef enum
{
STANDARD_NONE = 0,
STANDARD_PAL_B = (1 << 0),
STANDARD_PAL_B1 = (1 << 1),
STANDARD_PAL_G = (1 << 2),
STANDARD_PAL_H = (1 << 3),
STANDARD_PAL_I = (1 << 4),
STANDARD_PAL_D = (1 << 5),
STANDARD_PAL_D1 = (1 << 6),
STANDARD_PAL_K = (1 << 7),
STANDARD_PAL_M = (1 << 8),
STANDARD_PAL_N = (1 << 9),
STANDARD_PAL_Nc = (1 << 10),
STANDARD_PAL_60 = (1 << 11),
// STANDARD_PAL_60 is a hybrid standard with 525 lines, 60 Hz refresh rate, and PAL color modulation with a 4.43 MHz color subcarrier. Some PAL video recorders can play back NTSC tapes in this mode for display on a 50/60 Hz agnostic PAL TV.
STANDARD_NTSC_M = (1 << 12),
STANDARD_NTSC_M_JP = (1 << 13),
STANDARD_NTSC_443 = (1 << 14),
// STANDARD_NTSC_443 is a hybrid standard with 525 lines, 60 Hz refresh rate, and NTSC color modulation with a 4.43 MHz color subcarrier.
STANDARD_SECAM_B = (1 << 16),
STANDARD_SECAM_D = (1 << 17),
STANDARD_SECAM_G = (1 << 18),
STANDARD_SECAM_H = (1 << 19),
STANDARD_SECAM_K = (1 << 20),
STANDARD_SECAM_K1 = (1 << 21),
STANDARD_SECAM_L = (1 << 22),
STANDARD_SECAM_LC = (1 << 23),
// ATSC/HDTV
STANDARD_ATSC_8_VSB = (1 << 24),
STANDARD_ATSC_16_VSB = (1 << 25),
STANDARD_PAL_BG = ( STANDARD_PAL_B | STANDARD_PAL_B1 | STANDARD_PAL_G ),
STANDARD_PAL_DK = ( STANDARD_PAL_D | STANDARD_PAL_D1 | STANDARD_PAL_K ),
STANDARD_PAL = ( STANDARD_PAL_BG | STANDARD_PAL_DK | STANDARD_PAL_H | STANDARD_PAL_I ),
STANDARD_NTSC = ( STANDARD_NTSC_M | STANDARD_NTSC_M_JP ),
STANDARD_SECAM_DK = ( STANDARD_SECAM_D | STANDARD_SECAM_K | STANDARD_SECAM_K1 ),
STANDARD_SECAM = ( STANDARD_SECAM_B | STANDARD_SECAM_G | STANDARD_SECAM_H | STANDARD_SECAM_DK | STANDARD_SECAM_L),
STANDARD_525_60 = ( STANDARD_PAL_M | STANDARD_PAL_60 | STANDARD_NTSC | STANDARD_NTSC_443),
STANDARD_625_50 = ( STANDARD_PAL | STANDARD_PAL_N | STANDARD_PAL_Nc | STANDARD_SECAM),
STANDARD_ALL = ( STANDARD_525_60 | STANDARD_625_50)
} signal_standard;
typedef enum
{
IO_METHOD_NONE,
IO_METHOD_READ,
IO_METHOD_MMAP,
IO_METHOD_USERPTR
} io_method;
struct imagebuffer
{
int height;
int width;
pixel_format pixelformat;
TQValueVector <uchar> data; // maybe it should be a rawbuffer instead of it? It could make us avoid a memory copy
};
struct rawbuffer // raw buffer
{
uchar * start;
size_t length;
};
class VideoDevice{
public:
VideoDevice();
~VideoDevice();
int setFileName(TQString filename);
int open();
bool isOpen();
int checkDevice();
int showDeviceCapabilities();
int initDevice();
unsigned int inputs();
int width();
int minWidth();
int maxWidth();
int height();
int minHeight();
int maxHeight();
int setSize( int newwidth, int newheight);
pixel_format setPixelFormat(pixel_format newformat);
int pixelFormatCode(pixel_format pixelformat);
pixel_format pixelFormatForPalette( int palette );
int pixelFormatDepth(pixel_format pixelformat);
TQString pixelFormatName(pixel_format pixelformat);
TQString pixelFormatName(int pixelformat);
int detectPixelFormats();
__u64 signalStandardCode(signal_standard standard);
TQString signalStandardName(signal_standard standard);
TQString signalStandardName(int standard);
int detectSignalStandards();
int currentInput();
int selectInput(int input);
int setInputParameters();
int startCapturing();
int getFrame();
int getFrame(imagebuffer *imgbuffer);
int getImage(TQImage *qimage);
int stopCapturing();
int close();
float getBrightness();
float setBrightness(float brightness);
float getContrast();
float setContrast(float contrast);
float getSaturation();
float setSaturation(float saturation);
float getWhiteness();
float setWhiteness(float whiteness);
float getHue();
float setHue(float Hue);
bool getAutoBrightnessContrast();
bool setAutoBrightnessContrast(bool brightnesscontrast);
bool getAutoColorCorrection();
bool setAutoColorCorrection(bool colorcorrection);
bool getImageAsMirror();
bool setImageAsMirror(bool imageasmirror);
bool canCapture();
bool canChromakey();
bool canScale();
bool canOverlay();
bool canRead();
bool canAsyncIO();
bool canStream();
TQString m_model;
TQString m_name;
size_t m_modelindex; // Defines what's the number of a device when more than 1 device of a given model is present;
TQString full_filename;
videodev_driver m_driver;
int descriptor;
//protected:
#if (defined(__linux__) || defined(__FreeBSD__)) && defined(ENABLE_AV)
#ifdef V4L2_CAP_VIDEO_CAPTURE
struct v4l2_capability V4L2_capabilities;
struct v4l2_cropcap cropcap;
struct v4l2_crop crop;
struct v4l2_format fmt;
struct v4l2_fmtdesc fmtdesc; // Not sure if it must be here or inside detectPixelFormats(). Should inve
// struct v4l2_input m_input;
struct v4l2_queryctrl queryctrl;
struct v4l2_querymenu querymenu;
void enumerateMenu (void);
#endif
#ifdef ENABLE_AV
struct video_capability V4L_capabilities;
struct video_buffer V4L_videobuffer;
#endif
#endif
TQValueVector<Kopete::AV::VideoInput> m_input;
TQValueVector<Kopete::AV::VideoControl> m_control;
// TQFile file;
protected:
int currentwidth, minwidth, maxwidth, currentheight, minheight, maxheight;
bool m_disablemmap;
bool m_workaroundbrokendriver;
TQValueVector<rawbuffer> m_rawbuffers;
unsigned int m_streambuffers;
imagebuffer m_currentbuffer;
int m_buffer_size;
int m_current_input;
pixel_format m_pixelformat;
io_method m_io_method;
bool m_videocapture;
bool m_videochromakey;
bool m_videoscale;
bool m_videooverlay;
bool m_videoread;
bool m_videoasyncio;
bool m_videostream;
int xioctl(int request, void *arg);
int errnoReturn(const char* s);
int initRead();
int initMmap();
int initUserptr();
};
}
}
#endif
|