[asterisk-commits] file: branch 1.4 r58783 - /branches/1.4/main/rtp.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun Mar 11 18:21:13 MST 2007


Author: file
Date: Sun Mar 11 20:21:12 2007
New Revision: 58783

URL: http://svn.digium.com/view/asterisk?view=rev&rev=58783
Log:
Allow RFC2833 compensation to compensate for even stupider implementations by queueing up the end frame at the start, not the actual end. (issue #8963 reported by AndrewZ)

Modified:
    branches/1.4/main/rtp.c

Modified: branches/1.4/main/rtp.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/rtp.c?view=diff&rev=58783&r1=58782&r2=58783
==============================================================================
--- branches/1.4/main/rtp.c (original)
+++ branches/1.4/main/rtp.c Sun Mar 11 20:21:12 2007
@@ -138,7 +138,7 @@
 
 	/* DTMF Reception Variables */
 	char resp;
-	unsigned int lasteventendseqn;
+	unsigned int lastevent;
 	int dtmfcount;
 	unsigned int dtmfsamples;
 	/* DTMF Transmission Variables */
@@ -705,7 +705,7 @@
  * \param seqno
  * \returns
  */
-static struct ast_frame *process_rfc2833(struct ast_rtp *rtp, unsigned char *data, int len, unsigned int seqno)
+static struct ast_frame *process_rfc2833(struct ast_rtp *rtp, unsigned char *data, int len, unsigned int seqno, unsigned int timestamp)
 {
 	unsigned int event;
 	unsigned int event_end;
@@ -739,21 +739,23 @@
 		resp = 'X';	
 	}
 
-	if ((!(rtp->resp) && (!(event_end & 0x80))) || (rtp->resp && rtp->resp != resp)) {
-		rtp->resp = resp;
-		if (!ast_test_flag(rtp, FLAG_DTMF_COMPENSATE))
+	if (ast_test_flag(rtp, FLAG_DTMF_COMPENSATE)) {
+		if ((rtp->lastevent != timestamp) || (rtp->resp && rtp->resp != resp)) {
+			rtp->resp = resp;
+			f = send_dtmf(rtp, AST_FRAME_DTMF_END);
+			f->len = 0;
+			rtp->lastevent = timestamp;
+		}
+	} else {
+		if ((!(rtp->resp) && (!(event_end & 0x80))) || (rtp->resp && rtp->resp != resp)) {
+			rtp->resp = resp;
 			f = send_dtmf(rtp, AST_FRAME_DTMF_BEGIN);
-	} else if (event_end & 0x80 && rtp->lasteventendseqn != seqno && rtp->resp) {
-		f = send_dtmf(rtp, AST_FRAME_DTMF_END);
-		f->len = ast_tvdiff_ms(ast_samp2tv(samples, 8000), ast_tv(0, 0)); /* XXX hard coded 8kHz */
-		rtp->resp = 0;
-		rtp->lasteventendseqn = seqno;
-	} else if (ast_test_flag(rtp, FLAG_DTMF_COMPENSATE) && event_end & 0x80 && rtp->lasteventendseqn != seqno) {
-		rtp->resp = resp;
-		f = send_dtmf(rtp, AST_FRAME_DTMF_END);
-		f->len = ast_tvdiff_ms(ast_samp2tv(samples, 8000), ast_tv(0, 0)); /* XXX hard coded 8kHz */
-		rtp->resp = 0;
-		rtp->lasteventendseqn = seqno;
+		} else if ((event_end & 0x80) && (rtp->lastevent != seqno) && rtp->resp) {
+			f = send_dtmf(rtp, AST_FRAME_DTMF_END);
+			f->len = ast_tvdiff_ms(ast_samp2tv(samples, 8000), ast_tv(0, 0)); /* XXX hard coded 8kHz */
+			rtp->resp = 0;
+			rtp->lastevent = seqno;
+		}
 	}
 
 	rtp->dtmfcount = dtmftimeout;
@@ -1240,12 +1242,12 @@
 				duration &= 0xFFFF;
 				ast_verbose("Got  RTP RFC2833 from   %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u, mark %d, event %08x, end %d, duration %-5.5d) \n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp, res - hdrlen, (mark?1:0), event, ((event_end & 0x80)?1:0), duration);
 			}
-			f = process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno);
+			f = process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno, timestamp);
 		} else if (rtpPT.code == AST_RTP_CISCO_DTMF) {
 			/* It's really special -- process it the Cisco way */
-			if (rtp->lasteventseqn <= seqno || (rtp->lasteventseqn >= 65530 && seqno <= 6)) {
+			if (rtp->lastevent <= seqno || (rtp->lastevent >= 65530 && seqno <= 6)) {
 				f = process_cisco_dtmf(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen);
-				rtp->lasteventseqn = seqno;
+				rtp->lastevent = seqno;
 			}
 		} else if (rtpPT.code == AST_RTP_CN) {
 			/* Comfort Noise */
@@ -2013,7 +2015,7 @@
 	rtp->lastividtimestamp = 0;
 	rtp->lastovidtimestamp = 0;
 	rtp->lasteventseqn = 0;
-	rtp->lasteventendseqn = 0;
+	rtp->lastevent = 0;
 	rtp->lasttxformat = 0;
 	rtp->lastrxformat = 0;
 	rtp->dtmfcount = 0;



More information about the asterisk-commits mailing list