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 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 } | 248 } |
248 | 249 |
249 void VerifyLogStartEvent(const rtclog::Event& event) { | 250 void VerifyLogStartEvent(const rtclog::Event& event) { |
250 ASSERT_TRUE(IsValidBasicEvent(event)); | 251 ASSERT_TRUE(IsValidBasicEvent(event)); |
251 ASSERT_EQ(rtclog::Event::DEBUG_EVENT, event.type()); | 252 ASSERT_EQ(rtclog::Event::DEBUG_EVENT, event.type()); |
252 const rtclog::DebugEvent& debug_event = event.debug_event(); | 253 const rtclog::DebugEvent& debug_event = event.debug_event(); |
253 ASSERT_TRUE(debug_event.has_type()); | 254 ASSERT_TRUE(debug_event.has_type()); |
254 EXPECT_EQ(rtclog::DebugEvent::LOG_START, debug_event.type()); | 255 EXPECT_EQ(rtclog::DebugEvent::LOG_START, debug_event.type()); |
255 } | 256 } |
256 | 257 |
258 size_t GenerateRtpPacket(uint8_t* packet, size_t packet_size) { | |
259 Clock* clock = Clock::GetRealTimeClock(); | |
260 | |
261 RTPSender rtp_sender(rand(), // int32_t id | |
hlundin-webrtc
2015/08/04 09:43:50
Use 0 as id instead. This test is not for testing
terelius
2015/08/12 13:12:40
Done.
| |
262 false, // bool audio | |
263 clock, // Clock* clock | |
264 nullptr, // Transport* | |
265 nullptr, // RtpAudioFeedback* | |
266 nullptr, // PacedSender* | |
267 nullptr, // BitrateStatisticsObserver* | |
268 nullptr, // FrameCountObserver* | |
269 nullptr); // SendSideDelayObserver* | |
270 | |
271 std::vector<uint32_t> csrcs; | |
272 csrcs.push_back(rand()); | |
273 rtp_sender.SetCsrcs(csrcs); | |
274 rtp_sender.SetSSRC(rand()); | |
275 rtp_sender.SetStartTimestamp(rand(), true); | |
276 rtp_sender.SetSequenceNumber(rand()); | |
277 | |
278 RTPExtensionType extension_types[] = { | |
279 RTPExtensionType::kRtpExtensionTransmissionTimeOffset, | |
280 RTPExtensionType::kRtpExtensionAudioLevel, | |
281 RTPExtensionType::kRtpExtensionAbsoluteSendTime, | |
282 RTPExtensionType::kRtpExtensionVideoRotation, | |
283 RTPExtensionType::kRtpExtensionTransportSequenceNumber, | |
284 }; | |
285 for (int i=0; i<5; i++) { | |
286 if (rand()%2) { | |
hlundin-webrtc
2015/08/04 09:43:50
I don't like this randomized test configuration. C
terelius
2015/08/12 13:12:40
I've rewritten to the tests to allow manual contro
| |
287 rtp_sender.RegisterRtpHeaderExtension(extension_types[i], i+2); | |
288 } | |
289 } | |
290 | |
291 int8_t payload_type = rand()%128; | |
292 bool marker_bit = rand()&0x01; | |
293 uint32_t capture_timestamp = rand(); | |
294 int64_t capture_time_ms = rand(); | |
295 bool timestamp_provided = rand()&0x01; | |
296 bool inc_sequence_number = rand()&0x01; | |
297 | |
298 size_t header_size = rtp_sender.BuildRTPheader(packet, | |
299 payload_type, | |
300 marker_bit, | |
301 capture_timestamp, | |
302 capture_time_ms, | |
303 timestamp_provided, | |
304 inc_sequence_number); | |
305 | |
306 for (size_t i = header_size; i < packet_size; i++) { | |
307 packet[i] = rand(); | |
308 } | |
309 | |
310 return header_size; | |
311 } | |
312 | |
257 void GenerateVideoReceiveConfig(VideoReceiveStream::Config* config) { | 313 void GenerateVideoReceiveConfig(VideoReceiveStream::Config* config) { |
258 // Create a map from a payload type to an encoder name. | 314 // Create a map from a payload type to an encoder name. |
259 VideoReceiveStream::Decoder decoder; | 315 VideoReceiveStream::Decoder decoder; |
260 decoder.payload_type = rand(); | 316 decoder.payload_type = rand(); |
261 decoder.payload_name = (rand() % 2 ? "VP8" : "H264"); | 317 decoder.payload_name = (rand() % 2 ? "VP8" : "H264"); |
262 config->decoders.push_back(decoder); | 318 config->decoders.push_back(decoder); |
263 // Add SSRCs for the stream. | 319 // Add SSRCs for the stream. |
264 config->rtp.remote_ssrc = rand(); | 320 config->rtp.remote_ssrc = rand(); |
265 config->rtp.local_ssrc = rand(); | 321 config->rtp.local_ssrc = rand(); |
266 // Add extensions and settings for RTCP. | 322 // Add extensions and settings for RTCP. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 : RtpExtension::kVideoRotation; | 355 : RtpExtension::kVideoRotation; |
300 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); | 356 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); |
301 extension_name = rand() % 2 ? RtpExtension::kAudioLevel | 357 extension_name = rand() % 2 ? RtpExtension::kAudioLevel |
302 : RtpExtension::kAbsSendTime; | 358 : RtpExtension::kAbsSendTime; |
303 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); | 359 config->rtp.extensions.push_back(RtpExtension(extension_name, rand())); |
304 } | 360 } |
305 | 361 |
306 // Test for the RtcEventLog class. Dumps some RTP packets to disk, then reads | 362 // Test for the RtcEventLog class. Dumps some RTP packets to disk, then reads |
307 // them back to see if they match. | 363 // them back to see if they match. |
308 void LogSessionAndReadBack(size_t rtp_count, unsigned random_seed) { | 364 void LogSessionAndReadBack(size_t rtp_count, unsigned random_seed) { |
309 std::vector<std::vector<uint8_t>> rtp_packets; | 365 std::vector<uint8_t*> rtp_packets; |
366 std::vector<size_t> rtp_packet_sizes; | |
367 std::vector<size_t> rtp_header_sizes; | |
ivoc
2015/08/06 12:29:44
I don't see the advantage of this collection of da
terelius
2015/08/12 13:12:40
I agree that memory leaks is a concern, but all ot
ivoc
2015/08/14 11:21:53
I think in your example the vector code could look
terelius
2015/08/14 18:17:45
Some functions like BuildRTPHeader writes some byt
hlundin-webrtc
2015/08/17 13:47:07
My random thoughts:
1. Consider using rtc::Buffer
kwiberg-webrtc
2015/08/17 18:41:57
+1
| |
310 std::vector<uint8_t> incoming_rtcp_packet; | 368 std::vector<uint8_t> incoming_rtcp_packet; |
311 std::vector<uint8_t> outgoing_rtcp_packet; | 369 std::vector<uint8_t> outgoing_rtcp_packet; |
312 | 370 |
313 VideoReceiveStream::Config receiver_config; | 371 VideoReceiveStream::Config receiver_config; |
314 VideoSendStream::Config sender_config; | 372 VideoSendStream::Config sender_config; |
315 | 373 |
316 srand(random_seed); | 374 srand(random_seed); |
317 | 375 |
318 // Create rtp_count RTP packets containing random data. | 376 // 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++) { | 377 for (size_t i = 0; i < rtp_count; i++) { |
321 size_t packet_size = 1000 + rand() % 30; | 378 size_t packet_size = 1000 + rand() % 30; |
322 rtp_packets.push_back(std::vector<uint8_t>()); | 379 rtp_packet_sizes.push_back(packet_size); |
323 rtp_packets[i].reserve(packet_size); | 380 rtp_packets.push_back(new uint8_t[packet_size]); |
324 for (size_t j = 0; j < packet_size; j++) { | 381 size_t header_size = GenerateRtpPacket(rtp_packets[i], packet_size); |
325 rtp_packets[i].push_back(rand()); | 382 rtp_header_sizes.push_back(header_size); |
326 } | |
327 } | 383 } |
328 // Create two RTCP packets containing random data. | 384 // Create two RTCP packets containing random data. |
329 size_t packet_size = 1000 + rand() % 30; | 385 size_t packet_size = 1000 + rand() % 30; |
330 outgoing_rtcp_packet.reserve(packet_size); | 386 outgoing_rtcp_packet.reserve(packet_size); |
331 for (size_t j = 0; j < packet_size; j++) { | 387 for (size_t j = 0; j < packet_size; j++) { |
332 outgoing_rtcp_packet.push_back(rand()); | 388 outgoing_rtcp_packet.push_back(rand()); |
333 } | 389 } |
334 packet_size = 1000 + rand() % 30; | 390 packet_size = 1000 + rand() % 30; |
335 incoming_rtcp_packet.reserve(packet_size); | 391 incoming_rtcp_packet.reserve(packet_size); |
336 for (size_t j = 0; j < packet_size; j++) { | 392 for (size_t j = 0; j < packet_size; j++) { |
(...skipping 13 matching lines...) Expand all Loading... | |
350 // to disk. | 406 // to disk. |
351 { | 407 { |
352 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); | 408 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); |
353 log_dumper->LogVideoReceiveStreamConfig(receiver_config); | 409 log_dumper->LogVideoReceiveStreamConfig(receiver_config); |
354 log_dumper->LogVideoSendStreamConfig(sender_config); | 410 log_dumper->LogVideoSendStreamConfig(sender_config); |
355 size_t i = 0; | 411 size_t i = 0; |
356 for (; i < rtp_count / 2; i++) { | 412 for (; i < rtp_count / 2; i++) { |
357 log_dumper->LogRtpHeader( | 413 log_dumper->LogRtpHeader( |
358 (i % 2 == 0), // Every second packet is incoming. | 414 (i % 2 == 0), // Every second packet is incoming. |
359 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 415 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
360 rtp_packets[i].data(), rtp_header_size, rtp_packets[i].size()); | 416 rtp_packets[i], rtp_packet_sizes[i]); |
361 } | 417 } |
362 log_dumper->LogRtcpPacket(false, MediaType::AUDIO, | 418 log_dumper->LogRtcpPacket(false, MediaType::AUDIO, |
363 outgoing_rtcp_packet.data(), | 419 outgoing_rtcp_packet.data(), |
364 outgoing_rtcp_packet.size()); | 420 outgoing_rtcp_packet.size()); |
365 log_dumper->StartLogging(temp_filename, 10000000); | 421 log_dumper->StartLogging(temp_filename, 10000000); |
366 for (; i < rtp_count; i++) { | 422 for (; i < rtp_count; i++) { |
367 log_dumper->LogRtpHeader( | 423 log_dumper->LogRtpHeader( |
368 (i % 2 == 0), // Every second packet is incoming, | 424 (i % 2 == 0), // Every second packet is incoming, |
369 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 425 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
370 rtp_packets[i].data(), rtp_header_size, rtp_packets[i].size()); | 426 rtp_packets[i], rtp_packet_sizes[i]); |
371 } | 427 } |
372 log_dumper->LogRtcpPacket(true, MediaType::VIDEO, | 428 log_dumper->LogRtcpPacket(true, MediaType::VIDEO, |
373 incoming_rtcp_packet.data(), | 429 incoming_rtcp_packet.data(), |
374 incoming_rtcp_packet.size()); | 430 incoming_rtcp_packet.size()); |
375 } | 431 } |
376 | 432 |
377 const int config_count = 2; | 433 const int config_count = 2; |
378 const int rtcp_count = 2; | 434 const int rtcp_count = 2; |
379 const int debug_count = 1; // Only LogStart event, | 435 const int debug_count = 1; // Only LogStart event, |
380 const int event_count = config_count + debug_count + rtcp_count + rtp_count; | 436 const int event_count = config_count + debug_count + rtcp_count + rtp_count; |
381 | 437 |
382 // Read the generated file from disk. | 438 // Read the generated file from disk. |
383 rtclog::EventStream parsed_stream; | 439 rtclog::EventStream parsed_stream; |
384 | 440 |
385 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | 441 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); |
386 | 442 |
387 // Verify the result. | 443 // Verify the result. |
388 EXPECT_EQ(event_count, parsed_stream.stream_size()); | 444 EXPECT_EQ(event_count, parsed_stream.stream_size()); |
389 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); | 445 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); |
390 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); | 446 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); |
391 size_t i = 0; | 447 size_t i = 0; |
392 for (; i < rtp_count / 2; i++) { | 448 for (; i < rtp_count / 2; i++) { |
393 VerifyRtpEvent(parsed_stream.stream(config_count + i), | 449 VerifyRtpEvent(parsed_stream.stream(config_count + i), |
394 (i % 2 == 0), // Every second packet is incoming. | 450 (i % 2 == 0), // Every second packet is incoming. |
395 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 451 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
396 rtp_packets[i].data(), rtp_header_size, | 452 rtp_packets[i], rtp_header_sizes[i], rtp_packet_sizes[i]); |
397 rtp_packets[i].size()); | |
398 } | 453 } |
399 VerifyRtcpEvent(parsed_stream.stream(config_count + rtp_count / 2), | 454 VerifyRtcpEvent(parsed_stream.stream(config_count + rtp_count / 2), |
400 false, // Outgoing RTCP packet. | 455 false, // Outgoing RTCP packet. |
401 MediaType::AUDIO, outgoing_rtcp_packet.data(), | 456 MediaType::AUDIO, outgoing_rtcp_packet.data(), |
402 outgoing_rtcp_packet.size()); | 457 outgoing_rtcp_packet.size()); |
403 | 458 |
404 VerifyLogStartEvent(parsed_stream.stream(1 + config_count + rtp_count / 2)); | 459 VerifyLogStartEvent(parsed_stream.stream(1 + config_count + rtp_count / 2)); |
405 for (; i < rtp_count; i++) { | 460 for (; i < rtp_count; i++) { |
406 VerifyRtpEvent(parsed_stream.stream(2 + config_count + i), | 461 VerifyRtpEvent(parsed_stream.stream(2 + config_count + i), |
407 (i % 2 == 0), // Every second packet is incoming. | 462 (i % 2 == 0), // Every second packet is incoming. |
408 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 463 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
409 rtp_packets[i].data(), rtp_header_size, | 464 rtp_packets[i], rtp_header_sizes[i], rtp_packet_sizes[i]); |
410 rtp_packets[i].size()); | |
411 } | 465 } |
412 VerifyRtcpEvent(parsed_stream.stream(2 + config_count + rtp_count), | 466 VerifyRtcpEvent(parsed_stream.stream(2 + config_count + rtp_count), |
413 true, // Incoming RTCP packet. | 467 true, // Incoming RTCP packet. |
414 MediaType::VIDEO, incoming_rtcp_packet.data(), | 468 MediaType::VIDEO, incoming_rtcp_packet.data(), |
415 incoming_rtcp_packet.size()); | 469 incoming_rtcp_packet.size()); |
416 | 470 |
417 // Clean up temporary file - can be pretty slow. | 471 // Clean up temporary file - can be pretty slow. |
418 remove(temp_filename.c_str()); | 472 remove(temp_filename.c_str()); |
473 | |
474 // Free memory | |
475 for (size_t i = 0; i < rtp_count; i++) { | |
hlundin-webrtc
2015/08/04 09:43:50
for (auto packet : rtp_packets) {
delete[] packe
terelius
2015/08/12 13:12:40
Done.
| |
476 delete[] rtp_packets[i]; | |
477 } | |
419 } | 478 } |
420 | 479 |
421 TEST(RtcEventLogTest, LogSessionAndReadBack) { | 480 TEST(RtcEventLogTest, LogSessionAndReadBack) { |
422 LogSessionAndReadBack(5, 321); | 481 LogSessionAndReadBack(5, 321); |
423 LogSessionAndReadBack(8, 3141592653u); | 482 LogSessionAndReadBack(8, 3141592653u); |
424 LogSessionAndReadBack(9, 2718281828u); | 483 LogSessionAndReadBack(9, 2718281828u); |
425 } | 484 } |
426 | 485 |
427 } // namespace webrtc | 486 } // namespace webrtc |
428 | 487 |
429 #endif // ENABLE_RTC_EVENT_LOG | 488 #endif // ENABLE_RTC_EVENT_LOG |
OLD | NEW |