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/buffer.h" |
18 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/scoped_ptr.h" | 20 #include "webrtc/base/scoped_ptr.h" |
20 #include "webrtc/call.h" | 21 #include "webrtc/call.h" |
| 22 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" |
21 #include "webrtc/system_wrappers/interface/clock.h" | 23 #include "webrtc/system_wrappers/interface/clock.h" |
22 #include "webrtc/test/test_suite.h" | 24 #include "webrtc/test/test_suite.h" |
23 #include "webrtc/test/testsupport/fileutils.h" | 25 #include "webrtc/test/testsupport/fileutils.h" |
24 #include "webrtc/test/testsupport/gtest_disable.h" | 26 #include "webrtc/test/testsupport/gtest_disable.h" |
25 #include "webrtc/video/rtc_event_log.h" | 27 #include "webrtc/video/rtc_event_log.h" |
26 | 28 |
27 // Files generated at build-time by the protobuf compiler. | 29 // Files generated at build-time by the protobuf compiler. |
28 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 30 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
29 #include "external/webrtc/webrtc/video/rtc_event_log.pb.h" | 31 #include "external/webrtc/webrtc/video/rtc_event_log.pb.h" |
30 #else | 32 #else |
31 #include "webrtc/video/rtc_event_log.pb.h" | 33 #include "webrtc/video/rtc_event_log.pb.h" |
32 #endif | 34 #endif |
33 | 35 |
34 namespace webrtc { | 36 namespace webrtc { |
35 | 37 |
| 38 namespace { |
| 39 |
| 40 const RTPExtensionType kExtensionTypes[] = { |
| 41 RTPExtensionType::kRtpExtensionTransmissionTimeOffset, |
| 42 RTPExtensionType::kRtpExtensionAudioLevel, |
| 43 RTPExtensionType::kRtpExtensionAbsoluteSendTime, |
| 44 RTPExtensionType::kRtpExtensionVideoRotation, |
| 45 RTPExtensionType::kRtpExtensionTransportSequenceNumber}; |
| 46 const char* kExtensionNames[] = {RtpExtension::kTOffset, |
| 47 RtpExtension::kAudioLevel, |
| 48 RtpExtension::kAbsSendTime, |
| 49 RtpExtension::kVideoRotation, |
| 50 RtpExtension::kTransportSequenceNumber}; |
| 51 const size_t kNumExtensions = 5; |
| 52 |
| 53 } // namepsace |
| 54 |
36 // TODO(terelius): Place this definition with other parsing functions? | 55 // TODO(terelius): Place this definition with other parsing functions? |
37 MediaType GetRuntimeMediaType(rtclog::MediaType media_type) { | 56 MediaType GetRuntimeMediaType(rtclog::MediaType media_type) { |
38 switch (media_type) { | 57 switch (media_type) { |
39 case rtclog::MediaType::ANY: | 58 case rtclog::MediaType::ANY: |
40 return MediaType::ANY; | 59 return MediaType::ANY; |
41 case rtclog::MediaType::AUDIO: | 60 case rtclog::MediaType::AUDIO: |
42 return MediaType::AUDIO; | 61 return MediaType::AUDIO; |
43 case rtclog::MediaType::VIDEO: | 62 case rtclog::MediaType::VIDEO: |
44 return MediaType::VIDEO; | 63 return MediaType::VIDEO; |
45 case rtclog::MediaType::DATA: | 64 case rtclog::MediaType::DATA: |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 EXPECT_EQ(incoming, rtcp_packet.incoming()); | 258 EXPECT_EQ(incoming, rtcp_packet.incoming()); |
240 ASSERT_TRUE(rtcp_packet.has_type()); | 259 ASSERT_TRUE(rtcp_packet.has_type()); |
241 EXPECT_EQ(media_type, GetRuntimeMediaType(rtcp_packet.type())); | 260 EXPECT_EQ(media_type, GetRuntimeMediaType(rtcp_packet.type())); |
242 ASSERT_TRUE(rtcp_packet.has_packet_data()); | 261 ASSERT_TRUE(rtcp_packet.has_packet_data()); |
243 ASSERT_EQ(total_size, rtcp_packet.packet_data().size()); | 262 ASSERT_EQ(total_size, rtcp_packet.packet_data().size()); |
244 for (size_t i = 0; i < total_size; i++) { | 263 for (size_t i = 0; i < total_size; i++) { |
245 EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.packet_data()[i])); | 264 EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.packet_data()[i])); |
246 } | 265 } |
247 } | 266 } |
248 | 267 |
| 268 void VerifyPlayoutEvent(const rtclog::Event& event) { |
| 269 ASSERT_TRUE(IsValidBasicEvent(event)); |
| 270 ASSERT_EQ(rtclog::Event::DEBUG_EVENT, event.type()); |
| 271 const rtclog::DebugEvent& debug_event = event.debug_event(); |
| 272 ASSERT_TRUE(debug_event.has_type()); |
| 273 EXPECT_EQ(rtclog::DebugEvent::AUDIO_PLAYOUT, debug_event.type()); |
| 274 } |
| 275 |
249 void VerifyLogStartEvent(const rtclog::Event& event) { | 276 void VerifyLogStartEvent(const rtclog::Event& event) { |
250 ASSERT_TRUE(IsValidBasicEvent(event)); | 277 ASSERT_TRUE(IsValidBasicEvent(event)); |
251 ASSERT_EQ(rtclog::Event::DEBUG_EVENT, event.type()); | 278 ASSERT_EQ(rtclog::Event::DEBUG_EVENT, event.type()); |
252 const rtclog::DebugEvent& debug_event = event.debug_event(); | 279 const rtclog::DebugEvent& debug_event = event.debug_event(); |
253 ASSERT_TRUE(debug_event.has_type()); | 280 ASSERT_TRUE(debug_event.has_type()); |
254 EXPECT_EQ(rtclog::DebugEvent::LOG_START, debug_event.type()); | 281 EXPECT_EQ(rtclog::DebugEvent::LOG_START, debug_event.type()); |
255 } | 282 } |
256 | 283 |
257 void GenerateVideoReceiveConfig(VideoReceiveStream::Config* config) { | 284 /* |
| 285 * Bit number i of extension_bitvector is set to indicate the |
| 286 * presence of extension number i from kExtensionTypes / kExtensionNames. |
| 287 * The least significant bit extension_bitvector has number 0. |
| 288 */ |
| 289 size_t GenerateRtpPacket(uint32_t extensions_bitvector, |
| 290 uint32_t csrcs_count, |
| 291 uint8_t* packet, |
| 292 size_t packet_size) { |
| 293 CHECK_GE(packet_size, 16 + 4 * csrcs_count + 4 * kNumExtensions); |
| 294 Clock* clock = Clock::GetRealTimeClock(); |
| 295 |
| 296 RTPSender rtp_sender(0, // int32_t id |
| 297 false, // bool audio |
| 298 clock, // Clock* clock |
| 299 nullptr, // Transport* |
| 300 nullptr, // RtpAudioFeedback* |
| 301 nullptr, // PacedSender* |
| 302 nullptr, // PacketRouter* |
| 303 nullptr, // SendTimeObserver* |
| 304 nullptr, // BitrateStatisticsObserver* |
| 305 nullptr, // FrameCountObserver* |
| 306 nullptr); // SendSideDelayObserver* |
| 307 |
| 308 std::vector<uint32_t> csrcs; |
| 309 for (unsigned i = 0; i < csrcs_count; i++) { |
| 310 csrcs.push_back(rand()); |
| 311 } |
| 312 rtp_sender.SetCsrcs(csrcs); |
| 313 rtp_sender.SetSSRC(rand()); |
| 314 rtp_sender.SetStartTimestamp(rand(), true); |
| 315 rtp_sender.SetSequenceNumber(rand()); |
| 316 |
| 317 for (unsigned i = 0; i < kNumExtensions; i++) { |
| 318 if (extensions_bitvector & (1u << i)) { |
| 319 rtp_sender.RegisterRtpHeaderExtension(kExtensionTypes[i], i + 1); |
| 320 } |
| 321 } |
| 322 |
| 323 int8_t payload_type = rand() % 128; |
| 324 bool marker_bit = (rand() % 2 == 1); |
| 325 uint32_t capture_timestamp = rand(); |
| 326 int64_t capture_time_ms = rand(); |
| 327 bool timestamp_provided = (rand() % 2 == 1); |
| 328 bool inc_sequence_number = (rand() % 2 == 1); |
| 329 |
| 330 size_t header_size = rtp_sender.BuildRTPheader( |
| 331 packet, payload_type, marker_bit, capture_timestamp, capture_time_ms, |
| 332 timestamp_provided, inc_sequence_number); |
| 333 |
| 334 for (size_t i = header_size; i < packet_size; i++) { |
| 335 packet[i] = rand(); |
| 336 } |
| 337 |
| 338 return header_size; |
| 339 } |
| 340 |
| 341 void GenerateRtcpPacket(uint8_t* packet, size_t packet_size) { |
| 342 for (size_t i = 0; i < packet_size; i++) { |
| 343 packet[i] = rand(); |
| 344 } |
| 345 } |
| 346 |
| 347 void GenerateVideoReceiveConfig(uint32_t extensions_bitvector, |
| 348 VideoReceiveStream::Config* config) { |
258 // Create a map from a payload type to an encoder name. | 349 // Create a map from a payload type to an encoder name. |
259 VideoReceiveStream::Decoder decoder; | 350 VideoReceiveStream::Decoder decoder; |
260 decoder.payload_type = rand(); | 351 decoder.payload_type = rand(); |
261 decoder.payload_name = (rand() % 2 ? "VP8" : "H264"); | 352 decoder.payload_name = (rand() % 2 ? "VP8" : "H264"); |
262 config->decoders.push_back(decoder); | 353 config->decoders.push_back(decoder); |
263 // Add SSRCs for the stream. | 354 // Add SSRCs for the stream. |
264 config->rtp.remote_ssrc = rand(); | 355 config->rtp.remote_ssrc = rand(); |
265 config->rtp.local_ssrc = rand(); | 356 config->rtp.local_ssrc = rand(); |
266 // Add extensions and settings for RTCP. | 357 // Add extensions and settings for RTCP. |
267 config->rtp.rtcp_mode = rand() % 2 ? newapi::kRtcpCompound | 358 config->rtp.rtcp_mode = rand() % 2 ? newapi::kRtcpCompound |
268 : newapi::kRtcpReducedSize; | 359 : newapi::kRtcpReducedSize; |
269 config->rtp.rtcp_xr.receiver_reference_time_report = | 360 config->rtp.rtcp_xr.receiver_reference_time_report = (rand() % 2 == 1); |
270 static_cast<bool>(rand() % 2); | 361 config->rtp.remb = (rand() % 2 == 1); |
271 config->rtp.remb = static_cast<bool>(rand() % 2); | |
272 // Add a map from a payload type to a new ssrc and a new payload type for RTX. | 362 // Add a map from a payload type to a new ssrc and a new payload type for RTX. |
273 VideoReceiveStream::Config::Rtp::Rtx rtx_pair; | 363 VideoReceiveStream::Config::Rtp::Rtx rtx_pair; |
274 rtx_pair.ssrc = rand(); | 364 rtx_pair.ssrc = rand(); |
275 rtx_pair.payload_type = rand(); | 365 rtx_pair.payload_type = rand(); |
276 config->rtp.rtx.insert(std::make_pair(rand(), rtx_pair)); | 366 config->rtp.rtx.insert(std::make_pair(rand(), rtx_pair)); |
277 // Add two random header extensions. | 367 // Add header extensions. |
278 const char* extension_name = rand() % 2 ? RtpExtension::kTOffset | 368 for (unsigned i = 0; i < kNumExtensions; i++) { |
279 : RtpExtension::kVideoRotation; | 369 if (extensions_bitvector & (1u << i)) { |
280 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); | 370 config->rtp.extensions.push_back( |
281 extension_name = rand() % 2 ? RtpExtension::kAudioLevel | 371 RtpExtension(kExtensionNames[i], rand())); |
282 : RtpExtension::kAbsSendTime; | 372 } |
283 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); | 373 } |
284 } | 374 } |
285 | 375 |
286 void GenerateVideoSendConfig(VideoSendStream::Config* config) { | 376 void GenerateVideoSendConfig(uint32_t extensions_bitvector, |
| 377 VideoSendStream::Config* config) { |
287 // Create a map from a payload type to an encoder name. | 378 // Create a map from a payload type to an encoder name. |
288 config->encoder_settings.payload_type = rand(); | 379 config->encoder_settings.payload_type = rand(); |
289 config->encoder_settings.payload_name = (rand() % 2 ? "VP8" : "H264"); | 380 config->encoder_settings.payload_name = (rand() % 2 ? "VP8" : "H264"); |
290 // Add SSRCs for the stream. | 381 // Add SSRCs for the stream. |
291 config->rtp.ssrcs.push_back(rand()); | 382 config->rtp.ssrcs.push_back(rand()); |
292 // Add a map from a payload type to new ssrcs and a new payload type for RTX. | 383 // Add a map from a payload type to new ssrcs and a new payload type for RTX. |
293 config->rtp.rtx.ssrcs.push_back(rand()); | 384 config->rtp.rtx.ssrcs.push_back(rand()); |
294 config->rtp.rtx.payload_type = rand(); | 385 config->rtp.rtx.payload_type = rand(); |
295 // Add a CNAME. | 386 // Add a CNAME. |
296 config->rtp.c_name = "some.user@some.host"; | 387 config->rtp.c_name = "some.user@some.host"; |
297 // Add two random header extensions. | 388 // Add header extensions. |
298 const char* extension_name = rand() % 2 ? RtpExtension::kTOffset | 389 for (unsigned i = 0; i < kNumExtensions; i++) { |
299 : RtpExtension::kVideoRotation; | 390 if (extensions_bitvector & (1u << i)) { |
300 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); | 391 config->rtp.extensions.push_back( |
301 extension_name = rand() % 2 ? RtpExtension::kAudioLevel | 392 RtpExtension(kExtensionNames[i], rand())); |
302 : RtpExtension::kAbsSendTime; | 393 } |
303 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); | 394 } |
304 } | 395 } |
305 | 396 |
306 // Test for the RtcEventLog class. Dumps some RTP packets to disk, then reads | 397 // Test for the RtcEventLog class. Dumps some RTP packets to disk, then reads |
307 // them back to see if they match. | 398 // them back to see if they match. |
308 void LogSessionAndReadBack(size_t rtp_count, unsigned random_seed) { | 399 void LogSessionAndReadBack(size_t rtp_count, |
309 std::vector<std::vector<uint8_t>> rtp_packets; | 400 size_t rtcp_count, |
310 std::vector<uint8_t> incoming_rtcp_packet; | 401 size_t debug_count, |
311 std::vector<uint8_t> outgoing_rtcp_packet; | 402 uint32_t extensions_bitvector, |
| 403 uint32_t csrcs_count, |
| 404 unsigned random_seed) { |
| 405 ASSERT_LE(rtcp_count, rtp_count); |
| 406 ASSERT_LE(debug_count, rtp_count); |
| 407 std::vector<rtc::Buffer> rtp_packets; |
| 408 std::vector<rtc::Buffer> rtcp_packets; |
| 409 std::vector<size_t> rtp_header_sizes; |
312 | 410 |
313 VideoReceiveStream::Config receiver_config; | 411 VideoReceiveStream::Config receiver_config; |
314 VideoSendStream::Config sender_config; | 412 VideoSendStream::Config sender_config; |
315 | 413 |
316 srand(random_seed); | 414 srand(random_seed); |
317 | 415 |
318 // Create rtp_count RTP packets containing random data. | 416 // Create rtp_count RTP packets containing random data. |
319 const size_t rtp_header_size = 20; | |
320 for (size_t i = 0; i < rtp_count; i++) { | 417 for (size_t i = 0; i < rtp_count; i++) { |
321 size_t packet_size = 1000 + rand() % 30; | 418 size_t packet_size = 1000 + rand() % 64; |
322 rtp_packets.push_back(std::vector<uint8_t>()); | 419 rtp_packets.push_back(rtc::Buffer(packet_size)); |
323 rtp_packets[i].reserve(packet_size); | 420 size_t header_size = GenerateRtpPacket(extensions_bitvector, csrcs_count, |
324 for (size_t j = 0; j < packet_size; j++) { | 421 rtp_packets[i].data(), packet_size); |
325 rtp_packets[i].push_back(rand()); | 422 rtp_header_sizes.push_back(header_size); |
326 } | |
327 } | 423 } |
328 // Create two RTCP packets containing random data. | 424 // Create rtcp_count RTCP packets containing random data. |
329 size_t packet_size = 1000 + rand() % 30; | 425 for (size_t i = 0; i < rtcp_count; i++) { |
330 outgoing_rtcp_packet.reserve(packet_size); | 426 size_t packet_size = 1000 + rand() % 64; |
331 for (size_t j = 0; j < packet_size; j++) { | 427 rtcp_packets.push_back(rtc::Buffer(packet_size)); |
332 outgoing_rtcp_packet.push_back(rand()); | 428 GenerateRtcpPacket(rtcp_packets[i].data(), packet_size); |
333 } | |
334 packet_size = 1000 + rand() % 30; | |
335 incoming_rtcp_packet.reserve(packet_size); | |
336 for (size_t j = 0; j < packet_size; j++) { | |
337 incoming_rtcp_packet.push_back(rand()); | |
338 } | 429 } |
339 // Create configurations for the video streams. | 430 // Create configurations for the video streams. |
340 GenerateVideoReceiveConfig(&receiver_config); | 431 GenerateVideoReceiveConfig(extensions_bitvector, &receiver_config); |
341 GenerateVideoSendConfig(&sender_config); | 432 GenerateVideoSendConfig(extensions_bitvector, &sender_config); |
| 433 const int config_count = 2; |
342 | 434 |
343 // Find the name of the current test, in order to use it as a temporary | 435 // Find the name of the current test, in order to use it as a temporary |
344 // filename. | 436 // filename. |
345 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 437 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
346 const std::string temp_filename = | 438 const std::string temp_filename = |
347 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 439 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
348 | 440 |
349 // When log_dumper goes out of scope, it causes the log file to be flushed | 441 // When log_dumper goes out of scope, it causes the log file to be flushed |
350 // to disk. | 442 // to disk. |
351 { | 443 { |
352 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); | 444 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); |
353 log_dumper->LogVideoReceiveStreamConfig(receiver_config); | 445 log_dumper->LogVideoReceiveStreamConfig(receiver_config); |
354 log_dumper->LogVideoSendStreamConfig(sender_config); | 446 log_dumper->LogVideoSendStreamConfig(sender_config); |
355 size_t i = 0; | 447 size_t rtcp_index = 1, debug_index = 1; |
356 for (; i < rtp_count / 2; i++) { | 448 for (size_t i = 1; i <= rtp_count; i++) { |
357 log_dumper->LogRtpHeader( | 449 log_dumper->LogRtpHeader( |
358 (i % 2 == 0), // Every second packet is incoming. | 450 (i % 2 == 0), // Every second packet is incoming. |
359 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 451 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
360 rtp_packets[i].data(), rtp_header_size, rtp_packets[i].size()); | 452 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); |
| 453 if (i * rtcp_count >= rtcp_index * rtp_count) { |
| 454 log_dumper->LogRtcpPacket( |
| 455 rtcp_index % 2 == 0, // Every second packet is incoming |
| 456 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, |
| 457 rtcp_packets[rtcp_index - 1].data(), |
| 458 rtcp_packets[rtcp_index - 1].size()); |
| 459 rtcp_index++; |
| 460 } |
| 461 if (i * debug_count >= debug_index * rtp_count) { |
| 462 log_dumper->LogDebugEvent(RtcEventLog::DebugEvent::kAudioPlayout); |
| 463 debug_index++; |
| 464 } |
| 465 if (i == rtp_count / 2) { |
| 466 log_dumper->StartLogging(temp_filename, 10000000); |
| 467 } |
361 } | 468 } |
362 log_dumper->LogRtcpPacket(false, MediaType::AUDIO, | |
363 outgoing_rtcp_packet.data(), | |
364 outgoing_rtcp_packet.size()); | |
365 log_dumper->StartLogging(temp_filename, 10000000); | |
366 for (; i < rtp_count; i++) { | |
367 log_dumper->LogRtpHeader( | |
368 (i % 2 == 0), // Every second packet is incoming, | |
369 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | |
370 rtp_packets[i].data(), rtp_header_size, rtp_packets[i].size()); | |
371 } | |
372 log_dumper->LogRtcpPacket(true, MediaType::VIDEO, | |
373 incoming_rtcp_packet.data(), | |
374 incoming_rtcp_packet.size()); | |
375 } | 469 } |
376 | 470 |
377 const int config_count = 2; | |
378 const int rtcp_count = 2; | |
379 const int debug_count = 1; // Only LogStart event, | |
380 const int event_count = config_count + debug_count + rtcp_count + rtp_count; | |
381 | |
382 // Read the generated file from disk. | 471 // Read the generated file from disk. |
383 rtclog::EventStream parsed_stream; | 472 rtclog::EventStream parsed_stream; |
384 | 473 |
385 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | 474 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); |
386 | 475 |
387 // Verify the result. | 476 // Verify the result. |
| 477 const int event_count = |
| 478 config_count + debug_count + rtcp_count + rtp_count + 1; |
388 EXPECT_EQ(event_count, parsed_stream.stream_size()); | 479 EXPECT_EQ(event_count, parsed_stream.stream_size()); |
389 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); | 480 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); |
390 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); | 481 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); |
391 size_t i = 0; | 482 size_t event_index = config_count, rtcp_index = 1, debug_index = 1; |
392 for (; i < rtp_count / 2; i++) { | 483 for (size_t i = 1; i <= rtp_count; i++) { |
393 VerifyRtpEvent(parsed_stream.stream(config_count + i), | 484 VerifyRtpEvent(parsed_stream.stream(event_index), |
394 (i % 2 == 0), // Every second packet is incoming. | 485 (i % 2 == 0), // Every second packet is incoming. |
395 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 486 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
396 rtp_packets[i].data(), rtp_header_size, | 487 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1], |
397 rtp_packets[i].size()); | 488 rtp_packets[i - 1].size()); |
| 489 event_index++; |
| 490 if (i * rtcp_count >= rtcp_index * rtp_count) { |
| 491 VerifyRtcpEvent(parsed_stream.stream(event_index), |
| 492 rtcp_index % 2 == 0, // Every second packet is incoming. |
| 493 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, |
| 494 rtcp_packets[rtcp_index - 1].data(), |
| 495 rtcp_packets[rtcp_index - 1].size()); |
| 496 event_index++; |
| 497 rtcp_index++; |
| 498 } |
| 499 if (i * debug_count >= debug_index * rtp_count) { |
| 500 VerifyPlayoutEvent(parsed_stream.stream(event_index)); |
| 501 event_index++; |
| 502 debug_index++; |
| 503 } |
| 504 if (i == rtp_count / 2) { |
| 505 VerifyLogStartEvent(parsed_stream.stream(event_index)); |
| 506 event_index++; |
| 507 } |
398 } | 508 } |
399 VerifyRtcpEvent(parsed_stream.stream(config_count + rtp_count / 2), | |
400 false, // Outgoing RTCP packet. | |
401 MediaType::AUDIO, outgoing_rtcp_packet.data(), | |
402 outgoing_rtcp_packet.size()); | |
403 | |
404 VerifyLogStartEvent(parsed_stream.stream(1 + config_count + rtp_count / 2)); | |
405 for (; i < rtp_count; i++) { | |
406 VerifyRtpEvent(parsed_stream.stream(2 + config_count + i), | |
407 (i % 2 == 0), // Every second packet is incoming. | |
408 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | |
409 rtp_packets[i].data(), rtp_header_size, | |
410 rtp_packets[i].size()); | |
411 } | |
412 VerifyRtcpEvent(parsed_stream.stream(2 + config_count + rtp_count), | |
413 true, // Incoming RTCP packet. | |
414 MediaType::VIDEO, incoming_rtcp_packet.data(), | |
415 incoming_rtcp_packet.size()); | |
416 | 509 |
417 // Clean up temporary file - can be pretty slow. | 510 // Clean up temporary file - can be pretty slow. |
418 remove(temp_filename.c_str()); | 511 remove(temp_filename.c_str()); |
419 } | 512 } |
420 | 513 |
421 TEST(RtcEventLogTest, LogSessionAndReadBack) { | 514 TEST(RtcEventLogTest, LogSessionAndReadBack) { |
422 LogSessionAndReadBack(5, 321); | 515 // Log 5 RTP, 2 RTCP, and 0 playout events with no header extensions or CSRCS. |
423 LogSessionAndReadBack(8, 3141592653u); | 516 LogSessionAndReadBack(5, 2, 0, 0, 0, 321); |
424 LogSessionAndReadBack(9, 2718281828u); | 517 |
| 518 // Enable AbsSendTime and TransportSequenceNumbers |
| 519 uint32_t extensions = 0; |
| 520 for (uint32_t i = 0; i < kNumExtensions; i++) { |
| 521 if (kExtensionTypes[i] == RTPExtensionType::kRtpExtensionAbsoluteSendTime || |
| 522 kExtensionTypes[i] == |
| 523 RTPExtensionType::kRtpExtensionTransportSequenceNumber) { |
| 524 extensions |= 1u << i; |
| 525 } |
| 526 } |
| 527 LogSessionAndReadBack(8, 2, 0, extensions, 0, 3141592653u); |
| 528 |
| 529 extensions = (1u << kNumExtensions) - 1; // Enable all header extensions |
| 530 LogSessionAndReadBack(9, 2, 3, extensions, 2, 2718281828u); |
| 531 |
| 532 // Try all combinations of header extensions and up to 2 CSRCS. |
| 533 for (extensions = 0; extensions < (1u << kNumExtensions); extensions++) { |
| 534 for (uint32_t csrcs_count = 0; csrcs_count < 3; csrcs_count++) { |
| 535 LogSessionAndReadBack(5 + extensions, // Number of RTP packets. |
| 536 2 + csrcs_count, // Number of RTCP packets. |
| 537 3 + csrcs_count, // Number of playout events |
| 538 extensions, // Bit vector choosing extensions |
| 539 csrcs_count, // Number of contributing sources |
| 540 rand()); |
| 541 } |
| 542 } |
425 } | 543 } |
426 | 544 |
427 } // namespace webrtc | 545 } // namespace webrtc |
428 | 546 |
429 #endif // ENABLE_RTC_EVENT_LOG | 547 #endif // ENABLE_RTC_EVENT_LOG |
OLD | NEW |