Refactor ec_enc_patch_initial_bits().
The return code has been eliminated in favor of using the existing
error flag in the ec_enc struct.
This also adds the declaration to the header, which JM's importation
of Koen's adaptation of my original code in b3c05b6b
omitted.
This commit is contained in:
parent
5b236756a3
commit
f18ad4387a
2 changed files with 37 additions and 23 deletions
|
@ -215,10 +215,10 @@ void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,unsigned _bits){
|
||||||
_this->nbits_total+=_bits;
|
_this->nbits_total+=_bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,int _nbits){
|
void ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,unsigned _nbits){
|
||||||
int shift;
|
int shift;
|
||||||
unsigned mask;
|
unsigned mask;
|
||||||
if(_nbits<0||_nbits>EC_SYM_BITS)return -1;
|
celt_assert(_nbits<=EC_SYM_BITS);
|
||||||
shift=EC_SYM_BITS-_nbits;
|
shift=EC_SYM_BITS-_nbits;
|
||||||
mask=(1<<_nbits)-1<<shift;
|
mask=(1<<_nbits)-1<<shift;
|
||||||
if(_this->offs>0){
|
if(_this->offs>0){
|
||||||
|
@ -235,9 +235,7 @@ int ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,int _nbits){
|
||||||
(ec_uint32)_val<<EC_CODE_SHIFT+shift;
|
(ec_uint32)_val<<EC_CODE_SHIFT+shift;
|
||||||
}
|
}
|
||||||
/*The encoder hasn't even encoded _nbits of data yet.*/
|
/*The encoder hasn't even encoded _nbits of data yet.*/
|
||||||
else return -1;
|
else _this->error=-1;
|
||||||
/*Success!*/
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ec_enc_shrink(ec_enc *_this,ec_uint32 _size){
|
void ec_enc_shrink(ec_enc *_this,ec_uint32 _size){
|
||||||
|
|
|
@ -78,6 +78,22 @@ void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft);
|
||||||
This must be between 0 and 25, inclusive.*/
|
This must be between 0 and 25, inclusive.*/
|
||||||
void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,unsigned _ftb);
|
void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,unsigned _ftb);
|
||||||
|
|
||||||
|
/*Overwrites a few bits at the very start of an existing stream, after they
|
||||||
|
have already been encoded.
|
||||||
|
This makes it possible to have a few flags up front, where it is easy for
|
||||||
|
decoders to access them without parsing the whole stream, even if their
|
||||||
|
values are not determined until late in the encoding process, without having
|
||||||
|
to buffer all the intermediate symbols in the encoder.
|
||||||
|
In order for this to work, at least _nbits bits must have already been
|
||||||
|
encoded using probabilities that are an exact power of two.
|
||||||
|
The encoder can verify the number of encoded bits is sufficient, but cannot
|
||||||
|
check this latter condition.
|
||||||
|
_val: The bits to encode (in the least _nbits significant bits).
|
||||||
|
They will be decoded in order from most-significant to least.
|
||||||
|
_nbits: The number of bits to overwrite.
|
||||||
|
This must be no more than 8.*/
|
||||||
|
void ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,unsigned _nbits);
|
||||||
|
|
||||||
/*Compacts the data to fit in the target size.
|
/*Compacts the data to fit in the target size.
|
||||||
This moves up the raw bits at the end of the current buffer so they are at
|
This moves up the raw bits at the end of the current buffer so they are at
|
||||||
the end of the new buffer size.
|
the end of the new buffer size.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue