/alps/ipecamera

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to reader.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-08-12 15:37:04 UTC
  • Revision ID: csa@suren.me-20150812153704-u8vfxrs1jz00w3zc
Handle frame headers split between 2 packets

Show diffs side-by-side

added added

removed removed

Lines of Context:
163
163
    ipecamera_debug_buffer(RAW_PACKETS, bufsize, buf, PCILIB_DEBUG_BUFFER_MKDIR, "frame%4lu/frame%9lu", ctx->event_id, packet_id);
164
164
 
165
165
    if (!ctx->cur_size) {
 
166
#ifdef IPECAMERA_BUG_MULTIFRAME_HEADERS
 
167
        if (ctx->saved_header_size) {
 
168
            void *buf2 = alloca(ctx->saved_header_size + bufsize);
 
169
            if (!buf2) {
 
170
                pcilib_error("Error allocating %zu bytes of memory in stack", ctx->saved_header_size + bufsize);
 
171
                return -PCILIB_ERROR_MEMORY;
 
172
            }
 
173
            memcpy(buf2, ctx->saved_header, ctx->saved_header_size);
 
174
            memcpy(buf2 + ctx->saved_header_size, buf, bufsize);
 
175
 
 
176
            buf = buf2;
 
177
            bufsize += ctx->saved_header_size;
 
178
 
 
179
            ctx->saved_header_size = 0;
 
180
        }
 
181
#endif /* IPECAMERA_BUG_MULTIFRAME_HEADERS */
 
182
 
166
183
#if defined(IPECAMERA_BUG_INCOMPLETE_PACKETS)||defined(IPECAMERA_BUG_MULTIFRAME_PACKETS)
167
184
        size_t startpos;
168
 
        for (startpos = 0; (startpos + CMOSIS_FRAME_HEADER_SIZE) <= bufsize; startpos += sizeof(ipecamera_payload_t)) {
 
185
        for (startpos = 0; (startpos + CMOSIS_ENTITY_SIZE) <= bufsize; startpos += sizeof(ipecamera_payload_t)) {
169
186
            if (!CHECK_FRAME_MAGIC(buf + startpos)) break;
170
187
        }
171
188
        
172
 
        if ((startpos + CMOSIS_FRAME_HEADER_SIZE) > bufsize) {
 
189
        if ((startpos +  CMOSIS_ENTITY_SIZE) > bufsize) {
173
190
            ipecamera_debug_buffer(RAW_PACKETS, bufsize, NULL, 0, "frame%4lu/frame%9lu.invalid", ctx->event_id, packet_id);
174
191
            
175
192
            if (invalid_frame_id != ctx->event_id) {
200
217
                // We should handle the case when multi-header is split between multiple DMA packets
201
218
            if (!ipecamera_parse_header(ctx, buf, bufsize))
202
219
                return PCILIB_STREAMING_CONTINUE;
 
220
 
 
221
#ifdef IPECAMERA_BUG_MULTIFRAME_HEADERS
 
222
        } else if ((bufsize >= CMOSIS_ENTITY_SIZE)&&(!CHECK_FRAME_MAGIC(buf))) {
 
223
            memcpy(ctx->saved_header, buf, bufsize);
 
224
            ctx->saved_header_size = bufsize;
 
225
            return PCILIB_STREAMING_REQ_FRAGMENT;
 
226
#endif /* IPECAMERA_BUG_MULTIFRAME_HEADERS */
203
227
        } else {
204
 
            ipecamera_debug(HARDWARE, "Frame magic is not found, ignoring broken data...");
 
228
            ipecamera_debug(HARDWARE, "Frame magic is not found in the remaining DMA packet consisting of %u bytes, ignoring broken data...", bufsize);
205
229
            return PCILIB_STREAMING_CONTINUE;
206
230
        }
207
231
    }
213
237
    if (ctx->cur_size + bufsize > ctx->roi_raw_size) {
214
238
        size_t need;
215
239
        
216
 
        for (need = ctx->roi_raw_size - ctx->cur_size; (need + CMOSIS_FRAME_HEADER_SIZE) <= bufsize; need += sizeof(uint32_t)) {
 
240
        for (need = ctx->roi_raw_size - ctx->cur_size; (need + CMOSIS_ENTITY_SIZE) <= bufsize; need += sizeof(uint32_t)) {
217
241
            if (!CHECK_FRAME_MAGIC(buf + need)) break;
218
242
        }
219
243
        
220
 
        if ((need + CMOSIS_FRAME_HEADER_SIZE) <= bufsize) {
 
244
        if ((need + CMOSIS_ENTITY_SIZE) <= bufsize) {
221
245
            extra_data = bufsize - need;
222
246
            eof = 1;
223
247
        }