2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
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.
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.
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
23 Video* Video::instance = NULL;
48 Video* Video::getInstance()
53 int Video::init(UCHAR tformat)
55 if (initted) return 0;
58 if ((fdVideo = open("/dev/vdec_dev", O_WRONLY)) < 0) return 0;
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; }
69 if (format == PAL) setLetterboxBorder("38");
70 else setLetterboxBorder("31");
78 void Video::setLetterboxBorder(char* border)
80 FILE* fdlbox = fopen("/proc/lbox_border", "w");
82 fputs(border, fdlbox);
86 int Video::setTVsize(UCHAR ttvsize)
90 // Override the aspect ratio usage, temporarily use to set the video chip mode
91 if (!setAspectRatio(tvsize)) { shutdown(); return 0; }
93 if ((fdVideo = open("/dev/vdec_dev", O_WRONLY)) < 0) return 0;
94 if (!setSource()) { shutdown(); return 0; }
95 if (!attachFrameBuffer()) { shutdown(); return 0; }
97 // Reopening the fd causes the scart aspect line to go back to 4:3
98 // Set this again to the same as the tv screen size
99 if (!setAspectRatio(tvsize)) { shutdown(); return 0; }
101 // mode == LETTERBOX is invalid if the TV is widescreen
102 if (tvsize == ASPECT16X9) setMode(NORMAL);
107 int Video::setDefaultAspect()
109 return setAspectRatio(tvsize);
112 int Video::shutdown()
114 if (!initted) return 0;
120 int Video::checkSCART()
122 // Returns 3 for SCART Composite out
123 // Returns 3 for SCART S-Video out
124 // Returns 2 for SCART RGB out
125 // Returns 3 for SCART not plugged in
127 // So, as you can have RGB and composite out simultaneously,
128 // and it can't detect S-Video, what is the point of this?
131 if (ioctl(fdVideo, AV_CHK_SCART, &scart) != 0) return -10;
136 int Video::setFormat(UCHAR tformat)
138 if (!initted) return 0;
139 if ((tformat != PAL) && (tformat != NTSC)) return 0;
142 if (ioctl(fdVideo, AV_SET_VID_DISP_FMT, format) != 0) return 0;
158 int Video::setConnection(UCHAR tconnection)
160 if (!initted) return 0;
161 if ((tconnection != COMPOSITERGB) && (tconnection != SVIDEO)) return 0;
162 connection = tconnection;
164 if (ioctl(fdVideo, AV_SET_VID_OUTPUT, connection) != 0) return 0;
168 int Video::setAspectRatio(UCHAR taspectRatio)
170 if (!initted) return 0;
171 if ((taspectRatio != ASPECT4X3) && (taspectRatio != ASPECT16X9)) return 0;
172 aspectRatio = taspectRatio;
174 if (ioctl(fdVideo, AV_SET_VID_RATIO, aspectRatio) != 0) return 0;
178 int Video::setMode(UCHAR tmode)
180 if (!initted) return 0;
182 if ((tmode == LETTERBOX) && (tvsize == ASPECT16X9)) return 0; // invalid mode
184 if ((tmode != NORMAL) && (tmode != LETTERBOX) && (tmode != UNKNOWN2) && (tmode != QUARTER) && (tmode != EIGHTH)
185 && (tmode != ZOOM) && (tmode != UNKNOWN6)) return 0;
188 if (ioctl(fdVideo, AV_SET_VID_MODE, mode) != 0) return 0;
192 int Video::signalOff()
194 if (ioctl(fdVideo, AV_SET_VID_DENC, 0) != 0) return 0;
198 int Video::signalOn()
200 if (ioctl(fdVideo, AV_SET_VID_DENC, 1) != 0) return 0;
204 int Video::setSource()
206 if (!initted) return 0;
208 // What does this do...
209 if (ioctl(fdVideo, AV_SET_VID_SRC, 1) != 0) return 0;
213 int Video::setPosition(int x, int y)
215 if (!initted) return 0;
217 // vid_pos_regs_t pos_d;
221 vid_pos_regs_t pos_d;
223 memset(&pos_d, 0, sizeof(pos_d));
248 pos_d.y = 100; // Top left X
249 pos_d.x = 50; // Top left Y
257 if (ioctl(fdVideo, AV_SET_VID_POSITION, &pos_d) != 0) return 0;
263 if (!initted) return 0;
265 if (ioctl(fdVideo, AV_SET_VID_SYNC, 2) != 0) return 0;
271 if (!initted) return 0;
273 if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
279 if (!initted) return 0;
281 if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
287 if (!initted) return 0;
289 if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
295 if (!initted) return 0;
297 if (ioctl(fdVideo, AV_SET_VID_PAUSE, 0) != 0) return 0;
301 int Video::unPause() // FIXME get rid - same as play!!
303 if (!initted) return 0;
304 if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
308 int Video::fastForward()
310 if (!initted) return 0;
312 if (ioctl(fdVideo, AV_SET_VID_FFWD, 1) != 0) return 0;
316 int Video::unFastForward()
318 if (!initted) return 0;
320 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
322 if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
326 int Video::attachFrameBuffer()
328 if (!initted) return 0;
330 if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
334 int Video::blank(void)
336 if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
337 if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
343 if (!initted) return 0;
348 UCHAR Video::getFormat()
353 UINT Video::getScreenWidth()
358 UINT Video::getScreenHeight()
363 UCHAR Video::getTVsize()
374 // return ioctl(fdVideo, AV_SET_VID_STC, &stc);