]> git.vomp.tv Git - vompclient.git/blob - video.cc
New aspect mode change code
[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
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 //  mode = LETTERBOX;
156
157 //  if (ioctl(fdVideo, AV_SET_VID_MODE, mode) != 0) return 0;
158
159   int a = ioctl(fdVideo, AV_SET_VID_MODE, mode);
160   printf("Mode requested: %i, result: %i\n", mode, a);
161
162   return 1;
163 }
164
165 int Video::test()
166 {
167   return 0;
168
169 //  ULLONG stc = 0;
170 //  return ioctl(fdVideo, AV_SET_VID_STC, &stc);
171 /*
172  // reset();
173   return 1;
174 */
175 }
176
177 int Video::test2()
178 {
179   return 0;
180 }
181
182
183
184 int Video::signalOff()
185 {
186   if (ioctl(fdVideo, AV_SET_VID_DENC, 0) != 0) return 0;
187   return 1;
188 }
189
190 int Video::signalOn()
191 {
192   if (ioctl(fdVideo, AV_SET_VID_DENC, 1) != 0) return 0;
193   return 1;
194 }
195
196 int Video::setSource()
197 {
198   if (!initted) return 0;
199
200   // What does this do...
201   if (ioctl(fdVideo, AV_SET_VID_SRC, 1) != 0) return 0;
202   return 1;
203 }
204
205 int Video::setPosition(int x, int y)
206 {
207   if (!initted) return 0;
208
209   vid_pos_regs_t pos_d;
210   pos_d.x = x;
211   pos_d.y = y;
212
213 /*
214 typedef struct {
215   int w;
216   int h;
217   int scale;
218   int x1;
219   int y;
220   int x;
221   int y2;
222   int x3;
223   int y3;
224   int x4;
225   int y4;
226 } vid_pos_regs_t;
227 */
228
229 /*
230   pos_d.w = 100;
231   pos_d.h = 30;
232   pos_d.scale = 2;
233   pos_d.x1 = 0;
234   pos_d.y = 100;            // Top left X
235   pos_d.x = 50;            // Top left Y
236   pos_d.y2 = 30;
237   pos_d.x3 = 60;
238   pos_d.y3 = 90;
239   pos_d.x4 = 120;
240   pos_d.y4 = 150;
241 */
242
243   if (ioctl(fdVideo, AV_SET_VID_POSITION, &pos_d) != 0) return 0;
244   return 1;
245 }
246
247 int Video::sync()
248 {
249   if (!initted) return 0;
250
251   if (ioctl(fdVideo, AV_SET_VID_SYNC, 2) != 0) return 0;
252   return 1;
253 }
254
255 int Video::play()
256 {
257   if (!initted) return 0;
258
259   if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
260   return 1;
261 }
262
263 int Video::stop()
264 {
265   if (!initted) return 0;
266
267   if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
268   return 1;
269 }
270
271 int Video::reset()
272 {
273   if (!initted) return 0;
274
275   if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
276   return 1;
277 }
278
279 int Video::pause()
280 {
281   if (!initted) return 0;
282
283   if (ioctl(fdVideo, AV_SET_VID_PAUSE, 0) != 0) return 0;
284   return 1;
285 }
286
287 int Video::unPause() // FIXME get rid - same as play!!
288 {
289   if (!initted) return 0;
290   if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
291   return 1;
292 }
293
294 int Video::fastForward()
295 {
296   if (!initted) return 0;
297
298   if (ioctl(fdVideo, AV_SET_VID_FFWD, 1) != 0) return 0;
299   return 1;
300 }
301
302 int Video::unFastForward()
303 {
304   if (!initted) return 0;
305
306 //  if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
307
308   if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
309   return 1;
310 }
311
312 int Video::attachFrameBuffer()
313 {
314   if (!initted) return 0;
315
316   if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
317   return 1;
318 }
319
320 int Video::blank(void)
321 {
322   if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
323   if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
324   return 1;
325 }
326
327 int Video::getFD()
328 {
329   if (!initted) return 0;
330
331   return fdVideo;
332 }
333
334 UCHAR Video::getFormat()
335 {
336   return format;
337 }
338
339 UINT Video::getScreenWidth()
340 {
341   return screenWidth;
342 }
343
344 UINT Video::getScreenHeight()
345 {
346   return screenHeight;
347 }