/alps/ipecamera

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to reader.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-04-28 21:35:25 UTC
  • Revision ID: csa@suren.me-20150428213525-i4m5dxn8xda8ow0y
Simplify size tracking in the reader

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    size_t line_size, raw_size, padded_blocks;
30
30
 
31
31
    switch (ctx->firmware) {
32
 
     case 4:
33
 
        line_size = IPECAMERA_MAX_CHANNELS * (2 + IPECAMERA_PIXELS_PER_CHANNEL / 3) * sizeof(ipecamera_payload_t);
34
 
        raw_size = header_size + lines * line_size + footer_size;
35
 
        break;
36
32
     default:
37
33
        line_size = (1 + IPECAMERA_PIXELS_PER_CHANNEL) * 32; 
38
34
        raw_size = lines * line_size;
47
43
 
48
44
    padded_blocks = raw_size / IPECAMERA_DMA_PACKET_LENGTH + ((raw_size % IPECAMERA_DMA_PACKET_LENGTH)?1:0);
49
45
    
50
 
    ctx->cur_raw_size = raw_size;
51
 
    ctx->cur_full_size = padded_blocks * IPECAMERA_DMA_PACKET_LENGTH;
52
 
 
53
 
#ifdef IPECAMERA_BUG_EXTRA_DATA
54
 
    ctx->cur_full_size += 8;
55
 
    padded_blocks ++;
56
 
#endif /* IPECAMERA_BUG_EXTRA_DATA */
57
 
 
58
 
    ctx->cur_padded_size = padded_blocks * IPECAMERA_DMA_PACKET_LENGTH;
59
 
//    printf("%lu %lu %lu\n", ctx->cur_raw_size, ctx->cur_full_size, ctx->cur_padded_size);
 
46
    ctx->roi_raw_size = raw_size;
 
47
    ctx->roi_padded_size = padded_blocks * IPECAMERA_DMA_PACKET_LENGTH;
 
48
//    printf("%lu %lu\n", ctx->roi_raw_size, ctx->roi_padded_size);
60
49
 
61
50
    return 0;
62
51
}
64
53
static inline int ipecamera_new_frame(ipecamera_t *ctx) {
65
54
    ctx->frame[ctx->buffer_pos].event.raw_size = ctx->cur_size;
66
55
 
67
 
    if (ctx->cur_size < ctx->cur_raw_size) {
 
56
    if (ctx->cur_size < ctx->roi_raw_size) {
68
57
        ctx->frame[ctx->buffer_pos].event.info.flags |= PCILIB_EVENT_INFO_FLAG_BROKEN;
69
58
    }
70
59
    
175
164
        // for rawdata_callback with complete padding
176
165
    real_size = bufsize;
177
166
    
178
 
    if (ctx->cur_size + bufsize > ctx->cur_raw_size) {
 
167
    if (ctx->cur_size + bufsize > ctx->roi_raw_size) {
179
168
        size_t need;
180
169
        
181
 
        for (need = ctx->cur_raw_size - ctx->cur_size; (need + sizeof(frame_magic)) < bufsize; need += sizeof(uint32_t)) {
 
170
        for (need = ctx->roi_raw_size - ctx->cur_size; (need + sizeof(frame_magic)) < bufsize; need += sizeof(uint32_t)) {
182
171
            if (!memcmp(buf + need, frame_magic, sizeof(frame_magic))) break;
183
172
        }
184
173
        
189
178
        }
190
179
 
191
180
            // just rip of padding
192
 
        bufsize = ctx->cur_raw_size - ctx->cur_size;
 
181
        bufsize = ctx->roi_raw_size - ctx->cur_size;
193
182
 
194
183
#ifdef IPECAMERA_DEBUG_RAW_PACKETS
195
184
        sprintf(fname + strlen(fname) - 8, ".partial");
203
192
#endif /* IPECAMERA_BUG_MULTIFRAME_PACKETS */
204
193
 
205
194
    if (ctx->parse_data) {
206
 
        if (ctx->cur_size + bufsize > ctx->full_size) {
207
 
            pcilib_error("Unexpected event data, we are expecting at maximum (%zu) bytes, but (%zu) already read", ctx->full_size, ctx->cur_size + bufsize);
 
195
        if (ctx->cur_size + bufsize > ctx->padded_size) {
 
196
            pcilib_error("Unexpected event data, we are expecting at maximum (%zu) bytes, but (%zu) already read", ctx->padded_size, ctx->cur_size + bufsize);
208
197
            return -PCILIB_ERROR_TOOBIG;
209
198
        }
210
199
 
215
204
    ctx->cur_size += bufsize;
216
205
//    printf("%i: %i %i\n", ctx->buffer_pos, ctx->cur_size, bufsize);
217
206
 
218
 
    if (ctx->cur_size >= ctx->cur_raw_size) {
 
207
    if (ctx->cur_size >= ctx->roi_raw_size) {
219
208
        eof = 1;
220
209
    }
221
210
 
250
239
        err = pcilib_stream_dma(ctx->event.pcilib, ctx->rdma, 0, 0, PCILIB_DMA_FLAG_MULTIPACKET, IPECAMERA_DMA_TIMEOUT, &ipecamera_data_callback, user);
251
240
        if (err) {
252
241
            if (err == PCILIB_ERROR_TIMEOUT) {
253
 
                if (ctx->cur_size >= ctx->cur_raw_size) ipecamera_new_frame(ctx);
 
242
                if (ctx->cur_size >= ctx->roi_raw_size) ipecamera_new_frame(ctx);
254
243
#ifdef IPECAMERA_BUG_INCOMPLETE_PACKETS
255
244
                else if (ctx->cur_size > 0) ipecamera_new_frame(ctx);
256
245
#endif /* IPECAMERA_BUG_INCOMPLETE_PACKETS */