Commit ebc087d0 authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Mauro Carvalho Chehab

[media] V4L: add a new videobuf2 buffer state VB2_BUF_STATE_PREPARED

This patch prepares for a better separation of the buffer preparation
stage.
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 2b3d0457
...@@ -366,6 +366,7 @@ static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b) ...@@ -366,6 +366,7 @@ static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
b->flags |= V4L2_BUF_FLAG_DONE; b->flags |= V4L2_BUF_FLAG_DONE;
break; break;
case VB2_BUF_STATE_DEQUEUED: case VB2_BUF_STATE_DEQUEUED:
case VB2_BUF_STATE_PREPARED:
/* nothing */ /* nothing */
break; break;
} }
...@@ -832,6 +833,33 @@ static void __enqueue_in_driver(struct vb2_buffer *vb) ...@@ -832,6 +833,33 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
q->ops->buf_queue(vb); q->ops->buf_queue(vb);
} }
static int __buf_prepare(struct vb2_buffer *vb, struct v4l2_buffer *b)
{
struct vb2_queue *q = vb->vb2_queue;
int ret;
switch (q->memory) {
case V4L2_MEMORY_MMAP:
ret = __qbuf_mmap(vb, b);
break;
case V4L2_MEMORY_USERPTR:
ret = __qbuf_userptr(vb, b);
break;
default:
WARN(1, "Invalid queue type\n");
ret = -EINVAL;
}
if (!ret)
ret = call_qop(q, buf_prepare, vb);
if (ret)
dprintk(1, "qbuf: buffer preparation failed: %d\n", ret);
else
vb->state = VB2_BUF_STATE_PREPARED;
return ret;
}
/** /**
* vb2_qbuf() - Queue a buffer from userspace * vb2_qbuf() - Queue a buffer from userspace
* @q: videobuf2 queue * @q: videobuf2 queue
...@@ -841,8 +869,8 @@ static void __enqueue_in_driver(struct vb2_buffer *vb) ...@@ -841,8 +869,8 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
* Should be called from vidioc_qbuf ioctl handler of a driver. * Should be called from vidioc_qbuf ioctl handler of a driver.
* This function: * This function:
* 1) verifies the passed buffer, * 1) verifies the passed buffer,
* 2) calls buf_prepare callback in the driver (if provided), in which * 2) if necessary, calls buf_prepare callback in the driver (if provided), in
* driver-specific buffer initialization can be performed, * which driver-specific buffer initialization can be performed,
* 3) if streaming is on, queues the buffer in driver by the means of buf_queue * 3) if streaming is on, queues the buffer in driver by the means of buf_queue
* callback for processing. * callback for processing.
* *
...@@ -852,7 +880,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb) ...@@ -852,7 +880,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
{ {
struct vb2_buffer *vb; struct vb2_buffer *vb;
int ret = 0; int ret;
if (q->fileio) { if (q->fileio) {
dprintk(1, "qbuf: file io in progress\n"); dprintk(1, "qbuf: file io in progress\n");
...@@ -881,27 +909,16 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) ...@@ -881,27 +909,16 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
return -EINVAL; return -EINVAL;
} }
if (vb->state != VB2_BUF_STATE_DEQUEUED) { switch (vb->state) {
dprintk(1, "qbuf: buffer already in use\n"); case VB2_BUF_STATE_DEQUEUED:
return -EINVAL; ret = __buf_prepare(vb, b);
}
if (q->memory == V4L2_MEMORY_MMAP)
ret = __qbuf_mmap(vb, b);
else if (q->memory == V4L2_MEMORY_USERPTR)
ret = __qbuf_userptr(vb, b);
else {
WARN(1, "Invalid queue type\n");
return -EINVAL;
}
if (ret) if (ret)
return ret; return ret;
case VB2_BUF_STATE_PREPARED:
ret = call_qop(q, buf_prepare, vb); break;
if (ret) { default:
dprintk(1, "qbuf: buffer preparation failed\n"); dprintk(1, "qbuf: buffer already in use\n");
return ret; return -EINVAL;
} }
/* /*
......
...@@ -105,6 +105,7 @@ enum vb2_fileio_flags { ...@@ -105,6 +105,7 @@ enum vb2_fileio_flags {
/** /**
* enum vb2_buffer_state - current video buffer state * enum vb2_buffer_state - current video buffer state
* @VB2_BUF_STATE_DEQUEUED: buffer under userspace control * @VB2_BUF_STATE_DEQUEUED: buffer under userspace control
* @VB2_BUF_STATE_PREPARED: buffer prepared in videobuf and by the driver
* @VB2_BUF_STATE_QUEUED: buffer queued in videobuf, but not in driver * @VB2_BUF_STATE_QUEUED: buffer queued in videobuf, but not in driver
* @VB2_BUF_STATE_ACTIVE: buffer queued in driver and possibly used * @VB2_BUF_STATE_ACTIVE: buffer queued in driver and possibly used
* in a hardware operation * in a hardware operation
...@@ -116,6 +117,7 @@ enum vb2_fileio_flags { ...@@ -116,6 +117,7 @@ enum vb2_fileio_flags {
*/ */
enum vb2_buffer_state { enum vb2_buffer_state {
VB2_BUF_STATE_DEQUEUED, VB2_BUF_STATE_DEQUEUED,
VB2_BUF_STATE_PREPARED,
VB2_BUF_STATE_QUEUED, VB2_BUF_STATE_QUEUED,
VB2_BUF_STATE_ACTIVE, VB2_BUF_STATE_ACTIVE,
VB2_BUF_STATE_DONE, VB2_BUF_STATE_DONE,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment