]> git.vomp.tv Git - vompclient-marten.git/blob - video.cc
Clean up of all video init system, NTSC/PAL, screen size functions.
[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 (!setAspectRatio(ASPECT4X3))    { shutdown(); return 0; }
62   if (!setMode(NORMAL))              { 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::shutdown()
72 {
73   if (!initted) return 0;
74   initted = 0;
75   close(fdVideo);
76   return 1;
77 }
78
79 int Video::write(char *buf, int len)
80 {
81   return 1;//write(fdVideo, buf, len);
82 }
83
84 int Video::checkSCART()
85 {
86   // Returns 3 for SCART Composite out
87   // Returns 3 for SCART S-Video out
88   // Returns 2 for SCART RGB out
89   // Returns 3 for SCART not plugged in
90
91   // So, as you can have RGB and composite out simultaneously,
92   // and it can't detect S-Video, what is the point of this?
93
94   int scart;
95   if (ioctl(fdVideo, AV_CHK_SCART, &scart) != 0) return -10;
96
97   return scart;
98 }
99
100 int Video::setFormat(UCHAR tformat)
101 {
102   if (!initted) return 0;
103   if ((tformat != PAL) && (tformat != NTSC)) return 0;
104   format = tformat;
105
106   if (ioctl(fdVideo, AV_SET_VID_DISP_FMT, format) != 0) return 0;
107
108   if (format == NTSC)
109   {
110     screenWidth = 720;
111     screenHeight = 480;
112   }
113   if (format == PAL)
114   {
115     screenWidth = 720;
116     screenHeight = 576;
117   }
118
119   return 1;
120 }
121
122 int Video::setConnection(UCHAR tconnection)
123 {
124   if (!initted) return 0;
125   if ((tconnection != COMPOSITERGB) && (tconnection != SVIDEO)) return 0;
126   connection = tconnection;
127
128   if (ioctl(fdVideo, AV_SET_VID_OUTPUT, connection) != 0) return 0;
129   return 1;
130 }
131
132 int Video::setAspectRatio(UCHAR taspectRatio)
133 {
134   if (!initted) return 0;
135   if ((taspectRatio != ASPECT4X3) && (taspectRatio != ASPECT16X9)) return 0;
136   aspectRatio = taspectRatio;
137
138   if (ioctl(fdVideo, AV_SET_VID_RATIO, aspectRatio) != 0) return 0;
139   return 1;
140 }
141
142 int Video::setMode(UCHAR tmode)
143 {
144   if (!initted) return 0;
145
146   if ((tmode != NORMAL) && (tmode != LETTERBOX) && (tmode != UNKNOWN2) && (tmode != QUARTER) && (tmode != EIGHTH)
147       && (tmode != ZOOM) && (tmode != UNKNOWN6)) return 0;
148   mode = tmode;
149
150 //  mode = LETTERBOX;
151
152   if (ioctl(fdVideo, AV_SET_VID_MODE, mode) != 0) return 0;
153   return 1;
154 }
155
156 int Video::test()
157 {
158   return 0;
159
160 //  ULLONG stc = 0;
161 //  return ioctl(fdVideo, AV_SET_VID_STC, &stc);
162 /*
163  // reset();
164   return 1;
165 */
166 }
167
168 int Video::test2()
169 {
170   return 0;
171 }
172
173
174
175 int Video::signalOff()
176 {
177   if (ioctl(fdVideo, AV_SET_VID_DENC, 0) != 0) return 0;
178   return 1;
179 }
180
181 int Video::signalOn()
182 {
183   if (ioctl(fdVideo, AV_SET_VID_DENC, 1) != 0) return 0;
184   return 1;
185 }
186
187 int Video::setSource()
188 {
189   if (!initted) return 0;
190
191   // What does this do...
192   if (ioctl(fdVideo, AV_SET_VID_SRC, 1) != 0) return 0;
193   return 1;
194 }
195
196 int Video::setPosition(int x, int y)
197 {
198   if (!initted) return 0;
199
200   vid_pos_regs_t pos_d;
201   pos_d.x = x;
202   pos_d.y = y;
203
204 /*
205 typedef struct {
206   int w;
207   int h;
208   int scale;
209   int x1;
210   int y;
211   int x;
212   int y2;
213   int x3;
214   int y3;
215   int x4;
216   int y4;
217 } vid_pos_regs_t;
218 */
219
220 /*
221   pos_d.w = 100;
222   pos_d.h = 30;
223   pos_d.scale = 2;
224   pos_d.x1 = 0;
225   pos_d.y = 100;            // Top left X
226   pos_d.x = 50;            // Top left Y
227   pos_d.y2 = 30;
228   pos_d.x3 = 60;
229   pos_d.y3 = 90;
230   pos_d.x4 = 120;
231   pos_d.y4 = 150;
232 */
233
234   if (ioctl(fdVideo, AV_SET_VID_POSITION, &pos_d) != 0) return 0;
235   return 1;
236 }
237
238 int Video::sync()
239 {
240   if (!initted) return 0;
241
242   if (ioctl(fdVideo, AV_SET_VID_SYNC, 2) != 0) return 0;
243   return 1;
244 }
245
246 int Video::play()
247 {
248   if (!initted) return 0;
249
250   if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
251   return 1;
252 }
253
254 int Video::stop()
255 {
256   if (!initted) return 0;
257
258   if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
259   return 1;
260 }
261
262 int Video::reset()
263 {
264   if (!initted) return 0;
265
266   if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
267   return 1;
268 }
269
270 int Video::pause()
271 {
272   if (!initted) return 0;
273
274   if (ioctl(fdVideo, AV_SET_VID_PAUSE, 0) != 0) return 0;
275   return 1;
276 }
277
278 int Video::unPause() // FIXME get rid - same as play!!
279 {
280   if (!initted) return 0;
281   if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
282   return 1;
283 }
284
285 int Video::fastForward()
286 {
287   if (!initted) return 0;
288
289   if (ioctl(fdVideo, AV_SET_VID_FFWD, 1) != 0) return 0;
290   return 1;
291 }
292
293 int Video::unFastForward()
294 {
295   if (!initted) return 0;
296
297 //  if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
298
299   if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
300   return 1;
301 }
302
303 int Video::attachFrameBuffer()
304 {
305   if (!initted) return 0;
306
307   if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
308   return 1;
309 }
310
311 int Video::blank(void)
312 {
313   if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
314   if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
315   return 1;
316 }
317
318 int Video::getFD()
319 {
320   if (!initted) return 0;
321
322   return fdVideo;
323 }
324
325 UCHAR Video::getFormat()
326 {
327   return format;
328 }
329
330 UINT Video::getScreenWidth()
331 {
332   return screenWidth;
333 }
334
335 UINT Video::getScreenHeight()
336 {
337   return screenHeight;
338 }