*set v4l2_fh into filp->private_data
for later use,and initial v4l2_fh
*/
filp->private_data
= fh;
if(fh
==
NULL)
return -ENOMEM;
v4l2_fh_init(fh, vdev);
v4l2_fh_add(fh);
return 0;
}
EXPORT_SYMBOL_GPL(v4l2_fh_open);
这个open方法只是初始化了一个v4l2_fh,并关联到filp->private中,方便以后使用
这里设置V4L2_FL_USES_V4L2_FH这个标志位,设置优先级为UNSET,如果我们的自己驱动程序实现了,支持
VIDIOC_SUBSCRIBE_EVENT,那么v4l2_event_init,在events初始化中初始化链表,并设置sequence为-1,如果不支持,则设置fh->events为NULL
最后add list
STEP 2: if (-1 == xioctl (fd, VIDIOC_QUERYCAP, &cap))
这么调用完成下面过程,不行的从驱动层获取cap。直到成功拿到我们想要的数据
static int xioctl
(int fd,int request,void
* arg)
{
int r;
/* Here use this method
to make sure cmd success*/
static int vidioc_reqbufs(struct file
*file, void
*priv,
struct v4l2_requestbuffers *p)
{
struct vivi_dev *dev
= video_drvdata(file);
return vb2_reqbufs(&dev->vb_vidq,
p);
}
到了这里来到了这个全新的话题,实现 vb2_reqbufs(&dev->vb_vidq, p); 这里暂且不讨论这个方法,相对较复杂,待日后研究,先把注释部分放到这里,包括其他内存操作,之后深入研究补充,专门作为一篇整理 /**
* Should be called from vidioc_reqbufs ioctl handler of a driver.
* This function:
* 1) verifies streaming parameters passed from the userspace,
* 2) sets up the queue,
* 3) negotiates number of buffers and planes per buffer with the driver to be used during streaming,
* 4) allocates internal buffer structures (struct vb2_buffer), according to the agreed parameters,
* 5) for MMAP memory type, allocates actual video memory, using the memory handling/allocation routines provided during queue initialization
* If req->count is 0, all the memory will be freed instead.
* If the queue has been allocated previously (by a previous vb2_reqbufs) call
* and the queue is not busy, memory will be reallocated.
* The return values from this function are intended to be directly returned from vidioc_reqbufs handler in driver.
*/
static int vidioc_querybuf(struct file
*file, void
*priv, struct v4l2_buffer
*p)
{
struct vivi_dev *dev
= video_drvdata(file);
return vb2_querybuf(&dev->vb_vidq,
p);
}
/**
* Should be called from vidioc_querybuf ioctl handler in driver.
* This function will verify the passed v4l2_buffer structure and fill the
* relevant information for the userspace.
* The return values from this function are intended to be directly returned from vidioc_querybuf handler in driver.
*/
static int vidioc_qbuf(struct file
*file, void
*priv, struct v4l2_buffer
*p)
{
struct vivi_dev *dev
= video_drvdata(file);
return vb2_qbuf(&dev->vb_vidq,
p);
}
/**
* Should be called from vidioc_qbuf ioctl handler of a driver.
* This function:
* 1) verifies the passed buffer,
* 2) calls buf_prepare callback in the driver (if provided), in which driver-specific buffer initialization can be performed,
* 3) if streaming is on, queues the buffer in driver by the means of buf_queue callback for processing.
* The return values from this function are intended to be directly returned from vidioc_qbuf handler in driver.
*/
static int vidioc_streamon(struct file
*file, void
*priv, enum v4l2_buf_type i)
{
struct vivi_dev *dev
= video_drvdata(file);
return vb2_streamon(&dev->vb_vidq,
i);
}
/**
* Should be called from vidioc_streamon handler of a driver.
* This function:
* 1) verifies current state
* 2) starts streaming and passes any previously queued buffers to the driver
* The return values from this function are intended to be directly returned from vidioc_streamon handler in the driver.
*/
/**
* This function implements poll file operation handler for a driver.
* For CAPTURE queues, if a buffer is ready to be dequeued, the userspace will be informed that the file descriptor of a video device is available for reading.
* For OUTPUT queues, if a buffer is ready to be dequeued, the file descriptor will be reported as available for writing.
* The return values from this function are intended to be directly returned from poll handler in driver.
*/
/**
* Should be called from vidioc_dqbuf ioctl handler of a driver.
* This function:
* 1) verifies the passed buffer,
* 2) calls buf_finish callback in the driver (if provided), in which driver can perform any additional operations that may be required before returning the buffer to userspace, such as cache sync,
* 3) the buffer struct members are filled with relevant information for the userspace.
* The return values from this function are intended to be directly returned from vidioc_dqbuf handler in driver.
*/