1<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>struct vb2_ops</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Linux Device Drivers"><link rel="up" href="mediadev.html#id-1.8.2" title="Video2Linux devices"><link rel="prev" href="API-struct-vb2-buffer.html" title="struct vb2_buffer"><link rel="next" href="API-struct-vb2-queue.html" title="struct vb2_queue"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">struct vb2_ops</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-struct-vb2-buffer.html">Prev</a> </td><th width="60%" align="center">Video2Linux devices</th><td width="20%" align="right"> <a accesskey="n" href="API-struct-vb2-queue.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-struct-vb2-ops"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>struct vb2_ops — 
2     driver-specific callbacks
3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="programlisting">
4struct vb2_ops {
5  int (* queue_setup) (struct vb2_queue *q, const void *parg,unsigned int *num_buffers, unsigned int *num_planes,unsigned int sizes[], void *alloc_ctxs[]);
6  void (* wait_prepare) (struct vb2_queue *q);
7  void (* wait_finish) (struct vb2_queue *q);
8  int (* buf_init) (struct vb2_buffer *vb);
9  int (* buf_prepare) (struct vb2_buffer *vb);
10  void (* buf_finish) (struct vb2_buffer *vb);
11  void (* buf_cleanup) (struct vb2_buffer *vb);
12  int (* start_streaming) (struct vb2_queue *q, unsigned int count);
13  void (* stop_streaming) (struct vb2_queue *q);
14  void (* buf_queue) (struct vb2_buffer *vb);
15};  </pre></div><div class="refsect1"><a name="id-1.8.2.93.5"></a><h2>Members</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term">queue_setup</span></dt><dd><p>
16   called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
17   handlers before memory allocation, or, if
18   *num_planes != 0, after the allocation to verify a
19   smaller number of buffers. Driver should return
20   the required number of buffers in *num_buffers, the
21   required number of planes per buffer in *num_planes; the
22   size of each plane should be set in the sizes[] array
23   and optional per-plane allocator specific context in the
24   alloc_ctxs[] array. When called from VIDIOC_REQBUFS,
25   fmt == NULL, the driver has to use the currently
26   configured format and *num_buffers is the total number
27   of buffers, that are being allocated. When called from
28   VIDIOC_CREATE_BUFS, fmt != NULL and it describes the
29   target frame format (if the format isn't valid the
30   callback must return -EINVAL). In this case *num_buffers
31   are being allocated additionally to q-&gt;num_buffers.
32      </p></dd><dt><span class="term">wait_prepare</span></dt><dd><p>
33   release any locks taken while calling vb2 functions;
34   it is called before an ioctl needs to wait for a new
35   buffer to arrive; required to avoid a deadlock in
36   blocking access type.
37      </p></dd><dt><span class="term">wait_finish</span></dt><dd><p>
38   reacquire all locks released in the previous callback;
39   required to continue operation after sleeping while
40   waiting for a new buffer to arrive.
41      </p></dd><dt><span class="term">buf_init</span></dt><dd><p>
42   called once after allocating a buffer (in MMAP case)
43   or after acquiring a new USERPTR buffer; drivers may
44   perform additional buffer-related initialization;
45   initialization failure (return != 0) will prevent
46   queue setup from completing successfully; optional.
47      </p></dd><dt><span class="term">buf_prepare</span></dt><dd><p>
48   called every time the buffer is queued from userspace
49   and from the VIDIOC_PREPARE_BUF ioctl; drivers may
50   perform any initialization required before each
51   hardware operation in this callback; drivers can
52   access/modify the buffer here as it is still synced for
53   the CPU; drivers that support VIDIOC_CREATE_BUFS must
54   also validate the buffer size; if an error is returned,
55   the buffer will not be queued in driver; optional.
56      </p></dd><dt><span class="term">buf_finish</span></dt><dd><p>
57   called before every dequeue of the buffer back to
58   userspace; the buffer is synced for the CPU, so drivers
59   can access/modify the buffer contents; drivers may
60   perform any operations required before userspace
61   accesses the buffer; optional. The buffer state can be
62      </p></dd><dt><span class="term">buf_cleanup</span></dt><dd><p>
63   called once before the buffer is freed; drivers may
64   perform any additional cleanup; optional.
65      </p></dd><dt><span class="term">start_streaming</span></dt><dd><p>
66   called once to enter 'streaming' state; the driver may
67   receive buffers with <em class="parameter"><code>buf_queue</code></em> callback before
68   <em class="parameter"><code>start_streaming</code></em> is called; the driver gets the number
69   of already queued buffers in count parameter; driver
70   can return an error if hardware fails, in that case all
71   buffers that have been already given by the <em class="parameter"><code>buf_queue</code></em>
72   callback are to be returned by the driver by calling
73   <em class="parameter"><code>vb2_buffer_done</code></em>(VB2_BUF_STATE_QUEUED).
74   If you need a minimum number of buffers before you can
75   start streaming, then set <em class="parameter"><code>min_buffers_needed</code></em> in the
76   vb2_queue structure. If that is non-zero then
77   start_streaming won't be called until at least that
78   many buffers have been queued up by userspace.
79      </p></dd><dt><span class="term">stop_streaming</span></dt><dd><p>
80   called when 'streaming' state must be disabled; driver
81   should stop any DMA transactions or wait until they
82   finish and give back all buffers it got from <code class="function">buf_queue</code>
83   callback by calling <em class="parameter"><code>vb2_buffer_done</code></em>() with either
84   VB2_BUF_STATE_DONE or VB2_BUF_STATE_ERROR; may use
85   <code class="function">vb2_wait_for_all_buffers</code> function
86      </p></dd><dt><span class="term">buf_queue</span></dt><dd><p>
87   passes buffer vb to the driver; driver may start
88   hardware operation on this buffer; driver should give
89   the buffer back by calling <code class="function">vb2_buffer_done</code> function;
90   it is allways called after calling STREAMON ioctl;
91   might be called before start_streaming callback if user
92   pre-queued buffers before calling STREAMON.
93      </p></dd></dl></div></div><div class="refsect1"><a name="id-1.8.2.93.6"></a><h2>one of the following</h2><p>
94   DONE and ERROR occur while
95   streaming is in progress, and the PREPARED state occurs
96   when the queue has been canceled and all pending
97   buffers are being returned to their default DEQUEUED
98   state. Typically you only have to do something if the
99   state is VB2_BUF_STATE_DONE, since in all other cases
100   the buffer contents will be ignored anyway.
101</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-struct-vb2-buffer.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="mediadev.html#id-1.8.2">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="API-struct-vb2-queue.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">struct vb2_buffer</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="phrase">struct vb2_queue</span></td></tr></table></div></body></html>
102