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

📄 rvwp_bdy.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************
 * Name :		rvwp_bdy.c
 *
 * Type :			C source file
 *
 * Description :	Wrapper event handler functions
 *
 * Date : 			2004-03-23
 *
 *************************************************************************/
#include <string.h>
#include "stdio.h"
#include "rvwpt.h"
#include "rvrtp.h"
/*#include "configuration.h"*/

HAPP hApp;
AudioInfo   Codec;

CallInfo	wpCallInfo[MAX_CONCURRENT_CALL_NUM];

/* 2004.05.20 Move G.723 to the first, to adapt our bp8805v1 codec list */
/*WpCodecList wpCodecList;*/
int allowFastStart = 1;		/*  Allow fast start */

WpCodec ackCodec;

void GetCodec(AudioInfo AudioCodec)
{
	int i;
	for(i=0;i<AUDIO_CODEC_NUM;i++)
	{
		Codec.codecPrefOrder[i].isUsed = AudioCodec.codecPrefOrder[i].isUsed;
		Codec.codecPrefOrder[i].codecType = AudioCodec.codecPrefOrder[i].codecType;
		strcpy(Codec.codecPrefOrder[i].codecName,AudioCodec.codecPrefOrder[i].codecName);
	}
}
/*************************************************************************
 * Function:		wpCallAddFastStart
 * 
 * Description:	Initializes the structure that stores a list of proposed Fast Start
 *				channels, RTP and RTCP addresses. The application opens Fast
 *				Start channels
 *
 * input:			hsCall - The Stack handle for the call.
 *************************************************************************/

extern RvSemaphore* fileSem;
extern FILE* fp;
void wpCallAddFastStart(HCALL hsCall)
{
/*	cmFastStartMessage fsMessage;*/
	cmFastStartChannel fsChannel;
	int callIndex;
	int i;
	int retVal;

/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
	{ 
		fprintf(fp,"wpCallAddFastStart()\n");
		ReleaseSemaphore(fileSem,1,NULL);
	}
*/	

	callIndex = wPGetCallIndex(hsCall);
	
	fsChannel.rtp.ip = 0;
	fsChannel.rtp.type = cmTransportTypeIP;
	fsChannel.rtp.port = FIRST_RTP_PORT + callIndex * 2;
	fsChannel.rtcp.ip = 0;
	fsChannel.rtcp.type = cmTransportTypeIP;
	fsChannel.rtcp.port = fsChannel.rtp.port + 1;
	fsChannel.dataTypeHandle = -1;

#ifdef INCLUDE_RV_RTP
	OpenLocalRtp(callIndex, &fsChannel.rtp.port, NULL, NULL);
#endif

	fsChannel.rtcp.port = fsChannel.rtp.port + 1;

	for (i = 0; i < AUDIO_CODEC_NUM; i++)
	{
		if (!Codec.codecPrefOrder[i].isUsed)
		{
			continue;
		}

		fsChannel.channelName = Codec.codecPrefOrder[i].codecName;			

		retVal = cmFastStartBuild(hsCall, Codec.codecPrefOrder[i].codecType, 
					dirReceive, &fsChannel);

		if (retVal >= 0)
		{
			retVal = cmCallAddFastStartMessage(hsCall, retVal);
		}

		if (retVal < 0)
		{
	/*		if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
			{ 
				fprintf(fp,"Add fast start message error: Codec = %s(dirReceive)\n",
				Codec.codecPrefOrder[i].codecName);	
				ReleaseSemaphore(fileSem,1,NULL);
			}
	*/		
		}

		retVal = cmFastStartBuild(hsCall, Codec.codecPrefOrder[i].codecType, 
					dirTransmit, &fsChannel);

		if (retVal >= 0)
		{
			retVal = cmCallAddFastStartMessage(hsCall, retVal);
		}
		
		if (retVal < 0)
		{
		/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
			{ 
				fprintf(fp,"Add fast start message error: Codec = %s(dirTransmit)\n",
				Codec.codecPrefOrder[i].codecName);	
				ReleaseSemaphore(fileSem,1,NULL);
			}
		*/
		}
	}
}


static int isE164Num(char* number)
{
	int i;
	int len = strlen(number);
	for (i = 0; i < len; i++)
	{
		if (!isdigit(number[i]))
			return FALSE;
	}
	return TRUE;
}

/*************************************************************************
 * Function:		wpSendQuery
 *
 * Description:	This function sends the query to remote end.
 *
 *************************************************************************/
extern void ConvertInt2CharNum(char* ipAddr,  unsigned int num, int flag);
void wpSendQuery(WrapperMsg *msg)
{
	CallInfo*	Call;
	int		retVal;
	HCALL	hsCall;
	char		dstAddr[128], srcAddr[128], tmp[32];

	
/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
	{ 
		fprintf(fp,"wpSendQuery()\n");
		ReleaseSemaphore(fileSem,1,NULL);
	}*/
	Call = &wpCallInfo[msg->baseInfo.callIndex];
	memset(Call, 0, sizeof(CallInfo));
	/* Create new call */
	retVal = cmCallNew(hApp,(HAPPCALL)Call, &hsCall);
	if (retVal < 0)
	{
	/*	TRACE("cmCallNew return %d, return...\n", retVal);*/
		return;
	}

	Call->hsCall = hsCall;

	if (msg->baseInfo.remoteIpAddr != 0)
	{
		ConvertInt2CharNum(tmp,  msg->baseInfo.remoteIpAddr, 2);
		sprintf(dstAddr, "TA:%s:%d", tmp, H245_SEND_PORT);
	}
	else if (msg->baseInfo.remoteE164Num[0] != '\0')
	{
		if (isE164Num(msg->baseInfo.remoteE164Num))
		{
			cmAlias alias;
			sprintf(dstAddr, "TEL:%s", msg->baseInfo.remoteE164Num);
			alias.type = cmAliasTypePartyNumber;
			alias.length = strlen(msg->baseInfo.remoteE164Num);
			alias.pnType = cmPartyNumberPublicNationalNumber;
			alias.string = msg->baseInfo.remoteE164Num;
			cmCallSetParam(hsCall, cmParamCalledPartyNumber, 0, alias.length, (char*)&alias);
		}
		else
		{
			sprintf(dstAddr, "NAME:%s", msg->baseInfo.remoteE164Num);
		}
	}

	if (msg->baseInfo.localE164Num[0] != '\0')
	{
		cmAlias alias;
		sprintf(srcAddr, "TEL:%s", msg->baseInfo.localE164Num);
		alias.type = cmAliasTypePartyNumber;
		alias.length = strlen(msg->baseInfo.localE164Num);
		alias.pnType = cmPartyNumberPublicNationalNumber;
		alias.string = msg->baseInfo.localE164Num;
		cmCallSetParam(hsCall, cmParamCallingPartyNumber, 0, alias.length, (char*)&alias);
	}
	else
	{
		srcAddr[0] = '\0';
	}

	if ((retVal = cmCallMake(hsCall, 
			BANDWIDTH, 
			0, 
			dstAddr, 
			srcAddr,
			(char *)msg->baseInfo.display, 
			0, 
			0)) >= 0)
	{
	/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
		{ 
			fprintf(fp,"Make the call successd\n");
			ReleaseSemaphore(fileSem,1,NULL);
		}
*/
	}
	else
	{
	/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
		{ 
			fprintf(fp,"Make the call failed\n");
			ReleaseSemaphore(fileSem,1,NULL);
		}
	*/	
	}
}


/*************************************************************************
 * Function:		wpSendAlerting
 *
 * Description:	This function accepts the incoming call and sends the alerting message 
 *				to remote end.
 *
 *************************************************************************/
RVAPI void RVCALLCONV wpSendAlerting(WrapperMsg *msg)
{
	HCALL hsCall;
	int retVal;
	
	
/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
	{ 
		fprintf(fp,"wpSendAvail()\n");
		ReleaseSemaphore(fileSem,1,NULL);
	}*/
	hsCall = wpCallInfo[msg->baseInfo.callIndex].hsCall;
/*	TRACE("sendAlerting:hsCall = %x\n", hsCall);*/
	if ((retVal = cmCallAccept(hsCall)) >= 0)
	{
	/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
		{ 
			fprintf(fp,"Accept the call successed\n");
			ReleaseSemaphore(fileSem,1,NULL);
		}*/
	}
	else
	{
	/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
		{ 
			fprintf(fp,"Accept the call failed\n");
			ReleaseSemaphore(fileSem,1,NULL);
		}*/
	}
}


/*************************************************************************
 * Function:		wpSendBusy
 *
 * Description:	This function rejects the incoming call and sends the busy reason 
 *				to remote end.
 *
 *************************************************************************/
void wpSendBusy(WrapperMsg *msg)
{
	HCALL hsCall;
	
/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
	{ 
		fprintf(fp,"wpSendBusy()\n");
		ReleaseSemaphore(fileSem,1,NULL);
	}*/
	hsCall = wpCallInfo[msg->baseInfo.callIndex].hsCall;
/*	TRACE("hsCall = %x\n", hsCall);*/

	if (cmMeiEnter(hApp) >= 0)
	{
		cmCallSetParam(hsCall, cmParamReleaseCompleteCause, 0, 17, NULL);
		if (cmCallDrop(hsCall) >= 0)
		{
		/*	TRACE("Reject the call with busy reason successed\n");*/
		}
		else
		{
		/*	TRACE("Reject the call with busy reason failed\n");*/
		}
		cmMeiExit(hApp);
	}
	else
	{
	/*	TRACE("can't get hApp in critical section! return ...\n");*/
	}
}


int cmpChannelName(char *name)
{
	int i;
	for (i = 0; i < AUDIO_CODEC_NUM; i++)
	{
		if (Codec.codecPrefOrder[i].isUsed
			&& strcmp(name, Codec.codecPrefOrder[i].codecName) == 0)
			return i;
	}
	return -1;
}


int AckCodec
(
	HCALL hsCall, 
	FastStartChannelAck* chAck, 
	int size, 
	cmTransportAddress* ownCSAddr, 
	WrapperMsg *msg
)
{
	int i, j;
	int recIndex = -1;
	int transIndex = -1;
	cmFastStartChannel	fsChan;
	RvPvtNodeId 			ackChan;
	int rtpPort;
	
	for (i = 0; i < size; i++)
	{
		if (chAck[i].dir == 2)
		{
			ackCodec.remoteRtpIpAddr = chAck[i].rtp.ip;
			ackCodec.remoteRtpPort = chAck[i].rtp.port - 1;	
			#ifdef INCLUDE_RV_RTP
				OpenLocalRtp( msg->baseInfo.callIndex, &rtpPort, 
					&ackCodec.remoteRtpIpAddr, &ackCodec.remoteRtpPort);
			#else
				rtpPort = FIRST_RTP_PORT +  msg->baseInfo.callIndex * 2;
			#endif
			fsChan.rtcp.ip = ownCSAddr->ip;
			fsChan.rtcp.port = rtpPort + 1;
			fsChan.rtp.ip = ownCSAddr->ip;
			fsChan.rtp.port = rtpPort;
			ackChan = cmFastStartChannelsAckIndex(hsCall, chAck[i].ackIndex, &fsChan.rtcp, &fsChan.rtp);
	/*		if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
			{ 
				fprintf(fp,"local codec match remote OK(1):%s!\n", Codec.codecPrefOrder[chAck[i].wpcodecIndex].codecName);
				ReleaseSemaphore(fileSem,1,NULL);
			}
		*/	
			ackCodec.rx = chAck[i].wpcodecIndex;
			ackCodec.tx = chAck[i].wpcodecIndex;					
			return 0;
		}
	}

	for (i = 0; i < size; i++)
	{
		for (j = i+1; j < size; j++)
		{
			if ((chAck[i].wpcodecIndex == chAck[j].wpcodecIndex)
				&& (chAck[i].dir != chAck[j].dir))
			{
				ackCodec.remoteRtpIpAddr = chAck[i].rtp.ip;
				if (chAck[i].dir == 0)
					ackCodec.remoteRtpPort = chAck[i].rtp.port - 1;
				else
					ackCodec.remoteRtpPort = chAck[j].rtp.port - 1;
				
				#ifdef INCLUDE_RV_RTP
					OpenLocalRtp( msg->baseInfo.callIndex, &rtpPort, 
						&ackCodec.remoteRtpIpAddr, &ackCodec.remoteRtpPort);
				#else
					rtpPort = FIRST_RTP_PORT +  msg->baseInfo.callIndex * 2;
				#endif
				
				fsChan.rtcp.ip = ownCSAddr->ip;
				fsChan.rtcp.port = rtpPort + 1;
				fsChan.rtp.ip = ownCSAddr->ip;
				fsChan.rtp.port = rtpPort;

⌨️ 快捷键说明

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