[rtcp] Tmmbn/Tmmbr Parse updated not to use RTCPUtility
BUG=webrtc:5260
Review-Url: https://codereview.webrtc.org/2010723002
Cr-Commit-Position: refs/heads/master@{#12916}
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/rtpfb.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/rtpfb.cc
index b5571d4..1286229 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_packet/rtpfb.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/rtpfb.cc
@@ -14,7 +14,7 @@
namespace webrtc {
namespace rtcp {
-
+constexpr uint8_t Rtpfb::kPacketType;
// RFC 4585, Section 6.1: Feedback format.
//
// Common packet format:
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/rtpfb.h b/webrtc/modules/rtp_rtcp/source/rtcp_packet/rtpfb.h
index 801aa08..de1cf76 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_packet/rtpfb.h
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/rtpfb.h
@@ -22,10 +22,10 @@
// RFC4585, Section 6.2
class Rtpfb : public RtcpPacket {
public:
- static const uint8_t kPacketType = 205;
+ static constexpr uint8_t kPacketType = 205;
Rtpfb() : sender_ssrc_(0), media_ssrc_(0) {}
- virtual ~Rtpfb() {}
+ ~Rtpfb() override {}
void From(uint32_t ssrc) { sender_ssrc_ = ssrc; }
void To(uint32_t ssrc) { media_ssrc_ = ssrc; }
@@ -34,7 +34,7 @@
uint32_t media_ssrc() const { return media_ssrc_; }
protected:
- static const size_t kCommonFeedbackLength = 8;
+ static constexpr size_t kCommonFeedbackLength = 8;
void ParseCommonFeedback(const uint8_t* payload);
void CreateCommonFeedback(uint8_t* payload) const;
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.cc
index 730b408..f5683fb 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.cc
@@ -13,11 +13,11 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
-
-using webrtc::RTCPUtility::RtcpCommonHeader;
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
namespace webrtc {
namespace rtcp {
+constexpr uint8_t Tmmbn::kFeedbackMessageType;
// RFC 4585: Feedback format.
// Common packet format:
//
@@ -42,23 +42,23 @@
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | MxTBR Exp | MxTBR Mantissa |Measured Overhead|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-bool Tmmbn::Parse(const RtcpCommonHeader& header, const uint8_t* payload) {
- RTC_CHECK(header.packet_type == kPacketType);
- RTC_CHECK(header.count_or_format == kFeedbackMessageType);
+bool Tmmbn::Parse(const CommonHeader& packet) {
+ RTC_DCHECK_EQ(packet.type(), kPacketType);
+ RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType);
- if (header.payload_size_bytes < kCommonFeedbackLength) {
- LOG(LS_WARNING) << "Payload length " << header.payload_size_bytes
+ if (packet.payload_size_bytes() < kCommonFeedbackLength) {
+ LOG(LS_WARNING) << "Payload length " << packet.payload_size_bytes()
<< " is too small for TMMBN.";
return false;
}
- size_t items_size_bytes = header.payload_size_bytes - kCommonFeedbackLength;
+ size_t items_size_bytes = packet.payload_size_bytes() - kCommonFeedbackLength;
if (items_size_bytes % TmmbItem::kLength != 0) {
- LOG(LS_WARNING) << "Payload length " << header.payload_size_bytes
+ LOG(LS_WARNING) << "Payload length " << packet.payload_size_bytes()
<< " is not valid for TMMBN.";
return false;
}
- ParseCommonFeedback(payload);
- const uint8_t* next_item = payload + kCommonFeedbackLength;
+ ParseCommonFeedback(packet.payload());
+ const uint8_t* next_item = packet.payload() + kCommonFeedbackLength;
size_t number_of_items = items_size_bytes / TmmbItem::kLength;
items_.resize(number_of_items);
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.h b/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.h
index c84d0df..a801816 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.h
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.h
@@ -17,22 +17,22 @@
#include "webrtc/base/constructormagic.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rtpfb.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmb_item.h"
-#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
namespace webrtc {
namespace rtcp {
+class CommonHeader;
+
// Temporary Maximum Media Stream Bit Rate Notification (TMMBN).
// RFC 5104, Section 4.2.2.
class Tmmbn : public Rtpfb {
public:
- static const uint8_t kFeedbackMessageType = 4;
+ static constexpr uint8_t kFeedbackMessageType = 4;
Tmmbn() {}
~Tmmbn() override {}
// Parse assumes header is already parsed and validated.
- bool Parse(const RTCPUtility::RtcpCommonHeader& header,
- const uint8_t* payload); // Size of the payload is in the header.
+ bool Parse(const CommonHeader& packet);
void WithTmmbr(uint32_t ssrc, uint32_t bitrate_kbps, uint16_t overhead) {
WithTmmbr(TmmbItem(ssrc, bitrate_kbps * 1000, overhead));
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn_unittest.cc
index c3b43e4..3df6b5d 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn_unittest.cc
@@ -12,14 +12,13 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/test/rtcp_packet_parser.h"
using testing::ElementsAreArray;
using testing::IsEmpty;
using testing::make_tuple;
using webrtc::rtcp::TmmbItem;
using webrtc::rtcp::Tmmbn;
-using webrtc::RTCPUtility::RtcpCommonHeader;
-using webrtc::RTCPUtility::RtcpParseCommonHeader;
namespace webrtc {
namespace {
@@ -32,13 +31,6 @@
0x00, 0x00, 0x00, 0x00,
0x23, 0x45, 0x67, 0x89,
0x0a, 0x61, 0x61, 0xfe};
-
-bool ParseTmmbn(const uint8_t* buffer, size_t length, Tmmbn* tmmbn) {
- RtcpCommonHeader header;
- EXPECT_TRUE(RtcpParseCommonHeader(buffer, length, &header));
- EXPECT_EQ(length, header.BlockSize());
- return tmmbn->Parse(header, buffer + RtcpCommonHeader::kHeaderSizeBytes);
-}
} // namespace
TEST(RtcpPacketTmmbnTest, Create) {
@@ -54,7 +46,7 @@
TEST(RtcpPacketTmmbnTest, Parse) {
Tmmbn tmmbn;
- EXPECT_TRUE(ParseTmmbn(kPacket, sizeof(kPacket), &tmmbn));
+ EXPECT_TRUE(test::ParseSinglePacket(kPacket, &tmmbn));
const Tmmbn& parsed = tmmbn;
@@ -71,7 +63,7 @@
rtc::Buffer packet = tmmbn.Build();
Tmmbn parsed;
- EXPECT_TRUE(ParseTmmbn(packet.data(), packet.size(), &parsed));
+ EXPECT_TRUE(test::ParseSinglePacket(packet, &parsed));
EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
EXPECT_THAT(parsed.items(), IsEmpty());
@@ -85,7 +77,7 @@
rtc::Buffer packet = tmmbn.Build();
Tmmbn parsed;
- EXPECT_TRUE(ParseTmmbn(packet.data(), packet.size(), &parsed));
+ EXPECT_TRUE(test::ParseSinglePacket(packet, &parsed));
EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
EXPECT_EQ(2u, parsed.items().size());
@@ -101,7 +93,7 @@
const uint8_t kSmallPacket[] = {0x84, 205, 0x00, 0x01,
0x12, 0x34, 0x56, 0x78};
Tmmbn tmmbn;
- EXPECT_FALSE(ParseTmmbn(kSmallPacket, sizeof(kSmallPacket), &tmmbn));
+ EXPECT_FALSE(test::ParseSinglePacket(kSmallPacket, &tmmbn));
}
TEST(RtcpPacketTmmbnTest, ParseFailsOnUnAlignedPacket) {
@@ -111,6 +103,6 @@
0x23, 0x45, 0x67, 0x89};
Tmmbn tmmbn;
- EXPECT_FALSE(ParseTmmbn(kUnalignedPacket, sizeof(kUnalignedPacket), &tmmbn));
+ EXPECT_FALSE(test::ParseSinglePacket(kUnalignedPacket, &tmmbn));
}
} // namespace webrtc
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.cc
index b24b039..6f957ae 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.cc
@@ -13,11 +13,11 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
-
-using webrtc::RTCPUtility::RtcpCommonHeader;
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
namespace webrtc {
namespace rtcp {
+constexpr uint8_t Tmmbr::kFeedbackMessageType;
// RFC 4585: Feedback format.
// Common packet format:
//
@@ -43,24 +43,24 @@
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | MxTBR Exp | MxTBR Mantissa |Measured Overhead|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-bool Tmmbr::Parse(const RtcpCommonHeader& header, const uint8_t* payload) {
- RTC_CHECK(header.packet_type == kPacketType);
- RTC_CHECK(header.count_or_format == kFeedbackMessageType);
+bool Tmmbr::Parse(const CommonHeader& packet) {
+ RTC_DCHECK_EQ(packet.type(), kPacketType);
+ RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType);
- if (header.payload_size_bytes < kCommonFeedbackLength + TmmbItem::kLength) {
- LOG(LS_WARNING) << "Payload length " << header.payload_size_bytes
+ if (packet.payload_size_bytes() < kCommonFeedbackLength + TmmbItem::kLength) {
+ LOG(LS_WARNING) << "Payload length " << packet.payload_size_bytes()
<< " is too small for a TMMBR.";
return false;
}
- size_t items_size_bytes = header.payload_size_bytes - kCommonFeedbackLength;
+ size_t items_size_bytes = packet.payload_size_bytes() - kCommonFeedbackLength;
if (items_size_bytes % TmmbItem::kLength != 0) {
- LOG(LS_WARNING) << "Payload length " << header.payload_size_bytes
+ LOG(LS_WARNING) << "Payload length " << packet.payload_size_bytes()
<< " is not valid for a TMMBR.";
return false;
}
- ParseCommonFeedback(payload);
+ ParseCommonFeedback(packet.payload());
- const uint8_t* next_item = payload + kCommonFeedbackLength;
+ const uint8_t* next_item = packet.payload() + kCommonFeedbackLength;
size_t number_of_items = items_size_bytes / TmmbItem::kLength;
items_.resize(number_of_items);
for (TmmbItem& item : items_) {
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h b/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h
index 15bfc58..3705f52 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h
@@ -17,22 +17,22 @@
#include "webrtc/base/constructormagic.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rtpfb.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmb_item.h"
-#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
namespace webrtc {
namespace rtcp {
+class CommonHeader;
+
// Temporary Maximum Media Stream Bit Rate Request (TMMBR).
// RFC 5104, Section 4.2.1.
class Tmmbr : public Rtpfb {
public:
- static const uint8_t kFeedbackMessageType = 3;
+ static constexpr uint8_t kFeedbackMessageType = 3;
Tmmbr() {}
~Tmmbr() override {}
// Parse assumes header is already parsed and validated.
- bool Parse(const RTCPUtility::RtcpCommonHeader& header,
- const uint8_t* payload); // Size of the payload is in the header.
+ bool Parse(const CommonHeader& packet);
void WithTmmbr(const TmmbItem& item);
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr_unittest.cc
index 7ced3f8..45f12c3 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr_unittest.cc
@@ -12,14 +12,13 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/test/rtcp_packet_parser.h"
using testing::ElementsAreArray;
using testing::IsEmpty;
using testing::make_tuple;
using webrtc::rtcp::TmmbItem;
using webrtc::rtcp::Tmmbr;
-using webrtc::RTCPUtility::RtcpCommonHeader;
-using webrtc::RTCPUtility::RtcpParseCommonHeader;
namespace webrtc {
namespace {
@@ -32,13 +31,6 @@
0x00, 0x00, 0x00, 0x00,
0x23, 0x45, 0x67, 0x89,
0x0a, 0x61, 0x61, 0xfe};
-
-bool ParseTmmbr(const uint8_t* buffer, size_t length, Tmmbr* tmmbr) {
- RtcpCommonHeader header;
- EXPECT_TRUE(RtcpParseCommonHeader(buffer, length, &header));
- EXPECT_EQ(length, header.BlockSize());
- return tmmbr->Parse(header, buffer + RtcpCommonHeader::kHeaderSizeBytes);
-}
} // namespace
TEST(RtcpPacketTmmbrTest, Create) {
@@ -54,7 +46,7 @@
TEST(RtcpPacketTmmbrTest, Parse) {
Tmmbr tmmbr;
- EXPECT_TRUE(ParseTmmbr(kPacket, sizeof(kPacket), &tmmbr));
+ EXPECT_TRUE(test::ParseSinglePacket(kPacket, &tmmbr));
const Tmmbr& parsed = tmmbr;
EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
@@ -73,7 +65,7 @@
rtc::Buffer packet = tmmbr.Build();
Tmmbr parsed;
- EXPECT_TRUE(ParseTmmbr(packet.data(), packet.size(), &parsed));
+ EXPECT_TRUE(test::ParseSinglePacket(packet, &parsed));
EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
EXPECT_EQ(2u, parsed.requests().size());
@@ -87,7 +79,7 @@
0x00, 0x00, 0x00, 0x00};
Tmmbr tmmbr;
- EXPECT_FALSE(ParseTmmbr(kZeroItemsPacket, sizeof(kZeroItemsPacket), &tmmbr));
+ EXPECT_FALSE(test::ParseSinglePacket(kZeroItemsPacket, &tmmbr));
}
TEST(RtcpPacketTmmbrTest, ParseFailsOnUnAlignedPacket) {
@@ -99,6 +91,6 @@
0x34, 0x56, 0x78, 0x9a};
Tmmbr tmmbr;
- EXPECT_FALSE(ParseTmmbr(kUnalignedPacket, sizeof(kUnalignedPacket), &tmmbr));
+ EXPECT_FALSE(test::ParseSinglePacket(kUnalignedPacket, &tmmbr));
}
} // namespace webrtc