Пример #1
0
void CConferenceInfo::sendVideoFrame(CMemberData::pointer memberData)
{
	BOOST_ASSERT (memberData.get() != 0);

	boost::mutex::scoped_lock lock(m_members.mutex());
	CConferenceMember * pDataConferenceMember = (CConferenceMember*)memberData->getRtpParam();
	if (pDataConferenceMember->getClosed()) return;

	BOOST_ASSERT (pDataConferenceMember->getVideoHandler().get() == memberData->getDoRtpHandler().get());
	CLockMap<void*, CConferenceMember::pointer>::iterator iter;
	for (iter=m_members.begin(); iter!= m_members.end(); iter++)
	{
		// don't send to owner
		//if (pDataConferenceMember == iter->second.get())
		//	continue;

		// member don't receive video
		if (!iter->second->getVideoRecv())
			continue;

		// The user don't receive this member video
		if (iter->second->getRecvIndex() != pDataConferenceMember->getIndex()) 
		{
			continue;
		}

		int timestamp = memberData->getRtpData()->timestamp();
		//int timestamp = 0;
		DoRtpHandler::pointer pDoRtpHandler = iter->second->getVideoHandler();
		pDoRtpHandler->doSendData(memberData->getRtpData()->data(), memberData->getRtpData()->size(), timestamp);
	}
}
Пример #2
0
void CConferenceInfo::sendAudioFrame(const CLockMap<CConferenceMember*, CMemberData::pointer> & audios)
{
	if (audios.empty()) return;

	boost::mutex::scoped_lock lock(m_members.mutex());
	CLockMap<void*, CConferenceMember::pointer>::iterator iter;
	for (iter=m_members.begin(); iter!= m_members.end(); iter++)
	{
		// member don't receive audio
		if (!iter->second->getAudioRecv())
			continue;

		int timestamp = 0;
		if (mix_member_frame(iter->second, audios, timestamp))
		{
			DoRtpHandler::pointer pDoRtpHandler = iter->second->getAudioHandler();

			long sendSize = 0;
			unsigned char * tempBuffer = 0;
			encode_audio(pDoRtpHandler->doGetMediaType(), iter->second->audioBuffer(), &tempBuffer, sendSize);

			//int timestamp = 0;			
			pDoRtpHandler->doSendData(tempBuffer, sendSize, timestamp);
			delete[] tempBuffer;
		}
	}

}
Пример #3
0
	virtual void invalidate(bool bClose)
	{
		if (m_pDoRtpHandler.get() != NULL)
		{
			if (bClose)
				m_handler->onInvalidate(m_pDoRtpHandler);
			m_pDoRtpHandler.reset();
		}
	}
Пример #4
0
	virtual int sendData(const unsigned char * data, size_t size)
	{
		BOOST_ASSERT(data != 0);
		if (isInvalidate()) return -1;

		m_pDoRtpHandler->doClearDest();
		m_pDoRtpHandler->doAddDest(m_destIp, m_destPort);
		return m_pDoRtpHandler->doSendData(data, size, 0);
	}
Пример #5
0
void CRtp::stopRtp(DoRtpHandler::pointer handler)
{
	CRtpProxy::pointer rtpProxy;
	if (m_rtpProxy.find(handler.get(), rtpProxy, true))
	{
		//handler->doSetRtpHandler(0);
		rtpProxy->DestroySession();
		handler->doSetRtpHandler(0);
	}
}
Пример #6
0
	virtual bool initService(cgcValueInfo::pointer parameter)
	{
		if (m_commHandler.get() == NULL) return false;
		if (m_bServiceInited) return true;

		if (parameter.get() != NULL && parameter->getType() == cgcValueInfo::TYPE_VECTOR)
		{
			const std::vector<cgcValueInfo::pointer>& lists = parameter->getVector();
			if (lists.size() > 2)
				m_protocol = lists[2]->getInt();
			if (lists.size() > 1)
				m_capacity = lists[1]->getInt();
			if (lists.size() > 0)
				m_commPort = lists[0]->getInt();
			else
				return false;
		}

		if (m_pDoRtpHandler.get() == 0)
		{
			m_pDoRtpHandler = m_rtpService->startRtp(m_commPort);
			if (m_pDoRtpHandler.get() == 0)
				return false;
			m_pDoRtpHandler->doSetMediaType(1);
			m_pDoRtpHandler->doSetRtpHandler(this);
		}

		m_capacity = m_capacity < 1 ? 1 : m_capacity;
		CIDEvent * pIDEvent = new CIDEvent();
		pIDEvent->m_nCurIDEvent = theCurrentIdEvent+1;
		pIDEvent->m_nCapacity = m_capacity;
		theAppAttributes->setAttribute(EVENT_ATTRIBUTE, this, cgcObject::pointer(pIDEvent));

		for (int i=0; i<m_capacity; i++)
		{
			theApplication->SetTimer(++theCurrentIdEvent, m_capacity, shared_from_this());
		}

		m_bServiceInited = true;
		CGC_LOG((LOG_INFO, _T("**** [%s:%d] Start succeeded ****\n"), serviceName().c_str(), m_commPort));
		return true;
	}
Пример #7
0
	virtual void finalService(void)
	{
		if (!m_bServiceInited) return;

		cgcObject::pointer eventPointer = theAppAttributes->removeAttribute(EVENT_ATTRIBUTE, this);
		CIDEvent * pIDEvent = (CIDEvent*)eventPointer.get();
		if (pIDEvent != NULL)
		{
			for (unsigned int i=pIDEvent->m_nCurIDEvent; i<pIDEvent->m_nCurIDEvent+pIDEvent->m_nCapacity; i++)
				theApplication->KillTimer(i);
		}

		m_mapCgcRemote.clear();
		m_listMgr.clear();

		DoRtpHandler::pointer pDoRtpHandlerTemp = m_pDoRtpHandler;
		m_pDoRtpHandler.reset();
		m_rtpService->stopRtp(pDoRtpHandlerTemp);
		m_bServiceInited = false;
		CGC_LOG((LOG_INFO, _T("**** [%s:%d] Stop succeeded ****\n"), serviceName().c_str(), m_commPort));
	}
Пример #8
0
	virtual bool isInvalidate(void) const {return m_pDoRtpHandler.get() == 0;}
Пример #9
0
	virtual unsigned long getIpAddress(void) const {return m_pDoRtpHandler.get()==NULL?0:m_destIp;}
Пример #10
0
	virtual unsigned long getRemoteId(void) const {return m_pDoRtpHandler.get() == 0 ? 0 : m_destIp+m_destPort;}
Пример #11
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));
	}

}