Error checking on the decoder side
This commit is contained in:
parent
9d785afb67
commit
b1e017f58d
7 changed files with 43 additions and 16 deletions
|
@ -1104,7 +1104,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, c
|
||||||
ec_enc_done(enc);
|
ec_enc_done(enc);
|
||||||
|
|
||||||
RESTORE_STACK;
|
RESTORE_STACK;
|
||||||
if (enc->error)
|
if (ec_enc_get_error(enc))
|
||||||
return CELT_CORRUPTED_DATA;
|
return CELT_CORRUPTED_DATA;
|
||||||
else
|
else
|
||||||
return nbCompressedBytes;
|
return nbCompressedBytes;
|
||||||
|
@ -1734,7 +1734,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
|
||||||
{
|
{
|
||||||
celt_decode_lost(st, pcm, N, LM);
|
celt_decode_lost(st, pcm, N, LM);
|
||||||
RESTORE_STACK;
|
RESTORE_STACK;
|
||||||
return 0;
|
return CELT_OK;
|
||||||
}
|
}
|
||||||
if (len<0) {
|
if (len<0) {
|
||||||
RESTORE_STACK;
|
RESTORE_STACK;
|
||||||
|
@ -1785,6 +1785,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
|
||||||
if (maxpitch<0)
|
if (maxpitch<0)
|
||||||
{
|
{
|
||||||
celt_notify("detected pitch when not allowed, bit corruption suspected");
|
celt_notify("detected pitch when not allowed, bit corruption suspected");
|
||||||
|
dec->error |= 1;
|
||||||
pitch_index = 0;
|
pitch_index = 0;
|
||||||
has_pitch = 0;
|
has_pitch = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1856,7 +1857,10 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
|
||||||
deemphasis(st->out_mem, pcm, N, C, st->mode->preemph, st->preemph_memD);
|
deemphasis(st->out_mem, pcm, N, C, st->mode->preemph, st->preemph_memD);
|
||||||
st->loss_count = 0;
|
st->loss_count = 0;
|
||||||
RESTORE_STACK;
|
RESTORE_STACK;
|
||||||
return 0;
|
if (ec_dec_get_error(dec))
|
||||||
|
return CELT_CORRUPTED_DATA;
|
||||||
|
else
|
||||||
|
return CELT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FIXED_POINT
|
#ifdef FIXED_POINT
|
||||||
|
@ -1888,6 +1892,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
|
||||||
|
|
||||||
ALLOC(out, C*N, celt_int16);
|
ALLOC(out, C*N, celt_int16);
|
||||||
ret=celt_decode_with_ec(st, data, len, out, frame_size, dec);
|
ret=celt_decode_with_ec(st, data, len, out, frame_size, dec);
|
||||||
|
if (ret==0)
|
||||||
for (j=0;j<C*N;j++)
|
for (j=0;j<C*N;j++)
|
||||||
pcm[j]=out[j]*(1/32768.);
|
pcm[j]=out[j]*(1/32768.);
|
||||||
|
|
||||||
|
@ -1924,6 +1929,7 @@ int celt_decode_with_ec(CELTDecoder * restrict st, const unsigned char *data, in
|
||||||
|
|
||||||
ret=celt_decode_with_ec_float(st, data, len, out, frame_size, dec);
|
ret=celt_decode_with_ec_float(st, data, len, out, frame_size, dec);
|
||||||
|
|
||||||
|
if (ret==0)
|
||||||
for (j=0;j<C*N;j++)
|
for (j=0;j<C*N;j++)
|
||||||
pcm[j] = FLOAT2INT16 (out[j]);
|
pcm[j] = FLOAT2INT16 (out[j]);
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,7 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){
|
||||||
if (t>_ft)
|
if (t>_ft)
|
||||||
{
|
{
|
||||||
celt_notify("uint decode error");
|
celt_notify("uint decode error");
|
||||||
|
_this->error |= 1;
|
||||||
t = _ft;
|
t = _ft;
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
|
@ -111,3 +112,8 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ec_dec_get_error(ec_dec *_this)
|
||||||
|
{
|
||||||
|
return _this->error || (ec_dec_tell(_this,0) > 8*_this->buf->storage);
|
||||||
|
}
|
||||||
|
|
|
@ -56,6 +56,8 @@ struct ec_dec{
|
||||||
/*Number of valid bits in end_byte*/
|
/*Number of valid bits in end_byte*/
|
||||||
int end_bits_left;
|
int end_bits_left;
|
||||||
int nb_end_bits;
|
int nb_end_bits;
|
||||||
|
/*Nonzero if an error occurred*/
|
||||||
|
int error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,4 +125,7 @@ int ec_dec_bit_prob(ec_dec *_this,unsigned _prob);
|
||||||
rounding error is in the positive direction).*/
|
rounding error is in the positive direction).*/
|
||||||
long ec_dec_tell(ec_dec *_this,int _b);
|
long ec_dec_tell(ec_dec *_this,int _b);
|
||||||
|
|
||||||
|
/*Returns a nonzero value if any error has been detected during decoding*/
|
||||||
|
int ec_dec_get_error(ec_dec *_this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -102,3 +102,8 @@ void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){
|
||||||
ec_encode(_this,_fl,_fl+1,_ft+1);
|
ec_encode(_this,_fl,_fl+1,_ft+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ec_enc_get_error(ec_enc *_this)
|
||||||
|
{
|
||||||
|
return _this->error;
|
||||||
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ struct ec_enc{
|
||||||
/*Number of valid bits in end_byte*/
|
/*Number of valid bits in end_byte*/
|
||||||
int end_bits_left;
|
int end_bits_left;
|
||||||
int nb_end_bits;
|
int nb_end_bits;
|
||||||
/*Nonzero is an error occurred*/
|
/*Nonzero if an error occurred*/
|
||||||
int error;
|
int error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -111,4 +111,7 @@ long ec_enc_tell(ec_enc *_this,int _b);
|
||||||
ec_enc_init() must be called before the encoder can be used again.*/
|
ec_enc_init() must be called before the encoder can be used again.*/
|
||||||
void ec_enc_done(ec_enc *_this);
|
void ec_enc_done(ec_enc *_this);
|
||||||
|
|
||||||
|
/*Returns a nonzero value if any error has been detected during encoding*/
|
||||||
|
int ec_enc_get_error(ec_enc *_this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -144,6 +144,7 @@ void ec_dec_init(ec_dec *_this,ec_byte_buffer *_buf){
|
||||||
/*_this->end_byte=ec_byte_look_at_end(_this->buf);*/
|
/*_this->end_byte=ec_byte_look_at_end(_this->buf);*/
|
||||||
_this->end_bits_left=0;
|
_this->end_bits_left=0;
|
||||||
_this->nb_end_bits=0;
|
_this->nb_end_bits=0;
|
||||||
|
_this->error=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -136,10 +136,8 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
len = celt_encode_resynthesis(enc, in, in, frame_size, data, bytes_per_packet);
|
len = celt_encode_resynthesis(enc, in, in, frame_size, data, bytes_per_packet);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
{
|
fprintf (stderr, "celt_encode() failed: %s\n", celt_strerror(len));
|
||||||
fprintf (stderr, "celt_encode() returned an error: %s\n", celt_strerror(len));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
/* This is for simulating bit errors */
|
/* This is for simulating bit errors */
|
||||||
#if 0
|
#if 0
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
|
@ -162,13 +160,16 @@ int main(int argc, char *argv[])
|
||||||
else if (errors%2 == 1)
|
else if (errors%2 == 1)
|
||||||
data[rand()%8] ^= 1<<rand()%8;
|
data[rand()%8] ^= 1<<rand()%8;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1 /* Set to zero to use the encoder's output instead */
|
#if 1 /* Set to zero to use the encoder's output instead */
|
||||||
/* This is to simulate packet loss */
|
/* This is to simulate packet loss */
|
||||||
if (argc==9 && rand()%1000<atoi(argv[argc-3]))
|
if (argc==9 && rand()%1000<atoi(argv[argc-3]))
|
||||||
/*if (errors && (errors%2==0))*/
|
/*if (errors && (errors%2==0))*/
|
||||||
celt_decode(dec, NULL, len, out, frame_size);
|
err = celt_decode(dec, NULL, len, out, frame_size);
|
||||||
else
|
else
|
||||||
celt_decode(dec, data, len, out, frame_size);
|
err = celt_decode(dec, data, len, out, frame_size);
|
||||||
|
if (err != 0)
|
||||||
|
fprintf(stderr, "celt_decode() failed: %s\n", celt_strerror(err));
|
||||||
#else
|
#else
|
||||||
for (i=0;i<frame_size*channels;i++)
|
for (i=0;i<frame_size*channels;i++)
|
||||||
out[i] = in[i];
|
out[i] = in[i];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue