.. | .. |
---|
13 | 13 | #define _MEDIA_VIDEOBUF2_V4L2_H |
---|
14 | 14 | |
---|
15 | 15 | #include <linux/videodev2.h> |
---|
| 16 | +#include <linux/android_kabi.h> |
---|
16 | 17 | #include <media/videobuf2-core.h> |
---|
17 | 18 | |
---|
18 | 19 | #if VB2_MAX_FRAME != VIDEO_MAX_FRAME |
---|
.. | .. |
---|
23 | 24 | #error VB2_MAX_PLANES != VIDEO_MAX_PLANES |
---|
24 | 25 | #endif |
---|
25 | 26 | |
---|
| 27 | +struct video_device; |
---|
| 28 | + |
---|
26 | 29 | /** |
---|
27 | 30 | * struct vb2_v4l2_buffer - video buffer information for v4l2. |
---|
28 | 31 | * |
---|
.. | .. |
---|
32 | 35 | * &enum v4l2_field. |
---|
33 | 36 | * @timecode: frame timecode. |
---|
34 | 37 | * @sequence: sequence count of this frame. |
---|
| 38 | + * @request_fd: the request_fd associated with this buffer |
---|
| 39 | + * @is_held: if true, then this capture buffer was held |
---|
| 40 | + * @planes: plane information (userptr/fd, length, bytesused, data_offset). |
---|
35 | 41 | * |
---|
36 | 42 | * Should contain enough information to be able to cover all the fields |
---|
37 | 43 | * of &struct v4l2_buffer at ``videodev2.h``. |
---|
.. | .. |
---|
43 | 49 | __u32 field; |
---|
44 | 50 | struct v4l2_timecode timecode; |
---|
45 | 51 | __u32 sequence; |
---|
| 52 | + __s32 request_fd; |
---|
| 53 | + bool is_held; |
---|
| 54 | + struct vb2_plane planes[VB2_MAX_PLANES]; |
---|
| 55 | + |
---|
| 56 | + ANDROID_KABI_RESERVE(1); |
---|
46 | 57 | }; |
---|
| 58 | + |
---|
| 59 | +/* VB2 V4L2 flags as set in vb2_queue.subsystem_flags */ |
---|
| 60 | +#define VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 0) |
---|
47 | 61 | |
---|
48 | 62 | /* |
---|
49 | 63 | * to_vb2_v4l2_buffer() - cast struct vb2_buffer * to struct vb2_v4l2_buffer * |
---|
50 | 64 | */ |
---|
51 | 65 | #define to_vb2_v4l2_buffer(vb) \ |
---|
52 | 66 | container_of(vb, struct vb2_v4l2_buffer, vb2_buf) |
---|
| 67 | + |
---|
| 68 | +/** |
---|
| 69 | + * vb2_find_timestamp() - Find buffer with given timestamp in the queue |
---|
| 70 | + * |
---|
| 71 | + * @q: pointer to &struct vb2_queue with videobuf2 queue. |
---|
| 72 | + * @timestamp: the timestamp to find. |
---|
| 73 | + * @start_idx: the start index (usually 0) in the buffer array to start |
---|
| 74 | + * searching from. Note that there may be multiple buffers |
---|
| 75 | + * with the same timestamp value, so you can restart the search |
---|
| 76 | + * by setting @start_idx to the previously found index + 1. |
---|
| 77 | + * |
---|
| 78 | + * Returns the buffer index of the buffer with the given @timestamp, or |
---|
| 79 | + * -1 if no buffer with @timestamp was found. |
---|
| 80 | + */ |
---|
| 81 | +int vb2_find_timestamp(const struct vb2_queue *q, u64 timestamp, |
---|
| 82 | + unsigned int start_idx); |
---|
53 | 83 | |
---|
54 | 84 | int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b); |
---|
55 | 85 | |
---|
.. | .. |
---|
77 | 107 | * vb2_prepare_buf() - Pass ownership of a buffer from userspace to the kernel |
---|
78 | 108 | * |
---|
79 | 109 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
---|
| 110 | + * @mdev: pointer to &struct media_device, may be NULL. |
---|
80 | 111 | * @b: buffer structure passed from userspace to |
---|
81 | 112 | * &v4l2_ioctl_ops->vidioc_prepare_buf handler in driver |
---|
82 | 113 | * |
---|
.. | .. |
---|
88 | 119 | * #) verifies the passed buffer, |
---|
89 | 120 | * #) calls &vb2_ops->buf_prepare callback in the driver (if provided), |
---|
90 | 121 | * in which driver-specific buffer initialization can be performed. |
---|
| 122 | + * #) if @b->request_fd is non-zero and @mdev->ops->req_queue is set, |
---|
| 123 | + * then bind the prepared buffer to the request. |
---|
91 | 124 | * |
---|
92 | 125 | * The return values from this function are intended to be directly returned |
---|
93 | 126 | * from &v4l2_ioctl_ops->vidioc_prepare_buf handler in driver. |
---|
94 | 127 | */ |
---|
95 | | -int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b); |
---|
| 128 | +int vb2_prepare_buf(struct vb2_queue *q, struct media_device *mdev, |
---|
| 129 | + struct v4l2_buffer *b); |
---|
96 | 130 | |
---|
97 | 131 | /** |
---|
98 | 132 | * vb2_qbuf() - Queue a buffer from userspace |
---|
99 | 133 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
---|
| 134 | + * @mdev: pointer to &struct media_device, may be NULL. |
---|
100 | 135 | * @b: buffer structure passed from userspace to |
---|
101 | 136 | * &v4l2_ioctl_ops->vidioc_qbuf handler in driver |
---|
102 | 137 | * |
---|
.. | .. |
---|
105 | 140 | * This function: |
---|
106 | 141 | * |
---|
107 | 142 | * #) verifies the passed buffer; |
---|
| 143 | + * #) if @b->request_fd is non-zero and @mdev->ops->req_queue is set, |
---|
| 144 | + * then bind the buffer to the request. |
---|
108 | 145 | * #) if necessary, calls &vb2_ops->buf_prepare callback in the driver |
---|
109 | 146 | * (if provided), in which driver-specific buffer initialization can |
---|
110 | 147 | * be performed; |
---|
.. | .. |
---|
114 | 151 | * The return values from this function are intended to be directly returned |
---|
115 | 152 | * from &v4l2_ioctl_ops->vidioc_qbuf handler in driver. |
---|
116 | 153 | */ |
---|
117 | | -int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b); |
---|
| 154 | +int vb2_qbuf(struct vb2_queue *q, struct media_device *mdev, |
---|
| 155 | + struct v4l2_buffer *b); |
---|
118 | 156 | |
---|
119 | 157 | /** |
---|
120 | 158 | * vb2_expbuf() - Export a buffer as a file descriptor |
---|
.. | .. |
---|
204 | 242 | int __must_check vb2_queue_init(struct vb2_queue *q); |
---|
205 | 243 | |
---|
206 | 244 | /** |
---|
| 245 | + * vb2_queue_init_name() - initialize a videobuf2 queue with a name |
---|
| 246 | + * @q: pointer to &struct vb2_queue with videobuf2 queue. |
---|
| 247 | + * @name: the queue name |
---|
| 248 | + * |
---|
| 249 | + * This function initializes the vb2_queue exactly like vb2_queue_init(), |
---|
| 250 | + * and additionally sets the queue name. The queue name is used for logging |
---|
| 251 | + * purpose, and should uniquely identify the queue within the context of the |
---|
| 252 | + * device it belongs to. This is useful to attribute kernel log messages to the |
---|
| 253 | + * right queue for m2m devices or other devices that handle multiple queues. |
---|
| 254 | + */ |
---|
| 255 | +int __must_check vb2_queue_init_name(struct vb2_queue *q, const char *name); |
---|
| 256 | + |
---|
| 257 | +/** |
---|
207 | 258 | * vb2_queue_release() - stop streaming, release the queue and free memory |
---|
208 | 259 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
---|
209 | 260 | * |
---|
.. | .. |
---|
274 | 325 | #endif |
---|
275 | 326 | |
---|
276 | 327 | /** |
---|
| 328 | + * vb2_video_unregister_device - unregister the video device and release queue |
---|
| 329 | + * |
---|
| 330 | + * @vdev: pointer to &struct video_device |
---|
| 331 | + * |
---|
| 332 | + * If the driver uses vb2_fop_release()/_vb2_fop_release(), then it should use |
---|
| 333 | + * vb2_video_unregister_device() instead of video_unregister_device(). |
---|
| 334 | + * |
---|
| 335 | + * This function will call video_unregister_device() and then release the |
---|
| 336 | + * vb2_queue if streaming is in progress. This will stop streaming and |
---|
| 337 | + * this will simplify the unbind sequence since after this call all subdevs |
---|
| 338 | + * will have stopped streaming as well. |
---|
| 339 | + */ |
---|
| 340 | +void vb2_video_unregister_device(struct video_device *vdev); |
---|
| 341 | + |
---|
| 342 | +/** |
---|
277 | 343 | * vb2_ops_wait_prepare - helper function to lock a struct &vb2_queue |
---|
278 | 344 | * |
---|
279 | 345 | * @vq: pointer to &struct vb2_queue |
---|
.. | .. |
---|
291 | 357 | */ |
---|
292 | 358 | void vb2_ops_wait_finish(struct vb2_queue *vq); |
---|
293 | 359 | |
---|
| 360 | +struct media_request; |
---|
| 361 | +int vb2_request_validate(struct media_request *req); |
---|
| 362 | +void vb2_request_queue(struct media_request *req); |
---|
| 363 | + |
---|
294 | 364 | #endif /* _MEDIA_VIDEOBUF2_V4L2_H */ |
---|