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 | 10 |
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h" |
12 | 12 |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "webrtc/test/rtcp_packet_parser.h" |
15 | 16 |
16 using testing::AllOf; | 17 using testing::AllOf; |
17 using testing::ElementsAre; | 18 using testing::ElementsAre; |
18 using testing::ElementsAreArray; | 19 using testing::ElementsAreArray; |
19 using testing::Eq; | 20 using testing::Eq; |
20 using testing::Field; | 21 using testing::Field; |
21 using testing::make_tuple; | 22 using testing::make_tuple; |
22 using webrtc::rtcp::Fir; | 23 using webrtc::rtcp::Fir; |
23 using webrtc::RTCPUtility::RtcpCommonHeader; | |
24 using webrtc::RTCPUtility::RtcpParseCommonHeader; | |
25 | 24 |
26 namespace webrtc { | 25 namespace webrtc { |
27 namespace { | 26 namespace { |
28 | 27 |
29 const uint32_t kSenderSsrc = 0x12345678; | 28 constexpr uint32_t kSenderSsrc = 0x12345678; |
30 const uint32_t kRemoteSsrc = 0x23456789; | 29 constexpr uint32_t kRemoteSsrc = 0x23456789; |
31 const uint8_t kSeqNr = 13; | 30 constexpr uint8_t kSeqNr = 13; |
32 // Manually created Fir packet matching constants above. | 31 // Manually created Fir packet matching constants above. |
33 const uint8_t kPacket[] = {0x84, 206, 0x00, 0x04, | 32 constexpr uint8_t kPacket[] = {0x84, 206, 0x00, 0x04, |
34 0x12, 0x34, 0x56, 0x78, | 33 0x12, 0x34, 0x56, 0x78, |
35 0x00, 0x00, 0x00, 0x00, | 34 0x00, 0x00, 0x00, 0x00, |
36 0x23, 0x45, 0x67, 0x89, | 35 0x23, 0x45, 0x67, 0x89, |
37 0x0d, 0x00, 0x00, 0x00}; | 36 0x0d, 0x00, 0x00, 0x00}; |
38 | 37 } // namespace |
39 bool ParseFir(const uint8_t* buffer, size_t length, Fir* fir) { | |
40 RtcpCommonHeader header; | |
41 EXPECT_TRUE(RtcpParseCommonHeader(buffer, length, &header)); | |
42 EXPECT_THAT(header.BlockSize(), Eq(length)); | |
43 return fir->Parse(header, buffer + RtcpCommonHeader::kHeaderSizeBytes); | |
44 } | |
45 | 38 |
46 TEST(RtcpPacketFirTest, Parse) { | 39 TEST(RtcpPacketFirTest, Parse) { |
47 Fir mutable_parsed; | 40 Fir mutable_parsed; |
48 EXPECT_TRUE(ParseFir(kPacket, sizeof(kPacket), &mutable_parsed)); | 41 EXPECT_TRUE(test::ParseSinglePacket(kPacket, &mutable_parsed)); |
49 const Fir& parsed = mutable_parsed; // Read values from constant object. | 42 const Fir& parsed = mutable_parsed; // Read values from constant object. |
50 | 43 |
51 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc()); | 44 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc()); |
52 EXPECT_THAT(parsed.requests(), | 45 EXPECT_THAT(parsed.requests(), |
53 ElementsAre(AllOf(Field(&Fir::Request::ssrc, Eq(kRemoteSsrc)), | 46 ElementsAre(AllOf(Field(&Fir::Request::ssrc, Eq(kRemoteSsrc)), |
54 Field(&Fir::Request::seq_nr, Eq(kSeqNr))))); | 47 Field(&Fir::Request::seq_nr, Eq(kSeqNr))))); |
55 } | 48 } |
56 | 49 |
57 TEST(RtcpPacketFirTest, Create) { | 50 TEST(RtcpPacketFirTest, Create) { |
58 Fir fir; | 51 Fir fir; |
59 fir.From(kSenderSsrc); | 52 fir.From(kSenderSsrc); |
60 fir.WithRequestTo(kRemoteSsrc, kSeqNr); | 53 fir.WithRequestTo(kRemoteSsrc, kSeqNr); |
61 | 54 |
62 rtc::Buffer packet = fir.Build(); | 55 rtc::Buffer packet = fir.Build(); |
63 | 56 |
64 EXPECT_THAT(make_tuple(packet.data(), packet.size()), | 57 EXPECT_THAT(make_tuple(packet.data(), packet.size()), |
65 ElementsAreArray(kPacket)); | 58 ElementsAreArray(kPacket)); |
66 } | 59 } |
67 | 60 |
68 TEST(RtcpPacketFirTest, TwoFciEntries) { | 61 TEST(RtcpPacketFirTest, TwoFciEntries) { |
69 Fir fir; | 62 Fir fir; |
70 fir.From(kSenderSsrc); | 63 fir.From(kSenderSsrc); |
71 fir.WithRequestTo(kRemoteSsrc, kSeqNr); | 64 fir.WithRequestTo(kRemoteSsrc, kSeqNr); |
72 fir.WithRequestTo(kRemoteSsrc + 1, kSeqNr + 1); | 65 fir.WithRequestTo(kRemoteSsrc + 1, kSeqNr + 1); |
73 | 66 |
74 rtc::Buffer packet = fir.Build(); | 67 rtc::Buffer packet = fir.Build(); |
75 Fir parsed; | 68 Fir parsed; |
76 EXPECT_TRUE(ParseFir(packet.data(), packet.size(), &parsed)); | 69 EXPECT_TRUE(test::ParseSinglePacket(packet, &parsed)); |
77 | 70 |
78 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc()); | 71 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc()); |
79 EXPECT_THAT(parsed.requests(), | 72 EXPECT_THAT(parsed.requests(), |
80 ElementsAre(AllOf(Field(&Fir::Request::ssrc, Eq(kRemoteSsrc)), | 73 ElementsAre(AllOf(Field(&Fir::Request::ssrc, Eq(kRemoteSsrc)), |
81 Field(&Fir::Request::seq_nr, Eq(kSeqNr))), | 74 Field(&Fir::Request::seq_nr, Eq(kSeqNr))), |
82 AllOf(Field(&Fir::Request::ssrc, Eq(kRemoteSsrc + 1)), | 75 AllOf(Field(&Fir::Request::ssrc, Eq(kRemoteSsrc + 1)), |
83 Field(&Fir::Request::seq_nr, Eq(kSeqNr + 1))))); | 76 Field(&Fir::Request::seq_nr, Eq(kSeqNr + 1))))); |
84 } | 77 } |
85 | 78 |
86 TEST(RtcpPacketFirTest, ParseFailsOnZeroFciEntries) { | 79 TEST(RtcpPacketFirTest, ParseFailsOnZeroFciEntries) { |
87 Fir fir; | 80 constexpr uint8_t kPacketWithoutFci[] = {0x84, 206, 0x00, 0x02, |
88 fir.From(kSenderSsrc); | 81 0x12, 0x34, 0x56, 0x78, |
89 fir.WithRequestTo(kRemoteSsrc, kSeqNr); | 82 0x00, 0x00, 0x00, 0x00}; |
90 | |
91 rtc::Buffer packet = fir.Build(); | |
92 | |
93 RtcpCommonHeader header; | |
94 RtcpParseCommonHeader(packet.data(), packet.size(), &header); | |
95 ASSERT_EQ(16u, header.payload_size_bytes); // Common: 8, 1xfci: 8. | |
96 header.payload_size_bytes = 8; // Common: 8, 0xfcis. | |
97 | |
98 Fir parsed; | 83 Fir parsed; |
99 EXPECT_FALSE(parsed.Parse( | 84 EXPECT_FALSE(test::ParseSinglePacket(kPacketWithoutFci, &parsed)); |
100 header, packet.data() + RtcpCommonHeader::kHeaderSizeBytes)); | |
101 } | 85 } |
102 | 86 |
103 TEST(RtcpPacketFirTest, ParseFailsOnFractionalFciEntries) { | 87 TEST(RtcpPacketFirTest, ParseFailsOnFractionalFciEntries) { |
104 Fir fir; | 88 constexpr uint8_t kPacketWithOneAndHalfFci[] = {0x84, 206, 0x00, 0x05, |
105 fir.From(kSenderSsrc); | 89 0x12, 0x34, 0x56, 0x78, |
106 fir.WithRequestTo(kRemoteSsrc, kSeqNr); | 90 0x00, 0x00, 0x00, 0x00, |
107 fir.WithRequestTo(kRemoteSsrc + 1, kSeqNr + 1); | 91 0x23, 0x45, 0x67, 0x89, |
| 92 0x0d, 0x00, 0x00, 0x00, |
| 93 'h', 'a', 'l', 'f'}; |
108 | 94 |
109 rtc::Buffer packet = fir.Build(); | 95 Fir parsed; |
| 96 EXPECT_FALSE(test::ParseSinglePacket(kPacketWithOneAndHalfFci, &parsed)); |
| 97 } |
110 | 98 |
111 RtcpCommonHeader header; | |
112 RtcpParseCommonHeader(packet.data(), packet.size(), &header); | |
113 ASSERT_EQ(24u, header.payload_size_bytes); // Common: 8, 2xfcis: 16. | |
114 | |
115 const uint8_t* payload = packet.data() + RtcpCommonHeader::kHeaderSizeBytes; | |
116 Fir good; | |
117 EXPECT_TRUE(good.Parse(header, payload)); | |
118 for (size_t i = 1; i < 8; ++i) { | |
119 header.payload_size_bytes = 16 + i; | |
120 Fir bad; | |
121 EXPECT_FALSE(bad.Parse(header, payload)); | |
122 } | |
123 } | |
124 } // namespace | |
125 } // namespace webrtc | 99 } // namespace webrtc |
OLD | NEW |