annotate tvision.c @ 4558:aac57ef92bab

rgb32 & rgb24 input support squished a endianness bug in the 15/16bgr output
author michael
date Wed, 06 Feb 2002 22:55:57 +0000
parents df8e0f71cc3c
children
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
4433
df8e0f71cc3c new info for tuning
nick
parents: 2803
diff changeset
112 // video_out->preinit() LOST here ?
df8e0f71cc3c new info for tuning
nick
parents: 2803
diff changeset
113
df8e0f71cc3c new info for tuning
nick
parents: 2803
diff changeset
114 video_out->config(gb1.width,gb1.height,1024,768,0,0,IMGFMT_YV12,NULL);
df8e0f71cc3c new info for tuning
nick
parents: 2803
diff changeset
115 // video_out->config(gb1.width,gb1.height,1024,768,0,0,IMGFMT_UYVY,NULL);
df8e0f71cc3c new info for tuning
nick
parents: 2803
diff changeset
116 // video_out->config(gb1.width,gb1.height,1024,768,0,0,IMGFMT_YUY2,NULL);
df8e0f71cc3c new info for tuning
nick
parents: 2803
diff changeset
117 // video_out->config(gb1.width,gb1.height,1024,768,0,0,IMGFMT_RGB|24,NULL);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118
2803
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
119 tmpframe=malloc(gb1.width*gb1.height*3/2);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
120 stride[0]=(gb1.width+15)&(~15);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
121 stride[1]=stride[2]=stride[0]/2;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
122 planes[0]=tmpframe;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
123 planes[1]=planes[0]+stride[0]*gb1.height;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
124 planes[2]=planes[1]+stride[0]*gb1.height/4;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
125
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
126 tmpframe2=malloc(gb1.width*gb1.height*3/2);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
127 stride2[0]=(gb1.width+15)&(~15);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
128 stride2[1]=stride2[2]=stride2[0]/2;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
129 planes2[0]=tmpframe2;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
130 planes2[1]=planes2[0]+stride2[0]*gb1.height;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
131 planes2[2]=planes2[1]+stride2[0]*gb1.height/4;
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
132
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 if (-1 == ioctl(fd,VIDIOCMCAPTURE,&gb1)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 if (errno == EAGAIN)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 perror("ioctl VIDIOCMCAPTURE");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 count++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 while(1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 // MAIN LOOP
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 if (-1 == ioctl(fd,VIDIOCMCAPTURE,(count%2) ? &gb2 : &gb1)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 if (errno == EAGAIN)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 perror("ioctl VIDIOCMCAPTURE");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 if (-1 == ioctl(fd,VIDIOCSYNC,(count%2) ? &gb1.frame : &gb2.frame)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 perror("ioctl VIDIOCSYNC");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 frame=map + gb_buffers.offsets[(count%2) ? 0 : 1];
2803
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
156 #if 0
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 video_out->draw_frame((unsigned char**)&frame);
2803
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
158 #else
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
159 {
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
160 uyvytoyv12(frame,planes[0],planes[1],planes[2],
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
161 gb1.width,gb1.height,
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
162 stride[0],stride[1],gb1.width*2);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
163
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
164
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
165 postprocess(planes,stride[0],
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
166 planes2,stride2[0],
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
167 gb1.width,gb1.height,
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
168 planes[0],0, 0x20000);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
169
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
170 video_out->draw_slice(planes2,stride2,gb1.width,gb1.height,0,0);
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
171 }
470d571ccb16 uyvy->yv12->postprocess->libvo
arpi
parents: 1
diff changeset
172 #endif
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 video_out->flip_page();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 count++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 { FILE *f=fopen("frame.yuv","wb");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 fwrite(map,320*240*2,1,f);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 fclose(f);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 }
4433
df8e0f71cc3c new info for tuning
nick
parents: 2803
diff changeset
183 video_out->config(320,240,800,600,0,0,IMGFMT_YUY2,NULL);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 video_out->draw_frame(count?map1:map2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 video_out->flip_page();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 getchar();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 #endif
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193