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"
13 class LoggingRawTest
: public ::testing::Test
{
16 raw_
.AddSubscriber(&event_subscriber_
);
19 virtual ~LoggingRawTest() { raw_
.RemoveSubscriber(&event_subscriber_
); }
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();
57 bool key_frame
= true;
58 int target_bitrate
= 4096;
59 raw_
.InsertEncodedFrameEvent(timestamp
, event_type
, media_type
,
60 rtp_timestamp
, frame_id
, size
, key_frame
, target_bitrate
);
62 event_subscriber_
.GetPacketEventsAndReset(&packet_events_
);
63 EXPECT_TRUE(packet_events_
.empty());
65 event_subscriber_
.GetFrameEventsAndReset(&frame_events_
);
66 ASSERT_EQ(1u, frame_events_
.size());
67 EXPECT_EQ(rtp_timestamp
, frame_events_
[0].rtp_timestamp
);
68 EXPECT_EQ(frame_id
, frame_events_
[0].frame_id
);
69 EXPECT_EQ(size
, static_cast<int>(frame_events_
[0].size
));
70 EXPECT_EQ(timestamp
, frame_events_
[0].timestamp
);
71 EXPECT_EQ(event_type
, frame_events_
[0].type
);
72 EXPECT_EQ(media_type
, frame_events_
[0].media_type
);
73 EXPECT_EQ(base::TimeDelta(), frame_events_
[0].delay_delta
);
74 EXPECT_EQ(key_frame
, frame_events_
[0].key_frame
);
75 EXPECT_EQ(target_bitrate
, frame_events_
[0].target_bitrate
);
78 TEST_F(LoggingRawTest
, FrameEventWithDelay
) {
79 CastLoggingEvent event_type
= FRAME_PLAYOUT
;
80 EventMediaType media_type
= VIDEO_EVENT
;
81 uint32 frame_id
= 456u;
82 RtpTimestamp rtp_timestamp
= 123u;
83 base::TimeTicks timestamp
= base::TimeTicks();
84 base::TimeDelta delay
= base::TimeDelta::FromMilliseconds(20);
85 raw_
.InsertFrameEventWithDelay(timestamp
, event_type
, media_type
,
86 rtp_timestamp
, frame_id
, delay
);
88 event_subscriber_
.GetPacketEventsAndReset(&packet_events_
);
89 EXPECT_TRUE(packet_events_
.empty());
91 event_subscriber_
.GetFrameEventsAndReset(&frame_events_
);
92 ASSERT_EQ(1u, frame_events_
.size());
93 EXPECT_EQ(rtp_timestamp
, frame_events_
[0].rtp_timestamp
);
94 EXPECT_EQ(frame_id
, frame_events_
[0].frame_id
);
95 EXPECT_EQ(0u, frame_events_
[0].size
);
96 EXPECT_EQ(timestamp
, frame_events_
[0].timestamp
);
97 EXPECT_EQ(event_type
, frame_events_
[0].type
);
98 EXPECT_EQ(media_type
, frame_events_
[0].media_type
);
99 EXPECT_EQ(delay
, frame_events_
[0].delay_delta
);
102 TEST_F(LoggingRawTest
, PacketEvent
) {
103 CastLoggingEvent event_type
= PACKET_RECEIVED
;
104 EventMediaType media_type
= VIDEO_EVENT
;
105 uint32 frame_id
= 456u;
106 uint16 packet_id
= 1u;
107 uint16 max_packet_id
= 10u;
108 RtpTimestamp rtp_timestamp
= 123u;
109 base::TimeTicks timestamp
= base::TimeTicks();
111 raw_
.InsertPacketEvent(timestamp
, event_type
, media_type
,
112 rtp_timestamp
, frame_id
, packet_id
, max_packet_id
, size
);
114 event_subscriber_
.GetFrameEventsAndReset(&frame_events_
);
115 EXPECT_TRUE(frame_events_
.empty());
117 event_subscriber_
.GetPacketEventsAndReset(&packet_events_
);
118 ASSERT_EQ(1u, packet_events_
.size());
120 EXPECT_EQ(rtp_timestamp
, packet_events_
[0].rtp_timestamp
);
121 EXPECT_EQ(frame_id
, packet_events_
[0].frame_id
);
122 EXPECT_EQ(max_packet_id
, packet_events_
[0].max_packet_id
);
123 EXPECT_EQ(packet_id
, packet_events_
[0].packet_id
);
124 EXPECT_EQ(size
, packet_events_
[0].size
);
125 EXPECT_EQ(timestamp
, packet_events_
[0].timestamp
);
126 EXPECT_EQ(event_type
, packet_events_
[0].type
);
127 EXPECT_EQ(media_type
, packet_events_
[0].media_type
);
130 TEST_F(LoggingRawTest
, MultipleSubscribers
) {
131 SimpleEventSubscriber event_subscriber_2
;
133 // Now raw_ has two subscribers.
134 raw_
.AddSubscriber(&event_subscriber_2
);
136 CastLoggingEvent event_type
= FRAME_DECODED
;
137 EventMediaType media_type
= VIDEO_EVENT
;
138 uint32 frame_id
= 456u;
139 RtpTimestamp rtp_timestamp
= 123u;
140 base::TimeTicks timestamp
= base::TimeTicks();
141 raw_
.InsertFrameEvent(timestamp
, event_type
, media_type
,
142 rtp_timestamp
, frame_id
);
144 event_subscriber_
.GetPacketEventsAndReset(&packet_events_
);
145 EXPECT_TRUE(packet_events_
.empty());
147 event_subscriber_
.GetFrameEventsAndReset(&frame_events_
);
148 ASSERT_EQ(1u, frame_events_
.size());
149 EXPECT_EQ(rtp_timestamp
, frame_events_
[0].rtp_timestamp
);
150 EXPECT_EQ(frame_id
, frame_events_
[0].frame_id
);
151 EXPECT_EQ(0u, frame_events_
[0].size
);
152 EXPECT_EQ(timestamp
, frame_events_
[0].timestamp
);
153 EXPECT_EQ(event_type
, frame_events_
[0].type
);
154 EXPECT_EQ(media_type
, frame_events_
[0].media_type
);
155 EXPECT_EQ(base::TimeDelta(), frame_events_
[0].delay_delta
);
157 event_subscriber_2
.GetPacketEventsAndReset(&packet_events_
);
158 EXPECT_TRUE(packet_events_
.empty());
160 event_subscriber_2
.GetFrameEventsAndReset(&frame_events_
);
161 ASSERT_EQ(1u, frame_events_
.size());
162 EXPECT_EQ(rtp_timestamp
, frame_events_
[0].rtp_timestamp
);
163 EXPECT_EQ(frame_id
, frame_events_
[0].frame_id
);
164 EXPECT_EQ(0u, frame_events_
[0].size
);
165 EXPECT_EQ(timestamp
, frame_events_
[0].timestamp
);
166 EXPECT_EQ(event_type
, frame_events_
[0].type
);
167 EXPECT_EQ(media_type
, frame_events_
[0].media_type
);
168 EXPECT_EQ(base::TimeDelta(), frame_events_
[0].delay_delta
);
170 // Remove event_subscriber_2, so it shouldn't receive events after this.
171 raw_
.RemoveSubscriber(&event_subscriber_2
);
173 media_type
= AUDIO_EVENT
;
176 timestamp
= base::TimeTicks();
177 raw_
.InsertFrameEvent(timestamp
, event_type
, media_type
,
178 rtp_timestamp
, frame_id
);
180 // |event_subscriber_| should still receive events.
181 event_subscriber_
.GetFrameEventsAndReset(&frame_events_
);
182 ASSERT_EQ(1u, frame_events_
.size());
183 EXPECT_EQ(rtp_timestamp
, frame_events_
[0].rtp_timestamp
);
184 EXPECT_EQ(frame_id
, frame_events_
[0].frame_id
);
185 EXPECT_EQ(0u, frame_events_
[0].size
);
186 EXPECT_EQ(timestamp
, frame_events_
[0].timestamp
);
187 EXPECT_EQ(event_type
, frame_events_
[0].type
);
188 EXPECT_EQ(media_type
, frame_events_
[0].media_type
);
189 EXPECT_EQ(base::TimeDelta(), frame_events_
[0].delay_delta
);
191 event_subscriber_2
.GetFrameEventsAndReset(&frame_events_
);
192 EXPECT_TRUE(frame_events_
.empty());