Index: webrtc/modules/pacing/paced_sender_unittest.cc |
diff --git a/webrtc/modules/pacing/paced_sender_unittest.cc b/webrtc/modules/pacing/paced_sender_unittest.cc |
index 15bb462949b4394e160db3703aad94b246d44816..941c81335b6cf073c7a5bac225c84fecbeb5784d 100644 |
--- a/webrtc/modules/pacing/paced_sender_unittest.cc |
+++ b/webrtc/modules/pacing/paced_sender_unittest.cc |
@@ -22,9 +22,10 @@ using testing::Return; |
namespace webrtc { |
namespace test { |
-static const int kTargetBitrateBps = 800000; |
+static const int kTargetBitrate = 800; |
+static const float kPaceMultiplier = 1.5f; |
-class MockPacedSenderCallback : public PacedSender::PacketSender { |
+class MockPacedSenderCallback : public PacedSender::Callback { |
public: |
MOCK_METHOD4(TimeToSendPacket, |
bool(uint32_t ssrc, |
@@ -35,7 +36,7 @@ class MockPacedSenderCallback : public PacedSender::PacketSender { |
size_t(size_t bytes)); |
}; |
-class PacedSenderPadding : public PacedSender::PacketSender { |
+class PacedSenderPadding : public PacedSender::Callback { |
public: |
PacedSenderPadding() : padding_sent_(0) {} |
@@ -59,7 +60,7 @@ class PacedSenderPadding : public PacedSender::PacketSender { |
size_t padding_sent_; |
}; |
-class PacedSenderProbing : public PacedSender::PacketSender { |
+class PacedSenderProbing : public PacedSender::Callback { |
public: |
PacedSenderProbing(const std::list<int>& expected_deltas, Clock* clock) |
: prev_packet_time_ms_(-1), |
@@ -107,7 +108,11 @@ class PacedSenderTest : public ::testing::Test { |
PacedSenderTest() : clock_(123456) { |
srand(0); |
// Need to initialize PacedSender after we initialize clock. |
- send_bucket_.reset(new PacedSender(&clock_, &callback_, kTargetBitrateBps)); |
+ send_bucket_.reset(new PacedSender(&clock_, |
+ &callback_, |
+ kTargetBitrate, |
+ kPaceMultiplier * kTargetBitrate, |
+ 0)); |
// Default to bitrate probing disabled for testing purposes. Probing tests |
// have to enable probing, either by creating a new PacedSender instance or |
// by calling SetProbingEnabled(true). |
@@ -136,21 +141,29 @@ class PacedSenderTest : public ::testing::Test { |
TEST_F(PacedSenderTest, QueuePacket) { |
uint32_t ssrc = 12345; |
uint16_t sequence_number = 1234; |
- // Due to the multiplicative factor we can send 5 packets during a send |
- // interval. (network capacity * multiplier / (8 bits per byte * |
- // (packet size * #send intervals per second) |
- const size_t packets_to_send = |
- kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); |
- for (size_t i = 0; i < packets_to_send; ++i) { |
- SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
- clock_.TimeInMilliseconds(), 250, false); |
- } |
- |
+ // Due to the multiplicative factor we can send 3 packets not 2 packets. |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
int64_t queued_packet_timestamp = clock_.TimeInMilliseconds(); |
send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
sequence_number, queued_packet_timestamp, 250, |
false); |
- EXPECT_EQ(packets_to_send + 1, send_bucket_->QueueSizePackets()); |
send_bucket_->Process(); |
EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); |
@@ -158,79 +171,86 @@ TEST_F(PacedSenderTest, QueuePacket) { |
EXPECT_EQ(1, send_bucket_->TimeUntilNextProcess()); |
clock_.AdvanceTimeMilliseconds(1); |
EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
- EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); |
- EXPECT_CALL(callback_, TimeToSendPacket(ssrc, sequence_number, |
- queued_packet_timestamp, false)) |
+ EXPECT_CALL( |
+ callback_, |
+ TimeToSendPacket(ssrc, sequence_number++, queued_packet_timestamp, false)) |
.Times(1) |
.WillRepeatedly(Return(true)); |
send_bucket_->Process(); |
sequence_number++; |
- EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); |
- |
- // We can send packets_to_send -1 packets of size 250 during the current |
- // interval since one packet has already been sent. |
- for (size_t i = 0; i < packets_to_send - 1; ++i) { |
- SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
- clock_.TimeInMilliseconds(), 250, false); |
- } |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
sequence_number++, clock_.TimeInMilliseconds(), |
250, false); |
- EXPECT_EQ(packets_to_send, send_bucket_->QueueSizePackets()); |
send_bucket_->Process(); |
- EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); |
} |
TEST_F(PacedSenderTest, PaceQueuedPackets) { |
uint32_t ssrc = 12345; |
uint16_t sequence_number = 1234; |
- // Due to the multiplicative factor we can send 5 packets during a send |
- // interval. (network capacity * multiplier / (8 bits per byte * |
- // (packet size * #send intervals per second) |
- const size_t packets_to_send_per_interval = |
- kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); |
- for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
- SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
- clock_.TimeInMilliseconds(), 250, false); |
+ // Due to the multiplicative factor we can send 3 packets not 2 packets. |
+ for (int i = 0; i < 3; ++i) { |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
} |
- |
- for (size_t j = 0; j < packets_to_send_per_interval * 10; ++j) { |
+ for (int j = 0; j < 30; ++j) { |
send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
sequence_number++, clock_.TimeInMilliseconds(), |
250, false); |
} |
- EXPECT_EQ(packets_to_send_per_interval + packets_to_send_per_interval * 10, |
- send_bucket_->QueueSizePackets()); |
send_bucket_->Process(); |
- EXPECT_EQ(packets_to_send_per_interval * 10, |
- send_bucket_->QueueSizePackets()); |
EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); |
for (int k = 0; k < 10; ++k) { |
EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
clock_.AdvanceTimeMilliseconds(5); |
EXPECT_CALL(callback_, TimeToSendPacket(ssrc, _, _, false)) |
- .Times(packets_to_send_per_interval) |
+ .Times(3) |
.WillRepeatedly(Return(true)); |
EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
send_bucket_->Process(); |
} |
- EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); |
EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
clock_.AdvanceTimeMilliseconds(5); |
EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
- EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); |
send_bucket_->Process(); |
- |
- for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
- SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
- clock_.TimeInMilliseconds(), 250, false); |
- } |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
sequence_number, clock_.TimeInMilliseconds(), 250, |
false); |
send_bucket_->Process(); |
- EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); |
} |
TEST_F(PacedSenderTest, PaceQueuedPacketsWithDuplicates) { |
@@ -238,18 +258,18 @@ TEST_F(PacedSenderTest, PaceQueuedPacketsWithDuplicates) { |
uint16_t sequence_number = 1234; |
uint16_t queued_sequence_number; |
- // Due to the multiplicative factor we can send 5 packets during a send |
- // interval. (network capacity * multiplier / (8 bits per byte * |
- // (packet size * #send intervals per second) |
- const size_t packets_to_send_per_interval = |
- kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); |
- for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
- SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
- clock_.TimeInMilliseconds(), 250, false); |
+ // Due to the multiplicative factor we can send 3 packets not 2 packets. |
+ for (int i = 0; i < 3; ++i) { |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
} |
queued_sequence_number = sequence_number; |
- for (size_t j = 0; j < packets_to_send_per_interval * 10; ++j) { |
+ for (int j = 0; j < 30; ++j) { |
// Send in duplicate packets. |
send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
sequence_number, clock_.TimeInMilliseconds(), |
@@ -264,7 +284,7 @@ TEST_F(PacedSenderTest, PaceQueuedPacketsWithDuplicates) { |
EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
clock_.AdvanceTimeMilliseconds(5); |
- for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
+ for (int i = 0; i < 3; ++i) { |
EXPECT_CALL(callback_, |
TimeToSendPacket(ssrc, queued_sequence_number++, _, false)) |
.Times(1) |
@@ -277,16 +297,28 @@ TEST_F(PacedSenderTest, PaceQueuedPacketsWithDuplicates) { |
clock_.AdvanceTimeMilliseconds(5); |
EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
send_bucket_->Process(); |
- |
- for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
- SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
- clock_.TimeInMilliseconds(), 250, false); |
- } |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
sequence_number++, clock_.TimeInMilliseconds(), |
250, false); |
send_bucket_->Process(); |
- EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); |
} |
TEST_F(PacedSenderTest, CanQueuePacketsWithSameSequenceNumberOnDifferentSsrcs) { |
@@ -316,33 +348,33 @@ TEST_F(PacedSenderTest, Padding) { |
uint32_t ssrc = 12345; |
uint16_t sequence_number = 1234; |
- send_bucket_->SetEstimatedBitrate(kTargetBitrateBps); |
- send_bucket_->SetAllocatedSendBitrate(kTargetBitrateBps, kTargetBitrateBps); |
- |
- // Due to the multiplicative factor we can send 5 packets during a send |
- // interval. (network capacity * multiplier / (8 bits per byte * |
- // (packet size * #send intervals per second) |
- const size_t packets_to_send_per_interval = |
- kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); |
- for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
- SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
- clock_.TimeInMilliseconds(), 250, false); |
- } |
+ send_bucket_->UpdateBitrate( |
+ kTargetBitrate, kPaceMultiplier * kTargetBitrate, kTargetBitrate); |
+ // Due to the multiplicative factor we can send 3 packets not 2 packets. |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ clock_.TimeInMilliseconds(), |
+ 250, |
+ false); |
// No padding is expected since we have sent too much already. |
EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); |
EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
clock_.AdvanceTimeMilliseconds(5); |
EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
send_bucket_->Process(); |
- EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); |
- |
- // 5 milliseconds later should not send padding since we filled the buffers |
- // initially. |
- EXPECT_CALL(callback_, TimeToSendPadding(250)).Times(0); |
- EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
- clock_.AdvanceTimeMilliseconds(5); |
- EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
- send_bucket_->Process(); |
// 5 milliseconds later we have enough budget to send some padding. |
EXPECT_CALL(callback_, TimeToSendPadding(250)).Times(1). |
@@ -359,9 +391,8 @@ TEST_F(PacedSenderTest, VerifyPaddingUpToBitrate) { |
int64_t capture_time_ms = 56789; |
const int kTimeStep = 5; |
const int64_t kBitrateWindow = 100; |
- send_bucket_->SetEstimatedBitrate(kTargetBitrateBps); |
- send_bucket_->SetAllocatedSendBitrate(kTargetBitrateBps, kTargetBitrateBps); |
- |
+ send_bucket_->UpdateBitrate( |
+ kTargetBitrate, kPaceMultiplier * kTargetBitrate, kTargetBitrate); |
int64_t start_time = clock_.TimeInMilliseconds(); |
while (clock_.TimeInMilliseconds() - start_time < kBitrateWindow) { |
SendAndExpectPacket(PacedSender::kNormalPriority, |
@@ -384,11 +415,11 @@ TEST_F(PacedSenderTest, VerifyAverageBitrateVaryingMediaPayload) { |
const int kTimeStep = 5; |
const int64_t kBitrateWindow = 10000; |
PacedSenderPadding callback; |
- send_bucket_.reset(new PacedSender(&clock_, &callback, kTargetBitrateBps)); |
+ send_bucket_.reset(new PacedSender( |
+ &clock_, &callback, kTargetBitrate, kPaceMultiplier * kTargetBitrate, 0)); |
send_bucket_->SetProbingEnabled(false); |
- send_bucket_->SetEstimatedBitrate(kTargetBitrateBps); |
- send_bucket_->SetAllocatedSendBitrate(kTargetBitrateBps, kTargetBitrateBps); |
- |
+ send_bucket_->UpdateBitrate( |
+ kTargetBitrate, kPaceMultiplier * kTargetBitrate, kTargetBitrate); |
int64_t start_time = clock_.TimeInMilliseconds(); |
size_t media_bytes = 0; |
while (clock_.TimeInMilliseconds() - start_time < kBitrateWindow) { |
@@ -401,10 +432,9 @@ TEST_F(PacedSenderTest, VerifyAverageBitrateVaryingMediaPayload) { |
clock_.AdvanceTimeMilliseconds(kTimeStep); |
send_bucket_->Process(); |
} |
- EXPECT_NEAR(kTargetBitrateBps / 1000, |
+ EXPECT_NEAR(kTargetBitrate, |
static_cast<int>(8 * (media_bytes + callback.padding_sent()) / |
- kBitrateWindow), |
- 1); |
+ kBitrateWindow), 1); |
} |
TEST_F(PacedSenderTest, Priority) { |
@@ -414,41 +444,50 @@ TEST_F(PacedSenderTest, Priority) { |
int64_t capture_time_ms = 56789; |
int64_t capture_time_ms_low_priority = 1234567; |
- // Due to the multiplicative factor we can send 5 packets during a send |
- // interval. (network capacity * multiplier / (8 bits per byte * |
- // (packet size * #send intervals per second) |
- const size_t packets_to_send_per_interval = |
- kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); |
- for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
- SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
- clock_.TimeInMilliseconds(), 250, false); |
- } |
+ // Due to the multiplicative factor we can send 3 packets not 2 packets. |
+ SendAndExpectPacket(PacedSender::kLowPriority, |
+ ssrc, |
+ sequence_number++, |
+ capture_time_ms, |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ capture_time_ms, |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ capture_time_ms, |
+ 250, |
+ false); |
send_bucket_->Process(); |
- EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); |
// Expect normal and low priority to be queued and high to pass through. |
send_bucket_->InsertPacket(PacedSender::kLowPriority, ssrc_low_priority, |
sequence_number++, capture_time_ms_low_priority, |
250, false); |
- |
- for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
- send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
- sequence_number++, capture_time_ms, 250, false); |
- } |
+ send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
+ sequence_number++, capture_time_ms, 250, false); |
+ send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
+ sequence_number++, capture_time_ms, 250, false); |
+ send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
+ sequence_number++, capture_time_ms, 250, false); |
send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc, |
sequence_number++, capture_time_ms, 250, false); |
// Expect all high and normal priority to be sent out first. |
EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); |
EXPECT_CALL(callback_, TimeToSendPacket(ssrc, _, capture_time_ms, false)) |
- .Times(packets_to_send_per_interval + 1) |
+ .Times(4) |
.WillRepeatedly(Return(true)); |
EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
clock_.AdvanceTimeMilliseconds(5); |
EXPECT_EQ(0, send_bucket_->TimeUntilNextProcess()); |
send_bucket_->Process(); |
- EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); |
EXPECT_CALL(callback_, |
TimeToSendPacket( |
@@ -474,30 +513,23 @@ TEST_F(PacedSenderTest, HighPrioDoesntAffectBudget) { |
capture_time_ms, 250, false); |
} |
send_bucket_->Process(); |
- // Low prio packets does affect the budget. |
- // Due to the multiplicative factor we can send 5 packets during a send |
- // interval. (network capacity * multiplier / (8 bits per byte * |
- // (packet size * #send intervals per second) |
- const size_t packets_to_send_per_interval = |
- kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); |
- for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
+ // Low prio packets does affect the budget, so we should only be able to send |
+ // 3 at once, the 4th should be queued. |
+ for (int i = 0; i < 3; ++i) { |
SendAndExpectPacket(PacedSender::kLowPriority, ssrc, sequence_number++, |
- clock_.TimeInMilliseconds(), 250, false); |
+ capture_time_ms, 250, false); |
} |
send_bucket_->InsertPacket(PacedSender::kLowPriority, ssrc, sequence_number, |
capture_time_ms, 250, false); |
EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
clock_.AdvanceTimeMilliseconds(5); |
send_bucket_->Process(); |
- EXPECT_EQ(1u, send_bucket_->QueueSizePackets()); |
EXPECT_CALL(callback_, |
TimeToSendPacket(ssrc, sequence_number++, capture_time_ms, false)) |
- .Times(1) |
- .WillRepeatedly(Return(true)); |
+ .Times(1); |
EXPECT_EQ(5, send_bucket_->TimeUntilNextProcess()); |
clock_.AdvanceTimeMilliseconds(5); |
send_bucket_->Process(); |
- EXPECT_EQ(0u, send_bucket_->QueueSizePackets()); |
} |
TEST_F(PacedSenderTest, Pause) { |
@@ -508,16 +540,25 @@ TEST_F(PacedSenderTest, Pause) { |
EXPECT_EQ(0, send_bucket_->QueueInMs()); |
- // Due to the multiplicative factor we can send 5 packets during a send |
- // interval. (network capacity * multiplier / (8 bits per byte * |
- // (packet size * #send intervals per second) |
- const size_t packets_to_send_per_interval = |
- kTargetBitrateBps * PacedSender::kDefaultPaceMultiplier / (8 * 250 * 200); |
- for (size_t i = 0; i < packets_to_send_per_interval; ++i) { |
- SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
- clock_.TimeInMilliseconds(), 250, false); |
- } |
- |
+ // Due to the multiplicative factor we can send 3 packets not 2 packets. |
+ SendAndExpectPacket(PacedSender::kLowPriority, |
+ ssrc, |
+ sequence_number++, |
+ capture_time_ms, |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ capture_time_ms, |
+ 250, |
+ false); |
+ SendAndExpectPacket(PacedSender::kNormalPriority, |
+ ssrc, |
+ sequence_number++, |
+ capture_time_ms, |
+ 250, |
+ false); |
send_bucket_->Process(); |
send_bucket_->Pause(); |
@@ -627,18 +668,18 @@ TEST_F(PacedSenderTest, ExpectedQueueTimeMs) { |
uint16_t sequence_number = 1234; |
const size_t kNumPackets = 60; |
const size_t kPacketSize = 1200; |
- const int32_t kMaxBitrate = PacedSender::kDefaultPaceMultiplier * 30000; |
+ const int32_t kMaxBitrate = kPaceMultiplier * 30; |
EXPECT_EQ(0, send_bucket_->ExpectedQueueTimeMs()); |
- send_bucket_->SetEstimatedBitrate(30000); |
+ send_bucket_->UpdateBitrate(30, kMaxBitrate, 0); |
for (size_t i = 0; i < kNumPackets; ++i) { |
SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
clock_.TimeInMilliseconds(), kPacketSize, false); |
} |
- // Queue in ms = 1000 * (bytes in queue) *8 / (bits per second) |
+ // Queue in ms = 1000 * (bytes in queue) / (kbit per second * 1000 / 8) |
int64_t queue_in_ms = |
- static_cast<int64_t>(1000 * kNumPackets * kPacketSize * 8 / kMaxBitrate); |
+ static_cast<int64_t>(kNumPackets * kPacketSize * 8 / kMaxBitrate); |
EXPECT_EQ(queue_in_ms, send_bucket_->ExpectedQueueTimeMs()); |
int64_t time_start = clock_.TimeInMilliseconds(); |
@@ -656,7 +697,7 @@ TEST_F(PacedSenderTest, ExpectedQueueTimeMs) { |
// Allow for aliasing, duration should be within one pack of max time limit. |
EXPECT_NEAR(duration, PacedSender::kMaxQueueLengthMs, |
- static_cast<int64_t>(1000 * kPacketSize * 8 / kMaxBitrate)); |
+ static_cast<int64_t>(kPacketSize * 8 / kMaxBitrate)); |
} |
TEST_F(PacedSenderTest, QueueTimeGrowsOverTime) { |
@@ -664,7 +705,7 @@ TEST_F(PacedSenderTest, QueueTimeGrowsOverTime) { |
uint16_t sequence_number = 1234; |
EXPECT_EQ(0, send_bucket_->QueueInMs()); |
- send_bucket_->SetEstimatedBitrate(30000); |
+ send_bucket_->UpdateBitrate(30, kPaceMultiplier * 30, 0); |
SendAndExpectPacket(PacedSender::kNormalPriority, |
ssrc, |
sequence_number, |
@@ -682,22 +723,25 @@ TEST_F(PacedSenderTest, ProbingWithInitialFrame) { |
const int kNumPackets = 11; |
const int kNumDeltas = kNumPackets - 1; |
const size_t kPacketSize = 1200; |
- const int kInitialBitrateBps = 300000; |
+ const int kInitialBitrateKbps = 300; |
uint32_t ssrc = 12346; |
uint16_t sequence_number = 1234; |
- |
const int expected_deltas[kNumDeltas] = {10, 10, 10, 10, 10, 5, 5, 5, 5, 5}; |
std::list<int> expected_deltas_list(expected_deltas, |
expected_deltas + kNumDeltas); |
PacedSenderProbing callback(expected_deltas_list, &clock_); |
- send_bucket_.reset(new PacedSender(&clock_, &callback, kInitialBitrateBps)); |
+ send_bucket_.reset( |
+ new PacedSender(&clock_, |
+ &callback, |
+ kInitialBitrateKbps, |
+ kPaceMultiplier * kInitialBitrateKbps, |
+ 0)); |
for (int i = 0; i < kNumPackets; ++i) { |
send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
sequence_number++, clock_.TimeInMilliseconds(), |
kPacketSize, false); |
} |
- |
while (callback.packets_sent() < kNumPackets) { |
int time_until_process = send_bucket_->TimeUntilNextProcess(); |
if (time_until_process <= 0) { |
@@ -712,14 +756,15 @@ TEST_F(PacedSenderTest, ProbingWithTooSmallInitialFrame) { |
const int kNumPackets = 11; |
const int kNumDeltas = kNumPackets - 1; |
const size_t kPacketSize = 1200; |
- const int kInitialBitrateBps = 300000; |
+ const int kInitialBitrateKbps = 300; |
uint32_t ssrc = 12346; |
uint16_t sequence_number = 1234; |
const int expected_deltas[kNumDeltas] = {10, 10, 10, 10, 10, 5, 5, 5, 5, 5}; |
std::list<int> expected_deltas_list(expected_deltas, |
expected_deltas + kNumDeltas); |
PacedSenderProbing callback(expected_deltas_list, &clock_); |
- send_bucket_.reset(new PacedSender(&clock_, &callback, kInitialBitrateBps)); |
+ send_bucket_.reset(new PacedSender(&clock_, &callback, kInitialBitrateKbps, |
+ kPaceMultiplier * kInitialBitrateKbps, 0)); |
for (int i = 0; i < kNumPackets - 5; ++i) { |
send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, |
@@ -794,21 +839,21 @@ TEST_F(PacedSenderTest, PaddingOveruse) { |
uint16_t sequence_number = 1234; |
const size_t kPacketSize = 1200; |
- send_bucket_->SetEstimatedBitrate(60000); |
- send_bucket_->SetAllocatedSendBitrate(60000, 0); |
- |
+ // Min bitrate 0 => no padding, padding budget will stay at 0. |
+ send_bucket_->UpdateBitrate(60, 90, 0); |
SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
clock_.TimeInMilliseconds(), kPacketSize, false); |
send_bucket_->Process(); |
// Add 30kbit padding. When increasing budget, media budget will increase from |
- // negative (overuse) while padding budget will increase from 0. |
+ // negative (overuse) while padding budget will increase form 0. |
clock_.AdvanceTimeMilliseconds(5); |
- send_bucket_->SetAllocatedSendBitrate(60000, 30000); |
+ send_bucket_->UpdateBitrate(60, 90, 30); |
+ |
+ send_bucket_->InsertPacket(PacedSender::kHighPriority, ssrc, |
+ sequence_number++, clock_.TimeInMilliseconds(), |
+ kPacketSize, false); |
- SendAndExpectPacket(PacedSender::kNormalPriority, ssrc, sequence_number++, |
- clock_.TimeInMilliseconds(), kPacketSize, false); |
- EXPECT_LT(5u, send_bucket_->ExpectedQueueTimeMs()); |
// Don't send padding if queue is non-empty, even if padding budget > 0. |
EXPECT_CALL(callback_, TimeToSendPadding(_)).Times(0); |
send_bucket_->Process(); |
@@ -819,8 +864,9 @@ TEST_F(PacedSenderTest, AverageQueueTime) { |
uint16_t sequence_number = 1234; |
const size_t kPacketSize = 1200; |
const int kBitrateBps = 10 * kPacketSize * 8; // 10 packets per second. |
+ const int kBitrateKbps = (kBitrateBps + 500) / 1000; |
- send_bucket_->SetEstimatedBitrate(kBitrateBps); |
+ send_bucket_->UpdateBitrate(kBitrateKbps, kBitrateKbps, kBitrateKbps); |
EXPECT_EQ(0, send_bucket_->AverageQueueTimeMs()); |