blob: b5fa260c7dc67094e9161151f6f9df1d63820e27 [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
11#include <map>
12
13#include "testing/gtest/include/gtest/gtest.h"
14#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000015#include "webrtc/system_wrappers/interface/scoped_ptr.h"
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000016#include "webrtc/test/rtp_file_reader.h"
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000017#include "webrtc/test/testsupport/fileutils.h"
18
19namespace webrtc {
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000020
21class 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
43TEST_F(TestRtpFileReader, Test60Packets) {
44 Init("pltype103");
45 EXPECT_EQ(60, CountRtpPackets());
46}
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000047
48typedef std::map<uint32_t, int> PacketsPerSsrc;
49
50class 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.org4b5625e2014-08-06 16:26:56 +000055 rtp_packet_source_.reset(
56 test::RtpFileReader::Create(test::RtpFileReader::kPcap, filepath));
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000057 ASSERT_TRUE(rtp_packet_source_.get() != NULL);
58 }
59
60 int CountRtpPackets() {
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000061 int c = 0;
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000062 test::RtpFileReader::Packet packet;
63 while (rtp_packet_source_->NextPacket(&packet))
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000064 c++;
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000065 return c;
66 }
67
68 PacketsPerSsrc CountRtpPacketsPerSsrc() {
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000069 PacketsPerSsrc pps;
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000070 test::RtpFileReader::Packet packet;
71 while (rtp_packet_source_->NextPacket(&packet)) {
72 RtpUtility::RtpHeaderParser rtp_header_parser(packet.data, packet.length);
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000073 webrtc::RTPHeader header;
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000074 if (!rtp_header_parser.RTCP() && rtp_header_parser.Parse(header, NULL)) {
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000075 pps[header.ssrc]++;
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000076 }
77 }
78 return pps;
79 }
80
81 private:
pbos@webrtc.org4b5625e2014-08-06 16:26:56 +000082 scoped_ptr<test::RtpFileReader> rtp_packet_source_;
solenberg@webrtc.org56b5f772013-04-16 10:31:56 +000083};
84
85TEST_F(TestPcapFileReader, TestEthernetIIFrame) {
86 Init("frame-ethernet-ii");
87 EXPECT_EQ(368, CountRtpPackets());
88}
89
90TEST_F(TestPcapFileReader, TestLoopbackFrame) {
91 Init("frame-loopback");
92 EXPECT_EQ(491, CountRtpPackets());
93}
94
95TEST_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
103TEST_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.org56b5f772013-04-16 10:31:56 +0000111} // namespace webrtc