summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2012-07-05 01:54:12 +0200
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2012-07-05 01:54:12 +0200
commit59a6ce037b0806e26c5d6dada2e12ea4bbe1b588 (patch)
tree679c51c7127780792ace07e7b98dea7edca77ecf
parent71657075c0e9991d36f640554b8f4ac4d2ae95ba (diff)
downloadpcitool-59a6ce037b0806e26c5d6dada2e12ea4bbe1b588.tar.gz
pcitool-59a6ce037b0806e26c5d6dada2e12ea4bbe1b588.tar.bz2
pcitool-59a6ce037b0806e26c5d6dada2e12ea4bbe1b588.tar.xz
pcitool-59a6ce037b0806e26c5d6dada2e12ea4bbe1b588.zip
UFO5 size estimation
-rw-r--r--ipecamera/ipecamera.c23
-rw-r--r--ipecamera/private.h3
-rw-r--r--ipecamera/reader.c36
-rw-r--r--ipecamera/reader.h2
4 files changed, 41 insertions, 23 deletions
diff --git a/ipecamera/ipecamera.c b/ipecamera/ipecamera.c
index b76cf19..9b7482a 100644
--- a/ipecamera/ipecamera.c
+++ b/ipecamera/ipecamera.c
@@ -241,13 +241,6 @@ int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_ev
pcilib_t *pcilib = vctx->pcilib;
pcilib_register_value_t value;
- const size_t chan_size = (2 + IPECAMERA_PIXELS_PER_CHANNEL / 3) * sizeof(ipecamera_payload_t);
- const size_t line_size = (IPECAMERA_MAX_CHANNELS * chan_size);
- const size_t header_size = 8 * sizeof(ipecamera_payload_t);
- const size_t footer_size = 8 * sizeof(ipecamera_payload_t);
- size_t raw_size;
- size_t padded_blocks;
-
pthread_attr_t attr;
struct sched_param sched;
@@ -279,19 +272,13 @@ int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_ev
ctx->dim.width = IPECAMERA_WIDTH;
GET_REG(n_lines_reg, ctx->dim.height);
- raw_size = header_size + ctx->dim.height * line_size + footer_size;
- padded_blocks = raw_size / IPECAMERA_DMA_PACKET_LENGTH + ((raw_size % IPECAMERA_DMA_PACKET_LENGTH)?1:0);
-
- ctx->image_size = ctx->dim.width * ctx->dim.height;
- ctx->raw_size = raw_size;
- ctx->full_size = padded_blocks * IPECAMERA_DMA_PACKET_LENGTH;
+ ipecamera_compute_buffer_size(ctx, ctx->dim.height);
-#ifdef IPECAMERA_BUG_EXTRA_DATA
- ctx->full_size += 8;
- padded_blocks ++;
-#endif /* IPECAMERA_BUG_EXTRA_DATA */
+ ctx->raw_size = ctx->cur_raw_size;
+ ctx->full_size = ctx->cur_full_size;
+ ctx->padded_size = ctx->cur_padded_size;
- ctx->padded_size = padded_blocks * IPECAMERA_DMA_PACKET_LENGTH;
+ ctx->image_size = ctx->dim.width * ctx->dim.height;
ctx->buffer = malloc(ctx->padded_size * ctx->buffer_size);
if (!ctx->buffer) {
diff --git a/ipecamera/private.h b/ipecamera/private.h
index 0542429..34eb99a 100644
--- a/ipecamera/private.h
+++ b/ipecamera/private.h
@@ -97,6 +97,9 @@ struct ipecamera_s {
size_t raw_size; /**< Size of raw data in bytes */
size_t full_size; /**< Size of raw data including the padding */
size_t padded_size; /**< Size of buffer for raw data, including the padding for performance */
+ size_t cur_raw_size; /**< Size of raw data in bytes */
+ size_t cur_full_size; /**< Size of raw data including the padding */
+ size_t cur_padded_size; /**< Size of buffer for raw data, including the padding for performance */
size_t image_size; /**< Size of a single image in bytes */
diff --git a/ipecamera/reader.c b/ipecamera/reader.c
index 9be6533..05df5e7 100644
--- a/ipecamera/reader.c
+++ b/ipecamera/reader.c
@@ -16,9 +16,32 @@
#include "../error.h"
#include "pcilib.h"
+#include "model.h"
#include "private.h"
#include "reader.h"
+
+int ipecamera_compute_buffer_size(ipecamera_t *ctx, size_t lines) {
+ const size_t line_size = (1 + IPECAMERA_PIXELS_PER_CHANNEL) * 32;
+ const size_t header_size = 8 * sizeof(ipecamera_payload_t);
+ const size_t footer_size = 8 * sizeof(ipecamera_payload_t);
+
+ size_t raw_size = header_size + lines * line_size - 32 + footer_size;
+ size_t 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;
+
+ return 0;
+}
+
static inline int ipecamera_new_frame(ipecamera_t *ctx) {
ctx->frame[ctx->buffer_pos].event.raw_size = ctx->cur_size;
@@ -44,7 +67,7 @@ static inline int ipecamera_new_frame(ipecamera_t *ctx) {
return 0;
}
-static uint32_t frame_magic[6] = { 0x51111111, 0x52222222, 0x53333333, 0x54444444, 0x55555555, 0x56666666 };
+static uint32_t frame_magic[5] = { 0x51111111, 0x52222222, 0x53333333, 0x54444444, 0x55555555 };
static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t bufsize, void *buf) {
int res;
@@ -62,6 +85,7 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t
size_t startpos;
for (startpos = 0; (startpos + 8) < bufsize; startpos++) {
if (!memcmp(buf + startpos, frame_magic, sizeof(frame_magic))) break;
+//o raw_size =
}
if (startpos) {
@@ -81,6 +105,8 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t
#endif /* IPECAMERA_BUG_INCOMPLETE_PACKETS */
if ((bufsize >= 8)&&(!memcmp(buf, frame_magic, sizeof(frame_magic)))) {
+ size_t n_lines = ((uint32_t*)buf)[5] & 0x7FF;
+ ipecamera_compute_buffer_size(ctx, n_lines);
/*
// Not implemented in hardware yet
ctx->frame[ctx->buffer_pos].event.info.seqnum = ((uint32_t*)buf)[6] & 0xF0000000;
@@ -99,10 +125,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->raw_size) {
+ if (ctx->cur_size + bufsize > ctx->cur_raw_size) {
size_t need;
- for (need = ctx->raw_size - ctx->cur_size; need < bufsize; need += sizeof(uint32_t)) {
+ for (need = ctx->cur_raw_size - ctx->cur_size; need < bufsize; need += sizeof(uint32_t)) {
if (*(uint32_t*)(buf + need) == frame_magic[0]) break;
}
@@ -113,7 +139,7 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t
}
// just rip of padding
- bufsize = ctx->raw_size - ctx->cur_size;
+ bufsize = ctx->cur_raw_size - ctx->cur_size;
}
#endif /* IPECAMERA_BUG_MULTIFRAME_PACKETS */
@@ -166,7 +192,7 @@ void *ipecamera_reader_thread(void *user) {
err = pcilib_stream_dma(ctx->event.pcilib, ctx->rdma, 0, 0, PCILIB_DMA_FLAG_MULTIPACKET, PCILIB_DMA_TIMEOUT, &ipecamera_data_callback, user);
if (err) {
if (err == PCILIB_ERROR_TIMEOUT) {
- if (ctx->cur_size > ctx->raw_size) ipecamera_new_frame(ctx);
+ if (ctx->cur_size > ctx->cur_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 */
diff --git a/ipecamera/reader.h b/ipecamera/reader.h
index 738d742..5d631c0 100644
--- a/ipecamera/reader.h
+++ b/ipecamera/reader.h
@@ -1,6 +1,8 @@
#ifndef _IPECAMERA_READER_H
#define _IPECAMERA_READER_H
+int ipecamera_compute_buffer_size(ipecamera_t *ctx, size_t lines);
+
void *ipecamera_reader_thread(void *user);
#endif /* _IPECAMERA_READER_H */