Jetson Inference
DNN Vision Library
videoSource.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __VIDEO_SOURCE_H_
24 #define __VIDEO_SOURCE_H_
25 
26 
27 #include "videoOptions.h"
28 #include "imageFormat.h"
29 #include "commandLine.h"
30 
31 
36 #define VIDEO_SOURCE_USAGE_STRING "videoSource arguments: \n" \
37  " input_URI resource URI of the input stream, for example:\n" \
38  " * /dev/video0 (V4L2 camera #0)\n" \
39  " * csi://0 (MIPI CSI camera #0)\n" \
40  " * rtp://@:1234 (RTP stream)\n" \
41  " * rtsp://user:pass@ip:1234 (RTSP stream)\n" \
42  " * file://my_image.jpg (image file)\n" \
43  " * file://my_video.mp4 (video file)\n" \
44  " * file://my_directory/ (directory of images)\n" \
45  " --input-width=WIDTH explicitly request a width of the stream (optional)\n" \
46  " --input-height=HEIGHT explicitly request a height of the stream (optional)\n" \
47  " --input-rate=RATE explicitly request a framerate of the stream (optional)\n" \
48  " --input-codec=CODEC RTP requires the codec to be set, one of these:\n" \
49  " * h264, h265\n" \
50  " * vp8, vp9\n" \
51  " * mpeg2, mpeg4\n" \
52  " * mjpeg\n" \
53  " --input-flip=FLIP flip method to apply to input (excludes V4L2):\n" \
54  " * none (default)\n" \
55  " * counterclockwise\n" \
56  " * rotate-180\n" \
57  " * clockwise\n" \
58  " * horizontal\n" \
59  " * vertical\n" \
60  " * upper-right-diagonal\n" \
61  " * upper-left-diagonal\n" \
62  " --input-loop=LOOP for file-based inputs, the number of loops to run:\n" \
63  " * -1 = loop forever\n" \
64  " * 0 = don't loop (default)\n" \
65  " * >0 = set number of loops\n\n"
66 
67 
113 {
114 public:
119  static videoSource* Create( const videoOptions& options );
120 
125  static videoSource* Create( const char* URI, const videoOptions& options=videoOptions() );
126 
132  static videoSource* Create( const char* URI, const commandLine& cmdLine );
133 
139  static videoSource* Create( const char* URI, const int argc, char** argv );
140 
149  static videoSource* Create( const int argc, char** argv, int positionArg=-1 );
150 
159  static videoSource* Create( const commandLine& cmdLine, int positionArg=-1 );
160 
164  virtual ~videoSource();
165 
169  static inline const char* Usage() { return VIDEO_SOURCE_USAGE_STRING; }
170 
195  template<typename T> bool Capture( T** image, uint64_t timeout=UINT64_MAX ) { return Capture((void**)image, imageFormatFromType<T>(), timeout); }
196 
214  virtual bool Capture( void** image, imageFormat format, uint64_t timeout=UINT64_MAX ) = 0;
215 
226  virtual bool Open();
227 
235  virtual void Close();
236 
243  inline bool IsStreaming() const { return mStreaming; }
244 
248  inline uint32_t GetWidth() const { return mOptions.width; }
249 
253  inline uint32_t GetHeight() const { return mOptions.height; }
254 
258  inline uint32_t GetFrameRate() const { return mOptions.frameRate; }
259 
263  inline const URI& GetResource() const { return mOptions.resource; }
264 
268  inline const videoOptions& GetOptions() const { return mOptions; }
269 
278  virtual inline uint32_t GetType() const { return 0; }
279 
284  inline bool IsType( uint32_t type ) const { return (type == GetType()); }
285 
293  template<typename T> bool IsType() const { return IsType(T::Type); }
294 
298  inline const char* TypeToStr() const { return TypeToStr(GetType()); }
299 
303  static const char* TypeToStr( uint32_t type );
304 
305 protected:
306  //videoSource();
307  videoSource( const videoOptions& options );
308 
311 };
312 
313 #endif
videoSource(const videoOptions &options)
bool IsType(uint32_t type) const
Check if this stream is of a particular type.
Definition: videoSource.h:284
static const char * Usage()
Usage string for command line arguments to Create()
Definition: videoSource.h:169
bool IsStreaming() const
Check if the device is actively streaming or not.
Definition: videoSource.h:243
virtual bool Open()
Begin streaming the device.
#define VIDEO_SOURCE_USAGE_STRING
Standard command-line options able to be passed to videoSource::Create()
Definition: videoSource.h:36
float frameRate
The framerate of the stream (the default is 30Hz).
Definition: videoOptions.h:70
Resource URI of a video device, IP stream, or file/directory.
Definition: URI.h:91
const URI & GetResource() const
Return the resource URI of the stream.
Definition: videoSource.h:263
uint32_t height
The height of the stream (in pixels).
Definition: videoOptions.h:63
The videoOptions struct contains common settings that are used to configure and query videoSource and...
Definition: videoOptions.h:37
bool Capture(T **image, uint64_t timeout=UINT64_MAX)
Capture the next image from the video stream.
Definition: videoSource.h:195
uint32_t GetFrameRate() const
Return the framerate, in Hz or FPS.
Definition: videoSource.h:258
Command line parser for extracting flags, values, and strings.
Definition: commandLine.h:35
uint32_t width
The width of the stream (in pixels).
Definition: videoOptions.h:56
bool mStreaming
Definition: videoSource.h:309
virtual ~videoSource()
Destroy interface and release all resources.
const char * TypeToStr() const
Convert this stream&#39;s class type to string.
Definition: videoSource.h:298
videoOptions mOptions
Definition: videoSource.h:310
bool IsType() const
Check if a this stream is of a particular type.
Definition: videoSource.h:293
uint32_t GetWidth() const
Return the width of the stream, in pixels.
Definition: videoSource.h:248
virtual void Close()
Stop streaming the device.
uint32_t GetHeight() const
Return the height of the stream, in pixels.
Definition: videoSource.h:253
const videoOptions & GetOptions() const
Return the videoOptions of the stream.
Definition: videoSource.h:268
virtual uint32_t GetType() const
Return the interface type of the stream.
Definition: videoSource.h:278
The videoSource API is for capturing frames from video input devices such as MIPI CSI cameras...
Definition: videoSource.h:112
URI resource
The resource URI of the device, IP stream, or file/directory.
Definition: videoOptions.h:49
static videoSource * Create(const videoOptions &options)
Create videoSource interface from a videoOptions struct that&#39;s already been filled out...
imageFormat
The imageFormat enum is used to identify the pixel format and colorspace of an image.
Definition: imageFormat.h:49