JeVois  1.0
JeVois Smart Embedded Machine Vision Toolkit
VideoMapping.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 <iosfwd>
21 #include <vector>
22 #include <string>
23 #include <linux/videodev2.h> // for v4l2_fract
24 
25 namespace jevois
26 {
27  //! Simple struct to hold video mapping definitions for the processing Engine
28  /*! This struct specifies an output video format, resolution, and frame rate (to be send to the end user over USB),
29  the corresponding camera capture video format, resolution and frame rate, and the Module to use to process the
30  camera frames and generate the corresponding output frames. This class also provides conversion functions between
31  frame rate and frame interval periods for both USB and V4L2, which use different units.
32 
33  Operation of JeVois is based on a list of available VideoMapping definitions, which is configured in a file called
34  JEVOIS:config/videomappings.cfg on the microSD card. The video mappings indicate which output formats are exposed
35  to the host computer connected over USB, and which corresponding camera format and vision processing module should
36  be used when a given output format is selected by video capture software running on the host computer.
37 
38  See \ref UserModes for explanations about how to organize videomappings.cfg
39 
40  \ingroup core */
41  struct VideoMapping
42  {
43  unsigned int ofmt; //!< output pixel format, or 0 for no output over USB
44  unsigned int ow; //!< output width
45  unsigned int oh; //!< output height
46  float ofps; //!< output frame rate in frames/sec
47 
48  unsigned int cfmt; //!< camera pixel format
49  unsigned int cw; //!< camera width
50  unsigned int ch; //!< camera height
51  float cfps; //!< camera frame rate in frames/sec
52 
53  unsigned int uvcformat; //!< USB-UVC format number (1-based)
54  unsigned int uvcframe; //!< USB UVC frame number (1-based)
55 
56  std::string vendor; //!< Module creator name, used as a directory to organize the modules
57 
58  std::string modulename; //!< Name of the Module that will process this mapping
59 
60  //! Return the full absolute path and file name of the module's .so file
61  std::string sopath() const;
62 
63  //! Return the size in bytes of an output image
64  unsigned int osize() const;
65 
66  //! Return the size in bytes of a camera image
67  unsigned int csize() const;
68 
69  //! Convert from USB/UVC interval to fps
70  /*! This function rounds to the nearest 1/100 fps. */
71  static float uvcToFps(unsigned int interval);
72 
73  //! Convert from fps to USB/UCV interval
74  static unsigned int fpsToUvc(float fps);
75 
76  //! Convert from V4L2 interval to fps
77  /*! This function rounds to the nearest 1/100 fps. */
78  static float v4l2ToFps(struct v4l2_fract const & interval);
79 
80  //! Convert from fps to V4L2 interval
81  static struct v4l2_fract fpsToV4l2(float fps);
82 
83  //! Return true if this VideoMapping's output format is a match to the given output parameters
84  bool match(unsigned int oformat, unsigned int owidth, unsigned int oheight, float oframespersec) const;
85 
86  //! Convenience function to print out FCC WxH @ fps, for the output (UVC) format
87  std::string ostr() const;
88 
89  //! Convenience function to print out FCC WxH @ fps, for the input (camera) format
90  std::string cstr() const;
91 
92  //! Convenience function to print out the whole mapping
93  std::string str() const;
94  };
95 
96  //! Load all the video mappings from the default config file
97  /*! \relates VideoMapping */
98  std::vector<VideoMapping> loadVideoMappings(size_t & defidx);
99 
100  //! Parse all the mappings in a config file and also indicate which one is the default
101  /*! The contents of the file are sorted so that the resulting vector is ordered by increasing 1) format fcc, then 2)
102  resolution (from large to small, looking at x first), and 3) framerate (from high to low).
103 
104  In case of duplicate output formats, frame rates will be decreased by 1fps for each additional duplicate. This is
105  because we need to present the host computer with distrinct video format sso that a user can select th eone they
106  want. For example:
107  \verbatim
108  YUYV 320 240 60.0 YUYV 320 240 60.0 JeVois SaveVideo
109  YUYV 320 240 60.0 YUYV 320 240 60.0 VendorX MyModule
110  YUYV 320 240 60.0 YUYV 320 240 60.0 VendorY MyModule
111  YUYV 320 240 60.0 YUYV 320 240 60.0 VendorZ MyModule
112  \endverbatim
113 
114  will be disambiguated into:
115 
116  \verbatim
117  YUYV 320 240 60.0 YUYV 320 240 60.0 JeVois SaveVideo
118  YUYV 320 240 59.0 YUYV 320 240 60.0 VendorX MyModule
119  YUYV 320 240 58.0 YUYV 320 240 60.0 VendorY MyModule
120  YUYV 320 240 57.0 YUYV 320 240 60.0 VendorZ MyModule
121  \endverbatim
122 
123  and in \c guvcview or similar program running on a host computer, these 4 mappings will be available since they
124  correspond to 4 different framerates. It is recommended that you issue a \c listmapping command in the JeVois
125  command-line interface to confirm the final mappings that are used at runtime after any adjustments; see \ref
126  UserCli for details.
127 
128  defidx is the index of the default format in the resulting vector of mappings. If several default formats are
129  specified, the first one prevails.
130 
131  See \ref UserModes for explanations about how to organize videomappings.cfg
132  \relates VideoMapping */
133  std::vector<VideoMapping> videoMappingsFromStream(std::istream & is, size_t & defidx);
134 }
135 
float ofps
output frame rate in frames/sec
Definition: VideoMapping.H:46
unsigned int uvcformat
USB-UVC format number (1-based)
Definition: VideoMapping.H:53
unsigned int osize() const
Return the size in bytes of an output image.
Definition: VideoMapping.C:51
static struct v4l2_fract fpsToV4l2(float fps)
Convert from fps to V4L2 interval.
Definition: VideoMapping.C:79
unsigned int ofmt
output pixel format, or 0 for no output over USB
Definition: VideoMapping.H:43
std::string cstr() const
Convenience function to print out FCC WxH @ fps, for the input (camera) format.
Definition: VideoMapping.C:93
std::string modulename
Name of the Module that will process this mapping.
Definition: VideoMapping.H:58
unsigned int ch
camera height
Definition: VideoMapping.H:50
static float uvcToFps(unsigned int interval)
Convert from USB/UVC interval to fps.
Definition: VideoMapping.C:59
std::string ostr() const
Convenience function to print out FCC WxH @ fps, for the output (UVC) format.
Definition: VideoMapping.C:85
Simple struct to hold video mapping definitions for the processing Engine.
Definition: VideoMapping.H:41
std::string sopath() const
Return the full absolute path and file name of the module's .so file.
Definition: VideoMapping.C:45
unsigned int uvcframe
USB UVC frame number (1-based)
Definition: VideoMapping.H:54
unsigned int oh
output height
Definition: VideoMapping.H:45
static float v4l2ToFps(struct v4l2_fract const &interval)
Convert from V4L2 interval to fps.
Definition: VideoMapping.C:72
std::string str() const
Convenience function to print out the whole mapping.
Definition: VideoMapping.C:101
unsigned int cfmt
camera pixel format
Definition: VideoMapping.H:48
unsigned int cw
camera width
Definition: VideoMapping.H:49
bool match(unsigned int oformat, unsigned int owidth, unsigned int oheight, float oframespersec) const
Return true if this VideoMapping's output format is a match to the given output parameters.
Definition: VideoMapping.C:272
static unsigned int fpsToUvc(float fps)
Convert from fps to USB/UCV interval.
Definition: VideoMapping.C:66
unsigned int ow
output width
Definition: VideoMapping.H:44
std::string vendor
Module creator name, used as a directory to organize the modules.
Definition: VideoMapping.H:56
unsigned int csize() const
Return the size in bytes of a camera image.
Definition: VideoMapping.C:55
float cfps
camera frame rate in frames/sec
Definition: VideoMapping.H:51