[asterisk-commits] trunk r37494 - in /trunk: ./ channels/ codecs/ include/asterisk/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Jul 12 15:42:14 MST 2006


Author: kpfleming
Date: Wed Jul 12 17:42:13 2006
New Revision: 37494

URL: http://svn.digium.com/view/asterisk?rev=37494&view=rev
Log:
G726-32 changes:
split support for G726-32 into RFC3551 and AAL2 packing orders, since both are in use
change "G726-32" to be RFC3551 packing order, in spite of devices that use AAL2 order with this MIME type
add ability to directly transcode between packing orders

Modified:
    trunk/channel.c
    trunk/channels/chan_iax2.c
    trunk/codecs/codec_g726.c
    trunk/frame.c
    trunk/include/asterisk/frame.h
    trunk/rtp.c

Modified: trunk/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/channel.c?rev=37494&r1=37493&r2=37494&view=diff
==============================================================================
--- trunk/channel.c (original)
+++ trunk/channel.c Wed Jul 12 17:42:13 2006
@@ -546,8 +546,10 @@
 		AST_FORMAT_ALAW,
 		/*! Okay, well, signed linear is easy to translate into other stuff */
 		AST_FORMAT_SLINEAR,
-		/*! G.726 is standard ADPCM */
+		/*! G.726 is standard ADPCM, in RFC3551 packing order */
 		AST_FORMAT_G726,
+		/*! G.726 is standard ADPCM, in AAL2 packing order */
+		AST_FORMAT_G726_AAL2,
 		/*! ADPCM has great sound quality and is still pretty easy to translate */
 		AST_FORMAT_ADPCM,
 		/*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?rev=37494&r1=37493&r2=37494&view=diff
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Wed Jul 12 17:42:13 2006
@@ -182,16 +182,17 @@
 #define IAX_CAPABILITY_FULLBANDWIDTH 	0xFFFF
 /* T1, maybe ISDN */
 #define IAX_CAPABILITY_MEDBANDWIDTH 	(IAX_CAPABILITY_FULLBANDWIDTH & 	\
-							~AST_FORMAT_SLINEAR & 	\
-							~AST_FORMAT_ULAW & 	\
-							~AST_FORMAT_ALAW) 
+					 ~AST_FORMAT_SLINEAR &			\
+					 ~AST_FORMAT_ULAW &			\
+					 ~AST_FORMAT_ALAW) 
 /* A modem */
-#define IAX_CAPABILITY_LOWBANDWIDTH		(IAX_CAPABILITY_MEDBANDWIDTH & 	\
-							~AST_FORMAT_G726 & 	\
-							~AST_FORMAT_ADPCM)
+#define IAX_CAPABILITY_LOWBANDWIDTH	(IAX_CAPABILITY_MEDBANDWIDTH & 		\
+					 ~AST_FORMAT_G726 &			\
+					 ~AST_FORMAT_G726_AAL2 &		\
+					 ~AST_FORMAT_ADPCM)
 
 #define IAX_CAPABILITY_LOWFREE		(IAX_CAPABILITY_LOWBANDWIDTH & 		\
-							 ~AST_FORMAT_G723_1)
+					 ~AST_FORMAT_G723_1)
 
 
 #define DEFAULT_MAXMS		2000		/* Must be faster than 2 seconds by default */

Modified: trunk/codecs/codec_g726.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_g726.c?rev=37494&r1=37493&r2=37494&view=diff
==============================================================================
--- trunk/codecs/codec_g726.c (original)
+++ trunk/codecs/codec_g726.c Wed Jul 12 17:42:13 2006
@@ -1,9 +1,10 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 1999 - 2005, Digium, Inc.
+ * Copyright (C) 1999 - 2006, Digium, Inc.
  *
  * Mark Spencer <markster at digium.com>
+ * Kevin P. Fleming <kpfleming at digium.com>
  *
  * Based on frompcm.c and topcm.c from the Emiliano MIPL browser/
  * interpreter.  See http://www.bsdtelephony.com.mx
@@ -21,7 +22,7 @@
 
 /*! \file
  *
- * \brief codec_g726.c - translate between signed linear and ITU G.726-32kbps
+ * \brief codec_g726.c - translate between signed linear and ITU G.726-32kbps (both RFC3551 and AAL2 codeword packing)
  *
  * \ingroup codecs
  */
@@ -73,10 +74,10 @@
 
 /*
  * The following is the definition of the state structure
- * used by the G.721/G.723 encoder and decoder to preserve their internal
+ * used by the G.726 encoder and decoder to preserve their internal
  * state between successive calls.  The meanings of the majority
  * of the state structure fields are explained in detail in the
- * CCITT Recommendation G.721.  The field names are essentially indentical
+ * CCITT Recommendation G.721.  The field names are essentially identical
  * to variable names in the bit level description of the coding algorithm
  * included in this Recommendation.
  */
@@ -86,24 +87,20 @@
 	int dms;	/* Short term energy estimate. */
 	int dml;	/* Long term energy estimate. */
 	int ap;		/* Linear weighting coefficient of 'yl' and 'yu'. */
-
 	int a[2];	/* Coefficients of pole portion of prediction filter.
-				 * stored as fixed-point 1==2^14 */
+			 * stored as fixed-point 1==2^14 */
 	int b[6];	/* Coefficients of zero portion of prediction filter.
-				 * stored as fixed-point 1==2^14 */
+			 * stored as fixed-point 1==2^14 */
 	int pk[2];	/* Signs of previous two samples of a partially
-			 * reconstructed signal.
-			 */
-	int dq[6];  /* Previous 6 samples of the quantized difference signal
-				 * stored as fixed point 1==2^12,
-				 * or in internal floating point format */
+			 * reconstructed signal. */
+	int dq[6];  	/* Previous 6 samples of the quantized difference signal
+			 * stored as fixed point 1==2^12,
+			 * or in internal floating point format */
 	int sr[2];	/* Previous 2 samples of the quantized difference signal
-				 * stored as fixed point 1==2^12,
-				 * or in internal floating point format */
-	int td;	/* delayed tone detect, new in 1988 version */
+			 * stored as fixed point 1==2^12,
+			 * or in internal floating point format */
+	int td;		/* delayed tone detect, new in 1988 version */
 };
-
-
 
 static int qtab_721[7] = {-124, 80, 178, 246, 300, 349, 400};
 /*
@@ -124,10 +121,6 @@
 static int _fitab[16] = {0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00,
 				0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0};
 
-/* Deprecated
-static int power2[15] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80,
-			0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000};
-*/
 
 /*
  * g72x_init_state()
@@ -685,10 +678,6 @@
 }
 
 /*
- * ------------ Asterisk-codec hooks. -------------------
- */
-
-/*
  * Private workspace for translating signed linear signals to G726.
  * Don't bother to define two distinct structs.
  */
@@ -709,31 +698,35 @@
 	return 0;
 }
 
-/*! \brief decode packed 4-bit G726 values and store in buffer. */
-static int g726tolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
+/*! \brief decode packed 4-bit G726 values (AAL2 packing) and store in buffer. */
+static int g726aal2tolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
 	struct g726_coder_pvt *tmp = pvt->pvt;
 	unsigned char *src = f->data;
-	int16_t *dst = (int16_t *)pvt->outbuf + pvt->samples;
-	int i;
-
-	for ( i = 0 ; i < f->datalen ; i++ ) {
+	int16_t *dst = (int16_t *) pvt->outbuf + pvt->samples;
+	unsigned int i;
+
+	for (i = 0; i < f->datalen; i++) {
 		*dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726);
 		*dst++ = g726_decode(src[i] & 0x0f, &tmp->g726);
 	}
+
 	pvt->samples += f->samples;
 	pvt->datalen += 2 * f->samples; /* 2 bytes/sample */
+
 	return 0;
 }
 
-/*! \brief compress and store data (4-bit G726 samples) in outbuf */
-static int lintog726_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
+/*! \brief compress and store data (4-bit G726 samples, AAL2 packing) in outbuf */
+static int lintog726aal2_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
 	struct g726_coder_pvt *tmp = pvt->pvt;
 	int16_t *src = f->data;
-	int i;
-	for ( i = 0; i < f->samples; i++ ) {
+	unsigned int i;
+
+	for (i = 0; i < f->samples; i++) {
 		unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */
+
 		if (tmp->next_flag & 0x80) {	/* merge with leftover sample */
 			pvt->outbuf[pvt->datalen++] = ((tmp->next_flag & 0xf)<< 4) | d;
 			pvt->samples += 2;	/* 2 samples per byte */
@@ -742,37 +735,92 @@
 			tmp->next_flag = 0x80 | d;
 		}
 	}
+
 	return 0;
 }
 
-/*! \brief G726ToLin_Sample */
+/*! \brief decode packed 4-bit G726 values (RFC3551 packing) and store in buffer. */
+static int g726tolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
+{
+	struct g726_coder_pvt *tmp = pvt->pvt;
+	unsigned char *src = f->data;
+	int16_t *dst = (int16_t *) pvt->outbuf + pvt->samples;
+	unsigned int i;
+
+	for (i = 0; i < f->datalen; i++) {
+		*dst++ = g726_decode(src[i] & 0x0f, &tmp->g726);
+		*dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726);
+	}
+
+	pvt->samples += f->samples;
+	pvt->datalen += 2 * f->samples; /* 2 bytes/sample */
+
+	return 0;
+}
+
+/*! \brief compress and store data (4-bit G726 samples, RFC3551 packing) in outbuf */
+static int lintog726_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
+{
+	struct g726_coder_pvt *tmp = pvt->pvt;
+	int16_t *src = f->data;
+	unsigned int i;
+
+	for (i = 0; i < f->samples; i++) {
+		unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */
+
+		if (tmp->next_flag & 0x80) {	/* merge with leftover sample */
+			pvt->outbuf[pvt->datalen++] = (d << 4) | (tmp->next_flag & 0xf);
+			pvt->samples += 2;	/* 2 samples per byte */
+			tmp->next_flag = 0;
+		} else {
+			tmp->next_flag = 0x80 | d;
+		}
+	}
+
+	return 0;
+}
+
+/*! \brief convert G726-32 RFC3551 packed data into AAL2 packed data (or vice-versa) */
+static int g726tog726aal2_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
+{
+	unsigned char *src = f->data;
+	unsigned char *dst = (unsigned char *) pvt->outbuf + pvt->samples;
+	unsigned int i;
+
+	for (i = 0; i < f->datalen; i++)
+		*dst++ = ((src[i] & 0xf) << 4) | (src[i] >> 4);
+
+	pvt->samples += f->samples;
+	pvt->datalen += f->samples; /* 1 byte/sample */
+
+	return 0;
+}
+
 static struct ast_frame *g726tolin_sample(void)
 {
-	static struct ast_frame f;
-	f.frametype = AST_FRAME_VOICE;
-	f.subclass = AST_FORMAT_G726;
-	f.datalen = sizeof (g726_slin_ex);
-	f.samples = sizeof(g726_slin_ex) * 2;	/* 2 samples per byte */
-	f.mallocd = 0;
-	f.offset = 0;
-	f.src = __PRETTY_FUNCTION__;
-	f.data = g726_slin_ex;
+	static struct ast_frame f = {
+		.frametype = AST_FRAME_VOICE,
+		.subclass = AST_FORMAT_G726,
+		.datalen = sizeof(g726_slin_ex),
+		.samples = sizeof(g726_slin_ex) * 2,	/* 2 samples per byte */
+		.src = __PRETTY_FUNCTION__,
+		.data = g726_slin_ex,
+	};
+
 	return &f;
 }
 
-/*! \brief LinToG726_Sample */
 static struct ast_frame *lintog726_sample (void)
 {
-	static struct ast_frame f;
-	f.frametype = AST_FRAME_VOICE;
-	f.subclass = AST_FORMAT_SLINEAR;
-	f.datalen = sizeof (slin_g726_ex);
-	/* Assume 8000 Hz */
-	f.samples = sizeof (slin_g726_ex) / 2;	/* 1 sample per 2 bytes */
-	f.mallocd = 0;
-	f.offset = 0;
-	f.src = __PRETTY_FUNCTION__;
-	f.data = slin_g726_ex;
+	static struct ast_frame f = {
+		.frametype = AST_FRAME_VOICE,
+		.subclass = AST_FORMAT_SLINEAR,
+		.datalen = sizeof(slin_g726_ex),
+		.samples = sizeof(slin_g726_ex) / 2,	/* 1 sample per 2 bytes */
+		.src = __PRETTY_FUNCTION__,
+		.data = slin_g726_ex,
+	};
+
 	return &f;
 }
 
@@ -801,10 +849,56 @@
 	.buf_size = BUFFER_SAMPLES/2,
 };
 
+static struct ast_translator g726aal2tolin = {
+	.name = "g726aal2tolin",
+	.srcfmt = AST_FORMAT_G726_AAL2,
+	.dstfmt = AST_FORMAT_SLINEAR,
+	.newpvt = lintog726_new,	/* same for both directions */
+	.framein = g726aal2tolin_framein,
+	.sample = g726tolin_sample,
+	.desc_size = sizeof(struct g726_coder_pvt),
+	.buffer_samples = BUFFER_SAMPLES,
+	.buf_size = BUFFER_SAMPLES * 2,
+	.plc_samples = 160,
+};
+
+static struct ast_translator lintog726aal2 = {
+	.name = "lintog726aal2",
+	.srcfmt = AST_FORMAT_SLINEAR,
+	.dstfmt = AST_FORMAT_G726_AAL2,
+	.newpvt = lintog726_new,	/* same for both directions */
+	.framein = lintog726aal2_framein,
+	.sample = lintog726_sample,
+	.desc_size = sizeof(struct g726_coder_pvt),
+	.buffer_samples = BUFFER_SAMPLES,
+	.buf_size = BUFFER_SAMPLES / 2,
+};
+
+static struct ast_translator g726tog726aal2 = {
+	.name = "g726tog726aal2",
+	.srcfmt = AST_FORMAT_G726,
+	.dstfmt = AST_FORMAT_G726_AAL2,
+	.framein = g726tog726aal2_framein,	/* same for both directions */
+	.sample = lintog726_sample,
+	.buffer_samples = BUFFER_SAMPLES,
+	.buf_size = BUFFER_SAMPLES,
+};
+
+static struct ast_translator g726aal2tog726 = {
+	.name = "g726aal2tog726",
+	.srcfmt = AST_FORMAT_G726_AAL2,
+	.dstfmt = AST_FORMAT_G726,
+	.framein = g726tog726aal2_framein,	/* same for both directions */
+	.sample = lintog726_sample,
+	.buffer_samples = BUFFER_SAMPLES,
+	.buf_size = BUFFER_SAMPLES,
+};
+
 static void parse_config(void)
 {
 	struct ast_variable *var;
 	struct ast_config *cfg = ast_config_load("codecs.conf");
+
 	if (!cfg)
 		return;
 	for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
@@ -818,31 +912,47 @@
 	ast_config_destroy(cfg);
 }
 
-/*! \brief standard module glue */
-
 static int reload(void *mod)
 {
 	parse_config();
+
 	return 0;
 }
 
 static int unload_module (void *mod)
 {
-	int res;
-	res = ast_unregister_translator (&lintog726);
-	res |= ast_unregister_translator (&g726tolin);
+	int res = 0;
+
+	res |= ast_unregister_translator(&g726tolin);
+	res |= ast_unregister_translator(&lintog726);
+
+	res |= ast_unregister_translator(&g726aal2tolin);
+	res |= ast_unregister_translator(&lintog726aal2);
+
+	res |= ast_unregister_translator(&g726aal2tog726);
+	res |= ast_unregister_translator(&g726tog726aal2);
+
 	return res;
 }
 
 static int load_module (void *mod)
 {
-	int res;
+	int res = 0;
+
 	parse_config();
-	res = ast_register_translator (&g726tolin, mod);
-	if (!res)
-		res = ast_register_translator (&lintog726, mod);
-	else
-		ast_unregister_translator (&g726tolin);
+
+	res |= ast_register_translator(&g726tolin, mod);
+	res |= ast_register_translator(&lintog726, mod);
+
+	res |= ast_register_translator(&g726aal2tolin, mod);
+	res |= ast_register_translator(&lintog726aal2, mod);
+
+	res |= ast_register_translator(&g726aal2tog726, mod);
+	res |= ast_register_translator(&g726tog726aal2, mod);
+
+	if (res)
+		unload_module(mod);
+
 	return res;
 }
 
@@ -855,4 +965,5 @@
 {
 	return ASTERISK_GPL_KEY;
 }
+
 STD_MOD(MOD_1, reload, NULL, NULL);

Modified: trunk/frame.c
URL: http://svn.digium.com/view/asterisk/trunk/frame.c?rev=37494&r1=37493&r2=37494&view=diff
==============================================================================
--- trunk/frame.c (original)
+++ trunk/frame.c Wed Jul 12 17:42:13 2006
@@ -81,17 +81,18 @@
 	char *name;	/*!< short name */
 	char *desc;	/*!< Description */
 } AST_FORMAT_LIST[] = {					/*!< Bit number: comment  - Bit numbers are hard coded in show_codec() */
-	{ 1, AST_FORMAT_G723_1 , "g723" , "G.723.1"},	/*!<  1: codec_g723_1.c */
+	{ 1, AST_FORMAT_G723_1 , "g723" , "G.723.1"},	/*!<  1 */
 	{ 1, AST_FORMAT_GSM, "gsm" , "GSM"},		/*!<  2: codec_gsm.c */
 	{ 1, AST_FORMAT_ULAW, "ulaw", "G.711 u-law" },	/*!<  3: codec_ulaw.c */
 	{ 1, AST_FORMAT_ALAW, "alaw", "G.711 A-law" },	/*!<  4: codec_alaw.c */
-	{ 1, AST_FORMAT_G726, "g726", "G.726" },	/*!<  5: codec_g726.c */
+	{ 1, AST_FORMAT_G726, "g726", "G.726 RFC3551" },/*!<  5: codec_g726.c */
 	{ 1, AST_FORMAT_ADPCM, "adpcm" , "ADPCM"},	/*!<  6: codec_adpcm.c */
 	{ 1, AST_FORMAT_SLINEAR, "slin",  "16 bit Signed Linear PCM"},	/*!< 7 */
 	{ 1, AST_FORMAT_LPC10, "lpc10", "LPC10" },	/*!<  8: codec_lpc10.c */
 	{ 1, AST_FORMAT_G729A, "g729", "G.729A" },	/*!<  9: Binary commercial distribution */
 	{ 1, AST_FORMAT_SPEEX, "speex", "SpeeX" },	/*!< 10: codec_speex.c */
 	{ 1, AST_FORMAT_ILBC, "ilbc", "iLBC"},		/*!< 11: codec_ilbc.c */
+	{ 1, AST_FORMAT_G726_AAL2, "g726aal2", "G.726 AAL2" },	/*!<  12: codec_g726.c */
 	{ 0, 0, "nothing", "undefined" },
 	{ 0, 0, "nothing", "undefined" },
 	{ 0, 0, "nothing", "undefined" },
@@ -1255,6 +1256,7 @@
 		break;
 	case AST_FORMAT_ADPCM:
 	case AST_FORMAT_G726:
+	case AST_FORMAT_G726_AAL2:
 		samples = f->datalen * 2;
 		break;
 	default:
@@ -1287,6 +1289,7 @@
 		break;
 	case AST_FORMAT_ADPCM:
 	case AST_FORMAT_G726:
+	case AST_FORMAT_G726_AAL2:
 		len = samples / 2;
 		break;
 	default:

Modified: trunk/include/asterisk/frame.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/frame.h?rev=37494&r1=37493&r2=37494&view=diff
==============================================================================
--- trunk/include/asterisk/frame.h (original)
+++ trunk/include/asterisk/frame.h Wed Jul 12 17:42:13 2006
@@ -214,7 +214,7 @@
 #define AST_FORMAT_ULAW		(1 << 2)
 /*! Raw A-law data (G.711) */
 #define AST_FORMAT_ALAW		(1 << 3)
-/*! ADPCM (G.726, 32kbps) */
+/*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
 #define AST_FORMAT_G726		(1 << 4)
 /*! ADPCM (IMA) */
 #define AST_FORMAT_ADPCM	(1 << 5)
@@ -228,6 +228,8 @@
 #define AST_FORMAT_SPEEX	(1 << 9)
 /*! iLBC Free Compression */
 #define AST_FORMAT_ILBC		(1 << 10)
+/*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
+#define AST_FORMAT_G726_AAL2	(1 << 11)
 /*! Maximum audio format */
 #define AST_FORMAT_MAX_AUDIO	(1 << 15)
 /*! Maximum audio mask */

Modified: trunk/rtp.c
URL: http://svn.digium.com/view/asterisk/trunk/rtp.c?rev=37494&r1=37493&r2=37494&view=diff
==============================================================================
--- trunk/rtp.c (original)
+++ trunk/rtp.c Wed Jul 12 17:42:13 2006
@@ -1182,6 +1182,7 @@
 	{{1, AST_FORMAT_G729A}, "audio", "G729"},
 	{{1, AST_FORMAT_SPEEX}, "audio", "speex"},
 	{{1, AST_FORMAT_ILBC}, "audio", "iLBC"},
+	{{1, AST_FORMAT_G726_AAL2}, "audio", "AAL2-G726-32"},
 	{{0, AST_RTP_DTMF}, "audio", "telephone-event"},
 	{{0, AST_RTP_CISCO_DTMF}, "audio", "cisco-telephone-event"},
 	{{0, AST_RTP_CN}, "audio", "CN"},
@@ -1223,6 +1224,7 @@
 	[101] = {0, AST_RTP_DTMF},
 	[110] = {1, AST_FORMAT_SPEEX},
 	[111] = {1, AST_FORMAT_G726},
+	[112] = {1, AST_FORMAT_G726_AAL2},
 	[121] = {0, AST_RTP_CISCO_DTMF}, /* Must be type 121 */
 };
 
@@ -2376,6 +2378,7 @@
 		break;
 	case AST_FORMAT_ADPCM:
 	case AST_FORMAT_G726:
+	case AST_FORMAT_G726_AAL2:
 		if (!rtp->smoother) {
 			rtp->smoother = ast_smoother_new(80);
 		}



More information about the asterisk-commits mailing list