Mercurial > mplayer.hg
comparison tvision.c @ 1:3b5f5d1c5041
Initial revision
author | arpi_esp |
---|---|
date | Sat, 24 Feb 2001 20:28:24 +0000 |
parents | |
children | 470d571ccb16 |
comparison
equal
deleted
inserted
replaced
0:c1bb2c071d63 | 1:3b5f5d1c5041 |
---|---|
1 // testing only, not finished!!!!!!! | |
2 | |
3 // little TeleVision program by A'rpi/ESP-team | |
4 // based on streamer-old.c video capture util (part of xawtv) by | |
5 // (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de> | |
6 | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <unistd.h> | |
10 #include <math.h> | |
11 #include <errno.h> | |
12 #include <fcntl.h> | |
13 #include <string.h> | |
14 #include <ctype.h> | |
15 #include <signal.h> | |
16 #include <sys/types.h> | |
17 #include <sys/socket.h> | |
18 #include <sys/time.h> | |
19 #include <sys/ioctl.h> | |
20 #include <sys/stat.h> | |
21 #include <sys/mman.h> | |
22 #include <sys/shm.h> | |
23 #include <sys/ipc.h> | |
24 #include <sys/wait.h> | |
25 | |
26 | |
27 #include <asm/types.h> /* XXX glibc */ | |
28 #include "videodev.h" | |
29 | |
30 #include "libvo/video_out.h" | |
31 | |
32 #define DEVNAME "/dev/video" | |
33 | |
34 static struct video_mmap gb1,gb2; | |
35 static struct video_capability capability; | |
36 static struct video_channel channel; | |
37 static struct video_mbuf gb_buffers = { 2*0x151000, 0, {0,0x151000 }}; | |
38 static unsigned char *map = NULL; | |
39 | |
40 | |
41 int main(int argc,char* argv[]){ | |
42 vo_functions_t *video_out=NULL; | |
43 char* video_driver=NULL; //"mga"; // default | |
44 int i; | |
45 int fd=-1; | |
46 char* frame=NULL; | |
47 int count=0; | |
48 | |
49 if(argc>1) video_driver=argv[1]; | |
50 | |
51 // check video_out driver name: | |
52 if(!video_driver) | |
53 video_out=video_out_drivers[0]; | |
54 else | |
55 for (i=0; video_out_drivers[i] != NULL; i++){ | |
56 const vo_info_t *info = video_out_drivers[i]->get_info (); | |
57 if(strcmp(info->short_name,video_driver) == 0){ | |
58 video_out = video_out_drivers[i];break; | |
59 } | |
60 } | |
61 if(!video_out){ | |
62 printf("Invalid video output driver name: %s\n",video_driver); | |
63 return 0; | |
64 } | |
65 | |
66 | |
67 /* open */ | |
68 if (-1 == fd && -1 == (fd = open(DEVNAME,O_RDWR))) { | |
69 fprintf(stderr,"open %s: %s\n",DEVNAME,strerror(errno)); | |
70 exit(1); | |
71 } | |
72 | |
73 /* get settings */ | |
74 if (-1 == ioctl(fd,VIDIOCGCAP,&capability)) { | |
75 perror("ioctl VIDIOCGCAP"); | |
76 exit(1); | |
77 } | |
78 if (-1 == ioctl(fd,VIDIOCGCHAN,&channel)) | |
79 perror("ioctl VIDIOCGCHAN"); | |
80 | |
81 /* mmap() buffer */ | |
82 if (-1 == ioctl(fd,VIDIOCGMBUF,&gb_buffers)) { | |
83 perror("ioctl VIDIOCGMBUF"); | |
84 } | |
85 map = mmap(0,gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); | |
86 if ((unsigned char*)-1 == map) { | |
87 perror("mmap"); | |
88 } else { | |
89 fprintf(stderr,"v4l: mmap()'ed buffer size = 0x%x\n", | |
90 gb_buffers.size); | |
91 } | |
92 | |
93 /* prepare for grabbing */ | |
94 gb1.format = VIDEO_PALETTE_YUV422; | |
95 // gb1.format = VIDEO_PALETTE_RGB24; | |
96 gb1.frame = 0; | |
97 gb1.width = 352;//720;//640;//320; | |
98 gb1.height = 288;//576;//480;//240; | |
99 | |
100 gb2.format = gb1.format; | |
101 gb2.frame = 1; | |
102 gb2.width = gb1.width; | |
103 gb2.height = gb1.height; | |
104 | |
105 video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_YUY2); | |
106 // video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_RGB|24); | |
107 | |
108 if (-1 == ioctl(fd,VIDIOCMCAPTURE,&gb1)) { | |
109 if (errno == EAGAIN) | |
110 fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n"); | |
111 else | |
112 perror("ioctl VIDIOCMCAPTURE"); | |
113 exit(1); | |
114 } | |
115 count++; | |
116 while(1){ | |
117 // MAIN LOOP | |
118 if (-1 == ioctl(fd,VIDIOCMCAPTURE,(count%2) ? &gb2 : &gb1)) { | |
119 if (errno == EAGAIN) | |
120 fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n"); | |
121 else | |
122 perror("ioctl VIDIOCMCAPTURE"); | |
123 exit(1); | |
124 } | |
125 | |
126 if (-1 == ioctl(fd,VIDIOCSYNC,(count%2) ? &gb1.frame : &gb2.frame)) { | |
127 perror("ioctl VIDIOCSYNC"); | |
128 exit(1); | |
129 } | |
130 frame=map + gb_buffers.offsets[(count%2) ? 0 : 1]; | |
131 video_out->draw_frame((unsigned char**)&frame); | |
132 video_out->flip_page(); | |
133 | |
134 count++; | |
135 } | |
136 | |
137 #if 0 | |
138 { FILE *f=fopen("frame.yuv","wb"); | |
139 fwrite(map,320*240*2,1,f); | |
140 fclose(f); | |
141 } | |
142 video_out->init(320,240,800,600,0,0,IMGFMT_YUY2); | |
143 video_out->draw_frame(count?map1:map2); | |
144 video_out->flip_page(); | |
145 | |
146 getchar(); | |
147 #endif | |
148 | |
149 | |
150 | |
151 } | |
152 |