[svn-commits] tilghman: trunk r125386 - in /trunk: codecs/ include/asterisk/ main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jun 26 12:06:18 CDT 2008


Author: tilghman
Date: Thu Jun 26 12:06:17 2008
New Revision: 125386

URL: http://svn.digium.com/view/asterisk?view=rev&rev=125386
Log:
Convert casts to unions, to fix alignment issues on Solaris
(closes issue #12932)
 Reported by: snuffy
 Patches: 
       bug_12932_20080627.diff uploaded by snuffy (license 35)

Modified:
    trunk/codecs/codec_a_mu.c
    trunk/codecs/codec_adpcm.c
    trunk/codecs/codec_alaw.c
    trunk/codecs/codec_g722.c
    trunk/codecs/codec_g726.c
    trunk/codecs/codec_gsm.c
    trunk/codecs/codec_ilbc.c
    trunk/codecs/codec_lpc10.c
    trunk/codecs/codec_resample.c
    trunk/codecs/codec_speex.c
    trunk/codecs/codec_ulaw.c
    trunk/include/asterisk/translate.h
    trunk/main/translate.c

Modified: trunk/codecs/codec_a_mu.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_a_mu.c?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/codecs/codec_a_mu.c (original)
+++ trunk/codecs/codec_a_mu.c Thu Jun 26 12:06:17 2008
@@ -47,7 +47,7 @@
 {
 	int x = f->samples;
 	unsigned char *src = f->data.ptr;
-	unsigned char *dst = (unsigned char *)pvt->outbuf + pvt->samples;
+	unsigned char *dst = pvt->outbuf.uc + 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 = (unsigned char *)pvt->outbuf + pvt->samples;
+	unsigned char *dst = pvt->outbuf.uc + pvt->samples;
 
 	pvt->samples += x;
 	pvt->datalen += x;

Modified: trunk/codecs/codec_adpcm.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_adpcm.c?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/codecs/codec_adpcm.c (original)
+++ trunk/codecs/codec_adpcm.c Thu Jun 26 12:06:17 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 = (int16_t *)pvt->outbuf + pvt->samples;
+	int16_t *dst = pvt->outbuf.i16 + pvt->samples;
 
 	while (x--) {
 		*dst++ = decode((*src >> 4) & 0xf, &tmp->state);
@@ -265,7 +265,7 @@
 	pvt->samples &= ~1; /* atomic size is 2 samples */
 
 	for (i = 0; i < pvt->samples; i += 2) {
-		pvt->outbuf[i/2] =
+		pvt->outbuf.c[i/2] =
 			(adpcm(tmp->inbuf[i  ], &tmp->state) << 4) |
 			(adpcm(tmp->inbuf[i+1], &tmp->state)     );
 	};

Modified: trunk/codecs/codec_alaw.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_alaw.c?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/codecs/codec_alaw.c (original)
+++ trunk/codecs/codec_alaw.c Thu Jun 26 12:06:17 2008
@@ -45,7 +45,7 @@
 {
 	int i = f->samples;
 	unsigned char *src = f->data.ptr;
-	int16_t *dst = (int16_t *)pvt->outbuf + pvt->samples;
+	int16_t *dst = pvt->outbuf.i16 + 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 + pvt->samples;
+	char *dst = pvt->outbuf.c + pvt->samples;
 	int16_t *src = f->data.ptr;
 
 	pvt->samples += i;

Modified: trunk/codecs/codec_g722.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_g722.c?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/codecs/codec_g722.c (original)
+++ trunk/codecs/codec_g722.c Thu Jun 26 12:06:17 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, (int16_t *) &pvt->outbuf[pvt->samples * sizeof(int16_t)], 
+	out_samples = g722_decode(&tmp->g722, &pvt->outbuf.i16[pvt->samples * sizeof(int16_t)], 
 		(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, (uint8_t *) (&pvt->outbuf[pvt->datalen]), 
+	outlen = g722_encode(&tmp->g722, (&pvt->outbuf.ui8[pvt->datalen]), 
 		(int16_t *) f->data.ptr, f->samples);
 
 	pvt->samples += outlen * 2;

Modified: trunk/codecs/codec_g726.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_g726.c?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/codecs/codec_g726.c (original)
+++ trunk/codecs/codec_g726.c Thu Jun 26 12:06:17 2008
@@ -693,7 +693,7 @@
 {
 	struct g726_coder_pvt *tmp = pvt->pvt;
 	unsigned char *src = f->data.ptr;
-	int16_t *dst = (int16_t *) pvt->outbuf + pvt->samples;
+	int16_t *dst = pvt->outbuf.i16 + pvt->samples;
 	unsigned int i;
 
 	for (i = 0; i < f->datalen; i++) {
@@ -718,7 +718,7 @@
 		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->outbuf.c[pvt->datalen++] = ((tmp->next_flag & 0xf)<< 4) | d;
 			pvt->samples += 2;	/* 2 samples per byte */
 			tmp->next_flag = 0;
 		} else {
@@ -734,7 +734,7 @@
 {
 	struct g726_coder_pvt *tmp = pvt->pvt;
 	unsigned char *src = f->data.ptr;
-	int16_t *dst = (int16_t *) pvt->outbuf + pvt->samples;
+	int16_t *dst = pvt->outbuf.i16 + pvt->samples;
 	unsigned int i;
 
 	for (i = 0; i < f->datalen; i++) {
@@ -759,7 +759,7 @@
 		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->outbuf.c[pvt->datalen++] = (d << 4) | (tmp->next_flag & 0xf);
 			pvt->samples += 2;	/* 2 samples per byte */
 			tmp->next_flag = 0;
 		} else {
@@ -774,7 +774,7 @@
 static int g726tog726aal2_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
 	unsigned char *src = f->data.ptr;
-	unsigned char *dst = (unsigned char *) pvt->outbuf + pvt->samples;
+	unsigned char *dst = pvt->outbuf.uc + pvt->samples;
 	unsigned int i;
 
 	for (i = 0; i < f->datalen; i++)

Modified: trunk/codecs/codec_gsm.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_gsm.c?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/codecs/codec_gsm.c (original)
+++ trunk/codecs/codec_gsm.c Thu Jun 26 12:06:17 2008
@@ -103,7 +103,7 @@
 {
 	struct gsm_translator_pvt *tmp = pvt->pvt;
 	int x;
-	int16_t *dst = (int16_t *)pvt->outbuf;
+	int16_t *dst = pvt->outbuf.i16;
 	/* 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 + datalen);
+		gsm_encode(tmp->gsm, tmp->buf + samples, (gsm_byte *) pvt->outbuf.c + datalen);
 		datalen += GSM_FRAME_LEN;
 		samples += GSM_SAMPLES;
 		pvt->samples -= GSM_SAMPLES;

Modified: trunk/codecs/codec_ilbc.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_ilbc.c?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/codecs/codec_ilbc.c (original)
+++ trunk/codecs/codec_ilbc.c Thu Jun 26 12:06:17 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 = (int16_t *)pvt->outbuf;
+	int16_t *dst = pvt->outbuf.i16;
 	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((unsigned char *) pvt->outbuf + datalen, tmpf, &tmp->enc);
+		iLBC_encode( pvt->outbuf.uc + datalen, tmpf, &tmp->enc);
 
 		datalen += ILBC_FRAME_LEN;
 		samples += ILBC_SAMPLES;

Modified: trunk/codecs/codec_lpc10.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_lpc10.c?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/codecs/codec_lpc10.c (original)
+++ trunk/codecs/codec_lpc10.c Thu Jun 26 12:06:17 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 = (int16_t *)pvt->outbuf;
+	int16_t *dst = pvt->outbuf.i16;
 	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((unsigned char *) pvt->outbuf + datalen, bits);
+		build_bits(pvt->outbuf.uc + datalen, bits);
 		datalen += LPC10_BYTES_IN_COMPRESSED_FRAME;
 		samples += LPC10_SAMPLES_PER_FRAME;
 		pvt->samples -= LPC10_SAMPLES_PER_FRAME;

Modified: trunk/codecs/codec_resample.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_resample.c?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/codecs/codec_resample.c (original)
+++ trunk/codecs/codec_resample.c Thu Jun 26 12:06:17 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 = (int16_t *) pvt->outbuf + pvt->samples;
+	int16_t *out_buf = pvt->outbuf.i16 + pvt->samples;
 	float in_buf_f[f->samples];
 	float out_buf_f[2048];
 	int res = 0;

Modified: trunk/codecs/codec_speex.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_speex.c?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/codecs/codec_speex.c (original)
+++ trunk/codecs/codec_speex.c Thu Jun 26 12:06:17 2008
@@ -193,7 +193,7 @@
 	   the tail location.  Read in as many frames as there are */
 	int x;
 	int res;
-	int16_t *dst = (int16_t *)pvt->outbuf;
+	int16_t *dst = pvt->outbuf.i16;
 	/* 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, pvt->t->buf_size);
+	datalen = speex_bits_write(&tmp->bits, pvt->outbuf.c, pvt->t->buf_size);
 	return ast_trans_frameout(pvt, datalen, samples);
 }
 

Modified: trunk/codecs/codec_ulaw.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_ulaw.c?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/codecs/codec_ulaw.c (original)
+++ trunk/codecs/codec_ulaw.c Thu Jun 26 12:06:17 2008
@@ -45,7 +45,7 @@
 {
 	int i = f->samples;
 	unsigned char *src = f->data.ptr;
-	int16_t *dst = (int16_t *)pvt->outbuf + pvt->samples;
+	int16_t *dst = pvt->outbuf.i16 + 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 + pvt->samples;
+	char *dst = pvt->outbuf.c + pvt->samples;
 	int16_t *src = f->data.ptr;
 
 	pvt->samples += i;

Modified: trunk/include/asterisk/translate.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/translate.h?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/include/asterisk/translate.h (original)
+++ trunk/include/asterisk/translate.h Thu Jun 26 12:06:17 2008
@@ -136,14 +136,19 @@
  */
 struct ast_trans_pvt {
 	struct ast_translator *t;
-	struct ast_frame f;	/*!< used in frameout */
-	int samples;		/*!< samples available in outbuf */
+	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 */
-	char *outbuf;		/*!< the useful portion of the buffer */
-	plc_state_t *plc;	/*!< optional plc pointer */
-	struct ast_trans_pvt *next;	/*!< next in translator chain */
+	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 timeval nextin;
 	struct timeval nextout;
 	unsigned int destroy:1;

Modified: trunk/main/translate.c
URL: http://svn.digium.com/view/asterisk/trunk/main/translate.c?view=diff&rev=125386&r1=125385&r2=125386
==============================================================================
--- trunk/main/translate.c (original)
+++ trunk/main/translate.c Thu Jun 26 12:06:17 2008
@@ -119,7 +119,7 @@
 		ofs += sizeof(plc_state_t);
 	}
 	if (t->buf_size)		/* finally buffer and header */
-		pvt->outbuf = ofs + AST_FRIENDLY_OFFSET;
+		pvt->outbuf.c = ofs + AST_FRIENDLY_OFFSET;
 	/* call local init routine, if present */
 	if (t->newpvt && t->newpvt(pvt)) {
 		ast_free(pvt);
@@ -153,7 +153,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 = (int16_t *)pvt->outbuf;
+	int16_t *dst = pvt->outbuf.i16;
 	int ret;
 	int samples = pvt->samples;	/* initial value */
 	
@@ -235,7 +235,7 @@
 	f->mallocd = 0;
 	f->offset = AST_FRIENDLY_OFFSET;
 	f->src = pvt->t->name;
-	f->data.ptr = pvt->outbuf;
+	f->data.ptr = pvt->outbuf.c;
 
 	ast_set_flag(f, AST_FRFLAG_FROM_TRANSLATOR);
 




More information about the svn-commits mailing list