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_defines.h"
      8 #include "media/cast/cast_environment.h"
      9 #include "media/cast/net/pacing/paced_sender.h"
     10 #include "media/cast/rtcp/rtcp_sender.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 namespace {
     20 static const uint32 kSendingSsrc = 0x12345678;
     21 static const uint32 kMediaSsrc = 0x87654321;
     22 static const std::string kCName("test (at) 10.1.1.1");
     23 }  // namespace
     24 
     25 class TestRtcpTransport : public PacedPacketSender {
     26  public:
     27   TestRtcpTransport()
     28       : expected_packet_length_(0),
     29         packet_count_(0) {
     30   }
     31 
     32   virtual bool SendRtcpPacket(const Packet& packet) OVERRIDE {
     33     EXPECT_EQ(expected_packet_length_, packet.size());
     34     EXPECT_EQ(0, memcmp(expected_packet_, &(packet[0]), packet.size()));
     35     packet_count_++;
     36     return true;
     37   }
     38 
     39   virtual bool SendPackets(const PacketList& packets) OVERRIDE {
     40     return false;
     41   }
     42 
     43   virtual bool ResendPackets(const PacketList& packets) OVERRIDE {
     44     return false;
     45   }
     46 
     47   void SetExpectedRtcpPacket(const uint8* rtcp_buffer, size_t length) {
     48     expected_packet_length_ = length;
     49     memcpy(expected_packet_, rtcp_buffer, length);
     50   }
     51 
     52   int packet_count() const { return packet_count_; }
     53 
     54  private:
     55   uint8 expected_packet_[kIpPacketSize];
     56   size_t expected_packet_length_;
     57   int packet_count_;
     58 };
     59 
     60 class RtcpSenderTest : public ::testing::Test {
     61  protected:
     62   RtcpSenderTest()
     63       : task_runner_(new test::FakeTaskRunner(&testing_clock_)),
     64         cast_environment_(new CastEnvironment(&testing_clock_, task_runner_,
     65             task_runner_, task_runner_, task_runner_, task_runner_,
     66             GetDefaultCastLoggingConfig())),
     67         rtcp_sender_(new RtcpSender(cast_environment_,
     68                                     &test_transport_,
     69                                     kSendingSsrc,
     70                                     kCName)) {
     71   }
     72 
     73   base::SimpleTestTickClock testing_clock_;
     74   TestRtcpTransport test_transport_;
     75   scoped_refptr<test::FakeTaskRunner> task_runner_;
     76   scoped_refptr<CastEnvironment> cast_environment_;
     77   scoped_ptr<RtcpSender> rtcp_sender_;
     78 };
     79 
     80 TEST_F(RtcpSenderTest, RtcpSenderReport) {
     81   RtcpSenderInfo sender_info;
     82   sender_info.ntp_seconds = kNtpHigh;
     83   sender_info.ntp_fraction = kNtpLow;
     84   sender_info.rtp_timestamp = kRtpTimestamp;
     85   sender_info.send_packet_count = kSendPacketCount;
     86   sender_info.send_octet_count = kSendOctetCount;
     87 
     88   // Sender report + c_name.
     89   TestRtcpPacketBuilder p;
     90   p.AddSr(kSendingSsrc, 0);
     91   p.AddSdesCname(kSendingSsrc, kCName);
     92   test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length());
     93 
     94   rtcp_sender_->SendRtcpFromRtpSender(RtcpSender::kRtcpSr,
     95                                       &sender_info,
     96                                       NULL,
     97                                       NULL);
     98 
     99   EXPECT_EQ(1, test_transport_.packet_count());
    100 }
    101 
    102 TEST_F(RtcpSenderTest, RtcpReceiverReport) {
    103   // Empty receiver report + c_name.
    104   TestRtcpPacketBuilder p1;
    105   p1.AddRr(kSendingSsrc, 0);
    106   p1.AddSdesCname(kSendingSsrc, kCName);
    107   test_transport_.SetExpectedRtcpPacket(p1.Packet(), p1.Length());
    108 
    109   rtcp_sender_->SendRtcpFromRtpReceiver(RtcpSender::kRtcpRr,
    110       NULL, NULL, NULL, NULL);
    111 
    112   EXPECT_EQ(1, test_transport_.packet_count());
    113 
    114   // Receiver report with report block + c_name.
    115   TestRtcpPacketBuilder p2;
    116   p2.AddRr(kSendingSsrc, 1);
    117   p2.AddRb(kMediaSsrc);
    118   p2.AddSdesCname(kSendingSsrc, kCName);
    119   test_transport_.SetExpectedRtcpPacket(p2.Packet(), p2.Length());
    120 
    121   RtcpReportBlock report_block;
    122   // Initialize remote_ssrc to a "clearly illegal" value.
    123   report_block.remote_ssrc = 0xDEAD;
    124   report_block.media_ssrc = kMediaSsrc;  // SSRC of the RTP packet sender.
    125   report_block.fraction_lost = kLoss >> 24;
    126   report_block.cumulative_lost = kLoss;  // 24 bits valid.
    127   report_block.extended_high_sequence_number = kExtendedMax;
    128   report_block.jitter = kTestJitter;
    129   report_block.last_sr = kLastSr;
    130   report_block.delay_since_last_sr = kDelayLastSr;
    131 
    132   rtcp_sender_->SendRtcpFromRtpReceiver(RtcpSender::kRtcpRr, &report_block,
    133                                         NULL, NULL, NULL);
    134 
    135   EXPECT_EQ(2, test_transport_.packet_count());
    136 }
    137 
    138 TEST_F(RtcpSenderTest, RtcpSenderReportWithDlrr) {
    139   RtcpSenderInfo sender_info;
    140   sender_info.ntp_seconds = kNtpHigh;
    141   sender_info.ntp_fraction = kNtpLow;
    142   sender_info.rtp_timestamp = kRtpTimestamp;
    143   sender_info.send_packet_count = kSendPacketCount;
    144   sender_info.send_octet_count = kSendOctetCount;
    145 
    146   // Sender report + c_name + dlrr.
    147   TestRtcpPacketBuilder p1;
    148   p1.AddSr(kSendingSsrc, 0);
    149   p1.AddSdesCname(kSendingSsrc, kCName);
    150   p1.AddXrHeader(kSendingSsrc);
    151   p1.AddXrDlrrBlock(kSendingSsrc);
    152   test_transport_.SetExpectedRtcpPacket(p1.Packet(), p1.Length());
    153 
    154   RtcpDlrrReportBlock dlrr_rb;
    155   dlrr_rb.last_rr = kLastRr;
    156   dlrr_rb.delay_since_last_rr = kDelayLastRr;
    157 
    158   rtcp_sender_->SendRtcpFromRtpSender(
    159       RtcpSender::kRtcpSr | RtcpSender::kRtcpDlrr,
    160       &sender_info,
    161       &dlrr_rb,
    162       NULL);
    163 
    164   EXPECT_EQ(1, test_transport_.packet_count());
    165 }
    166 
    167 TEST_F(RtcpSenderTest, RtcpSenderReportWithDlrrAndLog) {
    168   RtcpSenderInfo sender_info;
    169   sender_info.ntp_seconds = kNtpHigh;
    170   sender_info.ntp_fraction = kNtpLow;
    171   sender_info.rtp_timestamp = kRtpTimestamp;
    172   sender_info.send_packet_count = kSendPacketCount;
    173   sender_info.send_octet_count = kSendOctetCount;
    174 
    175   // Sender report + c_name + dlrr + sender log.
    176   TestRtcpPacketBuilder p;
    177   p.AddSr(kSendingSsrc, 0);
    178   p.AddSdesCname(kSendingSsrc, kCName);
    179   p.AddXrHeader(kSendingSsrc);
    180   p.AddXrDlrrBlock(kSendingSsrc);
    181   p.AddSenderLog(kSendingSsrc);
    182   p.AddSenderFrameLog(kRtcpSenderFrameStatusSentToNetwork, kRtpTimestamp);
    183 
    184   test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length());
    185 
    186   RtcpDlrrReportBlock dlrr_rb;
    187   dlrr_rb.last_rr = kLastRr;
    188   dlrr_rb.delay_since_last_rr = kDelayLastRr;
    189 
    190   RtcpSenderFrameLogMessage sender_frame_log;
    191   sender_frame_log.frame_status = kRtcpSenderFrameStatusSentToNetwork;
    192   sender_frame_log.rtp_timestamp = kRtpTimestamp;
    193 
    194   RtcpSenderLogMessage sender_log;
    195   sender_log.push_back(sender_frame_log);
    196 
    197   rtcp_sender_->SendRtcpFromRtpSender(
    198       RtcpSender::kRtcpSr | RtcpSender::kRtcpDlrr | RtcpSender::kRtcpSenderLog,
    199       &sender_info,
    200       &dlrr_rb,
    201       &sender_log);
    202 
    203   EXPECT_EQ(1, test_transport_.packet_count());
    204   EXPECT_TRUE(sender_log.empty());
    205 }
    206 
    207 TEST_F(RtcpSenderTest, RtcpSenderReporWithTooManyLogFrames) {
    208   RtcpSenderInfo sender_info;
    209   sender_info.ntp_seconds = kNtpHigh;
    210   sender_info.ntp_fraction = kNtpLow;
    211   sender_info.rtp_timestamp = kRtpTimestamp;
    212   sender_info.send_packet_count = kSendPacketCount;
    213   sender_info.send_octet_count = kSendOctetCount;
    214 
    215   // Sender report + c_name + sender log.
    216   TestRtcpPacketBuilder p;
    217   p.AddSr(kSendingSsrc, 0);
    218   p.AddSdesCname(kSendingSsrc, kCName);
    219   p.AddSenderLog(kSendingSsrc);
    220 
    221   for (int i = 0; i < 359; ++i) {
    222     p.AddSenderFrameLog(kRtcpSenderFrameStatusSentToNetwork,
    223                         kRtpTimestamp + i * 90);
    224   }
    225   test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length());
    226 
    227 
    228   RtcpSenderLogMessage sender_log;
    229   for (int j = 0; j < 400; ++j) {
    230     RtcpSenderFrameLogMessage sender_frame_log;
    231     sender_frame_log.frame_status = kRtcpSenderFrameStatusSentToNetwork;
    232     sender_frame_log.rtp_timestamp = kRtpTimestamp + j * 90;
    233     sender_log.push_back(sender_frame_log);
    234   }
    235 
    236   rtcp_sender_->SendRtcpFromRtpSender(
    237       RtcpSender::kRtcpSr | RtcpSender::kRtcpSenderLog,
    238       &sender_info,
    239       NULL,
    240       &sender_log);
    241 
    242   EXPECT_EQ(1, test_transport_.packet_count());
    243   EXPECT_EQ(41u, sender_log.size());
    244 }
    245 
    246 TEST_F(RtcpSenderTest, RtcpReceiverReportWithRrtr) {
    247   // Receiver report with report block + c_name.
    248   TestRtcpPacketBuilder p;
    249   p.AddRr(kSendingSsrc, 1);
    250   p.AddRb(kMediaSsrc);
    251   p.AddSdesCname(kSendingSsrc, kCName);
    252   p.AddXrHeader(kSendingSsrc);
    253   p.AddXrRrtrBlock();
    254   test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length());
    255 
    256   RtcpReportBlock report_block;
    257   // Initialize remote_ssrc to a "clearly illegal" value.
    258   report_block.remote_ssrc = 0xDEAD;
    259   report_block.media_ssrc = kMediaSsrc;  // SSRC of the RTP packet sender.
    260   report_block.fraction_lost = kLoss >> 24;
    261   report_block.cumulative_lost = kLoss;  // 24 bits valid.
    262   report_block.extended_high_sequence_number = kExtendedMax;
    263   report_block.jitter = kTestJitter;
    264   report_block.last_sr = kLastSr;
    265   report_block.delay_since_last_sr = kDelayLastSr;
    266 
    267   RtcpReceiverReferenceTimeReport rrtr;
    268   rrtr.ntp_seconds = kNtpHigh;
    269   rrtr.ntp_fraction = kNtpLow;
    270 
    271   rtcp_sender_->SendRtcpFromRtpReceiver(
    272       RtcpSender::kRtcpRr | RtcpSender::kRtcpRrtr,
    273       &report_block,
    274       &rrtr,
    275       NULL,
    276       NULL);
    277 
    278   EXPECT_EQ(1, test_transport_.packet_count());
    279 }
    280 
    281 TEST_F(RtcpSenderTest, RtcpReceiverReportWithCast) {
    282   // Receiver report with report block + c_name.
    283   TestRtcpPacketBuilder p;
    284   p.AddRr(kSendingSsrc, 1);
    285   p.AddRb(kMediaSsrc);
    286   p.AddSdesCname(kSendingSsrc, kCName);
    287   p.AddCast(kSendingSsrc, kMediaSsrc);
    288   test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length());
    289 
    290   RtcpReportBlock report_block;
    291   // Initialize remote_ssrc to a "clearly illegal" value.
    292   report_block.remote_ssrc = 0xDEAD;
    293   report_block.media_ssrc = kMediaSsrc;  // SSRC of the RTP packet sender.
    294   report_block.fraction_lost = kLoss >> 24;
    295   report_block.cumulative_lost = kLoss;  // 24 bits valid.
    296   report_block.extended_high_sequence_number = kExtendedMax;
    297   report_block.jitter = kTestJitter;
    298   report_block.last_sr = kLastSr;
    299   report_block.delay_since_last_sr = kDelayLastSr;
    300 
    301   RtcpCastMessage cast_message(kMediaSsrc);
    302   cast_message.ack_frame_id_ = kAckFrameId;
    303   PacketIdSet missing_packets;
    304   cast_message.missing_frames_and_packets_[kLostFrameId] = missing_packets;
    305 
    306   missing_packets.insert(kLostPacketId1);
    307   missing_packets.insert(kLostPacketId2);
    308   missing_packets.insert(kLostPacketId3);
    309   cast_message.missing_frames_and_packets_[kFrameIdWithLostPackets] =
    310       missing_packets;
    311 
    312   rtcp_sender_->SendRtcpFromRtpReceiver(
    313       RtcpSender::kRtcpRr | RtcpSender::kRtcpCast,
    314       &report_block,
    315       NULL,
    316       &cast_message,
    317       NULL);
    318 
    319   EXPECT_EQ(1, test_transport_.packet_count());
    320 }
    321 
    322 TEST_F(RtcpSenderTest, RtcpReceiverReportWithRrtraAndCastMessage) {
    323   TestRtcpPacketBuilder p;
    324   p.AddRr(kSendingSsrc, 1);
    325   p.AddRb(kMediaSsrc);
    326   p.AddSdesCname(kSendingSsrc, kCName);
    327   p.AddXrHeader(kSendingSsrc);
    328   p.AddXrRrtrBlock();
    329   p.AddCast(kSendingSsrc, kMediaSsrc);
    330   test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length());
    331 
    332   RtcpReportBlock report_block;
    333   // Initialize remote_ssrc to a "clearly illegal" value.
    334   report_block.remote_ssrc = 0xDEAD;
    335   report_block.media_ssrc = kMediaSsrc;  // SSRC of the RTP packet sender.
    336   report_block.fraction_lost = kLoss >> 24;
    337   report_block.cumulative_lost = kLoss;  // 24 bits valid.
    338   report_block.extended_high_sequence_number = kExtendedMax;
    339   report_block.jitter = kTestJitter;
    340   report_block.last_sr = kLastSr;
    341   report_block.delay_since_last_sr = kDelayLastSr;
    342 
    343   RtcpReceiverReferenceTimeReport rrtr;
    344   rrtr.ntp_seconds = kNtpHigh;
    345   rrtr.ntp_fraction = kNtpLow;
    346 
    347   RtcpCastMessage cast_message(kMediaSsrc);
    348   cast_message.ack_frame_id_ = kAckFrameId;
    349   PacketIdSet missing_packets;
    350   cast_message.missing_frames_and_packets_[kLostFrameId] = missing_packets;
    351 
    352   missing_packets.insert(kLostPacketId1);
    353   missing_packets.insert(kLostPacketId2);
    354   missing_packets.insert(kLostPacketId3);
    355   cast_message.missing_frames_and_packets_[kFrameIdWithLostPackets] =
    356       missing_packets;
    357 
    358   rtcp_sender_->SendRtcpFromRtpReceiver(
    359       RtcpSender::kRtcpRr | RtcpSender::kRtcpRrtr | RtcpSender::kRtcpCast,
    360       &report_block,
    361       &rrtr,
    362       &cast_message,
    363       NULL);
    364 
    365   EXPECT_EQ(1, test_transport_.packet_count());
    366 }
    367 
    368 TEST_F(RtcpSenderTest, RtcpReceiverReportWithRrtrCastMessageAndLog) {
    369   static const uint32 kTimeBaseMs = 12345678;
    370   static const uint32 kTimeDelayMs = 10;
    371   static const uint32 kDelayDeltaMs = 123;
    372 
    373   TestRtcpPacketBuilder p;
    374   p.AddRr(kSendingSsrc, 1);
    375   p.AddRb(kMediaSsrc);
    376   p.AddSdesCname(kSendingSsrc, kCName);
    377   p.AddXrHeader(kSendingSsrc);
    378   p.AddXrRrtrBlock();
    379   p.AddCast(kSendingSsrc, kMediaSsrc);
    380   test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length());
    381 
    382   RtcpReportBlock report_block;
    383   // Initialize remote_ssrc to a "clearly illegal" value.
    384   report_block.remote_ssrc = 0xDEAD;
    385   report_block.media_ssrc = kMediaSsrc;  // SSRC of the RTP packet sender.
    386   report_block.fraction_lost = kLoss >> 24;
    387   report_block.cumulative_lost = kLoss;  // 24 bits valid.
    388   report_block.extended_high_sequence_number = kExtendedMax;
    389   report_block.jitter = kTestJitter;
    390   report_block.last_sr = kLastSr;
    391   report_block.delay_since_last_sr = kDelayLastSr;
    392 
    393   RtcpReceiverReferenceTimeReport rrtr;
    394   rrtr.ntp_seconds = kNtpHigh;
    395   rrtr.ntp_fraction = kNtpLow;
    396 
    397   RtcpCastMessage cast_message(kMediaSsrc);
    398   cast_message.ack_frame_id_ = kAckFrameId;
    399   PacketIdSet missing_packets;
    400   cast_message.missing_frames_and_packets_[kLostFrameId] = missing_packets;
    401 
    402   missing_packets.insert(kLostPacketId1);
    403   missing_packets.insert(kLostPacketId2);
    404   missing_packets.insert(kLostPacketId3);
    405   cast_message.missing_frames_and_packets_[kFrameIdWithLostPackets] =
    406       missing_packets;
    407 
    408   // Test empty Log message.
    409   RtcpReceiverLogMessage receiver_log;
    410 
    411   VLOG(0) << " Test empty Log  " ;
    412   rtcp_sender_->SendRtcpFromRtpReceiver(
    413       RtcpSender::kRtcpRr | RtcpSender::kRtcpRrtr | RtcpSender::kRtcpCast |
    414       RtcpSender::kRtcpReceiverLog,
    415       &report_block,
    416       &rrtr,
    417       &cast_message,
    418       &receiver_log);
    419 
    420 
    421   base::SimpleTestTickClock testing_clock;
    422   testing_clock.Advance(base::TimeDelta::FromMilliseconds(kTimeBaseMs));
    423 
    424   p.AddReceiverLog(kSendingSsrc);
    425   p.AddReceiverFrameLog(kRtpTimestamp, 2, kTimeBaseMs);
    426   p.AddReceiverEventLog(kDelayDeltaMs, 1, 0);
    427   p.AddReceiverEventLog(kLostPacketId1, 6, kTimeDelayMs);
    428 
    429   test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length());
    430 
    431   RtcpReceiverFrameLogMessage frame_log(kRtpTimestamp);
    432   RtcpReceiverEventLogMessage event_log;
    433 
    434   event_log.type = kAckSent;
    435   event_log.event_timestamp = testing_clock.NowTicks();
    436   event_log.delay_delta = base::TimeDelta::FromMilliseconds(kDelayDeltaMs);
    437   frame_log.event_log_messages_.push_back(event_log);
    438 
    439   testing_clock.Advance(base::TimeDelta::FromMilliseconds(kTimeDelayMs));
    440   event_log.type = kPacketReceived;
    441   event_log.event_timestamp = testing_clock.NowTicks();
    442   event_log.packet_id = kLostPacketId1;
    443   frame_log.event_log_messages_.push_back(event_log);
    444 
    445   receiver_log.push_back(frame_log);
    446 
    447   VLOG(0) << " Test  Log  " ;
    448   rtcp_sender_->SendRtcpFromRtpReceiver(
    449       RtcpSender::kRtcpRr | RtcpSender::kRtcpRrtr | RtcpSender::kRtcpCast |
    450       RtcpSender::kRtcpReceiverLog,
    451       &report_block,
    452       &rrtr,
    453       &cast_message,
    454       &receiver_log);
    455 
    456   EXPECT_TRUE(receiver_log.empty());
    457   EXPECT_EQ(2, test_transport_.packet_count());
    458 }
    459 
    460 TEST_F(RtcpSenderTest, RtcpReceiverReportWithOversizedFrameLog) {
    461   static const uint32 kTimeBaseMs = 12345678;
    462   static const uint32 kTimeDelayMs = 10;
    463   static const uint32 kDelayDeltaMs = 123;
    464 
    465   TestRtcpPacketBuilder p;
    466   p.AddRr(kSendingSsrc, 1);
    467   p.AddRb(kMediaSsrc);
    468   p.AddSdesCname(kSendingSsrc, kCName);
    469 
    470   RtcpReportBlock report_block;
    471   // Initialize remote_ssrc to a "clearly illegal" value.
    472   report_block.remote_ssrc = 0xDEAD;
    473   report_block.media_ssrc = kMediaSsrc;  // SSRC of the RTP packet sender.
    474   report_block.fraction_lost = kLoss >> 24;
    475   report_block.cumulative_lost = kLoss;  // 24 bits valid.
    476   report_block.extended_high_sequence_number = kExtendedMax;
    477   report_block.jitter = kTestJitter;
    478   report_block.last_sr = kLastSr;
    479   report_block.delay_since_last_sr = kDelayLastSr;
    480 
    481   base::SimpleTestTickClock testing_clock;
    482   testing_clock.Advance(base::TimeDelta::FromMilliseconds(kTimeBaseMs));
    483 
    484   p.AddReceiverLog(kSendingSsrc);
    485 
    486   p.AddReceiverFrameLog(kRtpTimestamp, 1, kTimeBaseMs);
    487   p.AddReceiverEventLog(kDelayDeltaMs, 1, 0);
    488   p.AddReceiverFrameLog(kRtpTimestamp + 2345,
    489       kRtcpMaxReceiverLogMessages, kTimeBaseMs);
    490 
    491   for (size_t i = 0; i < kRtcpMaxReceiverLogMessages; ++i) {
    492     p.AddReceiverEventLog(
    493         kLostPacketId1, 6, static_cast<uint16>(kTimeDelayMs * i));
    494   }
    495 
    496   test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length());
    497 
    498   RtcpReceiverFrameLogMessage frame_1_log(kRtpTimestamp);
    499   RtcpReceiverEventLogMessage event_log;
    500 
    501   event_log.type = kAckSent;
    502   event_log.event_timestamp = testing_clock.NowTicks();
    503   event_log.delay_delta = base::TimeDelta::FromMilliseconds(kDelayDeltaMs);
    504   frame_1_log.event_log_messages_.push_back(event_log);
    505 
    506   RtcpReceiverLogMessage receiver_log;
    507   receiver_log.push_back(frame_1_log);
    508 
    509   RtcpReceiverFrameLogMessage frame_2_log(kRtpTimestamp + 2345);
    510 
    511   for (int j = 0; j < 300; ++j) {
    512     event_log.type = kPacketReceived;
    513     event_log.event_timestamp = testing_clock.NowTicks();
    514     event_log.packet_id = kLostPacketId1;
    515     frame_2_log.event_log_messages_.push_back(event_log);
    516     testing_clock.Advance(base::TimeDelta::FromMilliseconds(kTimeDelayMs));
    517   }
    518   receiver_log.push_back(frame_2_log);
    519 
    520   rtcp_sender_->SendRtcpFromRtpReceiver(
    521       RtcpSender::kRtcpRr | RtcpSender::kRtcpReceiverLog,
    522       &report_block,
    523       NULL,
    524       NULL,
    525       &receiver_log);
    526 
    527   EXPECT_EQ(1, test_transport_.packet_count());
    528   EXPECT_EQ(1u, receiver_log.size());
    529   EXPECT_EQ(300u - kRtcpMaxReceiverLogMessages,
    530             receiver_log.front().event_log_messages_.size());
    531 }
    532 
    533 TEST_F(RtcpSenderTest, RtcpReceiverReportWithTooManyLogFrames) {
    534   static const uint32 kTimeBaseMs = 12345678;
    535   static const uint32 kTimeDelayMs = 10;
    536   static const uint32 kDelayDeltaMs = 123;
    537 
    538   TestRtcpPacketBuilder p;
    539   p.AddRr(kSendingSsrc, 1);
    540   p.AddRb(kMediaSsrc);
    541   p.AddSdesCname(kSendingSsrc, kCName);
    542 
    543   RtcpReportBlock report_block;
    544   // Initialize remote_ssrc to a "clearly illegal" value.
    545   report_block.remote_ssrc = 0xDEAD;
    546   report_block.media_ssrc = kMediaSsrc;  // SSRC of the RTP packet sender.
    547   report_block.fraction_lost = kLoss >> 24;
    548   report_block.cumulative_lost = kLoss;  // 24 bits valid.
    549   report_block.extended_high_sequence_number = kExtendedMax;
    550   report_block.jitter = kTestJitter;
    551   report_block.last_sr = kLastSr;
    552   report_block.delay_since_last_sr = kDelayLastSr;
    553 
    554   base::SimpleTestTickClock testing_clock;
    555   testing_clock.Advance(base::TimeDelta::FromMilliseconds(kTimeBaseMs));
    556 
    557   p.AddReceiverLog(kSendingSsrc);
    558 
    559   for (int i = 0; i < 119; ++i) {
    560     p.AddReceiverFrameLog(kRtpTimestamp, 1, kTimeBaseMs +  i * kTimeDelayMs);
    561     p.AddReceiverEventLog(kDelayDeltaMs, 1, 0);
    562   }
    563   test_transport_.SetExpectedRtcpPacket(p.Packet(), p.Length());
    564 
    565   RtcpReceiverLogMessage receiver_log;
    566 
    567   for (int j = 0; j < 200; ++j) {
    568     RtcpReceiverFrameLogMessage frame_log(kRtpTimestamp);
    569     RtcpReceiverEventLogMessage event_log;
    570 
    571     event_log.type = kAckSent;
    572     event_log.event_timestamp = testing_clock.NowTicks();
    573     event_log.delay_delta = base::TimeDelta::FromMilliseconds(kDelayDeltaMs);
    574     frame_log.event_log_messages_.push_back(event_log);
    575     receiver_log.push_back(frame_log);
    576     testing_clock.Advance(base::TimeDelta::FromMilliseconds(kTimeDelayMs));
    577   }
    578   rtcp_sender_->SendRtcpFromRtpReceiver(
    579       RtcpSender::kRtcpRr | RtcpSender::kRtcpReceiverLog,
    580       &report_block,
    581       NULL,
    582       NULL,
    583       &receiver_log);
    584 
    585   EXPECT_EQ(1, test_transport_.packet_count());
    586   EXPECT_EQ(81u, receiver_log.size());
    587 }
    588 
    589 }  // namespace cast
    590 }  // namespace media
    591