]> git.vomp.tv Git - vompclient-marten.git/blob - video.cc
Widescreen support, segfault fix on livetv interrupt
[vompclient-marten.git] / video.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP 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     VOMP 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 VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "video.h"
22
23 Video* Video::instance = NULL;
24
25 Video::Video()
26 {
27   if (instance) return;
28   instance = this;
29   initted = 0;
30
31   fdVideo = 0;
32
33   format = 0;
34   connection = 0;
35   aspectRatio = 0;
36   mode = 0;
37
38   screenWidth = 0;
39   screenHeight = 0;
40 }
41
42 Video::~Video()
43 {
44   instance = NULL;
45 }
46
47 Video* Video::getInstance()
48 {
49   return instance;
50 }
51
52 int Video::init(UCHAR tformat)
53 {
54   if (initted) return 0;
55   initted = 1;
56
57   if ((fdVideo = open("/dev/vdec_dev", O_WRONLY)) < 0) return 0;
58
59   if (!setFormat(tformat))           { shutdown(); return 0; }
60   if (!setConnection(COMPOSITERGB))  { shutdown(); return 0; }
61   if (!setMode(NORMAL))              { shutdown(); return 0; }
62   if (!setAspectRatio(ASPECT4X3))    { shutdown(); return 0; }
63   if (!setSource())                  { shutdown(); return 0; }
64   if (!attachFrameBuffer())          { shutdown(); return 0; }
65
66   stop();
67
68   return 1;
69 }
70
71 int Video::reinit()
72 {
73   close(fdVideo);
74   if ((fdVideo = open("/dev/vdec_dev", O_WRONLY)) < 0) return 0;
75   if (!setSource())                  { shutdown(); return 0; }
76   if (!attachFrameBuffer())          { shutdown(); return 0; }
77
78   return 1;
79 }
80
81 int Video::shutdown()
82 {
83   if (!initted) return 0;
84   initted = 0;
85   close(fdVideo);
86   return 1;
87 }
88
89 int Video::checkSCART()
90 {
91   // Returns 3 for SCART Composite out
92   // Returns 3 for SCART S-Video out
93   // Returns 2 for SCART RGB out
94   // Returns 3 for SCART not plugged in
95
96   // So, as you can have RGB and composite out simultaneously,
97   // and it can't detect S-Video, what is the point of this?
98
99   int scart;
100   if (ioctl(fdVideo, AV_CHK_SCART, &scart) != 0) return -10;
101
102   return scart;
103 }
104
105 int Video::setFormat(UCHAR tformat)
106 {
107   if (!initted) return 0;
108   if ((tformat != PAL) && (tformat != NTSC)) return 0;
109   format = tformat;
110
111   if (ioctl(fdVideo, AV_SET_VID_DISP_FMT, format) != 0) return 0;
112
113   if (format == NTSC)
114   {
115     screenWidth = 720;
116     screenHeight = 480;
117   }
118   if (format == PAL)
119   {
120     screenWidth = 720;
121     screenHeight = 576;
122   }
123
124   return 1;
125 }
126
127 int Video::setConnection(UCHAR tconnection)
128 {
129   if (!initted) return 0;
130   if ((tconnection != COMPOSITERGB) && (tconnection != SVIDEO)) return 0;
131   connection = tconnection;
132
133   if (ioctl(fdVideo, AV_SET_VID_OUTPUT, connection) != 0) return 0;
134   return 1;
135 }
136
137 int Video::setAspectRatio(UCHAR taspectRatio)
138 {
139   if (!initted) return 0;
140   if ((taspectRatio != ASPECT4X3) && (taspectRatio != ASPECT16X9)) return 0;
141   aspectRatio = taspectRatio;
142
143   if (ioctl(fdVideo, AV_SET_VID_RATIO, aspectRatio) != 0) return 0;
144   return 1;
145 }
146
147 int Video::setMode(UCHAR tmode)
148 {
149   if (!initted) return 0;
150
151   if ((tmode != NORMAL) && (tmode != LETTERBOX) && (tmode != UNKNOWN2) && (tmode != QUARTER) && (tmode != EIGHTH)
152       && (tmode != ZOOM) && (tmode != UNKNOWN6)) return 0;
153   mode = tmode;
154
155   if (ioctl(fdVideo, AV_SET_VID_MODE, mode) != 0) return 0;
156
157 //  int a = ioctl(fdVideo, AV_SET_VID_MODE, mode);
158 //  printf("Mode requested: %i, result: %i\n", mode, a);
159
160   return 1;
161 }
162
163 #ifdef DEV
164 int Video::test()
165 {
166   return 0;
167
168 //  ULLONG stc = 0;
169 //  return ioctl(fdVideo, AV_SET_VID_STC, &stc);
170 /*
171  // reset();
172   return 1;
173 */
174 }
175
176 int Video::test2()
177 {
178   return 0;
179 }
180 #endif
181
182 int Video::signalOff()
183 {
184   if (ioctl(fdVideo, AV_SET_VID_DENC, 0) != 0) return 0;
185   return 1;
186 }
187
188 int Video::signalOn()
189 {
190   if (ioctl(fdVideo, AV_SET_VID_DENC, 1) != 0) return 0;
191   return 1;
192 }
193
194 int Video::setSource()
195 {
196   if (!initted) return 0;
197
198   // What does this do...
199   if (ioctl(fdVideo, AV_SET_VID_SRC, 1) != 0) return 0;
200   return 1;
201 }
202
203 int Video::setPosition(int x, int y)
204 {
205   if (!initted) return 0;
206
207   vid_pos_regs_t pos_d;
208   pos_d.x = x;
209   pos_d.y = y;
210
211 /*
212 typedef struct {
213   int w;
214   int h;
215   int scale;
216   int x1;
217   int y;
218   int x;
219   int y2;
220   int x3;
221   int y3;
222   int x4;
223   int y4;
224 } vid_pos_regs_t;
225 */
226
227 /*
228   pos_d.w = 100;
229   pos_d.h = 30;
230   pos_d.scale = 2;
231   pos_d.x1 = 0;
232   pos_d.y = 100;            // Top left X
233   pos_d.x = 50;            // Top left Y
234   pos_d.y2 = 30;
235   pos_d.x3 = 60;
236   pos_d.y3 = 90;
237   pos_d.x4 = 120;
238   pos_d.y4 = 150;
239 */
240
241   if (ioctl(fdVideo, AV_SET_VID_POSITION, &pos_d) != 0) return 0;
242   return 1;
243 }
244
245 int Video::sync()
246 {
247   if (!initted) return 0;
248
249   if (ioctl(fdVideo, AV_SET_VID_SYNC, 2) != 0) return 0;
250   return 1;
251 }
252
253 int Video::play()
254 {
255   if (!initted) return 0;
256
257   if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
258   return 1;
259 }
260
261 int Video::stop()
262 {
263   if (!initted) return 0;
264
265   if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
266   return 1;
267 }
268
269 int Video::reset()
270 {
271   if (!initted) return 0;
272
273   if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
274   return 1;
275 }
276
277 int Video::pause()
278 {
279   if (!initted) return 0;
280
281   if (ioctl(fdVideo, AV_SET_VID_PAUSE, 0) != 0) return 0;
282   return 1;
283 }
284
285 int Video::unPause() // FIXME get rid - same as play!!
286 {
287   if (!initted) return 0;
288   if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
289   return 1;
290 }
291
292 int Video::fastForward()
293 {
294   if (!initted) return 0;
295
296   if (ioctl(fdVideo, AV_SET_VID_FFWD, 1) != 0) return 0;
297   return 1;
298 }
299
300 int Video::unFastForward()
301 {
302   if (!initted) return 0;
303
304 //  if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
305
306   if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
307   return 1;
308 }
309
310 int Video::attachFrameBuffer()
311 {
312   if (!initted) return 0;
313
314   if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
315   return 1;
316 }
317
318 int Video::blank(void)
319 {
320   if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
321   if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
322   return 1;
323 }
324
325 int Video::getFD()
326 {
327   if (!initted) return 0;
328
329   return fdVideo;
330 }
331
332 UCHAR Video::getFormat()
333 {
334   return format;
335 }
336
337 UINT Video::getScreenWidth()
338 {
339   return screenWidth;
340 }
341
342 UINT Video::getScreenHeight()
343 {
344   return screenHeight;
345 }
346
347 UCHAR Video::getAspectRatio()
348 {
349   return aspectRatio;
350 }