ref: c64b321e7a564c673ab0322e4df895be51ec29a2
parent: 39f68ce356b8377a27759cd2356ec9b366e639b9
author: Jean-Marc Valin <jmvalin@amazon.com>
date: Tue May 23 14:31:45 EDT 2023
DRED API update output() renamed to decode(), dred objects using alloc() and free(), OpusDRED now passed as cost for decoding.
--- a/include/opus.h
+++ b/include/opus.h
@@ -557,12 +557,12 @@
/** Allocates and initializes a DRED state.
* @param [out] error <tt>int*</tt>: #OPUS_OK Success or @ref opus_errorcodes
*/
-OPUS_EXPORT OpusDRED *opus_dred_create(int *error);
+OPUS_EXPORT OpusDRED *opus_dred_alloc(int *error);
/** Frees an <code>OpusDRED</code> allocated by opus_dred_create().
* @param[in] st <tt>OpusDRED*</tt>: State to be freed.
*/
-OPUS_EXPORT void opus_dred_destroy(OpusDRED *dec);
+OPUS_EXPORT void opus_dred_free(OpusDRED *dec);
/** Decode an Opus DRED packet.
* @param [in] dred <tt>OpusDRED*</tt>: DRED state
@@ -592,7 +592,7 @@
* frame_size <b>must</b> be a multiple of 2.5 ms.
* @returns Number of decoded samples or @ref opus_errorcodes
*/
-OPUS_EXPORT int opus_decoder_dred_output(OpusDecoder *st, OpusDRED *dred, opus_int32 dred_offset, opus_int16 *pcm, opus_int32 frame_size);
+OPUS_EXPORT int opus_decoder_dred_decode(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, opus_int16 *pcm, opus_int32 frame_size);
/** Decode audio from an Opus DRED packet with floating point output.
* @param [in] st <tt>OpusDecoder*</tt>: Decoder state
@@ -604,7 +604,7 @@
* frame_size <b>must</b> be a multiple of 2.5 ms.
* @returns Number of decoded samples or @ref opus_errorcodes
*/
-OPUS_EXPORT int opus_decoder_dred_output_float(OpusDecoder *st, OpusDRED *dred, opus_int32 dred_offset, float *pcm, opus_int32 frame_size);
+OPUS_EXPORT int opus_decoder_dred_decode_float(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, float *pcm, opus_int32 frame_size);
/** Parse an opus packet into one or more frames.
--- a/silk/dred_decoder.c
+++ b/silk/dred_decoder.c
@@ -37,29 +37,7 @@
#include "celt/entdec.h"
-int opus_dred_get_size(void)
-{
- return sizeof(OpusDRED);
-}
-OpusDRED *opus_dred_create(int *error)
-{
- OpusDRED *dec;
- dec = (OpusDRED *)opus_alloc(opus_dred_get_size());
- if (dec == NULL)
- {
- if (error)
- *error = OPUS_ALLOC_FAIL;
- return NULL;
- }
- return dec;
-
-}
-
-void opus_dred_destroy(OpusDRED *dec)
-{
- free(dec);
-}
int dred_ec_decode(OpusDRED *dec, const opus_uint8 *bytes, int num_bytes, int min_feature_frames)
{
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -634,7 +634,7 @@
int opus_decode_native(OpusDecoder *st, const unsigned char *data,
opus_int32 len, opus_val16 *pcm, int frame_size, int decode_fec,
- int self_delimited, opus_int32 *packet_offset, int soft_clip, OpusDRED *dred, opus_int32 dred_offset)
+ int self_delimited, opus_int32 *packet_offset, int soft_clip, const OpusDRED *dred, opus_int32 dred_offset)
{
int i, nb_samples;
int count, offset;
@@ -1207,6 +1207,41 @@
}
#endif
+int opus_dred_get_size(void)
+{
+#ifdef ENABLE_NEURAL_FEC
+ return sizeof(OpusDRED);
+#else
+ return 0;
+#endif
+}
+
+OpusDRED *opus_dred_alloc(int *error)
+{
+#ifdef ENABLE_NEURAL_FEC
+ OpusDRED *dec;
+ dec = (OpusDRED *)opus_alloc(opus_dred_get_size());
+ if (dec == NULL)
+ {
+ if (error)
+ *error = OPUS_ALLOC_FAIL;
+ return NULL;
+ }
+ return dec;
+#else
+ if (error)
+ *error = OPUS_UNIMPLEMENTED;
+ return NULL;
+#endif
+}
+
+void opus_dred_free(OpusDRED *dec)
+{
+#ifdef ENABLE_NEURAL_FEC
+ free(dec);
+#endif
+}
+
int opus_dred_parse(OpusDREDDecoder *dred_dec, OpusDRED *dred, const unsigned char *data, opus_int32 len, opus_int32 max_dred_samples, opus_int32 sampling_rate, int defer_processing)
{
#ifdef ENABLE_NEURAL_FEC
@@ -1261,7 +1296,7 @@
#endif
}
-int opus_decoder_dred_output(OpusDecoder *st, OpusDRED *dred, opus_int32 dred_offset, opus_int16 *pcm, opus_int32 frame_size)
+int opus_decoder_dred_decode(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, opus_int16 *pcm, opus_int32 frame_size)
{
#ifdef ENABLE_NEURAL_FEC
VARDECL(float, out);
@@ -1295,7 +1330,7 @@
#endif
}
-int opus_decoder_dred_output_float(OpusDecoder *st, OpusDRED *dred, opus_int32 dred_offset, float *pcm, opus_int32 frame_size)
+int opus_decoder_dred_decode_float(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, float *pcm, opus_int32 frame_size)
{
#ifdef ENABLE_NEURAL_FEC
if(frame_size<=0)
--- a/src/opus_demo.c
+++ b/src/opus_demo.c
@@ -632,7 +632,7 @@
frame_size = 2*48000;
}
dred_dec = opus_dred_decoder_create(&err);
- dred = opus_dred_create(&err);
+ dred = opus_dred_alloc(&err);
while (!stop)
{
if (delayed_celt)
@@ -815,7 +815,7 @@
output_samples = opus_decode(dec, data, len, out, output_samples, 1);
} else if (fr < lost_count) {
opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&output_samples));
- output_samples = opus_decoder_dred_output(dec, dred, (lost_count-fr)*sampling_rate/100, out, output_samples);
+ output_samples = opus_decoder_dred_decode(dec, dred, (lost_count-fr)*sampling_rate/100, out, output_samples);
} else {
output_samples = max_frame_size;
output_samples = opus_decode(dec, data, len, out, output_samples, 0);
@@ -918,7 +918,7 @@
failure:
opus_encoder_destroy(enc);
opus_decoder_destroy(dec);
- opus_dred_destroy(dred);
+ opus_dred_free(dred);
opus_dred_decoder_destroy(dred_dec);
free(data);
if (fin)
--- a/src/opus_private.h
+++ b/src/opus_private.h
@@ -155,7 +155,7 @@
int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 len,
opus_val16 *pcm, int frame_size, int decode_fec, int self_delimited,
- opus_int32 *packet_offset, int soft_clip, OpusDRED *dred, opus_int32 dred_offset);
+ opus_int32 *packet_offset, int soft_clip, const OpusDRED *dred, opus_int32 dred_offset);
/* Make sure everything is properly aligned. */
static OPUS_INLINE int align(int i)
--
⑨