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 "test/rtp_file_reader.h"
12
13 #include <map>
14 #include <memory>
15
16 #include "modules/rtp_rtcp/source/rtp_utility.h"
17 #include "test/gtest.h"
18 #include "test/testsupport/file_utils.h"
19
20 namespace webrtc {
21
22 class TestRtpFileReader : public ::testing::Test {
23 public:
Init(const std::string & filename,bool headers_only_file)24 void Init(const std::string& filename, bool headers_only_file) {
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);
30 headers_only_file_ = headers_only_file;
31 }
32
CountRtpPackets()33 int CountRtpPackets() {
34 test::RtpPacket packet;
35 int c = 0;
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);
41 c++;
42 }
43 return c;
44 }
45
46 private:
47 std::unique_ptr<test::RtpFileReader> rtp_packet_source_;
48 bool headers_only_file_;
49 };
50
TEST_F(TestRtpFileReader,Test60Packets)51 TEST_F(TestRtpFileReader, Test60Packets) {
52 Init("pltype103", false);
53 EXPECT_EQ(60, CountRtpPackets());
54 }
55
TEST_F(TestRtpFileReader,Test60PacketsHeaderOnly)56 TEST_F(TestRtpFileReader, Test60PacketsHeaderOnly) {
57 Init("pltype103_header_only", true);
58 EXPECT_EQ(60, CountRtpPackets());
59 }
60
61 typedef std::map<uint32_t, int> PacketsPerSsrc;
62
63 class TestPcapFileReader : public ::testing::Test {
64 public:
Init(const std::string & filename)65 void Init(const std::string& filename) {
66 std::string filepath =
67 test::ResourcePath("video_coding/" + filename, "pcap");
68 rtp_packet_source_.reset(
69 test::RtpFileReader::Create(test::RtpFileReader::kPcap, filepath));
70 ASSERT_TRUE(rtp_packet_source_.get() != NULL);
71 }
72
CountRtpPackets()73 int CountRtpPackets() {
74 int c = 0;
75 test::RtpPacket packet;
76 while (rtp_packet_source_->NextPacket(&packet)) {
77 EXPECT_EQ(packet.length, packet.original_length);
78 c++;
79 }
80 return c;
81 }
82
CountRtpPacketsPerSsrc()83 PacketsPerSsrc CountRtpPacketsPerSsrc() {
84 PacketsPerSsrc pps;
85 test::RtpPacket packet;
86 while (rtp_packet_source_->NextPacket(&packet)) {
87 RtpUtility::RtpHeaderParser rtp_header_parser(packet.data, packet.length);
88 webrtc::RTPHeader header;
89 if (!rtp_header_parser.RTCP() &&
90 rtp_header_parser.Parse(&header, nullptr)) {
91 pps[header.ssrc]++;
92 }
93 }
94 return pps;
95 }
96
97 private:
98 std::unique_ptr<test::RtpFileReader> rtp_packet_source_;
99 };
100
TEST_F(TestPcapFileReader,TestEthernetIIFrame)101 TEST_F(TestPcapFileReader, TestEthernetIIFrame) {
102 Init("frame-ethernet-ii");
103 EXPECT_EQ(368, CountRtpPackets());
104 }
105
TEST_F(TestPcapFileReader,TestLoopbackFrame)106 TEST_F(TestPcapFileReader, TestLoopbackFrame) {
107 Init("frame-loopback");
108 EXPECT_EQ(491, CountRtpPackets());
109 }
110
TEST_F(TestPcapFileReader,TestTwoSsrc)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
TEST_F(TestPcapFileReader,TestThreeSsrc)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 }
127 } // namespace webrtc
128