1
0

bitstream.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /***************************************************************************\
  2. *
  3. * MPEG Layer3-Audio Decoder
  4. * © 1997-2006 by Fraunhofer IIS
  5. * All Rights Reserved
  6. *
  7. * filename: bitstream.h
  8. * project : MPEG Decoder
  9. * author : Martin Sieler
  10. * date : 1997-12-05
  11. * contents/description: generic bitbuffer - HEADER
  12. *
  13. *
  14. \***************************************************************************/
  15. /*
  16. * $Date: 2011/01/18 18:22:02 $
  17. * $Id: bitstream.h,v 1.4 2011/01/18 18:22:02 audiodsp Exp $
  18. */
  19. #ifndef __BITSTREAM_H__
  20. #define __BITSTREAM_H__
  21. /* ------------------------ includes --------------------------------------*/
  22. /*-------------------------- defines --------------------------------------*/
  23. class CGioBase;
  24. /*-------------------------------------------------------------------------*/
  25. //
  26. // Bitstream input class.
  27. //
  28. // This class defines the interface that the mp3 decoder object will
  29. // read all of its bitstream input data from.
  30. //
  31. class CBitStream
  32. {
  33. public:
  34. CBitStream(int cbSize);
  35. CBitStream(unsigned char *pBuf, int cbSize, bool fDataValid = false);
  36. virtual ~CBitStream();
  37. virtual void Reset();
  38. bool ByteAligned() const { return !(m_BitNdx & 7); }
  39. bool ResetOccurred() { return m_ResetOccurred; }
  40. void SetResetState(bool state) { m_ResetOccurred = state; }
  41. void Connect(CGioBase *pGB);
  42. void ResetBitCnt() { m_BitCnt = 0; }
  43. int GetBitCnt() const { return m_BitCnt; }
  44. unsigned int GetBits(unsigned int nBits); // gets 16 bits or less
  45. unsigned int GetBits8(unsigned int nBits); // gets 8 bits or less
  46. unsigned int Get1Bit();
  47. unsigned long Get32Bits();
  48. bool Ff(int nBits) { return ( (nBits > 0) ? Seek(nBits) : false); }
  49. bool Rewind(int nBits) { return ( (nBits > 0) ? Seek(-nBits) : false); }
  50. bool Seek(int nBits)
  51. {
  52. m_BitCnt += nBits;
  53. m_ValidBits -= nBits;
  54. m_BitNdx = (m_BitNdx+nBits) & m_bitMask;
  55. return true;
  56. }
  57. int GetValidBits() const { return m_ValidBits; }
  58. int GetFree() const;
  59. void SetEof();
  60. int Fill(const unsigned char *pBuf, int cbSize);
  61. int Fill(CBitStream &Bs, int cbSize);
  62. protected:
  63. int Refill();
  64. bool IsEof() const;
  65. bool IsConnected() const;
  66. private:
  67. CGioBase *m_pGB; // I/O object
  68. int m_nBytes; // size of buffer in bytes
  69. int m_mask;
  70. int m_nBits; // size of buffer in bits
  71. int m_bitMask;
  72. int m_ValidBits; // valid bits in buffer
  73. int m_ReadOffset; // where to write next
  74. int m_BitCnt; // bit counter
  75. int m_BitNdx; // position of next bit in byte
  76. bool m_fEof; // indication of input eof
  77. unsigned char *m_Buf; // the buffer
  78. bool m_fBufferIntern; // did we allocate the buffer ourselves
  79. bool m_ResetOccurred; // reset just occurred, only for dynamic buffer used
  80. };
  81. /*-------------------------------------------------------------------------*/
  82. #endif