1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Memory-to-memory device framework for Video for Linux 2.
5 * Helper functions for devices that use memory buffers for both source
8 * Copyright (c) 2009 Samsung Electronics Co., Ltd.
9 * Pawel Osciak, <pawel@osciak.com>
10 * Marek Szyprowski, <m.szyprowski@samsung.com>
13 #ifndef _MEDIA_V4L2_MEM2MEM_H
14 #define _MEDIA_V4L2_MEM2MEM_H
16 #include <media/videobuf2-v4l2.h>
19 * struct v4l2_m2m_ops - mem-to-mem device driver callbacks
20 * @device_run: required. Begin the actual job (transaction) inside this
22 * The job does NOT have to end before this callback returns
23 * (and it will be the usual case). When the job finishes,
24 * v4l2_m2m_job_finish() or v4l2_m2m_buf_done_and_job_finish()
26 * @job_ready: optional. Should return 0 if the driver does not have a job
27 * fully prepared to run yet (i.e. it will not be able to finish a
28 * transaction without sleeping). If not provided, it will be
29 * assumed that one source and one destination buffer are all
30 * that is required for the driver to perform one full transaction.
31 * This method may not sleep.
32 * @job_abort: optional. Informs the driver that it has to abort the currently
33 * running transaction as soon as possible (i.e. as soon as it can
34 * stop the device safely; e.g. in the next interrupt handler),
35 * even if the transaction would not have been finished by then.
36 * After the driver performs the necessary steps, it has to call
37 * v4l2_m2m_job_finish() or v4l2_m2m_buf_done_and_job_finish() as
38 * if the transaction ended normally.
39 * This function does not have to (and will usually not) wait
40 * until the device enters a state when it can be stopped.
43 void (*device_run
)(void *priv
);
44 int (*job_ready
)(void *priv
);
45 void (*job_abort
)(void *priv
);
52 * struct v4l2_m2m_queue_ctx - represents a queue for buffers ready to be
55 * @q: pointer to struct &vb2_queue
56 * @rdy_queue: List of V4L2 mem-to-mem queues
57 * @rdy_spinlock: spin lock to protect the struct usage
58 * @num_rdy: number of buffers ready to be processed
59 * @buffered: is the queue buffered?
61 * Queue for buffers ready to be processed as soon as this
62 * instance receives access to the device.
65 struct v4l2_m2m_queue_ctx
{
68 struct list_head rdy_queue
;
69 spinlock_t rdy_spinlock
;
75 * struct v4l2_m2m_ctx - Memory to memory context structure
77 * @q_lock: struct &mutex lock
78 * @new_frame: valid in the device_run callback: if true, then this
79 * starts a new frame; if false, then this is a new slice
80 * for an existing frame. This is always true unless
81 * V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF is set, which
82 * indicates slicing support.
83 * @m2m_dev: opaque pointer to the internal data to handle M2M context
84 * @cap_q_ctx: Capture (output to memory) queue context
85 * @out_q_ctx: Output (input from memory) queue context
86 * @queue: List of memory to memory contexts
87 * @job_flags: Job queue flags, used internally by v4l2-mem2mem.c:
88 * %TRANS_QUEUED, %TRANS_RUNNING and %TRANS_ABORT.
89 * @finished: Wait queue used to signalize when a job queue finished.
90 * @priv: Instance private data
92 * The memory to memory context is specific to a file handle, NOT to e.g.
96 /* optional cap/out vb2 queues lock */
101 /* internal use only */
102 struct v4l2_m2m_dev
*m2m_dev
;
104 struct v4l2_m2m_queue_ctx cap_q_ctx
;
106 struct v4l2_m2m_queue_ctx out_q_ctx
;
108 /* For device job queue */
109 struct list_head queue
;
110 unsigned long job_flags
;
111 wait_queue_head_t finished
;
117 * struct v4l2_m2m_buffer - Memory to memory buffer
119 * @vb: pointer to struct &vb2_v4l2_buffer
120 * @list: list of m2m buffers
122 struct v4l2_m2m_buffer
{
123 struct vb2_v4l2_buffer vb
;
124 struct list_head list
;
128 * v4l2_m2m_get_curr_priv() - return driver private data for the currently
129 * running instance or NULL if no instance is running
131 * @m2m_dev: opaque pointer to the internal data to handle M2M context
133 void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev
*m2m_dev
);
136 * v4l2_m2m_get_vq() - return vb2_queue for the given type
138 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
139 * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type
141 struct vb2_queue
*v4l2_m2m_get_vq(struct v4l2_m2m_ctx
*m2m_ctx
,
142 enum v4l2_buf_type type
);
145 * v4l2_m2m_try_schedule() - check whether an instance is ready to be added to
146 * the pending job queue and add it if so.
148 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
150 * There are three basic requirements an instance has to meet to be able to run:
151 * 1) at least one source buffer has to be queued,
152 * 2) at least one destination buffer has to be queued,
153 * 3) streaming has to be on.
155 * If a queue is buffered (for example a decoder hardware ringbuffer that has
156 * to be drained before doing streamoff), allow scheduling without v4l2 buffers
159 * There may also be additional, custom requirements. In such case the driver
160 * should supply a custom callback (job_ready in v4l2_m2m_ops) that should
161 * return 1 if the instance is ready.
162 * An example of the above could be an instance that requires more than one
163 * src/dst buffer per transaction.
165 void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx
*m2m_ctx
);
168 * v4l2_m2m_job_finish() - inform the framework that a job has been finished
169 * and have it clean up
171 * @m2m_dev: opaque pointer to the internal data to handle M2M context
172 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
174 * Called by a driver to yield back the device after it has finished with it.
175 * Should be called as soon as possible after reaching a state which allows
176 * other instances to take control of the device.
178 * This function has to be called only after &v4l2_m2m_ops->device_run
179 * callback has been called on the driver. To prevent recursion, it should
180 * not be called directly from the &v4l2_m2m_ops->device_run callback though.
182 void v4l2_m2m_job_finish(struct v4l2_m2m_dev
*m2m_dev
,
183 struct v4l2_m2m_ctx
*m2m_ctx
);
186 * v4l2_m2m_buf_done_and_job_finish() - return source/destination buffers with
187 * state and inform the framework that a job has been finished and have it
190 * @m2m_dev: opaque pointer to the internal data to handle M2M context
191 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
192 * @state: vb2 buffer state passed to v4l2_m2m_buf_done().
194 * Drivers that set V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF must use this
195 * function instead of job_finish() to take held buffers into account. It is
196 * optional for other drivers.
198 * This function removes the source buffer from the ready list and returns
199 * it with the given state. The same is done for the destination buffer, unless
200 * it is marked 'held'. In that case the buffer is kept on the ready list.
202 * After that the job is finished (see job_finish()).
204 * This allows for multiple output buffers to be used to fill in a single
205 * capture buffer. This is typically used by stateless decoders where
206 * multiple e.g. H.264 slices contribute to a single decoded frame.
208 void v4l2_m2m_buf_done_and_job_finish(struct v4l2_m2m_dev
*m2m_dev
,
209 struct v4l2_m2m_ctx
*m2m_ctx
,
210 enum vb2_buffer_state state
);
213 v4l2_m2m_buf_done(struct vb2_v4l2_buffer
*buf
, enum vb2_buffer_state state
)
215 vb2_buffer_done(&buf
->vb2_buf
, state
);
219 * v4l2_m2m_reqbufs() - multi-queue-aware REQBUFS multiplexer
221 * @file: pointer to struct &file
222 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
223 * @reqbufs: pointer to struct &v4l2_requestbuffers
225 int v4l2_m2m_reqbufs(struct file
*file
, struct v4l2_m2m_ctx
*m2m_ctx
,
226 struct v4l2_requestbuffers
*reqbufs
);
229 * v4l2_m2m_querybuf() - multi-queue-aware QUERYBUF multiplexer
231 * @file: pointer to struct &file
232 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
233 * @buf: pointer to struct &v4l2_buffer
235 * See v4l2_m2m_mmap() documentation for details.
237 int v4l2_m2m_querybuf(struct file
*file
, struct v4l2_m2m_ctx
*m2m_ctx
,
238 struct v4l2_buffer
*buf
);
241 * v4l2_m2m_qbuf() - enqueue a source or destination buffer, depending on
244 * @file: pointer to struct &file
245 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
246 * @buf: pointer to struct &v4l2_buffer
248 int v4l2_m2m_qbuf(struct file
*file
, struct v4l2_m2m_ctx
*m2m_ctx
,
249 struct v4l2_buffer
*buf
);
252 * v4l2_m2m_dqbuf() - dequeue a source or destination buffer, depending on
255 * @file: pointer to struct &file
256 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
257 * @buf: pointer to struct &v4l2_buffer
259 int v4l2_m2m_dqbuf(struct file
*file
, struct v4l2_m2m_ctx
*m2m_ctx
,
260 struct v4l2_buffer
*buf
);
263 * v4l2_m2m_prepare_buf() - prepare a source or destination buffer, depending on
266 * @file: pointer to struct &file
267 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
268 * @buf: pointer to struct &v4l2_buffer
270 int v4l2_m2m_prepare_buf(struct file
*file
, struct v4l2_m2m_ctx
*m2m_ctx
,
271 struct v4l2_buffer
*buf
);
274 * v4l2_m2m_create_bufs() - create a source or destination buffer, depending
277 * @file: pointer to struct &file
278 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
279 * @create: pointer to struct &v4l2_create_buffers
281 int v4l2_m2m_create_bufs(struct file
*file
, struct v4l2_m2m_ctx
*m2m_ctx
,
282 struct v4l2_create_buffers
*create
);
285 * v4l2_m2m_expbuf() - export a source or destination buffer, depending on
288 * @file: pointer to struct &file
289 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
290 * @eb: pointer to struct &v4l2_exportbuffer
292 int v4l2_m2m_expbuf(struct file
*file
, struct v4l2_m2m_ctx
*m2m_ctx
,
293 struct v4l2_exportbuffer
*eb
);
296 * v4l2_m2m_streamon() - turn on streaming for a video queue
298 * @file: pointer to struct &file
299 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
300 * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type
302 int v4l2_m2m_streamon(struct file
*file
, struct v4l2_m2m_ctx
*m2m_ctx
,
303 enum v4l2_buf_type type
);
306 * v4l2_m2m_streamoff() - turn off streaming for a video queue
308 * @file: pointer to struct &file
309 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
310 * @type: type of the V4L2 buffer, as defined by enum &v4l2_buf_type
312 int v4l2_m2m_streamoff(struct file
*file
, struct v4l2_m2m_ctx
*m2m_ctx
,
313 enum v4l2_buf_type type
);
316 * v4l2_m2m_poll() - poll replacement, for destination buffers only
318 * @file: pointer to struct &file
319 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
320 * @wait: pointer to struct &poll_table_struct
322 * Call from the driver's poll() function. Will poll both queues. If a buffer
323 * is available to dequeue (with dqbuf) from the source queue, this will
324 * indicate that a non-blocking write can be performed, while read will be
325 * returned in case of the destination queue.
327 __poll_t
v4l2_m2m_poll(struct file
*file
, struct v4l2_m2m_ctx
*m2m_ctx
,
328 struct poll_table_struct
*wait
);
331 * v4l2_m2m_mmap() - source and destination queues-aware mmap multiplexer
333 * @file: pointer to struct &file
334 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
335 * @vma: pointer to struct &vm_area_struct
337 * Call from driver's mmap() function. Will handle mmap() for both queues
338 * seamlessly for videobuffer, which will receive normal per-queue offsets and
339 * proper videobuf queue pointers. The differentiation is made outside videobuf
340 * by adding a predefined offset to buffers from one of the queues and
341 * subtracting it before passing it back to videobuf. Only drivers (and
342 * thus applications) receive modified offsets.
344 int v4l2_m2m_mmap(struct file
*file
, struct v4l2_m2m_ctx
*m2m_ctx
,
345 struct vm_area_struct
*vma
);
348 * v4l2_m2m_init() - initialize per-driver m2m data
350 * @m2m_ops: pointer to struct v4l2_m2m_ops
352 * Usually called from driver's ``probe()`` function.
354 * Return: returns an opaque pointer to the internal data to handle M2M context
356 struct v4l2_m2m_dev
*v4l2_m2m_init(const struct v4l2_m2m_ops
*m2m_ops
);
358 #if defined(CONFIG_MEDIA_CONTROLLER)
359 void v4l2_m2m_unregister_media_controller(struct v4l2_m2m_dev
*m2m_dev
);
360 int v4l2_m2m_register_media_controller(struct v4l2_m2m_dev
*m2m_dev
,
361 struct video_device
*vdev
, int function
);
364 v4l2_m2m_unregister_media_controller(struct v4l2_m2m_dev
*m2m_dev
)
369 v4l2_m2m_register_media_controller(struct v4l2_m2m_dev
*m2m_dev
,
370 struct video_device
*vdev
, int function
)
377 * v4l2_m2m_release() - cleans up and frees a m2m_dev structure
379 * @m2m_dev: opaque pointer to the internal data to handle M2M context
381 * Usually called from driver's ``remove()`` function.
383 void v4l2_m2m_release(struct v4l2_m2m_dev
*m2m_dev
);
386 * v4l2_m2m_ctx_init() - allocate and initialize a m2m context
388 * @m2m_dev: opaque pointer to the internal data to handle M2M context
389 * @drv_priv: driver's instance private data
390 * @queue_init: a callback for queue type-specific initialization function
391 * to be used for initializing videobuf_queues
393 * Usually called from driver's ``open()`` function.
395 struct v4l2_m2m_ctx
*v4l2_m2m_ctx_init(struct v4l2_m2m_dev
*m2m_dev
,
397 int (*queue_init
)(void *priv
, struct vb2_queue
*src_vq
, struct vb2_queue
*dst_vq
));
399 static inline void v4l2_m2m_set_src_buffered(struct v4l2_m2m_ctx
*m2m_ctx
,
402 m2m_ctx
->out_q_ctx
.buffered
= buffered
;
405 static inline void v4l2_m2m_set_dst_buffered(struct v4l2_m2m_ctx
*m2m_ctx
,
408 m2m_ctx
->cap_q_ctx
.buffered
= buffered
;
412 * v4l2_m2m_ctx_release() - release m2m context
414 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
416 * Usually called from driver's release() function.
418 void v4l2_m2m_ctx_release(struct v4l2_m2m_ctx
*m2m_ctx
);
421 * v4l2_m2m_buf_queue() - add a buffer to the proper ready buffers list.
423 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
424 * @vbuf: pointer to struct &vb2_v4l2_buffer
426 * Call from videobuf_queue_ops->ops->buf_queue, videobuf_queue_ops callback.
428 void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx
*m2m_ctx
,
429 struct vb2_v4l2_buffer
*vbuf
);
432 * v4l2_m2m_num_src_bufs_ready() - return the number of source buffers ready for
435 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
438 unsigned int v4l2_m2m_num_src_bufs_ready(struct v4l2_m2m_ctx
*m2m_ctx
)
440 return m2m_ctx
->out_q_ctx
.num_rdy
;
444 * v4l2_m2m_num_dst_bufs_ready() - return the number of destination buffers
447 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
450 unsigned int v4l2_m2m_num_dst_bufs_ready(struct v4l2_m2m_ctx
*m2m_ctx
)
452 return m2m_ctx
->cap_q_ctx
.num_rdy
;
456 * v4l2_m2m_next_buf() - return next buffer from the list of ready buffers
458 * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx
460 struct vb2_v4l2_buffer
*v4l2_m2m_next_buf(struct v4l2_m2m_queue_ctx
*q_ctx
);
463 * v4l2_m2m_next_src_buf() - return next source buffer from the list of ready
466 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
468 static inline struct vb2_v4l2_buffer
*
469 v4l2_m2m_next_src_buf(struct v4l2_m2m_ctx
*m2m_ctx
)
471 return v4l2_m2m_next_buf(&m2m_ctx
->out_q_ctx
);
475 * v4l2_m2m_next_dst_buf() - return next destination buffer from the list of
478 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
480 static inline struct vb2_v4l2_buffer
*
481 v4l2_m2m_next_dst_buf(struct v4l2_m2m_ctx
*m2m_ctx
)
483 return v4l2_m2m_next_buf(&m2m_ctx
->cap_q_ctx
);
487 * v4l2_m2m_last_buf() - return last buffer from the list of ready buffers
489 * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx
491 struct vb2_v4l2_buffer
*v4l2_m2m_last_buf(struct v4l2_m2m_queue_ctx
*q_ctx
);
494 * v4l2_m2m_last_src_buf() - return last destination buffer from the list of
497 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
499 static inline struct vb2_v4l2_buffer
*
500 v4l2_m2m_last_src_buf(struct v4l2_m2m_ctx
*m2m_ctx
)
502 return v4l2_m2m_last_buf(&m2m_ctx
->out_q_ctx
);
506 * v4l2_m2m_last_dst_buf() - return last destination buffer from the list of
509 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
511 static inline struct vb2_v4l2_buffer
*
512 v4l2_m2m_last_dst_buf(struct v4l2_m2m_ctx
*m2m_ctx
)
514 return v4l2_m2m_last_buf(&m2m_ctx
->cap_q_ctx
);
518 * v4l2_m2m_for_each_dst_buf() - iterate over a list of destination ready
521 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
522 * @b: current buffer of type struct v4l2_m2m_buffer
524 #define v4l2_m2m_for_each_dst_buf(m2m_ctx, b) \
525 list_for_each_entry(b, &m2m_ctx->cap_q_ctx.rdy_queue, list)
528 * v4l2_m2m_for_each_src_buf() - iterate over a list of source ready buffers
530 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
531 * @b: current buffer of type struct v4l2_m2m_buffer
533 #define v4l2_m2m_for_each_src_buf(m2m_ctx, b) \
534 list_for_each_entry(b, &m2m_ctx->out_q_ctx.rdy_queue, list)
537 * v4l2_m2m_for_each_dst_buf_safe() - iterate over a list of destination ready
540 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
541 * @b: current buffer of type struct v4l2_m2m_buffer
542 * @n: used as temporary storage
544 #define v4l2_m2m_for_each_dst_buf_safe(m2m_ctx, b, n) \
545 list_for_each_entry_safe(b, n, &m2m_ctx->cap_q_ctx.rdy_queue, list)
548 * v4l2_m2m_for_each_src_buf_safe() - iterate over a list of source ready
551 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
552 * @b: current buffer of type struct v4l2_m2m_buffer
553 * @n: used as temporary storage
555 #define v4l2_m2m_for_each_src_buf_safe(m2m_ctx, b, n) \
556 list_for_each_entry_safe(b, n, &m2m_ctx->out_q_ctx.rdy_queue, list)
559 * v4l2_m2m_get_src_vq() - return vb2_queue for source buffers
561 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
564 struct vb2_queue
*v4l2_m2m_get_src_vq(struct v4l2_m2m_ctx
*m2m_ctx
)
566 return &m2m_ctx
->out_q_ctx
.q
;
570 * v4l2_m2m_get_dst_vq() - return vb2_queue for destination buffers
572 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
575 struct vb2_queue
*v4l2_m2m_get_dst_vq(struct v4l2_m2m_ctx
*m2m_ctx
)
577 return &m2m_ctx
->cap_q_ctx
.q
;
581 * v4l2_m2m_buf_remove() - take off a buffer from the list of ready buffers and
584 * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx
586 struct vb2_v4l2_buffer
*v4l2_m2m_buf_remove(struct v4l2_m2m_queue_ctx
*q_ctx
);
589 * v4l2_m2m_src_buf_remove() - take off a source buffer from the list of ready
590 * buffers and return it
592 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
594 static inline struct vb2_v4l2_buffer
*
595 v4l2_m2m_src_buf_remove(struct v4l2_m2m_ctx
*m2m_ctx
)
597 return v4l2_m2m_buf_remove(&m2m_ctx
->out_q_ctx
);
601 * v4l2_m2m_dst_buf_remove() - take off a destination buffer from the list of
602 * ready buffers and return it
604 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
606 static inline struct vb2_v4l2_buffer
*
607 v4l2_m2m_dst_buf_remove(struct v4l2_m2m_ctx
*m2m_ctx
)
609 return v4l2_m2m_buf_remove(&m2m_ctx
->cap_q_ctx
);
613 * v4l2_m2m_buf_remove_by_buf() - take off exact buffer from the list of ready
616 * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx
617 * @vbuf: the buffer to be removed
619 void v4l2_m2m_buf_remove_by_buf(struct v4l2_m2m_queue_ctx
*q_ctx
,
620 struct vb2_v4l2_buffer
*vbuf
);
623 * v4l2_m2m_src_buf_remove_by_buf() - take off exact source buffer from the list
626 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
627 * @vbuf: the buffer to be removed
629 static inline void v4l2_m2m_src_buf_remove_by_buf(struct v4l2_m2m_ctx
*m2m_ctx
,
630 struct vb2_v4l2_buffer
*vbuf
)
632 v4l2_m2m_buf_remove_by_buf(&m2m_ctx
->out_q_ctx
, vbuf
);
636 * v4l2_m2m_dst_buf_remove_by_buf() - take off exact destination buffer from the
637 * list of ready buffers
639 * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx
640 * @vbuf: the buffer to be removed
642 static inline void v4l2_m2m_dst_buf_remove_by_buf(struct v4l2_m2m_ctx
*m2m_ctx
,
643 struct vb2_v4l2_buffer
*vbuf
)
645 v4l2_m2m_buf_remove_by_buf(&m2m_ctx
->cap_q_ctx
, vbuf
);
648 struct vb2_v4l2_buffer
*
649 v4l2_m2m_buf_remove_by_idx(struct v4l2_m2m_queue_ctx
*q_ctx
, unsigned int idx
);
651 static inline struct vb2_v4l2_buffer
*
652 v4l2_m2m_src_buf_remove_by_idx(struct v4l2_m2m_ctx
*m2m_ctx
, unsigned int idx
)
654 return v4l2_m2m_buf_remove_by_idx(&m2m_ctx
->out_q_ctx
, idx
);
657 static inline struct vb2_v4l2_buffer
*
658 v4l2_m2m_dst_buf_remove_by_idx(struct v4l2_m2m_ctx
*m2m_ctx
, unsigned int idx
)
660 return v4l2_m2m_buf_remove_by_idx(&m2m_ctx
->cap_q_ctx
, idx
);
664 * v4l2_m2m_buf_copy_metadata() - copy buffer metadata from
665 * the output buffer to the capture buffer
667 * @out_vb: the output buffer that is the source of the metadata.
668 * @cap_vb: the capture buffer that will receive the metadata.
669 * @copy_frame_flags: copy the KEY/B/PFRAME flags as well.
671 * This helper function copies the timestamp, timecode (if the TIMECODE
672 * buffer flag was set), field and the TIMECODE, KEYFRAME, BFRAME, PFRAME
673 * and TSTAMP_SRC_MASK flags from @out_vb to @cap_vb.
675 * If @copy_frame_flags is false, then the KEYFRAME, BFRAME and PFRAME
676 * flags are not copied. This is typically needed for encoders that
677 * set this bits explicitly.
679 void v4l2_m2m_buf_copy_metadata(const struct vb2_v4l2_buffer
*out_vb
,
680 struct vb2_v4l2_buffer
*cap_vb
,
681 bool copy_frame_flags
);
683 /* v4l2 request helper */
685 void v4l2_m2m_request_queue(struct media_request
*req
);
687 /* v4l2 ioctl helpers */
689 int v4l2_m2m_ioctl_reqbufs(struct file
*file
, void *priv
,
690 struct v4l2_requestbuffers
*rb
);
691 int v4l2_m2m_ioctl_create_bufs(struct file
*file
, void *fh
,
692 struct v4l2_create_buffers
*create
);
693 int v4l2_m2m_ioctl_querybuf(struct file
*file
, void *fh
,
694 struct v4l2_buffer
*buf
);
695 int v4l2_m2m_ioctl_expbuf(struct file
*file
, void *fh
,
696 struct v4l2_exportbuffer
*eb
);
697 int v4l2_m2m_ioctl_qbuf(struct file
*file
, void *fh
,
698 struct v4l2_buffer
*buf
);
699 int v4l2_m2m_ioctl_dqbuf(struct file
*file
, void *fh
,
700 struct v4l2_buffer
*buf
);
701 int v4l2_m2m_ioctl_prepare_buf(struct file
*file
, void *fh
,
702 struct v4l2_buffer
*buf
);
703 int v4l2_m2m_ioctl_streamon(struct file
*file
, void *fh
,
704 enum v4l2_buf_type type
);
705 int v4l2_m2m_ioctl_streamoff(struct file
*file
, void *fh
,
706 enum v4l2_buf_type type
);
707 int v4l2_m2m_ioctl_try_encoder_cmd(struct file
*file
, void *fh
,
708 struct v4l2_encoder_cmd
*ec
);
709 int v4l2_m2m_ioctl_try_decoder_cmd(struct file
*file
, void *fh
,
710 struct v4l2_decoder_cmd
*dc
);
711 int v4l2_m2m_ioctl_stateless_try_decoder_cmd(struct file
*file
, void *fh
,
712 struct v4l2_decoder_cmd
*dc
);
713 int v4l2_m2m_ioctl_stateless_decoder_cmd(struct file
*file
, void *priv
,
714 struct v4l2_decoder_cmd
*dc
);
715 int v4l2_m2m_fop_mmap(struct file
*file
, struct vm_area_struct
*vma
);
716 __poll_t
v4l2_m2m_fop_poll(struct file
*file
, poll_table
*wait
);
718 #endif /* _MEDIA_V4L2_MEM2MEM_H */