forked from lit-robotics/libcamera-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.cpp
134 lines (102 loc) · 4.06 KB
/
camera.cpp
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "camera.h"
extern "C" {
void libcamera_camera_configuration_destroy(libcamera_camera_configuration_t* config) {
delete config;
}
size_t libcamera_camera_configuration_size(const libcamera_camera_configuration_t* config) {
return config->size();
}
libcamera_stream_configuration_t *libcamera_camera_configuration_at(libcamera_camera_configuration_t* config, size_t index) {
if (config->size() > index) {
return &config->at(index);
} else {
return nullptr;
}
}
libcamera_camera_configuration_status_t libcamera_camera_configuration_validate(libcamera_camera_configuration_t* config) {
return config->validate();
}
void libcamera_camera_configuration_clear_sensor_config(libcamera_camera_configuration_t* config) {
config->sensorConfig.reset();
}
void libcamera_camera_configuration_set_sensor_config(
libcamera_camera_configuration_t* config,
const libcamera_sensor_configuration_t* sensor_config
) {
config->sensorConfig = *sensor_config;
}
libcamera_sensor_configuration_t* libcamera_sensor_configuration_new() {
return new libcamera_sensor_configuration_t();
}
void libcamera_sensor_configuration_set_size(
libcamera_sensor_configuration_t* config,
unsigned int width, unsigned int height
) {
config->outputSize.width = width;
config->outputSize.height = height;
}
void libcamera_sensor_configuration_set_bit_depth(
libcamera_sensor_configuration_t* config,
unsigned int bit_depth
) {
config->bitDepth = bit_depth;
}
bool libcamera_sensor_configuration_validate(const libcamera_sensor_configuration_t* config) {
return config->isValid();
}
void libcamera_sensor_configuration_destroy(libcamera_sensor_configuration_t* config) {
delete config;
}
libcamera_camera_t* libcamera_camera_copy(libcamera_camera_t *cam) {
const libcamera_camera_t& ptr = *cam;
return new libcamera_camera_t(ptr);
}
void libcamera_camera_destroy(libcamera_camera_t *cam) {
delete cam;
}
const char *libcamera_camera_id(const libcamera_camera_t *cam) {
return cam->get()->id().c_str();
}
libcamera_callback_handle_t *libcamera_camera_request_completed_connect(libcamera_camera_t *cam, libcamera_request_completed_cb_t *callback, void *data) {
libcamera_callback_handle_t *handle = new libcamera_callback_handle_t {};
cam->get()->requestCompleted.connect(handle, [=](libcamera::Request *request) {
callback(data, request);
});
return handle;
}
void libcamera_camera_request_completed_disconnect(libcamera_camera_t *cam, libcamera_callback_handle_t *handle) {
cam->get()->requestCompleted.disconnect(handle);
delete handle;
}
int libcamera_camera_acquire(libcamera_camera_t *cam) {
return cam->get()->acquire();
}
int libcamera_camera_release(libcamera_camera_t *cam) {
return cam->get()->release();
}
const libcamera_control_info_map_t *libcamera_camera_controls(const libcamera_camera_t *cam) {
return &cam->get()->controls();
}
const libcamera_control_list_t *libcamera_camera_properties(const libcamera_camera_t *cam) {
return &cam->get()->properties();
}
libcamera_camera_configuration_t *libcamera_camera_generate_configuration(libcamera_camera_t *cam, const enum libcamera_stream_role *roles, size_t role_count) {
std::vector<libcamera::StreamRole> roles_vec((libcamera::StreamRole*)roles, (libcamera::StreamRole*)roles + role_count);
return cam->get()->generateConfiguration(roles_vec).release();
}
int libcamera_camera_configure(libcamera_camera_t *cam, libcamera_camera_configuration_t *config) {
return cam->get()->configure(config);
}
libcamera_request_t *libcamera_camera_create_request(libcamera_camera_t *cam, uint64_t cookie) {
return cam->get()->createRequest(cookie).release();
}
int libcamera_camera_queue_request(libcamera_camera_t *cam, libcamera_request_t *request) {
return cam->get()->queueRequest(request);
}
int libcamera_camera_start(libcamera_camera_t *cam, const libcamera_control_list_t *controls) {
return cam->get()->start(controls);
}
int libcamera_camera_stop(libcamera_camera_t *cam) {
return cam->get()->stop();
}
}