1
|
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;
|
2803
|
48 unsigned char* tmpframe=NULL;
|
|
49 unsigned char* tmpframe2=NULL;
|
|
50 unsigned char* planes[3];
|
|
51 unsigned int stride[3];
|
|
52 unsigned char* planes2[3];
|
|
53 unsigned int stride2[3];
|
1
|
54
|
2803
|
55 // if(argc>1) video_driver=argv[1];
|
1
|
56
|
|
57 // check video_out driver name:
|
|
58 if(!video_driver)
|
|
59 video_out=video_out_drivers[0];
|
|
60 else
|
|
61 for (i=0; video_out_drivers[i] != NULL; i++){
|
|
62 const vo_info_t *info = video_out_drivers[i]->get_info ();
|
|
63 if(strcmp(info->short_name,video_driver) == 0){
|
|
64 video_out = video_out_drivers[i];break;
|
|
65 }
|
|
66 }
|
|
67 if(!video_out){
|
|
68 printf("Invalid video output driver name: %s\n",video_driver);
|
|
69 return 0;
|
|
70 }
|
|
71
|
|
72
|
|
73 /* open */
|
|
74 if (-1 == fd && -1 == (fd = open(DEVNAME,O_RDWR))) {
|
|
75 fprintf(stderr,"open %s: %s\n",DEVNAME,strerror(errno));
|
|
76 exit(1);
|
|
77 }
|
|
78
|
|
79 /* get settings */
|
|
80 if (-1 == ioctl(fd,VIDIOCGCAP,&capability)) {
|
|
81 perror("ioctl VIDIOCGCAP");
|
|
82 exit(1);
|
|
83 }
|
|
84 if (-1 == ioctl(fd,VIDIOCGCHAN,&channel))
|
|
85 perror("ioctl VIDIOCGCHAN");
|
|
86
|
|
87 /* mmap() buffer */
|
|
88 if (-1 == ioctl(fd,VIDIOCGMBUF,&gb_buffers)) {
|
|
89 perror("ioctl VIDIOCGMBUF");
|
|
90 }
|
|
91 map = mmap(0,gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
|
|
92 if ((unsigned char*)-1 == map) {
|
|
93 perror("mmap");
|
|
94 } else {
|
|
95 fprintf(stderr,"v4l: mmap()'ed buffer size = 0x%x\n",
|
|
96 gb_buffers.size);
|
|
97 }
|
|
98
|
|
99 /* prepare for grabbing */
|
2803
|
100 gb1.format = (argc>1) ? atoi(argv[1]) : VIDEO_PALETTE_YUV422;
|
|
101 // gb1.format = VIDEO_PALETTE_YUV420;
|
1
|
102 // gb1.format = VIDEO_PALETTE_RGB24;
|
|
103 gb1.frame = 0;
|
2803
|
104 gb1.width = 704;//640;//320;
|
|
105 gb1.height = 576;//480;//240;
|
1
|
106
|
|
107 gb2.format = gb1.format;
|
|
108 gb2.frame = 1;
|
|
109 gb2.width = gb1.width;
|
|
110 gb2.height = gb1.height;
|
|
111
|
4433
|
112 // video_out->preinit() LOST here ?
|
|
113
|
|
114 video_out->config(gb1.width,gb1.height,1024,768,0,0,IMGFMT_YV12,NULL);
|
|
115 // video_out->config(gb1.width,gb1.height,1024,768,0,0,IMGFMT_UYVY,NULL);
|
|
116 // video_out->config(gb1.width,gb1.height,1024,768,0,0,IMGFMT_YUY2,NULL);
|
|
117 // video_out->config(gb1.width,gb1.height,1024,768,0,0,IMGFMT_RGB|24,NULL);
|
1
|
118
|
2803
|
119 tmpframe=malloc(gb1.width*gb1.height*3/2);
|
|
120 stride[0]=(gb1.width+15)&(~15);
|
|
121 stride[1]=stride[2]=stride[0]/2;
|
|
122 planes[0]=tmpframe;
|
|
123 planes[1]=planes[0]+stride[0]*gb1.height;
|
|
124 planes[2]=planes[1]+stride[0]*gb1.height/4;
|
|
125
|
|
126 tmpframe2=malloc(gb1.width*gb1.height*3/2);
|
|
127 stride2[0]=(gb1.width+15)&(~15);
|
|
128 stride2[1]=stride2[2]=stride2[0]/2;
|
|
129 planes2[0]=tmpframe2;
|
|
130 planes2[1]=planes2[0]+stride2[0]*gb1.height;
|
|
131 planes2[2]=planes2[1]+stride2[0]*gb1.height/4;
|
|
132
|
1
|
133 if (-1 == ioctl(fd,VIDIOCMCAPTURE,&gb1)) {
|
|
134 if (errno == EAGAIN)
|
|
135 fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n");
|
|
136 else
|
|
137 perror("ioctl VIDIOCMCAPTURE");
|
|
138 exit(1);
|
|
139 }
|
|
140 count++;
|
|
141 while(1){
|
|
142 // MAIN LOOP
|
|
143 if (-1 == ioctl(fd,VIDIOCMCAPTURE,(count%2) ? &gb2 : &gb1)) {
|
|
144 if (errno == EAGAIN)
|
|
145 fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n");
|
|
146 else
|
|
147 perror("ioctl VIDIOCMCAPTURE");
|
|
148 exit(1);
|
|
149 }
|
|
150
|
|
151 if (-1 == ioctl(fd,VIDIOCSYNC,(count%2) ? &gb1.frame : &gb2.frame)) {
|
|
152 perror("ioctl VIDIOCSYNC");
|
|
153 exit(1);
|
|
154 }
|
|
155 frame=map + gb_buffers.offsets[(count%2) ? 0 : 1];
|
2803
|
156 #if 0
|
1
|
157 video_out->draw_frame((unsigned char**)&frame);
|
2803
|
158 #else
|
|
159 {
|
|
160 uyvytoyv12(frame,planes[0],planes[1],planes[2],
|
|
161 gb1.width,gb1.height,
|
|
162 stride[0],stride[1],gb1.width*2);
|
|
163
|
|
164
|
|
165 postprocess(planes,stride[0],
|
|
166 planes2,stride2[0],
|
|
167 gb1.width,gb1.height,
|
|
168 planes[0],0, 0x20000);
|
|
169
|
|
170 video_out->draw_slice(planes2,stride2,gb1.width,gb1.height,0,0);
|
|
171 }
|
|
172 #endif
|
1
|
173 video_out->flip_page();
|
|
174
|
|
175 count++;
|
|
176 }
|
|
177
|
|
178 #if 0
|
|
179 { FILE *f=fopen("frame.yuv","wb");
|
|
180 fwrite(map,320*240*2,1,f);
|
|
181 fclose(f);
|
|
182 }
|
4433
|
183 video_out->config(320,240,800,600,0,0,IMGFMT_YUY2,NULL);
|
1
|
184 video_out->draw_frame(count?map1:map2);
|
|
185 video_out->flip_page();
|
|
186
|
|
187 getchar();
|
|
188 #endif
|
|
189
|
|
190
|
|
191
|
|
192 }
|
|
193
|