[asterisk-commits] kpfleming: branch kpfleming/aligner r126394 - in /team/kpfleming/aligner: ./ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jun 29 12:50:36 CDT 2008


Author: kpfleming
Date: Sun Jun 29 12:50:36 2008
New Revision: 126394

URL: http://svn.digium.com/view/asterisk?view=rev&rev=126394
Log:
save away this work to be merged elsewhere

Added:
    team/kpfleming/aligner/
      - copied from r126355, trunk/
    team/kpfleming/aligner/configure
      - copied unchanged from r126356, trunk/configure
    team/kpfleming/aligner/configure.ac
      - copied unchanged from r126356, trunk/configure.ac
    team/kpfleming/aligner/include/asterisk/aligner.h   (with props)
    team/kpfleming/aligner/pbx/Makefile
      - copied unchanged from r126356, trunk/pbx/Makefile
    team/kpfleming/aligner/pbx/pbx_gtkconsole.c
      - copied unchanged from r126356, trunk/pbx/pbx_gtkconsole.c
    team/kpfleming/aligner/pbx/pbx_lua.c
      - copied unchanged from r126356, trunk/pbx/pbx_lua.c
Modified:
    team/kpfleming/aligner/codecs/codec_a_mu.c
    team/kpfleming/aligner/codecs/codec_adpcm.c
    team/kpfleming/aligner/codecs/codec_alaw.c
    team/kpfleming/aligner/codecs/codec_g722.c
    team/kpfleming/aligner/codecs/codec_g726.c
    team/kpfleming/aligner/codecs/codec_gsm.c
    team/kpfleming/aligner/codecs/codec_ilbc.c
    team/kpfleming/aligner/codecs/codec_lpc10.c
    team/kpfleming/aligner/codecs/codec_resample.c
    team/kpfleming/aligner/codecs/codec_speex.c
    team/kpfleming/aligner/codecs/codec_ulaw.c
    team/kpfleming/aligner/include/asterisk/translate.h
    team/kpfleming/aligner/main/translate.c
    team/kpfleming/aligner/main/utils.c

Modified: team/kpfleming/aligner/codecs/codec_a_mu.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/codecs/codec_a_mu.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/codecs/codec_a_mu.c (original)
+++ team/kpfleming/aligner/codecs/codec_a_mu.c Sun Jun 29 12:50:36 2008
@@ -47,7 +47,7 @@
 {
 	int x = f->samples;
 	unsigned char *src = f->data.ptr;
-	unsigned char *dst = pvt->outbuf.uc + pvt->samples;
+	unsigned char *dst = (unsigned char *) pvt->outbuf + pvt->samples;
 
 	pvt->samples += x;
 	pvt->datalen += x;
@@ -63,7 +63,7 @@
 {
 	int x = f->samples;
 	unsigned char *src = f->data.ptr;
-	unsigned char *dst = pvt->outbuf.uc + pvt->samples;
+	unsigned char *dst = (unsigned char *) pvt->outbuf + pvt->samples;
 
 	pvt->samples += x;
 	pvt->datalen += x;

Modified: team/kpfleming/aligner/codecs/codec_adpcm.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/codecs/codec_adpcm.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/codecs/codec_adpcm.c (original)
+++ team/kpfleming/aligner/codecs/codec_adpcm.c Sun Jun 29 12:50:36 2008
@@ -230,7 +230,7 @@
 	struct adpcm_decoder_pvt *tmp = pvt->pvt;
 	int x = f->datalen;
 	unsigned char *src = f->data.ptr;
-	int16_t *dst = pvt->outbuf.i16 + pvt->samples;
+	int16_t *dst = pvt->outbuf + pvt->samples;
 
 	while (x--) {
 		*dst++ = decode((*src >> 4) & 0xf, &tmp->state);
@@ -258,6 +258,7 @@
 	struct ast_frame *f;
 	int i;
 	int samples = pvt->samples;	/* save original number */
+	char *dst = (char *) pvt->outbuf;
   
 	if (samples < 2)
 		return NULL;
@@ -265,9 +266,8 @@
 	pvt->samples &= ~1; /* atomic size is 2 samples */
 
 	for (i = 0; i < pvt->samples; i += 2) {
-		pvt->outbuf.c[i/2] =
-			(adpcm(tmp->inbuf[i  ], &tmp->state) << 4) |
-			(adpcm(tmp->inbuf[i+1], &tmp->state)     );
+		dst[i/2] = (adpcm(tmp->inbuf[i  ], &tmp->state) << 4) |
+			   (adpcm(tmp->inbuf[i+1], &tmp->state));
 	};
 
 	f = ast_trans_frameout(pvt, pvt->samples/2, 0);

Modified: team/kpfleming/aligner/codecs/codec_alaw.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/codecs/codec_alaw.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/codecs/codec_alaw.c (original)
+++ team/kpfleming/aligner/codecs/codec_alaw.c Sun Jun 29 12:50:36 2008
@@ -45,7 +45,7 @@
 {
 	int i = f->samples;
 	unsigned char *src = f->data.ptr;
-	int16_t *dst = pvt->outbuf.i16 + pvt->samples;
+	int16_t *dst = pvt->outbuf + pvt->samples;
 
 	pvt->samples += i;
 	pvt->datalen += i * 2;	/* 2 bytes/sample */
@@ -60,7 +60,7 @@
 static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
 	int i = f->samples;
-	char *dst = pvt->outbuf.c + pvt->samples;
+	char *dst = (char *) pvt->outbuf + pvt->samples;
 	int16_t *src = f->data.ptr;
 
 	pvt->samples += i;

Modified: team/kpfleming/aligner/codecs/codec_g722.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/codecs/codec_g722.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/codecs/codec_g722.c (original)
+++ team/kpfleming/aligner/codecs/codec_g722.c Sun Jun 29 12:50:36 2008
@@ -107,7 +107,7 @@
 	/* g722_decode expects the samples to be in the invalid samples / 2 format */
 	in_samples = f->samples / 2;
 
-	out_samples = g722_decode(&tmp->g722, &pvt->outbuf.i16[pvt->samples * sizeof(int16_t)], 
+	out_samples = g722_decode(&tmp->g722, &pvt->outbuf[pvt->samples], 
 		(uint8_t *) f->data.ptr, in_samples);
 
 	pvt->samples += out_samples;
@@ -122,7 +122,7 @@
 	struct g722_encoder_pvt *tmp = pvt->pvt;
 	int outlen;
 
-	outlen = g722_encode(&tmp->g722, (&pvt->outbuf.ui8[pvt->datalen]), 
+	outlen = g722_encode(&tmp->g722, (uint8_t *) &pvt->outbuf[pvt->datalen / sizeof(*pvt->outbuf)],
 		(int16_t *) f->data.ptr, f->samples);
 
 	pvt->samples += outlen * 2;

Modified: team/kpfleming/aligner/codecs/codec_g726.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/codecs/codec_g726.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/codecs/codec_g726.c (original)
+++ team/kpfleming/aligner/codecs/codec_g726.c Sun Jun 29 12:50:36 2008
@@ -693,7 +693,7 @@
 {
 	struct g726_coder_pvt *tmp = pvt->pvt;
 	unsigned char *src = f->data.ptr;
-	int16_t *dst = pvt->outbuf.i16 + pvt->samples;
+	int16_t *dst = pvt->outbuf + pvt->samples;
 	unsigned int i;
 
 	for (i = 0; i < f->datalen; i++) {
@@ -712,13 +712,14 @@
 {
 	struct g726_coder_pvt *tmp = pvt->pvt;
 	int16_t *src = f->data.ptr;
+	char *dst = (char *) pvt->outbuf;
 	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.c[pvt->datalen++] = ((tmp->next_flag & 0xf)<< 4) | d;
+			dst[pvt->datalen++] = ((tmp->next_flag & 0xf)<< 4) | d;
 			pvt->samples += 2;	/* 2 samples per byte */
 			tmp->next_flag = 0;
 		} else {
@@ -734,7 +735,7 @@
 {
 	struct g726_coder_pvt *tmp = pvt->pvt;
 	unsigned char *src = f->data.ptr;
-	int16_t *dst = pvt->outbuf.i16 + pvt->samples;
+	int16_t *dst = pvt->outbuf + pvt->samples;
 	unsigned int i;
 
 	for (i = 0; i < f->datalen; i++) {
@@ -753,13 +754,14 @@
 {
 	struct g726_coder_pvt *tmp = pvt->pvt;
 	int16_t *src = f->data.ptr;
+	char *dst = (char *) pvt->outbuf;
 	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.c[pvt->datalen++] = (d << 4) | (tmp->next_flag & 0xf);
+			dst[pvt->datalen++] = (d << 4) | (tmp->next_flag & 0xf);
 			pvt->samples += 2;	/* 2 samples per byte */
 			tmp->next_flag = 0;
 		} else {
@@ -774,7 +776,7 @@
 static int g726tog726aal2_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
 	unsigned char *src = f->data.ptr;
-	unsigned char *dst = pvt->outbuf.uc + pvt->samples;
+	unsigned char *dst = (unsigned char *) pvt->outbuf + pvt->samples;
 	unsigned int i;
 
 	for (i = 0; i < f->datalen; i++)

Modified: team/kpfleming/aligner/codecs/codec_gsm.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/codecs/codec_gsm.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/codecs/codec_gsm.c (original)
+++ team/kpfleming/aligner/codecs/codec_gsm.c Sun Jun 29 12:50:36 2008
@@ -103,7 +103,7 @@
 {
 	struct gsm_translator_pvt *tmp = pvt->pvt;
 	int x;
-	int16_t *dst = pvt->outbuf.i16;
+	int16_t *dst = pvt->outbuf;
 	/* guess format from frame len. 65 for MSGSM, 33 for regular GSM */
 	int flen = (f->datalen % MSGSM_FRAME_LEN == 0) ?
 		MSGSM_FRAME_LEN : GSM_FRAME_LEN;
@@ -176,7 +176,7 @@
 		return NULL;
 	while (pvt->samples >= GSM_SAMPLES) {
 		/* Encode a frame of data */
-		gsm_encode(tmp->gsm, tmp->buf + samples, (gsm_byte *) pvt->outbuf.c + datalen);
+		gsm_encode(tmp->gsm, tmp->buf + samples, (gsm_byte *) pvt->outbuf + datalen);
 		datalen += GSM_FRAME_LEN;
 		samples += GSM_SAMPLES;
 		pvt->samples -= GSM_SAMPLES;

Modified: team/kpfleming/aligner/codecs/codec_ilbc.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/codecs/codec_ilbc.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/codecs/codec_ilbc.c (original)
+++ team/kpfleming/aligner/codecs/codec_ilbc.c Sun Jun 29 12:50:36 2008
@@ -114,7 +114,7 @@
 	/* Assuming there's space left, decode into the current buffer at
 	   the tail location.  Read in as many frames as there are */
 	int x,i;
-	int16_t *dst = pvt->outbuf.i16;
+	int16_t *dst = pvt->outbuf;
 	float tmpf[ILBC_SAMPLES];
 
 	if (f->datalen == 0) { /* native PLC, set fake f->datalen and clear plc_mode */
@@ -174,7 +174,7 @@
 		/* Encode a frame of data */
 		for (i = 0 ; i < ILBC_SAMPLES ; i++)
 			tmpf[i] = tmp->buf[samples + i];
-		iLBC_encode( pvt->outbuf.uc + datalen, tmpf, &tmp->enc);
+		iLBC_encode((unsigned char *) pvt->outbuf + datalen, tmpf, &tmp->enc);
 
 		datalen += ILBC_FRAME_LEN;
 		samples += ILBC_SAMPLES;

Modified: team/kpfleming/aligner/codecs/codec_lpc10.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/codecs/codec_lpc10.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/codecs/codec_lpc10.c (original)
+++ team/kpfleming/aligner/codecs/codec_lpc10.c Sun Jun 29 12:50:36 2008
@@ -140,7 +140,7 @@
 static int lpc10tolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
 	struct lpc10_coder_pvt *tmp = pvt->pvt;
-	int16_t *dst = pvt->outbuf.i16;
+	int16_t *dst = pvt->outbuf;
 	int len = 0;
 
 	while (len + LPC10_BYTES_IN_COMPRESSED_FRAME <= f->datalen) {
@@ -200,7 +200,7 @@
 		for (x=0;x<LPC10_SAMPLES_PER_FRAME;x++)
 			tmpbuf[x] = (float)tmp->buf[x + samples] / 32768.0;
 		lpc10_encode(tmpbuf, bits, tmp->lpc10.enc);
-		build_bits(pvt->outbuf.uc + datalen, bits);
+		build_bits((unsigned char *) pvt->outbuf + datalen, bits);
 		datalen += LPC10_BYTES_IN_COMPRESSED_FRAME;
 		samples += LPC10_SAMPLES_PER_FRAME;
 		pvt->samples -= LPC10_SAMPLES_PER_FRAME;

Modified: team/kpfleming/aligner/codecs/codec_resample.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/codecs/codec_resample.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/codecs/codec_resample.c (original)
+++ team/kpfleming/aligner/codecs/codec_resample.c Sun Jun 29 12:50:36 2008
@@ -103,7 +103,7 @@
 	int total_in_buf_used = 0;
 	int total_out_buf_used = 0;
 	int16_t *in_buf = (int16_t *) f->data.ptr;
-	int16_t *out_buf = pvt->outbuf.i16 + pvt->samples;
+	int16_t *out_buf = pvt->outbuf + pvt->samples;
 	float in_buf_f[f->samples];
 	float out_buf_f[2048];
 	int res = 0;

Modified: team/kpfleming/aligner/codecs/codec_speex.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/codecs/codec_speex.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/codecs/codec_speex.c (original)
+++ team/kpfleming/aligner/codecs/codec_speex.c Sun Jun 29 12:50:36 2008
@@ -193,7 +193,7 @@
 	   the tail location.  Read in as many frames as there are */
 	int x;
 	int res;
-	int16_t *dst = pvt->outbuf.i16;
+	int16_t *dst = pvt->outbuf;
 	/* XXX fout is a temporary buffer, may have different types */
 #ifdef _SPEEX_TYPES_H
 	spx_int16_t fout[1024];
@@ -316,7 +316,7 @@
 
 	/* Terminate bit stream */
 	speex_bits_pack(&tmp->bits, 15, 5);
-	datalen = speex_bits_write(&tmp->bits, pvt->outbuf.c, pvt->t->buf_size);
+	datalen = speex_bits_write(&tmp->bits, (char *) pvt->outbuf, pvt->t->buf_size);
 	return ast_trans_frameout(pvt, datalen, samples);
 }
 

Modified: team/kpfleming/aligner/codecs/codec_ulaw.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/codecs/codec_ulaw.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/codecs/codec_ulaw.c (original)
+++ team/kpfleming/aligner/codecs/codec_ulaw.c Sun Jun 29 12:50:36 2008
@@ -45,7 +45,7 @@
 {
 	int i = f->samples;
 	unsigned char *src = f->data.ptr;
-	int16_t *dst = pvt->outbuf.i16 + pvt->samples;
+	int16_t *dst = pvt->outbuf + pvt->samples;
 
 	pvt->samples += i;
 	pvt->datalen += i * 2;	/* 2 bytes/sample */
@@ -61,7 +61,7 @@
 static int lintoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
 	int i = f->samples;
-	char *dst = pvt->outbuf.c + pvt->samples;
+	char *dst = (char *) pvt->outbuf + pvt->samples;
 	int16_t *src = f->data.ptr;
 
 	pvt->samples += i;

Added: team/kpfleming/aligner/include/asterisk/aligner.h
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/include/asterisk/aligner.h?view=auto&rev=126394
==============================================================================
--- team/kpfleming/aligner/include/asterisk/aligner.h (added)
+++ team/kpfleming/aligner/include/asterisk/aligner.h Sun Jun 29 12:50:36 2008
@@ -1,0 +1,92 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2008, Digium, Inc.
+ *
+ * Kevin P. Fleming <kpfleming at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ * \brief Functions for properly aligning dynamic structure elements
+ */
+
+#ifndef _ASTERISK_ALIGNER_H
+#define _ASTERISK_ALIGNER_H
+
+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+/*!
+ * \brief Compute the space required to hold the next structure element(s)
+ * \param space The amount of space currently used (will be updated)
+ * \param num The number of elements to be added
+ * \param element The \b type \b of the element to be added
+ *
+ * This macro will determine how much padding must be used \b before \b the
+ * new elements are added to the structure, then add in the space for the
+ * elements themselves.
+ */
+#define ast_align_update_space(space, num, element) __ast_align_update_space(space, num, sizeof(element), __alignof__(element))
+
+/*!
+ * \brief Compute the space required to hold the next structure element(s), using the alignment of a different type
+ * \param space The amount of space currently used (will be updated)
+ * \param num The number of elements to be added
+ * \param size The \b type \b of the element to be added
+ * \param align The \b type \b of the element to be used for alignment calculations
+ *
+ * This macro will determine how much padding must be used \b before \b the
+ * new elements are added to the structure, then add in the space for the
+ * elements themselves.
+ */
+#define ast_align_update_space_force(space, num, size, align) __ast_align_update_space(space, num, sizeof(size), __alignof__(align))
+
+void __ast_align_update_space(size_t *space, unsigned int num_elements, size_t size_element, size_t align_element);
+
+/*!
+ * \brief Compute the base address of the next element in a structure
+ * \param base The base address of the memory allocation
+ * \param offset The amount of space currently used (will be updated)
+ * \param num The number of elements to be added
+ * \param element The \b type \b of the element to be added
+ * \return The address of the first new element
+ *
+ * This macro will determine how much padding must be used \b before \b the
+ * new elements are added to the structure, then add in the space for the
+ * elements themselves.
+ */
+#define ast_align_compute_element_ptr(base, offset, num, element) __ast_align_compute_element_ptr(base, offset, num, sizeof(element), __alignof__(element))
+
+/*!
+ * \brief Compute the base address of the next element in a structure, using the alignment of a different type
+ * \param base The base address of the memory allocation
+ * \param offset The amount of space currently used (will be updated)
+ * \param num The number of elements to be added
+ * \param size The \b type \b of the element to be added
+ * \param align The \b type \b of the element to be used for alignment calculations
+ * \return The address of the first new element
+ *
+ * This macro will determine how much padding must be used \b before \b the
+ * new elements are added to the structure, then add in the space for the
+ * elements themselves.
+ */
+#define ast_align_compute_element_ptr_force(base, offset, num, size, align) __ast_align_compute_element_ptr(base, offset, num, sizeof(size), __alignof__(align))
+
+void *__ast_align_compute_element_ptr(void *base, size_t *offset, unsigned int num_elements, size_t size_element, size_t align_element);
+
+#if defined(__cplusplus) || defined(c_plusplus)
+}
+#endif
+
+#endif /* _ASTERISK_ALIGNER_H */

Propchange: team/kpfleming/aligner/include/asterisk/aligner.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/kpfleming/aligner/include/asterisk/aligner.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/kpfleming/aligner/include/asterisk/aligner.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/kpfleming/aligner/include/asterisk/translate.h
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/include/asterisk/translate.h?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/include/asterisk/translate.h (original)
+++ team/kpfleming/aligner/include/asterisk/translate.h Sun Jun 29 12:50:36 2008
@@ -136,19 +136,13 @@
  */
 struct ast_trans_pvt {
 	struct ast_translator *t;
-	struct ast_frame f;         /*!< used in frameout */
-	int samples;                /*!< samples available in outbuf */
-	/*! \brief actual space used in outbuf */
-	int datalen;
-	void *pvt;                  /*!< more private data, if any */
-	union {
-		char *c;                /*!< the useful portion of the buffer */
-		unsigned char *uc;      /*!< the useful portion of the buffer */
-		int16_t *i16;
-		uint8_t *ui8;
-	} outbuf; 
-	plc_state_t *plc;           /*!< optional plc pointer */
-	struct ast_trans_pvt *next; /*!< next in translator chain */
+	struct ast_frame f;		/*!< used in frameout */
+	int samples;			/*!< samples available in outbuf */
+	int datalen;			/*!< \brief actual space used in outbuf */
+	void *pvt;			/*!< more private data, if any */
+	int16_t *outbuf;		/*!< the useful portion of the buffer */
+	plc_state_t *plc;		/*!< optional plc pointer */
+	struct ast_trans_pvt *next;	/*!< next in translator chain */
 	struct timeval nextin;
 	struct timeval nextout;
 	unsigned int destroy:1;

Modified: team/kpfleming/aligner/main/translate.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/main/translate.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/main/translate.c (original)
+++ team/kpfleming/aligner/main/translate.c Sun Jun 29 12:50:36 2008
@@ -38,6 +38,7 @@
 #include "asterisk/sched.h"
 #include "asterisk/cli.h"
 #include "asterisk/term.h"
+#include "asterisk/aligner.h"
 
 #define MAX_RECALC 1000 /* max sample recalc */
 
@@ -92,40 +93,59 @@
 static void *newpvt(struct ast_translator *t)
 {
 	struct ast_trans_pvt *pvt;
-	int len;
-	int useplc = t->plc_samples > 0 && t->useplc;	/* cache, because it can change on the fly */
-	char *ofs;
+	size_t len;
+	size_t offset;
+	int useplc = (t->plc_samples) > 0 && t->useplc;	/* cache, because it can change on the fly */
 
 	/*
 	 * compute the required size adding private descriptor,
-	 * plc, buffer, AST_FRIENDLY_OFFSET.
+	 * plc, buffer, AST_FRIENDLY_OFFSET and other fields,
+	 * properly aligning as we go along
 	 */
-	len = sizeof(*pvt) + t->desc_size;
-	if (useplc)
-		len += sizeof(plc_state_t);
-	if (t->buf_size)
-		len += AST_FRIENDLY_OFFSET + t->buf_size;
-	pvt = ast_calloc(1, len);
-	if (!pvt)
+
+	/* we don't know the required alignment of the private descriptor, so we have to use the worst-case
+	   of a pointer as the alignment target
+	*/
+	len = sizeof(*pvt);
+
+	ast_align_update_space_force(&len, 1, t->desc_size, void *);
+
+	if (useplc) {
+		ast_align_update_space(&len, 1, plc_state_t);
+	}
+
+	/* the output buffer can hold 16-bit elements, so perform the alignment for that case */
+
+	if (t->buf_size) {
+		ast_align_update_space_force(&len, 1, AST_FRIENDLY_OFFSET + t->buf_size, short);
+	}
+
+	if (!(pvt = ast_calloc(1, len))) {
 		return NULL;
+	}
+
 	pvt->t = t;
-	ofs = (char *)(pvt + 1);	/* pointer to data space */
-	if (t->desc_size) {		/* first comes the descriptor */
-		pvt->pvt = ofs;
-		ofs += t->desc_size;
-	}
+
+	offset = sizeof(*pvt);
+
+	pvt->pvt = ast_align_compute_element_ptr_force(pvt, &offset, 1, t->desc_size, void *);
+
 	if (useplc) {			/* then plc state */
-		pvt->plc = (plc_state_t *)ofs;
-		ofs += sizeof(plc_state_t);
-	}
-	if (t->buf_size)		/* finally buffer and header */
-		pvt->outbuf.c = ofs + AST_FRIENDLY_OFFSET;
+		pvt->plc = ast_align_compute_element_ptr(pvt, &offset, 1, plc_state_t);
+	}
+
+	if (t->buf_size) {		/* finally buffer and header */
+		pvt->outbuf = ast_align_compute_element_ptr_force(pvt, &offset, 1, AST_FRIENDLY_OFFSET + t->buf_size, short);
+	}
+
 	/* call local init routine, if present */
 	if (t->newpvt && t->newpvt(pvt)) {
 		ast_free(pvt);
 		return NULL;
 	}
+
 	ast_module_ref(t->module);
+
 	return pvt;
 }
 
@@ -153,7 +173,7 @@
 /*! \brief framein wrapper, deals with plc and bound checks.  */
 static int framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
-	int16_t *dst = pvt->outbuf.i16;
+	int16_t *dst = pvt->outbuf;
 	int ret;
 	int samples = pvt->samples;	/* initial value */
 	
@@ -235,7 +255,7 @@
 	f->mallocd = 0;
 	f->offset = AST_FRIENDLY_OFFSET;
 	f->src = pvt->t->name;
-	f->data.ptr = pvt->outbuf.c;
+	f->data.ptr = pvt->outbuf;
 
 	ast_set_flag(f, AST_FRFLAG_FROM_TRANSLATOR);
 
@@ -645,17 +665,6 @@
 		return -1;
 	}
 
-	if (t->buf_size) {
-		/*
-		 * Align buf_size properly, rounding up to the machine-specific
-		 * alignment for pointers.
-		 */
-		struct _test_align { void *a, *b; } p;
-		int align = (char *)&p.b - (char *)&p.a;
-
-		t->buf_size = ((t->buf_size + align - 1) / align) * align;
-	}
-
 	if (t->frameout == NULL)
 		t->frameout = default_frameout;
   

Modified: team/kpfleming/aligner/main/utils.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/aligner/main/utils.c?view=diff&rev=126394&r1=126355&r2=126394
==============================================================================
--- team/kpfleming/aligner/main/utils.c (original)
+++ team/kpfleming/aligner/main/utils.c Sun Jun 29 12:50:36 2008
@@ -61,6 +61,9 @@
 
 #define AST_API_MODULE
 #include "asterisk/config.h"
+
+#define AST_API_MODULE
+#include "asterisk/aligner.h"
 
 static char base64[64];
 static char b2a[256];
@@ -1744,3 +1747,32 @@
 	return res;
 }
 #endif
+
+
+void __ast_align_update_space(size_t *space, unsigned int num_elements, size_t size_element, size_t align_element)
+{
+	size_t align_base;
+
+	if ((align_base = *space % align_element) != 0) {
+		*space += align_element - align_base;
+	}
+
+	*space += size_element * num_elements;
+}
+
+void *__ast_align_compute_element_ptr(void *base, size_t *offset, unsigned int num_elements, size_t size_element, size_t align_element)
+{
+	size_t align_base;
+	void *retval;
+
+	if ((align_base = *offset % align_element) != 0) {
+		/* add padding to move up to the next alignment boundary */
+		*offset += (align_element - align_base);
+	}
+
+	retval = base + *offset;
+	*offset += size_element * num_elements;
+
+	return retval;
+}
+




More information about the asterisk-commits mailing list