solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 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 | |
| 11 | #include <map> |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 12 | #include <memory> |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "modules/rtp_rtcp/source/rtp_utility.h" |
| 15 | #include "test/gtest.h" |
| 16 | #include "test/rtp_file_reader.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 17 | #include "test/testsupport/file_utils.h" |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 20 | |
| 21 | class TestRtpFileReader : public ::testing::Test { |
| 22 | public: |
henrik.lundin@webrtc.org | 38c121c | 2014-09-30 11:08:44 +0000 | [diff] [blame] | 23 | void Init(const std::string& filename, bool headers_only_file) { |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 24 | std::string filepath = |
| 25 | test::ResourcePath("video_coding/" + filename, "rtp"); |
| 26 | rtp_packet_source_.reset( |
| 27 | test::RtpFileReader::Create(test::RtpFileReader::kRtpDump, filepath)); |
| 28 | ASSERT_TRUE(rtp_packet_source_.get() != NULL); |
henrik.lundin@webrtc.org | 38c121c | 2014-09-30 11:08:44 +0000 | [diff] [blame] | 29 | headers_only_file_ = headers_only_file; |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | int CountRtpPackets() { |
henrik.lundin@webrtc.org | 91d928e | 2014-11-26 15:50:30 +0000 | [diff] [blame] | 33 | test::RtpPacket packet; |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 34 | int c = 0; |
henrik.lundin@webrtc.org | 38c121c | 2014-09-30 11:08:44 +0000 | [diff] [blame] | 35 | while (rtp_packet_source_->NextPacket(&packet)) { |
| 36 | if (headers_only_file_) |
| 37 | EXPECT_LT(packet.length, packet.original_length); |
| 38 | else |
| 39 | EXPECT_EQ(packet.length, packet.original_length); |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 40 | c++; |
henrik.lundin@webrtc.org | 38c121c | 2014-09-30 11:08:44 +0000 | [diff] [blame] | 41 | } |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 42 | return c; |
| 43 | } |
| 44 | |
| 45 | private: |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 46 | std::unique_ptr<test::RtpFileReader> rtp_packet_source_; |
henrik.lundin@webrtc.org | 38c121c | 2014-09-30 11:08:44 +0000 | [diff] [blame] | 47 | bool headers_only_file_; |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | TEST_F(TestRtpFileReader, Test60Packets) { |
henrik.lundin@webrtc.org | 38c121c | 2014-09-30 11:08:44 +0000 | [diff] [blame] | 51 | Init("pltype103", false); |
| 52 | EXPECT_EQ(60, CountRtpPackets()); |
| 53 | } |
| 54 | |
| 55 | TEST_F(TestRtpFileReader, Test60PacketsHeaderOnly) { |
| 56 | Init("pltype103_header_only", true); |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 57 | EXPECT_EQ(60, CountRtpPackets()); |
| 58 | } |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 59 | |
| 60 | typedef std::map<uint32_t, int> PacketsPerSsrc; |
| 61 | |
| 62 | class TestPcapFileReader : public ::testing::Test { |
| 63 | public: |
| 64 | void Init(const std::string& filename) { |
| 65 | std::string filepath = |
| 66 | test::ResourcePath("video_coding/" + filename, "pcap"); |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 67 | rtp_packet_source_.reset( |
| 68 | test::RtpFileReader::Create(test::RtpFileReader::kPcap, filepath)); |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 69 | ASSERT_TRUE(rtp_packet_source_.get() != NULL); |
| 70 | } |
| 71 | |
| 72 | int CountRtpPackets() { |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 73 | int c = 0; |
henrik.lundin@webrtc.org | 91d928e | 2014-11-26 15:50:30 +0000 | [diff] [blame] | 74 | test::RtpPacket packet; |
henrik.lundin@webrtc.org | 38c121c | 2014-09-30 11:08:44 +0000 | [diff] [blame] | 75 | while (rtp_packet_source_->NextPacket(&packet)) { |
| 76 | EXPECT_EQ(packet.length, packet.original_length); |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 77 | c++; |
henrik.lundin@webrtc.org | 38c121c | 2014-09-30 11:08:44 +0000 | [diff] [blame] | 78 | } |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 79 | return c; |
| 80 | } |
| 81 | |
| 82 | PacketsPerSsrc CountRtpPacketsPerSsrc() { |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 83 | PacketsPerSsrc pps; |
henrik.lundin@webrtc.org | 91d928e | 2014-11-26 15:50:30 +0000 | [diff] [blame] | 84 | test::RtpPacket packet; |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame] | 85 | while (rtp_packet_source_->NextPacket(&packet)) { |
| 86 | RtpUtility::RtpHeaderParser rtp_header_parser(packet.data, packet.length); |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 87 | webrtc::RTPHeader header; |
danilchap | f6975f4 | 2015-12-28 10:18:46 -0800 | [diff] [blame] | 88 | if (!rtp_header_parser.RTCP() && |
| 89 | rtp_header_parser.Parse(&header, nullptr)) { |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 90 | pps[header.ssrc]++; |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | return pps; |
| 94 | } |
| 95 | |
| 96 | private: |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 97 | std::unique_ptr<test::RtpFileReader> rtp_packet_source_; |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | TEST_F(TestPcapFileReader, TestEthernetIIFrame) { |
| 101 | Init("frame-ethernet-ii"); |
| 102 | EXPECT_EQ(368, CountRtpPackets()); |
| 103 | } |
| 104 | |
| 105 | TEST_F(TestPcapFileReader, TestLoopbackFrame) { |
| 106 | Init("frame-loopback"); |
| 107 | EXPECT_EQ(491, CountRtpPackets()); |
| 108 | } |
| 109 | |
| 110 | TEST_F(TestPcapFileReader, TestTwoSsrc) { |
| 111 | Init("ssrcs-2"); |
| 112 | PacketsPerSsrc pps = CountRtpPacketsPerSsrc(); |
| 113 | EXPECT_EQ(2UL, pps.size()); |
| 114 | EXPECT_EQ(370, pps[0x78d48f61]); |
| 115 | EXPECT_EQ(60, pps[0xae94130b]); |
| 116 | } |
| 117 | |
| 118 | TEST_F(TestPcapFileReader, TestThreeSsrc) { |
| 119 | Init("ssrcs-3"); |
| 120 | PacketsPerSsrc pps = CountRtpPacketsPerSsrc(); |
| 121 | EXPECT_EQ(3UL, pps.size()); |
| 122 | EXPECT_EQ(162, pps[0x938c5eaa]); |
| 123 | EXPECT_EQ(113, pps[0x59fe6ef0]); |
| 124 | EXPECT_EQ(61, pps[0xed2bd2ac]); |
| 125 | } |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 126 | } // namespace webrtc |