📄 rvwp_ex_ms.c
字号:
/*************************************************************************
* Name : rvwp_ex_ms.c
*
* Type : C source file
*
* Description : Wrapper event handler
*
* Date : 2004-03-22
*
*************************************************************************/
#include "income.h"
#include "stdio.h"
#include "rvwpt.h"
#include "cmCall.h"
#include "rvrtp.h"
#include "rvrtcp.h"
/*#include "sysdep.h"*/
/*#include "configuration.h"*/
extern HAPP hApp;
extern CallInfo wpCallInfo[MAX_CONCURRENT_CALL_NUM];
extern int allowFastStart;
extern WpCodec ackCodec;
extern int codeIndex;
extern AudioInfo Codec;
extern RvH323TimerPoolHandle rv_timer;
extern WNDCLASS wc;
extern HWND hSWnd;
int needOLCAgain = 0;
RvTimer *rvTimer = NULL;
/* deleted by mxd 2005.1.18 for windows */
/*
static MSG_Q_ID rvwpMsgQId = NULL;
void Initrvwp()
{
rvwpMsgQId = msgQCreate( MAX_BUFFERS, MAX_BUF_LEN, MSG_Q_FIFO );
}
void ReInitrvwp(void)
{
msgQDelete(rvwpMsgQId);
rvwpMsgQId = msgQCreate( MAX_BUFFERS, MAX_BUF_LEN, MSG_Q_FIFO );
}
int rvwpSend(WrapperMsg *msg)
{
return (msgQSend( rvwpMsgQId, (char*)msg, MAX_BUF_LEN, WAIT_FOREVER,
MSG_PRI_NORMAL ));
}
int rvwpReceive(WrapperMsg *msg)
{
return msgQReceive( rvwpMsgQId, (char*)msg, MAX_BUF_LEN, NO_WAIT);
}
*/
/*************************************************************************
* Function: wpHandleMsg
*
* Description: This function dispatches the message that the application sent
* to the Wrapper, call other specific function to handle msgs.
*
*************************************************************************/
/* modified by mxd 2005.1.18 for windows */
extern RvSemaphore* fileSem;
extern FILE* fp;
LRESULT CALLBACK wpHandleMsg(HWND hWnd, UINT uMsg,WPARAM wParam,LPARAM lParam)
//void wpHandleMsg(WrapperMsg *msg)
{
WrapperMsg* msg = (WrapperMsg*)lParam;
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"start wpHandleMsg()\n");
ReleaseSemaphore(fileSem,1,NULL);
}*/
switch(uMsg)
{
case WM_WPMSG:
switch (msg->msgId)
{
case WP_SEND_QUERY_AVA:
wpSendQuery(msg);
break;
case WP_SEND_CONN:
wpSendConn(msg);
break;
case WP_SEND_TERM:
wpSendTerm(msg);
break;
case WP_SEND_AVA:
wpSendAlerting(msg);
break;
case WP_SEND_NOTAVA:
wpSendBusy(msg);
break;
case WP_SEND_REGISTER:
wpSendRegister(msg);
break;
case WP_SEND_UNREGISTER:
break;
case WP_INITIATE_CALL_TRANSFER:
wpSendCTorCF(msg);
break;
case WP_SEND_CALL_TRANSFER_SETUP:
case WP_SEND_CALL_FORWARD:
wpSendCTorCF(msg);
break;
default:
/* TRACE("Wrong message ID for sending\n");*/
break;
}
break;
default:
break;
}
}
/*************************************************************************
* Function: cmEvCallStateChanged
*
* Description: Handle changes in the state of calls.
* This is a callback function called by the CM.
*
* input: haCall - The application handle for the call
* hsCall - The stack handle for the call
* state - The new state of the call
* stateMode - The new state mode. This parameter discribes why or how
* the call enters a new state
* output: none
* return: none
*************************************************************************/
int RVCALLCONV cmEvCallStateChanged
(
IN HAPPCALL haCall,
IN HCALL hsCall,
IN cmCallState_e state,
IN cmCallStateMode_e stateMode
)
{
WrapperMsg wpmsg;
/* RvInt8 callIndex;*/
RvInt32 IsFastConnect = RV_FALSE;
int retVal;
static char* stateStr[] =
{
"cmCallStateInit",
"cmCallStateDialtone",
"cmCallStateProceeding",
"cmCallStateRingBack",
"cmCallStateConnected",
"cmCallStateDisconnected",
"cmCallStateIdle",
"cmCallStateOffering",
"cmCallStateTransfering",
"cmCallStateIncompleteAddress",
"cmCallStateWaitAddressAck"
};
static char* smStr[] = {
"cmCallStateModeDisconnectedBusy",
"cmCallStateModeDisconnectedNormal",
"cmCallStateModeDisconnectedReject",
"cmCallStateModeDisconnectedUnreachable",
"cmCallStateModeDisconnectedUnknown",
"cmCallStateModeDisconnectedLocal",
"cmCallStateModeConnectedControl",
"cmCallStateModeConnectedCallSetup",
"cmCallStateModeConnectedCall",
"cmCallStateModeConnectedConference",
"cmCallStateModeControlConnected=cmCallStateModeConnectedControl",
"cmCallStateModeCallSetupConnected",
"cmCallStateModeCallConnected",
"cmCallStateModeOfferingCreate",
"cmCallStateModeOfferingInvite",
"cmCallStateModeOfferingJoin",
"cmCallStateModeOfferingCapabilityNegotiation",
"cmCallStateModeOfferingCallIndependentSupplementaryService",
"cmCallStateModeDisconnectedIncompleteAddress",
"cmCallStateModeTransferingForwarded",
"cmCallStateModeTransferingRouteToMC",
"cmCallStateModeTransferingRouteToGatekeeper"
};
int callId = wPGetCallIndex(hsCall);
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"cmEvCallStateChanged()\n hsCall:%x, state:%s, statemode:%s\n", hsCall, stateStr[state+1], smStr[stateMode]);
ReleaseSemaphore(fileSem,1,NULL);
}
*/
switch (state)
{
/* There is no call. This is where cmCallClose() should be called. */
case cmCallStateIdle:
if (callId == -1)
{
retVal = cmCallClose(hsCall);
if (retVal < 0)
{
/* TRACE("Close the call failed\n");*/
}
else
{
/* TRACE("Close the call successed\n");*/
}
return 0;
}
if (!wpCallInfo[callId].isCallDroped
&& !wpCallInfo[callId].isForwarded)
{
retVal = cmCallClose(hsCall);
if (retVal < 0)
{
/* TRACE("Close the call failed\n");*/
}
else
{
/* TRACE("Close the call successed\n");*/
}
memset(&ackCodec, 0, sizeof(ackCodec));
wpRelsCall(hsCall);
}
wpCallInfo[callId].isForwarded = RV_FALSE;
return 0;
/* The first state after calling the cmCallMake() function. */
case cmCallStateDialtone:
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"Received cmCallStateDialtone\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/ wpCallInfo[callId].isIncoming = RV_FALSE;
if (allowFastStart)
{
wpCallAddFastStart(hsCall);
}
return 0;
/* Received an Alerting message from the remote side of the call. */
case cmCallStateRingBack:
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"Received Alerting message\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
/*RvH323TimerCancel(cmGetTimersHandle(hApp),&((callElem*)hsCall)->timer);*/
wpmsg.msgId = WP_REC_AVA;
wpmsg.baseInfo.callIndex = callId;
break;
/* Received a CallProceeding message from the remote side of the call. */
case cmCallStateProceeding:
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"Received CallProceeding message\n");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
/*wpmsg.msgId = WP_REC_AVA;*/
return 0;
/* The call is connected. */
case cmCallStateConnected:
if (stateMode == cmCallStateModeCallSetupConnected)
{
/*cmTransportAddress remoteH245Addr;
RvInt32 len;
TRACE("The call is connected\n");
/*cmCallGetParam(hsCall, cmParamH245Address, 0, &len, (char *)&remoteH245Addr);
retVal = cmCallCreateControlSession(hsCall, &remoteH245Addr);
if (retVal < 0)
{
TRACE("Create control sesssion failed\n");
return 0;
}*/
/* if(WaitForSingleObject(fileSem,INFINITE) == WAIT_OBJECT_0)
{
fprintf(fp,"The call is connected");
ReleaseSemaphore(fileSem,1,NULL);
}
*/
if (wpCallInfo[callId].isFastConnect == RV_TRUE && allowFastStart)
{
char display[MAX_DISPLAY_LENGTH + 1];
int ret;
/* int size;*/
/* cmTransportAddress callta;*/
/* TRACE("Incoming call is fs && we accept it\n");*/
wpmsg.msgId = WP_REC_CONN;
wpmsg.baseInfo.callIndex = callId;
wpCallInfo[callId].isConnected = RV_TRUE;
wpmsg.rtpSession = wpCallInfo[callId].rtpSession;
memset(display, 0, sizeof(display));
ret = cmCallGetDisplayInfo(hsCall, display, sizeof(display));
if (ret <= 0)
{
/* TRACE("Get the remote display info error\n");*/
}
strncpy(wpmsg.baseInfo.display, display, MAX_DISPLAY_LENGTH);
wpmsg.baseInfo.display[MAX_DISPLAY_LENGTH] = '\0';
wpmsg.d.codec = ackCodec;
/* TRACE("wpmsg.d.codec.remote ip = %x\n", wpmsg.d.codec.remoteRtpIpAddr);*/
/* TRACE("wpmsg.d.codec.remote port = %d\n", wpmsg.d.codec.remoteRtpPort);*/
wpmsg.d.codec.localRtpPort = FIRST_RTP_PORT + callId * 2;
break;
}
return 0;
}
else if (stateMode == cmCallStateModeCallConnected) /* ready for olc */
{
if (wpCallInfo[callId].isFastConnect == RV_TRUE && allowFastStart)
{
/* need do nothing */
}
else
{
if (!wpCallInfo[callId].isConnected)
wpOutChannelOpen(hsCall);
}
return 0;
}
else
{
return 0;
}
break;
/* The call is disconnected. */
case cmCallStateDisconnected:
{
if (wpCallInfo[callId].isForwarded)
return 0;
if (stateMode == cmCallStateModeDisconnectedBusy)
{
/* TRACE("Received User Busy message\n");*/
wpmsg.msgId = WP_REC_NOTAVA;
wpmsg.baseInfo.callIndex = callId;
}
else
{
int reason = -1;
cmCallGetParam(hsCall, cmParamReleaseCompleteReason, 0, &reason, NULL);
/* TRACE("Release Complete reason = %d\n", reason);*/
if ((reason == cmReasonTypeFacilityCallDeflection) /* Call transferring */
&& (wpCallInfo[callId].isTransferring))
{
/* TRACE("Call transferring ok, received terminate message\n");*/
wpmsg.msgId = WP_CT_INIT_RESULT_RCVD;
wpmsg.baseInfo.callIndex = callId;
}
else
{
/* TRACE("Received terminate message\n");*/
wpmsg.msgId = WP_REC_TERM;
wpmsg.baseInfo.callIndex = callId;
}
}
wpmsg.reason = stateMode;
break;
}
/* A call Setup message has been received and not yet answered. */
case cmCallStateOffering:
{
if (cmCallOffer(haCall, hsCall, state, stateMode, &wpmsg) < 0)
{
/* TRACE("prepare income call error, drop and return...\n");*/
/* send not available message to remote end */
cmCallSetParam(hsCall, cmParamReleaseCompleteCause, 0, 17, NULL);
cmCallDrop(hsCall);
return 0;
}
break;
}
/* The call is currently transferred. */
case cmCallStateTransfering:
{
wpCallInfo[callId].isIncoming = RV_FALSE;
wpCallInfo[callId].isConnected = RV_FALSE;
break;
}
default:
break;
}
wpSendMsgToApp(&wpmsg);
return 0;
}
#ifdef INCLUDE_RV_RTP
RvUint32 rtp_start_time;
void OpenLocalRtp(int callId, int *rtpPort, RvUint32* remoteIp, RvUint16* remotePort)
{
int ret = 0;
char cname[128];
if (wpCallInfo[callId].rtpSession != NULL)
{
if (rtpPort != NULL)
*rtpPort = rtpGetPort(wpCallInfo[callId].rtpSession);
if (remoteIp != NULL && remotePort != NULL)
{
/* TRACE("rtp set remote ip:%x, port:%d\n", *remoteIp, *remotePort);*/
rtpSetRemoteAddress(wpCallInfo[callId].rtpSession, *remoteIp, *remotePort);
rtcpSetRemoteAddress(wpCallInfo[callId].rtcpSession, *remoteIp, *remotePort+1);
}
return;
}
while (!wpCallInfo[callId].rtpSession)
{
*rtpPort = FIRST_RTP_PORT + callId * 2 + MAX_CONCURRENT_CALL_NUM * (ret++) * 2;
if (*rtpPort > MAX_RTP_PORT)
{
/* TRACE("port = %d, no rtp port can be opened\n", *rtpPort);*/
return;
}
sprintf(cname, "RTP:%d", *rtpPort);
wpCallInfo[callId].rtpSession = rtpOpenEx(*rtpPort, 1, 0xff, cname);
if (wpCallInfo[callId].rtpSession == NULL)
{
/* TRACE("rtpOpen port:%d return NULL!\n", *rtpPort);*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -