inbits.h
资源名称:NETVIDEO.rar [点击查看]
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:3k
源码类别:
流媒体/Mpeg4/MP4
开发平台:
Visual C++
- /*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: inbits.h,v 1.4 2002/03/07 23:04:01 wmay Exp $
- */
- #ifndef __BITS_H__
- #define __BITS_H__ 1
- #include "systems.h"
- extern unsigned int bit_msk[33];
- #define INLINE __inline
- class CInBitStream
- {
- public:
- CInBitStream(void);
- CInBitStream(int istrm);
- ~CInBitStream();
- void init(void);
- int eof() const { return m_orig_buflen == 0; };
- void set_buffer(unsigned char *bptr, uint32_t blen);
- int get_used_bytes(void) { return m_framebits / 8; };
- uint32_t getBits(uint32_t numBits);
- INLINE uint32_t peekBits(uint32_t numBits)
- {
- int rbit;
- uint32_t b;
- check_buffer(numBits);
- rbit = 32 - m_bitcnt;
- #define _SWAP(a) ((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3])
- b = _SWAP(m_rdptr);
- return ((b & bit_msk[rbit]) >> (rbit-numBits));
- };
- int peekOneBit(uint32_t numBits);
- int peekBitsTillByteAlign(int &nBitsToPeek);
- int peekBitsFromByteAlign(int nBitsToPeek);
- Void flush (int nExtraBits = 0);
- INLINE Void setBookmark (void) {
- assert(m_bookmark == 0);
- m_bookmark_rdptr = m_rdptr;
- m_bookmark_bitcnt = m_bitcnt;
- m_bookmark_framebits = m_framebits;
- m_bookmark = 1;
- };
- INLINE Void gotoBookmark (void) {
- assert(m_bookmark == 1);
- m_rdptr = m_bookmark_rdptr;
- m_bitcnt = m_bookmark_bitcnt;
- m_framebits = m_bookmark_framebits;
- m_bookmark = 0;
- };
- void bookmark (Bool bSet);
- private:
- int m_pistrm;
- unsigned char *m_buffer;
- unsigned char *m_rdptr, *m_bookmark_rdptr;
- int m_bitcnt, m_bookmark_bitcnt;
- int m_framebits, m_bookmark_framebits;
- int m_framebits_max;
- uint32_t m_orig_buflen;
- int m_bookmark;
- INLINE void check_buffer (int n) {
- int cmp;
- cmp = m_framebits + n;
- if (cmp > m_framebits_max) {
- if (m_pistrm < 0) {
- throw ((int)1);
- } else {
- read_ifstream_buffer();
- }
- }
- };
- INLINE void flushbits(int n)
- {
- m_bitcnt += n;
- if (m_bitcnt >= 8) {
- m_rdptr += (m_bitcnt>>3);
- m_bitcnt &= 7;
- }
- m_framebits += n;
- };
- void read_ifstream_buffer(void);
- };
- #endif