v4l tests
[my-code/ivac.git] / v4lapi.c
1 /*
2  * v4lapi.c -- api to the video4linux interface
3  *
4  * author: hackbard@hackdaworld.dyndns.org
5  *
6  */
7
8 #include <stdio.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <fcntl.h>
12 #include <sys/ioctl.h>
13
14 #include <linux/videodev.h>
15
16 int v4l_init(char *dev) {
17         int fd;
18         struct video_capability vc;
19         struct video_buffer vb;
20         struct video_window vw;
21         
22         if((fd=open(dev,O_RDONLY))<0) {
23                 puts("open failed");
24                 return -1;
25         }
26
27         if(ioctl(fd,VIDIOCGCAP,&vc)<0) {
28                 puts("ioctl VIDIOCGCAP failed");
29                 return -1;
30         }
31
32         printf("video device information:\n");
33         printf("-------------------------\n\n");
34         printf("interface name: %s\n\n",vc.name);
35         printf("type:\n");
36         printf("capture:\t %c\n",(vc.type&1)?'y':'n');
37         printf("tuner:\t\t %c\n",((vc.type>>1)&1)?'y':'n');
38         printf("teletext:\t %c\n",((vc.type>>2)&1)?'y':'n');
39         printf("overlay:\t %c\n",((vc.type>>3)&1)?'y':'n');
40         printf("chromakey:\t %c\n",((vc.type>>4)&1)?'y':'n');
41         printf("clipping:\t %c\n",((vc.type>>5)&1)?'y':'n');
42         printf("fb memory:\t %c\n",((vc.type>>6)&1)?'y':'n');
43         printf("scalable:\t %c\n",((vc.type>>7)&1)?'y':'n');
44         printf("monochrome:\t %c\n",((vc.type>>8)&1)?'y':'n');
45         printf("subcapture:\t %c\n",((vc.type>>9)&1)?'y':'n');
46         printf("decode: ");
47         if((vc.type>>10)&1) printf("mpeg ");
48         if((vc.type>>12)&1) printf("mjpeg ");
49         printf("\n");
50         printf("encode: ");
51         if((vc.type>>11)&1) printf("mpeg ");
52         if((vc.type>>13)&1) printf("mjpeg ");
53         printf("\n\n");
54         printf("channels:\t %d\n",vc.channels);
55         printf("audios:\t\t %d\n",vc.audios);
56         printf("width:\t\t %d - %d\n",vc.minwidth,vc.maxwidth);
57         printf("height:\t\t %d - %d\n\n",vc.minheight,vc.maxheight);
58
59         if(ioctl(fd,VIDIOCGFBUF,&vb)<0)
60                 puts("direct framebuffer access unsupported");
61                 puts("");
62         else {
63                 printf("\n");
64                 printf("framebuffer:\n");
65                 printf("buffer addr:\t %d\n",vb.base);
66                 printf("h: %d - w: %d - d: %d - bpl: %d\n\n",vb.height,vb.width,vb.depth,vb.bytesperline);
67         }
68
69         if(ioctl(fd,VIDIOCGWIN,&vw)<0) {
70                 puts("ioctl VIDIOCGWIN failed");
71                 return -1;
72         }
73
74         printf("capture area:\n");
75         printf("x: %u - y: %u\n",vw.x,vw.y);
76         printf("w: %u - h: %u\n",vw.width,vw.height);
77         printf("
78         return 1;
79 }