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 13 matching lines...) Expand all Loading... |
24 constexpr int8_t kPayloadType = 100; | 24 constexpr int8_t kPayloadType = 100; |
25 constexpr uint32_t kSsrc = 0x12345678; | 25 constexpr uint32_t kSsrc = 0x12345678; |
26 constexpr uint16_t kSeqNum = 88; | 26 constexpr uint16_t kSeqNum = 88; |
27 constexpr uint32_t kTimestamp = 0x65431278; | 27 constexpr uint32_t kTimestamp = 0x65431278; |
28 constexpr uint8_t kTransmissionOffsetExtensionId = 1; | 28 constexpr uint8_t kTransmissionOffsetExtensionId = 1; |
29 constexpr uint8_t kAudioLevelExtensionId = 9; | 29 constexpr uint8_t kAudioLevelExtensionId = 9; |
30 constexpr int32_t kTimeOffset = 0x56ce; | 30 constexpr int32_t kTimeOffset = 0x56ce; |
31 constexpr bool kVoiceActive = true; | 31 constexpr bool kVoiceActive = true; |
32 constexpr uint8_t kAudioLevel = 0x5a; | 32 constexpr uint8_t kAudioLevel = 0x5a; |
33 constexpr size_t kMaxPaddingSize = 224u; | 33 constexpr size_t kMaxPaddingSize = 224u; |
34 // clang-format off | |
35 constexpr uint8_t kMinimumPacket[] = { | 34 constexpr uint8_t kMinimumPacket[] = { |
36 0x80, kPayloadType, 0x00, kSeqNum, | 35 0x80, kPayloadType, 0x00, kSeqNum, |
37 0x65, 0x43, 0x12, 0x78, | 36 0x65, 0x43, 0x12, 0x78, |
38 0x12, 0x34, 0x56, 0x78}; | 37 0x12, 0x34, 0x56, 0x78}; |
39 constexpr uint8_t kPacketWithTO[] = { | 38 constexpr uint8_t kPacketWithTO[] = { |
40 0x90, kPayloadType, 0x00, kSeqNum, | 39 0x90, kPayloadType, 0x00, kSeqNum, |
41 0x65, 0x43, 0x12, 0x78, | 40 0x65, 0x43, 0x12, 0x78, |
42 0x12, 0x34, 0x56, 0x78, | 41 0x12, 0x34, 0x56, 0x78, |
43 0xbe, 0xde, 0x00, 0x01, | 42 0xbe, 0xde, 0x00, 0x01, |
44 0x12, 0x00, 0x56, 0xce}; | 43 0x12, 0x00, 0x56, 0xce}; |
(...skipping 12 matching lines...) Expand all Loading... |
57 constexpr uint8_t kPacket[] = { | 56 constexpr uint8_t kPacket[] = { |
58 0xb2, kPayloadType, 0x00, kSeqNum, | 57 0xb2, kPayloadType, 0x00, kSeqNum, |
59 0x65, 0x43, 0x12, 0x78, | 58 0x65, 0x43, 0x12, 0x78, |
60 0x12, 0x34, 0x56, 0x78, | 59 0x12, 0x34, 0x56, 0x78, |
61 0x34, 0x56, 0x78, 0x90, | 60 0x34, 0x56, 0x78, 0x90, |
62 0x32, 0x43, 0x54, 0x65, | 61 0x32, 0x43, 0x54, 0x65, |
63 0xbe, 0xde, 0x00, 0x01, | 62 0xbe, 0xde, 0x00, 0x01, |
64 0x12, 0x00, 0x56, 0xce, | 63 0x12, 0x00, 0x56, 0xce, |
65 'p', 'a', 'y', 'l', 'o', 'a', 'd', | 64 'p', 'a', 'y', 'l', 'o', 'a', 'd', |
66 'p', 'a', 'd', 'd', 'i', 'n', 'g', kPacketPaddingSize}; | 65 'p', 'a', 'd', 'd', 'i', 'n', 'g', kPacketPaddingSize}; |
67 // clang-format on | 66 |
68 } // namespace | 67 } // namespace |
69 | 68 |
70 TEST(RtpPacketTest, CreateMinimum) { | 69 TEST(RtpPacketTest, CreateMinimum) { |
71 RtpPacketToSend packet(nullptr); | 70 RtpPacketToSend packet(nullptr); |
72 packet.SetPayloadType(kPayloadType); | 71 packet.SetPayloadType(kPayloadType); |
73 packet.SetSequenceNumber(kSeqNum); | 72 packet.SetSequenceNumber(kSeqNum); |
74 packet.SetTimestamp(kTimestamp); | 73 packet.SetTimestamp(kTimestamp); |
75 packet.SetSsrc(kSsrc); | 74 packet.SetSsrc(kSsrc); |
76 EXPECT_THAT(kMinimumPacket, ElementsAreArray(packet.data(), packet.size())); | 75 EXPECT_THAT(kMinimumPacket, ElementsAreArray(packet.data(), packet.size())); |
77 } | 76 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 EXPECT_EQ(kSeqNum, packet.SequenceNumber()); | 186 EXPECT_EQ(kSeqNum, packet.SequenceNumber()); |
188 EXPECT_EQ(kTimestamp, packet.Timestamp()); | 187 EXPECT_EQ(kTimestamp, packet.Timestamp()); |
189 EXPECT_EQ(kSsrc, packet.Ssrc()); | 188 EXPECT_EQ(kSsrc, packet.Ssrc()); |
190 int32_t time_offset; | 189 int32_t time_offset; |
191 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset)); | 190 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset)); |
192 EXPECT_EQ(kTimeOffset, time_offset); | 191 EXPECT_EQ(kTimeOffset, time_offset); |
193 EXPECT_EQ(0u, packet.payload_size()); | 192 EXPECT_EQ(0u, packet.payload_size()); |
194 EXPECT_EQ(0u, packet.padding_size()); | 193 EXPECT_EQ(0u, packet.padding_size()); |
195 } | 194 } |
196 | 195 |
197 TEST(RtpPacketTest, ParseWithInvalidSizedExtension) { | |
198 // clang-format off | |
199 constexpr uint8_t kBadPacket[] = { | |
200 0x90, kPayloadType, 0x00, kSeqNum, | |
201 0x65, 0x43, 0x12, 0x78, // kTimestamp. | |
202 0x12, 0x34, 0x56, 0x78, // kSSrc. | |
203 0xbe, 0xde, 0x00, 0x02, // Extension block of size 2 x 32bit words. | |
204 (kTransmissionOffsetExtensionId << 4) | 6, // (6+1)-byte extension, but | |
205 'e', 'x', 't', // Transmission Offset | |
206 'd', 'a', 't', 'a', // expected to be 3-bytes. | |
207 'p', 'a', 'y', 'l', 'o', 'a', 'd', | |
208 }; | |
209 // clang-format on | |
210 | |
211 RtpPacketToSend::ExtensionManager extensions; | |
212 extensions.Register(kRtpExtensionTransmissionTimeOffset, | |
213 kTransmissionOffsetExtensionId); | |
214 | |
215 RtpPacketReceived packet(&extensions); | |
216 EXPECT_TRUE(packet.Parse(kBadPacket, sizeof(kBadPacket))); | |
217 | |
218 // Extension should be ignored. | |
219 int32_t time_offset; | |
220 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset)); | |
221 | |
222 // But shouldn't prevent reading payload. | |
223 EXPECT_THAT(make_tuple(packet.payload(), packet.payload_size()), | |
224 ElementsAreArray(kPayload)); | |
225 } | |
226 | |
227 TEST(RtpPacketTest, ParseWith2Extensions) { | 196 TEST(RtpPacketTest, ParseWith2Extensions) { |
228 RtpPacketToSend::ExtensionManager extensions; | 197 RtpPacketToSend::ExtensionManager extensions; |
229 extensions.Register(kRtpExtensionTransmissionTimeOffset, | 198 extensions.Register(kRtpExtensionTransmissionTimeOffset, |
230 kTransmissionOffsetExtensionId); | 199 kTransmissionOffsetExtensionId); |
231 extensions.Register(kRtpExtensionAudioLevel, kAudioLevelExtensionId); | 200 extensions.Register(kRtpExtensionAudioLevel, kAudioLevelExtensionId); |
232 RtpPacketReceived packet(&extensions); | 201 RtpPacketReceived packet(&extensions); |
233 EXPECT_TRUE(packet.Parse(kPacketWithTOAndAL, sizeof(kPacketWithTOAndAL))); | 202 EXPECT_TRUE(packet.Parse(kPacketWithTOAndAL, sizeof(kPacketWithTOAndAL))); |
234 int32_t time_offset; | 203 int32_t time_offset; |
235 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset)); | 204 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset)); |
236 EXPECT_EQ(kTimeOffset, time_offset); | 205 EXPECT_EQ(kTimeOffset, time_offset); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 int32_t time_offset; | 243 int32_t time_offset; |
275 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset)); | 244 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset)); |
276 packet.IdentifyExtensions(&extensions); | 245 packet.IdentifyExtensions(&extensions); |
277 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset)); | 246 EXPECT_TRUE(packet.GetExtension<TransmissionOffset>(&time_offset)); |
278 EXPECT_EQ(kTimeOffset, time_offset); | 247 EXPECT_EQ(kTimeOffset, time_offset); |
279 EXPECT_EQ(0u, packet.payload_size()); | 248 EXPECT_EQ(0u, packet.payload_size()); |
280 EXPECT_EQ(0u, packet.padding_size()); | 249 EXPECT_EQ(0u, packet.padding_size()); |
281 } | 250 } |
282 | 251 |
283 } // namespace webrtc | 252 } // namespace webrtc |
OLD | NEW |