uvc_queue.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _UVC_QUEUE_H_
  3. #define _UVC_QUEUE_H_
  4. #ifdef __KERNEL__
  5. #include <linux/kernel.h>
  6. #include <linux/poll.h>
  7. #include <linux/videodev2.h>
  8. #include <media/videobuf2-v4l2.h>
  9. /* Maximum frame size in bytes, for sanity checking. */
  10. #define UVC_MAX_FRAME_SIZE (16*1024*1024)
  11. /* Maximum number of video buffers. */
  12. #define UVC_MAX_VIDEO_BUFFERS 32
  13. /* ------------------------------------------------------------------------
  14. * Structures.
  15. */
  16. enum uvc_buffer_state {
  17. UVC_BUF_STATE_IDLE = 0,
  18. UVC_BUF_STATE_QUEUED = 1,
  19. UVC_BUF_STATE_ACTIVE = 2,
  20. UVC_BUF_STATE_DONE = 3,
  21. UVC_BUF_STATE_ERROR = 4,
  22. };
  23. struct uvc_buffer {
  24. struct vb2_v4l2_buffer buf;
  25. struct list_head queue;
  26. enum uvc_buffer_state state;
  27. void *mem;
  28. unsigned int length;
  29. unsigned int bytesused;
  30. };
  31. #define UVC_QUEUE_DISCONNECTED (1 << 0)
  32. #define UVC_QUEUE_DROP_INCOMPLETE (1 << 1)
  33. #define UVC_QUEUE_PAUSED (1 << 2)
  34. struct uvc_video_queue {
  35. struct vb2_queue queue;
  36. unsigned int flags;
  37. __u32 sequence;
  38. unsigned int buf_used;
  39. spinlock_t irqlock; /* Protects flags and irqqueue */
  40. struct list_head irqqueue;
  41. };
  42. static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
  43. {
  44. return vb2_is_streaming(&queue->queue);
  45. }
  46. int uvcg_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
  47. struct mutex *lock);
  48. void uvcg_free_buffers(struct uvc_video_queue *queue);
  49. int uvcg_alloc_buffers(struct uvc_video_queue *queue,
  50. struct v4l2_requestbuffers *rb);
  51. int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
  52. int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf);
  53. int uvcg_dequeue_buffer(struct uvc_video_queue *queue,
  54. struct v4l2_buffer *buf, int nonblocking);
  55. __poll_t uvcg_queue_poll(struct uvc_video_queue *queue,
  56. struct file *file, poll_table *wait);
  57. int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma);
  58. #ifndef CONFIG_MMU
  59. unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue,
  60. unsigned long pgoff);
  61. #endif /* CONFIG_MMU */
  62. void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect);
  63. int uvcg_queue_enable(struct uvc_video_queue *queue, int enable);
  64. struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue,
  65. struct uvc_buffer *buf);
  66. struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue);
  67. #endif /* __KERNEL__ */
  68. #endif /* _UVC_QUEUE_H_ */