[svn-commits] dvossel: branch 1.6.2 r205595 - in /branches/1.6.2: ./ channels/ include/aste...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jul 9 10:37:09 CDT 2009


Author: dvossel
Date: Thu Jul  9 10:37:05 2009
New Revision: 205595

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=205595
Log:
Merged revisions 205479 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
  r205479 | dvossel | 2009-07-08 18:19:09 -0500 (Wed, 08 Jul 2009) | 16 lines
  
  Merged revisions 205471 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r205471 | dvossel | 2009-07-08 18:15:54 -0500 (Wed, 08 Jul 2009) | 10 lines
    
    Fixes 8khz assumptions
    
    Many calculations assume 8khz is the codec rate. This
    is not always the case.  This patch only addresses chan_iax.c
    and res_rtp_asterisk.c, but I am sure there are other areas
    that make this assumption as well.
    
    Review: https://reviewboard.asterisk.org/r/306/
  ........
................

Modified:
    branches/1.6.2/   (props changed)
    branches/1.6.2/channels/chan_iax2.c
    branches/1.6.2/include/asterisk/frame.h
    branches/1.6.2/main/rtp.c

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

Modified: branches/1.6.2/channels/chan_iax2.c
URL: http://svn.asterisk.org/svn-view/asterisk/branches/1.6.2/channels/chan_iax2.c?view=diff&rev=205595&r1=205594&r2=205595
==============================================================================
--- branches/1.6.2/channels/chan_iax2.c (original)
+++ branches/1.6.2/channels/chan_iax2.c Thu Jul  9 10:37:05 2009
@@ -3181,7 +3181,7 @@
 			/* create an interpolation frame */
 			af.frametype = AST_FRAME_VOICE;
 			af.subclass = pvt->voiceformat;
-			af.samples  = frame.ms * 8;
+			af.samples  = frame.ms * (ast_format_rate(pvt->voiceformat) / 1000);
 			af.src  = "IAX2 JB interpolation";
 			af.delivery = ast_tvadd(pvt->rxcore, ast_samp2tv(next, 1000));
 			af.offset = AST_FRIENDLY_OFFSET;
@@ -3253,7 +3253,7 @@
 
 	if(fr->af.frametype == AST_FRAME_VOICE) {
 		type = JB_TYPE_VOICE;
-		len = ast_codec_get_samples(&fr->af) / 8;
+		len = ast_codec_get_samples(&fr->af) / (ast_format_rate(fr->af.subclass) / 1000);
 	} else if(fr->af.frametype == AST_FRAME_CNG) {
 		type = JB_TYPE_SILENCE;
 	}
@@ -4601,6 +4601,7 @@
 	int voice = 0;
 	int genuine = 0;
 	int adjust;
+	int rate = ast_format_rate(f->subclass) / 1000;
 	struct timeval *delivery = NULL;
 
 
@@ -4668,7 +4669,7 @@
 					p->offset = ast_tvadd(p->offset, ast_samp2tv(adjust, 10000));
 
 				if (!p->nextpred) {
-					p->nextpred = ms; /*f->samples / 8;*/
+					p->nextpred = ms; /*f->samples / rate;*/
 					if (p->nextpred <= p->lastsent)
 						p->nextpred = p->lastsent + 3;
 				}
@@ -4687,11 +4688,11 @@
 					ast_debug(1, "predicted timestamp skew (%u) > max (%u), using real ts instead.\n",
 						abs(ms - p->nextpred), MAX_TIMESTAMP_SKEW);
 
-				if (f->samples >= 8) /* check to make sure we dont core dump */
+				if (f->samples >= rate) /* check to make sure we dont core dump */
 				{
-					int diff = ms % (f->samples / 8);
+					int diff = ms % (f->samples / rate);
 					if (diff)
-					    ms += f->samples/8 - diff;
+					    ms += f->samples/rate - diff;
 				}
 
 				p->nextpred = ms;
@@ -4723,7 +4724,7 @@
 	}
 	p->lastsent = ms;
 	if (voice)
-		p->nextpred = p->nextpred + f->samples / 8;
+		p->nextpred = p->nextpred + f->samples / rate;
 	return ms;
 }
 

Modified: branches/1.6.2/include/asterisk/frame.h
URL: http://svn.asterisk.org/svn-view/asterisk/branches/1.6.2/include/asterisk/frame.h?view=diff&rev=205595&r1=205594&r2=205595
==============================================================================
--- branches/1.6.2/include/asterisk/frame.h (original)
+++ branches/1.6.2/include/asterisk/frame.h Thu Jul  9 10:37:05 2009
@@ -149,7 +149,7 @@
 	int subclass;				
 	/*! Length of data */
 	int datalen;				
-	/*! Number of 8khz samples in this frame */
+	/*! Number of samples in this frame */
 	int samples;				
 	/*! Was the data malloc'd?  i.e. should we free it when we discard the frame? */
 	int mallocd;				

Modified: branches/1.6.2/main/rtp.c
URL: http://svn.asterisk.org/svn-view/asterisk/branches/1.6.2/main/rtp.c?view=diff&rev=205595&r1=205594&r2=205595
==============================================================================
--- branches/1.6.2/main/rtp.c (original)
+++ branches/1.6.2/main/rtp.c Thu Jul  9 10:37:05 2009
@@ -726,6 +726,11 @@
 	return -1;
 }
 
+static int rtp_get_rate(int subclass)
+{
+	return (subclass == AST_FORMAT_G722) ? 8000 : ast_format_rate(subclass);
+}
+
 unsigned int ast_rtcp_calc_interval(struct ast_rtp *rtp)
 {
 	unsigned int interval;
@@ -984,10 +989,10 @@
 		}
 	} else if ((rtp->resp == resp) && !power) {
 		f = send_dtmf(rtp, AST_FRAME_DTMF_END);
-		f->samples = rtp->dtmfsamples * 8;
+		f->samples = rtp->dtmfsamples * (rtp_get_rate(f->subclass) / 1000);
 		rtp->resp = 0;
 	} else if (rtp->resp == resp)
-		rtp->dtmfsamples += 20 * 8;
+		rtp->dtmfsamples += 20 * (rtp_get_rate(f->subclass) / 1000);
 	rtp->dtmf_timeout = dtmftimeout;
 	return f;
 }
@@ -1068,7 +1073,7 @@
 			if ((rtp->lastevent != seqno) && rtp->resp) {
 				rtp->dtmf_duration = new_duration;
 				f = send_dtmf(rtp, AST_FRAME_DTMF_END);
-				f->len = ast_tvdiff_ms(ast_samp2tv(rtp->dtmf_duration, 8000), ast_tv(0, 0));
+				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;
 			}
@@ -1078,7 +1083,7 @@
 			if (rtp->resp && rtp->resp != resp) {
 				/* Another digit already began. End it */
 				f = send_dtmf(rtp, AST_FRAME_DTMF_END);
-				f->len = ast_tvdiff_ms(ast_samp2tv(rtp->dtmf_duration, 8000), ast_tv(0, 0));
+				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;
 			}
@@ -1453,15 +1458,16 @@
 	double d;
 	double dtv;
 	double prog;
-	
 	double normdev_rxjitter_current;
+	int rate = rtp_get_rate(rtp->f.subclass);
+
 	if ((!rtp->rxcore.tv_sec && !rtp->rxcore.tv_usec) || mark) {
 		gettimeofday(&rtp->rxcore, NULL);
 		rtp->drxcore = (double) rtp->rxcore.tv_sec + (double) rtp->rxcore.tv_usec / 1000000;
 		/* map timestamp to a real time */
 		rtp->seedrxts = timestamp; /* Their RTP timestamp started with this */
-		rtp->rxcore.tv_sec -= timestamp / 8000;
-		rtp->rxcore.tv_usec -= (timestamp % 8000) * 125;
+		rtp->rxcore.tv_sec -= timestamp / rate;
+		rtp->rxcore.tv_usec -= (timestamp % rate) * 125;
 		/* Round to 0.1ms for nice, pretty timestamps */
 		rtp->rxcore.tv_usec -= rtp->rxcore.tv_usec % 100;
 		if (rtp->rxcore.tv_usec < 0) {
@@ -1473,13 +1479,13 @@
 
 	gettimeofday(&now,NULL);
 	/* rxcore is the mapping between the RTP timestamp and _our_ real time from gettimeofday() */
-	when->tv_sec = rtp->rxcore.tv_sec + timestamp / 8000;
-	when->tv_usec = rtp->rxcore.tv_usec + (timestamp % 8000) * 125;
+	when->tv_sec = rtp->rxcore.tv_sec + timestamp / rate;
+	when->tv_usec = rtp->rxcore.tv_usec + (timestamp % rate) * 125;
 	if (when->tv_usec >= 1000000) {
 		when->tv_usec -= 1000000;
 		when->tv_sec += 1;
 	}
-	prog = (double)((timestamp-rtp->seedrxts)/8000.);
+	prog = (double)((timestamp-rtp->seedrxts)/(float)(rate));
 	dtv = (double)rtp->drxcore + (double)(prog);
 	current_time = (double)now.tv_sec + (double)now.tv_usec/1000000;
 	transit = current_time - dtv;
@@ -1791,7 +1797,7 @@
 		if (rtp->resp) {
 			struct ast_frame *f;
 			f = send_dtmf(rtp, AST_FRAME_DTMF_END);
-			f->len = ast_tvdiff_ms(ast_samp2tv(rtp->dtmf_duration, 8000), ast_tv(0, 0));
+			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;
 			return f;
@@ -1868,7 +1874,7 @@
 		calc_rxstamp(&rtp->f.delivery, rtp, timestamp, mark);
 		/* Add timing data to let ast_generic_bridge() put the frame into a jitterbuf */
 		ast_set_flag(&rtp->f, AST_FRFLAG_HAS_TIMING_INFO);
-		rtp->f.ts = timestamp / 8;
+		rtp->f.ts = timestamp / (rtp_get_rate(rtp->f.subclass) / 1000);
 		rtp->f.len = rtp->f.samples / ((ast_format_rate(rtp->f.subclass) / 1000));
 	} else if (rtp->f.subclass & AST_FORMAT_VIDEO_MASK) {
 		/* Video -- samples is # of samples vs. 90000 */
@@ -3605,6 +3611,11 @@
 	unsigned int ms;
 	int pred;
 	int mark = 0;
+	int rate = rtp_get_rate(f->subclass) / 1000;
+
+	if (f->subclass == AST_FORMAT_G722) {
+		f->samples /= 2;
+	}
 
 	if (rtp->sending_digit) {
 		return 0;
@@ -3616,7 +3627,7 @@
 		pred = rtp->lastts + f->samples;
 
 		/* Re-calculate last TS */
-		rtp->lastts = rtp->lastts + ms * 8;
+		rtp->lastts = rtp->lastts + ms * rate;
 		if (ast_tvzero(f->delivery)) {
 			/* If this isn't an absolute delivery time, Check if it is close to our prediction, 
 			   and if so, go with our prediction */
@@ -3671,7 +3682,7 @@
 		rtp->lastdigitts = rtp->lastts;
 
 	if (ast_test_flag(f, AST_FRFLAG_HAS_TIMING_INFO))
-		rtp->lastts = f->ts * 8;
+		rtp->lastts = f->ts * rate;
 
 	/* Get a pointer to the header */
 	rtpheader = (unsigned char *)(f->data.ptr - hdrlen);
@@ -3853,11 +3864,6 @@
 		}
 
 		while ((f = ast_smoother_read(rtp->smoother)) && (f->data.ptr)) {
-			if (f->subclass == AST_FORMAT_G722) {
-				/* G.722 is silllllllllllllly */
-				f->samples /= 2;
-			}
-
 			ast_rtp_raw_write(rtp, f, codec);
 		}
 	} else {




More information about the svn-commits mailing list