Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: webrtc/modules/rtp_rtcp/source/rtp_packet_unittest.cc

Issue 2789773004: Add functions to get/set rtp header extension by id. (Closed)
Patch Set: nits Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_packet.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/rtp_rtcp/source/rtp_packet_unittest.cc
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_packet_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_packet_unittest.cc
index 2f1259e1bc4ed615ece0efe7ac542b4f6cf03d95..d8870654f8b37071a9d79c3e22447e85bf338037 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_packet_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_packet_unittest.cc
@@ -116,6 +116,52 @@ TEST(RtpPacketTest, CreateWith2Extensions) {
ElementsAreArray(packet.data(), packet.size()));
}
+TEST(RtpPacketTest, CreateWithExtensionsWithoutManager) {
+ RtpPacketToSend packet(nullptr);
+ packet.SetPayloadType(kPayloadType);
+ packet.SetSequenceNumber(kSeqNum);
+ packet.SetTimestamp(kTimestamp);
+ packet.SetSsrc(kSsrc);
+
+ auto raw = packet.AllocateRawExtension(kTransmissionOffsetExtensionId,
+ TransmissionOffset::kValueSizeBytes);
+ EXPECT_EQ(raw.size(), TransmissionOffset::kValueSizeBytes);
+ TransmissionOffset::Write(raw.data(), kTimeOffset);
+
+ raw = packet.AllocateRawExtension(kAudioLevelExtensionId,
+ AudioLevel::kValueSizeBytes);
+ EXPECT_EQ(raw.size(), AudioLevel::kValueSizeBytes);
+ AudioLevel::Write(raw.data(), kVoiceActive, kAudioLevel);
+
+ EXPECT_THAT(kPacketWithTOAndAL,
+ ElementsAreArray(packet.data(), packet.size()));
+}
+
+TEST(RtpPacketTest, CreateWithMaxSizeHeaderExtension) {
+ const size_t kMaxExtensionSize = 16;
+ const int kId = 1;
+ const uint8_t kValue[16] = "123456789abcdef";
+
+ // Write packet with a custom extension.
+ RtpPacketToSend packet(nullptr);
+ packet.SetRawExtension(kId, kValue);
+ // Using different size for same id is not allowed.
+ EXPECT_TRUE(packet.AllocateRawExtension(kId, kMaxExtensionSize - 1).empty());
+
+ packet.SetPayloadSize(42);
+ // Rewriting allocated extension is allowed.
+ EXPECT_EQ(packet.AllocateRawExtension(kId, kMaxExtensionSize).size(),
+ kMaxExtensionSize);
+ // Adding another extension after payload is set is not allowed.
+ EXPECT_TRUE(packet.AllocateRawExtension(kId + 1, kMaxExtensionSize).empty());
+
+ // Read packet with the custom extension.
+ RtpPacketReceived parsed;
+ EXPECT_TRUE(parsed.Parse(packet.Buffer()));
+ auto read_raw = parsed.GetRawExtension(kId);
+ EXPECT_THAT(read_raw, ElementsAreArray(kValue, kMaxExtensionSize));
+}
+
TEST(RtpPacketTest, SetReservedExtensionsAfterPayload) {
const size_t kPayloadSize = 4;
RtpPacketToSend::ExtensionManager extensions;
@@ -300,4 +346,21 @@ TEST(RtpPacketTest, ParseWithExtensionDelayed) {
EXPECT_EQ(0u, packet.padding_size());
}
+TEST(RtpPacketTest, ParseWithoutExtensionManager) {
+ RtpPacketReceived packet;
+ EXPECT_TRUE(packet.Parse(kPacketWithTO, sizeof(kPacketWithTO)));
+
+ EXPECT_FALSE(packet.HasRawExtension(kAudioLevelExtensionId));
+ EXPECT_TRUE(packet.GetRawExtension(kAudioLevelExtensionId).empty());
+
+ EXPECT_TRUE(packet.HasRawExtension(kTransmissionOffsetExtensionId));
+
+ int32_t time_offset = 0;
+ auto raw_extension = packet.GetRawExtension(kTransmissionOffsetExtensionId);
+ EXPECT_EQ(raw_extension.size(), TransmissionOffset::kValueSizeBytes);
+ EXPECT_TRUE(TransmissionOffset::Parse(raw_extension.data(), &time_offset));
+
+ EXPECT_EQ(time_offset, kTimeOffset);
+}
+
} // namespace webrtc
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_packet.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698