JeVois  1.0
JeVois Smart Embedded Machine Vision Toolkit
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 41 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. More...
 
 ~VideoBuffers ()
 Free the MMAP'd memory area. More...
 
size_t size () const
 Get the number of buffers allocated. More...
 
size_t nqueued () const
 Get the number of buffers queued, this is always in [0 .. size()[. More...
 
std::shared_ptr< VideoBufget (size_t const index) const
 Get one buffer, by index [0 .. size()[. More...
 
void qbuf (size_t const index)
 Queue one buffer to V4L2, by index [0 .. size()[. More...
 
void qbuf (struct v4l2_buffer &buf)
 Queue one buffer to V4L2, by v4l2_buffer. More...
 
void qbufall ()
 Queue all buffers, typically used when starting streaming on capture devices. More...
 
void dqbuf (struct v4l2_buffer &buf)
 Dequeue the next captured/displayed buffer, blocks until one is available. More...
 
void dqbufall ()
 Dequeue all buffers, typically used when stopping a stream, not that this may take some time. More...
 

Constructor & Destructor Documentation

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 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, and XIOCTL.

jevois::VideoBuffers::~VideoBuffers ( )

Free the MMAP'd memory area.

Definition at line 56 of file VideoBuffers.C.

References FDLDEBUG, and XIOCTL_QUIET.

Member Function Documentation

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

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

Definition at line 133 of file VideoBuffers.C.

References FDLFATAL, and XIOCTL.

void jevois::VideoBuffers::dqbufall ( )

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

Definition at line 147 of file VideoBuffers.C.

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

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

Definition at line 92 of file VideoBuffers.C.

References FDLFATAL.

size_t jevois::VideoBuffers::nqueued ( ) const

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

Definition at line 86 of file VideoBuffers.C.

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 100 of file VideoBuffers.C.

References FDLFATAL, and XIOCTL.

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 117 of file VideoBuffers.C.

References FDLFATAL, and XIOCTL.

void jevois::VideoBuffers::qbufall ( )

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

Definition at line 127 of file VideoBuffers.C.

size_t jevois::VideoBuffers::size ( ) const

Get the number of buffers allocated.

Definition at line 80 of file VideoBuffers.C.


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