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