int v4l2_init(CAM_V4L *cam_v4l, const char *dev_name) { int ret = 0; int fd = 0; enum v4l2_buf_type type; fd = ::open(dev_name, O_RDWR); if (fd == -1) { ret = ERR_CAM_OPEN; goto exit; } cam_v4l->fd = fd; cam_v4l->video_buf = NULL; cam_v4l->buf_num = 3; cam_v4l->index = -1; ret = v4l2_get_capability(cam_v4l); if (ret) { goto exit; } ret = v4l2_set_fmt(cam_v4l); if (ret) { goto exit; } ret = v4l2_set_memory(cam_v4l); if (ret) { goto exit; } type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (::ioctl (fd, VIDIOC_STREAMON, &type) < 0) { ret = ERR_CAM_VIDIOC_STREAMON; goto exit; } exit: return ret; }
static void vid_set_fmt(struct vid *v, __u8 *req) { __u32 *fmt_nr = (__u32*)(&req[0]); __u32 *frm_nr = (__u32*)(&req[4]); v4l2_set_fmt(v->cam, *fmt_nr, *frm_nr); }