Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Memory-to-memory device framework for Video for Linux 2. |
| 3 | * |
| 4 | * Helper functions for devices that use memory buffers for both source |
| 5 | * and destination. |
| 6 | * |
| 7 | * Copyright (c) 2009 Samsung Electronics Co., Ltd. |
Pawel Osciak | 9507208 | 2011-03-13 15:23:32 -0300 | [diff] [blame] | 8 | * Pawel Osciak, <pawel@osciak.com> |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 9 | * Marek Szyprowski, <m.szyprowski@samsung.com> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by the |
| 13 | * Free Software Foundation; either version 2 of the |
| 14 | * License, or (at your option) any later version |
| 15 | */ |
| 16 | |
| 17 | #ifndef _MEDIA_V4L2_MEM2MEM_H |
| 18 | #define _MEDIA_V4L2_MEM2MEM_H |
| 19 | |
Junghak Sung | c139990 | 2015-09-22 10:30:29 -0300 | [diff] [blame] | 20 | #include <media/videobuf2-v4l2.h> |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * struct v4l2_m2m_ops - mem-to-mem device driver callbacks |
| 24 | * @device_run: required. Begin the actual job (transaction) inside this |
| 25 | * callback. |
| 26 | * The job does NOT have to end before this callback returns |
| 27 | * (and it will be the usual case). When the job finishes, |
| 28 | * v4l2_m2m_job_finish() has to be called. |
| 29 | * @job_ready: optional. Should return 0 if the driver does not have a job |
| 30 | * fully prepared to run yet (i.e. it will not be able to finish a |
| 31 | * transaction without sleeping). If not provided, it will be |
| 32 | * assumed that one source and one destination buffer are all |
| 33 | * that is required for the driver to perform one full transaction. |
| 34 | * This method may not sleep. |
Ezequiel Garcia | 5525b83 | 2018-06-18 00:38:52 -0400 | [diff] [blame] | 35 | * @job_abort: optional. Informs the driver that it has to abort the currently |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 36 | * running transaction as soon as possible (i.e. as soon as it can |
| 37 | * stop the device safely; e.g. in the next interrupt handler), |
| 38 | * even if the transaction would not have been finished by then. |
| 39 | * After the driver performs the necessary steps, it has to call |
| 40 | * v4l2_m2m_job_finish() (as if the transaction ended normally). |
| 41 | * This function does not have to (and will usually not) wait |
| 42 | * until the device enters a state when it can be stopped. |
| 43 | */ |
| 44 | struct v4l2_m2m_ops { |
| 45 | void (*device_run)(void *priv); |
| 46 | int (*job_ready)(void *priv); |
| 47 | void (*job_abort)(void *priv); |
| 48 | }; |
| 49 | |
Ezequiel Garcia | be2fff6 | 2018-07-02 11:36:05 -0400 | [diff] [blame] | 50 | struct video_device; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 51 | struct v4l2_m2m_dev; |
| 52 | |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 53 | /** |
| 54 | * struct v4l2_m2m_queue_ctx - represents a queue for buffers ready to be |
| 55 | * processed |
| 56 | * |
| 57 | * @q: pointer to struct &vb2_queue |
| 58 | * @rdy_queue: List of V4L2 mem-to-mem queues |
| 59 | * @rdy_spinlock: spin lock to protect the struct usage |
| 60 | * @num_rdy: number of buffers ready to be processed |
| 61 | * @buffered: is the queue buffered? |
| 62 | * |
| 63 | * Queue for buffers ready to be processed as soon as this |
| 64 | * instance receives access to the device. |
| 65 | */ |
| 66 | |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 67 | struct v4l2_m2m_queue_ctx { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 68 | struct vb2_queue q; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 69 | |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 70 | struct list_head rdy_queue; |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 71 | spinlock_t rdy_spinlock; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 72 | u8 num_rdy; |
Philipp Zabel | 33bdd5a | 2013-06-03 04:23:48 -0300 | [diff] [blame] | 73 | bool buffered; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 74 | }; |
| 75 | |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 76 | /** |
| 77 | * struct v4l2_m2m_ctx - Memory to memory context structure |
| 78 | * |
| 79 | * @q_lock: struct &mutex lock |
Mauro Carvalho Chehab | 9f8d3a2 | 2016-09-08 17:20:44 -0300 | [diff] [blame] | 80 | * @m2m_dev: opaque pointer to the internal data to handle M2M context |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 81 | * @cap_q_ctx: Capture (output to memory) queue context |
| 82 | * @out_q_ctx: Output (input from memory) queue context |
| 83 | * @queue: List of memory to memory contexts |
| 84 | * @job_flags: Job queue flags, used internally by v4l2-mem2mem.c: |
| 85 | * %TRANS_QUEUED, %TRANS_RUNNING and %TRANS_ABORT. |
| 86 | * @finished: Wait queue used to signalize when a job queue finished. |
| 87 | * @priv: Instance private data |
Sakari Ailus | 708f48e | 2016-10-18 11:15:32 -0200 | [diff] [blame] | 88 | * |
| 89 | * The memory to memory context is specific to a file handle, NOT to e.g. |
| 90 | * a device. |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 91 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 92 | struct v4l2_m2m_ctx { |
Sylwester Nawrocki | 8e6e8f9 | 2013-09-14 18:39:04 -0300 | [diff] [blame] | 93 | /* optional cap/out vb2 queues lock */ |
| 94 | struct mutex *q_lock; |
| 95 | |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 96 | /* internal use only */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 97 | struct v4l2_m2m_dev *m2m_dev; |
| 98 | |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 99 | struct v4l2_m2m_queue_ctx cap_q_ctx; |
| 100 | |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 101 | struct v4l2_m2m_queue_ctx out_q_ctx; |
| 102 | |
| 103 | /* For device job queue */ |
| 104 | struct list_head queue; |
| 105 | unsigned long job_flags; |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 106 | wait_queue_head_t finished; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 107 | |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 108 | void *priv; |
| 109 | }; |
| 110 | |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 111 | /** |
| 112 | * struct v4l2_m2m_buffer - Memory to memory buffer |
| 113 | * |
| 114 | * @vb: pointer to struct &vb2_v4l2_buffer |
| 115 | * @list: list of m2m buffers |
| 116 | */ |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 117 | struct v4l2_m2m_buffer { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 118 | struct vb2_v4l2_buffer vb; |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 119 | struct list_head list; |
| 120 | }; |
| 121 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 122 | /** |
| 123 | * v4l2_m2m_get_curr_priv() - return driver private data for the currently |
| 124 | * running instance or NULL if no instance is running |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 125 | * |
Mauro Carvalho Chehab | 9f8d3a2 | 2016-09-08 17:20:44 -0300 | [diff] [blame] | 126 | * @m2m_dev: opaque pointer to the internal data to handle M2M context |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 127 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 128 | void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev); |
| 129 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 130 | /** |
| 131 | * v4l2_m2m_get_vq() - return vb2_queue for the given type |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 132 | * |
| 133 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 134 | * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 135 | */ |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 136 | struct vb2_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx, |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 137 | enum v4l2_buf_type type); |
| 138 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 139 | /** |
| 140 | * v4l2_m2m_try_schedule() - check whether an instance is ready to be added to |
| 141 | * the pending job queue and add it if so. |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 142 | * |
| 143 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 144 | * |
| 145 | * There are three basic requirements an instance has to meet to be able to run: |
| 146 | * 1) at least one source buffer has to be queued, |
| 147 | * 2) at least one destination buffer has to be queued, |
| 148 | * 3) streaming has to be on. |
| 149 | * |
| 150 | * If a queue is buffered (for example a decoder hardware ringbuffer that has |
| 151 | * to be drained before doing streamoff), allow scheduling without v4l2 buffers |
| 152 | * on that queue. |
| 153 | * |
| 154 | * There may also be additional, custom requirements. In such case the driver |
| 155 | * should supply a custom callback (job_ready in v4l2_m2m_ops) that should |
| 156 | * return 1 if the instance is ready. |
| 157 | * An example of the above could be an instance that requires more than one |
| 158 | * src/dst buffer per transaction. |
| 159 | */ |
Michael Olbrich | 1190a41 | 2014-07-22 09:36:04 -0300 | [diff] [blame] | 160 | void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx); |
| 161 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 162 | /** |
| 163 | * v4l2_m2m_job_finish() - inform the framework that a job has been finished |
| 164 | * and have it clean up |
| 165 | * |
Mauro Carvalho Chehab | 9f8d3a2 | 2016-09-08 17:20:44 -0300 | [diff] [blame] | 166 | * @m2m_dev: opaque pointer to the internal data to handle M2M context |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 167 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 168 | * |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 169 | * Called by a driver to yield back the device after it has finished with it. |
| 170 | * Should be called as soon as possible after reaching a state which allows |
| 171 | * other instances to take control of the device. |
| 172 | * |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 173 | * This function has to be called only after &v4l2_m2m_ops->device_run |
| 174 | * callback has been called on the driver. To prevent recursion, it should |
| 175 | * not be called directly from the &v4l2_m2m_ops->device_run callback though. |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 176 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 177 | void v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev, |
| 178 | struct v4l2_m2m_ctx *m2m_ctx); |
| 179 | |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 180 | static inline void |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 181 | v4l2_m2m_buf_done(struct vb2_v4l2_buffer *buf, enum vb2_buffer_state state) |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 182 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 183 | vb2_buffer_done(&buf->vb2_buf, state); |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 184 | } |
| 185 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 186 | /** |
| 187 | * v4l2_m2m_reqbufs() - multi-queue-aware REQBUFS multiplexer |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 188 | * |
| 189 | * @file: pointer to struct &file |
| 190 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 191 | * @reqbufs: pointer to struct &v4l2_requestbuffers |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 192 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 193 | int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 194 | struct v4l2_requestbuffers *reqbufs); |
| 195 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 196 | /** |
| 197 | * v4l2_m2m_querybuf() - multi-queue-aware QUERYBUF multiplexer |
| 198 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 199 | * @file: pointer to struct &file |
| 200 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 201 | * @buf: pointer to struct &v4l2_buffer |
| 202 | * |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 203 | * See v4l2_m2m_mmap() documentation for details. |
| 204 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 205 | int v4l2_m2m_querybuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 206 | struct v4l2_buffer *buf); |
| 207 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 208 | /** |
| 209 | * v4l2_m2m_qbuf() - enqueue a source or destination buffer, depending on |
| 210 | * the type |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 211 | * |
| 212 | * @file: pointer to struct &file |
| 213 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 214 | * @buf: pointer to struct &v4l2_buffer |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 215 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 216 | int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 217 | struct v4l2_buffer *buf); |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 218 | |
| 219 | /** |
| 220 | * v4l2_m2m_dqbuf() - dequeue a source or destination buffer, depending on |
| 221 | * the type |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 222 | * |
| 223 | * @file: pointer to struct &file |
| 224 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 225 | * @buf: pointer to struct &v4l2_buffer |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 226 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 227 | int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 228 | struct v4l2_buffer *buf); |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 229 | |
| 230 | /** |
| 231 | * v4l2_m2m_prepare_buf() - prepare a source or destination buffer, depending on |
| 232 | * the type |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 233 | * |
| 234 | * @file: pointer to struct &file |
| 235 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 236 | * @buf: pointer to struct &v4l2_buffer |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 237 | */ |
Hans Verkuil | e68cf47 | 2015-06-05 11:28:50 -0300 | [diff] [blame] | 238 | int v4l2_m2m_prepare_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 239 | struct v4l2_buffer *buf); |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * v4l2_m2m_create_bufs() - create a source or destination buffer, depending |
| 243 | * on the type |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 244 | * |
| 245 | * @file: pointer to struct &file |
| 246 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 247 | * @create: pointer to struct &v4l2_create_buffers |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 248 | */ |
Philipp Zabel | 8b94ca6 | 2013-05-21 04:16:28 -0300 | [diff] [blame] | 249 | int v4l2_m2m_create_bufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 250 | struct v4l2_create_buffers *create); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 251 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 252 | /** |
| 253 | * v4l2_m2m_expbuf() - export a source or destination buffer, depending on |
| 254 | * the type |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 255 | * |
| 256 | * @file: pointer to struct &file |
| 257 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 258 | * @eb: pointer to struct &v4l2_exportbuffer |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 259 | */ |
Tomasz Stanislawski | 83ae7c5 | 2012-06-14 11:32:24 -0300 | [diff] [blame] | 260 | int v4l2_m2m_expbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 261 | struct v4l2_exportbuffer *eb); |
| 262 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 263 | /** |
| 264 | * v4l2_m2m_streamon() - turn on streaming for a video queue |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 265 | * |
| 266 | * @file: pointer to struct &file |
| 267 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 268 | * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 269 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 270 | int v4l2_m2m_streamon(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 271 | enum v4l2_buf_type type); |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 272 | |
| 273 | /** |
| 274 | * v4l2_m2m_streamoff() - turn off streaming for a video queue |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 275 | * |
| 276 | * @file: pointer to struct &file |
| 277 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 278 | * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 279 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 280 | int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 281 | enum v4l2_buf_type type); |
| 282 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 283 | /** |
| 284 | * v4l2_m2m_poll() - poll replacement, for destination buffers only |
| 285 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 286 | * @file: pointer to struct &file |
| 287 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 288 | * @wait: pointer to struct &poll_table_struct |
| 289 | * |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 290 | * Call from the driver's poll() function. Will poll both queues. If a buffer |
| 291 | * is available to dequeue (with dqbuf) from the source queue, this will |
| 292 | * indicate that a non-blocking write can be performed, while read will be |
| 293 | * returned in case of the destination queue. |
| 294 | */ |
Al Viro | c23e0cb | 2017-07-03 03:02:56 -0400 | [diff] [blame] | 295 | __poll_t v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 296 | struct poll_table_struct *wait); |
| 297 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 298 | /** |
| 299 | * v4l2_m2m_mmap() - source and destination queues-aware mmap multiplexer |
| 300 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 301 | * @file: pointer to struct &file |
| 302 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 303 | * @vma: pointer to struct &vm_area_struct |
| 304 | * |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 305 | * Call from driver's mmap() function. Will handle mmap() for both queues |
| 306 | * seamlessly for videobuffer, which will receive normal per-queue offsets and |
| 307 | * proper videobuf queue pointers. The differentiation is made outside videobuf |
| 308 | * by adding a predefined offset to buffers from one of the queues and |
| 309 | * subtracting it before passing it back to videobuf. Only drivers (and |
| 310 | * thus applications) receive modified offsets. |
| 311 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 312 | int v4l2_m2m_mmap(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, |
| 313 | struct vm_area_struct *vma); |
| 314 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 315 | /** |
| 316 | * v4l2_m2m_init() - initialize per-driver m2m data |
| 317 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 318 | * @m2m_ops: pointer to struct v4l2_m2m_ops |
| 319 | * |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 320 | * Usually called from driver's ``probe()`` function. |
| 321 | * |
| 322 | * Return: returns an opaque pointer to the internal data to handle M2M context |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 323 | */ |
Guennadi Liakhovetski | b1252eb | 2012-09-11 06:32:17 -0300 | [diff] [blame] | 324 | struct v4l2_m2m_dev *v4l2_m2m_init(const struct v4l2_m2m_ops *m2m_ops); |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 325 | |
Ezequiel Garcia | be2fff6 | 2018-07-02 11:36:05 -0400 | [diff] [blame] | 326 | #if defined(CONFIG_MEDIA_CONTROLLER) |
| 327 | void v4l2_m2m_unregister_media_controller(struct v4l2_m2m_dev *m2m_dev); |
| 328 | int v4l2_m2m_register_media_controller(struct v4l2_m2m_dev *m2m_dev, |
| 329 | struct video_device *vdev, int function); |
| 330 | #else |
| 331 | static inline void |
| 332 | v4l2_m2m_unregister_media_controller(struct v4l2_m2m_dev *m2m_dev) |
| 333 | { |
| 334 | } |
| 335 | |
| 336 | static inline int |
| 337 | v4l2_m2m_register_media_controller(struct v4l2_m2m_dev *m2m_dev, |
| 338 | struct video_device *vdev, int function) |
| 339 | { |
| 340 | return 0; |
| 341 | } |
| 342 | #endif |
| 343 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 344 | /** |
| 345 | * v4l2_m2m_release() - cleans up and frees a m2m_dev structure |
| 346 | * |
Mauro Carvalho Chehab | 9f8d3a2 | 2016-09-08 17:20:44 -0300 | [diff] [blame] | 347 | * @m2m_dev: opaque pointer to the internal data to handle M2M context |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 348 | * |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 349 | * Usually called from driver's ``remove()`` function. |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 350 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 351 | void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev); |
| 352 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 353 | /** |
| 354 | * v4l2_m2m_ctx_init() - allocate and initialize a m2m context |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 355 | * |
Mauro Carvalho Chehab | 9f8d3a2 | 2016-09-08 17:20:44 -0300 | [diff] [blame] | 356 | * @m2m_dev: opaque pointer to the internal data to handle M2M context |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 357 | * @drv_priv: driver's instance private data |
| 358 | * @queue_init: a callback for queue type-specific initialization function |
| 359 | * to be used for initializing videobuf_queues |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 360 | * |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 361 | * Usually called from driver's ``open()`` function. |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 362 | */ |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 363 | struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(struct v4l2_m2m_dev *m2m_dev, |
| 364 | void *drv_priv, |
| 365 | int (*queue_init)(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)); |
| 366 | |
Philipp Zabel | 33bdd5a | 2013-06-03 04:23:48 -0300 | [diff] [blame] | 367 | static inline void v4l2_m2m_set_src_buffered(struct v4l2_m2m_ctx *m2m_ctx, |
| 368 | bool buffered) |
| 369 | { |
| 370 | m2m_ctx->out_q_ctx.buffered = buffered; |
| 371 | } |
| 372 | |
| 373 | static inline void v4l2_m2m_set_dst_buffered(struct v4l2_m2m_ctx *m2m_ctx, |
| 374 | bool buffered) |
| 375 | { |
| 376 | m2m_ctx->cap_q_ctx.buffered = buffered; |
| 377 | } |
| 378 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 379 | /** |
| 380 | * v4l2_m2m_ctx_release() - release m2m context |
| 381 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 382 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 383 | * |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 384 | * Usually called from driver's release() function. |
| 385 | */ |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 386 | void v4l2_m2m_ctx_release(struct v4l2_m2m_ctx *m2m_ctx); |
| 387 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 388 | /** |
| 389 | * v4l2_m2m_buf_queue() - add a buffer to the proper ready buffers list. |
| 390 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 391 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 392 | * @vbuf: pointer to struct &vb2_v4l2_buffer |
| 393 | * |
Mauro Carvalho Chehab | 5fa5edb | 2016-09-08 10:16:36 -0300 | [diff] [blame] | 394 | * Call from videobuf_queue_ops->ops->buf_queue, videobuf_queue_ops callback. |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 395 | */ |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 396 | void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, |
| 397 | struct vb2_v4l2_buffer *vbuf); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 398 | |
| 399 | /** |
| 400 | * v4l2_m2m_num_src_bufs_ready() - return the number of source buffers ready for |
| 401 | * use |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 402 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 403 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 404 | */ |
| 405 | static inline |
| 406 | unsigned int v4l2_m2m_num_src_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx) |
| 407 | { |
Sascha Hauer | 961ae44 | 2012-08-31 09:18:04 -0300 | [diff] [blame] | 408 | return m2m_ctx->out_q_ctx.num_rdy; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | /** |
Mauro Carvalho Chehab | e383ce0 | 2016-09-22 07:59:03 -0300 | [diff] [blame] | 412 | * v4l2_m2m_num_dst_bufs_ready() - return the number of destination buffers |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 413 | * ready for use |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 414 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 415 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 416 | */ |
| 417 | static inline |
| 418 | unsigned int v4l2_m2m_num_dst_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx) |
| 419 | { |
Sascha Hauer | 961ae44 | 2012-08-31 09:18:04 -0300 | [diff] [blame] | 420 | return m2m_ctx->cap_q_ctx.num_rdy; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 421 | } |
| 422 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 423 | /** |
| 424 | * v4l2_m2m_next_buf() - return next buffer from the list of ready buffers |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 425 | * |
| 426 | * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 427 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame^] | 428 | struct vb2_v4l2_buffer *v4l2_m2m_next_buf(struct v4l2_m2m_queue_ctx *q_ctx); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 429 | |
| 430 | /** |
| 431 | * v4l2_m2m_next_src_buf() - return next source buffer from the list of ready |
| 432 | * buffers |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 433 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 434 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 435 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame^] | 436 | static inline struct vb2_v4l2_buffer * |
| 437 | v4l2_m2m_next_src_buf(struct v4l2_m2m_ctx *m2m_ctx) |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 438 | { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 439 | return v4l2_m2m_next_buf(&m2m_ctx->out_q_ctx); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /** |
| 443 | * v4l2_m2m_next_dst_buf() - return next destination buffer from the list of |
| 444 | * ready buffers |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 445 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 446 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 447 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame^] | 448 | static inline struct vb2_v4l2_buffer * |
| 449 | v4l2_m2m_next_dst_buf(struct v4l2_m2m_ctx *m2m_ctx) |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 450 | { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 451 | return v4l2_m2m_next_buf(&m2m_ctx->cap_q_ctx); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /** |
Hans Verkuil | ee1228c | 2018-06-26 09:26:52 -0400 | [diff] [blame] | 455 | * v4l2_m2m_last_buf() - return last buffer from the list of ready buffers |
| 456 | * |
| 457 | * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx |
| 458 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame^] | 459 | struct vb2_v4l2_buffer *v4l2_m2m_last_buf(struct v4l2_m2m_queue_ctx *q_ctx); |
Hans Verkuil | ee1228c | 2018-06-26 09:26:52 -0400 | [diff] [blame] | 460 | |
| 461 | /** |
| 462 | * v4l2_m2m_last_src_buf() - return last destination buffer from the list of |
| 463 | * ready buffers |
| 464 | * |
| 465 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 466 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame^] | 467 | static inline struct vb2_v4l2_buffer * |
| 468 | v4l2_m2m_last_src_buf(struct v4l2_m2m_ctx *m2m_ctx) |
Hans Verkuil | ee1228c | 2018-06-26 09:26:52 -0400 | [diff] [blame] | 469 | { |
| 470 | return v4l2_m2m_last_buf(&m2m_ctx->out_q_ctx); |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * v4l2_m2m_last_dst_buf() - return last destination buffer from the list of |
| 475 | * ready buffers |
| 476 | * |
| 477 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 478 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame^] | 479 | static inline struct vb2_v4l2_buffer * |
| 480 | v4l2_m2m_last_dst_buf(struct v4l2_m2m_ctx *m2m_ctx) |
Hans Verkuil | ee1228c | 2018-06-26 09:26:52 -0400 | [diff] [blame] | 481 | { |
| 482 | return v4l2_m2m_last_buf(&m2m_ctx->cap_q_ctx); |
| 483 | } |
| 484 | |
| 485 | /** |
Stanimir Varbanov | d498756 | 2017-06-15 13:31:42 -0300 | [diff] [blame] | 486 | * v4l2_m2m_for_each_dst_buf() - iterate over a list of destination ready |
| 487 | * buffers |
| 488 | * |
| 489 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 490 | * @b: current buffer of type struct v4l2_m2m_buffer |
| 491 | */ |
| 492 | #define v4l2_m2m_for_each_dst_buf(m2m_ctx, b) \ |
| 493 | list_for_each_entry(b, &m2m_ctx->cap_q_ctx.rdy_queue, list) |
| 494 | |
| 495 | /** |
| 496 | * v4l2_m2m_for_each_src_buf() - iterate over a list of source ready buffers |
| 497 | * |
| 498 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 499 | * @b: current buffer of type struct v4l2_m2m_buffer |
| 500 | */ |
| 501 | #define v4l2_m2m_for_each_src_buf(m2m_ctx, b) \ |
| 502 | list_for_each_entry(b, &m2m_ctx->out_q_ctx.rdy_queue, list) |
| 503 | |
| 504 | /** |
| 505 | * v4l2_m2m_for_each_dst_buf_safe() - iterate over a list of destination ready |
| 506 | * buffers safely |
| 507 | * |
| 508 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 509 | * @b: current buffer of type struct v4l2_m2m_buffer |
| 510 | * @n: used as temporary storage |
| 511 | */ |
| 512 | #define v4l2_m2m_for_each_dst_buf_safe(m2m_ctx, b, n) \ |
| 513 | list_for_each_entry_safe(b, n, &m2m_ctx->cap_q_ctx.rdy_queue, list) |
| 514 | |
| 515 | /** |
| 516 | * v4l2_m2m_for_each_src_buf_safe() - iterate over a list of source ready |
| 517 | * buffers safely |
| 518 | * |
| 519 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 520 | * @b: current buffer of type struct v4l2_m2m_buffer |
| 521 | * @n: used as temporary storage |
| 522 | */ |
| 523 | #define v4l2_m2m_for_each_src_buf_safe(m2m_ctx, b, n) \ |
| 524 | list_for_each_entry_safe(b, n, &m2m_ctx->out_q_ctx.rdy_queue, list) |
| 525 | |
| 526 | /** |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 527 | * v4l2_m2m_get_src_vq() - return vb2_queue for source buffers |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 528 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 529 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 530 | */ |
| 531 | static inline |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 532 | struct vb2_queue *v4l2_m2m_get_src_vq(struct v4l2_m2m_ctx *m2m_ctx) |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 533 | { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 534 | return &m2m_ctx->out_q_ctx.q; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | /** |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 538 | * v4l2_m2m_get_dst_vq() - return vb2_queue for destination buffers |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 539 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 540 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 541 | */ |
| 542 | static inline |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 543 | struct vb2_queue *v4l2_m2m_get_dst_vq(struct v4l2_m2m_ctx *m2m_ctx) |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 544 | { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 545 | return &m2m_ctx->cap_q_ctx.q; |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 546 | } |
| 547 | |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 548 | /** |
| 549 | * v4l2_m2m_buf_remove() - take off a buffer from the list of ready buffers and |
| 550 | * return it |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 551 | * |
| 552 | * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx |
Mauro Carvalho Chehab | 4781646 | 2016-09-08 10:16:27 -0300 | [diff] [blame] | 553 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame^] | 554 | struct vb2_v4l2_buffer *v4l2_m2m_buf_remove(struct v4l2_m2m_queue_ctx *q_ctx); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 555 | |
| 556 | /** |
| 557 | * v4l2_m2m_src_buf_remove() - take off a source buffer from the list of ready |
| 558 | * buffers and return it |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 559 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 560 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 561 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame^] | 562 | static inline struct vb2_v4l2_buffer * |
| 563 | v4l2_m2m_src_buf_remove(struct v4l2_m2m_ctx *m2m_ctx) |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 564 | { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 565 | return v4l2_m2m_buf_remove(&m2m_ctx->out_q_ctx); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /** |
| 569 | * v4l2_m2m_dst_buf_remove() - take off a destination buffer from the list of |
| 570 | * ready buffers and return it |
Mauro Carvalho Chehab | 62c0d01 | 2015-08-22 05:34:40 -0300 | [diff] [blame] | 571 | * |
Mauro Carvalho Chehab | dcbd873 | 2016-09-08 10:39:58 -0300 | [diff] [blame] | 572 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 573 | */ |
Ezequiel Garcia | 8dd22b2 | 2019-02-08 11:17:48 -0500 | [diff] [blame^] | 574 | static inline struct vb2_v4l2_buffer * |
| 575 | v4l2_m2m_dst_buf_remove(struct v4l2_m2m_ctx *m2m_ctx) |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 576 | { |
Marek Szyprowski | 908a0d7 | 2011-01-12 06:50:24 -0300 | [diff] [blame] | 577 | return v4l2_m2m_buf_remove(&m2m_ctx->cap_q_ctx); |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 578 | } |
| 579 | |
Stanimir Varbanov | d498756 | 2017-06-15 13:31:42 -0300 | [diff] [blame] | 580 | /** |
| 581 | * v4l2_m2m_buf_remove_by_buf() - take off exact buffer from the list of ready |
| 582 | * buffers |
| 583 | * |
| 584 | * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx |
| 585 | * @vbuf: the buffer to be removed |
| 586 | */ |
| 587 | void v4l2_m2m_buf_remove_by_buf(struct v4l2_m2m_queue_ctx *q_ctx, |
| 588 | struct vb2_v4l2_buffer *vbuf); |
| 589 | |
| 590 | /** |
| 591 | * v4l2_m2m_src_buf_remove_by_buf() - take off exact source buffer from the list |
| 592 | * of ready buffers |
| 593 | * |
| 594 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 595 | * @vbuf: the buffer to be removed |
| 596 | */ |
| 597 | static inline void v4l2_m2m_src_buf_remove_by_buf(struct v4l2_m2m_ctx *m2m_ctx, |
| 598 | struct vb2_v4l2_buffer *vbuf) |
| 599 | { |
| 600 | v4l2_m2m_buf_remove_by_buf(&m2m_ctx->out_q_ctx, vbuf); |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * v4l2_m2m_dst_buf_remove_by_buf() - take off exact destination buffer from the |
| 605 | * list of ready buffers |
| 606 | * |
| 607 | * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx |
| 608 | * @vbuf: the buffer to be removed |
| 609 | */ |
| 610 | static inline void v4l2_m2m_dst_buf_remove_by_buf(struct v4l2_m2m_ctx *m2m_ctx, |
| 611 | struct vb2_v4l2_buffer *vbuf) |
| 612 | { |
| 613 | v4l2_m2m_buf_remove_by_buf(&m2m_ctx->cap_q_ctx, vbuf); |
| 614 | } |
| 615 | |
| 616 | struct vb2_v4l2_buffer * |
| 617 | v4l2_m2m_buf_remove_by_idx(struct v4l2_m2m_queue_ctx *q_ctx, unsigned int idx); |
| 618 | |
| 619 | static inline struct vb2_v4l2_buffer * |
| 620 | v4l2_m2m_src_buf_remove_by_idx(struct v4l2_m2m_ctx *m2m_ctx, unsigned int idx) |
| 621 | { |
| 622 | return v4l2_m2m_buf_remove_by_idx(&m2m_ctx->out_q_ctx, idx); |
| 623 | } |
| 624 | |
| 625 | static inline struct vb2_v4l2_buffer * |
| 626 | v4l2_m2m_dst_buf_remove_by_idx(struct v4l2_m2m_ctx *m2m_ctx, unsigned int idx) |
| 627 | { |
| 628 | return v4l2_m2m_buf_remove_by_idx(&m2m_ctx->cap_q_ctx, idx); |
| 629 | } |
| 630 | |
Hans Verkuil | e2d8ffe2 | 2018-11-13 03:52:18 -0500 | [diff] [blame] | 631 | /** |
Ezequiel Garcia | a4d3d61 | 2019-02-05 16:20:33 -0500 | [diff] [blame] | 632 | * v4l2_m2m_buf_copy_metadata() - copy buffer metadata from |
| 633 | * the output buffer to the capture buffer |
Hans Verkuil | e2d8ffe2 | 2018-11-13 03:52:18 -0500 | [diff] [blame] | 634 | * |
Ezequiel Garcia | a4d3d61 | 2019-02-05 16:20:33 -0500 | [diff] [blame] | 635 | * @out_vb: the output buffer that is the source of the metadata. |
| 636 | * @cap_vb: the capture buffer that will receive the metadata. |
Hans Verkuil | e2d8ffe2 | 2018-11-13 03:52:18 -0500 | [diff] [blame] | 637 | * @copy_frame_flags: copy the KEY/B/PFRAME flags as well. |
| 638 | * |
| 639 | * This helper function copies the timestamp, timecode (if the TIMECODE |
| 640 | * buffer flag was set), field and the TIMECODE, KEYFRAME, BFRAME, PFRAME |
| 641 | * and TSTAMP_SRC_MASK flags from @out_vb to @cap_vb. |
| 642 | * |
| 643 | * If @copy_frame_flags is false, then the KEYFRAME, BFRAME and PFRAME |
| 644 | * flags are not copied. This is typically needed for encoders that |
| 645 | * set this bits explicitly. |
| 646 | */ |
Ezequiel Garcia | a4d3d61 | 2019-02-05 16:20:33 -0500 | [diff] [blame] | 647 | void v4l2_m2m_buf_copy_metadata(const struct vb2_v4l2_buffer *out_vb, |
| 648 | struct vb2_v4l2_buffer *cap_vb, |
| 649 | bool copy_frame_flags); |
Hans Verkuil | e2d8ffe2 | 2018-11-13 03:52:18 -0500 | [diff] [blame] | 650 | |
Hans Verkuil | 803a7ab | 2018-05-21 04:54:53 -0400 | [diff] [blame] | 651 | /* v4l2 request helper */ |
| 652 | |
Ezequiel Garcia | ef86eaf | 2018-10-18 14:54:29 -0400 | [diff] [blame] | 653 | void v4l2_m2m_request_queue(struct media_request *req); |
Hans Verkuil | 803a7ab | 2018-05-21 04:54:53 -0400 | [diff] [blame] | 654 | |
Sylwester Nawrocki | 8e6e8f9 | 2013-09-14 18:39:04 -0300 | [diff] [blame] | 655 | /* v4l2 ioctl helpers */ |
| 656 | |
| 657 | int v4l2_m2m_ioctl_reqbufs(struct file *file, void *priv, |
| 658 | struct v4l2_requestbuffers *rb); |
| 659 | int v4l2_m2m_ioctl_create_bufs(struct file *file, void *fh, |
| 660 | struct v4l2_create_buffers *create); |
| 661 | int v4l2_m2m_ioctl_querybuf(struct file *file, void *fh, |
| 662 | struct v4l2_buffer *buf); |
| 663 | int v4l2_m2m_ioctl_expbuf(struct file *file, void *fh, |
| 664 | struct v4l2_exportbuffer *eb); |
| 665 | int v4l2_m2m_ioctl_qbuf(struct file *file, void *fh, |
| 666 | struct v4l2_buffer *buf); |
| 667 | int v4l2_m2m_ioctl_dqbuf(struct file *file, void *fh, |
| 668 | struct v4l2_buffer *buf); |
Hans Verkuil | e68cf47 | 2015-06-05 11:28:50 -0300 | [diff] [blame] | 669 | int v4l2_m2m_ioctl_prepare_buf(struct file *file, void *fh, |
| 670 | struct v4l2_buffer *buf); |
Sylwester Nawrocki | 8e6e8f9 | 2013-09-14 18:39:04 -0300 | [diff] [blame] | 671 | int v4l2_m2m_ioctl_streamon(struct file *file, void *fh, |
| 672 | enum v4l2_buf_type type); |
| 673 | int v4l2_m2m_ioctl_streamoff(struct file *file, void *fh, |
| 674 | enum v4l2_buf_type type); |
| 675 | int v4l2_m2m_fop_mmap(struct file *file, struct vm_area_struct *vma); |
Al Viro | c23e0cb | 2017-07-03 03:02:56 -0400 | [diff] [blame] | 676 | __poll_t v4l2_m2m_fop_poll(struct file *file, poll_table *wait); |
Sylwester Nawrocki | 8e6e8f9 | 2013-09-14 18:39:04 -0300 | [diff] [blame] | 677 | |
Pawel Osciak | 7f98639 | 2010-04-23 05:38:37 -0300 | [diff] [blame] | 678 | #endif /* _MEDIA_V4L2_MEM2MEM_H */ |
| 679 | |