Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv5421/channels

Modified Files:
      Tag: v1-0
        chan_iax2.c chan_phone.c iax2-parser.c 
Log Message:
handle AST_FORMAT_SLINEAR endianness properly on big-endian systems (bug #3865)


Index: chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.188.2.16
retrieving revision 1.188.2.17
diff -u -d -r1.188.2.16 -r1.188.2.17
--- chan_iax2.c 5 Apr 2005 05:56:44 -0000       1.188.2.16
+++ chan_iax2.c 5 Apr 2005 07:10:06 -0000       1.188.2.17
@@ -6034,9 +6034,12 @@
        f.src = "IAX2";
        f.mallocd = 0;
        f.offset = 0;
-       if (f.datalen && (f.frametype == AST_FRAME_VOICE)) 
+       if (f.datalen && (f.frametype == AST_FRAME_VOICE)) {
                f.samples = get_samples(&f);
-       else
+               /* We need to byteswap incoming slinear samples from network 
byte order */
+               if (f.subclass == AST_FORMAT_SLINEAR)
+                       ast_frame_byteswap_be(&f);
+       } else
                f.samples = 0;
        iax_frame_wrap(&fr, &f);
 

Index: chan_phone.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_phone.c,v
retrieving revision 1.33.2.1
retrieving revision 1.33.2.2
diff -u -d -r1.33.2.1 -r1.33.2.2
--- chan_phone.c        12 Nov 2004 14:13:57 -0000      1.33.2.1
+++ chan_phone.c        5 Apr 2005 07:10:06 -0000       1.33.2.2
@@ -472,10 +472,13 @@
        p->fr.frametype = AST_FRAME_VOICE;
        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, char *buf, int len, int frlen)
+static int phone_write_buf(struct phone_pvt *p, char *buf, int len, int frlen, 
int swap)
 {
        int res;
        /* Store as much of the buffer as we can, then write fixed frames */
@@ -483,7 +486,10 @@
        /* 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);
@@ -628,12 +634,17 @@
                                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)) {

Index: iax2-parser.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/iax2-parser.c,v
retrieving revision 1.27.2.1
retrieving revision 1.27.2.2
diff -u -d -r1.27.2.1 -r1.27.2.2
--- iax2-parser.c       25 Oct 2004 17:57:25 -0000      1.27.2.1
+++ iax2-parser.c       5 Apr 2005 07:10:06 -0000       1.27.2.2
@@ -688,8 +688,15 @@
        fr->af.delivery.tv_sec = 0;
        fr->af.delivery.tv_usec = 0;
        fr->af.data = fr->afdata;
-       if (fr->af.datalen) 
+       if (fr->af.datalen) {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+               /* We need to byte-swap slinear samples from network byte order 
*/
+               if (fr->af.subclass == AST_FORMAT_SLINEAR) {
+                       ast_memcpy_byteswap(fr->af.data, f->data, 
fr->af.samples);
+               } else
+#endif
                memcpy(fr->af.data, f->data, fr->af.datalen);
+       }
 }
 
 struct iax_frame *iax_frame_new(int direction, int datalen)

_______________________________________________
Asterisk-Cvs mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-cvs

Reply via email to