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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_packet_unittest.cc

Issue 2899293002: Correct sequence-number injection into packets in rtp_packet_unittest.cc (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h"
12 12
13 #include "webrtc/base/random.h" 13 #include "webrtc/base/random.h"
14 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" 14 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
15 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" 15 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
16 #include "webrtc/test/gmock.h" 16 #include "webrtc/test/gmock.h"
17 #include "webrtc/test/gtest.h" 17 #include "webrtc/test/gtest.h"
18 18
19 namespace webrtc { 19 namespace webrtc {
20 namespace { 20 namespace {
21 using ::testing::ElementsAreArray; 21 using ::testing::ElementsAreArray;
22 using ::testing::IsEmpty; 22 using ::testing::IsEmpty;
23 using ::testing::make_tuple; 23 using ::testing::make_tuple;
24 24
25 constexpr int8_t kPayloadType = 100; 25 constexpr int8_t kPayloadType = 100;
26 constexpr uint32_t kSsrc = 0x12345678; 26 constexpr uint32_t kSsrc = 0x12345678;
27 constexpr uint16_t kSeqNum = 88; 27 constexpr uint16_t kSeqNum = 0x1234;
28 constexpr uint8_t kSeqNumFirstHalf = kSeqNum >> 8;
danilchap 2017/05/24 14:52:16 may be ...FirstByte
eladalon 2017/05/24 15:09:17 Done.
29 constexpr uint8_t kSeqNumSecondHalf = kSeqNum & 0xff;
28 constexpr uint32_t kTimestamp = 0x65431278; 30 constexpr uint32_t kTimestamp = 0x65431278;
29 constexpr uint8_t kTransmissionOffsetExtensionId = 1; 31 constexpr uint8_t kTransmissionOffsetExtensionId = 1;
30 constexpr uint8_t kAudioLevelExtensionId = 9; 32 constexpr uint8_t kAudioLevelExtensionId = 9;
31 constexpr uint8_t kRtpStreamIdExtensionId = 0xa; 33 constexpr uint8_t kRtpStreamIdExtensionId = 0xa;
32 constexpr int32_t kTimeOffset = 0x56ce; 34 constexpr int32_t kTimeOffset = 0x56ce;
33 constexpr bool kVoiceActive = true; 35 constexpr bool kVoiceActive = true;
34 constexpr uint8_t kAudioLevel = 0x5a; 36 constexpr uint8_t kAudioLevel = 0x5a;
35 constexpr char kStreamId[] = "streamid"; 37 constexpr char kStreamId[] = "streamid";
36 constexpr size_t kMaxPaddingSize = 224u; 38 constexpr size_t kMaxPaddingSize = 224u;
37 // clang-format off 39 // clang-format off
38 constexpr uint8_t kMinimumPacket[] = { 40 constexpr uint8_t kMinimumPacket[] = {
39 0x80, kPayloadType, 0x00, kSeqNum, 41 0x80, kPayloadType, kSeqNumFirstHalf, kSeqNumSecondHalf,
40 0x65, 0x43, 0x12, 0x78, 42 0x65, 0x43, 0x12, 0x78,
41 0x12, 0x34, 0x56, 0x78}; 43 0x12, 0x34, 0x56, 0x78};
42 44
43 constexpr uint8_t kPacketWithTO[] = { 45 constexpr uint8_t kPacketWithTO[] = {
44 0x90, kPayloadType, 0x00, kSeqNum, 46 0x90, kPayloadType, kSeqNumFirstHalf, kSeqNumSecondHalf,
45 0x65, 0x43, 0x12, 0x78, 47 0x65, 0x43, 0x12, 0x78,
46 0x12, 0x34, 0x56, 0x78, 48 0x12, 0x34, 0x56, 0x78,
47 0xbe, 0xde, 0x00, 0x01, 49 0xbe, 0xde, 0x00, 0x01,
48 0x12, 0x00, 0x56, 0xce}; 50 0x12, 0x00, 0x56, 0xce};
49 51
50 constexpr uint8_t kPacketWithTOAndAL[] = { 52 constexpr uint8_t kPacketWithTOAndAL[] = {
51 0x90, kPayloadType, 0x00, kSeqNum, 53 0x90, kPayloadType, kSeqNumFirstHalf, kSeqNumSecondHalf,
52 0x65, 0x43, 0x12, 0x78, 54 0x65, 0x43, 0x12, 0x78,
53 0x12, 0x34, 0x56, 0x78, 55 0x12, 0x34, 0x56, 0x78,
54 0xbe, 0xde, 0x00, 0x02, 56 0xbe, 0xde, 0x00, 0x02,
55 0x12, 0x00, 0x56, 0xce, 57 0x12, 0x00, 0x56, 0xce,
56 0x90, 0x80|kAudioLevel, 0x00, 0x00}; 58 0x90, 0x80|kAudioLevel, 0x00, 0x00};
57 59
58 constexpr uint8_t kPacketWithRsid[] = { 60 constexpr uint8_t kPacketWithRsid[] = {
59 0x90, kPayloadType, 0x00, kSeqNum, 61 0x90, kPayloadType, kSeqNumFirstHalf, kSeqNumSecondHalf,
60 0x65, 0x43, 0x12, 0x78, 62 0x65, 0x43, 0x12, 0x78,
61 0x12, 0x34, 0x56, 0x78, 63 0x12, 0x34, 0x56, 0x78,
62 0xbe, 0xde, 0x00, 0x03, 64 0xbe, 0xde, 0x00, 0x03,
63 0xa7, 's', 't', 'r', 65 0xa7, 's', 't', 'r',
64 'e', 'a', 'm', 'i', 66 'e', 'a', 'm', 'i',
65 'd' , 0x00, 0x00, 0x00}; 67 'd' , 0x00, 0x00, 0x00};
66 68
67 constexpr uint32_t kCsrcs[] = {0x34567890, 0x32435465}; 69 constexpr uint32_t kCsrcs[] = {0x34567890, 0x32435465};
68 constexpr uint8_t kPayload[] = {'p', 'a', 'y', 'l', 'o', 'a', 'd'}; 70 constexpr uint8_t kPayload[] = {'p', 'a', 'y', 'l', 'o', 'a', 'd'};
69 constexpr uint8_t kPacketPaddingSize = 8; 71 constexpr uint8_t kPacketPaddingSize = 8;
70 constexpr uint8_t kPacket[] = { 72 constexpr uint8_t kPacket[] = {
71 0xb2, kPayloadType, 0x00, kSeqNum, 73 0xb2, kPayloadType, kSeqNumFirstHalf, kSeqNumSecondHalf,
72 0x65, 0x43, 0x12, 0x78, 74 0x65, 0x43, 0x12, 0x78,
73 0x12, 0x34, 0x56, 0x78, 75 0x12, 0x34, 0x56, 0x78,
74 0x34, 0x56, 0x78, 0x90, 76 0x34, 0x56, 0x78, 0x90,
75 0x32, 0x43, 0x54, 0x65, 77 0x32, 0x43, 0x54, 0x65,
76 0xbe, 0xde, 0x00, 0x01, 78 0xbe, 0xde, 0x00, 0x01,
77 0x12, 0x00, 0x56, 0xce, 79 0x12, 0x00, 0x56, 0xce,
78 'p', 'a', 'y', 'l', 'o', 'a', 'd', 80 'p', 'a', 'y', 'l', 'o', 'a', 'd',
79 'p', 'a', 'd', 'd', 'i', 'n', 'g', kPacketPaddingSize}; 81 'p', 'a', 'd', 'd', 'i', 'n', 'g', kPacketPaddingSize};
80 82
81 constexpr uint8_t kPacketWithInvalidExtension[] = { 83 constexpr uint8_t kPacketWithInvalidExtension[] = {
82 0x90, kPayloadType, 0x00, kSeqNum, 84 0x90, kPayloadType, kSeqNumFirstHalf, kSeqNumSecondHalf,
83 0x65, 0x43, 0x12, 0x78, // kTimestamp. 85 0x65, 0x43, 0x12, 0x78, // kTimestamp.
84 0x12, 0x34, 0x56, 0x78, // kSSrc. 86 0x12, 0x34, 0x56, 0x78, // kSSrc.
85 0xbe, 0xde, 0x00, 0x02, // Extension block of size 2 x 32bit words. 87 0xbe, 0xde, 0x00, 0x02, // Extension block of size 2 x 32bit words.
86 (kTransmissionOffsetExtensionId << 4) | 6, // (6+1)-byte extension, but 88 (kTransmissionOffsetExtensionId << 4) | 6, // (6+1)-byte extension, but
87 'e', 'x', 't', // Transmission Offset 89 'e', 'x', 't', // Transmission Offset
88 'd', 'a', 't', 'a', // expected to be 3-bytes. 90 'd', 'a', 't', 'a', // expected to be 3-bytes.
89 'p', 'a', 'y', 'l', 'o', 'a', 'd' 91 'p', 'a', 'y', 'l', 'o', 'a', 'd'
90 }; 92 };
91 // clang-format on 93 // clang-format on
92 } // namespace 94 } // namespace
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 int32_t time_offset; 307 int32_t time_offset;
306 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset)); 308 EXPECT_FALSE(packet.GetExtension<TransmissionOffset>(&time_offset));
307 309
308 // But shouldn't prevent reading payload. 310 // But shouldn't prevent reading payload.
309 EXPECT_THAT(packet.payload(), ElementsAreArray(kPayload)); 311 EXPECT_THAT(packet.payload(), ElementsAreArray(kPayload));
310 } 312 }
311 313
312 TEST(RtpPacketTest, ParseWithOverSizedExtension) { 314 TEST(RtpPacketTest, ParseWithOverSizedExtension) {
313 // clang-format off 315 // clang-format off
314 const uint8_t bad_packet[] = { 316 const uint8_t bad_packet[] = {
315 0x90, kPayloadType, 0x00, kSeqNum, 317 0x90, kPayloadType, kSeqNumFirstHalf, kSeqNumSecondHalf,
316 0x65, 0x43, 0x12, 0x78, // kTimestamp. 318 0x65, 0x43, 0x12, 0x78, // kTimestamp.
317 0x12, 0x34, 0x56, 0x78, // kSsrc. 319 0x12, 0x34, 0x56, 0x78, // kSsrc.
318 0xbe, 0xde, 0x00, 0x01, // Extension of size 1x32bit word. 320 0xbe, 0xde, 0x00, 0x01, // Extension of size 1x32bit word.
319 0x00, // Add a byte of padding. 321 0x00, // Add a byte of padding.
320 0x12, // Extension id 1 size (2+1). 322 0x12, // Extension id 1 size (2+1).
321 0xda, 0x1a // Only 2 bytes of extension payload. 323 0xda, 0x1a // Only 2 bytes of extension payload.
322 }; 324 };
323 // clang-format on 325 // clang-format on
324 RtpPacketToSend::ExtensionManager extensions; 326 RtpPacketToSend::ExtensionManager extensions;
325 extensions.Register(TransmissionOffset::kId, 1); 327 extensions.Register(TransmissionOffset::kId, 1);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 auto raw_extension = packet.GetRawExtension(kTransmissionOffsetExtensionId); 402 auto raw_extension = packet.GetRawExtension(kTransmissionOffsetExtensionId);
401 EXPECT_EQ(raw_extension.size(), TransmissionOffset::kValueSizeBytes); 403 EXPECT_EQ(raw_extension.size(), TransmissionOffset::kValueSizeBytes);
402 EXPECT_TRUE(TransmissionOffset::Parse(raw_extension, &time_offset)); 404 EXPECT_TRUE(TransmissionOffset::Parse(raw_extension, &time_offset));
403 405
404 EXPECT_EQ(time_offset, kTimeOffset); 406 EXPECT_EQ(time_offset, kTimeOffset);
405 } 407 }
406 408
407 TEST(RtpPacketTest, ParseDynamicSizeExtension) { 409 TEST(RtpPacketTest, ParseDynamicSizeExtension) {
408 // clang-format off 410 // clang-format off
409 const uint8_t kPacket1[] = { 411 const uint8_t kPacket1[] = {
410 0x90, kPayloadType, 0x00, kSeqNum, 412 0x90, kPayloadType, kSeqNumFirstHalf, kSeqNumSecondHalf,
411 0x65, 0x43, 0x12, 0x78, // Timestamp. 413 0x65, 0x43, 0x12, 0x78, // Timestamp.
412 0x12, 0x34, 0x56, 0x78, // Ssrc. 414 0x12, 0x34, 0x56, 0x78, // Ssrc.
413 0xbe, 0xde, 0x00, 0x02, // Extensions block of size 2x32bit words. 415 0xbe, 0xde, 0x00, 0x02, // Extensions block of size 2x32bit words.
414 0x21, 'H', 'D', // Extension with id = 2, size = (1+1). 416 0x21, 'H', 'D', // Extension with id = 2, size = (1+1).
415 0x12, 'r', 't', 'x', // Extension with id = 1, size = (2+1). 417 0x12, 'r', 't', 'x', // Extension with id = 1, size = (2+1).
416 0x00}; // Extension padding. 418 0x00}; // Extension padding.
417 const uint8_t kPacket2[] = { 419 const uint8_t kPacket2[] = {
418 0x90, kPayloadType, 0x00, kSeqNum, 420 0x90, kPayloadType, kSeqNumFirstHalf, kSeqNumSecondHalf,
419 0x65, 0x43, 0x12, 0x78, // Timestamp. 421 0x65, 0x43, 0x12, 0x78, // Timestamp.
420 0x12, 0x34, 0x56, 0x79, // Ssrc. 422 0x12, 0x34, 0x56, 0x79, // Ssrc.
421 0xbe, 0xde, 0x00, 0x01, // Extensions block of size 1x32bit words. 423 0xbe, 0xde, 0x00, 0x01, // Extensions block of size 1x32bit words.
422 0x11, 'H', 'D', // Extension with id = 1, size = (1+1). 424 0x11, 'H', 'D', // Extension with id = 1, size = (1+1).
423 0x00}; // Extension padding. 425 0x00}; // Extension padding.
424 // clang-format on 426 // clang-format on
425 RtpPacketReceived::ExtensionManager extensions; 427 RtpPacketReceived::ExtensionManager extensions;
426 extensions.Register<RtpStreamId>(1); 428 extensions.Register<RtpStreamId>(1);
427 extensions.Register<RepairedRtpStreamId>(2); 429 extensions.Register<RepairedRtpStreamId>(2);
428 RtpPacketReceived packet(&extensions); 430 RtpPacketReceived packet(&extensions);
(...skipping 25 matching lines...) Expand all
454 ASSERT_TRUE(packet.Parse(kPacket, sizeof(kPacket))); 456 ASSERT_TRUE(packet.Parse(kPacket, sizeof(kPacket)));
455 457
456 EXPECT_FALSE(packet.HasRawExtension(kInvalidId)); 458 EXPECT_FALSE(packet.HasRawExtension(kInvalidId));
457 EXPECT_THAT(packet.GetRawExtension(kInvalidId), IsEmpty()); 459 EXPECT_THAT(packet.GetRawExtension(kInvalidId), IsEmpty());
458 const uint8_t kExtension[] = {'e', 'x', 't'}; 460 const uint8_t kExtension[] = {'e', 'x', 't'};
459 EXPECT_FALSE(packet.SetRawExtension(kInvalidId, kExtension)); 461 EXPECT_FALSE(packet.SetRawExtension(kInvalidId, kExtension));
460 EXPECT_THAT(packet.AllocateRawExtension(kInvalidId, 3), IsEmpty()); 462 EXPECT_THAT(packet.AllocateRawExtension(kInvalidId, 3), IsEmpty());
461 } 463 }
462 464
463 } // namespace webrtc 465 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698