Adapting bitrate according to maxplaybackrate for Opus.
BUG= R=mflodman@webrtc.org, tina.legrand@webrtc.org Review URL: https://webrtc-codereview.appspot.com/29929004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7575 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
8328e7c44d
commit
2dc6f3154d
@ -110,13 +110,26 @@ static const int kDefaultAudioDeviceId = 0;
|
||||
|
||||
static const char kIsacCodecName[] = "ISAC";
|
||||
static const char kL16CodecName[] = "L16";
|
||||
// Codec parameters for Opus.
|
||||
static const int kOpusMonoBitrate = 32000;
|
||||
|
||||
// Parameter used for NACK.
|
||||
// This value is equivalent to 5 seconds of audio data at 20 ms per packet.
|
||||
static const int kNackMaxPackets = 250;
|
||||
static const int kOpusStereoBitrate = 64000;
|
||||
|
||||
// Codec parameters for Opus.
|
||||
// draft-spittka-payload-rtp-opus-03
|
||||
|
||||
// Recommended bitrates:
|
||||
// 8-12 kb/s for NB speech,
|
||||
// 16-20 kb/s for WB speech,
|
||||
// 28-40 kb/s for FB speech,
|
||||
// 48-64 kb/s for FB mono music, and
|
||||
// 64-128 kb/s for FB stereo music.
|
||||
// The current implementation applies the following values to mono signals,
|
||||
// and multiplies them by 2 for stereo.
|
||||
static const int kOpusBitrateNb = 12000;
|
||||
static const int kOpusBitrateWb = 20000;
|
||||
static const int kOpusBitrateFb = 32000;
|
||||
|
||||
// Opus bitrate should be in the range between 6000 and 510000.
|
||||
static const int kOpusMinBitrate = 6000;
|
||||
static const int kOpusMaxBitrate = 510000;
|
||||
@ -417,8 +430,17 @@ static int GetOpusBitrate(const AudioCodec& codec, int max_playback_rate) {
|
||||
use_param = false;
|
||||
}
|
||||
if (bitrate <= 0) {
|
||||
bitrate = IsOpusStereoEnabled(codec) ? kOpusStereoBitrate :
|
||||
kOpusMonoBitrate;
|
||||
if (max_playback_rate <= 8000) {
|
||||
bitrate = kOpusBitrateNb;
|
||||
} else if (max_playback_rate <= 16000) {
|
||||
bitrate = kOpusBitrateWb;
|
||||
} else {
|
||||
bitrate = kOpusBitrateFb;
|
||||
}
|
||||
|
||||
if (IsOpusStereoEnabled(codec)) {
|
||||
bitrate *= 2;
|
||||
}
|
||||
} else if (bitrate < kOpusMinBitrate || bitrate > kOpusMaxBitrate) {
|
||||
bitrate = (bitrate < kOpusMinBitrate) ? kOpusMinBitrate : kOpusMaxBitrate;
|
||||
std::string rate_source =
|
||||
@ -459,9 +481,6 @@ static void GetOpusConfig(const AudioCodec& codec, webrtc::CodecInst* voe_codec,
|
||||
// the bitrate is not specified, i.e. is <= zero, we set it to the
|
||||
// appropriate default value for mono or stereo Opus.
|
||||
|
||||
// TODO(minyue): The determination of bit rate might take the maximum playback
|
||||
// rate into account.
|
||||
|
||||
voe_codec->channels = IsOpusStereoEnabled(codec) ? 2 : 1;
|
||||
voe_codec->rate = GetOpusBitrate(codec, *max_playback_rate);
|
||||
}
|
||||
|
@ -1254,9 +1254,12 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) {
|
||||
webrtc::CodecInst gcodec;
|
||||
EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
|
||||
EXPECT_STREQ("opus", gcodec.plname);
|
||||
// TODO(minyue): Default bit rate is not but can in future be affected by
|
||||
// kCodecParamMaxPlaybackRate.
|
||||
EXPECT_EQ(32000, gcodec.rate);
|
||||
|
||||
EXPECT_EQ(12000, gcodec.rate);
|
||||
codecs[0].SetParam(cricket::kCodecParamStereo, "1");
|
||||
EXPECT_TRUE(channel_->SetSendCodecs(codecs));
|
||||
EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
|
||||
EXPECT_EQ(24000, gcodec.rate);
|
||||
}
|
||||
|
||||
// Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode.
|
||||
@ -1273,9 +1276,12 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateMb) {
|
||||
webrtc::CodecInst gcodec;
|
||||
EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
|
||||
EXPECT_STREQ("opus", gcodec.plname);
|
||||
// TODO(minyue): Default bit rate is not but can in future be affected by
|
||||
// kCodecParamMaxPlaybackRate.
|
||||
EXPECT_EQ(32000, gcodec.rate);
|
||||
|
||||
EXPECT_EQ(20000, gcodec.rate);
|
||||
codecs[0].SetParam(cricket::kCodecParamStereo, "1");
|
||||
EXPECT_TRUE(channel_->SetSendCodecs(codecs));
|
||||
EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
|
||||
EXPECT_EQ(40000, gcodec.rate);
|
||||
}
|
||||
|
||||
// Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode.
|
||||
@ -1292,9 +1298,12 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateWb) {
|
||||
webrtc::CodecInst gcodec;
|
||||
EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
|
||||
EXPECT_STREQ("opus", gcodec.plname);
|
||||
// TODO(minyue): Default bit rate is not but can in future be affected by
|
||||
// kCodecParamMaxPlaybackRate.
|
||||
EXPECT_EQ(32000, gcodec.rate);
|
||||
|
||||
EXPECT_EQ(20000, gcodec.rate);
|
||||
codecs[0].SetParam(cricket::kCodecParamStereo, "1");
|
||||
EXPECT_TRUE(channel_->SetSendCodecs(codecs));
|
||||
EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
|
||||
EXPECT_EQ(40000, gcodec.rate);
|
||||
}
|
||||
|
||||
// Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode.
|
||||
@ -1311,9 +1320,12 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateSwb) {
|
||||
webrtc::CodecInst gcodec;
|
||||
EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
|
||||
EXPECT_STREQ("opus", gcodec.plname);
|
||||
// TODO(minyue): Default bit rate is not but can in future be affected by
|
||||
// kCodecParamMaxPlaybackRate.
|
||||
|
||||
EXPECT_EQ(32000, gcodec.rate);
|
||||
codecs[0].SetParam(cricket::kCodecParamStereo, "1");
|
||||
EXPECT_TRUE(channel_->SetSendCodecs(codecs));
|
||||
EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
|
||||
EXPECT_EQ(64000, gcodec.rate);
|
||||
}
|
||||
|
||||
// Test 24000 < maxplaybackrate triggers Opus full band mode.
|
||||
@ -1330,9 +1342,12 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateFb) {
|
||||
webrtc::CodecInst gcodec;
|
||||
EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
|
||||
EXPECT_STREQ("opus", gcodec.plname);
|
||||
// TODO(minyue): Default bit rate is not but can in future be affected by
|
||||
// kCodecParamMaxPlaybackRate.
|
||||
|
||||
EXPECT_EQ(32000, gcodec.rate);
|
||||
codecs[0].SetParam(cricket::kCodecParamStereo, "1");
|
||||
EXPECT_TRUE(channel_->SetSendCodecs(codecs));
|
||||
EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
|
||||
EXPECT_EQ(64000, gcodec.rate);
|
||||
}
|
||||
|
||||
// Test Opus that without maxplaybackrate, default playback rate is used.
|
||||
|
Loading…
Reference in New Issue
Block a user