From 78bc557c6d2c10f0e8052e84f1cea19b2ea9dc3f Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 8 Feb 2007 22:22:43 +0000 Subject: Add Andrew Donkin's iovec patch to libogg 1. Applied as-is after review. git-svn-id: http://svn.xiph.org/trunk/ogg@12446 0101bb08-14d6-0310-b084-bc0e0c8e3800 --- src/framing.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/framing.c b/src/framing.c index e2c6f48..1dbf061 100644 --- a/src/framing.c +++ b/src/framing.c @@ -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,8 +268,12 @@ void ogg_page_checksum_set(ogg_page *og){ } /* 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 @@ -284,7 +288,7 @@ int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){ } /* 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 @@ int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){ 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;ilacing_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 @@ int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){ /* 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 @@ long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){ 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. -- cgit v1.2.1