int fd_init()
{
fd = open("/dev/video0", O_RDWR);
if(fd == -1) { error_exit("capture device"); }
else { printf("******************** Open capture devive success ********************\n");}
struct v4l2_capability cap;
if(ioctl(fd,VIDIOC_QUERYCAP,&cap)==-1) { error_exit("VIOIOV_QUERYCAP"); }
printf("*********************** Capability Informations *************************\n");
printf(" driver: %s\n", cap.driver);
printf(" card: %s\n", cap.card);
printf(" bus_info: %s\n", cap.bus_info);
printf(" version: %u.%u.%u\n", (cap.version >> 16) & 0xFF,(cap.version >> 8) & 0xFF,cap.version & 0xFF);
printf(" capabilities: %08x\n", cap.capabilities);
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
{
printf("******************* Device is no video capture device *********************\n");
return -1;
}
struct v4l2_input input;
CLEAR(input);
if (-1 == ioctl (fd, VIDIOC_G_INPUT, &input.index)) { error_exit ("VIDIOC_G_INPUT");}
if (-1 == ioctl (fd,VIDIOC_ENUMINPUT, &input)) { error_exit ("VIDIOC_ENUMINPUT");}
printf("************************ Input information ************************\n");
printf (" inputname: %s\n", input.name);
switch (input.type) {
case V4L2_INPUT_TYPE_TUNER: printf(" V4L2_INPUT_TYPE_TUNER\n");
case V4L2_INPUT_TYPE_CAMERA: printf(" V4L2_INPUT_TYPE_CAMERA\n");
}
printf (" status: %0x\n", input.status);
struct v4l2_fmtdesc fmtdesc;
CLEAR(fmtdesc);
fmtdesc.index = 0;
fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
printf("********************* Support Format Informations **********************\n");
while ((ret = ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc)) == 0)
{
fmtdesc.index++;
printf(" pixelformat ''%c%c%c%c'', description ''%s''\n",
fmtdesc.pixelformat & 0xFF, (fmtdesc.pixelformat >> 8) & 0xFF, (fmtdesc.pixelformat >> 16) & 0xFF,
(fmtdesc.pixelformat >> 24) & 0xFF, fmtdesc.description);
}
struct v4l2_cropcap cropcap;
struct v4l2_crop crop;
CLEAR(cropcap);
cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (-1 == ioctl (fd, VIDIOC_CROPCAP, &cropcap)) { error_exit("VIDIOC_CROPCAP"); }
CLEAR(crop);
crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
crop.c = cropcap.defrect;
if (-1 == ioctl (fd, VIDIOC_S_CROP, &crop) && errno != EINVAL) { error_exit("VIDIOC_S_CROP"); } |