Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 1 | pmbaty | 1 | /** | 
| 2 |         libsmacker - A C library for decoding .smk Smacker Video files | ||
| 3 |         Copyright (C) 2012-2017 Greg Kennedy | ||
| 4 | |||
| 5 |         See smacker.h for more information. | ||
| 6 | |||
| 7 |         smk_bitstream.h | ||
| 8 |                 SMK bitstream structure. Presents a block of raw bytes one | ||
| 9 |                 bit at a time, and protects against over-read. | ||
| 10 | */ | ||
| 11 | |||
| 12 | #ifndef SMK_BITSTREAM_H | ||
| 13 | #define SMK_BITSTREAM_H | ||
| 14 | |||
| 15 | /** Bitstream structure, Forward declaration */ | ||
| 16 | struct smk_bit_t; | ||
| 17 | |||
| 18 | /* BITSTREAM Functions */ | ||
| 19 | /** Initialize a bitstream */ | ||
| 20 | struct smk_bit_t* smk_bs_init(const unsigned char* b, unsigned long size); | ||
| 21 | |||
| 22 | /** This macro checks return code from _smk_bs_read_1 and | ||
| 23 |         jumps to error label if problems occur. */ | ||
| 24 | #define smk_bs_read_1(t,uc) \ | ||
| 25 | { \ | ||
| 26 |         if ((char)(uc = _smk_bs_read_1(t)) < 0) \ | ||
| 27 |         { \ | ||
| 28 |                 fprintf(stderr, "libsmacker::smk_bs_read_1(" #t ", " #uc ") - ERROR (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \ | ||
| 29 |                 goto error; \ | ||
| 30 |         } \ | ||
| 31 | } | ||
| 32 | /** Read a single bit from the bitstream, and advance. | ||
| 33 |         Returns -1 on error. */ | ||
| 34 | char _smk_bs_read_1(struct smk_bit_t* bs); | ||
| 35 | |||
| 36 | /** This macro checks return code from _smk_bs_read_8 and | ||
| 37 |         jumps to error label if problems occur. */ | ||
| 38 | #define smk_bs_read_8(t,s) \ | ||
| 39 | { \ | ||
| 40 |         if ((short)(s = _smk_bs_read_8(t)) < 0) \ | ||
| 41 |         { \ | ||
| 42 |                 fprintf(stderr, "libsmacker::smk_bs_read_8(" #t ", " #s ") - ERROR (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \ | ||
| 43 |                 goto error; \ | ||
| 44 |         } \ | ||
| 45 | } | ||
| 46 | /** Read eight bits from the bitstream (one byte), and advance. | ||
| 47 |         Returns -1 on error. */ | ||
| 48 | short _smk_bs_read_8(struct smk_bit_t* bs); | ||
| 49 | |||
| 50 | #endif |