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 
28 
36 {
37 public:
41  static gstEncoder* Create( gstCodec codec, uint32_t width, uint32_t height, const char* filename );
42 
46  static gstEncoder* Create( gstCodec codec, uint32_t width, uint32_t height, const char* ipAddress, uint16_t port );
47 
51  static gstEncoder* Create( gstCodec codec, uint32_t width, uint32_t height, const char* filename, const char* ipAddress, uint16_t port );
52 
56  ~gstEncoder();
57 
67  bool EncodeRGBA( uint8_t* buffer );
68 
78  bool EncodeRGBA( float* buffer, float maxPixelValue=255.0f );
79 
86  bool EncodeI420( void* buffer, size_t size );
87 
91  inline uint32_t GetWidth() const { return mWidth; }
92 
96  inline uint32_t GetHeight() const { return mHeight; }
97 
98 protected:
99  gstEncoder();
100 
101  bool buildCapsStr();
102  bool buildLaunchStr();
103 
104  bool init( gstCodec codec, uint32_t width, uint32_t height, const char* filename, const char* ipAddress, uint16_t port );
105 
106  static void onNeedData( _GstElement* pipeline, uint32_t size, void* user_data );
107  static void onEnoughData( _GstElement* pipeline, void* user_data );
108 
109  _GstBus* mBus;
110  _GstCaps* mBufferCaps;
111  _GstElement* mAppSrc;
112  _GstElement* mPipeline;
114  bool mNeedData;
115  uint32_t mWidth;
116  uint32_t mHeight;
117 
118  std::string mCapsStr;
119  std::string mLaunchStr;
120  std::string mOutputPath;
121  std::string mOutputIP;
122  uint16_t mOutputPort;
123 
124  // format conversion buffers
125  void* mCpuRGBA;
126  void* mGpuRGBA;
127  void* mCpuI420;
128  void* mGpuI420;
129 };
130 
131 
132 #endif
bool mNeedData
Definition: gstEncoder.h:114
uint32_t GetWidth() const
Retrieve the width that the encoder was created for, in pixels.
Definition: gstEncoder.h:91
bool EncodeI420(void *buffer, size_t size)
Encode the next I420 frame provided by the user.
static void onEnoughData(_GstElement *pipeline, void *user_data)
std::string mOutputIP
Definition: gstEncoder.h:121
~gstEncoder()
Destructor.
bool buildLaunchStr()
_GstBus * mBus
Definition: gstEncoder.h:109
std::string mLaunchStr
Definition: gstEncoder.h:119
uint32_t mHeight
Definition: gstEncoder.h:116
_GstElement * mAppSrc
Definition: gstEncoder.h:111
void * mGpuRGBA
Definition: gstEncoder.h:126
uint16_t mOutputPort
Definition: gstEncoder.h:122
std::string mOutputPath
Definition: gstEncoder.h:120
Hardware-accelerated H.264/H.265 video encoder for Jetson using GStreamer.
Definition: gstEncoder.h:35
gstCodec
Video codec (H.264/H.265) enumeration.
Definition: gstUtility.h:34
void * mGpuI420
Definition: gstEncoder.h:128
static void onNeedData(_GstElement *pipeline, uint32_t size, void *user_data)
_GstElement * mPipeline
Definition: gstEncoder.h:112
void * mCpuRGBA
Definition: gstEncoder.h:125
bool init(gstCodec codec, uint32_t width, uint32_t height, const char *filename, const char *ipAddress, uint16_t port)
bool buildCapsStr()
std::string mCapsStr
Definition: gstEncoder.h:118
_GstCaps * mBufferCaps
Definition: gstEncoder.h:110
void * mCpuI420
Definition: gstEncoder.h:127
bool EncodeRGBA(uint8_t *buffer)
Encode the next fixed-point RGBA frame.
uint32_t mWidth
Definition: gstEncoder.h:115
uint32_t GetHeight() const
Retrieve the height that the encoder was created for, in pixels.
Definition: gstEncoder.h:96
static gstEncoder * Create(gstCodec codec, uint32_t width, uint32_t height, const char *filename)
Create an encoder instance that outputs to a file on disk.
gstCodec mCodec
Definition: gstEncoder.h:113