forked from Hermann-SW/fork-raspiraw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraspiCam.cpp
104 lines (94 loc) · 2.92 KB
/
raspiCam.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
//
// Created by falcon on 31/03/2020.
//
#include "raspiCam.h"
raspiCam::raspiCam() {
}
raspiCam::~raspiCam() {
}
void raspiCam::callback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer) {
static int count = 0;
vcos_log_error("Buffer %p returned, filled %d, timestamp %llu, flags %04X", buffer, buffer->length, buffer->pts,
buffer->flags);
int running = 1;
if (running) {
RASPIRAW_PARAMS_T *cfg = (RASPIRAW_PARAMS_T *) port->userdata;
if (!(buffer->flags & MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO)) {
// // Save every Nth frame
// // SD card access is too slow to do much more.
// FILE *file;
// char *filename = NULL;
// if (create_filenames(&filename, cfg->output, count) == MMAL_SUCCESS)
// {
// file = fopen(filename, "wb");
// if (file)
// {
// if (cfg->ptso) // make sure previous malloc() was successful
// {
// cfg->ptso->idx = count;
// cfg->ptso->pts = buffer->pts;
// cfg->ptso->nxt = malloc(sizeof(*cfg->ptso->nxt));
// cfg->ptso = cfg->ptso->nxt;
// }
// if (!cfg->write_empty)
// {
// if (cfg->write_header)
// fwrite(brcm_header, BRCM_RAW_HEADER_LENGTH, 1, file);
// fwrite(buffer->data, buffer->length, 1, file);
// }
// fclose(file);
// }
// free(filename);
// }
// Yeet every frame via ZeroMQ
// TODO: do zmq send here!
}
buffer->length = 0;
mmal_port_send_buffer(port, buffer);
} else {
mmal_buffer_header_release(buffer);
}
}
int raspiCam::start() {
RASPIRAW_PARAMS_T cfg = {
mode: 0,
hflip: 0,
vflip: 0,
exposure: -1,
gain: -1,
output: NULL,
capture: 0,
write_header: 0,
timeout: 5000,
saverate: 1,
bit_depth: -1,
camera_num: -1,
exposure_us: -1,
i2c_bus: DEFAULT_I2C_DEVICE,
awb_gains_r: 0.0,
awb_gains_b: 0.0,
regs: NULL,
hinc: -1,
vinc: -1,
voinc: -1,
hoinc: -1,
bin44: 0,
fps: 500,
width: -1,
height: -1,
left: -1,
top: -1,
write_header0: NULL,
write_headerg: NULL,
write_timestamps: NULL,
write_empty: 0,
ptsa: NULL,
ptso: NULL,
};
return camera_main(cfg, &(raspiCam::callback));
}
int main() {
raspiCam* camObject = new raspiCam();
camObject->start();
delete camObject;
}