⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bitstream.c

📁 <VC++视频音频开发>一书的光盘资料。
💻 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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -