Jetson Inference
DNN Vision Library
gstCamera.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, 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_CAMERA_H__
24 #define __GSTREAMER_CAMERA_H__
25 
26 #include <gst/gst.h>
27 #include <string>
28 
29 #include "videoSource.h"
30 #include "gstBufferManager.h"
31 
32 
33 // Forward declarations
34 struct _GstAppSink;
35 
36 
57 class gstCamera : public videoSource
58 {
59 public:
63  static gstCamera* Create( const videoOptions& options );
64 
83  static gstCamera* Create( const char* camera=NULL ); // use MIPI CSI camera by default
84 
106  static gstCamera* Create( uint32_t width, uint32_t height, const char* camera=NULL );
107 
112  ~gstCamera();
113 
124  virtual bool Open();
125 
132  virtual void Close();
133 
138  virtual bool Capture( void** image, imageFormat format, uint64_t timeout=DEFAULT_TIMEOUT, int* status=NULL );
139 
173  bool CaptureRGBA( float** image, uint64_t timeout=DEFAULT_TIMEOUT, bool zeroCopy=false );
174 
179  void SetZeroCopy(bool zeroCopy) { mOptions.zeroCopy = zeroCopy; }
180 
184  virtual inline uint32_t GetType() const { return Type; }
185 
189  static const uint32_t Type = (1 << 0);
190 
194  static const uint32_t DefaultWidth = 1280;
195 
199  static const uint32_t DefaultHeight = 720;
200 
201 private:
202  static void onEOS(_GstAppSink* sink, void* user_data);
203  static GstFlowReturn onPreroll(_GstAppSink* sink, void* user_data);
204  static GstFlowReturn onBuffer(_GstAppSink* sink, void* user_data);
205 
206  gstCamera( const videoOptions& options );
207 
208  bool init();
209  bool discover();
210  bool buildLaunchStr();
211 
212  void checkMsgBus();
213  void checkBuffer();
214 
215  bool matchCaps( GstCaps* caps );
216  bool printCaps( GstCaps* caps );
217  bool parseCaps( GstStructure* caps, videoOptions::Codec* codec, imageFormat* format, uint32_t* width, uint32_t* height, float* frameRate );
218 
219  _GstBus* mBus;
220  _GstAppSink* mAppSink;
221  _GstElement* mPipeline;
222 
223  std::string mLaunchStr;
224  imageFormat mFormatYUV;
225 
226  gstBufferManager* mBufferManager;
227 };
228 
229 #endif
videoSource.h
gstCamera::CaptureRGBA
bool CaptureRGBA(float **image, uint64_t timeout=DEFAULT_TIMEOUT, bool zeroCopy=false)
Capture the next image frame from the camera and convert it to float4 RGBA format,...
gstCamera::Close
virtual void Close()
Stop streaming the camera.
gstCamera::Create
static gstCamera * Create(const videoOptions &options)
Create a MIPI CSI or V4L2 camera device.
gstBufferManager
gstBufferManager recieves GStreamer buffers from appsink elements and unpacks/maps them into CUDA add...
Definition: gstBufferManager.h:61
gstCamera
MIPI CSI and V4L2 camera capture using GStreamer and nvarguscamerasrc or v4l2src elements.
Definition: gstCamera.h:57
gstCamera::SetZeroCopy
void SetZeroCopy(bool zeroCopy)
Set whether converted RGB(A) images should use ZeroCopy buffer allocation.
Definition: gstCamera.h:179
gstBufferManager.h
gstCamera::DefaultWidth
static const uint32_t DefaultWidth
Default camera width, unless otherwise specified during Create()
Definition: gstCamera.h:194
videoOptions::Codec
Codec
Video codecs.
Definition: videoOptions.h:198
gstCamera::~gstCamera
~gstCamera()
Release the camera interface and resources.
gstCamera::Capture
virtual bool Capture(void **image, imageFormat format, uint64_t timeout=DEFAULT_TIMEOUT, int *status=NULL)
Capture the next image frame from the camera.
videoSource::mOptions
videoOptions mOptions
Definition: videoSource.h:378
videoOptions::zeroCopy
bool zeroCopy
If true, indicates the buffers are allocated in zeroCopy memory that is mapped to both the CPU and GP...
Definition: videoOptions.h:104
gstCamera::GetType
virtual uint32_t GetType() const
Return the interface type (gstCamera::Type)
Definition: gstCamera.h:184
videoSource::DEFAULT_TIMEOUT
static const uint64_t DEFAULT_TIMEOUT
The default Capture timeout (1000ms)
Definition: videoSource.h:371
gstCamera::DefaultHeight
static const uint32_t DefaultHeight
Default camera height, unless otherwise specified during Create()
Definition: gstCamera.h:199
videoOptions
The videoOptions struct contains common settings that are used to configure and query videoSource and...
Definition: videoOptions.h:37
gstCamera::Open
virtual bool Open()
Begin streaming the camera.
gstCamera::Type
static const uint32_t Type
Unique type identifier of gstCamera class.
Definition: gstCamera.h:189
imageFormat
imageFormat
The imageFormat enum is used to identify the pixel format and colorspace of an image.
Definition: imageFormat.h:49
videoSource
The videoSource API is for capturing frames from video input devices such as MIPI CSI cameras,...
Definition: videoSource.h:118