shithub: opus

Download patch

ref: 906ee4b2369d7f0d5526274ee97d39da9ba616ad
parent: 34a4ba0d4f813ffcbcc5a4952c7bb9265e774775
author: Jean-Marc Valin <jmvalin@amazon.com>
date: Fri May 12 15:05:31 EDT 2023

DRED refactoring/renaming

--- a/include/opus.h
+++ b/include/opus.h
@@ -398,6 +398,9 @@
   */
 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 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.
--- 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();
--- 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);
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -75,7 +75,7 @@
    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 @@
    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 @@
       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 @@
    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
--- a/src/opus_demo.c
+++ b/src/opus_demo.c
@@ -801,7 +801,7 @@
                 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++) {
--