annotate tvision.c @ 2476:a6c5a537f30a

a few warning fixes (missing #include's)
author pl
date Thu, 25 Oct 2001 23:34:14 +0000
parents 3b5f5d1c5041
children 470d571ccb16
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;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 if(argc>1) video_driver=argv[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 // check video_out driver name:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 if(!video_driver)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 video_out=video_out_drivers[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 for (i=0; video_out_drivers[i] != NULL; i++){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 const vo_info_t *info = video_out_drivers[i]->get_info ();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 if(strcmp(info->short_name,video_driver) == 0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 video_out = video_out_drivers[i];break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 if(!video_out){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 printf("Invalid video output driver name: %s\n",video_driver);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 }
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 /* open */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 if (-1 == fd && -1 == (fd = open(DEVNAME,O_RDWR))) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 fprintf(stderr,"open %s: %s\n",DEVNAME,strerror(errno));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 exit(1);
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 /* get settings */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 if (-1 == ioctl(fd,VIDIOCGCAP,&capability)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 perror("ioctl VIDIOCGCAP");
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 if (-1 == ioctl(fd,VIDIOCGCHAN,&channel))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 perror("ioctl VIDIOCGCHAN");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 /* mmap() buffer */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 if (-1 == ioctl(fd,VIDIOCGMBUF,&gb_buffers)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 perror("ioctl VIDIOCGMBUF");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 map = mmap(0,gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 if ((unsigned char*)-1 == map) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 perror("mmap");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 fprintf(stderr,"v4l: mmap()'ed buffer size = 0x%x\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 gb_buffers.size);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 /* prepare for grabbing */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 gb1.format = VIDEO_PALETTE_YUV422;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 // gb1.format = VIDEO_PALETTE_RGB24;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 gb1.frame = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 gb1.width = 352;//720;//640;//320;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 gb1.height = 288;//576;//480;//240;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 gb2.format = gb1.format;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 gb2.frame = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 gb2.width = gb1.width;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 gb2.height = gb1.height;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_YUY2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 // video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_RGB|24);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 if (-1 == ioctl(fd,VIDIOCMCAPTURE,&gb1)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 if (errno == EAGAIN)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 perror("ioctl VIDIOCMCAPTURE");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 count++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 while(1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 // MAIN LOOP
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 if (-1 == ioctl(fd,VIDIOCMCAPTURE,(count%2) ? &gb2 : &gb1)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 if (errno == EAGAIN)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 perror("ioctl VIDIOCMCAPTURE");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 if (-1 == ioctl(fd,VIDIOCSYNC,(count%2) ? &gb1.frame : &gb2.frame)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 perror("ioctl VIDIOCSYNC");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 exit(1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 frame=map + gb_buffers.offsets[(count%2) ? 0 : 1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 video_out->draw_frame((unsigned char**)&frame);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 video_out->flip_page();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 count++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 { FILE *f=fopen("frame.yuv","wb");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 fwrite(map,320*240*2,1,f);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 fclose(f);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 video_out->init(320,240,800,600,0,0,IMGFMT_YUY2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 video_out->draw_frame(count?map1:map2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 video_out->flip_page();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 getchar();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148
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 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152