aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2024-03-03 02:55:37 -0500
committerJean-Marc Valin <jmvalin@jmvalin.ca>2024-03-03 02:55:37 -0500
commit4eca11c001294a2495f405773795b6d919605ca5 (patch)
tree8d1067d0c558a0c8bed0b455d6b5afdd796d20c1
parent32d4d874accd322f7e237b734678542fea88393b (diff)
downloadlibopus-4eca11c001294a2495f405773795b6d919605ca5.tar.gz
Avoid OSCE crash if weights aren't loaded
-rw-r--r--dnn/osce.c7
-rw-r--r--dnn/osce_structs.h1
-rw-r--r--silk/dec_API.c6
3 files changed, 11 insertions, 3 deletions
diff --git a/dnn/osce.c b/dnn/osce.c
index fb446f9a..c412d5a1 100644
--- a/dnn/osce.c
+++ b/dnn/osce.c
@@ -927,6 +927,7 @@ void osce_enhance_frame(
float numbits[2];
int periods[4];
int i;
+ int method;
/* enhancement only implemented for 20 ms frame at 16kHz */
if (psDec->fs_kHz != 16 || psDec->nb_subfr != 4)
@@ -943,7 +944,11 @@ void osce_enhance_frame(
in_buffer[i] = ((float) xq[i]) * (1.f/32768.f);
}
- switch(psDec->osce.method)
+ if (model->loaded)
+ method = psDec->osce.method;
+ else
+ method = OSCE_METHOD_NONE;
+ switch(method)
{
case OSCE_METHOD_NONE:
OPUS_COPY(out_buffer, in_buffer, 320);
diff --git a/dnn/osce_structs.h b/dnn/osce_structs.h
index e5a61949..6358681f 100644
--- a/dnn/osce_structs.h
+++ b/dnn/osce_structs.h
@@ -104,6 +104,7 @@ typedef struct {
/* OSCEModel */
typedef struct {
+ int loaded;
#ifndef DISABLE_LACE
LACE lace;
#endif
diff --git a/silk/dec_API.c b/silk/dec_API.c
index e4ae8343..c1091d13 100644
--- a/silk/dec_API.c
+++ b/silk/dec_API.c
@@ -64,7 +64,7 @@ opus_int silk_LoadOSCEModels(void *decState, const unsigned char *data, int len)
opus_int ret = SILK_NO_ERROR;
ret = osce_load_models(&((silk_decoder *)decState)->osce_model, data, len);
-
+ ((silk_decoder *)decState)->osce_model.loaded = (ret == 0);
return ret;
#else
(void) decState;
@@ -110,7 +110,9 @@ opus_int silk_InitDecoder( /* O Returns error co
{
opus_int n, ret = SILK_NO_ERROR;
silk_decoder_state *channel_state = ((silk_decoder *)decState)->channel_state;
-
+#ifdef ENABLE_OSCE
+ ((silk_decoder *)decState)->osce_model.loaded = 0;
+#endif
#ifndef USE_WEIGHTS_FILE
/* load osce models */
silk_LoadOSCEModels(decState, NULL, 0);