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