You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.4 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "test/rtp_file_reader.h"
  11. #include <map>
  12. #include <memory>
  13. #include "modules/rtp_rtcp/source/rtp_utility.h"
  14. #include "test/gtest.h"
  15. #include "test/testsupport/file_utils.h"
  16. namespace webrtc {
  17. class TestRtpFileReader : public ::testing::Test {
  18. public:
  19. void Init(const std::string& filename, bool headers_only_file) {
  20. std::string filepath =
  21. test::ResourcePath("video_coding/" + filename, "rtp");
  22. rtp_packet_source_.reset(
  23. test::RtpFileReader::Create(test::RtpFileReader::kRtpDump, filepath));
  24. ASSERT_TRUE(rtp_packet_source_.get() != NULL);
  25. headers_only_file_ = headers_only_file;
  26. }
  27. int CountRtpPackets() {
  28. test::RtpPacket packet;
  29. int c = 0;
  30. while (rtp_packet_source_->NextPacket(&packet)) {
  31. if (headers_only_file_)
  32. EXPECT_LT(packet.length, packet.original_length);
  33. else
  34. EXPECT_EQ(packet.length, packet.original_length);
  35. c++;
  36. }
  37. return c;
  38. }
  39. private:
  40. std::unique_ptr<test::RtpFileReader> rtp_packet_source_;
  41. bool headers_only_file_;
  42. };
  43. TEST_F(TestRtpFileReader, Test60Packets) {
  44. Init("pltype103", false);
  45. EXPECT_EQ(60, CountRtpPackets());
  46. }
  47. TEST_F(TestRtpFileReader, Test60PacketsHeaderOnly) {
  48. Init("pltype103_header_only", true);
  49. EXPECT_EQ(60, CountRtpPackets());
  50. }
  51. typedef std::map<uint32_t, int> PacketsPerSsrc;
  52. class TestPcapFileReader : public ::testing::Test {
  53. public:
  54. void Init(const std::string& filename) {
  55. std::string filepath =
  56. test::ResourcePath("video_coding/" + filename, "pcap");
  57. rtp_packet_source_.reset(
  58. test::RtpFileReader::Create(test::RtpFileReader::kPcap, filepath));
  59. ASSERT_TRUE(rtp_packet_source_.get() != NULL);
  60. }
  61. int CountRtpPackets() {
  62. int c = 0;
  63. test::RtpPacket packet;
  64. while (rtp_packet_source_->NextPacket(&packet)) {
  65. EXPECT_EQ(packet.length, packet.original_length);
  66. c++;
  67. }
  68. return c;
  69. }
  70. PacketsPerSsrc CountRtpPacketsPerSsrc() {
  71. PacketsPerSsrc pps;
  72. test::RtpPacket packet;
  73. while (rtp_packet_source_->NextPacket(&packet)) {
  74. RtpUtility::RtpHeaderParser rtp_header_parser(packet.data, packet.length);
  75. webrtc::RTPHeader header;
  76. if (!rtp_header_parser.RTCP() &&
  77. rtp_header_parser.Parse(&header, nullptr)) {
  78. pps[header.ssrc]++;
  79. }
  80. }
  81. return pps;
  82. }
  83. private:
  84. std::unique_ptr<test::RtpFileReader> rtp_packet_source_;
  85. };
  86. TEST_F(TestPcapFileReader, TestEthernetIIFrame) {
  87. Init("frame-ethernet-ii");
  88. EXPECT_EQ(368, CountRtpPackets());
  89. }
  90. TEST_F(TestPcapFileReader, TestLoopbackFrame) {
  91. Init("frame-loopback");
  92. EXPECT_EQ(491, CountRtpPackets());
  93. }
  94. TEST_F(TestPcapFileReader, TestTwoSsrc) {
  95. Init("ssrcs-2");
  96. PacketsPerSsrc pps = CountRtpPacketsPerSsrc();
  97. EXPECT_EQ(2UL, pps.size());
  98. EXPECT_EQ(370, pps[0x78d48f61]);
  99. EXPECT_EQ(60, pps[0xae94130b]);
  100. }
  101. TEST_F(TestPcapFileReader, TestThreeSsrc) {
  102. Init("ssrcs-3");
  103. PacketsPerSsrc pps = CountRtpPacketsPerSsrc();
  104. EXPECT_EQ(3UL, pps.size());
  105. EXPECT_EQ(162, pps[0x938c5eaa]);
  106. EXPECT_EQ(113, pps[0x59fe6ef0]);
  107. EXPECT_EQ(61, pps[0xed2bd2ac]);
  108. }
  109. } // namespace webrtc