[svn-commits] kpfleming: branch 1.4 r3328 - in /branches/1.4: ./ wctc4xxp/base.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Dec 6 13:44:04 CST 2007


Author: kpfleming
Date: Thu Dec  6 13:44:03 2007
New Revision: 3328

URL: http://svn.digium.com/view/zaptel?view=rev&rev=3328
Log:
Merged revisions 3327 via svnmerge from 
https://origsvn.digium.com/svn/zaptel/branches/1.2

........
r3327 | kpfleming | 2007-12-06 13:42:13 -0600 (Thu, 06 Dec 2007) | 2 lines

make the TC400B driver tolerant of incoming G.723.1 frames in all possible formats (6.3kb/s, 5.3kb/s and SID)

........

Modified:
    branches/1.4/   (props changed)
    branches/1.4/wctc4xxp/base.c

Propchange: branches/1.4/
------------------------------------------------------------------------------
Binary property 'branch-1.2-merged' - no diff available.

Modified: branches/1.4/wctc4xxp/base.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/wctc4xxp/base.c?view=diff&rev=3328&r1=3327&r2=3328
==============================================================================
--- branches/1.4/wctc4xxp/base.c (original)
+++ branches/1.4/wctc4xxp/base.c Thu Dec  6 13:44:03 2007
@@ -81,13 +81,13 @@
 #define G729_LENGTH 20
 #define G723_LENGTH 30
 
-#define G729_SAMPLES 160	/* g.729 */
-#define G723_SAMPLES 240 	/* g.723 */
-
-#define G729_BYTES 20	/* g.729 */
-#define G723_BYTES 20 	/* g.723 */
-
-
+#define G729_SAMPLES 160	/* G.729 */
+#define G723_SAMPLES 240 	/* G.723.1 */
+
+#define G729_BYTES 20		/* G.729 */
+#define G723_6K_BYTES 24 	/* G.723.1 at 6.3kb/s */
+#define G723_5K_BYTES 20	/* G.723.1 at 5.3kb/s */
+#define G723_SID_BYTES 4	/* G.723.1 SID frame */
 
 #define ACK_SPACE 20
 
@@ -759,14 +759,13 @@
 	case ZT_TCOP_TRANSCODE:
 		if ( (((zth->srcfmt == ZT_FORMAT_ULAW) || (zth->srcfmt == ZT_FORMAT_ALAW)) && ((zth->dstfmt == ZT_FORMAT_G729A  && zth->srclen >= G729_SAMPLES) ||(zth->dstfmt == ZT_FORMAT_G723_1  && zth->srclen >= G723_SAMPLES)) )
 			|| ((zth->srcfmt == ZT_FORMAT_G729A) && (zth->srclen >= G729_BYTES))
-			|| ((zth->srcfmt == ZT_FORMAT_G723_1) && (zth->srclen >= G723_BYTES)) )
+			|| ((zth->srcfmt == ZT_FORMAT_G723_1) && (zth->srclen >= G723_SID_BYTES)) )
 		{
 			do
 			{
 				chars = (unsigned char *)(zth->srcdata + zth->srcoffset);
 					
-				if ((zth->srcfmt == ZT_FORMAT_ULAW) || (zth->srcfmt == ZT_FORMAT_ALAW))
-				{
+				if ((zth->srcfmt == ZT_FORMAT_ULAW) || (zth->srcfmt == ZT_FORMAT_ALAW)) {
 					if (zth->dstfmt == ZT_FORMAT_G729A) {
 						inbytes = G729_SAMPLES; 
 						timestamp_inc = G729_SAMPLES; 
@@ -774,14 +773,27 @@
 						inbytes = G723_SAMPLES; 
 						timestamp_inc = G723_SAMPLES; 
 					}
-
-				} else if (zth->srcfmt == ZT_FORMAT_G729A)
-				{
+				} else if (zth->srcfmt == ZT_FORMAT_G729A) {
 					inbytes = G729_BYTES;
 					timestamp_inc = G729_SAMPLES;
-				} else if (zth->srcfmt == ZT_FORMAT_G723_1)
-				{
-					inbytes = G723_BYTES;
+				} else if (zth->srcfmt == ZT_FORMAT_G723_1) {
+					/* determine the size of the frame */
+					switch (chars[0] & 0x03) {
+					case 0x00:
+						inbytes = G723_6K_BYTES;
+						break;
+					case 0x01:
+						inbytes = G723_5K_BYTES;
+						break;
+					case 0x02:
+						inbytes = G723_SID_BYTES;
+						break;
+					case 0x03:
+						/* this is a 'reserved' value in the G.723.1
+						   spec and should never occur in real media streams */
+						inbytes = G723_SID_BYTES;
+						break;
+					}
 					timestamp_inc = G723_SAMPLES;
 				}
 
@@ -850,7 +862,7 @@
 
 			} while ((((zth->srcfmt == ZT_FORMAT_ULAW) || (zth->srcfmt == ZT_FORMAT_ALAW)) && ((zth->dstfmt == ZT_FORMAT_G729A  && zth->srclen >= G729_SAMPLES) ||(zth->dstfmt == ZT_FORMAT_G723_1  && zth->srclen >= G723_SAMPLES)) )
 				|| ((zth->srcfmt == ZT_FORMAT_G729A) && (zth->srclen >= G729_BYTES))
-				|| ((zth->srcfmt == ZT_FORMAT_G723_1) && (zth->srclen >= G723_BYTES)) );
+				|| ((zth->srcfmt == ZT_FORMAT_G723_1) && (zth->srclen >= G723_SID_BYTES)) );
 
 		} else {
 			zt_transcoder_alert(ztc);
@@ -1060,15 +1072,16 @@
 			}
 			zt_transcoder_alert(ztc);
 		}
-		else if (rcodec == 0x04)	/* g.723.1 */
+		else if (rcodec == 0x04)	/* G.723.1 */
 		{
-			if (zt_tc_sanitycheck(zth, rlen) && (rlen == G723_BYTES))
+			if (zt_tc_sanitycheck(zth, rlen) &&
+			    ((rlen == G723_6K_BYTES) || (rlen == G723_5K_BYTES) || (rlen == G723_SID_BYTES)))
 			{
 				for (i = 0; i < rlen; i++)
 					chars[i] = readchunk[i+54];
 
 				zth->dstlen += rlen;
-				zth->dstsamples = zth->dstlen * 12;
+				zth->dstsamples += G723_SAMPLES;
 
 			} else {
 				ztc->errorstatus = -EOVERFLOW;
@@ -1079,7 +1092,7 @@
 				zt_transcoder_alert(ztc);
 			} 
 		}
-		else if (rcodec == 0x12)	/* g.729a */
+		else if (rcodec == 0x12)	/* G.729a */
 		{
 			if (zt_tc_sanitycheck(zth, rlen) && (rlen == G729_BYTES))
 			{
@@ -1087,7 +1100,7 @@
 					chars[i] = readchunk[i+54];
 
 				zth->dstlen += rlen;
-				zth->dstsamples = zth->dstlen * 8;
+				zth->dstsamples += G729_SAMPLES;
 
 			} else {
 				ztc->errorstatus = -EOVERFLOW;




More information about the svn-commits mailing list