uvc_queue.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /* Maximum frame size in bytes, for sanity checking. */
  8. #define UVC_MAX_FRAME_SIZE (16*1024*1024)
  9. /* Maximum number of video buffers. */
  10. #define UVC_MAX_VIDEO_BUFFERS 32
  11. /* ------------------------------------------------------------------------
  12. * Structures.
  13. */
  14. enum uvc_buffer_state {
  15. UVC_BUF_STATE_IDLE = 0,
  16. UVC_BUF_STATE_QUEUED = 1,
  17. UVC_BUF_STATE_ACTIVE = 2,
  18. UVC_BUF_STATE_DONE = 3,
  19. UVC_BUF_STATE_ERROR = 4,
  20. };
  21. struct uvc_buffer {
  22. unsigned long vma_use_count;
  23. struct list_head stream;
  24. /* Touched by interrupt handler. */
  25. struct v4l2_buffer buf;
  26. struct list_head queue;
  27. wait_queue_head_t wait;
  28. enum uvc_buffer_state state;
  29. };
  30. #define UVC_QUEUE_STREAMING (1 << 0)
  31. #define UVC_QUEUE_DISCONNECTED (1 << 1)
  32. #define UVC_QUEUE_DROP_INCOMPLETE (1 << 2)
  33. #define UVC_QUEUE_PAUSED (1 << 3)
  34. struct uvc_video_queue {
  35. enum v4l2_buf_type type;
  36. void *mem;
  37. unsigned int flags;
  38. __u32 sequence;
  39. unsigned int count;
  40. unsigned int buf_size;
  41. unsigned int buf_used;
  42. struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
  43. struct mutex mutex; /* protects buffers and mainqueue */
  44. spinlock_t irqlock; /* protects irqqueue */
  45. struct list_head mainqueue;
  46. struct list_head irqqueue;
  47. };
  48. extern void uvc_queue_init(struct uvc_video_queue *queue,
  49. enum v4l2_buf_type type);
  50. extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
  51. unsigned int nbuffers, unsigned int buflength);
  52. extern int uvc_free_buffers(struct uvc_video_queue *queue);
  53. extern int uvc_query_buffer(struct uvc_video_queue *queue,
  54. struct v4l2_buffer *v4l2_buf);
  55. extern int uvc_queue_buffer(struct uvc_video_queue *queue,
  56. struct v4l2_buffer *v4l2_buf);
  57. extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
  58. struct v4l2_buffer *v4l2_buf, int nonblocking);
  59. extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
  60. extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
  61. extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
  62. struct uvc_buffer *buf);
  63. extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
  64. struct file *file, poll_table *wait);
  65. extern int uvc_queue_mmap(struct uvc_video_queue *queue,
  66. struct vm_area_struct *vma);
  67. static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
  68. {
  69. return queue->flags & UVC_QUEUE_STREAMING;
  70. }
  71. extern struct uvc_buffer *uvc_queue_head(struct uvc_video_queue *queue);
  72. #endif /* __KERNEL__ */
  73. #endif /* _UVC_QUEUE_H_ */