[xiph-cvs] cvs commit: ogg/src framing.c

Monty xiphmont at xiph.org
Wed May 23 18:04:37 PDT 2001



xiphmont    01/05/23 18:04:37

  Modified:    include/ogg ogg.h
               src      framing.c
  Log:
  Minor API additions; none break compatability.
  
  added ogg_stream_packetpeek; returns the next packet from the stream
  stste without removing it from the stream.
  
  ogg_stream_packetout can now be passed a NULL packet pointer; in this
  case it removes the packet at the head of the stream and drops it on
  the floor.
  
  Monty

Revision  Changes    Path
1.11      +2 -1      ogg/include/ogg/ogg.h

Index: ogg.h
===================================================================
RCS file: /usr/local/cvsroot/ogg/include/ogg/ogg.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ogg.h	2001/02/26 03:49:58	1.10
+++ ogg.h	2001/05/24 01:04:36	1.11
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: toplevel libogg include
- last mod: $Id: ogg.h,v 1.10 2001/02/26 03:49:58 xiphmont Exp $
+ last mod: $Id: ogg.h,v 1.11 2001/05/24 01:04:36 xiphmont Exp $
 
  ********************************************************************/
 #ifndef _OGG_H
@@ -145,6 +145,7 @@
 extern int      ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
 extern int      ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
 extern int      ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
+extern int      ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
 
 /* Ogg BITSTREAM PRIMITIVES: general ***************************/
 

1.12      +42 -21    ogg/src/framing.c

Index: framing.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/framing.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- framing.c	2001/02/26 03:49:59	1.11
+++ framing.c	2001/05/24 01:04:36	1.12
@@ -12,7 +12,7 @@
 
  function: code raw [Vorbis] packets into framed OggSquish stream and
            decode Ogg streams back into raw packets
- last mod: $Id: framing.c,v 1.11 2001/02/26 03:49:59 xiphmont Exp $
+ last mod: $Id: framing.c,v 1.12 2001/05/24 01:04:36 xiphmont Exp $
 
  note: The CRC code is directly derived from public domain code by
  Ross Williams (ross at guest.adelaide.edu.au).  See docs/framing.html
@@ -766,7 +766,7 @@
   return(0);
 }
 
-int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
+static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
 
   /* The last part of decode. We have the stream broken into packet
      segments.  Now we need to group them into packets (or return the
@@ -777,43 +777,55 @@
   if(os->lacing_packet<=ptr)return(0);
 
   if(os->lacing_vals[ptr]&0x400){
-    /* We lost sync here; let the app know */
-    os->lacing_returned++;
-
     /* we need to tell the codec there's a gap; it might need to
        handle previous packet dependencies. */
-    os->packetno++;
+    if(adv){
+      os->lacing_returned++;
+      os->packetno++;
+    }
     return(-1);
   }
 
   /* Gather the whole packet. We'll have no holes or a partial packet */
   {
     int size=os->lacing_vals[ptr]&0xff;
-    int bytes=0;
-
-    op->packet=os->body_data+os->body_returned;
-    op->e_o_s=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
-    op->b_o_s=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
-    bytes+=size;
+    int bytes=size;
+    int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
+    int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
 
     while(size==255){
       int val=os->lacing_vals[++ptr];
       size=val&0xff;
-      if(val&0x200)op->e_o_s=0x200;
+      if(val&0x200)eos=0x200;
       bytes+=size;
     }
 
-    op->packetno=os->packetno;
-    op->granulepos=os->granule_vals[ptr];
-    op->bytes=bytes;
+    if(op){
+      op->e_o_s=eos;
+      op->b_o_s=bos;
+      op->packet=os->body_data+os->body_returned;
+      op->packetno=os->packetno;
+      op->granulepos=os->granule_vals[ptr];
+      op->bytes=bytes;
+    }
 
-    os->body_returned+=bytes;
-    os->lacing_returned=ptr+1;
+    if(adv){
+      os->body_returned+=bytes;
+      os->lacing_returned=ptr+1;
+      os->packetno++;
+    }
   }
-  os->packetno++;
   return(1);
 }
 
+int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
+  return _packetout(os,op,1);
+}
+
+int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
+  return _packetout(os,op,0);
+}
+
 void ogg_packet_clear(ogg_packet *op) {
   free(op->packet);
   memset(op, 0, sizeof(ogg_packet));
@@ -1174,7 +1186,7 @@
 
         {
           ogg_page og_de;
-	  ogg_packet op_de;
+	  ogg_packet op_de,op_de2;
           char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
           memcpy(buf,og.header,og.header_len);
           memcpy(buf+og.header_len,og.body,og.body_len);
@@ -1191,8 +1203,17 @@
             ogg_stream_pagein(&os_de,&og_de);
 
             /* packets out? */
-	    while(ogg_stream_packetout(&os_de,&op_de)>0){
+	    while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
+	      ogg_stream_packetpeek(&os_de,NULL);
+	      ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
               
+	      /* verify peek and out match */
+	      if(memcmp(&op_de,&op_de2,sizeof(ogg_packet))){
+		fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
+			depacket);
+		exit(1);
+	      }
+
               /* verify the packet! */
               /* check data */
               if(memcmp(data+depacket,op_de.packet,op_de.bytes)){

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list