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> |
| 12 | |
| 13 | #include "testing/gtest/include/gtest/gtest.h" |
| 14 | #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 15 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame^] | 16 | #include "webrtc/test/rtp_file_reader.h" |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 17 | #include "webrtc/test/testsupport/fileutils.h" |
| 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: |
| 23 | void Init(const std::string& filename) { |
| 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); |
| 29 | } |
| 30 | |
| 31 | int CountRtpPackets() { |
| 32 | test::RtpFileReader::Packet packet; |
| 33 | int c = 0; |
| 34 | while (rtp_packet_source_->NextPacket(&packet)) |
| 35 | c++; |
| 36 | return c; |
| 37 | } |
| 38 | |
| 39 | private: |
| 40 | scoped_ptr<test::RtpFileReader> rtp_packet_source_; |
| 41 | }; |
| 42 | |
| 43 | TEST_F(TestRtpFileReader, Test60Packets) { |
| 44 | Init("pltype103"); |
| 45 | EXPECT_EQ(60, CountRtpPackets()); |
| 46 | } |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 47 | |
| 48 | typedef std::map<uint32_t, int> PacketsPerSsrc; |
| 49 | |
| 50 | class TestPcapFileReader : public ::testing::Test { |
| 51 | public: |
| 52 | void Init(const std::string& filename) { |
| 53 | std::string filepath = |
| 54 | test::ResourcePath("video_coding/" + filename, "pcap"); |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame^] | 55 | rtp_packet_source_.reset( |
| 56 | test::RtpFileReader::Create(test::RtpFileReader::kPcap, filepath)); |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 57 | ASSERT_TRUE(rtp_packet_source_.get() != NULL); |
| 58 | } |
| 59 | |
| 60 | int CountRtpPackets() { |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 61 | int c = 0; |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame^] | 62 | test::RtpFileReader::Packet packet; |
| 63 | while (rtp_packet_source_->NextPacket(&packet)) |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 64 | c++; |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 65 | return c; |
| 66 | } |
| 67 | |
| 68 | PacketsPerSsrc CountRtpPacketsPerSsrc() { |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 69 | PacketsPerSsrc pps; |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame^] | 70 | test::RtpFileReader::Packet packet; |
| 71 | while (rtp_packet_source_->NextPacket(&packet)) { |
| 72 | RtpUtility::RtpHeaderParser rtp_header_parser(packet.data, packet.length); |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 73 | webrtc::RTPHeader header; |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 74 | if (!rtp_header_parser.RTCP() && rtp_header_parser.Parse(header, NULL)) { |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 75 | pps[header.ssrc]++; |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | return pps; |
| 79 | } |
| 80 | |
| 81 | private: |
pbos@webrtc.org | 4b5625e | 2014-08-06 16:26:56 +0000 | [diff] [blame^] | 82 | scoped_ptr<test::RtpFileReader> rtp_packet_source_; |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | TEST_F(TestPcapFileReader, TestEthernetIIFrame) { |
| 86 | Init("frame-ethernet-ii"); |
| 87 | EXPECT_EQ(368, CountRtpPackets()); |
| 88 | } |
| 89 | |
| 90 | TEST_F(TestPcapFileReader, TestLoopbackFrame) { |
| 91 | Init("frame-loopback"); |
| 92 | EXPECT_EQ(491, CountRtpPackets()); |
| 93 | } |
| 94 | |
| 95 | TEST_F(TestPcapFileReader, TestTwoSsrc) { |
| 96 | Init("ssrcs-2"); |
| 97 | PacketsPerSsrc pps = CountRtpPacketsPerSsrc(); |
| 98 | EXPECT_EQ(2UL, pps.size()); |
| 99 | EXPECT_EQ(370, pps[0x78d48f61]); |
| 100 | EXPECT_EQ(60, pps[0xae94130b]); |
| 101 | } |
| 102 | |
| 103 | TEST_F(TestPcapFileReader, TestThreeSsrc) { |
| 104 | Init("ssrcs-3"); |
| 105 | PacketsPerSsrc pps = CountRtpPacketsPerSsrc(); |
| 106 | EXPECT_EQ(3UL, pps.size()); |
| 107 | EXPECT_EQ(162, pps[0x938c5eaa]); |
| 108 | EXPECT_EQ(113, pps[0x59fe6ef0]); |
| 109 | EXPECT_EQ(61, pps[0xed2bd2ac]); |
| 110 | } |
solenberg@webrtc.org | 56b5f77 | 2013-04-16 10:31:56 +0000 | [diff] [blame] | 111 | } // namespace webrtc |