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