12
#include <ufodecode.h>
22
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
if (ctx->parse_data) {
49
// This loop iterates while the generation
50
while ((run_flag)&&((ctx->run_streamer)||(ctx->reported_id != ctx->event_id))) {
51
#ifdef IPECAMERA_ANNOUNCE_READY
52
while (((!ctx->preproc)&&(ctx->reported_id != ctx->event_id))||((ctx->preproc)&&(ctx->reported_id != ctx->preproc_id))) {
53
#else /* IPECAMERA_ANNOUNCE_READY */
54
while (ctx->reported_id != ctx->event_id) {
55
#endif /* IPECAMERA_ANNOUNCE_READY */
56
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);
57
else ++ctx->reported_id;
59
memcpy(&info, ctx->frame + ((ctx->reported_id-1)%ctx->buffer_size), sizeof(ipecamera_event_info_t));
61
if ((ctx->event_id - ctx->reported_id) < ctx->buffer_size) {
62
res = callback(ctx->reported_id, (pcilib_event_info_t*)&info, user);
64
if (res < 0) err = -res;
70
usleep(IPECAMERA_NOFRAME_SLEEP);
73
while ((run_flag)&&(ctx->run_streamer)) {
74
usleep(IPECAMERA_NOFRAME_SLEEP);
81
ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
88
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) {
90
ipecamera_t *ctx = (ipecamera_t*)vctx;
93
pcilib_error("IPECamera imaging is not initialized");
94
return PCILIB_ERROR_NOTINITIALIZED;
98
pcilib_error("IPECamera is not in grabbing mode");
99
return PCILIB_ERROR_INVALID_REQUEST;
102
if (!ctx->parse_data) {
103
pcilib_error("RAWData only mode is requested");
104
return PCILIB_ERROR_INVALID_REQUEST;
107
#ifdef IPECAMERA_ANNOUNCE_READY
108
if (((!ctx->preproc)&&(ctx->reported_id == ctx->event_id))||((ctx->preproc)&&(ctx->reported_id == ctx->preproc_id))) {
109
#else /* IPECAMERA_ANNOUNCE_READY */
110
if (ctx->reported_id == ctx->event_id) {
111
#endif /* IPECAMERA_ANNOUNCE_READY */
114
if (timeout == PCILIB_TIMEOUT_INFINITE) {
115
#ifdef IPECAMERA_ANNOUNCE_READY
116
while ((((!ctx->preproc)&&(ctx->reported_id == ctx->event_id))||((ctx->preproc)&&(ctx->reported_id == ctx->preproc_id)))) {
117
#else /* IPECAMERA_ANNOUNCE_READY */
118
while ((ctx->reported_id == ctx->event_id)) {
119
#endif /* IPECAMERA_ANNOUNCE_READY */
120
usleep(IPECAMERA_NOFRAME_SLEEP);
123
pcilib_calc_deadline(&tv, timeout);
125
#ifdef IPECAMERA_ANNOUNCE_READY
126
while ((ctx->started)&&(pcilib_calc_time_to_deadline(&tv) > 0)&&(((!ctx->preproc)&&(ctx->reported_id == ctx->event_id))||((ctx->preproc)&&(ctx->reported_id == ctx->preproc_id)))) {
127
#else /* IPECAMERA_ANNOUNCE_READY */
128
while ((ctx->started)&&(pcilib_calc_time_to_deadline(&tv) > 0)&&(ctx->reported_id == ctx->event_id)) {
129
#endif /* IPECAMERA_ANNOUNCE_READY */
130
usleep(IPECAMERA_NOFRAME_SLEEP);
135
if (ctx->reported_id == ctx->event_id) {
136
return PCILIB_ERROR_TIMEOUT;
142
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);
143
else ++ctx->reported_id;
145
if (evid) *evid = ctx->reported_id;
148
if (info_size >= sizeof(ipecamera_event_info_t))
149
memcpy(info, ctx->frame + ((ctx->reported_id-1)%ctx->buffer_size), sizeof(ipecamera_event_info_t));
150
else if (info_size >= sizeof(pcilib_event_info_t))
151
memcpy(info, ctx->frame + ((ctx->reported_id-1)%ctx->buffer_size), sizeof(pcilib_event_info_t));
153
return PCILIB_ERROR_INVALID_ARGUMENT;
156
if ((ctx->event_id - ctx->reported_id) >= ctx->buffer_size) goto retry;