JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
VideoBuffers.H
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
18#pragma once
19
21#include <vector>
22#include <memory>
23#include <linux/videodev2.h>
24#include <string>
25
26namespace jevois
27{
28 //! Collection of buffers for V4L2 video frames (Camera or Gadget) with hooks to the MMAP'd areas
29 /*! Both the Camera and the Gadget use a VideoBuffers object to manage their video buffers. VideoBuffer is just a
30 vector of VideoBuf objects, with added functions to queue a buffer (send it to the kernel driver, either so that
31 it will be filed with a new camera frame, or so that its contents will be streamed out over the USB link), and to
32 dequeue a buffer (get the next grabbed camera frame, or the next empty USB buffer to be filled by user
33 code).
34
35 Note that this class provides no threading safety and must be protected externally in case of multithreaded
36 access.
37
38 VideoBuffers is mainly for internal use by Camera and Gadget. Machine vision programmers should just use Module
39 and the InputFrame and OutputFrame wrappers instead.
40
41 \ingroup core */
43 {
44 public:
45 //! Construct and allocate MMAP'd video buffers
46 /*! Type is the buffer type, typically V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE or
47 V4L2_BUF_TYPE_VIDEO_OUTPUT. \note name is only for debug messages, so we can differentiate camera from USB
48 buffers. */
49 VideoBuffers(char const * name, int const fd, v4l2_buf_type type, size_t const num = 4);
50
51 //! Free the MMAP'd memory area
53
54 //! Get the number of buffers allocated
55 size_t size() const;
56
57 //! Get the number of buffers queued, this is always in [0 .. size()[
58 size_t nqueued() const;
59
60 //! Get one buffer, by index [0 .. size()[
61 std::shared_ptr<VideoBuf> get(size_t const index) const;
62
63 //! Queue one buffer to V4L2, by index [0 .. size()[
64 /*! Beware that this throws if used on an output device as we would not know what value to use for bytesused (how
65 much data there is in the buffer; this is necessary to support streaming out MJPG images whose number of bytes
66 used is variable). Use qbuf(v4l2_buffer) instead on those, with typically a buffer obtained from dqbuf(), and
67 the number of bytes used set in the bytesused field on that buffer when it contains an MJPG image. */
68 void qbuf(size_t const index);
69
70 //! Queue one buffer to V4L2, by v4l2_buffer
71 /*! The caller is responsible for setting all the fields in the v4l2_buf, including an index that corresponds to a
72 valid previously requested and not already queued buffer. Typically, this is used by output devices which
73 first get the buffer via dqbuf(), then stuff the pixel data into it, and then send it back to qbuf(). */
74 void qbuf(struct v4l2_buffer & buf);
75
76 //! Queue all buffers, typically used when starting streaming on capture devices
77 void qbufall();
78
79 //! Queue all buffers that are not already queued except one specified
80 void qbufallbutone(size_t const index);
81
82 //! Dequeue the next captured/displayed buffer, blocks until one is available
83 void dqbuf(struct v4l2_buffer & buf);
84
85 //! Dequeue all buffers, typically used when stopping a stream, not that this may take some time
86 void dqbufall();
87
88 private:
89 int const itsFd;
90 std::string const itsName;
91 v4l2_buf_type const itsType;
92 std::vector<std::shared_ptr<VideoBuf> > itsBuffers;
93 size_t itsNqueued;
94 };
95
96} // namespace jevois
97
Collection of buffers for V4L2 video frames (Camera or Gadget) with hooks to the MMAP'd areas.
std::shared_ptr< VideoBuf > get(size_t const index) const
Get one buffer, by index [0 .. size()[.
void dqbufall()
Dequeue all buffers, typically used when stopping a stream, not that this may take some time.
void qbufall()
Queue all buffers, typically used when starting streaming on capture devices.
size_t nqueued() const
Get the number of buffers queued, this is always in [0 .. size()[.
size_t size() const
Get the number of buffers allocated.
void qbufallbutone(size_t const index)
Queue all buffers that are not already queued except one specified.
void qbuf(size_t const index)
Queue one buffer to V4L2, by index [0 .. size()[.
~VideoBuffers()
Free the MMAP'd memory area.
void dqbuf(struct v4l2_buffer &buf)
Dequeue the next captured/displayed buffer, blocks until one is available.
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2