[media] vb2: allow read/write as long as the format is single planar
authorHans Verkuil <hans.verkuil@cisco.com>
Fri, 11 Apr 2014 07:40:03 +0000 (04:40 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Wed, 16 Apr 2014 21:51:58 +0000 (18:51 -0300)
It was impossible to read() or write() a frame if the queue type was multiplanar.
Even if the current format is single planar. Change this to just check whether
the number of planes is 1 or more.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/media/v4l2-core/videobuf2-core.c

index b80fd24debfab24d9c2b97ceb1225bc8daa920f3..4a635c6bb6e1414d16b2179ac24230b5fca6777a 100644 (file)
@@ -2658,6 +2658,7 @@ struct vb2_fileio_buf {
  */
 struct vb2_fileio_data {
        struct v4l2_requestbuffers req;
+       struct v4l2_plane p;
        struct v4l2_buffer b;
        struct vb2_fileio_buf bufs[VIDEO_MAX_FRAME];
        unsigned int cur_index;
@@ -2748,13 +2749,21 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
         * Read mode requires pre queuing of all buffers.
         */
        if (read) {
+               bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
+
                /*
                 * Queue all buffers.
                 */
                for (i = 0; i < q->num_buffers; i++) {
                        struct v4l2_buffer *b = &fileio->b;
+
                        memset(b, 0, sizeof(*b));
                        b->type = q->type;
+                       if (is_multiplanar) {
+                               memset(&fileio->p, 0, sizeof(fileio->p));
+                               b->m.planes = &fileio->p;
+                               b->length = 1;
+                       }
                        b->memory = q->memory;
                        b->index = i;
                        ret = vb2_internal_qbuf(q, b);
@@ -2822,6 +2831,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 {
        struct vb2_fileio_data *fileio;
        struct vb2_fileio_buf *buf;
+       bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
        /*
         * When using write() to write data to an output video node the vb2 core
         * should set timestamps if V4L2_BUF_FLAG_TIMESTAMP_COPY is set. Nobody
@@ -2861,6 +2871,11 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
                memset(&fileio->b, 0, sizeof(fileio->b));
                fileio->b.type = q->type;
                fileio->b.memory = q->memory;
+               if (is_multiplanar) {
+                       memset(&fileio->p, 0, sizeof(fileio->p));
+                       fileio->b.m.planes = &fileio->p;
+                       fileio->b.length = 1;
+               }
                ret = vb2_internal_dqbuf(q, &fileio->b, nonblock);
                dprintk(5, "vb2_dqbuf result: %d\n", ret);
                if (ret)
@@ -2931,6 +2946,12 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
                fileio->b.memory = q->memory;
                fileio->b.index = index;
                fileio->b.bytesused = buf->pos;
+               if (is_multiplanar) {
+                       memset(&fileio->p, 0, sizeof(fileio->p));
+                       fileio->p.bytesused = buf->pos;
+                       fileio->b.m.planes = &fileio->p;
+                       fileio->b.length = 1;
+               }
                if (set_timestamp)
                        v4l2_get_timestamp(&fileio->b.timestamp);
                ret = vb2_internal_qbuf(q, &fileio->b);