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() & 0x01; | |
stefan-webrtc
2015/09/03 09:38:34
I think you may have to cast this to bool to avoid
terelius
2015/09/03 11:33:23
The C++ standard and all our trybots allow implici
| |
325 uint32_t capture_timestamp = rand(); | |
326 int64_t capture_time_ms = rand(); | |
327 bool timestamp_provided = rand() & 0x01; | |
328 bool inc_sequence_number = rand() & 0x01; | |
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 = |
270 static_cast<bool>(rand() % 2); | 361 static_cast<bool>(rand() % 2); |
271 config->rtp.remb = static_cast<bool>(rand() % 2); | 362 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. | 363 // 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; | 364 VideoReceiveStream::Config::Rtp::Rtx rtx_pair; |
274 rtx_pair.ssrc = rand(); | 365 rtx_pair.ssrc = rand(); |
275 rtx_pair.payload_type = rand(); | 366 rtx_pair.payload_type = rand(); |
276 config->rtp.rtx.insert(std::make_pair(rand(), rtx_pair)); | 367 config->rtp.rtx.insert(std::make_pair(rand(), rtx_pair)); |
277 // Add two random header extensions. | 368 // Add header extensions. |
278 const char* extension_name = rand() % 2 ? RtpExtension::kTOffset | 369 for (unsigned i = 0; i < kNumExtensions; i++) { |
279 : RtpExtension::kVideoRotation; | 370 if (extensions_bitvector & (1u << i)) { |
280 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); | 371 config->rtp.extensions.push_back( |
281 extension_name = rand() % 2 ? RtpExtension::kAudioLevel | 372 RtpExtension(kExtensionNames[i], rand())); |
282 : RtpExtension::kAbsSendTime; | 373 } |
283 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); | 374 } |
284 } | 375 } |
285 | 376 |
286 void GenerateVideoSendConfig(VideoSendStream::Config* config) { | 377 void GenerateVideoSendConfig(uint32_t extensions_bitvector, |
378 VideoSendStream::Config* config) { | |
287 // Create a map from a payload type to an encoder name. | 379 // Create a map from a payload type to an encoder name. |
288 config->encoder_settings.payload_type = rand(); | 380 config->encoder_settings.payload_type = rand(); |
289 config->encoder_settings.payload_name = (rand() % 2 ? "VP8" : "H264"); | 381 config->encoder_settings.payload_name = (rand() % 2 ? "VP8" : "H264"); |
290 // Add SSRCs for the stream. | 382 // Add SSRCs for the stream. |
291 config->rtp.ssrcs.push_back(rand()); | 383 config->rtp.ssrcs.push_back(rand()); |
292 // Add a map from a payload type to new ssrcs and a new payload type for RTX. | 384 // 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()); | 385 config->rtp.rtx.ssrcs.push_back(rand()); |
294 config->rtp.rtx.payload_type = rand(); | 386 config->rtp.rtx.payload_type = rand(); |
295 // Add a CNAME. | 387 // Add a CNAME. |
296 config->rtp.c_name = "some.user@some.host"; | 388 config->rtp.c_name = "some.user@some.host"; |
297 // Add two random header extensions. | 389 // Add header extensions. |
298 const char* extension_name = rand() % 2 ? RtpExtension::kTOffset | 390 for (unsigned i = 0; i < kNumExtensions; i++) { |
299 : RtpExtension::kVideoRotation; | 391 if (extensions_bitvector & (1u << i)) { |
300 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); | 392 config->rtp.extensions.push_back( |
301 extension_name = rand() % 2 ? RtpExtension::kAudioLevel | 393 RtpExtension(kExtensionNames[i], rand())); |
302 : RtpExtension::kAbsSendTime; | 394 } |
303 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); | 395 } |
304 } | 396 } |
305 | 397 |
306 // Test for the RtcEventLog class. Dumps some RTP packets to disk, then reads | 398 // Test for the RtcEventLog class. Dumps some RTP packets to disk, then reads |
307 // them back to see if they match. | 399 // them back to see if they match. |
308 void LogSessionAndReadBack(size_t rtp_count, unsigned random_seed) { | 400 void LogSessionAndReadBack(size_t rtp_count, |
309 std::vector<std::vector<uint8_t>> rtp_packets; | 401 size_t rtcp_count, |
310 std::vector<uint8_t> incoming_rtcp_packet; | 402 size_t debug_count, |
311 std::vector<uint8_t> outgoing_rtcp_packet; | 403 uint32_t extensions_bitvector, |
404 uint32_t csrcs_count, | |
405 unsigned random_seed) { | |
406 ASSERT_LE(rtcp_count, rtp_count); | |
407 ASSERT_LE(debug_count, rtp_count); | |
408 std::vector<rtc::Buffer> rtp_packets; | |
409 std::vector<rtc::Buffer> rtcp_packets; | |
410 std::vector<size_t> rtp_header_sizes; | |
312 | 411 |
313 VideoReceiveStream::Config receiver_config; | 412 VideoReceiveStream::Config receiver_config; |
314 VideoSendStream::Config sender_config; | 413 VideoSendStream::Config sender_config; |
315 | 414 |
316 srand(random_seed); | 415 srand(random_seed); |
317 | 416 |
318 // Create rtp_count RTP packets containing random data. | 417 // 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++) { | 418 for (size_t i = 0; i < rtp_count; i++) { |
321 size_t packet_size = 1000 + rand() % 30; | 419 size_t packet_size = 1000 + rand() % 64; |
322 rtp_packets.push_back(std::vector<uint8_t>()); | 420 rtp_packets.push_back(rtc::Buffer(packet_size)); |
323 rtp_packets[i].reserve(packet_size); | 421 size_t header_size = GenerateRtpPacket(extensions_bitvector, csrcs_count, |
324 for (size_t j = 0; j < packet_size; j++) { | 422 rtp_packets[i].data(), packet_size); |
325 rtp_packets[i].push_back(rand()); | 423 rtp_header_sizes.push_back(header_size); |
326 } | |
327 } | 424 } |
328 // Create two RTCP packets containing random data. | 425 // Create rtcp_count RTCP packets containing random data. |
329 size_t packet_size = 1000 + rand() % 30; | 426 for (size_t i = 0; i < rtcp_count; i++) { |
330 outgoing_rtcp_packet.reserve(packet_size); | 427 size_t packet_size = 1000 + rand() % 64; |
331 for (size_t j = 0; j < packet_size; j++) { | 428 rtcp_packets.push_back(rtc::Buffer(packet_size)); |
332 outgoing_rtcp_packet.push_back(rand()); | 429 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 } | 430 } |
339 // Create configurations for the video streams. | 431 // Create configurations for the video streams. |
340 GenerateVideoReceiveConfig(&receiver_config); | 432 GenerateVideoReceiveConfig(extensions_bitvector, &receiver_config); |
341 GenerateVideoSendConfig(&sender_config); | 433 GenerateVideoSendConfig(extensions_bitvector, &sender_config); |
434 const int config_count = 2; | |
342 | 435 |
343 // Find the name of the current test, in order to use it as a temporary | 436 // Find the name of the current test, in order to use it as a temporary |
344 // filename. | 437 // filename. |
345 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 438 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
346 const std::string temp_filename = | 439 const std::string temp_filename = |
347 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 440 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
348 | 441 |
349 // When log_dumper goes out of scope, it causes the log file to be flushed | 442 // When log_dumper goes out of scope, it causes the log file to be flushed |
350 // to disk. | 443 // to disk. |
351 { | 444 { |
352 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); | 445 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); |
353 log_dumper->LogVideoReceiveStreamConfig(receiver_config); | 446 log_dumper->LogVideoReceiveStreamConfig(receiver_config); |
354 log_dumper->LogVideoSendStreamConfig(sender_config); | 447 log_dumper->LogVideoSendStreamConfig(sender_config); |
355 size_t i = 0; | 448 size_t rtcp_index = 1, debug_index = 1; |
356 for (; i < rtp_count / 2; i++) { | 449 for (size_t i = 1; i <= rtp_count; i++) { |
357 log_dumper->LogRtpHeader( | 450 log_dumper->LogRtpHeader( |
358 (i % 2 == 0), // Every second packet is incoming. | 451 (i % 2 == 0), // Every second packet is incoming. |
359 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 452 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
360 rtp_packets[i].data(), rtp_header_size, rtp_packets[i].size()); | 453 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); |
454 if (i * rtcp_count >= rtcp_index * rtp_count) { | |
455 log_dumper->LogRtcpPacket( | |
456 rtcp_index % 2 == 0, // Every second packet is incoming | |
457 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, | |
458 rtcp_packets[rtcp_index - 1].data(), | |
459 rtcp_packets[rtcp_index - 1].size()); | |
460 rtcp_index++; | |
461 } | |
462 if (i * debug_count >= debug_index * rtp_count) { | |
463 log_dumper->LogDebugEvent(RtcEventLog::DebugEvent::kAudioPlayout); | |
464 debug_index++; | |
465 } | |
466 if (i == rtp_count / 2) { | |
467 log_dumper->StartLogging(temp_filename, 10000000); | |
468 } | |
361 } | 469 } |
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 } | 470 } |
376 | 471 |
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. | 472 // Read the generated file from disk. |
383 rtclog::EventStream parsed_stream; | 473 rtclog::EventStream parsed_stream; |
384 | 474 |
385 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | 475 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); |
386 | 476 |
387 // Verify the result. | 477 // Verify the result. |
478 const int event_count = | |
479 config_count + debug_count + rtcp_count + rtp_count + 1; | |
388 EXPECT_EQ(event_count, parsed_stream.stream_size()); | 480 EXPECT_EQ(event_count, parsed_stream.stream_size()); |
389 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); | 481 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); |
390 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); | 482 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); |
391 size_t i = 0; | 483 size_t event_index = config_count, rtcp_index = 1, debug_index = 1; |
392 for (; i < rtp_count / 2; i++) { | 484 for (size_t i = 1; i <= rtp_count; i++) { |
393 VerifyRtpEvent(parsed_stream.stream(config_count + i), | 485 VerifyRtpEvent(parsed_stream.stream(event_index), |
394 (i % 2 == 0), // Every second packet is incoming. | 486 (i % 2 == 0), // Every second packet is incoming. |
395 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 487 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
396 rtp_packets[i].data(), rtp_header_size, | 488 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1], |
397 rtp_packets[i].size()); | 489 rtp_packets[i - 1].size()); |
490 event_index++; | |
491 if (i * rtcp_count >= rtcp_index * rtp_count) { | |
492 VerifyRtcpEvent(parsed_stream.stream(event_index), | |
493 rtcp_index % 2 == 0, // Every second packet is incoming. | |
494 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, | |
495 rtcp_packets[rtcp_index - 1].data(), | |
496 rtcp_packets[rtcp_index - 1].size()); | |
497 event_index++; | |
498 rtcp_index++; | |
499 } | |
500 if (i * debug_count >= debug_index * rtp_count) { | |
501 VerifyPlayoutEvent(parsed_stream.stream(event_index)); | |
502 event_index++; | |
503 debug_index++; | |
504 } | |
505 if (i == rtp_count / 2) { | |
506 VerifyLogStartEvent(parsed_stream.stream(event_index)); | |
507 event_index++; | |
508 } | |
398 } | 509 } |
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 | 510 |
417 // Clean up temporary file - can be pretty slow. | 511 // Clean up temporary file - can be pretty slow. |
418 remove(temp_filename.c_str()); | 512 remove(temp_filename.c_str()); |
419 } | 513 } |
420 | 514 |
421 TEST(RtcEventLogTest, LogSessionAndReadBack) { | 515 TEST(RtcEventLogTest, LogSessionAndReadBack) { |
422 LogSessionAndReadBack(5, 321); | 516 // Log 5 RTP, 2 RTCP, and 0 playout events with no header extensions or CSRCS. |
423 LogSessionAndReadBack(8, 3141592653u); | 517 LogSessionAndReadBack(5, 2, 0, 0, 0, 321); |
424 LogSessionAndReadBack(9, 2718281828u); | 518 |
519 // Enable AbsSendTime and TransportSequenceNumbers | |
520 uint32_t extensions = 0; | |
521 for (uint32_t i = 0; i < kNumExtensions; i++) { | |
522 if (kExtensionTypes[i] == RTPExtensionType::kRtpExtensionAbsoluteSendTime || | |
523 kExtensionTypes[i] == | |
524 RTPExtensionType::kRtpExtensionTransportSequenceNumber) { | |
525 extensions |= 1u << i; | |
526 } | |
527 } | |
528 LogSessionAndReadBack(8, 2, 0, extensions, 0, 3141592653u); | |
529 | |
530 extensions = (1u << kNumExtensions) - 1; // Enable all header extensions | |
531 LogSessionAndReadBack(9, 2, 3, extensions, 2, 2718281828u); | |
532 | |
533 // Try all combinations of header extensions and up to 2 CSRCS. | |
534 for (extensions = 0; extensions < (1u << kNumExtensions); extensions++) { | |
535 for (uint32_t csrcs_count = 0; csrcs_count < 3; csrcs_count++) { | |
536 LogSessionAndReadBack(5 + extensions, // Number of RTP packets. | |
537 2 + csrcs_count, // Number of RTCP packets. | |
538 3 + csrcs_count, // Number of playout events | |
539 extensions, // Bit vector choosing extensions | |
540 csrcs_count, // Number of contributing sources | |
541 rand()); | |
542 } | |
543 } | |
425 } | 544 } |
426 | 545 |
427 } // namespace webrtc | 546 } // namespace webrtc |
428 | 547 |
429 #endif // ENABLE_RTC_EVENT_LOG | 548 #endif // ENABLE_RTC_EVENT_LOG |
OLD | NEW |