[asterisk-commits] branch oej/rtcp r31353 - in /team/oej/rtcp: ./ configs/ include/asterisk/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Jun 1 06:41:21 MST 2006


Author: oej
Date: Thu Jun  1 08:41:20 2006
New Revision: 31353

URL: http://svn.digium.com/view/asterisk?rev=31353&view=rev
Log:
- Cleanup
- remove unused function
- Add config option to rtp.conf.sample

Modified:
    team/oej/rtcp/configs/rtp.conf.sample
    team/oej/rtcp/include/asterisk/rtp.h
    team/oej/rtcp/rtp.c

Modified: team/oej/rtcp/configs/rtp.conf.sample
URL: http://svn.digium.com/view/asterisk/team/oej/rtcp/configs/rtp.conf.sample?rev=31353&r1=31352&r2=31353&view=diff
==============================================================================
--- team/oej/rtcp/configs/rtp.conf.sample (original)
+++ team/oej/rtcp/configs/rtp.conf.sample Thu Jun  1 08:41:20 2006
@@ -18,3 +18,5 @@
 ; allowed to continue (in 'samples', 1/8000 of a second)
 ;
 ;dtmftimeout=3000
+; rtcpinterval = 5000 	; Milliseconds between rtcp reports 
+			;(min 500, max 60000, default 5000)

Modified: team/oej/rtcp/include/asterisk/rtp.h
URL: http://svn.digium.com/view/asterisk/team/oej/rtcp/include/asterisk/rtp.h?rev=31353&r1=31352&r2=31353&view=diff
==============================================================================
--- team/oej/rtcp/include/asterisk/rtp.h (original)
+++ team/oej/rtcp/include/asterisk/rtp.h Thu Jun  1 08:41:20 2006
@@ -167,7 +167,7 @@
 void ast_rtp_stop(struct ast_rtp *rtp);
 
 /*! \brief Return RTCP quality string */
-char *ast_rtp_get_qualify(struct ast_rtp *rtp);
+char *ast_rtp_get_quality(struct ast_rtp *rtp);
 
 /*! \brief Send an H.261 fast update request. Some devices need this rather than the XML message  in SIP */
 int ast_rtcp_send_h261fur(void *data);

Modified: team/oej/rtcp/rtp.c
URL: http://svn.digium.com/view/asterisk/team/oej/rtcp/rtp.c?rev=31353&r1=31352&r2=31353&view=diff
==============================================================================
--- team/oej/rtcp/rtp.c (original)
+++ team/oej/rtcp/rtp.c Thu Jun  1 08:41:20 2006
@@ -58,10 +58,12 @@
 #include "asterisk/utils.h"
 
 #define MAX_TIMESTAMP_SKEW	640
-#define RTP_SEQ_MOD     (1<<16) /*A sequence number can't be more than 16 bits */
-#define RTCP_DEFAULT_INTERVALMS   5000 /* Default milli-seconds between RTCP reports we send */
-#define RTCP_MIN_INTERVALMS       500 /* Min milli-seconds between RTCP reports we send */
-#define RTCP_MAX_INTERVALMS       60000 /* Max milli-seconds between RTCP reports we send */
+
+#define RTP_SEQ_MOD     (1<<16) 	/*!< A sequence number can't be more than 16 bits */
+#define RTCP_DEFAULT_INTERVALMS   5000	/*!< Default milli-seconds between RTCP reports we send */
+#define RTCP_MIN_INTERVALMS       500	/*!< Min milli-seconds between RTCP reports we send */
+#define RTCP_MAX_INTERVALMS       60000	/*!< Max milli-seconds between RTCP reports we send */
+
 #define RTCP_PT_FUR     192
 #define RTCP_PT_SR      200
 #define RTCP_PT_RR      201
@@ -93,7 +95,6 @@
 static void timeval2ntp(struct timeval tv, unsigned int *msw, unsigned int *lsw);
 static int ast_rtcp_write_sr(void *data);
 static int ast_rtcp_write_rr(void *data);
-static void ast_rtp_offered_from_local(struct ast_rtp* rtp, int local);
 static unsigned int ast_rtcp_calc_interval(struct ast_rtp *rtp);
 
 /*! \brief The value of each payload format mapping: */
@@ -117,7 +118,7 @@
 	struct ast_frame f;
 	unsigned char rawdata[8192 + AST_FRIENDLY_OFFSET];
 	unsigned int ssrc;		/*!< Synchronization source, RFC 3550, page 10. */
-	unsigned int themssrc;			/* Their SSRC */
+	unsigned int themssrc;		/*!< Their SSRC */
 	unsigned int rxssrc;
 	unsigned int lastts;
 	unsigned int lastdigitts;
@@ -125,16 +126,16 @@
 	unsigned int lastividtimestamp;
 	unsigned int lastovidtimestamp;
 	unsigned int lasteventseqn;
-	int lastrxseqno;                /* Last received sequence number */
-	unsigned short seedrxseqno;     /* What sequence number did they start with?*/
-	unsigned int seedrxts;          /* What RTP timestamp did they start with? */
-	unsigned int rxcount;           /* How many packets have we received? */
-	unsigned int rxoctetcount;      /* How many octets have we received? should be rxcount *160*/
-	unsigned int txcount;           /* How many packets have we sent? */
-	unsigned int txoctetcount;      /* How many octets have we sent? (txcount*160)*/
-	unsigned int cycles;            /* Shifted count of sequence number cycles */
-	double rxjitter;                /* Interarrival jitter at the moment */
-	double rxtransit;               /* Relative transit time for previous packet */
+	int lastrxseqno;                /*!< Last received sequence number */
+	unsigned short seedrxseqno;     /*!< What sequence number did they start with?*/
+	unsigned int seedrxts;          /*!< What RTP timestamp did they start with? */
+	unsigned int rxcount;           /*!< How many packets have we received? */
+	unsigned int rxoctetcount;      /*!< How many octets have we received? should be rxcount *160*/
+	unsigned int txcount;           /*!< How many packets have we sent? */
+	unsigned int txoctetcount;      /*!< How many octets have we sent? (txcount*160)*/
+	unsigned int cycles;            /*!< Shifted count of sequence number cycles */
+	double rxjitter;                /*!< Interarrival jitter at the moment */
+	double rxtransit;               /*!< Relative transit time for previous packet */
 	unsigned int lasteventendseqn;
 	int lasttxformat;
 	int lastrxformat;
@@ -146,8 +147,8 @@
 	struct sockaddr_in them;	/*!< Socket representation of the remote endpoint. */
 	struct timeval rxcore;
 	struct timeval txcore;
-	double drxcore;                 /* The double representation of the first received packet */
-	struct timeval lastrx;          /* timeval when we last received a packet */
+	double drxcore;                 /*!< The double representation of the first received packet */
+	struct timeval lastrx;          /*!< timeval when we last received a packet */
 	struct timeval dtmfmute;
 	struct ast_smoother *smoother;
 	int *ioid;
@@ -161,7 +162,6 @@
 	int rtp_lookup_code_cache_isAstFormat; /*!< a cache for the result of rtp_lookup_code(): */
 	int rtp_lookup_code_cache_code;
 	int rtp_lookup_code_cache_result;
-	int rtp_offered_from_local;
 	struct ast_rtcp *rtcp;
 };
 
@@ -179,21 +179,21 @@
 	int s;				/*!< Socket */
 	struct sockaddr_in us;		/*!< Socket representation of the local endpoint. */
 	struct sockaddr_in them;	/*!< Socket representation of the remote endpoint. */
-	unsigned int soc; /* What they told us */
-	unsigned int spc; /* What they told us */
-	unsigned int themrxlsr; /* The middle 32 bits of the NTP timestamp in the last received SR*/
-	struct timeval rxlsr;   /* Time when we got their last SR */
-	struct timeval txlsr;   /* Time when we sent or last SR*/
-	unsigned int expected_prior; /* no. packets in previous interval */
-	unsigned int received_prior; /* no. packets received in previous interval */
-	int schedid; /*Schedid returned from ast_sched_add() to schedule RTCP-transmissions*/
-	unsigned int rr_count; /* number of RRs we've sent, not including report blocks in SR's */
-	unsigned int sr_count; /* number of SRs we've sent */
-	unsigned int lastsrtxcount;     /* Transmit packet count when last SR sent */
-	double accumulated_transit; /* accumulated a-dlsr-lsr */
-	double rtt; /* Last reported rtt */
-	unsigned int reported_jitter; /* The contents of their last jitter entry in the RR */
-	unsigned int reported_lost; /* Reported lost packets in their RR */
+	unsigned int soc;		/*!< What they told us */
+	unsigned int spc;		/*!< What they told us */
+	unsigned int themrxlsr;		/*!< The middle 32 bits of the NTP timestamp in the last received SR*/
+	struct timeval rxlsr;		/*!< Time when we got their last SR */
+	struct timeval txlsr;		/*!< Time when we sent or last SR*/
+	unsigned int expected_prior;	/*!< no. packets in previous interval */
+	unsigned int received_prior;	/*!< no. packets received in previous interval */
+	int schedid;			/*!< Schedid returned from ast_sched_add() to schedule RTCP-transmissions*/
+	unsigned int rr_count;		/*!< number of RRs we've sent, not including report blocks in SR's */
+	unsigned int sr_count;		/*!< number of SRs we've sent */
+	unsigned int lastsrtxcount;     /*!< Transmit packet count when last SR sent */
+	double accumulated_transit;	/*!< accumulated a-dlsr-lsr */
+	double rtt;			/*!< Last reported rtt */
+	unsigned int reported_jitter;	/*!< The contents of their last jitter entry in the RR */
+	unsigned int reported_lost;	/*!< Reported lost packets in their RR */
 	char quality[AST_MAX_USER_FIELD];
 	double maxrxjitter;
 	double minrxjitter;
@@ -490,7 +490,7 @@
 unsigned int ast_rtcp_calc_interval(struct ast_rtp *rtp)
 {
 	unsigned int interval;
-	/* TODO Do a more reasonable calculation on this one
+	/*! \todo XXX Do a more reasonable calculation on this one
 	* Look in RFC 3550 Section A.7 for an example*/
 	interval = rtcpinterval;
 	return interval;
@@ -776,26 +776,26 @@
 	position = 0;
 	while (position < packetwords) {
 		i = position;
-	  length = ntohl(rtcpheader[i]);
-	  pt = (length & 0xff0000) >> 16;
-	  rc = (length & 0x1f000000) >> 24;
-	  length &= 0xffff;
+		length = ntohl(rtcpheader[i]);
+		pt = (length & 0xff0000) >> 16;
+		rc = (length & 0x1f000000) >> 24;
+		length &= 0xffff;
     
 		if ((i + length) > packetwords) {
 			ast_log(LOG_WARNING, "RTCP Read too short\n");
 			return &ast_null_frame;
 		}
 		
-	  if(rtcp_debug_test_addr(&sin)){
+	if(rtcp_debug_test_addr(&sin)){
 	  	ast_verbose("\n\nGot RTCP from %s:%d\n",ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr),ntohs(sin.sin_port));
 	  	ast_verbose("PT: %d(%s)\n",pt,(pt==200)?"Sender Report":(pt==201)?"Receiver Report":(pt==192)?"H.261 FUR":"Unknown");
 	  	ast_verbose("Reception reports: %d\n",rc);
 	  	ast_verbose("SSRC of sender: %u\n",rtcpheader[i+1]);
-	  }
+	}
     
-		i+=2; /* Advance past header and ssrc */
+	i+=2; /* Advance past header and ssrc */
 		
-	  switch(pt){
+	switch(pt){
 	  	case RTCP_PT_SR:
 	  		gettimeofday(&rtp->rtcp->rxlsr,NULL); /* To be able to populate the dlsr */
 	  		rtp->rtcp->spc = ntohl(rtcpheader[i+3]);
@@ -807,10 +807,10 @@
 	  			ast_verbose("RTP timestamp: %lu\n",(unsigned long)ntohl(rtcpheader[i+2]));
 	  			ast_verbose("SPC: %lu\tSOC: %lu\n",(unsigned long)ntohl(rtcpheader[i+3]),(unsigned long)ntohl(rtcpheader[i+4]));
 	  		}
-				i += 5;
-				if (rc < 1)
-					break;
-				/* Intentional fall through */
+			i += 5;
+			if (rc < 1)
+				break;
+			/* Intentional fall through */
 	  	case RTCP_PT_RR:
 	  		/* This is the place to calculate RTT */
 				/* Don't handle multiple reception reports (rc > 1) yet */
@@ -866,7 +866,7 @@
 	  	default:
 	  		ast_log(LOG_NOTICE, "Unknown RTCP packet (pt=%d) received from %s:%d\n", pt, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port));
 	  		break;
-	  }
+		}
 		position += (length + 1);
 	}
 			
@@ -985,9 +985,9 @@
 		if ((rtp->them.sin_addr.s_addr != sin.sin_addr.s_addr) ||
 		    (rtp->them.sin_port != sin.sin_port)) {
 			rtp->them = sin;
-			if(rtp->rtcp){
-			    memcpy(&rtp->rtcp->them, &sin, sizeof(rtp->rtcp->them));
-			    rtp->rtcp->them.sin_port = htons(ntohs(rtp->them.sin_port)+1);
+			if(rtp->rtcp) {
+				memcpy(&rtp->rtcp->them, &sin, sizeof(rtp->rtcp->them));
+				rtp->rtcp->them.sin_port = htons(ntohs(rtp->them.sin_port)+1);
 			}
 			rtp->rxseqno = 0;
 			ast_set_flag(rtp, FLAG_NAT_ACTIVE);
@@ -1461,13 +1461,6 @@
 	}
 }
 
-void ast_rtp_offered_from_local(struct ast_rtp* rtp, int local) {
-	if (rtp)
-		rtp->rtp_offered_from_local = local;
-	else
-		ast_log(LOG_WARNING, "rtp structure is null\n");
-}
-
 struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt) 
 {
 	struct rtpPayloadType result;
@@ -1476,9 +1469,8 @@
 	if (pt < 0 || pt > MAX_RTP_PT) 
 		return result; /* bogus payload type */
 
-	/* Start with the negotiated codecs */
-	if (!rtp->rtp_offered_from_local)
-		result = rtp->current_RTP_PT[pt];
+	/* Start with negotiated codecs */
+	result = rtp->current_RTP_PT[pt];
 
 	/* If it doesn't exist, check our static RTP type list, just in case */
 	if (!result.code) 
@@ -1968,9 +1960,9 @@
 	char iabuf[INET_ADDRSTRLEN];
 
 	if(!rtp || !rtp->rtcp || (&rtp->rtcp->them.sin_addr == 0))
-	  return 0;
-	
-	if(!rtp->rtcp->them.sin_addr.s_addr){  /* This'll stop rtcp for this rtp session */
+		return 0;
+	
+	if(!rtp->rtcp->them.sin_addr.s_addr) {  /* This'll stop rtcp for this rtp session */
 		ast_verbose("RTCP SR transmission error, rtcp halted %s\n",strerror(errno));
 		ast_sched_del(rtp->sched, rtp->rtcp->schedid);
 		rtp->rtcp->schedid = -1;
@@ -1990,16 +1982,15 @@
 	
 	extended = rtp->cycles + rtp->lastrxseqno;
 	expected = extended - rtp->seedrxseqno + 1;
-	if(rtp->rxcount > expected) {
+	if (rtp->rxcount > expected) 
 		expected += rtp->rxcount - expected;
-	}
 	lost = expected - rtp->rxcount;
 	expected_interval = expected - rtp->rtcp->expected_prior;
 	rtp->rtcp->expected_prior = expected;
 	received_interval = rtp->rxcount - rtp->rtcp->received_prior;
 	rtp->rtcp->received_prior = rtp->rxcount;
 	lost_interval = expected_interval - received_interval;
-	if(expected_interval == 0 || lost_interval <= 0)
+	if (expected_interval == 0 || lost_interval <= 0)
 		fraction = 0;
 	else
 		fraction = (lost_interval << 8) / expected_interval;
@@ -2029,7 +2020,7 @@
 	len += 12;
 	
 	res = sendto(rtp->rtcp->s, (unsigned int *)rtcpheader, len, 0, (struct sockaddr *)&rtp->rtcp->them, sizeof(rtp->rtcp->them));
-	if(res<0){
+	if (res < 0) {
 		ast_log(LOG_ERROR, "RTCP SR transmission error to %s:%d, rtcp halted %s\n",ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port), strerror(errno));
 		ast_sched_del(rtp->sched, rtp->rtcp->schedid);
 		rtp->rtcp->schedid = -1;
@@ -2042,19 +2033,19 @@
 
 	rtp->rtcp->lastsrtxcount = rtp->txcount;	
 	
-	if(rtcp_debug_test_addr(&rtp->rtcp->them)){
-		ast_verbose("Sent RTCP SR to %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port));
-		ast_verbose("Our SSRC: %u\n", rtp->ssrc);
-		ast_verbose("Sent(NTP): %u.%010u\n", (unsigned int)now.tv_sec, (unsigned int)now.tv_usec*4096);
-		ast_verbose("Sent(RTP): %u\n", rtp->lastts);
-		ast_verbose("Sent packets: %u\n", rtp->txcount);
-		ast_verbose("Sent octets: %u\n", rtp->txoctetcount);
-		ast_verbose("Report block:\n");
-		ast_verbose("Fraction lost: %u\n", fraction);
-		ast_verbose("Cumulative loss: %u\n", lost);
-		ast_verbose("IA jitter: %.4f\n", rtp->rxjitter);
-		ast_verbose("Their last SR: %u\n", rtp->rtcp->themrxlsr);
-		ast_verbose("DLSR: %4.4f (sec)\n\n", (double)(ntohl(rtcpheader[12])/65536.0));
+	if (rtcp_debug_test_addr(&rtp->rtcp->them)) {
+		ast_verbose("* Sent RTCP SR to %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port));
+		ast_verbose("  Our SSRC: %u\n", rtp->ssrc);
+		ast_verbose("  Sent(NTP): %u.%010u\n", (unsigned int)now.tv_sec, (unsigned int)now.tv_usec*4096);
+		ast_verbose("  Sent(RTP): %u\n", rtp->lastts);
+		ast_verbose("  Sent packets: %u\n", rtp->txcount);
+		ast_verbose("  Sent octets: %u\n", rtp->txoctetcount);
+		ast_verbose("  Report block:\n");
+		ast_verbose("  Fraction lost: %u\n", fraction);
+		ast_verbose("  Cumulative loss: %u\n", lost);
+		ast_verbose("  IA jitter: %.4f\n", rtp->rxjitter);
+		ast_verbose("  Their last SR: %u\n", rtp->rtcp->themrxlsr);
+		ast_verbose("  DLSR: %4.4f (sec)\n\n", (double)(ntohl(rtcpheader[12])/65536.0));
 	}
 	return res;
 }
@@ -2078,10 +2069,10 @@
 	struct timeval dlsr;
 	int fraction;
 
-	if(!rtp || !rtp->rtcp || (&rtp->rtcp->them.sin_addr == 0))
+	if (!rtp || !rtp->rtcp || (&rtp->rtcp->them.sin_addr == 0))
 		return 0;
 	  
-	if(!rtp->rtcp->them.sin_addr.s_addr){
+	if (!rtp->rtcp->them.sin_addr.s_addr){
 		ast_log(LOG_ERROR, "RTCP RR transmission error to, rtcp halted %s\n",strerror(errno));
 		ast_sched_del(rtp->sched, rtp->rtcp->schedid);
 		rtp->rtcp->schedid = -1;
@@ -2096,7 +2087,7 @@
 	received_interval = rtp->rxcount - rtp->rtcp->received_prior;
 	rtp->rtcp->received_prior = rtp->rxcount;
 	lost_interval = expected_interval - received_interval;
-	if(expected_interval == 0 || lost_interval <= 0)
+	if (expected_interval == 0 || lost_interval <= 0)
 		fraction = 0;
 	else
 		fraction = (lost_interval << 8) / expected_interval;
@@ -2128,7 +2119,7 @@
 	
 	res = sendto(rtp->rtcp->s, (unsigned int *)rtcpheader, len, 0, (struct sockaddr *)&rtp->rtcp->them, sizeof(rtp->rtcp->them));
 
-	if(res < 0){
+	if (res < 0) {
 		ast_log(LOG_ERROR, "RTCP RR transmission error, rtcp halted: %s\n",strerror(errno));
 		/* Remove the scheduler */
 		ast_sched_del(rtp->sched, rtp->rtcp->schedid);
@@ -2138,12 +2129,12 @@
 
 	rtp->rtcp->rr_count++;
 
-	if(rtcp_debug_test_addr(&rtp->rtcp->them)){
-		ast_verbose("\nSending RTCP RR to %s:%d\n"
-			"Our SSRC: %u\nTheir SSRC: %u\niFraction lost: %d\nCumulative loss: %u\n" 
-			"IA jitter: %.4f\n" 
-			"Their last SR: %u\n" 
-			"DLSR: %4.4f (sec)\n\n",
+	if (rtcp_debug_test_addr(&rtp->rtcp->them)) {
+		ast_verbose("\n* Sending RTCP RR to %s:%d\n"
+			"  Our SSRC: %u\nTheir SSRC: %u\niFraction lost: %d\nCumulative loss: %u\n" 
+			"  IA jitter: %.4f\n" 
+			"  Their last SR: %u\n" 
+			"  DLSR: %4.4f (sec)\n\n",
 			ast_inet_ntoa(iabuf, sizeof(iabuf),
 			rtp->rtcp->them.sin_addr),
 			ntohs(rtp->rtcp->them.sin_port),
@@ -2280,18 +2271,17 @@
 					ast_log(LOG_DEBUG, "RTP NAT: Can't write RTP to private address %s:%d, waiting for other end to send audio...\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port));
 				ast_set_flag(rtp, FLAG_NAT_INACTIVE_NOWARN);
 			}
-		}else{
+		} else {
 			rtp->txcount++;
 			rtp->txoctetcount +=(res - hdrlen);
 			
-			if(rtp->rtcp->schedid<1){
+			if (rtp->rtcp->schedid < 1) 
 			    rtp->rtcp->schedid = ast_sched_add(rtp->sched, ast_rtcp_calc_interval(rtp), ast_rtcp_write, rtp);
-			}
 		}
 				
 		if(rtp_debug_test_addr(&rtp->them))
-			ast_verbose("Sent RTP packet to %s:%d (type %d, seq %u, ts %u, len %u)\n"
-					, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), codec, rtp->seqno, rtp->lastts,res - hdrlen);
+			ast_verbose("Sent RTP packet to %s:%d (type %d, seq %u, ts %u, len %u)\n",
+					ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), codec, rtp->seqno, rtp->lastts,res - hdrlen);
 	}
 
 	rtp->seqno++;
@@ -2759,7 +2749,7 @@
 
 	arg = argv[4];
 	p = strstr(arg, ":");
-	if (p){
+	if (p) {
 		*p = '\0';
 		p++;
 		port = atoi(p);
@@ -2850,6 +2840,7 @@
 	return RESULT_SUCCESS;
 }
    
+static int stun_no_debug(int fd, int argc, char *argv[])
 {
 	if(argc !=3)
 		return RESULT_SHOWUSAGE;



More information about the asterisk-commits mailing list