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

Side by Side Diff: media/cast/rtcp/rtcp_unittest.cc

Issue 34623008: Change to calculate the real NTP in TimeTicks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed flaky test Created 7 years, 1 month 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/test/simple_test_tick_clock.h" 5 #include "base/test/simple_test_tick_clock.h"
6 #include "media/cast/cast_defines.h" 6 #include "media/cast/cast_defines.h"
7 #include "media/cast/pacing/paced_sender.h" 7 #include "media/cast/pacing/paced_sender.h"
8 #include "media/cast/rtcp/mock_rtcp_receiver_feedback.h" 8 #include "media/cast/rtcp/mock_rtcp_receiver_feedback.h"
9 #include "media/cast/rtcp/mock_rtcp_sender_feedback.h" 9 #include "media/cast/rtcp/mock_rtcp_sender_feedback.h"
10 #include "media/cast/rtcp/rtcp.h" 10 #include "media/cast/rtcp/rtcp.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 EXPECT_CALL(mock_sender_feedback_, OnReceivedNackRequest(_)).Times(0); 106 EXPECT_CALL(mock_sender_feedback_, OnReceivedNackRequest(_)).Times(0);
107 EXPECT_CALL(mock_sender_feedback_, OnReceivedCastFeedback(_)).Times(0); 107 EXPECT_CALL(mock_sender_feedback_, OnReceivedCastFeedback(_)).Times(0);
108 } 108 }
109 109
110 base::SimpleTestTickClock testing_clock_; 110 base::SimpleTestTickClock testing_clock_;
111 LocalRtcpTransport transport_; 111 LocalRtcpTransport transport_;
112 MockRtcpSenderFeedback mock_sender_feedback_; 112 MockRtcpSenderFeedback mock_sender_feedback_;
113 }; 113 };
114 114
115 TEST_F(RtcpTest, TimeToSend) { 115 TEST_F(RtcpTest, TimeToSend) {
116 base::TimeTicks start_time = 116 base::TimeTicks start_time;
117 base::TimeTicks::FromInternalValue(kStartMillisecond * 1000); 117 start_time += base::TimeDelta::FromMilliseconds(kStartMillisecond);
118 Rtcp rtcp(&testing_clock_, 118 Rtcp rtcp(&testing_clock_,
119 &mock_sender_feedback_, 119 &mock_sender_feedback_,
120 &transport_, 120 &transport_,
121 NULL, 121 NULL,
122 NULL, 122 NULL,
123 kRtcpCompound, 123 kRtcpCompound,
124 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), 124 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
125 true, // Media sender. 125 true, // Media sender.
126 kSenderSsrc, 126 kSenderSsrc,
127 kCName); 127 kCName);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 1); 286 1);
287 EXPECT_NEAR(kAddedDelay + kAddedShortDelay, min_rtt.InMilliseconds(), 1); 287 EXPECT_NEAR(kAddedDelay + kAddedShortDelay, min_rtt.InMilliseconds(), 1);
288 EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1); 288 EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1);
289 rtcp_sender.SendRtcpReport(kSenderSsrc); 289 rtcp_sender.SendRtcpReport(kSenderSsrc);
290 EXPECT_TRUE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt, &max_rtt)); 290 EXPECT_TRUE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt, &max_rtt));
291 291
292 EXPECT_NEAR(2 * kAddedShortDelay, rtt.InMilliseconds(), 1); 292 EXPECT_NEAR(2 * kAddedShortDelay, rtt.InMilliseconds(), 1);
293 EXPECT_NEAR((2 * kAddedShortDelay + 2 * kAddedDelay) / 2, 293 EXPECT_NEAR((2 * kAddedShortDelay + 2 * kAddedDelay) / 2,
294 avg_rtt.InMilliseconds(), 294 avg_rtt.InMilliseconds(),
295 1); 295 1);
296 EXPECT_NEAR(2 * kAddedShortDelay, min_rtt.InMilliseconds(), 1); 296 EXPECT_NEAR(2 * kAddedShortDelay, min_rtt.InMilliseconds(), 1);
297 EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1); 297 EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1);
298 } 298 }
299 299
300 TEST_F(RtcpTest, NtpAndTime) { 300 TEST_F(RtcpTest, NtpAndTime) {
301 RtcpPeer rtcp_peer(&testing_clock_, 301 const int64 kSecondsbetweenYear1900and2010 = GG_INT64_C(40176 * 24 * 60 * 60);
302 &mock_sender_feedback_, 302 const int64 kSecondsbetweenYear1900and2030 = GG_INT64_C(47481 * 24 * 60 * 60);
303 NULL, 303
304 NULL, 304 uint32 ntp_seconds_1 = 0;
305 NULL, 305 uint32 ntp_fractions_1 = 0;
306 kRtcpReducedSize, 306 base::TimeTicks input_time = base::TimeTicks::Now();
307 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), 307 ConvertTimeTicksToNtp(input_time, &ntp_seconds_1, &ntp_fractions_1);
308 false, 308
309 kReceiverSsrc, 309 // Verify absolute value.
310 kCName); 310 EXPECT_GT(ntp_seconds_1, kSecondsbetweenYear1900and2010);
311 uint32 ntp_seconds = 0; 311 EXPECT_LT(ntp_seconds_1, kSecondsbetweenYear1900and2030);
312 uint32 ntp_fractions = 0; 312
313 base::TimeTicks input_time = base::TimeTicks::FromInternalValue( 313 base::TimeTicks out_1 = ConvertNtpToTimeTicks(ntp_seconds_1, ntp_fractions_1);
314 12345678901000LL + kNtpEpochDeltaMicroseconds); 314 EXPECT_EQ(input_time, out_1); // Verify inverse.
315 ConvertTimeToNtp(input_time, &ntp_seconds, &ntp_fractions); 315
316 EXPECT_EQ(12345678u, ntp_seconds); 316 base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(1100);
317 EXPECT_EQ(input_time, 317 input_time += time_delta;
318 ConvertNtpToTime(ntp_seconds, ntp_fractions)); 318
319 uint32 ntp_seconds_2 = 0;
320 uint32 ntp_fractions_2 = 0;
321
322 ConvertTimeTicksToNtp(input_time, &ntp_seconds_2, &ntp_fractions_2);
323 base::TimeTicks out_2 = ConvertNtpToTimeTicks(ntp_seconds_2, ntp_fractions_2);
324 EXPECT_EQ(input_time, out_2); // Verify inverse.
325
326 // Verify delta.
327 EXPECT_EQ((out_2 - out_1), time_delta);
328 EXPECT_EQ((ntp_seconds_2 - ntp_seconds_1), GG_UINT32_C(1));
329 EXPECT_NEAR((ntp_fractions_2 - ntp_fractions_1), 0xffffffff / 10, 1);
319 } 330 }
320 331
321 TEST_F(RtcpTest, WrapAround) { 332 TEST_F(RtcpTest, WrapAround) {
322 RtcpPeer rtcp_peer(&testing_clock_, 333 RtcpPeer rtcp_peer(&testing_clock_,
323 &mock_sender_feedback_, 334 &mock_sender_feedback_,
324 NULL, 335 NULL,
325 NULL, 336 NULL,
326 NULL, 337 NULL,
327 kRtcpReducedSize, 338 kRtcpReducedSize,
328 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), 339 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 int frequency = 32000; 371 int frequency = 32000;
361 uint32 rtp_timestamp = 64000; 372 uint32 rtp_timestamp = 64000;
362 base::TimeTicks rtp_timestamp_in_ticks; 373 base::TimeTicks rtp_timestamp_in_ticks;
363 374
364 // Test fail before we get a OnReceivedLipSyncInfo. 375 // Test fail before we get a OnReceivedLipSyncInfo.
365 EXPECT_FALSE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp, 376 EXPECT_FALSE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
366 &rtp_timestamp_in_ticks)); 377 &rtp_timestamp_in_ticks));
367 378
368 uint32 ntp_seconds = 0; 379 uint32 ntp_seconds = 0;
369 uint32 ntp_fractions = 0; 380 uint32 ntp_fractions = 0;
370 base::TimeTicks input_time = base::TimeTicks::FromInternalValue( 381 uint64 input_time_us = 12345678901000LL;
371 12345678901000LL + kNtpEpochDeltaMicroseconds); 382 base::TimeTicks input_time;
383 input_time += base::TimeDelta::FromMicroseconds(input_time_us);
372 384
373 // Test exact match. 385 // Test exact match.
374 ConvertTimeToNtp(input_time, &ntp_seconds, &ntp_fractions); 386 ConvertTimeTicksToNtp(input_time, &ntp_seconds, &ntp_fractions);
375 rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions); 387 rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions);
376 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp, 388 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
377 &rtp_timestamp_in_ticks)); 389 &rtp_timestamp_in_ticks));
378 EXPECT_EQ(input_time, rtp_timestamp_in_ticks); 390 EXPECT_EQ(input_time, rtp_timestamp_in_ticks);
379 391
380 // Test older rtp_timestamp. 392 // Test older rtp_timestamp.
381 rtp_timestamp = 32000; 393 rtp_timestamp = 32000;
382 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp, 394 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
383 &rtp_timestamp_in_ticks)); 395 &rtp_timestamp_in_ticks));
384 EXPECT_EQ(input_time - base::TimeDelta::FromMilliseconds(1000), 396 EXPECT_EQ(input_time - base::TimeDelta::FromMilliseconds(1000),
385 rtp_timestamp_in_ticks); 397 rtp_timestamp_in_ticks);
386 398
387 // Test older rtp_timestamp with wrap. 399 // Test older rtp_timestamp with wrap.
388 rtp_timestamp = 4294903296u; 400 rtp_timestamp = 4294903296u;
389 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp, 401 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
390 &rtp_timestamp_in_ticks)); 402 &rtp_timestamp_in_ticks));
391 EXPECT_EQ(input_time - base::TimeDelta::FromMilliseconds(4000), 403 EXPECT_EQ(input_time - base::TimeDelta::FromMilliseconds(4000),
392 rtp_timestamp_in_ticks); 404 rtp_timestamp_in_ticks);
393 405
394 // Test newer rtp_timestamp. 406 // Test newer rtp_timestamp.
395 rtp_timestamp = 128000; 407 rtp_timestamp = 128000;
396 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp, 408 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
397 &rtp_timestamp_in_ticks)); 409 &rtp_timestamp_in_ticks));
398 EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(2000), 410 EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(2000),
399 rtp_timestamp_in_ticks); 411 rtp_timestamp_in_ticks);
400 412
401 // Test newer rtp_timestamp with wrap. 413 // Test newer rtp_timestamp with wrap.
402 rtp_timestamp = 4294903296u; 414 rtp_timestamp = 4294903296u;
403 rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions); 415 rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions);
404 rtp_timestamp = 64000; 416 rtp_timestamp = 64000;
405 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp, 417 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
406 &rtp_timestamp_in_ticks)); 418 &rtp_timestamp_in_ticks));
407 EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(4000), 419 EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(4000),
408 rtp_timestamp_in_ticks); 420 rtp_timestamp_in_ticks);
409 } 421 }
410 422
411 } // namespace cast 423 } // namespace cast
412 } // namespace media 424 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/rtcp/rtcp.cc ('k') | media/cast/rtp_sender/rtp_packetizer/rtp_packetizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698