ref: 70e3c348228a28ea7f62def5ecbce71b975a517b
parent: fa2578bf4791be31b67748ce6a815829d9a6f175
author: Jean-Marc Valin <[email protected]>
date: Fri Sep 9 12:51:01 EDT 2016
Fixing failure due to CBR allocating zero byte to a stream
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -1336,7 +1336,8 @@
/* We need to make sure that "int" values always fit in 16 bits. */
cbrBytes = IMIN( (3*st->bitrate_bps/8 + frame_rate3/2)/frame_rate3, max_data_bytes);
st->bitrate_bps = cbrBytes*(opus_int32)frame_rate3*8/3;
- max_data_bytes = cbrBytes;
+ /* Make sure we provide at least one byte to avoid failing. */
+ max_data_bytes = IMAX(1, cbrBytes);
}
if (max_data_bytes<3 || st->bitrate_bps < 3*frame_rate*8
|| (frame_rate<50 && (max_data_bytes*frame_rate<300 || st->bitrate_bps < 2400)))
@@ -1363,6 +1364,8 @@
ret = opus_packet_pad(data, ret, max_data_bytes);
if (ret == OPUS_OK)
ret = max_data_bytes;
+ else
+ ret = OPUS_INTERNAL_ERROR;
}
RESTORE_STACK;
return ret;