1 /*
2 * test_video.c - Test program for new API
3 *
4 * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
5 * & Marcus Metzler <marcus@convergence.de>
6 for convergence integrated media GmbH
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 */
23
24 #include <sys/ioctl.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <stdint.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <time.h>
32 #include <unistd.h>
33
34 #include <linux/dvb/dmx.h>
35 #include <linux/dvb/frontend.h>
36 #include <linux/dvb/video.h>
37 #include <sys/poll.h>
38
videoStop(int fd)39 int videoStop(int fd)
40 {
41 int ans;
42
43 if ((ans = ioctl(fd,VIDEO_STOP,0)) < 0) {
44 perror("VIDEO STOP: ");
45 return -1;
46 }
47
48 return 0;
49 }
50
videoPlay(int fd)51 int videoPlay(int fd)
52 {
53 int ans;
54
55 if ((ans = ioctl(fd,VIDEO_PLAY)) < 0) {
56 perror("VIDEO PLAY: ");
57 return -1;
58 }
59
60 return 0;
61 }
62
63
videoFreeze(int fd)64 int videoFreeze(int fd)
65 {
66 int ans;
67
68 if ((ans = ioctl(fd,VIDEO_FREEZE)) < 0) {
69 perror("VIDEO FREEZE: ");
70 return -1;
71 }
72
73 return 0;
74 }
75
76
videoContinue(int fd)77 int videoContinue(int fd)
78 {
79 int ans;
80
81 if ((ans = ioctl(fd,VIDEO_CONTINUE)) < 0) {
82 perror("VIDEO CONTINUE: ");
83 return -1;
84 }
85
86 return 0;
87 }
88
videoSelectSource(int fd,video_stream_source_t source)89 int videoSelectSource(int fd, video_stream_source_t source)
90 {
91 int ans;
92
93 if ((ans = ioctl(fd,VIDEO_SELECT_SOURCE, source)) < 0) {
94 perror("VIDEO SELECT SOURCE: ");
95 return -1;
96 }
97
98 return 0;
99 }
100
101
102
videoSetBlank(int fd,int state)103 int videoSetBlank(int fd, int state)
104 {
105 int ans;
106
107 if ((ans = ioctl(fd,VIDEO_SET_BLANK, state)) < 0) {
108 perror("VIDEO SET BLANK: ");
109 return -1;
110 }
111
112 return 0;
113 }
114
videoFastForward(int fd,int nframes)115 int videoFastForward(int fd,int nframes)
116 {
117 int ans;
118
119 if ((ans = ioctl(fd,VIDEO_FAST_FORWARD, nframes)) < 0) {
120 perror("VIDEO FAST FORWARD: ");
121 return -1;
122 }
123
124 return 0;
125 }
126
videoSlowMotion(int fd,int nframes)127 int videoSlowMotion(int fd,int nframes)
128 {
129 int ans;
130
131 if ((ans = ioctl(fd,VIDEO_SLOWMOTION, nframes)) < 0) {
132 perror("VIDEO SLOWMOTION: ");
133 return -1;
134 }
135
136 return 0;
137 }
138
videoGetStatus(int fd)139 int videoGetStatus(int fd)
140 {
141 struct video_status vstat;
142 int ans;
143
144 if ((ans = ioctl(fd,VIDEO_GET_STATUS, &vstat)) < 0) {
145 perror("VIDEO GET STATUS: ");
146 return -1;
147 }
148
149 printf("Video Status:\n");
150 printf(" Blank State : %s\n",
151 (vstat.video_blank ? "BLANK" : "STILL"));
152 printf(" Play State : ");
153 switch ((int)vstat.play_state){
154 case VIDEO_STOPPED:
155 printf("STOPPED (%d)\n",vstat.play_state);
156 break;
157 case VIDEO_PLAYING:
158 printf("PLAYING (%d)\n",vstat.play_state);
159 break;
160 case VIDEO_FREEZED:
161 printf("FREEZED (%d)\n",vstat.play_state);
162 break;
163 default:
164 printf("unknown (%d)\n",vstat.play_state);
165 break;
166 }
167
168 printf(" Stream Source : ");
169 switch((int)vstat.stream_source){
170 case VIDEO_SOURCE_DEMUX:
171 printf("DEMUX (%d)\n",vstat.stream_source);
172 break;
173 case VIDEO_SOURCE_MEMORY:
174 printf("MEMORY (%d)\n",vstat.stream_source);
175 break;
176 default:
177 printf("unknown (%d)\n",vstat.stream_source);
178 break;
179 }
180
181 printf(" Format (Aspect Ratio): ");
182 switch((int)vstat.video_format){
183 case VIDEO_FORMAT_4_3:
184 printf("4:3 (%d)\n",vstat.video_format);
185 break;
186 case VIDEO_FORMAT_16_9:
187 printf("16:9 (%d)\n",vstat.video_format);
188 break;
189 default:
190 printf("unknown (%d)\n",vstat.video_format);
191 break;
192 }
193
194 printf(" Display Format : ");
195 switch((int)vstat.display_format){
196 case VIDEO_PAN_SCAN:
197 printf("Pan&Scan (%d)\n",vstat.display_format);
198 break;
199 case VIDEO_LETTER_BOX:
200 printf("Letterbox (%d)\n",vstat.display_format);
201 break;
202 case VIDEO_CENTER_CUT_OUT:
203 printf("Center cutout (%d)\n",vstat.display_format);
204 break;
205 default:
206 printf("unknown (%d)\n",vstat.display_format);
207 break;
208 }
209 return 0;
210 }
211
videoStillPicture(int fd,struct video_still_picture * sp)212 int videoStillPicture(int fd, struct video_still_picture *sp)
213 {
214 int ans;
215
216 if ((ans = ioctl(fd,VIDEO_STILLPICTURE, sp)) < 0) {
217 perror("VIDEO STILLPICTURE: ");
218 return -1;
219 }
220
221 return 0;
222 }
223
224 #define BUFFY 32768
225 #define NFD 2
play_file_video(int filefd,int fd)226 void play_file_video(int filefd, int fd)
227 {
228 char buf[BUFFY];
229 int count;
230 int written;
231 struct pollfd pfd[NFD];
232 // int stopped = 0;
233
234 pfd[0].fd = STDIN_FILENO;
235 pfd[0].events = POLLIN;
236
237 pfd[1].fd = fd;
238 pfd[1].events = POLLOUT;
239
240 videoSelectSource(fd,VIDEO_SOURCE_MEMORY);
241 videoPlay(fd);
242
243
244 count = read(filefd,buf,BUFFY);
245 write(fd,buf,count);
246
247 while ( (count = read(filefd,buf,BUFFY)) >= 0 ){
248 written = 0;
249 while(written < count){
250 if (poll(pfd,NFD,1)){
251 if (pfd[1].revents & POLLOUT){
252 written += write(fd,buf+written,
253 count-written);
254 }
255 if (pfd[0].revents & POLLIN){
256 int c = getchar();
257 switch(c){
258 case 'z':
259 videoFreeze(fd);
260 printf("playback frozen\n");
261 // stopped = 1;
262 break;
263
264 case 's':
265 videoStop(fd);
266 printf("playback stopped\n");
267 // stopped = 1;
268 break;
269
270 case 'c':
271 videoContinue(fd);
272 printf("playback continued\n");
273 // stopped = 0;
274 break;
275
276 case 'p':
277 videoPlay(fd);
278 printf("playback started\n");
279 // stopped = 0;
280 break;
281
282 case 'f':
283 videoFastForward(fd,0);
284 printf("fastforward\n");
285 // stopped = 0;
286 break;
287
288 case 'm':
289 videoSlowMotion(fd,2);
290 printf("slowmotion\n");
291 // stopped = 0;
292 break;
293
294 case 'q':
295 videoContinue(fd);
296 exit(0);
297 break;
298 }
299 }
300
301 }
302 }
303 }
304 }
305
load_iframe(int filefd,int fd)306 void load_iframe(int filefd, int fd)
307 {
308 struct stat st;
309 struct video_still_picture sp;
310
311 fstat(filefd, &st);
312
313 sp.iFrame = (char *) malloc(st.st_size);
314 sp.size = st.st_size;
315 printf("I-frame size: %d\n", sp.size);
316
317 if (!sp.iFrame) {
318 printf("No memory for I-Frame\n");
319 return;
320 }
321
322 printf("read: %zd bytes\n",read(filefd,sp.iFrame,sp.size));
323 videoStillPicture(fd,&sp);
324
325 sleep(3);
326 videoPlay(fd);
327 }
328
main(int argc,char ** argv)329 int main(int argc, char **argv)
330 {
331 int fd;
332 int filefd;
333
334 if (argc < 2) return -1;
335
336 if ( (filefd = open(argv[1],O_RDONLY)) < 0){
337 perror("File open:");
338 return -1;
339 }
340 if ((fd = open("/dev/dvb/adapter0/video0",O_RDWR|O_NONBLOCK)) < 0){
341 perror("VIDEO DEVICE: ");
342 return -1;
343 }
344
345
346
347
348 // videoSetBlank(fd,false);
349 //videoPlay(fd);
350 //sleep(4);
351 //videoFreeze(fd);
352 //sleep(3);
353 //videoContinue(fd);
354 //sleep(3);
355 //videoStop(fd);
356 videoGetStatus(fd);
357
358
359 //load_iframe(filefd, fd);
360 play_file_video(filefd, fd);
361 close(fd);
362 close(filefd);
363 return 0;
364
365
366 }
367