[xiph-rtp] errors in xiph_rtp.c

Stefan Ehmann shoesoft at gmx.net
Sat Jan 28 10:19:52 PST 2006


I'm currently working on a small project using vorbisrtp.

I've found an error in the reference implementation. In xiph_rtp.c the
frame packing is buggy. I've noticed that about 1% of all packets are
never sent due to this bug. This is also clearly audible with the files
I tested.

The attached patch addresses this issue. I've tested it with some files
and it works correctly for these.

Stefan

Index: xiph_rtp.c
===================================================================
--- xiph_rtp.c	(revision 1)
+++ xiph_rtp.c	(working copy)
@@ -206,9 +206,9 @@
 
 /*  Frame packing.  Used only for type 0 packets (raw Vorbis data) */
 
-	if ((length < max_payload && type == 0 ) || xr->fs.stacksize ) {
+	if ((length <= max_payload && type == 0 ) || xr->fs.stacksize ) {
 		framestack_t *fs = &xr->fs;
-		if (length + fs->stacksize < max_payload 
+		if (length + fs->stacksize <= max_payload 
 				&& fs->stackcount < 15) 
 		{
 		fs->framestack = realloc (fs->framestack, (fs->stacksize + (length +
2)));	
@@ -220,7 +220,7 @@
 		fs->stacksize += (length);
 		}
 
-		if (length + fs->stacksize > max_payload 
+		else if (length + fs->stacksize > max_payload 
 				|| fs->stackcount >= 15 || last)
 		{
 
@@ -258,12 +258,23 @@
 			fs->stackcount = 0;
 
 			free (packet);
+
+			if (length <= max_payload)
+			{
+				fs->framestack = realloc (fs->framestack, (fs->stacksize + (length
+ 2)));	
+				fs->framestack[fs->stacksize++]= (length&0xff00)>>8;
+				fs->framestack[fs->stacksize++]= length&0xff;
+				
+				memcpy (fs->framestack + (fs->stacksize), vorbdata, length);
+				fs->stackcount++;
+				fs->stacksize += (length);
+			}
 		}
 	} 
 
 /*  Send header packets (under max_payload octets) - No Packing		*/
 
-	else if (length < max_payload) {
+	else if (length <= max_payload) {
 
 		/*  Set Vorbis header flags  */
 		xr->bitfield.frag_type = 0;




More information about the xiph-rtp mailing list