[xiph-cvs] cvs commit: ogg/src buffer.c ogginternal.h stream.c sync.c

Monty xiphmont at xiph.org
Fri Mar 28 14:37:16 PST 2003



xiphmont    03/03/28 17:37:16

  Modified:    include/ogg2 Tag: libogg2-zerocopy ogg.h
               src      Tag: libogg2-zerocopy buffer.c ogginternal.h
                        stream.c sync.c
  Log:
  Enforce some additional API return value consistency upon call failure.

Revision  Changes    Path
No                   revision

<p>No                   revision

<p>1.1.2.4   +4 -2      ogg/include/ogg2/Attic/ogg.h

Index: ogg.h
===================================================================
RCS file: /usr/local/cvsroot/ogg/include/ogg2/Attic/ogg.h,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- ogg.h	26 Mar 2003 23:49:40 -0000	1.1.2.3
+++ ogg.h	28 Mar 2003 22:37:16 -0000	1.1.2.4
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: toplevel libogg include
- last mod: $Id: ogg.h,v 1.1.2.3 2003/03/26 23:49:40 xiphmont Exp $
+ last mod: $Id: ogg.h,v 1.1.2.4 2003/03/28 22:37:16 xiphmont Exp $
 
  ********************************************************************/
 #ifndef _OGG_H
@@ -39,7 +39,7 @@
 
 typedef struct {
   ogg_reference *packet;
-
+  long           bytes;
   long           b_o_s;
   long           e_o_s;
   ogg_int64_t    granulepos;
@@ -52,7 +52,9 @@
 
 typedef struct {
   ogg_reference *header;
+  int            header_len;
   ogg_reference *body;
+  int            body_len;
 } ogg_page;
 
 /* Ogg BITSTREAM PRIMITIVES: bitstream ************************/

<p><p>No                   revision

<p>No                   revision

<p>1.1.2.14  +31 -2     ogg/src/Attic/buffer.c

Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/buffer.c,v
retrieving revision 1.1.2.13
retrieving revision 1.1.2.14
diff -u -r1.1.2.13 -r1.1.2.14
--- buffer.c	27 Mar 2003 21:38:16 -0000	1.1.2.13
+++ buffer.c	28 Mar 2003 22:37:16 -0000	1.1.2.14
@@ -11,7 +11,7 @@
  ********************************************************************
 
   function: centralized fragment buffer management
-  last mod: $Id: buffer.c,v 1.1.2.13 2003/03/27 21:38:16 xiphmont Exp $
+  last mod: $Id: buffer.c,v 1.1.2.14 2003/03/28 22:37:16 xiphmont Exp $
 
  ********************************************************************/
 
@@ -169,7 +169,7 @@
    of range, NULL is returned; if the desired segment is simply zero
    length, a zero length ref is returned.  Partial range overlap
    returns the overlap of the ranges */
-ogg_reference *ogg_buffer_dup(ogg_reference *or,long begin,long length){
+ogg_reference *ogg_buffer_sub(ogg_reference *or,long begin,long length){
   ogg_reference *ret=0,*head=0;
 
   /* walk past any preceeding fragments we don't want */
@@ -209,6 +209,35 @@
     
     begin=0;
     length-=head->length;
+    or=or->next;
+  }
+
+  ogg_buffer_mark(ret);
+  return ret;
+}
+
+ogg_reference *ogg_buffer_dup(ogg_reference *or){
+  ogg_reference *ret=0,*head=0;
+
+  /* duplicate the reference chain; increment refcounts */
+  while(or){
+    ogg_reference *temp=_fetch_ref(or->buffer->ptr.owner);
+    if(head)
+      head->next=temp;
+    else
+      ret=temp;
+    head=temp;
+
+#ifdef OGGBUFFER_DEBUG
+    if(or->used==0){
+      fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+      exit(1);
+    }
+#endif
+
+    head->buffer=or->buffer;
+    head->begin=or->begin;
+    head->length=or->length;
     or=or->next;
   }
 

<p><p>1.1.2.14  +3 -2      ogg/src/Attic/ogginternal.h

Index: ogginternal.h
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/ogginternal.h,v
retrieving revision 1.1.2.13
retrieving revision 1.1.2.14
diff -u -r1.1.2.13 -r1.1.2.14
--- ogginternal.h	27 Mar 2003 21:38:16 -0000	1.1.2.13
+++ ogginternal.h	28 Mar 2003 22:37:16 -0000	1.1.2.14
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: internal/hidden data representation structures
- last mod: $Id: ogginternal.h,v 1.1.2.13 2003/03/27 21:38:16 xiphmont Exp $
+ last mod: $Id: ogginternal.h,v 1.1.2.14 2003/03/28 22:37:16 xiphmont Exp $
 
  ********************************************************************/
 
@@ -137,7 +137,8 @@
 extern void              ogg_buffer_destroy(ogg_buffer_state *bs);
 extern ogg_reference    *ogg_buffer_alloc(ogg_buffer_state *bs,long bytes);
 extern void              ogg_buffer_realloc(ogg_reference *or,long bytes);
-extern ogg_reference    *ogg_buffer_dup(ogg_reference *or,long begin,long length);
+extern ogg_reference    *ogg_buffer_sub(ogg_reference *or,long begin,long length);
+extern ogg_reference    *ogg_buffer_dup(ogg_reference *or);
 extern ogg_reference    *ogg_buffer_extend(ogg_reference *or,long bytes);
 extern void              ogg_buffer_mark(ogg_reference *or);
 extern void              ogg_buffer_release(ogg_reference *or);

<p><p>1.1.2.11  +41 -19    ogg/src/Attic/stream.c

Index: stream.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/stream.c,v
retrieving revision 1.1.2.10
retrieving revision 1.1.2.11
diff -u -r1.1.2.10 -r1.1.2.11
--- stream.c	28 Mar 2003 04:51:33 -0000	1.1.2.10
+++ stream.c	28 Mar 2003 22:37:16 -0000	1.1.2.11
@@ -12,7 +12,7 @@
 
  function: code raw packets into framed Ogg logical stream and
            decode Ogg logical streams back into raw packets
- last mod: $Id: stream.c,v 1.1.2.10 2003/03/28 04:51:33 xiphmont Exp $
+ last mod: $Id: stream.c,v 1.1.2.11 2003/03/28 22:37:16 xiphmont Exp $
 
  ********************************************************************/
 
@@ -54,7 +54,7 @@
   return OGG_SUCCESS;
 } 
 
-/* finish building a header then flush the current packet header and
+/* finish building a header then flush the current page header and
    body to the output buffer */
 static void _packet_flush(ogg_stream_state *os,int nextcomplete){
   oggbyte_buffer *obb=&os->header_build;
@@ -123,8 +123,11 @@
   int  remainder=bytes%255;
   int  i;
 
-  if(os->e_o_s)return OGG_EEOS;
-  
+  if(os->e_o_s){
+    ogg_packet_release(op);
+    return OGG_EEOS;
+  }
+
   if(!os->lacing_fill)
     oggbyte_init(&os->header_build,0,os->bufferpool);
 
@@ -157,7 +160,8 @@
      os->body_fill>=os->watermark ||
      !os->b_o_s ||
      os->lacing_fill==255)_packet_flush(os,0);
-  
+
+  memset(op,0,sizeof(*op));
   return OGG_SUCCESS;
 }
 
@@ -169,7 +173,10 @@
   int i;
 
   /* is there a page waiting to come back? */
-  if(!os->header_tail) return 0;
+  if(!os->header_tail){
+    if(og)memset(og,0,sizeof(*og));
+    return 0;
+  }
 
   /* get header and body sizes */
   oggbyte_init(&ob,os->header_tail,0);
@@ -180,7 +187,9 @@
   /* split page references out of the fifos */
   if(og){
     og->header=ogg_buffer_split(&os->header_tail,&os->header_head,header_bytes);
+    og->header_len=header_bytes;
     og->body=ogg_buffer_split(&os->body_tail,&os->body_head,body_bytes);
+    og->body_len=body_bytes;
 
     /* checksum */
     ogg_page_checksum_set(og);
@@ -355,8 +364,14 @@
   int version=ogg_page_version(og);
 
   /* check the serial number */
-  if(serialno!=os->serialno)return OGG_ESERIAL;
-  if(version>0)return OGG_EVERSION ;
+  if(serialno!=os->serialno){
+    ogg_page_release(og);
+    return OGG_ESERIAL;
+  }
+  if(version>0){
+    ogg_page_release(og);
+    return OGG_EVERSION;
+  }
 
   /* add to fifos */
   if(!os->body_tail){
@@ -373,6 +388,7 @@
     os->header_head=ogg_buffer_cat(os->header_head,og->header);
   }
 
+  memset(og,0,sizeof(*og));
   return OGG_SUCCESS;
 }
 
@@ -420,6 +436,7 @@
       os->holeflag=1;
     if(temp==2){
       os->packetno++;
+      if(op)memset(op,0,sizeof(*op));
       return OGG_HOLE;
     }
   }
@@ -431,11 +448,15 @@
       os->spanflag=1;
     if(temp==2){
       os->packetno++;
+      if(op)memset(op,0,sizeof(*op));
       return OGG_SPAN;
     }
   }
 
-  if(!(os->body_fill&FINFLAG))return 0;
+  if(!(os->body_fill&FINFLAG)){
+    if(op)memset(op,0,sizeof(*op));
+    return 0;
+  }
   if(!op && !adv)return 1; /* just using peek as an inexpensive way
                                to ask if there's a whole packet
                                waiting */
@@ -459,6 +480,7 @@
     /* split the body contents off */
     if(op){
       op->packet=ogg_buffer_split(&os->body_tail,&os->body_head,os->body_fill&FINMASK);
+      op->bytes=os->body_fill&FINMASK;
     }else{
       os->body_tail=ogg_buffer_pretruncate(os->body_tail,os->body_fill&FINMASK);
       if(os->body_tail==0)os->body_head=0;
@@ -468,7 +490,10 @@
     os->body_fill=os->body_fill_next;
     _next_lace(&ob,os);
   }else{
-    if(op)op->packet=ogg_buffer_dup(os->body_tail,0,os->body_fill&FINMASK);
+    if(op){
+      op->packet=ogg_buffer_sub(os->body_tail,0,os->body_fill&FINMASK);
+      op->bytes=os->body_fill&FINMASK;
+    }
   }
   
   if(adv){
@@ -1010,12 +1035,6 @@
   ogg_stream_reset(os_de);
   ogg_sync_reset(oy);
 
-
-  ogg_buffer_outstanding(os_en->bufferpool);
-  ogg_buffer_outstanding(os_de->bufferpool);
-  ogg_buffer_outstanding(oy->bufferpool);
-  ogg_buffer_outstanding(bs);
-
 }
 
 int main(void){
@@ -1168,9 +1187,12 @@
         exit(1);
       }
     }
-    if(ogg_stream_pageout(os_en,&og[0])>0){
-      fprintf(stderr,"Too many pages output building sync tests!\n");
-      exit(1);
+    {
+      ogg_page temp;
+      if(ogg_stream_pageout(os_en,&temp)>0){
+	fprintf(stderr,"Too many pages output building sync tests!\n");
+	exit(1);
+      }
     }
     
     /* Test lost pages on pagein/packetout: no rollback */

<p><p>1.1.2.11  +21 -5     ogg/src/Attic/sync.c

Index: sync.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/sync.c,v
retrieving revision 1.1.2.10
retrieving revision 1.1.2.11
diff -u -r1.1.2.10 -r1.1.2.11
--- sync.c	27 Mar 2003 21:38:16 -0000	1.1.2.10
+++ sync.c	28 Mar 2003 22:37:16 -0000	1.1.2.11
@@ -12,7 +12,7 @@
 
  function: decode stream sync and memory management foundation code;
            takes in raw data, spits out packets
- last mod: $Id: sync.c,v 1.1.2.10 2003/03/27 21:38:16 xiphmont Exp $
+ last mod: $Id: sync.c,v 1.1.2.11 2003/03/28 22:37:16 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
@@ -27,10 +27,6 @@
 
 /* A complete description of Ogg framing exists in docs/framing.html */
 
-/* Below we have stream buffer and memory management which is
-   handled by physical stream and centralized in the ogg_sync_state
-   structure. */
-
 int ogg_page_version(ogg_page *og){
   oggbyte_buffer ob;
   oggbyte_init(&ob,og->header,0);
@@ -336,7 +332,9 @@
   if(og){
     /* set up page output */
     og->header=ogg_buffer_split(&oy->fifo_tail,&oy->fifo_head,oy->headerbytes);
+    og->header_len=oy->headerbytes;
     og->body=ogg_buffer_split(&oy->fifo_tail,&oy->fifo_head,oy->bodybytes);
+    og->body_len=oy->bodybytes;
   }else{
     /* simply advance */
     oy->fifo_tail=
@@ -489,6 +487,7 @@
   else
     oy->fifo_head=ogg_buffer_walk(oy->fifo_tail=og->header);
   oy->fifo_head=ogg_buffer_cat(oy->fifo_head,og->body);
+  memset(og,0,sizeof(*og));
   return OGG_SUCCESS;
 }
 
@@ -517,4 +516,21 @@
   if(!oy->fifo_tail)oy->fifo_head=0;
 
   return OGG_SUCCESS;
+}
+
+void ogg_page_dup(ogg_page *dup,ogg_page *orig){
+  dup->header_len=orig->header_len;
+  dup->body_len=orig->body_len;
+  dup->header=ogg_buffer_dup(orig->header);
+  dup->body=ogg_buffer_dup(orig->body);
+}
+
+void ogg_packet_dup(ogg_packet *dup,ogg_packet *orig){
+  dup->bytes=orig->bytes;
+  dup->b_o_s=orig->b_o_s;
+  dup->e_o_s=orig->e_o_s;
+  dup->granulepos=orig->granulepos;
+  dup->packetno=orig->packetno;
+
+  dup->packet=ogg_buffer_dup(orig->packet);
 }

<p><p>--- >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