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

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

Issue 1257163003: Changed LogRtpHeader to read the header length from the packet (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Manual control of header extensions in unit test, and minor reviewer comments. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/rtc_event_log.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifdef ENABLE_RTC_EVENT_LOG 11 #ifdef ENABLE_RTC_EVENT_LOG
12 12
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webrtc/base/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
36 // TODO(terelius): Place this definition with other parsing functions? 37 // TODO(terelius): Place this definition with other parsing functions?
37 MediaType GetRuntimeMediaType(rtclog::MediaType media_type) { 38 MediaType GetRuntimeMediaType(rtclog::MediaType media_type) {
hlundin-webrtc 2015/08/13 14:09:52 Collect all the file-scope declarations and functi
terelius 2015/08/14 17:48:26 This will be moved to the RtcEventLogParser class
hlundin-webrtc 2015/08/17 13:47:07 Acknowledged.
38 switch (media_type) { 39 switch (media_type) {
39 case rtclog::MediaType::ANY: 40 case rtclog::MediaType::ANY:
40 return MediaType::ANY; 41 return MediaType::ANY;
41 case rtclog::MediaType::AUDIO: 42 case rtclog::MediaType::AUDIO:
42 return MediaType::AUDIO; 43 return MediaType::AUDIO;
43 case rtclog::MediaType::VIDEO: 44 case rtclog::MediaType::VIDEO:
44 return MediaType::VIDEO; 45 return MediaType::VIDEO;
45 case rtclog::MediaType::DATA: 46 case rtclog::MediaType::DATA:
46 return MediaType::DATA; 47 return MediaType::DATA;
47 } 48 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 EXPECT_EQ(incoming, rtcp_packet.incoming()); 240 EXPECT_EQ(incoming, rtcp_packet.incoming());
240 ASSERT_TRUE(rtcp_packet.has_type()); 241 ASSERT_TRUE(rtcp_packet.has_type());
241 EXPECT_EQ(media_type, GetRuntimeMediaType(rtcp_packet.type())); 242 EXPECT_EQ(media_type, GetRuntimeMediaType(rtcp_packet.type()));
242 ASSERT_TRUE(rtcp_packet.has_packet_data()); 243 ASSERT_TRUE(rtcp_packet.has_packet_data());
243 ASSERT_EQ(total_size, rtcp_packet.packet_data().size()); 244 ASSERT_EQ(total_size, rtcp_packet.packet_data().size());
244 for (size_t i = 0; i < total_size; i++) { 245 for (size_t i = 0; i < total_size; i++) {
245 EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.packet_data()[i])); 246 EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.packet_data()[i]));
246 } 247 }
247 } 248 }
248 249
250 void VerifyPlayoutEvent(const rtclog::Event& event) {
251 ASSERT_TRUE(IsValidBasicEvent(event));
hlundin-webrtc 2015/08/13 14:09:52 If any of the ASSERT_*s trigger, only this subfunc
terelius 2015/08/14 17:48:26 Yes, it is intentional. Even if we fail to read on
hlundin-webrtc 2015/08/17 13:47:07 Acknowledged.
252 ASSERT_EQ(rtclog::Event::DEBUG_EVENT, event.type());
253 const rtclog::DebugEvent& debug_event = event.debug_event();
254 ASSERT_TRUE(debug_event.has_type());
255 EXPECT_EQ(rtclog::DebugEvent::AUDIO_PLAYOUT, debug_event.type());
256 }
257
249 void VerifyLogStartEvent(const rtclog::Event& event) { 258 void VerifyLogStartEvent(const rtclog::Event& event) {
250 ASSERT_TRUE(IsValidBasicEvent(event)); 259 ASSERT_TRUE(IsValidBasicEvent(event));
251 ASSERT_EQ(rtclog::Event::DEBUG_EVENT, event.type()); 260 ASSERT_EQ(rtclog::Event::DEBUG_EVENT, event.type());
252 const rtclog::DebugEvent& debug_event = event.debug_event(); 261 const rtclog::DebugEvent& debug_event = event.debug_event();
253 ASSERT_TRUE(debug_event.has_type()); 262 ASSERT_TRUE(debug_event.has_type());
254 EXPECT_EQ(rtclog::DebugEvent::LOG_START, debug_event.type()); 263 EXPECT_EQ(rtclog::DebugEvent::LOG_START, debug_event.type());
255 } 264 }
256 265
257 void GenerateVideoReceiveConfig(VideoReceiveStream::Config* config) { 266 /*
267 * LSB of extension_bitvector indicates presence of TransmissionTimeOffset,
hlundin-webrtc 2015/08/13 14:09:52 Please, add constant bitmasks representing each bi
terelius 2015/08/14 17:48:27 I changed the approach to avoid repeating almost t
268 * next higher bit indicates AudioLevel, then AbsoluteSendTime, then
269 * VideoRotation and finally TransportSequenceNumber.
270 */
271 size_t GenerateRtpPacket(uint32_t extensions_bitvector,
272 uint32_t csrcs_count,
273 uint8_t* packet,
274 size_t packet_size) {
275 Clock* clock = Clock::GetRealTimeClock();
276
277 RTPSender rtp_sender(0, // int32_t id
278 false, // bool audio
279 clock, // Clock* clock
280 nullptr, // Transport*
281 nullptr, // RtpAudioFeedback*
282 nullptr, // PacedSender*
283 nullptr, // PacketRouter*
284 nullptr, // SendTimeObserver*
285 nullptr, // BitrateStatisticsObserver*
286 nullptr, // FrameCountObserver*
287 nullptr); // SendSideDelayObserver*
288
289 std::vector<uint32_t> csrcs;
290 for (unsigned i = 0; i < csrcs_count; i++) {
291 csrcs.push_back(rand());
292 }
293 rtp_sender.SetCsrcs(csrcs);
294 rtp_sender.SetSSRC(rand());
295 rtp_sender.SetStartTimestamp(rand(), true);
296 rtp_sender.SetSequenceNumber(rand());
297
298 if (extensions_bitvector & 1)
hlundin-webrtc 2015/08/13 14:09:52 Use the bitmasks here as well.
terelius 2015/08/14 17:48:26 Rewritten.
299 rtp_sender.RegisterRtpHeaderExtension(
300 RTPExtensionType::kRtpExtensionTransmissionTimeOffset, 1);
301 if (extensions_bitvector & 2)
302 rtp_sender.RegisterRtpHeaderExtension(
303 RTPExtensionType::kRtpExtensionAudioLevel, 2);
304 if (extensions_bitvector & 4)
305 rtp_sender.RegisterRtpHeaderExtension(
306 RTPExtensionType::kRtpExtensionAbsoluteSendTime, 3);
307 if (extensions_bitvector & 8)
308 rtp_sender.RegisterRtpHeaderExtension(
309 RTPExtensionType::kRtpExtensionVideoRotation, 4);
310 if (extensions_bitvector & 16)
311 rtp_sender.RegisterRtpHeaderExtension(
312 RTPExtensionType::kRtpExtensionTransportSequenceNumber, 5);
313
314 int8_t payload_type = rand() % 128;
315 bool marker_bit = rand() & 0x01;
316 uint32_t capture_timestamp = rand();
317 int64_t capture_time_ms = rand();
318 bool timestamp_provided = rand() & 0x01;
319 bool inc_sequence_number = rand() & 0x01;
320
321 size_t header_size = rtp_sender.BuildRTPheader(
322 packet, payload_type, marker_bit, capture_timestamp, capture_time_ms,
323 timestamp_provided, inc_sequence_number);
324
325 for (size_t i = header_size; i < packet_size; i++) {
326 packet[i] = rand();
327 }
328
329 return header_size;
330 }
331
332 void GenerateRtcpPacket(uint8_t* packet, size_t packet_size) {
333 for (size_t i = 0; i < packet_size; i++) {
334 packet[i] = rand();
335 }
336 }
337
338 void GenerateVideoReceiveConfig(uint32_t extensions_bitvector,
339 VideoReceiveStream::Config* config) {
258 // Create a map from a payload type to an encoder name. 340 // Create a map from a payload type to an encoder name.
259 VideoReceiveStream::Decoder decoder; 341 VideoReceiveStream::Decoder decoder;
260 decoder.payload_type = rand(); 342 decoder.payload_type = rand();
261 decoder.payload_name = (rand() % 2 ? "VP8" : "H264"); 343 decoder.payload_name = (rand() % 2 ? "VP8" : "H264");
262 config->decoders.push_back(decoder); 344 config->decoders.push_back(decoder);
263 // Add SSRCs for the stream. 345 // Add SSRCs for the stream.
264 config->rtp.remote_ssrc = rand(); 346 config->rtp.remote_ssrc = rand();
265 config->rtp.local_ssrc = rand(); 347 config->rtp.local_ssrc = rand();
266 // Add extensions and settings for RTCP. 348 // Add extensions and settings for RTCP.
267 config->rtp.rtcp_mode = rand() % 2 ? newapi::kRtcpCompound 349 config->rtp.rtcp_mode = rand() % 2 ? newapi::kRtcpCompound
268 : newapi::kRtcpReducedSize; 350 : newapi::kRtcpReducedSize;
269 config->rtp.rtcp_xr.receiver_reference_time_report = 351 config->rtp.rtcp_xr.receiver_reference_time_report =
270 static_cast<bool>(rand() % 2); 352 static_cast<bool>(rand() % 2);
271 config->rtp.remb = static_cast<bool>(rand() % 2); 353 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. 354 // 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; 355 VideoReceiveStream::Config::Rtp::Rtx rtx_pair;
274 rtx_pair.ssrc = rand(); 356 rtx_pair.ssrc = rand();
275 rtx_pair.payload_type = rand(); 357 rtx_pair.payload_type = rand();
276 config->rtp.rtx.insert(std::make_pair(rand(), rtx_pair)); 358 config->rtp.rtx.insert(std::make_pair(rand(), rtx_pair));
277 // Add two random header extensions. 359 // Add header extensions.
278 const char* extension_name = rand() % 2 ? RtpExtension::kTOffset 360 const char* extension_name;
279 : RtpExtension::kVideoRotation; 361 if (extensions_bitvector & 1) {
hlundin-webrtc 2015/08/13 14:09:52 ... and here.
terelius 2015/08/14 17:48:26 Rewritten.
280 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); 362 extension_name = RtpExtension::kTOffset;
hlundin-webrtc 2015/08/13 14:09:52 Can't you use RtpExtension::kTOffset directly in t
terelius 2015/08/14 17:48:26 I could, but that would make the lines too long. T
281 extension_name = rand() % 2 ? RtpExtension::kAudioLevel 363 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
282 : RtpExtension::kAbsSendTime; 364 }
283 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); 365 if (extensions_bitvector & 2) {
366 extension_name = RtpExtension::kAudioLevel;
367 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
368 }
369 if (extensions_bitvector & 4) {
370 extension_name = RtpExtension::kAbsSendTime;
371 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
372 }
373 if (extensions_bitvector & 8) {
374 extension_name = RtpExtension::kVideoRotation;
375 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
376 }
377 if (extensions_bitvector & 16) {
378 extension_name = RtpExtension::kTransportSequenceNumber; // TODO
379 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
380 }
284 } 381 }
285 382
286 void GenerateVideoSendConfig(VideoSendStream::Config* config) { 383 void GenerateVideoSendConfig(uint32_t extensions_bitvector,
384 VideoSendStream::Config* config) {
287 // Create a map from a payload type to an encoder name. 385 // Create a map from a payload type to an encoder name.
288 config->encoder_settings.payload_type = rand(); 386 config->encoder_settings.payload_type = rand();
289 config->encoder_settings.payload_name = (rand() % 2 ? "VP8" : "H264"); 387 config->encoder_settings.payload_name = (rand() % 2 ? "VP8" : "H264");
290 // Add SSRCs for the stream. 388 // Add SSRCs for the stream.
291 config->rtp.ssrcs.push_back(rand()); 389 config->rtp.ssrcs.push_back(rand());
292 // Add a map from a payload type to new ssrcs and a new payload type for RTX. 390 // 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()); 391 config->rtp.rtx.ssrcs.push_back(rand());
294 config->rtp.rtx.payload_type = rand(); 392 config->rtp.rtx.payload_type = rand();
295 // Add a CNAME. 393 // Add a CNAME.
296 config->rtp.c_name = "some.user@some.host"; 394 config->rtp.c_name = "some.user@some.host";
297 // Add two random header extensions. 395 // Add header extensions.
298 const char* extension_name = rand() % 2 ? RtpExtension::kTOffset 396 const char* extension_name;
299 : RtpExtension::kVideoRotation; 397 if (extensions_bitvector & 1) {
hlundin-webrtc 2015/08/13 14:09:52 ... and bitmasks here, too.
terelius 2015/08/14 17:48:26 Rewritten.
300 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); 398 extension_name = RtpExtension::kTOffset;
301 extension_name = rand() % 2 ? RtpExtension::kAudioLevel 399 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
302 : RtpExtension::kAbsSendTime; 400 }
303 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); 401 if (extensions_bitvector & 2) {
402 extension_name = RtpExtension::kAudioLevel;
403 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
404 }
405 if (extensions_bitvector & 4) {
406 extension_name = RtpExtension::kAbsSendTime;
407 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
408 }
409 if (extensions_bitvector & 8) {
410 extension_name = RtpExtension::kVideoRotation;
411 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
412 }
413 if (extensions_bitvector & 16) {
414 extension_name = RtpExtension::kTransportSequenceNumber;
415 config->rtp.extensions.push_back(RtpExtension(extension_name, rand()));
416 }
304 } 417 }
305 418
306 // Test for the RtcEventLog class. Dumps some RTP packets to disk, then reads 419 // Test for the RtcEventLog class. Dumps some RTP packets to disk, then reads
307 // them back to see if they match. 420 // them back to see if they match.
308 void LogSessionAndReadBack(size_t rtp_count, unsigned random_seed) { 421 void LogSessionAndReadBack(size_t rtp_count,
309 std::vector<std::vector<uint8_t>> rtp_packets; 422 size_t rtcp_count,
310 std::vector<uint8_t> incoming_rtcp_packet; 423 size_t debug_count,
311 std::vector<uint8_t> outgoing_rtcp_packet; 424 uint32_t extensions_bitvector,
425 uint32_t csrcs_count,
426 unsigned random_seed) {
427 assert(rtcp_count <= rtp_count);
hlundin-webrtc 2015/08/13 14:09:52 Use ASSERT_LE instead, to avoid crashing the entir
terelius 2015/08/14 17:48:26 Done.
428 assert(debug_count <= rtp_count);
429 std::vector<uint8_t*> rtp_packets;
430 std::vector<size_t> rtp_packet_sizes;
431 std::vector<size_t> rtp_header_sizes;
432 std::vector<uint8_t*> rtcp_packets;
433 std::vector<size_t> rtcp_packet_sizes;
312 434
313 VideoReceiveStream::Config receiver_config; 435 VideoReceiveStream::Config receiver_config;
314 VideoSendStream::Config sender_config; 436 VideoSendStream::Config sender_config;
315 437
316 srand(random_seed); 438 srand(random_seed);
317 439
318 // Create rtp_count RTP packets containing random data. 440 // 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++) { 441 for (size_t i = 0; i < rtp_count; i++) {
321 size_t packet_size = 1000 + rand() % 30; 442 size_t packet_size = 1000 + rand() % 30;
322 rtp_packets.push_back(std::vector<uint8_t>()); 443 rtp_packet_sizes.push_back(packet_size);
323 rtp_packets[i].reserve(packet_size); 444 rtp_packets.push_back(new uint8_t[packet_size]);
324 for (size_t j = 0; j < packet_size; j++) { 445 size_t header_size = GenerateRtpPacket(extensions_bitvector, csrcs_count,
325 rtp_packets[i].push_back(rand()); 446 rtp_packets[i], packet_size);
326 } 447 rtp_header_sizes.push_back(header_size);
327 } 448 }
328 // Create two RTCP packets containing random data. 449 // Create rtcp_count RTCP packets containing random data.
329 size_t packet_size = 1000 + rand() % 30; 450 for (size_t i = 0; i < rtcp_count; i++) {
330 outgoing_rtcp_packet.reserve(packet_size); 451 size_t packet_size = 1000 + rand() % 30;
331 for (size_t j = 0; j < packet_size; j++) { 452 rtcp_packet_sizes.push_back(packet_size);
332 outgoing_rtcp_packet.push_back(rand()); 453 rtcp_packets.push_back(new uint8_t[packet_size]);
333 } 454 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 } 455 }
339 // Create configurations for the video streams. 456 // Create configurations for the video streams.
340 GenerateVideoReceiveConfig(&receiver_config); 457 GenerateVideoReceiveConfig(extensions_bitvector, &receiver_config);
341 GenerateVideoSendConfig(&sender_config); 458 GenerateVideoSendConfig(extensions_bitvector, &sender_config);
459 const int config_count = 2;
342 460
343 // Find the name of the current test, in order to use it as a temporary 461 // Find the name of the current test, in order to use it as a temporary
344 // filename. 462 // filename.
345 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); 463 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
346 const std::string temp_filename = 464 const std::string temp_filename =
347 test::OutputPath() + test_info->test_case_name() + test_info->name(); 465 test::OutputPath() + test_info->test_case_name() + test_info->name();
348 466
349 // When log_dumper goes out of scope, it causes the log file to be flushed 467 // When log_dumper goes out of scope, it causes the log file to be flushed
350 // to disk. 468 // to disk.
351 { 469 {
352 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); 470 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create());
353 log_dumper->LogVideoReceiveStreamConfig(receiver_config); 471 log_dumper->LogVideoReceiveStreamConfig(receiver_config);
354 log_dumper->LogVideoSendStreamConfig(sender_config); 472 log_dumper->LogVideoSendStreamConfig(sender_config);
355 size_t i = 0; 473 size_t rtcp_index = 1, debug_index = 1;
356 for (; i < rtp_count / 2; i++) { 474 for (size_t i = 1; i <= rtp_count; i++) {
357 log_dumper->LogRtpHeader( 475 log_dumper->LogRtpHeader(
358 (i % 2 == 0), // Every second packet is incoming. 476 (i % 2 == 0), // Every second packet is incoming.
359 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, 477 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO,
360 rtp_packets[i].data(), rtp_header_size, rtp_packets[i].size()); 478 rtp_packets[i - 1], rtp_packet_sizes[i - 1]);
479 if (i * rtcp_count >= rtcp_index * rtp_count) {
480 log_dumper->LogRtcpPacket(
481 rtcp_index % 2 == 0, // Even packets incoming
482 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO,
483 rtcp_packets[rtcp_index - 1], rtcp_packet_sizes[rtcp_index - 1]);
484 rtcp_index++;
485 }
486 if (i * debug_count >= debug_index * rtp_count) {
487 log_dumper->LogDebugEvent(RtcEventLog::DebugEvent::kAudioPlayout);
488 debug_index++;
489 }
490 if (i == rtp_count / 2) {
491 log_dumper->StartLogging(temp_filename, 10000000);
492 }
361 } 493 }
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 } 494 }
376 495
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. 496 // Read the generated file from disk.
383 rtclog::EventStream parsed_stream; 497 rtclog::EventStream parsed_stream;
384 498
385 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); 499 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream));
386 500
387 // Verify the result. 501 // Verify the result.
502 const int event_count =
503 config_count + debug_count + rtcp_count + rtp_count + 1;
388 EXPECT_EQ(event_count, parsed_stream.stream_size()); 504 EXPECT_EQ(event_count, parsed_stream.stream_size());
389 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); 505 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config);
390 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); 506 VerifySendStreamConfig(parsed_stream.stream(1), sender_config);
391 size_t i = 0; 507 size_t event_index = config_count, rtcp_index = 1, debug_index = 1;
392 for (; i < rtp_count / 2; i++) { 508 for (size_t i = 1; i <= rtp_count; i++) {
393 VerifyRtpEvent(parsed_stream.stream(config_count + i), 509 VerifyRtpEvent(parsed_stream.stream(event_index),
394 (i % 2 == 0), // Every second packet is incoming. 510 (i % 2 == 0), // Every second packet is incoming.
395 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, 511 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO,
396 rtp_packets[i].data(), rtp_header_size, 512 rtp_packets[i - 1], rtp_header_sizes[i - 1],
397 rtp_packets[i].size()); 513 rtp_packet_sizes[i - 1]);
514 event_index++;
515 if (i * rtcp_count >= rtcp_index * rtp_count) {
516 VerifyRtcpEvent(parsed_stream.stream(event_index),
517 rtcp_index % 2 == 0, // Every second packet is incoming.
518 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO,
519 rtcp_packets[rtcp_index - 1],
520 rtcp_packet_sizes[rtcp_index - 1]);
521 event_index++;
522 rtcp_index++;
523 }
524 if (i * debug_count >= debug_index * rtp_count) {
525 VerifyPlayoutEvent(parsed_stream.stream(event_index));
526 event_index++;
527 debug_index++;
528 }
529 if (i == rtp_count / 2) {
530 VerifyLogStartEvent(parsed_stream.stream(event_index));
531 event_index++;
532 }
398 } 533 }
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 534
417 // Clean up temporary file - can be pretty slow. 535 // Clean up temporary file - can be pretty slow.
418 remove(temp_filename.c_str()); 536 remove(temp_filename.c_str());
537
538 // Free memory
539 for (auto packet : rtp_packets) {
540 delete[] packet;
541 }
542 for (auto packet : rtcp_packets) {
543 delete[] packet;
544 }
419 } 545 }
420 546
421 TEST(RtcEventLogTest, LogSessionAndReadBack) { 547 TEST(RtcEventLogTest, LogSessionAndReadBack) {
422 LogSessionAndReadBack(5, 321); 548 LogSessionAndReadBack(5, 2, 0, 0, 0, 321);
hlundin-webrtc 2015/08/13 14:09:52 Use the bitmask constants here too.
terelius 2015/08/14 17:48:26 This is the one place where named bitmasks might b
hlundin-webrtc 2015/08/17 13:47:07 I suggest you introduce an array of bitmasks, the
terelius 2015/08/18 08:20:51 That would not simplify the code here. The issue i
423 LogSessionAndReadBack(8, 3141592653u); 549 LogSessionAndReadBack(8, 2, 0, 4 + 16, 0, 3141592653u);
424 LogSessionAndReadBack(9, 2718281828u); 550 LogSessionAndReadBack(9, 2, 3, 1 + 2 + 4 + 8 + 16, 2, 2718281828u);
551
552 for (unsigned extensions = 0; extensions < 32; extensions++) {
hlundin-webrtc 2015/08/13 14:09:52 size_t, since extensions is used as input argument
terelius 2015/08/14 17:48:26 Sorry, I don't understand. Can you elaborate?
hlundin-webrtc 2015/08/17 13:47:07 I was nagging about you using unsigned as the type
terelius 2015/08/18 08:20:51 Oh, so you meant unsigned vs uint32_t. I got confu
553 for (unsigned csrcs_count = 0; csrcs_count < 3; csrcs_count++) {
hlundin-webrtc 2015/08/13 14:09:52 size_t
terelius 2015/08/14 17:48:27 I don't understand. Can you elaborate?
hlundin-webrtc 2015/08/17 13:47:07 Same as above.
terelius 2015/08/18 08:20:51 Same as above.
554 LogSessionAndReadBack(5 + extensions, // Number of RTP packets.
555 2 + csrcs_count, // Number of RTCP packets.
556 3 + csrcs_count, // Number of playout events
557 extensions, // Bit vector choosing extensions
558 csrcs_count, // Number of contributing sources
559 rand());
560 }
561 }
425 } 562 }
426 563
427 } // namespace webrtc 564 } // namespace webrtc
428 565
429 #endif // ENABLE_RTC_EVENT_LOG 566 #endif // ENABLE_RTC_EVENT_LOG
OLDNEW
« no previous file with comments | « webrtc/video/rtc_event_log.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698