[asterisk-commits] file: trunk r42569 - /trunk/main/rtp.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Sep 9 11:08:00 MST 2006


Author: file
Date: Sat Sep  9 13:07:59 2006
New Revision: 42569

URL: http://svn.digium.com/view/asterisk?rev=3D42569&view=3Drev
Log:
It's another round of RTP updates!

Modified:
    trunk/main/rtp.c

Modified: trunk/main/rtp.c
URL: http://svn.digium.com/view/asterisk/trunk/main/rtp.c?rev=3D42569&r1=3D=
42568&r2=3D42569&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/main/rtp.c (original)
+++ trunk/main/rtp.c Sat Sep  9 13:07:59 2006
@@ -137,6 +137,7 @@
 	unsigned int lastdigitts;
 	char send_digit;
 	int send_payload;
+	int send_duration;
 	int nat;
 	unsigned int flags;
 	struct sockaddr_in us;		/*!< Socket representation of the local endpoint.=
 */
@@ -1961,26 +1962,6 @@
 	return (unsigned int) ms;
 }
 =

-/* Convert DTMF digit into something usable */
-static int digit_convert(char digit)
-{
-	if ((digit <=3D '9') && (digit >=3D '0'))
-                digit -=3D '0';
-        else if (digit =3D=3D '*')
-                digit =3D 10;
-        else if (digit =3D=3D '#')
-                digit =3D 11;
-        else if ((digit >=3D 'A') && (digit <=3D 'D'))
-                digit =3D digit - 'A' + 12;
-        else if ((digit >=3D 'a') && (digit <=3D 'd'))
-                digit =3D digit - 'a' + 12;
-        else {
-                ast_log(LOG_WARNING, "Don't know how to represent '%c'\n",=
 digit);
-                return -1;
-        }
-	return 0;
-}
-
 /*! \brief Send begin frames for DTMF */
 int ast_rtp_senddigit_begin(struct ast_rtp *rtp, char digit)
 {
@@ -1988,8 +1969,20 @@
 	int hdrlen =3D 12, res =3D 0, i =3D 0, payload =3D 0;
 	char data[256];
 =

-	if (digit_convert(digit))
-		return -1;
+	if ((digit <=3D '9') && (digit >=3D '0'))
+		digit -=3D '0';
+	else if (digit =3D=3D '*')
+		digit =3D 10;
+	else if (digit =3D=3D '#')
+		digit =3D 11;
+	else if ((digit >=3D 'A') && (digit <=3D 'D'))
+		digit =3D digit - 'A' + 12;
+	else if ((digit >=3D 'a') && (digit <=3D 'd'))
+		digit =3D digit - 'a' + 12;
+	else {
+		ast_log(LOG_WARNING, "Don't know how to represent '%c'\n", digit);
+		return 0;
+	}
 =

 	/* If we have no peer, return immediately */	=

 	if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port)
@@ -1998,15 +1991,17 @@
 	payload =3D ast_rtp_lookup_code(rtp, 0, AST_RTP_DTMF);
 =

 	rtp->dtmfmute =3D ast_tvadd(ast_tvnow(), ast_tv(0, 500000));
+	rtp->send_duration =3D 160;
 	=

 	/* Get a pointer to the header */
 	rtpheader =3D (unsigned int *)data;
 	rtpheader[0] =3D htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->se=
qno));
 	rtpheader[1] =3D htonl(rtp->lastdigitts);
 	rtpheader[2] =3D htonl(rtp->ssrc); =

-	rtpheader[3] =3D htonl((digit << 24) | (0xa << 16) | (0));
 =

 	for (i =3D 0; i < 2; i++) {
+		rtpheader[3] =3D htonl((digit << 24) | (0xa << 16) | (0));
+		rtpheader[3] |=3D htonl((rtp->send_duration));
 		res =3D sendto(rtp->s, (void *) rtpheader, hdrlen + 4, 0, (struct sockad=
dr *) &rtp->them, sizeof(rtp->them));
 		if (res < 0) =

 			ast_log(LOG_ERROR, "RTP Transmission error to %s:%d: %s\n",
@@ -2018,6 +2013,8 @@
 				    ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastdigitts, =
res - hdrlen);
 		/* Increment sequence number */
 		rtp->seqno++;
+		/* Increment duration */
+		rtp->send_duration +=3D 160;
 		/* Clear marker bit and set seqno */
 		rtpheader[0] =3D htonl((2 << 30) | (payload << 16) | (rtp->seqno));
 	}
@@ -2045,6 +2042,7 @@
         rtpheader[1] =3D htonl(rtp->lastdigitts);
         rtpheader[2] =3D htonl(rtp->ssrc);
         rtpheader[3] =3D htonl((rtp->send_digit << 24) | (0xa << 16) | (0)=
);
+	rtpheader[3] |=3D htonl((rtp->send_duration));
 	rtpheader[0] =3D htonl((2 << 30) | (rtp->send_payload << 16) | (rtp->seqn=
o));
 	=

 	/* Transmit */
@@ -2060,6 +2058,8 @@
 =

 	/* Increment sequence number */
 	rtp->seqno++;
+	/* Increment duration */
+	rtp->send_duration +=3D 160;
 =

 	return 0;
 }
@@ -2075,9 +2075,20 @@
 	if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port)
 		return 0;
 	=

-	/* Convert our digit to the crazy RTP way */
-	if (digit_convert(digit))
-		return -1;
+	if ((digit <=3D '9') && (digit >=3D '0'))
+		digit -=3D '0';
+	else if (digit =3D=3D '*')
+		digit =3D 10;
+	else if (digit =3D=3D '#')
+		digit =3D 11;
+	else if ((digit >=3D 'A') && (digit <=3D 'D'))
+		digit =3D digit - 'A' + 12;
+	else if ((digit >=3D 'a') && (digit <=3D 'd'))
+		digit =3D digit - 'a' + 12;
+	else {
+		ast_log(LOG_WARNING, "Don't know how to represent '%c'\n", digit);
+		return 0;
+	}
 =

 	rtp->dtmfmute =3D ast_tvadd(ast_tvnow(), ast_tv(0, 500000));
 =

@@ -2087,7 +2098,7 @@
 	rtpheader[2] =3D htonl(rtp->ssrc);
 	rtpheader[3] =3D htonl((digit << 24) | (0xa << 16) | (0));
 	/* Send duration to 100ms */
-	rtpheader[3] |=3D htonl((800));
+	rtpheader[3] |=3D htonl((rtp->send_duration));
 	/* Set end bit */
 	rtpheader[3] |=3D htonl((1 << 23));
 	rtpheader[0] =3D htonl((2 << 30) | (rtp->send_payload << 16) | (rtp->seqn=
o));



More information about the asterisk-commits mailing list