| OLD | NEW | 
|---|
| 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 <stdint.h> | 
|  | 6 | 
| 5 #include "base/test/simple_test_tick_clock.h" | 7 #include "base/test/simple_test_tick_clock.h" | 
| 6 #include "media/cast/cast_defines.h" | 8 #include "media/cast/cast_defines.h" | 
| 7 #include "media/cast/cast_environment.h" | 9 #include "media/cast/cast_environment.h" | 
| 8 #include "media/cast/rtcp/mock_rtcp_receiver_feedback.h" | 10 #include "media/cast/rtcp/mock_rtcp_receiver_feedback.h" | 
| 9 #include "media/cast/rtcp/mock_rtcp_sender_feedback.h" | 11 #include "media/cast/rtcp/mock_rtcp_sender_feedback.h" | 
| 10 #include "media/cast/rtcp/rtcp.h" | 12 #include "media/cast/rtcp/rtcp.h" | 
| 11 #include "media/cast/rtcp/test_rtcp_packet_builder.h" | 13 #include "media/cast/rtcp/test_rtcp_packet_builder.h" | 
| 12 #include "media/cast/test/fake_single_thread_task_runner.h" | 14 #include "media/cast/test/fake_single_thread_task_runner.h" | 
| 13 #include "media/cast/transport/cast_transport_config.h" | 15 #include "media/cast/transport/cast_transport_config.h" | 
| 14 #include "media/cast/transport/cast_transport_sender_impl.h" | 16 #include "media/cast/transport/cast_transport_sender_impl.h" | 
| 15 #include "media/cast/transport/pacing/paced_sender.h" | 17 #include "media/cast/transport/pacing/paced_sender.h" | 
| 16 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" | 
| 17 | 19 | 
| 18 namespace media { | 20 namespace media { | 
| 19 namespace cast { | 21 namespace cast { | 
| 20 | 22 | 
| 21 using testing::_; | 23 using testing::_; | 
| 22 | 24 | 
| 23 static const uint32 kSenderSsrc = 0x10203; | 25 static const uint32 kSenderSsrc = 0x10203; | 
| 24 static const uint32 kReceiverSsrc = 0x40506; | 26 static const uint32 kReceiverSsrc = 0x40506; | 
| 25 static const std::string kCName("test@10.1.1.1"); | 27 static const std::string kCName("test@10.1.1.1"); | 
| 26 static const uint32 kRtcpIntervalMs = 500; | 28 static const uint32 kRtcpIntervalMs = 500; | 
| 27 static const int64 kStartMillisecond = GG_INT64_C(12345678900000); | 29 static const int64 kStartMillisecond = INT64_C(12345678900000); | 
| 28 static const int64 kAddedDelay = 123; | 30 static const int64 kAddedDelay = 123; | 
| 29 static const int64 kAddedShortDelay = 100; | 31 static const int64 kAddedShortDelay = 100; | 
| 30 | 32 | 
| 31 class RtcpTestPacketSender : public transport::PacketSender { | 33 class RtcpTestPacketSender : public transport::PacketSender { | 
| 32  public: | 34  public: | 
| 33   explicit RtcpTestPacketSender(base::SimpleTestTickClock* testing_clock) | 35   explicit RtcpTestPacketSender(base::SimpleTestTickClock* testing_clock) | 
| 34       : drop_packets_(false), | 36       : drop_packets_(false), | 
| 35         short_delay_(false), | 37         short_delay_(false), | 
| 36         rtcp_receiver_(NULL), | 38         rtcp_receiver_(NULL), | 
| 37         testing_clock_(testing_clock) {} | 39         testing_clock_(testing_clock) {} | 
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 480   rtcp_receiver.SendRtcpFromRtpReceiver(NULL, NULL); | 482   rtcp_receiver.SendRtcpFromRtpReceiver(NULL, NULL); | 
| 481   rtcp_sender.SendRtcpFromRtpSender(empty_sender_log, | 483   rtcp_sender.SendRtcpFromRtpSender(empty_sender_log, | 
| 482                                     rtp_sender_stats_.sender_info()); | 484                                     rtp_sender_stats_.sender_info()); | 
| 483   RunTasks(33); | 485   RunTasks(33); | 
| 484 | 486 | 
| 485   EXPECT_TRUE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt, &max_rtt)); | 487   EXPECT_TRUE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt, &max_rtt)); | 
| 486   EXPECT_NEAR(kAddedDelay + kAddedShortDelay, rtt.InMilliseconds(), 2); | 488   EXPECT_NEAR(kAddedDelay + kAddedShortDelay, rtt.InMilliseconds(), 2); | 
| 487 } | 489 } | 
| 488 | 490 | 
| 489 TEST_F(RtcpTest, NtpAndTime) { | 491 TEST_F(RtcpTest, NtpAndTime) { | 
| 490   const int64 kSecondsbetweenYear1900and2010 = GG_INT64_C(40176 * 24 * 60 * 60); | 492   const int64 kSecondsbetweenYear1900and2010 = INT64_C(40176 * 24 * 60 * 60); | 
| 491   const int64 kSecondsbetweenYear1900and2030 = GG_INT64_C(47481 * 24 * 60 * 60); | 493   const int64 kSecondsbetweenYear1900and2030 = INT64_C(47481 * 24 * 60 * 60); | 
| 492 | 494 | 
| 493   uint32 ntp_seconds_1 = 0; | 495   uint32 ntp_seconds_1 = 0; | 
| 494   uint32 ntp_fractions_1 = 0; | 496   uint32 ntp_fractions_1 = 0; | 
| 495   base::TimeTicks input_time = base::TimeTicks::Now(); | 497   base::TimeTicks input_time = base::TimeTicks::Now(); | 
| 496   ConvertTimeTicksToNtp(input_time, &ntp_seconds_1, &ntp_fractions_1); | 498   ConvertTimeTicksToNtp(input_time, &ntp_seconds_1, &ntp_fractions_1); | 
| 497 | 499 | 
| 498   // Verify absolute value. | 500   // Verify absolute value. | 
| 499   EXPECT_GT(ntp_seconds_1, kSecondsbetweenYear1900and2010); | 501   EXPECT_GT(ntp_seconds_1, kSecondsbetweenYear1900and2010); | 
| 500   EXPECT_LT(ntp_seconds_1, kSecondsbetweenYear1900and2030); | 502   EXPECT_LT(ntp_seconds_1, kSecondsbetweenYear1900and2030); | 
| 501 | 503 | 
| 502   base::TimeTicks out_1 = ConvertNtpToTimeTicks(ntp_seconds_1, ntp_fractions_1); | 504   base::TimeTicks out_1 = ConvertNtpToTimeTicks(ntp_seconds_1, ntp_fractions_1); | 
| 503   EXPECT_EQ(input_time, out_1);  // Verify inverse. | 505   EXPECT_EQ(input_time, out_1);  // Verify inverse. | 
| 504 | 506 | 
| 505   base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(1000); | 507   base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(1000); | 
| 506   input_time += time_delta; | 508   input_time += time_delta; | 
| 507 | 509 | 
| 508   uint32 ntp_seconds_2 = 0; | 510   uint32 ntp_seconds_2 = 0; | 
| 509   uint32 ntp_fractions_2 = 0; | 511   uint32 ntp_fractions_2 = 0; | 
| 510 | 512 | 
| 511   ConvertTimeTicksToNtp(input_time, &ntp_seconds_2, &ntp_fractions_2); | 513   ConvertTimeTicksToNtp(input_time, &ntp_seconds_2, &ntp_fractions_2); | 
| 512   base::TimeTicks out_2 = ConvertNtpToTimeTicks(ntp_seconds_2, ntp_fractions_2); | 514   base::TimeTicks out_2 = ConvertNtpToTimeTicks(ntp_seconds_2, ntp_fractions_2); | 
| 513   EXPECT_EQ(input_time, out_2);  // Verify inverse. | 515   EXPECT_EQ(input_time, out_2);  // Verify inverse. | 
| 514 | 516 | 
| 515   // Verify delta. | 517   // Verify delta. | 
| 516   EXPECT_EQ((out_2 - out_1), time_delta); | 518   EXPECT_EQ((out_2 - out_1), time_delta); | 
| 517   EXPECT_EQ((ntp_seconds_2 - ntp_seconds_1), GG_UINT32_C(1)); | 519   EXPECT_EQ((ntp_seconds_2 - ntp_seconds_1), UINT32_C(1)); | 
| 518   EXPECT_NEAR(ntp_fractions_2, ntp_fractions_1, 1); | 520   EXPECT_NEAR(ntp_fractions_2, ntp_fractions_1, 1); | 
| 519 | 521 | 
| 520   time_delta = base::TimeDelta::FromMilliseconds(500); | 522   time_delta = base::TimeDelta::FromMilliseconds(500); | 
| 521   input_time += time_delta; | 523   input_time += time_delta; | 
| 522 | 524 | 
| 523   uint32 ntp_seconds_3 = 0; | 525   uint32 ntp_seconds_3 = 0; | 
| 524   uint32 ntp_fractions_3 = 0; | 526   uint32 ntp_fractions_3 = 0; | 
| 525 | 527 | 
| 526   ConvertTimeTicksToNtp(input_time, &ntp_seconds_3, &ntp_fractions_3); | 528   ConvertTimeTicksToNtp(input_time, &ntp_seconds_3, &ntp_fractions_3); | 
| 527   base::TimeTicks out_3 = ConvertNtpToTimeTicks(ntp_seconds_3, ntp_fractions_3); | 529   base::TimeTicks out_3 = ConvertNtpToTimeTicks(ntp_seconds_3, ntp_fractions_3); | 
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 618   rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions); | 620   rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions); | 
| 619   rtp_timestamp = 64000; | 621   rtp_timestamp = 64000; | 
| 620   EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime( | 622   EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime( | 
| 621       frequency, rtp_timestamp, &rtp_timestamp_in_ticks)); | 623       frequency, rtp_timestamp, &rtp_timestamp_in_ticks)); | 
| 622   EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(4000), | 624   EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(4000), | 
| 623             rtp_timestamp_in_ticks); | 625             rtp_timestamp_in_ticks); | 
| 624 } | 626 } | 
| 625 | 627 | 
| 626 }  // namespace cast | 628 }  // namespace cast | 
| 627 }  // namespace media | 629 }  // namespace media | 
| OLD | NEW | 
|---|