Home | History | Annotate | Download | only in testAPI
      1 /*
      2  *  Copyright (c) 2012 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 "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h"
     12 
     13 #include <algorithm>
     14 #include <vector>
     15 
     16 using namespace webrtc;
     17 
     18 class RtpRtcpAPITest : public ::testing::Test {
     19  protected:
     20   RtpRtcpAPITest() : module(NULL), fake_clock(123456) {
     21     test_CSRC[0] = 1234;
     22     test_CSRC[1] = 2345;
     23     test_id = 123;
     24     test_ssrc = 3456;
     25     test_timestamp = 4567;
     26     test_sequence_number = 2345;
     27   }
     28   ~RtpRtcpAPITest() {}
     29 
     30   virtual void SetUp() {
     31     RtpRtcp::Configuration configuration;
     32     configuration.id = test_id;
     33     configuration.audio = true;
     34     configuration.clock = &fake_clock;
     35     module = RtpRtcp::CreateRtpRtcp(configuration);
     36     rtp_payload_registry_.reset(new RTPPayloadRegistry(
     37             RTPPayloadStrategy::CreateStrategy(true)));
     38     rtp_receiver_.reset(RtpReceiver::CreateAudioReceiver(
     39         test_id, &fake_clock, NULL, NULL, NULL, rtp_payload_registry_.get()));
     40   }
     41 
     42   virtual void TearDown() {
     43     delete module;
     44   }
     45 
     46   int test_id;
     47   scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
     48   scoped_ptr<RtpReceiver> rtp_receiver_;
     49   RtpRtcp* module;
     50   uint32_t test_ssrc;
     51   uint32_t test_timestamp;
     52   uint16_t test_sequence_number;
     53   uint32_t test_CSRC[webrtc::kRtpCsrcSize];
     54   SimulatedClock fake_clock;
     55 };
     56 
     57 TEST_F(RtpRtcpAPITest, Basic) {
     58   EXPECT_EQ(0, module->SetSequenceNumber(test_sequence_number));
     59   EXPECT_EQ(test_sequence_number, module->SequenceNumber());
     60 
     61   EXPECT_EQ(0, module->SetStartTimestamp(test_timestamp));
     62   EXPECT_EQ(test_timestamp, module->StartTimestamp());
     63 
     64   EXPECT_FALSE(module->Sending());
     65   EXPECT_EQ(0, module->SetSendingStatus(true));
     66   EXPECT_TRUE(module->Sending());
     67 }
     68 
     69 TEST_F(RtpRtcpAPITest, MTU) {
     70   EXPECT_EQ(-1, module->SetMaxTransferUnit(10));
     71   EXPECT_EQ(-1, module->SetMaxTransferUnit(IP_PACKET_SIZE + 1));
     72   EXPECT_EQ(0, module->SetMaxTransferUnit(1234));
     73   EXPECT_EQ(1234-20-8, module->MaxPayloadLength());
     74 
     75   EXPECT_EQ(0, module->SetTransportOverhead(true, true, 12));
     76   EXPECT_EQ(1234 - 20- 20 -20 - 12, module->MaxPayloadLength());
     77 
     78   EXPECT_EQ(0, module->SetTransportOverhead(false, false, 0));
     79   EXPECT_EQ(1234 - 20 - 8, module->MaxPayloadLength());
     80 }
     81 
     82 TEST_F(RtpRtcpAPITest, SSRC) {
     83   module->SetSSRC(test_ssrc);
     84   EXPECT_EQ(test_ssrc, module->SSRC());
     85 }
     86 
     87 TEST_F(RtpRtcpAPITest, CSRC) {
     88   EXPECT_EQ(0, module->SetCSRCs(test_CSRC, 2));
     89   uint32_t testOfCSRC[webrtc::kRtpCsrcSize];
     90   EXPECT_EQ(2, module->CSRCs(testOfCSRC));
     91   EXPECT_EQ(test_CSRC[0], testOfCSRC[0]);
     92   EXPECT_EQ(test_CSRC[1], testOfCSRC[1]);
     93 }
     94 
     95 TEST_F(RtpRtcpAPITest, RTCP) {
     96   EXPECT_EQ(kRtcpOff, module->RTCP());
     97   EXPECT_EQ(0, module->SetRTCPStatus(kRtcpCompound));
     98   EXPECT_EQ(kRtcpCompound, module->RTCP());
     99 
    100   EXPECT_EQ(0, module->SetCNAME("john.doe (at) test.test"));
    101 
    102   char cName[RTCP_CNAME_SIZE];
    103   EXPECT_EQ(0, module->CNAME(cName));
    104   EXPECT_STRCASEEQ(cName, "john.doe (at) test.test");
    105 
    106   EXPECT_FALSE(module->TMMBR());
    107   EXPECT_EQ(0, module->SetTMMBRStatus(true));
    108   EXPECT_TRUE(module->TMMBR());
    109   EXPECT_EQ(0, module->SetTMMBRStatus(false));
    110   EXPECT_FALSE(module->TMMBR());
    111 
    112   EXPECT_EQ(kNackOff, rtp_receiver_->NACK());
    113   rtp_receiver_->SetNACKStatus(kNackRtcp);
    114   EXPECT_EQ(kNackRtcp, rtp_receiver_->NACK());
    115 }
    116 
    117 TEST_F(RtpRtcpAPITest, RtxSender) {
    118   unsigned int ssrc = 0;
    119   int rtx_mode = kRtxOff;
    120   const int kRtxPayloadType = 119;
    121   int payload_type = -1;
    122   module->SetRTXSendStatus(kRtxRetransmitted);
    123   module->SetRtxSendPayloadType(kRtxPayloadType);
    124   module->SetRtxSsrc(1);
    125   module->RTXSendStatus(&rtx_mode, &ssrc, &payload_type);
    126   EXPECT_EQ(kRtxRetransmitted, rtx_mode);
    127   EXPECT_EQ(1u, ssrc);
    128   EXPECT_EQ(kRtxPayloadType, payload_type);
    129   rtx_mode = kRtxOff;
    130   module->SetRTXSendStatus(kRtxOff);
    131   payload_type = -1;
    132   module->SetRtxSendPayloadType(kRtxPayloadType);
    133   module->RTXSendStatus(&rtx_mode, &ssrc, &payload_type);
    134   EXPECT_EQ(kRtxOff, rtx_mode);
    135   EXPECT_EQ(kRtxPayloadType, payload_type);
    136   module->SetRTXSendStatus(kRtxRetransmitted);
    137   module->RTXSendStatus(&rtx_mode, &ssrc, &payload_type);
    138   EXPECT_EQ(kRtxRetransmitted, rtx_mode);
    139   EXPECT_EQ(kRtxPayloadType, payload_type);
    140 }
    141 
    142 TEST_F(RtpRtcpAPITest, RtxReceiver) {
    143   const uint32_t kRtxSsrc = 1;
    144   const int kRtxPayloadType = 119;
    145   EXPECT_FALSE(rtp_payload_registry_->RtxEnabled());
    146   rtp_payload_registry_->SetRtxSsrc(kRtxSsrc);
    147   rtp_payload_registry_->SetRtxPayloadType(kRtxPayloadType);
    148   EXPECT_TRUE(rtp_payload_registry_->RtxEnabled());
    149   RTPHeader rtx_header;
    150   rtx_header.ssrc = kRtxSsrc;
    151   rtx_header.payloadType = kRtxPayloadType;
    152   EXPECT_TRUE(rtp_payload_registry_->IsRtx(rtx_header));
    153   rtx_header.ssrc = 0;
    154   EXPECT_FALSE(rtp_payload_registry_->IsRtx(rtx_header));
    155   rtx_header.ssrc = kRtxSsrc;
    156   rtx_header.payloadType = 0;
    157   EXPECT_TRUE(rtp_payload_registry_->IsRtx(rtx_header));
    158 }
    159