From b96ae79baacf4012d524638c34f5eea97be426e5 Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Sun, 3 Apr 2005 22:57:18 +0000 Subject: handle AST_FORMAT_SLINEAR endianness properly on big-endian systems (bug #3865) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5373 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_phone.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'channels/chan_phone.c') diff --git a/channels/chan_phone.c b/channels/chan_phone.c index 5cee02e6f..8e5bdb523 100755 --- a/channels/chan_phone.c +++ b/channels/chan_phone.c @@ -544,10 +544,13 @@ static struct ast_frame *phone_read(struct ast_channel *ast) : AST_FRAME_VIDEO; p->fr.subclass = p->lastinput; p->fr.offset = AST_FRIENDLY_OFFSET; + /* Byteswap from little-endian to native-endian */ + if (p->fr.subclass == AST_FORMAT_SLINEAR) + ast_frame_byteswap_le(&p->fr); return &p->fr; } -static int phone_write_buf(struct phone_pvt *p, const char *buf, int len, int frlen) +static int phone_write_buf(struct phone_pvt *p, const char *buf, int len, int frlen, int swap) { int res; /* Store as much of the buffer as we can, then write fixed frames */ @@ -555,7 +558,10 @@ static int phone_write_buf(struct phone_pvt *p, const char *buf, int len, int fr /* Make sure we have enough buffer space to store the frame */ if (space < len) len = space; - memcpy(p->obuf + p->obuflen, buf, len); + if (swap) + ast_memcpy_byteswap(p->obuf+p->obuflen, buf, len/2); + else + memcpy(p->obuf + p->obuflen, buf, len); p->obuflen += len; while(p->obuflen > frlen) { res = write(p->fd, p->obuf, frlen); @@ -581,7 +587,7 @@ static int phone_write_buf(struct phone_pvt *p, const char *buf, int len, int fr static int phone_send_text(struct ast_channel *ast, const char *text) { int length = strlen(text); - return phone_write_buf(ast->tech_pvt, text, length, length) == + return phone_write_buf(ast->tech_pvt, text, length, length, 0) == length ? 0 : -1; } @@ -729,12 +735,17 @@ static int phone_write(struct ast_channel *ast, struct ast_frame *frame) memset(tmpbuf + 4, 0, sizeof(tmpbuf) - 4); memcpy(tmpbuf, frame->data, 4); expected = 24; - res = phone_write_buf(p, tmpbuf, expected, maxfr); + res = phone_write_buf(p, tmpbuf, expected, maxfr, 0); } res = 4; expected=4; } else { - res = phone_write_buf(p, pos, expected, maxfr); + int swap = 0; +#if __BYTE_ORDER == __BIG_ENDIAN + if (frame->subclass == AST_FORMAT_SLINEAR) + swap = 1; /* Swap big-endian samples to little-endian as we copy */ +#endif + res = phone_write_buf(p, pos, expected, maxfr, swap); } if (res != expected) { if ((errno != EAGAIN) && (errno != EINTR)) { -- cgit v1.2.3