Skip to content

Commit

Permalink
Fixes unit tests and bad sequence number translations (#818)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Mar 22, 2017
1 parent f448295 commit 0a75766
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
5 changes: 4 additions & 1 deletion erizo/src/erizo/rtp/SequenceNumberTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ SequenceNumber SequenceNumberTranslator::generate() {
}

void SequenceNumberTranslator::updateLastOutputSequenceNumber(bool skip, uint16_t output_sequence_number) {
if (!skip && RtpUtils::sequenceNumberLessThan(last_output_sequence_number_, output_sequence_number)) {
bool first_packet = !initialized_ && !(reset_ || offset_ > 0);
if (!skip &&
(RtpUtils::sequenceNumberLessThan(last_output_sequence_number_, output_sequence_number) || first_packet)) {
last_output_sequence_number_ = output_sequence_number;
}
}
Expand Down Expand Up @@ -138,6 +140,7 @@ void SequenceNumberTranslator::reset() {
return;
}
initialized_ = false;
reset_ = true;
first_input_sequence_number_ = 0;
last_input_sequence_number_ = 0;
in_out_buffer_ = std::vector<SequenceNumber>(kMaxSequenceNumberInBuffer);
Expand Down
30 changes: 24 additions & 6 deletions erizo/src/test/rtp/SequenceNumberTranslatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,21 @@ TEST_P(SequenceNumberTranslatorTest, shouldReturnRightOutputSequenceNumbers) {
SequenceNumber output;
if (packet.state == PacketState::Reset) {
translator.reset();
return;
continue;
} else if (packet.state == PacketState::Generate) {
output = translator.generate();
} else {
output = translator.get(packet.sequence_number, skip);
}
EXPECT_THAT(output.output, Eq(packet.expected_output));
if (output.type == SequenceNumberType::Valid) {
EXPECT_THAT(output.output, Eq(packet.expected_output));
}
EXPECT_THAT(output.type, Eq(packet.expected_type));

translator.reverse(packet.expected_output);
ASSERT_THAT(output.input, Eq(packet.sequence_number));
if (output.type == SequenceNumberType::Valid) {
ASSERT_THAT(output.input, Eq(packet.sequence_number));
}
ASSERT_THAT(output.type, Eq(packet.expected_type));
}
}
Expand Down Expand Up @@ -167,6 +171,12 @@ INSTANTIATE_TEST_CASE_P(
{ 0, PacketState::Reset, 0, SequenceNumberType::Skip},
{ 23537, PacketState::Forward, 5059, SequenceNumberType::Valid}}),

// input expected_output
std::vector<Packet>({{ 50000, PacketState::Forward, 50000, SequenceNumberType::Valid},
{ 0, PacketState::Reset, 0, SequenceNumberType::Skip},
{ 23537, PacketState::Forward, 50001, SequenceNumberType::Valid},
{ 23538, PacketState::Forward, 50002, SequenceNumberType::Valid}}),

// input expected_output
std::vector<Packet>({{ 0, PacketState::Generate, 1, SequenceNumberType::Generated},
{ 6, PacketState::Forward, 2, SequenceNumberType::Valid},
Expand All @@ -177,7 +187,7 @@ INSTANTIATE_TEST_CASE_P(
std::vector<Packet>({{ 6, PacketState::Forward, 6, SequenceNumberType::Valid},
{ 10, PacketState::Skip, 10, SequenceNumberType::Skip},
{ 0, PacketState::Reset, 0, SequenceNumberType::Skip},
{ 301, PacketState::Skip, 301, SequenceNumberType::Skip},
{ 301, PacketState::Skip, 7, SequenceNumberType::Skip},
{ 0, PacketState::Reset, 0, SequenceNumberType::Skip},
{ 901, PacketState::Forward, 7, SequenceNumberType::Valid}}),

Expand Down Expand Up @@ -206,7 +216,7 @@ INSTANTIATE_TEST_CASE_P(
{ 0, PacketState::Reset, 0, SequenceNumberType::Skip},
{ 0, PacketState::Generate, 32, SequenceNumberType::Generated},
{ 0, PacketState::Reset, 0, SequenceNumberType::Skip},
{ 6, PacketState::Forward, 34, SequenceNumberType::Valid}}),
{ 6, PacketState::Forward, 33, SequenceNumberType::Valid}}),

// input expected_output
std::vector<Packet>({{ 5059, PacketState::Skip, 5059, SequenceNumberType::Skip},
Expand All @@ -215,14 +225,22 @@ INSTANTIATE_TEST_CASE_P(
{ 0, PacketState::Reset, 0, SequenceNumberType::Skip},
{ 0, PacketState::Generate, 32, SequenceNumberType::Generated},
{ 0, PacketState::Reset, 0, SequenceNumberType::Skip},
{ 6, PacketState::Forward, 34, SequenceNumberType::Valid}}),
{ 6, PacketState::Forward, 33, SequenceNumberType::Valid}}),

// input expected_output
std::vector<Packet>({{ 5, PacketState::Forward, 5, SequenceNumberType::Valid},
{ 0, PacketState::Generate, 6, SequenceNumberType::Generated},
{ 6, PacketState::Forward, 7, SequenceNumberType::Valid},
{ 7, PacketState::Forward, 8, SequenceNumberType::Valid}}),

// input expected_output
std::vector<Packet>({{ 5, PacketState::Forward, 5, SequenceNumberType::Valid},
{ 0, PacketState::Generate, 6, SequenceNumberType::Generated},
{ 6, PacketState::Forward, 7, SequenceNumberType::Valid},
{ 7, PacketState::Forward, 8, SequenceNumberType::Valid},
{ 0, PacketState::Generate, 9, SequenceNumberType::Generated},
{ 8, PacketState::Forward, 10, SequenceNumberType::Valid}}),

// input expected_output
std::vector<Packet>({{ 5, PacketState::Forward, 5, SequenceNumberType::Valid},
{ 0, PacketState::Generate, 6, SequenceNumberType::Generated},
Expand Down

0 comments on commit 0a75766

Please sign in to comment.