[xiph-cvs] cvs commit: ogg/src buffer.c bytewise.c ogginternal.h stream.c sync.c
Monty
xiphmont at xiph.org
Wed Mar 26 15:49:26 PST 2003
xiphmont 03/03/26 18:49:26
Modified: src Tag: libogg2-zerocopy buffer.c bytewise.c
ogginternal.h stream.c sync.c
Log:
Fixing according to unit tests slowly but surely
Revision Changes Path
No revision
<p>No revision
<p>1.1.2.10 +100 -6 ogg/src/Attic/buffer.c
Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/buffer.c,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -u -r1.1.2.9 -r1.1.2.10
--- buffer.c 23 Mar 2003 23:40:58 -0000 1.1.2.9
+++ buffer.c 26 Mar 2003 23:49:26 -0000 1.1.2.10
@@ -11,7 +11,7 @@
********************************************************************
function: centralized fragment buffer management
- last mod: $Id: buffer.c,v 1.1.2.9 2003/03/23 23:40:58 xiphmont Exp $
+ last mod: $Id: buffer.c,v 1.1.2.10 2003/03/26 23:49:26 xiphmont Exp $
********************************************************************/
@@ -98,7 +98,8 @@
/* allocate a new buffer */
ogg_mutex_unlock(&bs->mutex);
ob=_ogg_malloc(sizeof(*ob));
- ob->data=_ogg_malloc(bytes);
+ ob->data=_ogg_malloc(bytes<OGGPACK_MINCHUNKSIZE?
+ OGGPACK_MINCHUNKSIZE:bytes);
ob->size=bytes;
}
@@ -126,7 +127,9 @@
or->begin=0;
or->length=0;
or->next=0;
-
+#ifdef OGGBUFFER_DEBUG
+ or->used=1;
+#endif
return or;
}
@@ -160,6 +163,12 @@
/* walk past any preceeding fragments we don't want */
while(or && begin>=or->length){
+#ifdef OGGBUFFER_DEBUG
+ if(or->used==0){
+ fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+ exit(1);
+ }
+#endif
begin-=or->length;
or=or->next;
}
@@ -171,6 +180,13 @@
head=temp;
if(!ret)ret=head;
+#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+begin;
@@ -192,8 +208,14 @@
pools */
#ifdef OGGBUFFER_DEBUG
- if(or->buffer->refcount==0)
+ if(or->buffer->refcount==0){
fprintf(stderr,"WARNING: marking buffer fragment with refcount of zero!\n");
+ exit(1);
+ }
+ if(or->used==0){
+ fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+ exit(1);
+ }
#endif
or->buffer->refcount++;
@@ -211,10 +233,18 @@
b) the fragment that needs split somewhere in the middle */
while(or && pos>or->length){
+#ifdef OGGBUFFER_DEBUG
+ if(or->used==0){
+ fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+ exit(1);
+ }
+#endif
pos-=or->length;
or=or->next;
}
+ if(!or)return NULL;
+
if(pos>=or->length){
/* exact split, or off the end */
if(or->next){
@@ -257,8 +287,20 @@
/* add a new fragment link to the end of a chain; return ptr to the new link */
ogg_reference *ogg_buffer_extend(ogg_reference *or,long bytes){
if(or){
+#ifdef OGGBUFFER_DEBUG
+ if(or->used==0){
+ fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+ exit(1);
+ }
+#endif
while(or->next){
or=or->next;
+#ifdef OGGBUFFER_DEBUG
+ if(or->used==0){
+ fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+ exit(1);
+ }
+#endif
}
or->next=ogg_buffer_alloc(or->buffer->ptr.owner,bytes);
return(or->next);
@@ -280,8 +322,15 @@
ogg_mutex_lock(&bs->mutex);
#ifdef OGGBUFFER_DEBUG
- if(ob->refcount==0)
+ if(ob->refcount==0){
fprintf(stderr,"WARNING: releasing buffer fragment with refcount of zero!\n");
+ exit(1);
+ }
+ if(or->used==0){
+ fprintf(stderr,"WARNING: releasing previously released reference!\n");
+ exit(1);
+ }
+ or->used=0;
#endif
ob->refcount--;
@@ -318,6 +367,12 @@
or=next;
}
if (or) {
+#ifdef OGGBUFFER_DEBUG
+ if(or->used==0){
+ fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+ exit(1);
+ }
+#endif
or->begin+=pos;
or->length-=pos;
}
@@ -327,6 +382,12 @@
void ogg_buffer_posttruncate(ogg_reference *or,long pos){
/* walk to the point where we want to begin truncate */
while(or && pos>or->length){
+#ifdef OGGBUFFER_DEBUG
+ if(or->used==0){
+ fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+ exit(1);
+ }
+#endif
pos-=or->length;
or=or->next;
}
@@ -340,7 +401,22 @@
}
ogg_reference *ogg_buffer_walk(ogg_reference *or){
- while(or->next)or=or->next;
+ if(!or)return NULL;
+ while(or->next){
+#ifdef OGGBUFFER_DEBUG
+ if(or->used==0){
+ fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+ exit(1);
+ }
+#endif
+ or=or->next;
+ }
+#ifdef OGGBUFFER_DEBUG
+ if(or->used==0){
+ fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+ exit(1);
+ }
+#endif
return(or);
}
@@ -348,8 +424,20 @@
be valid pointers, with *tail at the tail and *head at the head */
ogg_reference *ogg_buffer_cat(ogg_reference *tail, ogg_reference *head){
while(tail->next){
+#ifdef OGGBUFFER_DEBUG
+ if(tail->used==0){
+ fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+ exit(1);
+ }
+#endif
tail=tail->next;
}
+#ifdef OGGBUFFER_DEBUG
+ if(tail->used==0){
+ fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+ exit(1);
+ }
+#endif
tail->next=head;
return ogg_buffer_walk(head);
}
@@ -357,6 +445,12 @@
long ogg_buffer_length(ogg_reference *or){
int count=0;
while(or){
+#ifdef OGGBUFFER_DEBUG
+ if(or->used==0){
+ fprintf(stderr,"\nERROR: Using reference marked as usused.\n");
+ exit(1);
+ }
+#endif
count+=or->length;
or=or->next;
}
<p><p>1.1.2.5 +2 -2 ogg/src/Attic/bytewise.c
Index: bytewise.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/bytewise.c,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- bytewise.c 23 Mar 2003 23:40:58 -0000 1.1.2.4
+++ bytewise.c 26 Mar 2003 23:49:26 -0000 1.1.2.5
@@ -11,7 +11,7 @@
********************************************************************
function: byte-aligned access; array-like abstraction over buffers
- last mod: $Id: bytewise.c,v 1.1.2.4 2003/03/23 23:40:58 xiphmont Exp $
+ last mod: $Id: bytewise.c,v 1.1.2.5 2003/03/26 23:49:26 xiphmont Exp $
********************************************************************/
@@ -94,7 +94,7 @@
}
ogg_reference *oggbyte_return_and_reset(oggbyte_buffer *b){
- if(b->external){
+ if(!b->external){
ogg_reference *ret=b->baseref;
oggbyte_init(b,0,b->owner);
return(ret);
<p><p>1.1.2.11 +7 -7 ogg/src/Attic/ogginternal.h
Index: ogginternal.h
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/ogginternal.h,v
retrieving revision 1.1.2.10
retrieving revision 1.1.2.11
diff -u -r1.1.2.10 -r1.1.2.11
--- ogginternal.h 26 Mar 2003 07:35:20 -0000 1.1.2.10
+++ ogginternal.h 26 Mar 2003 23:49:26 -0000 1.1.2.11
@@ -11,7 +11,7 @@
********************************************************************
function: internal/hidden data representation structures
- last mod: $Id: ogginternal.h,v 1.1.2.10 2003/03/26 07:35:20 xiphmont Exp $
+ last mod: $Id: ogginternal.h,v 1.1.2.11 2003/03/26 23:49:26 xiphmont Exp $
********************************************************************/
@@ -45,7 +45,11 @@
struct ogg_buffer *buffer;
long begin;
long length;
+
struct ogg_reference *next;
+#ifdef OGGBUFFER_DEBUG
+ int used;
+#endif
};
struct oggpack_buffer {
@@ -81,10 +85,7 @@
/* stream buffers */
ogg_reference *fifo_head;
ogg_reference *fifo_tail;
-
long fifo_fill;
- ogg_reference *returned_header;
- ogg_reference *returned_body;
/* stream sync management */
int unsynced;
@@ -102,9 +103,6 @@
ogg_reference *body_head;
ogg_reference *body_tail;
- ogg_reference *returned;
- ogg_reference *returned_header;
-
int e_o_s; /* set when we have buffered the last
packet in the logical bitstream */
int b_o_s; /* set after we've written the initial page
@@ -167,8 +165,10 @@
#ifdef _V_SELFTEST
#define OGGPACK_CHUNKSIZE 3
+#define OGGPACK_MINCHUNKSIZE 1
#else
#define OGGPACK_CHUNKSIZE 128
+#define OGGPACK_MINCHUNKSIZE 16
#endif
#endif
<p><p>1.1.2.6 +89 -88 ogg/src/Attic/stream.c
Index: stream.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/stream.c,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- stream.c 26 Mar 2003 09:41:46 -0000 1.1.2.5
+++ stream.c 26 Mar 2003 23:49:26 -0000 1.1.2.6
@@ -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.5 2003/03/26 09:41:46 xiphmont Exp $
+ last mod: $Id: stream.c,v 1.1.2.6 2003/03/26 23:49:26 xiphmont Exp $
********************************************************************/
@@ -40,18 +40,10 @@
return OGG_EINVAL;
}
-static void _returned_release(ogg_stream_state *os){
- ogg_buffer_release(os->returned);
- os->returned=0;
- ogg_buffer_release(os->returned_header);
- os->returned_header=0;
-}
-
/* _clear does not free os, only the non-flat storage within */
-void ogg_stream_destroy(ogg_stream_state *os){
+int ogg_stream_destroy(ogg_stream_state *os){
if(os){
- _returned_release(os);
ogg_buffer_release(os->header_tail);
ogg_buffer_release(os->body_tail);
oggbyte_clear(&os->header_build);
@@ -59,7 +51,7 @@
memset(os,0,sizeof(*os));
}
- return;
+ return OGG_SUCCESS;
}
/* finish building a header then flush the current packet header and
@@ -84,10 +76,13 @@
if(os->e_o_s)ctemp|=0x04; /* last page flag? */
oggbyte_set1(obb,ctemp,5);
+ /* 64 bits of PCM position */
+ if(!os->b_o_s)
+ oggbyte_set8(obb,0,6);
+ else
+ oggbyte_set8(obb,os->granulepos,6);
os->b_o_s=1;
- /* 64 bits of PCM position */
- oggbyte_set8(obb,os->granulepos,6);
/* 32 bits of stream serial number */
oggbyte_set4(obb,os->serialno,14);
@@ -126,7 +121,7 @@
int remainder=bytes%255;
int i;
- if(op->e_o_s)return OGG_EEOS;
+ if(os->e_o_s)return OGG_EEOS;
if(!os->lacing_fill)
oggbyte_init(&os->header_build,0,os->bufferpool);
@@ -138,12 +133,12 @@
os->body_tail=os->body_head=op->packet;
/* add lacing vals, but finish/flush packet first if we hit a
- watermark */
+ (watermark && not initial page) */
for(i=0;i<lacing_vals-1;i++){ /* handle the 255s first */
os->body_fill+=255;
oggbyte_set1(&os->header_build,255,27+os->lacing_fill++);
- if(os->body_fill>=os->watermark)_packet_flush(os,1);
+ if(os->body_fill>=os->watermark && os->b_o_s)_packet_flush(os,1);
if(os->lacing_fill==255)_packet_flush(os,1);
}
@@ -164,19 +159,13 @@
return OGG_SUCCESS;
}
-/* This constructs pages from buffered packet segments. The pointers
- returned are to static buffers; do not free. The returned buffers
- are good only until the next call (using the same ogg_stream_state) */
-
+/* This constructs pages from buffered packet segments. */
int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
oggbyte_buffer ob;
long header_bytes;
long body_bytes=0;
int i;
- /* clear out previously returned pages if any */
- _returned_release(os);
-
/* is there a page waiting to come back? */
if(!os->header_tail) return 0;
@@ -188,8 +177,8 @@
/* split page references out of the fifos */
if(og){
- os->returned_header=os->header_tail;
- os->returned=os->body_tail;
+ og->header=os->header_tail;
+ og->body=os->body_tail;
os->header_tail=ogg_buffer_split(os->header_tail,header_bytes);
os->body_tail=ogg_buffer_split(os->body_tail,body_bytes);
@@ -268,22 +257,24 @@
declared span. Naturally, this error should also not be
mistriggered due to seek or reset, or reported redundantly. */
-static int _span_queued_page(ogg_stream_state *os){
+static void _span_queued_page(ogg_stream_state *os){
while( !(os->body_fill&FINFLAG) ){
- if(!os->header_tail) return 0;
+ if(!os->header_tail)break;
/* first flush out preceeding page header (if any). Body is
flushed as it's consumed, so that's not done here. */
-
+
+ if(os->lacing_fill>=0)
+ os->header_tail=ogg_buffer_pretruncate(os->header_tail,
+ os->lacing_fill+27);
os->lacing_fill=0;
os->laceptr=0;
os->clearflag=0;
- os->header_tail=ogg_buffer_pretruncate(os->header_tail,
- os->lacing_fill+27);
+
if(!os->header_tail){
os->header_head=0;
- return 0;
+ break;
}else{
/* process/prepare next page, if any */
@@ -347,8 +338,6 @@
}
}
-
- return 1;
}
/* add the incoming page to the stream state; we decompose the page
@@ -364,8 +353,6 @@
if(version>0)return OGG_EVERSION ;
/* add to fifos */
- ogg_buffer_mark(og->header);
- ogg_buffer_mark(og->body);
if(!os->body_tail){
os->body_tail=og->body;
os->body_head=ogg_buffer_walk(og->body);
@@ -375,6 +362,7 @@
if(!os->header_tail){
os->header_tail=og->header;
os->header_head=ogg_buffer_walk(og->header);
+ os->lacing_fill=-27;
}else{
os->header_head=ogg_buffer_cat(os->header_head,og->header);
}
@@ -384,7 +372,6 @@
int ogg_stream_reset(ogg_stream_state *os){
- _returned_release(os);
ogg_buffer_release(os->header_tail);
ogg_buffer_release(os->body_tail);
os->header_head=0;
@@ -416,8 +403,9 @@
}
static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
- _returned_release(os);
-
+
+ _span_queued_page(os);
+
if(os->holeflag){
int temp=os->holeflag;
if(os->clearflag)
@@ -441,18 +429,21 @@
}
}
- if(!_span_queued_page(os))return 0;
+ if(!(os->body_fill&FINFLAG))return 0;
if(!op && !adv)return 1; /* just using peek as an inexpensive way
to ask if there's a whole packet
waiting */
if(op){
op->b_o_s=os->b_o_s;
- os->b_o_s=0;
+ if(os->e_o_s && os->body_fill_next==0)
+ op->e_o_s=os->e_o_s;
+ else
+ op->e_o_s=0;
if( (os->body_fill&FINFLAG) && !(os->body_fill_next&FINFLAG) )
op->granulepos=os->granulepos;
else
op->granulepos=-1;
-
+ op->packetno=os->packetno;
}
if(adv){
@@ -461,7 +452,7 @@
/* split the body contents off */
if(op){
- os->returned=os->body_tail;
+ op->packet=os->body_tail;
os->body_tail=ogg_buffer_split(os->body_tail,os->body_fill&FINMASK);
}else{
os->body_tail=ogg_buffer_pretruncate(os->body_tail,os->body_fill&FINMASK);
@@ -472,20 +463,14 @@
os->body_fill=os->body_fill_next;
_next_lace(&ob,os);
}else{
- os->returned=ogg_buffer_dup(os->body_tail,0,os->body_fill&FINMASK);
+ if(op)op->packet=ogg_buffer_dup(os->body_tail,0,os->body_fill&FINMASK);
}
- if(op){
- if(os->e_o_s && os->body_fill==0)
- op->e_o_s=os->e_o_s;
- else
- op->e_o_s=0;
- op->packet=os->returned;
- op->packetno=os->packetno;
+ if(adv){
+ os->packetno++;
+ os->b_o_s=0;
}
- if(adv) os->packetno++;
-
return 1;
}
@@ -497,12 +482,20 @@
return _packetout(os,op,0);
}
-void ogg_packet_clear(ogg_packet *op) {
+int ogg_packet_release(ogg_packet *op) {
ogg_buffer_release(op->packet);
memset(op, 0, sizeof(*op));
+ return OGG_SUCCESS;
}
-#ifdef _V_SELFTEST
+int ogg_page_release(ogg_page *og) {
+ ogg_buffer_release(og->header);
+ ogg_buffer_release(og->body);
+ memset(og, 0, sizeof(*og));
+ return OGG_SUCCESS;
+}
+
+#ifdef _V_SELFTEST2
#include <stdio.h>
ogg_stream_state *os_en, *os_de;
@@ -815,6 +808,16 @@
}
}
+int bufcmp(void *data,ogg_reference *or){
+ while(or){
+ int ret=memcmp(data,or->buffer->data+or->begin,or->length);
+ if(ret)return ret;
+ data+=or->length;
+ or=or->next;
+ }
+ return 0;
+}
+
void test_pack(const int *pl, const int **headers){
unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
long inptr=0;
@@ -845,6 +848,7 @@
for(j=0;j<len;j++)data[inptr+j]=i+j;
memcpy(op.packet->buffer->data,data+inptr,len);
+ op.packet->length=len;
inptr+=j;
/* submit the test packet */
@@ -875,7 +879,7 @@
ogg_page og_de;
ogg_packet op_de,op_de2;
int blen=ogg_buffer_length(og.header)+ogg_buffer_length(og.body);
- char *buf=ogg_sync_buffer(oy,blen);
+ char *buf=ogg_sync_bufferin(oy,blen);
bufcpy(buf,og.header);
bufcpy(buf+ogg_buffer_length(og.header),og.body);
ogg_sync_wrote(oy,blen);
@@ -897,14 +901,12 @@
/* verify the packets! */
/* check data */
- if(memcmp(data+depacket,op_de.packet,
- ogg_buffer_length(op_de.packet))){
+ if(bufcmp(data+depacket,op_de.packet)){
fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
depacket);
exit(1);
}
- if(memcmp(data+depacket,op_de2.packet,
- ogg_buffer_length(op_de2.packet))){
+ if(bufcmp(data+depacket,op_de2.packet)){
fprintf(stderr,"packet data mismatch in peek! pos=%ld\n",
depacket);
exit(1);
@@ -1118,6 +1120,7 @@
for(j=0;j<len;j++)data[inptr+j]=i+j;
memcpy(op.packet->buffer->data,data+inptr,len);
+ op.packet->length=len;
ogg_stream_packetin(os_en,&op);
inptr+=j;
@@ -1131,8 +1134,6 @@
fprintf(stderr,"Too few pages output building sync tests!\n");
exit(1);
}
- ogg_buffer_mark(og[i].header);
- ogg_buffer_mark(og[i].body);
}
/* Test lost pages on pagein/packetout: no rollback */
@@ -1145,10 +1146,10 @@
ogg_sync_reset(oy);
ogg_stream_reset(os_de);
for(i=0;i<5;i++){
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[i].header)),
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[i].header)),
og[i].header);
ogg_sync_wrote(oy,ogg_buffer_length(og[i].header));
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[i].body)),
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[i].body)),
og[i].body);
ogg_sync_wrote(oy,ogg_buffer_length(og[i].body));
}
@@ -1191,10 +1192,10 @@
ogg_sync_reset(oy);
ogg_stream_reset(os_de);
for(i=0;i<5;i++){
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[i].header)),
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[i].header)),
og[i].header);
ogg_sync_wrote(oy,ogg_buffer_length(og[i].header));
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[i].body)),
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[i].body)),
og[i].body);
ogg_sync_wrote(oy,ogg_buffer_length(og[i].body));
}
@@ -1235,31 +1236,31 @@
/* Test fractional page inputs: incomplete capture */
fprintf(stderr,"Testing sync on partial inputs... ");
ogg_sync_reset(oy);
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[1].header)),og[1].header);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].header)),og[1].header);
ogg_sync_wrote(oy,3);
if(ogg_sync_pageout(oy,&og_de)>0)error();
/* Test fractional page inputs: incomplete fixed header */
- bufcpy2(ogg_sync_buffer(oy,ogg_buffer_length(og[1].header)),og[1].header,3);
+ bufcpy2(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].header)),og[1].header,3);
ogg_sync_wrote(oy,20);
if(ogg_sync_pageout(oy,&og_de)>0)error();
/* Test fractional page inputs: incomplete header */
- bufcpy2(ogg_sync_buffer(oy,ogg_buffer_length(og[1].header)),og[1].header,33);
+ bufcpy2(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].header)),og[1].header,33);
ogg_sync_wrote(oy,5);
if(ogg_sync_pageout(oy,&og_de)>0)error();
/* Test fractional page inputs: incomplete body */
- bufcpy2(ogg_sync_buffer(oy,ogg_buffer_length(og[1].header)),og[1].header,28);
+ bufcpy2(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].header)),og[1].header,28);
ogg_sync_wrote(oy,ogg_buffer_length(og[1].header)-28);
if(ogg_sync_pageout(oy,&og_de)>0)error();
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[1].body)),og[1].body);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].body)),og[1].body);
ogg_sync_wrote(oy,1000);
if(ogg_sync_pageout(oy,&og_de)>0)error();
- bufcpy2(ogg_sync_buffer(oy,ogg_buffer_length(og[1].body)),og[1].body,1000);
+ bufcpy2(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].body)),og[1].body,1000);
ogg_sync_wrote(oy,ogg_buffer_length(og[1].body)-1000);
if(ogg_sync_pageout(oy,&og_de)<=0)error();
@@ -1272,21 +1273,21 @@
fprintf(stderr,"Testing sync on 1+partial inputs... ");
ogg_sync_reset(oy);
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[1].header)),og[1].header);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].header)),og[1].header);
ogg_sync_wrote(oy,ogg_buffer_length(og[1].header));
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[1].body)),og[1].body);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].body)),og[1].body);
ogg_sync_wrote(oy,ogg_buffer_length(og[1].body));
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[1].header)),og[1].header);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].header)),og[1].header);
ogg_sync_wrote(oy,20);
if(ogg_sync_pageout(oy,&og_de)<=0)error();
if(ogg_sync_pageout(oy,&og_de)>0)error();
- bufcpy2(ogg_sync_buffer(oy,ogg_buffer_length(og[1].header)),og[1].header,20);
+ bufcpy2(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].header)),og[1].header,20);
ogg_sync_wrote(oy,ogg_buffer_length(og[1].header)-20);
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[1].body)),og[1].body);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].body)),og[1].body);
ogg_sync_wrote(oy,ogg_buffer_length(og[1].body));
if(ogg_sync_pageout(oy,&og_de)<=0)error();
@@ -1301,26 +1302,26 @@
ogg_sync_reset(oy);
/* 'garbage' */
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[1].body)),og[1].body);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].body)),og[1].body);
ogg_sync_wrote(oy,ogg_buffer_length(og[1].body));
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[1].header)),og[1].header);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].header)),og[1].header);
ogg_sync_wrote(oy,ogg_buffer_length(og[1].header));
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[1].body)),og[1].body);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].body)),og[1].body);
ogg_sync_wrote(oy,ogg_buffer_length(og[1].body));
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[2].header)),og[2].header);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[2].header)),og[2].header);
ogg_sync_wrote(oy,20);
if(ogg_sync_pageout(oy,&og_de)>0)error();
if(ogg_sync_pageout(oy,&og_de)<=0)error();
if(ogg_sync_pageout(oy,&og_de)>0)error();
- bufcpy2(ogg_sync_buffer(oy,ogg_buffer_length(og[2].header)),og[2].header,20);
+ bufcpy2(ogg_sync_bufferin(oy,ogg_buffer_length(og[2].header)),og[2].header,20);
ogg_sync_wrote(oy,ogg_buffer_length(og[2].header)-20);
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[2].body)),og[2].body);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[2].body)),og[2].body);
ogg_sync_wrote(oy,ogg_buffer_length(og[2].body));
if(ogg_sync_pageout(oy,&og_de)<=0)error();
@@ -1333,27 +1334,27 @@
fprintf(stderr,"Testing recapture... ");
ogg_sync_reset(oy);
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[1].header)),og[1].header);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].header)),og[1].header);
ogg_sync_wrote(oy,ogg_buffer_length(og[1].header));
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[1].body)),og[1].body);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[1].body)),og[1].body);
ogg_sync_wrote(oy,ogg_buffer_length(og[1].body));
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[2].header)),og[2].header);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[2].header)),og[2].header);
ogg_sync_wrote(oy,ogg_buffer_length(og[2].header));
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[2].header)),og[2].header);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[2].header)),og[2].header);
ogg_sync_wrote(oy,ogg_buffer_length(og[2].header));
if(ogg_sync_pageout(oy,&og_de)<=0)error();
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[2].body)),og[2].body);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[2].body)),og[2].body);
ogg_sync_wrote(oy,ogg_buffer_length(og[2].body)-5);
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[3].header)),og[3].header);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[3].header)),og[3].header);
ogg_sync_wrote(oy,ogg_buffer_length(og[1].header));
- bufcpy(ogg_sync_buffer(oy,ogg_buffer_length(og[3].body)),og[3].body);
+ bufcpy(ogg_sync_bufferin(oy,ogg_buffer_length(og[3].body)),og[3].body);
ogg_sync_wrote(oy,ogg_buffer_length(og[3].body));
if(ogg_sync_pageout(oy,&og_de)>0)error();
<p><p>1.1.2.7 +25 -35 ogg/src/Attic/sync.c
Index: sync.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/sync.c,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -r1.1.2.6 -r1.1.2.7
--- sync.c 26 Mar 2003 07:35:20 -0000 1.1.2.6
+++ sync.c 26 Mar 2003 23:49:26 -0000 1.1.2.7
@@ -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.6 2003/03/26 07:35:20 xiphmont Exp $
+ last mod: $Id: sync.c,v 1.1.2.7 2003/03/26 23:49:26 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
@@ -204,17 +204,7 @@
return OGG_SUCCESS;
}
-static void _release_returned(ogg_sync_state *oy){
- ogg_buffer_release(oy->returned_header);
- ogg_buffer_release(oy->returned_body);
- oy->returned_header=0;
- oy->returned_body=0;
-}
-
unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long bytes){
- /* release the 'held' reference (if any) previously returned by the
- sync */
- _release_returned(oy);
/* [allocate and] expose a buffer for data submission.
@@ -271,7 +261,7 @@
ogg_uint32_t crc_reg=0;
int j,post;
- while(or->next){
+ while(or){
unsigned char *data=or->buffer->data+or->begin;
post=(bytes<or->length?bytes:or->length);
for(j=0;j<post;++j)
@@ -298,8 +288,6 @@
oggbyte_buffer page;
long bytes,ret=0;
- _release_returned(oy);
-
bytes=oy->fifo_fill;
oggbyte_init(&page,oy->fifo_tail,0);
@@ -341,14 +329,15 @@
oggbyte_set4(&page,chksum,22);
goto sync_fail;
}
+ oggbyte_set4(&page,chksum,22);
}
/* We have a page. Set up page return. */
if(og){
/* set up page output */
- oy->returned_header=og->header=oy->fifo_tail;
+ og->header=oy->fifo_tail;
oy->fifo_tail=ogg_buffer_split(oy->fifo_tail,oy->headerbytes);
- oy->returned_body=og->body=oy->fifo_tail;
+ og->body=oy->fifo_tail;
oy->fifo_tail=ogg_buffer_split(oy->fifo_tail,oy->bodybytes);
}else{
/* simply advance */
@@ -361,6 +350,7 @@
oy->headerbytes=0;
oy->bodybytes=0;
if(!oy->fifo_tail)oy->fifo_head=0;
+ oy->fifo_fill-=ret;
return ret;
@@ -391,6 +381,7 @@
}
}
if(!oy->fifo_tail)oy->fifo_head=0;
+ oy->fifo_fill+=ret;
sync_out:
return ret;
@@ -437,7 +428,7 @@
/* clear things to an initial state. Good to call, eg, before seeking */
int ogg_sync_reset(ogg_sync_state *oy){
- _release_returned(oy);
+
ogg_buffer_release(oy->fifo_tail);
oy->fifo_tail=oy->fifo_head=0;
@@ -449,8 +440,8 @@
/* checksum the page; direct table CRC */
-void ogg_page_checksum_set(ogg_page *og){
- if(og){
+int ogg_page_checksum_set(ogg_page *og){
+ if(og && og->header){
oggbyte_buffer ob;
ogg_reference *or;
ogg_uint32_t crc_reg=0;
@@ -461,7 +452,7 @@
oggbyte_set4(&ob,0,22);
or=og->header;
- while(or->next){
+ while(or){
unsigned char *data=or->buffer->data+or->begin;
for(j=0;j<or->length;j++)
crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^data[j]];
@@ -469,7 +460,7 @@
}
or=og->body;
- while(or->next){
+ while(or){
unsigned char *data=or->buffer->data+or->begin;
for(j=0;j<or->length;j++)
crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^data[j]];
@@ -478,7 +469,9 @@
oggbyte_set4(&ob,crc_reg,22);
+ return OGG_SUCCESS;
}
+ return OGG_EINVAL;
}
/* ENCODING PRIMITIVES: raw stream and page layer *******************/
@@ -488,13 +481,8 @@
linked buffers as an iteration over flat char buffers.
ogg_sync_encode and ogg_sync_destroy are as in decode. */
-extern int ogg_sync_pagein(ogg_sync_state *oy,ogg_page *og){
- /* free up returned */
- _release_returned(oy);
-
+int ogg_sync_pagein(ogg_sync_state *oy,ogg_page *og){
/* buffer new */
- ogg_buffer_mark(og->header);
- ogg_buffer_mark(og->body);
if(oy->fifo_head)
oy->fifo_head=ogg_buffer_cat(oy->fifo_head,og->header);
else
@@ -503,27 +491,29 @@
return OGG_SUCCESS;
}
-extern long ogg_sync_bufferout(ogg_sync_state *oy, unsigned char **buffer){
+long ogg_sync_bufferout(ogg_sync_state *oy, unsigned char **buffer){
long ret=0;
/* return next fragment */
while(!ret){
- _release_returned(oy);
if(!oy->fifo_tail){
- _release_returned(oy);
*buffer=0;
return 0;
}
- oy->returned_body=oy->fifo_tail;
- oy->fifo_tail=oy->fifo_tail->next;
- oy->returned_body->next=0;
- *buffer=oy->returned_body->buffer->data+oy->returned_body->begin;
- ret=oy->returned_body->length;
+ *buffer=oy->fifo_tail->buffer->data+oy->fifo_tail->begin;
+ ret=oy->fifo_tail->length;
}
return ret;
+}
+int ogg_sync_read(ogg_sync_state *oy, long bytes){
+ if(!oy->fifo_tail)return OGG_EINVAL;
+ oy->fifo_tail=ogg_buffer_pretruncate(oy->fifo_tail,bytes);
+ if(!oy->fifo_tail)oy->fifo_head=0;
+
+ return OGG_SUCCESS;
}
<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