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

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: Changed to use a LazyInstance instead of a Singleton 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 EXPECT_GT(ntp_seconds_1, kSecondsbetweenYear1900and2010);
310 kCName); 310 EXPECT_LT(ntp_seconds_1, kSecondsbetweenYear1900and2030);
311 uint32 ntp_seconds = 0; 311
312 uint32 ntp_fractions = 0; 312 base::TimeTicks out_1 = ConvertNtpToTimeTicks(ntp_seconds_1, ntp_fractions_1);
313 base::TimeTicks input_time = base::TimeTicks::FromInternalValue( 313 base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(1100);
314 12345678901000LL + kNtpEpochDeltaMicroseconds); 314 input_time += time_delta;
315 ConvertTimeToNtp(input_time, &ntp_seconds, &ntp_fractions); 315
316 EXPECT_EQ(12345678u, ntp_seconds); 316 uint32 ntp_seconds_2 = 0;
317 EXPECT_EQ(input_time, 317 uint32 ntp_fractions_2 = 0;
318 ConvertNtpToTime(ntp_seconds, ntp_fractions)); 318
319 ConvertTimeTicksToNtp(input_time, &ntp_seconds_2, &ntp_fractions_2);
320 base::TimeTicks out_2 = ConvertNtpToTimeTicks(ntp_seconds_2, ntp_fractions_2);
321
322 EXPECT_EQ((out_2 - out_1), time_delta);
323 EXPECT_EQ((ntp_seconds_2 - ntp_seconds_1), 1);
324 EXPECT_NEAR((ntp_fractions_2 - ntp_fractions_1), 0xffffffff / 10, 1);
319 } 325 }
320 326
321 TEST_F(RtcpTest, WrapAround) { 327 TEST_F(RtcpTest, WrapAround) {
322 RtcpPeer rtcp_peer(&testing_clock_, 328 RtcpPeer rtcp_peer(&testing_clock_,
323 &mock_sender_feedback_, 329 &mock_sender_feedback_,
324 NULL, 330 NULL,
325 NULL, 331 NULL,
326 NULL, 332 NULL,
327 kRtcpReducedSize, 333 kRtcpReducedSize,
328 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs), 334 base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 int frequency = 32000; 366 int frequency = 32000;
361 uint32 rtp_timestamp = 64000; 367 uint32 rtp_timestamp = 64000;
362 base::TimeTicks rtp_timestamp_in_ticks; 368 base::TimeTicks rtp_timestamp_in_ticks;
363 369
364 // Test fail before we get a OnReceivedLipSyncInfo. 370 // Test fail before we get a OnReceivedLipSyncInfo.
365 EXPECT_FALSE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp, 371 EXPECT_FALSE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
366 &rtp_timestamp_in_ticks)); 372 &rtp_timestamp_in_ticks));
367 373
368 uint32 ntp_seconds = 0; 374 uint32 ntp_seconds = 0;
369 uint32 ntp_fractions = 0; 375 uint32 ntp_fractions = 0;
370 base::TimeTicks input_time = base::TimeTicks::FromInternalValue( 376 uint64 input_time_us = 12345678901000LL;
371 12345678901000LL + kNtpEpochDeltaMicroseconds); 377 base::TimeTicks input_time;
378 input_time += base::TimeDelta::FromMicroseconds(input_time_us);
372 379
373 // Test exact match. 380 // Test exact match.
374 ConvertTimeToNtp(input_time, &ntp_seconds, &ntp_fractions); 381 ConvertTimeToFractions(input_time_us, &ntp_seconds, &ntp_fractions);
375 rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions); 382 rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions);
376 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp, 383 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
377 &rtp_timestamp_in_ticks)); 384 &rtp_timestamp_in_ticks));
378 EXPECT_EQ(input_time, rtp_timestamp_in_ticks); 385 EXPECT_EQ(input_time, rtp_timestamp_in_ticks);
379 386
380 // Test older rtp_timestamp. 387 // Test older rtp_timestamp.
381 rtp_timestamp = 32000; 388 rtp_timestamp = 32000;
382 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp, 389 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
383 &rtp_timestamp_in_ticks)); 390 &rtp_timestamp_in_ticks));
384 EXPECT_EQ(input_time - base::TimeDelta::FromMilliseconds(1000), 391 EXPECT_EQ(input_time - base::TimeDelta::FromMilliseconds(1000),
(...skipping 18 matching lines...) Expand all
403 rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions); 410 rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions);
404 rtp_timestamp = 64000; 411 rtp_timestamp = 64000;
405 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp, 412 EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
406 &rtp_timestamp_in_ticks)); 413 &rtp_timestamp_in_ticks));
407 EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(4000), 414 EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(4000),
408 rtp_timestamp_in_ticks); 415 rtp_timestamp_in_ticks);
409 } 416 }
410 417
411 } // namespace cast 418 } // namespace cast
412 } // namespace media 419 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698