Remove INJECT_EVENTS permissions from test APKs.
[chromium-blink-merge.git] / media / cast / logging / encoding_event_subscriber_unittest.cc
blobb052bbb889344cb097bac3d8c4907c8793f72524
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
3 // found in the LICENSE file.
5 #include "base/memory/ref_counted.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/test/simple_test_tick_clock.h"
8 #include "base/time/tick_clock.h"
9 #include "media/cast/cast_environment.h"
10 #include "media/cast/logging/encoding_event_subscriber.h"
11 #include "media/cast/logging/logging_defines.h"
12 #include "media/cast/test/fake_single_thread_task_runner.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 using media::cast::proto::AggregatedFrameEvent;
16 using media::cast::proto::AggregatedPacketEvent;
17 using media::cast::proto::BasePacketEvent;
18 using media::cast::proto::LogMetadata;
20 namespace {
22 int64 InMilliseconds(base::TimeTicks event_time) {
23 return (event_time - base::TimeTicks()).InMilliseconds();
28 namespace media {
29 namespace cast {
31 class EncodingEventSubscriberTest : public ::testing::Test {
32 protected:
33 EncodingEventSubscriberTest()
34 : testing_clock_(new base::SimpleTestTickClock()),
35 task_runner_(new test::FakeSingleThreadTaskRunner(testing_clock_)),
36 cast_environment_(new CastEnvironment(
37 scoped_ptr<base::TickClock>(testing_clock_).Pass(),
38 task_runner_,
39 task_runner_,
40 task_runner_)),
41 first_rtp_timestamp_(0) {}
43 void Init(EventMediaType event_media_type) {
44 DCHECK(!event_subscriber_);
45 event_subscriber_.reset(new EncodingEventSubscriber(event_media_type, 10));
46 cast_environment_->Logging()->AddRawEventSubscriber(
47 event_subscriber_.get());
50 ~EncodingEventSubscriberTest() override {
51 if (event_subscriber_) {
52 cast_environment_->Logging()->RemoveRawEventSubscriber(
53 event_subscriber_.get());
57 void GetEventsAndReset() {
58 event_subscriber_->GetEventsAndReset(
59 &metadata_, &frame_events_, &packet_events_);
60 first_rtp_timestamp_ = metadata_.first_rtp_timestamp();
63 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment.
64 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
65 scoped_refptr<CastEnvironment> cast_environment_;
66 scoped_ptr<EncodingEventSubscriber> event_subscriber_;
67 FrameEventList frame_events_;
68 PacketEventList packet_events_;
69 LogMetadata metadata_;
70 RtpTimestamp first_rtp_timestamp_;
73 TEST_F(EncodingEventSubscriberTest, FrameEventTruncating) {
74 Init(VIDEO_EVENT);
76 base::TimeTicks now(testing_clock_->NowTicks());
78 // Entry with RTP timestamp 0 should get dropped.
79 int width = 320;
80 int height = 180;
81 for (int i = 0; i < 11; i++) {
82 cast_environment_->Logging()->InsertFrameEvent(now,
83 FRAME_CAPTURE_BEGIN,
84 VIDEO_EVENT,
85 i * 100,
86 /*frame_id*/ 0);
87 cast_environment_->Logging()->InsertCapturedVideoFrameEvent(now,
88 i * 100,
89 width,
90 height);
91 cast_environment_->Logging()->InsertFrameEvent(now,
92 FRAME_DECODED,
93 VIDEO_EVENT,
94 i * 100,
95 /*frame_id*/ 0);
96 width += 160;
97 height += 90;
100 GetEventsAndReset();
102 ASSERT_EQ(10u, frame_events_.size());
103 EXPECT_EQ(100u, frame_events_.front()->relative_rtp_timestamp());
104 EXPECT_EQ(1000u, frame_events_.back()->relative_rtp_timestamp());
105 width = 320;
106 height = 180;
107 for (const auto& event : frame_events_) {
108 width += 160;
109 height += 90;
110 EXPECT_EQ(width, event->width());
111 EXPECT_EQ(height, event->height());
115 TEST_F(EncodingEventSubscriberTest, PacketEventTruncating) {
116 Init(AUDIO_EVENT);
118 base::TimeTicks now(testing_clock_->NowTicks());
120 // Entry with RTP timestamp 0 should get dropped.
121 for (int i = 0; i < 11; i++) {
122 cast_environment_->Logging()->InsertPacketEvent(now,
123 PACKET_RECEIVED,
124 AUDIO_EVENT,
125 /*rtp_timestamp*/ i * 100,
126 /*frame_id*/ 0,
127 /*packet_id*/ i,
128 /*max_packet_id*/ 10,
129 /*size*/ 123);
132 GetEventsAndReset();
134 ASSERT_EQ(10u, packet_events_.size());
135 EXPECT_EQ(100u, packet_events_.front()->relative_rtp_timestamp());
136 EXPECT_EQ(1000u, packet_events_.back()->relative_rtp_timestamp());
139 TEST_F(EncodingEventSubscriberTest, EventFiltering) {
140 Init(VIDEO_EVENT);
142 base::TimeTicks now(testing_clock_->NowTicks());
143 RtpTimestamp rtp_timestamp = 100;
144 cast_environment_->Logging()->InsertFrameEvent(now,
145 FRAME_DECODED,
146 VIDEO_EVENT,
147 rtp_timestamp,
148 /*frame_id*/ 0);
150 // This is an AUDIO_EVENT and shouldn't be processed by the subscriber.
151 cast_environment_->Logging()->InsertFrameEvent(now,
152 FRAME_DECODED,
153 AUDIO_EVENT,
154 rtp_timestamp,
155 /*frame_id*/ 0);
157 GetEventsAndReset();
159 ASSERT_EQ(1u, frame_events_.size());
160 FrameEventList::iterator it = frame_events_.begin();
162 linked_ptr<AggregatedFrameEvent> frame_event = *it;
164 ASSERT_EQ(1, frame_event->event_type_size());
165 EXPECT_EQ(media::cast::proto::FRAME_DECODED,
166 frame_event->event_type(0));
168 GetEventsAndReset();
170 EXPECT_TRUE(packet_events_.empty());
173 TEST_F(EncodingEventSubscriberTest, FrameEvent) {
174 Init(VIDEO_EVENT);
175 base::TimeTicks now(testing_clock_->NowTicks());
176 RtpTimestamp rtp_timestamp = 100;
177 cast_environment_->Logging()->InsertFrameEvent(now, FRAME_DECODED,
178 VIDEO_EVENT,
179 rtp_timestamp,
180 /*frame_id*/ 0);
182 GetEventsAndReset();
184 ASSERT_EQ(1u, frame_events_.size());
186 RtpTimestamp relative_rtp_timestamp = rtp_timestamp - first_rtp_timestamp_;
187 FrameEventList::iterator it = frame_events_.begin();
189 linked_ptr<AggregatedFrameEvent> event = *it;
191 EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
193 ASSERT_EQ(1, event->event_type_size());
194 EXPECT_EQ(media::cast::proto::FRAME_DECODED, event->event_type(0));
195 ASSERT_EQ(1, event->event_timestamp_ms_size());
196 EXPECT_EQ(InMilliseconds(now), event->event_timestamp_ms(0));
198 EXPECT_EQ(0, event->encoded_frame_size());
199 EXPECT_EQ(0, event->delay_millis());
201 GetEventsAndReset();
202 EXPECT_TRUE(frame_events_.empty());
205 TEST_F(EncodingEventSubscriberTest, FrameEventDelay) {
206 Init(AUDIO_EVENT);
207 base::TimeTicks now(testing_clock_->NowTicks());
208 RtpTimestamp rtp_timestamp = 100;
209 int delay_ms = 100;
210 cast_environment_->Logging()->InsertFrameEventWithDelay(
211 now, FRAME_PLAYOUT, AUDIO_EVENT, rtp_timestamp,
212 /*frame_id*/ 0, base::TimeDelta::FromMilliseconds(delay_ms));
214 GetEventsAndReset();
216 ASSERT_EQ(1u, frame_events_.size());
218 RtpTimestamp relative_rtp_timestamp = rtp_timestamp - first_rtp_timestamp_;
219 FrameEventList::iterator it = frame_events_.begin();
221 linked_ptr<AggregatedFrameEvent> event = *it;
223 EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
225 ASSERT_EQ(1, event->event_type_size());
226 EXPECT_EQ(media::cast::proto::FRAME_PLAYOUT, event->event_type(0));
227 ASSERT_EQ(1, event->event_timestamp_ms_size());
228 EXPECT_EQ(InMilliseconds(now), event->event_timestamp_ms(0));
230 EXPECT_EQ(0, event->encoded_frame_size());
231 EXPECT_EQ(100, event->delay_millis());
232 EXPECT_FALSE(event->has_key_frame());
235 TEST_F(EncodingEventSubscriberTest, FrameEventSize) {
236 Init(VIDEO_EVENT);
237 base::TimeTicks now(testing_clock_->NowTicks());
238 RtpTimestamp rtp_timestamp = 100;
239 int size = 123;
240 bool key_frame = true;
241 int target_bitrate = 1024;
242 double encoder_cpu_utilization = 0.90;
243 double idealized_bitrate_utilization = 0.42;
244 cast_environment_->Logging()->InsertEncodedFrameEvent(
245 now, FRAME_ENCODED, VIDEO_EVENT, rtp_timestamp,
246 /*frame_id*/ 0, size, key_frame, target_bitrate,
247 encoder_cpu_utilization, idealized_bitrate_utilization);
249 GetEventsAndReset();
251 ASSERT_EQ(1u, frame_events_.size());
253 RtpTimestamp relative_rtp_timestamp = rtp_timestamp - first_rtp_timestamp_;
254 FrameEventList::iterator it = frame_events_.begin();
256 linked_ptr<AggregatedFrameEvent> event = *it;
258 EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
260 ASSERT_EQ(1, event->event_type_size());
261 EXPECT_EQ(media::cast::proto::FRAME_ENCODED, event->event_type(0));
262 ASSERT_EQ(1, event->event_timestamp_ms_size());
263 EXPECT_EQ(InMilliseconds(now), event->event_timestamp_ms(0));
265 EXPECT_EQ(size, event->encoded_frame_size());
266 EXPECT_EQ(0, event->delay_millis());
267 EXPECT_TRUE(event->has_key_frame());
268 EXPECT_EQ(key_frame, event->key_frame());
269 EXPECT_EQ(target_bitrate, event->target_bitrate());
270 EXPECT_EQ(90, event->encoder_cpu_percent_utilized());
271 EXPECT_EQ(42, event->idealized_bitrate_percent_utilized());
274 TEST_F(EncodingEventSubscriberTest, MultipleFrameEvents) {
275 Init(AUDIO_EVENT);
276 RtpTimestamp rtp_timestamp1 = 100;
277 RtpTimestamp rtp_timestamp2 = 200;
278 base::TimeTicks now1(testing_clock_->NowTicks());
279 cast_environment_->Logging()->InsertFrameEventWithDelay(
280 now1, FRAME_PLAYOUT, AUDIO_EVENT, rtp_timestamp1,
281 /*frame_id*/ 0, /*delay*/ base::TimeDelta::FromMilliseconds(100));
283 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(20));
284 base::TimeTicks now2(testing_clock_->NowTicks());
285 cast_environment_->Logging()->InsertEncodedFrameEvent(
286 now2, FRAME_ENCODED, AUDIO_EVENT, rtp_timestamp2,
287 /*frame_id*/ 0, /*size*/ 123, /* key_frame - unused */ false,
288 /*target_bitrate - unused*/ 0,
289 0.44, 0.55);
291 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(20));
292 base::TimeTicks now3(testing_clock_->NowTicks());
293 cast_environment_->Logging()->InsertFrameEvent(
294 now3, FRAME_DECODED, AUDIO_EVENT, rtp_timestamp1, /*frame_id*/ 0);
296 GetEventsAndReset();
298 ASSERT_EQ(2u, frame_events_.size());
300 RtpTimestamp relative_rtp_timestamp = rtp_timestamp1 - first_rtp_timestamp_;
301 FrameEventList::iterator it = frame_events_.begin();
303 linked_ptr<AggregatedFrameEvent> event = *it;
305 EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
307 ASSERT_EQ(2, event->event_type_size());
308 EXPECT_EQ(media::cast::proto::FRAME_PLAYOUT, event->event_type(0));
309 EXPECT_EQ(media::cast::proto::FRAME_DECODED, event->event_type(1));
311 ASSERT_EQ(2, event->event_timestamp_ms_size());
312 EXPECT_EQ(InMilliseconds(now1), event->event_timestamp_ms(0));
313 EXPECT_EQ(InMilliseconds(now3), event->event_timestamp_ms(1));
315 EXPECT_FALSE(event->has_key_frame());
317 relative_rtp_timestamp = rtp_timestamp2 - first_rtp_timestamp_;
318 ++it;
320 event = *it;
322 EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
324 ASSERT_EQ(1, event->event_type_size());
325 EXPECT_EQ(media::cast::proto::FRAME_ENCODED, event->event_type(0));
327 ASSERT_EQ(1, event->event_timestamp_ms_size());
328 EXPECT_EQ(InMilliseconds(now2), event->event_timestamp_ms(0));
330 EXPECT_FALSE(event->has_key_frame());
331 EXPECT_EQ(44, event->encoder_cpu_percent_utilized());
332 EXPECT_EQ(55, event->idealized_bitrate_percent_utilized());
335 TEST_F(EncodingEventSubscriberTest, PacketEvent) {
336 Init(AUDIO_EVENT);
337 base::TimeTicks now(testing_clock_->NowTicks());
338 RtpTimestamp rtp_timestamp = 100;
339 int packet_id = 2;
340 int size = 100;
341 cast_environment_->Logging()->InsertPacketEvent(
342 now, PACKET_RECEIVED, AUDIO_EVENT,
343 rtp_timestamp, /*frame_id*/ 0, packet_id,
344 /*max_packet_id*/ 10, size);
346 GetEventsAndReset();
348 ASSERT_EQ(1u, packet_events_.size());
350 RtpTimestamp relative_rtp_timestamp = rtp_timestamp - first_rtp_timestamp_;
351 PacketEventList::iterator it = packet_events_.begin();
353 linked_ptr<AggregatedPacketEvent> event = *it;
355 EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
357 ASSERT_EQ(1, event->base_packet_event_size());
358 const BasePacketEvent& base_event = event->base_packet_event(0);
359 EXPECT_EQ(packet_id, base_event.packet_id());
360 ASSERT_EQ(1, base_event.event_type_size());
361 EXPECT_EQ(media::cast::proto::PACKET_RECEIVED,
362 base_event.event_type(0));
363 ASSERT_EQ(1, base_event.event_timestamp_ms_size());
364 EXPECT_EQ(InMilliseconds(now), base_event.event_timestamp_ms(0));
365 EXPECT_EQ(size, base_event.size());
367 GetEventsAndReset();
368 EXPECT_TRUE(packet_events_.empty());
371 TEST_F(EncodingEventSubscriberTest, MultiplePacketEventsForPacket) {
372 Init(VIDEO_EVENT);
373 base::TimeTicks now1(testing_clock_->NowTicks());
374 RtpTimestamp rtp_timestamp = 100;
375 int packet_id = 2;
376 int size = 100;
377 cast_environment_->Logging()->InsertPacketEvent(now1,
378 PACKET_SENT_TO_NETWORK,
379 VIDEO_EVENT,
380 rtp_timestamp,
381 /*frame_id*/ 0,
382 packet_id,
383 /*max_packet_id*/ 10,
384 size);
386 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(20));
387 base::TimeTicks now2(testing_clock_->NowTicks());
388 cast_environment_->Logging()->InsertPacketEvent(now2,
389 PACKET_RETRANSMITTED,
390 VIDEO_EVENT,
391 rtp_timestamp,
392 /*frame_id*/ 0,
393 packet_id,
394 /*max_packet_id*/ 10,
395 size);
397 GetEventsAndReset();
399 ASSERT_EQ(1u, packet_events_.size());
401 RtpTimestamp relative_rtp_timestamp = rtp_timestamp - first_rtp_timestamp_;
402 PacketEventList::iterator it = packet_events_.begin();
404 linked_ptr<AggregatedPacketEvent> event = *it;
406 EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
408 ASSERT_EQ(1, event->base_packet_event_size());
409 const BasePacketEvent& base_event = event->base_packet_event(0);
410 EXPECT_EQ(packet_id, base_event.packet_id());
411 ASSERT_EQ(2, base_event.event_type_size());
412 EXPECT_EQ(media::cast::proto::PACKET_SENT_TO_NETWORK,
413 base_event.event_type(0));
414 EXPECT_EQ(media::cast::proto::PACKET_RETRANSMITTED,
415 base_event.event_type(1));
416 ASSERT_EQ(2, base_event.event_timestamp_ms_size());
417 EXPECT_EQ(InMilliseconds(now1), base_event.event_timestamp_ms(0));
418 EXPECT_EQ(InMilliseconds(now2), base_event.event_timestamp_ms(1));
421 TEST_F(EncodingEventSubscriberTest, MultiplePacketEventsForFrame) {
422 Init(VIDEO_EVENT);
423 base::TimeTicks now1(testing_clock_->NowTicks());
424 RtpTimestamp rtp_timestamp = 100;
425 int packet_id_1 = 2;
426 int packet_id_2 = 3;
427 int size = 100;
428 cast_environment_->Logging()->InsertPacketEvent(now1,
429 PACKET_SENT_TO_NETWORK,
430 VIDEO_EVENT,
431 rtp_timestamp,
432 /*frame_id*/ 0,
433 packet_id_1,
434 /*max_packet_id*/ 10,
435 size);
437 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(20));
438 base::TimeTicks now2(testing_clock_->NowTicks());
439 cast_environment_->Logging()->InsertPacketEvent(now2,
440 PACKET_RETRANSMITTED,
441 VIDEO_EVENT,
442 rtp_timestamp,
443 /*frame_id*/ 0,
444 packet_id_2,
445 /*max_packet_id*/ 10,
446 size);
448 GetEventsAndReset();
450 ASSERT_EQ(1u, packet_events_.size());
452 RtpTimestamp relative_rtp_timestamp = rtp_timestamp - first_rtp_timestamp_;
453 PacketEventList::iterator it = packet_events_.begin();
455 linked_ptr<AggregatedPacketEvent> event = *it;
457 EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
459 ASSERT_EQ(2, event->base_packet_event_size());
460 const BasePacketEvent& base_event = event->base_packet_event(0);
461 EXPECT_EQ(packet_id_1, base_event.packet_id());
462 ASSERT_EQ(1, base_event.event_type_size());
463 EXPECT_EQ(media::cast::proto::PACKET_SENT_TO_NETWORK,
464 base_event.event_type(0));
465 ASSERT_EQ(1, base_event.event_timestamp_ms_size());
466 EXPECT_EQ(InMilliseconds(now1), base_event.event_timestamp_ms(0));
468 const BasePacketEvent& base_event_2 = event->base_packet_event(1);
469 EXPECT_EQ(packet_id_2, base_event_2.packet_id());
470 ASSERT_EQ(1, base_event_2.event_type_size());
471 EXPECT_EQ(media::cast::proto::PACKET_RETRANSMITTED,
472 base_event_2.event_type(0));
473 ASSERT_EQ(1, base_event_2.event_timestamp_ms_size());
474 EXPECT_EQ(InMilliseconds(now2), base_event_2.event_timestamp_ms(0));
477 TEST_F(EncodingEventSubscriberTest, MultiplePacketEvents) {
478 Init(VIDEO_EVENT);
479 base::TimeTicks now1(testing_clock_->NowTicks());
480 RtpTimestamp rtp_timestamp_1 = 100;
481 RtpTimestamp rtp_timestamp_2 = 200;
482 int packet_id_1 = 2;
483 int packet_id_2 = 3;
484 int size = 100;
485 cast_environment_->Logging()->InsertPacketEvent(now1,
486 PACKET_SENT_TO_NETWORK,
487 VIDEO_EVENT,
488 rtp_timestamp_1,
489 /*frame_id*/ 0,
490 packet_id_1,
491 /*max_packet_id*/ 10,
492 size);
494 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(20));
495 base::TimeTicks now2(testing_clock_->NowTicks());
496 cast_environment_->Logging()->InsertPacketEvent(now2,
497 PACKET_RETRANSMITTED,
498 VIDEO_EVENT,
499 rtp_timestamp_2,
500 /*frame_id*/ 0,
501 packet_id_2,
502 /*max_packet_id*/ 10,
503 size);
505 GetEventsAndReset();
507 ASSERT_EQ(2u, packet_events_.size());
509 RtpTimestamp relative_rtp_timestamp = rtp_timestamp_1 - first_rtp_timestamp_;
510 PacketEventList::iterator it = packet_events_.begin();
512 linked_ptr<AggregatedPacketEvent> event = *it;
514 EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
516 ASSERT_EQ(1, event->base_packet_event_size());
517 const BasePacketEvent& base_event = event->base_packet_event(0);
518 EXPECT_EQ(packet_id_1, base_event.packet_id());
519 ASSERT_EQ(1, base_event.event_type_size());
520 EXPECT_EQ(media::cast::proto::PACKET_SENT_TO_NETWORK,
521 base_event.event_type(0));
522 ASSERT_EQ(1, base_event.event_timestamp_ms_size());
523 EXPECT_EQ(InMilliseconds(now1), base_event.event_timestamp_ms(0));
525 relative_rtp_timestamp = rtp_timestamp_2 - first_rtp_timestamp_;
526 ++it;
527 ASSERT_TRUE(it != packet_events_.end());
529 event = *it;
530 EXPECT_EQ(relative_rtp_timestamp, event->relative_rtp_timestamp());
532 ASSERT_EQ(1, event->base_packet_event_size());
533 const BasePacketEvent& base_event_2 = event->base_packet_event(0);
534 EXPECT_EQ(packet_id_2, base_event_2.packet_id());
535 ASSERT_EQ(1, base_event_2.event_type_size());
536 EXPECT_EQ(media::cast::proto::PACKET_RETRANSMITTED,
537 base_event_2.event_type(0));
538 ASSERT_EQ(1, base_event_2.event_timestamp_ms_size());
539 EXPECT_EQ(InMilliseconds(now2), base_event_2.event_timestamp_ms(0));
542 TEST_F(EncodingEventSubscriberTest, FirstRtpTimestamp) {
543 Init(VIDEO_EVENT);
544 RtpTimestamp rtp_timestamp = 12345;
545 base::TimeTicks now(testing_clock_->NowTicks());
547 cast_environment_->Logging()->InsertFrameEvent(now,
548 FRAME_CAPTURE_BEGIN,
549 VIDEO_EVENT,
550 rtp_timestamp,
551 /*frame_id*/ 0);
553 cast_environment_->Logging()->InsertCapturedVideoFrameEvent(
554 now,
555 rtp_timestamp + 30,
556 1280, 720);
558 GetEventsAndReset();
560 EXPECT_EQ(rtp_timestamp, first_rtp_timestamp_);
561 FrameEventList::iterator it = frame_events_.begin();
562 ASSERT_NE(frame_events_.end(), it);
563 EXPECT_EQ(0u, (*it)->relative_rtp_timestamp());
565 ++it;
566 ASSERT_NE(frame_events_.end(), it);
567 EXPECT_EQ(30u, (*it)->relative_rtp_timestamp());
568 EXPECT_EQ(1280, (*it)->width());
569 EXPECT_EQ(720, (*it)->height());
571 rtp_timestamp = 67890;
573 cast_environment_->Logging()->InsertFrameEvent(now,
574 FRAME_CAPTURE_BEGIN,
575 VIDEO_EVENT,
576 rtp_timestamp,
577 /*frame_id*/ 0);
578 GetEventsAndReset();
580 EXPECT_EQ(rtp_timestamp, first_rtp_timestamp_);
583 TEST_F(EncodingEventSubscriberTest, RelativeRtpTimestampWrapAround) {
584 Init(VIDEO_EVENT);
585 RtpTimestamp rtp_timestamp = 0xffffffff - 20;
586 base::TimeTicks now(testing_clock_->NowTicks());
588 cast_environment_->Logging()->InsertFrameEvent(now,
589 FRAME_CAPTURE_BEGIN,
590 VIDEO_EVENT,
591 rtp_timestamp,
592 /*frame_id*/ 0);
594 // RtpTimestamp has now wrapped around.
595 cast_environment_->Logging()->InsertCapturedVideoFrameEvent(
596 now,
597 rtp_timestamp + 30,
598 1280, 720);
600 GetEventsAndReset();
602 FrameEventList::iterator it = frame_events_.begin();
603 ASSERT_NE(frame_events_.end(), it);
604 EXPECT_EQ(0u, (*it)->relative_rtp_timestamp());
606 ++it;
607 ASSERT_NE(frame_events_.end(), it);
608 EXPECT_EQ(30u, (*it)->relative_rtp_timestamp());
609 EXPECT_EQ(1280, (*it)->width());
610 EXPECT_EQ(720, (*it)->height());
613 TEST_F(EncodingEventSubscriberTest, MaxEventsPerProto) {
614 Init(VIDEO_EVENT);
615 RtpTimestamp rtp_timestamp = 100;
616 for (int i = 0; i < kMaxEventsPerProto + 1; i++) {
617 cast_environment_->Logging()->InsertFrameEvent(testing_clock_->NowTicks(),
618 FRAME_ACK_RECEIVED,
619 VIDEO_EVENT,
620 rtp_timestamp,
621 /*frame_id*/ 0);
622 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30));
625 GetEventsAndReset();
627 ASSERT_EQ(2u, frame_events_.size());
628 FrameEventList::iterator frame_it = frame_events_.begin();
629 ASSERT_TRUE(frame_it != frame_events_.end());
631 linked_ptr<AggregatedFrameEvent> frame_event = *frame_it;
633 EXPECT_EQ(kMaxEventsPerProto, frame_event->event_type_size());
635 for (int i = 0; i < kMaxPacketsPerFrame + 1; i++) {
636 cast_environment_->Logging()->InsertPacketEvent(
637 testing_clock_->NowTicks(),
638 PACKET_SENT_TO_NETWORK,
639 VIDEO_EVENT,
640 rtp_timestamp,
641 /*frame_id*/ 0,
643 kMaxPacketsPerFrame,
644 123);
645 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30));
648 GetEventsAndReset();
650 EXPECT_EQ(2u, packet_events_.size());
652 PacketEventList::iterator packet_it = packet_events_.begin();
653 ASSERT_TRUE(packet_it != packet_events_.end());
655 linked_ptr<AggregatedPacketEvent> packet_event = *packet_it;
657 EXPECT_EQ(kMaxPacketsPerFrame,
658 packet_event->base_packet_event_size());
660 ++packet_it;
661 packet_event = *packet_it;
662 EXPECT_EQ(1, packet_event->base_packet_event_size());
664 for (int j = 0; j < kMaxEventsPerProto + 1; j++) {
665 cast_environment_->Logging()->InsertPacketEvent(
666 testing_clock_->NowTicks(),
667 PACKET_SENT_TO_NETWORK,
668 VIDEO_EVENT,
669 rtp_timestamp,
670 /*frame_id*/ 0,
673 123);
674 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(30));
677 GetEventsAndReset();
679 EXPECT_EQ(2u, packet_events_.size());
680 packet_it = packet_events_.begin();
681 ASSERT_TRUE(packet_it != packet_events_.end());
683 packet_event = *packet_it;
685 EXPECT_EQ(kMaxEventsPerProto,
686 packet_event->base_packet_event(0).event_type_size());
688 ++packet_it;
689 packet_event = *packet_it;
690 EXPECT_EQ(1, packet_event->base_packet_event(0).event_type_size());
693 } // namespace cast
694 } // namespace media