[xiph-commits] r8848 - trunk/xiph-rtp
giles at motherfish-iii.xiph.org
giles at motherfish-iii.xiph.org
Sun Feb 6 21:26:31 PST 2005
Author: giles
Date: 2005-02-06 21:26:30 -0800 (Sun, 06 Feb 2005)
New Revision: 8848
Modified:
trunk/xiph-rtp/vorbisrtp.c
Log:
Fix an endian bug in the vorbis rtp server. The Vorbis RTP header was being
written directly from the struct where the flags are defined as bitfields,
but the packing order for bitfields is implementation-dependent. In particular,
gcc packs them little-endian on x86 systems. Replace the simple memcpy() with
a function that uses traditional mask and shift to set the flag octect in big
endian order.
Modified: trunk/xiph-rtp/vorbisrtp.c
===================================================================
--- trunk/xiph-rtp/vorbisrtp.c 2005-02-07 05:20:57 UTC (rev 8847)
+++ trunk/xiph-rtp/vorbisrtp.c 2005-02-07 05:26:30 UTC (rev 8848)
@@ -326,6 +326,23 @@
}
/*****************************************************************************/
+/* Fills in the Vorbis RTP header in a packet. */
+/*****************************************************************************/
+
+int makevorbisheader (unsigned char *packet, int length, struct VorbisBitfields *vorbheader)
+{
+ if (length < 5) return -1;
+
+ ((unsigned int *)packet)[0] = vorbheader->cbident;
+ packet[4] = (vorbheader -> continuation) << 7;
+ packet[4] |= (vorbheader -> fragment) << 6;
+ packet[4] |= (vorbheader -> reserved) << 5;
+ packet[4] |= (vorbheader -> pkts) & 0x1f;
+
+ return 0;
+}
+
+/*****************************************************************************/
/* Creates RTP packet from Vorbis frame. */
/* Deals with fragmentation and multiple Vorbis frame RTP packets */
/*****************************************************************************/
@@ -366,7 +383,7 @@
packet = malloc (262);
- memcpy (packet, vorbheader, 5);
+ makevorbisheader (packet, 262, vorbheader);
memcpy (packet + 5, &framesize, 1);
memmove (packet + 6, vorbdata, 256);
@@ -399,7 +416,7 @@
packet = malloc (length + 6);
- memcpy (packet, vorbheader, 5);
+ makevorbisheader (packet, length + 6, vorbheader);
memcpy (packet + 5, &framesize, 1);
memcpy (packet + 6, vorbdata + position, length);
@@ -448,7 +465,7 @@
packet = malloc (stacksize + 6);
- memmove (packet, vorbheader, 5);
+ makevorbisheader (packet, stacksize + 6, vorbheader);
memmove (packet + 6, framestack, stacksize);
/* Swap RTP headers from host to network order */
@@ -495,7 +512,7 @@
packet = malloc (length + 6);
- memcpy (packet, vorbheader, 5);
+ makevorbisheader (packet, length + 6, vorbheader);
memcpy (packet + 5, &framesize, 1);
memcpy (packet + 6, vorbdata, length);
More information about the commits
mailing list