Home | History | Annotate | Download | only in test
      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"
     15 #include "webrtc/modules/video_coding/main/test/pcap_file_reader.h"
     16 #include "webrtc/modules/video_coding/main/test/rtp_player.h"
     17 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
     18 #include "webrtc/test/testsupport/fileutils.h"
     19 
     20 namespace webrtc {
     21 namespace rtpplayer {
     22 
     23 typedef std::map<uint32_t, int> PacketsPerSsrc;
     24 
     25 class TestPcapFileReader : public ::testing::Test {
     26  public:
     27   void Init(const std::string& filename) {
     28     std::string filepath =
     29         test::ResourcePath("video_coding/" + filename, "pcap");
     30     rtp_packet_source_.reset(CreatePcapFileReader(filepath));
     31     ASSERT_TRUE(rtp_packet_source_.get() != NULL);
     32   }
     33 
     34   int CountRtpPackets() {
     35     const uint32_t kBufferSize = 4096;
     36     uint8_t data[kBufferSize];
     37     uint32_t length = kBufferSize;
     38     uint32_t dummy_time_ms = 0;
     39     int c = 0;
     40     while (rtp_packet_source_->NextPacket(data, &length, &dummy_time_ms) == 0) {
     41       EXPECT_GE(kBufferSize, length);
     42       length = kBufferSize;
     43       c++;
     44     }
     45     return c;
     46   }
     47 
     48   PacketsPerSsrc CountRtpPacketsPerSsrc() {
     49     const uint32_t kBufferSize = 4096;
     50     uint8_t data[kBufferSize];
     51     uint32_t length = kBufferSize;
     52     uint32_t dummy_time_ms = 0;
     53     PacketsPerSsrc pps;
     54     while (rtp_packet_source_->NextPacket(data, &length, &dummy_time_ms) == 0) {
     55       EXPECT_GE(kBufferSize, length);
     56       length = kBufferSize;
     57 
     58       ModuleRTPUtility::RTPHeaderParser rtp_header_parser(data, length);
     59       webrtc::RTPHeader header;
     60       if (!rtp_header_parser.RTCP() && rtp_header_parser.Parse(header, NULL)) {
     61         pps[header.ssrc]++;
     62       }
     63     }
     64     return pps;
     65   }
     66 
     67  private:
     68   scoped_ptr<RtpPacketSourceInterface> rtp_packet_source_;
     69 };
     70 
     71 TEST_F(TestPcapFileReader, TestEthernetIIFrame) {
     72   Init("frame-ethernet-ii");
     73   EXPECT_EQ(368, CountRtpPackets());
     74 }
     75 
     76 TEST_F(TestPcapFileReader, TestLoopbackFrame) {
     77   Init("frame-loopback");
     78   EXPECT_EQ(491, CountRtpPackets());
     79 }
     80 
     81 TEST_F(TestPcapFileReader, TestTwoSsrc) {
     82   Init("ssrcs-2");
     83   PacketsPerSsrc pps = CountRtpPacketsPerSsrc();
     84   EXPECT_EQ(2UL, pps.size());
     85   EXPECT_EQ(370, pps[0x78d48f61]);
     86   EXPECT_EQ(60, pps[0xae94130b]);
     87 }
     88 
     89 TEST_F(TestPcapFileReader, TestThreeSsrc) {
     90   Init("ssrcs-3");
     91   PacketsPerSsrc pps = CountRtpPacketsPerSsrc();
     92   EXPECT_EQ(3UL, pps.size());
     93   EXPECT_EQ(162, pps[0x938c5eaa]);
     94   EXPECT_EQ(113, pps[0x59fe6ef0]);
     95   EXPECT_EQ(61, pps[0xed2bd2ac]);
     96 }
     97 
     98 }  // namespace rtpplayer
     99 }  // namespace webrtc
    100