Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@amazon.com>2023-09-16 07:59:57 +0300
committerJean-Marc Valin <jmvalin@amazon.com>2023-09-21 01:04:08 +0300
commit52c15629eef8e1d913ce67c1b46f27301854b05d (patch)
treed323c2faec05ab851fdb0d6987b89a0a93aec599
parent71da9781eb82c9ec9f5edb88295f8fd8853df0bf (diff)
Handle the case where the initial state didn't fit
-rw-r--r--silk/dred_encoder.c5
-rw-r--r--src/opus_encoder.c37
2 files changed, 24 insertions, 18 deletions
diff --git a/silk/dred_encoder.c b/silk/dred_encoder.c
index 7b34cefe..41228334 100644
--- a/silk/dred_encoder.c
+++ b/silk/dred_encoder.c
@@ -238,6 +238,9 @@ int dred_encode_silk_frame(const DREDEnc *enc, unsigned char *buf, int max_chunk
dead_zone + state_qoffset,
r + state_qoffset,
p0 + state_qoffset);
+ if (ec_tell(&ec_encoder) > 8*max_bytes) {
+ return 0;
+ }
for (i = 0; i < IMIN(2*max_chunks, enc->latents_buffer_fill-enc->latent_offset-1); i += 2)
{
ec_enc ec_bak;
@@ -256,6 +259,8 @@ int dred_encode_silk_frame(const DREDEnc *enc, unsigned char *buf, int max_chunk
);
if (ec_tell(&ec_encoder) > 8*max_bytes) {
ec_encoder = ec_bak;
+ /* If we haven't been able to code one chunk, give up on DRED completely. */
+ if (i==0) return 0;
break;
}
}
diff --git a/src/opus_encoder.c b/src/opus_encoder.c
index cb03a1e5..7291c814 100644
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -1122,6 +1122,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
int analysis_read_subframe_bak=-1;
int is_silence = 0;
#endif
+ int apply_padding;
#ifdef ENABLE_NEURAL_FEC
opus_int32 dred_bitrate_bps;
#endif
@@ -2252,6 +2253,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
}
/* Count ToC and redundancy */
ret += 1+redundancy_bytes;
+ apply_padding = !st->use_vbr;
#ifdef ENABLE_NEURAL_FEC
if (st->dred_duration > 0) {
opus_extension_data extension;
@@ -2271,26 +2273,25 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
buf[1] = DRED_EXPERIMENTAL_VERSION;
#endif
dred_bytes = dred_encode_silk_frame(&st->dred_encoder, buf+DRED_EXPERIMENTAL_BYTES, dred_chunks, dred_bytes_left-DRED_EXPERIMENTAL_BYTES);
- dred_bytes += DRED_EXPERIMENTAL_BYTES;
- celt_assert(dred_bytes <= dred_bytes_left);
- extension.id = DRED_EXTENSION_ID;
- extension.frame = 0;
- extension.data = buf;
- extension.len = dred_bytes;
- ret = opus_packet_pad_impl(data, ret, max_data_bytes, !st->use_vbr, &extension, 1);
- } else if (!st->use_vbr) {
- ret = opus_packet_pad(data, ret, max_data_bytes);
- if (ret == OPUS_OK)
- ret = max_data_bytes;
- }
- if (ret < 0)
- {
- RESTORE_STACK;
- return OPUS_INTERNAL_ERROR;
+ if (dred_bytes > 0) {
+ dred_bytes += DRED_EXPERIMENTAL_BYTES;
+ celt_assert(dred_bytes <= dred_bytes_left);
+ extension.id = DRED_EXTENSION_ID;
+ extension.frame = 0;
+ extension.data = buf;
+ extension.len = dred_bytes;
+ ret = opus_packet_pad_impl(data, ret, max_data_bytes, !st->use_vbr, &extension, 1);
+ if (ret < 0)
+ {
+ RESTORE_STACK;
+ return OPUS_INTERNAL_ERROR;
+ }
+ apply_padding = 0;
+ }
}
- } else
+ }
#endif
- if (!st->use_vbr)
+ if (apply_padding)
{
if (opus_packet_pad(data, ret, max_data_bytes) != OPUS_OK)
{