⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umc_avs_dec_byte_stream.h

📁 audio-video-codecs.rar语音编解码器
💻 H
字号:
/*
//
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2007 Intel Corporation. All Rights Reserved.
//
//
*/

#ifndef __UMC_AVS_DEC_BYTE_STREAM_H
#define __UMC_AVS_DEC_BYTE_STREAM_H

#include "ippdefs.h"
#include "umc_structures.h"

namespace UMC
{

//
// This class was designed to parse headers only.
// Headers shall not have 'start code emulation preventing' bits,
// so we can use simplified bitstream parsing for them.
//

class AVSByteStream
{
public:
    // Default constructor
    AVSByteStream(void)
    {
        m_nBits = 0;
        m_iBitsNum = 0;

        m_pSource = (Ipp8u *) 0;
    }

    // Destructor
    ~AVSByteStream(void)
    {
        Close();
    }

    // Initialize the bit stream
    Status Init(Ipp8u *pSource, size_t nSize)
    {
        m_nBits = 0;
        m_iBitsNum = 0;

        if (NULL == pSource)
            return UMC_ERR_INVALID_PARAMS;

        m_pSource = pSource;
        m_pSourceEnd = pSource + nSize;

        return UMC_OK;
    }

    // Release the object
    Status Close(void)
    {
        // check used amount of bit stream
        if ((m_pSource < m_pSourceEnd) ||
            ((m_pSource - m_pSourceEnd) * 8 <= m_iBitsNum))
            return UMC_OK;

        return UMC_ERR_FAILED;
    }

    // Get bit from the bit stream
    Ipp32u GetBit(void)
    {
        if (0 > m_iBitsNum)
            UploadBits();

        m_iBitsNum -= 1;
        return ((m_nBits >> m_iBitsNum) & 1);
    }

    // Get bits from the bit stream
    Ipp32u GetBits(Ipp32s iNum)
    {
        if (24 < iNum)
            return 0;

        if (m_iBitsNum < iNum)
            UploadBits();

        m_iBitsNum -= iNum;
        return ((m_nBits >> m_iBitsNum) & ~(-1 << iNum));
    }

    void SkipBits(Ipp32s iNum)
    {
        m_iBitsNum -= iNum;

        if (m_iBitsNum < iNum)
            UploadBits();
    }

protected:
    // Upload bits
    void UploadBits(void)
    {
        while (24 >= m_iBitsNum)
        {
            m_nBits = (m_nBits << 8) | m_pSource[0];
            m_iBitsNum += 8;
            m_pSource += 1;
        }
    }

    Ipp32u m_nBits;
    Ipp32s m_iBitsNum;

    Ipp8u *m_pSource;
    Ipp8u *m_pSourceEnd;
};

} // namespace UMC

#endif // __UMC_AVS_DEC_BYTE_STREAM_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -