OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifdef ENABLE_RTC_EVENT_LOG | 11 #ifdef ENABLE_RTC_EVENT_LOG |
12 | 12 |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/scoped_ptr.h" | 19 #include "webrtc/base/scoped_ptr.h" |
20 #include "webrtc/call.h" | 20 #include "webrtc/call.h" |
21 #include "webrtc/system_wrappers/interface/clock.h" | 21 #include "webrtc/system_wrappers/interface/clock.h" |
22 #include "webrtc/test/test_suite.h" | 22 #include "webrtc/test/test_suite.h" |
23 #include "webrtc/test/testsupport/fileutils.h" | 23 #include "webrtc/test/testsupport/fileutils.h" |
24 #include "webrtc/test/testsupport/gtest_disable.h" | 24 #include "webrtc/test/testsupport/gtest_disable.h" |
25 #include "webrtc/video/rtc_event_log.h" | 25 #include "webrtc/video/rtc_event_log.h" |
| 26 #include "webrtc/video/rtc_event_log_parser.h" |
26 | 27 |
27 // Files generated at build-time by the protobuf compiler. | 28 // Files generated at build-time by the protobuf compiler. |
28 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 29 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
29 #include "external/webrtc/webrtc/video/rtc_event_log.pb.h" | 30 #include "external/webrtc/webrtc/video/rtc_event_log.pb.h" |
30 #else | 31 #else |
31 #include "webrtc/video/rtc_event_log.pb.h" | 32 #include "webrtc/video/rtc_event_log.pb.h" |
32 #endif | 33 #endif |
33 | 34 |
34 namespace webrtc { | 35 namespace webrtc { |
35 | 36 |
36 // TODO(terelius): Place this definition with other parsing functions? | |
37 MediaType GetRuntimeMediaType(rtclog::MediaType media_type) { | |
38 switch (media_type) { | |
39 case rtclog::MediaType::ANY: | |
40 return MediaType::ANY; | |
41 case rtclog::MediaType::AUDIO: | |
42 return MediaType::AUDIO; | |
43 case rtclog::MediaType::VIDEO: | |
44 return MediaType::VIDEO; | |
45 case rtclog::MediaType::DATA: | |
46 return MediaType::DATA; | |
47 } | |
48 RTC_NOTREACHED(); | |
49 return MediaType::ANY; | |
50 } | |
51 | |
52 // Checks that the event has a timestamp, a type and exactly the data field | 37 // Checks that the event has a timestamp, a type and exactly the data field |
53 // corresponding to the type. | 38 // corresponding to the type. |
54 ::testing::AssertionResult IsValidBasicEvent(const rtclog::Event& event) { | 39 ::testing::AssertionResult IsValidBasicEvent(const rtclog::Event& event) { |
55 if (!event.has_timestamp_us()) | 40 if (!event.has_timestamp_us()) |
56 return ::testing::AssertionFailure() << "Event has no timestamp"; | 41 return ::testing::AssertionFailure() << "Event has no timestamp"; |
57 if (!event.has_type()) | 42 if (!event.has_type()) |
58 return ::testing::AssertionFailure() << "Event has no event type"; | 43 return ::testing::AssertionFailure() << "Event has no event type"; |
59 rtclog::Event_EventType type = event.type(); | 44 rtclog::Event_EventType type = event.type(); |
60 if ((type == rtclog::Event::RTP_EVENT) != event.has_rtp_packet()) | 45 if ((type == rtclog::Event::RTP_EVENT) != event.has_rtp_packet()) |
61 return ::testing::AssertionFailure() | 46 return ::testing::AssertionFailure() |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 MediaType media_type, | 195 MediaType media_type, |
211 uint8_t* header, | 196 uint8_t* header, |
212 size_t header_size, | 197 size_t header_size, |
213 size_t total_size) { | 198 size_t total_size) { |
214 ASSERT_TRUE(IsValidBasicEvent(event)); | 199 ASSERT_TRUE(IsValidBasicEvent(event)); |
215 ASSERT_EQ(rtclog::Event::RTP_EVENT, event.type()); | 200 ASSERT_EQ(rtclog::Event::RTP_EVENT, event.type()); |
216 const rtclog::RtpPacket& rtp_packet = event.rtp_packet(); | 201 const rtclog::RtpPacket& rtp_packet = event.rtp_packet(); |
217 ASSERT_TRUE(rtp_packet.has_incoming()); | 202 ASSERT_TRUE(rtp_packet.has_incoming()); |
218 EXPECT_EQ(incoming, rtp_packet.incoming()); | 203 EXPECT_EQ(incoming, rtp_packet.incoming()); |
219 ASSERT_TRUE(rtp_packet.has_type()); | 204 ASSERT_TRUE(rtp_packet.has_type()); |
220 EXPECT_EQ(media_type, GetRuntimeMediaType(rtp_packet.type())); | 205 EXPECT_EQ(media_type, |
| 206 RtcEventLogParser::GetRuntimeMediaType(rtp_packet.type())); |
221 ASSERT_TRUE(rtp_packet.has_packet_length()); | 207 ASSERT_TRUE(rtp_packet.has_packet_length()); |
222 EXPECT_EQ(total_size, rtp_packet.packet_length()); | 208 EXPECT_EQ(total_size, rtp_packet.packet_length()); |
223 ASSERT_TRUE(rtp_packet.has_header()); | 209 ASSERT_TRUE(rtp_packet.has_header()); |
224 ASSERT_EQ(header_size, rtp_packet.header().size()); | 210 ASSERT_EQ(header_size, rtp_packet.header().size()); |
225 for (size_t i = 0; i < header_size; i++) { | 211 for (size_t i = 0; i < header_size; i++) { |
226 EXPECT_EQ(header[i], static_cast<uint8_t>(rtp_packet.header()[i])); | 212 EXPECT_EQ(header[i], static_cast<uint8_t>(rtp_packet.header()[i])); |
227 } | 213 } |
228 } | 214 } |
229 | 215 |
230 void VerifyRtcpEvent(const rtclog::Event& event, | 216 void VerifyRtcpEvent(const rtclog::Event& event, |
231 bool incoming, | 217 bool incoming, |
232 MediaType media_type, | 218 MediaType media_type, |
233 uint8_t* packet, | 219 uint8_t* packet, |
234 size_t total_size) { | 220 size_t total_size) { |
235 ASSERT_TRUE(IsValidBasicEvent(event)); | 221 ASSERT_TRUE(IsValidBasicEvent(event)); |
236 ASSERT_EQ(rtclog::Event::RTCP_EVENT, event.type()); | 222 ASSERT_EQ(rtclog::Event::RTCP_EVENT, event.type()); |
237 const rtclog::RtcpPacket& rtcp_packet = event.rtcp_packet(); | 223 const rtclog::RtcpPacket& rtcp_packet = event.rtcp_packet(); |
238 ASSERT_TRUE(rtcp_packet.has_incoming()); | 224 ASSERT_TRUE(rtcp_packet.has_incoming()); |
239 EXPECT_EQ(incoming, rtcp_packet.incoming()); | 225 EXPECT_EQ(incoming, rtcp_packet.incoming()); |
240 ASSERT_TRUE(rtcp_packet.has_type()); | 226 ASSERT_TRUE(rtcp_packet.has_type()); |
241 EXPECT_EQ(media_type, GetRuntimeMediaType(rtcp_packet.type())); | 227 EXPECT_EQ(media_type, |
| 228 RtcEventLogParser::GetRuntimeMediaType(rtcp_packet.type())); |
242 ASSERT_TRUE(rtcp_packet.has_packet_data()); | 229 ASSERT_TRUE(rtcp_packet.has_packet_data()); |
243 ASSERT_EQ(total_size, rtcp_packet.packet_data().size()); | 230 ASSERT_EQ(total_size, rtcp_packet.packet_data().size()); |
244 for (size_t i = 0; i < total_size; i++) { | 231 for (size_t i = 0; i < total_size; i++) { |
245 EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.packet_data()[i])); | 232 EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.packet_data()[i])); |
246 } | 233 } |
247 } | 234 } |
248 | 235 |
249 void VerifyLogStartEvent(const rtclog::Event& event) { | 236 void VerifyLogStartEvent(const rtclog::Event& event) { |
250 ASSERT_TRUE(IsValidBasicEvent(event)); | 237 ASSERT_TRUE(IsValidBasicEvent(event)); |
251 ASSERT_EQ(rtclog::Event::DEBUG_EVENT, event.type()); | 238 ASSERT_EQ(rtclog::Event::DEBUG_EVENT, event.type()); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } | 362 } |
376 | 363 |
377 const int config_count = 2; | 364 const int config_count = 2; |
378 const int rtcp_count = 2; | 365 const int rtcp_count = 2; |
379 const int debug_count = 1; // Only LogStart event, | 366 const int debug_count = 1; // Only LogStart event, |
380 const int event_count = config_count + debug_count + rtcp_count + rtp_count; | 367 const int event_count = config_count + debug_count + rtcp_count + rtp_count; |
381 | 368 |
382 // Read the generated file from disk. | 369 // Read the generated file from disk. |
383 rtclog::EventStream parsed_stream; | 370 rtclog::EventStream parsed_stream; |
384 | 371 |
385 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | 372 ASSERT_TRUE( |
| 373 RtcEventLogParser::ParseRtcEventLog(temp_filename, &parsed_stream)); |
386 | 374 |
387 // Verify the result. | 375 // Verify the result. |
388 EXPECT_EQ(event_count, parsed_stream.stream_size()); | 376 EXPECT_EQ(event_count, parsed_stream.stream_size()); |
389 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); | 377 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); |
390 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); | 378 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); |
391 size_t i = 0; | 379 size_t i = 0; |
392 for (; i < rtp_count / 2; i++) { | 380 for (; i < rtp_count / 2; i++) { |
393 VerifyRtpEvent(parsed_stream.stream(config_count + i), | 381 VerifyRtpEvent(parsed_stream.stream(config_count + i), |
394 (i % 2 == 0), // Every second packet is incoming. | 382 (i % 2 == 0), // Every second packet is incoming. |
395 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 383 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
(...skipping 24 matching lines...) Expand all Loading... |
420 | 408 |
421 TEST(RtcEventLogTest, LogSessionAndReadBack) { | 409 TEST(RtcEventLogTest, LogSessionAndReadBack) { |
422 LogSessionAndReadBack(5, 321); | 410 LogSessionAndReadBack(5, 321); |
423 LogSessionAndReadBack(8, 3141592653u); | 411 LogSessionAndReadBack(8, 3141592653u); |
424 LogSessionAndReadBack(9, 2718281828u); | 412 LogSessionAndReadBack(9, 2718281828u); |
425 } | 413 } |
426 | 414 |
427 } // namespace webrtc | 415 } // namespace webrtc |
428 | 416 |
429 #endif // ENABLE_RTC_EVENT_LOG | 417 #endif // ENABLE_RTC_EVENT_LOG |
OLD | NEW |