blob: 995d9fbc9d3ccc2e11c304415b8b3d0b4129bdc0 [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
Danil Chapovalov33fdb342021-07-23 15:28:17 +020016#include "api/array_view.h"
17#include "modules/rtp_rtcp/source/rtp_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "test/gtest.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#include "test/testsupport/file_utils.h"
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000020
21namespace webrtc {
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000022
23class TestRtpFileReader : public ::testing::Test {
24 public:
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000025 void Init(const std::string& filename, bool headers_only_file) {
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000026 std::string filepath =
27 test::ResourcePath("video_coding/" + filename, "rtp");
28 rtp_packet_source_.reset(
29 test::RtpFileReader::Create(test::RtpFileReader::kRtpDump, filepath));
30 ASSERT_TRUE(rtp_packet_source_.get() != NULL);
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000031 headers_only_file_ = headers_only_file;
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000032 }
33
34 int CountRtpPackets() {
henrik.lundin@webrtc.org91d928e2014-11-26 15:50:30 +000035 test::RtpPacket packet;
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000036 int c = 0;
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000037 while (rtp_packet_source_->NextPacket(&packet)) {
38 if (headers_only_file_)
39 EXPECT_LT(packet.length, packet.original_length);
40 else
41 EXPECT_EQ(packet.length, packet.original_length);
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000042 c++;
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000043 }
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000044 return c;
45 }
46
47 private:
kwibergbfefb032016-05-01 14:53:46 -070048 std::unique_ptr<test::RtpFileReader> rtp_packet_source_;
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000049 bool headers_only_file_;
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000050};
51
52TEST_F(TestRtpFileReader, Test60Packets) {
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000053 Init("pltype103", false);
54 EXPECT_EQ(60, CountRtpPackets());
55}
56
57TEST_F(TestRtpFileReader, Test60PacketsHeaderOnly) {
58 Init("pltype103_header_only", true);
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000059 EXPECT_EQ(60, CountRtpPackets());
60}
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000061
62typedef std::map<uint32_t, int> PacketsPerSsrc;
63
64class TestPcapFileReader : public ::testing::Test {
65 public:
66 void Init(const std::string& filename) {
67 std::string filepath =
68 test::ResourcePath("video_coding/" + filename, "pcap");
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000069 rtp_packet_source_.reset(
70 test::RtpFileReader::Create(test::RtpFileReader::kPcap, filepath));
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000071 ASSERT_TRUE(rtp_packet_source_.get() != NULL);
72 }
73
74 int CountRtpPackets() {
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000075 int c = 0;
henrik.lundin@webrtc.org91d928e2014-11-26 15:50:30 +000076 test::RtpPacket packet;
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000077 while (rtp_packet_source_->NextPacket(&packet)) {
78 EXPECT_EQ(packet.length, packet.original_length);
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000079 c++;
henrik.lundin@webrtc.org38c121c2014-09-30 11:08:44 +000080 }
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000081 return c;
82 }
83
84 PacketsPerSsrc CountRtpPacketsPerSsrc() {
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000085 PacketsPerSsrc pps;
henrik.lundin@webrtc.org91d928e2014-11-26 15:50:30 +000086 test::RtpPacket packet;
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000087 while (rtp_packet_source_->NextPacket(&packet)) {
Danil Chapovalov33fdb342021-07-23 15:28:17 +020088 rtc::ArrayView<const uint8_t> raw(packet.data, packet.length);
89 if (IsRtpPacket(raw)) {
90 pps[ParseRtpSsrc(raw)]++;
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000091 }
92 }
93 return pps;
94 }
95
96 private:
kwibergbfefb032016-05-01 14:53:46 -070097 std::unique_ptr<test::RtpFileReader> rtp_packet_source_;
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000098};
99
100TEST_F(TestPcapFileReader, TestEthernetIIFrame) {
101 Init("frame-ethernet-ii");
102 EXPECT_EQ(368, CountRtpPackets());
103}
104
105TEST_F(TestPcapFileReader, TestLoopbackFrame) {
106 Init("frame-loopback");
107 EXPECT_EQ(491, CountRtpPackets());
108}
109
110TEST_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
118TEST_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.org56b5f772013-04-16 10:31:56 +0000126} // namespace webrtc