[asterisk-commits] oej: branch oej/rana-dtmf-rtp-duration-1.6.0 r305751 - /team/oej/rana-dtmf-rt...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 2 08:20:45 CST 2011


Author: oej
Date: Wed Feb  2 08:20:39 2011
New Revision: 305751

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=305751
Log:
Updates after testing with and without local channels

Found out that features.c did not support DTMF duration at all.

Modified:
    team/oej/rana-dtmf-rtp-duration-1.6.0/main/features.c
    team/oej/rana-dtmf-rtp-duration-1.6.0/main/rtp.c

Modified: team/oej/rana-dtmf-rtp-duration-1.6.0/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/rana-dtmf-rtp-duration-1.6.0/main/features.c?view=diff&rev=305751&r1=305750&r2=305751
==============================================================================
--- team/oej/rana-dtmf-rtp-duration-1.6.0/main/features.c (original)
+++ team/oej/rana-dtmf-rtp-duration-1.6.0/main/features.c Wed Feb  2 08:20:39 2011
@@ -2389,11 +2389,13 @@
 					   digits to come in for features. */
 					ast_debug(1, "Timed out for feature!\n");
 					if (!ast_strlen_zero(peer_featurecode)) {
-						ast_dtmf_stream(chan, peer, peer_featurecode, 0, 0);
+						ast_log(LOG_DEBUG, "--- Sending DTMF here\n");
+						ast_dtmf_stream(chan, peer, peer_featurecode, 0, f->len);
 						memset(peer_featurecode, 0, sizeof(peer_featurecode));
 					}
 					if (!ast_strlen_zero(chan_featurecode)) {
-						ast_dtmf_stream(peer, chan, chan_featurecode, 0, 0);
+						ast_log(LOG_DEBUG, "--- Sending DTMF here - 2\n");
+						ast_dtmf_stream(peer, chan, chan_featurecode, 0, f->len);
 						memset(chan_featurecode, 0, sizeof(chan_featurecode));
 					}
 					if (f)
@@ -2464,6 +2466,7 @@
 		} else if (f->frametype == AST_FRAME_DTMF) {
 			char *featurecode;
 			int sense;
+			unsigned int dtmfduration = f->len;
 
 			hadfeatures = hasfeatures;
 			/* This cannot overrun because the longest feature is one shorter than our buffer */
@@ -2486,7 +2489,8 @@
 			res = ast_feature_interpret(chan, peer, config, featurecode, sense);
 			switch(res) {
 			case FEATURE_RETURN_PASSDIGITS:
-				ast_dtmf_stream(other, who, featurecode, 0, 0);
+				ast_log(LOG_DEBUG, "--- Sending DTMF here - 3 Duration %d\n", dtmfduration);
+				ast_dtmf_stream(other, who, featurecode, 0, dtmfduration);
 				/* Fall through */
 			case FEATURE_RETURN_SUCCESS:
 				memset(featurecode, 0, sizeof(chan_featurecode));

Modified: team/oej/rana-dtmf-rtp-duration-1.6.0/main/rtp.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/rana-dtmf-rtp-duration-1.6.0/main/rtp.c?view=diff&rev=305751&r1=305750&r2=305751
==============================================================================
--- team/oej/rana-dtmf-rtp-duration-1.6.0/main/rtp.c (original)
+++ team/oej/rana-dtmf-rtp-duration-1.6.0/main/rtp.c Wed Feb  2 08:20:39 2011
@@ -144,6 +144,7 @@
 	unsigned int lastdigitts;
 	char sending_digit;	/*!< boolean - are we sending digits */
 	char send_digit;	/*!< digit we are sending */
+	char send_dtmf_frame;	/*!< Number of samples in a frame with the current packetization */
 	int send_payload;
 	int send_duration;
 	int send_endflag:1;	/*!< We have received END marker but are in waiting mode */
@@ -1015,7 +1016,7 @@
 				f = ast_frdup(create_dtmf_frame(rtp, AST_FRAME_DTMF_END));
 				f->len = ast_tvdiff_ms(ast_samp2tv(rtp->dtmf_duration, rtp_get_rate(f->subclass)), ast_tv(0, 0));
 				rtp->resp = 0;
-				ast_log(LOG_DEBUG, "--GOT DTMF END message. Duration samples %d\n", rtp->dtmf_duration);
+				ast_log(LOG_DEBUG, "--GOT DTMF END message. Duration samples %d (%ld ms)\n", rtp->dtmf_duration, f->len);
 				rtp->dtmf_duration = rtp->dtmf_timeout = 0;
 				AST_LIST_INSERT_TAIL(frames, f, frame_list);
 			}
@@ -2725,11 +2726,9 @@
 				    ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastdigitts, res - hdrlen);
 		/* Increment sequence number */
 		rtp->seqno++;
-		/* Clear marker bit and set seqno */
-		rtpheader[0] = htonl((2 << 30) | (payload << 16) | (rtp->seqno));
-	}
-	/* Increment duration */
-	rtp->send_duration += 160;
+		/* Raise the seqno */
+		rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno));
+	}
 
 	/* Since we received a begin, we can safely store the digit and disable any compensation */
 	rtp->sending_digit = 1;
@@ -2754,8 +2753,7 @@
 		   so we can't assume 20 ms (160 units in 8000 hz audio).
 		*/
 		// int dursamples =  duration * (rtp_get_rate(f->subclass) / 1000)
-		int dursamples =  duration * (8000 / 1000);	/* How do we get the sample rate for the primary media in this call? */
-		// f->len = ast_tvdiff_ms(ast_samp2tv(rtp->dtmf_duration, rtp_get_rate(f->subclass)), ast_tv(0, 0));
+		int dursamples =  duration * (rtp_get_rate(rtp->f.subclass) / 1000);	/* How do we get the sample rate for the primary media in this call? */
 
 		ast_log(LOG_DEBUG, "DTMF CONTINUE : %d ms %d samples\n", duration, dursamples);
 		rtp->received_duration = dursamples;
@@ -2777,11 +2775,11 @@
 		return 0;
 
 	ast_log(LOG_DEBUG, "---- Send duration %d Received duration %d Endflag %d Send-digit %d\n", rtp->send_duration, rtp->received_duration, rtp->send_endflag, rtp->send_digit);
-	if (rtp->send_duration + 160 < rtp->received_duration) {
+
+	if (rtp->received_duration == 0 || rtp->send_duration + 160 <= rtp->received_duration) {
 		rtp->send_duration += 160;
 	} else if (rtp->send_endflag) {
 		ast_log(LOG_DEBUG, "---- Send duration %d Received duration %d - sending END packet\n", rtp->send_duration, rtp->received_duration);
-		rtp->send_duration += 160;
 		/* We are done, ready to send end flag */
 		rtp->send_endflag = 0;
 		return ast_rtp_senddigit_end(rtp, 0, rtp->received_duration);
@@ -2819,6 +2817,7 @@
 	unsigned int *rtpheader;
 	int hdrlen = 12, res = 0, i = 0;
 	char data[256];
+
 	int dursamples =  duration * (8000 / 1000);	/* How do we get the sample rate for the primary media in this call? */
 	
 	/* If no address, then bail out */
@@ -2826,7 +2825,11 @@
 		return 0;
 
 
-	ast_log(LOG_DEBUG, "---- Send duration %d Received duration %d Endflag %d Digit %d Send-digit %d\n", rtp->send_duration, rtp->received_duration, rtp->send_endflag, digit, rtp->send_digit);
+	ast_log(LOG_DEBUG, "---- Send duration %d Received duration %d Duration %d Endflag %d Digit %d Send-digit %d\n", rtp->send_duration, rtp->received_duration, duration, rtp->send_endflag, digit, rtp->send_digit);
+
+	//if (dursamples > rtp->received_duration) {
+		//rtp->received_duration = dursamples;
+	//}
 
 	if (!rtp->send_endflag && rtp->send_duration + 160 < rtp->received_duration) {
 		/* We still have to send DTMF continuation, because otherwise we will end prematurely. Set end flag to indicate
@@ -2861,8 +2864,11 @@
 
 	rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000));
 
-	//rtp->send_duration = rtp->received_duration;	/* Compensate for the last CONT packet */
-	rtp->send_duration = dursamples;	/* Compensate for the last CONT packet */
+	rtp->send_duration += 160;
+
+	if (rtp->received_duration > rtp->send_duration) {
+		rtp->send_duration = rtp->received_duration;
+	}
 
 	rtpheader = (unsigned int *)data;
 	rtpheader[1] = htonl(rtp->lastdigitts);
@@ -2885,7 +2891,7 @@
 				    ast_inet_ntoa(rtp->them.sin_addr),
 				    ntohs(rtp->them.sin_port), rtp->send_payload, rtp->seqno, rtp->lastdigitts, res - hdrlen);
 	}
-	ast_log(LOG_DEBUG, "-- DTMF END: Duration samples %d ms %d\n", rtp->send_duration, duration);
+	ast_log(LOG_DEBUG, "-- DTMF END: Duration samples sent %d got %d ms (%d samples)\n", rtp->send_duration, duration, dursamples);
 	rtp->lastts += rtp->send_duration;
 	rtp->sending_digit = 0;
 	rtp->send_digit = 0;




More information about the asterisk-commits mailing list