[Asterisk-cvs] asterisk/channels chan_iax2.c, 1.265, 1.266 chan_phone.c, 1.47, 1.48 iax2-parser.c, 1.39, 1.40

kpfleming at lists.digium.com kpfleming at lists.digium.com
Sun Apr 3 18:04:21 CDT 2005


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

Modified Files:
	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.265
retrieving revision 1.266
diff -u -d -r1.265 -r1.266
--- chan_iax2.c	3 Apr 2005 21:16:00 -0000	1.265
+++ chan_iax2.c	3 Apr 2005 22:57:17 -0000	1.266
@@ -7337,9 +7337,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.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- chan_phone.c	30 Mar 2005 06:39:39 -0000	1.47
+++ chan_phone.c	3 Apr 2005 22:57:17 -0000	1.48
@@ -544,10 +544,13 @@
 			  : 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 @@
 	/* 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_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 @@
 				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.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- iax2-parser.c	29 Mar 2005 04:49:24 -0000	1.39
+++ iax2-parser.c	3 Apr 2005 22:57:17 -0000	1.40
@@ -855,8 +855,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)




More information about the svn-commits mailing list