2 * v4lapi.c -- api to the video4linux interface
4 * author: hackbard@hackdaworld.dyndns.org
12 #include <sys/ioctl.h>
16 #include <linux/videodev.h>
18 int v4l_init(char *dev) {
20 unsigned char buf[500*500];
21 struct video_capability vc;
22 struct video_buffer vb;
23 struct video_window vw;
24 struct video_picture vp;
26 if((fd=open(dev,O_RDONLY))<0) {
31 if(ioctl(fd,VIDIOCGCAP,&vc)<0) {
32 puts("ioctl VIDIOCGCAP failed");
36 printf("video device information:\n");
37 printf("-------------------------\n\n");
38 printf("interface name: %s\n\n",vc.name);
40 printf("capture:\t %c\n",(vc.type&1)?'y':'n');
41 printf("tuner:\t\t %c\n",((vc.type>>1)&1)?'y':'n');
42 printf("teletext:\t %c\n",((vc.type>>2)&1)?'y':'n');
43 printf("overlay:\t %c\n",((vc.type>>3)&1)?'y':'n');
44 printf("chromakey:\t %c\n",((vc.type>>4)&1)?'y':'n');
45 printf("clipping:\t %c\n",((vc.type>>5)&1)?'y':'n');
46 printf("fb memory:\t %c\n",((vc.type>>6)&1)?'y':'n');
47 printf("scalable:\t %c\n",((vc.type>>7)&1)?'y':'n');
48 printf("monochrome:\t %c\n",((vc.type>>8)&1)?'y':'n');
49 printf("subcapture:\t %c\n",((vc.type>>9)&1)?'y':'n');
51 if((vc.type>>10)&1) printf("mpeg ");
52 if((vc.type>>12)&1) printf("mjpeg ");
55 if((vc.type>>11)&1) printf("mpeg ");
56 if((vc.type>>13)&1) printf("mjpeg ");
58 printf("channels:\t %d\n",vc.channels);
59 printf("audios:\t\t %d\n",vc.audios);
60 printf("width:\t\t %d - %d\n",vc.minwidth,vc.maxwidth);
61 printf("height:\t\t %d - %d\n\n",vc.minheight,vc.maxheight);
63 if(ioctl(fd,VIDIOCGFBUF,&vb)<0) {
64 puts("direct framebuffer access unsupported");
69 printf("framebuffer:\n");
70 printf("buffer addr:\t %d\n",vb.base);
71 printf("h: %d - w: %d - d: %d - bpl: %d\n\n",vb.height,vb.width,vb.depth,vb.bytesperline);
74 memset(&vw,0,sizeof(struct video_window));
78 vw.height=vc.maxheight;
80 if(ioctl(fd,VIDIOCSWIN,&vw)<0) {
81 puts("ioctl VIDIOCSWIN failed");
85 if(ioctl(fd,VIDIOCGWIN,&vw)<0) {
86 puts("ioctl VIDIOCGWIN failed");
90 printf("real capture area:\n");
91 printf("x: %u - y: %u\n",vw.x,vw.y);
92 printf("w: %u - h: %u\n",vw.width,vw.height);
93 printf("flags: %08x\n",vw.flags);
95 memset(&vp,0,sizeof(struct video_picture));
97 if(ioctl(fd,VIDIOCGPICT,&vp)<0) {
98 puts("ioctl VIDIOCGPICT failed");
102 printf("picture: b: %04x - h: %04x - c: %04x - c: %04x - w: %04x - d: %04x - p: %04x\n",vp.brightness,vp.hue,vp.colour,vp.contrast,vp.whiteness,vp.depth,vp.palette);
104 if(ioctl(fd,VIDIOCSPICT,&vp)<0) {
105 puts("ioctl VIDIOCSPICT failed");
109 if((res=read(fd,buf,(500*500)))<0) {
113 printf("debug: wrote %d bytes:\n",i);
114 for(i=0;i<res;i++) printf("%c ",buf[i]);