Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / cast / logging / logging_raw_unittest.cc
blob0ecfbbf8048f769909badeca25201ef0524ac560
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 "media/cast/logging/logging_defines.h"
6 #include "media/cast/logging/logging_raw.h"
7 #include "media/cast/logging/simple_event_subscriber.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace media {
11 namespace cast {
13 class LoggingRawTest : public ::testing::Test {
14 protected:
15 LoggingRawTest() {
16 raw_.AddSubscriber(&event_subscriber_);
19 ~LoggingRawTest() override { raw_.RemoveSubscriber(&event_subscriber_); }
21 LoggingRaw raw_;
22 SimpleEventSubscriber event_subscriber_;
23 std::vector<FrameEvent> frame_events_;
24 std::vector<PacketEvent> packet_events_;
27 TEST_F(LoggingRawTest, FrameEvent) {
28 CastLoggingEvent event_type = FRAME_DECODED;
29 EventMediaType media_type = VIDEO_EVENT;
30 uint32 frame_id = 456u;
31 RtpTimestamp rtp_timestamp = 123u;
32 base::TimeTicks timestamp = base::TimeTicks();
33 raw_.InsertFrameEvent(timestamp, event_type, media_type,
34 rtp_timestamp, frame_id);
36 event_subscriber_.GetPacketEventsAndReset(&packet_events_);
37 EXPECT_TRUE(packet_events_.empty());
39 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
40 ASSERT_EQ(1u, frame_events_.size());
41 EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp);
42 EXPECT_EQ(frame_id, frame_events_[0].frame_id);
43 EXPECT_EQ(0u, frame_events_[0].size);
44 EXPECT_EQ(timestamp, frame_events_[0].timestamp);
45 EXPECT_EQ(event_type, frame_events_[0].type);
46 EXPECT_EQ(media_type, frame_events_[0].media_type);
47 EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta);
50 TEST_F(LoggingRawTest, EncodedFrameEvent) {
51 CastLoggingEvent event_type = FRAME_ENCODED;
52 EventMediaType media_type = VIDEO_EVENT;
53 uint32 frame_id = 456u;
54 RtpTimestamp rtp_timestamp = 123u;
55 base::TimeTicks timestamp = base::TimeTicks();
56 int size = 1024;
57 bool key_frame = true;
58 int target_bitrate = 4096;
59 double encoder_cpu_utilization = 0.11;
60 double idealized_bitrate_utilization = 0.98;
61 raw_.InsertEncodedFrameEvent(timestamp, event_type, media_type,
62 rtp_timestamp, frame_id, size, key_frame, target_bitrate,
63 encoder_cpu_utilization, idealized_bitrate_utilization);
65 event_subscriber_.GetPacketEventsAndReset(&packet_events_);
66 EXPECT_TRUE(packet_events_.empty());
68 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
69 ASSERT_EQ(1u, frame_events_.size());
70 EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp);
71 EXPECT_EQ(frame_id, frame_events_[0].frame_id);
72 EXPECT_EQ(size, static_cast<int>(frame_events_[0].size));
73 EXPECT_EQ(timestamp, frame_events_[0].timestamp);
74 EXPECT_EQ(event_type, frame_events_[0].type);
75 EXPECT_EQ(media_type, frame_events_[0].media_type);
76 EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta);
77 EXPECT_EQ(key_frame, frame_events_[0].key_frame);
78 EXPECT_EQ(target_bitrate, frame_events_[0].target_bitrate);
79 EXPECT_EQ(encoder_cpu_utilization, frame_events_[0].encoder_cpu_utilization);
80 EXPECT_EQ(idealized_bitrate_utilization,
81 frame_events_[0].idealized_bitrate_utilization);
84 TEST_F(LoggingRawTest, FrameEventWithDelay) {
85 CastLoggingEvent event_type = FRAME_PLAYOUT;
86 EventMediaType media_type = VIDEO_EVENT;
87 uint32 frame_id = 456u;
88 RtpTimestamp rtp_timestamp = 123u;
89 base::TimeTicks timestamp = base::TimeTicks();
90 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(20);
91 raw_.InsertFrameEventWithDelay(timestamp, event_type, media_type,
92 rtp_timestamp, frame_id, delay);
94 event_subscriber_.GetPacketEventsAndReset(&packet_events_);
95 EXPECT_TRUE(packet_events_.empty());
97 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
98 ASSERT_EQ(1u, frame_events_.size());
99 EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp);
100 EXPECT_EQ(frame_id, frame_events_[0].frame_id);
101 EXPECT_EQ(0u, frame_events_[0].size);
102 EXPECT_EQ(timestamp, frame_events_[0].timestamp);
103 EXPECT_EQ(event_type, frame_events_[0].type);
104 EXPECT_EQ(media_type, frame_events_[0].media_type);
105 EXPECT_EQ(delay, frame_events_[0].delay_delta);
108 TEST_F(LoggingRawTest, PacketEvent) {
109 CastLoggingEvent event_type = PACKET_RECEIVED;
110 EventMediaType media_type = VIDEO_EVENT;
111 uint32 frame_id = 456u;
112 uint16 packet_id = 1u;
113 uint16 max_packet_id = 10u;
114 RtpTimestamp rtp_timestamp = 123u;
115 base::TimeTicks timestamp = base::TimeTicks();
116 size_t size = 1024u;
117 raw_.InsertPacketEvent(timestamp, event_type, media_type,
118 rtp_timestamp, frame_id, packet_id, max_packet_id, size);
120 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
121 EXPECT_TRUE(frame_events_.empty());
123 event_subscriber_.GetPacketEventsAndReset(&packet_events_);
124 ASSERT_EQ(1u, packet_events_.size());
126 EXPECT_EQ(rtp_timestamp, packet_events_[0].rtp_timestamp);
127 EXPECT_EQ(frame_id, packet_events_[0].frame_id);
128 EXPECT_EQ(max_packet_id, packet_events_[0].max_packet_id);
129 EXPECT_EQ(packet_id, packet_events_[0].packet_id);
130 EXPECT_EQ(size, packet_events_[0].size);
131 EXPECT_EQ(timestamp, packet_events_[0].timestamp);
132 EXPECT_EQ(event_type, packet_events_[0].type);
133 EXPECT_EQ(media_type, packet_events_[0].media_type);
136 TEST_F(LoggingRawTest, MultipleSubscribers) {
137 SimpleEventSubscriber event_subscriber_2;
139 // Now raw_ has two subscribers.
140 raw_.AddSubscriber(&event_subscriber_2);
142 CastLoggingEvent event_type = FRAME_DECODED;
143 EventMediaType media_type = VIDEO_EVENT;
144 uint32 frame_id = 456u;
145 RtpTimestamp rtp_timestamp = 123u;
146 base::TimeTicks timestamp = base::TimeTicks();
147 raw_.InsertFrameEvent(timestamp, event_type, media_type,
148 rtp_timestamp, frame_id);
150 event_subscriber_.GetPacketEventsAndReset(&packet_events_);
151 EXPECT_TRUE(packet_events_.empty());
153 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
154 ASSERT_EQ(1u, frame_events_.size());
155 EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp);
156 EXPECT_EQ(frame_id, frame_events_[0].frame_id);
157 EXPECT_EQ(0u, frame_events_[0].size);
158 EXPECT_EQ(timestamp, frame_events_[0].timestamp);
159 EXPECT_EQ(event_type, frame_events_[0].type);
160 EXPECT_EQ(media_type, frame_events_[0].media_type);
161 EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta);
163 event_subscriber_2.GetPacketEventsAndReset(&packet_events_);
164 EXPECT_TRUE(packet_events_.empty());
166 event_subscriber_2.GetFrameEventsAndReset(&frame_events_);
167 ASSERT_EQ(1u, frame_events_.size());
168 EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp);
169 EXPECT_EQ(frame_id, frame_events_[0].frame_id);
170 EXPECT_EQ(0u, frame_events_[0].size);
171 EXPECT_EQ(timestamp, frame_events_[0].timestamp);
172 EXPECT_EQ(event_type, frame_events_[0].type);
173 EXPECT_EQ(media_type, frame_events_[0].media_type);
174 EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta);
176 // Remove event_subscriber_2, so it shouldn't receive events after this.
177 raw_.RemoveSubscriber(&event_subscriber_2);
179 media_type = AUDIO_EVENT;
180 frame_id = 789;
181 rtp_timestamp = 456;
182 timestamp = base::TimeTicks();
183 raw_.InsertFrameEvent(timestamp, event_type, media_type,
184 rtp_timestamp, frame_id);
186 // |event_subscriber_| should still receive events.
187 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
188 ASSERT_EQ(1u, frame_events_.size());
189 EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp);
190 EXPECT_EQ(frame_id, frame_events_[0].frame_id);
191 EXPECT_EQ(0u, frame_events_[0].size);
192 EXPECT_EQ(timestamp, frame_events_[0].timestamp);
193 EXPECT_EQ(event_type, frame_events_[0].type);
194 EXPECT_EQ(media_type, frame_events_[0].media_type);
195 EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta);
197 event_subscriber_2.GetFrameEventsAndReset(&frame_events_);
198 EXPECT_TRUE(frame_events_.empty());
201 } // namespace cast
202 } // namespace media