Parse the number of packets lost in RTCP SR as a signed integer.

The cumulative number of packets lost in a RTCP sender report can be
negative if there are duplicates. This CL fixes a bug that the parser of
RTCP reports treats the field as an unsigned integer, and incorrectly
reports large packet losses when a negative loss is reported.

Bug: webrtc:9601
Change-Id: I1109ac0741614d61bda743e13a390b7d3e147a9c
Reviewed-on: https://webrtc-review.googlesource.com/92942
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Qingsi Wang <qingsi@google.com>
Cr-Commit-Position: refs/heads/master@{#24234}
This commit is contained in:
Qingsi Wang 2018-08-07 17:06:45 -07:00 committed by Commit Bot
parent 25d31ec440
commit b2db53998d
2 changed files with 16 additions and 1 deletions

View File

@ -54,7 +54,7 @@ bool ReportBlock::Parse(const uint8_t* buffer, size_t length) {
source_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&buffer[0]);
fraction_lost_ = buffer[4];
cumulative_lost_ = ByteReader<uint32_t, 3>::ReadBigEndian(&buffer[5]);
cumulative_lost_ = ByteReader<int32_t, 3>::ReadBigEndian(&buffer[5]);
extended_high_seq_num_ = ByteReader<uint32_t>::ReadBigEndian(&buffer[8]);
jitter_ = ByteReader<uint32_t>::ReadBigEndian(&buffer[12]);
last_sr_ = ByteReader<uint32_t>::ReadBigEndian(&buffer[16]);

View File

@ -91,5 +91,20 @@ TEST(RtcpPacketReportBlockTest, ValidateCumulativeLost) {
EXPECT_EQ(0u, rb.cumulative_lost());
}
TEST(RtcpPacketReportBlockTest, ParseNegativeCumulativeLost) {
// CumulativeLost is a signed 24-bit integer.
const int32_t kNegativeCumulativeLost = -123;
ReportBlock rb;
EXPECT_TRUE(rb.SetCumulativeLost(kNegativeCumulativeLost));
uint8_t buffer[kBufferLength];
rb.Create(buffer);
ReportBlock parsed;
EXPECT_TRUE(parsed.Parse(buffer, kBufferLength));
EXPECT_EQ(kNegativeCumulativeLost, parsed.cumulative_lost_signed());
}
} // namespace
} // namespace webrtc