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

Side by Side Diff: media/cast/logging/stats_event_subscriber_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 "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 "base/values.h" 10 #include "base/values.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 base::SimpleTestTickClock receiver_clock_; 60 base::SimpleTestTickClock receiver_clock_;
61 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; 61 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
62 scoped_refptr<CastEnvironment> cast_environment_; 62 scoped_refptr<CastEnvironment> cast_environment_;
63 test::FakeReceiverTimeOffsetEstimator fake_offset_estimator_; 63 test::FakeReceiverTimeOffsetEstimator fake_offset_estimator_;
64 scoped_ptr<StatsEventSubscriber> subscriber_; 64 scoped_ptr<StatsEventSubscriber> subscriber_;
65 }; 65 };
66 66
67 TEST_F(StatsEventSubscriberTest, CaptureEncode) { 67 TEST_F(StatsEventSubscriberTest, CaptureEncode) {
68 Init(VIDEO_EVENT); 68 Init(VIDEO_EVENT);
69 69
70 uint32 rtp_timestamp = 0; 70 uint32_t rtp_timestamp = 0;
71 uint32 frame_id = 0; 71 uint32_t frame_id = 0;
72 int extra_frames = 50; 72 int extra_frames = 50;
73 // Only the first |extra_frames| frames logged will be taken into account 73 // Only the first |extra_frames| frames logged will be taken into account
74 // when computing dropped frames. 74 // when computing dropped frames.
75 int num_frames = StatsEventSubscriber::kMaxFrameInfoMapSize + 50; 75 int num_frames = StatsEventSubscriber::kMaxFrameInfoMapSize + 50;
76 int dropped_frames = 0; 76 int dropped_frames = 0;
77 base::TimeTicks start_time = sender_clock_->NowTicks(); 77 base::TimeTicks start_time = sender_clock_->NowTicks();
78 // Drop half the frames during the encode step. 78 // Drop half the frames during the encode step.
79 for (int i = 0; i < num_frames; i++) { 79 for (int i = 0; i < num_frames; i++) {
80 scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent()); 80 scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent());
81 capture_begin_event->timestamp = sender_clock_->NowTicks(); 81 capture_begin_event->timestamp = sender_clock_->NowTicks();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 it = stats_map.find(StatsEventSubscriber::AVG_CAPTURE_LATENCY_MS); 141 it = stats_map.find(StatsEventSubscriber::AVG_CAPTURE_LATENCY_MS);
142 ASSERT_TRUE(it != stats_map.end()); 142 ASSERT_TRUE(it != stats_map.end());
143 143
144 EXPECT_DOUBLE_EQ(it->second, static_cast<double>(0.01)); 144 EXPECT_DOUBLE_EQ(it->second, static_cast<double>(0.01));
145 } 145 }
146 146
147 TEST_F(StatsEventSubscriberTest, Encode) { 147 TEST_F(StatsEventSubscriberTest, Encode) {
148 Init(VIDEO_EVENT); 148 Init(VIDEO_EVENT);
149 149
150 uint32 rtp_timestamp = 0; 150 uint32_t rtp_timestamp = 0;
151 uint32 frame_id = 0; 151 uint32_t frame_id = 0;
152 int num_frames = 10; 152 int num_frames = 10;
153 base::TimeTicks start_time = sender_clock_->NowTicks(); 153 base::TimeTicks start_time = sender_clock_->NowTicks();
154 AdvanceClocks(base::TimeDelta::FromMicroseconds(35678)); 154 AdvanceClocks(base::TimeDelta::FromMicroseconds(35678));
155 base::TimeTicks first_event_time = sender_clock_->NowTicks(); 155 base::TimeTicks first_event_time = sender_clock_->NowTicks();
156 base::TimeTicks last_event_time; 156 base::TimeTicks last_event_time;
157 int total_size = 0; 157 int total_size = 0;
158 for (int i = 0; i < num_frames; i++) { 158 for (int i = 0; i < num_frames; i++) {
159 int size = 1000 + base::RandInt(-100, 100); 159 int size = 1000 + base::RandInt(-100, 100);
160 total_size += size; 160 total_size += size;
161 scoped_ptr<FrameEvent> encode_event(new FrameEvent()); 161 scoped_ptr<FrameEvent> encode_event(new FrameEvent());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 ASSERT_TRUE(it != stats_map.end()); 208 ASSERT_TRUE(it != stats_map.end());
209 209
210 EXPECT_DOUBLE_EQ( 210 EXPECT_DOUBLE_EQ(
211 it->second, 211 it->second,
212 (last_event_time - base::TimeTicks::UnixEpoch()).InMillisecondsF()); 212 (last_event_time - base::TimeTicks::UnixEpoch()).InMillisecondsF());
213 } 213 }
214 214
215 TEST_F(StatsEventSubscriberTest, Decode) { 215 TEST_F(StatsEventSubscriberTest, Decode) {
216 Init(VIDEO_EVENT); 216 Init(VIDEO_EVENT);
217 217
218 uint32 rtp_timestamp = 0; 218 uint32_t rtp_timestamp = 0;
219 uint32 frame_id = 0; 219 uint32_t frame_id = 0;
220 int num_frames = 10; 220 int num_frames = 10;
221 base::TimeTicks start_time = sender_clock_->NowTicks(); 221 base::TimeTicks start_time = sender_clock_->NowTicks();
222 for (int i = 0; i < num_frames; i++) { 222 for (int i = 0; i < num_frames; i++) {
223 scoped_ptr<FrameEvent> decode_event(new FrameEvent()); 223 scoped_ptr<FrameEvent> decode_event(new FrameEvent());
224 decode_event->timestamp = receiver_clock_.NowTicks(); 224 decode_event->timestamp = receiver_clock_.NowTicks();
225 decode_event->type = FRAME_DECODED; 225 decode_event->type = FRAME_DECODED;
226 decode_event->media_type = VIDEO_EVENT; 226 decode_event->media_type = VIDEO_EVENT;
227 decode_event->rtp_timestamp = rtp_timestamp; 227 decode_event->rtp_timestamp = rtp_timestamp;
228 decode_event->frame_id = frame_id; 228 decode_event->frame_id = frame_id;
229 cast_environment_->logger()->DispatchFrameEvent(decode_event.Pass()); 229 cast_environment_->logger()->DispatchFrameEvent(decode_event.Pass());
(...skipping 14 matching lines...) Expand all
244 244
245 base::TimeDelta duration = end_time - start_time; 245 base::TimeDelta duration = end_time - start_time;
246 EXPECT_DOUBLE_EQ( 246 EXPECT_DOUBLE_EQ(
247 it->second, 247 it->second,
248 static_cast<double>(num_frames) / duration.InMillisecondsF() * 1000); 248 static_cast<double>(num_frames) / duration.InMillisecondsF() * 1000);
249 } 249 }
250 250
251 TEST_F(StatsEventSubscriberTest, PlayoutDelay) { 251 TEST_F(StatsEventSubscriberTest, PlayoutDelay) {
252 Init(VIDEO_EVENT); 252 Init(VIDEO_EVENT);
253 253
254 uint32 rtp_timestamp = 0; 254 uint32_t rtp_timestamp = 0;
255 uint32 frame_id = 0; 255 uint32_t frame_id = 0;
256 int num_frames = 10; 256 int num_frames = 10;
257 int late_frames = 0; 257 int late_frames = 0;
258 for (int i = 0, delay_ms = -50; i < num_frames; i++, delay_ms += 10) { 258 for (int i = 0, delay_ms = -50; i < num_frames; i++, delay_ms += 10) {
259 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(delay_ms); 259 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(delay_ms);
260 if (delay_ms > 0) 260 if (delay_ms > 0)
261 late_frames++; 261 late_frames++;
262 scoped_ptr<FrameEvent> playout_event(new FrameEvent()); 262 scoped_ptr<FrameEvent> playout_event(new FrameEvent());
263 playout_event->timestamp = receiver_clock_.NowTicks(); 263 playout_event->timestamp = receiver_clock_.NowTicks();
264 playout_event->type = FRAME_PLAYOUT; 264 playout_event->type = FRAME_PLAYOUT;
265 playout_event->media_type = VIDEO_EVENT; 265 playout_event->media_type = VIDEO_EVENT;
(...skipping 13 matching lines...) Expand all
279 StatsEventSubscriber::StatsMap::iterator it = stats_map.find( 279 StatsEventSubscriber::StatsMap::iterator it = stats_map.find(
280 StatsEventSubscriber::NUM_FRAMES_LATE); 280 StatsEventSubscriber::NUM_FRAMES_LATE);
281 ASSERT_TRUE(it != stats_map.end()); 281 ASSERT_TRUE(it != stats_map.end());
282 282
283 EXPECT_DOUBLE_EQ(it->second, late_frames); 283 EXPECT_DOUBLE_EQ(it->second, late_frames);
284 } 284 }
285 285
286 TEST_F(StatsEventSubscriberTest, E2ELatency) { 286 TEST_F(StatsEventSubscriberTest, E2ELatency) {
287 Init(VIDEO_EVENT); 287 Init(VIDEO_EVENT);
288 288
289 uint32 rtp_timestamp = 0; 289 uint32_t rtp_timestamp = 0;
290 uint32 frame_id = 0; 290 uint32_t frame_id = 0;
291 int num_frames = 10; 291 int num_frames = 10;
292 base::TimeDelta total_latency; 292 base::TimeDelta total_latency;
293 for (int i = 0; i < num_frames; i++) { 293 for (int i = 0; i < num_frames; i++) {
294 scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent()); 294 scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent());
295 capture_begin_event->timestamp = sender_clock_->NowTicks(); 295 capture_begin_event->timestamp = sender_clock_->NowTicks();
296 capture_begin_event->type = FRAME_CAPTURE_BEGIN; 296 capture_begin_event->type = FRAME_CAPTURE_BEGIN;
297 capture_begin_event->media_type = VIDEO_EVENT; 297 capture_begin_event->media_type = VIDEO_EVENT;
298 capture_begin_event->rtp_timestamp = rtp_timestamp; 298 capture_begin_event->rtp_timestamp = rtp_timestamp;
299 cast_environment_->logger()->DispatchFrameEvent(capture_begin_event.Pass()); 299 cast_environment_->logger()->DispatchFrameEvent(capture_begin_event.Pass());
300 300
(...skipping 25 matching lines...) Expand all
326 stats_map.find(StatsEventSubscriber::AVG_E2E_LATENCY_MS); 326 stats_map.find(StatsEventSubscriber::AVG_E2E_LATENCY_MS);
327 ASSERT_TRUE(it != stats_map.end()); 327 ASSERT_TRUE(it != stats_map.end());
328 328
329 EXPECT_DOUBLE_EQ( 329 EXPECT_DOUBLE_EQ(
330 it->second, total_latency.InMillisecondsF() / num_frames); 330 it->second, total_latency.InMillisecondsF() / num_frames);
331 } 331 }
332 332
333 TEST_F(StatsEventSubscriberTest, Packets) { 333 TEST_F(StatsEventSubscriberTest, Packets) {
334 Init(VIDEO_EVENT); 334 Init(VIDEO_EVENT);
335 335
336 uint32 rtp_timestamp = 0; 336 uint32_t rtp_timestamp = 0;
337 int num_packets = 10; 337 int num_packets = 10;
338 int num_latency_recorded_packets = 0; 338 int num_latency_recorded_packets = 0;
339 base::TimeTicks start_time = sender_clock_->NowTicks(); 339 base::TimeTicks start_time = sender_clock_->NowTicks();
340 int total_size = 0; 340 int total_size = 0;
341 int retransmit_total_size = 0; 341 int retransmit_total_size = 0;
342 base::TimeDelta total_network_latency; 342 base::TimeDelta total_network_latency;
343 base::TimeDelta total_queueing_latency; 343 base::TimeDelta total_queueing_latency;
344 base::TimeDelta total_packet_latency; 344 base::TimeDelta total_packet_latency;
345 int num_packets_transmitted = 0; 345 int num_packets_transmitted = 0;
346 int num_packets_received = 0; 346 int num_packets_received = 0;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 return false; 550 return false;
551 return bucket_count == expected_count; 551 return bucket_count == expected_count;
552 } 552 }
553 return false; 553 return false;
554 } 554 }
555 555
556 TEST_F(StatsEventSubscriberTest, Histograms) { 556 TEST_F(StatsEventSubscriberTest, Histograms) {
557 Init(VIDEO_EVENT); 557 Init(VIDEO_EVENT);
558 AdvanceClocks(base::TimeDelta::FromMilliseconds(123)); 558 AdvanceClocks(base::TimeDelta::FromMilliseconds(123));
559 559
560 uint32 rtp_timestamp = 123; 560 uint32_t rtp_timestamp = 123;
561 uint32 frame_id = 0; 561 uint32_t frame_id = 0;
562 562
563 // 10 Frames with capture latency in the bucket of "10-14"ms. 563 // 10 Frames with capture latency in the bucket of "10-14"ms.
564 // 10 Frames with encode time in the bucket of "15-19"ms. 564 // 10 Frames with encode time in the bucket of "15-19"ms.
565 for (int i = 0; i < 10; ++i) { 565 for (int i = 0; i < 10; ++i) {
566 ++frame_id; 566 ++frame_id;
567 ++rtp_timestamp; 567 ++rtp_timestamp;
568 568
569 scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent()); 569 scoped_ptr<FrameEvent> capture_begin_event(new FrameEvent());
570 capture_begin_event->timestamp = sender_clock_->NowTicks(); 570 capture_begin_event->timestamp = sender_clock_->NowTicks();
571 capture_begin_event->type = FRAME_CAPTURE_BEGIN; 571 capture_begin_event->type = FRAME_CAPTURE_BEGIN;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 677
678 histogram = subscriber_->GetHistogramForTesting( 678 histogram = subscriber_->GetHistogramForTesting(
679 StatsEventSubscriber::LATE_FRAME_MS_HISTO); 679 StatsEventSubscriber::LATE_FRAME_MS_HISTO);
680 ASSERT_TRUE(histogram); 680 ASSERT_TRUE(histogram);
681 values = histogram->GetHistogram().Pass(); 681 values = histogram->GetHistogram().Pass();
682 EXPECT_TRUE(CheckHistogramHasValue(values.get(), "100-119", 1)); 682 EXPECT_TRUE(CheckHistogramHasValue(values.get(), "100-119", 1));
683 } 683 }
684 684
685 } // namespace cast 685 } // namespace cast
686 } // namespace media 686 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698