[asterisk-commits] jrose: trunk r401622 - in /trunk: ./ main/translate.c res/res_rtp_asterisk.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 23 12:56:55 CDT 2013


Author: jrose
Date: Wed Oct 23 12:56:44 2013
New Revision: 401622

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=401622
Log:
res_rtp_asterisk: Address jittery DTMF events in RTP streams

(closes issue ASTERISK-21170)
Reported by: NITESH BANSAL
Patches:
    dtmf-timestamp.patch uploaded by NITESH BANSAL (license 6418)
Review: https://reviewboard.asterisk.org/r/2938/
........

Merged revisions 401619 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 401620 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 401621 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/main/translate.c
    trunk/res/res_rtp_asterisk.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: trunk/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/translate.c?view=diff&rev=401622&r1=401621&r2=401622
==============================================================================
--- trunk/main/translate.c (original)
+++ trunk/main/translate.c Wed Oct 23 12:56:44 2013
@@ -537,6 +537,10 @@
 		/* Predict next outgoing timestamp from samples in this
 		   frame. */
 		path->nextout = ast_tvadd(path->nextout, ast_samp2tv(out->samples, ast_format_rate(&out->subclass.format)));
+		if (f->samples != out->samples && ast_test_flag(out, AST_FRFLAG_HAS_TIMING_INFO)) {
+			ast_debug(4, "Sample size different %u vs %u\n", f->samples, out->samples);
+			ast_clear_flag(out, AST_FRFLAG_HAS_TIMING_INFO);
+		}
 	} else {
 		out->delivery = ast_tv(0, 0);
 		ast_set2_flag(out, has_timing_info, AST_FRFLAG_HAS_TIMING_INFO);

Modified: trunk/res/res_rtp_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_rtp_asterisk.c?view=diff&rev=401622&r1=401621&r2=401622
==============================================================================
--- trunk/res/res_rtp_asterisk.c (original)
+++ trunk/res/res_rtp_asterisk.c Wed Oct 23 12:56:44 2013
@@ -94,6 +94,7 @@
 #define RTCP_PT_PSFB    206
 
 #define RTP_MTU		1200
+#define DTMF_SAMPLE_RATE_MS    8 /*!< DTMF samples per millisecond */
 
 #define DEFAULT_DTMF_TIMEOUT (150 * (8000 / 1000))	/*!< samples */
 
@@ -1726,6 +1727,35 @@
 }
 #endif
 
+/*!
+ * \internal
+ * \brief Calculates the elapsed time from issue of the first tx packet in an
+ *        rtp session and a specified time
+ *
+ * \param rtp pointer to the rtp struct with the transmitted rtp packet
+ * \param delivery time of delivery - if NULL or zero value, will be ast_tvnow()
+ *
+ * \return time elapsed in milliseconds
+ */
+static unsigned int calc_txstamp(struct ast_rtp *rtp, struct timeval *delivery)
+{
+	struct timeval t;
+	long ms;
+
+	if (ast_tvzero(rtp->txcore)) {
+		rtp->txcore = ast_tvnow();
+		rtp->txcore.tv_usec -= rtp->txcore.tv_usec % 20000;
+	}
+
+	t = (delivery && !ast_tvzero(*delivery)) ? *delivery : ast_tvnow();
+	if ((ms = ast_tvdiff_ms(t, rtp->txcore)) < 0) {
+		ms = 0;
+	}
+	rtp->txcore = t;
+
+	return (unsigned int) ms;
+}
+
 static int ast_rtp_new(struct ast_rtp_instance *instance,
 		       struct ast_sched_context *sched, struct ast_sockaddr *addr,
 		       void *data)
@@ -1957,6 +1987,7 @@
 
 	rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000));
 	rtp->send_duration = 160;
+	rtp->lastts += calc_txstamp(rtp, NULL) * DTMF_SAMPLE_RATE_MS;
 	rtp->lastdigitts = rtp->lastts + rtp->send_duration;
 
 	/* Create the actual packet that we will be sending */
@@ -2037,6 +2068,7 @@
 	/* And now we increment some values for the next time we swing by */
 	rtp->seqno++;
 	rtp->send_duration += 160;
+	rtp->lastts += calc_txstamp(rtp, NULL) * DTMF_SAMPLE_RATE_MS;
 
 	return 0;
 }
@@ -2114,7 +2146,7 @@
 	res = 0;
 
 	/* Oh and we can't forget to turn off the stuff that says we are sending DTMF */
-	rtp->lastts += rtp->send_duration;
+	rtp->lastts += calc_txstamp(rtp, NULL) * DTMF_SAMPLE_RATE_MS;
 cleanup:
 	rtp->sending_digit = 0;
 	rtp->send_digit = 0;
@@ -2162,25 +2194,6 @@
 	rtp->ssrc = ssrc;
 
 	return;
-}
-
-static unsigned int calc_txstamp(struct ast_rtp *rtp, struct timeval *delivery)
-{
-	struct timeval t;
-	long ms;
-
-	if (ast_tvzero(rtp->txcore)) {
-		rtp->txcore = ast_tvnow();
-		rtp->txcore.tv_usec -= rtp->txcore.tv_usec % 20000;
-	}
-
-	t = (delivery && !ast_tvzero(*delivery)) ? *delivery : ast_tvnow();
-	if ((ms = ast_tvdiff_ms(t, rtp->txcore)) < 0) {
-		ms = 0;
-	}
-	rtp->txcore = t;
-
-	return (unsigned int) ms;
 }
 
 static void timeval2ntp(struct timeval tv, unsigned int *msw, unsigned int *lsw)




More information about the asterisk-commits mailing list