From a1fa45760e632d9a689d0476b25409af81a4f5d1 Mon Sep 17 00:00:00 2001 From: tilghman Date: Thu, 26 Jun 2008 17:06:17 +0000 Subject: 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) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@125386 f38db490-d61c-443f-a65b-d21fe96a405b --- codecs/codec_a_mu.c | 4 ++-- codecs/codec_adpcm.c | 4 ++-- codecs/codec_alaw.c | 4 ++-- codecs/codec_g722.c | 4 ++-- codecs/codec_g726.c | 10 +++++----- codecs/codec_gsm.c | 4 ++-- codecs/codec_ilbc.c | 4 ++-- codecs/codec_lpc10.c | 4 ++-- codecs/codec_resample.c | 2 +- codecs/codec_speex.c | 4 ++-- codecs/codec_ulaw.c | 4 ++-- include/asterisk/translate.h | 17 +++++++++++------ main/translate.c | 6 +++--- 13 files changed, 38 insertions(+), 33 deletions(-) diff --git a/codecs/codec_a_mu.c b/codecs/codec_a_mu.c index 23f04f055..cf0354720 100644 --- a/codecs/codec_a_mu.c +++ b/codecs/codec_a_mu.c @@ -47,7 +47,7 @@ static int alawtoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) { 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 @@ static int ulawtoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) { 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; diff --git a/codecs/codec_adpcm.c b/codecs/codec_adpcm.c index cad4ded75..5cdf54176 100644 --- a/codecs/codec_adpcm.c +++ b/codecs/codec_adpcm.c @@ -230,7 +230,7 @@ static int adpcmtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) 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 @@ static struct ast_frame *lintoadpcm_frameout(struct ast_trans_pvt *pvt) 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) ); }; diff --git a/codecs/codec_alaw.c b/codecs/codec_alaw.c index b2f4f9435..a261dedb7 100644 --- a/codecs/codec_alaw.c +++ b/codecs/codec_alaw.c @@ -45,7 +45,7 @@ static int alawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) { 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 alawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) 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; diff --git a/codecs/codec_g722.c b/codecs/codec_g722.c index a574136e8..19e6b33b1 100644 --- a/codecs/codec_g722.c +++ b/codecs/codec_g722.c @@ -107,7 +107,7 @@ static int g722tolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) /* 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 @@ static int lintog722_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) 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; diff --git a/codecs/codec_g726.c b/codecs/codec_g726.c index 8d1346e66..80e0e8ea9 100644 --- a/codecs/codec_g726.c +++ b/codecs/codec_g726.c @@ -693,7 +693,7 @@ 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.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 @@ static int lintog726aal2_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) 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 @@ 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.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 @@ static int lintog726_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) 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 lintog726_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) 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++) diff --git a/codecs/codec_gsm.c b/codecs/codec_gsm.c index 805e79b66..defc1d898 100644 --- a/codecs/codec_gsm.c +++ b/codecs/codec_gsm.c @@ -103,7 +103,7 @@ static int gsmtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) { 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 @@ static struct ast_frame *lintogsm_frameout(struct ast_trans_pvt *pvt) 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; diff --git a/codecs/codec_ilbc.c b/codecs/codec_ilbc.c index 3f9b10edb..4914392a4 100644 --- a/codecs/codec_ilbc.c +++ b/codecs/codec_ilbc.c @@ -114,7 +114,7 @@ static int ilbctolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) /* 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 @@ static struct ast_frame *lintoilbc_frameout(struct ast_trans_pvt *pvt) /* 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; diff --git a/codecs/codec_lpc10.c b/codecs/codec_lpc10.c index dfcdc7988..abea9d204 100644 --- a/codecs/codec_lpc10.c +++ b/codecs/codec_lpc10.c @@ -140,7 +140,7 @@ static void build_bits(unsigned char *c, INT32 *bits) 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 @@ static struct ast_frame *lintolpc10_frameout(struct ast_trans_pvt *pvt) for (x=0;xbuf[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; diff --git a/codecs/codec_resample.c b/codecs/codec_resample.c index bdf9d19f9..f0ae03307 100644 --- a/codecs/codec_resample.c +++ b/codecs/codec_resample.c @@ -103,7 +103,7 @@ static int resample_frame(struct ast_trans_pvt *pvt, 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; diff --git a/codecs/codec_speex.c b/codecs/codec_speex.c index b9f879535..734491c75 100644 --- a/codecs/codec_speex.c +++ b/codecs/codec_speex.c @@ -193,7 +193,7 @@ static int speextolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) 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 @@ static struct ast_frame *lintospeex_frameout(struct ast_trans_pvt *pvt) /* 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); } diff --git a/codecs/codec_ulaw.c b/codecs/codec_ulaw.c index 2e0a16467..d58abe926 100644 --- a/codecs/codec_ulaw.c +++ b/codecs/codec_ulaw.c @@ -45,7 +45,7 @@ static int ulawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) { 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 ulawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) 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; diff --git a/include/asterisk/translate.h b/include/asterisk/translate.h index 97f10283f..01841ee01 100644 --- a/include/asterisk/translate.h +++ b/include/asterisk/translate.h @@ -136,14 +136,19 @@ struct ast_translator { */ 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; diff --git a/main/translate.c b/main/translate.c index 9326f4880..4ee94d940 100644 --- a/main/translate.c +++ b/main/translate.c @@ -119,7 +119,7 @@ static void *newpvt(struct ast_translator *t) 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 @@ static void destroy(struct ast_trans_pvt *pvt) /*! \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 @@ struct ast_frame *ast_trans_frameout(struct ast_trans_pvt *pvt, 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); -- cgit v1.2.3