[asterisk-commits] mmichelson: branch 1.6.0 r254455 - in /branches/1.6.0: ./ main/rtp.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 25 11:11:06 CDT 2010


Author: mmichelson
Date: Thu Mar 25 11:11:02 2010
New Revision: 254455

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=254455
Log:
Recorded merge of revisions 254454 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
  r254454 | mmichelson | 2010-03-25 11:04:48 -0500 (Thu, 25 Mar 2010) | 50 lines
  
  Recorded merge of revisions 254452 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r254452 | mmichelson | 2010-03-25 10:59:56 -0500 (Thu, 25 Mar 2010) | 44 lines
    
    Several fixes regarding RFC2833 DTMF detection.
    
    Here is a copy and paste of the details from my request on
    reviewboard that dealt with these changes:
    
    Fix 1. The first change in place is to fix Mantis issue 15811, which deals with a situation where Asterisk will incorrectly interpret out of order RFC2833 frames as duplicate DTMF digits. For instance, we would receive a sequence like:
    
    seqno 1: DTMF 1
    seqno 2: DTMF 1
    seqno 3: DTMF 1
    seqno 4: DTMF 1
    seqno 6: DTMF 1 (end)
    seqno 5: DTMF 1
    seqno 7: DTMF 1 (end)
    seqno 8: DTMF 1 (end)
    
    Prior to this patch when we received the frame with seqno 5, we would interpret this as a new DTMF 1. With this patch, we will check the seqno of the incoming digit and not process the frame if the seqno is lower than the last recorded seqno. Note that we do not record the seqno of the dropped DTMF frame for future processing. While the above situation is what was designed to be fixed, the patch is written in such a way that the following would also be fixed too:
    
    seqno  9: DTMF 1
    seqno 10: DTMF 1 (end)
    seqno 11: DTMF 1 (end)
    seqno 13: DTMF 2
    seqno 12: DTMF 1 (end)
    seqno 14: DTMF 2
    seqno 15: DTMF 2 (end)
    seqno 16: DTMF 2 (end)
    seqno 17: DTMF 2 (end)
    
    In this second situation, the beginning of the DTMF 2 arrives before the final end frame of the DTMF 1. With the patch, seqno 12 is no processed and thus we properly interpret the DTMF.
    
    Fix 2. The second change in place is to fix an issue like the following:
    
    seqno 1: DTMF 1
    seqno 2: DTMF 1
    seqno 3: DTMF 1 (end) *packet lost*
    seqno 4: DTMF 1 (end) *packet lost*
    seqno 5: DTMF 1 (end) *packet lost*
    seqno 6: DTMF 2
    
    When we receive seqno 6, we had code in place that was supposed to properly end the previously unended DTMF 1. The problem was that the code was essentially a no-op. The code would set up an end frame for the DTMF 1 but would immediately overwrite the frame with the begin for DTMF 2. I changed process_dtmf_rfc2833() so that instead of returning a single frame, it is given as an output parameter a list of frames. Each frame that needs to be returned is appended to this list.
    
    Fix 3. The final change is a minor one where an AST_CONTROL_SRCCHANGE frame could get lost. If we process a cisco DTMF or an RFC 3389 frame and no frame was returned, then we would return &ast_null_frame. The problem is that earlier in the function, we may have generated an AST_CONTROL_SRCCHANGE frame and put it in the list of frames we wish to return. This frame would be lost in such a case. The patch fixes this problem
  ........
................

Modified:
    branches/1.6.0/   (props changed)
    branches/1.6.0/main/rtp.c

Propchange: branches/1.6.0/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.0/main/rtp.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.0/main/rtp.c?view=diff&rev=254455&r1=254454&r2=254455
==============================================================================
--- branches/1.6.0/main/rtp.c (original)
+++ branches/1.6.0/main/rtp.c Thu Mar 25 11:11:02 2010
@@ -181,6 +181,8 @@
 	int set_marker_bit:1;           /*!< Whether to set the marker bit or not */
 };
 
+AST_LIST_HEAD_NOLOCK(frame_list, ast_frame);
+
 /* Forward declarations */
 static int ast_rtcp_write(const void *data);
 static void timeval2ntp(struct timeval tv, unsigned int *msw, unsigned int *lsw);
@@ -794,7 +796,7 @@
 	return;
 }
 
-static struct ast_frame *send_dtmf(struct ast_rtp *rtp, enum ast_frame_type type)
+static struct ast_frame *create_dtmf_frame(struct ast_rtp *rtp, enum ast_frame_type type)
 {
 	if (((ast_test_flag(rtp, FLAG_DTMF_COMPENSATE) && type == AST_FRAME_DTMF_END) ||
 	     (type == AST_FRAME_DTMF_BEGIN)) && ast_tvcmp(ast_tvnow(), rtp->dtmfmute) < 0) {
@@ -815,6 +817,7 @@
 	rtp->f.samples = 0;
 	rtp->f.mallocd = 0;
 	rtp->f.src = "RTP";
+	AST_LIST_NEXT(&rtp->f, frame_list) = NULL;
 	return &rtp->f;
 	
 }
@@ -911,11 +914,11 @@
 		rtp->resp = resp;
 		/* Why we should care on DTMF compensation at reception? */
 		if (!ast_test_flag(rtp, FLAG_DTMF_COMPENSATE)) {
-			f = send_dtmf(rtp, AST_FRAME_DTMF_BEGIN);
+			f = create_dtmf_frame(rtp, AST_FRAME_DTMF_BEGIN);
 			rtp->dtmfsamples = 0;
 		}
 	} else if ((rtp->resp == resp) && !power) {
-		f = send_dtmf(rtp, AST_FRAME_DTMF_END);
+		f = create_dtmf_frame(rtp, AST_FRAME_DTMF_END);
 		f->samples = rtp->dtmfsamples * (rtp_get_rate(f->subclass) / 1000);
 		rtp->resp = 0;
 	} else if (rtp->resp == resp)
@@ -936,7 +939,7 @@
  * \param timestamp
  * \returns
  */
-static struct ast_frame *process_rfc2833(struct ast_rtp *rtp, unsigned char *data, int len, unsigned int seqno, unsigned int timestamp)
+static void process_rfc2833(struct ast_rtp *rtp, unsigned char *data, int len, unsigned int seqno, unsigned int timestamp, struct frame_list *frames)
 {
 	unsigned int event;
 	unsigned int event_end;
@@ -971,16 +974,17 @@
 	} else {
 		/* Not a supported event */
 		ast_log(LOG_DEBUG, "Ignoring RTP 2833 Event: %08x. Not a DTMF Digit.\n", event);
-		return &ast_null_frame;
+		return;
 	}
 
 	if (ast_test_flag(rtp, FLAG_DTMF_COMPENSATE)) {
 		if ((rtp->lastevent != timestamp) || (rtp->resp && rtp->resp != resp)) {
 			rtp->resp = resp;
 			rtp->dtmf_timeout = 0;
-			f = send_dtmf(rtp, AST_FRAME_DTMF_END);
+			f = ast_frdup(create_dtmf_frame(rtp, AST_FRAME_DTMF_END));
 			f->len = 0;
 			rtp->lastevent = timestamp;
+			AST_LIST_INSERT_TAIL(frames, f, frame_list);
 		}
 	} else {
 		/*  The duration parameter measures the complete
@@ -995,24 +999,34 @@
 			new_duration += 0xFFFF + 1;
 		new_duration = (new_duration & ~0xFFFF) | samples;
 
+		if (rtp->lastevent > seqno) {
+			/* Out of order frame. Processing this can cause us to
+			 * improperly duplicate incoming DTMF, so just drop
+			 * this.
+			 */
+			return;
+		}
+
 		if (event_end & 0x80) {
 			/* End event */
 			if ((rtp->lastevent != seqno) && rtp->resp) {
 				rtp->dtmf_duration = new_duration;
-				f = send_dtmf(rtp, AST_FRAME_DTMF_END);
+				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;
 				rtp->dtmf_duration = rtp->dtmf_timeout = 0;
+				AST_LIST_INSERT_TAIL(frames, f, frame_list);
 			}
 		} else {
 			/* Begin/continuation */
 
 			if (rtp->resp && rtp->resp != resp) {
 				/* Another digit already began. End it */
-				f = send_dtmf(rtp, AST_FRAME_DTMF_END);
+				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;
 				rtp->dtmf_duration = rtp->dtmf_timeout = 0;
+				AST_LIST_INSERT_TAIL(frames, f, frame_list);
 			}
 
 
@@ -1022,8 +1036,9 @@
 			} else {
 				/* New digit began */
 				rtp->resp = resp;
-				f = send_dtmf(rtp, AST_FRAME_DTMF_BEGIN);
+				f = ast_frdup(create_dtmf_frame(rtp, AST_FRAME_DTMF_BEGIN));
 				rtp->dtmf_duration = samples;
+				AST_LIST_INSERT_TAIL(frames, f, frame_list);
 			}
 
 			rtp->dtmf_timeout = timestamp + rtp->dtmf_duration + dtmftimeout;
@@ -1033,8 +1048,6 @@
 	}
 
 	rtp->dtmfsamples = samples;
-
-	return f;
 }
 
 /*!
@@ -1433,7 +1446,7 @@
 	unsigned int *rtpheader;
 	struct rtpPayloadType rtpPT;
 	struct ast_rtp *bridged = NULL;
-	AST_LIST_HEAD_NOLOCK(, ast_frame) frames;
+	struct frame_list frames;
 	
 	/* If time is up, kill it */
 	if (rtp->sending_digit)
@@ -1628,7 +1641,11 @@
 				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, timestamp);
+			/* process_rfc2833 may need to return multiple frames. We do this
+			 * by passing the pointer to the frame list to it so that the method
+			 * can append frames to the list as needed
+			 */
+			process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno, timestamp, &frames);
 		} else if (rtpPT.code == AST_RTP_CISCO_DTMF) {
 			/* It's really special -- process it the Cisco way */
 			if (rtp->lastevent <= seqno || (rtp->lastevent >= 65530 && seqno <= 6)) {
@@ -1643,6 +1660,11 @@
 		}
 		if (f) {
 			AST_LIST_INSERT_TAIL(&frames, f, frame_list);
+		}
+		/* Even if no frame was returned by one of the above methods,
+		 * we may have a frame to return in our frame list
+		 */
+		if (!AST_LIST_EMPTY(&frames)) {
 			return AST_LIST_FIRST(&frames);
 		}
 		return &ast_null_frame;
@@ -1657,7 +1679,7 @@
 
 		if (rtp->resp) {
 			struct ast_frame *f;
-			f = send_dtmf(rtp, AST_FRAME_DTMF_END);
+			f = 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;
 			rtp->dtmf_timeout = rtp->dtmf_duration = 0;




More information about the asterisk-commits mailing list