blob: 8dc817de60f656406c72f4b383e4799e54b0e811 [file] [log] [blame]
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +00001/*
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 Olssona4d87372019-07-05 19:08:33 +020011#include "test/rtp_file_reader.h"
12
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000013#include <map>
kwibergbfefb032016-05-01 14:53:46 -070014#include <memory>
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000015
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/rtp_rtcp/source/rtp_utility.h"
17#include "test/gtest.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "test/testsupport/file_utils.h"
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000019
20namespace webrtc {
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000021
22class TestRtpFileReader : public ::testing::Test {
23 public:
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000024 void Init(const std::string& filename, bool headers_only_file) {
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000025 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.org38c121c2014-09-30 11:08:44 +000030 headers_only_file_ = headers_only_file;
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000031 }
32
33 int CountRtpPackets() {
henrik.lundin@webrtc.org91d928e2014-11-26 15:50:30 +000034 test::RtpPacket packet;
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000035 int c = 0;
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000036 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.org4b5625e2014-08-06 16:26:56 +000041 c++;
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000042 }
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000043 return c;
44 }
45
46 private:
kwibergbfefb032016-05-01 14:53:46 -070047 std::unique_ptr<test::RtpFileReader> rtp_packet_source_;
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000048 bool headers_only_file_;
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000049};
50
51TEST_F(TestRtpFileReader, Test60Packets) {
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000052 Init("pltype103", false);
53 EXPECT_EQ(60, CountRtpPackets());
54}
55
56TEST_F(TestRtpFileReader, Test60PacketsHeaderOnly) {
57 Init("pltype103_header_only", true);
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000058 EXPECT_EQ(60, CountRtpPackets());
59}
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000060
61typedef std::map<uint32_t, int> PacketsPerSsrc;
62
63class 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.org4b5625e2014-08-06 16:26:56 +000068 rtp_packet_source_.reset(
69 test::RtpFileReader::Create(test::RtpFileReader::kPcap, filepath));
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000070 ASSERT_TRUE(rtp_packet_source_.get() != NULL);
71 }
72
73 int CountRtpPackets() {
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000074 int c = 0;
henrik.lundin@webrtc.org91d928e2014-11-26 15:50:30 +000075 test::RtpPacket packet;
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000076 while (rtp_packet_source_->NextPacket(&packet)) {
77 EXPECT_EQ(packet.length, packet.original_length);
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000078 c++;
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000079 }
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000080 return c;
81 }
82
83 PacketsPerSsrc CountRtpPacketsPerSsrc() {
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000084 PacketsPerSsrc pps;
henrik.lundin@webrtc.org91d928e2014-11-26 15:50:30 +000085 test::RtpPacket packet;
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000086 while (rtp_packet_source_->NextPacket(&packet)) {
87 RtpUtility::RtpHeaderParser rtp_header_parser(packet.data, packet.length);
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000088 webrtc::RTPHeader header;
danilchapf6975f42015-12-28 10:18:46 -080089 if (!rtp_header_parser.RTCP() &&
90 rtp_header_parser.Parse(&header, nullptr)) {
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000091 pps[header.ssrc]++;
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000092 }
93 }
94 return pps;
95 }
96
97 private:
kwibergbfefb032016-05-01 14:53:46 -070098 std::unique_ptr<test::RtpFileReader> rtp_packet_source_;
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000099};
100
101TEST_F(TestPcapFileReader, TestEthernetIIFrame) {
102 Init("frame-ethernet-ii");
103 EXPECT_EQ(368, CountRtpPackets());
104}
105
106TEST_F(TestPcapFileReader, TestLoopbackFrame) {
107 Init("frame-loopback");
108 EXPECT_EQ(491, CountRtpPackets());
109}
110
111TEST_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
119TEST_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.org56b5f772013-04-16 10:31:56 +0000127} // namespace webrtc