Jetson Inference
DNN Vision Library
gstEncoder Class Reference

Hardware-accelerated video encoder for Jetson using GStreamer. More...

#include <gstEncoder.h>

Inheritance diagram for gstEncoder:
videoOutput

Public Member Functions

 ~gstEncoder ()
 Destructor. More...
 
template<typename T >
bool Render (T *image, uint32_t width, uint32_t height)
 Encode the next frame. More...
 
virtual bool Render (void *image, uint32_t width, uint32_t height, imageFormat format)
 Encode the next frame. More...
 
virtual bool Open ()
 Open the stream. More...
 
virtual void Close ()
 Close the stream. More...
 
GstPipeline * GetPipeline () const
 Return the GStreamer pipeline object. More...
 
WebRTCServerGetWebRTCServer () const
 Return the WebRTC server (only used when the protocol is "webrtc://") More...
 
virtual uint32_t GetType () const
 Return the interface type (gstEncoder::Type) More...
 
- Public Member Functions inherited from videoOutput
virtual ~videoOutput ()
 Destroy interface and release all resources. More...
 
template<typename T >
bool Render (T *image, uint32_t width, uint32_t height)
 Render and output the next frame to the stream. More...
 
bool IsStreaming () const
 Check if the device is actively streaming or not. More...
 
uint32_t GetWidth () const
 Return the width of the stream, in pixels. More...
 
uint32_t GetHeight () const
 Return the height of the stream, in pixels. More...
 
float GetFrameRate () const
 Return the framerate, in Hz or FPS. More...
 
uint64_t GetFrameCount () const
 Return the number of frames output. More...
 
const URIGetResource () const
 Return the resource URI of the stream. More...
 
const videoOptionsGetOptions () const
 Return the videoOptions of the stream. More...
 
void AddOutput (videoOutput *output)
 Add an output sub-stream. More...
 
uint32_t GetNumOutputs () const
 Return the number of sub-streams. More...
 
videoOutputGetOutput (uint32_t index) const
 Return a sub-stream. More...
 
virtual void SetStatus (const char *str)
 Set a status string (i.e. More...
 
bool IsType (uint32_t type) const
 Check if this stream is of a particular type. More...
 
template<typename T >
bool IsType () const
 Check if a this stream is of a particular type. More...
 
const char * TypeToStr () const
 Convert this stream's class type to string. More...
 

Static Public Member Functions

static gstEncoderCreate (const videoOptions &options)
 Create an encoder from the provided video options. More...
 
static gstEncoderCreate (const URI &resource, videoOptions::Codec codec)
 Create an encoder instance from resource URI and codec. More...
 
static bool IsSupportedExtension (const char *ext)
 Return true if the extension is in the list of SupportedExtensions. More...
 
- Static Public Member Functions inherited from videoOutput
static videoOutputCreate (const videoOptions &options)
 Create videoOutput interface from a videoOptions struct that's already been filled out. More...
 
static videoOutputCreate (const char *URI, const videoOptions &options=videoOptions())
 Create videoOutput interface from a resource URI string and optional videoOptions. More...
 
static videoOutputCreate (const char *URI, const commandLine &cmdLine)
 Create videoOutput interface from a resource URI string and parsing command line arguments. More...
 
static videoOutputCreate (const char *URI, const int argc, char **argv)
 Create videoOutput interface from a resource URI string and parsing command line arguments. More...
 
static videoOutputCreate (const int argc, char **argv, int positionArg=-1)
 Create videoOutput interface by parsing command line arguments, including the resource URI. More...
 
static videoOutputCreate (const commandLine &cmdLine, int positionArg=-1)
 Create videoOutput interface by parsing command line arguments, including the resource URI. More...
 
static videoOutputCreateNullOutput ()
 Create videoOutput interface that acts as a NULL output and does nothing with incoming frames. More...
 
static const char * Usage ()
 Usage string for command line arguments to Create() More...
 
static const char * TypeToStr (uint32_t type)
 Convert a class type to a string. More...
 

Static Public Attributes

static const uint32_t Type = (1 << 2)
 Unique type identifier of gstEncoder class. More...
 
static const char * SupportedExtensions []
 String array of supported video file extensions, terminated with a NULL sentinel value. More...
 

Protected Member Functions

 gstEncoder (const videoOptions &options)
 
bool init ()
 
bool initPipeline ()
 
void destroyPipeline ()
 
void checkMsgBus ()
 
bool buildCapsStr ()
 
bool buildLaunchStr ()
 
bool encodeYUV (void *buffer, size_t size)
 
- Protected Member Functions inherited from videoOutput
 videoOutput (const videoOptions &options)
 

Static Protected Member Functions

static void onNeedData (GstElement *pipeline, uint32_t size, void *user_data)
 
static void onEnoughData (GstElement *pipeline, void *user_data)
 
static void onWebsocketMessage (WebRTCPeer *peer, const char *message, size_t message_size, void *user_data)
 

Protected Attributes

GstBus * mBus
 
GstCaps * mBufferCaps
 
GstElement * mAppSrc
 
GstElement * mPipeline
 
bool mNeedData
 
std::string mCapsStr
 
std::string mLaunchStr
 
RingBuffer mBufferYUV
 
RTSPServermRTSPServer
 
WebRTCServermWebRTCServer
 
- Protected Attributes inherited from videoOutput
bool mStreaming
 
videoOptions mOptions
 
std::vector< videoOutput * > mOutputs
 

Detailed Description

Hardware-accelerated video encoder for Jetson using GStreamer.

The encoder can write the encoded video to disk in (MKV, MP4, AVI, FLV), or stream over the network to a remote host via RTP/RTSP using UDP/IP. The supported encoder codecs are H.264, H.265, VP8, VP9, and MJPEG.

Note
gstEncoder implements the videoOutput interface and is intended to be used through that as opposed to directly. videoOutput implements additional command-line parsing of videoOptions to construct instances.
See also
videoOutput

Constructor & Destructor Documentation

◆ ~gstEncoder()

gstEncoder::~gstEncoder ( )

Destructor.

◆ gstEncoder()

gstEncoder::gstEncoder ( const videoOptions options)
protected

Member Function Documentation

◆ buildCapsStr()

bool gstEncoder::buildCapsStr ( )
protected

◆ buildLaunchStr()

bool gstEncoder::buildLaunchStr ( )
protected

◆ checkMsgBus()

void gstEncoder::checkMsgBus ( )
protected

◆ Close()

virtual void gstEncoder::Close ( )
virtual

Close the stream.

See also
videoOutput::Open()

Reimplemented from videoOutput.

◆ Create() [1/2]

static gstEncoder* gstEncoder::Create ( const URI resource,
videoOptions::Codec  codec 
)
static

Create an encoder instance from resource URI and codec.

◆ Create() [2/2]

static gstEncoder* gstEncoder::Create ( const videoOptions options)
static

Create an encoder from the provided video options.

◆ destroyPipeline()

void gstEncoder::destroyPipeline ( )
protected

◆ encodeYUV()

bool gstEncoder::encodeYUV ( void *  buffer,
size_t  size 
)
protected

◆ GetPipeline()

GstPipeline* gstEncoder::GetPipeline ( ) const
inline

Return the GStreamer pipeline object.

◆ GetType()

virtual uint32_t gstEncoder::GetType ( ) const
inlinevirtual

Return the interface type (gstEncoder::Type)

Reimplemented from videoOutput.

◆ GetWebRTCServer()

WebRTCServer* gstEncoder::GetWebRTCServer ( ) const
inline

Return the WebRTC server (only used when the protocol is "webrtc://")

◆ init()

bool gstEncoder::init ( )
protected

◆ initPipeline()

bool gstEncoder::initPipeline ( )
protected

◆ IsSupportedExtension()

static bool gstEncoder::IsSupportedExtension ( const char *  ext)
static

Return true if the extension is in the list of SupportedExtensions.

Parameters
extstring containing the extension to be checked (should not contain leading dot)
See also
SupportedExtensions for the list of supported Video Streaming file extensions.

◆ onEnoughData()

static void gstEncoder::onEnoughData ( GstElement *  pipeline,
void *  user_data 
)
staticprotected

◆ onNeedData()

static void gstEncoder::onNeedData ( GstElement *  pipeline,
uint32_t  size,
void *  user_data 
)
staticprotected

◆ onWebsocketMessage()

static void gstEncoder::onWebsocketMessage ( WebRTCPeer peer,
const char *  message,
size_t  message_size,
void *  user_data 
)
staticprotected

◆ Open()

virtual bool gstEncoder::Open ( )
virtual

Open the stream.

See also
videoOutput::Open()

Reimplemented from videoOutput.

◆ Render() [1/2]

template<typename T >
bool gstEncoder::Render ( T *  image,
uint32_t  width,
uint32_t  height 
)
inline

Encode the next frame.

See also
videoOutput::Render()

◆ Render() [2/2]

virtual bool gstEncoder::Render ( void *  image,
uint32_t  width,
uint32_t  height,
imageFormat  format 
)
virtual

Encode the next frame.

See also
videoOutput::Render()

Reimplemented from videoOutput.

Member Data Documentation

◆ mAppSrc

GstElement* gstEncoder::mAppSrc
protected

◆ mBufferCaps

GstCaps* gstEncoder::mBufferCaps
protected

◆ mBufferYUV

RingBuffer gstEncoder::mBufferYUV
protected

◆ mBus

GstBus* gstEncoder::mBus
protected

◆ mCapsStr

std::string gstEncoder::mCapsStr
protected

◆ mLaunchStr

std::string gstEncoder::mLaunchStr
protected

◆ mNeedData

bool gstEncoder::mNeedData
protected

◆ mPipeline

GstElement* gstEncoder::mPipeline
protected

◆ mRTSPServer

RTSPServer* gstEncoder::mRTSPServer
protected

◆ mWebRTCServer

WebRTCServer* gstEncoder::mWebRTCServer
protected

◆ SupportedExtensions

const char* gstEncoder::SupportedExtensions[]
static

String array of supported video file extensions, terminated with a NULL sentinel value.

The supported extension are:

  • MKV
  • MP4 / QT
  • AVI
  • FLV
See also
IsSupportedExtension() to check a string against this list.

◆ Type

const uint32_t gstEncoder::Type = (1 << 2)
static

Unique type identifier of gstEncoder class.


The documentation for this class was generated from the following file: