[Asterisk-cvs] asterisk frame.c,1.48,1.49 rtp.c,1.118,1.119

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


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

Modified Files:
	frame.c rtp.c 
Log Message:
handle AST_FORMAT_SLINEAR endianness properly on big-endian systems (bug #3865)


Index: frame.c
===================================================================
RCS file: /usr/cvsroot/asterisk/frame.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- frame.c	21 Mar 2005 04:30:57 -0000	1.48
+++ frame.c	3 Apr 2005 22:57:17 -0000	1.49
@@ -83,7 +83,7 @@
 	s->flags = flags;
 }
 
-int ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f)
+int __ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f, int swap)
 {
 	if (f->frametype != AST_FRAME_VOICE) {
 		ast_log(LOG_WARNING, "Huh?  Can't smooth a non-voice frame!\n");
@@ -129,7 +129,10 @@
 			return 0;
 		}
 	}
-	memcpy(s->data + s->len, f->data, f->datalen);
+	if (swap)
+		ast_swapcopy_samples(s->data+s->len, f->data, f->samples);
+	else
+		memcpy(s->data + s->len, f->data, f->datalen);
 	/* If either side is empty, reset the delivery time */
 	if (!s->len || (!f->delivery.tv_sec && !f->delivery.tv_usec) ||
 			(!s->delivery.tv_sec && !s->delivery.tv_usec))
@@ -399,6 +402,16 @@
 	return ast_fr_fdwrite(fd, &hangup);
 }
 
+void ast_swapcopy_samples(void *dst, void *src, int samples)
+{
+	int i;
+	unsigned short *dst_s = dst;
+	unsigned short *src_s = src;
+
+	for (i=0; i<samples; i++)
+		dst_s[i] = (src_s[i]<<8) | (src_s[i]>>8);
+}
+
 static struct ast_format_list AST_FORMAT_LIST[] = {
 	{ 1, AST_FORMAT_G723_1 , "g723" , "G.723.1"},
 	{ 1, AST_FORMAT_GSM, "gsm" , "GSM"},

Index: rtp.c
===================================================================
RCS file: /usr/cvsroot/asterisk/rtp.c,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- rtp.c	31 Mar 2005 19:09:48 -0000	1.118
+++ rtp.c	3 Apr 2005 22:57:17 -0000	1.119
@@ -596,6 +596,7 @@
 			break;
 		case AST_FORMAT_SLINEAR:
 			rtp->f.samples = rtp->f.datalen / 2;
+			ast_frame_byteswap_be(&rtp->f);
 			break;
 		case AST_FORMAT_GSM:
 			rtp->f.samples = 160 * (rtp->f.datalen / 33);
@@ -1320,6 +1321,19 @@
 
 
 	switch(subclass) {
+	case AST_FORMAT_SLINEAR:
+		if (!rtp->smoother) {
+			rtp->smoother = ast_smoother_new(320);
+		}
+		if (!rtp->smoother) {
+			ast_log(LOG_WARNING, "Unable to create smoother :(\n");
+			return -1;
+		}
+		ast_smoother_feed_be(rtp->smoother, _f);
+		
+		while((f = ast_smoother_read(rtp->smoother)))
+			ast_rtp_raw_write(rtp, f, codec);
+		break;
 	case AST_FORMAT_ULAW:
 	case AST_FORMAT_ALAW:
 		if (!rtp->smoother) {




More information about the svn-commits mailing list