2008-07-01 02:04:50 +08:00
|
|
|
/*
|
|
|
|
* uvc_queue.c -- USB Video Class driver - Buffers management
|
|
|
|
*
|
2010-09-20 17:10:10 +08:00
|
|
|
* Copyright (C) 2005-2010
|
|
|
|
* Laurent Pinchart (laurent.pinchart@ideasonboard.com)
|
2008-07-01 02:04:50 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
#include <linux/atomic.h>
|
2008-07-01 02:04:50 +08:00
|
|
|
#include <linux/kernel.h>
|
2008-07-24 12:28:13 +08:00
|
|
|
#include <linux/mm.h>
|
2008-07-01 02:04:50 +08:00
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/wait.h>
|
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 21:30:30 +08:00
|
|
|
#include <media/videobuf2-v4l2.h>
|
2011-10-24 22:53:59 +08:00
|
|
|
#include <media/videobuf2-vmalloc.h>
|
2008-07-01 02:04:50 +08:00
|
|
|
|
|
|
|
#include "uvcvideo.h"
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------
|
|
|
|
* Video buffers queue management.
|
|
|
|
*
|
|
|
|
* Video queues is initialized by uvc_queue_init(). The function performs
|
|
|
|
* basic initialization of the uvc_video_queue struct and never fails.
|
|
|
|
*
|
2011-10-24 22:53:59 +08:00
|
|
|
* Video buffers are managed by videobuf2. The driver uses a mutex to protect
|
|
|
|
* the videobuf2 queue operations by serializing calls to videobuf2 and a
|
|
|
|
* spinlock to protect the IRQ queue that holds the buffers to be processed by
|
|
|
|
* the driver.
|
2008-07-01 02:04:50 +08:00
|
|
|
*/
|
|
|
|
|
2014-10-21 23:58:35 +08:00
|
|
|
static inline struct uvc_streaming *
|
|
|
|
uvc_queue_to_stream(struct uvc_video_queue *queue)
|
|
|
|
{
|
|
|
|
return container_of(queue, struct uvc_streaming, queue);
|
|
|
|
}
|
|
|
|
|
2016-12-12 19:16:49 +08:00
|
|
|
static inline struct uvc_buffer *uvc_vbuf_to_buffer(struct vb2_v4l2_buffer *buf)
|
|
|
|
{
|
|
|
|
return container_of(buf, struct uvc_buffer, buf);
|
|
|
|
}
|
|
|
|
|
2014-10-22 03:37:55 +08:00
|
|
|
/*
|
|
|
|
* Return all queued buffers to videobuf2 in the requested state.
|
|
|
|
*
|
|
|
|
* This function must be called with the queue spinlock held.
|
|
|
|
*/
|
|
|
|
static void uvc_queue_return_buffers(struct uvc_video_queue *queue,
|
|
|
|
enum uvc_buffer_state state)
|
|
|
|
{
|
|
|
|
enum vb2_buffer_state vb2_state = state == UVC_BUF_STATE_ERROR
|
|
|
|
? VB2_BUF_STATE_ERROR
|
|
|
|
: VB2_BUF_STATE_QUEUED;
|
|
|
|
|
|
|
|
while (!list_empty(&queue->irqqueue)) {
|
|
|
|
struct uvc_buffer *buf = list_first_entry(&queue->irqqueue,
|
|
|
|
struct uvc_buffer,
|
|
|
|
queue);
|
|
|
|
list_del(&buf->queue);
|
|
|
|
buf->state = state;
|
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 21:30:30 +08:00
|
|
|
vb2_buffer_done(&buf->buf.vb2_buf, vb2_state);
|
2014-10-22 03:37:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* videobuf2 queue operations
|
2010-11-22 01:46:44 +08:00
|
|
|
*/
|
2011-10-24 22:53:59 +08:00
|
|
|
|
2015-10-28 10:50:37 +08:00
|
|
|
static int uvc_queue_setup(struct vb2_queue *vq,
|
2011-10-24 22:53:59 +08:00
|
|
|
unsigned int *nbuffers, unsigned int *nplanes,
|
2016-04-15 20:15:05 +08:00
|
|
|
unsigned int sizes[], struct device *alloc_devs[])
|
2010-11-22 01:46:44 +08:00
|
|
|
{
|
2011-10-24 22:53:59 +08:00
|
|
|
struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
|
2017-12-06 23:15:40 +08:00
|
|
|
struct uvc_streaming *stream;
|
|
|
|
unsigned int size;
|
|
|
|
|
|
|
|
switch (vq->type) {
|
|
|
|
case V4L2_BUF_TYPE_META_CAPTURE:
|
|
|
|
size = UVC_METATADA_BUF_SIZE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
stream = uvc_queue_to_stream(queue);
|
|
|
|
size = stream->ctrl.dwMaxVideoFrameSize;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-22 01:46:44 +08:00
|
|
|
|
2017-08-08 20:56:22 +08:00
|
|
|
/*
|
|
|
|
* When called with plane sizes, validate them. The driver supports
|
|
|
|
* single planar formats only, and requires buffers to be large enough
|
|
|
|
* to store a complete frame.
|
|
|
|
*/
|
2015-10-28 10:50:37 +08:00
|
|
|
if (*nplanes)
|
2017-08-08 20:56:22 +08:00
|
|
|
return *nplanes != 1 || sizes[0] < size ? -EINVAL : 0;
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
*nplanes = 1;
|
2015-10-28 10:50:37 +08:00
|
|
|
sizes[0] = size;
|
2010-11-22 01:46:44 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
static int uvc_buffer_prepare(struct vb2_buffer *vb)
|
2010-11-22 01:46:44 +08:00
|
|
|
{
|
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 21:30:30 +08:00
|
|
|
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
|
2011-10-24 22:53:59 +08:00
|
|
|
struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
|
2016-12-12 19:16:49 +08:00
|
|
|
struct uvc_buffer *buf = uvc_vbuf_to_buffer(vbuf);
|
2010-11-22 01:46:44 +08:00
|
|
|
|
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 21:30:30 +08:00
|
|
|
if (vb->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
|
2011-10-24 22:53:59 +08:00
|
|
|
vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
|
|
|
|
uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2008-07-01 02:04:50 +08:00
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
if (unlikely(queue->flags & UVC_QUEUE_DISCONNECTED))
|
|
|
|
return -ENODEV;
|
2008-07-01 02:04:50 +08:00
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
buf->state = UVC_BUF_STATE_QUEUED;
|
|
|
|
buf->error = 0;
|
|
|
|
buf->mem = vb2_plane_vaddr(vb, 0);
|
|
|
|
buf->length = vb2_plane_size(vb, 0);
|
2017-12-06 23:15:40 +08:00
|
|
|
if (vb->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
|
2011-10-24 22:53:59 +08:00
|
|
|
buf->bytesused = 0;
|
|
|
|
else
|
|
|
|
buf->bytesused = vb2_get_plane_payload(vb, 0);
|
2008-07-01 02:04:50 +08:00
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2008-07-01 02:04:50 +08:00
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
static void uvc_buffer_queue(struct vb2_buffer *vb)
|
|
|
|
{
|
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 21:30:30 +08:00
|
|
|
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
|
2011-10-24 22:53:59 +08:00
|
|
|
struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
|
2016-12-12 19:16:49 +08:00
|
|
|
struct uvc_buffer *buf = uvc_vbuf_to_buffer(vbuf);
|
2011-10-24 22:53:59 +08:00
|
|
|
unsigned long flags;
|
2008-07-01 02:04:50 +08:00
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
spin_lock_irqsave(&queue->irqlock, flags);
|
|
|
|
if (likely(!(queue->flags & UVC_QUEUE_DISCONNECTED))) {
|
|
|
|
list_add_tail(&buf->queue, &queue->irqqueue);
|
|
|
|
} else {
|
|
|
|
/* If the device is disconnected return the buffer to userspace
|
|
|
|
* directly. The next QBUF call will fail with -ENODEV.
|
|
|
|
*/
|
|
|
|
buf->state = UVC_BUF_STATE_ERROR;
|
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 21:30:30 +08:00
|
|
|
vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
|
2008-07-01 02:04:50 +08:00
|
|
|
}
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
spin_unlock_irqrestore(&queue->irqlock, flags);
|
|
|
|
}
|
2008-07-01 02:04:50 +08:00
|
|
|
|
2014-03-04 18:27:13 +08:00
|
|
|
static void uvc_buffer_finish(struct vb2_buffer *vb)
|
2011-09-24 21:46:55 +08:00
|
|
|
{
|
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 21:30:30 +08:00
|
|
|
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
|
2011-09-24 21:46:55 +08:00
|
|
|
struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
|
2014-10-21 23:58:35 +08:00
|
|
|
struct uvc_streaming *stream = uvc_queue_to_stream(queue);
|
2016-12-12 19:16:49 +08:00
|
|
|
struct uvc_buffer *buf = uvc_vbuf_to_buffer(vbuf);
|
2011-09-24 21:46:55 +08:00
|
|
|
|
2014-03-04 18:34:49 +08:00
|
|
|
if (vb->state == VB2_BUF_STATE_DONE)
|
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 21:30:30 +08:00
|
|
|
uvc_video_clock_update(stream, vbuf, buf);
|
2011-09-24 21:46:55 +08:00
|
|
|
}
|
|
|
|
|
2014-10-22 00:03:08 +08:00
|
|
|
static int uvc_start_streaming(struct vb2_queue *vq, unsigned int count)
|
|
|
|
{
|
|
|
|
struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
|
|
|
|
struct uvc_streaming *stream = uvc_queue_to_stream(queue);
|
2014-10-22 03:37:55 +08:00
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
2014-10-22 00:03:08 +08:00
|
|
|
|
|
|
|
queue->buf_used = 0;
|
|
|
|
|
2014-10-22 03:37:55 +08:00
|
|
|
ret = uvc_video_enable(stream, 1);
|
|
|
|
if (ret == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&queue->irqlock, flags);
|
|
|
|
uvc_queue_return_buffers(queue, UVC_BUF_STATE_QUEUED);
|
|
|
|
spin_unlock_irqrestore(&queue->irqlock, flags);
|
|
|
|
|
|
|
|
return ret;
|
2014-10-22 00:03:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uvc_stop_streaming(struct vb2_queue *vq)
|
|
|
|
{
|
|
|
|
struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
|
|
|
|
unsigned long flags;
|
|
|
|
|
2017-12-06 23:15:40 +08:00
|
|
|
if (vq->type != V4L2_BUF_TYPE_META_CAPTURE)
|
|
|
|
uvc_video_enable(uvc_queue_to_stream(queue), 0);
|
2014-10-22 00:03:08 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&queue->irqlock, flags);
|
2014-10-22 03:37:55 +08:00
|
|
|
uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR);
|
2014-10-22 00:03:08 +08:00
|
|
|
spin_unlock_irqrestore(&queue->irqlock, flags);
|
|
|
|
}
|
|
|
|
|
2016-09-09 07:59:01 +08:00
|
|
|
static const struct vb2_ops uvc_queue_qops = {
|
2011-10-24 22:53:59 +08:00
|
|
|
.queue_setup = uvc_queue_setup,
|
|
|
|
.buf_prepare = uvc_buffer_prepare,
|
|
|
|
.buf_queue = uvc_buffer_queue,
|
2011-09-24 21:46:55 +08:00
|
|
|
.buf_finish = uvc_buffer_finish,
|
2014-11-27 07:25:44 +08:00
|
|
|
.wait_prepare = vb2_ops_wait_prepare,
|
|
|
|
.wait_finish = vb2_ops_wait_finish,
|
2014-10-22 00:03:08 +08:00
|
|
|
.start_streaming = uvc_start_streaming,
|
|
|
|
.stop_streaming = uvc_stop_streaming,
|
2011-10-24 22:53:59 +08:00
|
|
|
};
|
2008-07-01 02:04:50 +08:00
|
|
|
|
2017-12-06 23:15:40 +08:00
|
|
|
static const struct vb2_ops uvc_meta_queue_qops = {
|
|
|
|
.queue_setup = uvc_queue_setup,
|
|
|
|
.buf_prepare = uvc_buffer_prepare,
|
|
|
|
.buf_queue = uvc_buffer_queue,
|
|
|
|
.wait_prepare = vb2_ops_wait_prepare,
|
|
|
|
.wait_finish = vb2_ops_wait_finish,
|
|
|
|
.stop_streaming = uvc_stop_streaming,
|
|
|
|
};
|
|
|
|
|
2012-09-26 18:30:34 +08:00
|
|
|
int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
|
2011-10-24 22:53:59 +08:00
|
|
|
int drop_corrupted)
|
|
|
|
{
|
2012-09-26 18:30:34 +08:00
|
|
|
int ret;
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
queue->queue.type = type;
|
2017-12-06 23:15:40 +08:00
|
|
|
queue->queue.io_modes = VB2_MMAP | VB2_USERPTR;
|
2011-10-24 22:53:59 +08:00
|
|
|
queue->queue.drv_priv = queue;
|
|
|
|
queue->queue.buf_struct_size = sizeof(struct uvc_buffer);
|
|
|
|
queue->queue.mem_ops = &vb2_vmalloc_memops;
|
2014-02-11 06:26:44 +08:00
|
|
|
queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
|
|
|
|
| V4L2_BUF_FLAG_TSTAMP_SRC_SOE;
|
2014-11-27 07:25:44 +08:00
|
|
|
queue->queue.lock = &queue->mutex;
|
2017-12-06 23:15:40 +08:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case V4L2_BUF_TYPE_META_CAPTURE:
|
|
|
|
queue->queue.ops = &uvc_meta_queue_qops;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
queue->queue.io_modes |= VB2_DMABUF;
|
|
|
|
queue->queue.ops = &uvc_queue_qops;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-26 18:30:34 +08:00
|
|
|
ret = vb2_queue_init(&queue->queue);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-07-01 02:04:50 +08:00
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
mutex_init(&queue->mutex);
|
|
|
|
spin_lock_init(&queue->irqlock);
|
|
|
|
INIT_LIST_HEAD(&queue->irqqueue);
|
|
|
|
queue->flags = drop_corrupted ? UVC_QUEUE_DROP_CORRUPTED : 0;
|
2012-09-26 18:30:34 +08:00
|
|
|
|
|
|
|
return 0;
|
2008-07-01 02:04:50 +08:00
|
|
|
}
|
|
|
|
|
2014-10-22 03:07:15 +08:00
|
|
|
void uvc_queue_release(struct uvc_video_queue *queue)
|
|
|
|
{
|
|
|
|
mutex_lock(&queue->mutex);
|
|
|
|
vb2_queue_release(&queue->queue);
|
|
|
|
mutex_unlock(&queue->mutex);
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* V4L2 queue operations
|
2009-06-04 20:26:39 +08:00
|
|
|
*/
|
2011-10-24 22:53:59 +08:00
|
|
|
|
2014-10-22 03:02:00 +08:00
|
|
|
int uvc_request_buffers(struct uvc_video_queue *queue,
|
|
|
|
struct v4l2_requestbuffers *rb)
|
2009-06-04 20:26:39 +08:00
|
|
|
{
|
2011-10-24 22:53:59 +08:00
|
|
|
int ret;
|
2009-06-04 20:26:39 +08:00
|
|
|
|
|
|
|
mutex_lock(&queue->mutex);
|
2011-10-24 22:53:59 +08:00
|
|
|
ret = vb2_reqbufs(&queue->queue, rb);
|
2009-06-04 20:26:39 +08:00
|
|
|
mutex_unlock(&queue->mutex);
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
return ret ? ret : rb->count;
|
2009-06-04 20:26:39 +08:00
|
|
|
}
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
int uvc_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf)
|
2008-07-01 02:04:50 +08:00
|
|
|
{
|
2011-10-24 22:53:59 +08:00
|
|
|
int ret;
|
2008-07-01 02:04:50 +08:00
|
|
|
|
|
|
|
mutex_lock(&queue->mutex);
|
2011-10-24 22:53:59 +08:00
|
|
|
ret = vb2_querybuf(&queue->queue, buf);
|
2009-01-04 06:12:40 +08:00
|
|
|
mutex_unlock(&queue->mutex);
|
2011-10-24 22:53:59 +08:00
|
|
|
|
2009-01-04 06:12:40 +08:00
|
|
|
return ret;
|
2008-07-01 02:04:50 +08:00
|
|
|
}
|
|
|
|
|
2014-01-30 00:13:52 +08:00
|
|
|
int uvc_create_buffers(struct uvc_video_queue *queue,
|
|
|
|
struct v4l2_create_buffers *cb)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&queue->mutex);
|
|
|
|
ret = vb2_create_bufs(&queue->queue, cb);
|
|
|
|
mutex_unlock(&queue->mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
int uvc_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf)
|
2008-07-01 02:04:50 +08:00
|
|
|
{
|
2011-10-24 22:53:59 +08:00
|
|
|
int ret;
|
2008-07-01 02:04:50 +08:00
|
|
|
|
|
|
|
mutex_lock(&queue->mutex);
|
2011-10-24 22:53:59 +08:00
|
|
|
ret = vb2_qbuf(&queue->queue, buf);
|
2008-07-01 02:04:50 +08:00
|
|
|
mutex_unlock(&queue->mutex);
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
return ret;
|
2008-07-01 02:04:50 +08:00
|
|
|
}
|
|
|
|
|
2015-04-14 15:19:51 +08:00
|
|
|
int uvc_export_buffer(struct uvc_video_queue *queue,
|
|
|
|
struct v4l2_exportbuffer *exp)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&queue->mutex);
|
|
|
|
ret = vb2_expbuf(&queue->queue, exp);
|
|
|
|
mutex_unlock(&queue->mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
int uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf,
|
|
|
|
int nonblocking)
|
2008-07-01 02:04:50 +08:00
|
|
|
{
|
2011-10-24 22:53:59 +08:00
|
|
|
int ret;
|
2008-07-01 02:04:50 +08:00
|
|
|
|
|
|
|
mutex_lock(&queue->mutex);
|
2011-10-24 22:53:59 +08:00
|
|
|
ret = vb2_dqbuf(&queue->queue, buf, nonblocking);
|
2008-07-01 02:04:50 +08:00
|
|
|
mutex_unlock(&queue->mutex);
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
return ret;
|
2010-11-22 02:18:08 +08:00
|
|
|
}
|
|
|
|
|
2014-10-22 03:19:04 +08:00
|
|
|
int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type type)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&queue->mutex);
|
|
|
|
ret = vb2_streamon(&queue->queue, type);
|
|
|
|
mutex_unlock(&queue->mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type type)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&queue->mutex);
|
|
|
|
ret = vb2_streamoff(&queue->queue, type);
|
|
|
|
mutex_unlock(&queue->mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-22 02:18:08 +08:00
|
|
|
int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma)
|
|
|
|
{
|
2015-02-17 01:38:28 +08:00
|
|
|
return vb2_mmap(&queue->queue, vma);
|
2011-10-24 22:53:59 +08:00
|
|
|
}
|
2010-11-22 02:18:08 +08:00
|
|
|
|
2012-04-30 19:19:10 +08:00
|
|
|
#ifndef CONFIG_MMU
|
|
|
|
unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
|
|
|
|
unsigned long pgoff)
|
|
|
|
{
|
2015-02-17 01:38:28 +08:00
|
|
|
return vb2_get_unmapped_area(&queue->queue, 0, 0, pgoff, 0);
|
2012-04-30 19:19:10 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-07-03 15:02:56 +08:00
|
|
|
__poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file,
|
2011-10-24 22:53:59 +08:00
|
|
|
poll_table *wait)
|
|
|
|
{
|
2017-07-03 15:02:56 +08:00
|
|
|
__poll_t ret;
|
2010-11-22 02:18:08 +08:00
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
mutex_lock(&queue->mutex);
|
|
|
|
ret = vb2_poll(&queue->queue, file, wait);
|
2010-11-22 02:18:08 +08:00
|
|
|
mutex_unlock(&queue->mutex);
|
2011-10-24 22:53:59 +08:00
|
|
|
|
2010-11-22 02:18:08 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:53:59 +08:00
|
|
|
/* -----------------------------------------------------------------------------
|
2008-07-01 02:04:50 +08:00
|
|
|
*
|
|
|
|
*/
|
2011-10-24 22:53:59 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if buffers have been allocated.
|
|
|
|
*/
|
|
|
|
int uvc_queue_allocated(struct uvc_video_queue *queue)
|
2008-07-01 02:04:50 +08:00
|
|
|
{
|
2011-10-24 22:53:59 +08:00
|
|
|
int allocated;
|
2008-07-01 02:04:50 +08:00
|
|
|
|
|
|
|
mutex_lock(&queue->mutex);
|
2011-10-24 22:53:59 +08:00
|
|
|
allocated = vb2_is_busy(&queue->queue);
|
2008-07-01 02:04:50 +08:00
|
|
|
mutex_unlock(&queue->mutex);
|
2011-10-24 22:53:59 +08:00
|
|
|
|
|
|
|
return allocated;
|
2008-07-01 02:04:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel the video buffers queue.
|
|
|
|
*
|
|
|
|
* Cancelling the queue marks all buffers on the irq queue as erroneous,
|
2009-01-04 06:12:40 +08:00
|
|
|
* wakes them up and removes them from the queue.
|
2008-07-01 02:04:50 +08:00
|
|
|
*
|
|
|
|
* If the disconnect parameter is set, further calls to uvc_queue_buffer will
|
|
|
|
* fail with -ENODEV.
|
|
|
|
*
|
|
|
|
* This function acquires the irq spinlock and can be called from interrupt
|
|
|
|
* context.
|
|
|
|
*/
|
|
|
|
void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&queue->irqlock, flags);
|
2014-10-22 03:37:55 +08:00
|
|
|
uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR);
|
2008-07-01 02:04:50 +08:00
|
|
|
/* This must be protected by the irqlock spinlock to avoid race
|
2011-10-24 22:53:59 +08:00
|
|
|
* conditions between uvc_buffer_queue and the disconnection event that
|
2008-07-01 02:04:50 +08:00
|
|
|
* could result in an interruptible wait in uvc_dequeue_buffer. Do not
|
2011-10-24 22:53:59 +08:00
|
|
|
* blindly replace this logic by checking for the UVC_QUEUE_DISCONNECTED
|
2008-07-01 02:04:50 +08:00
|
|
|
* state outside the queue code.
|
|
|
|
*/
|
|
|
|
if (disconnect)
|
|
|
|
queue->flags |= UVC_QUEUE_DISCONNECTED;
|
|
|
|
spin_unlock_irqrestore(&queue->irqlock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
|
|
|
|
struct uvc_buffer *buf)
|
|
|
|
{
|
|
|
|
struct uvc_buffer *nextbuf;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-06-17 17:52:37 +08:00
|
|
|
if ((queue->flags & UVC_QUEUE_DROP_CORRUPTED) && buf->error) {
|
|
|
|
buf->error = 0;
|
2008-07-01 02:04:50 +08:00
|
|
|
buf->state = UVC_BUF_STATE_QUEUED;
|
2012-07-15 21:54:03 +08:00
|
|
|
buf->bytesused = 0;
|
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 21:30:30 +08:00
|
|
|
vb2_set_plane_payload(&buf->buf.vb2_buf, 0, 0);
|
2008-07-01 02:04:50 +08:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&queue->irqlock, flags);
|
|
|
|
list_del(&buf->queue);
|
|
|
|
if (!list_empty(&queue->irqqueue))
|
|
|
|
nextbuf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
|
|
|
|
queue);
|
|
|
|
else
|
|
|
|
nextbuf = NULL;
|
|
|
|
spin_unlock_irqrestore(&queue->irqlock, flags);
|
|
|
|
|
2016-12-12 19:16:51 +08:00
|
|
|
buf->state = buf->error ? UVC_BUF_STATE_ERROR : UVC_BUF_STATE_DONE;
|
[media] media: videobuf2: Restructure vb2_buffer
Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.
Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
<snip>
unsigned int bytesused;
unsigned int length;
union {
unsigned int offset;
unsigned long userptr;
int fd;
} m;
unsigned int data_offset;
}
Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
<snip>
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VIDEO_MAX_PLANES];
<snip>
};
v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct timeval timestamp;
struct v4l2_timecode timecode;
__u32 sequence;
};
Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-09-22 21:30:30 +08:00
|
|
|
vb2_set_plane_payload(&buf->buf.vb2_buf, 0, buf->bytesused);
|
|
|
|
vb2_buffer_done(&buf->buf.vb2_buf, VB2_BUF_STATE_DONE);
|
2011-10-24 22:53:59 +08:00
|
|
|
|
2008-07-01 02:04:50 +08:00
|
|
|
return nextbuf;
|
|
|
|
}
|