Parcourir la source

Simplify size tracking in the reader

Suren A. Chilingaryan il y a 9 ans
Parent
commit
c177a207d4
4 fichiers modifiés avec 23 ajouts et 37 suppressions
  1. 2 3
      base.c
  2. 6 6
      data.c
  3. 4 6
      private.h
  4. 11 22
      reader.c

+ 2 - 3
base.c

@@ -321,9 +321,8 @@ int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_ev
     
     ipecamera_compute_buffer_size(ctx, ctx->dim.height);
 
-    ctx->raw_size = ctx->cur_raw_size;
-    ctx->full_size = ctx->cur_full_size;
-    ctx->padded_size = ctx->cur_padded_size;
+    ctx->raw_size = ctx->roi_raw_size;
+    ctx->padded_size = ctx->roi_padded_size;
 
     ctx->image_size = ctx->dim.width * ctx->dim.height;
 

+ 6 - 6
data.c

@@ -53,13 +53,13 @@ inline static int ipecamera_decode_frame(ipecamera_t *ctx, pcilib_event_id_t eve
 		
     pixels = ctx->image + buf_ptr * ctx->image_size;
     memset(ctx->cmask + ctx->buffer_pos * ctx->dim.height, 0, ctx->dim.height * sizeof(ipecamera_change_mask_t));
-/*
-    printf("decoding %lx...\n", ctx->raw_size);
+
+/*    printf("decoding %lx...\n", ctx->raw_size);
     FILE *f = fopen("/mnt/frame.xxx", "w");
-    fwrite(ctx->buffer + buf_ptr * ctx->padded_size, 1, ctx->raw_size, f);
-    fclose(f);*/
-    res = ufo_decoder_decode_frame(ctx->ipedec, ctx->buffer + buf_ptr * ctx->padded_size, ctx->raw_size, pixels, &ctx->frame[buf_ptr].event.meta);
-//    puts("done\n");
+    fwrite(ctx->buffer + buf_ptr * ctx->padded_size, 1, ctx->roi_raw_size, f);
+    fclose(f);
+    printf("%lu\n", ctx->raw_size);*/
+    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) {
 #ifdef IPECAMERA_DEBUG_BROKEN_FRAMES
 	char name[128];

+ 4 - 6
private.h

@@ -5,7 +5,7 @@
 #include <pcilib/model.h>
 #include "ipecamera.h"
 
-#define IPECAMERA_BUG_MISSING_PAYLOAD		//**< CMOSIS fails to provide a first payload for each frame, therefore the frame is 32 bit shorter */
+//#define IPECAMERA_BUG_MISSING_PAYLOAD		//**< CMOSIS fails to provide a first payload for each frame, therefore the frame is 32 bit shorter */
 #define IPECAMERA_BUG_MULTIFRAME_PACKETS	//**< This is by design, start of packet comes directly after the end of last one in streaming mode */
 //#define IPECAMERA_BUG_INCOMPLETE_PACKETS	//**< Support incomplete packets, i.e. check for frame magic even if full frame size is not reached yet (slow) */
 #define IPECAMERA_BUG_POSTPONED_READ
@@ -120,11 +120,9 @@ struct ipecamera_s {
     size_t buffer_pos;		/**< Current image offset in the buffer, due to synchronization reasons should not be used outside of reader_thread */
     size_t cur_size;		/**< Already written part of data in bytes */
     size_t raw_size;		/**< Expected maximum size of raw data in bytes */
-    size_t full_size;		/**< Expected maximum size of raw data including the padding */
-    size_t padded_size;		/**< Expected maximum size of buffer for raw data, including additional padding due to the ipecamera bugs */
-    size_t cur_raw_size;	/**< Expected size (for currently configured ROI) of raw data in bytes */
-    size_t cur_full_size;	/**< Expected size (for currently configured ROI) of raw data including the padding */
-    size_t cur_padded_size;	/**< Expected size (for currently configured ROI) of buffer for raw data, including additional padding due to the ipecamera bugs */
+    size_t padded_size;		/**< Expected maximum size of buffer for raw data, including additional padding */
+    size_t roi_raw_size;	/**< Expected size (for currently configured ROI) of raw data in bytes */
+    size_t roi_padded_size;	/**< Expected size (for currently configured ROI) of buffer for raw data, including additional padding */
     
     size_t image_size;		/**< Size of a single image in bytes */
     

+ 11 - 22
reader.c

@@ -29,10 +29,6 @@ int ipecamera_compute_buffer_size(ipecamera_t *ctx, size_t lines) {
     size_t line_size, raw_size, padded_blocks;
 
     switch (ctx->firmware) {
-     case 4:
-	line_size = IPECAMERA_MAX_CHANNELS * (2 + IPECAMERA_PIXELS_PER_CHANNEL / 3) * sizeof(ipecamera_payload_t);
-	raw_size = header_size + lines * line_size + footer_size;
-	break;
      default:
 	line_size = (1 + IPECAMERA_PIXELS_PER_CHANNEL) * 32; 
 	raw_size = lines * line_size;
@@ -47,16 +43,9 @@ int ipecamera_compute_buffer_size(ipecamera_t *ctx, size_t lines) {
 
     padded_blocks = raw_size / IPECAMERA_DMA_PACKET_LENGTH + ((raw_size % IPECAMERA_DMA_PACKET_LENGTH)?1:0);
     
-    ctx->cur_raw_size = raw_size;
-    ctx->cur_full_size = padded_blocks * IPECAMERA_DMA_PACKET_LENGTH;
-
-#ifdef IPECAMERA_BUG_EXTRA_DATA
-    ctx->cur_full_size += 8;
-    padded_blocks ++;
-#endif /* IPECAMERA_BUG_EXTRA_DATA */
-
-    ctx->cur_padded_size = padded_blocks * IPECAMERA_DMA_PACKET_LENGTH;
-//    printf("%lu %lu %lu\n", ctx->cur_raw_size, ctx->cur_full_size, ctx->cur_padded_size);
+    ctx->roi_raw_size = raw_size;
+    ctx->roi_padded_size = padded_blocks * IPECAMERA_DMA_PACKET_LENGTH;
+//    printf("%lu %lu\n", ctx->roi_raw_size, ctx->roi_padded_size);
 
     return 0;
 }
@@ -64,7 +53,7 @@ int ipecamera_compute_buffer_size(ipecamera_t *ctx, size_t lines) {
 static inline int ipecamera_new_frame(ipecamera_t *ctx) {
     ctx->frame[ctx->buffer_pos].event.raw_size = ctx->cur_size;
 
-    if (ctx->cur_size < ctx->cur_raw_size) {
+    if (ctx->cur_size < ctx->roi_raw_size) {
 	ctx->frame[ctx->buffer_pos].event.info.flags |= PCILIB_EVENT_INFO_FLAG_BROKEN;
     }
     
@@ -175,10 +164,10 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t
 	// for rawdata_callback with complete padding
     real_size = bufsize;
     
-    if (ctx->cur_size + bufsize > ctx->cur_raw_size) {
+    if (ctx->cur_size + bufsize > ctx->roi_raw_size) {
         size_t need;
 	
-	for (need = ctx->cur_raw_size - ctx->cur_size; (need + sizeof(frame_magic)) < bufsize; need += sizeof(uint32_t)) {
+	for (need = ctx->roi_raw_size - ctx->cur_size; (need + sizeof(frame_magic)) < bufsize; need += sizeof(uint32_t)) {
 	    if (!memcmp(buf + need, frame_magic, sizeof(frame_magic))) break;
 	}
 	
@@ -189,7 +178,7 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t
 	}
 
 	    // just rip of padding
-	bufsize = ctx->cur_raw_size - ctx->cur_size;
+	bufsize = ctx->roi_raw_size - ctx->cur_size;
 
 #ifdef IPECAMERA_DEBUG_RAW_PACKETS
 	sprintf(fname + strlen(fname) - 8, ".partial");
@@ -203,8 +192,8 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t
 #endif /* IPECAMERA_BUG_MULTIFRAME_PACKETS */
 
     if (ctx->parse_data) {
-	if (ctx->cur_size + bufsize > ctx->full_size) {
-    	    pcilib_error("Unexpected event data, we are expecting at maximum (%zu) bytes, but (%zu) already read", ctx->full_size, ctx->cur_size + bufsize);
+	if (ctx->cur_size + bufsize > ctx->padded_size) {
+    	    pcilib_error("Unexpected event data, we are expecting at maximum (%zu) bytes, but (%zu) already read", ctx->padded_size, ctx->cur_size + bufsize);
 	    return -PCILIB_ERROR_TOOBIG;
 	}
 
@@ -215,7 +204,7 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t
     ctx->cur_size += bufsize;
 //    printf("%i: %i %i\n", ctx->buffer_pos, ctx->cur_size, bufsize);
 
-    if (ctx->cur_size >= ctx->cur_raw_size) {
+    if (ctx->cur_size >= ctx->roi_raw_size) {
 	eof = 1;
     }
 
@@ -250,7 +239,7 @@ void *ipecamera_reader_thread(void *user) {
 	err = pcilib_stream_dma(ctx->event.pcilib, ctx->rdma, 0, 0, PCILIB_DMA_FLAG_MULTIPACKET, IPECAMERA_DMA_TIMEOUT, &ipecamera_data_callback, user);
 	if (err) {
 	    if (err == PCILIB_ERROR_TIMEOUT) {
-		if (ctx->cur_size >= ctx->cur_raw_size) ipecamera_new_frame(ctx);
+		if (ctx->cur_size >= ctx->roi_raw_size) ipecamera_new_frame(ctx);
 #ifdef IPECAMERA_BUG_INCOMPLETE_PACKETS
 		else if (ctx->cur_size > 0) ipecamera_new_frame(ctx);
 #endif /* IPECAMERA_BUG_INCOMPLETE_PACKETS */