Compile on OpenSolaris
[kdenetwork.git] / kopete / libkopete / avdevice / videodevice.h
blobac21e33f2f627c2e684358eb77fca0a5bc9a7ccf
1 /*
2 videodevice.cpp - Kopete Video Device Low-level Support
4 Copyright (c) 2005-2006 by Cláudio da Silveira Pinheiro <taupter@gmail.com>
6 Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
8 *************************************************************************
9 * *
10 * This library is free software; you can redistribute it and/or *
11 * modify it under the terms of the GNU Lesser General Public *
12 * License as published by the Free Software Foundation; either *
13 * version 2 of the License, or (at your option) any later version. *
14 * *
15 *************************************************************************
18 #define ENABLE_AV
20 #ifndef KOPETE_AVVIDEODEVICELISTITEM_H
21 #define KOPETE_AVVIDEODEVICELISTITEM_H
23 #include <config-kopete.h>
25 #include <sys/time.h>
26 #include <sys/mman.h>
27 #include <sys/ioctl.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <unistd.h>
32 #include <signal.h>
34 #if defined(__linux__) && defined(ENABLE_AV)
36 #include <asm/types.h>
37 #undef __STRICT_ANSI__
38 #ifndef __u64 //required by videodev.h
39 #define __u64 unsigned long long
40 #endif // __u64
41 #ifndef __s64 //required by videodev.h
42 #define __s64 signed long long
43 #endif // __s64
44 #ifndef __s32 //required by videodev.h
45 #define __s32 signed long
46 #endif // __s32
49 #ifndef pgoff_t
50 #define pgoff_t unsigned long
51 #endif
53 #include <linux/fs.h>
54 #include <linux/kernel.h>
55 #include <linux/videodev.h>
56 #define VIDEO_MODE_PAL_Nc 3
57 #define VIDEO_MODE_PAL_M 4
58 #define VIDEO_MODE_PAL_N 5
59 #define VIDEO_MODE_NTSC_JP 6
60 #define __STRICT_ANSI__
62 #endif // __linux__
64 #include <qstring.h>
65 #include <qfile.h>
66 #include <qimage.h>
67 #include <q3valuevector.h>
68 #include <kcombobox.h>
70 #include "videoinput.h"
72 namespace Kopete {
74 namespace AV {
76 /**
77 @author Kopete Developers
79 typedef enum
81 VIDEODEV_DRIVER_NONE
82 #if defined( __linux__) && defined(ENABLE_AV)
84 VIDEODEV_DRIVER_V4L
85 #ifdef V4L2_CAP_VIDEO_CAPTURE
87 VIDEODEV_DRIVER_V4L2
88 #endif
89 #endif
90 } videodev_driver;
92 typedef enum
94 // Packed RGB formats
95 PIXELFORMAT_NONE = 0,
96 PIXELFORMAT_GREY = (1 << 0),
97 PIXELFORMAT_RGB332 = (1 << 1),
98 PIXELFORMAT_RGB444 = (1 << 2),
99 PIXELFORMAT_RGB555 = (1 << 3),
100 PIXELFORMAT_RGB565 = (1 << 4),
101 PIXELFORMAT_RGB555X = (1 << 5),
102 PIXELFORMAT_RGB565X = (1 << 6),
103 PIXELFORMAT_BGR24 = (1 << 7),
104 PIXELFORMAT_RGB24 = (1 << 8),
105 PIXELFORMAT_BGR32 = (1 << 9),
106 PIXELFORMAT_RGB32 = (1 << 10),
108 // Bayer RGB format
109 PIXELFORMAT_SBGGR8 = (1 << 11),
111 // YUV formats
112 PIXELFORMAT_YUYV = (1 << 12),
113 PIXELFORMAT_UYVY = (1 << 13),
114 PIXELFORMAT_YUV420P = (1 << 14),
115 PIXELFORMAT_YUV422P = (1 << 15),
117 // Compressed formats
118 PIXELFORMAT_JPEG = (1 << 16),
119 PIXELFORMAT_MPEG = (1 << 17),
121 // Reserved formats
122 PIXELFORMAT_DV = (1 << 18),
123 PIXELFORMAT_ET61X251 = (1 << 19),
124 PIXELFORMAT_HI240 = (1 << 20),
125 PIXELFORMAT_HM12 = (1 << 21),
126 PIXELFORMAT_MJPEG = (1 << 22),
127 PIXELFORMAT_PWC1 = (1 << 23),
128 PIXELFORMAT_PWC2 = (1 << 24),
129 PIXELFORMAT_SN9C10X = (1 << 25),
130 PIXELFORMAT_WNVA = (1 << 26),
131 PIXELFORMAT_YYUV = (1 << 27)
133 // PIXELFORMAT_ALL = 0x00003FFF
134 } pixel_format;
136 typedef enum
138 // One bit for each
139 STANDARD_PAL_B = (1 << 0),
140 STANDARD_PAL_B1 = (1 << 1),
141 STANDARD_PAL_G = (1 << 2),
142 STANDARD_PAL_H = (1 << 3),
143 STANDARD_PAL_I = (1 << 4),
144 STANDARD_PAL_D = (1 << 5),
145 STANDARD_PAL_D1 = (1 << 6),
146 STANDARD_PAL_K = (1 << 7),
148 STANDARD_PAL_M = (1 << 8),
149 STANDARD_PAL_N = (1 << 9),
150 STANDARD_PAL_Nc = (1 << 10),
151 STANDARD_PAL_60 = (1 << 11),
152 // 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.
154 STANDARD_NTSC_M = (1 << 12),
155 STANDARD_NTSC_M_JP = (1 << 13),
156 STANDARD_NTSC_443 = (1 << 14),
157 // 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.
158 STANDARD_NTSC_M_KR = (1 << 15),
160 STANDARD_SECAM_B = (1 << 16),
161 STANDARD_SECAM_D = (1 << 17),
162 STANDARD_SECAM_G = (1 << 18),
163 STANDARD_SECAM_H = (1 << 19),
164 STANDARD_SECAM_K = (1 << 20),
165 STANDARD_SECAM_K1 = (1 << 21),
166 STANDARD_SECAM_L = (1 << 22),
167 STANDARD_SECAM_LC = (1 << 23),
169 // ATSC/HDTV
170 STANDARD_ATSC_8_VSB = (1 << 24),
171 STANDARD_ATSC_16_VSB = (1 << 25),
173 // Some common needed stuff
174 STANDARD_PAL_BG = ( STANDARD_PAL_B | STANDARD_PAL_B1 | STANDARD_PAL_G ),
175 STANDARD_PAL_DK = ( STANDARD_PAL_D | STANDARD_PAL_D1 | STANDARD_PAL_K ),
176 STANDARD_PAL = ( STANDARD_PAL_BG | STANDARD_PAL_DK | STANDARD_PAL_H | STANDARD_PAL_I ),
177 STANDARD_NTSC = ( STANDARD_NTSC_M | STANDARD_NTSC_M_JP| STANDARD_NTSC_M_KR ),
178 STANDARD_SECAM_DK = ( STANDARD_SECAM_D | STANDARD_SECAM_K | STANDARD_SECAM_K1 ),
179 STANDARD_SECAM = ( STANDARD_SECAM_B | STANDARD_SECAM_G | STANDARD_SECAM_H | STANDARD_SECAM_DK | STANDARD_SECAM_L | STANDARD_SECAM_LC ),
181 // some merged standards */
182 STANDARD_MN = ( STANDARD_PAL_M | STANDARD_PAL_N | STANDARD_PAL_Nc | STANDARD_NTSC ),
183 STANDARD_B = ( STANDARD_PAL_B | STANDARD_PAL_B1 | STANDARD_SECAM_B ),
184 STANDARD_GH = ( STANDARD_PAL_G | STANDARD_PAL_H | STANDARD_SECAM_G | STANDARD_SECAM_H ),
185 STANDARD_DK = ( STANDARD_PAL_DK | STANDARD_SECAM_DK ),
187 STANDARD_525_60 = ( STANDARD_PAL_M | STANDARD_PAL_60 | STANDARD_NTSC | STANDARD_NTSC_443),
188 STANDARD_625_50 = ( STANDARD_PAL | STANDARD_PAL_N | STANDARD_PAL_Nc | STANDARD_SECAM),
189 STANDARD_ATSC = ( STANDARD_ATSC_8_VSB | STANDARD_ATSC_16_VSB ),
191 STANDARD_UNKNOWN = 0,
192 STANDARD_ALL = ( STANDARD_525_60 | STANDARD_625_50)
193 } signal_standard;
196 typedef enum
198 IO_METHOD_NONE,
199 IO_METHOD_READ,
200 IO_METHOD_MMAP,
201 IO_METHOD_USERPTR
202 } io_method;
204 struct imagebuffer
206 int height;
207 int width;
208 pixel_format pixelformat;
209 QVector <uchar> data; // maybe it should be a rawbuffer instead of it? It could make us avoid a memory copy
211 struct rawbuffer // raw buffer
213 uchar * start;
214 size_t length;
218 class VideoDevice{
219 public:
220 VideoDevice();
221 ~VideoDevice();
222 int setFileName(QString filename);
223 int open();
224 bool isOpen();
225 int checkDevice();
226 int showDeviceCapabilities();
227 int initDevice();
228 int inputs();
229 int width();
230 int minWidth();
231 int maxWidth();
232 int height();
233 int minHeight();
234 int maxHeight();
235 int setSize( int newwidth, int newheight);
237 pixel_format setPixelFormat(pixel_format newformat);
238 int pixelFormatCode(pixel_format pixelformat);
239 pixel_format pixelFormatForPalette( int palette );
240 int pixelFormatDepth(pixel_format pixelformat);
241 QString pixelFormatName(pixel_format pixelformat);
242 QString pixelFormatName(int pixelformat);
243 int detectPixelFormats();
245 __u64 signalStandardCode(signal_standard standard);
246 QString signalStandardName(signal_standard standard);
247 QString signalStandardName(int standard);
248 int detectSignalStandards();
250 int currentInput();
251 int selectInput(int input);
252 int setInputParameters();
253 int startCapturing();
254 int getFrame();
255 int getFrame(imagebuffer *imgbuffer);
256 int getImage(QImage *qimage);
257 int stopCapturing();
258 int close();
260 float getBrightness();
261 float setBrightness(float brightness);
262 float getContrast();
263 float setContrast(float contrast);
264 float getSaturation();
265 float setSaturation(float saturation);
266 float getWhiteness();
267 float setWhiteness(float whiteness);
268 float getHue();
269 float setHue(float Hue);
271 bool getAutoBrightnessContrast();
272 bool setAutoBrightnessContrast(bool brightnesscontrast);
273 bool getAutoColorCorrection();
274 bool setAutoColorCorrection(bool colorcorrection);
275 bool getImageAsMirror();
276 bool setImageAsMirror(bool imageasmirror);
278 bool canCapture();
279 bool canChromakey();
280 bool canScale();
281 bool canOverlay();
282 bool canRead();
283 bool canAsyncIO();
284 bool canStream();
286 void setUdi( const QString & );
287 QString udi() const;
288 QString m_model;
289 QString m_name;
290 size_t m_modelindex; // Defines what's the number of a device when more than 1 device of a given model is present;
291 QString full_filename;
292 videodev_driver m_driver;
293 int descriptor;
295 //protected:
296 #if defined(__linux__) && defined(ENABLE_AV)
297 #ifdef V4L2_CAP_VIDEO_CAPTURE
298 struct v4l2_capability V4L2_capabilities;
299 struct v4l2_cropcap cropcap;
300 struct v4l2_crop crop;
301 struct v4l2_format fmt;
302 struct v4l2_fmtdesc fmtdesc; // Not sure if it must be here or inside detectPixelFormats(). Should inve
303 // struct v4l2_input m_input;
304 struct v4l2_queryctrl queryctrl;
305 struct v4l2_querymenu querymenu;
306 void enumerateMenu (void);
307 #endif
308 struct video_capability V4L_capabilities;
309 struct video_buffer V4L_videobuffer;
310 #endif
311 QVector<Kopete::AV::VideoInput> m_input;
312 // QFile file;
313 protected:
314 int currentwidth, minwidth, maxwidth, currentheight, minheight, maxheight;
316 QVector<rawbuffer> m_rawbuffers;
317 unsigned int m_streambuffers;
318 imagebuffer m_currentbuffer;
319 int m_buffer_size;
321 int m_current_input;
322 pixel_format m_pixelformat;
324 io_method m_io_method;
325 bool m_videocapture;
326 bool m_videochromakey;
327 bool m_videoscale;
328 bool m_videooverlay;
329 bool m_videoread;
330 bool m_videoasyncio;
331 bool m_videostream;
333 int xioctl(int request, void *arg);
334 int errnoReturn(const char* s);
335 int initRead();
336 int initMmap();
337 int initUserptr();
339 QString m_udi;
346 #endif