Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Side by Side Diff: media/cast/net/pacing/paced_sender_unittest.cc

Issue 1487223002: Change PacketKey to be unique for each frame packet by including (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/cast/net/pacing/paced_sender.cc ('k') | media/cast/net/rtp/packet_storage_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 public: 51 public:
52 std::list<int> expected_packet_size_; 52 std::list<int> expected_packet_size_;
53 int64 bytes_sent_; 53 int64 bytes_sent_;
54 54
55 DISALLOW_COPY_AND_ASSIGN(TestPacketSender); 55 DISALLOW_COPY_AND_ASSIGN(TestPacketSender);
56 }; 56 };
57 57
58 class PacedSenderTest : public ::testing::Test { 58 class PacedSenderTest : public ::testing::Test {
59 protected: 59 protected:
60 PacedSenderTest() { 60 PacedSenderTest() : frame_id_(0) {
61 testing_clock_.Advance( 61 testing_clock_.Advance(
62 base::TimeDelta::FromMilliseconds(kStartMillisecond)); 62 base::TimeDelta::FromMilliseconds(kStartMillisecond));
63 task_runner_ = new test::FakeSingleThreadTaskRunner(&testing_clock_); 63 task_runner_ = new test::FakeSingleThreadTaskRunner(&testing_clock_);
64 paced_sender_.reset(new PacedSender(kTargetBurstSize, kMaxBurstSize, 64 paced_sender_.reset(new PacedSender(kTargetBurstSize, kMaxBurstSize,
65 &testing_clock_, &packet_events_, 65 &testing_clock_, &packet_events_,
66 &mock_transport_, task_runner_)); 66 &mock_transport_, task_runner_));
67 paced_sender_->RegisterAudioSsrc(kAudioSsrc); 67 paced_sender_->RegisterAudioSsrc(kAudioSsrc);
68 paced_sender_->RegisterVideoSsrc(kVideoSsrc); 68 paced_sender_->RegisterVideoSsrc(kVideoSsrc);
69 } 69 }
70 70
71 static void UpdateCastTransportStatus(CastTransportStatus status) { 71 static void UpdateCastTransportStatus(CastTransportStatus status) {
72 NOTREACHED(); 72 NOTREACHED();
73 } 73 }
74 74
75 SendPacketVector CreateSendPacketVector(size_t packet_size, 75 SendPacketVector CreateSendPacketVector(size_t packet_size,
76 int num_of_packets_in_frame, 76 int num_of_packets_in_frame,
77 bool audio) { 77 bool audio) {
78 DCHECK_GE(packet_size, 12u); 78 DCHECK_GE(packet_size, 12u);
79 SendPacketVector packets; 79 SendPacketVector packets;
80 base::TimeTicks frame_tick = testing_clock_.NowTicks();
81 // Advance the clock so that we don't get the same frame_tick
82 // next time this function is called.
83 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(1));
84 for (int i = 0; i < num_of_packets_in_frame; ++i) { 80 for (int i = 0; i < num_of_packets_in_frame; ++i) {
85 PacketKey key = PacedPacketSender::MakePacketKey( 81 PacketKey key = PacedPacketSender::MakePacketKey(
86 frame_tick, 82 PacketKey::RTP, frame_id_,
87 audio ? kAudioSsrc : kVideoSsrc, // ssrc 83 audio ? kAudioSsrc : kVideoSsrc, // ssrc
88 i); 84 i);
89 85
90 PacketRef packet(new base::RefCountedData<Packet>); 86 PacketRef packet(new base::RefCountedData<Packet>);
91 packet->data.resize(packet_size, kValue); 87 packet->data.resize(packet_size, kValue);
92 // Fill-in packet header fields to test the header parsing (for populating 88 // Fill-in packet header fields to test the header parsing (for populating
93 // the logging events). 89 // the logging events).
94 base::BigEndianWriter writer(reinterpret_cast<char*>(&packet->data[0]), 90 base::BigEndianWriter writer(reinterpret_cast<char*>(&packet->data[0]),
95 packet_size); 91 packet_size);
96 bool success = writer.Skip(4); 92 bool success = writer.Skip(4);
97 success &= writer.WriteU32(kFrameRtpTimestamp); 93 success &= writer.WriteU32(kFrameRtpTimestamp);
98 success &= writer.WriteU32(audio ? kAudioSsrc : kVideoSsrc); 94 success &= writer.WriteU32(audio ? kAudioSsrc : kVideoSsrc);
99 success &= writer.Skip(2); 95 success &= writer.Skip(2);
100 success &= writer.WriteU16(i); 96 success &= writer.WriteU16(i);
101 success &= writer.WriteU16(num_of_packets_in_frame - 1); 97 success &= writer.WriteU16(num_of_packets_in_frame - 1);
102 CHECK(success); 98 CHECK(success);
103 packets.push_back(std::make_pair(key, packet)); 99 packets.push_back(std::make_pair(key, packet));
104 } 100 }
101 // Increase |frame_id_| so that we don't get the same key next time this
102 // function is called.
103 ++frame_id_;
105 return packets; 104 return packets;
106 } 105 }
107 106
108 // Use this function to drain the packet list in PacedSender without having 107 // Use this function to drain the packet list in PacedSender without having
109 // to test the pacing implementation details. 108 // to test the pacing implementation details.
110 bool RunUntilEmpty(int max_tries) { 109 bool RunUntilEmpty(int max_tries) {
111 for (int i = 0; i < max_tries; i++) { 110 for (int i = 0; i < max_tries; i++) {
112 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10)); 111 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10));
113 task_runner_->RunTasks(); 112 task_runner_->RunTasks();
114 if (mock_transport_.expected_packet_size_.empty()) 113 if (mock_transport_.expected_packet_size_.empty())
115 return true; 114 return true;
116 i++; 115 i++;
117 } 116 }
118 117
119 return mock_transport_.expected_packet_size_.empty(); 118 return mock_transport_.expected_packet_size_.empty();
120 } 119 }
121 120
122 std::vector<PacketEvent> packet_events_; 121 std::vector<PacketEvent> packet_events_;
123 base::SimpleTestTickClock testing_clock_; 122 base::SimpleTestTickClock testing_clock_;
124 TestPacketSender mock_transport_; 123 TestPacketSender mock_transport_;
125 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; 124 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
126 scoped_ptr<PacedSender> paced_sender_; 125 scoped_ptr<PacedSender> paced_sender_;
126 uint32 frame_id_;
127 127
128 DISALLOW_COPY_AND_ASSIGN(PacedSenderTest); 128 DISALLOW_COPY_AND_ASSIGN(PacedSenderTest);
129 }; 129 };
130 130
131 } // namespace 131 } // namespace
132 132
133 TEST_F(PacedSenderTest, PassThroughRtcp) { 133 TEST_F(PacedSenderTest, PassThroughRtcp) {
134 mock_transport_.AddExpectedSize(kSize1, 2); 134 mock_transport_.AddExpectedSize(kSize1, 2);
135 SendPacketVector packets = CreateSendPacketVector(kSize1, 1, true); 135 SendPacketVector packets = CreateSendPacketVector(kSize1, 1, true);
136 136
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 EXPECT_TRUE(paced_sender_->ResendPackets(packets, dedup_info)); 452 EXPECT_TRUE(paced_sender_->ResendPackets(packets, dedup_info));
453 EXPECT_EQ(static_cast<int64>(kSize1), mock_transport_.GetBytesSent()); 453 EXPECT_EQ(static_cast<int64>(kSize1), mock_transport_.GetBytesSent());
454 454
455 dedup_info.resend_interval = base::TimeDelta::FromMilliseconds(5); 455 dedup_info.resend_interval = base::TimeDelta::FromMilliseconds(5);
456 EXPECT_TRUE(paced_sender_->ResendPackets(packets, dedup_info)); 456 EXPECT_TRUE(paced_sender_->ResendPackets(packets, dedup_info));
457 EXPECT_EQ(static_cast<int64>(2 * kSize1), mock_transport_.GetBytesSent()); 457 EXPECT_EQ(static_cast<int64>(2 * kSize1), mock_transport_.GetBytesSent());
458 } 458 }
459 459
460 } // namespace cast 460 } // namespace cast
461 } // namespace media 461 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/net/pacing/paced_sender.cc ('k') | media/cast/net/rtp/packet_storage_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698