Adding a 5% as packet loss level for Opus

This is a follow up of
https://webrtc-codereview.appspot.com/16979004/

The purpose of this CL is to add 5% as a level for optimizing the packet loss rate to report to Opus. Adding such a level makes the grid finer.

BUG=
R=tina.legrand@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/13179004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6902 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
minyue@webrtc.org 2014-08-14 12:16:12 +00:00
parent 4521e2d0bd
commit e8018b0b24
2 changed files with 49 additions and 36 deletions

View File

@ -226,24 +226,29 @@ int ACMOpus::SetFEC(bool enable_fec) {
int ACMOpus::SetPacketLossRate(int loss_rate) {
// Optimize the loss rate to configure Opus. Basically, optimized loss rate is
// the input loss rate rounded down to various levels, because a robustly good
// audio quality is achieved by lowering the packet loss lower down.
// audio quality is achieved by lowering the packet loss down.
// Additionally, to prevent toggling, margins are used, i.e., when jumping to
// a loss rate from below, a higher threshold is used than jumping to the same
// level from above.
const int kPacketLossRateHigh = 20;
const int kPacketLossRateMedium = 10;
const int kPacketLossRateLow = 1;
const int kLossRateHighMargin = 2;
const int kLossRateMediumMargin = 1;
const int kPacketLossRate20 = 20;
const int kPacketLossRate10 = 10;
const int kPacketLossRate5 = 5;
const int kPacketLossRate1 = 1;
const int kLossRate20Margin = 2;
const int kLossRate10Margin = 1;
const int kLossRate5Margin = 1;
int opt_loss_rate;
if (loss_rate >= kPacketLossRateHigh + kLossRateHighMargin *
SIGN(kPacketLossRateHigh - packet_loss_rate_)) {
opt_loss_rate = kPacketLossRateHigh;
} else if (loss_rate >= kPacketLossRateMedium + kLossRateMediumMargin *
SIGN(kPacketLossRateMedium - packet_loss_rate_)) {
opt_loss_rate = kPacketLossRateMedium;
} else if (loss_rate >= kPacketLossRateLow) {
opt_loss_rate = kPacketLossRateLow;
if (loss_rate >= kPacketLossRate20 + kLossRate20Margin *
SIGN(kPacketLossRate20 - packet_loss_rate_)) {
opt_loss_rate = kPacketLossRate20;
} else if (loss_rate >= kPacketLossRate10 + kLossRate10Margin *
SIGN(kPacketLossRate10 - packet_loss_rate_)) {
opt_loss_rate = kPacketLossRate10;
} else if (loss_rate >= kPacketLossRate5 + kLossRate5Margin *
SIGN(kPacketLossRate5 - packet_loss_rate_)) {
opt_loss_rate = kPacketLossRate5;
} else if (loss_rate >= kPacketLossRate1) {
opt_loss_rate = kPacketLossRate1;
} else {
opt_loss_rate = 0;
}

View File

@ -20,11 +20,13 @@ namespace acm2 {
namespace {
const CodecInst kOpusCodecInst = {105, "opus", 48000, 960, 1, 32000};
// These constants correspond to those used in ACMOpus::SetPacketLossRate().
const int kPacketLossRateHigh = 20;
const int kPacketLossRateMedium = 10;
const int kPacketLossRateLow = 1;
const int kLossRateHighMargin = 2;
const int kLossRateMediumMargin = 1;
const int kPacketLossRate20 = 20;
const int kPacketLossRate10 = 10;
const int kPacketLossRate5 = 5;
const int kPacketLossRate1 = 1;
const int kLossRate20Margin = 2;
const int kLossRate10Margin = 1;
const int kLossRate5Margin = 1;
} // namespace
class AcmOpusTest : public ACMOpus {
@ -54,24 +56,30 @@ TEST(AcmOpusTest, PacketLossRateOptimized) {
// Note that the order of the following calls is critical.
opus.TestSetPacketLossRate(0, 0, 0);
opus.TestSetPacketLossRate(kPacketLossRateLow,
kPacketLossRateMedium + kLossRateMediumMargin - 1,
kPacketLossRateLow);
opus.TestSetPacketLossRate(kPacketLossRateMedium + kLossRateMediumMargin,
kPacketLossRateHigh + kLossRateHighMargin - 1,
kPacketLossRateMedium);
opus.TestSetPacketLossRate(kPacketLossRateHigh + kLossRateHighMargin,
opus.TestSetPacketLossRate(kPacketLossRate1,
kPacketLossRate5 + kLossRate5Margin - 1,
kPacketLossRate1);
opus.TestSetPacketLossRate(kPacketLossRate5 + kLossRate5Margin,
kPacketLossRate10 + kLossRate10Margin - 1,
kPacketLossRate5);
opus.TestSetPacketLossRate(kPacketLossRate10 + kLossRate10Margin,
kPacketLossRate20 + kLossRate20Margin - 1,
kPacketLossRate10);
opus.TestSetPacketLossRate(kPacketLossRate20 + kLossRate20Margin,
100,
kPacketLossRateHigh);
opus.TestSetPacketLossRate(kPacketLossRateHigh + kLossRateHighMargin,
kPacketLossRateHigh - kLossRateHighMargin,
kPacketLossRateHigh);
opus.TestSetPacketLossRate(kPacketLossRateHigh - kLossRateHighMargin - 1,
kPacketLossRateMedium - kLossRateMediumMargin,
kPacketLossRateMedium);
opus.TestSetPacketLossRate(kPacketLossRateMedium - kLossRateMediumMargin - 1,
kPacketLossRateLow,
kPacketLossRateLow);
kPacketLossRate20);
opus.TestSetPacketLossRate(kPacketLossRate20 + kLossRate20Margin,
kPacketLossRate20 - kLossRate20Margin,
kPacketLossRate20);
opus.TestSetPacketLossRate(kPacketLossRate20 - kLossRate20Margin - 1,
kPacketLossRate10 - kLossRate10Margin,
kPacketLossRate10);
opus.TestSetPacketLossRate(kPacketLossRate10 - kLossRate10Margin - 1,
kPacketLossRate5 - kLossRate5Margin,
kPacketLossRate5);
opus.TestSetPacketLossRate(kPacketLossRate5 - kLossRate5Margin - 1,
kPacketLossRate1,
kPacketLossRate1);
opus.TestSetPacketLossRate(0, 0, 0);
}
#else