ref: e1326fe6c8a246aa0b98074040542e3b8ca14c53
parent: 370286cd4aa9c6c9d41690bbb303974321bf81c6
author: Jean-Marc Valin <[email protected]>
date: Wed Sep 3 21:48:46 EDT 2014
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
--- a/include/opus_defines.h
+++ b/include/opus_defines.h
@@ -46,7 +46,7 @@
#define OPUS_OK 0
/** One or more invalid/out of range arguments @hideinitializer*/
#define OPUS_BAD_ARG -1
-/** The mode struct passed is invalid @hideinitializer*/
+/** Not enough bytes allocated in the buffer @hideinitializer*/
#define OPUS_BUFFER_TOO_SMALL -2
/** An internal error was detected @hideinitializer*/
#define OPUS_INTERNAL_ERROR -3
--- a/src/opus_multistream_encoder.c
+++ b/src/opus_multistream_encoder.c
@@ -744,17 +744,13 @@
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 @@
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 @@
/* 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,