Jetson Inference
DNN Vision Library
v4l2Camera.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 __V4L2_CAPTURE_H__
24 #define __V4L2_CAPTURE_H__
25 
26 #include <linux/videodev2.h>
27 
28 #include <stdint.h>
29 #include <string>
30 #include <vector>
31 
32 
33 
42 {
43 public:
48  static v4l2Camera* Create( const char* device_path );
49 
53  ~v4l2Camera();
54 
58  bool Open();
59 
63  bool Close();
64 
68  void* Capture( size_t timeout=0 );
69 
73  inline uint32_t GetWidth() const { return mWidth; }
74 
78  inline uint32_t GetHeight() const { return mHeight; }
79 
83  inline uint32_t GetPitch() const { return mPitch; }
84 
88  inline uint32_t GetPixelDepth() const { return mPixelDepth; }
89 
90 private:
91 
92  v4l2Camera( const char* device_path );
93 
94  bool init();
95  bool initCaps();
96  bool initFormats();
97  bool initStream();
98 
99  bool initUserPtr();
100  bool initMMap();
101 
102  int mFD;
103  int mRequestFormat;
104  uint32_t mRequestWidth;
105  uint32_t mRequestHeight;
106  uint32_t mWidth;
107  uint32_t mHeight;
108  uint32_t mPitch;
109  uint32_t mPixelDepth;
110 
111  struct v4l2_mmap
112  {
113  struct v4l2_buffer buf;
114  void* ptr;
115  };
116 
117  v4l2_mmap* mBuffersMMap;
118  size_t mBufferCountMMap;
119 
120  std::vector<v4l2_fmtdesc> mFormats;
121  std::string mDevicePath;
122 };
123 
124 
125 #endif
126 
127 
v4l2Camera
Video4Linux2 (V4L2) camera capture streaming.
Definition: v4l2Camera.h:41
v4l2Camera::Close
bool Close()
Stop streaming.
v4l2Camera::Capture
void * Capture(size_t timeout=0)
Return the next image.
v4l2Camera::GetPitch
uint32_t GetPitch() const
Return the size in bytes of one line of the image.
Definition: v4l2Camera.h:83
v4l2Camera::GetHeight
uint32_t GetHeight() const
Retrieve height, in pixels, of camera image.
Definition: v4l2Camera.h:78
v4l2Camera::Create
static v4l2Camera * Create(const char *device_path)
Create V4L2 interface.
v4l2Camera::GetWidth
uint32_t GetWidth() const
Get width, in pixels, of camera image.
Definition: v4l2Camera.h:73
v4l2Camera::~v4l2Camera
~v4l2Camera()
Destructor.
v4l2Camera::Open
bool Open()
Start streaming.
v4l2Camera::GetPixelDepth
uint32_t GetPixelDepth() const
Return the bit depth per pixel.
Definition: v4l2Camera.h:88