Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 1 | #ifndef _UVC_QUEUE_H_ |
| 2 | #define _UVC_QUEUE_H_ |
| 3 | |
| 4 | #ifdef __KERNEL__ |
| 5 | |
| 6 | #include <linux/kernel.h> |
| 7 | #include <linux/poll.h> |
| 8 | #include <linux/videodev2.h> |
Junghak Sung | c139990 | 2015-09-22 10:30:29 -0300 | [diff] [blame] | 9 | #include <media/videobuf2-v4l2.h> |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 10 | |
| 11 | /* Maximum frame size in bytes, for sanity checking. */ |
| 12 | #define UVC_MAX_FRAME_SIZE (16*1024*1024) |
| 13 | /* Maximum number of video buffers. */ |
| 14 | #define UVC_MAX_VIDEO_BUFFERS 32 |
| 15 | |
| 16 | /* ------------------------------------------------------------------------ |
| 17 | * Structures. |
| 18 | */ |
| 19 | |
| 20 | enum uvc_buffer_state { |
| 21 | UVC_BUF_STATE_IDLE = 0, |
| 22 | UVC_BUF_STATE_QUEUED = 1, |
| 23 | UVC_BUF_STATE_ACTIVE = 2, |
| 24 | UVC_BUF_STATE_DONE = 3, |
| 25 | UVC_BUF_STATE_ERROR = 4, |
| 26 | }; |
| 27 | |
| 28 | struct uvc_buffer { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 29 | struct vb2_v4l2_buffer buf; |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 30 | struct list_head queue; |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 31 | |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 32 | enum uvc_buffer_state state; |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 33 | void *mem; |
| 34 | unsigned int length; |
| 35 | unsigned int bytesused; |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 36 | }; |
| 37 | |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 38 | #define UVC_QUEUE_DISCONNECTED (1 << 0) |
| 39 | #define UVC_QUEUE_DROP_INCOMPLETE (1 << 1) |
| 40 | #define UVC_QUEUE_PAUSED (1 << 2) |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 41 | |
| 42 | struct uvc_video_queue { |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 43 | struct vb2_queue queue; |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 44 | |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 45 | unsigned int flags; |
| 46 | __u32 sequence; |
| 47 | |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 48 | unsigned int buf_used; |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 49 | |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 50 | spinlock_t irqlock; /* Protects flags and irqqueue */ |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 51 | struct list_head irqqueue; |
| 52 | }; |
| 53 | |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 54 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) |
| 55 | { |
Bhupesh Sharma | d692522 | 2013-03-28 15:11:52 +0530 | [diff] [blame] | 56 | return vb2_is_streaming(&queue->queue); |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 57 | } |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 58 | |
Hans Verkuil | d8e96c4 | 2015-02-17 05:44:06 -0300 | [diff] [blame] | 59 | int uvcg_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type, |
| 60 | struct mutex *lock); |
Andrzej Pietrasiewicz | 3a83c16 | 2014-09-09 02:02:09 +0300 | [diff] [blame] | 61 | |
| 62 | void uvcg_free_buffers(struct uvc_video_queue *queue); |
| 63 | |
| 64 | int uvcg_alloc_buffers(struct uvc_video_queue *queue, |
| 65 | struct v4l2_requestbuffers *rb); |
| 66 | |
| 67 | int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf); |
| 68 | |
| 69 | int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf); |
| 70 | |
| 71 | int uvcg_dequeue_buffer(struct uvc_video_queue *queue, |
| 72 | struct v4l2_buffer *buf, int nonblocking); |
| 73 | |
| 74 | unsigned int uvcg_queue_poll(struct uvc_video_queue *queue, |
| 75 | struct file *file, poll_table *wait); |
| 76 | |
| 77 | int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma); |
| 78 | |
| 79 | #ifndef CONFIG_MMU |
| 80 | unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue, |
| 81 | unsigned long pgoff); |
| 82 | #endif /* CONFIG_MMU */ |
| 83 | |
| 84 | void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect); |
| 85 | |
| 86 | int uvcg_queue_enable(struct uvc_video_queue *queue, int enable); |
| 87 | |
| 88 | struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue, |
| 89 | struct uvc_buffer *buf); |
| 90 | |
| 91 | struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue); |
| 92 | |
Laurent Pinchart | cdda479 | 2010-05-02 20:57:41 +0200 | [diff] [blame] | 93 | #endif /* __KERNEL__ */ |
| 94 | |
| 95 | #endif /* _UVC_QUEUE_H_ */ |
| 96 | |