]> git.vomp.tv Git - vompclient.git/blob - video.cc
Initial import
[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
39 Video::~Video()
40 {
41   instance = NULL;
42 }
43
44 Video* Video::getInstance()
45 {
46   return instance;
47 }
48
49 int Video::init(UCHAR format, UCHAR connection, UCHAR aspectRatio, UCHAR mode)
50 {
51   if (initted) return 0;
52   initted = 1;
53
54 //  if ((fdVideo = open("/dev/vdec_dev", O_RDWR | O_NONBLOCK)) < 0) return 0;
55   if ((fdVideo = open("/dev/vdec_dev", O_WRONLY)) < 0) return 0;
56
57   this->format = format;
58   this->connection = connection;
59   this->aspectRatio = aspectRatio;
60   this->mode = mode;
61
62   if (!initAllParams())
63   {
64     shutdown();
65     return 0;
66   }
67
68   attachFrameBuffer();
69   stop();
70
71   return 1;
72 }
73
74 int Video::initAllParams()
75 {
76   return (setFormat(format) && setConnection(connection) &&
77           setAspectRatio(aspectRatio) && setMode(mode) && setSource());
78 }
79
80 int Video::shutdown()
81 {
82   if (!initted) return 0;
83   initted = 0;
84   close(fdVideo);
85   return 1;
86 }
87
88 int Video::write(char *buf, int len)
89 {
90   return 1;//write(fdVideo, buf, len);
91 }
92
93 int Video::setFormat(UCHAR format)
94 {
95   if (!initted) return 0;
96   if ((format != PAL) && (format != NTSC)) return 0;
97
98   if (ioctl(fdVideo, AV_SET_VID_DISP_FMT, format) != 0) return 0;
99   this->format = format;
100   return 1;
101 }
102
103 int Video::setConnection(UCHAR connection)
104 {
105   if (!initted) return 0;
106   if ((connection != SCART) && (connection != COMPOSITE) && (connection != SVIDEO)) return 0;
107
108   if (ioctl(fdVideo, AV_SET_VID_OUTPUT, connection) != 0) return 0;
109   this->connection = connection;
110   return 1;
111 }
112
113 int Video::setAspectRatio(UCHAR aspectRatio)
114 {
115   if (!initted) return 0;
116   if ((aspectRatio != ASPECT4X3) && (aspectRatio != ASPECT16X9)) return 0;
117
118   if (ioctl(fdVideo, AV_SET_VID_RATIO, aspectRatio) != 0) return 0;
119   this->aspectRatio = aspectRatio;
120   return 1;
121 }
122
123 int Video::setMode(UCHAR mode)
124 {
125   if (!initted) return 0;
126
127   if ((mode != NORMAL) && (mode != LETTERBOX) && (mode != UNKNOWN2) && (mode != QUARTER) && (mode != EIGHTH)
128       && (mode != ZOOM) && (mode != UNKNOWN6)) return 0;
129
130 //  mode = LETTERBOX;
131
132   if (ioctl(fdVideo, AV_SET_VID_MODE, mode) != 0) return 0;
133   this->mode = mode;
134   return 1;
135 }
136
137 int Video::test()
138 {
139   return 0;
140
141 //  ULLONG stc = 0;
142 //  return ioctl(fdVideo, AV_SET_VID_STC, &stc);
143 /*
144  // reset();
145   return 1;
146 */
147 }
148
149 int Video::test2()
150 {
151   return 0;
152 }
153
154
155
156 int Video::signalOff()
157 {
158   if (ioctl(fdVideo, AV_SET_VID_DENC, 0) != 0) return 0;
159   return 1;
160 }
161
162 int Video::signalOn()
163 {
164   if (ioctl(fdVideo, AV_SET_VID_DENC, 1) != 0) return 0;
165   return 1;
166 }
167
168 int Video::setSource()
169 {
170   if (!initted) return 0;
171
172   // What does this do...
173   if (ioctl(fdVideo, AV_SET_VID_SRC, 1) != 0) return 0;
174   return 1;
175 }
176
177 int Video::setPosition(int x, int y)
178 {
179   if (!initted) return 0;
180
181   vid_pos_regs_t pos_d;
182   pos_d.x = x;
183   pos_d.y = y;
184
185 /*
186 typedef struct {
187   int w;
188   int h;
189   int scale;
190   int x1;
191   int y;
192   int x;
193   int y2;
194   int x3;
195   int y3;
196   int x4;
197   int y4;
198 } vid_pos_regs_t;
199 */
200
201 /*
202   pos_d.w = 100;
203   pos_d.h = 30;
204   pos_d.scale = 2;
205   pos_d.x1 = 0;
206   pos_d.y = 100;            // Top left X
207   pos_d.x = 50;            // Top left Y
208   pos_d.y2 = 30;
209   pos_d.x3 = 60;
210   pos_d.y3 = 90;
211   pos_d.x4 = 120;
212   pos_d.y4 = 150;
213 */
214
215   if (ioctl(fdVideo, AV_SET_VID_POSITION, &pos_d) != 0) return 0;
216   return 1;
217 }
218
219 int Video::sync()
220 {
221   if (!initted) return 0;
222
223   if (ioctl(fdVideo, AV_SET_VID_SYNC, 2) != 0) return 0;
224   return 1;
225 }
226
227 int Video::play()
228 {
229   if (!initted) return 0;
230
231   if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
232   return 1;
233 }
234
235 int Video::stop()
236 {
237   if (!initted) return 0;
238
239   if (ioctl(fdVideo, AV_SET_VID_STOP, 0) != 0) return 0;
240   return 1;
241 }
242
243 int Video::reset()
244 {
245   if (!initted) return 0;
246
247   if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0;
248   return 1;
249 }
250
251 int Video::pause()
252 {
253   if (!initted) return 0;
254
255   if (ioctl(fdVideo, AV_SET_VID_PAUSE, 0) != 0) return 0;
256   return 1;
257 }
258
259 int Video::unPause()
260 {
261   if (!initted) return 0;
262   if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
263   return 1;
264 }
265
266 int Video::fastForward()
267 {
268   if (!initted) return 0;
269
270   if (ioctl(fdVideo, AV_SET_VID_FFWD, 1) != 0) return 0;
271   return 1;
272 }
273
274 int Video::unFastForward()
275 {
276   if (!initted) return 0;
277
278 //  if (ioctl(fdVideo, AV_SET_VID_RESET, 0x11) != 0) return 0; // don't need this.
279
280   if (ioctl(fdVideo, AV_SET_VID_PLAY, 0) != 0) return 0;
281   return 1;
282 }
283
284 int Video::attachFrameBuffer()
285 {
286   if (!initted) return 0;
287
288   if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
289   return 1;
290 }
291
292 int Video::blank(void)
293 {
294   if (ioctl(fdVideo, AV_SET_VID_FB, 1) != 0) return 0;
295   if (ioctl(fdVideo, AV_SET_VID_FB, 0) != 0) return 0;
296   return 1;
297 }
298
299 int Video::getFD()
300 {
301   if (!initted) return 0;
302
303   return fdVideo;
304 }