Example #1
0
bool 
NALUnit::Parse(const BYTE* pBuffer, int cSpace, int LengthSize, bool bEnd)
{
    // if we get the start code but not the whole
    // NALU, we can return false but still have the length property valid
    m_cBytes = 0;

    ResetBitstream();

    if (LengthSize > 0)
    {
		m_pStartCodeStart = pBuffer;

        if (LengthSize > cSpace)
        {
            return false;
        }

        m_cBytes = 0;
        for (int i = 0; i < LengthSize; i++)
        {
            m_cBytes <<= 8;
            m_cBytes += *pBuffer++;
        }

        if ((m_cBytes+LengthSize) <= cSpace)
        {
            m_pStart = pBuffer;
            return true;
        }
    } else {
        // this is not length-delimited: we must look for start codes
        const BYTE* pBegin;
        if (GetStartCode(pBegin, pBuffer, cSpace))
        {
            m_pStart = pBuffer;
			m_pStartCodeStart = pBegin;

            // either we find another startcode, or we continue to the
            // buffer end (if this is the last block of data)
            if (GetStartCode(pBegin, pBuffer, cSpace))
            {
                m_cBytes = int(pBegin - m_pStart);
                return true;
            } else if (bEnd)
            {
                // current element extends to end of buffer
                m_cBytes = cSpace;
                return true;
            }
        }
    }
    return false;
}
Example #2
0
bool 
NALUnit::Parse(const BYTE* pBuffer, int cSpace, int LengthSize, bool bEnd)
{
    m_cBytes = 0;

    ResetBitstream();

    if (LengthSize > 0)
    {
		m_pStartCodeStart = pBuffer;

        if (LengthSize > cSpace)
        {
            return false;
        }

        m_cBytes = 0;
        for (int i = 0; i < LengthSize; i++)
        {
            m_cBytes <<= 8;
            m_cBytes += *pBuffer++;
        }

        if ((m_cBytes+LengthSize) <= cSpace)
        {
            m_pStart = pBuffer;
            return true;
        }
    } else {
       
        const BYTE* pBegin;
        if (GetStartCode(pBegin, pBuffer, cSpace))
        {
            m_pStart = pBuffer;
			m_pStartCodeStart = pBegin;

            
            if (GetStartCode(pBegin, pBuffer, cSpace))
            {
                m_cBytes = int(pBegin - m_pStart);
                return true;
            } else if (bEnd)
            {
                
                m_cBytes = cSpace;
                return true;
            }
        }
    }
    return false;
}