Skip to content

Commit

Permalink
added extern C for old headers
Browse files Browse the repository at this point in the history
  • Loading branch information
blondejamtart committed Apr 6, 2020
1 parent 4b8d591 commit bdec741
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 121 deletions.
110 changes: 77 additions & 33 deletions raspiCam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,83 @@ raspiCam::~raspiCam() {

}

static 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);
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 = 20,
.bit_depth = -1,
.camera_num = -1,
.exposure_us = -1,
.i2c_bus = DEFAULT_I2C_DEVICE,
.regs = NULL,
.hinc = -1,
.vinc = -1,
.voinc = -1,
.hoinc = -1,
.bin44 = 0,
.fps = -1,
.width = -1,
.height = -1,
.left = -1,
.top = -1,
.write_header0 = NULL,
.write_headerg = NULL,
.write_timestamps = NULL,
.write_empty = 0,
.ptsa = NULL,
.ptso = NULL,
RASPIRAW_PARAMS_T cfg = {
mode: 0,
hflip: 0,
vflip: 0,
exposure: -1,
gain: -1,
output: NULL,
capture: 0,
write_header: 0,
timeout: 5000,
saverate: 20,
bit_depth: -1,
camera_num: -1,
exposure_us: -1,
i2c_bus: DEFAULT_I2C_DEVICE,
regs: NULL,
hinc: -1,
vinc: -1,
voinc: -1,
hoinc: -1,
bin44: 0,
fps: -1,
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);
return camera_main(cfg, &(this->callback));
}
36 changes: 1 addition & 35 deletions raspiCam.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,14 @@

#include "raspiraw.h"

// RASPIRAW_PARAMS_T cfg = {
// .mode = 0,
// .hflip = 0,
// .vflip = 0,
// .exposure = -1,
// .gain = -1,
// .output = NULL,
// .capture = 0,
// .write_header = 0,
// .timeout = 5000,
// .saverate = 20,
// .bit_depth = -1,
// .camera_num = -1,
// .exposure_us = -1,
// .i2c_bus = DEFAULT_I2C_DEVICE,
// .regs = NULL,
// .hinc = -1,
// .vinc = -1,
// .voinc = -1,
// .hoinc = -1,
// .bin44 = 0,
// .fps = -1,
// .width = -1,
// .height = -1,
// .left = -1,
// .top = -1,
// .write_header0 = NULL,
// .write_headerg = NULL,
// .write_timestamps = NULL,
// .write_empty = 0,
// .ptsa = NULL,
// .ptso = NULL,
// };


class raspiCam {
public:
raspiCam();
~raspiCam();

private:
int start();
virtual void callback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
};

#endif //FORK_RASPIRAW_RASPICAM_H
Expand Down
51 changes: 3 additions & 48 deletions raspiraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <zmq.h>

#include "raspiraw.h"

static char i2c_device_name[I2C_DEVICE_NAME_LEN];
Expand Down Expand Up @@ -220,53 +222,6 @@ MMAL_STATUS_T create_filenames(char **finalName, char *pattern, int frame)

int running = 0;

static void 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);
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);
}

uint32_t order_and_bit_depth_to_encoding(enum bayer_order order, int bit_depth)
{
//BAYER_ORDER_BGGR,
Expand Down Expand Up @@ -318,7 +273,7 @@ uint32_t order_and_bit_depth_to_encoding(enum bayer_order order, int bit_depth)
return 0;
}

int camera_main(RASPIRAW_PARAMS_T cfg)
int camera_main(RASPIRAW_PARAMS_T cfg, void (*callback)())
{
// RASPIRAW_PARAMS_T cfg = {
// .mode = 0,
Expand Down
12 changes: 7 additions & 5 deletions raspiraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ enum bayer_order
{
//Carefully ordered so that an hflip is ^1,
//and a vflip is ^2.
BAYER_ORDER_BGGR,
BAYER_ORDER_BGGR,
BAYER_ORDER_GBRG,
BAYER_ORDER_GRBG,
BAYER_ORDER_RGGB
Expand Down Expand Up @@ -152,9 +152,11 @@ struct sensor_def

#define NUM_ELEMENTS(a) (sizeof(a) / sizeof(a[0]))

#include "ov5647_modes.h"
#include "imx219_modes.h"
#include "adv7282m_modes.h"
extern "C" {
#include "ov5647_modes.h"
#include "imx219_modes.h"
#include "adv7282m_modes.h"
}

const struct sensor_def *sensors[] = {
&ov5647,
Expand Down Expand Up @@ -271,7 +273,7 @@ uint32_t order_and_bit_depth_to_encoding(enum bayer_order order, int bit_depth);

void modReg(struct mode_def *mode, uint16_t reg, int startBit, int endBit, int value, enum operation op);

int camera_main(RASPIRAW_PARAMS_T cfg);
int camera_main(RASPIRAW_PARAMS_T cfg, void (*callback)());

void modRegBit(struct mode_def *mode, uint16_t reg, int bit, int value, enum operation op);

Expand Down

0 comments on commit bdec741

Please sign in to comment.