OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/big_endian.h" | 7 #include "base/big_endian.h" |
8 #include "base/test/simple_test_tick_clock.h" | 8 #include "base/test/simple_test_tick_clock.h" |
9 #include "media/cast/net/pacing/paced_sender.h" | 9 #include "media/cast/net/pacing/paced_sender.h" |
10 #include "media/cast/test/fake_single_thread_task_runner.h" | 10 #include "media/cast/test/fake_single_thread_task_runner.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 | 12 |
13 using testing::_; | 13 using testing::_; |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 namespace cast { | 16 namespace cast { |
17 namespace { | 17 namespace { |
18 | 18 |
19 static const uint8 kValue = 123; | 19 static const uint8 kValue = 123; |
20 static const size_t kSize1 = 101; | 20 static const size_t kSize1 = 101; |
21 static const size_t kSize2 = 102; | 21 static const size_t kSize2 = 102; |
22 static const size_t kSize3 = 103; | 22 static const size_t kSize3 = 103; |
23 static const size_t kSize4 = 104; | 23 static const size_t kSize4 = 104; |
24 static const size_t kNackSize = 105; | 24 static const size_t kNackSize = 105; |
25 static const int64 kStartMillisecond = INT64_C(12345678900000); | 25 static const int64 kStartMillisecond = INT64_C(12345678900000); |
26 static const uint32 kVideoSsrc = 0x1234; | 26 static const uint32 kVideoSsrc = 0x1234; |
27 static const uint32 kAudioSsrc = 0x5678; | 27 static const uint32 kAudioSsrc = 0x5678; |
28 static const uint32 kFrameRtpTimestamp = 12345; | 28 static const uint32_t kVideoFrameRtpTimestamp = 12345; |
| 29 static const uint32_t kAudioFrameRtpTimestamp = 23456; |
29 | 30 |
30 class TestPacketSender : public PacketSender { | 31 class TestPacketSender : public PacketSender { |
31 public: | 32 public: |
32 TestPacketSender() : bytes_sent_(0) {} | 33 TestPacketSender() : bytes_sent_(0) {} |
33 | 34 |
34 bool SendPacket(PacketRef packet, const base::Closure& cb) final { | 35 bool SendPacket(PacketRef packet, const base::Closure& cb) final { |
35 EXPECT_FALSE(expected_packet_size_.empty()); | 36 EXPECT_FALSE(expected_packet_size_.empty()); |
36 size_t expected_packet_size = expected_packet_size_.front(); | 37 size_t expected_packet_size = expected_packet_size_.front(); |
37 expected_packet_size_.pop_front(); | 38 expected_packet_size_.pop_front(); |
38 EXPECT_EQ(expected_packet_size, packet->data.size()); | 39 EXPECT_EQ(expected_packet_size, packet->data.size()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 audio ? kAudioSsrc : kVideoSsrc, // ssrc | 84 audio ? kAudioSsrc : kVideoSsrc, // ssrc |
84 i); | 85 i); |
85 | 86 |
86 PacketRef packet(new base::RefCountedData<Packet>); | 87 PacketRef packet(new base::RefCountedData<Packet>); |
87 packet->data.resize(packet_size, kValue); | 88 packet->data.resize(packet_size, kValue); |
88 // Fill-in packet header fields to test the header parsing (for populating | 89 // Fill-in packet header fields to test the header parsing (for populating |
89 // the logging events). | 90 // the logging events). |
90 base::BigEndianWriter writer(reinterpret_cast<char*>(&packet->data[0]), | 91 base::BigEndianWriter writer(reinterpret_cast<char*>(&packet->data[0]), |
91 packet_size); | 92 packet_size); |
92 bool success = writer.Skip(4); | 93 bool success = writer.Skip(4); |
93 success &= writer.WriteU32(kFrameRtpTimestamp); | 94 success &= writer.WriteU32(audio ? kAudioFrameRtpTimestamp |
| 95 : kVideoFrameRtpTimestamp); |
94 success &= writer.WriteU32(audio ? kAudioSsrc : kVideoSsrc); | 96 success &= writer.WriteU32(audio ? kAudioSsrc : kVideoSsrc); |
95 success &= writer.Skip(2); | 97 success &= writer.Skip(2); |
96 success &= writer.WriteU16(i); | 98 success &= writer.WriteU16(i); |
97 success &= writer.WriteU16(num_of_packets_in_frame - 1); | 99 success &= writer.WriteU16(num_of_packets_in_frame - 1); |
98 CHECK(success); | 100 CHECK(success); |
99 packets.push_back(std::make_pair(key, packet)); | 101 packets.push_back(std::make_pair(key, packet)); |
100 } | 102 } |
101 // Increase |frame_id_| so that we don't get the same key next time this | 103 // Increase |frame_id_| so that we don't get the same key next time this |
102 // function is called. | 104 // function is called. |
103 ++frame_id_; | 105 ++frame_id_; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 const base::TimeTicks latest_event_timestamp = testing_clock_.NowTicks(); | 178 const base::TimeTicks latest_event_timestamp = testing_clock_.NowTicks(); |
177 | 179 |
178 // Check that packet logging events match expected values. | 180 // Check that packet logging events match expected values. |
179 EXPECT_EQ(num_of_packets, static_cast<int>(packet_events_.size())); | 181 EXPECT_EQ(num_of_packets, static_cast<int>(packet_events_.size())); |
180 uint16 expected_packet_id = 0; | 182 uint16 expected_packet_id = 0; |
181 for (const PacketEvent& e : packet_events_) { | 183 for (const PacketEvent& e : packet_events_) { |
182 ASSERT_LE(earliest_event_timestamp, e.timestamp); | 184 ASSERT_LE(earliest_event_timestamp, e.timestamp); |
183 ASSERT_GE(latest_event_timestamp, e.timestamp); | 185 ASSERT_GE(latest_event_timestamp, e.timestamp); |
184 ASSERT_EQ(PACKET_SENT_TO_NETWORK, e.type); | 186 ASSERT_EQ(PACKET_SENT_TO_NETWORK, e.type); |
185 ASSERT_EQ(VIDEO_EVENT, e.media_type); | 187 ASSERT_EQ(VIDEO_EVENT, e.media_type); |
186 ASSERT_EQ(kFrameRtpTimestamp, e.rtp_timestamp); | 188 ASSERT_EQ(kVideoFrameRtpTimestamp, e.rtp_timestamp.lower_32_bits()); |
187 ASSERT_EQ(num_of_packets - 1, e.max_packet_id); | 189 ASSERT_EQ(num_of_packets - 1, e.max_packet_id); |
188 ASSERT_EQ(expected_packet_id++, e.packet_id); | 190 ASSERT_EQ(expected_packet_id++, e.packet_id); |
189 ASSERT_EQ(kSize1, e.size); | 191 ASSERT_EQ(kSize1, e.size); |
190 } | 192 } |
191 } | 193 } |
192 | 194 |
193 TEST_F(PacedSenderTest, PaceWithNack) { | 195 TEST_F(PacedSenderTest, PaceWithNack) { |
194 // Testing what happen when we get multiple NACK requests for a fully lost | 196 // Testing what happen when we get multiple NACK requests for a fully lost |
195 // frames just as we sent the first packets in a frame. | 197 // frames just as we sent the first packets in a frame. |
196 int num_of_packets_in_frame = 12; | 198 int num_of_packets_in_frame = 12; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 EXPECT_TRUE(paced_sender_->ResendPackets(packets, dedup_info)); | 454 EXPECT_TRUE(paced_sender_->ResendPackets(packets, dedup_info)); |
453 EXPECT_EQ(static_cast<int64>(kSize1), mock_transport_.GetBytesSent()); | 455 EXPECT_EQ(static_cast<int64>(kSize1), mock_transport_.GetBytesSent()); |
454 | 456 |
455 dedup_info.resend_interval = base::TimeDelta::FromMilliseconds(5); | 457 dedup_info.resend_interval = base::TimeDelta::FromMilliseconds(5); |
456 EXPECT_TRUE(paced_sender_->ResendPackets(packets, dedup_info)); | 458 EXPECT_TRUE(paced_sender_->ResendPackets(packets, dedup_info)); |
457 EXPECT_EQ(static_cast<int64>(2 * kSize1), mock_transport_.GetBytesSent()); | 459 EXPECT_EQ(static_cast<int64>(2 * kSize1), mock_transport_.GetBytesSent()); |
458 } | 460 } |
459 | 461 |
460 } // namespace cast | 462 } // namespace cast |
461 } // namespace media | 463 } // namespace media |
OLD | NEW |