| 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 <map> | 13 #include <map> |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <string> | 15 #include <string> |
| 16 #include <utility> | 16 #include <utility> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "webrtc/base/buffer.h" | 20 #include "webrtc/base/buffer.h" |
| 21 #include "webrtc/base/checks.h" | 21 #include "webrtc/base/checks.h" |
| 22 #include "webrtc/base/random.h" | 22 #include "webrtc/base/random.h" |
| 23 #include "webrtc/call.h" | 23 #include "webrtc/call.h" |
| 24 #include "webrtc/call/rtc_event_log.h" | 24 #include "webrtc/call/rtc_event_log.h" |
| 25 #include "webrtc/call/rtc_event_log_parser.h" |
| 26 #include "webrtc/call/rtc_event_log_unittest_helper.h" |
| 25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" | 27 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" |
| 26 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" | 28 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
| 27 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" | 29 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" |
| 28 #include "webrtc/system_wrappers/include/clock.h" | 30 #include "webrtc/system_wrappers/include/clock.h" |
| 29 #include "webrtc/test/test_suite.h" | 31 #include "webrtc/test/test_suite.h" |
| 30 #include "webrtc/test/testsupport/fileutils.h" | 32 #include "webrtc/test/testsupport/fileutils.h" |
| 31 | 33 |
| 32 // Files generated at build-time by the protobuf compiler. | 34 // Files generated at build-time by the protobuf compiler. |
| 33 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 35 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
| 34 #include "external/webrtc/webrtc/call/rtc_event_log.pb.h" | 36 #include "external/webrtc/webrtc/call/rtc_event_log.pb.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 46 RTPExtensionType::kRtpExtensionAbsoluteSendTime, | 48 RTPExtensionType::kRtpExtensionAbsoluteSendTime, |
| 47 RTPExtensionType::kRtpExtensionVideoRotation, | 49 RTPExtensionType::kRtpExtensionVideoRotation, |
| 48 RTPExtensionType::kRtpExtensionTransportSequenceNumber}; | 50 RTPExtensionType::kRtpExtensionTransportSequenceNumber}; |
| 49 const char* kExtensionNames[] = {RtpExtension::kTOffset, | 51 const char* kExtensionNames[] = {RtpExtension::kTOffset, |
| 50 RtpExtension::kAudioLevel, | 52 RtpExtension::kAudioLevel, |
| 51 RtpExtension::kAbsSendTime, | 53 RtpExtension::kAbsSendTime, |
| 52 RtpExtension::kVideoRotation, | 54 RtpExtension::kVideoRotation, |
| 53 RtpExtension::kTransportSequenceNumber}; | 55 RtpExtension::kTransportSequenceNumber}; |
| 54 const size_t kNumExtensions = 5; | 56 const size_t kNumExtensions = 5; |
| 55 | 57 |
| 56 } // namespace | 58 void PrintActualEvents(const ParsedRtcEventLog& parsed_log) { |
| 57 | 59 std::map<int, size_t> actual_event_counts; |
| 58 // TODO(terelius): Place this definition with other parsing functions? | 60 for (size_t i = 0; i < parsed_log.GetNumberOfEvents(); i++) { |
| 59 MediaType GetRuntimeMediaType(rtclog::MediaType media_type) { | 61 actual_event_counts[parsed_log.GetEventType(i)]++; |
| 60 switch (media_type) { | |
| 61 case rtclog::MediaType::ANY: | |
| 62 return MediaType::ANY; | |
| 63 case rtclog::MediaType::AUDIO: | |
| 64 return MediaType::AUDIO; | |
| 65 case rtclog::MediaType::VIDEO: | |
| 66 return MediaType::VIDEO; | |
| 67 case rtclog::MediaType::DATA: | |
| 68 return MediaType::DATA; | |
| 69 } | 62 } |
| 70 RTC_NOTREACHED(); | 63 printf("Actual events: "); |
| 71 return MediaType::ANY; | 64 for (auto kv : actual_event_counts) { |
| 65 printf("%d_count = %zu, ", kv.first, kv.second); |
| 66 } |
| 67 printf("\n"); |
| 68 for (size_t i = 0; i < parsed_log.GetNumberOfEvents(); i++) { |
| 69 printf("%4d ", parsed_log.GetEventType(i)); |
| 70 } |
| 71 printf("\n"); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Checks that the event has a timestamp, a type and exactly the data field | 74 void PrintExpectedEvents(size_t rtp_count, |
| 75 // corresponding to the type. | 75 size_t rtcp_count, |
| 76 ::testing::AssertionResult IsValidBasicEvent(const rtclog::Event& event) { | 76 size_t playout_count, |
| 77 if (!event.has_timestamp_us()) | 77 size_t bwe_loss_count) { |
| 78 return ::testing::AssertionFailure() << "Event has no timestamp"; | 78 printf( |
| 79 if (!event.has_type()) | 79 "Expected events: rtp_count = %zu, rtcp_count = %zu," |
| 80 return ::testing::AssertionFailure() << "Event has no event type"; | 80 "playout_count = %zu, bwe_loss_count = %zu\n", |
| 81 rtclog::Event_EventType type = event.type(); | 81 rtp_count, rtcp_count, playout_count, bwe_loss_count); |
| 82 if ((type == rtclog::Event::RTP_EVENT) != event.has_rtp_packet()) | 82 size_t rtcp_index = 1, playout_index = 1, bwe_loss_index = 1; |
| 83 return ::testing::AssertionFailure() | 83 printf("strt cfg cfg "); |
| 84 << "Event of type " << type << " has " | 84 for (size_t i = 1; i <= rtp_count; i++) { |
| 85 << (event.has_rtp_packet() ? "" : "no ") << "RTP packet"; | 85 printf(" rtp "); |
| 86 if ((type == rtclog::Event::RTCP_EVENT) != event.has_rtcp_packet()) | 86 if (i * rtcp_count >= rtcp_index * rtp_count) { |
| 87 return ::testing::AssertionFailure() | 87 printf("rtcp "); |
| 88 << "Event of type " << type << " has " | 88 rtcp_index++; |
| 89 << (event.has_rtcp_packet() ? "" : "no ") << "RTCP packet"; | 89 } |
| 90 if ((type == rtclog::Event::AUDIO_PLAYOUT_EVENT) != | 90 if (i * playout_count >= playout_index * rtp_count) { |
| 91 event.has_audio_playout_event()) | 91 printf("play "); |
| 92 return ::testing::AssertionFailure() | 92 playout_index++; |
| 93 << "Event of type " << type << " has " | 93 } |
| 94 << (event.has_audio_playout_event() ? "" : "no ") | 94 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { |
| 95 << "audio_playout event"; | 95 printf("loss "); |
| 96 if ((type == rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT) != | 96 bwe_loss_index++; |
| 97 event.has_video_receiver_config()) | 97 } |
| 98 return ::testing::AssertionFailure() | |
| 99 << "Event of type " << type << " has " | |
| 100 << (event.has_video_receiver_config() ? "" : "no ") | |
| 101 << "receiver config"; | |
| 102 if ((type == rtclog::Event::VIDEO_SENDER_CONFIG_EVENT) != | |
| 103 event.has_video_sender_config()) | |
| 104 return ::testing::AssertionFailure() | |
| 105 << "Event of type " << type << " has " | |
| 106 << (event.has_video_sender_config() ? "" : "no ") << "sender config"; | |
| 107 if ((type == rtclog::Event::AUDIO_RECEIVER_CONFIG_EVENT) != | |
| 108 event.has_audio_receiver_config()) { | |
| 109 return ::testing::AssertionFailure() | |
| 110 << "Event of type " << type << " has " | |
| 111 << (event.has_audio_receiver_config() ? "" : "no ") | |
| 112 << "audio receiver config"; | |
| 113 } | 98 } |
| 114 if ((type == rtclog::Event::AUDIO_SENDER_CONFIG_EVENT) != | 99 printf("end \n"); |
| 115 event.has_audio_sender_config()) { | |
| 116 return ::testing::AssertionFailure() | |
| 117 << "Event of type " << type << " has " | |
| 118 << (event.has_audio_sender_config() ? "" : "no ") | |
| 119 << "audio sender config"; | |
| 120 } | |
| 121 return ::testing::AssertionSuccess(); | |
| 122 } | 100 } |
| 123 | 101 } // namespace |
| 124 void VerifyReceiveStreamConfig(const rtclog::Event& event, | |
| 125 const VideoReceiveStream::Config& config) { | |
| 126 ASSERT_TRUE(IsValidBasicEvent(event)); | |
| 127 ASSERT_EQ(rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT, event.type()); | |
| 128 const rtclog::VideoReceiveConfig& receiver_config = | |
| 129 event.video_receiver_config(); | |
| 130 // Check SSRCs. | |
| 131 ASSERT_TRUE(receiver_config.has_remote_ssrc()); | |
| 132 EXPECT_EQ(config.rtp.remote_ssrc, receiver_config.remote_ssrc()); | |
| 133 ASSERT_TRUE(receiver_config.has_local_ssrc()); | |
| 134 EXPECT_EQ(config.rtp.local_ssrc, receiver_config.local_ssrc()); | |
| 135 // Check RTCP settings. | |
| 136 ASSERT_TRUE(receiver_config.has_rtcp_mode()); | |
| 137 if (config.rtp.rtcp_mode == RtcpMode::kCompound) | |
| 138 EXPECT_EQ(rtclog::VideoReceiveConfig::RTCP_COMPOUND, | |
| 139 receiver_config.rtcp_mode()); | |
| 140 else | |
| 141 EXPECT_EQ(rtclog::VideoReceiveConfig::RTCP_REDUCEDSIZE, | |
| 142 receiver_config.rtcp_mode()); | |
| 143 ASSERT_TRUE(receiver_config.has_remb()); | |
| 144 EXPECT_EQ(config.rtp.remb, receiver_config.remb()); | |
| 145 // Check RTX map. | |
| 146 ASSERT_EQ(static_cast<int>(config.rtp.rtx.size()), | |
| 147 receiver_config.rtx_map_size()); | |
| 148 for (const rtclog::RtxMap& rtx_map : receiver_config.rtx_map()) { | |
| 149 ASSERT_TRUE(rtx_map.has_payload_type()); | |
| 150 ASSERT_TRUE(rtx_map.has_config()); | |
| 151 EXPECT_EQ(1u, config.rtp.rtx.count(rtx_map.payload_type())); | |
| 152 const rtclog::RtxConfig& rtx_config = rtx_map.config(); | |
| 153 const VideoReceiveStream::Config::Rtp::Rtx& rtx = | |
| 154 config.rtp.rtx.at(rtx_map.payload_type()); | |
| 155 ASSERT_TRUE(rtx_config.has_rtx_ssrc()); | |
| 156 ASSERT_TRUE(rtx_config.has_rtx_payload_type()); | |
| 157 EXPECT_EQ(rtx.ssrc, rtx_config.rtx_ssrc()); | |
| 158 EXPECT_EQ(rtx.payload_type, rtx_config.rtx_payload_type()); | |
| 159 } | |
| 160 // Check header extensions. | |
| 161 ASSERT_EQ(static_cast<int>(config.rtp.extensions.size()), | |
| 162 receiver_config.header_extensions_size()); | |
| 163 for (int i = 0; i < receiver_config.header_extensions_size(); i++) { | |
| 164 ASSERT_TRUE(receiver_config.header_extensions(i).has_name()); | |
| 165 ASSERT_TRUE(receiver_config.header_extensions(i).has_id()); | |
| 166 const std::string& name = receiver_config.header_extensions(i).name(); | |
| 167 int id = receiver_config.header_extensions(i).id(); | |
| 168 EXPECT_EQ(config.rtp.extensions[i].id, id); | |
| 169 EXPECT_EQ(config.rtp.extensions[i].name, name); | |
| 170 } | |
| 171 // Check decoders. | |
| 172 ASSERT_EQ(static_cast<int>(config.decoders.size()), | |
| 173 receiver_config.decoders_size()); | |
| 174 for (int i = 0; i < receiver_config.decoders_size(); i++) { | |
| 175 ASSERT_TRUE(receiver_config.decoders(i).has_name()); | |
| 176 ASSERT_TRUE(receiver_config.decoders(i).has_payload_type()); | |
| 177 const std::string& decoder_name = receiver_config.decoders(i).name(); | |
| 178 int decoder_type = receiver_config.decoders(i).payload_type(); | |
| 179 EXPECT_EQ(config.decoders[i].payload_name, decoder_name); | |
| 180 EXPECT_EQ(config.decoders[i].payload_type, decoder_type); | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 void VerifySendStreamConfig(const rtclog::Event& event, | |
| 185 const VideoSendStream::Config& config) { | |
| 186 ASSERT_TRUE(IsValidBasicEvent(event)); | |
| 187 ASSERT_EQ(rtclog::Event::VIDEO_SENDER_CONFIG_EVENT, event.type()); | |
| 188 const rtclog::VideoSendConfig& sender_config = event.video_sender_config(); | |
| 189 // Check SSRCs. | |
| 190 ASSERT_EQ(static_cast<int>(config.rtp.ssrcs.size()), | |
| 191 sender_config.ssrcs_size()); | |
| 192 for (int i = 0; i < sender_config.ssrcs_size(); i++) { | |
| 193 EXPECT_EQ(config.rtp.ssrcs[i], sender_config.ssrcs(i)); | |
| 194 } | |
| 195 // Check header extensions. | |
| 196 ASSERT_EQ(static_cast<int>(config.rtp.extensions.size()), | |
| 197 sender_config.header_extensions_size()); | |
| 198 for (int i = 0; i < sender_config.header_extensions_size(); i++) { | |
| 199 ASSERT_TRUE(sender_config.header_extensions(i).has_name()); | |
| 200 ASSERT_TRUE(sender_config.header_extensions(i).has_id()); | |
| 201 const std::string& name = sender_config.header_extensions(i).name(); | |
| 202 int id = sender_config.header_extensions(i).id(); | |
| 203 EXPECT_EQ(config.rtp.extensions[i].id, id); | |
| 204 EXPECT_EQ(config.rtp.extensions[i].name, name); | |
| 205 } | |
| 206 // Check RTX settings. | |
| 207 ASSERT_EQ(static_cast<int>(config.rtp.rtx.ssrcs.size()), | |
| 208 sender_config.rtx_ssrcs_size()); | |
| 209 for (int i = 0; i < sender_config.rtx_ssrcs_size(); i++) { | |
| 210 EXPECT_EQ(config.rtp.rtx.ssrcs[i], sender_config.rtx_ssrcs(i)); | |
| 211 } | |
| 212 if (sender_config.rtx_ssrcs_size() > 0) { | |
| 213 ASSERT_TRUE(sender_config.has_rtx_payload_type()); | |
| 214 EXPECT_EQ(config.rtp.rtx.payload_type, sender_config.rtx_payload_type()); | |
| 215 } | |
| 216 // Check encoder. | |
| 217 ASSERT_TRUE(sender_config.has_encoder()); | |
| 218 ASSERT_TRUE(sender_config.encoder().has_name()); | |
| 219 ASSERT_TRUE(sender_config.encoder().has_payload_type()); | |
| 220 EXPECT_EQ(config.encoder_settings.payload_name, | |
| 221 sender_config.encoder().name()); | |
| 222 EXPECT_EQ(config.encoder_settings.payload_type, | |
| 223 sender_config.encoder().payload_type()); | |
| 224 } | |
| 225 | |
| 226 void VerifyRtpEvent(const rtclog::Event& event, | |
| 227 PacketDirection direction, | |
| 228 MediaType media_type, | |
| 229 const uint8_t* header, | |
| 230 size_t header_size, | |
| 231 size_t total_size) { | |
| 232 ASSERT_TRUE(IsValidBasicEvent(event)); | |
| 233 ASSERT_EQ(rtclog::Event::RTP_EVENT, event.type()); | |
| 234 const rtclog::RtpPacket& rtp_packet = event.rtp_packet(); | |
| 235 ASSERT_TRUE(rtp_packet.has_incoming()); | |
| 236 EXPECT_EQ(direction == kIncomingPacket, rtp_packet.incoming()); | |
| 237 ASSERT_TRUE(rtp_packet.has_type()); | |
| 238 EXPECT_EQ(media_type, GetRuntimeMediaType(rtp_packet.type())); | |
| 239 ASSERT_TRUE(rtp_packet.has_packet_length()); | |
| 240 EXPECT_EQ(total_size, rtp_packet.packet_length()); | |
| 241 ASSERT_TRUE(rtp_packet.has_header()); | |
| 242 ASSERT_EQ(header_size, rtp_packet.header().size()); | |
| 243 for (size_t i = 0; i < header_size; i++) { | |
| 244 EXPECT_EQ(header[i], static_cast<uint8_t>(rtp_packet.header()[i])); | |
| 245 } | |
| 246 } | |
| 247 | |
| 248 void VerifyRtcpEvent(const rtclog::Event& event, | |
| 249 PacketDirection direction, | |
| 250 MediaType media_type, | |
| 251 const uint8_t* packet, | |
| 252 size_t total_size) { | |
| 253 ASSERT_TRUE(IsValidBasicEvent(event)); | |
| 254 ASSERT_EQ(rtclog::Event::RTCP_EVENT, event.type()); | |
| 255 const rtclog::RtcpPacket& rtcp_packet = event.rtcp_packet(); | |
| 256 ASSERT_TRUE(rtcp_packet.has_incoming()); | |
| 257 EXPECT_EQ(direction == kIncomingPacket, rtcp_packet.incoming()); | |
| 258 ASSERT_TRUE(rtcp_packet.has_type()); | |
| 259 EXPECT_EQ(media_type, GetRuntimeMediaType(rtcp_packet.type())); | |
| 260 ASSERT_TRUE(rtcp_packet.has_packet_data()); | |
| 261 ASSERT_EQ(total_size, rtcp_packet.packet_data().size()); | |
| 262 for (size_t i = 0; i < total_size; i++) { | |
| 263 EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.packet_data()[i])); | |
| 264 } | |
| 265 } | |
| 266 | |
| 267 void VerifyPlayoutEvent(const rtclog::Event& event, uint32_t ssrc) { | |
| 268 ASSERT_TRUE(IsValidBasicEvent(event)); | |
| 269 ASSERT_EQ(rtclog::Event::AUDIO_PLAYOUT_EVENT, event.type()); | |
| 270 const rtclog::AudioPlayoutEvent& playout_event = event.audio_playout_event(); | |
| 271 ASSERT_TRUE(playout_event.has_local_ssrc()); | |
| 272 EXPECT_EQ(ssrc, playout_event.local_ssrc()); | |
| 273 } | |
| 274 | |
| 275 void VerifyBweLossEvent(const rtclog::Event& event, | |
| 276 int32_t bitrate, | |
| 277 uint8_t fraction_loss, | |
| 278 int32_t total_packets) { | |
| 279 ASSERT_TRUE(IsValidBasicEvent(event)); | |
| 280 ASSERT_EQ(rtclog::Event::BWE_PACKET_LOSS_EVENT, event.type()); | |
| 281 const rtclog::BwePacketLossEvent& bwe_event = event.bwe_packet_loss_event(); | |
| 282 ASSERT_TRUE(bwe_event.has_bitrate()); | |
| 283 EXPECT_EQ(bitrate, bwe_event.bitrate()); | |
| 284 ASSERT_TRUE(bwe_event.has_fraction_loss()); | |
| 285 EXPECT_EQ(fraction_loss, bwe_event.fraction_loss()); | |
| 286 ASSERT_TRUE(bwe_event.has_total_packets()); | |
| 287 EXPECT_EQ(total_packets, bwe_event.total_packets()); | |
| 288 } | |
| 289 | |
| 290 void VerifyLogStartEvent(const rtclog::Event& event) { | |
| 291 ASSERT_TRUE(IsValidBasicEvent(event)); | |
| 292 EXPECT_EQ(rtclog::Event::LOG_START, event.type()); | |
| 293 } | |
| 294 | |
| 295 void VerifyLogEndEvent(const rtclog::Event& event) { | |
| 296 ASSERT_TRUE(IsValidBasicEvent(event)); | |
| 297 EXPECT_EQ(rtclog::Event::LOG_END, event.type()); | |
| 298 } | |
| 299 | 102 |
| 300 /* | 103 /* |
| 301 * Bit number i of extension_bitvector is set to indicate the | 104 * Bit number i of extension_bitvector is set to indicate the |
| 302 * presence of extension number i from kExtensionTypes / kExtensionNames. | 105 * presence of extension number i from kExtensionTypes / kExtensionNames. |
| 303 * The least significant bit extension_bitvector has number 0. | 106 * The least significant bit extension_bitvector has number 0. |
| 304 */ | 107 */ |
| 305 size_t GenerateRtpPacket(uint32_t extensions_bitvector, | 108 size_t GenerateRtpPacket(uint32_t extensions_bitvector, |
| 306 uint32_t csrcs_count, | 109 uint32_t csrcs_count, |
| 307 uint8_t* packet, | 110 uint8_t* packet, |
| 308 size_t packet_size, | 111 size_t packet_size, |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 } | 319 } |
| 517 if (i == rtp_count / 2) { | 320 if (i == rtp_count / 2) { |
| 518 log_dumper->StartLogging(temp_filename, 10000000); | 321 log_dumper->StartLogging(temp_filename, 10000000); |
| 519 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 322 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 520 } | 323 } |
| 521 } | 324 } |
| 522 log_dumper->StopLogging(); | 325 log_dumper->StopLogging(); |
| 523 } | 326 } |
| 524 | 327 |
| 525 // Read the generated file from disk. | 328 // Read the generated file from disk. |
| 526 rtclog::EventStream parsed_stream; | 329 ParsedRtcEventLog parsed_log; |
| 527 | 330 |
| 528 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | 331 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); |
| 529 | 332 |
| 530 // Verify that what we read back from the event log is the same as | 333 // Verify that what we read back from the event log is the same as |
| 531 // what we wrote down. For RTCP we log the full packets, but for | 334 // what we wrote down. For RTCP we log the full packets, but for |
| 532 // RTP we should only log the header. | 335 // RTP we should only log the header. |
| 533 const int event_count = config_count + playout_count + bwe_loss_count + | 336 const size_t event_count = config_count + playout_count + bwe_loss_count + |
| 534 rtcp_count + rtp_count + 2; | 337 rtcp_count + rtp_count + 2; |
| 535 EXPECT_GE(1000, event_count); // The events must fit in the message queue. | 338 EXPECT_GE(1000u, event_count); // The events must fit in the message queue. |
| 536 EXPECT_EQ(event_count, parsed_stream.stream_size()); | 339 EXPECT_EQ(event_count, parsed_log.GetNumberOfEvents()); |
| 537 if (event_count != parsed_stream.stream_size()) { | 340 if (event_count != parsed_log.GetNumberOfEvents()) { |
| 538 // Print the expected and actual event types for easier debugging. | 341 // Print the expected and actual event types for easier debugging. |
| 539 std::map<int, size_t> actual_event_counts; | 342 PrintActualEvents(parsed_log); |
| 540 for (size_t i = 0; i < static_cast<size_t>(parsed_stream.stream_size()); | 343 PrintExpectedEvents(rtp_count, rtcp_count, playout_count, bwe_loss_count); |
| 541 i++) { | |
| 542 actual_event_counts[parsed_stream.stream(i).type()]++; | |
| 543 } | |
| 544 printf("Actual events: "); | |
| 545 for (auto kv : actual_event_counts) { | |
| 546 printf("%d_count = %zu, ", kv.first, kv.second); | |
| 547 } | |
| 548 printf("\n"); | |
| 549 for (size_t i = 0; i < static_cast<size_t>(parsed_stream.stream_size()); | |
| 550 i++) { | |
| 551 printf("%4d ", parsed_stream.stream(i).type()); | |
| 552 } | |
| 553 printf("\n"); | |
| 554 printf( | |
| 555 "Expected events: rtp_count = %zu, rtcp_count = %zu," | |
| 556 "playout_count = %zu, bwe_loss_count = %zu\n", | |
| 557 rtp_count, rtcp_count, playout_count, bwe_loss_count); | |
| 558 size_t rtcp_index = 1, playout_index = 1, bwe_loss_index = 1; | |
| 559 printf("strt cfg cfg "); | |
| 560 for (size_t i = 1; i <= rtp_count; i++) { | |
| 561 printf(" rtp "); | |
| 562 if (i * rtcp_count >= rtcp_index * rtp_count) { | |
| 563 printf("rtcp "); | |
| 564 rtcp_index++; | |
| 565 } | |
| 566 if (i * playout_count >= playout_index * rtp_count) { | |
| 567 printf("play "); | |
| 568 playout_index++; | |
| 569 } | |
| 570 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { | |
| 571 printf("loss "); | |
| 572 bwe_loss_index++; | |
| 573 } | |
| 574 } | |
| 575 printf("\n"); | |
| 576 } | 344 } |
| 577 VerifyLogStartEvent(parsed_stream.stream(0)); | 345 RtcEventLogTestHelper::VerifyLogStartEvent(parsed_log, 0); |
| 578 VerifyReceiveStreamConfig(parsed_stream.stream(1), receiver_config); | 346 RtcEventLogTestHelper::VerifyReceiveStreamConfig(parsed_log, 1, |
| 579 VerifySendStreamConfig(parsed_stream.stream(2), sender_config); | 347 receiver_config); |
| 348 RtcEventLogTestHelper::VerifySendStreamConfig(parsed_log, 2, sender_config); |
| 580 size_t event_index = config_count + 1; | 349 size_t event_index = config_count + 1; |
| 581 size_t rtcp_index = 1; | 350 size_t rtcp_index = 1; |
| 582 size_t playout_index = 1; | 351 size_t playout_index = 1; |
| 583 size_t bwe_loss_index = 1; | 352 size_t bwe_loss_index = 1; |
| 584 for (size_t i = 1; i <= rtp_count; i++) { | 353 for (size_t i = 1; i <= rtp_count; i++) { |
| 585 VerifyRtpEvent(parsed_stream.stream(event_index), | 354 RtcEventLogTestHelper::VerifyRtpEvent( |
| 586 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, | 355 parsed_log, event_index, |
| 587 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 356 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, |
| 588 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1], | 357 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
| 589 rtp_packets[i - 1].size()); | 358 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1], |
| 359 rtp_packets[i - 1].size()); |
| 590 event_index++; | 360 event_index++; |
| 591 if (i * rtcp_count >= rtcp_index * rtp_count) { | 361 if (i * rtcp_count >= rtcp_index * rtp_count) { |
| 592 VerifyRtcpEvent(parsed_stream.stream(event_index), | 362 RtcEventLogTestHelper::VerifyRtcpEvent( |
| 593 (rtcp_index % 2 == 0) ? kIncomingPacket : kOutgoingPacket, | 363 parsed_log, event_index, |
| 594 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, | 364 rtcp_index % 2 == 0 ? kIncomingPacket : kOutgoingPacket, |
| 595 rtcp_packets[rtcp_index - 1].data(), | 365 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, |
| 596 rtcp_packets[rtcp_index - 1].size()); | 366 rtcp_packets[rtcp_index - 1].data(), |
| 367 rtcp_packets[rtcp_index - 1].size()); |
| 597 event_index++; | 368 event_index++; |
| 598 rtcp_index++; | 369 rtcp_index++; |
| 599 } | 370 } |
| 600 if (i * playout_count >= playout_index * rtp_count) { | 371 if (i * playout_count >= playout_index * rtp_count) { |
| 601 VerifyPlayoutEvent(parsed_stream.stream(event_index), | 372 RtcEventLogTestHelper::VerifyPlayoutEvent( |
| 602 playout_ssrcs[playout_index - 1]); | 373 parsed_log, event_index, playout_ssrcs[playout_index - 1]); |
| 603 event_index++; | 374 event_index++; |
| 604 playout_index++; | 375 playout_index++; |
| 605 } | 376 } |
| 606 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { | 377 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { |
| 607 VerifyBweLossEvent(parsed_stream.stream(event_index), | 378 RtcEventLogTestHelper::VerifyBweLossEvent( |
| 608 bwe_loss_updates[bwe_loss_index - 1].first, | 379 parsed_log, event_index, bwe_loss_updates[bwe_loss_index - 1].first, |
| 609 bwe_loss_updates[bwe_loss_index - 1].second, i); | 380 bwe_loss_updates[bwe_loss_index - 1].second, i); |
| 610 event_index++; | 381 event_index++; |
| 611 bwe_loss_index++; | 382 bwe_loss_index++; |
| 612 } | 383 } |
| 613 } | 384 } |
| 614 | 385 |
| 615 // Clean up temporary file - can be pretty slow. | 386 // Clean up temporary file - can be pretty slow. |
| 616 remove(temp_filename.c_str()); | 387 remove(temp_filename.c_str()); |
| 617 } | 388 } |
| 618 | 389 |
| 619 TEST(RtcEventLogTest, LogSessionAndReadBack) { | 390 TEST(RtcEventLogTest, LogSessionAndReadBack) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 log_dumper->StartLogging(temp_filename, 10000000); | 447 log_dumper->StartLogging(temp_filename, 10000000); |
| 677 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 448 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 678 | 449 |
| 679 log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO, | 450 log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO, |
| 680 rtcp_packet.data(), rtcp_packet.size()); | 451 rtcp_packet.data(), rtcp_packet.size()); |
| 681 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 452 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 682 | 453 |
| 683 log_dumper->StopLogging(); | 454 log_dumper->StopLogging(); |
| 684 | 455 |
| 685 // Read the generated file from disk. | 456 // Read the generated file from disk. |
| 686 rtclog::EventStream parsed_stream; | 457 ParsedRtcEventLog parsed_log; |
| 687 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | 458 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); |
| 688 | 459 |
| 689 // Verify that what we read back from the event log is the same as | 460 // Verify that what we read back from the event log is the same as |
| 690 // what we wrote down. | 461 // what we wrote down. |
| 691 EXPECT_EQ(4, parsed_stream.stream_size()); | 462 EXPECT_EQ(4u, parsed_log.GetNumberOfEvents()); |
| 692 | 463 |
| 693 VerifyLogStartEvent(parsed_stream.stream(0)); | 464 RtcEventLogTestHelper::VerifyLogStartEvent(parsed_log, 0); |
| 694 | 465 |
| 695 VerifyRtpEvent(parsed_stream.stream(1), kIncomingPacket, MediaType::VIDEO, | 466 RtcEventLogTestHelper::VerifyRtpEvent(parsed_log, 1, kIncomingPacket, |
| 696 rtp_packet.data(), header_size, rtp_packet.size()); | 467 MediaType::VIDEO, rtp_packet.data(), |
| 468 header_size, rtp_packet.size()); |
| 697 | 469 |
| 698 VerifyRtcpEvent(parsed_stream.stream(2), kOutgoingPacket, MediaType::VIDEO, | 470 RtcEventLogTestHelper::VerifyRtcpEvent(parsed_log, 2, kOutgoingPacket, |
| 699 rtcp_packet.data(), rtcp_packet.size()); | 471 MediaType::VIDEO, rtcp_packet.data(), |
| 472 rtcp_packet.size()); |
| 700 | 473 |
| 701 VerifyLogEndEvent(parsed_stream.stream(3)); | 474 RtcEventLogTestHelper::VerifyLogEndEvent(parsed_log, 3); |
| 702 | 475 |
| 703 // Clean up temporary file - can be pretty slow. | 476 // Clean up temporary file - can be pretty slow. |
| 704 remove(temp_filename.c_str()); | 477 remove(temp_filename.c_str()); |
| 705 } | 478 } |
| 706 } // namespace webrtc | 479 } // namespace webrtc |
| 707 | 480 |
| 708 #endif // ENABLE_RTC_EVENT_LOG | 481 #endif // ENABLE_RTC_EVENT_LOG |
| OLD | NEW |