Home | History | Annotate | Download | only in rtcp
      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
      3 // found in the LICENSE file.
      4 
      5 #include "base/test/simple_test_tick_clock.h"
      6 #include "media/cast/cast_defines.h"
      7 #include "media/cast/cast_environment.h"
      8 #include "media/cast/net/pacing/paced_sender.h"
      9 #include "media/cast/rtcp/mock_rtcp_receiver_feedback.h"
     10 #include "media/cast/rtcp/mock_rtcp_sender_feedback.h"
     11 #include "media/cast/rtcp/rtcp.h"
     12 #include "media/cast/rtcp/test_rtcp_packet_builder.h"
     13 #include "media/cast/test/fake_task_runner.h"
     14 #include "testing/gmock/include/gmock/gmock.h"
     15 
     16 namespace media {
     17 namespace cast {
     18 
     19 using testing::_;
     20 
     21 static const uint32 kSenderSsrc = 0x10203;
     22 static const uint32 kReceiverSsrc = 0x40506;
     23 static const std::string kCName("test (at) 10.1.1.1");
     24 static const uint32 kRtcpIntervalMs = 500;
     25 static const int64 kStartMillisecond = GG_INT64_C(12345678900000);
     26 static const int64 kAddedDelay = 123;
     27 static const int64 kAddedShortDelay= 100;
     28 
     29 class LocalRtcpTransport : public PacedPacketSender {
     30  public:
     31   explicit LocalRtcpTransport(scoped_refptr<CastEnvironment> cast_environment,
     32                               base::SimpleTestTickClock* testing_clock)
     33       : drop_packets_(false),
     34         short_delay_(false),
     35         testing_clock_(testing_clock) {}
     36 
     37   void SetRtcpReceiver(Rtcp* rtcp) { rtcp_ = rtcp; }
     38 
     39   void SetShortDelay() { short_delay_ = true; }
     40 
     41   void SetDropPackets(bool drop_packets) { drop_packets_ = drop_packets; }
     42 
     43 
     44   virtual bool SendRtcpPacket(const std::vector<uint8>& packet) OVERRIDE {
     45     if (short_delay_) {
     46       testing_clock_->Advance(
     47           base::TimeDelta::FromMilliseconds(kAddedShortDelay));
     48     } else {
     49       testing_clock_->Advance(base::TimeDelta::FromMilliseconds(kAddedDelay));
     50     }
     51     if (drop_packets_) return true;
     52 
     53     rtcp_->IncomingRtcpPacket(&(packet[0]), packet.size());
     54     return true;
     55   }
     56 
     57   virtual bool SendPackets(const PacketList& packets) OVERRIDE {
     58     return false;
     59   }
     60 
     61   virtual bool ResendPackets(const PacketList& packets) OVERRIDE {
     62     return false;
     63   }
     64 
     65  private:
     66   bool drop_packets_;
     67   bool short_delay_;
     68   Rtcp* rtcp_;
     69   base::SimpleTestTickClock* testing_clock_;
     70   scoped_refptr<CastEnvironment> cast_environment_;
     71 };
     72 
     73 class RtcpPeer : public Rtcp {
     74  public:
     75   RtcpPeer(scoped_refptr<CastEnvironment> cast_environment,
     76            RtcpSenderFeedback* sender_feedback,
     77            PacedPacketSender* const paced_packet_sender,
     78            RtpSenderStatistics* rtp_sender_statistics,
     79            RtpReceiverStatistics* rtp_receiver_statistics,
     80            RtcpMode rtcp_mode,
     81            const base::TimeDelta& rtcp_interval,
     82            uint32 local_ssrc,
     83            uint32 remote_ssrc,
     84            const std::string& c_name)
     85       : Rtcp(cast_environment,
     86              sender_feedback,
     87              paced_packet_sender,
     88              rtp_sender_statistics,
     89              rtp_receiver_statistics,
     90              rtcp_mode,
     91              rtcp_interval,
     92              local_ssrc,
     93              remote_ssrc,
     94              c_name) {
     95   }
     96 
     97   using Rtcp::CheckForWrapAround;
     98   using Rtcp::OnReceivedLipSyncInfo;
     99 };
    100 
    101 class RtcpTest : public ::testing::Test {
    102  protected:
    103   RtcpTest()
    104       : task_runner_(new test::FakeTaskRunner(&testing_clock_)),
    105         cast_environment_(new CastEnvironment(&testing_clock_, task_runner_,
    106             task_runner_, task_runner_, task_runner_, task_runner_,
    107             GetDefaultCastLoggingConfig())),
    108         transport_(cast_environment_, &testing_clock_) {
    109     testing_clock_.Advance(
    110         base::TimeDelta::FromMilliseconds(kStartMillisecond));
    111   }
    112 
    113   virtual ~RtcpTest() {}
    114 
    115   virtual void SetUp() {
    116     EXPECT_CALL(mock_sender_feedback_, OnReceivedCastFeedback(_)).Times(0);
    117   }
    118 
    119   base::SimpleTestTickClock testing_clock_;
    120   scoped_refptr<test::FakeTaskRunner> task_runner_;
    121   scoped_refptr<CastEnvironment> cast_environment_;
    122   LocalRtcpTransport transport_;
    123   MockRtcpSenderFeedback mock_sender_feedback_;
    124 };
    125 
    126 TEST_F(RtcpTest, TimeToSend) {
    127   base::TimeTicks start_time;
    128   start_time += base::TimeDelta::FromMilliseconds(kStartMillisecond);
    129   Rtcp rtcp(cast_environment_,
    130             &mock_sender_feedback_,
    131             &transport_,
    132             NULL,
    133             NULL,
    134             kRtcpCompound,
    135             base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
    136             kSenderSsrc,
    137             kReceiverSsrc,
    138             kCName);
    139   transport_.SetRtcpReceiver(&rtcp);
    140   EXPECT_LE(start_time, rtcp.TimeToSendNextRtcpReport());
    141   EXPECT_GE(start_time + base::TimeDelta::FromMilliseconds(
    142                 kRtcpIntervalMs * 3 / 2),
    143             rtcp.TimeToSendNextRtcpReport());
    144   base::TimeDelta delta = rtcp.TimeToSendNextRtcpReport() - start_time;
    145   testing_clock_.Advance(delta);
    146   EXPECT_EQ(testing_clock_.NowTicks(), rtcp.TimeToSendNextRtcpReport());
    147 }
    148 
    149 TEST_F(RtcpTest, BasicSenderReport) {
    150   Rtcp rtcp(cast_environment_,
    151             &mock_sender_feedback_,
    152             &transport_,
    153             NULL,
    154             NULL,
    155             kRtcpCompound,
    156             base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
    157             kSenderSsrc,
    158             kReceiverSsrc,
    159             kCName);
    160   transport_.SetRtcpReceiver(&rtcp);
    161   rtcp.SendRtcpFromRtpSender(NULL);
    162 }
    163 
    164 TEST_F(RtcpTest, BasicReceiverReport) {
    165   Rtcp rtcp(cast_environment_,
    166             &mock_sender_feedback_,
    167             &transport_,
    168             NULL,
    169             NULL,
    170             kRtcpCompound,
    171             base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
    172             kSenderSsrc,
    173             kReceiverSsrc,
    174             kCName);
    175   transport_.SetRtcpReceiver(&rtcp);
    176   rtcp.SendRtcpFromRtpReceiver(NULL, NULL);
    177 }
    178 
    179 TEST_F(RtcpTest, BasicCast) {
    180   EXPECT_CALL(mock_sender_feedback_, OnReceivedCastFeedback(_)).Times(1);
    181 
    182   // Media receiver.
    183   Rtcp rtcp(cast_environment_,
    184             &mock_sender_feedback_,
    185             &transport_,
    186             NULL,
    187             NULL,
    188             kRtcpReducedSize,
    189             base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
    190             kSenderSsrc,
    191             kSenderSsrc,
    192             kCName);
    193   transport_.SetRtcpReceiver(&rtcp);
    194   RtcpCastMessage cast_message(kSenderSsrc);
    195   cast_message.ack_frame_id_ = kAckFrameId;
    196   PacketIdSet missing_packets;
    197   cast_message.missing_frames_and_packets_[
    198       kLostFrameId] = missing_packets;
    199 
    200   missing_packets.insert(kLostPacketId1);
    201   missing_packets.insert(kLostPacketId2);
    202   missing_packets.insert(kLostPacketId3);
    203   cast_message.missing_frames_and_packets_[kFrameIdWithLostPackets] =
    204       missing_packets;
    205   rtcp.SendRtcpFromRtpReceiver(&cast_message, NULL);
    206 }
    207 
    208 TEST_F(RtcpTest, RttReducedSizeRtcp) {
    209   // Media receiver.
    210   LocalRtcpTransport receiver_transport(cast_environment_, &testing_clock_);
    211   Rtcp rtcp_receiver(cast_environment_,
    212                      &mock_sender_feedback_,
    213                      &receiver_transport,
    214                      NULL,
    215                      NULL,
    216                      kRtcpReducedSize,
    217                      base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
    218                      kReceiverSsrc,
    219                      kSenderSsrc,
    220                      kCName);
    221 
    222   // Media sender.
    223   LocalRtcpTransport sender_transport(cast_environment_, &testing_clock_);
    224   Rtcp rtcp_sender(cast_environment_,
    225                    &mock_sender_feedback_,
    226                    &sender_transport,
    227                    NULL,
    228                    NULL,
    229                    kRtcpReducedSize,
    230                    base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
    231                    kSenderSsrc,
    232                    kReceiverSsrc,
    233                    kCName);
    234 
    235   receiver_transport.SetRtcpReceiver(&rtcp_sender);
    236   sender_transport.SetRtcpReceiver(&rtcp_receiver);
    237 
    238   base::TimeDelta rtt;
    239   base::TimeDelta avg_rtt;
    240   base::TimeDelta min_rtt;
    241   base::TimeDelta max_rtt;
    242   EXPECT_FALSE(rtcp_sender.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    243   EXPECT_FALSE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    244 
    245   rtcp_sender.SendRtcpFromRtpSender(NULL);
    246   rtcp_receiver.SendRtcpFromRtpReceiver(NULL, NULL);
    247   EXPECT_TRUE(rtcp_sender.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    248   EXPECT_FALSE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    249   EXPECT_NEAR(2 * kAddedDelay, rtt.InMilliseconds(), 1);
    250   EXPECT_NEAR(2 * kAddedDelay, avg_rtt.InMilliseconds(), 1);
    251   EXPECT_NEAR(2 * kAddedDelay, min_rtt.InMilliseconds(), 1);
    252   EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1);
    253   rtcp_sender.SendRtcpFromRtpSender(NULL);
    254   EXPECT_TRUE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    255 
    256   EXPECT_NEAR(2 * kAddedDelay, rtt.InMilliseconds(), 1);
    257   EXPECT_NEAR(2 * kAddedDelay, avg_rtt.InMilliseconds(), 1);
    258   EXPECT_NEAR(2 * kAddedDelay, min_rtt.InMilliseconds(), 1);
    259   EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1);
    260 }
    261 
    262 TEST_F(RtcpTest, Rtt) {
    263   // Media receiver.
    264   LocalRtcpTransport receiver_transport(cast_environment_, &testing_clock_);
    265   Rtcp rtcp_receiver(cast_environment_,
    266                      &mock_sender_feedback_,
    267                      &receiver_transport,
    268                      NULL,
    269                      NULL,
    270                      kRtcpCompound,
    271                      base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
    272                      kReceiverSsrc,
    273                      kSenderSsrc,
    274                      kCName);
    275 
    276   // Media sender.
    277   LocalRtcpTransport sender_transport(cast_environment_, &testing_clock_);
    278   Rtcp rtcp_sender(cast_environment_,
    279                    &mock_sender_feedback_,
    280                    &sender_transport,
    281                    NULL,
    282                    NULL,
    283                    kRtcpCompound,
    284                    base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
    285                    kSenderSsrc,
    286                    kReceiverSsrc,
    287                    kCName);
    288 
    289   receiver_transport.SetRtcpReceiver(&rtcp_sender);
    290   sender_transport.SetRtcpReceiver(&rtcp_receiver);
    291 
    292   base::TimeDelta rtt;
    293   base::TimeDelta avg_rtt;
    294   base::TimeDelta min_rtt;
    295   base::TimeDelta max_rtt;
    296   EXPECT_FALSE(rtcp_sender.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    297   EXPECT_FALSE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    298 
    299   rtcp_sender.SendRtcpFromRtpSender(NULL);
    300   rtcp_receiver.SendRtcpFromRtpReceiver(NULL, NULL);
    301   EXPECT_TRUE(rtcp_sender.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    302   EXPECT_FALSE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    303   EXPECT_NEAR(2 * kAddedDelay, rtt.InMilliseconds(), 1);
    304   EXPECT_NEAR(2 * kAddedDelay, avg_rtt.InMilliseconds(), 1);
    305   EXPECT_NEAR(2 * kAddedDelay, min_rtt.InMilliseconds(), 1);
    306   EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1);
    307 
    308   rtcp_sender.SendRtcpFromRtpSender(NULL);
    309   EXPECT_TRUE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    310   EXPECT_NEAR(2 * kAddedDelay, rtt.InMilliseconds(), 1);
    311   EXPECT_NEAR(2 * kAddedDelay, avg_rtt.InMilliseconds(), 1);
    312   EXPECT_NEAR(2 * kAddedDelay, min_rtt.InMilliseconds(), 1);
    313   EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1);
    314 
    315   receiver_transport.SetShortDelay();
    316   sender_transport.SetShortDelay();
    317   rtcp_receiver.SendRtcpFromRtpReceiver(NULL, NULL);
    318   EXPECT_TRUE(rtcp_sender.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    319   EXPECT_NEAR(kAddedDelay + kAddedShortDelay, rtt.InMilliseconds(), 1);
    320   EXPECT_NEAR((kAddedShortDelay + 3 * kAddedDelay) / 2,
    321                avg_rtt.InMilliseconds(),
    322                1);
    323   EXPECT_NEAR(kAddedDelay + kAddedShortDelay, min_rtt.InMilliseconds(), 1);
    324   EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1);
    325 
    326   rtcp_sender.SendRtcpFromRtpSender(NULL);
    327   EXPECT_TRUE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    328   EXPECT_NEAR(2 * kAddedShortDelay, rtt.InMilliseconds(), 1);
    329   EXPECT_NEAR((2 * kAddedShortDelay + 2 * kAddedDelay) / 2,
    330                avg_rtt.InMilliseconds(),
    331                1);
    332   EXPECT_NEAR(2 * kAddedShortDelay, min_rtt.InMilliseconds(), 1);
    333   EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1);
    334 
    335   rtcp_receiver.SendRtcpFromRtpReceiver(NULL, NULL);
    336   EXPECT_TRUE(rtcp_sender.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    337   EXPECT_NEAR(2 * kAddedShortDelay, rtt.InMilliseconds(), 1);
    338   EXPECT_NEAR(2 * kAddedShortDelay, min_rtt.InMilliseconds(), 1);
    339   EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1);
    340 
    341   rtcp_receiver.SendRtcpFromRtpReceiver(NULL, NULL);
    342   EXPECT_TRUE(rtcp_sender.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    343   EXPECT_NEAR(2 * kAddedShortDelay, rtt.InMilliseconds(), 1);
    344   EXPECT_NEAR(2 * kAddedShortDelay, min_rtt.InMilliseconds(), 1);
    345   EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1);
    346 }
    347 
    348 TEST_F(RtcpTest, RttWithPacketLoss) {
    349   // Media receiver.
    350   LocalRtcpTransport receiver_transport(cast_environment_, &testing_clock_);
    351   Rtcp rtcp_receiver(cast_environment_,
    352                      &mock_sender_feedback_,
    353                      &receiver_transport,
    354                      NULL,
    355                      NULL,
    356                      kRtcpReducedSize,
    357                      base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
    358                      kSenderSsrc,
    359                      kReceiverSsrc,
    360                      kCName);
    361 
    362   // Media sender.
    363   LocalRtcpTransport sender_transport(cast_environment_, &testing_clock_);
    364   Rtcp rtcp_sender(cast_environment_,
    365                    &mock_sender_feedback_,
    366                    &sender_transport,
    367                    NULL,
    368                    NULL,
    369                    kRtcpReducedSize,
    370                    base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
    371                    kReceiverSsrc,
    372                    kSenderSsrc,
    373                    kCName);
    374 
    375   receiver_transport.SetRtcpReceiver(&rtcp_sender);
    376   sender_transport.SetRtcpReceiver(&rtcp_receiver);
    377 
    378   rtcp_receiver.SendRtcpFromRtpReceiver(NULL, NULL);
    379   rtcp_sender.SendRtcpFromRtpSender(NULL);
    380 
    381   base::TimeDelta rtt;
    382   base::TimeDelta avg_rtt;
    383   base::TimeDelta min_rtt;
    384   base::TimeDelta max_rtt;
    385   EXPECT_FALSE(rtcp_sender.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    386   EXPECT_TRUE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    387   EXPECT_NEAR(2 * kAddedDelay, rtt.InMilliseconds(), 1);
    388   EXPECT_NEAR(2 * kAddedDelay, avg_rtt.InMilliseconds(), 1);
    389   EXPECT_NEAR(2 * kAddedDelay, min_rtt.InMilliseconds(), 1);
    390   EXPECT_NEAR(2 * kAddedDelay, max_rtt.InMilliseconds(), 1);
    391 
    392   receiver_transport.SetShortDelay();
    393   sender_transport.SetShortDelay();
    394   receiver_transport.SetDropPackets(true);
    395 
    396   rtcp_receiver.SendRtcpFromRtpReceiver(NULL, NULL);
    397   rtcp_sender.SendRtcpFromRtpSender(NULL);
    398 
    399   EXPECT_TRUE(rtcp_receiver.Rtt(&rtt, &avg_rtt, &min_rtt,  &max_rtt));
    400   EXPECT_NEAR(kAddedDelay + kAddedShortDelay, rtt.InMilliseconds(), 1);
    401 }
    402 
    403 TEST_F(RtcpTest, NtpAndTime) {
    404   const int64 kSecondsbetweenYear1900and2010 = GG_INT64_C(40176 * 24 * 60 * 60);
    405   const int64 kSecondsbetweenYear1900and2030 = GG_INT64_C(47481 * 24 * 60 * 60);
    406 
    407   uint32 ntp_seconds_1 = 0;
    408   uint32 ntp_fractions_1 = 0;
    409   base::TimeTicks input_time = base::TimeTicks::Now();
    410   ConvertTimeTicksToNtp(input_time, &ntp_seconds_1, &ntp_fractions_1);
    411 
    412   // Verify absolute value.
    413   EXPECT_GT(ntp_seconds_1, kSecondsbetweenYear1900and2010);
    414   EXPECT_LT(ntp_seconds_1, kSecondsbetweenYear1900and2030);
    415 
    416   base::TimeTicks out_1 = ConvertNtpToTimeTicks(ntp_seconds_1, ntp_fractions_1);
    417   EXPECT_EQ(input_time, out_1);  // Verify inverse.
    418 
    419   base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(1000);
    420   input_time += time_delta;
    421 
    422   uint32 ntp_seconds_2 = 0;
    423   uint32 ntp_fractions_2 = 0;
    424 
    425   ConvertTimeTicksToNtp(input_time, &ntp_seconds_2, &ntp_fractions_2);
    426   base::TimeTicks out_2 = ConvertNtpToTimeTicks(ntp_seconds_2, ntp_fractions_2);
    427   EXPECT_EQ(input_time, out_2);  // Verify inverse.
    428 
    429   // Verify delta.
    430   EXPECT_EQ((out_2 - out_1), time_delta);
    431   EXPECT_EQ((ntp_seconds_2 - ntp_seconds_1), GG_UINT32_C(1));
    432   EXPECT_NEAR(ntp_fractions_2, ntp_fractions_1, 1);
    433 
    434   time_delta = base::TimeDelta::FromMilliseconds(500);
    435   input_time += time_delta;
    436 
    437   uint32 ntp_seconds_3 = 0;
    438   uint32 ntp_fractions_3 = 0;
    439 
    440   ConvertTimeTicksToNtp(input_time, &ntp_seconds_3, &ntp_fractions_3);
    441   base::TimeTicks out_3 = ConvertNtpToTimeTicks(ntp_seconds_3, ntp_fractions_3);
    442   EXPECT_EQ(input_time, out_3);  // Verify inverse.
    443 
    444   // Verify delta.
    445   EXPECT_EQ((out_3 - out_2), time_delta);
    446   EXPECT_NEAR((ntp_fractions_3 - ntp_fractions_2), 0xffffffff / 2, 1);
    447 }
    448 
    449 TEST_F(RtcpTest, WrapAround) {
    450   RtcpPeer rtcp_peer(cast_environment_,
    451                      &mock_sender_feedback_,
    452                      NULL,
    453                      NULL,
    454                      NULL,
    455                      kRtcpReducedSize,
    456                      base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
    457                      kReceiverSsrc,
    458                      kSenderSsrc,
    459                      kCName);
    460   uint32 new_timestamp = 0;
    461   uint32 old_timestamp = 0;
    462   EXPECT_EQ(0, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp));
    463   new_timestamp = 1234567890;
    464   old_timestamp = 1234567000;
    465   EXPECT_EQ(0, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp));
    466   new_timestamp = 1234567000;
    467   old_timestamp = 1234567890;
    468   EXPECT_EQ(0, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp));
    469   new_timestamp = 123;
    470   old_timestamp = 4234567890u;
    471   EXPECT_EQ(1, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp));
    472   new_timestamp = 4234567890u;
    473   old_timestamp = 123;
    474   EXPECT_EQ(-1, rtcp_peer.CheckForWrapAround(new_timestamp, old_timestamp));
    475 }
    476 
    477 TEST_F(RtcpTest, RtpTimestampInSenderTime) {
    478   RtcpPeer rtcp_peer(cast_environment_,
    479                      &mock_sender_feedback_,
    480                      NULL,
    481                      NULL,
    482                      NULL,
    483                      kRtcpReducedSize,
    484                      base::TimeDelta::FromMilliseconds(kRtcpIntervalMs),
    485                      kReceiverSsrc,
    486                      kSenderSsrc,
    487                      kCName);
    488   int frequency = 32000;
    489   uint32 rtp_timestamp = 64000;
    490   base::TimeTicks rtp_timestamp_in_ticks;
    491 
    492   // Test fail before we get a OnReceivedLipSyncInfo.
    493   EXPECT_FALSE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
    494                                                    &rtp_timestamp_in_ticks));
    495 
    496   uint32 ntp_seconds = 0;
    497   uint32 ntp_fractions = 0;
    498   uint64 input_time_us = 12345678901000LL;
    499   base::TimeTicks input_time;
    500   input_time += base::TimeDelta::FromMicroseconds(input_time_us);
    501 
    502   // Test exact match.
    503   ConvertTimeTicksToNtp(input_time, &ntp_seconds, &ntp_fractions);
    504   rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions);
    505   EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
    506                                                  &rtp_timestamp_in_ticks));
    507   EXPECT_EQ(input_time, rtp_timestamp_in_ticks);
    508 
    509   // Test older rtp_timestamp.
    510   rtp_timestamp = 32000;
    511   EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
    512                                                  &rtp_timestamp_in_ticks));
    513   EXPECT_EQ(input_time - base::TimeDelta::FromMilliseconds(1000),
    514             rtp_timestamp_in_ticks);
    515 
    516   // Test older rtp_timestamp with wrap.
    517   rtp_timestamp = 4294903296u;
    518   EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
    519                                                  &rtp_timestamp_in_ticks));
    520   EXPECT_EQ(input_time - base::TimeDelta::FromMilliseconds(4000),
    521             rtp_timestamp_in_ticks);
    522 
    523   // Test newer rtp_timestamp.
    524   rtp_timestamp = 128000;
    525   EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
    526                                                  &rtp_timestamp_in_ticks));
    527   EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(2000),
    528             rtp_timestamp_in_ticks);
    529 
    530   // Test newer rtp_timestamp with wrap.
    531   rtp_timestamp = 4294903296u;
    532   rtcp_peer.OnReceivedLipSyncInfo(rtp_timestamp, ntp_seconds, ntp_fractions);
    533   rtp_timestamp = 64000;
    534   EXPECT_TRUE(rtcp_peer.RtpTimestampInSenderTime(frequency, rtp_timestamp,
    535                                                  &rtp_timestamp_in_ticks));
    536   EXPECT_EQ(input_time + base::TimeDelta::FromMilliseconds(4000),
    537             rtp_timestamp_in_ticks);
    538 }
    539 
    540 }  // namespace cast
    541 }  // namespace media
    542