-
Notifications
You must be signed in to change notification settings - Fork 0
/
V4L2Camera.h
89 lines (65 loc) · 2.49 KB
/
V4L2Camera.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*/
#ifndef _V4L2CAMERA_H
#define _V4L2CAMERA_H
#define NB_BUFFER 4
#include <binder/MemoryBase.h>
#include <binder/MemoryHeapBase.h>
#include <utils/SortedVector.h>
#include "uvc_compat.h"
#include "SurfaceDesc.h"
namespace android {
struct vdIn {
struct v4l2_capability cap;
struct v4l2_format format; // Capture format being used
struct v4l2_buffer buf;
struct v4l2_requestbuffers rb;
struct v4l2_streamparm params; // v4l2 stream parameters struct
struct v4l2_jpegcompression jpegcomp; // v4l2 jpeg compression settings
void *mem[NB_BUFFER];
bool isStreaming;
void* tmpBuffer;
int outWidth; // Requested Output width
int outHeight; // Requested Output height
int outFrameSize; // The expected output framesize (in YUYV)
int capBytesPerPixel; // Capture bytes per pixel
int capCropOffset; // The offset in bytes to add to the captured buffer to get to the first pixel
};
class V4L2Camera {
public:
V4L2Camera();
~V4L2Camera();
int Open (const char *device);
void Close ();
int Init (int width, int height, int fps);
void Uninit ();
int StartStreaming ();
int StopStreaming ();
void GrabRawFrame (void *frameBuffer,int maxSize);
void getSize(int& width, int& height) const;
int getFps() const;
SortedVector<SurfaceSize> getAvailableSizes() const;
SortedVector<int> getAvailableFps() const;
const SurfaceDesc& getBestPreviewFmt() const;
const SurfaceDesc& getBestPictureFmt() const;
private:
bool EnumFrameIntervals(int pixfmt, int width, int height);
bool EnumFrameSizes(int pixfmt);
bool EnumFrameFormats();
int saveYUYVtoJPEG(uint8_t* src, uint8_t* dst, int maxsize, int width, int height, int quality);
private:
struct vdIn *videoIn;
int fd;
int nQueued;
int nDequeued;
SortedVector<SurfaceDesc> m_AllFmts; // Available video modes
SurfaceDesc m_BestPreviewFmt; // Best preview mode. maximum fps with biggest frame
SurfaceDesc m_BestPictureFmt; // Best picture format. maximum size
};
}; // namespace android
#endif