Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
bitstream.c
Upload User: hbbaokai
Upload Date: 2009-07-13
Package Size: 328k
Code Size: 1k
Category:
VOIP program
Development Platform:
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;
- }