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

Side by Side Diff: webrtc/system_wrappers/source/rtp_to_ntp_estimator_unittest.cc

Issue 2574133003: Make class of static functions in rtp_to_ntp.h: (Closed)
Patch Set: address comments Created 4 years 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
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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/system_wrappers/include/rtp_to_ntp.h" 11 #include "webrtc/system_wrappers/include/rtp_to_ntp_estimator.h"
12 #include "webrtc/test/gtest.h" 12 #include "webrtc/test/gtest.h"
13 13
14 namespace webrtc { 14 namespace webrtc {
15 namespace { 15 namespace {
16 const uint32_t kOneMsInNtpFrac = 4294967; 16 const uint32_t kOneMsInNtpFrac = 4294967;
17 const uint32_t kTimestampTicksPerMs = 90; 17 const uint32_t kTimestampTicksPerMs = 90;
18 } // namespace 18 } // namespace
19 19
20 TEST(WrapAroundTests, NoWrap) { 20 TEST(WrapAroundTests, NoWrap) {
21 EXPECT_EQ(0, CheckForWrapArounds(0xFFFFFFFF, 0xFFFFFFFE)); 21 EXPECT_EQ(0, CheckForWrapArounds(0xFFFFFFFF, 0xFFFFFFFE));
22 EXPECT_EQ(0, CheckForWrapArounds(1, 0)); 22 EXPECT_EQ(0, CheckForWrapArounds(1, 0));
23 EXPECT_EQ(0, CheckForWrapArounds(0x00010000, 0x0000FFFF)); 23 EXPECT_EQ(0, CheckForWrapArounds(0x00010000, 0x0000FFFF));
24 } 24 }
25 25
26 TEST(WrapAroundTests, ForwardWrap) { 26 TEST(WrapAroundTests, ForwardWrap) {
27 EXPECT_EQ(1, CheckForWrapArounds(0, 0xFFFFFFFF)); 27 EXPECT_EQ(1, CheckForWrapArounds(0, 0xFFFFFFFF));
28 EXPECT_EQ(1, CheckForWrapArounds(0, 0xFFFF0000)); 28 EXPECT_EQ(1, CheckForWrapArounds(0, 0xFFFF0000));
29 EXPECT_EQ(1, CheckForWrapArounds(0x0000FFFF, 0xFFFFFFFF)); 29 EXPECT_EQ(1, CheckForWrapArounds(0x0000FFFF, 0xFFFFFFFF));
30 EXPECT_EQ(1, CheckForWrapArounds(0x0000FFFF, 0xFFFF0000)); 30 EXPECT_EQ(1, CheckForWrapArounds(0x0000FFFF, 0xFFFF0000));
31 } 31 }
32 32
33 TEST(WrapAroundTests, BackwardWrap) { 33 TEST(WrapAroundTests, BackwardWrap) {
34 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFFFFFF, 0)); 34 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFFFFFF, 0));
35 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFF0000, 0)); 35 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFF0000, 0));
36 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFFFFFF, 0x0000FFFF)); 36 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFFFFFF, 0x0000FFFF));
37 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFF0000, 0x0000FFFF)); 37 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFF0000, 0x0000FFFF));
38 } 38 }
39 39
40 TEST(WrapAroundTests, OldRtcpWrapped_OldRtpTimestamp) { 40 TEST(WrapAroundTests, OldRtcpWrapped_OldRtpTimestamp) {
41 RtcpMeasurements rtcp; 41 RtpToNtpEstimator estimator;
42 bool new_sr; 42 bool new_sr;
43 uint32_t ntp_sec = 0; 43 uint32_t ntp_sec = 0;
44 uint32_t ntp_frac = 1; 44 uint32_t ntp_frac = 1;
45 uint32_t timestamp = 0; 45 uint32_t timestamp = 0;
46 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 46 EXPECT_TRUE(
47 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
47 ntp_frac += kOneMsInNtpFrac; 48 ntp_frac += kOneMsInNtpFrac;
48 timestamp -= kTimestampTicksPerMs; 49 timestamp -= kTimestampTicksPerMs;
49 // Expected to fail since the older RTCP has a smaller RTP timestamp than the 50 // Expected to fail since the older RTCP has a smaller RTP timestamp than the
50 // newer (old:0, new:4294967206). 51 // newer (old:0, new:4294967206).
51 EXPECT_FALSE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 52 EXPECT_FALSE(
53 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
52 } 54 }
53 55
54 TEST(WrapAroundTests, NewRtcpWrapped) { 56 TEST(WrapAroundTests, NewRtcpWrapped) {
55 RtcpMeasurements rtcp; 57 RtpToNtpEstimator estimator;
56 bool new_sr; 58 bool new_sr;
57 uint32_t ntp_sec = 0; 59 uint32_t ntp_sec = 0;
58 uint32_t ntp_frac = 1; 60 uint32_t ntp_frac = 1;
59 uint32_t timestamp = 0xFFFFFFFF; 61 uint32_t timestamp = 0xFFFFFFFF;
60 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 62 EXPECT_TRUE(
61 ntp_frac += kOneMsInNtpFrac; 63 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
62 timestamp += kTimestampTicksPerMs; 64 ntp_frac += kOneMsInNtpFrac;
63 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 65 timestamp += kTimestampTicksPerMs;
64 int64_t timestamp_ms = -1; 66 EXPECT_TRUE(
65 EXPECT_TRUE(RtpToNtpMs(rtcp.list.back().rtp_timestamp, rtcp, &timestamp_ms)); 67 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
68 int64_t timestamp_ms = -1;
69 EXPECT_TRUE(estimator.Estimate(0xFFFFFFFF, &timestamp_ms));
66 // Since this RTP packet has the same timestamp as the RTCP packet constructed 70 // Since this RTP packet has the same timestamp as the RTCP packet constructed
67 // at time 0 it should be mapped to 0 as well. 71 // at time 0 it should be mapped to 0 as well.
68 EXPECT_EQ(0, timestamp_ms); 72 EXPECT_EQ(0, timestamp_ms);
69 } 73 }
70 74
71 TEST(WrapAroundTests, RtpWrapped) { 75 TEST(WrapAroundTests, RtpWrapped) {
72 RtcpMeasurements rtcp; 76 RtpToNtpEstimator estimator;
73 bool new_sr; 77 bool new_sr;
74 uint32_t ntp_sec = 0; 78 uint32_t ntp_sec = 0;
75 uint32_t ntp_frac = 1; 79 uint32_t ntp_frac = 1;
76 uint32_t timestamp = 0xFFFFFFFF - 2 * kTimestampTicksPerMs; 80 uint32_t timestamp = 0xFFFFFFFF - 2 * kTimestampTicksPerMs;
77 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 81 EXPECT_TRUE(
78 ntp_frac += kOneMsInNtpFrac; 82 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
79 timestamp += kTimestampTicksPerMs; 83 ntp_frac += kOneMsInNtpFrac;
80 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 84 timestamp += kTimestampTicksPerMs;
81 85 EXPECT_TRUE(
82 int64_t timestamp_ms = -1; 86 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
83 EXPECT_TRUE(RtpToNtpMs(rtcp.list.back().rtp_timestamp, rtcp, &timestamp_ms)); 87
88 int64_t timestamp_ms = -1;
89 EXPECT_TRUE(estimator.Estimate(0xFFFFFFFF - 2 * kTimestampTicksPerMs,
90 &timestamp_ms));
84 // Since this RTP packet has the same timestamp as the RTCP packet constructed 91 // Since this RTP packet has the same timestamp as the RTCP packet constructed
85 // at time 0 it should be mapped to 0 as well. 92 // at time 0 it should be mapped to 0 as well.
86 EXPECT_EQ(0, timestamp_ms); 93 EXPECT_EQ(0, timestamp_ms);
87 // Two kTimestampTicksPerMs advanced. 94 // Two kTimestampTicksPerMs advanced.
88 timestamp += kTimestampTicksPerMs; 95 timestamp += kTimestampTicksPerMs;
89 EXPECT_TRUE(RtpToNtpMs(timestamp, rtcp, &timestamp_ms)); 96 EXPECT_TRUE(estimator.Estimate(timestamp, &timestamp_ms));
90 EXPECT_EQ(2, timestamp_ms); 97 EXPECT_EQ(2, timestamp_ms);
91 // Wrapped rtp. 98 // Wrapped rtp.
92 timestamp += kTimestampTicksPerMs; 99 timestamp += kTimestampTicksPerMs;
93 EXPECT_TRUE(RtpToNtpMs(timestamp, rtcp, &timestamp_ms)); 100 EXPECT_TRUE(estimator.Estimate(timestamp, &timestamp_ms));
94 EXPECT_EQ(3, timestamp_ms); 101 EXPECT_EQ(3, timestamp_ms);
95 } 102 }
96 103
97 TEST(WrapAroundTests, OldRtp_RtcpsWrapped) { 104 TEST(WrapAroundTests, OldRtp_RtcpsWrapped) {
98 RtcpMeasurements rtcp; 105 RtpToNtpEstimator estimator;
99 bool new_sr; 106 bool new_sr;
100 uint32_t ntp_sec = 0; 107 uint32_t ntp_sec = 0;
101 uint32_t ntp_frac = 1; 108 uint32_t ntp_frac = 1;
102 uint32_t timestamp = 0; 109 uint32_t timestamp = 0;
103 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 110 EXPECT_TRUE(
104 ntp_frac += kOneMsInNtpFrac; 111 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
105 timestamp += kTimestampTicksPerMs; 112 ntp_frac += kOneMsInNtpFrac;
106 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 113 timestamp += kTimestampTicksPerMs;
107 timestamp -= 2*kTimestampTicksPerMs; 114 EXPECT_TRUE(
108 int64_t timestamp_ms = -1; 115 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
109 EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, &timestamp_ms)); 116 timestamp -= 2 * kTimestampTicksPerMs;
117 int64_t timestamp_ms = -1;
118 EXPECT_FALSE(estimator.Estimate(timestamp, &timestamp_ms));
110 } 119 }
111 120
112 TEST(WrapAroundTests, OldRtp_NewRtcpWrapped) { 121 TEST(WrapAroundTests, OldRtp_NewRtcpWrapped) {
113 RtcpMeasurements rtcp; 122 RtpToNtpEstimator estimator;
114 bool new_sr; 123 bool new_sr;
115 uint32_t ntp_sec = 0; 124 uint32_t ntp_sec = 0;
116 uint32_t ntp_frac = 1; 125 uint32_t ntp_frac = 1;
117 uint32_t timestamp = 0xFFFFFFFF; 126 uint32_t timestamp = 0xFFFFFFFF;
118 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 127 EXPECT_TRUE(
119 ntp_frac += kOneMsInNtpFrac; 128 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
120 timestamp += kTimestampTicksPerMs; 129 ntp_frac += kOneMsInNtpFrac;
121 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 130 timestamp += kTimestampTicksPerMs;
131 EXPECT_TRUE(
132 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
122 timestamp -= kTimestampTicksPerMs; 133 timestamp -= kTimestampTicksPerMs;
123 int64_t timestamp_ms = -1; 134 int64_t timestamp_ms = -1;
124 EXPECT_TRUE(RtpToNtpMs(timestamp, rtcp, &timestamp_ms)); 135 EXPECT_TRUE(estimator.Estimate(timestamp, &timestamp_ms));
125 // Constructed at the same time as the first RTCP and should therefore be 136 // Constructed at the same time as the first RTCP and should therefore be
126 // mapped to zero. 137 // mapped to zero.
127 EXPECT_EQ(0, timestamp_ms); 138 EXPECT_EQ(0, timestamp_ms);
128 } 139 }
129 140
130 TEST(UpdateRtcpListTests, InjectRtcpSr) { 141 TEST(UpdateRtcpMeasurementTests, FailsForZeroNtp) {
131 const uint32_t kNtpSec = 10; 142 RtpToNtpEstimator estimator;
132 const uint32_t kNtpFrac = 12345;
133 const uint32_t kTs = 0x12345678;
134 bool new_sr;
135 RtcpMeasurements rtcp;
136 EXPECT_TRUE(UpdateRtcpList(kNtpSec, kNtpFrac, kTs, &rtcp, &new_sr));
137 EXPECT_TRUE(new_sr);
138 EXPECT_EQ(1u, rtcp.list.size());
139 EXPECT_EQ(kNtpSec, rtcp.list.front().ntp_time.seconds());
140 EXPECT_EQ(kNtpFrac, rtcp.list.front().ntp_time.fractions());
141 EXPECT_EQ(kTs, rtcp.list.front().rtp_timestamp);
142 // Add second report.
143 EXPECT_TRUE(UpdateRtcpList(kNtpSec, kNtpFrac + kOneMsInNtpFrac, kTs + 1,
144 &rtcp, &new_sr));
145 EXPECT_EQ(2u, rtcp.list.size());
146 EXPECT_EQ(kTs + 1, rtcp.list.front().rtp_timestamp);
147 EXPECT_EQ(kTs + 0, rtcp.list.back().rtp_timestamp);
148 // List should contain last two reports.
149 EXPECT_TRUE(UpdateRtcpList(kNtpSec, kNtpFrac + 2 * kOneMsInNtpFrac, kTs + 2,
150 &rtcp, &new_sr));
151 EXPECT_EQ(2u, rtcp.list.size());
152 EXPECT_EQ(kTs + 2, rtcp.list.front().rtp_timestamp);
153 EXPECT_EQ(kTs + 1, rtcp.list.back().rtp_timestamp);
154 }
155
156 TEST(UpdateRtcpListTests, FailsForZeroNtp) {
157 RtcpMeasurements rtcp;
158 uint32_t ntp_sec = 0; 143 uint32_t ntp_sec = 0;
159 uint32_t ntp_frac = 0; 144 uint32_t ntp_frac = 0;
160 uint32_t timestamp = 0x12345678; 145 uint32_t timestamp = 0x12345678;
161 bool new_sr; 146 bool new_sr;
162 EXPECT_FALSE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 147 EXPECT_FALSE(
163 EXPECT_FALSE(new_sr); 148 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
164 EXPECT_EQ(0u, rtcp.list.size()); 149 EXPECT_FALSE(new_sr);
165 } 150 }
166 151
167 TEST(UpdateRtcpListTests, FailsForEqualNtp) { 152 TEST(UpdateRtcpMeasurementTests, FailsForEqualNtp) {
168 RtcpMeasurements rtcp; 153 RtpToNtpEstimator estimator;
169 uint32_t ntp_sec = 0; 154 uint32_t ntp_sec = 0;
170 uint32_t ntp_frac = 699925050; 155 uint32_t ntp_frac = 699925050;
171 uint32_t timestamp = 0x12345678; 156 uint32_t timestamp = 0x12345678;
172 bool new_sr; 157 bool new_sr;
173 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 158 EXPECT_TRUE(
174 EXPECT_TRUE(new_sr); 159 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
175 EXPECT_EQ(1u, rtcp.list.size()); 160 EXPECT_TRUE(new_sr);
176 // Ntp time already added, list not updated. 161 // Ntp time already added, list not updated.
177 ++timestamp; 162 ++timestamp;
178 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 163 EXPECT_TRUE(
179 EXPECT_FALSE(new_sr); 164 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
180 EXPECT_EQ(1u, rtcp.list.size()); 165 EXPECT_FALSE(new_sr);
181 } 166 }
182 167
183 TEST(UpdateRtcpListTests, FailsForOldNtp) { 168 TEST(UpdateRtcpMeasurementTests, FailsForOldNtp) {
184 RtcpMeasurements rtcp; 169 RtpToNtpEstimator estimator;
185 uint32_t ntp_sec = 1; 170 uint32_t ntp_sec = 1;
186 uint32_t ntp_frac = 699925050; 171 uint32_t ntp_frac = 699925050;
187 uint32_t timestamp = 0x12345678; 172 uint32_t timestamp = 0x12345678;
188 bool new_sr; 173 bool new_sr;
189 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 174 EXPECT_TRUE(
190 EXPECT_TRUE(new_sr); 175 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
191 EXPECT_EQ(1u, rtcp.list.size()); 176 EXPECT_TRUE(new_sr);
192 // Old ntp time, list not updated. 177 // Old ntp time, list not updated.
193 ntp_frac -= kOneMsInNtpFrac; 178 ntp_frac -= kOneMsInNtpFrac;
194 timestamp += kTimestampTicksPerMs; 179 timestamp += kTimestampTicksPerMs;
195 EXPECT_FALSE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 180 EXPECT_FALSE(
196 EXPECT_EQ(1u, rtcp.list.size()); 181 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
197 } 182 }
198 183
199 TEST(UpdateRtcpListTests, FailsForEqualTimestamp) { 184 TEST(UpdateRtcpMeasurementTests, FailsForEqualTimestamp) {
200 RtcpMeasurements rtcp; 185 RtpToNtpEstimator estimator;
201 uint32_t ntp_sec = 0; 186 uint32_t ntp_sec = 0;
202 uint32_t ntp_frac = 2; 187 uint32_t ntp_frac = 2;
203 uint32_t timestamp = 0x12345678; 188 uint32_t timestamp = 0x12345678;
204 bool new_sr; 189 bool new_sr;
205 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 190 EXPECT_TRUE(
206 EXPECT_TRUE(new_sr); 191 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
207 EXPECT_EQ(1u, rtcp.list.size()); 192 EXPECT_TRUE(new_sr);
208 // Timestamp already added, list not updated. 193 // Timestamp already added, list not updated.
209 ++ntp_frac; 194 ++ntp_frac;
210 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 195 EXPECT_TRUE(
211 EXPECT_FALSE(new_sr); 196 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
212 EXPECT_EQ(1u, rtcp.list.size()); 197 EXPECT_FALSE(new_sr);
213 } 198 }
214 199
215 TEST(UpdateRtcpListTests, FailsForOldRtpTimestamp) { 200 TEST(UpdateRtcpMeasurementTests, FailsForOldRtpTimestamp) {
216 RtcpMeasurements rtcp; 201 RtpToNtpEstimator estimator;
217 uint32_t ntp_sec = 0; 202 uint32_t ntp_sec = 0;
218 uint32_t ntp_frac = 2; 203 uint32_t ntp_frac = 2;
219 uint32_t timestamp = 0x12345678; 204 uint32_t timestamp = 0x12345678;
220 bool new_sr; 205 bool new_sr;
221 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 206 EXPECT_TRUE(
222 EXPECT_TRUE(new_sr); 207 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
223 EXPECT_EQ(1u, rtcp.list.size()); 208 EXPECT_TRUE(new_sr);
224 // Old timestamp, list not updated. 209 // Old timestamp, list not updated.
225 ntp_frac += kOneMsInNtpFrac; 210 ntp_frac += kOneMsInNtpFrac;
226 timestamp -= kTimestampTicksPerMs; 211 timestamp -= kTimestampTicksPerMs;
227 EXPECT_FALSE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 212 EXPECT_FALSE(
228 EXPECT_FALSE(new_sr); 213 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
229 EXPECT_EQ(1u, rtcp.list.size()); 214 EXPECT_FALSE(new_sr);
230 } 215 }
231 216
232 TEST(UpdateRtcpListTests, VerifyParameters) { 217 TEST(UpdateRtcpMeasurementTests, VerifyParameters) {
233 RtcpMeasurements rtcp; 218 RtpToNtpEstimator estimator;
234 uint32_t ntp_sec = 1; 219 uint32_t ntp_sec = 1;
235 uint32_t ntp_frac = 2; 220 uint32_t ntp_frac = 2;
236 uint32_t timestamp = 0x12345678; 221 uint32_t timestamp = 0x12345678;
237 bool new_sr; 222 bool new_sr;
238 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 223 EXPECT_TRUE(
239 EXPECT_TRUE(new_sr); 224 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
240 EXPECT_FALSE(rtcp.params.calculated); 225 EXPECT_TRUE(new_sr);
226 EXPECT_FALSE(estimator.params().calculated);
241 // Add second report, parameters should be calculated. 227 // Add second report, parameters should be calculated.
242 ntp_frac += kOneMsInNtpFrac; 228 ntp_frac += kOneMsInNtpFrac;
243 timestamp += kTimestampTicksPerMs; 229 timestamp += kTimestampTicksPerMs;
244 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 230 EXPECT_TRUE(
245 EXPECT_TRUE(rtcp.params.calculated); 231 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
246 EXPECT_DOUBLE_EQ(90.0, rtcp.params.frequency_khz); 232 EXPECT_TRUE(estimator.params().calculated);
247 EXPECT_NE(0.0, rtcp.params.offset_ms); 233 EXPECT_DOUBLE_EQ(90.0, estimator.params().frequency_khz);
248 } 234 EXPECT_NE(0.0, estimator.params().offset_ms);
249
250 TEST(RtpToNtpTests, FailsForEmptyList) {
251 RtcpMeasurements rtcp;
252 rtcp.params.calculated = true;
253 // List is empty, conversion of RTP to NTP time should fail.
254 EXPECT_EQ(0u, rtcp.list.size());
255 int64_t timestamp_ms = -1;
256 EXPECT_FALSE(RtpToNtpMs(0, rtcp, &timestamp_ms));
257 } 235 }
258 236
259 TEST(RtpToNtpTests, FailsForNoParameters) { 237 TEST(RtpToNtpTests, FailsForNoParameters) {
260 RtcpMeasurements rtcp; 238 RtpToNtpEstimator estimator;
261 uint32_t ntp_sec = 1; 239 uint32_t ntp_sec = 1;
262 uint32_t ntp_frac = 2; 240 uint32_t ntp_frac = 2;
263 uint32_t timestamp = 0x12345678; 241 uint32_t timestamp = 0x12345678;
264 bool new_sr; 242 bool new_sr;
265 EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr)); 243 EXPECT_TRUE(
266 EXPECT_EQ(1u, rtcp.list.size()); 244 estimator.UpdateMeasurements(ntp_sec, ntp_frac, timestamp, &new_sr));
245 EXPECT_TRUE(new_sr);
267 // Parameters are not calculated, conversion of RTP to NTP time should fail. 246 // Parameters are not calculated, conversion of RTP to NTP time should fail.
268 EXPECT_FALSE(rtcp.params.calculated); 247 EXPECT_FALSE(estimator.params().calculated);
269 int64_t timestamp_ms = -1; 248 int64_t timestamp_ms = -1;
270 EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, &timestamp_ms)); 249 EXPECT_FALSE(estimator.Estimate(timestamp, &timestamp_ms));
271 } 250 }
272 251
273 }; // namespace webrtc 252 }; // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/system_wrappers/source/rtp_to_ntp_estimator.cc ('k') | webrtc/system_wrappers/source/rtp_to_ntp_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698