OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | 10 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 packet.SetPayloadType(kPayloadType); | 109 packet.SetPayloadType(kPayloadType); |
110 packet.SetSequenceNumber(kSeqNum); | 110 packet.SetSequenceNumber(kSeqNum); |
111 packet.SetTimestamp(kTimestamp); | 111 packet.SetTimestamp(kTimestamp); |
112 packet.SetSsrc(kSsrc); | 112 packet.SetSsrc(kSsrc); |
113 packet.SetExtension<TransmissionOffset>(kTimeOffset); | 113 packet.SetExtension<TransmissionOffset>(kTimeOffset); |
114 packet.SetExtension<AudioLevel>(kVoiceActive, kAudioLevel); | 114 packet.SetExtension<AudioLevel>(kVoiceActive, kAudioLevel); |
115 EXPECT_THAT(kPacketWithTOAndAL, | 115 EXPECT_THAT(kPacketWithTOAndAL, |
116 ElementsAreArray(packet.data(), packet.size())); | 116 ElementsAreArray(packet.data(), packet.size())); |
117 } | 117 } |
118 | 118 |
| 119 TEST(RtpPacketTest, CreateWithExtensionsWithoutManager) { |
| 120 RtpPacketToSend packet(nullptr); |
| 121 packet.SetPayloadType(kPayloadType); |
| 122 packet.SetSequenceNumber(kSeqNum); |
| 123 packet.SetTimestamp(kTimestamp); |
| 124 packet.SetSsrc(kSsrc); |
| 125 |
| 126 auto raw = packet.AllocateRawExtension(kTransmissionOffsetExtensionId, |
| 127 TransmissionOffset::kValueSizeBytes); |
| 128 EXPECT_EQ(raw.size(), TransmissionOffset::kValueSizeBytes); |
| 129 TransmissionOffset::Write(raw.data(), kTimeOffset); |
| 130 |
| 131 raw = packet.AllocateRawExtension(kAudioLevelExtensionId, |
| 132 AudioLevel::kValueSizeBytes); |
| 133 EXPECT_EQ(raw.size(), AudioLevel::kValueSizeBytes); |
| 134 AudioLevel::Write(raw.data(), kVoiceActive, kAudioLevel); |
| 135 |
| 136 EXPECT_THAT(kPacketWithTOAndAL, |
| 137 ElementsAreArray(packet.data(), packet.size())); |
| 138 } |
| 139 |
| 140 TEST(RtpPacketTest, CreateWithMaxSizeHeaderExtension) { |
| 141 const size_t kMaxExtensionSize = 16; |
| 142 const int kId = 1; |
| 143 const uint8_t kValue[16] = "123456789abcdef"; |
| 144 |
| 145 // Write packet with a custom extension. |
| 146 RtpPacketToSend packet(nullptr); |
| 147 packet.SetRawExtension(kId, kValue); |
| 148 // Using different size for same id is not allowed. |
| 149 EXPECT_TRUE(packet.AllocateRawExtension(kId, kMaxExtensionSize - 1).empty()); |
| 150 |
| 151 packet.SetPayloadSize(42); |
| 152 // Rewriting allocated extension is allowed. |
| 153 EXPECT_EQ(packet.AllocateRawExtension(kId, kMaxExtensionSize).size(), |
| 154 kMaxExtensionSize); |
| 155 // Adding another extension after payload is set is not allowed. |
| 156 EXPECT_TRUE(packet.AllocateRawExtension(kId + 1, kMaxExtensionSize).empty()); |
| 157 |
| 158 // Read packet with the custom extension. |
| 159 RtpPacketReceived parsed; |
| 160 EXPECT_TRUE(parsed.Parse(packet.Buffer())); |
| 161 auto read_raw = parsed.GetRawExtension(kId); |
| 162 EXPECT_THAT(read_raw, ElementsAreArray(kValue, kMaxExtensionSize)); |
| 163 } |
| 164 |
119 TEST(RtpPacketTest, SetReservedExtensionsAfterPayload) { | 165 TEST(RtpPacketTest, SetReservedExtensionsAfterPayload) { |
120 const size_t kPayloadSize = 4; | 166 const size_t kPayloadSize = 4; |
121 RtpPacketToSend::ExtensionManager extensions; | 167 RtpPacketToSend::ExtensionManager extensions; |
122 extensions.Register(kRtpExtensionTransmissionTimeOffset, | 168 extensions.Register(kRtpExtensionTransmissionTimeOffset, |
123 kTransmissionOffsetExtensionId); | 169 kTransmissionOffsetExtensionId); |
124 extensions.Register(kRtpExtensionAudioLevel, kAudioLevelExtensionId); | 170 extensions.Register(kRtpExtensionAudioLevel, kAudioLevelExtensionId); |
125 RtpPacketToSend packet(&extensions); | 171 RtpPacketToSend packet(&extensions); |
126 | 172 |
127 EXPECT_TRUE(packet.ReserveExtension<TransmissionOffset>()); | 173 EXPECT_TRUE(packet.ReserveExtension<TransmissionOffset>()); |
128 packet.SetPayloadSize(kPayloadSize); | 174 packet.SetPayloadSize(kPayloadSize); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 339 |
294 int32_t time_offset; | 340 int32_t time_offset; |
295 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset)); | 341 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset)); |
296 packet.IdentifyExtensions(extensions); | 342 packet.IdentifyExtensions(extensions); |
297 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset)); | 343 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset)); |
298 EXPECT_EQ(kTimeOffset, time_offset); | 344 EXPECT_EQ(kTimeOffset, time_offset); |
299 EXPECT_EQ(0u, packet.payload_size()); | 345 EXPECT_EQ(0u, packet.payload_size()); |
300 EXPECT_EQ(0u, packet.padding_size()); | 346 EXPECT_EQ(0u, packet.padding_size()); |
301 } | 347 } |
302 | 348 |
| 349 TEST(RtpPacketTest, ParseWithoutExtensionManager) { |
| 350 RtpPacketReceived packet; |
| 351 EXPECT_TRUE(packet.Parse(kPacketWithTO, sizeof(kPacketWithTO))); |
| 352 |
| 353 EXPECT_FALSE(packet.HasRawExtension(kAudioLevelExtensionId)); |
| 354 EXPECT_TRUE(packet.GetRawExtension(kAudioLevelExtensionId).empty()); |
| 355 |
| 356 EXPECT_TRUE(packet.HasRawExtension(kTransmissionOffsetExtensionId)); |
| 357 |
| 358 int32_t time_offset = 0; |
| 359 auto raw_extension = packet.GetRawExtension(kTransmissionOffsetExtensionId); |
| 360 EXPECT_EQ(raw_extension.size(), TransmissionOffset::kValueSizeBytes); |
| 361 EXPECT_TRUE(TransmissionOffset::Parse(raw_extension.data(), &time_offset)); |
| 362 |
| 363 EXPECT_EQ(time_offset, kTimeOffset); |
| 364 } |
| 365 |
303 } // namespace webrtc | 366 } // namespace webrtc |
OLD | NEW |