Jetson Inference
DNN Vision Library
gstDecoder.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, 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 __GSTREAMER_DECODER_H__
24 #define __GSTREAMER_DECODER_H__
25 
26 #include "gstUtility.h"
27 #include "gstBufferManager.h"
28 
29 #include "videoSource.h"
30 
31 
32 // Forward declarations
33 class WebRTCServer;
34 struct WebRTCPeer;
35 struct _GstAppSink;
36 
37 
52 class gstDecoder : public videoSource
53 {
54 public:
58  static gstDecoder* Create( const videoOptions& options );
59 
63  static gstDecoder* Create( const URI& resource, videoOptions::Codec codec );
64 
68  ~gstDecoder();
69 
74  virtual bool Capture( void** image, imageFormat format, uint64_t timeout=DEFAULT_TIMEOUT, int* status=NULL );
75 
80  virtual bool Open();
81 
86  virtual void Close();
87 
95  inline bool IsEOS() const { return mEOS; }
96 
100  virtual inline uint32_t GetType() const { return Type; }
101 
105  static const uint32_t Type = (1 << 1);
106 
118  static const char* SupportedExtensions[];
119 
125  static bool IsSupportedExtension( const char* ext );
126 
127 protected:
128  gstDecoder( const videoOptions& options );
129 
130  void checkMsgBus();
131  void checkBuffer();
132  bool buildLaunchStr();
133  bool discover();
134 
135  bool init();
136  bool initPipeline();
137  void destroyPipeline();
138 
139  inline bool isLooping() const { return (mOptions.loop < 0) || ((mOptions.loop > 0) && (mLoopCount < mOptions.loop)); }
140 
141  // appsink callbacks
142  static void onEOS(_GstAppSink* sink, void* user_data);
143 
144  static GstFlowReturn onPreroll(_GstAppSink* sink, void* user_data);
145  static GstFlowReturn onBuffer(_GstAppSink* sink, void* user_data);
146 
147  // WebRTC callbacks
148  static void onWebsocketMessage( WebRTCPeer* peer, const char* message, size_t message_size, void* user_data );
149 
150  GstBus* mBus;
151  GstElement* mPipeline;
152  _GstAppSink* mAppSink;
153 
155  std::string mLaunchStr;
158  bool mEOS;
159  size_t mLoopCount;
160 
162 
165 };
166 
167 #endif
videoSource.h
gstDecoder::mAppSink
_GstAppSink * mAppSink
Definition: gstDecoder.h:152
gstDecoder::Capture
virtual bool Capture(void **image, imageFormat format, uint64_t timeout=DEFAULT_TIMEOUT, int *status=NULL)
Capture the next decoded frame.
Event
Event object for signalling other threads.
Definition: Event.h:33
gstDecoder
Hardware-accelerated video decoder for Jetson using GStreamer.
Definition: gstDecoder.h:52
gstDecoder::onBuffer
static GstFlowReturn onBuffer(_GstAppSink *sink, void *user_data)
gstDecoder::mEOS
bool mEOS
Definition: gstDecoder.h:158
gstDecoder::GetType
virtual uint32_t GetType() const
Return the interface type (gstDecoder::Type)
Definition: gstDecoder.h:100
gstDecoder::mCustomSize
bool mCustomSize
Definition: gstDecoder.h:156
gstDecoder::checkBuffer
void checkBuffer()
WebRTCServer
WebRTC signalling server for establishing and negotiating connections with peers for bi-directional m...
Definition: WebRTCServer.h:116
gstDecoder::Close
virtual void Close()
Close the stream.
gstBufferManager
gstBufferManager recieves GStreamer buffers from appsink elements and unpacks/maps them into CUDA add...
Definition: gstBufferManager.h:61
gstDecoder::discover
bool discover()
gstDecoder::Open
virtual bool Open()
Open the stream.
gstDecoder::Create
static gstDecoder * Create(const videoOptions &options)
Create a decoder from the provided video options.
gstDecoder::IsEOS
bool IsEOS() const
Return true if End Of Stream (EOS) has been reached.
Definition: gstDecoder.h:95
gstBufferManager.h
gstDecoder::gstDecoder
gstDecoder(const videoOptions &options)
gstDecoder::IsSupportedExtension
static bool IsSupportedExtension(const char *ext)
Return true if the extension is in the list of SupportedExtensions.
gstDecoder::initPipeline
bool initPipeline()
gstUtility.h
gstDecoder::mLaunchStr
std::string mLaunchStr
Definition: gstDecoder.h:155
gstDecoder::isLooping
bool isLooping() const
Definition: gstDecoder.h:139
videoOptions::Codec
Codec
Video codecs.
Definition: videoOptions.h:198
gstDecoder::SupportedExtensions
static const char * SupportedExtensions[]
String array of supported video file extensions, terminated with a NULL sentinel value.
Definition: gstDecoder.h:118
URI
Resource URI of a video device, IP stream, or file/directory.
Definition: URI.h:101
gstDecoder::mCustomRate
bool mCustomRate
Definition: gstDecoder.h:157
gstDecoder::destroyPipeline
void destroyPipeline()
gstDecoder::onEOS
static void onEOS(_GstAppSink *sink, void *user_data)
gstDecoder::onPreroll
static GstFlowReturn onPreroll(_GstAppSink *sink, void *user_data)
videoOptions::loop
int loop
Control the number of loops for videoSource disk-based inputs (for example, the number of times that ...
Definition: videoOptions.h:119
videoSource::mOptions
videoOptions mOptions
Definition: videoSource.h:378
gstDecoder::onWebsocketMessage
static void onWebsocketMessage(WebRTCPeer *peer, const char *message, size_t message_size, void *user_data)
gstDecoder::mPipeline
GstElement * mPipeline
Definition: gstDecoder.h:151
gstDecoder::init
bool init()
gstDecoder::mLoopCount
size_t mLoopCount
Definition: gstDecoder.h:159
gstDecoder::mBufferManager
gstBufferManager * mBufferManager
Definition: gstDecoder.h:161
gstDecoder::mWebRTCConnected
bool mWebRTCConnected
Definition: gstDecoder.h:164
videoSource::DEFAULT_TIMEOUT
static const uint64_t DEFAULT_TIMEOUT
The default Capture timeout (1000ms)
Definition: videoSource.h:371
gstDecoder::mWaitEvent
Event mWaitEvent
Definition: gstDecoder.h:154
gstDecoder::mBus
GstBus * mBus
Definition: gstDecoder.h:150
gstDecoder::mWebRTCServer
WebRTCServer * mWebRTCServer
Definition: gstDecoder.h:163
gstDecoder::checkMsgBus
void checkMsgBus()
videoOptions
The videoOptions struct contains common settings that are used to configure and query videoSource and...
Definition: videoOptions.h:37
WebRTCPeer
Remote peer that has connected.
Definition: WebRTCServer.h:85
gstDecoder::~gstDecoder
~gstDecoder()
Destructor.
gstDecoder::buildLaunchStr
bool buildLaunchStr()
imageFormat
imageFormat
The imageFormat enum is used to identify the pixel format and colorspace of an image.
Definition: imageFormat.h:49
gstDecoder::Type
static const uint32_t Type
Unique type identifier of gstDecoder class.
Definition: gstDecoder.h:105
videoSource
The videoSource API is for capturing frames from video input devices such as MIPI CSI cameras,...
Definition: videoSource.h:118