摄像头L4V2框架编写APP,对获取数据的由抽象硬件到软件ioctl操作有具体流程。
查询设备能力属性
struct v4l2_capability cap;
ioctl(fd, VIDIOC_QUERYCAP, &cap);
枚举格式
struct v4l2_fmtdesc fmtdesc;
fmtdesc.index = fmt_index;
fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc);
枚举帧大小
struct v4l2_frmsizeenum fsenum;
fsenum.pixel_format = fmtdesc.pixelformat;
fsenum.index = frame_index;
ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &fsenum);
设置格式
struct v4l2_format fmt;
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = 1024;
fmt.fmt.pix.height = 768;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
fmt.fmt.pix.field = V4L2_FIELD_ANY;
ioctl(fd, VIDIOC_S_FMT, &fmt);
申请buffer
struct v4l2_requestbuffers rb;
rb.count = 32;
rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
rb.memory = V4L2_MEMORY_MMAP;
ioctl(fd, VIDIOC_REQBUFS, &rb);
查询buffer是否申请成功
struct v4l2_buffer buf;
buf.index = i;
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
ioctl(fd, VIDIOC_QUERYBUF, &buf);
buffer放入空闲链表
struct v4l2_buffer buf;
buf.index = i;
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
ioctl(fd, VIDIOC_QBUF, &buf);
启动摄像头
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
ioctl(fd, VIDIOC_STREAMON, &type);
buffer取出队列
struct v4l2_buffer buf;
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
ioctl(fd, VIDIOC_DQBUF, &buf);
使用id的 ioctrl命令
//查询设备支持的控制属性
struct v4l2_queryctrl qctrl;
qctrl.id = V4L2_CID_BRIGHTNESS;
ioctl(fd, VIDIOC_QUERYCTRL, &qctrl);
//获取当前的控制值
struct v4l2_control ctl;
ctl.id = V4L2_CID_BRIGHTNESS;
ioctl(fd, VIDIOC_G_CTRL, &ctl);
//设置当前的控制值
struct v4l2_control c;
c.id = V4L2_CID_BRIGHTNESS;
c.value = 99;
ioctl(h->fd, VIDIOC_S_CTRL, &c);