DRED API update

output() renamed to decode(), dred objects using alloc() and free(),
OpusDRED now passed as cost for decoding.
This commit is contained in:
Jean-Marc Valin 2023-05-23 18:31:45 -04:00
parent 39f68ce356
commit c64b321e7a
No known key found for this signature in database
GPG key ID: 531A52533318F00A
5 changed files with 46 additions and 33 deletions

View file

@ -557,12 +557,12 @@ OPUS_EXPORT int opus_dred_get_size(void);
/** 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 @@ OPUS_EXPORT int opus_dred_process(OpusDREDDecoder *dred_dec, const OpusDRED *src
* 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 @@ OPUS_EXPORT int opus_decoder_dred_output(OpusDecoder *st, OpusDRED *dred, opus_i
* 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.

View file

@ -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)
{

View file

@ -634,7 +634,7 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
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 @@ static int dred_find_payload(const unsigned char *data, opus_int32 len, const un
}
#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 @@ int opus_dred_process(OpusDREDDecoder *dred_dec, const OpusDRED *src, OpusDRED *
#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 @@ int opus_decoder_dred_output(OpusDecoder *st, OpusDRED *dred, opus_int32 dred_of
#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)

View file

@ -632,7 +632,7 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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)

View file

@ -155,7 +155,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
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)