home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource1
/
mpegplay
/
util.h
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-02
|
22KB
|
363 lines
/*
* Copyright (c) 1992 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice and the following
* two paragraphs appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
/* Status codes for bit stream i/o operations. */
#define NO_VID_STREAM -1
#define UNDERFLOW -2
#define OK 1
/* Size increment of extension data buffers. */
#define EXT_BUF_SIZE 1024
/* External declarations for bitstream i/o operations. */
extern unsigned int bitMask[];
extern unsigned int nBitMask[];
extern unsigned int rBitMask[];
extern unsigned int bitTest[];
/* External declarations of bitstream global variables. */
extern unsigned int curBits;
extern int bitOffset;
extern int bufLength;
extern unsigned int *bitBuffer;
/* Macro for updating bit counter if analysis tool is on. */
#ifdef ANALYSIS
#define UPDATE_COUNT(numbits) bitCount += numbits
#else
#define UPDATE_COUNT(numbits)
#endif
#ifdef NO_SANITY_CHECKS
#define get_bits1(result) \
{ \
UPDATE_COUNT(1); \
result = ((curBits & 0x80000000) != 0); \
curBits <<= 1; \
bitOffset++; \
\
if (bitOffset & 0x20) { \
bitOffset = 0; \
bitBuffer++; \
curBits = *bitBuffer; \
bufLength--; \
} \
}
#define get_bits2(result) \
{ \
UPDATE_COUNT(2); \
bitOffset += 2; \
\
if (bitOffset & 0x20) { \
bitOffset -= 32; \
bitBuffer++; \
bufLength--; \
if (bitOffset) { \
curBits |= (*bitBuffer >> (2 - bitOffset)); \
} \
result = ((curBits & 0xc0000000) >> 30); \
curBits = *bitBuffer << bitOffset; \
} \
\
result = ((curBits & 0xc0000000) >> 30); \
curBits <<= 2; \
}
#define get_bitsX(num, mask, shift, result) \
{ \
UPDATE_COUNT(num); \
bitOffset += num; \
\
if (bitOffset & 0x20) { \
bitOffset -= 32; \
bitBuffer++; \
bufLength--; \
if (bitOffset) { \
curBits |= (*bitBuffer >> (num - bitOffset)); \
} \
result = ((curBits & mask) >> shift); \
curBits = *bitBuffer << bitOffset; \
} \
else { \
result = ((curBits & mask) >> shift); \
curBits <<= num; \
} \
}
#else
#define get_bits1(result) \
{ \
/* Check for underflow. */ \
\
if (bufLength < 2) { \
correct_underflow(); \
} \
UPDATE_COUNT(1); \
result = ((curBits & 0x80000000) != 0); \
curBits <<= 1; \
bitOffset++; \
\
if (bitOffset & 0x20) { \
bitOffset = 0; \
bitBuffer++; \
curBits = *bitBuffer; \
bufLength--; \
} \
}
#define get_bits2(result) \
{ \
/* Check for underflow. */ \
\
if (bufLength < 2) { \
correct_underflow(); \
} \
UPDATE_COUNT(2); \
bitOffset += 2; \
\
if (bitOffset & 0x20) { \
bitOffset -= 32; \
bitBuffer++; \
bufLength--; \
if (bitOffset) { \
curBits |= (*bitBuffer >> (2 - bitOffset)); \