1
#define _IPECAMERA_IMAGE_C
13
#include <ufodecode.h>
23
int ipecamera_stream(pcilib_context_t *vctx, pcilib_event_callback_t callback, void *user) {
27
ipecamera_event_info_t info;
28
ipecamera_t *ctx = (ipecamera_t*)vctx;
31
pcilib_error("IPECamera imaging is not initialized");
32
return PCILIB_ERROR_NOTINITIALIZED;
36
ctx->run_streamer = 1;
39
err = ipecamera_start(vctx, PCILIB_EVENTS_ALL, PCILIB_EVENT_FLAGS_DEFAULT);
48
// This loop iterates while the generation
49
while ((ctx->run_streamer)||(ctx->reported_id != ctx->event_id)) {
50
while (ctx->reported_id != ctx->event_id) {
51
if ((ctx->event_id - ctx->reported_id) > (ctx->buffer_size - IPECAMERA_RESERVE_BUFFERS)) ctx->reported_id = ctx->event_id - (ctx->buffer_size - 1) - IPECAMERA_RESERVE_BUFFERS;
52
else ++ctx->reported_id;
54
memcpy(&info, ctx->frame + ((ctx->reported_id-1)%ctx->buffer_size), sizeof(ipecamera_event_info_t));
56
if ((ctx->event_id - ctx->reported_id) < ctx->buffer_size) {
57
err = callback(ctx->reported_id, (pcilib_event_info_t*)&info, user);
59
if (err < 0) err = -err;
64
usleep(IPECAMERA_NOFRAME_SLEEP);
70
ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
77
int ipecamera_next_event(pcilib_context_t *vctx, pcilib_timeout_t timeout, pcilib_event_id_t *evid, size_t info_size, pcilib_event_info_t *info) {
79
ipecamera_t *ctx = (ipecamera_t*)vctx;
82
pcilib_error("IPECamera imaging is not initialized");
83
return PCILIB_ERROR_NOTINITIALIZED;
87
pcilib_error("IPECamera is not in grabbing mode");
88
return PCILIB_ERROR_INVALID_REQUEST;
91
if (ctx->reported_id == ctx->event_id) {
93
pcilib_calc_deadline(&tv, timeout);
95
while ((pcilib_calc_time_to_deadline(&tv) > 0)&&(ctx->reported_id == ctx->event_id))
96
usleep(IPECAMERA_NOFRAME_SLEEP);
99
if (ctx->reported_id == ctx->event_id) return PCILIB_ERROR_TIMEOUT;
103
if ((ctx->event_id - ctx->reported_id) > (ctx->buffer_size - IPECAMERA_RESERVE_BUFFERS)) ctx->reported_id = ctx->event_id - (ctx->buffer_size - 1) - IPECAMERA_RESERVE_BUFFERS;
104
else ++ctx->reported_id;
106
if (evid) *evid = ctx->reported_id;
109
if (info_size >= sizeof(ipecamera_event_info_t))
110
memcpy(info, ctx->frame + ((ctx->reported_id-1)%ctx->buffer_size), sizeof(ipecamera_event_info_t));
111
else if (info_size >= sizeof(pcilib_event_info_t))
112
memcpy(info, ctx->frame + ((ctx->reported_id-1)%ctx->buffer_size), sizeof(pcilib_event_info_t));
114
return PCILIB_ERROR_INVALID_ARGUMENT;
117
if ((ctx->event_id - ctx->reported_id) >= ctx->buffer_size) goto retry;