[zaptel-commits] kpfleming: branch kpfleming/tc400-g723fix r3320 - in /team/kpfleming/tc400-g7...

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Tue Dec 4 22:08:21 CST 2007


Author: kpfleming
Date: Tue Dec  4 22:08:21 2007
New Revision: 3320

URL: http://svn.digium.com/view/zaptel?view=rev&rev=3320
Log:
put a potential fix for handling both G.723.1 bitrates into a branch so it can be reviewed

Added:
    team/kpfleming/tc400-g723fix/
      - copied from r3317, branches/1.2/
Modified:
    team/kpfleming/tc400-g723fix/wctc4xxp/base.c

Modified: team/kpfleming/tc400-g723fix/wctc4xxp/base.c
URL: http://svn.digium.com/view/zaptel/team/kpfleming/tc400-g723fix/wctc4xxp/base.c?view=diff&rev=3320&r1=3317&r2=3320
==============================================================================
--- team/kpfleming/tc400-g723fix/wctc4xxp/base.c (original)
+++ team/kpfleming/tc400-g723fix/wctc4xxp/base.c Tue Dec  4 22:08:21 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 zaptel-commits mailing list