Unverified Commit 559ba99b authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Can now reallocate page

parent 74225cb4
...@@ -163,7 +163,7 @@ oggpacker *oggp_create(int serialno) { ...@@ -163,7 +163,7 @@ oggpacker *oggp_create(int serialno) {
oggp->buf_size = MAX_PAGE_SIZE; oggp->buf_size = MAX_PAGE_SIZE;
oggp->lacing_size = 256; oggp->lacing_size = 256;
oggp->pages_size = 32; oggp->pages_size = 10;
oggp->alloc_buf = malloc(oggp->buf_size + MAX_HEADER_SIZE); oggp->alloc_buf = malloc(oggp->buf_size + MAX_HEADER_SIZE);
oggp->lacing = malloc(oggp->lacing_size); oggp->lacing = malloc(oggp->lacing_size);
...@@ -243,6 +243,8 @@ unsigned char *oggp_get_packet_buffer(oggpacker *oggp, int bytes) { ...@@ -243,6 +243,8 @@ unsigned char *oggp_get_packet_buffer(oggpacker *oggp, int bytes) {
int newsize; int newsize;
unsigned char *newbuf; unsigned char *newbuf;
newsize = oggp->buf_fill + bytes + MAX_HEADER_SIZE; newsize = oggp->buf_fill + bytes + MAX_HEADER_SIZE;
/* Making sure we don't need to do that too often. */
newsize = newsize*3/2;
newbuf = realloc(oggp->alloc_buf, newsize); newbuf = realloc(oggp->alloc_buf, newsize);
if (newbuf != NULL) { if (newbuf != NULL) {
oggp->alloc_buf = newbuf; oggp->alloc_buf = newbuf;
...@@ -279,6 +281,8 @@ int oggp_commit_packet(oggpacker *oggp, int bytes, oggp_uint64 granulepos, int e ...@@ -279,6 +281,8 @@ int oggp_commit_packet(oggpacker *oggp, int bytes, oggp_uint64 granulepos, int e
int newsize; int newsize;
unsigned char *newbuf; unsigned char *newbuf;
newsize = oggp->lacing_fill + nb_255s + 1; newsize = oggp->lacing_fill + nb_255s + 1;
/* Making sure we don't need to do that too often. */
newsize = newsize*3/2;
newbuf = realloc(oggp->lacing, newsize); newbuf = realloc(oggp->lacing, newsize);
if (newbuf != NULL) { if (newbuf != NULL) {
oggp->lacing = newbuf; oggp->lacing = newbuf;
...@@ -316,8 +320,19 @@ int oggp_flush_page(oggpacker *oggp) { ...@@ -316,8 +320,19 @@ int oggp_flush_page(oggpacker *oggp) {
} }
nb_lacing = oggp->lacing_fill - oggp->lacing_begin; nb_lacing = oggp->lacing_fill - oggp->lacing_begin;
do { do {
assert(oggp->pages_fill < oggp->pages_size); if (oggp->pages_fill >= oggp->pages_size) {
/* FIXME: Check we have a free page. */ int newsize;
oggp_page *newbuf;
/* Making sure we don't need to do that too often. */
newsize = 1 + oggp->pages_size*3/2;
newbuf = realloc(oggp->pages, newsize*sizeof(oggp_page));
if (newbuf != NULL) {
oggp->pages = newbuf;
oggp->pages_size = newsize;
} else {
assert(0);
}
}
p = &oggp->pages[oggp->pages_fill++]; p = &oggp->pages[oggp->pages_fill++];
p->granulepos = oggp->curr_granule; p->granulepos = oggp->curr_granule;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment