[svn-commits] file: branch file/rtp_engine r129500 - /team/file/rtp_engine/res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jul 9 17:57:37 CDT 2008


Author: file
Date: Wed Jul  9 17:57:37 2008
New Revision: 129500

URL: http://svn.digium.com/view/asterisk?view=rev&rev=129500
Log:
Bring back symmetric RTP support.

Modified:
    team/file/rtp_engine/res/res_rtp_asterisk.c

Modified: team/file/rtp_engine/res/res_rtp_asterisk.c
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/res/res_rtp_asterisk.c?view=diff&rev=129500&r1=129499&r2=129500
==============================================================================
--- team/file/rtp_engine/res/res_rtp_asterisk.c (original)
+++ team/file/rtp_engine/res/res_rtp_asterisk.c Wed Jul  9 17:57:37 2008
@@ -90,6 +90,15 @@
 	STRICT_RTP_LEARN,    /*! Accept next packet as source */
 	STRICT_RTP_CLOSED,   /*! Drop all RTP packets not coming from source that was learned */
 };
+
+#define FLAG_3389_WARNING               (1 << 0)
+#define FLAG_NAT_ACTIVE                 (3 << 1)
+#define FLAG_NAT_INACTIVE               (0 << 1)
+#define FLAG_NAT_INACTIVE_NOWARN        (1 << 1)
+#define FLAG_P2P_SENT_MARK              (1 << 4)
+#define FLAG_P2P_NEED_DTMF              (1 << 5)
+#define FLAG_NEED_MARKER_BIT            (1 << 6)
+#define FLAG_DTMF_COMPENSATE            (1 << 7)
 
 /*! \brief RTP session description */
 struct ast_rtp {
@@ -152,10 +161,6 @@
 
 	enum strict_rtp_state strict_rtp_state; /*!< Current state that strict RTP protection is in */
 	struct sockaddr_in strict_rtp_address;  /*!< Remote address information for strict RTP purposes */
-
-	unsigned int set_marker_bit:1;           /*!< Whether to set the marker bit or not */
-	unsigned int dtmf_compensate:1;
-	unsigned int cn_warning:1;
 };
 
 /*!
@@ -577,7 +582,7 @@
 	struct ast_rtp *rtp = instance->data;
 
 	/* We simply set this bit so that the next packet sent will have the marker bit turned on */
-	rtp->set_marker_bit = 1;
+	ast_set_flag(rtp, FLAG_NEED_MARKER_BIT);
 
 	return;
 }
@@ -654,9 +659,9 @@
         }
 
 	/* If we have been explicitly told to set the marker bit then do so */
-	if (rtp->set_marker_bit) {
+	if (ast_test_flag(rtp, FLAG_NEED_MARKER_BIT)) {
 		mark = 1;
-		rtp->set_marker_bit = 0;
+		ast_clear_flag(rtp, FLAG_NEED_MARKER_BIT);
 	}
 
 	/* If the timestamp for non-digt packets has moved beyond the timestamp for digits, update the digit timestamp */
@@ -678,6 +683,14 @@
 		put_unaligned_uint32(rtpheader + 8, htonl(rtp->ssrc));
 
 		if ((res = sendto(rtp->s, (void *)rtpheader, frame->datalen + hdrlen, 0, (struct sockaddr *)&instance->remote_address, sizeof(instance->remote_address)))) {
+                        if (!instance->properties[AST_RTP_PROPERTY_NAT] || (instance->properties[AST_RTP_PROPERTY_NAT] && (ast_test_flag(rtp, FLAG_NAT_ACTIVE) == FLAG_NAT_ACTIVE))) {
+                                ast_debug(1, "RTP Transmission error of packet %d to %s:%d: %s\n", rtp->seqno, ast_inet_ntoa(instance->remote_address.sin_addr), ntohs(instance->remote_address.sin_port), strerror(errno));
+                        } else if (((ast_test_flag(rtp, FLAG_NAT_ACTIVE) == FLAG_NAT_INACTIVE) || rtpdebug) && !ast_test_flag(rtp, FLAG_NAT_INACTIVE_NOWARN)) {
+                                /* Only give this error message once if we are not RTP debugging */
+                                if (option_debug || rtpdebug)
+                                        ast_debug(0, "RTP NAT: Can't write RTP to private address %s:%d, waiting for other end to send audio...\n", ast_inet_ntoa(instance->remote_address.sin_addr), ntohs(instance->remote_address.sin_port));
+                                ast_set_flag(rtp, FLAG_NAT_INACTIVE_NOWARN);
+                        }
 		} else {
 			rtp->txcount++;
 			rtp->txoctetcount += (res - hdrlen);
@@ -1031,10 +1044,10 @@
         if (rtpdebug)
                 ast_debug(0, "- RTP 3389 Comfort noise event: Level %d (len = %d)\n", rtp->lastrxformat, len);
 
-	if (!rtp->cn_warning) {
+	if (ast_test_flag(rtp, FLAG_3389_WARNING)) {
                 ast_log(LOG_NOTICE, "Comfort noise support incomplete in Asterisk (RFC 3389). Please turn off on client if possible. Client IP: %s\n",
                         ast_inet_ntoa(instance->remote_address.sin_addr));
-		rtp->cn_warning = 1;
+		ast_set_flag(rtp, FLAG_3389_WARNING);
         }
 
         /* Must have at least one byte */
@@ -1112,6 +1125,18 @@
 	}
 
 	/* If symmetric RTP is enabled see if the remote side is not what we expected and change where we are sending audio */
+        if (instance->properties[AST_RTP_PROPERTY_NAT]) {
+                if ((instance->remote_address.sin_addr.s_addr != sin.sin_addr.s_addr) ||
+                    (instance->remote_address.sin_port != sin.sin_port)) {
+                        instance->remote_address = sin;
+                        if (rtp->rtcp) {
+                        }
+                        rtp->rxseqno = 0;
+                        ast_set_flag(rtp, FLAG_NAT_ACTIVE);
+                        if (option_debug || rtpdebug)
+                                ast_debug(0, "RTP NAT: Got audio from other end. Now sending to address %s:%d\n", ast_inet_ntoa(instance->remote_address.sin_addr), ntohs(instance->remote_address.sin_port));
+                }
+        }
 
 	/* If the version is not what we expected by this point then just drop the packet */
 	if (version != 2) {




More information about the svn-commits mailing list