[xiph-cvs] cvs commit: ogg/src bitwise.c buffer.c mutex.h ogginternal.h
Monty
xiphmont at xiph.org
Mon Feb 10 10:05:46 PST 2003
xiphmont 03/02/10 13:05:46
Modified: src Tag: libogg2-zerocopy bitwise.c buffer.c mutex.h
ogginternal.h
Log:
More fixes to fun things found by randomized testing. One or two more outstanding bugs to go....
Revision Changes Path
No revision
<p>No revision
<p>1.14.2.7 +113 -83 ogg/src/bitwise.c
Index: bitwise.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/bitwise.c,v
retrieving revision 1.14.2.6
retrieving revision 1.14.2.7
diff -u -r1.14.2.6 -r1.14.2.7
--- bitwise.c 5 Feb 2003 06:42:28 -0000 1.14.2.6
+++ bitwise.c 10 Feb 2003 18:05:46 -0000 1.14.2.7
@@ -11,7 +11,7 @@
********************************************************************
function: pack variable sized words into an octet stream
- last mod: $Id: bitwise.c,v 1.14.2.6 2003/02/05 06:42:28 xiphmont Exp $
+ last mod: $Id: bitwise.c,v 1.14.2.7 2003/02/10 18:05:46 xiphmont Exp $
********************************************************************/
@@ -232,35 +232,60 @@
if(bits > b->headend<<3){
int end=b->headend;
unsigned char *ptr=b->headptr;
-
+ ogg_buffer *head=b->head;
+
/* headend's semantic usage is complex; it's a 'check carefully
past this point' marker. It can mean we're either at the end
of a buffer fragment, or done reading. */
- /* check to see if there are enough bytes left in next fragment
- [if any] to fufill read request. Spanning more than one boundary
- isn't possible so long as the ogg buffer abstraction enforces >
- 4 byte fragments, which it does. */
+ /* check to see if there are enough bytes left in next fragments
+ [if any] to fufill read request. */
if(bits > (b->length-b->head->used+b->headend)*8)
return -1;
/* At this point, we're certain we span and that there's sufficient
- data in the following buffer to fufill the read */
+ data in the following buffer[s] to fufill the read */
- if(!end)ptr=b->head->next->data;
+ while(!end){
+ ptr=b->head->next->data;
+ end=b->head->next->used; /* this value would be incorrect if we
+ didn't already know that we're not
+ going to fall off the absolute end
+ of the buffer */
+ }
*ret=*ptr++>>b->headbit;
if(bits>8){
- if(!--end)ptr=b->head->next->data;
+ --end;
+ while(!end){
+ head=head->next;
+ ptr=head->data;
+ end=head->used;
+ }
*ret|=*ptr++<<(8-b->headbit);
if(bits>16){
- if(!--end)ptr=b->head->next->data;
+ --end;
+ while(!end){
+ head=head->next;
+ ptr=head->data;
+ end=head->used;
+ }
*ret|=*ptr++<<(16-b->headbit);
if(bits>24){
- if(!--end)ptr=b->head->next->data;
+ --end;
+ while(!end){
+ head=head->next;
+ ptr=head->data;
+ end=head->used;
+ }
*ret|=*ptr++<<(24-b->headbit);
if(bits>32 && b->headbit){
- if(!--end)ptr=b->head->next->data;
+ --end;
+ while(!end){
+ head=head->next;
+ ptr=head->data;
+ end=head->used;
+ }
*ret|=*ptr<<(32-b->headbit);
}
}
@@ -297,35 +322,58 @@
if(bits > b->headend<<3){
int end=b->headend;
unsigned char *ptr=b->headptr;
+ ogg_buffer *head=b->head;
/* headend's semantic usage is complex; it's a 'check carefully
past this point' marker. It can mean we're either at the end
of a buffer fragment, or done reading. */
- /* check to see if there are enough bytes left in next fragment
- [if any] to fufill read request. Spanning more than one boundary
- isn't possible so long as the ogg buffer abstraction enforces >
- 4 byte fragments, which it does. */
+ /* check to see if there are enough bytes left in next fragments
+ [if any] to fufill read request. */
if(bits > (b->length-b->head->used+b->headend)*8)
return -1;
/* At this point, we're certain we span and that there's sufficient
- data in the following buffer to fufill the read */
+ data in the following buffer[s] to fufill the read */
- if(!end)ptr=b->head->next->data;
+ while(!end){
+ head=head->next;
+ ptr=head->data;
+ end=head->used;
+ }
*ret=*ptr++<<(24+b->headbit);
if(bits>8){
- if(!--end)ptr=b->head->next->data;
+ --end;
+ if(!end){
+ head=head->next;
+ ptr=head->data;
+ end=head->used;
+ }
*ret|=*ptr++<<(16+b->headbit);
if(bits>16){
- if(!--end)ptr=b->head->next->data;
+ --end;
+ if(!end){
+ head=head->next;
+ ptr=head->data;
+ end=head->used;
+ }
*ret|=*ptr++<<(8+b->headbit);
if(bits>24){
- if(!--end)ptr=b->head->next->data;
+ --end;
+ if(!end){
+ head=head->next;
+ ptr=head->data;
+ end=head->used;
+ }
*ret|=*ptr++<<(b->headbit);
if(bits>32 && b->headbit){
- if(!--end)ptr=b->head->next->data;
+ --end;
+ while(!end){
+ head=head->next;
+ ptr=head->data;
+ end=head->used;
+ }
*ret|=*ptr>>(8-b->headbit);
}
}
@@ -370,27 +418,29 @@
b->headbit=0;
}
-static void _oggpack_adv_spanner(oggpack_buffer *b){
-
- if(b->length-b->head->used>0){
- /* on to the next fragment */
+static void _oggpack_spanner(oggpack_buffer *b){
+ while(b->headend<1){
+ if(b->length-b->head->used>0){
+ /* on to the next fragment */
+
+ b->count+=b->head->used;
+ b->length-=b->head->used;
+ b->head=b->head->next;
+ b->headptr=b->head->data-b->headend;
+
+ if(b->length<b->head->used){
+ b->headend+=b->length;
+ }else{
+ b->headend+=b->head->used;
+ }
- b->count+=b->head->used;
- b->length-=b->head->used;
- b->head=b->head->next;
- b->headptr=b->head->data-b->headend;
-
- if(b->length<b->head->used){
- b->headend+=b->length;
}else{
- b->headend+=b->head->used;
+
+ /* no more, bring it to a halt */
+ _oggpack_adv_halt(b);
+ break;
+
}
-
- }else{
-
- /* no more, bring it to a halt */
- _oggpack_adv_halt(b);
-
}
}
@@ -400,8 +450,7 @@
b->headend-=bits/8;
b->headbit=bits&7;
b->headptr+=bits/8;
-
- if(b->headend<1)_oggpack_adv_spanner(b);
+ _oggpack_spanner(b);
}
void oggpackB_adv(oggpack_buffer *b,int bits){
@@ -413,7 +462,7 @@
b->headbit=0;
++b->headptr;
--b->headend;
- if(b->headend<1)_oggpack_adv_spanner(b);
+ _oggpack_spanner(b);
}
}
@@ -433,48 +482,37 @@
past this point' marker. It can mean we're either at the end
of a buffer fragment, or done reading. */
- /* check to see if there are enough bytes left in next fragment
- [if any] to fufill read request. Spanning more than one boundary
- isn't possible so long as the ogg buffer abstraction enforces >
- 4 byte fragments, which it does. */
+ /* check to see if there are enough bytes left in next fragments
+ [if any] to fufill read request. */
if(bits > (b->length-b->head->used+b->headend)*8){
_oggpack_adv_halt(b);
return -1;
}
- if(!b->headend)b->headptr=b->head->next->data;
+ if(!b->headend)_oggpack_spanner(b);
*ret=*b->headptr>>b->headbit;
if(bits>=8){
b->headptr++;
- if(!--b->headend)b->headptr=b->head->next->data;
+ if(!--b->headend)_oggpack_spanner(b);
*ret|=*b->headptr<<(8-b->headbit);
if(bits>=16){
b->headptr++;
- if(!--b->headend)b->headptr=b->head->next->data;
+ if(!--b->headend)_oggpack_spanner(b);
*ret|=*b->headptr<<(16-b->headbit);
if(bits>=24){
b->headptr++;
- if(!--b->headend)b->headptr=b->head->next->data;
+ if(!--b->headend)_oggpack_spanner(b);
*ret|=*b->headptr<<(24-b->headbit);
if(bits>=32){
b->headptr++;
- if(!--b->headend)b->headptr=b->head->next->data;
+ if(!--b->headend)_oggpack_spanner(b);
if(b->headbit)*ret|=*b->headptr<<(32-b->headbit);
}
}
}
}
- b->count+=b->head->used;
- b->length-=b->head->used;
- b->head=b->head->next;
-
- if(b->length<b->head->used)
- b->headend+=b->length;
- else
- b->headend+=b->head->used;
-
}else{
*ret=b->headptr[0]>>b->headbit;
@@ -522,37 +560,29 @@
return -1;
}
- if(!b->headend)b->headptr=b->head->next->data;
+ if(!b->headend)_oggpack_spanner(b);
*ret=*b->headptr<<(24+b->headbit);
if(bits>=8){
b->headptr++;
- if(!--b->headend)b->headptr=b->head->next->data;
+ if(!--b->headend)_oggpack_spanner(b);
*ret|=*b->headptr<<(16+b->headbit);
if(bits>=16){
b->headptr++;
- if(!--b->headend)b->headptr=b->head->next->data;
+ if(!--b->headend)_oggpack_spanner(b);
*ret|=*b->headptr<<(8+b->headbit);
if(bits>=24){
b->headptr++;
- if(!--b->headend)b->headptr=b->head->next->data;
+ if(!--b->headend)_oggpack_spanner(b);
*ret|=*b->headptr<<(b->headbit);
if(bits>=32){
b->headptr++;
- if(!--b->headend)b->headptr=b->head->next->data;
+ if(!--b->headend)_oggpack_spanner(b);
if(b->headbit)*ret|=*b->headptr>>(8-b->headbit);
}
}
}
}
- b->count+=b->head->used;
- b->length-=b->head->used;
- b->head=b->head->next;
- if(b->length<b->head->used)
- b->headend+=b->length;
- else
- b->headend+=b->head->used;
-
}else{
*ret=b->headptr[0]<<(24+b->headbit);
@@ -587,7 +617,7 @@
b->headbit=0;
++b->headptr;
--b->headend;
- if(b->headend<1)_oggpack_adv_spanner(b);
+ if(b->headend<1)_oggpack_spanner(b);
}
return(ret);
@@ -603,7 +633,7 @@
b->headbit=0;
++b->headptr;
--b->headend;
- if(b->headend<1)_oggpack_adv_spanner(b);
+ if(b->headend<1)_oggpack_spanner(b);
}
return(ret);
@@ -1129,7 +1159,7 @@
/* write the required number of bits out to packbuffer */
for(j=0;j<TESTWORDS;j++){
values[j]=rand();
- len[j]=(rand()%32)+1;
+ len[j]=(rand()%33);
count+=len[j];
oggpack_write(&o,values[j],len[j]);
@@ -1173,7 +1203,7 @@
else
ob=temp;
- ilen=(rand()%8)*4+4;
+ ilen=(rand()%32);
if(ilen>count2)ilen=count2;
obl=temp;
obl->data=ptr;
@@ -1269,7 +1299,7 @@
exit(1);
}
if(temp!=(values[j]&mask[len[j]])){
- fprintf(stderr,"\nERROR: Incorrect read %lx != %lx, word %d, len %d\n",
+ fprintf(stderr,"\nERROR: Incorrect look %lx != %lx, word %d, len %d\n",
values[j]&mask[len[j]],temp,j-begin,len[j]);
exit(1);
}
@@ -1279,12 +1309,12 @@
oggpack_adv(&o,len[j]);
bitcount+=len[j];
if(oggpack_bits(&o)!=bitcount){
- fprintf(stderr,"\nERROR: Read bitcounter %d != %ld!\n",
+ fprintf(stderr,"\nERROR: Look/Adv bitcounter %d != %ld!\n",
bitcount,oggpack_bits(&o));
exit(1);
}
if(oggpack_bytes(&o)!=(bitcount+7)/8){
- fprintf(stderr,"\nERROR: Read bytecounter %d != %ld!\n",
+ fprintf(stderr,"\nERROR: Look/Adv bytecounter %d != %ld!\n",
(bitcount+7)/8,oggpack_bytes(&o));
exit(1);
}
@@ -1314,7 +1344,7 @@
/* write the required number of bits out to packbuffer */
for(j=0;j<TESTWORDS;j++){
values[j]=rand();
- len[j]=(rand()%32)+1;
+ len[j]=(rand()%33);
count+=len[j];
oggpackB_write(&o,values[j],len[j]);
@@ -1358,7 +1388,7 @@
else
ob=temp;
- ilen=(rand()%8)*4+4;
+ ilen=(rand()%32);
if(ilen>count2)ilen=count2;
obl=temp;
obl->data=ptr;
<p><p>1.1.2.4 +2 -1 ogg/src/Attic/buffer.c
Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/buffer.c,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- buffer.c 21 Jan 2003 10:21:06 -0000 1.1.2.3
+++ buffer.c 10 Feb 2003 18:05:46 -0000 1.1.2.4
@@ -11,7 +11,7 @@
********************************************************************
function: centralized fragment buffer management
- last mod: $Id: buffer.c,v 1.1.2.3 2003/01/21 10:21:06 xiphmont Exp $
+ last mod: $Id: buffer.c,v 1.1.2.4 2003/02/10 18:05:46 xiphmont Exp $
********************************************************************/
@@ -65,6 +65,7 @@
bs->unused_pool=ret->next;
ogg_mutex_unlock(&bs->mutex);
+ /* if the unused buffer is too small, grow it */
if(ret->size<bytes){
ret->data=_ogg_realloc(ret->data,bytes);
ret->size=bytes;
<p><p>1.1.2.5 +6 -6 ogg/src/Attic/mutex.h
Index: mutex.h
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/mutex.h,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- mutex.h 3 Feb 2003 23:01:47 -0000 1.1.2.4
+++ mutex.h 10 Feb 2003 18:05:46 -0000 1.1.2.5
@@ -11,7 +11,7 @@
********************************************************************
function: #ifdef jail for basic thread mutexing
- last mod: $Id: mutex.h,v 1.1.2.4 2003/02/03 23:01:47 xiphmont Exp $
+ last mod: $Id: mutex.h,v 1.1.2.5 2003/02/10 18:05:46 xiphmont Exp $
********************************************************************/
@@ -36,11 +36,11 @@
#elif USE_NO_THREADS
typedef int ogg_mutex_t;
-static void noop(void){return;}
-#define ogg_mutex_init(m) (noop())
-#define ogg_mutex_clear(m) (noop())
-#define ogg_mutex_lock(m) (noop())
-#define ogg_mutex_unlock(m) (noop())
+#define noop() do {} while(0)
+#define ogg_mutex_init(m) noop()
+#define ogg_mutex_clear(m) noop()
+#define ogg_mutex_lock(m) noop()
+#define ogg_mutex_unlock(m) noop()
#else
#error "configure proper threading wrappers for this platform, or compile with -DUSE_NO_THREADS to build without threading support."
<p><p>1.1.2.4 +10 -9 ogg/src/Attic/ogginternal.h
Index: ogginternal.h
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/ogginternal.h,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- ogginternal.h 21 Jan 2003 10:21:06 -0000 1.1.2.3
+++ ogginternal.h 10 Feb 2003 18:05:46 -0000 1.1.2.4
@@ -11,7 +11,7 @@
********************************************************************
function: internal/hidden data representation structures
- last mod: $Id: ogginternal.h,v 1.1.2.3 2003/01/21 10:21:06 xiphmont Exp $
+ last mod: $Id: ogginternal.h,v 1.1.2.4 2003/02/10 18:05:46 xiphmont Exp $
********************************************************************/
@@ -28,9 +28,9 @@
};
typedef struct{
- ogg_buffer_reference *segment;
+ ogg_buffer *segment;
int cursor;
-} fragmented_cursor;
+} ogg_buffer_cursor;
struct ogg_buffer {
unsigned char *data;
@@ -66,14 +66,15 @@
} ogg_packet_chain;
struct ogg_sync_state {
+ /* encode/decode mem management */
+ ogg_buffer_state *bufferpool;
/* stream buffers */
- ogg_buffer *unused_fifo;
- ogg_buffer *fifo_head;
- ogg_buffer *fifo_tail;
- ogg_buffer *fifo_returned;
- int fifo_returned_pos;
- int fifo_fill;
+ ogg_buffer *fifo_head;
+ ogg_buffer *fifo_tail;
+
+ long fifo_cursor;
+ ogg_buffer_reference *returned;
/* stream sync management */
int unsynced;
<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