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