BitVector Class Reference

#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 ()
Boolean get1BitBoolean ()
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


Detailed Description

Definition at line 28 of file BitVector.hh.


Constructor & Destructor Documentation

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 }


Member Function Documentation

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 H264or5VideoStreamParser::analyze_seq_parameter_set_data(), H264or5VideoStreamParser::analyze_video_parameter_set_data(), H264or5VideoStreamParser::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 MP3FrameParams::get1Bit(), get1BitBoolean(), 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 }

Boolean BitVector::get1BitBoolean (  )  [inline]

Definition at line 43 of file BitVector.hh.

References get1Bit().

Referenced by H264or5VideoStreamParser::analyze_seq_parameter_set_data(), H264or5VideoStreamParser::analyze_video_parameter_set_data(), H264or5VideoStreamParser::analyze_vui_parameters(), and H264or5VideoStreamParser::profile_tier_level().

00043 { return get1Bit() != 0; }

void BitVector::skipBits ( unsigned  numBits  ) 

Definition at line 122 of file BitVector.cpp.

References fCurBitIndex, and fTotNumBits.

Referenced by H264or5VideoStreamParser::analyze_seq_parameter_set_data(), H264or5VideoStreamParser::analyze_video_parameter_set_data(), H264or5VideoStreamParser::analyze_vui_parameters(), MP3HuffmanDecode(), and H264or5VideoStreamParser::profile_tier_level().

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 47 of file BitVector.hh.

References fCurBitIndex.

Referenced by MP3HuffmanDecode().

00047 { return fCurBitIndex; }

unsigned BitVector::totNumBits (  )  const [inline]

Definition at line 48 of file BitVector.hh.

References fTotNumBits.

00048 { return fTotNumBits; }

unsigned BitVector::numBitsRemaining (  )  const [inline]

Definition at line 49 of file BitVector.hh.

References fCurBitIndex, and fTotNumBits.

00049 { return fTotNumBits - fCurBitIndex; }

unsigned BitVector::get_expGolomb (  ) 

Definition at line 130 of file BitVector.cpp.

References fCurBitIndex, fTotNumBits, get1Bit(), and getBits().

Referenced by H264or5VideoStreamParser::analyze_seq_parameter_set_data(), H264or5VideoStreamParser::analyze_video_parameter_set_data(), and H264or5VideoStreamParser::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 }


Field Documentation

unsigned char* BitVector::fBaseBytePtr [private]

Definition at line 55 of file BitVector.hh.

Referenced by get1Bit(), getBits(), put1Bit(), putBits(), and setup().

unsigned BitVector::fBaseBitOffset [private]

Definition at line 56 of file BitVector.hh.

Referenced by get1Bit(), getBits(), put1Bit(), putBits(), and setup().

unsigned BitVector::fTotNumBits [private]

Definition at line 57 of file BitVector.hh.

Referenced by get1Bit(), get_expGolomb(), getBits(), numBitsRemaining(), put1Bit(), putBits(), setup(), skipBits(), and totNumBits().

unsigned BitVector::fCurBitIndex [private]

Definition at line 58 of file BitVector.hh.

Referenced by curBitIndex(), get1Bit(), get_expGolomb(), getBits(), numBitsRemaining(), put1Bit(), putBits(), setup(), and skipBits().


The documentation for this class was generated from the following files:
Generated on Wed Apr 23 16:15:46 2014 for live by  doxygen 1.5.2