DRED integration work in progress

This commit is contained in:
Jean-Marc Valin 2022-12-06 16:09:39 -05:00
parent 0edb3954e8
commit 8623012b30
No known key found for this signature in database
GPG key ID: 531A52533318F00A
5 changed files with 23 additions and 7 deletions

View file

@ -47,7 +47,7 @@ void dred_deinit_decoder(DREDDec *dec)
DRED_rdovae_destroy_decoder(dec->rdovae_dec); DRED_rdovae_destroy_decoder(dec->rdovae_dec);
} }
void dred_decode_redundancy_package(DREDDec *dec, float *features, opus_uint8 *bytes, int num_bytes) void dred_decode_redundancy_package(DREDDec *dec, float *features, const opus_uint8 *bytes, int num_bytes)
{ {
const opus_uint16 *p0 = DRED_rdovae_get_p0_pointer(); const opus_uint16 *p0 = DRED_rdovae_get_p0_pointer();
const opus_uint16 *quant_scales = DRED_rdovae_get_quant_scales_pointer(); const opus_uint16 *quant_scales = DRED_rdovae_get_quant_scales_pointer();
@ -64,7 +64,7 @@ void dred_decode_redundancy_package(DREDDec *dec, float *features, opus_uint8 *b
celt_assert(DRED_NUM_REDUNDANCY_FRAMES % 2 == 0); celt_assert(DRED_NUM_REDUNDANCY_FRAMES % 2 == 0);
/* decode initial state and initialize RDOVAE decoder */ /* decode initial state and initialize RDOVAE decoder */
ec_dec_init(&dec->ec_dec, bytes, num_bytes); ec_dec_init(&dec->ec_dec, (unsigned char*)bytes, num_bytes);
dred_decode_state(&dec->ec_dec, state); dred_decode_state(&dec->ec_dec, state);
DRED_rdovae_dec_init_states(dec->rdovae_dec, state); DRED_rdovae_dec_init_states(dec->rdovae_dec, state);

View file

@ -39,4 +39,4 @@ void init_dred_decoder(DREDDec *dec);
void dred_deinit_decoder(DREDDec *dec); void dred_deinit_decoder(DREDDec *dec);
void dred_decode_redundancy_package(DREDDec *dec, float *features, opus_uint8 *bytes, int num_bytes); void dred_decode_redundancy_package(DREDDec *dec, float *features, const opus_uint8 *bytes, int num_bytes);

View file

@ -38,7 +38,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "lpcnet.h" #include "lpcnet.h"
#endif #endif
#ifdef ENABLE_NEURAL_FEC
#include "dred_encoder.h" #include "dred_encoder.h"
#include "dred_decoder.h"
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -258,6 +261,10 @@ typedef struct {
#ifdef NEURAL_PLC #ifdef NEURAL_PLC
/* FIXME: We should include the state struct directly to preserve the state shadow copy property. */ /* FIXME: We should include the state struct directly to preserve the state shadow copy property. */
LPCNetPLCState *lpcnet; LPCNetPLCState *lpcnet;
#ifdef ENABLE_NEURAL_FEC
DREDDec dred_decoder;
float fec_features[2*DRED_NUM_REDUNDANCY_FRAMES*DRED_NUM_FEATURES];
#endif
#endif #endif
} silk_PLC_struct; } silk_PLC_struct;

View file

@ -1054,6 +1054,8 @@ int opus_decoder_dred_input(OpusDecoder *st, const unsigned char *data,
/* Get the padding section of the packet. */ /* Get the padding section of the packet. */
ret = opus_packet_parse_impl(data, len, 0, NULL, frames, size, NULL, NULL, &data0, &len0); ret = opus_packet_parse_impl(data, len, 0, NULL, frames, size, NULL, NULL, &data0, &len0);
if (ret < 0)
return ret;
data = data0; data = data0;
len = len0; len = len0;
/* Scan extensions in order until we find the earliest frame with DRED data. */ /* Scan extensions in order until we find the earliest frame with DRED data. */
@ -1085,6 +1087,9 @@ int opus_decoder_dred_input(OpusDecoder *st, const unsigned char *data,
} }
if (payload != NULL) if (payload != NULL)
{ {
silk_decoder_state *silk_dec;
silk_dec = (silk_decoder_state*)((char*)st+st->silk_dec_offset);
dred_decode_redundancy_package(&silk_dec->sPLC.dred_decoder, silk_dec->sPLC.fec_features, payload, payload_len);
/* Found something -- do the decoding. */ /* Found something -- do the decoding. */
return 1; return 1;
} }

View file

@ -2179,15 +2179,19 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
} }
/* Count ToC and redundancy */ /* Count ToC and redundancy */
ret += 1+redundancy_bytes; ret += 1+redundancy_bytes;
if (0) { #ifdef ENABLE_NEURAL_FEC
opus_extension_data extension = {127, 0, (const unsigned char *)"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 50}; if (1) {
DREDEnc *dred = &((silk_encoder*)silk_enc)->state_Fxx[0].sCmn.dred_encoder;
opus_extension_data extension = {127, 0, dred->ec_buffer, dred->ec_encoder.storage};
ret = opus_packet_pad_impl(data, ret, max_data_bytes, !st->use_vbr, &extension, 1); ret = opus_packet_pad_impl(data, ret, max_data_bytes, !st->use_vbr, &extension, 1);
if (ret < 0) if (ret < 0)
{ {
RESTORE_STACK; RESTORE_STACK;
return OPUS_INTERNAL_ERROR; return OPUS_INTERNAL_ERROR;
} }
} else if (!st->use_vbr) } else
#endif
if (!st->use_vbr)
{ {
if (opus_packet_pad(data, ret, max_data_bytes) != OPUS_OK) if (opus_packet_pad(data, ret, max_data_bytes) != OPUS_OK)
{ {