GETBITS.H
资源名称:VC++视频传输.rar [点击查看]
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:3k
源码类别:
VC书籍
开发平台:
Visual C++
- #ifndef _DECORE_GETBITS_H
- #define _DECORE_GETBITS_H
- void initbits (unsigned char * stream, int length);
- void fillbfr (void);
- /***/
- #if defined(LINUX)
- #define _SWAP(a,b) b=*(int*)a;
- __asm__ ( "bswapl %0n" : "=g" (b) : "0" (b) )
- #elif defined(WIN32)
- #define _SWAP(a,b)
- b=*(int*)a; __asm mov eax,b __asm bswap eax __asm mov b, eax
- #else
- #define _SWAP(a,b) (b=((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]))
- #endif
- #ifdef WIN32
- #include <io.h>
- #endif
- /***/
- #ifndef _DECORE
- static unsigned int msk[33] =
- {
- 0x00000000, 0x00000001, 0x00000003, 0x00000007,
- 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
- 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
- 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
- 0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
- 0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
- 0x00ffffff, 0x01ffffff, 0x03ffffff, 0x07ffffff,
- 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff,
- 0xffffffff
- };
- static void fillbfr ()
- {
- int l;
- ld->inbfr[0] = ld->inbfr[8];
- ld->inbfr[1] = ld->inbfr[9];
- ld->inbfr[2] = ld->inbfr[10];
- ld->inbfr[3] = ld->inbfr[11];
- if (ld->rdptr >= ld->rdbfr + 2048)
- {
- l = read (ld->infile, ld->rdbfr, 2048);
- ld->rdptr = ld->rdbfr;
- if (l < 2048)
- {
- if (l < 0)
- l = 0;
- while (l < 2048)
- {
- ld->rdbfr[l++] = 0;
- ld->rdbfr[l++] = 0;
- ld->rdbfr[l++] = (1 << 7) | (31 << 2);
- }
- }
- }
- for (l = 0; l < 8; l++)
- ld->inbfr[l + 4] = ld->rdptr[l];
- ld->rdptr += 8;
- ld->incnt += 64;
- }
- //返回下n位
- static unsigned int showbits (int n)
- {
- unsigned char *v;
- unsigned int b;
- int c;
- if (ld->incnt < n)
- fillbfr ();
- v = ld->inbfr + ((96 - ld->incnt) >> 3);
- b = (v[0] << 24) | (v[1] << 16) | (v[2] << 8) | v[3];
- c = ((ld->incnt - 1) & 7) + 25;
- return (b >> (c - n)) & msk[n];
- }
- // 前进n位
- static void flushbits (int n)
- {
- ld->bitcnt += n;
- ld->incnt -= n;
- if (ld->incnt < 0)
- fillbfr ();
- }
- #else
- static __inline unsigned int showbits (int n)
- {
- int rbit = 32 - ld->bitcnt;
- unsigned int b;
- _SWAP(ld->rdptr, b);
- return (b & (0xFFFFFFFFU >> (ld->bitcnt))) >> (rbit-n);
- }
- static __inline void flushbits (int n)
- {
- ld->bitcnt += n;
- if (ld->bitcnt >= 8) {
- ld->rdptr += ld->bitcnt / 8;
- ld->bitcnt = ld->bitcnt % 8;
- }
- }
- #endif // !_DECORE
- static __inline unsigned int getbits (int n)
- {
- unsigned int l;
- l = showbits (n);
- flushbits (n);
- return l;
- }
- unsigned int getbits1 (void);
- #endif /* _DECORE_GETBITS_H */