summaryrefslogtreecommitdiff
path: root/wctc4xxp
diff options
context:
space:
mode:
authorkpfleming <kpfleming@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2007-12-06 19:42:13 +0000
committerkpfleming <kpfleming@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2007-12-06 19:42:13 +0000
commit46085770010623747887e99a9629c6fb44dd1273 (patch)
treeccc5b5eb38877de1808306f3aa4331b8f532134a /wctc4xxp
parentc00fc2b9230615d39c307d417ba2a4b46c488997 (diff)
make the TC400B driver tolerant of incoming G.723.1 frames in all possible formats (6.3kb/s, 5.3kb/s and SID)
git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.2@3327 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'wctc4xxp')
-rw-r--r--wctc4xxp/base.c55
1 files changed, 34 insertions, 21 deletions
diff --git a/wctc4xxp/base.c b/wctc4xxp/base.c
index 2f20623..0ddd79d 100644
--- a/wctc4xxp/base.c
+++ b/wctc4xxp/base.c
@@ -81,13 +81,13 @@ extern void _binary_tc400m_firmware_bin_size;
#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 @@ static int dte_operation(struct zt_transcoder_channel *ztc, int op)
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 @@ static int dte_operation(struct zt_transcoder_channel *ztc, int op)
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 @@ static int dte_operation(struct zt_transcoder_channel *ztc, int op)
} 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 @@ static inline void wcdte_receiveprep(struct wcdte *wc, int dbl)
}
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 @@ static inline void wcdte_receiveprep(struct wcdte *wc, int dbl)
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 @@ static inline void wcdte_receiveprep(struct wcdte *wc, int dbl)
chars[i] = readchunk[i+54];
zth->dstlen += rlen;
- zth->dstsamples = zth->dstlen * 8;
+ zth->dstsamples += G729_SAMPLES;
} else {
ztc->errorstatus = -EOVERFLOW;