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

Side by Side Diff: media/cast/net/rtp/receiver_stats_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more 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
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 <gtest/gtest.h> 5 #include <gtest/gtest.h>
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/test/simple_test_tick_clock.h" 9 #include "base/test/simple_test_tick_clock.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "media/cast/net/rtp/receiver_stats.h" 11 #include "media/cast/net/rtp/receiver_stats.h"
12 #include "media/cast/net/rtp/rtp_defines.h" 12 #include "media/cast/net/rtp/rtp_defines.h"
13 13
14 namespace media { 14 namespace media {
15 namespace cast { 15 namespace cast {
16 16
17 static const int64 kStartMillisecond = INT64_C(12345678900000); 17 static const int64_t kStartMillisecond = INT64_C(12345678900000);
18 static const uint32 kStdTimeIncrementMs = 33; 18 static const uint32_t kStdTimeIncrementMs = 33;
19 19
20 class ReceiverStatsTest : public ::testing::Test { 20 class ReceiverStatsTest : public ::testing::Test {
21 protected: 21 protected:
22 ReceiverStatsTest() 22 ReceiverStatsTest()
23 : stats_(&testing_clock_) { 23 : stats_(&testing_clock_) {
24 testing_clock_.Advance( 24 testing_clock_.Advance(
25 base::TimeDelta::FromMilliseconds(kStartMillisecond)); 25 base::TimeDelta::FromMilliseconds(kStartMillisecond));
26 start_time_ = testing_clock_.NowTicks(); 26 start_time_ = testing_clock_.NowTicks();
27 delta_increments_ = base::TimeDelta::FromMilliseconds(kStdTimeIncrementMs); 27 delta_increments_ = base::TimeDelta::FromMilliseconds(kStdTimeIncrementMs);
28 } 28 }
29 ~ReceiverStatsTest() override {} 29 ~ReceiverStatsTest() override {}
30 30
31 uint32 ExpectedJitter(uint32 const_interval, int num_packets) { 31 uint32_t ExpectedJitter(uint32_t const_interval, int num_packets) {
32 float jitter = 0; 32 float jitter = 0;
33 // Assume timestamps have a constant kStdTimeIncrementMs interval. 33 // Assume timestamps have a constant kStdTimeIncrementMs interval.
34 float float_interval = 34 float float_interval =
35 static_cast<float>(const_interval - kStdTimeIncrementMs); 35 static_cast<float>(const_interval - kStdTimeIncrementMs);
36 for (int i = 0; i < num_packets; ++i) { 36 for (int i = 0; i < num_packets; ++i) {
37 jitter += (float_interval - jitter) / 16; 37 jitter += (float_interval - jitter) / 16;
38 } 38 }
39 return static_cast<uint32>(jitter + 0.5f); 39 return static_cast<uint32_t>(jitter + 0.5f);
40 } 40 }
41 41
42 ReceiverStats stats_; 42 ReceiverStats stats_;
43 RtpCastHeader rtp_header_; 43 RtpCastHeader rtp_header_;
44 base::SimpleTestTickClock testing_clock_; 44 base::SimpleTestTickClock testing_clock_;
45 base::TimeTicks start_time_; 45 base::TimeTicks start_time_;
46 base::TimeDelta delta_increments_; 46 base::TimeDelta delta_increments_;
47 47
48 private: 48 private:
49 DISALLOW_COPY_AND_ASSIGN(ReceiverStatsTest); 49 DISALLOW_COPY_AND_ASSIGN(ReceiverStatsTest);
(...skipping 14 matching lines...) Expand all
64 if (i % 3) { 64 if (i % 3) {
65 rtp_header_.rtp_timestamp += 33 * 90; 65 rtp_header_.rtp_timestamp += 33 * 90;
66 } 66 }
67 ++rtp_header_.sequence_number; 67 ++rtp_header_.sequence_number;
68 testing_clock_.Advance(delta_increments_); 68 testing_clock_.Advance(delta_increments_);
69 } 69 }
70 RtpReceiverStatistics s = stats_.GetStatistics(); 70 RtpReceiverStatistics s = stats_.GetStatistics();
71 EXPECT_EQ(63u, s.fraction_lost); 71 EXPECT_EQ(63u, s.fraction_lost);
72 EXPECT_EQ(74u, s.cumulative_lost); 72 EXPECT_EQ(74u, s.cumulative_lost);
73 // Build extended sequence number. 73 // Build extended sequence number.
74 const uint32 extended_seq_num = rtp_header_.sequence_number - 1; 74 const uint32_t extended_seq_num = rtp_header_.sequence_number - 1;
75 EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number); 75 EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number);
76 } 76 }
77 77
78 TEST_F(ReceiverStatsTest, NoLossWrap) { 78 TEST_F(ReceiverStatsTest, NoLossWrap) {
79 rtp_header_.sequence_number = 65500; 79 rtp_header_.sequence_number = 65500;
80 for (int i = 0; i < 300; ++i) { 80 for (int i = 0; i < 300; ++i) {
81 stats_.UpdateStatistics(rtp_header_); 81 stats_.UpdateStatistics(rtp_header_);
82 if (i % 3) { 82 if (i % 3) {
83 rtp_header_.rtp_timestamp += 33 * 90; 83 rtp_header_.rtp_timestamp += 33 * 90;
84 } 84 }
85 ++rtp_header_.sequence_number; 85 ++rtp_header_.sequence_number;
86 testing_clock_.Advance(delta_increments_); 86 testing_clock_.Advance(delta_increments_);
87 } 87 }
88 RtpReceiverStatistics s = stats_.GetStatistics(); 88 RtpReceiverStatistics s = stats_.GetStatistics();
89 EXPECT_EQ(0u, s.fraction_lost); 89 EXPECT_EQ(0u, s.fraction_lost);
90 EXPECT_EQ(0u, s.cumulative_lost); 90 EXPECT_EQ(0u, s.cumulative_lost);
91 // Build extended sequence number (one wrap cycle). 91 // Build extended sequence number (one wrap cycle).
92 const uint32 extended_seq_num = (1 << 16) + rtp_header_.sequence_number - 1; 92 const uint32_t extended_seq_num = (1 << 16) + rtp_header_.sequence_number - 1;
93 EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number); 93 EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number);
94 } 94 }
95 95
96 TEST_F(ReceiverStatsTest, LossCountWrap) { 96 TEST_F(ReceiverStatsTest, LossCountWrap) {
97 const uint32 kStartSequenceNumber = 65500; 97 const uint32_t kStartSequenceNumber = 65500;
98 rtp_header_.sequence_number = kStartSequenceNumber; 98 rtp_header_.sequence_number = kStartSequenceNumber;
99 for (int i = 0; i < 300; ++i) { 99 for (int i = 0; i < 300; ++i) {
100 if (i % 4) 100 if (i % 4)
101 stats_.UpdateStatistics(rtp_header_); 101 stats_.UpdateStatistics(rtp_header_);
102 if (i % 3) 102 if (i % 3)
103 // Update timestamp. 103 // Update timestamp.
104 ++rtp_header_.rtp_timestamp; 104 ++rtp_header_.rtp_timestamp;
105 ++rtp_header_.sequence_number; 105 ++rtp_header_.sequence_number;
106 testing_clock_.Advance(delta_increments_); 106 testing_clock_.Advance(delta_increments_);
107 } 107 }
108 RtpReceiverStatistics s = stats_.GetStatistics(); 108 RtpReceiverStatistics s = stats_.GetStatistics();
109 EXPECT_EQ(63u, s.fraction_lost); 109 EXPECT_EQ(63u, s.fraction_lost);
110 EXPECT_EQ(74u, s.cumulative_lost); 110 EXPECT_EQ(74u, s.cumulative_lost);
111 // Build extended sequence number (one wrap cycle). 111 // Build extended sequence number (one wrap cycle).
112 const uint32 extended_seq_num = (1 << 16) + rtp_header_.sequence_number - 1; 112 const uint32_t extended_seq_num = (1 << 16) + rtp_header_.sequence_number - 1;
113 EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number); 113 EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number);
114 } 114 }
115 115
116 TEST_F(ReceiverStatsTest, BasicJitter) { 116 TEST_F(ReceiverStatsTest, BasicJitter) {
117 for (int i = 0; i < 300; ++i) { 117 for (int i = 0; i < 300; ++i) {
118 stats_.UpdateStatistics(rtp_header_); 118 stats_.UpdateStatistics(rtp_header_);
119 ++rtp_header_.sequence_number; 119 ++rtp_header_.sequence_number;
120 rtp_header_.rtp_timestamp += 33 * 90; 120 rtp_header_.rtp_timestamp += 33 * 90;
121 testing_clock_.Advance(delta_increments_); 121 testing_clock_.Advance(delta_increments_);
122 } 122 }
123 RtpReceiverStatistics s = stats_.GetStatistics(); 123 RtpReceiverStatistics s = stats_.GetStatistics();
124 EXPECT_FALSE(s.fraction_lost); 124 EXPECT_FALSE(s.fraction_lost);
125 EXPECT_FALSE(s.cumulative_lost); 125 EXPECT_FALSE(s.cumulative_lost);
126 // Build extended sequence number (one wrap cycle). 126 // Build extended sequence number (one wrap cycle).
127 const uint32 extended_seq_num = rtp_header_.sequence_number - 1; 127 const uint32_t extended_seq_num = rtp_header_.sequence_number - 1;
128 EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number); 128 EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number);
129 EXPECT_EQ(ExpectedJitter(kStdTimeIncrementMs, 300), s.jitter); 129 EXPECT_EQ(ExpectedJitter(kStdTimeIncrementMs, 300), s.jitter);
130 } 130 }
131 131
132 TEST_F(ReceiverStatsTest, NonTrivialJitter) { 132 TEST_F(ReceiverStatsTest, NonTrivialJitter) {
133 const int kAdditionalIncrement = 5; 133 const int kAdditionalIncrement = 5;
134 for (int i = 0; i < 300; ++i) { 134 for (int i = 0; i < 300; ++i) {
135 stats_.UpdateStatistics(rtp_header_); 135 stats_.UpdateStatistics(rtp_header_);
136 ++rtp_header_.sequence_number; 136 ++rtp_header_.sequence_number;
137 rtp_header_.rtp_timestamp += 33 * 90; 137 rtp_header_.rtp_timestamp += 33 * 90;
138 base::TimeDelta additional_delta = 138 base::TimeDelta additional_delta =
139 base::TimeDelta::FromMilliseconds(kAdditionalIncrement); 139 base::TimeDelta::FromMilliseconds(kAdditionalIncrement);
140 testing_clock_.Advance(delta_increments_ + additional_delta); 140 testing_clock_.Advance(delta_increments_ + additional_delta);
141 } 141 }
142 RtpReceiverStatistics s = stats_.GetStatistics(); 142 RtpReceiverStatistics s = stats_.GetStatistics();
143 EXPECT_FALSE(s.fraction_lost); 143 EXPECT_FALSE(s.fraction_lost);
144 EXPECT_FALSE(s.cumulative_lost); 144 EXPECT_FALSE(s.cumulative_lost);
145 // Build extended sequence number (one wrap cycle). 145 // Build extended sequence number (one wrap cycle).
146 const uint32 extended_seq_num = rtp_header_.sequence_number - 1; 146 const uint32_t extended_seq_num = rtp_header_.sequence_number - 1;
147 EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number); 147 EXPECT_EQ(extended_seq_num, s.extended_high_sequence_number);
148 EXPECT_EQ(ExpectedJitter(kStdTimeIncrementMs + kAdditionalIncrement, 300), 148 EXPECT_EQ(ExpectedJitter(kStdTimeIncrementMs + kAdditionalIncrement, 300),
149 s.jitter); 149 s.jitter);
150 } 150 }
151 151
152 } // namespace cast 152 } // namespace cast
153 } // namespace media 153 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698