JeVois  1.2
JeVois Smart Embedded Machine Vision Toolkit
VideoInput.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 <jevois/Image/RawImage.H>
22 
23 namespace jevois
24 {
25  //! Base class for video input, which will get derived into Camera and MovieInput
26  /*! Engine uses a VideoInput to capture input frames and pass them to its currently loaded machine vision Module for
27  processing. The VideoInput class is abstract and simply defines the interface. For live video processing, Engine
28  will implement its VideoInput as a Camera, and for processing of pre-recorded videos or image sequences (useful to
29  debug or tune an algorithm on reproducible image sequences), it can also implement its VideoInout as a
30  MovieInput. \ingroup core */
31  class VideoInput
32  {
33  public:
34  //! Constructor
35  /*! \param devname name of the device, or movie file, or empty
36  \param nbufs number of video buffers to use, or 0 for automatic. */
37  VideoInput(std::string const & devname, unsigned int const nbufs = 0);
38 
39  //! Virtual destructor for save inheritance
40  virtual ~VideoInput();
41 
42  //! Start streaming
43  virtual void streamOn() = 0;
44 
45  //! Abort streaming
46  /*! This only cancels future get() and done() calls, one should still call streamOff() to turn off streaming. */
47  virtual void abortStream() = 0;
48 
49  //! Stop streaming
50  virtual void streamOff() = 0;
51 
52  //! Get the next captured buffer
53  /*! Throws if we are not streaming or blocks until an image is available (has been captured). The image img should
54  have been allocated by the caller and will be filled in by what we receive from the device here. */
55  virtual void get(RawImage & img) = 0;
56 
57  //! Indicate that user processing is done with an image previously obtained via get()
58  /*! You should call this as soon after get() as possible, once you are finished with the RawImage data so that it
59  can be recycled.
60 
61  \note This also invalidates the image and in particular its pixel buffer! */
62  virtual void done(RawImage & img) = 0;;
63 
64  //! Get information about a control, throw if unsupported by hardware
65  /*! Caller should zero-out qc and then set the id field to the desired control id. See VIDIOC_QUERYCTRL for more
66  information. */
67  virtual void queryControl(struct v4l2_queryctrl & qc) const = 0;
68 
69  //! Get the available menu entry names for a menu-type control, throw if unsupported by hardware
70  /*! Caller should zero-out qm and then set the id and index fields to the desired control id and menu item
71  index. See VIDIOC_QUERYMENU for more information. */
72  virtual void queryMenu(struct v4l2_querymenu & qm) const = 0;
73 
74  //! Get a control's current value, throw if unsupported by hardware
75  /*! This is just a pass-through to VIDIOC_G_CTRL */
76  virtual void getControl(struct v4l2_control & ctrl) const = 0;
77 
78  //! Set a control, throw if the hardware rejects the value
79  /*! This is just a pass-through to VIDIOC_S_CTRL */
80  virtual void setControl(struct v4l2_control const & ctrl) = 0;
81 
82  //! Set the video format and frame rate
83  virtual void setFormat(VideoMapping const & m) = 0;
84 
85  //! Write a value of one of the camera's registers
86  /*! This very low-level access is for development of optimal camera settings only and should not be used in normal
87  operation, it can crash your system. */
88  virtual void writeRegister(unsigned char reg, unsigned char val) = 0;
89 
90  //! Read a value from one of the camera's registers
91  /*! This very low-level access is for development of optimal camera settings only and should not be used in normal
92  operation, it can crash your system. */
93  virtual unsigned char readRegister(unsigned char reg) = 0;
94 
95  protected:
96  std::string const itsDevName; //!< Our device or movie file name
97  unsigned int const itsNbufs; //!< Our number of buffers
98  };
99 } // namespace jevois
VideoInput(std::string const &devname, unsigned int const nbufs=0)
Constructor.
Definition: VideoInput.C:21
virtual ~VideoInput()
Virtual destructor for save inheritance.
Definition: VideoInput.C:27
virtual void setControl(struct v4l2_control const &ctrl)=0
Set a control, throw if the hardware rejects the value.
virtual void streamOff()=0
Stop streaming.
virtual unsigned char readRegister(unsigned char reg)=0
Read a value from one of the camera's registers.
unsigned int const itsNbufs
Our number of buffers.
Definition: VideoInput.H:97
virtual void setFormat(VideoMapping const &m)=0
Set the video format and frame rate.
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition: RawImage.H:110
virtual void done(RawImage &img)=0
Indicate that user processing is done with an image previously obtained via get() ...
virtual void queryMenu(struct v4l2_querymenu &qm) const =0
Get the available menu entry names for a menu-type control, throw if unsupported by hardware...
Simple struct to hold video mapping definitions for the processing Engine.
Definition: VideoMapping.H:41
virtual void queryControl(struct v4l2_queryctrl &qc) const =0
Get information about a control, throw if unsupported by hardware.
Base class for video input, which will get derived into Camera and MovieInput.
Definition: VideoInput.H:31
virtual void abortStream()=0
Abort streaming.
virtual void streamOn()=0
Start streaming.
virtual void writeRegister(unsigned char reg, unsigned char val)=0
Write a value of one of the camera's registers.
std::string const itsDevName
Our device or movie file name.
Definition: VideoInput.H:96
virtual void getControl(struct v4l2_control &ctrl) const =0
Get a control's current value, throw if unsupported by hardware.