--- /dev/null
+/*
+ * v4lapi.c -- api to the video4linux interface
+ *
+ * author: hackbard@hackdaworld.dyndns.org
+ *
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+#include <linux/videodev.h>
+
+int v4l_init(char *dev) {
+ int fd;
+ struct video_capability vc;
+ struct video_buffer vb;
+ struct video_window vw;
+
+ if((fd=open(dev,O_RDONLY))<0) {
+ puts("open failed");
+ return -1;
+ }
+
+ if(ioctl(fd,VIDIOCGCAP,&vc)<0) {
+ puts("ioctl VIDIOCGCAP failed");
+ return -1;
+ }
+
+ printf("video device information:\n");
+ printf("-------------------------\n\n");
+ printf("interface name: %s\n\n",vc.name);
+ printf("type:\n");
+ printf("capture:\t %c\n",(vc.type&1)?'y':'n');
+ printf("tuner:\t\t %c\n",((vc.type>>1)&1)?'y':'n');
+ printf("teletext:\t %c\n",((vc.type>>2)&1)?'y':'n');
+ printf("overlay:\t %c\n",((vc.type>>3)&1)?'y':'n');
+ printf("chromakey:\t %c\n",((vc.type>>4)&1)?'y':'n');
+ printf("clipping:\t %c\n",((vc.type>>5)&1)?'y':'n');
+ printf("fb memory:\t %c\n",((vc.type>>6)&1)?'y':'n');
+ printf("scalable:\t %c\n",((vc.type>>7)&1)?'y':'n');
+ printf("monochrome:\t %c\n",((vc.type>>8)&1)?'y':'n');
+ printf("subcapture:\t %c\n",((vc.type>>9)&1)?'y':'n');
+ printf("decode: ");
+ if((vc.type>>10)&1) printf("mpeg ");
+ if((vc.type>>12)&1) printf("mjpeg ");
+ printf("\n");
+ printf("encode: ");
+ if((vc.type>>11)&1) printf("mpeg ");
+ if((vc.type>>13)&1) printf("mjpeg ");
+ printf("\n\n");
+ printf("channels:\t %d\n",vc.channels);
+ printf("audios:\t\t %d\n",vc.audios);
+ printf("width:\t\t %d - %d\n",vc.minwidth,vc.maxwidth);
+ printf("height:\t\t %d - %d\n\n",vc.minheight,vc.maxheight);
+
+ if(ioctl(fd,VIDIOCGFBUF,&vb)<0)
+ puts("direct framebuffer access unsupported");
+ puts("");
+ else {
+ printf("\n");
+ printf("framebuffer:\n");
+ printf("buffer addr:\t %d\n",vb.base);
+ printf("h: %d - w: %d - d: %d - bpl: %d\n\n",vb.height,vb.width,vb.depth,vb.bytesperline);
+ }
+
+ if(ioctl(fd,VIDIOCGWIN,&vw)<0) {
+ puts("ioctl VIDIOCGWIN failed");
+ return -1;
+ }
+
+ printf("capture area:\n");
+ printf("x: %u - y: %u\n",vw.x,vw.y);
+ printf("w: %u - h: %u\n",vw.width,vw.height);
+ printf("
+ return 1;
+}