예제 #1
0
파일: CommRtpServer.cpp 프로젝트: mycp/mycp
	// OnRtpHandler
	virtual void onReceiveEvent(CRTPData::pointer receiveData, DoRtpHandler::pointer pDoRtpHandler, void * rtpParam)
	{
		BOOST_ASSERT (receiveData.get() != 0);
		if (m_commHandler.get() != NULL)
		{
			// ?
			unsigned long destIp = receiveData->destip();
			unsigned int  destPort = receiveData->destport();
			u_long remoteAddrHash = destIp + destPort;

			cgcRemote::pointer pCgcRemote;
			if (!m_mapCgcRemote.find(remoteAddrHash, pCgcRemote, false))
			{
				pCgcRemote = cgcRemote::pointer(new CcgcRemote(destIp, destPort, (CRemoteHandler*)this, m_pDoRtpHandler));
				m_mapCgcRemote.insert(remoteAddrHash, pCgcRemote);
			}else if (pCgcRemote->isInvalidate())
			{
				m_mapCgcRemote.remove(remoteAddrHash);
				pCgcRemote = cgcRemote::pointer(new CcgcRemote(destIp, destPort, (CRemoteHandler*)this, m_pDoRtpHandler));
				m_mapCgcRemote.insert(remoteAddrHash, pCgcRemote);
			}else
			{
				((CcgcRemote*)pCgcRemote.get())->SetRemote(destIp, destPort);
			}
			CRtpRemoteInfo::pointer pEventData = CRtpRemoteInfo::create(CCommEventData::CET_Recv);
			pEventData->setRemote(pCgcRemote);
			pEventData->setRemoteId(pCgcRemote->getRemoteId());
			pEventData->recvdata(receiveData);
			m_listMgr.add(pEventData);
		}
	}
예제 #2
0
void CConferenceInfo::onReceiveEvent(CRTPData::pointer receiveData, DoRtpHandler::pointer pDoRtpHandler, void * rtpParam)
{
	BOOST_ASSERT (receiveData.get() != NULL);
	BOOST_ASSERT (pDoRtpHandler.get() != NULL);
	BOOST_ASSERT (rtpParam != NULL);

	CConferenceMember * pDataConferenceMember = (CConferenceMember*)rtpParam;
	if (pDataConferenceMember->getClosed() || pDataConferenceMember->getAudioHandler() == 0 || pDataConferenceMember->getVideoHandler() == 0)
		return;

	if (receiveData->size() == 4)
	{
		if (pDataConferenceMember->getAudioHandler().get() == pDoRtpHandler.get())
		{
			pDataConferenceMember->getAudioHandler()->doClearDest();
			pDataConferenceMember->getAudioHandler()->doAddDest(receiveData->destip(), receiveData->destport());
		}else if (pDataConferenceMember->getVideoHandler().get() == pDoRtpHandler.get())
		{
			pDataConferenceMember->getVideoHandler()->doClearDest();
			pDataConferenceMember->getVideoHandler()->doAddDest(receiveData->destip(), receiveData->destport());
		}
		return;
	}

	if (!pDataConferenceMember->getAudioSend() && pDataConferenceMember->getAudioHandler() == pDoRtpHandler)
	{
		// member audio closed
		return;
	}else if (!pDataConferenceMember->getVideoSend() && pDataConferenceMember->getVideoHandler() == pDoRtpHandler)
	{
		// member video closed
		return;
	}

	bool is_audioData = pDataConferenceMember->getAudioHandler() == pDoRtpHandler;
	if (is_audioData)
	{
		// decode PCM audio

		short v1 = 0;
		short v2 = 0;
		bool has_voice = false;
		switch (receiveData->payloadtype())
		{
		case 8:
			{
				long size = receiveData->size();
				unsigned char * tempBuffer = new unsigned char[size * 2];
				G711Coder::DecodeA((short*)tempBuffer, receiveData->data(), size);
				receiveData->data(tempBuffer, size * 2);

				has_voice = v1 > Default_Silence_Value1 || v2 < Default_Silence_Value2;
			}break;
		case 0:
			{
				long size = receiveData->size();
				unsigned char * tempBuffer = new unsigned char[size * 2];
				G711Coder::DecodeU((short*)tempBuffer, receiveData->data(), size, &v1, &v2);
				receiveData->data(tempBuffer, size * 2);

				has_voice = v1 > Default_Silence_Value1 || v2 < Default_Silence_Value2;
				//if (v1 > Default_Silence_Value1 || v2 < Default_Silence_Value2)
				//{
				//	int i = 0;
				//}
			}break;
		case 18:
			{
				long size = receiveData->size();
				unsigned char * tempBuffer = new unsigned char[(int)(size * (80.0/10.0)*2)];
				m_g729a.g729a_decoder(receiveData->data(), size, (short*)tempBuffer, &v1, &v2);
				receiveData->data(tempBuffer, (long)(size*(80.0/10.0)*2));

				has_voice = v1 > Default_Silence_Value1 || v2 < Default_Silence_Value2;
			}break;
		default:
			break;
		}
		pDataConferenceMember->setRecvDataTime();
		m_datasa.add(CMemberData::create(receiveData, pDoRtpHandler, rtpParam, !has_voice));
	}else
	{
		m_datasv.add(CMemberData::create(receiveData, pDoRtpHandler, rtpParam));
	}

}