[media] uvcvideo: Move fields from uvc_buffer::buf to uvc_buffer
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Mon, 24 Oct 2011 14:49:19 +0000 (11:49 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sun, 11 Dec 2011 13:12:05 +0000 (11:12 -0200)
Add mem, length and bytesused fields to the uvc_buffer structure and use
them instead of accessing the uvc_buffer::buf m.offset, length and
bytesused fields directly. This prepares the driver to the conversion to
videobuf2.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/uvc/uvc_isight.c
drivers/media/video/uvc/uvc_queue.c
drivers/media/video/uvc/uvc_video.c
drivers/media/video/uvc/uvcvideo.h

index 74bbe8f18f3e51a6b337a22963a8de2474809763..8510e7259e7639cdf30e343801fa38792dd619f0 100644 (file)
@@ -74,7 +74,7 @@ static int isight_decode(struct uvc_video_queue *queue, struct uvc_buffer *buf,
         * Empty buffers (bytesused == 0) don't trigger end of frame detection
         * as it doesn't make sense to return an empty buffer.
         */
-       if (is_header && buf->buf.bytesused != 0) {
+       if (is_header && buf->bytesused != 0) {
                buf->state = UVC_BUF_STATE_DONE;
                return -EAGAIN;
        }
@@ -83,13 +83,13 @@ static int isight_decode(struct uvc_video_queue *queue, struct uvc_buffer *buf,
         * contain no data.
         */
        if (!is_header) {
-               maxlen = buf->buf.length - buf->buf.bytesused;
-               mem = queue->mem + buf->buf.m.offset + buf->buf.bytesused;
+               maxlen = buf->length - buf->bytesused;
+               mem = buf->mem + buf->bytesused;
                nbytes = min(len, maxlen);
                memcpy(mem, data, nbytes);
-               buf->buf.bytesused += nbytes;
+               buf->bytesused += nbytes;
 
-               if (len > maxlen || buf->buf.bytesused == buf->buf.length) {
+               if (len > maxlen || buf->bytesused == buf->length) {
                        uvc_trace(UVC_TRACE_FRAME, "Frame complete "
                                  "(overflow).\n");
                        buf->state = UVC_BUF_STATE_DONE;
index 677691c44500f1ee0d8212c6639acf64861d1428..0fbb04bc0b044cae446ae8ac25a7dae9f2348cf4 100644 (file)
@@ -173,6 +173,9 @@ int uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers,
                queue->buffer[i].buf.field = V4L2_FIELD_NONE;
                queue->buffer[i].buf.memory = V4L2_MEMORY_MMAP;
                queue->buffer[i].buf.flags = 0;
+
+               queue->buffer[i].mem = queue->mem + i * bufsize;
+               queue->buffer[i].length = buflength;
                init_waitqueue_head(&queue->buffer[i].wait);
        }
 
@@ -293,9 +296,9 @@ int uvc_queue_buffer(struct uvc_video_queue *queue,
        }
        buf->state = UVC_BUF_STATE_QUEUED;
        if (v4l2_buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
-               buf->buf.bytesused = 0;
+               buf->bytesused = 0;
        else
-               buf->buf.bytesused = v4l2_buf->bytesused;
+               buf->bytesused = v4l2_buf->bytesused;
 
        list_add_tail(&buf->stream, &queue->mainqueue);
        list_add_tail(&buf->queue, &queue->irqqueue);
@@ -437,7 +440,7 @@ int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma)
         */
        vma->vm_flags |= VM_IO;
 
-       addr = (unsigned long)queue->mem + buffer->buf.m.offset;
+       addr = (unsigned long)buffer->mem;
 #ifdef CONFIG_MMU
        while (size > 0) {
                page = vmalloc_to_page((void *)addr);
@@ -515,7 +518,7 @@ unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
                ret = -EINVAL;
                goto done;
        }
-       ret = (unsigned long)queue->mem + buffer->buf.m.offset;
+       ret = (unsigned long)buf->mem;
 done:
        mutex_unlock(&queue->mutex);
        return ret;
@@ -621,6 +624,7 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
        list_del(&buf->queue);
        buf->error = 0;
        buf->state = UVC_BUF_STATE_DONE;
+       buf->buf.bytesused = buf->bytesused;
        if (!list_empty(&queue->irqqueue))
                nextbuf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
                                           queue);
index b015e8e5e8b08ad6ade229a02e63f2ea2396edaf..00fe749c0cc0001b19e2613f22e1986c6275e524 100644 (file)
@@ -490,7 +490,7 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
         * avoids detecting end of frame conditions at FID toggling if the
         * previous payload had the EOF bit set.
         */
-       if (fid != stream->last_fid && buf->buf.bytesused != 0) {
+       if (fid != stream->last_fid && buf->bytesused != 0) {
                uvc_trace(UVC_TRACE_FRAME, "Frame complete (FID bit "
                                "toggled).\n");
                buf->state = UVC_BUF_STATE_READY;
@@ -505,7 +505,6 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
 static void uvc_video_decode_data(struct uvc_streaming *stream,
                struct uvc_buffer *buf, const __u8 *data, int len)
 {
-       struct uvc_video_queue *queue = &stream->queue;
        unsigned int maxlen, nbytes;
        void *mem;
 
@@ -513,11 +512,11 @@ static void uvc_video_decode_data(struct uvc_streaming *stream,
                return;
 
        /* Copy the video data to the buffer. */
-       maxlen = buf->buf.length - buf->buf.bytesused;
-       mem = queue->mem + buf->buf.m.offset + buf->buf.bytesused;
+       maxlen = buf->length - buf->bytesused;
+       mem = buf->mem + buf->bytesused;
        nbytes = min((unsigned int)len, maxlen);
        memcpy(mem, data, nbytes);
-       buf->buf.bytesused += nbytes;
+       buf->bytesused += nbytes;
 
        /* Complete the current frame if the buffer size was exceeded. */
        if (len > maxlen) {
@@ -530,7 +529,7 @@ static void uvc_video_decode_end(struct uvc_streaming *stream,
                struct uvc_buffer *buf, const __u8 *data, int len)
 {
        /* Mark the buffer as done if the EOF marker is set. */
-       if (data[1] & UVC_STREAM_EOF && buf->buf.bytesused != 0) {
+       if (data[1] & UVC_STREAM_EOF && buf->bytesused != 0) {
                uvc_trace(UVC_TRACE_FRAME, "Frame complete (EOF found).\n");
                if (data[0] == len)
                        uvc_trace(UVC_TRACE_FRAME, "EOF in empty payload.\n");
@@ -568,8 +567,8 @@ static int uvc_video_encode_data(struct uvc_streaming *stream,
        void *mem;
 
        /* Copy video data to the URB buffer. */
-       mem = queue->mem + buf->buf.m.offset + queue->buf_used;
-       nbytes = min((unsigned int)len, buf->buf.bytesused - queue->buf_used);
+       mem = buf->mem + queue->buf_used;
+       nbytes = min((unsigned int)len, buf->bytesused - queue->buf_used);
        nbytes = min(stream->bulk.max_payload_size - stream->bulk.payload_size,
                        nbytes);
        memcpy(data, mem, nbytes);
@@ -624,7 +623,7 @@ static void uvc_video_decode_isoc(struct urb *urb, struct uvc_streaming *stream,
                        urb->iso_frame_desc[i].actual_length);
 
                if (buf->state == UVC_BUF_STATE_READY) {
-                       if (buf->buf.length != buf->buf.bytesused &&
+                       if (buf->length != buf->bytesused &&
                            !(stream->cur_format->flags &
                              UVC_FMT_FLAG_COMPRESSED))
                                buf->error = 1;
@@ -724,9 +723,9 @@ static void uvc_video_encode_bulk(struct urb *urb, struct uvc_streaming *stream,
        stream->bulk.payload_size += ret;
        len -= ret;
 
-       if (buf->buf.bytesused == stream->queue.buf_used ||
+       if (buf->bytesused == stream->queue.buf_used ||
            stream->bulk.payload_size == stream->bulk.max_payload_size) {
-               if (buf->buf.bytesused == stream->queue.buf_used) {
+               if (buf->bytesused == stream->queue.buf_used) {
                        stream->queue.buf_used = 0;
                        buf->state = UVC_BUF_STATE_READY;
                        buf->buf.sequence = ++stream->sequence;
index 4c1392ebcd4bd2634b245a23209f37c129e7be1f..55f917105b57bfb40261229f2a76120ca1ee2598 100644 (file)
@@ -328,6 +328,10 @@ struct uvc_buffer {
        wait_queue_head_t wait;
        enum uvc_buffer_state state;
        unsigned int error;
+
+       void *mem;
+       unsigned int length;
+       unsigned int bytesused;
 };
 
 #define UVC_QUEUE_STREAMING            (1 << 0)