ref: ef20e39374a35d51bd5d6681132c0f625bb50891
parent: a7be4387166462d6dd5ea6184debacb0aca509a0
author: Jean-Marc Valin <[email protected]>
date: Fri Mar 18 11:34:11 EDT 2011
Non-fatal bit-stream errors are now reported through ctl()
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -1626,7 +1626,7 @@
RESTORE_STACK;
if (ec_get_error(enc))
- return CELT_CORRUPTED_DATA;
+ return CELT_INTERNAL_ERROR;
else
return nbCompressedBytes;
}
@@ -1839,6 +1839,7 @@
#define DECODER_RESET_START rng
celt_uint32 rng;
+ int error;
int last_pitch_index;
int loss_count;
int postfilter_period;
@@ -2279,7 +2280,7 @@
if (LM>st->mode->maxLM)
return CELT_CORRUPTED_DATA;
if (frame_size < st->mode->shortMdctSize<<LM)
- return CELT_BAD_ARG;
+ return CELT_BUFFER_TOO_SMALL;
else
frame_size = st->mode->shortMdctSize<<LM;
} else {
@@ -2571,10 +2572,11 @@
deemphasis(out_syn, pcm, N, CC, st->downsample, st->mode->preemph, st->preemph_memD);
st->loss_count = 0;
RESTORE_STACK;
- if (ec_tell(dec) > 8*len || ec_get_error(dec))
- return CELT_CORRUPTED_DATA;
- else
- return frame_size/st->downsample;
+ if (ec_tell(dec) > 8*len)
+ return CELT_INTERNAL_ERROR;
+ if(ec_get_error(dec))
+ st->error = 1;
+ return frame_size/st->downsample;
}
#ifdef FIXED_POINT
@@ -2685,6 +2687,15 @@
{
celt_int32 value = va_arg(ap, celt_int32);
st->signalling = value;
+ }
+ break;
+ case CELT_GET_AND_CLEAR_ERROR_REQUEST:
+ {
+ int *value = va_arg(ap, int*);
+ if (value==NULL)
+ goto bad_arg;
+ *value=st->error;
+ st->error = 0;
}
break;
case CELT_RESET_STATE:
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -51,6 +51,7 @@
#define _celt_check_int(x) (((void)((x) == (celt_int32)0)), (celt_int32)(x))
#define _celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (CELTMode**)(ptr)))
+#define _celt_check_int_ptr(ptr) ((ptr) + ((ptr) - (int*)(ptr)))
/* Error codes */
/** No error */
@@ -58,7 +59,7 @@
/** An (or more) invalid argument (e.g. out of range) */
#define CELT_BAD_ARG -1
/** The mode struct passed is invalid */
-#define CELT_INVALID_MODE -2
+#define CELT_BUFFER_TOO_SMALL -2
/** An internal error was detected */
#define CELT_INTERNAL_ERROR -3
/** The data passed (e.g. compressed data to decoder) is corrupted */
@@ -104,6 +105,10 @@
#define CELT_SET_INPUT_CLIPPING_REQUEST 14
#define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, _celt_check_int(x)
+#define CELT_GET_AND_CLEAR_ERROR_REQUEST 15
+#define CELT_GET_AND_CLEAR_ERROR(x) CELT_GET_AND_CLEAR_ERROR_REQUEST, _celt_check_int_ptr(x)
+
+/* Internal */
#define CELT_SET_START_BAND_REQUEST 10000
#define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, _celt_check_int(x)
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -308,7 +308,7 @@
if ((celt_int32)frame_size*1000 < Fs)
{
if (error)
- *error = CELT_INVALID_MODE;
+ *error = CELT_BAD_ARG;
return NULL;
}
@@ -330,7 +330,7 @@
if ((celt_int32)(frame_size>>LM)*300 > Fs)
{
if (error)
- *error = CELT_INVALID_MODE;
+ *error = CELT_BAD_ARG;
return NULL;
}
@@ -425,7 +425,7 @@
return mode;
failure:
if (error)
- *error = CELT_INVALID_MODE;
+ *error = CELT_ALLOC_FAIL;
if (mode!=NULL)
celt_mode_destroy(mode);
return NULL;