#include <BitVector.hh>
Public Member Functions | |
| BitVector (unsigned char *baseBytePtr, unsigned baseBitOffset, unsigned totNumBits) | |
| void | setup (unsigned char *baseBytePtr, unsigned baseBitOffset, unsigned totNumBits) |
| void | putBits (unsigned from, unsigned numBits) |
| void | put1Bit (unsigned bit) |
| unsigned | getBits (unsigned numBits) |
| unsigned | get1Bit () |
| void | skipBits (unsigned numBits) |
| unsigned | curBitIndex () const |
| unsigned | totNumBits () const |
| unsigned | numBitsRemaining () const |
| unsigned | get_expGolomb () |
Private Attributes | |
| unsigned char * | fBaseBytePtr |
| unsigned | fBaseBitOffset |
| unsigned | fTotNumBits |
| unsigned | fCurBitIndex |
Definition at line 24 of file BitVector.hh.
| BitVector::BitVector | ( | unsigned char * | baseBytePtr, | |
| unsigned | baseBitOffset, | |||
| unsigned | totNumBits | |||
| ) |
Definition at line 23 of file BitVector.cpp.
References setup().
00025 { 00026 setup(baseBytePtr, baseBitOffset, totNumBits); 00027 }
| void BitVector::setup | ( | unsigned char * | baseBytePtr, | |
| unsigned | baseBitOffset, | |||
| unsigned | totNumBits | |||
| ) |
Definition at line 29 of file BitVector.cpp.
References fBaseBitOffset, fBaseBytePtr, fCurBitIndex, and fTotNumBits.
Referenced by BitVector(), and MP3FrameParams::setBytePointer().
00031 { 00032 fBaseBytePtr = baseBytePtr; 00033 fBaseBitOffset = baseBitOffset; 00034 fTotNumBits = totNumBits; 00035 fCurBitIndex = 0; 00036 }
| void BitVector::putBits | ( | unsigned | from, | |
| unsigned | numBits | |||
| ) |
Definition at line 43 of file BitVector.cpp.
References fBaseBitOffset, fBaseBytePtr, fCurBitIndex, fTotNumBits, MAX_LENGTH, and shiftBits().
Referenced by putSideInfo1(), and putSideInfo2().
00043 { 00044 if (numBits == 0) return; 00045 00046 unsigned char tmpBuf[4]; 00047 unsigned overflowingBits = 0; 00048 00049 if (numBits > MAX_LENGTH) { 00050 numBits = MAX_LENGTH; 00051 } 00052 00053 if (numBits > fTotNumBits - fCurBitIndex) { 00054 overflowingBits = numBits - (fTotNumBits - fCurBitIndex); 00055 } 00056 00057 tmpBuf[0] = (unsigned char)(from>>24); 00058 tmpBuf[1] = (unsigned char)(from>>16); 00059 tmpBuf[2] = (unsigned char)(from>>8); 00060 tmpBuf[3] = (unsigned char)from; 00061 00062 shiftBits(fBaseBytePtr, fBaseBitOffset + fCurBitIndex, /* to */ 00063 tmpBuf, MAX_LENGTH - numBits, /* from */ 00064 numBits - overflowingBits /* num bits */); 00065 fCurBitIndex += numBits - overflowingBits; 00066 }
| void BitVector::put1Bit | ( | unsigned | bit | ) |
Definition at line 68 of file BitVector.cpp.
References fBaseBitOffset, fBaseBytePtr, fCurBitIndex, fTotNumBits, and singleBitMask.
Referenced by putSideInfo1(), and putSideInfo2().
00068 { 00069 // The following is equivalent to "putBits(..., 1)", except faster: 00070 if (fCurBitIndex >= fTotNumBits) { /* overflow */ 00071 return; 00072 } else { 00073 unsigned totBitOffset = fBaseBitOffset + fCurBitIndex++; 00074 unsigned char mask = singleBitMask[totBitOffset%8]; 00075 if (bit) { 00076 fBaseBytePtr[totBitOffset/8] |= mask; 00077 } else { 00078 fBaseBytePtr[totBitOffset/8] &=~ mask; 00079 } 00080 } 00081 }
| unsigned BitVector::getBits | ( | unsigned | numBits | ) |
Definition at line 83 of file BitVector.cpp.
References fBaseBitOffset, fBaseBytePtr, fCurBitIndex, fTotNumBits, MAX_LENGTH, and shiftBits().
Referenced by H264VideoStreamParser::analyze_seq_parameter_set_data(), H264VideoStreamParser::analyze_slice_header(), H264VideoStreamParser::analyze_vui_parameters(), get_expGolomb(), MP3FrameParams::getBits(), MPEG4GenericRTPSource::processSpecialHeader(), and rsf_huffman_decoder().
00083 { 00084 if (numBits == 0) return 0; 00085 00086 unsigned char tmpBuf[4]; 00087 unsigned overflowingBits = 0; 00088 00089 if (numBits > MAX_LENGTH) { 00090 numBits = MAX_LENGTH; 00091 } 00092 00093 if (numBits > fTotNumBits - fCurBitIndex) { 00094 overflowingBits = numBits - (fTotNumBits - fCurBitIndex); 00095 } 00096 00097 shiftBits(tmpBuf, 0, /* to */ 00098 fBaseBytePtr, fBaseBitOffset + fCurBitIndex, /* from */ 00099 numBits - overflowingBits /* num bits */); 00100 fCurBitIndex += numBits - overflowingBits; 00101 00102 unsigned result 00103 = (tmpBuf[0]<<24) | (tmpBuf[1]<<16) | (tmpBuf[2]<<8) | tmpBuf[3]; 00104 result >>= (MAX_LENGTH - numBits); // move into low-order part of word 00105 result &= (0xFFFFFFFF << overflowingBits); // so any overflow bits are 0 00106 return result; 00107 }
| unsigned BitVector::get1Bit | ( | ) |
Definition at line 109 of file BitVector.cpp.
References fBaseBitOffset, fBaseBytePtr, fCurBitIndex, and fTotNumBits.
Referenced by H264VideoStreamParser::analyze_seq_parameter_set_data(), H264VideoStreamParser::analyze_slice_header(), H264VideoStreamParser::analyze_vui_parameters(), MP3FrameParams::get1Bit(), get_expGolomb(), and rsf_huffman_decoder().
00109 { 00110 // The following is equivalent to "getBits(1)", except faster: 00111 00112 if (fCurBitIndex >= fTotNumBits) { /* overflow */ 00113 return 0; 00114 } else { 00115 unsigned totBitOffset = fBaseBitOffset + fCurBitIndex++; 00116 unsigned char curFromByte = fBaseBytePtr[totBitOffset/8]; 00117 unsigned result = (curFromByte >> (7-(totBitOffset%8))) & 0x01; 00118 return result; 00119 } 00120 }
| void BitVector::skipBits | ( | unsigned | numBits | ) |
Definition at line 122 of file BitVector.cpp.
References fCurBitIndex, and fTotNumBits.
Referenced by H264VideoStreamParser::analyze_seq_parameter_set_data(), H264VideoStreamParser::analyze_slice_header(), H264VideoStreamParser::analyze_vui_parameters(), and MP3HuffmanDecode().
00122 { 00123 if (numBits > fTotNumBits - fCurBitIndex) { /* overflow */ 00124 fCurBitIndex = fTotNumBits; 00125 } else { 00126 fCurBitIndex += numBits; 00127 } 00128 }
| unsigned BitVector::curBitIndex | ( | ) | const [inline] |
Definition at line 42 of file BitVector.hh.
References fCurBitIndex.
Referenced by MP3HuffmanDecode().
00042 { return fCurBitIndex; }
| unsigned BitVector::totNumBits | ( | ) | const [inline] |
| unsigned BitVector::numBitsRemaining | ( | ) | const [inline] |
Definition at line 44 of file BitVector.hh.
References fCurBitIndex, and fTotNumBits.
00044 { return fTotNumBits - fCurBitIndex; }
| unsigned BitVector::get_expGolomb | ( | ) |
Definition at line 130 of file BitVector.cpp.
References fCurBitIndex, fTotNumBits, get1Bit(), and getBits().
Referenced by H264VideoStreamParser::analyze_seq_parameter_set_data(), H264VideoStreamParser::analyze_slice_header(), and H264VideoStreamParser::analyze_vui_parameters().
00130 { 00131 unsigned numLeadingZeroBits = 0; 00132 unsigned codeStart = 1; 00133 00134 while (get1Bit() == 0 && fCurBitIndex < fTotNumBits) { 00135 ++numLeadingZeroBits; 00136 codeStart *= 2; 00137 } 00138 00139 return codeStart -1 + getBits(numLeadingZeroBits); 00140 }
unsigned char* BitVector::fBaseBytePtr [private] |
unsigned BitVector::fBaseBitOffset [private] |
unsigned BitVector::fTotNumBits [private] |
Definition at line 52 of file BitVector.hh.
Referenced by get1Bit(), get_expGolomb(), getBits(), numBitsRemaining(), put1Bit(), putBits(), setup(), skipBits(), and totNumBits().
unsigned BitVector::fCurBitIndex [private] |
Definition at line 53 of file BitVector.hh.
Referenced by curBitIndex(), get1Bit(), get_expGolomb(), getBits(), numBitsRemaining(), put1Bit(), putBits(), setup(), and skipBits().
1.5.2