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

📄 sdpparse_test.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    {
	DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleStringCountCmd : failed to convert parameter\n"));	
    }
    else if (valueIndex >= m_nValues)
    {
	DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleStringCountCmd : invalid value index\n"));
    }
    else
    {
	IHXValues* pHdr = m_ppValues[valueIndex];
	unsigned int ulCount = 0;

	const char* pName = 0;
	IHXBuffer* pValue = 0;
	HX_RESULT res = pHdr->GetFirstPropertyCString(pName, pValue);

	while (HXR_OK == res)
	{
	    //DPRINTF (D_ERROR, ("String %s -> '%s'\n", 
	    //		       pName, 
	    //		       pValue->GetBuffer()));
	    ulCount++;

	    HX_RELEASE(pValue);

	    res = pHdr->GetNextPropertyCString(pName, pValue);
	}

	HX_RELEASE(pValue);

	if (ulCount != expectedCount)
	{
	    DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleStringCountCmd : expected %lu, got %lu\n",
			      expectedCount, ulCount));
	}
	else
	{
	    ret = true;
	}
    }

    return ret;
}

bool SDPMediaDescParserTest::HandleBufferCountCmd(const UTVector<UTString>& info)
{    
    bool ret = false;

    unsigned int valueIndex = 0;
    unsigned int expectedCount = 0;

    
    //DPRINTF (D_ERROR, ("-=#=-=#=-\n"));

    if (!UTParamUtil::GetUInt(info[1], valueIndex) ||
	!UTParamUtil::GetUInt(info[2], expectedCount))
    {
	DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleBufferCountCmd : failed to convert parameter\n"));	
    }
    else if (valueIndex >= m_nValues)
    {
	DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleBufferCountCmd : invalid value index\n"));
    }
    else
    {
	IHXValues* pHdr = m_ppValues[valueIndex];
	unsigned int ulCount = 0;

	const char* pName = 0;
	IHXBuffer* pValue = 0;
	HX_RESULT res = pHdr->GetFirstPropertyBuffer(pName, pValue);

	while (HXR_OK == res)
	{
	    //PrintBuffer(pName, pValue);

	    ulCount++;

	    HX_RELEASE(pValue);

	    res = pHdr->GetNextPropertyBuffer(pName, pValue);
	}

	HX_RELEASE(pValue);

	if (ulCount != expectedCount)
	{
	    DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleBufferCountCmd : expected %lu, got %lu\n",
			      expectedCount, ulCount));
	}
	else
	{
	    ret = true;
	}
    }

    return ret;
}

bool SDPMediaDescParserTest::HandleGetIntCmd(const UTVector<UTString>& info)
{
    bool ret = false;

    unsigned int valueIndex = 0;
    unsigned int expectedValue = 0;

    if (!UTParamUtil::GetUInt(info[1], valueIndex) ||
	!UTParamUtil::GetUInt(info[3], expectedValue))
    {
	DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetIntCmd : failed to convert parameter\n"));	
    }
    else if (valueIndex >= m_nValues)
    {
	DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetIntCmd : invalid value index\n"));
    }
    else
    {
	IHXValues* pHdr = m_ppValues[valueIndex];

	ULONG32 ulValue = 0;
	HX_RESULT res = pHdr->GetPropertyULONG32(info[2], ulValue);

	if (HXR_OK != res)
	{
	    DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetIntCmd : get failed\n"));
	}
	else if (ulValue != expectedValue)
	{
	    DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetIntCmd : expected %lu, got %lu\n",
			      expectedValue, ulValue));
	}
	else
	{
	    ret = true;
	}
    }

    return ret;
}

bool SDPMediaDescParserTest::HandleGetStringCmd(const UTVector<UTString>& info)
{
    bool ret = false;

    unsigned int valueIndex = 0;

    if (!UTParamUtil::GetUInt(info[1], valueIndex))
    {
	DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetStringCmd : failed to convert parameter\n"));	
    }
    else if (valueIndex >= m_nValues)
    {
	DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetStringCmd : invalid value index\n"));
    }
    else
    {
	IHXValues* pHdr = m_ppValues[valueIndex];

	IHXBuffer* pValue = 0;
	HX_RESULT res = pHdr->GetPropertyCString(info[2], pValue);

	if (HXR_OK != res)
	{
	    DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetStringCmd : get failed\n"));
	}
	else if (strcmp((const char*)pValue->GetBuffer(), info[3]))
	{
	    DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetStringCmd : expected '%s', got '%s'\n",
			      (const char*)info[3], 
			      (const char*)pValue->GetBuffer()));
	}
	else
	{
	    ret = true;
	}

	HX_RELEASE(pValue);
    }

    return ret;
}

bool SDPMediaDescParserTest::HandleGetBufferCmd(const UTVector<UTString>& info)
{
    bool ret = false;

    unsigned int valueIndex = 0;
    IHXBuffer* pExpected = 0;

    if (!UTParamUtil::GetUInt(info[1], valueIndex) ||
	!GetBuffer(info[3], pExpected))
    {
	DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetBufferCmd : failed to convert parameter\n"));	
    }
    else if (valueIndex >= m_nValues)
    {
	DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetBufferCmd : invalid value index\n"));
    }
    else
    {
	IHXValues* pHdr = m_ppValues[valueIndex];

	IHXBuffer* pValue = 0;
	HX_RESULT res = pHdr->GetPropertyBuffer(info[2], pValue);

	if (HXR_OK != res)
	{
	    DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetBufferCmd : get failed\n"));
	}
	else if (pValue->GetSize() != pExpected->GetSize())
	{
	    DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetBufferCmd : size expected %lu, got %lu\n",
			      pExpected->GetSize(),
			      pValue->GetSize()));
	}
	else if (memcmp(pValue->GetBuffer(), pExpected->GetBuffer(), 
			pValue->GetSize()))
	{
	    DPRINTF(D_ERROR, ("SDPMediaDescParserTest::HandleGetBufferCmd : buffers don't match\n"));
	}
	else
	{
	    ret = true;
	}

	HX_RELEASE(pValue);
    }

    HX_RELEASE(pExpected);

    return ret;
}

static int Char2Num(char ch)
{
    int ret = -1;

    if ((ch >= '0') && (ch <= '9'))
	ret = ch - '0';
    else if ((ch >= 'a') && (ch <= 'f'))
	ret = ch - 'a' + 10;
    else if ((ch >= 'A') && (ch <= 'F'))
	ret = ch - 'A' + 10;

    return ret;
}

bool SDPMediaDescParserTest::GetBuffer(const char* pStr, 
				       IHXBuffer*& pValue) const
{
    bool ret = false;

    int length = strlen(pStr);

    if (m_pCCF && (length > 0) && ((length & 0x1) == 0) &&
	(HXR_OK == m_pCCF->CreateInstance(CLSID_IHXBuffer, (void**)&pValue))&&
	(HXR_OK == pValue->SetSize(length / 2)))
    {
	ret = true;

	unsigned char* pDest = pValue->GetBuffer();

	while(ret && *pStr)
	{
	    int high = Char2Num(*pStr++);
	    int low = Char2Num(*pStr++);

	    if ((high == -1) || (low == -1))
	    {
		ret = false;
	    }
	    else
	    {
		*pDest++ = (unsigned char)((high << 4) | low);
	    }
	}
    }

    if (!ret)
    {
	HX_RELEASE(pValue);
    }

    return ret;
}

void SDPMediaDescParserTest::PrintBuffer(const char* pLabel, 
					 IHXBuffer* pBuf) const
{
    IHXBuffer* pStrBuf = 0;

    if (m_pCCF &&
	(HXR_OK == m_pCCF->CreateInstance(CLSID_IHXBuffer, (void**)&pStrBuf))&&
	(HXR_OK == pStrBuf->SetSize(pBuf->GetSize() * 2 + 1)))
    {
	static const char z_hexChars[] = "0123456789abcdef";
	
	UINT8* pSrc = pBuf->GetBuffer();
	char* pDest = (char*)pStrBuf->GetBuffer();
	
	for (ULONG32 i = 0; i < pBuf->GetSize(); i++)
	{
	    *pDest++ = z_hexChars[*pSrc >> 4];
	    *pDest++ = z_hexChars[*pSrc++ & 0xf];
	}
	*pDest = '\0';

	DPRINTF (D_ERROR, ("%s '%s'\n", 
			   pLabel, (const char*)pStrBuf->GetBuffer()));
    }

    HX_RELEASE(pStrBuf);
}

void SDPMediaDescParserTest::DestroyValues()
{
    if (m_ppValues)
    {
	for (UINT16 i = 0; i < m_nValues; i++)
	{
	    HX_RELEASE(m_ppValues[i]);
	}
    }

    m_nValues = 0;

    delete [] m_ppValues;
    m_ppValues = 0;
}

⌨️ 快捷键说明

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