shithub: opus

Download patch

ref: c4cb071f7512b00b940524c785f92c4545ed91d2
parent: 634defacdca0e5b701ae3967154248fa886734b4
author: Jean-Marc Valin <jmvalin@amazon.com>
date: Tue Dec 6 20:43:29 EST 2022

DRED: Decode variable number of frames

--- a/silk/dred_decoder.c
+++ b/silk/dred_decoder.c
@@ -47,7 +47,7 @@
     DRED_rdovae_destroy_decoder(dec->rdovae_dec);
 }
 
-void dred_decode_redundancy_package(DREDDec *dec, float *features, const opus_uint8 *bytes, int num_bytes)
+int dred_decode_redundancy_package(DREDDec *dec, float *features, const opus_uint8 *bytes, int num_bytes, int max_fec_frames)
 {
     const opus_uint16 *p0              = DRED_rdovae_get_p0_pointer();
     const opus_uint16 *quant_scales    = DRED_rdovae_get_quant_scales_pointer();
@@ -70,7 +70,7 @@
     DRED_rdovae_dec_init_states(dec->rdovae_dec, state);
 
     /* decode newest to oldest and store oldest to newest */
-    for (i = 0; i < DRED_NUM_REDUNDANCY_FRAMES; i += 2)
+    for (i = 0; i < IMIN(DRED_NUM_REDUNDANCY_FRAMES, (max_fec_frames+1)/2); i += 2)
     {
         /* FIXME: Figure out how to avoid missing a last frame that would take up < 8 bits. */
         if (8*num_bytes - ec_tell(&ec) <= 7)
@@ -85,10 +85,11 @@
             p0 + offset
             );
 
-        offset = (2 * DRED_NUM_REDUNDANCY_FRAMES - 4 - 2 * i) * DRED_NUM_FEATURES;
+        offset = 2 * i * DRED_NUM_FEATURES;
         DRED_rdovae_decode_qframe(
             dec->rdovae_dec,
             features + offset,
             latents);
     }
+    return 2*i;
 }
--- a/silk/dred_decoder.h
+++ b/silk/dred_decoder.h
@@ -38,4 +38,4 @@
 
 void dred_deinit_decoder(DREDDec *dec);
 
-void dred_decode_redundancy_package(DREDDec *dec, float *features, const opus_uint8 *bytes, int num_bytes);
+int dred_decode_redundancy_package(DREDDec *dec, float *features, const opus_uint8 *bytes, int num_bytes, int max_fec_frames);
--- a/silk/structs.h
+++ b/silk/structs.h
@@ -264,6 +264,7 @@
 #ifdef ENABLE_NEURAL_FEC
     DREDDec                     dred_decoder;
     float                       fec_features[2*DRED_NUM_REDUNDANCY_FRAMES*DRED_NUM_FEATURES];
+    int                         nb_fec_frames;
 #endif
 #endif
 } silk_PLC_struct;
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -1090,11 +1090,13 @@
    }
    if (payload != NULL)
    {
+      int max_fec_frames;
       silk_decoder_state *silk_dec;
       silk_dec = (silk_decoder_state*)((char*)st+st->silk_dec_offset);
       /*printf("Found: %p of size %d\n", payload, payload_len);*/
-      dred_decode_redundancy_package(&silk_dec->sPLC.dred_decoder, silk_dec->sPLC.fec_features, payload, payload_len);
-      /* Found something -- do the decoding. */
+      max_fec_frames = IMIN(2 + offset, 2*DRED_NUM_REDUNDANCY_FRAMES);
+      silk_dec->sPLC.nb_fec_frames = dred_decode_redundancy_package(&silk_dec->sPLC.dred_decoder, silk_dec->sPLC.fec_features, payload, payload_len, max_fec_frames);
+      /*printf("%d\n", silk_dec->sPLC.nb_fec_frames);*/
       return 1;
    }
    return 0;
--