docs/html/gstEncoder_8h_source.html
| | Jetson Inference
DNN Vision Library |
gstEncoder.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_ENCODER_H__
24 #define __GSTREAMER_ENCODER_H__
25
26 #include "gstUtility.h"
27 #include "videoOutput.h"
28 #include "RingBuffer.h"
29
30
31 // Forward declarations
32 class RTSPServer;
33 class WebRTCServer;
34 struct WebRTCPeer;
35
36
51 class gstEncoder : public videoOutput
52 {
53 public:
57static gstEncoder* Create( const videoOptions& options );
58
62static gstEncoder* Create( const URI& resource, videoOptions::Codec codec );
63
67~gstEncoder();
68
73template<typename T> bool Render( T* image, uint32_t width, uint32_t height ) { return Render((void**)image, width, height, imageFormatFromType<T>()); }
74
79virtual bool Render( void* image, uint32_t width, uint32_t height, imageFormat format );
80
85virtual bool Open();
86
91virtual void Close();
92
96inline GstPipeline* GetPipeline() const { return GST_PIPELINE(mPipeline); }
97
101inline WebRTCServer* GetWebRTCServer() const { return mWebRTCServer; }
102
106virtual inline uint32_t GetType() const { return Type; }
107
111static const uint32_t Type = (1 << 2);
112
124static const char* SupportedExtensions[];
125
131static bool IsSupportedExtension( const char* ext );
132
133 protected:
134gstEncoder( const videoOptions& options );
135
136bool init();
137bool initPipeline();
138void destroyPipeline();
139
140void checkMsgBus();
141bool buildCapsStr();
142bool buildLaunchStr();
143bool encodeYUV( void* buffer, size_t size );
144
145// appsrc callbacks
146static void onNeedData( GstElement* pipeline, uint32_t size, void* user_data );
147static void onEnoughData( GstElement* pipeline, void* user_data );
148
149// WebRTC callbacks
150static void onWebsocketMessage( WebRTCPeer* peer, const char* message, size_t message_size, void* user_data );
151
153 GstCaps* mBufferCaps;
157
159 std::string mLaunchStr;
160
162
164WebRTCServer* mWebRTCServer;
165 };
166
167
168 #endif
bool buildCapsStr()
static void onEnoughData(GstElement *pipeline, void *user_data)
std::string mLaunchStr
Definition: gstEncoder.h:159
RTSP server for transmitting encoded GStreamer pipelines to client devices.
Definition: RTSPServer.h:55
gstEncoder::SupportedExtensions
static const char * SupportedExtensions[]
String array of supported video file extensions, terminated with a NULL sentinel value.
Definition: gstEncoder.h:124
RingBuffer mBufferYUV
Definition: gstEncoder.h:161
void destroyPipeline()
static const uint32_t Type
Unique type identifier of gstEncoder class.
Definition: gstEncoder.h:111
virtual bool Open()
Open the stream.
bool initPipeline()
GstBus * mBus
Definition: gstEncoder.h:152
WebRTC signalling server for establishing and negotiating connections with peers for bi-directional m...
Definition: WebRTCServer.h:116
GstElement * mPipeline
Definition: gstEncoder.h:155
WebRTCServer * GetWebRTCServer() const
Return the WebRTC server (only used when the protocol is "webrtc://")
Definition: gstEncoder.h:101
static gstEncoder * Create(const videoOptions &options)
Create an encoder from the provided video options.
GstCaps * mBufferCaps
Definition: gstEncoder.h:153
bool init()
virtual uint32_t GetType() const
Return the interface type (gstEncoder::Type)
Definition: gstEncoder.h:106
GstElement * mAppSrc
Definition: gstEncoder.h:154
Codec
Video codecs.
Definition: videoOptions.h:198
virtual void Close()
Close the stream.
bool encodeYUV(void *buffer, size_t size)
Resource URI of a video device, IP stream, or file/directory.
Definition: URI.h:101
bool buildLaunchStr()
gstEncoder::onWebsocketMessage
static void onWebsocketMessage(WebRTCPeer *peer, const char *message, size_t message_size, void *user_data)
std::string mCapsStr
Definition: gstEncoder.h:158
~gstEncoder()
Destructor.
gstEncoder::IsSupportedExtension
static bool IsSupportedExtension(const char *ext)
Return true if the extension is in the list of SupportedExtensions.
bool Render(T *image, uint32_t width, uint32_t height)
Encode the next frame.
Definition: gstEncoder.h:73
Thread-safe circular ring buffer queue.
Definition: RingBuffer.h:33
GstPipeline * GetPipeline() const
Return the GStreamer pipeline object.
Definition: gstEncoder.h:96
gstEncoder(const videoOptions &options)
The videoOutput API is for rendering and transmitting frames to video input devices such as display w...
Definition: videoOutput.h:104
RTSPServer * mRTSPServer
Definition: gstEncoder.h:163
bool mNeedData
Definition: gstEncoder.h:156
The videoOptions struct contains common settings that are used to configure and query videoSource and...
Definition: videoOptions.h:37
void checkMsgBus()
Remote peer that has connected.
Definition: WebRTCServer.h:85
WebRTCServer * mWebRTCServer
Definition: gstEncoder.h:164
imageFormat
The imageFormat enum is used to identify the pixel format and colorspace of an image.
Definition: imageFormat.h:49
static void onNeedData(GstElement *pipeline, uint32_t size, void *user_data)
Hardware-accelerated video encoder for Jetson using GStreamer.
Definition: gstEncoder.h:51