[xiph-commits] r12446 - in trunk/ogg: include/ogg src

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Thu Feb 8 14:22:45 PST 2007


Author: xiphmont
Date: 2007-02-08 14:22:43 -0800 (Thu, 08 Feb 2007)
New Revision: 12446

Modified:
   trunk/ogg/include/ogg/ogg.h
   trunk/ogg/src/framing.c
Log:
Add Andrew Donkin's iovec patch to libogg 1.  Applied as-is after 
review.



Modified: trunk/ogg/include/ogg/ogg.h
===================================================================
--- trunk/ogg/include/ogg/ogg.h	2007-02-08 21:02:35 UTC (rev 12445)
+++ trunk/ogg/include/ogg/ogg.h	2007-02-08 22:22:43 UTC (rev 12446)
@@ -5,13 +5,13 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
 
  function: toplevel libogg include
- last mod: $Id: ogg.h,v 1.19 2002/09/15 23:48:02 xiphmont Exp $
+ last mod: $Id$
 
  ********************************************************************/
 #ifndef _OGG_H
@@ -24,6 +24,11 @@
 #include <ogg/os_types.h>
 
 typedef struct {
+  void *iov_base; 
+  size_t iov_len;
+} ogg_iovec_t;
+
+typedef struct {
   long endbyte;
   int  endbit;
 
@@ -148,6 +153,8 @@
 /* Ogg BITSTREAM PRIMITIVES: encoding **************************/
 
 extern int      ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
+extern int      ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov,
+				   int count, long e_o_s, ogg_int64_t granulepos);
 extern int      ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
 extern int      ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
 

Modified: trunk/ogg/src/framing.c
===================================================================
--- trunk/ogg/src/framing.c	2007-02-08 21:02:35 UTC (rev 12445)
+++ trunk/ogg/src/framing.c	2007-02-08 22:22:43 UTC (rev 12446)
@@ -5,7 +5,7 @@
  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
  * by the Xiph.Org Foundation http://www.xiph.org/                  *
  *                                                                  *
  ********************************************************************
@@ -268,9 +268,13 @@
 }
 
 /* submit data to the internal buffer of the framing engine */
-int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
-  int lacing_vals=op->bytes/255+1,i;
+int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov, int count,
+                       long e_o_s, ogg_int64_t granulepos){
 
+  int bytes = 0, lacing_vals, i;
+  for (i = 0; i < count; ++i) bytes += (int)iov[i].iov_len;
+  lacing_vals=bytes/255+1;
+
   if(os->body_returned){
     /* advance packet data according to the body_returned pointer. We
        had to keep it around to return a pointer into the buffer last
@@ -284,7 +288,7 @@
   }
  
   /* make sure we have the buffer storage */
-  _os_body_expand(os,op->bytes);
+  _os_body_expand(os,bytes);
   _os_lacing_expand(os,lacing_vals);
 
   /* Copy in the submitted packet.  Yes, the copy is a waste; this is
@@ -292,16 +296,18 @@
      will actually be fairly easy to eliminate the extra copy in the
      future */
 
-  memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
-  os->body_fill+=op->bytes;
+  for (i = 0; i < count; ++i) {
+    memcpy(os->body_data+os->body_fill, iov[i].iov_base, iov[i].iov_len);
+    os->body_fill += (int)iov[i].iov_len;
+  }
 
   /* 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->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
-  os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
+  os->lacing_vals[os->lacing_fill+i]=bytes%255;
+  os->granulepos=os->granule_vals[os->lacing_fill+i]=granulepos;
 
   /* flag the first segment as the beginning of the packet */
   os->lacing_vals[os->lacing_fill]|= 0x100;
@@ -311,11 +317,18 @@
   /* for the sake of completeness */
   os->packetno++;
 
-  if(op->e_o_s)os->e_o_s=1;
+  if(e_o_s)os->e_o_s=1;
 
   return(0);
 }
 
+int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
+  ogg_iovec_t iov;
+  iov.iov_base = op->packet;
+  iov.iov_len = op->bytes;
+  return ogg_stream_iovecin(os, &iov, 1, op->e_o_s, op->granulepos);
+}
+
 /* This will flush remaining packets into a page (returning nonzero),
    even if there is not enough data to trigger a flush normally
    (undersized page). If there are no packets or partial packets to
@@ -624,8 +637,8 @@
   if(!next)
     next=oy->data+oy->fill;
 
-  oy->returned=next-oy->data;
-  return(-(next-page));
+  oy->returned=(int)(next-oy->data);
+  return((long)-(next-page));
 }
 
 /* sync the stream and get a page.  Keep trying until we find a page.



More information about the commits mailing list