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 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  " * rtsp://@:8554/my_stream (RTSP stream)\n" \
45  " * webrtc://@:1234/my_stream (WebRTC stream)\n" \
46  " * display://0 (OpenGL window)\n" \
47  " --output-codec=CODEC desired codec for compressed output streams:\n" \
48  " * h264 (default), h265\n" \
49  " * vp8, vp9\n" \
50  " * mpeg2, mpeg4\n" \
51  " * mjpeg\n" \
52  " --output-encoder=TYPE the encoder engine to use, one of these:\n" \
53  " * cpu\n" \
54  " * omx (aarch64/JetPack4 only)\n" \
55  " * v4l2 (aarch64/JetPack5 only)\n" \
56  " --output-save=FILE path to a video file for saving the compressed stream\n" \
57  " to disk, in addition to the primary output above\n" \
58  " --bitrate=BITRATE desired target VBR bitrate for compressed streams,\n" \
59  " in bits per second. The default is 4000000 (4 Mbps)\n" \
60  " --headless don't create a default OpenGL GUI window\n\n"
61 
62 
105 {
106 public:
111  static videoOutput* Create( const videoOptions& options );
112 
117  static videoOutput* Create( const char* URI, const videoOptions& options=videoOptions() );
118 
124  static videoOutput* Create( const char* URI, const commandLine& cmdLine );
125 
131  static videoOutput* Create( const char* URI, const int argc, char** argv );
132 
141  static videoOutput* Create( const int argc, char** argv, int positionArg=-1 );
142 
151  static videoOutput* Create( const commandLine& cmdLine, int positionArg=-1 );
152 
157  static videoOutput* CreateNullOutput();
158 
162  virtual ~videoOutput();
163 
167  static inline const char* Usage() { return VIDEO_OUTPUT_USAGE_STRING; }
168 
186  template<typename T> bool Render( T* image, uint32_t width, uint32_t height ) { return Render((void**)image, width, height, imageFormatFromType<T>()); }
187 
200  virtual bool Render( void* image, uint32_t width, uint32_t height, imageFormat format );
201 
212  virtual bool Open();
213 
221  virtual void Close();
222 
229  inline bool IsStreaming() const { return mStreaming; }
230 
234  inline uint32_t GetWidth() const { return mOptions.width; }
235 
239  inline uint32_t GetHeight() const { return mOptions.height; }
240 
244  inline float GetFrameRate() const { return mOptions.frameRate; }
245 
249  inline uint64_t GetFrameCount() const { return mOptions.frameCount; }
250 
254  inline const URI& GetResource() const { return mOptions.resource; }
255 
259  inline const videoOptions& GetOptions() const { return mOptions; }
260 
265  inline void AddOutput( videoOutput* output ) { if(output != NULL) mOutputs.push_back(output); }
266 
270  inline uint32_t GetNumOutputs() const { return mOutputs.size(); }
271 
275  inline videoOutput* GetOutput( uint32_t index ) const { return mOutputs[index]; }
276 
281  virtual void SetStatus( const char* str );
282 
291  virtual inline uint32_t GetType() const { return 0; }
292 
297  inline bool IsType( uint32_t type ) const { return (type == GetType()); }
298 
306  template<typename T> bool IsType() const { return IsType(T::Type); }
307 
311  inline const char* TypeToStr() const { return TypeToStr(GetType()); }
312 
316  static const char* TypeToStr( uint32_t type );
317 
318 protected:
319  videoOutput( const videoOptions& options );
320 
323 
324  std::vector<videoOutput*> mOutputs;
325 };
326 
327 #endif
videoOutput::SetStatus
virtual void SetStatus(const char *str)
Set a status string (i.e.
VIDEO_OUTPUT_USAGE_STRING
#define VIDEO_OUTPUT_USAGE_STRING
Standard command-line options able to be passed to videoOutput::Create()
Definition: videoOutput.h:38
videoOutput::AddOutput
void AddOutput(videoOutput *output)
Add an output sub-stream.
Definition: videoOutput.h:265
videoOutput::GetOutput
videoOutput * GetOutput(uint32_t index) const
Return a sub-stream.
Definition: videoOutput.h:275
videoOutput::GetFrameCount
uint64_t GetFrameCount() const
Return the number of frames output.
Definition: videoOutput.h:249
videoOutput::Open
virtual bool Open()
Begin streaming the device.
videoOutput::IsType
bool IsType() const
Check if a this stream is of a particular type.
Definition: videoOutput.h:306
videoOutput::~videoOutput
virtual ~videoOutput()
Destroy interface and release all resources.
videoOutput::GetHeight
uint32_t GetHeight() const
Return the height of the stream, in pixels.
Definition: videoOutput.h:239
videoOutput::Render
bool Render(T *image, uint32_t width, uint32_t height)
Render and output the next frame to the stream.
Definition: videoOutput.h:186
commandLine.h
videoOutput::mStreaming
bool mStreaming
Definition: videoOutput.h:321
videoOutput::GetResource
const URI & GetResource() const
Return the resource URI of the stream.
Definition: videoOutput.h:254
videoOutput::mOptions
videoOptions mOptions
Definition: videoOutput.h:322
videoOutput::Close
virtual void Close()
Stop streaming the device.
videoOptions::resource
URI resource
The resource URI of the device, IP stream, or file/directory.
Definition: videoOptions.h:49
videoOutput::videoOutput
videoOutput(const videoOptions &options)
videoOutput::GetNumOutputs
uint32_t GetNumOutputs() const
Return the number of sub-streams.
Definition: videoOutput.h:270
videoOutput::IsType
bool IsType(uint32_t type) const
Check if this stream is of a particular type.
Definition: videoOutput.h:297
URI
Resource URI of a video device, IP stream, or file/directory.
Definition: URI.h:101
videoOutput::Create
static videoOutput * Create(const videoOptions &options)
Create videoOutput interface from a videoOptions struct that's already been filled out.
videoOutput::CreateNullOutput
static videoOutput * CreateNullOutput()
Create videoOutput interface that acts as a NULL output and does nothing with incoming frames.
videoOutput::TypeToStr
const char * TypeToStr() const
Convert this stream's class type to string.
Definition: videoOutput.h:311
videoOutput::GetWidth
uint32_t GetWidth() const
Return the width of the stream, in pixels.
Definition: videoOutput.h:234
videoOutput::Usage
static const char * Usage()
Usage string for command line arguments to Create()
Definition: videoOutput.h:167
videoOutput
The videoOutput API is for rendering and transmitting frames to video input devices such as display w...
Definition: videoOutput.h:104
videoOutput::IsStreaming
bool IsStreaming() const
Check if the device is actively streaming or not.
Definition: videoOutput.h:229
videoOutput::GetFrameRate
float GetFrameRate() const
Return the framerate, in Hz or FPS.
Definition: videoOutput.h:244
videoOptions
The videoOptions struct contains common settings that are used to configure and query videoSource and...
Definition: videoOptions.h:37
commandLine
Command line parser for extracting flags, values, and strings.
Definition: commandLine.h:35
videoOptions::width
uint32_t width
The width of the stream (in pixels).
Definition: videoOptions.h:64
videoOutput::mOutputs
std::vector< videoOutput * > mOutputs
Definition: videoOutput.h:324
videoOutput::GetOptions
const videoOptions & GetOptions() const
Return the videoOptions of the stream.
Definition: videoOutput.h:259
videoOptions::frameCount
uint64_t frameCount
The number of frames that have been captured or output on this interface.
Definition: videoOptions.h:83
videoOptions::frameRate
float frameRate
The framerate of the stream (the default is 30Hz).
Definition: videoOptions.h:78
imageFormat.h
videoOptions.h
imageFormat
imageFormat
The imageFormat enum is used to identify the pixel format and colorspace of an image.
Definition: imageFormat.h:49
videoOptions::height
uint32_t height
The height of the stream (in pixels).
Definition: videoOptions.h:71
videoOutput::GetType
virtual uint32_t GetType() const
Return the interface type of the stream.
Definition: videoOutput.h:291