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