[asterisk-commits] pcadach: branch pcadach/chan_h323-live r42443 - in /team/pcadach/chan_h323-li...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Sep 8 10:19:20 MST 2006


Author: pcadach
Date: Fri Sep  8 12:19:19 2006
New Revision: 42443

URL: http://svn.digium.com/view/asterisk?rev=42443&view=rev
Log:
1) Simulate DTMF END signal if timed H225 signal message is received without
   signal update message with real information of signal duration;
2) Allow receive only RTP setups when call placed on hold by CCM (remote
   receiver's IP is set to 0.0.0.0);
3) Handle DISPLAY and CALLING NUMBER information correctly.

Modified:
    team/pcadach/chan_h323-live/channels/chan_h323.c
    team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp

Modified: team/pcadach/chan_h323-live/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/team/pcadach/chan_h323-live/channels/chan_h323.c?rev=42443&r1=42442&r2=42443&view=diff
==============================================================================
--- team/pcadach/chan_h323-live/channels/chan_h323.c (original)
+++ team/pcadach/chan_h323-live/channels/chan_h323.c Fri Sep  8 12:19:19 2006
@@ -186,7 +186,9 @@
 	int jointcapability;				/* Common capabilities for local and remote side */
 	int dtmf_pt;						/* Payload code used for RFC2833 messages */
 	int curDTMF;						/* DTMF tone being generated */
+	int DTMFsched;						/* Scheduler descriptor for DTMF */
 	int update_rtp_info;				/* Configuration of fd's array is pending */
+	int recvonly;						/* Peer isn't wish to receive our voice stream */
 	struct oh323_pvt *next;				/* Next channel in list */
 } *iflist = NULL;
 
@@ -281,6 +283,37 @@
 	free(peer);
 }
 
+static int oh323_simulate_dtmf_end(void *data)
+{
+	struct oh323_pvt *pvt = data;
+
+	if (pvt) {
+		ast_mutex_lock(&pvt->lock);
+		/* Don't hold pvt lock while trying to lock the channel */
+		while(pvt->owner && ast_channel_trylock(pvt->owner)) {
+			ast_mutex_unlock(&pvt->lock);
+			usleep(1);
+			ast_mutex_lock(&pvt->lock);
+		}
+
+		if (pvt->owner) {
+			struct ast_frame f = {
+				.frametype = AST_FRAME_DTMF_END,
+				.subclass = pvt->curDTMF,
+				.samples = 0,
+				.src = "SIMULATE_DTMF_END",
+			};
+			ast_queue_frame(pvt->owner, &f);
+			ast_channel_unlock(pvt->owner);
+		}
+
+		pvt->DTMFsched = -1;
+		ast_mutex_unlock(&pvt->lock);
+	}
+
+	return 0;
+}
+
 /* Channel and private structures should be already locked */
 static void __oh323_update_info(struct ast_channel *c, struct oh323_pvt *pvt)
 {
@@ -298,7 +331,7 @@
 		c->hangupcause = pvt->hangupcause;
 		ast_queue_hangup(c);
 		pvt->needhangup = 0;
-		pvt->newstate = pvt->newcontrol = pvt->newdigit = -1;
+		pvt->newstate = pvt->newcontrol = pvt->newdigit = pvt->DTMFsched = -1;
 	}
 	if (pvt->newstate >= 0) {
 		ast_setstate(c, pvt->newstate);
@@ -317,9 +350,18 @@
 		};
 		if (pvt->newdigit == ' ') {		/* signalUpdate message */
 			f.subclass = pvt->curDTMF;
+			if (pvt->DTMFsched >= 0) {
+				ast_sched_del(sched, pvt->DTMFsched);
+				pvt->DTMFsched = -1;
+			}
 		} else {						/* Regular input or signal message */
-			if (pvt->newduration)		/* This is a signal, signalUpdate follows */
+			if (pvt->newduration) {		/* This is a signal, signalUpdate follows */
 				f.frametype = AST_FRAME_DTMF_BEGIN;
+				if (pvt->DTMFsched >= 0)
+					ast_sched_del(sched, pvt->DTMFsched);
+				pvt->DTMFsched = ast_sched_add(sched, pvt->newduration, oh323_simulate_dtmf_end, pvt);
+				ast_log(LOG_DEBUG, "Scheduled DTMF END simulation for %d ms, id=%d\n", pvt->newduration, pvt->DTMFsched);
+			}
 			pvt->curDTMF = pvt->newdigit;
 		}
 		ast_queue_frame(c, &f);
@@ -540,9 +582,11 @@
 
 	if (c->cid.cid_num) {
 		strncpy(pvt->options.cid_num, c->cid.cid_num, sizeof(pvt->options.cid_num));
+		ast_log(LOG_DEBUG, "Setting CID number to %s\n", pvt->options.cid_num);
 	}
 	if (c->cid.cid_name) {
 		strncpy(pvt->options.cid_name, c->cid.cid_name, sizeof(pvt->options.cid_name));
+		ast_log(LOG_DEBUG, "Setting CID name to %s\n", pvt->options.cid_name);
 	}
 
 	/* indicate that this is an outgoing call */
@@ -741,9 +785,8 @@
 	}
 	if (pvt) {
 		ast_mutex_lock(&pvt->lock);
-		if (pvt->rtp) {
+		if (pvt->rtp && !pvt->recvonly)
 			res =  ast_rtp_write(pvt->rtp, frame);
-		}
 		__oh323_update_info(c, pvt);
 		ast_mutex_unlock(&pvt->lock);
 	}
@@ -1020,7 +1063,7 @@
 		pvt->nonCodecCapability &= ~AST_RTP_DTMF;
 	}
 	strncpy(pvt->context, default_context, sizeof(pvt->context) - 1);
-	pvt->newstate = pvt->newcontrol = pvt->newdigit = pvt->update_rtp_info = -1;
+	pvt->newstate = pvt->newcontrol = pvt->newdigit = pvt->update_rtp_info = pvt->DTMFsched = -1;
 	ast_mutex_init(&pvt->lock);
 	/* Add to interface list */
 	ast_mutex_lock(&iflock);
@@ -1664,9 +1707,18 @@
 			};
 			if (digit == ' ') {		/* signalUpdate message */
 				f.subclass = pvt->curDTMF;
+				if (pvt->DTMFsched >= 0) {
+					ast_sched_del(sched, pvt->DTMFsched);
+					pvt->DTMFsched = -1;
+				}
 			} else {				/* Regular input or signal message */
-				if (duration)		/* This is a signal, signalUpdate follows */
+				if (duration) {		/* This is a signal, signalUpdate follows */
 					f.frametype = AST_FRAME_DTMF_BEGIN;
+					if (pvt->DTMFsched >= 0)
+						ast_sched_del(sched, pvt->DTMFsched);
+					pvt->DTMFsched = ast_sched_add(sched, duration, oh323_simulate_dtmf_end, pvt);
+					ast_log(LOG_DEBUG, "Scheduled DTMF END simulation for %d ms, id=%d\n", duration, pvt->DTMFsched);
+				}
 				pvt->curDTMF = digit;
 			}
 			res = ast_queue_frame(pvt->owner, &f);
@@ -1746,6 +1798,7 @@
 	struct sockaddr_in them;
 	struct rtpPayloadType rtptype;
 	int nativeformats_changed;
+	enum { NEED_NONE, NEED_HOLD, NEED_UNHOLD } rtp_change = NEED_NONE;
 
 	if (h323debug)
 		ast_log(LOG_DEBUG, "Setting up RTP connection for %s\n", token);
@@ -1763,6 +1816,25 @@
 	
 	if (!pvt->rtp)
 		__oh323_rtp_create(pvt);
+
+	them.sin_family = AF_INET;
+	/* only works for IPv4 */
+	them.sin_addr.s_addr = inet_addr(remoteIp); 
+	them.sin_port = htons(remotePort);
+
+	if (them.sin_addr.s_addr) {
+		ast_rtp_set_peer(pvt->rtp, &them);
+		if (pvt->recvonly) {
+			pvt->recvonly = 0;
+			rtp_change = NEED_UNHOLD;
+		}
+	} else {
+		ast_rtp_stop(pvt->rtp);
+		if (!pvt->recvonly) {
+			pvt->recvonly = 1;
+			rtp_change = NEED_HOLD;
+		}
+	}
 
 	/* Change native format to reflect information taken from OLC/OLCAck */
 	nativeformats_changed = 0;
@@ -1778,7 +1850,7 @@
 		ast_log(LOG_NOTICE, "Payload type is unknown, formats isn't changed\n");
 
 	/* Don't try to lock the channel if nothing changed */
-	if (nativeformats_changed || pvt->options.progress_audio) {
+	if (nativeformats_changed || pvt->options.progress_audio || (rtp_change != NEED_NONE)) {
 		if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
 			/* Re-build translation path only if native format(s) has been changed */
 			if (pvt->owner->nativeformats != pvt->nativeformats) {
@@ -1790,22 +1862,29 @@
 			}
 			if (pvt->options.progress_audio)
 				ast_queue_control(pvt->owner, AST_CONTROL_PROGRESS);
+			switch (rtp_change) {
+			case NEED_HOLD:
+				ast_queue_control(pvt->owner, AST_CONTROL_HOLD);
+				break;
+			case NEED_UNHOLD:
+				ast_queue_control(pvt->owner, AST_CONTROL_UNHOLD);
+				break;
+			default:
+				break;
+			}
 			ast_channel_unlock(pvt->owner);
 		}
 		else {
 			if (pvt->options.progress_audio)
 				pvt->newcontrol = AST_CONTROL_PROGRESS;
+			else if (rtp_change == NEED_HOLD)
+				pvt->newcontrol = AST_CONTROL_HOLD;
+			else if (rtp_change == NEED_UNHOLD)
+				pvt->newcontrol = AST_CONTROL_UNHOLD;
 			if (h323debug)
 				ast_log(LOG_DEBUG, "RTP connection preparation for %s is pending...\n", token);
 		}
 	}
-
-	them.sin_family = AF_INET;
-	/* only works for IPv4 */
-	them.sin_addr.s_addr = inet_addr(remoteIp); 
-	them.sin_port = htons(remotePort);
-	ast_rtp_set_peer(pvt->rtp, &them);
-
 	ast_mutex_unlock(&pvt->lock);
 
 	if (h323debug)

Modified: team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp
URL: http://svn.digium.com/view/asterisk/team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp?rev=42443&r1=42442&r2=42443&view=diff
==============================================================================
--- team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp (original)
+++ team/pcadach/chan_h323-live/channels/h323/ast_h323.cpp Fri Sep  8 12:19:19 2006
@@ -816,12 +816,15 @@
 			h245Tunneling = TRUE;
 	}
 
-	if (opts->cid_num)
+	if (opts->cid_num) {
 		ast_cid_num = PString(opts->cid_num);
+		if (!isIncoming)
+			SetLocalPartyName(ast_cid_num);
+	}
 	if (opts->cid_name) {
 		ast_cid_name = PString(opts->cid_name);
 		if (!isIncoming)
-			SetLocalPartyName(ast_cid_name);
+			SetDisplayName(ast_cid_name);
 	}
 }
 
@@ -917,10 +920,6 @@
 	if (connectionState == ShuttingDownConnection)
 		return FALSE;
 
-	if (!ast_cid_num.IsEmpty())
-		setupPDU.GetQ931().SetCallingPartyNumber(ast_cid_num);
-	if (!ast_cid_name.IsEmpty())
-		setupPDU.GetQ931().SetDisplayName(ast_cid_name);
 	if (progressSetup)
 		setupPDU.GetQ931().SetProgressIndicator(progressSetup);
 	
@@ -1377,20 +1376,17 @@
 
 BOOL MyH323_ExternalRTPChannel::OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param)
 {
-	PIPSocket::Address remoteIpAddress;
-	WORD remotePort;
-
 	if (h323debug) {
 		cout << "	MyH323_ExternalRTPChannel::OnReceivedAckPDU" << endl;
 	}
 
 	if (H323_ExternalRTPChannel::OnReceivedAckPDU(param)) {
-		GetRemoteAddress(remoteIpAddress, remotePort);
+		GetRemoteAddress(remoteIpAddr, remotePort);
 		if (h323debug) {
-			cout << "		-- remoteIpAddress: " << remoteIpAddress << endl;
+			cout << "		-- remoteIpAddress: " << remoteIpAddr << endl;
 			cout << "		-- remotePort: " << remotePort << endl;
 		}
-		on_start_rtp_channel(connection.GetCallReference(), (const char *)remoteIpAddress.AsString(),
+		on_start_rtp_channel(connection.GetCallReference(), (const char *)remoteIpAddr.AsString(),
 				remotePort, (const char *)connection.GetCallToken(), (int)payloadCode);
 		return TRUE;
 	}



More information about the asterisk-commits mailing list