cachobj.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 606 行 · 第 1/2 页

CPP
606
字号
    return HXR_OK;
}

HX_RESULT 
HXFIFOCache::CacheClientPacket(IHXClientPacket* pClientPacket)
{
    HX_RESULT	theErr = HXR_OK;
    BOOL	bContiguousDataPointer = FALSE;
    UINT32	ulBytesWrote = 0;
    UINT32	ulBytesToWrite = 0;
    char*	pData = NULL;
    char*	pCursor = NULL;
#if !defined(HELIX_FEATURE_FULLGUID)
    GUID	tmp = IID_IHXClientPacket;
#endif
    if (!pClientPacket)
    {
	theErr = HXR_FAILED;
	goto cleanup;
    }

    // caculate the size of client packet
    ClientPacket::Pack(pClientPacket, NULL, ulBytesToWrite);
    ulBytesToWrite += sizeof(ChunkyCacheLayout);

    // check whether we have cont. memory chunk of the size needed
    if (HXR_OK == m_pChunkyRes->GetContiguousDataPointer(m_ulCurrentWritePosition,
							 pData,
							 ulBytesToWrite) && pData)
    {	
	bContiguousDataPointer = TRUE;
	pCursor = pData;
    }
    // otherwise we allocated our own
    else
    {
	pData = new char[ulBytesToWrite];
	pCursor = pData;
    }

    // total chunk bytes
    *pCursor++ = (BYTE)ulBytesToWrite; *pCursor++ = (BYTE)(ulBytesToWrite >> 8);
    ulBytesWrote += 2;
    // GUID
#if !defined(HELIX_FEATURE_FULLGUID)
    memcpy(pCursor, (char*)&tmp, sizeof(GUID)); /* Flawfinder: ignore */
#else
    memcpy(pCursor, (char*)&IID_IHXClientPacket, sizeof(GUID)); /* Flawfinder: ignore */
#endif
    pCursor += sizeof(GUID);
    ulBytesWrote += sizeof(GUID);

    // pack data
    ClientPacket::Pack(pClientPacket, pCursor, ulBytesWrote);	

    if (!bContiguousDataPointer)
    {
	// let the memory manager take care of the contingency
	theErr = m_pChunkyRes->SetData(m_ulCurrentWritePosition, pData, ulBytesWrote);
    }

    HX_ASSERT(ulBytesToWrite == ulBytesWrote);
    // advance the write cursor
    m_ulCurrentWritePosition += ulBytesToWrite;

cleanup:

    if (!bContiguousDataPointer)
    {
	HX_VECTOR_DELETE(pData);
    }

    return theErr;
}

HX_RESULT 
HXFIFOCache::CacheTimestampBuffer(IHXTimeStampedBuffer* pTimeStampBuffer)
{
    HX_RESULT	theErr = HXR_OK;
    BOOL	bContiguousDataPointer = FALSE;
    UINT32	ulBytesWrote = 0;
    UINT32	ulBytesToWrite = 0;
    char*	pData = NULL;
    char*	pCursor = NULL;
#if !defined(HELIX_FEATURE_FULLGUID)
    GUID	tmp = IID_IHXBuffer;
#endif

    if (!pTimeStampBuffer)
    {
	theErr = HXR_FAILED;
	goto cleanup;
    }

    // caculate the size of buffer
    CHXTimeStampedBuffer::Pack(pTimeStampBuffer, NULL, 0, ulBytesToWrite);
    ulBytesToWrite += sizeof(ChunkyCacheLayout);

    // check whether we have cont. memory chunk of the size needed
    if (HXR_OK == m_pChunkyRes->GetContiguousDataPointer(m_ulCurrentWritePosition,
							 pData,
							 ulBytesToWrite) && pData)
    {	
	bContiguousDataPointer = TRUE;
	pCursor = pData;
    }
    // otherwise we allocated our own
    else
    {
	pData = new char[ulBytesToWrite];
	pCursor = pData;
    }

    // total chunk bytes
    *pCursor++ = (BYTE)ulBytesToWrite; *pCursor++ = (BYTE)(ulBytesToWrite >> 8);
    ulBytesWrote += 2;
    // GUID
#if !defined(HELIX_FEATURE_FULLGUID)
    memcpy(pCursor, (char*)&tmp, sizeof(GUID)); /* Flawfinder: ignore */
#else
    memcpy(pCursor, (char*)&IID_IHXBuffer, sizeof(GUID)); /* Flawfinder: ignore */
#endif
    pCursor += sizeof(GUID);
    ulBytesWrote += sizeof(GUID);

    // pack data
    CHXTimeStampedBuffer::Pack(pTimeStampBuffer, pCursor,
                               ulBytesToWrite - ulBytesWrote, ulBytesWrote);	

    if (!bContiguousDataPointer)
    {
	// let the memory manager take care of the contingency
	theErr = m_pChunkyRes->SetData(m_ulCurrentWritePosition, pData, ulBytesWrote);
    }

    HX_ASSERT(ulBytesToWrite == ulBytesWrote);
    // advance the write cursor
    m_ulCurrentWritePosition += ulBytesToWrite;

cleanup:

    if (!bContiguousDataPointer)
    {
	HX_VECTOR_DELETE(pData);
    }

    return theErr;
}

HX_RESULT 
HXFIFOCache::CacheBuffer(IHXBuffer* pBuffer)
{
    HX_RESULT	theErr = HXR_OK;
    BOOL	bContiguousDataPointer = FALSE;
    UINT32	ulBytesWrote = 0;
    UINT32	ulBytesToWrite = 0;
    char*	pData = NULL;
    char*	pCursor = NULL;
#if !defined(HELIX_FEATURE_FULLGUID)
    GUID	tmp = IID_IHXBuffer;
#endif

    if (!pBuffer)
    {
	theErr = HXR_FAILED;
	goto cleanup;
    }

    // caculate the size of client packet
    ulBytesToWrite = pBuffer->GetSize();
    ulBytesToWrite += sizeof(ChunkyCacheLayout);

    // check whether we have cont. memory chunk of the size needed
    if (HXR_OK == m_pChunkyRes->GetContiguousDataPointer(m_ulCurrentWritePosition,
							 pData,
							 ulBytesToWrite) && pData)
    {	
	bContiguousDataPointer = TRUE;
	pCursor = pData;
    }
    // otherwise we allocated our own
    else
    {
	pData = new char[ulBytesToWrite];
	pCursor = pData;
    }

    // total chunk bytes
    *pCursor++ = (BYTE)ulBytesToWrite; *pCursor++ = (BYTE)(ulBytesToWrite >> 8);
    ulBytesWrote += 2;
    // GUID
#if !defined(HELIX_FEATURE_FULLGUID)
    memcpy(pCursor, (char*)&tmp, sizeof(GUID)); /* Flawfinder: ignore */
#else
    memcpy(pCursor, (char*)&IID_IHXBuffer, sizeof(GUID)); /* Flawfinder: ignore */
#endif
    pCursor += sizeof(GUID);
    ulBytesWrote += sizeof(GUID);

    // pack data
    memcpy(pCursor, (char*)pBuffer->GetBuffer(), pBuffer->GetSize()); /* Flawfinder: ignore */

    if (!bContiguousDataPointer)
    {
	// let the memory manager take care of the contingency
	theErr = m_pChunkyRes->SetData(m_ulCurrentWritePosition, pData, ulBytesWrote);
    }

    HX_ASSERT(ulBytesToWrite == ulBytesWrote);
    // advance the write cursor
    m_ulCurrentWritePosition += ulBytesToWrite;

cleanup:

    if (!bContiguousDataPointer)
    {
	HX_VECTOR_DELETE(pData);
    }

    return theErr;
}

HX_RESULT 
HXFIFOCache::CachePacket(IHXPacket* pPacket)
{
    HX_RESULT	theErr = HXR_OK;
    BOOL	bContiguousDataPointer = FALSE;
    UINT32	ulBytesWrote = 0;
    UINT32	ulBytesToWrite = 0;
    char*	pData = NULL;
    char*	pCursor = NULL;
#if !defined(HELIX_FEATURE_FULLGUID)
    GUID	tmp = IID_IHXPacket;
#endif

    if (!pPacket)
    {
	theErr = HXR_FAILED;
	goto cleanup;
    }

    // caculate the size of client packet
    CHXPacket::Pack(pPacket, NULL, ulBytesToWrite);
    ulBytesToWrite += sizeof(ChunkyCacheLayout);

    // check whether we have cont. memory chunk of the size needed
    if (HXR_OK == m_pChunkyRes->GetContiguousDataPointer(m_ulCurrentWritePosition,
							 pData,
							 ulBytesToWrite) && pData)
    {	
	bContiguousDataPointer = TRUE;
	pCursor = pData;
    }
    // otherwise we allocated our own
    else
    {
	pData = new char[ulBytesToWrite];
	pCursor = pData;
    }

    // total chunk bytes
    *pCursor++ = (BYTE)ulBytesToWrite; *pCursor++ = (BYTE)(ulBytesToWrite >> 8);
    ulBytesWrote += 2;
    // GUID
#if !defined(HELIX_FEATURE_FULLGUID)
    memcpy(pCursor, (char*)&tmp, sizeof(GUID)); /* Flawfinder: ignore */
#else
    memcpy(pCursor, (char*)&IID_IHXPacket, sizeof(GUID)); /* Flawfinder: ignore */
#endif
    pCursor += sizeof(GUID);
    ulBytesWrote += sizeof(GUID);

    // pack data
    CHXPacket::Pack(pPacket, pCursor, ulBytesWrote);	

    if (!bContiguousDataPointer)
    {
	// let the memory manager take care of the contingency
	theErr = m_pChunkyRes->SetData(m_ulCurrentWritePosition, pData, ulBytesWrote);
    }

    HX_ASSERT(ulBytesToWrite == ulBytesWrote);
    // advance the write cursor
    m_ulCurrentWritePosition += ulBytesToWrite;

cleanup:

    if (!bContiguousDataPointer)
    {
	HX_VECTOR_DELETE(pData);
    }

    return theErr;
}

HX_RESULT 
HXFIFOCache::CacheValues(IHXValues* pValues)
{
    // TBD
    HX_RESULT theErr = HXR_NOTIMPL;
    return theErr;
}

⌨️ 快捷键说明

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