1 /* SPDX-License-Identifier: GPL-2.0 */
7 #include <linux/kernel.h>
8 #include <linux/poll.h>
9 #include <linux/videodev2.h>
10 #include <media/videobuf2-v4l2.h>
12 /* Maximum frame size in bytes, for sanity checking. */
13 #define UVC_MAX_FRAME_SIZE (16*1024*1024)
14 /* Maximum number of video buffers. */
15 #define UVC_MAX_VIDEO_BUFFERS 32
17 /* ------------------------------------------------------------------------
21 enum uvc_buffer_state
{
22 UVC_BUF_STATE_IDLE
= 0,
23 UVC_BUF_STATE_QUEUED
= 1,
24 UVC_BUF_STATE_ACTIVE
= 2,
25 UVC_BUF_STATE_DONE
= 3,
26 UVC_BUF_STATE_ERROR
= 4,
30 struct vb2_v4l2_buffer buf
;
31 struct list_head queue
;
33 enum uvc_buffer_state state
;
36 unsigned int bytesused
;
39 #define UVC_QUEUE_DISCONNECTED (1 << 0)
40 #define UVC_QUEUE_DROP_INCOMPLETE (1 << 1)
41 #define UVC_QUEUE_PAUSED (1 << 2)
43 struct uvc_video_queue
{
44 struct vb2_queue queue
;
49 unsigned int buf_used
;
51 spinlock_t irqlock
; /* Protects flags and irqqueue */
52 struct list_head irqqueue
;
55 static inline int uvc_queue_streaming(struct uvc_video_queue
*queue
)
57 return vb2_is_streaming(&queue
->queue
);
60 int uvcg_queue_init(struct uvc_video_queue
*queue
, enum v4l2_buf_type type
,
63 void uvcg_free_buffers(struct uvc_video_queue
*queue
);
65 int uvcg_alloc_buffers(struct uvc_video_queue
*queue
,
66 struct v4l2_requestbuffers
*rb
);
68 int uvcg_query_buffer(struct uvc_video_queue
*queue
, struct v4l2_buffer
*buf
);
70 int uvcg_queue_buffer(struct uvc_video_queue
*queue
, struct v4l2_buffer
*buf
);
72 int uvcg_dequeue_buffer(struct uvc_video_queue
*queue
,
73 struct v4l2_buffer
*buf
, int nonblocking
);
75 __poll_t
uvcg_queue_poll(struct uvc_video_queue
*queue
,
76 struct file
*file
, poll_table
*wait
);
78 int uvcg_queue_mmap(struct uvc_video_queue
*queue
, struct vm_area_struct
*vma
);
81 unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue
*queue
,
83 #endif /* CONFIG_MMU */
85 void uvcg_queue_cancel(struct uvc_video_queue
*queue
, int disconnect
);
87 int uvcg_queue_enable(struct uvc_video_queue
*queue
, int enable
);
89 struct uvc_buffer
*uvcg_queue_next_buffer(struct uvc_video_queue
*queue
,
90 struct uvc_buffer
*buf
);
92 struct uvc_buffer
*uvcg_queue_head(struct uvc_video_queue
*queue
);
94 #endif /* __KERNEL__ */
96 #endif /* _UVC_QUEUE_H_ */