diff options
author | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2014-09-04 09:48:46 +0400 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2014-09-04 09:48:46 +0400 |
commit | e1326fe6c8a246aa0b98074040542e3b8ca14c53 (patch) | |
tree | 9580cd5ffda8dfdb1d10dacc253af694b4537c13 /src | |
parent | 370286cd4aa9c6c9d41690bbb303974321bf81c6 (diff) |
Lowered the smallest packet that the multi-stream encoder can encode
Limit now at 2*streams-1 and anything below that returns OPUS_BUFFER_TOO_SMALL
rather than OPUS_BAD_ARG
Diffstat (limited to 'src')
-rw-r--r-- | src/opus_multistream_encoder.c | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/opus_multistream_encoder.c b/src/opus_multistream_encoder.c index aa464f59..854f85e3 100644 --- a/src/opus_multistream_encoder.c +++ b/src/opus_multistream_encoder.c @@ -744,17 +744,13 @@ static int opus_multistream_encode_native RESTORE_STACK; return OPUS_BAD_ARG; } - /* Estimate (slightly overestimating) of the smallest packet the encoder can produce. */ - if (50*frame_size <= Fs) - { - smallest_packet = st->layout.nb_streams*4; - } else { - smallest_packet = st->layout.nb_streams*4*50*frame_size/Fs; - } + + /* Smallest packet the encoder can produce. */ + smallest_packet = st->layout.nb_streams*2-1; if (max_data_bytes < smallest_packet) { RESTORE_STACK; - return OPUS_BAD_ARG; + return OPUS_BUFFER_TOO_SMALL; } ALLOC(buf, 2*frame_size, opus_val16); coupled_size = opus_encoder_get_size(2); @@ -766,12 +762,6 @@ static int opus_multistream_encode_native surround_analysis(celt_mode, pcm, bandSMR, mem, preemph_mem, frame_size, 120, st->layout.nb_channels, Fs, copy_channel_in); } - if (max_data_bytes < 4*st->layout.nb_streams-1) - { - RESTORE_STACK; - return OPUS_BUFFER_TOO_SMALL; - } - /* Compute bitrate allocation between streams (this could be a lot better) */ rate_sum = surround_rate_allocation(st, bitrates, frame_size); @@ -871,8 +861,10 @@ static int opus_multistream_encode_native /* number of bytes left (+Toc) */ curr_max = max_data_bytes - tot_size; /* Reserve three bytes for the last stream and four for the others */ - curr_max -= IMAX(0,4*(st->layout.nb_streams-s-1)-1); + curr_max -= IMAX(0,2*(st->layout.nb_streams-s-1)-1); curr_max = IMIN(curr_max,MS_FRAME_TMP); + /* Repacketizer will add one byte for self-delimited frames */ + if (s != st->layout.nb_streams-1) curr_max--; if (!vbr && s == st->layout.nb_streams-1) opus_encoder_ctl(enc, OPUS_SET_BITRATE(curr_max*(8*Fs/frame_size))); len = opus_encode_native(enc, buf, frame_size, tmp_data, curr_max, lsb_depth, |