Opus multistream.

This is a backwards-compatible change. It makes WebRTC use the Opus
multistream decoder for all Opus packets. Single-stream packets are a
special case of multistream ones (with stream=1).

The tricky parts are 'WebRtcOpus_GetMaxPlaybackRate' and
'WebRtcOpus_GetSurroundParameters'. GetMaxPlaybackRate is supposed to
do what opus_encoder_ctl(encoder, OPUS_GET_MAX_BANDWIDTH(&bandwidth))
did when we had single-stream encoders. Now there may be several
independent encoders with possibly different BANDWIDTH. The new
GetMaxPlaybackRate queries all of them, and returns a playback rate if
all the encoder's rates are equal.

WebRtcOpus_GetSurroundParameters is a configuration convention. It
maps the number of channels to a multi-stream encoder/decoder
configuration. As described in RFC 7845
https://tools.ietf.org/html/rfc7845#section-5.1.1, a multi-stream
encoder/decoder needs a number of streams, number of coupled streams
and a 255-byte mapping array. The function GetSurroundParameters
computes all of these from the number of channels. [1, 2, 4, 6, 8]
channels are supported.

Bug: webrtc:8649
Change-Id: I271de8e387d738254d6aa53af7fcf8644a53edb5
Reviewed-on: https://webrtc-review.googlesource.com/c/111750
Commit-Queue: Alex Loiko <aleloi@webrtc.org>
Reviewed-by: Minyue Li <minyue@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26293}
This commit is contained in:
Alex Loiko
2019-01-17 12:32:11 +01:00
committed by Commit Bot
parent fe626f53f0
commit 83ed89a45f
7 changed files with 199 additions and 54 deletions

View File

@ -27,7 +27,7 @@ using ::testing::Values;
using ::testing::Combine;
// Maximum number of bytes in output bitstream.
const size_t kMaxBytes = 1000;
const size_t kMaxBytes = 2000;
// Sample rate of Opus.
const size_t kOpusRateKhz = 48;
// Number of samples-per-channel in a 20 ms frame, sampled at 48 kHz.
@ -86,10 +86,14 @@ OpusTest::OpusTest()
void OpusTest::PrepareSpeechData(size_t channel,
int block_length_ms,
int loop_length_ms) {
std::map<int, std::string> channel_to_basename = {
{1, "audio_coding/testfile32kHz"},
{2, "audio_coding/teststereo32kHz"},
{4, "audio_coding/speech_4_channels_48k_one_second"}};
std::map<int, std::string> channel_to_suffix = {
{1, "pcm"}, {2, "pcm"}, {4, "wav"}};
const std::string file_name = webrtc::test::ResourcePath(
(channel == 1) ? "audio_coding/testfile32kHz"
: "audio_coding/teststereo32kHz",
"pcm");
channel_to_basename[channel], channel_to_suffix[channel]);
if (loop_length_ms < block_length_ms) {
loop_length_ms = block_length_ms;
}
@ -103,7 +107,7 @@ void OpusTest::SetMaxPlaybackRate(WebRtcOpusEncInst* encoder,
int32_t set) {
opus_int32 bandwidth;
EXPECT_EQ(0, WebRtcOpus_SetMaxPlaybackRate(opus_encoder_, set));
opus_encoder_ctl(opus_encoder_->encoder, OPUS_GET_MAX_BANDWIDTH(&bandwidth));
EXPECT_EQ(0, WebRtcOpus_GetMaxPlaybackRate(opus_encoder_, &bandwidth));
EXPECT_EQ(expect, bandwidth);
}
@ -354,13 +358,13 @@ TEST(OpusTest, OpusCreateFail) {
// Test to see that an invalid pointer is caught.
EXPECT_EQ(-1, WebRtcOpus_EncoderCreate(NULL, 1, 0));
// Invalid channel number.
EXPECT_EQ(-1, WebRtcOpus_EncoderCreate(&opus_encoder, 3, 0));
EXPECT_EQ(-1, WebRtcOpus_EncoderCreate(&opus_encoder, 257, 0));
// Invalid applciation mode.
EXPECT_EQ(-1, WebRtcOpus_EncoderCreate(&opus_encoder, 1, 2));
EXPECT_EQ(-1, WebRtcOpus_DecoderCreate(NULL, 1));
// Invalid channel number.
EXPECT_EQ(-1, WebRtcOpus_DecoderCreate(&opus_decoder, 3));
EXPECT_EQ(-1, WebRtcOpus_DecoderCreate(&opus_decoder, 257));
}
// Test failing Free.
@ -399,7 +403,8 @@ TEST_P(OpusTest, OpusEncodeDecode) {
// Check application mode.
opus_int32 app;
opus_encoder_ctl(opus_encoder_->encoder, OPUS_GET_APPLICATION(&app));
opus_multistream_encoder_ctl(opus_encoder_->encoder,
OPUS_GET_APPLICATION(&app));
EXPECT_EQ(application_ == 0 ? OPUS_APPLICATION_VOIP : OPUS_APPLICATION_AUDIO,
app);
@ -450,6 +455,11 @@ TEST_P(OpusTest, OpusSetComplexity) {
}
TEST_P(OpusTest, OpusSetBandwidth) {
if (channels_ > 2) {
// TODO(webrtc:10217): investigate why multi-stream Opus reports
// narrowband when it's configured with FULLBAND.
return;
}
PrepareSpeechData(channels_, 20, 20);
int16_t audio_type;
@ -495,7 +505,7 @@ TEST_P(OpusTest, OpusForceChannels) {
ASSERT_EQ(0,
WebRtcOpus_EncoderCreate(&opus_encoder_, channels_, application_));
if (channels_ == 2) {
if (channels_ >= 2) {
EXPECT_EQ(-1, WebRtcOpus_SetForceChannels(opus_encoder_, 3));
EXPECT_EQ(0, WebRtcOpus_SetForceChannels(opus_encoder_, 2));
EXPECT_EQ(0, WebRtcOpus_SetForceChannels(opus_encoder_, 1));
@ -568,17 +578,17 @@ TEST_P(OpusTest, OpusEnableDisableDtx) {
opus_int32 dtx;
// DTX is off by default.
opus_encoder_ctl(opus_encoder_->encoder, OPUS_GET_DTX(&dtx));
opus_multistream_encoder_ctl(opus_encoder_->encoder, OPUS_GET_DTX(&dtx));
EXPECT_EQ(0, dtx);
// Test to enable DTX.
EXPECT_EQ(0, WebRtcOpus_EnableDtx(opus_encoder_));
opus_encoder_ctl(opus_encoder_->encoder, OPUS_GET_DTX(&dtx));
opus_multistream_encoder_ctl(opus_encoder_->encoder, OPUS_GET_DTX(&dtx));
EXPECT_EQ(1, dtx);
// Test to disable DTX.
EXPECT_EQ(0, WebRtcOpus_DisableDtx(opus_encoder_));
opus_encoder_ctl(opus_encoder_->encoder, OPUS_GET_DTX(&dtx));
opus_multistream_encoder_ctl(opus_encoder_->encoder, OPUS_GET_DTX(&dtx));
EXPECT_EQ(0, dtx);
// Free memory.
@ -592,6 +602,11 @@ TEST_P(OpusTest, OpusDtxOff) {
}
TEST_P(OpusTest, OpusDtxOn) {
if (channels_ > 2) {
// TODO(webrtc:10218): adapt the test to the sizes and order of multi-stream
// DTX packets.
return;
}
TestDtxEffect(true, 10);
TestDtxEffect(true, 20);
TestDtxEffect(true, 40);
@ -723,6 +738,12 @@ TEST_P(OpusTest, OpusDurationEstimation) {
}
TEST_P(OpusTest, OpusDecodeRepacketized) {
if (channels_ > 2) {
// As per the Opus documentation
// https://mf4.xiph.org/jenkins/view/opus/job/opus/ws/doc/html/group__opus__repacketizer.html#details,
// multiple streams are not supported.
return;
}
constexpr size_t kPackets = 6;
PrepareSpeechData(channels_, 20, 20 * kPackets);
@ -787,6 +808,6 @@ TEST_P(OpusTest, OpusDecodeRepacketized) {
INSTANTIATE_TEST_CASE_P(VariousMode,
OpusTest,
Combine(Values(1, 2), Values(0, 1)));
Combine(Values(1, 2, 4), Values(0, 1)));
} // namespace webrtc