summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@amazon.com>2023-05-12 19:05:31 -0400
committerJean-Marc Valin <jmvalin@amazon.com>2023-05-12 19:05:31 -0400
commitdc976e5dd4a1bcf639a65b50c3dbb2c6720cd12d (patch)
tree74c7ab22b35fcdd456604773ea86df84b861048e
parent8706458f689866af3e955797db33f02f7ebd0f06 (diff)
downloadopus-dc976e5dd4a1bcf639a65b50c3dbb2c6720cd12d.tar.gz
DRED refactoring/renaming
-rw-r--r--include/opus.h13
-rw-r--r--silk/dred_decoder.c36
-rw-r--r--silk/dred_decoder.h13
-rw-r--r--src/opus_decoder.c8
-rw-r--r--src/opus_demo.c2
5 files changed, 56 insertions, 16 deletions
diff --git a/include/opus.h b/include/opus.h
index d96c9d6b..8185f2ef 100644
--- a/include/opus.h
+++ b/include/opus.h
@@ -398,6 +398,9 @@ OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NON
*/
typedef struct OpusDecoder OpusDecoder;
+
+typedef struct OpusDRED OpusDRED;
+
/** Gets the size of an <code>OpusDecoder</code> structure.
* @param [in] channels <tt>int</tt>: Number of channels.
* This must be 1 or 2.
@@ -511,7 +514,15 @@ OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NON
*/
OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st);
-OPUS_EXPORT int opus_decoder_dred_input(OpusDecoder *st, const unsigned char *data,
+OPUS_EXPORT int opus_dred_get_size(void);
+
+OPUS_EXPORT int opus_dred_init(OpusDRED *dec);
+
+OPUS_EXPORT OpusDRED *opus_dred_create(int *error);
+
+OPUS_EXPORT void opus_dred_destroy(OpusDRED *dec);
+
+OPUS_EXPORT int opus_dred_parse(OpusDecoder *st, const unsigned char *data,
opus_int32 len, int offset) OPUS_ARG_NONNULL(1);
/** Parse an opus packet into one or more frames.
diff --git a/silk/dred_decoder.c b/silk/dred_decoder.c
index 54a47926..5240a67a 100644
--- a/silk/dred_decoder.c
+++ b/silk/dred_decoder.c
@@ -31,23 +31,53 @@
#include "config.h"
#endif
+#include "os_support.h"
#include "dred_decoder.h"
#include "dred_coding.h"
#include "celt/entdec.h"
-void init_dred_decoder(DREDDec *dec)
+int opus_dred_init(OpusDRED *dec)
{
memset(dec, 0, sizeof(*dec));
dec->rdovae_dec = DRED_rdovae_create_decoder();
+ return OPUS_OK;
}
-void dred_deinit_decoder(DREDDec *dec)
+int opus_dred_get_size(void)
+{
+ return sizeof(OpusDRED);
+}
+
+OpusDRED *opus_dred_create(int *error)
+{
+ int ret;
+ OpusDRED *dec;
+ dec = (OpusDRED *)opus_alloc(opus_dred_get_size());
+ if (dec == NULL)
+ {
+ if (error)
+ *error = OPUS_ALLOC_FAIL;
+ return NULL;
+ }
+ ret = opus_dred_init(dec);
+ if (error)
+ *error = ret;
+ if (ret != OPUS_OK)
+ {
+ opus_free(dec);
+ dec = NULL;
+ }
+ return dec;
+
+}
+
+void opus_dred_destroy(OpusDRED *dec)
{
DRED_rdovae_destroy_decoder(dec->rdovae_dec);
}
-int dred_decode_redundancy_package(DREDDec *dec, float *features, const opus_uint8 *bytes, int num_bytes, int min_feature_frames)
+int dred_decode_redundancy_package(OpusDRED *dec, float *features, const opus_uint8 *bytes, int num_bytes, int min_feature_frames)
{
const opus_uint16 *p0 = DRED_rdovae_get_p0_pointer();
const opus_uint16 *quant_scales = DRED_rdovae_get_quant_scales_pointer();
diff --git a/silk/dred_decoder.h b/silk/dred_decoder.h
index 633e4c83..2c739d4a 100644
--- a/silk/dred_decoder.h
+++ b/silk/dred_decoder.h
@@ -25,17 +25,16 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "opus.h"
#include "dred_config.h"
#include "dred_rdovae.h"
#include "entcode.h"
-typedef struct {
+struct OpusDRED {
RDOVAEDec *rdovae_dec;
-} DREDDec;
+ float fec_features[2*DRED_NUM_REDUNDANCY_FRAMES*DRED_NUM_FEATURES];
+ int nb_fec_frames;
+};
-void init_dred_decoder(DREDDec *dec);
-
-void dred_deinit_decoder(DREDDec *dec);
-
-int dred_decode_redundancy_package(DREDDec *dec, float *features, const opus_uint8 *bytes, int num_bytes, int min_feature_frames);
+int dred_decode_redundancy_package(OpusDRED *dec, float *features, const opus_uint8 *bytes, int num_bytes, int min_feature_frames);
diff --git a/src/opus_decoder.c b/src/opus_decoder.c
index 1341c79a..f8880ec3 100644
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -75,7 +75,7 @@ struct OpusDecoder {
opus_val16 softclip_mem[2];
#endif
#ifdef ENABLE_NEURAL_FEC
- DREDDec dred_decoder;
+ OpusDRED dred_decoder;
float fec_features[2*DRED_NUM_REDUNDANCY_FRAMES*DRED_NUM_FEATURES];
int nb_fec_frames;
#endif
@@ -156,7 +156,7 @@ int opus_decoder_init(OpusDecoder *st, opus_int32 Fs, int channels)
celt_decoder_ctl(celt_dec, CELT_SET_SIGNALLING(0));
#ifdef ENABLE_NEURAL_FEC
- init_dred_decoder(&st->dred_decoder);
+ opus_dred_init(&st->dred_decoder);
#endif
st->prev_mode = 0;
st->frame_size = Fs/400;
@@ -913,7 +913,7 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...)
st->stream_channels = st->channels;
st->frame_size = st->Fs/400;
#ifdef ENABLE_NEURAL_FEC
- init_dred_decoder(&st->dred_decoder);
+ opus_dred_init(&st->dred_decoder);
#endif
}
break;
@@ -1071,7 +1071,7 @@ int opus_decoder_get_nb_samples(const OpusDecoder *dec,
return opus_packet_get_nb_samples(packet, len, dec->Fs);
}
-int opus_decoder_dred_input(OpusDecoder *st, const unsigned char *data,
+int opus_dred_parse(OpusDecoder *st, const unsigned char *data,
opus_int32 len, int offset)
{
#ifdef ENABLE_NEURAL_FEC
diff --git a/src/opus_demo.c b/src/opus_demo.c
index 294dd858..e657b5a5 100644
--- a/src/opus_demo.c
+++ b/src/opus_demo.c
@@ -801,7 +801,7 @@ int main(int argc, char *argv[])
opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&output_samples));
dred_input = lost_count*output_samples*100/sampling_rate;
/* Only decode the amount we need to fill in the gap. */
- opus_decoder_dred_input(dec, data, len, IMIN(100, IMAX(0, dred_input)));
+ opus_dred_parse(dec, data, len, IMIN(100, IMAX(0, dred_input)));
}
/* FIXME: Figure out how to trigger the decoder when the last packet of the file is lost. */
for (fr=0;fr<run_decoder;fr++) {