From 280522822611d16c87e9931f8807878fc023e97d Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Fri, 14 Aug 2015 02:59:59 +0200 Subject: Fix a bug causing image_broken flag to be checked before it set when preprocessing was enabled --- data.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/data.c b/data.c index c5c8a60..04a4be1 100644 --- a/data.c +++ b/data.c @@ -58,13 +58,12 @@ inline static int ipecamera_decode_frame(ipecamera_t *ctx, pcilib_event_id_t eve res = ufo_decoder_decode_frame(ctx->ipedec, ctx->buffer + buf_ptr * ctx->padded_size, ctx->frame[buf_ptr].event.raw_size, pixels, &ctx->frame[buf_ptr].event.meta); if (!res) { - ipecamera_debug(HARDWARE, "Decoding of frame %u has failed, ufodecode returns error %i", ctx->event_id, res); ipecamera_debug_buffer(BROKEN_FRAMES, ctx->frame[buf_ptr].event.raw_size, ctx->buffer + buf_ptr * ctx->padded_size, PCILIB_DEBUG_BUFFER_MKDIR, "broken_frame.%4lu", ctx->event_id); err = PCILIB_ERROR_INVALID_DATA; ctx->frame[buf_ptr].event.image_broken = err; goto ready; - } - + } + ctx->frame[buf_ptr].event.image_broken = 0; ready: @@ -157,11 +156,8 @@ void *ipecamera_preproc_thread(void *user) { static int ipecamera_get_frame(ipecamera_t *ctx, pcilib_event_id_t event_id) { int err; int buf_ptr = (event_id - 1) % ctx->buffer_size; - - if (ctx->preproc) { - if (ctx->frame[buf_ptr].event.image_broken) - return ctx->frame[buf_ptr].event.image_broken; - } else { + + if (!ctx->preproc) { pthread_rwlock_rdlock(&ctx->frame[buf_ptr].mutex); err = ipecamera_decode_frame(ctx, event_id); @@ -175,13 +171,16 @@ static int ipecamera_get_frame(ipecamera_t *ctx, pcilib_event_id_t event_id) { } - while (!ctx->frame[buf_ptr].event.image_ready) { + while (!((volatile ipecamera_t*)ctx)->frame[buf_ptr].event.image_ready) { usleep(IPECAMERA_NOFRAME_PREPROC_SLEEP); buf_ptr = ipecamera_resolve_event_id(ctx, event_id); if (buf_ptr < 0) return PCILIB_ERROR_OVERWRITTEN; } + if (((volatile ipecamera_t*)ctx)->frame[buf_ptr].event.image_broken) + return ctx->frame[buf_ptr].event.image_broken; + pthread_rwlock_rdlock(&ctx->frame[buf_ptr].mutex); buf_ptr = ipecamera_resolve_event_id(ctx, event_id); -- cgit v1.2.1