Jetson Inference
DNN Vision Library
videoOutput.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_OUTPUT_H_
24 #define __VIDEO_OUTPUT_H_
25 
26 
27 #include "videoOptions.h"
28 #include "imageFormat.h"
29 #include "commandLine.h"
30 
31 #include <vector>
32 
33 
38 #define VIDEO_OUTPUT_USAGE_STRING "videoOutput arguments: \n" \
39  " output_URI resource URI of the output stream, for example:\n" \
40  " * file://my_image.jpg (image file)\n" \
41  " * file://my_video.mp4 (video file)\n" \
42  " * file://my_directory/ (directory of images)\n" \
43  " * rtp://<remote-ip>:1234 (RTP stream)\n" \
44  " * display://0 (OpenGL window)\n" \
45  " --output-codec=CODEC desired codec for compressed output streams:\n" \
46  " * h264 (default), h265\n" \
47  " * vp8, vp9\n" \
48  " * mpeg2, mpeg4\n" \
49  " * mjpeg\n" \
50  " --bitrate=BITRATE desired target VBR bitrate for compressed streams,\n" \
51  " in bits per second. The default is 4000000 (4 Mbps)\n" \
52  " --headless don't create a default OpenGL GUI window\n\n"
53 
54 
87 {
88 public:
93  static videoOutput* Create( const videoOptions& options );
94 
99  static videoOutput* Create( const char* URI, const videoOptions& options=videoOptions() );
100 
106  static videoOutput* Create( const char* URI, const commandLine& cmdLine );
107 
113  static videoOutput* Create( const char* URI, const int argc, char** argv );
114 
123  static videoOutput* Create( const int argc, char** argv, int positionArg=-1 );
124 
133  static videoOutput* Create( const commandLine& cmdLine, int positionArg=-1 );
134 
139  static videoOutput* CreateNullOutput();
140 
144  virtual ~videoOutput();
145 
149  static inline const char* Usage() { return VIDEO_OUTPUT_USAGE_STRING; }
150 
168  template<typename T> bool Render( T* image, uint32_t width, uint32_t height ) { return Render((void**)image, width, height, imageFormatFromType<T>()); }
169 
182  virtual bool Render( void* image, uint32_t width, uint32_t height, imageFormat format );
183 
194  virtual bool Open();
195 
203  virtual void Close();
204 
211  inline bool IsStreaming() const { return mStreaming; }
212 
216  inline uint32_t GetWidth() const { return mOptions.width; }
217 
221  inline uint32_t GetHeight() const { return mOptions.height; }
222 
226  inline float GetFrameRate() const { return mOptions.frameRate; }
227 
231  inline const URI& GetResource() const { return mOptions.resource; }
232 
236  inline const videoOptions& GetOptions() const { return mOptions; }
237 
242  inline void AddOutput( videoOutput* output ) { if(output != NULL) mOutputs.push_back(output); }
243 
247  inline uint32_t GetNumOutputs() const { return mOutputs.size(); }
248 
252  inline videoOutput* GetOutput( uint32_t index ) const { return mOutputs[index]; }
253 
258  virtual void SetStatus( const char* str );
259 
268  virtual inline uint32_t GetType() const { return 0; }
269 
274  inline bool IsType( uint32_t type ) const { return (type == GetType()); }
275 
283  template<typename T> bool IsType() const { return IsType(T::Type); }
284 
288  inline const char* TypeToStr() const { return TypeToStr(GetType()); }
289 
293  static const char* TypeToStr( uint32_t type );
294 
295 protected:
296  videoOutput( const videoOptions& options );
297 
300 
301  std::vector<videoOutput*> mOutputs;
302 };
303 
304 #endif
const URI & GetResource() const
Return the resource URI of the stream.
Definition: videoOutput.h:231
virtual ~videoOutput()
Destroy interface and release all resources.
float GetFrameRate() const
Return the framerate, in Hz or FPS.
Definition: videoOutput.h:226
static videoOutput * CreateNullOutput()
Create videoOutput interface that acts as a NULL output and does nothing with incoming frames...
videoOutput(const videoOptions &options)
static videoOutput * Create(const videoOptions &options)
Create videoOutput interface from a videoOptions struct that&#39;s already been filled out...
bool IsStreaming() const
Check if the device is actively streaming or not.
Definition: videoOutput.h:211
bool IsType() const
Check if a this stream is of a particular type.
Definition: videoOutput.h:283
const videoOptions & GetOptions() const
Return the videoOptions of the stream.
Definition: videoOutput.h:236
const char * TypeToStr() const
Convert this stream&#39;s class type to string.
Definition: videoOutput.h:288
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
The videoOutput API is for rendering and transmitting frames to video input devices such as display w...
Definition: videoOutput.h:86
videoOutput * GetOutput(uint32_t index) const
Return a sub-stream.
Definition: videoOutput.h:252
#define VIDEO_OUTPUT_USAGE_STRING
Standard command-line options able to be passed to videoOutput::Create()
Definition: videoOutput.h:38
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
static const char * Usage()
Usage string for command line arguments to Create()
Definition: videoOutput.h:149
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
videoOptions mOptions
Definition: videoOutput.h:299
bool IsType(uint32_t type) const
Check if this stream is of a particular type.
Definition: videoOutput.h:274
virtual void Close()
Stop streaming the device.
virtual bool Open()
Begin streaming the device.
std::vector< videoOutput * > mOutputs
Definition: videoOutput.h:301
bool mStreaming
Definition: videoOutput.h:298
void AddOutput(videoOutput *output)
Add an output sub-stream.
Definition: videoOutput.h:242
uint32_t GetNumOutputs() const
Return the number of sub-streams.
Definition: videoOutput.h:247
virtual void SetStatus(const char *str)
Set a status string (i.e.
uint32_t GetHeight() const
Return the height of the stream, in pixels.
Definition: videoOutput.h:221
bool Render(T *image, uint32_t width, uint32_t height)
Render and output the next frame to the stream.
Definition: videoOutput.h:168
URI resource
The resource URI of the device, IP stream, or file/directory.
Definition: videoOptions.h:49
uint32_t GetWidth() const
Return the width of the stream, in pixels.
Definition: videoOutput.h:216
imageFormat
The imageFormat enum is used to identify the pixel format and colorspace of an image.
Definition: imageFormat.h:49
virtual uint32_t GetType() const
Return the interface type of the stream.
Definition: videoOutput.h:268