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

📄 rvwp_bdy.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 2 页
字号:

				ackChan = cmFastStartChannelsAckIndex(hsCall, chAck[i].ackIndex, &fsChan.rtcp, &fsChan.rtp);
				ackChan = cmFastStartChannelsAckIndex(hsCall, chAck[j].ackIndex, &fsChan.rtcp, &fsChan.rtp);
		/*		if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
				{ 
					fprintf(fp,"local codec match remote OK(2):%s!\n",Codec.codecPrefOrder[chAck[i].wpcodecIndex].codecName);
					ReleaseSemaphore(fileSem,1,NULL);
				}
		*/
				ackCodec.rx = chAck[i].wpcodecIndex;
				ackCodec.tx = chAck[i].wpcodecIndex;
				
		/*		TRACE("chAck[i].rtp.ip = %x, port = %d\n", chAck[i].rtp.ip, chAck[i].rtp.port-1);*/
		/*		TRACE("chAck[j].rtp.ip = %x, port = %d\n", chAck[j].rtp.ip, chAck[j].rtp.port-1);*/
				return 0;
			}
		}
	}

	for (i = 0; i < size; i++)
	{
		if (chAck[i].dir == 0)
			recIndex = i;
		else if (chAck[i].dir == 1)
			transIndex = i;

		if (recIndex != -1 && transIndex != -1)
			break;
	}

	if (recIndex != -1 && transIndex != -1)
	{
		ackCodec.remoteRtpIpAddr = chAck[recIndex].rtp.ip;
		ackCodec.remoteRtpPort = chAck[recIndex].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);
/*		TRACE("local codec match remote with two signal direction!\n");*/
		ackCodec.rx = chAck[recIndex].wpcodecIndex;
		ackCodec.tx = chAck[transIndex].wpcodecIndex;		
		return 0;
	}

/*	TRACE("local codec can't match remote, ERROR!\n");*/
	return -1;
}


/*************************************************************************
 * Function:		wpSendConn
 *
 * Description:	This function answers the incoming call.
 *
 * Note:			After this function done, the Stack connects the call and notifies the 
 *				application through cmEvCallStateChanged() with the cmCallStateConnected
 *				state.
 *
 *************************************************************************/
void wpSendConn(WrapperMsg *msg)
{
	HCALL hsCall;
		
	
/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
	{ 
		fprintf(fp,"wpSendConn()\n");
		ReleaseSemaphore(fileSem,1,NULL);
	}*/			
	hsCall = wpCallInfo[msg->baseInfo.callIndex].hsCall;

	if (wpCallInfo[msg->baseInfo.callIndex].isFastConnect && allowFastStart)
	{
		int					i;
		cmTransportAddress	ownCSAddr;
		int					channelId = 0;
		cmCapDataType		dataType;
		cmChannelDirection	chanDir;
		cmFastStartChannel	fsChan;
		RvBool				channels[48];
		FastStartChannelAck	chAck[48];
		int					chAckSize = 0;
		int					wplistIndex;
		
		memset(channels, 0, sizeof(channels));
		cmGetLocalCallSignalAddress(hApp, &ownCSAddr);	
		
		for (i=0; channelId >= 0; i++)
		{
/*			RvPvtNodeId ackChan;*/

			channelId = cmFastStartGetByIndex(hsCall, i);
			if(channelId < 0)
			{
				break;
			}		
			cmFastStartGet(hsCall, channelId, &dataType, &chanDir, &fsChan);

			wplistIndex = cmpChannelName(fsChan.channelName);
			if (wplistIndex == -1)
				continue;

			if (fsChan.rtcp.port != 0)
			{
				chAck[chAckSize].ackIndex = i;
				chAck[chAckSize].rtp = fsChan.rtcp;
				chAck[chAckSize].dir = chanDir;
				chAck[chAckSize].wpcodecIndex = wplistIndex;

				if (chAckSize++ >= 48)
					break;
			}
			
			/*if (channels[(chanDir * 16) + dataType] == RV_FALSE)
			{
				fsChan.rtcp.ip = ownCSAddr.ip;
				fsChan.rtcp.port = FIRST_RTP_PORT + msg->baseInfo.callIndex * 2 + 1;
				fsChan.rtp.ip = ownCSAddr.ip;
				fsChan.rtp.port = FIRST_RTP_PORT + msg->baseInfo.callIndex * 2;

				ackChan = cmFastStartChannelsAckIndex(hsCall, i, &fsChan.rtcp, &fsChan.rtp);
				channels[(chanDir * 16) + dataType] = RV_TRUE;
			}*/
		}	
		AckCodec(hsCall, chAck, chAckSize, &ownCSAddr, msg);
		cmFastStartChannelsReady(hsCall);
	}
	
	if (cmCallAnswerDisplay(hsCall, msg->baseInfo.display) >= 0)
	{
	/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
		{ 
			fprintf(fp,"Answer the call successed\n");
			ReleaseSemaphore(fileSem,1,NULL);
		}
	*/	
	}
	else
	{
/*		if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
		{ 
			fprintf(fp,"Answer the call failed\n");
			ReleaseSemaphore(fileSem,1,NULL);
		}*/
	}
}


/*************************************************************************
 * Function:		wpSendTerm
 *
 * Description:	This function drops the current call.
 *
 *************************************************************************/
void wpSendTerm(WrapperMsg *msg)
{
	HCALL hsCall;
	HCHAN hsChan;
	
/*	if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0) 
	{ 
		fprintf(fp,"wpSendTerm()\n");
		ReleaseSemaphore(fileSem,1,NULL);
	}*/
	hsChan = wpCallInfo[msg->baseInfo.callIndex].hsChan;
	if (cmChannelDrop(hsChan) >= 0)
	{
	/*	TRACE("Drop the channel successed\n");*/
	}
	else
	{
	/*	TRACE("Drop the channel failed\n");*/
	}

	hsCall = wpCallInfo[msg->baseInfo.callIndex].hsCall;
	if (hsCall == NULL)
	{
	/*	TRACE("wpSendTerm:hsCall is NULL, return ...\n");*/
		return;
	}

	wpCallInfo[msg->baseInfo.callIndex].isCallDroped = RV_TRUE;

	if (cmCallDrop(hsCall) >= 0)
	{
	/*	TRACE("Drop the call successed\n");*/
	}
	else
	{		
	/*	TRACE("Drop the call failed\n");*/
	}

	if (cmCallClose(hsCall) < 0)
	{
	/*	TRACE("Close the call failed\n");*/
	}
	else
	{
	/*	TRACE("Close the call successed\n");*/
	}
	wpRelsCall(hsCall);
}

#if 0
void wpSendTerminalCapabilitySet
(
	IN HCALL hsCall
)
{
	/*int ret;
	cmCapStruct cap1 = {"g729AnnexA", 0, -1, cmCapReceiveAndTransmit, cmCapAudio};
	cmCapStruct cap2 = {"g729", 0, -1, cmCapReceiveAndTransmit, cmCapAudio};
	cmCapStruct cap3 = {"g729wAnnexB", 0, -1, cmCapReceiveAndTransmit, cmCapAudio};
	cmCapStruct cap4 = {"g729AnnexAwAnnexB", 0, -1, cmCapReceiveAndTransmit, cmCapAudio};
	cmCapStruct cap5 = {"g7231", 0, -1, cmCapReceiveAndTransmit, cmCapAudio};
	cmCapStruct cap6 = {"g711Ulaw64k", 0, -1, cmCapReceiveAndTransmit, cmCapAudio};
	cmCapStruct cap7 = {"g711Alaw64k", 0, -1, cmCapReceiveAndTransmit, cmCapAudio};

	cmCapStruct *capSet[] = {&cap1, &cap2, &cap3, &cap4, &cap5, &cap6, &cap7, 0};

	cmCapStruct *capAlt1[] = {&cap1, &cap2, 0};
	cmCapStruct *capAlt2[] = {&cap3, 0};
	cmCapStruct **capSim[] = {capAlt1, capAlt2, 0};
	cmCapStruct ***capDesc[] = {capSim, 0};
	
	TRACE("wpSendTerminalCapabilitySet()\n");

	ret = cmCallCapabilitiesSend(hsCall, capSet, capDesc);
	if (ret < 0)
	{
		TRACE("Send capabilities set failed\n");
	}
*/
	int ret;
    int rootNodeId;
	HPVT hVal;
	HPST hSyn;
	
    hVal = cmGetValTree(hApp);
    hSyn = cmGetSynTreeByRootName(hApp, (char *)"h245");

    /* Create the root of a TCS message - we have to pass such a
       message to cmCallSendCapability() */
    rootNodeId = pvtAddRootByPath(hVal, hSyn, (char*)"request.terminalCapabilitySet", 0, NULL);

    /* We send this root as an empty capability message. */
    ret = cmCallSendCapability(hsCall, rootNodeId);

    if (ret < 0)
    {
        TRACE("Send capabilities set failed\n");
        /* We got an error while trying to send this Empty Capability Set */
    }
}
#endif

RVAPI void RVCALLCONV wpSetFastStart(int mode)
{
	allowFastStart = mode;
}

int wpGetFastStart()
{
	return allowFastStart;
}
#if 0
int wpAddCodecToList(char* codecName, int codecType)
{
	int i = wpCodecList.numCodecs;

	TRACE("wpAddCodecToList()\n");
	
	if (i >= AUDIO_CODEC_MAX)
	{
		TRACE("Max number of Codec list is %d, overflow\n", AUDIO_CODEC_MAX);
		return RV_FALSE;
	}

	if ((codecName == NULL) || (cmpChannelName(codecName) != -1))
	{
		TRACE("Codec is already in our array(wpCodecList), index = %d,ignore\n",
			cmpChannelName(codecName));
		return RV_FALSE;
	}

	strncpy(wpCodecList.codecPrefOrder[i].codecName, codecName, 31);
	wpCodecList.codecPrefOrder[i].codecName[31] = '\0';
	wpCodecList.codecPrefOrder[i].codecType = codecType;
	wpCodecList.codecPrefOrder[i].isUsed = RV_TRUE;
	wpCodecList.numCodecs++;
	return RV_TRUE;
}


int wpSetCodecProperty
(
	int oldIndex,		/* Old index of the codec in the wpCodecList array */
	int newIndex,	/* New index of the codec to be set */
	char *codecName,
	int codecType,
	int isUsed
)
{
	int i;
	
	TRACE("wpSetCodecProperty()\n");

	if (oldIndex < 0 || oldIndex >= wpCodecList.numCodecs
		|| newIndex < 0 || newIndex >= wpCodecList.numCodecs)
	{
		TRACE("Parameter oldIndex(%d) or newIndex(%d) error,return\n",oldIndex, newIndex);
		return RV_FALSE;
	}

	strncpy(wpCodecList.codecPrefOrder[oldIndex].codecName, codecName, 31);
	wpCodecList.codecPrefOrder[oldIndex].codecName[31] = '\0';
	wpCodecList.codecPrefOrder[oldIndex].codecType = codecType;
	wpCodecList.codecPrefOrder[oldIndex].isUsed = isUsed;

	if (newIndex == oldIndex)
	{
		return RV_TRUE;
	}
	else if (newIndex < oldIndex)
	{
		CodecS temp = wpCodecList.codecPrefOrder[oldIndex];
		for (i = oldIndex; i > newIndex; i--)
		{
			wpCodecList.codecPrefOrder[i] = wpCodecList.codecPrefOrder[i-1];
		}
		wpCodecList.codecPrefOrder[newIndex] = temp;
	}
	else
	{
		CodecS temp = wpCodecList.codecPrefOrder[oldIndex];
		for (i = oldIndex; i < newIndex; i++)
		{
			wpCodecList.codecPrefOrder[i] = wpCodecList.codecPrefOrder[i+1];
		}
		wpCodecList.codecPrefOrder[newIndex] = temp;
	}
	return RV_TRUE;
}
#endif

void wpShowCodec()
{
/*	int i;*/
	static char* codecType[] = {
		"cmCapEmpty",
		"cmCapAudio",
		"cmCapVideo",
		"cmCapData",
		"cmCapNonStandard",
		"cmCapUserInput",
		"cmCapConference",
		"cmCapH235",
		"cmCapMaxPendingReplacementFor",
		"cmCapGeneric",
		"cmCapMultiplexedStream",
		"cmCapAudioTelephonyEvent",
		"cmCapAudioTone"};

/*	TRACE("wpShowCodec()\n");*/

/*	TRACE("No.%20s%20s%7s\n", "Codec", "Type", "On/Off");*/
/*
	for (i = 0; i < AUDIO_CODEC_NUM; i++)
	{
		if (Codec.codecPrefOrder[i].isUsed)
		{
			TRACE("[%d]%20s%20s%7s\n", i, Codec.codecPrefOrder[i].codecName,
				codecType[Codec.codecPrefOrder[i].codecType], "On");
		}
		else
		{
			TRACE("[%d]%20s%20s%7s\n", i, " ", cmCapAudio, "Off");
		}
	}
	*/
}

int sort_function( const void *a, const void *b) 
{
	CapElem *x = (CapElem*)a;
	CapElem *y = (CapElem*)b;
	return ((x->capEntryNumber > y->capEntryNumber) \
		? 1 : ((x->capEntryNumber == y->capEntryNumber) ? 0 : -1)); 
} 

⌨️ 快捷键说明

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