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

lu_zero at svn.xiph.org lu_zero at svn.xiph.org
Fri Dec 2 14:46:23 PST 2005


Author: lu_zero
Date: 2005-12-02 14:46:18 -0800 (Fri, 02 Dec 2005)
New Revision: 10527

Modified:
   trunk/xiph-rtp/theorartp-client.c
   trunk/xiph-rtp/theorartp.c
   trunk/xiph-rtp/xiph_rtp.h
Log:
theora-rtp complete, yet untested

Modified: trunk/xiph-rtp/theorartp-client.c
===================================================================
--- trunk/xiph-rtp/theorartp-client.c	2005-12-02 20:10:06 UTC (rev 10526)
+++ trunk/xiph-rtp/theorartp-client.c	2005-12-02 22:46:18 UTC (rev 10527)
@@ -59,7 +59,7 @@
 	ogg_packet op;
 	ogg_stream_state os;
 	ogg_page og;
-	long long int last_gp;
+	long long int prev_gp;
 	long int prev_keyframe;
 	long int curr_frame;
 
@@ -69,24 +69,12 @@
 
 
 	int frag;
-	uint64_t timestamp;
-	unsigned int time_den;
-	unsigned int time_num;
+	long int timestamp;
 
-	int gpshift;
-	int gpmask;
+	int gp_shift;
 
-} ogg_context_t; 
+} ogg_context_t;
 
-static int rtp_ilog(unsigned int v){
-  int ret=0;
-  while(v){
-    ret++;
-    v>>=1;
-  }
-  return(ret);
-}
-
 int
 dump_packet_raw (unsigned char *data, const int len, FILE * out)
 {
@@ -200,31 +188,21 @@
 
 	oggpack_read(&opb,64);
 	
-	ogg->time_den = oggpack_read(&opb,32);
-	ogg->time_num = oggpack_read(&opb,32);
+//	ogg->time_den =
+	oggpack_read(&opb,32);
+//	ogg->time_num = 
+	oggpack_read(&opb,32);
 
 	oggpack_read(&opb,24);
 	oggpack_read(&opb,24);
 	
 	oggpack_read(&opb,38);
 	
-	ogg->gpshift = oggpack_read(&opb,5);
-	ogg->gpmask = (1 << ogg->gpshift) -1;
-	
+	ogg->gp_shift = oggpack_read(&opb,5);
+
 	return 0; //FIXME add some checks and return -1 on failure
 }
 
-//FIXME incomplete
-uint64_t pkt_granulepos(ogg_context_t *ogg)
-{
-	ogg->op.granulepos = 
-		(ogg->curr_frame - ogg->prev_keyframe - 1) << ogg->gpshift +
-		ogg->prev_keyframe - 1;
-
-	return ogg->op.granulepos;
-}
-
-	
 int
 cfg_repack(ogg_context_t *ogg, FILE* out)
 {
@@ -282,10 +260,60 @@
 }
 
 int
-pkt_repack(ogg_context_t *ogg, FILE *out){
+pkt_repack(ogg_context_t *ogg, int64_t timestamp, FILE *out){
 
-  ogg->op.granulepos = pkt_granulepos(ogg);
+  int frame_type;
+  ogg_packet *op = &ogg->op;
   
+  oggpack_buffer opb;
+  oggpack_readinit(&opb,op->packet,op->bytes);
+  oggpack_read(&opb,1); //video marker
+  
+  frame_type = oggpack_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
+		  ogg->prev_keyframe = timestamp;
+	  
+	  ogg->curr_frame = timestamp;
+	  
+	  op->granulepos = (ogg->curr_frame - ogg->prev_keyframe)
+		   | ogg->prev_keyframe << ogg->gp_shift;
+  }
+  else
+  {
+      if(ogg->prev_gp==-1)
+      {
+        op->granulepos = 0;
+      }
+      else
+      {
+        if(frame_type == 0) //KEY_FRAME
+	{
+          ogg->prev_keyframe = op->granulepos &
+		  ((1<<ogg->gp_shift)-1);
+          op->granulepos >>= ogg->gp_shift;
+          op->granulepos += ++ogg->prev_keyframe;
+          op->granulepos <<= ogg->gp_shift;
+        }
+	else
+          op->granulepos++;
+      }
+  }
+
+  ogg->prev_gp = op->granulepos;
+
+
   ogg_stream_packetin(&ogg->os,&ogg->op);
   do{
     int result=ogg_stream_pageout(&ogg->os,&ogg->og);
@@ -375,7 +403,7 @@
       op->bytes += data[offset++];
       op->packet = &data[offset];
       op->packetno++;
-      count += pkt_repack(ogg,out);
+      count += pkt_repack(ogg, i ? 0 : timestamp, out);
       offset += op->bytes;
       op->b_o_s=0;
     }   

Modified: trunk/xiph-rtp/theorartp.c
===================================================================
--- trunk/xiph-rtp/theorartp.c	2005-12-02 20:10:06 UTC (rev 10526)
+++ trunk/xiph-rtp/theorartp.c	2005-12-02 22:46:18 UTC (rev 10527)
@@ -61,8 +61,32 @@
 #include "xiph_rtp.h"
 
 #define BUFFER_SIZE 4096
+unsigned int cfg_parse( xiph_rtp_t *xr )
+{
+	oggpack_buffer opb;
+	
+	oggpack_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);
 
+	oggpack_read(&opb,64);
 
+	oggpack_read(&opb,32);
+	oggpack_read(&opb,32);
+
+	oggpack_read(&opb,24);
+	oggpack_read(&opb,24);
+	
+	oggpack_read(&opb,38);
+	
+	xr->gp_shift = oggpack_read(&opb,5);
+
+	return 0; //FIXME...
+}
+
 int main (int argc, char **argv) 
 {
 	xiph_rtp_t xr;
@@ -263,6 +287,7 @@
     free(conf_packet);
 }
 
+cfg_parse(&xr);
 
 /*  Read raw data and send RTP packet  */
 
@@ -288,9 +313,9 @@
 			theora_decode_packetin(&xr.td,&xr.op);   
 #ifdef DEBUG
 			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
-			timestamp = 
-				theora_granule_time(&xr.td,xr.op.granulepos);	
+#endif		
+			timestamp =  (xr.op.granulepos>>xr.gp_shift)+
+			(xr.op.granulepos & ((1<<xr.gp_shift)-1));
 			creatertp ( &xr, xr.op.packet, xr.op.bytes, 
 					timestamp, 0);
             	    }

Modified: trunk/xiph-rtp/xiph_rtp.h
===================================================================
--- trunk/xiph-rtp/xiph_rtp.h	2005-12-02 20:10:06 UTC (rev 10526)
+++ trunk/xiph-rtp/xiph_rtp.h	2005-12-02 22:46:18 UTC (rev 10527)
@@ -102,6 +102,7 @@
 	theora_info      ti;
 	theora_comment   tc;
 	theora_state     td;
+	unsigned int gp_shift;
 #endif
 	/* codec specific (speex) */
 	//FIXME



More information about the commits mailing list