videobuf2-v4l2.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * videobuf2-v4l2.h - V4L2 driver helper framework
  3. *
  4. * Copyright (C) 2010 Samsung Electronics
  5. *
  6. * Author: Pawel Osciak <pawel@osciak.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation.
  11. */
  12. #ifndef _MEDIA_VIDEOBUF2_V4L2_H
  13. #define _MEDIA_VIDEOBUF2_V4L2_H
  14. #include <linux/videodev2.h>
  15. #include <media/videobuf2-core.h>
  16. #if VB2_MAX_FRAME != VIDEO_MAX_FRAME
  17. #error VB2_MAX_FRAME != VIDEO_MAX_FRAME
  18. #endif
  19. #if VB2_MAX_PLANES != VIDEO_MAX_PLANES
  20. #error VB2_MAX_PLANES != VIDEO_MAX_PLANES
  21. #endif
  22. /**
  23. * struct vb2_v4l2_buffer - video buffer information for v4l2
  24. * @vb2_buf: video buffer 2
  25. * @flags: buffer informational flags
  26. * @field: enum v4l2_field; field order of the image in the buffer
  27. * @timestamp: frame timestamp
  28. * @timecode: frame timecode
  29. * @sequence: sequence count of this frame
  30. * Should contain enough information to be able to cover all the fields
  31. * of struct v4l2_buffer at videodev2.h
  32. */
  33. struct vb2_v4l2_buffer {
  34. struct vb2_buffer vb2_buf;
  35. __u32 flags;
  36. __u32 field;
  37. struct timeval timestamp;
  38. struct v4l2_timecode timecode;
  39. __u32 sequence;
  40. };
  41. /*
  42. * to_vb2_v4l2_buffer() - cast struct vb2_buffer * to struct vb2_v4l2_buffer *
  43. */
  44. #define to_vb2_v4l2_buffer(vb) \
  45. container_of(vb, struct vb2_v4l2_buffer, vb2_buf)
  46. int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
  47. int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req);
  48. int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create);
  49. int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b);
  50. int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
  51. int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb);
  52. int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking);
  53. int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type);
  54. int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type);
  55. int __must_check vb2_queue_init(struct vb2_queue *q);
  56. void vb2_queue_release(struct vb2_queue *q);
  57. unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
  58. size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
  59. loff_t *ppos, int nonblock);
  60. size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
  61. loff_t *ppos, int nonblock);
  62. /*
  63. * vb2_thread_fnc - callback function for use with vb2_thread
  64. *
  65. * This is called whenever a buffer is dequeued in the thread.
  66. */
  67. typedef int (*vb2_thread_fnc)(struct vb2_buffer *vb, void *priv);
  68. /**
  69. * vb2_thread_start() - start a thread for the given queue.
  70. * @q: videobuf queue
  71. * @fnc: callback function
  72. * @priv: priv pointer passed to the callback function
  73. * @thread_name:the name of the thread. This will be prefixed with "vb2-".
  74. *
  75. * This starts a thread that will queue and dequeue until an error occurs
  76. * or @vb2_thread_stop is called.
  77. *
  78. * This function should not be used for anything else but the videobuf2-dvb
  79. * support. If you think you have another good use-case for this, then please
  80. * contact the linux-media mailinglist first.
  81. */
  82. int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
  83. const char *thread_name);
  84. /**
  85. * vb2_thread_stop() - stop the thread for the given queue.
  86. * @q: videobuf queue
  87. */
  88. int vb2_thread_stop(struct vb2_queue *q);
  89. /*
  90. * The following functions are not part of the vb2 core API, but are simple
  91. * helper functions that you can use in your struct v4l2_file_operations,
  92. * struct v4l2_ioctl_ops and struct vb2_ops. They will serialize if vb2_queue->lock
  93. * or video_device->lock is set, and they will set and test vb2_queue->owner
  94. * to check if the calling filehandle is permitted to do the queuing operation.
  95. */
  96. /* struct v4l2_ioctl_ops helpers */
  97. int vb2_ioctl_reqbufs(struct file *file, void *priv,
  98. struct v4l2_requestbuffers *p);
  99. int vb2_ioctl_create_bufs(struct file *file, void *priv,
  100. struct v4l2_create_buffers *p);
  101. int vb2_ioctl_prepare_buf(struct file *file, void *priv,
  102. struct v4l2_buffer *p);
  103. int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p);
  104. int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p);
  105. int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p);
  106. int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i);
  107. int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i);
  108. int vb2_ioctl_expbuf(struct file *file, void *priv,
  109. struct v4l2_exportbuffer *p);
  110. /* struct v4l2_file_operations helpers */
  111. int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma);
  112. int vb2_fop_release(struct file *file);
  113. int _vb2_fop_release(struct file *file, struct mutex *lock);
  114. ssize_t vb2_fop_write(struct file *file, const char __user *buf,
  115. size_t count, loff_t *ppos);
  116. ssize_t vb2_fop_read(struct file *file, char __user *buf,
  117. size_t count, loff_t *ppos);
  118. unsigned int vb2_fop_poll(struct file *file, poll_table *wait);
  119. #ifndef CONFIG_MMU
  120. unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr,
  121. unsigned long len, unsigned long pgoff, unsigned long flags);
  122. #endif
  123. /* struct vb2_ops helpers, only use if vq->lock is non-NULL. */
  124. void vb2_ops_wait_prepare(struct vb2_queue *vq);
  125. void vb2_ops_wait_finish(struct vb2_queue *vq);
  126. #endif /* _MEDIA_VIDEOBUF2_V4L2_H */