Skip to content

Commit 9f577d6

Browse files
committed
media: dvb kAPI docs: document dvb_vb2.h
Document the data structures and functions inside this kAPI header. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
1 parent 15128be commit 9f577d6

3 files changed

Lines changed: 184 additions & 6 deletions

File tree

‎Documentation/media/kapi/dtv-common.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,8 @@ copy it from/to userspace.
5353
Two or more writers must be locked against each other.
5454

5555
.. kernel-doc:: include/media/dvb_ringbuffer.h
56+
57+
Digital TV VB2 handler
58+
~~~~~~~~~~~~~~~~~~~~~~
59+
60+
.. kernel-doc:: include/media/dvb_vb2.h

‎include/media/dmxdev.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct dmxdev_feed {
112112
* @state: state of the dmxdev filter, as defined by &enum dmxdev_state.
113113
* @dev: pointer to &struct dmxdev.
114114
* @buffer: an embedded &struct dvb_ringbuffer buffer.
115+
* @vb2_ctx: control struct for VB2 handler
115116
* @mutex: protects the access to &struct dmxdev_filter.
116117
* @timer: &struct timer_list embedded timer, used to check for
117118
* feed timeouts.
@@ -165,6 +166,7 @@ struct dmxdev_filter {
165166
* @exit: flag to indicate that the demux is being released.
166167
* @dvr_orig_fe: pointer to &struct dmx_frontend.
167168
* @dvr_buffer: embedded &struct dvb_ringbuffer for DVB output.
169+
* @dvr_vb2_ctx: control struct for VB2 handler
168170
* @mutex: protects the usage of this structure.
169171
* @lock: protects access to &dmxdev->filter->data.
170172
*/

‎include/media/dvb_vb2.h‎

Lines changed: 177 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,72 @@
2222
#include <media/videobuf2-dma-contig.h>
2323
#include <media/videobuf2-vmalloc.h>
2424

25+
/**
26+
* enum dvb_buf_type - types of Digital TV memory-mapped buffers
27+
*
28+
* @DVB_BUF_TYPE_CAPTURE: buffer is filled by the Kernel,
29+
* with a received Digital TV stream
30+
*/
2531
enum dvb_buf_type {
2632
DVB_BUF_TYPE_CAPTURE = 1,
2733
};
2834

29-
#define DVB_VB2_STATE_NONE (0x0)
30-
#define DVB_VB2_STATE_INIT (0x1)
31-
#define DVB_VB2_STATE_REQBUFS (0x2)
32-
#define DVB_VB2_STATE_STREAMON (0x4)
35+
/**
36+
* enum dvb_vb2_states - states to control VB2 state machine
37+
* @DVB_VB2_STATE_NONE:
38+
* VB2 engine not initialized yet, init failed or VB2 was released.
39+
* @DVB_VB2_STATE_INIT:
40+
* VB2 engine initialized.
41+
* @DVB_VB2_STATE_REQBUFS:
42+
* Buffers were requested
43+
* @DVB_VB2_STATE_STREAMON:
44+
* VB2 is streaming. Callers should not check it directly. Instead,
45+
* they should use dvb_vb2_is_streaming().
46+
*
47+
* Note:
48+
*
49+
* Callers should not touch at the state machine directly. This
50+
* is handled inside dvb_vb2.c.
51+
*/
52+
enum dvb_vb2_states {
53+
DVB_VB2_STATE_NONE = 0x0,
54+
DVB_VB2_STATE_INIT = 0x1,
55+
DVB_VB2_STATE_REQBUFS = 0x2,
56+
DVB_VB2_STATE_STREAMON = 0x4,
57+
};
3358

3459
#define DVB_VB2_NAME_MAX (20)
3560

61+
/**
62+
* struct dvb_buffer - video buffer information for v4l2.
63+
*
64+
* @vb: embedded struct &vb2_buffer.
65+
* @list: list of &struct dvb_buffer.
66+
*/
3667
struct dvb_buffer {
3768
struct vb2_buffer vb;
3869
struct list_head list;
3970
};
4071

72+
/**
73+
* struct dvb_vb2_ctx - control struct for VB2 handler
74+
* @vb_q: pointer to &struct vb2_queue with videobuf2 queue.
75+
* @mutex: mutex to serialize vb2 operations. Used by
76+
* vb2 core %wait_prepare and %wait_finish operations.
77+
* @slock: spin lock used to protect buffer filling at dvb_vb2.c.
78+
* @dvb_q: List of buffers that are not filled yet.
79+
* @buf: Pointer to the buffer that are currently being filled.
80+
* @offset: index to the next position at the @buf to be filled.
81+
* @remain: How many bytes are left to be filled at @buf.
82+
* @state: bitmask of buffer states as defined by &enum dvb_vb2_states.
83+
* @buf_siz: size of each VB2 buffer.
84+
* @buf_cnt: number of VB2 buffers.
85+
* @nonblocking:
86+
* If different than zero, device is operating on non-blocking
87+
* mode.
88+
* @name: name of the device type. Currently, it can either be
89+
* "dvr" or "demux_filter".
90+
*/
4191
struct dvb_vb2_ctx {
4292
struct vb2_queue vb_q;
4393
struct mutex mutex;
@@ -53,8 +103,6 @@ struct dvb_vb2_ctx {
53103
char name[DVB_VB2_NAME_MAX + 1];
54104
};
55105

56-
int dvb_vb2_stream_on(struct dvb_vb2_ctx *ctx);
57-
int dvb_vb2_stream_off(struct dvb_vb2_ctx *ctx);
58106
#ifndef DVB_MMAP
59107
static inline int dvb_vb2_init(struct dvb_vb2_ctx *ctx,
60108
const char *name, int non_blocking)
@@ -75,21 +123,144 @@ static inline unsigned int dvb_vb2_poll(struct dvb_vb2_ctx *ctx,
75123
return 0;
76124
}
77125
#else
126+
/**
127+
* dvb_vb2_init - initializes VB2 handler
128+
*
129+
* @ctx: control struct for VB2 handler
130+
* @name: name for the VB2 handler
131+
* @non_blocking:
132+
* if not zero, it means that the device is at non-blocking mode
133+
*/
78134
int dvb_vb2_init(struct dvb_vb2_ctx *ctx, const char *name, int non_blocking);
135+
136+
/**
137+
* dvb_vb2_release - Releases the VB2 handler allocated resources and
138+
* put @ctx at DVB_VB2_STATE_NONE state.
139+
* @ctx: control struct for VB2 handler
140+
*/
79141
int dvb_vb2_release(struct dvb_vb2_ctx *ctx);
142+
143+
/**
144+
* dvb_vb2_is_streaming - checks if the VB2 handler is streaming
145+
* @ctx: control struct for VB2 handler
146+
*
147+
* Return: 0 if not streaming, 1 otherwise.
148+
*/
80149
int dvb_vb2_is_streaming(struct dvb_vb2_ctx *ctx);
150+
151+
/**
152+
* dvb_vb2_fill_buffer - fills a VB2 buffer
153+
* @ctx: control struct for VB2 handler
154+
* @src: place where the data is stored
155+
* @len: number of bytes to be copied from @src
156+
*/
81157
int dvb_vb2_fill_buffer(struct dvb_vb2_ctx *ctx,
82158
const unsigned char *src, int len);
159+
160+
/**
161+
* dvb_vb2_poll - Wrapper to vb2_core_streamon() for Digital TV
162+
* buffer handling.
163+
*
164+
* @ctx: control struct for VB2 handler
165+
* @file: &struct file argument passed to the poll
166+
* file operation handler.
167+
* @wait: &poll_table wait argument passed to the poll
168+
* file operation handler.
169+
*
170+
* Implements poll syscall() logic.
171+
*/
83172
unsigned int dvb_vb2_poll(struct dvb_vb2_ctx *ctx, struct file *file,
84173
poll_table *wait);
85174
#endif
86175

176+
/**
177+
* dvb_vb2_stream_on() - Wrapper to vb2_core_streamon() for Digital TV
178+
* buffer handling.
179+
*
180+
* @ctx: control struct for VB2 handler
181+
*
182+
* Starts dvb streaming
183+
*/
184+
int dvb_vb2_stream_on(struct dvb_vb2_ctx *ctx);
185+
/**
186+
* dvb_vb2_stream_off() - Wrapper to vb2_core_streamoff() for Digital TV
187+
* buffer handling.
188+
*
189+
* @ctx: control struct for VB2 handler
190+
*
191+
* Stops dvb streaming
192+
*/
193+
int dvb_vb2_stream_off(struct dvb_vb2_ctx *ctx);
87194

195+
/**
196+
* dvb_vb2_reqbufs() - Wrapper to vb2_core_reqbufs() for Digital TV
197+
* buffer handling.
198+
*
199+
* @ctx: control struct for VB2 handler
200+
* @req: &struct dmx_requestbuffers passed from userspace in
201+
* order to handle &DMX_REQBUFS.
202+
*
203+
* Initiate streaming by requesting a number of buffers. Also used to
204+
* free previously requested buffers, is ``req->count`` is zero.
205+
*/
88206
int dvb_vb2_reqbufs(struct dvb_vb2_ctx *ctx, struct dmx_requestbuffers *req);
207+
208+
/**
209+
* dvb_vb2_querybuf() - Wrapper to vb2_core_querybuf() for Digital TV
210+
* buffer handling.
211+
*
212+
* @ctx: control struct for VB2 handler
213+
* @b: &struct dmx_buffer passed from userspace in
214+
* order to handle &DMX_QUERYBUF.
215+
*
216+
*
217+
*/
89218
int dvb_vb2_querybuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b);
219+
220+
/**
221+
* dvb_vb2_expbuf() - Wrapper to vb2_core_expbuf() for Digital TV
222+
* buffer handling.
223+
*
224+
* @ctx: control struct for VB2 handler
225+
* @exp: &struct dmx_exportbuffer passed from userspace in
226+
* order to handle &DMX_EXPBUF.
227+
*
228+
* Export a buffer as a file descriptor.
229+
*/
90230
int dvb_vb2_expbuf(struct dvb_vb2_ctx *ctx, struct dmx_exportbuffer *exp);
231+
232+
/**
233+
* dvb_vb2_qbuf() - Wrapper to vb2_core_qbuf() for Digital TV buffer handling.
234+
*
235+
* @ctx: control struct for VB2 handler
236+
* @b: &struct dmx_buffer passed from userspace in
237+
* order to handle &DMX_QBUF.
238+
*
239+
* Queue a Digital TV buffer as requested by userspace
240+
*/
91241
int dvb_vb2_qbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b);
242+
243+
/**
244+
* dvb_vb2_dqbuf() - Wrapper to vb2_core_dqbuf() for Digital TV
245+
* buffer handling.
246+
*
247+
* @ctx: control struct for VB2 handler
248+
* @b: &struct dmx_buffer passed from userspace in
249+
* order to handle &DMX_DQBUF.
250+
*
251+
* Dequeue a Digital TV buffer to the userspace
252+
*/
92253
int dvb_vb2_dqbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b);
254+
255+
/**
256+
* dvb_vb2_mmap() - Wrapper to vb2_mmap() for Digital TV buffer handling.
257+
*
258+
* @ctx: control struct for VB2 handler
259+
* @vma: pointer to &struct vm_area_struct with the vma passed
260+
* to the mmap file operation handler in the driver.
261+
*
262+
* map Digital TV video buffers into application address space.
263+
*/
93264
int dvb_vb2_mmap(struct dvb_vb2_ctx *ctx, struct vm_area_struct *vma);
94265

95266
#endif /* _DVB_VB2_H */

0 commit comments

Comments
 (0)