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

📄 megacomgc.c

📁 h.248协议源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	rvMegacoAddCommandConstruct(&addCommand1, &applInfo[termInd].terminationId);
	
	/* 2nd add command requests to create */
	/* a related RTP term. in that context*/
	rvMegacoTerminationIdConstruct(&terminationId, "$");
	rvMegacoAddCommandConstruct(&addCommand2, &terminationId);
	
	/* Construct MediaDescriptor object, add stream to it */
	rvMegacoMediaDescriptorConstruct(&media);
	
	rvMegacoContextIdDestruct(&applInfo[termInd].contextId);
	rvMegacoContextIdConstructSpecial(&applInfo[termInd].contextId,
	  RV_MEGACOCONTEXTID_CHOOSE);
	rvMegacoStreamDescriptorConstruct(&stream,
	applInfo[termInd].streamId); 

	/* Set mode for this stream */
	rvMegacoStreamDescriptorSetMode(&stream, mode);

	/* Construct PackageItem we need */
	rvMegacoPackageItemConstruct(&packageItem1,
	  "nt",		/* Network package */
	  "jit");	/* Define max jitter */

	/* The value of "jit" in ms */ 
	rvMegacoParameterValueConstruct(&paramValue1, "40"); 
	rvMegacoStreamDescriptorSetParameter(&stream, &packageItem1, &paramValue1);

	/* Construct sdp session description message */
	rvSdpMsgConstruct(&sdpMsg);         
	rvSdpMsgSetVersionN(&sdpMsg, &version, 1);
	rvSdpMsgSetConnection(&sdpMsg, RV_SDPNETTYPE_IN, RV_SDPADDRTYPE_IP4, "$"); 
	sdpMediaDescr = rvSdpMsgAddMediaDescr(&sdpMsg, RV_SDPSYMB_AUDIO, 
	  RV_SDPPORT_ANY, RV_SDPPROTOCOL_RTP);
	
	/* Set all the codecs from the table  */
	do                                    
	{
		sprintf(dispBuf, "%d", codecsInfo[i].number); 
		rvSdpMediaDescrAddFormat(sdpMediaDescr, dispBuf);
		if (strlen(codecsInfo[i].name))
			rvSdpMediaDescrAddRtpMap(sdpMediaDescr, codecsInfo[i].number,
			  (const char *)codecsInfo[i].name, codecRate);
		i++;
	} while (codecsInfo[i].number >= 0);  
    
	/* Set packetization time as configured */
	if (strlen(ptime))                  
		rvSdpMediaDescrAddAttr(sdpMediaDescr, "ptime", ptime);

	rvMegacoStreamDescriptorAddLocalDescriptor(&stream, &sdpMsg);

	/* Add this streamDescriptor to media object */
	rvMegacoMediaDescriptorAddStream(&media, &stream); 
	rvMegacoAddCommandSetMedia(&addCommand2, &media);
	
	/* Set up the action */
	applInfo[termInd].actionOutPtr =      
	  rvAllocAllocate(&rvDefaultAlloc, (sizeof(RvMegacoAddCommand)) * 2);
	rvMegacoActionConstruct(applInfo[termInd].actionOutPtr, 
	  &applInfo[termInd].contextId);	        
	rvMegacoActionAddCommand(applInfo[termInd].actionOutPtr, &addCommand1);
	rvMegacoActionAddCommand(applInfo[termInd].actionOutPtr, &addCommand2);

	sendRequest(SEND_ACTION);
	applInfo[termInd].connectInitiatorInd = termInd;

	/* Remote termination is not off hook  */
	/* but in use already                  */
	applInfo[applInfo[termInd].remoteTermInd].callInProgress = rvTrue;
                                      
	applInfo[termInd].nextEvent = E_APPL_SPECIAL;  
	rvMegacoTerminationIdDestruct(&terminationId);
	rvMegacoPackageItemDestruct(&packageItem1);
	rvMegacoParameterValueDestruct(&paramValue1);
	rvSdpMsgDestruct(&sdpMsg);
	rvMegacoMediaDescriptorDestruct(&media); 
	rvMegacoStreamDescriptorDestruct(&stream);
	rvMegacoAddCommandDestruct(&addCommand1); 
	rvMegacoAddCommandDestruct(&addCommand2); 
	rvMegacoActionDestruct(applInfo[termInd].actionOutPtr);
	rvAllocDeallocate(&rvDefaultAlloc, (sizeof(RvMegacoAddCommand)) * 2,
	  applInfo[termInd].actionOutPtr); 
	applInfo[termInd].actionOutPtr = NULL;

	return NO_EVENT;
}

/********************************************************************************/
/*   We come here in state 1 when we need to request MG to listen for the       */
/*  off_hook signal on an active termination and notify us when it happens      */
/*  For this matter we program curent termination in a NULL context, assigning  */
/*  it streamId, requestId, mode, and package with the event to notify us about */
/*                                                                              */
/*  It's possible to use a function call                                        */
/*        rvMegacoTransactionConstructParse(RvMegacoTransaction *x,            */
/*                                           const char *text,                  */
/*                                           RvParseError *error)              */
/*                                                                              */ 
/*  and a prefabricated "canned" message text instead of constructing this      */
/*  command from separate elements.                                             */
/*  The text for the applOffHookListenReq() command will be as follows:         */ 
/*                                                                              */
/*       "T=1{C=-{MF=terma{M{L{\n \                                             */
/*        v=0\n \                                                               */
/*        c=IN IP4 $\n \                                                        */
/*        a=fmtp:PCMU VAD=X-NNVAD\n \                                           */ 
/*        m=audio $ RTP/AVP 0\n \                                               */
/*        },O{MO=SR,tdmc/ec=on,tdmc/gain=2}},E=1{al/of}}}}\n"                   */  
/*                                                                              */
/********************************************************************************/
int  applOffHookListenReq(void)  
{
	RvMegacoMediaDescriptor    media;
	RvMegacoStreamDescriptor   stream;
	RvMegacoStreamMode         mode = RV_MEGACOSTREAMMODE_SENDRECV;
	RvMegacoEventsDescriptor   eventsDescriptor;  
	RvMegacoRequestedEvent     requestedEvent;
	RvMegacoPackageItem        packageItem1, packageItem2, packageItem3;
	RvSdpMsg                   sdpMsg1;  
	RvSdpMediaDescr            *sdpMediaDescr;
	const char                 version = 0x30;
	RvMegacoParameterValue     paramValue2, paramValue3;

	sprintf(dispBuf, "In applOffHookListenReq(), termInd %d", termInd);
	rvLogInfo3(&rvLog, dispBuf); 

	applInfo[termInd].markedAction = NO_EVENT; /* Clean everything up            */
	applInfo[termInd].connectInitiatorInd = -1;
	applInfo[termInd].discInitiatorInd = -1;

	applInfo[termInd].modifyCommandPtr = rvAllocAllocate(&rvDefaultAlloc,
	  sizeof(RvMegacoModifyCommand)); 

	rvMegacoModifyCommandConstruct(applInfo[termInd].modifyCommandPtr, 
	  &applInfo[termInd].terminationId);

	/* Create new streamDescriptor */
	applInfo[termInd].streamId = rvMegacoStreamIdDefault;
	rvMegacoStreamDescriptorConstruct(&stream, applInfo[termInd].streamId); 

	/* Set mode for this streamDescr */
	rvMegacoStreamDescriptorSetMode(&stream, mode);

	/* Construct PackageItem we need */
	rvMegacoPackageItemConstruct(&packageItem2,
								  "tdmc",	/* Support TDM circuit termination*/
								  "gain");	/* Adapt the level of the signal  */
	rvMegacoParameterValueConstruct(&paramValue2,
									 "2");   /* The value of "gain"            */ 
	rvMegacoStreamDescriptorSetParameter(&stream, &packageItem2, &paramValue2);

	/* Construct PackageItem we need */
	rvMegacoPackageItemConstruct(&packageItem3,
								  "tdmc",	/* Support TDM circuit termination*/
								  "ec");	/* Echo cancellation is requested */
	rvMegacoParameterValueConstruct(&paramValue3,
									 "on");  /* The value of "ec"              */ 
	rvMegacoStreamDescriptorSetParameter(&stream,       
										  &packageItem3,
										  &paramValue3); 

	rvMegacoMediaDescriptorConstruct(&media);/* Construct MediaDescriptor     */
											  /* object. It may contain         */
											  /* multiple stream objects        */
	rvSdpMsgConstruct(&sdpMsg1);            /* Assemble SDP message for local */                  
	rvSdpMsgSetVersionN(&sdpMsg1, &version, 1);
	rvSdpMsgSetConnection(&sdpMsg1, RV_SDPNETTYPE_IN, RV_SDPADDRTYPE_IP4, "$"); 
	sdpMediaDescr = rvSdpMsgAddMediaDescr(&sdpMsg1, 
										   RV_SDPSYMB_AUDIO,
										   RV_SDPPORT_ANY, 
										   RV_SDPPROTOCOL_RTP);
	rvSdpMediaDescrAddFormat(sdpMediaDescr, "0");
	rvSdpMsgAddAttr(&sdpMsg1,
					 "fmtp",                  /*Special voice activity detection*/  
					 "PCMU VAD=X-NNVAD");    /* algorithm                      */
	rvMegacoStreamDescriptorAddLocalDescriptor(&stream, &sdpMsg1);
											  /* Add media to command object    */
											  /* Add this streamDescriptor to   */
											  /* media object                   */
	rvMegacoMediaDescriptorAddStream(&media, &stream); 
	rvMegacoModifyCommandSetMedia(applInfo[termInd].modifyCommandPtr,
								   &media);

	rvMegacoPackageItemConstruct(&packageItem1,/* Construct PackageItem we need*/
								  "al",       /* Analog Line Supervisory Package*/
								  "of");     /* Offhook eventId                */
											  /* Construct requestedEvent with  */
											  /* our packageItem                */
	rvMegacoRequestedEventConstruct(&requestedEvent, &packageItem1);
											  /* Create new EventsDescriptor    */
											  /* with the next requestId. It may*/
											  /* contain multiple events        */
	applInfo[termInd].requestId = 1;
	rvMegacoEventsDescriptorConstruct(&eventsDescriptor,
									   applInfo[termInd].requestId); 
											  /* Add requestedEvent             */
	rvMegacoEventsDescriptorAddEvent(&eventsDescriptor, &requestedEvent);
											  /* Add eventsDescriptor to command*/
	rvMegacoModifyCommandSetEvents(applInfo[termInd].modifyCommandPtr,
									&eventsDescriptor);
											  /* Construct initial contextId    */
	rvMegacoContextIdConstructSpecial(&applInfo[termInd].contextId,
									   RV_MEGACOCONTEXTID_NULL); 
	applInfo[termInd].commandType = RV_MEGACOCOMMANDTYPE_MODIFY;    
	sendRequest(SEND_COMMAND);   
											  /* Event to perform next if this  */
											  /* request is confirmed           */
	applInfo[termInd].nextEvent = NO_EVENT;   /* Sit idle and ready             */
	rvSdpMsgDestruct(&sdpMsg1);              
	rvMegacoStreamDescriptorDestruct(&stream); 
	rvMegacoMediaDescriptorDestruct(&media);
	rvMegacoParameterValueDestruct(&paramValue2);
	rvMegacoParameterValueDestruct(&paramValue3);
	rvMegacoPackageItemDestruct(&packageItem1);
	rvMegacoPackageItemDestruct(&packageItem2);
	rvMegacoPackageItemDestruct(&packageItem3);
	rvMegacoRequestedEventDestruct(&requestedEvent);
	rvMegacoEventsDescriptorDestruct(&eventsDescriptor);

	return NO_EVENT;
}

/********************************************************************************/
/*  One of the terminations ends the call in state 2. The 2nd termination is    */
/* not in the context yet, the first one may or may not be in context           */ 
/********************************************************************************/
int  applOnHookDiscInd2(void)    
{
	RvMegacoSubtractCommand    subtractCommand1;
	RvMegacoContextIdType type =
		rvMegacoContextIdGetType(&applInfo[termInd].contextId);

	sprintf(dispBuf, "In applOnHookDiscInd2(), termInd %d", termInd);
	rvLogInfo3(&rvLog, dispBuf); 

	if (type == RV_MEGACOCONTEXTID_NORMAL);
	else
		{
		applInfo[termInd].callInProgress = rvFalse;
		rvMegacoContextIdDestruct(&applInfo[termInd].contextId);
		applInfo[termInd].requestId = 0;
		return  E_OFF_HOOK_LISTEN_REQ; 
		}

	applInfo[termInd].actionOutPtr =            /* Set up the action            */
		rvAllocAllocate(&rvDefaultAlloc,
					 (sizeof(RvMegacoSubtractCommand))*2); 
	rvMegacoActionConstruct(applInfo[termInd].actionOutPtr, 
							 &applInfo[termInd].contextId);	        
	rvMegacoSubtractCommandConstruct(&subtractCommand1,
									  &applInfo[termInd].terminationId);
	rvMegacoActionAddCommand(applInfo[termInd].actionOutPtr, &subtractCommand1);
	sendRequest(SEND_ACTION);

	rvMegacoSubtractCommandDestruct(&subtractCommand1); 

	rvMegacoActionDestruct(applInfo[termInd].actionOutPtr);
	rvAllocDeallocate(&rvDefaultAlloc,
					   (sizeof(RvMegacoSubtractCommand))*2,
					   applInfo[termInd].actionOutPtr); 
	applInfo[termInd].actionOutPtr = NULL;                                          
	rvMegacoContextIdDestruct(&applInfo[termInd].contextId);
	applInfo[termInd].remoteTermInd = -1;

	applInfo[termInd].requestId = 0;
	applInfo[termInd].callInProgress = rvFalse;
	
	return E_OFF_HOOK_LISTEN_REQ;
}

⌨️ 快捷键说明

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