-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathV4l2Device.h
More file actions
96 lines (74 loc) · 2.15 KB
/
Copy pathV4l2Device.h
File metadata and controls
96 lines (74 loc) · 2.15 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef V4L2DEVICE_H
#define V4L2DEVICE_H
#include <linux/videodev2.h>
#include <sys/poll.h>
#include <stdint.h>
#include <utils/Vector.h>
#include <utils/Log.h>
#include <utils/Mutex.h>
#include <utils/Timers.h>
#ifndef V4L2DEVICE_BUF_COUNT
# define V4L2DEVICE_BUF_COUNT 4
#endif
#ifndef V4L2DEVICE_PIXEL_FORMAT
# warning V4L2DEVICE_PIXEL_FORMAT not defined, using default value (V4L2_PIX_FMT_UYVY)
# define V4L2DEVICE_PIXEL_FORMAT V4L2_PIX_FMT_UYVY
#endif
namespace android {
class V4l2Device
{
public:
struct Resolution {
unsigned width;
unsigned height;
};
class VBuffer {
public:
uint8_t *buf;
uint32_t len;
uint32_t pixFmt;
private:
VBuffer(): buf(NULL), len(0) {}
~VBuffer();
bool map(int fd, unsigned offset, unsigned len);
void unmap();
friend class V4l2Device;
};
V4l2Device(const char *devNode = "/dev/video0");
~V4l2Device();
const Vector<V4l2Device::Resolution> & availableResolutions();
V4l2Device::Resolution sensorResolution();
bool setResolution(unsigned width, unsigned height);
V4l2Device::Resolution resolution();
bool connect();
bool disconnect();
bool isConnected() const { return mFd >= 0; }
bool setStreaming(bool enable);
bool isStreaming() const { return mStreaming; }
const VBuffer * readLock();
bool unlock(const VBuffer *buf);
private:
bool queueBuffer(unsigned id);
int dequeueBuffer();
bool iocStreamOff();
bool iocStreamOn();
bool iocSFmt(unsigned width, unsigned height);
bool iocReqBufs(unsigned *count);
bool iocQueryBuf(unsigned id, unsigned *offset, unsigned *len);
bool setResolutionAndAllocateBuffers(unsigned width, unsigned height);
void cleanup();
int mFd;
bool mConnected;
bool mStreaming;
const char *mDevNode;
Vector<V4l2Device::Resolution> mAvailableResolutions;
V4l2Device::Resolution mForcedResolution;
struct v4l2_format mFormat;
VBuffer mBuf[V4L2DEVICE_BUF_COUNT];
struct pollfd mPFd;
#if V4L2DEVICE_FPS_LIMIT > 0
nsecs_t mLastTimestamp;
#endif
};
}; /* namespace android */
#endif // V4L2DEVICE_H