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

Side by Side Diff: webrtc/video/rtc_event_log_unittest.cc

Issue 1295753003: Convenience functions to convert RtcEvents to webrtc types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase and change CHECK to RTC_CHECK Created 5 years, 3 months 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
« no previous file with comments | « webrtc/video/rtc_event_log_parser.cc ('k') | webrtc/webrtc.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/buffer.h" 18 #include "webrtc/base/buffer.h"
19 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
20 #include "webrtc/base/scoped_ptr.h" 20 #include "webrtc/base/scoped_ptr.h"
21 #include "webrtc/call.h" 21 #include "webrtc/call.h"
22 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" 22 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h"
23 #include "webrtc/system_wrappers/interface/clock.h" 23 #include "webrtc/system_wrappers/interface/clock.h"
24 #include "webrtc/test/test_suite.h" 24 #include "webrtc/test/test_suite.h"
25 #include "webrtc/test/testsupport/fileutils.h" 25 #include "webrtc/test/testsupport/fileutils.h"
26 #include "webrtc/test/testsupport/gtest_disable.h" 26 #include "webrtc/test/testsupport/gtest_disable.h"
27 #include "webrtc/video/rtc_event_log.h" 27 #include "webrtc/video/rtc_event_log.h"
28 #include "webrtc/video/rtc_event_log_parser.h"
28 29
29 // Files generated at build-time by the protobuf compiler. 30 // Files generated at build-time by the protobuf compiler.
30 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD 31 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
31 #include "external/webrtc/webrtc/video/rtc_event_log.pb.h" 32 #include "external/webrtc/webrtc/video/rtc_event_log.pb.h"
32 #else 33 #else
33 #include "webrtc/video/rtc_event_log.pb.h" 34 #include "webrtc/video/rtc_event_log.pb.h"
34 #endif 35 #endif
35 36
36 namespace webrtc { 37 namespace webrtc {
37 38
38 namespace { 39 namespace {
39 40
40 const RTPExtensionType kExtensionTypes[] = { 41 const RTPExtensionType kExtensionTypes[] = {
41 RTPExtensionType::kRtpExtensionTransmissionTimeOffset, 42 RTPExtensionType::kRtpExtensionTransmissionTimeOffset,
42 RTPExtensionType::kRtpExtensionAudioLevel, 43 RTPExtensionType::kRtpExtensionAudioLevel,
43 RTPExtensionType::kRtpExtensionAbsoluteSendTime, 44 RTPExtensionType::kRtpExtensionAbsoluteSendTime,
44 RTPExtensionType::kRtpExtensionVideoRotation, 45 RTPExtensionType::kRtpExtensionVideoRotation,
45 RTPExtensionType::kRtpExtensionTransportSequenceNumber}; 46 RTPExtensionType::kRtpExtensionTransportSequenceNumber};
46 const char* kExtensionNames[] = {RtpExtension::kTOffset, 47 const char* kExtensionNames[] = {RtpExtension::kTOffset,
47 RtpExtension::kAudioLevel, 48 RtpExtension::kAudioLevel,
48 RtpExtension::kAbsSendTime, 49 RtpExtension::kAbsSendTime,
49 RtpExtension::kVideoRotation, 50 RtpExtension::kVideoRotation,
50 RtpExtension::kTransportSequenceNumber}; 51 RtpExtension::kTransportSequenceNumber};
51 const size_t kNumExtensions = 5; 52 const size_t kNumExtensions = 5;
52 53
53 } // namepsace 54 } // namespace
54
55 // TODO(terelius): Place this definition with other parsing functions?
56 MediaType GetRuntimeMediaType(rtclog::MediaType media_type) {
57 switch (media_type) {
58 case rtclog::MediaType::ANY:
59 return MediaType::ANY;
60 case rtclog::MediaType::AUDIO:
61 return MediaType::AUDIO;
62 case rtclog::MediaType::VIDEO:
63 return MediaType::VIDEO;
64 case rtclog::MediaType::DATA:
65 return MediaType::DATA;
66 }
67 RTC_NOTREACHED();
68 return MediaType::ANY;
69 }
70 55
71 // Checks that the event has a timestamp, a type and exactly the data field 56 // Checks that the event has a timestamp, a type and exactly the data field
72 // corresponding to the type. 57 // corresponding to the type.
73 ::testing::AssertionResult IsValidBasicEvent(const rtclog::Event& event) { 58 ::testing::AssertionResult IsValidBasicEvent(const rtclog::Event& event) {
74 if (!event.has_timestamp_us()) 59 if (!event.has_timestamp_us())
75 return ::testing::AssertionFailure() << "Event has no timestamp"; 60 return ::testing::AssertionFailure() << "Event has no timestamp";
76 if (!event.has_type()) 61 if (!event.has_type())
77 return ::testing::AssertionFailure() << "Event has no event type"; 62 return ::testing::AssertionFailure() << "Event has no event type";
78 rtclog::Event_EventType type = event.type(); 63 rtclog::Event_EventType type = event.type();
79 if ((type == rtclog::Event::RTP_EVENT) != event.has_rtp_packet()) 64 if ((type == rtclog::Event::RTP_EVENT) != event.has_rtp_packet())
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 ASSERT_EQ(rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT, event.type()); 107 ASSERT_EQ(rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT, event.type());
123 const rtclog::VideoReceiveConfig& receiver_config = 108 const rtclog::VideoReceiveConfig& receiver_config =
124 event.video_receiver_config(); 109 event.video_receiver_config();
125 // Check SSRCs. 110 // Check SSRCs.
126 ASSERT_TRUE(receiver_config.has_remote_ssrc()); 111 ASSERT_TRUE(receiver_config.has_remote_ssrc());
127 EXPECT_EQ(config.rtp.remote_ssrc, receiver_config.remote_ssrc()); 112 EXPECT_EQ(config.rtp.remote_ssrc, receiver_config.remote_ssrc());
128 ASSERT_TRUE(receiver_config.has_local_ssrc()); 113 ASSERT_TRUE(receiver_config.has_local_ssrc());
129 EXPECT_EQ(config.rtp.local_ssrc, receiver_config.local_ssrc()); 114 EXPECT_EQ(config.rtp.local_ssrc, receiver_config.local_ssrc());
130 // Check RTCP settings. 115 // Check RTCP settings.
131 ASSERT_TRUE(receiver_config.has_rtcp_mode()); 116 ASSERT_TRUE(receiver_config.has_rtcp_mode());
132 if (config.rtp.rtcp_mode == newapi::kRtcpCompound) 117 EXPECT_EQ(config.rtp.rtcp_mode,
133 EXPECT_EQ(rtclog::VideoReceiveConfig::RTCP_COMPOUND, 118 RtcEventLogParser::GetRuntimeRtcpMode(receiver_config.rtcp_mode()));
134 receiver_config.rtcp_mode());
135 else
136 EXPECT_EQ(rtclog::VideoReceiveConfig::RTCP_REDUCEDSIZE,
137 receiver_config.rtcp_mode());
138 ASSERT_TRUE(receiver_config.has_receiver_reference_time_report()); 119 ASSERT_TRUE(receiver_config.has_receiver_reference_time_report());
139 EXPECT_EQ(config.rtp.rtcp_xr.receiver_reference_time_report, 120 EXPECT_EQ(config.rtp.rtcp_xr.receiver_reference_time_report,
140 receiver_config.receiver_reference_time_report()); 121 receiver_config.receiver_reference_time_report());
141 ASSERT_TRUE(receiver_config.has_remb()); 122 ASSERT_TRUE(receiver_config.has_remb());
142 EXPECT_EQ(config.rtp.remb, receiver_config.remb()); 123 EXPECT_EQ(config.rtp.remb, receiver_config.remb());
143 // Check RTX map. 124 // Check RTX map.
144 ASSERT_EQ(static_cast<int>(config.rtp.rtx.size()), 125 ASSERT_EQ(static_cast<int>(config.rtp.rtx.size()),
145 receiver_config.rtx_map_size()); 126 receiver_config.rtx_map_size());
146 for (const rtclog::RtxMap& rtx_map : receiver_config.rtx_map()) { 127 for (const rtclog::RtxMap& rtx_map : receiver_config.rtx_map()) {
147 ASSERT_TRUE(rtx_map.has_payload_type()); 128 ASSERT_TRUE(rtx_map.has_payload_type());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 MediaType media_type, 210 MediaType media_type,
230 uint8_t* header, 211 uint8_t* header,
231 size_t header_size, 212 size_t header_size,
232 size_t total_size) { 213 size_t total_size) {
233 ASSERT_TRUE(IsValidBasicEvent(event)); 214 ASSERT_TRUE(IsValidBasicEvent(event));
234 ASSERT_EQ(rtclog::Event::RTP_EVENT, event.type()); 215 ASSERT_EQ(rtclog::Event::RTP_EVENT, event.type());
235 const rtclog::RtpPacket& rtp_packet = event.rtp_packet(); 216 const rtclog::RtpPacket& rtp_packet = event.rtp_packet();
236 ASSERT_TRUE(rtp_packet.has_incoming()); 217 ASSERT_TRUE(rtp_packet.has_incoming());
237 EXPECT_EQ(incoming, rtp_packet.incoming()); 218 EXPECT_EQ(incoming, rtp_packet.incoming());
238 ASSERT_TRUE(rtp_packet.has_type()); 219 ASSERT_TRUE(rtp_packet.has_type());
239 EXPECT_EQ(media_type, GetRuntimeMediaType(rtp_packet.type())); 220 EXPECT_EQ(media_type,
221 RtcEventLogParser::GetRuntimeMediaType(rtp_packet.type()));
240 ASSERT_TRUE(rtp_packet.has_packet_length()); 222 ASSERT_TRUE(rtp_packet.has_packet_length());
241 EXPECT_EQ(total_size, rtp_packet.packet_length()); 223 EXPECT_EQ(total_size, rtp_packet.packet_length());
242 ASSERT_TRUE(rtp_packet.has_header()); 224 ASSERT_TRUE(rtp_packet.has_header());
243 ASSERT_EQ(header_size, rtp_packet.header().size()); 225 ASSERT_EQ(header_size, rtp_packet.header().size());
244 for (size_t i = 0; i < header_size; i++) { 226 for (size_t i = 0; i < header_size; i++) {
245 EXPECT_EQ(header[i], static_cast<uint8_t>(rtp_packet.header()[i])); 227 EXPECT_EQ(header[i], static_cast<uint8_t>(rtp_packet.header()[i]));
246 } 228 }
247 } 229 }
248 230
249 void VerifyRtcpEvent(const rtclog::Event& event, 231 void VerifyRtcpEvent(const rtclog::Event& event,
250 bool incoming, 232 bool incoming,
251 MediaType media_type, 233 MediaType media_type,
252 uint8_t* packet, 234 uint8_t* packet,
253 size_t total_size) { 235 size_t total_size) {
254 ASSERT_TRUE(IsValidBasicEvent(event)); 236 ASSERT_TRUE(IsValidBasicEvent(event));
255 ASSERT_EQ(rtclog::Event::RTCP_EVENT, event.type()); 237 ASSERT_EQ(rtclog::Event::RTCP_EVENT, event.type());
256 const rtclog::RtcpPacket& rtcp_packet = event.rtcp_packet(); 238 const rtclog::RtcpPacket& rtcp_packet = event.rtcp_packet();
257 ASSERT_TRUE(rtcp_packet.has_incoming()); 239 ASSERT_TRUE(rtcp_packet.has_incoming());
258 EXPECT_EQ(incoming, rtcp_packet.incoming()); 240 EXPECT_EQ(incoming, rtcp_packet.incoming());
259 ASSERT_TRUE(rtcp_packet.has_type()); 241 ASSERT_TRUE(rtcp_packet.has_type());
260 EXPECT_EQ(media_type, GetRuntimeMediaType(rtcp_packet.type())); 242 EXPECT_EQ(media_type,
243 RtcEventLogParser::GetRuntimeMediaType(rtcp_packet.type()));
261 ASSERT_TRUE(rtcp_packet.has_packet_data()); 244 ASSERT_TRUE(rtcp_packet.has_packet_data());
262 ASSERT_EQ(total_size, rtcp_packet.packet_data().size()); 245 ASSERT_EQ(total_size, rtcp_packet.packet_data().size());
263 for (size_t i = 0; i < total_size; i++) { 246 for (size_t i = 0; i < total_size; i++) {
264 EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.packet_data()[i])); 247 EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.packet_data()[i]));
265 } 248 }
266 } 249 }
267 250
268 void VerifyPlayoutEvent(const rtclog::Event& event, uint32_t ssrc) { 251 void VerifyPlayoutEvent(const rtclog::Event& event, uint32_t ssrc) {
269 ASSERT_TRUE(IsValidBasicEvent(event)); 252 ASSERT_TRUE(IsValidBasicEvent(event));
270 ASSERT_EQ(rtclog::Event::DEBUG_EVENT, event.type()); 253 ASSERT_EQ(rtclog::Event::DEBUG_EVENT, event.type());
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 453 }
471 if (i == rtp_count / 2) { 454 if (i == rtp_count / 2) {
472 log_dumper->StartLogging(temp_filename, 10000000); 455 log_dumper->StartLogging(temp_filename, 10000000);
473 } 456 }
474 } 457 }
475 } 458 }
476 459
477 // Read the generated file from disk. 460 // Read the generated file from disk.
478 rtclog::EventStream parsed_stream; 461 rtclog::EventStream parsed_stream;
479 462
480 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); 463 ASSERT_TRUE(
464 RtcEventLogParser::ParseRtcEventLog(temp_filename, &parsed_stream));
481 465
482 // Verify the result. 466 // Verify the result.
483 const int event_count = 467 const int event_count =
484 config_count + debug_count + rtcp_count + rtp_count + 1; 468 config_count + debug_count + rtcp_count + rtp_count + 1;
485 EXPECT_EQ(event_count, parsed_stream.stream_size()); 469 EXPECT_EQ(event_count, parsed_stream.stream_size());
486 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); 470 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config);
487 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); 471 VerifySendStreamConfig(parsed_stream.stream(1), sender_config);
488 size_t event_index = config_count, rtcp_index = 1, debug_index = 1; 472 size_t event_index = config_count, rtcp_index = 1, debug_index = 1;
489 for (size_t i = 1; i <= rtp_count; i++) { 473 for (size_t i = 1; i <= rtp_count; i++) {
490 VerifyRtpEvent(parsed_stream.stream(event_index), 474 VerifyRtpEvent(parsed_stream.stream(event_index),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 extensions, // Bit vector choosing extensions 529 extensions, // Bit vector choosing extensions
546 csrcs_count, // Number of contributing sources 530 csrcs_count, // Number of contributing sources
547 rand()); 531 rand());
548 } 532 }
549 } 533 }
550 } 534 }
551 535
552 } // namespace webrtc 536 } // namespace webrtc
553 537
554 #endif // ENABLE_RTC_EVENT_LOG 538 #endif // ENABLE_RTC_EVENT_LOG
OLDNEW
« no previous file with comments | « webrtc/video/rtc_event_log_parser.cc ('k') | webrtc/webrtc.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698