JeVois  1.0
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 nbufs number of video buffers to use, or 0 for automatic. */
36  VideoInput(std::string const & devname, unsigned int const nbufs = 0);
37 
38  //! Virtual destructor for save inheritance
39  virtual ~VideoInput();
40 
41  //! Start streaming
42  virtual void streamOn() = 0;
43 
44  //! Abort streaming
45  /*! This only cancels future get() and done() calls, one should still call streamOff() to turn off streaming. */
46  virtual void abortStream() = 0;
47 
48  //! Stop streaming
49  virtual void streamOff() = 0;
50 
51  //! Get the next captured buffer
52  /*! Throws if we are not streaming or blocks until an image is available (has been captured). The image img should
53  have been allocated by the caller and will be filled in by what we receive from the device here. */
54  virtual void get(RawImage & img) = 0;
55 
56  //! Indicate that user processing is done with an image previously obtained via get()
57  /*! You should call this as soon after get() as possible, once you are finished with the RawImage data so that it
58  can be recycled.
59 
60  \note This also invalidates the image and in particular its pixel buffer! */
61  virtual void done(RawImage & img) = 0;;
62 
63  //! Get information about a control, throw if unsupported by hardware
64  /*! Caller should zero-out qc and then set the id field to the desired control id. See VIDIOC_QUERYCTRL for more
65  information. */
66  virtual void queryControl(struct v4l2_queryctrl & qc) const = 0;
67 
68  //! Get the available menu entry names for a menu-type control, throw if unsupported by hardware
69  /*! Caller should zero-out qm and then set the id and index fields to the desired control id and menu item
70  index. See VIDIOC_QUERYMENU for more information. */
71  virtual void queryMenu(struct v4l2_querymenu & qm) const = 0;
72 
73  //! Get a control's current value, throw if unsupported by hardware
74  /*! This is just a pass-through to VIDIOC_G_CTRL */
75  virtual void getControl(struct v4l2_control & ctrl) const = 0;
76 
77  //! Set a control, throw if the hardware rejects the value
78  /*! This is just a pass-through to VIDIOC_S_CTRL */
79  virtual void setControl(struct v4l2_control const & ctrl) = 0;
80 
81  //! Set the video format and frame rate
82  virtual void setFormat(VideoMapping const & m) = 0;
83 
84  //! Write a value of one of the camera's registers
85  /*! This very low-level access is for development of optimal camera settings only and should not be used in normal
86  operation, it can crash your system. */
87  virtual void writeRegister(unsigned char reg, unsigned char val) = 0;
88 
89  //! Read a value from one of the camera's registers
90  /*! This very low-level access is for development of optimal camera settings only and should not be used in normal
91  operation, it can crash your system. */
92  virtual unsigned char readRegister(unsigned char reg) = 0;
93 
94  protected:
95  std::string const itsDevName; //!< Our device or movie file name
96  unsigned int const itsNbufs; //!< Our number of buffers
97  };
98 } // 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:96
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:95
virtual void getControl(struct v4l2_control &ctrl) const =0
Get a control's current value, throw if unsupported by hardware.