-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathv4l2capture.h
executable file
·68 lines (57 loc) · 1.32 KB
/
v4l2capture.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef V4L2CAPTURE_H
#define V4L2CAPTURE_H
extern "C"
{
#include <linux/videodev2.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
}
#include <string>
#include <vector>
#define V4L2_BUFFER_NUM 6
class V4l2Capture
{
public:
struct CapBuffers {
void *start;
size_t offset;
size_t length;
};
enum PixFormat {
UYVY = V4L2_PIX_FMT_UYVY,
RGB565 = V4L2_PIX_FMT_RGB565,
YUYV = V4L2_PIX_FMT_YUYV
};
struct ImgFormat {
uint height;
uint width;
PixFormat pixFmt;
};
V4l2Capture();
V4l2Capture(std::string &fileName, const ImgFormat &ImgFmt);
V4l2Capture(int index, const ImgFormat &ImgFmt);
~V4l2Capture();
int open(std::string &fileName, const ImgFormat &ImgFmt);
int open(int index, const ImgFormat &ImgFmt);
bool isOpened() const;
int startCapturing();
void stopCapturing();
int getFrame(CapBuffers **ppbuf);
int doneFrame();
void printSupportFormat();
private:
void init();
int initDevice(const ImgFormat &ImgFmt);
void deinitDevice();
void release();
int fd_cap_v4l;
std::vector<CapBuffers> buffers;
struct v4l2_buffer v4lBuf;
};
#endif // V4L2CAPTURE_H