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
33 int VideoMVP::init(UCHAR tformat)
35 if (initted) return 0;
38 if ((fdVideo = open("/dev/vdec_dev", O_WRONLY)) < 0) return 0;
40 if (!setFormat(tformat)) { shutdown(); return 0; }
41 if (!setConnection(COMPOSITERGB)) { shutdown(); return 0; }
42 if (!setAspectRatio(ASPECT4X3)) { shutdown(); return 0; }
43 if (!setMode(NORMAL)) { shutdown(); return 0; }
44 if (!setSource()) { shutdown(); return 0; }
45 if (!attachFrameBuffer()) { shutdown(); return 0; }
49 if (format == PAL) setLetterboxBorder("38");
50 else setLetterboxBorder("31");
58 void VideoMVP::setLetterboxBorder(char* border)
60 FILE* fdlbox = fopen("/proc/lbox_border", "w");
62 fputs(border, fdlbox);
66 int VideoMVP::setTVsize(UCHAR ttvsize)
70 // Override the aspect ratio usage, temporarily use to set the video chip mode
71 if (!setAspectRatio(tvsize)) { shutdown(); return 0; }
73 if ((fdVideo = open("/dev/vdec_dev", O_WRONLY)) < 0) return 0;
74 if (!setSource()) { shutdown(); return 0; }
75 if (!attachFrameBuffer()) { shutdown(); return 0; }
77 // Reopening the fd causes the scart aspect line to go back to 4:3
78 // Set this again to the same as the tv screen size
79 if (!setAspectRatio(tvsize)) { shutdown(); return 0; }
81 // mode == LETTERBOX is invalid if the TV is widescreen
82 if (tvsize == ASPECT16X9) setMode(NORMAL);
87 int VideoMVP::setDefaultAspect()
89 return setAspectRatio(tvsize);
92 int VideoMVP::shutdown()
94 if (!initted) return 0;
100 int VideoMVP::checkSCART()
102 // Returns 3 for SCART Composite out
103 // Returns 3 for SCART S-Video out
104 // Returns 2 for SCART RGB out
105 // Returns 3 for SCART not plugged in
107 // So, as you can have RGB and composite out simultaneously,
108 // and it can't detect S-Video, what is the point of this?
111 if (ioctl(fdVideo, AV_CHK_SCART, &scart) != 0) return -10;
116 int VideoMVP::setFormat(UCHAR tformat)
118 if (!initted) return 0;
119 if ((tformat != PAL) && (tformat != NTSC)) return 0;
122 if (ioctl(fdVideo, AV_SET_VID_DISP_FMT, format) != 0) return 0;
138 int VideoMVP::setConnection(UCHAR tconnection)
140 if (!initted) return 0;
141 if ((tconnection != COMPOSITERGB) && (tconnection != SVIDEO)) return 0;
142 connection = tconnection;
144 if (ioctl(fdVideo, AV_SET_VID_OUTPUT, connection) != 0) return 0;
148 int VideoMVP::setAspectRatio(UCHAR taspectRatio)
150 if (!initted) return 0;
151 if ((taspectRatio != ASPECT4X3) && (taspectRatio != ASPECT16X9)) return 0;
152 aspectRatio = taspectRatio;
154 if (ioctl(fdVideo, AV_SET_VID_RATIO, aspectRatio) != 0) return 0;
158 int VideoMVP::setMode(UCHAR tmode)
160 if (!initted) return 0;
162 if ((tmode == LETTERBOX) && (tvsize == ASPECT16X9)) return 0; // invalid mode
164 if ((tmode != NORMAL) && (tmode != LETTERBOX) && (tmode != UNKNOWN2) && (tmode != QUARTER) && (tmode != EIGHTH)
165 && (tmode != ZOOM) && (tmode != UNKNOWN6)) return 0;
168 if (ioctl(fdVideo, AV_SET_VID_MODE, mode) != 0) return 0;
172 int VideoMVP::signalOff()
174 if (ioctl(fdVideo, AV_SET_VID_DENC, 0) != 0) return 0;
178 int VideoMVP::signalOn()
180 if (ioctl(fdVideo, AV_SET_VID_DENC, 1) != 0) return 0;
184 int VideoMVP::setSource()
186 if (!initted) return 0;
188 // What does this do...
189 if (ioctl(fdVideo, AV_SET_VID_SRC, 1) != 0) return 0;
193 int VideoMVP::setPosition(int x, int y)
195 if (!initted) return 0;
197 // vid_pos_regs_t pos_d;
201 vid_pos_regs_t pos_d;
203 memset(&pos_d, 0, sizeof(pos_d));
228 pos_d.y = 100; // Top left X
229 pos_d.x = 50; // Top left Y
237 if (ioctl(fdVideo, AV_SET_VID_POSITION, &pos_d) != 0) return 0;
243 if (!initted) return 0;
245 if (ioctl(fdVideo, AV_SET_VID_SYNC, 2) != 0) return 0;
251 if (!initted) return 0;
253 if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
259 if (!initted) return 0;
261 if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
265 int VideoMVP::reset()
267 if (!initted) return 0;
269 if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
273 int VideoMVP::pause()
275 if (!initted) return 0;
277 if (ioctl(fdVideo, AV_SET_VID_PAUSE, 0) != 0) return 0;
281 int VideoMVP::unPause() // FIXME get rid - same as play!!
283 if (!initted) return 0;
284 if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
288 int VideoMVP::fastForward()
290 if (!initted) return 0;
292 if (ioctl(fdVideo, AV_SET_VID_FFWD, 1) != 0) return 0;
296 int VideoMVP::unFastForward()
298 if (!initted) return 0;
300 // if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
302 if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
306 int VideoMVP::attachFrameBuffer()
308 if (!initted) return 0;
310 if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
314 int VideoMVP::blank(void)
316 if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
317 if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
321 int VideoMVP::getFD()
323 if (!initted) return 0;
328 ULLONG VideoMVP::getCurrentTimestamp()
330 sync_data_t timestamps;
331 if (ioctl(fdVideo, AV_GET_VID_TIMESTAMPS, ×tamps) == 0)
333 // FIXME are these the right way around?
335 timestamps.stc = (timestamps.stc >> 31 ) | (timestamps.stc & 1);
336 timestamps.pts = (timestamps.pts >> 31 ) | (timestamps.pts & 1);
338 return timestamps.stc;
346 ULONG VideoMVP::timecodeToFrameNumber(ULLONG timecode)
348 if (format == PAL) return (ULONG)(((double)timecode / (double)90000) * (double)25);
349 else return (ULONG)(((double)timecode / (double)90000) * (double)30);
358 // return ioctl(fdVideo, AV_SET_VID_STC, &stc);
365 int VideoMVP::test2()