OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | |
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | |
15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" | |
13 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
14 | 17 |
15 namespace webrtc { | 18 namespace webrtc { |
19 namespace rtcp { | |
16 | 20 |
17 TEST(RtcpUtilityTest, MidNtp) { | 21 TEST(RtcpUtilityTest, MidNtp) { |
18 const uint32_t kNtpSec = 0x12345678; | 22 const uint32_t kNtpSec = 0x12345678; |
19 const uint32_t kNtpFrac = 0x23456789; | 23 const uint32_t kNtpFrac = 0x23456789; |
20 const uint32_t kNtpMid = 0x56782345; | 24 const uint32_t kNtpMid = 0x56782345; |
21 EXPECT_EQ(kNtpMid, RTCPUtility::MidNtp(kNtpSec, kNtpFrac)); | 25 EXPECT_EQ(kNtpMid, RTCPUtility::MidNtp(kNtpSec, kNtpFrac)); |
22 } | 26 } |
23 | 27 |
24 TEST(RtcpUtilityTest, NackRequests) { | 28 TEST(RtcpUtilityTest, NackRequests) { |
25 RTCPUtility::NackStats stats; | 29 RTCPUtility::NackStats stats; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 | 65 |
62 stats.ReportRequest(65535); | 66 stats.ReportRequest(65535); |
63 EXPECT_EQ(3U, stats.unique_requests()); | 67 EXPECT_EQ(3U, stats.unique_requests()); |
64 stats.ReportRequest(0); | 68 stats.ReportRequest(0); |
65 EXPECT_EQ(3U, stats.unique_requests()); | 69 EXPECT_EQ(3U, stats.unique_requests()); |
66 stats.ReportRequest(1); | 70 stats.ReportRequest(1); |
67 EXPECT_EQ(4U, stats.unique_requests()); | 71 EXPECT_EQ(4U, stats.unique_requests()); |
68 EXPECT_EQ(8U, stats.requests()); | 72 EXPECT_EQ(8U, stats.requests()); |
69 } | 73 } |
70 | 74 |
75 // Override RtcpPacket so we can test protected methods. | |
åsapersson
2015/09/10 13:27:33
override RtcpPacket?
sprang_webrtc
2015/09/11 13:03:19
Done.
| |
76 class RtcpPacketHeaderTest : public ::testing::Test, protected RtcpPacket { | |
åsapersson
2015/09/10 13:27:33
maybe call the test RtcpParseCommonHeaderTest
sprang_webrtc
2015/09/11 13:03:19
Done.
| |
77 public: | |
78 RtcpPacketHeaderTest() { memset(buffer, 0, kBufferCapacityBytes); } | |
79 | |
80 virtual ~RtcpPacketHeaderTest() {} | |
81 | |
82 bool Create(uint8_t* packet, | |
83 size_t* index, | |
84 size_t max_length, | |
85 PacketReadyCallback* callback) const override { | |
86 RTC_NOTREACHED(); | |
87 return false; | |
88 } | |
89 | |
90 size_t BlockLength() const { return 0; } | |
91 | |
92 protected: | |
93 static const size_t kHeaderSizeBytes = 4; | |
åsapersson
2015/09/10 13:27:33
use the define in RtcpCommonHeader
sprang_webrtc
2015/09/11 13:03:19
Done.
| |
94 static const size_t kBufferCapacityBytes = 40; | |
95 uint8_t buffer[kBufferCapacityBytes]; | |
96 RTCPUtility::RtcpCommonHeader header; | |
97 }; | |
98 | |
99 TEST_F(RtcpPacketHeaderTest, TooSmallBuffer) { | |
100 // Buffer needs to be able to hold the header. | |
101 for (size_t i = 0; i < kHeaderSizeBytes; ++i) | |
102 EXPECT_FALSE(RtcpParseCommonHeader(buffer, i, &header)); | |
103 } | |
104 | |
105 TEST_F(RtcpPacketHeaderTest, Version) { | |
106 // Version 2 is the only allowed for now. | |
107 for (int v = 0; v < 4; ++v) { | |
108 buffer[0] = v << 6; | |
109 EXPECT_EQ(v == 2, RtcpParseCommonHeader(buffer, kHeaderSizeBytes, &header)); | |
110 } | |
111 } | |
112 | |
113 TEST_F(RtcpPacketHeaderTest, PacketSize) { | |
114 // Set v = 2, leave p, fmt, pt as 0. | |
115 buffer[0] = 2 << 6; | |
116 | |
117 const size_t kBlockSize = 3; | |
118 ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], kBlockSize); | |
119 const size_t kSizeInBytes = (kBlockSize + 1) * 4; | |
120 | |
121 EXPECT_FALSE(RtcpParseCommonHeader(buffer, kSizeInBytes - 1, &header)); | |
122 EXPECT_TRUE(RtcpParseCommonHeader(buffer, kSizeInBytes, &header)); | |
123 } | |
124 | |
125 TEST_F(RtcpPacketHeaderTest, PayloadSize) { | |
126 // Set v = 2, p = 1, but leave fmt, pt as 0. | |
127 buffer[0] = (2 << 6) | (1 << 5); | |
128 | |
129 const size_t kBlockSize = 3; | |
130 ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], kBlockSize); | |
131 const size_t kSizeInBytes = (kBlockSize + 1) * 4; | |
132 const size_t kPayloadSizeBytes = kSizeInBytes - kHeaderSizeBytes; | |
133 | |
134 // Padding one byte larger than possible. | |
135 buffer[kSizeInBytes - 1] = kPayloadSizeBytes + 1; | |
136 EXPECT_FALSE(RtcpParseCommonHeader(buffer, kSizeInBytes, &header)); | |
137 | |
138 // Pure padding packet? | |
139 buffer[kSizeInBytes - 1] = kPayloadSizeBytes; | |
140 EXPECT_TRUE(RtcpParseCommonHeader(buffer, kSizeInBytes, &header)); | |
141 EXPECT_EQ(kPayloadSizeBytes, header.padding_bytes); | |
142 EXPECT_EQ(0u, header.payload_size_bytes); | |
143 | |
144 // Single byte of actual data. | |
145 buffer[kSizeInBytes - 1] = kPayloadSizeBytes - 1; | |
146 EXPECT_TRUE(RtcpParseCommonHeader(buffer, kSizeInBytes, &header)); | |
147 EXPECT_EQ(kPayloadSizeBytes - 1, header.padding_bytes); | |
148 EXPECT_EQ(1u, header.payload_size_bytes); | |
149 } | |
150 | |
151 TEST_F(RtcpPacketHeaderTest, FormatAndPayloadType) { | |
152 // Format/count and packet type both set to max values. | |
153 const uint8_t kCountOrFormat = 0x1F; | |
154 const uint8_t kPacketType = 0xFF; | |
155 buffer[0] = 2 << 6; // V = 2. | |
156 buffer[0] |= kCountOrFormat; | |
157 buffer[1] = kPacketType; | |
158 | |
159 EXPECT_TRUE(RtcpParseCommonHeader(buffer, kHeaderSizeBytes, &header)); | |
160 EXPECT_EQ(kCountOrFormat, header.count_or_format); | |
161 EXPECT_EQ(kPacketType, header.packet_type); | |
162 } | |
163 | |
164 } // namespace rtcp | |
71 } // namespace webrtc | 165 } // namespace webrtc |
72 | 166 |
OLD | NEW |