[xiph-commits] r10834 - trunk/xiph-rtp
lu_zero at svn.xiph.org
lu_zero at svn.xiph.org
Sun Feb 19 14:35:13 PST 2006
Author: lu_zero
Date: 2006-02-19 14:35:10 -0800 (Sun, 19 Feb 2006)
New Revision: 10834
Modified:
trunk/xiph-rtp/xiph_rtp.c
Log:
creatertp cleanup part I
Modified: trunk/xiph-rtp/xiph_rtp.c
===================================================================
--- trunk/xiph-rtp/xiph_rtp.c 2006-02-19 19:38:09 UTC (rev 10833)
+++ trunk/xiph-rtp/xiph_rtp.c 2006-02-19 22:35:10 UTC (rev 10834)
@@ -183,63 +183,87 @@
return (ret);
}
-
-//FIXME max_payload should stay somewhere else
-void creatertp (xiph_rtp_t *xr, unsigned char* vorbdata, int length,
- long timestamp, int type, int last)
+//FIXME timestamp and sleeptime could be just one parameter
+static void flush_stack (xiph_rtp_t *xr, long sleeptime, long timestamp)
{
- int sleeptime, frag, position = 0;
- unsigned short framesize;
- unsigned char *packet;
framestack_t *fs = &xr->fs;
- const unsigned int max_payload = 1000;
+ unsigned char *packet;
+
+ if ( fs->stackcount )
+ {
+ /* Set Vorbis header flags */
+ xr->bitfield.frag_type = 0;
+ xr->bitfield.data_type = 0;
+ xr->bitfield.pkts = fs->stackcount;
-/* Set sleeptime value based on timestamp */
+ packet = malloc (fs->stacksize + 4);
- if (type)
- sleeptime = 300; // ((1 / (float) bitrate) * 1000000);
- // flush any other packet in queue (chained ogg!)
- if ( fs->stackcount ) { //FIXME avoid code duplication!
- /* Set Vorbis header flags */
- xr->bitfield.frag_type = 0;
- xr->bitfield.data_type = 0;
- xr->bitfield.pkts = fs->stackcount;
+ makeheader (xr, packet, fs->stacksize + 4);
+ memcpy (packet + 4, fs->framestack, fs->stacksize);
- packet = malloc (fs->stacksize + 4);
+ /* Swap RTP headers from host to network order */
+ xr->headers.sequence = htons (xr->headers.sequence);
+ xr->headers.timestamp = htonl (xr->headers.timestamp);
- makeheader (xr, packet, fs->stacksize + 4);
- memcpy (packet + 4, fs->framestack, fs->stacksize);
+ sendrtp (xr, packet, fs->stacksize + 4);
- /* Swap RTP headers from host to network order */
- xr->headers.sequence = htons (xr->headers.sequence);
- xr->headers.timestamp = htonl (xr->headers.timestamp);
+ /* Swap headers back to host order */
+ xr->headers.sequence = htons (xr->headers.sequence);
+ xr->headers.timestamp = ntohl (xr->headers.timestamp);
- sendrtp (xr, packet, fs->stacksize + 4);
+ if (fs->stackcount == 1)
+ progressmarker (0);
+ else
+ progressmarker (5);
- /* Swap headers back to host order */
- xr->headers.sequence = htons (xr->headers.sequence);
- xr->headers.timestamp = ntohl (xr->headers.timestamp);
+ usleep (sleeptime);
- if (fs->stackcount == 1)
- progressmarker (0);
- else
- progressmarker (5);
+ xr->headers.sequence++;
+ xr->headers.timestamp += timestamp;
- usleep (sleeptime);
+ fs->stacksize = 0;
+ fs->stackcount = 0;
- xr->headers.sequence++;
- xr->headers.timestamp += timestamp;
+ free (packet);
+ }
+}
- fs->stacksize = 0;
- fs->stackcount = 0;
+static void stack_packet(xiph_rtp_t *xr, unsigned char* vorbdata, int length)
+{
+ framestack_t *fs = &xr->fs;
+
+ 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;
- free (packet);
- }
-
- else
- sleeptime = timestamp;
+}
+//FIXME max_payload should stay somewhere else
+void creatertp (xiph_rtp_t *xr, unsigned char* vorbdata, int length,
+ long timestamp, int type, int last)
+{
+ int frag, position = 0;
+ unsigned short framesize;
+ unsigned char *packet;
+ long sleeptime = timestamp;
+ framestack_t *fs = &xr->fs;
+ const unsigned int max_payload = 1000;
+/* Set sleeptime value based on timestamp */
+
+ if (type)
+ {
+ sleeptime = 300; // ((1 / (float) bitrate) * 1000000);
+ // flush any other packet in queue (chained ogg!)
+ flush_stack(xr, timestamp, timestamp);
+ }
+
/* Frame packing. Used only for type 0 packets (raw Vorbis data) */
if ((length <= max_payload && type == 0 ) || fs->stacksize ) {
@@ -247,71 +271,20 @@
if (length + fs->stacksize <= max_payload
&& fs->stackcount < 15)
{
- 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;
+ stack_packet(xr, vorbdata, length);
}
else if (length + fs->stacksize > max_payload
- || fs->stackcount >= 15 || last)
+ || fs->stackcount >= 15)
{
- /* Set Vorbis header flags */
- xr->bitfield.frag_type = 0;
- xr->bitfield.data_type = 0;
- xr->bitfield.pkts = fs->stackcount;
-
- packet = malloc (fs->stacksize + 4);
-
- makeheader (xr, packet, fs->stacksize + 4);
- memcpy (packet + 4, fs->framestack, fs->stacksize);
-
- /* Swap RTP headers from host to network order */
- xr->headers.sequence = htons (xr->headers.sequence);
- xr->headers.timestamp = htonl (xr->headers.timestamp);
-
- sendrtp (xr, packet, fs->stacksize + 4);
-
- /* Swap headers back to host order */
- xr->headers.sequence = htons (xr->headers.sequence);
- xr->headers.timestamp = ntohl (xr->headers.timestamp);
-
- if (fs->stackcount == 1)
- progressmarker (0);
- else
- progressmarker (5);
-
- usleep (sleeptime);
-
- xr->headers.sequence++;
- xr->headers.timestamp += timestamp;
-
- fs->stacksize = 0;
- fs->stackcount = 0;
-
- free (packet);
-
- //FIXME workaround, the whole logic should be improved
- 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;
- }
- }
+ flush_stack(xr, sleeptime, timestamp);
+ if (length <= max_payload)
+ stack_packet(xr,vorbdata,length);
+ }
+ if (last)
+ flush_stack(xr, sleeptime, timestamp);
+
}
/* Send header packets (under max_payload octets) - No Packing */
More information about the commits
mailing list