[xiph-commits] r10586 - trunk/xiph-rtp

lu_zero at svn.xiph.org lu_zero at svn.xiph.org
Tue Dec 13 05:52:04 PST 2005


Author: lu_zero
Date: 2005-12-13 05:51:58 -0800 (Tue, 13 Dec 2005)
New Revision: 10586

Modified:
   trunk/xiph-rtp/theorartp-client.c
   trunk/xiph-rtp/theorartp.c
   trunk/xiph-rtp/vorbisrtp-client.c
   trunk/xiph-rtp/vorbisrtp.c
   trunk/xiph-rtp/xiph_rtp.c
   trunk/xiph-rtp/xiph_rtp.h
Log:
theora fixed, eof case handled

Modified: trunk/xiph-rtp/theorartp-client.c
===================================================================
--- trunk/xiph-rtp/theorartp-client.c	2005-12-13 13:16:15 UTC (rev 10585)
+++ trunk/xiph-rtp/theorartp-client.c	2005-12-13 13:51:58 UTC (rev 10586)
@@ -69,7 +69,7 @@
 
 
 	int frag;
-	long int timestamp;
+	unsigned int timestamp;
 
 	int gp_shift;
 
@@ -179,26 +179,26 @@
 {
 	oggpack_buffer opb;
 	
-	oggpack_readinit(&opb,ogg->op.packet, ogg->op.bytes);
+	oggpackB_readinit(&opb,ogg->op.packet, ogg->op.bytes);
 	
-	oggpack_read(&opb,8*7);
-	oggpack_read(&opb,8*3);
-	oggpack_read(&opb,16);
-	oggpack_read(&opb,16);
+	oggpackB_read(&opb,8*7);
+	oggpackB_read(&opb,8*3);
+	oggpackB_read(&opb,16);
+	oggpackB_read(&opb,16);
 
-	oggpack_read(&opb,64);
+	oggpackB_read(&opb,64);
 	
 //	ogg->time_den =
-	oggpack_read(&opb,32);
+	oggpackB_read(&opb,32);
 //	ogg->time_num = 
-	oggpack_read(&opb,32);
+	oggpackB_read(&opb,32);
 
-	oggpack_read(&opb,24);
-	oggpack_read(&opb,24);
+	oggpackB_read(&opb,24);
+	oggpackB_read(&opb,24);
 	
-	oggpack_read(&opb,38);
+	oggpackB_read(&opb,38);
 	
-	ogg->gp_shift = oggpack_read(&opb,5);
+	ogg->gp_shift = oggpackB_read(&opb,5);
 
 	return 0; //FIXME add some checks and return -1 on failure
 }
@@ -259,7 +259,7 @@
 }
 
 int
-pkt_repack(ogg_context_t *ogg, int64_t timestamp, FILE *out){
+pkt_repack(ogg_context_t *ogg, unsigned int timestamp, FILE *out){
 
   int frame_type;
   ogg_packet *op = &ogg->op;
@@ -268,17 +268,9 @@
   oggpack_readinit(&opb,op->packet,op->bytes);
   oggpack_read(&opb,1); //video marker
   
-  frame_type = oggpack_read(&opb,1);
+  frame_type = oggpackB_read(&opb,1);
 
-  oggpack_read(&opb,6);
-  
-  if(oggpack_read(&opb,1))
-  {
-	  oggpack_read(&opb,6);
-	  if(oggpack_read(&opb,1))
-		  oggpack_read(&opb,6);
-  }
-
+ 
   if(timestamp)
   {
 	  if (frame_type == 0) //KEY_FRAME
@@ -312,6 +304,10 @@
 
   ogg->prev_gp = op->granulepos;
 
+#ifdef DEBUG
+  fprintf(stderr," type %d, timestamp %d, bytes %ld bos %ld eos %ld gp %lld pno %lld\n",frame_type, timestamp, op->bytes, op->b_o_s, op->e_o_s, op->granulepos, op->packetno );
+#endif
+ 
 
   ogg_stream_packetin(&ogg->os,&ogg->op);
   do{
@@ -370,7 +366,7 @@
     break;
   case 1:
     op->bytes = 0;
-    if (op->packet) free (op->packet);
+    //FIXME malloc checks
     op->packet = NULL;
   case 2:
     length = data[offset++] << 8;
@@ -394,7 +390,7 @@
   switch (VDT) {
 
   case 0:
-
+  
   count += pkt_repack(ogg, timestamp, out);
   
   for (i = 1; i < pkts; i++)
@@ -411,19 +407,20 @@
       count += pkt_repack(ogg, 0, out);
       offset += op->bytes;
     }
-    break;
+  break;
   case 1:
     count = cfg_repack(ogg, out);
+    op->packetno+=3;
     break;
   default:
     //ignore
     break;
     
   }
-  if (F == 3) 
+  if ( F == 3 ) 
   {
-	  free(op->packet);
-	  op->packet = NULL;
+	free(op->packet);
+	op->packet = NULL;
   }
   return count;
 }
@@ -444,10 +441,8 @@
   memset(&ogg,0,sizeof(ogg_context_t));
   ogg.prev_gp=-1;
 
-  fprintf (stderr,
-	   "||---------------------------------------------------------------------------||\n");
 
-  fprintf (stderr, "||  Vorbis RTP Client (draft-barbato-avt-rtp-theora-05)\n");
+  fprintf (stderr, "  Vorbis RTP Client (draft-barbato-avt-rtp-theora-05)\n");
 
   while ((opt = getopt (argc, argv, "i:p:f:v")) != -1)
     {

Modified: trunk/xiph-rtp/theorartp.c
===================================================================
--- trunk/xiph-rtp/theorartp.c	2005-12-13 13:16:15 UTC (rev 10585)
+++ trunk/xiph-rtp/theorartp.c	2005-12-13 13:51:58 UTC (rev 10586)
@@ -65,25 +65,27 @@
 {
 	oggpack_buffer opb;
 	
-	oggpack_readinit(&opb,xr->header[0].packet, xr->header[0].bytes);
+	oggpackB_readinit(&opb,xr->header[0].packet, xr->header[0].bytes);
 	
-	oggpack_read(&opb,8*7);
-	oggpack_read(&opb,8*3);
-	oggpack_read(&opb,16);
-	oggpack_read(&opb,16);
+	oggpackB_read(&opb,8*7); // 0x80"theora"
+	oggpackB_read(&opb,8*3); // version
+	oggpackB_read(&opb,16); //w
+	oggpackB_read(&opb,16); //h
 
-	oggpack_read(&opb,64);
+	oggpackB_read(&opb,64); 
 
-	oggpack_read(&opb,32);
-	oggpack_read(&opb,32);
+	oggpackB_read(&opb,32);
+	oggpackB_read(&opb,32);
 
-	oggpack_read(&opb,24);
-	oggpack_read(&opb,24);
+	oggpackB_read(&opb,24);
+	oggpackB_read(&opb,24);
 	
-	oggpack_read(&opb,38);
+	oggpackB_read(&opb,38);
 	
-	xr->gp_shift = oggpack_read(&opb,5);
+	xr->gp_shift = oggpackB_read(&opb,5);
 
+	printf("gp_shift %d \n", xr->gp_shift);
+
 	return 0; //FIXME...
 }
 
@@ -281,7 +283,7 @@
     memcpy (conf_packet + xr.header[0].bytes, 
 		    xr.header[2].packet,
 		    xr.header[2].bytes);
-    creatertp(&xr, conf_packet, conf_bytes, 0, 1);
+    creatertp(&xr, conf_packet, conf_bytes, 0, 1, 0);
     
     free(conf_packet);
 }
@@ -310,15 +312,25 @@
                         /* no reason to complain; already complained above  */
             	    } else {
 			theora_decode_packetin(&xr.td,&xr.op);   
+			if (xr.op.granulepos != -1)
+				timestamp =  (xr.op.granulepos>>xr.gp_shift)+
+				(xr.op.granulepos & ((1<<xr.gp_shift)-1));
+			else 
+				timestamp++ ;
 #ifdef DEBUG
+			{
+			oggpack_buffer opb;
+			int type;
+			  oggpackB_readinit(&opb,xr.op.packet,xr.op.bytes);
+			  oggpack_read(&opb,1); //video marker
+  
+			  type = oggpackB_read(&opb,1);
+			  printf("  type %d stamp %ld", type, timestamp);
+			}
 			printf("  bytes %ld bos %ld eos %ld gp %lld pno %lld\n", xr.op.bytes, xr.op.b_o_s, xr.op.e_o_s, xr.op.granulepos, xr.op.packetno);
 #endif
-			if (xr.op.granulepos != -1)
-			timestamp =  (xr.op.granulepos>>xr.gp_shift)+
-			(xr.op.granulepos & ((1<<xr.gp_shift)-1));
-			else timestamp++ ;
 			creatertp ( &xr, xr.op.packet, xr.op.bytes, 
-					timestamp, 0);
+					timestamp, 0, xr.op.e_o_s );
             	    }
                 }
 

Modified: trunk/xiph-rtp/vorbisrtp-client.c
===================================================================
--- trunk/xiph-rtp/vorbisrtp-client.c	2005-12-13 13:16:15 UTC (rev 10585)
+++ trunk/xiph-rtp/vorbisrtp-client.c	2005-12-13 13:51:58 UTC (rev 10586)
@@ -607,17 +607,17 @@
       count += pkt_repack(ogg,out);
       offset += op->bytes;
       op->b_o_s=0;
-    }   
-    break;
+    }
+  break;
   case 1:
     count = cfg_repack(ogg, out);
-    break;
+  break;
   default:
     //ignore
-    break;
+  break;
     
   }
-  if (F == 3)
+  if ( F == 3 )
   {
 	  free(op->packet);
 	  op->packet = NULL;

Modified: trunk/xiph-rtp/vorbisrtp.c
===================================================================
--- trunk/xiph-rtp/vorbisrtp.c	2005-12-13 13:16:15 UTC (rev 10585)
+++ trunk/xiph-rtp/vorbisrtp.c	2005-12-13 13:51:58 UTC (rev 10586)
@@ -77,7 +77,6 @@
 
 	int i = 0;
 	int opt;
-	long int acc=0;
 
 	char *ip = "227.0.0.1";
 	unsigned int port = 4044;
@@ -256,7 +255,7 @@
     memcpy (conf_packet + xr.header[0].bytes, 
 		    xr.header[2].packet,
 		    xr.header[2].bytes);
-    creatertp(&xr, conf_packet, conf_bytes, 0, 1);
+    creatertp(&xr, conf_packet, conf_bytes, 0, 1, 0);
     
     free(conf_packet);
 }
@@ -288,7 +287,7 @@
 			printf("  bytes %ld bos %ld eos %ld gp %lld pno %lld\n", xr.op.bytes, xr.op.b_o_s, xr.op.e_o_s, xr.op.granulepos, xr.op.packetno);
 #endif
 			creatertp ( &xr, xr.op.packet, xr.op.bytes, 
-					timestamp, 0);
+					timestamp, 0, xr.op.e_o_s );
 			timestamp = ( vorbis_packet_blocksize(&xr.vi,&xr.op) +
 					prev ) / 4*1000000L / xr.vi.rate;
 			prev = vorbis_packet_blocksize(&xr.vi,&xr.op);

Modified: trunk/xiph-rtp/xiph_rtp.c
===================================================================
--- trunk/xiph-rtp/xiph_rtp.c	2005-12-13 13:16:15 UTC (rev 10585)
+++ trunk/xiph-rtp/xiph_rtp.c	2005-12-13 13:51:58 UTC (rev 10586)
@@ -167,7 +167,10 @@
 	int ret;
 	char *outbuffer;
 
-		outbuffer = malloc (sizeof (rtp_headers_t) + len);
+#if 0
+	fprintf(stderr,"sent %d bytes\n",len);
+#endif
+	outbuffer = malloc (sizeof (rtp_headers_t) + len);
 	
 	memcpy (outbuffer,  &xr->headers, sizeof (rtp_headers_t));
 	memcpy (outbuffer + sizeof (rtp_headers_t), data, len);
@@ -183,7 +186,7 @@
 
 //FIXME max_payload should stay somewhere else
 void creatertp (xiph_rtp_t *xr, unsigned char* vorbdata, int length,
-		long timestamp, int type)
+		long timestamp, int type, int last)
 {
 	int sleeptime, frag, position = 0;
 	unsigned short framesize;
@@ -198,85 +201,14 @@
 	else
 		sleeptime = timestamp;
 
-/*  Frame fragmentation */
 
-	if (length > max_payload) {
-		frag = 1;
-		while (length > max_payload) {		
-		/*  Set Vorbis header flags  */
-			xr->bitfield.frag_type = frag;
-			xr->bitfield.data_type = type;
-			xr->bitfield.pkts = 0;
-
-			framesize = max_payload;
-
-			packet = malloc (framesize + 4 + 2);
-
-			makeheader (xr, packet, framesize + 2 + 4);
-		/* write 16-bit network order fragment length */
-			packet[4]=(framesize&0xff00)>>8;
-			packet[5]=framesize&0xff;
-			memcpy (packet + 4 + 2, vorbdata + position, framesize);
-
-			/*  Swap RTP headers from host to network order  */
-			xr->headers.sequence = htons (xr->headers.sequence);
-
-			sendrtp (xr, packet, framesize + 4 + 2);
-
-			/*  Swap headers back to host order  */
-			xr->headers.sequence = ntohs (xr->headers.sequence);
-
-			length -= max_payload;
-			position += max_payload;
-			frag = 2;
-
-			xr->headers.sequence = xr->headers.sequence + 1;
-
-			progressmarker (1);
-
-			free (packet);
-		}
-
-		/*  Set Vorbis header flags  */
-		xr->bitfield.frag_type = 3;
-		xr->bitfield.data_type = type;
-		xr->bitfield.pkts = 0;
-
-		framesize = length;
-
-		packet = malloc (length + 4 + 2);
-
-		makeheader (xr, packet, length + 4 + 2);
-		packet[4]=(framesize&0xff00)>>8;
-		packet[5]=framesize&0xff;
-		memcpy (packet + 4 + 2, vorbdata + position, length);
-
-		/*  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, length + 4 + 2);
-
-		/*  Swap headers back to host order  */
-		xr->headers.sequence = htons (xr->headers.sequence);
-		xr->headers.timestamp = ntohl (xr->headers.timestamp);
-
-		/*  Increment RTP headers  */
-		xr->headers.sequence++;
-		xr->headers.timestamp += sleeptime;
-
-		progressmarker (2);
-
-		free (packet);
-		return;
-	}
-
 /*  Frame packing.  Used only for type 0 packets (raw Vorbis data) */
 
-	if (length < max_payload && type == 0) {
+	if ((length < max_payload && type == 0 ) || xr->fs.stacksize ) {
 		framestack_t *fs = &xr->fs;
-
-		if (length + fs->stacksize < max_payload && fs->stackcount < 15) {
+		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;
@@ -286,10 +218,10 @@
 		fs->stacksize += (length);
 		}
 
-	/* todo: we also need to be able to flush this at end-of-stream */
+		if (length + fs->stacksize > max_payload 
+				|| fs->stackcount >= 15 || last)
+		{
 
-		if (length + fs->stacksize > max_payload || fs->stackcount >= 15) {
-
 			/*  Set Vorbis header flags  */
 			xr->bitfield.frag_type = 0;
 			xr->bitfield.data_type = 0;
@@ -318,19 +250,16 @@
 			usleep (sleeptime); /* WRONG */
 
 			xr->headers.sequence++;
-			xr->headers.timestamp += sleeptime;
+			xr->headers.timestamp += timestamp;
 
 			fs->stacksize = 0;
 			fs->stackcount = 0;
 
 			free (packet);
-		}   
-		return;
+		}
 	} 
 
-/*===========================================================================*/
-/*  Send header packets (under max_payload octets) - No Packing			  */
-/*===========================================================================*/
+/*  Send header packets (under max_payload octets) - No Packing		*/
 
 	else if (length < max_payload) {
 
@@ -345,8 +274,8 @@
 
 		makeheader (xr, packet, length + 4 + 2);
 
-	packet[4]=(length&0xff00)>>8;
-	packet[5]=length&0xff;
+		packet[4]=(length&0xff00)>>8;
+		packet[5]=length&0xff;
 
 		memcpy (packet + 4 + 2, vorbdata, length);
 
@@ -360,16 +289,89 @@
 		xr->headers.sequence = htons (xr->headers.sequence);
 		xr->headers.timestamp = ntohl (xr->headers.timestamp);
 
-	/* WRONG. We need to sleep something like 1/2 the time to the
-	   next packet. The caller should probably handle this. */
+	/* We need to sleep something like enough time to not overflow
+	 * the playout buffer nor starve it */
 		sleeptime = timestamp;
 		usleep (sleeptime);
 
 		xr->headers.sequence++;
-		xr->headers.timestamp += sleeptime;
+		xr->headers.timestamp += timestamp;
 
 		free (packet);
 	}			
+	
+/*  Frame fragmentation */
+
+	if (length > max_payload) {
+		frag = 1;
+		while (length > max_payload) {		
+		/*  Set Vorbis header flags  */
+			xr->bitfield.frag_type = frag;
+			xr->bitfield.data_type = type;
+			xr->bitfield.pkts = 0;
+
+			framesize = max_payload;
+
+			packet = malloc (framesize + 4 + 2);
+
+			makeheader (xr, packet, framesize + 2 + 4);
+		/* write 16-bit network order fragment length */
+			packet[4]=(framesize&0xff00)>>8;
+			packet[5]=framesize&0xff;
+			memcpy (packet + 4 + 2, vorbdata + position, framesize);
+
+			/*  Swap RTP headers from host to network order  */
+			xr->headers.sequence = htons (xr->headers.sequence);
+
+			sendrtp (xr, packet, framesize + 4 + 2);
+
+			/*  Swap headers back to host order  */
+			xr->headers.sequence = ntohs (xr->headers.sequence);
+
+			length -= max_payload;
+			position += max_payload;
+			frag = 2;
+
+			xr->headers.sequence = xr->headers.sequence + 1;
+
+			progressmarker (1);
+
+			free (packet);
+		}
+
+		/*  Set Vorbis header flags  */
+		xr->bitfield.frag_type = 3;
+		xr->bitfield.data_type = type;
+		xr->bitfield.pkts = 0;
+
+		framesize = length;
+
+		packet = malloc (length + 4 + 2);
+
+		makeheader (xr, packet, length + 4 + 2);
+		packet[4]=(framesize&0xff00)>>8;
+		packet[5]=framesize&0xff;
+		memcpy (packet + 4 + 2, vorbdata + position, length);
+
+		/*  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, length + 4 + 2);
+
+		/*  Swap headers back to host order  */
+		xr->headers.sequence = htons (xr->headers.sequence);
+		xr->headers.timestamp = ntohl (xr->headers.timestamp);
+
+		/*  Increment RTP headers  */
+		xr->headers.sequence++;
+		xr->headers.timestamp += timestamp;
+
+		progressmarker (2);
+
+		free (packet);
+		return;
+	}
 }
 	
 int makeheader (xiph_rtp_t *xr, unsigned char *packet, int length)

Modified: trunk/xiph-rtp/xiph_rtp.h
===================================================================
--- trunk/xiph-rtp/xiph_rtp.h	2005-12-13 13:16:15 UTC (rev 10585)
+++ trunk/xiph-rtp/xiph_rtp.h	2005-12-13 13:51:58 UTC (rev 10586)
@@ -113,7 +113,7 @@
 		  unsigned char TTL);
 
 void creatertp (xiph_rtp_t *xr, unsigned char* vorbdata, int length,
-		long timestamp, int type);
+		long timestamp, int type, int last);
 
 int sendrtp (xiph_rtp_t *xr, const void *data, int len);
 



More information about the commits mailing list