uvc_queue.h 2.4 KB

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