Debian Codegraph @

samples/qtvidcap/v4lxif.h

raw symbols SCIP
1 /*
2 kwintv, Video4Linux compatible KDE application
3
4 Copyright (C) 1998 Moritz Wenk ([email protected])
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #ifndef V4LIF_H
22 #define V4LIF_H
23
24 /* GUILESS should be defined if this interface will be used for a text-console
25 application - define it in config.h (using autoconf) */
26
27 #include <avm_default.h>
28 #include <avm_locker.h>
29 #include <avm_output.h>
30 #include "wintv.h"
31
32 #include <sys/types.h>
33
34 /* Necessary to prevent collisions between <linux/time.h> and <sys/time.h> when V4L2 is installed. */
35 #define _LINUX_TIME_H
36 #include <linux/videodev.h>
37
38 #define V4L_DEVICE "/dev/video"
39 #define V4L_VBI_DEVICE "/dev/vbi"
40
41 /* WANT_V4L_DEBUG should be set in config.h/autoconf */
42 #define MAXCLIPRECS 100
43
44 #define PALETTE(x) ((x < sizeof(device_pal)/sizeof(char*)) ? device_pal[x] : "UNKNOWN")
45
46 struct STRTAB {
47 int nr;
48 const char* str;
49 };
50
51 //--------------------------------------------------------------------------------
52 //--------------------- the virtual interface ------------------------------------
53 //--------------------------------------------------------------------------------
54
55 class v4lxif : public avm::AvmOutputLog {
56 public:
57 enum v4lxif_version { none, v4l1, v4l2 };
58
59 v4lxif(const char* _device = V4L_DEVICE, const char* _vbi_dev=V4L_VBI_DEVICE, v4lxif_version _ifv = v4l1);
60 virtual ~v4lxif();
61
62 v4lxif_version interface() { return ifv; }
63
64 bool hasvbi() { return (m_iDevVBI>=0); }
65 int getvbidev() { return m_iDevVBI; }
66 int readvbi(void* buf, unsigned int cnt);
67 // rest is virtual
68
69 virtual int init();
70 // set
71 virtual void setCapture( bool on) = 0; // de/activate overlay capturing
72 virtual void setFreq(unsigned long freq) = 0; // in 1/16th MHz
73
74 virtual void setPicBrightness(int bri) = 0; // -127 .. 127
75 virtual void setPicConstrast(int contr) = 0; // 0 .. 511
76 virtual void setPicColor(int color) = 0; // 0 .. 511
77 virtual void setPicHue(int hue) = 0; // -127 .. 127
78
79 virtual void setChannel(int source) = 0; // input source like Tuner, Camera
80 virtual void setChannelName(const char* name) = 0; // input channel, Tuner,
81 virtual void setChannelNorm(int norm) = 0; // VIDEO_TUNER_PAL, _NTSC, _SECAM, _AUTO
82
83 virtual void setTuner(int no) = 0; // Nr of Tuner (any card aviable with more than one ??)
84 virtual void setTunerMode(int norm) = 0; // (VIDEO_TUNER_PAL, _NTSC, _SECAM, _AUTO)
85
86 virtual void setAudioMute(bool on) = 0; // toggle mute
87 virtual void setAudioVolume(int vol) = 0; // set volume of TV card
88 virtual void setAudioBalance(int bal) = 0; // set balance
89 virtual void setAudioMode(int mode) = 0; // VIDEO_SOUND_MONO, _STEREO, _LANG1, _LANG2
90
91 virtual void setPalette(int pal) = 0; // set the pallette
92
93 // get
94 virtual bool getCapture() = 0; // overlay captureing enabled?
95
96 virtual int getChannelActive() = 0; // get active input source
97
98 virtual int getTunerActive() = 0; // get active tuner
99 virtual int getTunerMode() = 0; // VIDEO_MODE_PAL, _NTSC, _SECAM, _AUTO
100 virtual unsigned long getTunerSignal() = 0; // Signal strength if known - between 0-65535
101 virtual int getTunerFlags() = 0; // VIDEO_TUNER_*
102
103 virtual int getAudioActive() = 0; // get active audio
104 virtual bool getAudioMute() = 0; // get mute state
105 virtual int getAudioVolume() = 0; // get vol
106 virtual int getAudioBalance() = 0; //
107 virtual int getAudioMode() = 0; // VIDEO_SOUND_MONO, _STEREO, _LANG1, _LANG2
108
109 // getChannel
110 virtual int getChannelType() = 0; // VIDEO_TYPE_TV, _CAMERA
111 virtual int getChannelNorm() = 0; // norm set for this channel
112
113 // capAutio
114 virtual bool capAudioVolume() = 0; // tv card capable to set volume?
115 virtual bool capAudioMutable() = 0; // tv card capable to mute/unmute?
116
117 // capTuner
118 virtual bool capTunerStereo() = 0; // tuner sees stereo?
119 virtual bool capTunerNorm() = 0; // tuner has settable norm
120
121 // capChannel
122 virtual bool capChannelAudio(int no) = 0; // active channel has audio
123 virtual bool capChannelNorm(int no) = 0; // " has setable norm
124 virtual bool capChannelTuner(int no ) = 0; // " has a tv tuner
125 virtual char * capChannelName(int no) = 0; // name of channel
126
127 // capCap
128 virtual int capCapChannelC() = 0; // number of channels (= input devices)
129 virtual int capCapAudioC() = 0; // " of audios
130 virtual char * capCapName() = 0; // name of interface
131 virtual int capCapType() = 0; // type ", VID_TYPE_*
132 virtual void capCapSize(unsigned int *minw, /* TV screen min/max size */
133 unsigned int *minh,
134 unsigned int *maxw,
135 unsigned int *maxh) = 0;
136
137 // clipping stuff for capture area setup
138 virtual void resetCapAClip() = 0;
139 virtual int addCapAClip(int x1, int y1, unsigned int x2, unsigned int y2, int xadj=0, int yadj=0) = 0;
140 virtual int setCapAClip(int x,int y, unsigned int width, unsigned int height) = 0;
141 virtual void getCapAClip(int *x,int *y, unsigned int *width, unsigned int *height) = 0;
142 virtual int applyCapAClip(int nclips) = 0;
143 virtual bool changedCapAClip() = 0;
144
145 // additional
146 virtual int getWWidth() = 0;
147 virtual int getWHeight() = 0;
148
149 // frame buffer
150 virtual unsigned int getFBheight() = 0;
151 virtual unsigned int getFBwidth() = 0;
152 virtual unsigned int getFBdepth() = 0;
153 virtual unsigned int getFBbpl() = 0;
154
155 // capture image stuff
156 virtual bool grabSetParams(int width, int height, int palette) = 0;
157 virtual char * grabCapture(bool single) = 0; // single=false for stream captureing
158
159 virtual int isOk() =0;
160 protected:
161 v4lxif_version ifv;
162 avm::PthreadMutex m_Mutex;
163 const char* m_sDevice; // name of the video4linux-device
164 const char* m_sDeviceVBI; // name of the video4linux VBI device
165 int m_iDevVBI;
166 int m_iDevV4L; // the video4linux-device
167 };
168
169 //--------------------------------------------------------------------------------
170 //--------------------- the video 4 linux interface -------------------------------
171 //--------------------------------------------------------------------------------
172
173 class v4l1baseif : public v4lxif {
174 public:
175 v4l1baseif(const char* mem=0, const char * _device = V4L_DEVICE, int _bpp = 0, int _palette = 0);
176 v4l1baseif(int);
177 ~v4l1baseif();
178
179 virtual int init();
180
181 void setCapture(bool on);
182 void setFreq(unsigned long freq);
183
184 void setPicBrightness(int bri); // -127 .. 127
185 void setPicConstrast(int contr); // 0 .. 511
186 void setPicColor(int color); // 0 .. 511
187 void setPicHue(int hue); // -127 .. 127
188
189 void setChannel(int source); // input channel, Tuner,
190 void setChannelName(const char* name); // input channel, Tuner,
191 void setChannelNorm(int norm);
192
193 void setTuner(int no); // tuner, if more than one exists
194 void setTunerMode(int norm); // PAL, NTSC, SECAM, AUTO
195
196 void setAudio(int source);
197 void setAudioMute(bool on);
198 void setAudioVolume(int vol);
199 void setAudioBalance(int bal) {}
200 void setAudioMode(int mode);
201
202 virtual void setPalette(int pal);
203
204 bool getCapture() { return scapture; }
205
206 // getTuner
207 int getTunerActive() { return atuner; }
208 int getTunerMode();
209 unsigned long getTunerSignal();
210 int getTunerFlags();
211
212 // getAudio
213 int getAudioActive() { return aaudio; }
214 bool getAudioMute();
215 int getAudioVolume();
216 int getAudioBalance() { return 0; }
217 int getAudioMode();
218
219 // getChannel
220 int getChannelType() { return vchan[achan].type; }
221 int getChannelNorm() { return vchan[achan].norm; }
222 int getChannelActive() { return achan; }
223
224 // capAudio
225 bool capAudioVolume();
226 bool capAudioMutable();
227
228 // capTuner
229 bool capTunerStereo();
230 bool capTunerNorm();
231
232 // capChannel
233 bool capChannelAudio(int no) { return (vchan[no].flags & VIDEO_VC_AUDIO); }
234 bool capChannelNorm(int no) { return true; /*return vchan[no].flags & VIDEO_VC_NORM;*/ }
235 bool capChannelTuner(int no) { return (vchan[no].flags & VIDEO_VC_TUNER); }
236 char * capChannelName(int no) { return vchan[no].name; }
237
238 // capCap
239 int capCapChannelC() { return vcap.channels; }
240 int capCapAudioC() { return vcap.audios; }
241 char * capCapName() { return &(vcap.name[0]); }
242 int capCapType() { return vcap.type; }
243 void capCapSize(unsigned int *minw, unsigned int *minh, unsigned int *maxw, unsigned int *maxh);
244
245 // clipping stuff
246 void resetCapAClip() { nrofclips= 0; clipTabChanged= false; }
247 int addCapAClip(int x1, int y1, unsigned int x2, unsigned int y2, int xadj=0, int yadj=0);
248 int setCapAClip(int x, int y, unsigned int width, unsigned int height);
249 void getCapAClip(int *x, int *y, unsigned int *width, unsigned int *height);
250 int applyCapAClip(int nclips);
251 bool changedCapAClip() { return clipTabChanged; }
252
253 // additional
254 int getWWidth() { return vwin.width; }
255 int getWHeight() { return vwin.height; }
256
257 // frame buffer
258 unsigned int getFBheight() { return vbuf.height; }
259 unsigned int getFBwidth() { return vbuf.width; }
260 unsigned int getFBdepth() { return vbuf.depth; }
261 unsigned int getFBbpl() { return vbuf.bytesperline; }
262
263 // capture image stuff
264 bool grabSetParams(int width, int height, int palette);
265 char * grabCapture(bool single);
266
267 int isOk() {return _state;}
268 protected:
269 bool grabOne(int frame);
270 void grabWait(int frame);
271
272 // video 4 linux
273 // frame buffer
274 struct video_buffer vbuf;
275
276 // capabilities
277 struct video_capability vcap;
278 struct video_channel *vchan;
279 struct video_tuner vtuner;
280 struct video_picture vpic;
281 struct video_audio *vaudio;
282
283 // grabbing stuff
284 struct video_mmap vgrab[2];
285 struct video_mbuf vmbuf;
286 char * grabbermem; // memory for snapshot (was: unchar)
287 int msize; // size of memory for grabbermem
288
289 // capture area stuff
290 struct video_window vwin;
291 struct video_clip cliprecs[MAXCLIPRECS]; // list of clips
292 int nrofclips;
293
294 int m_iBpp;
295 int m_iPalette;
296
297 // additional
298 int achan; // the active channel set by setChannel()
299 int aaudio; // the active audio set by setAudio()
300 int atuner; // active tuner set by setTuner()
301
302 bool scapture, smute;
303
304 int gsync,ggrab;
305 bool geven;
306
307 bool setupok;
308
309 bool clipTabChanged;
310
311 int _state;
312 };
313
314 class v4l1if : public v4l1baseif {
315 public:
316 v4l1if(const char* mem = 0, const char * _device = V4L_DEVICE, int _bpp = 0, int _palette = 0);
317
318 virtual int init();
319 virtual void setPalette(int pal);
320
321 private:
322 unsigned int pixmap_bytes, x11_format;
323 };
324
325 #endif