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

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

Issue 1540383002: [rtp_rtcp] ReportBlockInformation cleaned and moved out of the rtcp_receiver_help. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <algorithm>
12
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/base/logging.h"
15 #include "webrtc/base/random.h"
16 #include "webrtc/modules/rtp_rtcp/source/report_block_information.h"
17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.h"
18 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
19 #include "webrtc/modules/rtp_rtcp/source/time_util.h"
20
21 using webrtc::rtcp::ReportBlock;
22 using webrtc::rtcp::ReportBlockInformation;
23 using webrtc::RTCPUtility::RTCPPacketReportBlockItem;
24
25 namespace webrtc {
26
27 class RtcpReportBlockInformationTest : public ::testing::Test {
28 protected:
29 Random rand_;
30 const uint32_t kSourceSsrc;
31 const uint32_t kRemoteSsrc;
32 const uint32_t kDelayNtp;
33 const uint8_t kFractionLost;
34 const uint32_t kCumulativeLost;
35 const uint32_t kSequenceNumber;
36 const uint32_t kJitter;
37 const uint32_t kLastSr;
38 RtcpReportBlockInformationTest()
39 : rand_(0x123456789abcdef),
40 kSourceSsrc(RandSsrc()),
41 kRemoteSsrc(RandSsrc()),
42 kDelayNtp(Rand<uint32_t>()),
43 kFractionLost(Rand<uint8_t>()),
44 kCumulativeLost(Rand((1 << 24) - 1)),
45 kSequenceNumber(Rand<uint32_t>()),
46 kJitter(Rand<uint32_t>()),
47 kLastSr(Rand<uint32_t>()) {}
48
49 uint32_t RandSsrc() { return rand_.Rand(0x00000001u, 0xfffffffeu); }
50 template <typename T>
51 T Rand() {
52 return rand_.Rand<T>();
53 }
54 uint32_t Rand(uint32_t max) { return rand_.Rand(max); }
55 uint32_t Rand(uint32_t min, uint32_t max) { return rand_.Rand(min, max); }
56 };
57
58 template <>
59 NtpTime RtcpReportBlockInformationTest::Rand<NtpTime>() {
60 return NtpTime(Rand<uint32_t>(), Rand<uint32_t>());
61 }
62
63 TEST_F(RtcpReportBlockInformationTest, RemembersLastReportBlock) {
64 ReportBlockInformation rbi;
65 const NtpTime kNow = Rand<NtpTime>();
66 ReportBlock b;
67 b.To(kSourceSsrc);
68 b.WithFractionLost(kFractionLost);
69 b.WithCumulativeLost(kCumulativeLost);
70 b.WithExtHighestSeqNum(kSequenceNumber);
71 b.WithJitter(kJitter);
72 b.WithLastSr(kLastSr);
73 b.WithDelayLastSr(kDelayNtp);
74
75 rbi.AddBlock(b, kRemoteSsrc, kNow);
76
77 EXPECT_EQ(rbi.LastBlock().sourceSSRC, kSourceSsrc);
philipel 2016/02/29 13:21:48 Switch to expected value first: EXPECT_EQ(kSourceS
danilchap 2016/02/29 14:41:27 Done.
78 EXPECT_EQ(rbi.LastBlock().remoteSSRC, kRemoteSsrc);
79 EXPECT_EQ(rbi.LastBlock().fractionLost, kFractionLost);
80 EXPECT_EQ(rbi.LastBlock().cumulativeLost, kCumulativeLost);
81 EXPECT_EQ(rbi.LastBlock().extendedHighSeqNum, kSequenceNumber);
82 EXPECT_EQ(rbi.LastBlock().jitter, kJitter);
83 EXPECT_EQ(rbi.LastBlock().lastSR, kLastSr);
84 EXPECT_EQ(rbi.LastBlock().delaySinceLastSR, kDelayNtp);
85 }
86
87 TEST_F(RtcpReportBlockInformationTest, AcceptsRTCPUtilityReportBlockItem) {
88 ReportBlockInformation rbi;
89 const NtpTime kNow = Rand<NtpTime>();
90 RTCPPacketReportBlockItem b;
91 b.SSRC = kSourceSsrc;
92 b.FractionLost = kFractionLost;
93 b.CumulativeNumOfPacketsLost = kCumulativeLost;
94 b.ExtendedHighestSequenceNumber = kSequenceNumber;
95 b.Jitter = kJitter;
96 b.LastSR = kLastSr;
97 b.DelayLastSR = kDelayNtp;
98
99 rbi.AddBlock(b, kRemoteSsrc, kNow);
100
101 EXPECT_EQ(rbi.LastBlock().sourceSSRC, kSourceSsrc);
philipel 2016/02/29 13:21:48 switch
danilchap 2016/02/29 14:41:27 Done.
102 EXPECT_EQ(rbi.LastBlock().remoteSSRC, kRemoteSsrc);
103 EXPECT_EQ(rbi.LastBlock().fractionLost, kFractionLost);
104 EXPECT_EQ(rbi.LastBlock().cumulativeLost, kCumulativeLost);
105 EXPECT_EQ(rbi.LastBlock().extendedHighSeqNum, kSequenceNumber);
106 EXPECT_EQ(rbi.LastBlock().jitter, kJitter);
107 EXPECT_EQ(rbi.LastBlock().lastSR, kLastSr);
108 EXPECT_EQ(rbi.LastBlock().delaySinceLastSR, kDelayNtp);
109 }
110
111 TEST_F(RtcpReportBlockInformationTest, ReportBlockWithoutRTT) {
112 ReportBlockInformation rbi;
113 const NtpTime kNow = Rand<NtpTime>();
114 ReportBlock b;
115 b.To(kSourceSsrc);
116 b.WithLastSr(0); // LastSR = 0 means RTT can't be calculated.
117
118 rbi.AddBlock(b, kRemoteSsrc, kNow);
119
120 EXPECT_FALSE(rbi.HasRtt());
121 EXPECT_EQ(rbi.LastBlock().sourceSSRC, kSourceSsrc);
philipel 2016/02/29 13:21:48 switch
danilchap 2016/02/29 14:41:28 Done.
122 EXPECT_EQ(rbi.LastBlock().remoteSSRC, kRemoteSsrc);
123 }
124
125 TEST_F(RtcpReportBlockInformationTest, ReportBlockWithRTT) {
126 const uint32_t kRttMs = Rand(1, 18 * 3600 * 1000);
127 ReportBlockInformation rbi;
128 SimulatedClock clock(Rand<uint32_t>());
129 ReportBlock b;
130 b.To(kSourceSsrc);
131 NtpTime start(clock);
132 b.WithLastSr(CompactNtp(start));
133 b.WithDelayLastSr(kDelayNtp);
134 clock.AdvanceTimeMilliseconds(kRttMs + CompactNtpIntervalToMs(kDelayNtp));
135 NtpTime now(clock);
136
137 rbi.AddBlock(b, kRemoteSsrc, now);
138
139 EXPECT_TRUE(rbi.HasRtt());
140 EXPECT_NEAR(kRttMs, rbi.LastRttMs(), 1);
141 }
142
143 TEST_F(RtcpReportBlockInformationTest, RTTStats) {
144 const uint32_t kRttMs1 = Rand(1, 18 * 3600 * 1000);
145 const uint32_t kRttMs2 = Rand(1, 18 * 3600 * 1000);
146 const uint32_t kRttMs3 = Rand(1, 18 * 3600 * 1000);
147 const uint32_t kRttMin = std::min({kRttMs1, kRttMs2, kRttMs3});
148 const uint32_t kRttMax = std::max({kRttMs1, kRttMs2, kRttMs3});
149 const uint32_t kRttAvg = (kRttMs1 + kRttMs2 + kRttMs3) / 3;
150 const uint32_t kDelayMs = CompactNtpIntervalToMs(kDelayNtp);
151 ReportBlockInformation rbi;
152 SimulatedClock clock(Rand<uint32_t>());
philipel 2016/02/29 13:21:48 Why do you use Random values? If you seed the rand
danilchap 2016/02/29 14:41:27 Random values demonstrate the range of values this
153 ReportBlock b;
154 b.To(kSourceSsrc);
155 const NtpTime start(clock);
156 b.WithDelayLastSr(kDelayNtp);
157
158 b.WithLastSr(CompactNtp(start));
159 clock.AdvanceTimeMilliseconds(kRttMs1 + kDelayMs);
160 const NtpTime time1(clock);
161 rbi.AddBlock(b, kRemoteSsrc, time1);
162
163 b.WithLastSr(CompactNtp(time1));
164 clock.AdvanceTimeMilliseconds(kRttMs2 + kDelayMs);
165 const NtpTime time2(clock);
166 rbi.AddBlock(b, kRemoteSsrc, time2);
167
168 b.WithLastSr(CompactNtp(time2));
169 clock.AdvanceTimeMilliseconds(kRttMs3 + kDelayMs);
170 const NtpTime time3(clock);
171 rbi.AddBlock(b, kRemoteSsrc, time3);
172
173 EXPECT_TRUE(rbi.HasRtt());
174 EXPECT_NEAR(kRttMs3, rbi.LastRttMs(), 1);
175 EXPECT_NEAR(kRttMin, rbi.MinRttMs(), 1);
176 EXPECT_NEAR(kRttMax, rbi.MaxRttMs(), 1);
177 EXPECT_NEAR(kRttAvg, rbi.AvgRttMs(), 1);
178 }
179
180 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698