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/memory/scoped_ptr.h"
      6 #include "base/test/simple_test_tick_clock.h"
      7 #include "media/cast/cast_environment.h"
      8 #include "media/cast/rtcp/mock_rtcp_receiver_feedback.h"
      9 #include "media/cast/rtcp/mock_rtcp_sender_feedback.h"
     10 #include "media/cast/rtcp/rtcp_receiver.h"
     11 #include "media/cast/rtcp/rtcp_utility.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 kSourceSsrc = 0x40506;
     23 static const uint32 kUnknownSsrc = 0xDEAD;
     24 static const std::string kCName("test (at) 10.1.1.1");
     25 
     26 namespace {
     27 class SenderFeedbackCastVerification : public RtcpSenderFeedback {
     28  public:
     29   SenderFeedbackCastVerification() : called_(false) {}
     30 
     31   virtual void OnReceivedCastFeedback(
     32       const RtcpCastMessage& cast_feedback) OVERRIDE {
     33     EXPECT_EQ(cast_feedback.media_ssrc_, kSenderSsrc);
     34     EXPECT_EQ(cast_feedback.ack_frame_id_, kAckFrameId);
     35 
     36     MissingFramesAndPacketsMap::const_iterator frame_it =
     37         cast_feedback.missing_frames_and_packets_.begin();
     38 
     39     EXPECT_TRUE(frame_it != cast_feedback.missing_frames_and_packets_.end());
     40     EXPECT_EQ(kLostFrameId, frame_it->first);
     41     EXPECT_TRUE(frame_it->second.empty());
     42     ++frame_it;
     43     EXPECT_TRUE(frame_it != cast_feedback.missing_frames_and_packets_.end());
     44     EXPECT_EQ(kFrameIdWithLostPackets, frame_it->first);
     45     EXPECT_EQ(3UL, frame_it->second.size());
     46     PacketIdSet::const_iterator packet_it = frame_it->second.begin();
     47     EXPECT_EQ(kLostPacketId1, *packet_it);
     48     ++packet_it;
     49     EXPECT_EQ(kLostPacketId2, *packet_it);
     50     ++packet_it;
     51     EXPECT_EQ(kLostPacketId3, *packet_it);
     52     ++frame_it;
     53     EXPECT_EQ(frame_it, cast_feedback.missing_frames_and_packets_.end());
     54     called_ = true;
     55   }
     56 
     57   bool called() const { return called_; }
     58 
     59  private:
     60   bool called_;
     61 };
     62 
     63 class RtcpReceiverCastLogVerification : public RtcpReceiverFeedback {
     64  public:
     65   RtcpReceiverCastLogVerification()
     66       : called_on_received_sender_log_(false),
     67         called_on_received_receiver_log_(false) {}
     68 
     69   virtual void OnReceivedSenderReport(
     70       const RtcpSenderInfo& remote_sender_info) OVERRIDE {};
     71 
     72   virtual void OnReceiverReferenceTimeReport(
     73       const RtcpReceiverReferenceTimeReport& remote_time_report) OVERRIDE {};
     74 
     75   virtual void OnReceivedSendReportRequest() OVERRIDE {};
     76 
     77   virtual void OnReceivedReceiverLog(
     78       const RtcpReceiverLogMessage& receiver_log) OVERRIDE {
     79     EXPECT_EQ(expected_receiver_log_.size(), receiver_log.size());
     80     RtcpReceiverLogMessage::const_iterator expected_it =
     81        expected_receiver_log_.begin();
     82     RtcpReceiverLogMessage::const_iterator incoming_it = receiver_log.begin();
     83     for (; incoming_it != receiver_log.end(); ++incoming_it) {
     84       EXPECT_EQ(expected_it->rtp_timestamp_, incoming_it->rtp_timestamp_);
     85       EXPECT_EQ(expected_it->event_log_messages_.size(),
     86                 incoming_it->event_log_messages_.size());
     87 
     88       RtcpReceiverEventLogMessages::const_iterator event_incoming_it =
     89           incoming_it->event_log_messages_.begin();
     90       RtcpReceiverEventLogMessages::const_iterator event_expected_it =
     91           expected_it->event_log_messages_.begin();
     92       for (; event_incoming_it != incoming_it->event_log_messages_.end();
     93            ++event_incoming_it, ++event_expected_it) {
     94         EXPECT_EQ(event_expected_it->type, event_incoming_it->type);
     95         EXPECT_EQ(event_expected_it->event_timestamp,
     96                   event_incoming_it->event_timestamp);
     97         if (event_expected_it->type == kPacketReceived) {
     98           EXPECT_EQ(event_expected_it->packet_id, event_incoming_it->packet_id);
     99         } else {
    100           EXPECT_EQ(event_expected_it->delay_delta,
    101                     event_incoming_it->delay_delta);
    102         }
    103       }
    104       expected_receiver_log_.pop_front();
    105       expected_it = expected_receiver_log_.begin();
    106     }
    107     called_on_received_receiver_log_ = true;
    108   }
    109 
    110   virtual void OnReceivedSenderLog(
    111       const RtcpSenderLogMessage& sender_log) OVERRIDE {
    112     EXPECT_EQ(expected_sender_log_.size(), sender_log.size());
    113 
    114     RtcpSenderLogMessage::const_iterator expected_it =
    115        expected_sender_log_.begin();
    116     RtcpSenderLogMessage::const_iterator incoming_it = sender_log.begin();
    117     for (; expected_it != expected_sender_log_.end();
    118         ++expected_it, ++incoming_it) {
    119       EXPECT_EQ(expected_it->frame_status, incoming_it->frame_status);
    120       EXPECT_EQ(0xffffff & expected_it->rtp_timestamp,
    121                 incoming_it->rtp_timestamp);
    122     }
    123     called_on_received_sender_log_ = true;
    124   }
    125 
    126   bool OnReceivedSenderLogCalled() {
    127     return called_on_received_sender_log_;
    128   }
    129 
    130   bool OnReceivedReceiverLogCalled() {
    131     return called_on_received_receiver_log_ && expected_receiver_log_.empty();
    132   }
    133 
    134   void SetExpectedReceiverLog(const RtcpReceiverLogMessage& receiver_log) {
    135     expected_receiver_log_ = receiver_log;
    136   }
    137 
    138   void SetExpectedSenderLog(const RtcpSenderLogMessage& sender_log) {
    139     expected_sender_log_ = sender_log;
    140   }
    141 
    142  private:
    143   RtcpReceiverLogMessage expected_receiver_log_;
    144   RtcpSenderLogMessage expected_sender_log_;
    145   bool called_on_received_sender_log_;
    146   bool called_on_received_receiver_log_;
    147 };
    148 
    149 }  // namespace
    150 
    151 class RtcpReceiverTest : public ::testing::Test {
    152  protected:
    153   RtcpReceiverTest()
    154       : task_runner_(new test::FakeTaskRunner(&testing_clock_)),
    155         cast_environment_(new CastEnvironment(&testing_clock_, task_runner_,
    156             task_runner_, task_runner_, task_runner_, task_runner_,
    157             GetDefaultCastLoggingConfig())),
    158         rtcp_receiver_(new RtcpReceiver(cast_environment_,
    159                                         &mock_sender_feedback_,
    160                                         &mock_receiver_feedback_,
    161                                         &mock_rtt_feedback_,
    162                                         kSourceSsrc)) {
    163   }
    164 
    165   virtual ~RtcpReceiverTest() {}
    166 
    167   virtual void SetUp() OVERRIDE {
    168     EXPECT_CALL(mock_receiver_feedback_, OnReceivedSenderReport(_)).Times(0);
    169     EXPECT_CALL(mock_receiver_feedback_,
    170                 OnReceiverReferenceTimeReport(_)).Times(0);
    171     EXPECT_CALL(mock_receiver_feedback_,
    172                 OnReceivedSendReportRequest()).Times(0);
    173     EXPECT_CALL(mock_sender_feedback_, OnReceivedCastFeedback(_)).Times(0);
    174     EXPECT_CALL(mock_rtt_feedback_,
    175                 OnReceivedDelaySinceLastReport(_, _, _)).Times(0);
    176 
    177     expected_sender_info_.ntp_seconds = kNtpHigh;
    178     expected_sender_info_.ntp_fraction = kNtpLow;
    179     expected_sender_info_.rtp_timestamp = kRtpTimestamp;
    180     expected_sender_info_.send_packet_count = kSendPacketCount;
    181     expected_sender_info_.send_octet_count = kSendOctetCount;
    182 
    183     expected_report_block_.remote_ssrc = kSenderSsrc;
    184     expected_report_block_.media_ssrc = kSourceSsrc;
    185     expected_report_block_.fraction_lost = kLoss >> 24;
    186     expected_report_block_.cumulative_lost = kLoss & 0xffffff;
    187     expected_report_block_.extended_high_sequence_number = kExtendedMax;
    188     expected_report_block_.jitter = kTestJitter;
    189     expected_report_block_.last_sr = kLastSr;
    190     expected_report_block_.delay_since_last_sr = kDelayLastSr;
    191     expected_receiver_reference_report_.remote_ssrc = kSenderSsrc;
    192     expected_receiver_reference_report_.ntp_seconds = kNtpHigh;
    193     expected_receiver_reference_report_.ntp_fraction = kNtpLow;
    194   }
    195 
    196   // Injects an RTCP packet into the receiver.
    197   void InjectRtcpPacket(const uint8* packet, uint16 length) {
    198     RtcpParser rtcp_parser(packet, length);
    199     rtcp_receiver_->IncomingRtcpPacket(&rtcp_parser);
    200   }
    201 
    202   base::SimpleTestTickClock testing_clock_;
    203   scoped_refptr<test::FakeTaskRunner> task_runner_;
    204   scoped_refptr<CastEnvironment> cast_environment_;
    205   MockRtcpReceiverFeedback mock_receiver_feedback_;
    206   MockRtcpRttFeedback mock_rtt_feedback_;
    207   MockRtcpSenderFeedback mock_sender_feedback_;
    208   scoped_ptr<RtcpReceiver> rtcp_receiver_;
    209   RtcpSenderInfo expected_sender_info_;
    210   RtcpReportBlock expected_report_block_;
    211   RtcpReceiverReferenceTimeReport expected_receiver_reference_report_;
    212 };
    213 
    214 TEST_F(RtcpReceiverTest, BrokenPacketIsIgnored) {
    215   const uint8 bad_packet[] = {0, 0, 0, 0};
    216   InjectRtcpPacket(bad_packet, sizeof(bad_packet));
    217 }
    218 
    219 TEST_F(RtcpReceiverTest, InjectSenderReportPacket) {
    220   TestRtcpPacketBuilder p;
    221   p.AddSr(kSenderSsrc, 0);
    222 
    223   // Expected to be ignored since the sender ssrc does not match our
    224   // remote ssrc.
    225   InjectRtcpPacket(p.Packet(), p.Length());
    226 
    227   EXPECT_CALL(mock_receiver_feedback_,
    228               OnReceivedSenderReport(expected_sender_info_)).Times(1);
    229   rtcp_receiver_->SetRemoteSSRC(kSenderSsrc);
    230 
    231   // Expected to be pass through since the sender ssrc match our remote ssrc.
    232   InjectRtcpPacket(p.Packet(), p.Length());
    233 }
    234 
    235 TEST_F(RtcpReceiverTest, InjectReceiveReportPacket) {
    236   TestRtcpPacketBuilder p1;
    237   p1.AddRr(kSenderSsrc, 1);
    238   p1.AddRb(kUnknownSsrc);
    239 
    240   // Expected to be ignored since the source ssrc does not match our
    241   // local ssrc.
    242   InjectRtcpPacket(p1.Packet(), p1.Length());
    243 
    244   EXPECT_CALL(mock_rtt_feedback_,
    245       OnReceivedDelaySinceLastReport(kSourceSsrc,
    246           kLastSr,
    247           kDelayLastSr)).Times(1);
    248 
    249   TestRtcpPacketBuilder p2;
    250   p2.AddRr(kSenderSsrc, 1);
    251   p2.AddRb(kSourceSsrc);
    252 
    253   // Expected to be pass through since the sender ssrc match our local ssrc.
    254   InjectRtcpPacket(p2.Packet(), p2.Length());
    255 }
    256 
    257 TEST_F(RtcpReceiverTest, InjectSenderReportWithReportBlockPacket) {
    258   TestRtcpPacketBuilder p1;
    259   p1.AddSr(kSenderSsrc, 1);
    260   p1.AddRb(kUnknownSsrc);
    261 
    262   // Sender report expected to be ignored since the sender ssrc does not match
    263   // our remote ssrc.
    264   // Report block expected to be ignored since the source ssrc does not match
    265   // our local ssrc.
    266   InjectRtcpPacket(p1.Packet(), p1.Length());
    267 
    268   EXPECT_CALL(mock_receiver_feedback_,
    269               OnReceivedSenderReport(expected_sender_info_)).Times(1);
    270   rtcp_receiver_->SetRemoteSSRC(kSenderSsrc);
    271 
    272   // Sender report expected to be pass through since the sender ssrc match our
    273   // remote ssrc.
    274   // Report block expected to be ignored since the source ssrc does not match
    275   // our local ssrc.
    276   InjectRtcpPacket(p1.Packet(), p1.Length());
    277 
    278   EXPECT_CALL(mock_receiver_feedback_, OnReceivedSenderReport(_)).Times(0);
    279   EXPECT_CALL(mock_rtt_feedback_,
    280       OnReceivedDelaySinceLastReport(kSourceSsrc,
    281         kLastSr,
    282         kDelayLastSr)).Times(1);
    283 
    284   rtcp_receiver_->SetRemoteSSRC(0);
    285 
    286   TestRtcpPacketBuilder p2;
    287   p2.AddSr(kSenderSsrc, 1);
    288   p2.AddRb(kSourceSsrc);
    289 
    290   // Sender report expected to be ignored since the sender ssrc does not match
    291   // our remote ssrc.
    292   // Receiver report expected to be pass through since the sender ssrc match
    293   // our local ssrc.
    294   InjectRtcpPacket(p2.Packet(), p2.Length());
    295 
    296   EXPECT_CALL(mock_receiver_feedback_,
    297               OnReceivedSenderReport(expected_sender_info_)).Times(1);
    298   EXPECT_CALL(mock_rtt_feedback_,
    299       OnReceivedDelaySinceLastReport(kSourceSsrc,
    300           kLastSr,
    301           kDelayLastSr)).Times(1);
    302 
    303   rtcp_receiver_->SetRemoteSSRC(kSenderSsrc);
    304 
    305   // Sender report expected to be pass through since the sender ssrc match our
    306   // remote ssrc.
    307   // Receiver report expected to be pass through since the sender ssrc match
    308   // our local ssrc.
    309   InjectRtcpPacket(p2.Packet(), p2.Length());
    310 }
    311 
    312 TEST_F(RtcpReceiverTest, InjectSenderReportPacketWithDlrr) {
    313   TestRtcpPacketBuilder p;
    314   p.AddSr(kSenderSsrc, 0);
    315   p.AddXrHeader(kSenderSsrc);
    316   p.AddXrUnknownBlock();
    317   p.AddXrExtendedDlrrBlock(kSenderSsrc);
    318   p.AddXrUnknownBlock();
    319   p.AddSdesCname(kSenderSsrc, kCName);
    320 
    321   // Expected to be ignored since the source ssrc does not match our
    322   // local ssrc.
    323   InjectRtcpPacket(p.Packet(), p.Length());
    324 
    325   EXPECT_CALL(mock_receiver_feedback_,
    326               OnReceivedSenderReport(expected_sender_info_)).Times(1);
    327   EXPECT_CALL(mock_rtt_feedback_,
    328       OnReceivedDelaySinceLastReport(kSenderSsrc,
    329           kLastSr,
    330           kDelayLastSr)).Times(1);
    331 
    332   // Enable receiving sender report.
    333   rtcp_receiver_->SetRemoteSSRC(kSenderSsrc);
    334 
    335   // Expected to be pass through since the sender ssrc match our local ssrc.
    336   InjectRtcpPacket(p.Packet(), p.Length());
    337 }
    338 
    339 TEST_F(RtcpReceiverTest, InjectReceiverReportPacketWithRrtr) {
    340   TestRtcpPacketBuilder p1;
    341   p1.AddRr(kSenderSsrc, 1);
    342   p1.AddRb(kUnknownSsrc);
    343   p1.AddXrHeader(kSenderSsrc);
    344   p1.AddXrRrtrBlock();
    345 
    346   // Expected to be ignored since the source ssrc does not match our
    347   // local ssrc.
    348   InjectRtcpPacket(p1.Packet(), p1.Length());
    349 
    350   EXPECT_CALL(mock_rtt_feedback_,
    351       OnReceivedDelaySinceLastReport(kSourceSsrc,
    352           kLastSr,
    353           kDelayLastSr)).Times(1);
    354   EXPECT_CALL(mock_receiver_feedback_, OnReceiverReferenceTimeReport(
    355       expected_receiver_reference_report_)).Times(1);
    356 
    357   // Enable receiving reference time report.
    358   rtcp_receiver_->SetRemoteSSRC(kSenderSsrc);
    359 
    360   TestRtcpPacketBuilder p2;
    361   p2.AddRr(kSenderSsrc, 1);
    362   p2.AddRb(kSourceSsrc);
    363   p2.AddXrHeader(kSenderSsrc);
    364   p2.AddXrRrtrBlock();
    365 
    366   // Expected to be pass through since the sender ssrc match our local ssrc.
    367   InjectRtcpPacket(p2.Packet(), p2.Length());
    368 }
    369 
    370 TEST_F(RtcpReceiverTest, InjectReceiverReportPacketWithIntraFrameRequest) {
    371   TestRtcpPacketBuilder p1;
    372   p1.AddRr(kSenderSsrc, 1);
    373   p1.AddRb(kUnknownSsrc);
    374   p1.AddPli(kSenderSsrc, kUnknownSsrc);
    375 
    376   // Expected to be ignored since the source ssrc does not match our
    377   // local ssrc.
    378   InjectRtcpPacket(p1.Packet(), p1.Length());
    379 
    380   EXPECT_CALL(mock_rtt_feedback_,
    381       OnReceivedDelaySinceLastReport(kSourceSsrc,
    382           kLastSr,
    383           kDelayLastSr)).Times(1);
    384 
    385   TestRtcpPacketBuilder p2;
    386   p2.AddRr(kSenderSsrc, 1);
    387   p2.AddRb(kSourceSsrc);
    388   p2.AddPli(kSenderSsrc, kSourceSsrc);
    389 
    390   // Expected to be pass through since the sender ssrc match our local ssrc.
    391   InjectRtcpPacket(p2.Packet(), p2.Length());
    392 }
    393 
    394 TEST_F(RtcpReceiverTest, InjectReceiverReportPacketWithCastFeedback) {
    395   TestRtcpPacketBuilder p1;
    396   p1.AddRr(kSenderSsrc, 1);
    397   p1.AddRb(kUnknownSsrc);
    398   p1.AddCast(kSenderSsrc, kUnknownSsrc);
    399 
    400   // Expected to be ignored since the source ssrc does not match our
    401   // local ssrc.
    402   InjectRtcpPacket(p1.Packet(), p1.Length());
    403 
    404   EXPECT_CALL(mock_rtt_feedback_,
    405       OnReceivedDelaySinceLastReport(kSourceSsrc,
    406           kLastSr,
    407           kDelayLastSr)).Times(1);
    408   EXPECT_CALL(mock_sender_feedback_, OnReceivedCastFeedback(_)).Times(1);
    409 
    410   // Enable receiving the cast feedback.
    411   rtcp_receiver_->SetRemoteSSRC(kSenderSsrc);
    412 
    413   TestRtcpPacketBuilder p2;
    414   p2.AddRr(kSenderSsrc, 1);
    415   p2.AddRb(kSourceSsrc);
    416   p2.AddCast(kSenderSsrc, kSourceSsrc);
    417 
    418   // Expected to be pass through since the sender ssrc match our local ssrc.
    419   InjectRtcpPacket(p2.Packet(), p2.Length());
    420 }
    421 
    422 TEST_F(RtcpReceiverTest, InjectReceiverReportPacketWithCastVerification) {
    423   SenderFeedbackCastVerification sender_feedback_cast_verification;
    424   RtcpReceiver rtcp_receiver(cast_environment_,
    425                              &sender_feedback_cast_verification,
    426                              &mock_receiver_feedback_,
    427                              &mock_rtt_feedback_,
    428                              kSourceSsrc);
    429 
    430   EXPECT_CALL(mock_rtt_feedback_,
    431       OnReceivedDelaySinceLastReport(kSourceSsrc,
    432           kLastSr,
    433           kDelayLastSr)).Times(1);
    434 
    435   // Enable receiving the cast feedback.
    436   rtcp_receiver.SetRemoteSSRC(kSenderSsrc);
    437 
    438   TestRtcpPacketBuilder p;
    439   p.AddRr(kSenderSsrc, 1);
    440   p.AddRb(kSourceSsrc);
    441   p.AddCast(kSenderSsrc, kSourceSsrc);
    442 
    443   // Expected to be pass through since the sender ssrc match our local ssrc.
    444   RtcpParser rtcp_parser(p.Packet(), p.Length());
    445   rtcp_receiver.IncomingRtcpPacket(&rtcp_parser);
    446 
    447   EXPECT_TRUE(sender_feedback_cast_verification.called());
    448 }
    449 
    450 TEST_F(RtcpReceiverTest, InjectSenderReportWithCastSenderLogVerification) {
    451   RtcpReceiverCastLogVerification cast_log_verification;
    452   RtcpReceiver rtcp_receiver(cast_environment_,
    453                              &mock_sender_feedback_,
    454                              &cast_log_verification,
    455                              &mock_rtt_feedback_,
    456                              kSourceSsrc);
    457   rtcp_receiver.SetRemoteSSRC(kSenderSsrc);
    458 
    459   RtcpSenderLogMessage sender_log;
    460   for (int j = 0; j < 359; ++j) {
    461     RtcpSenderFrameLogMessage sender_frame_log;
    462     sender_frame_log.frame_status = kRtcpSenderFrameStatusSentToNetwork;
    463     sender_frame_log.rtp_timestamp = kRtpTimestamp + j * 90;
    464     sender_log.push_back(sender_frame_log);
    465   }
    466   cast_log_verification.SetExpectedSenderLog(sender_log);
    467 
    468   TestRtcpPacketBuilder p;
    469   p.AddSr(kSenderSsrc, 0);
    470   p.AddSdesCname(kSenderSsrc, kCName);
    471   p.AddSenderLog(kSenderSsrc);
    472 
    473   for (int i = 0; i < 359; ++i) {
    474     p.AddSenderFrameLog(kRtcpSenderFrameStatusSentToNetwork,
    475                         kRtpTimestamp + i * 90);
    476   }
    477   RtcpParser rtcp_parser(p.Packet(), p.Length());
    478   rtcp_receiver.IncomingRtcpPacket(&rtcp_parser);
    479 
    480   EXPECT_TRUE(cast_log_verification.OnReceivedSenderLogCalled());
    481 }
    482 
    483 TEST_F(RtcpReceiverTest, InjectReceiverReportWithReceiverLogVerificationBase) {
    484   static const uint32 kTimeBaseMs = 12345678;
    485   static const uint32 kTimeDelayMs = 10;
    486   static const uint32 kDelayDeltaMs = 123;
    487   base::SimpleTestTickClock testing_clock;
    488   testing_clock.Advance(base::TimeDelta::FromMilliseconds(kTimeBaseMs));
    489 
    490   RtcpReceiverCastLogVerification cast_log_verification;
    491   RtcpReceiver rtcp_receiver(cast_environment_,
    492                              &mock_sender_feedback_,
    493                              &cast_log_verification,
    494                              &mock_rtt_feedback_,
    495                              kSourceSsrc);
    496   rtcp_receiver.SetRemoteSSRC(kSenderSsrc);
    497 
    498   RtcpReceiverLogMessage receiver_log;
    499   RtcpReceiverFrameLogMessage frame_log(kRtpTimestamp);
    500   RtcpReceiverEventLogMessage event_log;
    501 
    502   event_log.type = kAckSent;
    503   event_log.event_timestamp = testing_clock.NowTicks();
    504   event_log.delay_delta = base::TimeDelta::FromMilliseconds(kDelayDeltaMs);
    505   frame_log.event_log_messages_.push_back(event_log);
    506 
    507   testing_clock.Advance(base::TimeDelta::FromMilliseconds(kTimeDelayMs));
    508   event_log.type = kPacketReceived;
    509   event_log.event_timestamp = testing_clock.NowTicks();
    510   event_log.packet_id = kLostPacketId1;
    511   frame_log.event_log_messages_.push_back(event_log);
    512   receiver_log.push_back(frame_log);
    513 
    514   cast_log_verification.SetExpectedReceiverLog(receiver_log);
    515 
    516   TestRtcpPacketBuilder p;
    517   p.AddRr(kSenderSsrc, 1);
    518   p.AddRb(kSourceSsrc);
    519   p.AddReceiverLog(kSenderSsrc);
    520   p.AddReceiverFrameLog(kRtpTimestamp, 2, kTimeBaseMs);
    521   p.AddReceiverEventLog(kDelayDeltaMs, 1, 0);
    522   p.AddReceiverEventLog(kLostPacketId1, 6, kTimeDelayMs);
    523 
    524   EXPECT_CALL(mock_rtt_feedback_,
    525       OnReceivedDelaySinceLastReport(kSourceSsrc, kLastSr, kDelayLastSr)).
    526           Times(1);
    527 
    528   RtcpParser rtcp_parser(p.Packet(), p.Length());
    529   rtcp_receiver.IncomingRtcpPacket(&rtcp_parser);
    530 
    531   EXPECT_TRUE(cast_log_verification.OnReceivedReceiverLogCalled());
    532 }
    533 
    534 TEST_F(RtcpReceiverTest, InjectReceiverReportWithReceiverLogVerificationMulti) {
    535   static const uint32 kTimeBaseMs = 12345678;
    536   static const uint32 kTimeDelayMs = 10;
    537   static const uint32 kDelayDeltaMs = 123;
    538   base::SimpleTestTickClock testing_clock;
    539   testing_clock.Advance(base::TimeDelta::FromMilliseconds(kTimeBaseMs));
    540 
    541   RtcpReceiverCastLogVerification cast_log_verification;
    542   RtcpReceiver rtcp_receiver(cast_environment_,
    543                              &mock_sender_feedback_,
    544                              &cast_log_verification,
    545                              &mock_rtt_feedback_,
    546                              kSourceSsrc);
    547   rtcp_receiver.SetRemoteSSRC(kSenderSsrc);
    548 
    549   RtcpReceiverLogMessage receiver_log;
    550 
    551   for (int j = 0; j < 100; ++j) {
    552     RtcpReceiverFrameLogMessage frame_log(kRtpTimestamp);
    553     RtcpReceiverEventLogMessage event_log;
    554     event_log.type = kAckSent;
    555     event_log.event_timestamp = testing_clock.NowTicks();
    556     event_log.delay_delta = base::TimeDelta::FromMilliseconds(kDelayDeltaMs);
    557     frame_log.event_log_messages_.push_back(event_log);
    558     receiver_log.push_back(frame_log);
    559     testing_clock.Advance(base::TimeDelta::FromMilliseconds(kTimeDelayMs));
    560   }
    561 
    562   cast_log_verification.SetExpectedReceiverLog(receiver_log);
    563 
    564   TestRtcpPacketBuilder p;
    565   p.AddRr(kSenderSsrc, 1);
    566   p.AddRb(kSourceSsrc);
    567   p.AddReceiverLog(kSenderSsrc);
    568   for (int i = 0; i < 100; ++i) {
    569     p.AddReceiverFrameLog(kRtpTimestamp, 1, kTimeBaseMs +  i * kTimeDelayMs);
    570     p.AddReceiverEventLog(kDelayDeltaMs, 1, 0);
    571   }
    572 
    573   EXPECT_CALL(mock_rtt_feedback_,
    574       OnReceivedDelaySinceLastReport(kSourceSsrc, kLastSr, kDelayLastSr)).
    575           Times(1);
    576 
    577   RtcpParser rtcp_parser(p.Packet(), p.Length());
    578   rtcp_receiver.IncomingRtcpPacket(&rtcp_parser);
    579 
    580   EXPECT_TRUE(cast_log_verification.OnReceivedReceiverLogCalled());
    581 }
    582 
    583 
    584 
    585 }  // namespace cast
    586 }  // namespace media
    587