X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=old%2Fv4lapi.c;fp=old%2Fv4lapi.c;h=92b871a2e88972d7054f776ad7d25975d15ba6e6;hb=0e2dd277897f8959e363564b91dd7d098fb4873c;hp=0000000000000000000000000000000000000000;hpb=6b894156a6cd304f35a959d4388dfb1e1342e844;p=my-code%2Fivac.git diff --git a/old/v4lapi.c b/old/v4lapi.c new file mode 100644 index 0000000..92b871a --- /dev/null +++ b/old/v4lapi.c @@ -0,0 +1,118 @@ +/* + * v4lapi.c -- api to the video4linux interface + * + * author: hackbard@hackdaworld.dyndns.org + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +int v4l_init(char *dev) { + int fd,i,res; + unsigned char buf[500*500]; + struct video_capability vc; + struct video_buffer vb; + struct video_window vw; + struct video_picture vp; + + 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); + } + + memset(&vw,0,sizeof(struct video_window)); + vw.x=0; + vw.y=0; + vw.width=vc.maxwidth; + vw.height=vc.maxheight; + + if(ioctl(fd,VIDIOCSWIN,&vw)<0) { + puts("ioctl VIDIOCSWIN failed"); + return -1; + } + + if(ioctl(fd,VIDIOCGWIN,&vw)<0) { + puts("ioctl VIDIOCGWIN failed"); + return -1; + } + + printf("real capture area:\n"); + printf("x: %u - y: %u\n",vw.x,vw.y); + printf("w: %u - h: %u\n",vw.width,vw.height); + printf("flags: %08x\n",vw.flags); + + memset(&vp,0,sizeof(struct video_picture)); + + if(ioctl(fd,VIDIOCGPICT,&vp)<0) { + puts("ioctl VIDIOCGPICT failed"); + return -1; + } + + 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); + + if(ioctl(fd,VIDIOCSPICT,&vp)<0) { + puts("ioctl VIDIOCSPICT failed"); + return -1; + } + + if((res=read(fd,buf,(500*500)))<0) { + puts("read failed"); + return -1; + } + printf("debug: wrote %d bytes:\n",i); + for(i=0;i