JeVois  1.20
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
VideoBuf.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 
20 #include <cstddef>
21 
22 namespace jevois
23 {
24  //! A V4L2 video buffer, to be held in a shared_ptr
25  /*! Requests an MMAP'ed memory area from the given file descriptor at construction, and unmaps it at
26  destruction. VideoBuf is used to pass MMAP'ed video buffers from Camera and Gadget drivers to application code,
27  via RawImage. The actual memory allocation is performed by the kernel driver. Hence, VideoBuf pixel arrays cannot
28  be moved from one memory location to another. \ingroup core */
29  class VideoBuf
30  {
31  public:
32  //! Construct and allocate MMAP'd memory
33  /*! Mostly for debugging purposes (supporting VideoDisplay), if fd is -1 then we perform a regular memory
34  allocation instead of mmap. */
35  VideoBuf(int const fd, size_t const length, unsigned int offset, int const dmafd);
36 
37  //! Destructor unmaps the memory
38  ~VideoBuf();
39 
40  //! Sync the data
41  /*! This may be useful in some cases to avoid cache coherency issues between DMA-capable driver and CPU. */
42  void sync();
43 
44  //! Get a pointer to the buffer data
45  void * data() const;
46 
47  //! Get the allocated memory length
48  size_t length() const;
49 
50  //! Set the number of bytes used, eg, for MJPEG images that application code compressed into the buffer
51  void setBytesUsed(size_t n);
52 
53  //! Get the number of bytes used, valid only for MJPEG images
54  size_t bytesUsed() const;
55 
56  //! Get the dma_buf fd associated with this buffer, which was given at construction
57  int dmaFd() const;
58 
59 
60  private:
61  int const itsFd;
62  size_t const itsLength;
63  size_t itsBytesUsed;
64  void * itsAddr;
65  int const itsDmaBufFd;
66  };
67 
68 } // namespace jevois
jevois::VideoBuf::dmaFd
int dmaFd() const
Get the dma_buf fd associated with this buffer, which was given at construction.
Definition: VideoBuf.C:129
jevois
Definition: Concepts.dox:1
jevois::VideoBuf::sync
void sync()
Sync the data.
Definition: VideoBuf.C:85
jevois::VideoBuf::setBytesUsed
void setBytesUsed(size_t n)
Set the number of bytes used, eg, for MJPEG images that application code compressed into the buffer.
Definition: VideoBuf.C:117
jevois::VideoBuf::length
size_t length() const
Get the allocated memory length.
Definition: VideoBuf.C:111
jevois::VideoBuf::~VideoBuf
~VideoBuf()
Destructor unmaps the memory.
Definition: VideoBuf.C:49
jevois::VideoBuf::VideoBuf
VideoBuf(int const fd, size_t const length, unsigned int offset, int const dmafd)
Construct and allocate MMAP'd memory.
Definition: VideoBuf.C:27
jevois::VideoBuf::data
void * data() const
Get a pointer to the buffer data.
Definition: VideoBuf.C:105
jevois::VideoBuf
A V4L2 video buffer, to be held in a shared_ptr.
Definition: VideoBuf.H:29
jevois::VideoBuf::bytesUsed
size_t bytesUsed() const
Get the number of bytes used, valid only for MJPEG images.
Definition: VideoBuf.C:123