/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-27 00:28:57 UTC
  • Revision ID: csa@suren.me-20150427002857-82fk6r3e8rfgy4wr
First stand-alone ipecamera implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
#include <ufodecode.h>
15
15
 
16
 
#include "../tools.h"
17
 
#include "../error.h"
 
16
#include <pcilib.h>
 
17
#include <pcilib/tools.h>
 
18
#include <pcilib/error.h>
18
19
 
19
 
#include "pcilib.h"
20
20
#include "model.h"
21
21
#include "private.h"
22
22
#include "reader.h"
75
75
        return 1;
76
76
    }
77
77
        
78
 
    if (pcilib_check_deadline(&ctx->autostop.timestamp, PCILIB_DMA_TIMEOUT)) {
 
78
    if (pcilib_check_deadline(&ctx->autostop.timestamp, 0)) {
79
79
        ctx->run_reader = 0;
80
80
        return 1;
81
81
    }
119
119
    if (!ctx->cur_size) {
120
120
#if defined(IPECAMERA_BUG_INCOMPLETE_PACKETS)||defined(IPECAMERA_BUG_MULTIFRAME_PACKETS)
121
121
        size_t startpos;
122
 
        for (startpos = 0; (startpos + sizeof(frame_magic)) < bufsize; startpos += sizeof(uint32_t)) {
 
122
        for (startpos = 0; (startpos + sizeof(frame_magic)) <= bufsize; startpos += sizeof(uint32_t)) {
123
123
            if (!memcmp(buf + startpos, frame_magic, sizeof(frame_magic))) break;
124
124
        }
125
125
        
126
 
        if ((startpos + sizeof(frame_magic)) >= bufsize) {
 
126
        if ((startpos + sizeof(frame_magic)) > bufsize) {
127
127
#ifdef IPECAMERA_DEBUG_RAW_PACKETS
128
128
            FILE *f = fopen(fname, "w");
129
129
            if (f) fclose(f);
130
130
#endif /* IPECAMERA_DEBUG_RAW_PACKETS */
131
131
            
132
132
            if (invalid_frame_id != ctx->event_id) {
133
 
//              pcilib_warning("No frame magic in DMA packet of %u bytes, current event %lu (got %lu)", bufsize, ctx->event_id, invalid_frame_id);
 
133
//              pcilib_warning("No frame magic in DMA packet of %u bytes, current event %lu", bufsize, ctx->event_id);
134
134
                invalid_frame_id = ctx->event_id;
135
135
            }
136
136
 
159
159
 
160
160
            ctx->frame[ctx->buffer_pos].event.info.seqnum = ((uint32_t*)buf)[6] & 0x1FFFFFF;
161
161
            ctx->frame[ctx->buffer_pos].event.info.offset = (((uint32_t*)buf)[7] & 0xFFFFFF) * 80;
162
 
 
163
 
//          ctx->frame[ctx->buffer_pos].event.info.seqnum = ctx->event_id + 1;
164
 
 
165
162
            gettimeofday(&ctx->frame[ctx->buffer_pos].event.info.timestamp, NULL);
166
163
        } else {
167
164
//          pcilib_warning("Frame magic is not found, ignoring broken data...");
186
183
            eof = 1;
187
184
        }
188
185
 
189
 
//      printf("%lu %lu %lu - %u\n", ctx->event_id, ctx->cur_size, ctx->cur_raw_size, eof);
190
 
        
191
186
            // just rip of padding
192
187
        bufsize = ctx->cur_raw_size - ctx->cur_size;
193
188
 
208
203
            return -PCILIB_ERROR_TOOBIG;
209
204
        }
210
205
 
211
 
        memcpy(ctx->buffer + ctx->buffer_pos * ctx->padded_size +  ctx->cur_size, buf, bufsize);
 
206
        if (bufsize)
 
207
            memcpy(ctx->buffer + ctx->buffer_pos * ctx->padded_size +  ctx->cur_size, buf, bufsize);
212
208
    }
213
209
 
214
210
    ctx->cur_size += bufsize;
215
211
//    printf("%i: %i %i\n", ctx->buffer_pos, ctx->cur_size, bufsize);
216
212
 
217
 
    if (ctx->cur_size >= ctx->full_size) {
 
213
    if (ctx->cur_size >= ctx->cur_raw_size) {
218
214
        eof = 1;
219
215
    }
220
216
 
246
242
    ipecamera_t *ctx = (ipecamera_t*)user;
247
243
    
248
244
    while (ctx->run_reader) {
249
 
        err = pcilib_stream_dma(ctx->event.pcilib, ctx->rdma, 0, 0, PCILIB_DMA_FLAG_MULTIPACKET, 10 * PCILIB_DMA_TIMEOUT, &ipecamera_data_callback, user);
 
245
        err = pcilib_stream_dma(ctx->event.pcilib, ctx->rdma, 0, 0, PCILIB_DMA_FLAG_MULTIPACKET, IPECAMERA_DMA_TIMEOUT, &ipecamera_data_callback, user);
250
246
        if (err) {
251
247
            if (err == PCILIB_ERROR_TIMEOUT) {
252
248
                if (ctx->cur_size >= ctx->cur_raw_size) ipecamera_new_frame(ctx);
253
249
#ifdef IPECAMERA_BUG_INCOMPLETE_PACKETS
254
250
                else if (ctx->cur_size > 0) ipecamera_new_frame(ctx);
255
251
#endif /* IPECAMERA_BUG_INCOMPLETE_PACKETS */
256
 
                if (pcilib_check_deadline(&ctx->autostop.timestamp, 10 * PCILIB_DMA_TIMEOUT)) {
 
252
                if (pcilib_check_deadline(&ctx->autostop.timestamp, 0)) {
257
253
                    ctx->run_reader = 0;
258
254
                    break;
259
255
                }