Skip to content

Commit 4b586a3

Browse files
Jonathan CorbetMauro Carvalho Chehab
authored andcommitted
V4L/DVB: V4L2: Add a document describing the videobuf layer
Videobuf is a moderately complex API which most V4L2 drivers should use, but its documentation is...sparse. This document attempts to improve the situation. Signed-off-by: Jonathan Corbet <corbet@lwn.net> Reviewed-by: Randy Dunlap <rdunlap@xenotime.net> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
1 parent 995f5fe commit 4b586a3

2 files changed

Lines changed: 371 additions & 96 deletions

File tree

‎Documentation/video4linux/v4l2-framework.txt‎

Lines changed: 11 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -599,99 +599,14 @@ video_device::minor fields.
599599
video buffer helper functions
600600
-----------------------------
601601

602-
The v4l2 core API provides a standard method for dealing with video
603-
buffers. Those methods allow a driver to implement read(), mmap() and
604-
overlay() on a consistent way.
605-
606-
There are currently methods for using video buffers on devices that
607-
supports DMA with scatter/gather method (videobuf-dma-sg), DMA with
608-
linear access (videobuf-dma-contig), and vmalloced buffers, mostly
609-
used on USB drivers (videobuf-vmalloc).
610-
611-
Any driver using videobuf should provide operations (callbacks) for
612-
four handlers:
613-
614-
ops->buf_setup - calculates the size of the video buffers and avoid they
615-
to waste more than some maximum limit of RAM;
616-
ops->buf_prepare - fills the video buffer structs and calls
617-
videobuf_iolock() to alloc and prepare mmaped memory;
618-
ops->buf_queue - advices the driver that another buffer were
619-
requested (by read() or by QBUF);
620-
ops->buf_release - frees any buffer that were allocated.
621-
622-
In order to use it, the driver need to have a code (generally called at
623-
interrupt context) that will properly handle the buffer request lists,
624-
announcing that a new buffer were filled.
625-
626-
The irq handling code should handle the videobuf task lists, in order
627-
to advice videobuf that a new frame were filled, in order to honor to a
628-
request. The code is generally like this one:
629-
if (list_empty(&dma_q->active))
630-
return;
631-
632-
buf = list_entry(dma_q->active.next, struct vbuffer, vb.queue);
633-
634-
if (!waitqueue_active(&buf->vb.done))
635-
return;
636-
637-
/* Some logic to handle the buf may be needed here */
638-
639-
list_del(&buf->vb.queue);
640-
do_gettimeofday(&buf->vb.ts);
641-
wake_up(&buf->vb.done);
642-
643-
Those are the videobuffer functions used on drivers, implemented on
644-
videobuf-core:
645-
646-
- Videobuf init functions
647-
videobuf_queue_sg_init()
648-
Initializes the videobuf infrastructure. This function should be
649-
called before any other videobuf function on drivers that uses DMA
650-
Scatter/Gather buffers.
651-
652-
videobuf_queue_dma_contig_init
653-
Initializes the videobuf infrastructure. This function should be
654-
called before any other videobuf function on drivers that need DMA
655-
contiguous buffers.
656-
657-
videobuf_queue_vmalloc_init()
658-
Initializes the videobuf infrastructure. This function should be
659-
called before any other videobuf function on USB (and other drivers)
660-
that need a vmalloced type of videobuf.
661-
662-
- videobuf_iolock()
663-
Prepares the videobuf memory for the proper method (read, mmap, overlay).
664-
665-
- videobuf_queue_is_busy()
666-
Checks if a videobuf is streaming.
667-
668-
- videobuf_queue_cancel()
669-
Stops video handling.
670-
671-
- videobuf_mmap_free()
672-
frees mmap buffers.
673-
674-
- videobuf_stop()
675-
Stops video handling, ends mmap and frees mmap and other buffers.
676-
677-
- V4L2 api functions. Those functions correspond to VIDIOC_foo ioctls:
678-
videobuf_reqbufs(), videobuf_querybuf(), videobuf_qbuf(),
679-
videobuf_dqbuf(), videobuf_streamon(), videobuf_streamoff().
680-
681-
- V4L1 api function (corresponds to VIDIOCMBUF ioctl):
682-
videobuf_cgmbuf()
683-
This function is used to provide backward compatibility with V4L1
684-
API.
685-
686-
- Some help functions for read()/poll() operations:
687-
videobuf_read_stream()
688-
For continuous stream read()
689-
videobuf_read_one()
690-
For snapshot read()
691-
videobuf_poll_stream()
692-
polling help function
693-
694-
The better way to understand it is to take a look at vivi driver. One
695-
of the main reasons for vivi is to be a videobuf usage example. the
696-
vivi_thread_tick() does the task that the IRQ callback would do on PCI
697-
drivers (or the irq callback on USB).
602+
The v4l2 core API provides a set of standard methods (called "videobuf")
603+
for dealing with video buffers. Those methods allow a driver to implement
604+
read(), mmap() and overlay() in a consistent way. There are currently
605+
methods for using video buffers on devices that supports DMA with
606+
scatter/gather method (videobuf-dma-sg), DMA with linear access
607+
(videobuf-dma-contig), and vmalloced buffers, mostly used on USB drivers
608+
(videobuf-vmalloc).
609+
610+
Please see Documentation/video4linux/videobuf for more information on how
611+
to use the videobuf layer.
612+

0 commit comments

Comments
 (0)