re-enable support for resizable buffers in the range coder

This commit is contained in:
Jean-Marc Valin 2008-10-18 09:11:05 -04:00
parent 8679a80ee2
commit 761811d91b
3 changed files with 31 additions and 3 deletions

7
TODO
View file

@ -11,3 +11,10 @@
- Encode band shape (or just tilt)?
- Make energy encoding more robust to losses?
Misc:
Detect uint decoding and flag them in the decoder directly
If we attempt to write too many bits on the encoder side, set a flag instead of
aborting
Save "raw bytes" at the end of the stream

View file

@ -26,6 +26,7 @@ struct ec_byte_buffer{
unsigned char *buf;
unsigned char *ptr;
long storage;
int resizable;
};
/*Encoding functions.*/

View file

@ -12,11 +12,13 @@
void ec_byte_writeinit_buffer(ec_byte_buffer *_b, unsigned char *_buf, long _size){
_b->ptr=_b->buf=_buf;
_b->storage=_size;
_b->resizable = 0;
}
void ec_byte_writeinit(ec_byte_buffer *_b){
_b->ptr=_b->buf=celt_alloc(EC_BUFFER_INCREMENT*sizeof(char));
_b->storage=EC_BUFFER_INCREMENT;
_b->resizable = 1;
}
void ec_byte_writetrunc(ec_byte_buffer *_b,long _bytes){
@ -27,8 +29,14 @@ void ec_byte_write1(ec_byte_buffer *_b,unsigned _value){
ptrdiff_t endbyte;
endbyte=_b->ptr-_b->buf;
if(endbyte>=_b->storage){
if (_b->resizable){
_b->buf=celt_realloc(_b->buf,(_b->storage+EC_BUFFER_INCREMENT)*sizeof(char));
_b->storage+=EC_BUFFER_INCREMENT;
_b->ptr=_b->buf+endbyte;
} else {
celt_fatal("range encoder overflow\n");
}
}
*(_b->ptr++)=(unsigned char)_value;
}
@ -36,8 +44,14 @@ void ec_byte_write4(ec_byte_buffer *_b,ec_uint32 _value){
ptrdiff_t endbyte;
endbyte=_b->ptr-_b->buf;
if(endbyte+4>_b->storage){
if (_b->resizable){
_b->buf=celt_realloc(_b->buf,(_b->storage+EC_BUFFER_INCREMENT)*sizeof(char));
_b->storage+=EC_BUFFER_INCREMENT;
_b->ptr=_b->buf+endbyte;
} else {
celt_fatal("range encoder overflow\n");
}
}
*(_b->ptr++)=(unsigned char)_value;
_value>>=8;
*(_b->ptr++)=(unsigned char)_value;
@ -51,8 +65,14 @@ void ec_byte_writecopy(ec_byte_buffer *_b,void *_source,long _bytes){
ptrdiff_t endbyte;
endbyte=_b->ptr-_b->buf;
if(endbyte+_bytes>_b->storage){
if (_b->resizable){
_b->storage=endbyte+_bytes+EC_BUFFER_INCREMENT;
_b->buf=celt_realloc(_b->buf,_b->storage*sizeof(char));
_b->ptr=_b->buf+endbyte;
} else {
celt_fatal("range encoder overflow\n");
}
}
memmove(_b->ptr,_source,_bytes);
_b->ptr+=_bytes;
}