#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
+#include <string.h>
+#include <unistd.h>
#include <linux/videodev.h>
int v4l_init(char *dev) {
- int fd;
+ 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");
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)
+ if(ioctl(fd,VIDIOCGFBUF,&vb)<0) {
puts("direct framebuffer access unsupported");
puts("");
+ }
else {
printf("\n");
printf("framebuffer:\n");
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("capture area:\n");
+ 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("
+ 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<res;i++) printf("%c ",buf[i]);
+ printf("\n");
+
return 1;
}