/alps/ufodecode

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

« back to all changes in this revision

Viewing changes to src/ufodecode.c

  • Committer: Matthias Vogelgesang
  • Date: 2012-04-17 07:06:34 UTC
  • Revision ID: matthias.vogelgesang@kit.edu-20120417070634-zwnh90qb7sas8od0
Decode frames after encountering corrupted ones

Show diffs side-by-side

added added

removed removed

Lines of Context:
406
406
            if (header->row_number > num_rows) {
407
407
                fprintf(stderr, "Error: row_number in header is %i instead of %i\n", 
408
408
                        header->row_number, row); 
409
 
                abort();
 
409
                return 1;
 
410
                /* abort(); */
410
411
            }
411
412
 
412
413
            if (header->pixel_number > 128) {
413
414
                fprintf(stderr, "Error: pixel_number in header is %i instead of %i\n", 
414
415
                        header->pixel_number, pix); 
415
 
                abort();
 
416
                return 1;
 
417
                /* abort(); */
416
418
            }
417
419
 
418
420
            index = header->row_number * IPECAMERA_WIDTH + header->pixel_number;
556
558
            *time_stamp = raw[pos++] & 0xFFFFFF;
557
559
            break;
558
560
 
559
 
        /* case 5: */
560
 
        /*     printf("Alright!\n"); */
561
 
        /*     return 0; */
562
 
 
563
561
        default:
564
562
            fprintf(stderr, "Unsupported data format detected\n");
565
563
            return 0;
602
600
            break;
603
601
    }
604
602
 
605
 
    if (err) 
 
603
    if (err)
606
604
        return 0;
607
605
 
608
606
    pos += advance;
642
640
 * \param time_stamp Time stamp of the frame as reported in the header
643
641
 * \paran cmask Change-mask
644
642
 *
645
 
 * \return 0 in case of no error, ENOSR if end of stream was reached, ENOMEM if
 
643
 * \return 0 in case of no error, EIO if end of stream was reached, ENOMEM if
646
644
 * NULL was passed but no memory could be allocated, EILSEQ if data stream is
647
645
 * corrupt and EFAULT if pixels is a NULL-pointer.
648
646
 */
659
657
        return 0;
660
658
 
661
659
    if (pos >= num_words)
662
 
        return ENOSR; 
 
660
        return EIO; 
663
661
 
664
662
    if (num_words < 16)
665
663
        return EILSEQ;
670
668
            return ENOMEM;
671
669
    }
672
670
 
673
 
    while (raw[pos] != 0x51111111)
 
671
    while ((pos < num_words) && (raw[pos] != 0x51111111))
674
672
        pos++;
675
673
 
676
674
    advance = ufo_decoder_decode_frame(decoder, raw + pos, decoder->num_bytes -
677
675
            pos, *pixels, num_rows, frame_number, time_stamp, cmask);
678
676
 
679
 
    if (!advance) 
680
 
        return EILSEQ;
681
 
 
682
 
    pos += advance;
 
677
    /*
 
678
     * On error, advance is 0 but we have to advance at least a bit to net get
 
679
     * caught in an infinite loop when trying to decode subsequent frames.
 
680
     */
 
681
    pos += advance == 0 ? 1 : advance;
683
682
 
684
683
    /* if bytes left and we see fill bytes, skip them */
685
684
    if (((pos + 2) < num_words) && ((raw[pos] == 0x0) && (raw[pos+1] == 0x1111111))) {
689
688
    }
690
689
 
691
690
    decoder->current_pos = pos;
 
691
 
 
692
    if (!advance)
 
693
        return EILSEQ;
 
694
 
692
695
    return 0;
693
696
}
694
697