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
|
2803
|
112 video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_YV12);
|
|
113 // video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_UYVY);
|
|
114 // video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_YUY2);
|
1
|
115 // video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_RGB|24);
|
|
116
|
2803
|
117 tmpframe=malloc(gb1.width*gb1.height*3/2);
|
|
118 stride[0]=(gb1.width+15)&(~15);
|
|
119 stride[1]=stride[2]=stride[0]/2;
|
|
120 planes[0]=tmpframe;
|
|
121 planes[1]=planes[0]+stride[0]*gb1.height;
|
|
122 planes[2]=planes[1]+stride[0]*gb1.height/4;
|
|
123
|
|
124 tmpframe2=malloc(gb1.width*gb1.height*3/2);
|
|
125 stride2[0]=(gb1.width+15)&(~15);
|
|
126 stride2[1]=stride2[2]=stride2[0]/2;
|
|
127 planes2[0]=tmpframe2;
|
|
128 planes2[1]=planes2[0]+stride2[0]*gb1.height;
|
|
129 planes2[2]=planes2[1]+stride2[0]*gb1.height/4;
|
|
130
|
1
|
131 if (-1 == ioctl(fd,VIDIOCMCAPTURE,&gb1)) {
|
|
132 if (errno == EAGAIN)
|
|
133 fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n");
|
|
134 else
|
|
135 perror("ioctl VIDIOCMCAPTURE");
|
|
136 exit(1);
|
|
137 }
|
|
138 count++;
|
|
139 while(1){
|
|
140 // MAIN LOOP
|
|
141 if (-1 == ioctl(fd,VIDIOCMCAPTURE,(count%2) ? &gb2 : &gb1)) {
|
|
142 if (errno == EAGAIN)
|
|
143 fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n");
|
|
144 else
|
|
145 perror("ioctl VIDIOCMCAPTURE");
|
|
146 exit(1);
|
|
147 }
|
|
148
|
|
149 if (-1 == ioctl(fd,VIDIOCSYNC,(count%2) ? &gb1.frame : &gb2.frame)) {
|
|
150 perror("ioctl VIDIOCSYNC");
|
|
151 exit(1);
|
|
152 }
|
|
153 frame=map + gb_buffers.offsets[(count%2) ? 0 : 1];
|
2803
|
154 #if 0
|
1
|
155 video_out->draw_frame((unsigned char**)&frame);
|
2803
|
156 #else
|
|
157 {
|
|
158 uyvytoyv12(frame,planes[0],planes[1],planes[2],
|
|
159 gb1.width,gb1.height,
|
|
160 stride[0],stride[1],gb1.width*2);
|
|
161
|
|
162
|
|
163 postprocess(planes,stride[0],
|
|
164 planes2,stride2[0],
|
|
165 gb1.width,gb1.height,
|
|
166 planes[0],0, 0x20000);
|
|
167
|
|
168 video_out->draw_slice(planes2,stride2,gb1.width,gb1.height,0,0);
|
|
169 }
|
|
170 #endif
|
1
|
171 video_out->flip_page();
|
|
172
|
|
173 count++;
|
|
174 }
|
|
175
|
|
176 #if 0
|
|
177 { FILE *f=fopen("frame.yuv","wb");
|
|
178 fwrite(map,320*240*2,1,f);
|
|
179 fclose(f);
|
|
180 }
|
|
181 video_out->init(320,240,800,600,0,0,IMGFMT_YUY2);
|
|
182 video_out->draw_frame(count?map1:map2);
|
|
183 video_out->flip_page();
|
|
184
|
|
185 getchar();
|
|
186 #endif
|
|
187
|
|
188
|
|
189
|
|
190 }
|
|
191
|