Junghak Sung | c139990 | 2015-09-22 10:30:29 -0300 | [diff] [blame] | 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 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 15 | #include <linux/videodev2.h> |
Junghak Sung | c139990 | 2015-09-22 10:30:29 -0300 | [diff] [blame] | 16 | #include <media/videobuf2-core.h> |
| 17 | |
Junghak Sung | bed04f9 | 2015-10-06 06:37:47 -0300 | [diff] [blame] | 18 | #if VB2_MAX_FRAME != VIDEO_MAX_FRAME |
| 19 | #error VB2_MAX_FRAME != VIDEO_MAX_FRAME |
| 20 | #endif |
| 21 | |
| 22 | #if VB2_MAX_PLANES != VIDEO_MAX_PLANES |
| 23 | #error VB2_MAX_PLANES != VIDEO_MAX_PLANES |
| 24 | #endif |
| 25 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 26 | /** |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 27 | * struct vb2_v4l2_buffer - video buffer information for v4l2. |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 28 | * |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 29 | * @vb2_buf: embedded struct &vb2_buffer. |
| 30 | * @flags: buffer informational flags. |
| 31 | * @field: field order of the image in the buffer, as defined by |
| 32 | * &enum v4l2_field. |
| 33 | * @timecode: frame timecode. |
| 34 | * @sequence: sequence count of this frame. |
Hans Verkuil | 394dc58 | 2018-05-30 02:46:22 -0400 | [diff] [blame] | 35 | * @request_fd: the request_fd associated with this buffer |
Hans Verkuil | 137272c | 2019-10-11 06:32:40 -0300 | [diff] [blame] | 36 | * @is_held: if true, then this capture buffer was held |
Hans Verkuil | db6e8d5 | 2018-05-21 04:54:45 -0400 | [diff] [blame] | 37 | * @planes: plane information (userptr/fd, length, bytesused, data_offset). |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 38 | * |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 39 | * Should contain enough information to be able to cover all the fields |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 40 | * of &struct v4l2_buffer at ``videodev2.h``. |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 41 | */ |
| 42 | struct vb2_v4l2_buffer { |
| 43 | struct vb2_buffer vb2_buf; |
| 44 | |
| 45 | __u32 flags; |
| 46 | __u32 field; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 47 | struct v4l2_timecode timecode; |
| 48 | __u32 sequence; |
Hans Verkuil | 394dc58 | 2018-05-30 02:46:22 -0400 | [diff] [blame] | 49 | __s32 request_fd; |
Hans Verkuil | 137272c | 2019-10-11 06:32:40 -0300 | [diff] [blame] | 50 | bool is_held; |
Hans Verkuil | db6e8d5 | 2018-05-21 04:54:45 -0400 | [diff] [blame] | 51 | struct vb2_plane planes[VB2_MAX_PLANES]; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 52 | }; |
| 53 | |
Hans Verkuil | 137272c | 2019-10-11 06:32:40 -0300 | [diff] [blame] | 54 | /* VB2 V4L2 flags as set in vb2_queue.subsystem_flags */ |
| 55 | #define VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 0) |
| 56 | |
Mauro Carvalho Chehab | d383b57 | 2015-10-01 14:23:35 -0300 | [diff] [blame] | 57 | /* |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 58 | * to_vb2_v4l2_buffer() - cast struct vb2_buffer * to struct vb2_v4l2_buffer * |
| 59 | */ |
| 60 | #define to_vb2_v4l2_buffer(vb) \ |
Mauro Carvalho Chehab | d383b57 | 2015-10-01 14:23:35 -0300 | [diff] [blame] | 61 | container_of(vb, struct vb2_v4l2_buffer, vb2_buf) |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 62 | |
Hans Verkuil | 245ede4 | 2018-10-24 06:51:01 -0400 | [diff] [blame] | 63 | /** |
| 64 | * vb2_find_timestamp() - Find buffer with given timestamp in the queue |
| 65 | * |
| 66 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
Hans Verkuil | 03535e7 | 2019-01-24 06:47:49 -0200 | [diff] [blame] | 67 | * @timestamp: the timestamp to find. |
Hans Verkuil | 245ede4 | 2018-10-24 06:51:01 -0400 | [diff] [blame] | 68 | * @start_idx: the start index (usually 0) in the buffer array to start |
| 69 | * searching from. Note that there may be multiple buffers |
| 70 | * with the same timestamp value, so you can restart the search |
| 71 | * by setting @start_idx to the previously found index + 1. |
| 72 | * |
| 73 | * Returns the buffer index of the buffer with the given @timestamp, or |
| 74 | * -1 if no buffer with @timestamp was found. |
| 75 | */ |
| 76 | int vb2_find_timestamp(const struct vb2_queue *q, u64 timestamp, |
| 77 | unsigned int start_idx); |
| 78 | |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 79 | int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b); |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * vb2_reqbufs() - Wrapper for vb2_core_reqbufs() that also verifies |
| 83 | * the memory and type values. |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 84 | * |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 85 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
| 86 | * @req: &struct v4l2_requestbuffers passed from userspace to |
| 87 | * &v4l2_ioctl_ops->vidioc_reqbufs handler in driver. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 88 | */ |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 89 | int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req); |
| 90 | |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 91 | /** |
| 92 | * vb2_create_bufs() - Wrapper for vb2_core_create_bufs() that also verifies |
| 93 | * the memory and type values. |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 94 | * |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 95 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
| 96 | * @create: creation parameters, passed from userspace to |
| 97 | * &v4l2_ioctl_ops->vidioc_create_bufs handler in driver |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 98 | */ |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 99 | int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create); |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * vb2_prepare_buf() - Pass ownership of a buffer from userspace to the kernel |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 103 | * |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 104 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
Hans Verkuil | 394dc58 | 2018-05-30 02:46:22 -0400 | [diff] [blame] | 105 | * @mdev: pointer to &struct media_device, may be NULL. |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 106 | * @b: buffer structure passed from userspace to |
| 107 | * &v4l2_ioctl_ops->vidioc_prepare_buf handler in driver |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 108 | * |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 109 | * Should be called from &v4l2_ioctl_ops->vidioc_prepare_buf ioctl handler |
| 110 | * of a driver. |
| 111 | * |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 112 | * This function: |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 113 | * |
| 114 | * #) verifies the passed buffer, |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 115 | * #) calls &vb2_ops->buf_prepare callback in the driver (if provided), |
| 116 | * in which driver-specific buffer initialization can be performed. |
Hans Verkuil | 394dc58 | 2018-05-30 02:46:22 -0400 | [diff] [blame] | 117 | * #) if @b->request_fd is non-zero and @mdev->ops->req_queue is set, |
| 118 | * then bind the prepared buffer to the request. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 119 | * |
| 120 | * The return values from this function are intended to be directly returned |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 121 | * from &v4l2_ioctl_ops->vidioc_prepare_buf handler in driver. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 122 | */ |
Hans Verkuil | 394dc58 | 2018-05-30 02:46:22 -0400 | [diff] [blame] | 123 | int vb2_prepare_buf(struct vb2_queue *q, struct media_device *mdev, |
| 124 | struct v4l2_buffer *b); |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 125 | |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 126 | /** |
| 127 | * vb2_qbuf() - Queue a buffer from userspace |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 128 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
Hans Verkuil | 394dc58 | 2018-05-30 02:46:22 -0400 | [diff] [blame] | 129 | * @mdev: pointer to &struct media_device, may be NULL. |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 130 | * @b: buffer structure passed from userspace to |
| 131 | * &v4l2_ioctl_ops->vidioc_qbuf handler in driver |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 132 | * |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 133 | * Should be called from &v4l2_ioctl_ops->vidioc_qbuf handler of a driver. |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 134 | * |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 135 | * This function: |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 136 | * |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 137 | * #) verifies the passed buffer; |
Hans Verkuil | 394dc58 | 2018-05-30 02:46:22 -0400 | [diff] [blame] | 138 | * #) if @b->request_fd is non-zero and @mdev->ops->req_queue is set, |
| 139 | * then bind the buffer to the request. |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 140 | * #) if necessary, calls &vb2_ops->buf_prepare callback in the driver |
| 141 | * (if provided), in which driver-specific buffer initialization can |
| 142 | * be performed; |
| 143 | * #) if streaming is on, queues the buffer in driver by the means of |
| 144 | * &vb2_ops->buf_queue callback for processing. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 145 | * |
| 146 | * The return values from this function are intended to be directly returned |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 147 | * from &v4l2_ioctl_ops->vidioc_qbuf handler in driver. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 148 | */ |
Hans Verkuil | 394dc58 | 2018-05-30 02:46:22 -0400 | [diff] [blame] | 149 | int vb2_qbuf(struct vb2_queue *q, struct media_device *mdev, |
| 150 | struct v4l2_buffer *b); |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 151 | |
| 152 | /** |
| 153 | * vb2_expbuf() - Export a buffer as a file descriptor |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 154 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
| 155 | * @eb: export buffer structure passed from userspace to |
| 156 | * &v4l2_ioctl_ops->vidioc_expbuf handler in driver |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 157 | * |
| 158 | * The return values from this function are intended to be directly returned |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 159 | * from &v4l2_ioctl_ops->vidioc_expbuf handler in driver. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 160 | */ |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 161 | int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb); |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * vb2_dqbuf() - Dequeue a buffer to the userspace |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 165 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
| 166 | * @b: buffer structure passed from userspace to |
| 167 | * &v4l2_ioctl_ops->vidioc_dqbuf handler in driver |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 168 | * @nonblocking: if true, this call will not sleep waiting for a buffer if no |
| 169 | * buffers ready for dequeuing are present. Normally the driver |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 170 | * would be passing (&file->f_flags & %O_NONBLOCK) here |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 171 | * |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 172 | * Should be called from &v4l2_ioctl_ops->vidioc_dqbuf ioctl handler |
| 173 | * of a driver. |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 174 | * |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 175 | * This function: |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 176 | * |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 177 | * #) verifies the passed buffer; |
| 178 | * #) calls &vb2_ops->buf_finish callback in the driver (if provided), in which |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 179 | * driver can perform any additional operations that may be required before |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 180 | * returning the buffer to userspace, such as cache sync; |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 181 | * #) the buffer struct members are filled with relevant information for |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 182 | * the userspace. |
| 183 | * |
| 184 | * The return values from this function are intended to be directly returned |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 185 | * from &v4l2_ioctl_ops->vidioc_dqbuf handler in driver. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 186 | */ |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 187 | int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking); |
| 188 | |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 189 | /** |
| 190 | * vb2_streamon - start streaming |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 191 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
| 192 | * @type: type argument passed from userspace to vidioc_streamon handler, |
| 193 | * as defined by &enum v4l2_buf_type. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 194 | * |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 195 | * Should be called from &v4l2_ioctl_ops->vidioc_streamon handler of a driver. |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 196 | * |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 197 | * This function: |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 198 | * |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 199 | * 1) verifies current state |
| 200 | * 2) passes any previously queued buffers to the driver and starts streaming |
| 201 | * |
| 202 | * The return values from this function are intended to be directly returned |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 203 | * from &v4l2_ioctl_ops->vidioc_streamon handler in the driver. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 204 | */ |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 205 | int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type); |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 206 | |
| 207 | /** |
| 208 | * vb2_streamoff - stop streaming |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 209 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 210 | * @type: type argument passed from userspace to vidioc_streamoff handler |
| 211 | * |
| 212 | * Should be called from vidioc_streamoff handler of a driver. |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 213 | * |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 214 | * This function: |
Mauro Carvalho Chehab | bf4404b | 2016-09-08 18:01:44 -0300 | [diff] [blame] | 215 | * |
| 216 | * #) verifies current state, |
| 217 | * #) stop streaming and dequeues any queued buffers, including those previously |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 218 | * passed to the driver (after waiting for the driver to finish). |
| 219 | * |
| 220 | * This call can be used for pausing playback. |
| 221 | * The return values from this function are intended to be directly returned |
| 222 | * from vidioc_streamoff handler in the driver |
| 223 | */ |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 224 | int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type); |
| 225 | |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 226 | /** |
| 227 | * vb2_queue_init() - initialize a videobuf2 queue |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 228 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 229 | * |
| 230 | * The vb2_queue structure should be allocated by the driver. The driver is |
| 231 | * responsible of clearing it's content and setting initial values for some |
| 232 | * required entries before calling this function. |
| 233 | * q->ops, q->mem_ops, q->type and q->io_modes are mandatory. Please refer |
| 234 | * to the struct vb2_queue description in include/media/videobuf2-core.h |
| 235 | * for more information. |
| 236 | */ |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 237 | int __must_check vb2_queue_init(struct vb2_queue *q); |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 238 | |
| 239 | /** |
| 240 | * vb2_queue_release() - stop streaming, release the queue and free memory |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 241 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 242 | * |
| 243 | * This function stops streaming and performs necessary clean ups, including |
| 244 | * freeing video buffer memory. The driver is responsible for freeing |
| 245 | * the vb2_queue structure itself. |
| 246 | */ |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 247 | void vb2_queue_release(struct vb2_queue *q); |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 248 | |
| 249 | /** |
| 250 | * vb2_poll() - implements poll userspace operation |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 251 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
Mauro Carvalho Chehab | 24ade5b | 2016-09-08 14:22:00 -0300 | [diff] [blame] | 252 | * @file: file argument passed to the poll file operation handler |
| 253 | * @wait: wait argument passed to the poll file operation handler |
| 254 | * |
| 255 | * This function implements poll file operation handler for a driver. |
| 256 | * For CAPTURE queues, if a buffer is ready to be dequeued, the userspace will |
| 257 | * be informed that the file descriptor of a video device is available for |
| 258 | * reading. |
| 259 | * For OUTPUT queues, if a buffer is ready to be dequeued, the file descriptor |
| 260 | * will be reported as available for writing. |
| 261 | * |
| 262 | * If the driver uses struct v4l2_fh, then vb2_poll() will also check for any |
| 263 | * pending events. |
| 264 | * |
| 265 | * The return values from this function are intended to be directly returned |
| 266 | * from poll handler in driver. |
| 267 | */ |
Al Viro | c23e0cb | 2017-07-03 03:02:56 -0400 | [diff] [blame] | 268 | __poll_t vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait); |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 269 | |
| 270 | /* |
| 271 | * The following functions are not part of the vb2 core API, but are simple |
| 272 | * helper functions that you can use in your struct v4l2_file_operations, |
| 273 | * struct v4l2_ioctl_ops and struct vb2_ops. They will serialize if vb2_queue->lock |
| 274 | * or video_device->lock is set, and they will set and test vb2_queue->owner |
| 275 | * to check if the calling filehandle is permitted to do the queuing operation. |
| 276 | */ |
| 277 | |
| 278 | /* struct v4l2_ioctl_ops helpers */ |
| 279 | |
| 280 | int vb2_ioctl_reqbufs(struct file *file, void *priv, |
| 281 | struct v4l2_requestbuffers *p); |
| 282 | int vb2_ioctl_create_bufs(struct file *file, void *priv, |
| 283 | struct v4l2_create_buffers *p); |
| 284 | int vb2_ioctl_prepare_buf(struct file *file, void *priv, |
| 285 | struct v4l2_buffer *p); |
| 286 | int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p); |
| 287 | int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p); |
| 288 | int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p); |
| 289 | int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i); |
| 290 | int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i); |
| 291 | int vb2_ioctl_expbuf(struct file *file, void *priv, |
| 292 | struct v4l2_exportbuffer *p); |
| 293 | |
| 294 | /* struct v4l2_file_operations helpers */ |
| 295 | |
| 296 | int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma); |
| 297 | int vb2_fop_release(struct file *file); |
| 298 | int _vb2_fop_release(struct file *file, struct mutex *lock); |
| 299 | ssize_t vb2_fop_write(struct file *file, const char __user *buf, |
| 300 | size_t count, loff_t *ppos); |
| 301 | ssize_t vb2_fop_read(struct file *file, char __user *buf, |
| 302 | size_t count, loff_t *ppos); |
Al Viro | c23e0cb | 2017-07-03 03:02:56 -0400 | [diff] [blame] | 303 | __poll_t vb2_fop_poll(struct file *file, poll_table *wait); |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 304 | #ifndef CONFIG_MMU |
| 305 | unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr, |
| 306 | unsigned long len, unsigned long pgoff, unsigned long flags); |
| 307 | #endif |
| 308 | |
Mauro Carvalho Chehab | dba2d12 | 2016-09-08 18:12:18 -0300 | [diff] [blame] | 309 | /** |
| 310 | * vb2_ops_wait_prepare - helper function to lock a struct &vb2_queue |
| 311 | * |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 312 | * @vq: pointer to &struct vb2_queue |
Mauro Carvalho Chehab | dba2d12 | 2016-09-08 18:12:18 -0300 | [diff] [blame] | 313 | * |
| 314 | * ..note:: only use if vq->lock is non-NULL. |
| 315 | */ |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 316 | void vb2_ops_wait_prepare(struct vb2_queue *vq); |
Mauro Carvalho Chehab | dba2d12 | 2016-09-08 18:12:18 -0300 | [diff] [blame] | 317 | |
| 318 | /** |
| 319 | * vb2_ops_wait_finish - helper function to unlock a struct &vb2_queue |
| 320 | * |
Mauro Carvalho Chehab | 9fbe71b | 2017-10-09 05:36:52 -0400 | [diff] [blame] | 321 | * @vq: pointer to &struct vb2_queue |
Mauro Carvalho Chehab | dba2d12 | 2016-09-08 18:12:18 -0300 | [diff] [blame] | 322 | * |
| 323 | * ..note:: only use if vq->lock is non-NULL. |
| 324 | */ |
Junghak Sung | 3c5be98 | 2015-10-06 06:37:49 -0300 | [diff] [blame] | 325 | void vb2_ops_wait_finish(struct vb2_queue *vq); |
| 326 | |
Hans Verkuil | 86f6bd3 | 2018-05-21 04:54:52 -0400 | [diff] [blame] | 327 | struct media_request; |
| 328 | int vb2_request_validate(struct media_request *req); |
| 329 | void vb2_request_queue(struct media_request *req); |
| 330 | |
Junghak Sung | c139990 | 2015-09-22 10:30:29 -0300 | [diff] [blame] | 331 | #endif /* _MEDIA_VIDEOBUF2_V4L2_H */ |