JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
jevois::VideoBuffers Class Reference

#include <jevois/Core/VideoBuffers.H>

Collection of buffers for V4L2 video frames (Camera or Gadget) with hooks to the MMAP'd areas.

Both the Camera and the Gadget use a VideoBuffers object to manage their video buffers. VideoBuffer is just a vector of VideoBuf objects, with added functions to queue a buffer (send it to the kernel driver, either so that it will be filed with a new camera frame, or so that its contents will be streamed out over the USB link), and to dequeue a buffer (get the next grabbed camera frame, or the next empty USB buffer to be filled by user code).

Note that this class provides no threading safety and must be protected externally in case of multithreaded access.

VideoBuffers is mainly for internal use by Camera and Gadget. Machine vision programmers should just use Module and the InputFrame and OutputFrame wrappers instead.

Definition at line 42 of file VideoBuffers.H.

Public Member Functions

 VideoBuffers (char const *name, int const fd, v4l2_buf_type type, size_t const num=4)
 Construct and allocate MMAP'd video buffers.
 
 ~VideoBuffers ()
 Free the MMAP'd memory area.
 
size_t size () const
 Get the number of buffers allocated.
 
size_t nqueued () const
 Get the number of buffers queued, this is always in [0 .. size()[.
 
std::shared_ptr< VideoBufget (size_t const index) const
 Get one buffer, by index [0 .. size()[.
 
void qbuf (size_t const index)
 Queue one buffer to V4L2, by index [0 .. size()[.
 
void qbuf (struct v4l2_buffer &buf)
 Queue one buffer to V4L2, by v4l2_buffer.
 
void qbufall ()
 Queue all buffers, typically used when starting streaming on capture devices.
 
void qbufallbutone (size_t const index)
 Queue all buffers that are not already queued except one specified.
 
void dqbuf (struct v4l2_buffer &buf)
 Dequeue the next captured/displayed buffer, blocks until one is available.
 
void dqbufall ()
 Dequeue all buffers, typically used when stopping a stream, not that this may take some time.
 

Constructor & Destructor Documentation

◆ VideoBuffers()

jevois::VideoBuffers::VideoBuffers ( char const *  name,
int const  fd,
v4l2_buf_type  type,
size_t const  num = 4 
)

Construct and allocate MMAP'd video buffers.

Type is the buffer type, typically V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE or V4L2_BUF_TYPE_VIDEO_OUTPUT.

Note
name is only for debug messages, so we can differentiate camera from USB buffers.

Definition at line 30 of file VideoBuffers.C.

References FDLDEBUG, FDLFATAL, LFATAL, and XIOCTL.

◆ ~VideoBuffers()

jevois::VideoBuffers::~VideoBuffers ( )

Free the MMAP'd memory area.

Definition at line 91 of file VideoBuffers.C.

References FDLDEBUG, and XIOCTL_QUIET.

Member Function Documentation

◆ dqbuf()

void jevois::VideoBuffers::dqbuf ( struct v4l2_buffer &  buf)

Dequeue the next captured/displayed buffer, blocks until one is available.

Definition at line 183 of file VideoBuffers.C.

References FDLFATAL, and XIOCTL_QUIET_ONCE.

◆ dqbufall()

void jevois::VideoBuffers::dqbufall ( )

Dequeue all buffers, typically used when stopping a stream, not that this may take some time.

Definition at line 208 of file VideoBuffers.C.

◆ get()

std::shared_ptr< jevois::VideoBuf > jevois::VideoBuffers::get ( size_t const  index) const

Get one buffer, by index [0 .. size()[.

Definition at line 127 of file VideoBuffers.C.

References FDLFATAL.

◆ nqueued()

size_t jevois::VideoBuffers::nqueued ( ) const

Get the number of buffers queued, this is always in [0 .. size()[.

Definition at line 121 of file VideoBuffers.C.

◆ qbuf() [1/2]

void jevois::VideoBuffers::qbuf ( size_t const  index)

Queue one buffer to V4L2, by index [0 .. size()[.

Beware that this throws if used on an output device as we would not know what value to use for bytesused (how much data there is in the buffer; this is necessary to support streaming out MJPG images whose number of bytes used is variable). Use qbuf(v4l2_buffer) instead on those, with typically a buffer obtained from dqbuf(), and the number of bytes used set in the bytesused field on that buffer when it contains an MJPG image.

Definition at line 135 of file VideoBuffers.C.

References FDLFATAL, and XIOCTL_QUIET.

◆ qbuf() [2/2]

void jevois::VideoBuffers::qbuf ( struct v4l2_buffer &  buf)

Queue one buffer to V4L2, by v4l2_buffer.

The caller is responsible for setting all the fields in the v4l2_buf, including an index that corresponds to a valid previously requested and not already queued buffer. Typically, this is used by output devices which first get the buffer via dqbuf(), then stuff the pixel data into it, and then send it back to qbuf().

Definition at line 159 of file VideoBuffers.C.

References XIOCTL_QUIET.

◆ qbufall()

void jevois::VideoBuffers::qbufall ( )

Queue all buffers, typically used when starting streaming on capture devices.

Definition at line 170 of file VideoBuffers.C.

◆ qbufallbutone()

void jevois::VideoBuffers::qbufallbutone ( size_t const  index)

Queue all buffers that are not already queued except one specified.

Definition at line 176 of file VideoBuffers.C.

◆ size()

size_t jevois::VideoBuffers::size ( ) const

Get the number of buffers allocated.

Definition at line 115 of file VideoBuffers.C.


The documentation for this class was generated from the following files: