bitstream.c
资源名称:VC++视频传输.rar [点击查看]
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:1k
源码类别:
VC书籍
开发平台:
Visual C++
- #include "bitstream.h"
- static unsigned int mask[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 unsigned char *byteptr;
- static int bytecnt;
- static unsigned char outbfr;
- static int outcnt;
- void Bitstream_Init(void *buffer)
- {
- byteptr = (unsigned char *)buffer;
- bytecnt = 0;
- outbfr = 0;
- outcnt = 8;
- }
- void Bitstream_PutBits(int n, unsigned int val)
- {
- int diff;
- while ((diff = n - outcnt) >= 0) {
- outbfr |= (unsigned char)(val >> diff);
- n = diff;
- val &= mask[n];
- *(byteptr ++) = outbfr;
- bytecnt++;
- outbfr = 0;
- outcnt = 8;
- }
- if (n > 0) {
- outbfr |= (unsigned char)(val << (-diff));
- outcnt -= n;
- }
- }
- int Bitstream_Close()
- {
- while (outcnt != 8) Bitstream_PutBits(1, 1);
- return bytecnt;
- }
- int Bitstream_NextStartCode()
- {
- int count = outcnt;
- Bitstream_PutBits(1,0);
- while (outcnt != 8) Bitstream_PutBits(1, 1);
- return (count);
- }
- int Bitstream_GetLength()
- {
- return bytecnt;
- }