linux_驱动_v4l2_VIDIOC_QBUF与VIDIOC_DQBUF_camera

ioctl VIDIOC_QBUF, VIDIOC_DQBUF
NameVIDIOC_QBUF, VIDIOC_DQBUF -- Exchange a buffer with the driver
Synopsis

int ioctl(int fd, int request, struct v4l2_buffer *argp);

Arguments

fd

File descriptor returned by open().

request

VIDIOC_QBUF, VIDIOC_DQBUF

argp

Description
应用程序的获取队列和驱动程序的输出队列,是对接的。
QBUF:
应用程序用来入队一个空的获取队列,或者是填充一个驱动的输入队列中的输出buffer,说法依赖于I/O方法。

Applications call the VIDIOC_QBUF ioctl to enqueue an empty (capturing) or filled (output) buffer in the driver's incoming queue. The semantics语义 depend on the selected I/O method.



要是想入队一个内存mapped的buffer,应用程序设置一个v4l_buffer结构体的type域(与先前的v4l_format的type 和 v4l_requestbuffers的type 一样 ),设置memory域为

V4L2_MEMORY_MMAP  以及index域。可用的index的number从0到被分配的buffers的数字。

To enqueue a memory mapped buffer applications set the type field of a struct v4l2_buffer to the same buffer type as previously struct v4l2_format type and struct v4l2_requestbuffers type, the memory field to V4L2_MEMORY_MMAP and the index field. Valid index numbers range from zero to the number of buffers allocated


 withVIDIOC_REQBUFS (struct v4l2_requestbuffers count) minus one. The contents of the struct v4l2_buffer returned by a VIDIOC_QUERYBUF ioctl will do as well. When the buffer is intended for output (type is V4L2_BUF_TYPE_VIDEO_OUTPUT or V4L2_BUF_TYPE_VBI_OUTPUT) applications must also initialize the bytesused, field and timestamp fields. SeeSection 3.5 for details. When VIDIOC_QBUF is called with a pointer to this structure the driver sets


 the V4L2_BUF_FLAG_MAPPED and V4L2_BUF_FLAG_QUEUED flags and clears the V4L2_BUF_FLAG_DONE flag in the flags field, or it returns an EINVAL error code.


To enqueue a user pointer buffer applications set the type field of a struct v4l2_buffer to the same buffer type as previously struct v4l2_format type and struct v4l2_requestbuffers type, the memory field to V4L2_MEMORY_USERPTR and the m.userptr field to the address of the buffer and length to its size. When the buffer is intended for output additional fields must be set as above. When VIDIOC_QBUF is called with a pointer to this structure the driver sets the V4L2_BUF_FLAG_QUEUED flag and clears


 the V4L2_BUF_FLAG_MAPPED and V4L2_BUF_FLAG_DONE flags in the flags field, or it returns an error code. This ioctl locks the memory pages of the buffer in physical memory, they cannot be swapped out to disk. Buffers remain locked until dequeued, until the VIDIOC_STREAMOFF or VIDIOC_REQBUFS ioctl are called, or until the device is closed.




应用程序调用DQBUF 出队一个被填满的视频获取buffer或者是一个来自驱动的输出队列的显示用的(输出)buffer。

应用程序,只需要设置一个v4l2_buffer结构的type和memory域。

当使用一个指向这个结构体的指针来调用DQBUF时,驱动会填充这个结构体其他的域,或者发回一个EAGAIN错误码表示缓冲不可用。

Applications call the VIDIOC_DQBUF ioctl to dequeue a filled (capturing) or displayed (output) buffer from the driver's outgoing queue. They just set the type and memoryfields of a struct v4l2_buffer as above, when VIDIOC_DQBUF is called with a pointer to this structure the driver fills the remaining fields or returns an error code.

By default VIDIOC_DQBUF blocks when no buffer is in the outgoing queue. When the O_NONBLOCK flag was given to the open() function, VIDIOC_DQBUF returns immediately with an EAGAIN error code when no buffer is available.

The v4l2_buffer structure is specified in Section 3.5.

Return Value

On success 0 is returned, on error -1 and the errno variable is set appropriately适当的:

EAGAIN 表示没有阻塞的IO在使用O_NONBLOCK时被选中,并且输出队列中没有buffer。

Non-blocking I/O has been selected using O_NONBLOCK and no buffer was in the outgoing queue.

EINVAL

The buffer type is not supported, or the index is out of bounds, or no buffers have been allocated yet, or the userptr or length are invalid.

ENOMEM

Not enough physical or virtual memory was available to enqueue a user pointer buffer.

EIO

VIDIOC_DQBUF failed due to an internal error. Can also indicate temporary problems like signal loss. Note the driver might dequeue an (empty) buffer despite returning an error, or even stop capturing.

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值