Пример #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;
}
Пример #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;
}
Пример #3
0
///////////////////////////////////////////////////////////////////////////////
// Function:    Demux_ul
// Returns:     The number of bytes processed
///////////////////////////////////////////////////////////////////////////////
UINT32 CDemuxer::Demux_ul(UINT8 *pBuffer,
                             UINT32 ulBytes,
                             Packet *pPacket)
{
    UINT8       *pTemp = (UINT8*)pBuffer;
    UINT32      ulTemp = ulBytes;
    INT32       lCode = 0;

    memset(pPacket, 0, sizeof(Packet));

    UINT8 bCont = TRUE;

    while (ulTemp >= 4 && bCont)
    {
        lCode = GetStartCode(&pTemp, ulTemp);

        switch (lCode)
        {
            case -1:
                bCont = FALSE;
                break;

            case PACK_HEADER:
            {
	            m_pPack = pTemp;

                pTemp+=4;
	            ulTemp-=4;

                // Is this MPEG1 or MPEG2
                UINT8 yNext = *pTemp & 0xF0;

                // Check for MPEG1 or MPEG2.
                // In MPEG2 files, '0100' follows pack_start_code and
                // in MPEG1 files, '0010' follows pack_start_code.
                if ((yNext & 0xC0) == 0x40)
                    m_bMPEG2 = TRUE;
                else
                    m_bMPEG2 = FALSE;

                break;
            }

            default:
                // PRIVATE_STREAM_1
                // VIDEO_PACKET
                // AUDIO_PACKET
                if ( PRIVATE_STREAM_1 == lCode ||
                    (lCode & 0x000000F0) == 0xE0 ||
                    (lCode & 0x000000E0) == 0xC0)
                {
                    if (ProcessPacket(&pTemp, ulTemp, pPacket))
                    {
                        bCont = FALSE;
                    }
                }
                else
                {
                    pTemp+=4;
	                ulTemp-=4;
                }

                break;
        }
	}


    return (UINT32)(PTR_INT)(pTemp - pBuffer);
}