diff options
author | jbuethe <jbuethe@amazon.de> | 2023-03-10 12:35:20 +0000 |
---|---|---|
committer | jbuethe <jbuethe@amazon.de> | 2023-03-10 12:35:20 +0000 |
commit | 95765df6e7d4f0ee8b0b5747f6466431ee183502 (patch) | |
tree | d6257403107326a8dc5f655c189dbbd51fd09d7a | |
parent | 731a440fbe03c84b5a5f5ad9c97d48ebf280205f (diff) | |
download | opus-95765df6e7d4f0ee8b0b5747f6466431ee183502.tar.gz |
added some safeguards
-rw-r--r-- | silk/decode_frame.c | 10 | ||||
-rw-r--r-- | src/opus_decoder.c | 12 | ||||
-rw-r--r-- | src/opus_demo.c | 12 |
3 files changed, 24 insertions, 10 deletions
diff --git a/silk/decode_frame.c b/silk/decode_frame.c index 8d9ab58e..8c8a8d7e 100644 --- a/silk/decode_frame.c +++ b/silk/decode_frame.c @@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef FEATURES #include <stdio.h> +#include <stdlib.h> #endif #include "main.h" @@ -93,12 +94,7 @@ opus_int silk_decode_frame( psDec->indices.quantOffsetType, psDec->frame_length ); #ifdef FEATURES num_bits = ec_tell(psRangeDec) - num_bits; - if (num_bits_smooth < 0) { - num_bits_smooth = num_bits; - } - else { - num_bits_smooth = 0.9 * num_bits_smooth + 0.1 * num_bits; - } + num_bits_smooth = 0.9 * num_bits_smooth + 0.1 * num_bits; fwrite(&num_bits, sizeof(num_bits), 1, f_numbits); fwrite(&num_bits_smooth, sizeof(num_bits_smooth), 1, f_numbits_smooth); #endif @@ -126,6 +122,8 @@ opus_int silk_decode_frame( psDec->first_frame_after_reset = 0; } else { /* Handle packet loss by extrapolation */ + printf("packet lost!"); + exit(1); silk_PLC( psDec, psDecCtrl, pOut, 1, arch ); } diff --git a/src/opus_decoder.c b/src/opus_decoder.c index 6520e748..701eaee2 100644 --- a/src/opus_decoder.c +++ b/src/opus_decoder.c @@ -52,6 +52,11 @@ #include "mathops.h" #include "cpu_support.h" +#if 1 +#include <stdlib.h> +#include <stdio.h> +#endif + struct OpusDecoder { int celt_dec_offset; int silk_dec_offset; @@ -269,6 +274,7 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data, data = NULL; /* In that case, don't conceal more than what the ToC says */ frame_size = IMIN(frame_size, st->frame_size); + printf("data len <= 1\n"); exit(1); } if (data != NULL) { @@ -276,7 +282,13 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data, mode = st->mode; bandwidth = st->bandwidth; ec_dec_init(&dec,(unsigned char*)data,len); + if (mode != MODE_SILK_ONLY) + { + printf("mode is %d\n", mode); + return -9999; + } } else { + printf("data is NULL\n"); exit(1); audiosize = frame_size; /* Run PLC using last used mode (CELT if we ended with CELT redundancy) */ mode = st->prev_redundancy ? MODE_CELT_ONLY : st->prev_mode; diff --git a/src/opus_demo.c b/src/opus_demo.c index 71eb13e9..dab3edd8 100644 --- a/src/opus_demo.c +++ b/src/opus_demo.c @@ -207,15 +207,15 @@ static OpusDecoder *ms_opus_decoder_create(opus_int32 Fs, int channels, int *err } #endif -#define BITRATE_MIN 8000 -#define BITRATE_MAX 24000 -#define BITRATE_STEP 400 +#define BITRATE_MIN 6000 +#define BITRATE_MAX 20000 +#define BITRATE_STEP 100 #define COMPLEXITY_MIN 10 #define COMPLEXITY_MAX 10 #define PACKET_LOSS_PERC_MIN 0 -#define PACKET_LOSS_PERC_MAX 50 +#define PACKET_LOSS_PERC_MAX 0 #define PACKET_LOSS_PERC_STEP 5 @@ -310,6 +310,7 @@ int main(int argc, char *argv[]) int ret = EXIT_FAILURE; OPUS_SET_FORCE_MODE(MODE_SILK_ONLY); + //srand(0); if (argc < 5 ) { @@ -836,13 +837,16 @@ int main(int argc, char *argv[]) /* attempt to decode with in-band FEC from next packet */ opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&output_samples)); output_samples = opus_decode(dec, lost ? NULL : data[toggle], len[toggle], out, output_samples, 1); + if (output_samples != 320) {printf("[frame %d] decoder return value %d\n", silk_frame_counter, output_samples); exit(1);} } else { /* regular decode */ output_samples = max_frame_size; output_samples = opus_decode(dec, data[1-toggle], len[1-toggle], out, output_samples, 0); + if (output_samples != 320) {printf("[frame %d] decoder return value %d\n", silk_frame_counter, output_samples); exit(1);} } } else { output_samples = opus_decode(dec, lost ? NULL : data[toggle], len[toggle], out, output_samples, 0); + if (output_samples != 320) {printf("[frame %d] decoder return value %d\n", silk_frame_counter, output_samples); exit(1);} } if (output_samples>0) { |