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

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

Issue 1515433002: Replace uses of raw uint32's with a type-checked RtpTimeTicks data type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Speculative workaround fix for win8_chromium_ng compile error. Created 4 years, 11 months 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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/big_endian.h" 8 #include "base/big_endian.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/test/simple_test_tick_clock.h" 10 #include "base/test/simple_test_tick_clock.h"
11 #include "media/cast/net/pacing/paced_sender.h" 11 #include "media/cast/net/pacing/paced_sender.h"
12 #include "media/cast/test/fake_single_thread_task_runner.h" 12 #include "media/cast/test/fake_single_thread_task_runner.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 14
15 using testing::_; 15 using testing::_;
16 16
17 namespace media { 17 namespace media {
18 namespace cast { 18 namespace cast {
19 namespace { 19 namespace {
20 20
21 static const uint8_t kValue = 123; 21 static const uint8_t kValue = 123;
22 static const size_t kSize1 = 101; 22 static const size_t kSize1 = 101;
23 static const size_t kSize2 = 102; 23 static const size_t kSize2 = 102;
24 static const size_t kSize3 = 103; 24 static const size_t kSize3 = 103;
25 static const size_t kSize4 = 104; 25 static const size_t kSize4 = 104;
26 static const size_t kNackSize = 105; 26 static const size_t kNackSize = 105;
27 static const int64_t kStartMillisecond = INT64_C(12345678900000); 27 static const int64_t kStartMillisecond = INT64_C(12345678900000);
28 static const uint32_t kVideoSsrc = 0x1234; 28 static const uint32_t kVideoSsrc = 0x1234;
29 static const uint32_t kAudioSsrc = 0x5678; 29 static const uint32_t kAudioSsrc = 0x5678;
30 static const uint32_t kFrameRtpTimestamp = 12345; 30 static const uint32_t kVideoFrameRtpTimestamp = 12345;
31 static const uint32_t kAudioFrameRtpTimestamp = 23456;
31 32
32 class TestPacketSender : public PacketSender { 33 class TestPacketSender : public PacketSender {
33 public: 34 public:
34 TestPacketSender() : bytes_sent_(0) {} 35 TestPacketSender() : bytes_sent_(0) {}
35 36
36 bool SendPacket(PacketRef packet, const base::Closure& cb) final { 37 bool SendPacket(PacketRef packet, const base::Closure& cb) final {
37 EXPECT_FALSE(expected_packet_size_.empty()); 38 EXPECT_FALSE(expected_packet_size_.empty());
38 size_t expected_packet_size = expected_packet_size_.front(); 39 size_t expected_packet_size = expected_packet_size_.front();
39 expected_packet_size_.pop_front(); 40 expected_packet_size_.pop_front();
40 EXPECT_EQ(expected_packet_size, packet->data.size()); 41 EXPECT_EQ(expected_packet_size, packet->data.size());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 audio ? kAudioSsrc : kVideoSsrc, // ssrc 86 audio ? kAudioSsrc : kVideoSsrc, // ssrc
86 i); 87 i);
87 88
88 PacketRef packet(new base::RefCountedData<Packet>); 89 PacketRef packet(new base::RefCountedData<Packet>);
89 packet->data.resize(packet_size, kValue); 90 packet->data.resize(packet_size, kValue);
90 // Fill-in packet header fields to test the header parsing (for populating 91 // Fill-in packet header fields to test the header parsing (for populating
91 // the logging events). 92 // the logging events).
92 base::BigEndianWriter writer(reinterpret_cast<char*>(&packet->data[0]), 93 base::BigEndianWriter writer(reinterpret_cast<char*>(&packet->data[0]),
93 packet_size); 94 packet_size);
94 bool success = writer.Skip(4); 95 bool success = writer.Skip(4);
95 success &= writer.WriteU32(kFrameRtpTimestamp); 96 success &= writer.WriteU32(audio ? kAudioFrameRtpTimestamp
97 : kVideoFrameRtpTimestamp);
96 success &= writer.WriteU32(audio ? kAudioSsrc : kVideoSsrc); 98 success &= writer.WriteU32(audio ? kAudioSsrc : kVideoSsrc);
97 success &= writer.Skip(2); 99 success &= writer.Skip(2);
98 success &= writer.WriteU16(i); 100 success &= writer.WriteU16(i);
99 success &= writer.WriteU16(num_of_packets_in_frame - 1); 101 success &= writer.WriteU16(num_of_packets_in_frame - 1);
100 CHECK(success); 102 CHECK(success);
101 packets.push_back(std::make_pair(key, packet)); 103 packets.push_back(std::make_pair(key, packet));
102 } 104 }
103 // Increase |frame_id_| so that we don't get the same key next time this 105 // Increase |frame_id_| so that we don't get the same key next time this
104 // function is called. 106 // function is called.
105 ++frame_id_; 107 ++frame_id_;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 const base::TimeTicks latest_event_timestamp = testing_clock_.NowTicks(); 180 const base::TimeTicks latest_event_timestamp = testing_clock_.NowTicks();
179 181
180 // Check that packet logging events match expected values. 182 // Check that packet logging events match expected values.
181 EXPECT_EQ(num_of_packets, static_cast<int>(packet_events_.size())); 183 EXPECT_EQ(num_of_packets, static_cast<int>(packet_events_.size()));
182 uint16_t expected_packet_id = 0; 184 uint16_t expected_packet_id = 0;
183 for (const PacketEvent& e : packet_events_) { 185 for (const PacketEvent& e : packet_events_) {
184 ASSERT_LE(earliest_event_timestamp, e.timestamp); 186 ASSERT_LE(earliest_event_timestamp, e.timestamp);
185 ASSERT_GE(latest_event_timestamp, e.timestamp); 187 ASSERT_GE(latest_event_timestamp, e.timestamp);
186 ASSERT_EQ(PACKET_SENT_TO_NETWORK, e.type); 188 ASSERT_EQ(PACKET_SENT_TO_NETWORK, e.type);
187 ASSERT_EQ(VIDEO_EVENT, e.media_type); 189 ASSERT_EQ(VIDEO_EVENT, e.media_type);
188 ASSERT_EQ(kFrameRtpTimestamp, e.rtp_timestamp); 190 ASSERT_EQ(kVideoFrameRtpTimestamp, e.rtp_timestamp.lower_32_bits());
189 ASSERT_EQ(num_of_packets - 1, e.max_packet_id); 191 ASSERT_EQ(num_of_packets - 1, e.max_packet_id);
190 ASSERT_EQ(expected_packet_id++, e.packet_id); 192 ASSERT_EQ(expected_packet_id++, e.packet_id);
191 ASSERT_EQ(kSize1, e.size); 193 ASSERT_EQ(kSize1, e.size);
192 } 194 }
193 } 195 }
194 196
195 TEST_F(PacedSenderTest, PaceWithNack) { 197 TEST_F(PacedSenderTest, PaceWithNack) {
196 // Testing what happen when we get multiple NACK requests for a fully lost 198 // Testing what happen when we get multiple NACK requests for a fully lost
197 // frames just as we sent the first packets in a frame. 199 // frames just as we sent the first packets in a frame.
198 int num_of_packets_in_frame = 12; 200 int num_of_packets_in_frame = 12;
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 EXPECT_TRUE(paced_sender_->ResendPackets(packets, dedup_info)); 456 EXPECT_TRUE(paced_sender_->ResendPackets(packets, dedup_info));
455 EXPECT_EQ(static_cast<int64_t>(kSize1), mock_transport_.GetBytesSent()); 457 EXPECT_EQ(static_cast<int64_t>(kSize1), mock_transport_.GetBytesSent());
456 458
457 dedup_info.resend_interval = base::TimeDelta::FromMilliseconds(5); 459 dedup_info.resend_interval = base::TimeDelta::FromMilliseconds(5);
458 EXPECT_TRUE(paced_sender_->ResendPackets(packets, dedup_info)); 460 EXPECT_TRUE(paced_sender_->ResendPackets(packets, dedup_info));
459 EXPECT_EQ(static_cast<int64_t>(2 * kSize1), mock_transport_.GetBytesSent()); 461 EXPECT_EQ(static_cast<int64_t>(2 * kSize1), mock_transport_.GetBytesSent());
460 } 462 }
461 463
462 } // namespace cast 464 } // namespace cast
463 } // namespace media 465 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/net/pacing/paced_sender.cc ('k') | media/cast/net/rtcp/receiver_rtcp_event_subscriber.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698