forked from PhotonVision/photon-libcamera-gl-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera_grabber.h
63 lines (48 loc) · 1.84 KB
/
camera_grabber.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
#pragma once
#include <libcamera/camera.h>
#include <libcamera/framebuffer_allocator.h>
#include "camera_model.h"
#include <functional>
#include <memory>
#include <optional>
struct CameraSettings {
int32_t exposureTimeUs = 10000;
float analogGain = 2;
float brightness = 0.0;
float contrast = 1;
float awbRedGain = 1.5;
float awbBlueGain = 1.5;
float saturation = 1;
bool doAutoExposure = false;
// float digitalGain = 100;
};
class CameraGrabber {
public:
explicit CameraGrabber(std::shared_ptr<libcamera::Camera> camera, int width,
int height, int rotation);
~CameraGrabber();
const libcamera::StreamConfiguration &streamConfiguration();
void setOnData(std::function<void(libcamera::Request *)> onData);
void resetOnData();
inline const CameraModel model() { return m_model; }
inline CameraSettings &cameraSettings() { return m_settings; }
// Note: these 3 functions must be protected by mutual exclusion.
// Failure to do so will result in UB.
void startAndQueue();
void stop();
void requeueRequest(libcamera::Request *request);
private:
void requestComplete(libcamera::Request *request);
// The `FrameBufferAllocator` must be first here as it must be
// destroyed last, or else we get fun UAFs for some reason...
libcamera::FrameBufferAllocator m_buf_allocator;
std::vector<std::unique_ptr<libcamera::Request>> m_requests;
std::shared_ptr<libcamera::Camera> m_camera;
CameraModel m_model;
std::optional<std::array<libcamera::ControlValue, 4>> m_cameraExposureProfiles;
std::unique_ptr<libcamera::CameraConfiguration> m_config;
std::optional<std::function<void(libcamera::Request *)>> m_onData;
CameraSettings m_settings{};
bool running = false;
void setControls(libcamera::Request *request);
};