summaryrefslogtreecommitdiff
path: root/src/opus_decoder.c
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2014-01-07 21:00:18 -0500
committerJean-Marc Valin <jmvalin@jmvalin.ca>2014-01-07 21:00:18 -0500
commitb76888dc866868c073e5f94a63ccb80912a5be41 (patch)
tree530be0d200f3a1666b63e4066073119645c634cd /src/opus_decoder.c
parent9134e96cb24fa3a4c5249e3940a163d889fe692d (diff)
downloadopus-b76888dc866868c073e5f94a63ccb80912a5be41.tar.gz
Preventing unnecessary stack use when using a large decode buffer
This was causing pseudostack builds to fail because opus_demo uses a 2-second buffer.
Diffstat (limited to 'src/opus_decoder.c')
-rw-r--r--src/opus_decoder.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/opus_decoder.c b/src/opus_decoder.c
index 397446f2..3d97dd1c 100644
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -722,6 +722,7 @@ int opus_decode_float(OpusDecoder *st, const unsigned char *data,
{
VARDECL(opus_int16, out);
int ret, i;
+ int nb_samples;
ALLOC_STACK;
if(frame_size<=0)
@@ -729,6 +730,14 @@ int opus_decode_float(OpusDecoder *st, const unsigned char *data,
RESTORE_STACK;
return OPUS_BAD_ARG;
}
+ if (data != NULL && len > 0)
+ {
+ nb_samples = opus_decoder_get_nb_samples(st, data, len);
+ if (nb_samples>0)
+ frame_size = IMIN(frame_size, nb_samples);
+ else
+ return OPUS_INVALID_PACKET;
+ }
ALLOC(out, frame_size*st->channels, opus_int16);
ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 0);
@@ -749,6 +758,7 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
{
VARDECL(float, out);
int ret, i;
+ int nb_samples;
ALLOC_STACK;
if(frame_size<=0)
@@ -757,6 +767,14 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
return OPUS_BAD_ARG;
}
+ if (data != NULL && len > 0)
+ {
+ nb_samples = opus_decoder_get_nb_samples(st, data, len);
+ if (nb_samples>0)
+ frame_size = IMIN(frame_size, nb_samples);
+ else
+ return OPUS_INVALID_PACKET;
+ }
ALLOC(out, frame_size*st->channels, float);
ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 1);