summaryrefslogtreecommitdiff
path: root/src/opus_multistream_decoder.c
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2013-10-11 20:41:30 -0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2013-10-11 20:41:53 -0400
commitdbc83d316c2c221f9790e6162c9942082db8362a (patch)
treeb0b8d81ca58b4cc3bddb5e9af2ae65ad1593b546 /src/opus_multistream_decoder.c
parent970d0529eeaa97f7c06fb37d6bd1b5658ad1e68f (diff)
downloadopus-dbc83d316c2c221f9790e6162c9942082db8362a.tar.gz
Cleaning up multistream packet validation
Diffstat (limited to 'src/opus_multistream_decoder.c')
-rw-r--r--src/opus_multistream_decoder.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/opus_multistream_decoder.c b/src/opus_multistream_decoder.c
index d04a99f3..f4b2d1be 100644
--- a/src/opus_multistream_decoder.c
+++ b/src/opus_multistream_decoder.c
@@ -153,7 +153,7 @@ typedef void (*opus_copy_channel_out_func)(
);
static int opus_multistream_packet_validate(const unsigned char *data,
- opus_int32 len, int nb_streams)
+ opus_int32 len, int nb_streams, opus_int32 Fs)
{
int s;
int i;
@@ -173,14 +173,14 @@ static int opus_multistream_packet_validate(const unsigned char *data,
return count;
for (i=0;i<count;i++)
offset += size[i];
- tmp_samples = opus_packet_get_nb_samples(data, offset, 48000);
+ tmp_samples = opus_packet_get_nb_samples(data, offset, Fs);
if (s!=0 && samples != tmp_samples)
return OPUS_INVALID_PACKET;
samples = tmp_samples;
data += offset;
len -= offset;
}
- return OPUS_OK;
+ return samples;
}
static int opus_multistream_decode_native(
@@ -225,11 +225,15 @@ static int opus_multistream_decode_native(
}
if (!do_plc)
{
- int ret = opus_multistream_packet_validate(data, len, st->layout.nb_coupled_streams);
+ int ret = opus_multistream_packet_validate(data, len, st->layout.nb_coupled_streams, Fs);
if (ret < 0)
{
RESTORE_STACK;
return ret;
+ } else if (ret > frame_size)
+ {
+ RESTORE_STACK;
+ return OPUS_BUFFER_TOO_SMALL;
}
}
for (s=0;s<st->layout.nb_streams;s++)
@@ -243,22 +247,12 @@ static int opus_multistream_decode_native(
if (!do_plc && len<=0)
{
RESTORE_STACK;
- return OPUS_INVALID_PACKET;
+ return OPUS_INTERNAL_ERROR;
}
packet_offset = 0;
ret = opus_decode_native(dec, data, len, buf, frame_size, decode_fec, s!=st->layout.nb_streams-1, &packet_offset, soft_clip);
data += packet_offset;
len -= packet_offset;
- if (ret > frame_size)
- {
- RESTORE_STACK;
- return OPUS_BUFFER_TOO_SMALL;
- }
- if (s>0 && ret != frame_size)
- {
- RESTORE_STACK;
- return OPUS_INVALID_PACKET;
- }
if (ret <= 0)
{
RESTORE_STACK;