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