uvc_queue.h 2.4 KB

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