annotate tvision.c @ 2843:5be2017077fb

Use new logic suggested by Michael Niedermayer K7: Non-MMX stuff total=299997790 Old-MMX stuff: total=159120928 New-MMX stuff: total=80925337
author nick
date Sun, 11 Nov 2001 17:14:57 +0000
parents 470d571ccb16
children df8e0f71cc3c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 // testing only, not finished!!!!!!!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 // little TeleVision program by A'rpi/ESP-team
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 // based on streamer-old.c video capture util (part of xawtv) by
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 // (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 #include <unistd.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 #include <math.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 #include <errno.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 #include <fcntl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 #include <string.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 #include <ctype.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 #include <signal.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 #include <sys/types.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 #include <sys/socket.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 #include <sys/time.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 #include <sys/ioctl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 #include <sys/stat.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 #include <sys/mman.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 #include <sys/shm.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 #include <sys/ipc.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 #include <sys/wait.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 #include <asm/types.h> /* XXX glibc */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 #include "videodev.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 #include "libvo/video_out.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 #define DEVNAME "/dev/video"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 static struct video_mmap gb1,gb2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 static struct video_capability capability;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 static struct video_channel channel;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 static struct video_mbuf gb_buffers = { 2*0x151000, 0, {0,0x151000 }};
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 static unsigned char *map = NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 int main(int argc,char* argv[]){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 vo_functions_t *video_out=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 char* video_driver=NULL; //"mga"; // default
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 int fd=-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 char* frame=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 int count=0;
2803
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
48 unsigned char* tmpframe=NULL;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
49 unsigned char* tmpframe2=NULL;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
50 unsigned char* planes[3];
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
51 unsigned int stride[3];
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
52 unsigned char* planes2[3];
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
53 unsigned int stride2[3];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54
2803
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
55 // if(argc>1) video_driver=argv[1];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 // check video_out driver name:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 if(!video_driver)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 video_out=video_out_drivers[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 for (i=0; video_out_drivers[i] != NULL; i++){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 const vo_info_t *info = video_out_drivers[i]->get_info ();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 if(strcmp(info->short_name,video_driver) == 0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 video_out = video_out_drivers[i];break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 if(!video_out){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 printf("Invalid video output driver name: %s\n",video_driver);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 /* open */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 if (-1 == fd && -1 == (fd = open(DEVNAME,O_RDWR))) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 fprintf(stderr,"open %s: %s\n",DEVNAME,strerror(errno));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 /* get settings */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 if (-1 == ioctl(fd,VIDIOCGCAP,&capability)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 perror("ioctl VIDIOCGCAP");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 if (-1 == ioctl(fd,VIDIOCGCHAN,&channel))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 perror("ioctl VIDIOCGCHAN");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 /* mmap() buffer */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 if (-1 == ioctl(fd,VIDIOCGMBUF,&gb_buffers)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 perror("ioctl VIDIOCGMBUF");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 map = mmap(0,gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 if ((unsigned char*)-1 == map) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 perror("mmap");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 fprintf(stderr,"v4l: mmap()'ed buffer size = 0x%x\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 gb_buffers.size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 /* prepare for grabbing */
2803
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
100 gb1.format = (argc>1) ? atoi(argv[1]) : VIDEO_PALETTE_YUV422;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
101 // gb1.format = VIDEO_PALETTE_YUV420;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 // gb1.format = VIDEO_PALETTE_RGB24;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 gb1.frame = 0;
2803
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
104 gb1.width = 704;//640;//320;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
105 gb1.height = 576;//480;//240;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 gb2.format = gb1.format;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 gb2.frame = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 gb2.width = gb1.width;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 gb2.height = gb1.height;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111
2803
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
112 video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_YV12);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
113 // video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_UYVY);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
114 // video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_YUY2);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 // video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_RGB|24);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116
2803
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
117 tmpframe=malloc(gb1.width*gb1.height*3/2);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
118 stride[0]=(gb1.width+15)&(~15);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
119 stride[1]=stride[2]=stride[0]/2;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
120 planes[0]=tmpframe;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
121 planes[1]=planes[0]+stride[0]*gb1.height;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
122 planes[2]=planes[1]+stride[0]*gb1.height/4;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
123
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
124 tmpframe2=malloc(gb1.width*gb1.height*3/2);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
125 stride2[0]=(gb1.width+15)&(~15);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
126 stride2[1]=stride2[2]=stride2[0]/2;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
127 planes2[0]=tmpframe2;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
128 planes2[1]=planes2[0]+stride2[0]*gb1.height;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
129 planes2[2]=planes2[1]+stride2[0]*gb1.height/4;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
130
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 if (-1 == ioctl(fd,VIDIOCMCAPTURE,&gb1)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 if (errno == EAGAIN)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 perror("ioctl VIDIOCMCAPTURE");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 count++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 while(1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 // MAIN LOOP
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 if (-1 == ioctl(fd,VIDIOCMCAPTURE,(count%2) ? &gb2 : &gb1)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 if (errno == EAGAIN)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 perror("ioctl VIDIOCMCAPTURE");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 if (-1 == ioctl(fd,VIDIOCSYNC,(count%2) ? &gb1.frame : &gb2.frame)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 perror("ioctl VIDIOCSYNC");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 frame=map + gb_buffers.offsets[(count%2) ? 0 : 1];
2803
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
154 #if 0
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 video_out->draw_frame((unsigned char**)&frame);
2803
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
156 #else
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
157 {
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
158 uyvytoyv12(frame,planes[0],planes[1],planes[2],
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
159 gb1.width,gb1.height,
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
160 stride[0],stride[1],gb1.width*2);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
161
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
162
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
163 postprocess(planes,stride[0],
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
164 planes2,stride2[0],
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
165 gb1.width,gb1.height,
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
166 planes[0],0, 0x20000);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
167
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
168 video_out->draw_slice(planes2,stride2,gb1.width,gb1.height,0,0);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
169 }
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
170 #endif
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 video_out->flip_page();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 count++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 { FILE *f=fopen("frame.yuv","wb");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 fwrite(map,320*240*2,1,f);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 fclose(f);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 video_out->init(320,240,800,600,0,0,IMGFMT_YUY2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 video_out->draw_frame(count?map1:map2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 video_out->flip_page();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 getchar();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191