[ogg-dev] Discontinuous stream support in libogg1

Roman Vorobets gembox at ya.ru
Sat Apr 14 07:44:18 PDT 2007


Hello,

I recently added discontinuous stream support to libogg1. The patch is
attached.
I also wrote Writ codec for libogg1 (based on original code by Arc), and
sample Writ encoder (SubRip to Writ converter) and decoder.
Is anybody interested?

WBR,
Roman.


-------------- next part --------------
Index: include/ogg/ogg.h
===================================================================
--- include/ogg/ogg.h	(revision 12848)
+++ include/ogg/ogg.h	(working copy)
@@ -80,6 +80,7 @@
                              (which is in a seperate abstraction
                              layer) also knows about the gap */
   ogg_int64_t   granulepos;
+  int     discont; /* 0 = continuous, 1 = discontinuous */
 
 } ogg_stream_state;
 
@@ -176,6 +177,7 @@
 /* Ogg BITSTREAM PRIMITIVES: general ***************************/
 
 extern int      ogg_stream_init(ogg_stream_state *os,int serialno);
+extern int      ogg_stream_setdiscont(ogg_stream_state *os);
 extern int      ogg_stream_clear(ogg_stream_state *os);
 extern int      ogg_stream_reset(ogg_stream_state *os);
 extern int      ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
Index: src/framing.c
===================================================================
--- src/framing.c	(revision 12848)
+++ src/framing.c	(working copy)
@@ -214,6 +214,15 @@
   return(0);
 } 
 
+int ogg_stream_setdiscont(ogg_stream_state *os){
+  /* Discont mode must be known and set before Page 1 is processed */
+  if(os->pageno==0/*||(os->pageno==1&&os->packets==0)*/){
+    os->discont=1;
+    return(0);
+  }
+  return(-1);
+}
+
 int ogg_stream_destroy(ogg_stream_state *os){
   if(os){
     ogg_stream_clear(os);
@@ -304,7 +313,7 @@
   /* Store lacing vals for this packet */
   for(i=0;i<lacing_vals-1;i++){
     os->lacing_vals[os->lacing_fill+i]=255;
-    os->granule_vals[os->lacing_fill+i]=os->granulepos;
+    os->granule_vals[os->lacing_fill+i]=granulepos;
   }
   os->lacing_vals[os->lacing_fill+i]=bytes%255;
   os->granulepos=os->granule_vals[os->lacing_fill+i]=granulepos;
@@ -367,11 +376,14 @@
       }
     }
   }else{
+    int cont=1;
     for(vals=0;vals<maxvals;vals++){
       if(acc>4096)break;
       acc+=os->lacing_vals[vals]&0x0ff;
-      if((os->lacing_vals[vals]&0xff)<255)
+      if(os->discont?cont&&os->lacing_vals[vals]&0x100:os->lacing_vals[vals]&0xff<255){
         granule_pos=os->granule_vals[vals];
+        cont=0;
+      }
     }
   }
   
@@ -783,7 +795,8 @@
 	bos=0;
       }
       
-      if(val<255)saved=os->lacing_fill;
+      if(os->discont?saved==-1&&!continued:val<255)saved=os->lacing_fill;
+      if(val<255)continued=0;
       
       os->lacing_fill++;
       segptr++;
@@ -791,7 +804,9 @@
       if(val<255)os->lacing_packet=os->lacing_fill;
     }
   
-    /* set the granulepos on the last granuleval of the last full packet */
+    /* set the granulepos on the last granuleval of the last full packet
+       OR, for discontinuous stream,
+       set the granulepos on the first granuleval of the first packet */
     if(saved!=-1){
       os->granule_vals[saved]=granulepos;
     }
@@ -834,6 +849,7 @@
   os->pageno=-1;
   os->packetno=0;
   os->granulepos=0;
+  os->discont=0;
 
   return(0);
 }
@@ -873,6 +889,7 @@
     int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
     int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
 
+    if(op&&os->discont)op->granulepos=os->granule_vals[ptr];
     while(size==255){
       int val=os->lacing_vals[++ptr];
       size=val&0xff;
@@ -885,7 +902,7 @@
       op->b_o_s=bos;
       op->packet=os->body_data+os->body_returned;
       op->packetno=os->packetno;
-      op->granulepos=os->granule_vals[ptr];
+      if(!os->discont)op->granulepos=os->granule_vals[ptr];
       op->bytes=bytes;
     }
 


More information about the ogg-dev mailing list