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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/rand_util.h" | 7 #include "base/rand_util.h" |
8 #include "base/test/simple_test_tick_clock.h" | 8 #include "base/test/simple_test_tick_clock.h" |
9 #include "base/time/tick_clock.h" | 9 #include "base/time/tick_clock.h" |
10 #include "media/cast/cast_environment.h" | 10 #include "media/cast/cast_environment.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 EXPECT_DOUBLE_EQ(it->second, static_cast<double>(dropped_frames)); | 133 EXPECT_DOUBLE_EQ(it->second, static_cast<double>(dropped_frames)); |
134 } | 134 } |
135 | 135 |
136 TEST_F(StatsEventSubscriberTest, Encode) { | 136 TEST_F(StatsEventSubscriberTest, Encode) { |
137 Init(VIDEO_EVENT); | 137 Init(VIDEO_EVENT); |
138 | 138 |
139 uint32 rtp_timestamp = 0; | 139 uint32 rtp_timestamp = 0; |
140 uint32 frame_id = 0; | 140 uint32 frame_id = 0; |
141 int num_frames = 10; | 141 int num_frames = 10; |
142 base::TimeTicks start_time = sender_clock_->NowTicks(); | 142 base::TimeTicks start_time = sender_clock_->NowTicks(); |
| 143 AdvanceClocks(base::TimeDelta::FromMicroseconds(35678)); |
| 144 base::TimeTicks first_event_time = sender_clock_->NowTicks(); |
| 145 base::TimeTicks last_event_time; |
143 int total_size = 0; | 146 int total_size = 0; |
144 for (int i = 0; i < num_frames; i++) { | 147 for (int i = 0; i < num_frames; i++) { |
145 int size = 1000 + base::RandInt(-100, 100); | 148 int size = 1000 + base::RandInt(-100, 100); |
146 total_size += size; | 149 total_size += size; |
147 cast_environment_->Logging()->InsertEncodedFrameEvent( | 150 cast_environment_->Logging()->InsertEncodedFrameEvent( |
148 sender_clock_->NowTicks(), | 151 sender_clock_->NowTicks(), |
149 FRAME_ENCODED, VIDEO_EVENT, | 152 FRAME_ENCODED, VIDEO_EVENT, |
150 rtp_timestamp, | 153 rtp_timestamp, |
151 frame_id, | 154 frame_id, |
152 size, | 155 size, |
153 true, | 156 true, |
154 5678); | 157 5678); |
| 158 last_event_time = sender_clock_->NowTicks(); |
155 | 159 |
156 AdvanceClocks(base::TimeDelta::FromMicroseconds(35678)); | 160 AdvanceClocks(base::TimeDelta::FromMicroseconds(35678)); |
157 rtp_timestamp += 90; | 161 rtp_timestamp += 90; |
158 frame_id++; | 162 frame_id++; |
159 } | 163 } |
160 | 164 |
161 base::TimeTicks end_time = sender_clock_->NowTicks(); | 165 base::TimeTicks end_time = sender_clock_->NowTicks(); |
162 | 166 |
163 StatsEventSubscriber::StatsMap stats_map; | 167 StatsEventSubscriber::StatsMap stats_map; |
164 subscriber_->GetStatsInternal(&stats_map); | 168 subscriber_->GetStatsInternal(&stats_map); |
165 | 169 |
166 StatsEventSubscriber::StatsMap::iterator it = | 170 StatsEventSubscriber::StatsMap::iterator it = |
167 stats_map.find(StatsEventSubscriber::ENCODE_FPS); | 171 stats_map.find(StatsEventSubscriber::ENCODE_FPS); |
168 ASSERT_TRUE(it != stats_map.end()); | 172 ASSERT_TRUE(it != stats_map.end()); |
169 | 173 |
170 base::TimeDelta duration = end_time - start_time; | 174 base::TimeDelta duration = end_time - start_time; |
171 EXPECT_DOUBLE_EQ( | 175 EXPECT_DOUBLE_EQ( |
172 it->second, | 176 it->second, |
173 static_cast<double>(num_frames) / duration.InMillisecondsF() * 1000); | 177 static_cast<double>(num_frames) / duration.InMillisecondsF() * 1000); |
174 | 178 |
175 it = stats_map.find(StatsEventSubscriber::ENCODE_KBPS); | 179 it = stats_map.find(StatsEventSubscriber::ENCODE_KBPS); |
176 ASSERT_TRUE(it != stats_map.end()); | 180 ASSERT_TRUE(it != stats_map.end()); |
177 | 181 |
178 EXPECT_DOUBLE_EQ(it->second, | 182 EXPECT_DOUBLE_EQ(it->second, |
179 static_cast<double>(total_size) / duration.InMillisecondsF() * 8); | 183 static_cast<double>(total_size) / duration.InMillisecondsF() * 8); |
| 184 |
| 185 it = stats_map.find(StatsEventSubscriber::FIRST_EVENT_TIME_MS); |
| 186 ASSERT_TRUE(it != stats_map.end()); |
| 187 |
| 188 EXPECT_DOUBLE_EQ( |
| 189 it->second, |
| 190 (first_event_time - base::TimeTicks::UnixEpoch()).InMillisecondsF()); |
| 191 |
| 192 it = stats_map.find(StatsEventSubscriber::LAST_EVENT_TIME_MS); |
| 193 ASSERT_TRUE(it != stats_map.end()); |
| 194 |
| 195 EXPECT_DOUBLE_EQ( |
| 196 it->second, |
| 197 (last_event_time - base::TimeTicks::UnixEpoch()).InMillisecondsF()); |
180 } | 198 } |
181 | 199 |
182 TEST_F(StatsEventSubscriberTest, Decode) { | 200 TEST_F(StatsEventSubscriberTest, Decode) { |
183 Init(VIDEO_EVENT); | 201 Init(VIDEO_EVENT); |
184 | 202 |
185 uint32 rtp_timestamp = 0; | 203 uint32 rtp_timestamp = 0; |
186 uint32 frame_id = 0; | 204 uint32 frame_id = 0; |
187 int num_frames = 10; | 205 int num_frames = 10; |
188 base::TimeTicks start_time = sender_clock_->NowTicks(); | 206 base::TimeTicks start_time = sender_clock_->NowTicks(); |
189 for (int i = 0; i < num_frames; i++) { | 207 for (int i = 0; i < num_frames; i++) { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 EXPECT_DOUBLE_EQ(it->second, static_cast<double>(num_packets_retransmitted)); | 477 EXPECT_DOUBLE_EQ(it->second, static_cast<double>(num_packets_retransmitted)); |
460 | 478 |
461 it = stats_map.find(StatsEventSubscriber::NUM_PACKETS_RTX_REJECTED); | 479 it = stats_map.find(StatsEventSubscriber::NUM_PACKETS_RTX_REJECTED); |
462 ASSERT_TRUE(it != stats_map.end()); | 480 ASSERT_TRUE(it != stats_map.end()); |
463 | 481 |
464 EXPECT_DOUBLE_EQ(it->second, static_cast<double>(num_packets_rtx_rejected)); | 482 EXPECT_DOUBLE_EQ(it->second, static_cast<double>(num_packets_rtx_rejected)); |
465 } | 483 } |
466 | 484 |
467 } // namespace cast | 485 } // namespace cast |
468 } // namespace media | 486 } // namespace media |
OLD | NEW |