Home | History | Annotate | Download | only in source
      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 "testing/gtest/include/gtest/gtest.h"
     12 
     13 #include "webrtc/common_types.h"
     14 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
     15 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitrate_observer.h"
     16 #include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h"
     17 #include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h"
     18 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h"
     19 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
     20 #include "webrtc/typedefs.h"
     21 
     22 namespace {
     23 
     24 using namespace webrtc;
     25 
     26 
     27 class TestTransport : public Transport {
     28  public:
     29   TestTransport(RTCPReceiver* rtcp_receiver) :
     30     rtcp_receiver_(rtcp_receiver) {
     31   }
     32 
     33   virtual int SendPacket(int /*channel*/, const void* /*data*/, int /*len*/) {
     34     return -1;
     35   }
     36   virtual int SendRTCPPacket(int /*channel*/,
     37                              const void *packet,
     38                              int packetLength) {
     39     RTCPUtility::RTCPParserV2 rtcpParser((uint8_t*)packet,
     40                                          (int32_t)packetLength,
     41                                          true); // Allow non-compound RTCP
     42 
     43     EXPECT_TRUE(rtcpParser.IsValid());
     44     RTCPHelp::RTCPPacketInformation rtcpPacketInformation;
     45     EXPECT_EQ(0, rtcp_receiver_->IncomingRTCPPacket(rtcpPacketInformation,
     46                                                     &rtcpParser));
     47 
     48     EXPECT_EQ((uint32_t)kRtcpRemb,
     49               rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRemb);
     50     EXPECT_EQ((uint32_t)1234,
     51               rtcpPacketInformation.receiverEstimatedMaxBitrate);
     52     return packetLength;
     53   }
     54  private:
     55   RTCPReceiver* rtcp_receiver_;
     56 };
     57 
     58 
     59 class RtcpFormatRembTest : public ::testing::Test {
     60  protected:
     61   static const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000;
     62 
     63   RtcpFormatRembTest()
     64       : over_use_detector_options_(),
     65         system_clock_(Clock::GetRealTimeClock()),
     66         receive_statistics_(ReceiveStatistics::Create(system_clock_)),
     67         remote_bitrate_observer_(),
     68         remote_bitrate_estimator_(
     69             RemoteBitrateEstimatorFactory().Create(
     70                 &remote_bitrate_observer_,
     71                 system_clock_,
     72                 kMimdControl,
     73                 kRemoteBitrateEstimatorMinBitrateBps)) {}
     74   virtual void SetUp();
     75   virtual void TearDown();
     76 
     77   OverUseDetectorOptions over_use_detector_options_;
     78   Clock* system_clock_;
     79   ModuleRtpRtcpImpl* dummy_rtp_rtcp_impl_;
     80   scoped_ptr<ReceiveStatistics> receive_statistics_;
     81   RTCPSender* rtcp_sender_;
     82   RTCPReceiver* rtcp_receiver_;
     83   TestTransport* test_transport_;
     84   MockRemoteBitrateObserver remote_bitrate_observer_;
     85   scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
     86 };
     87 
     88 void RtcpFormatRembTest::SetUp() {
     89   RtpRtcp::Configuration configuration;
     90   configuration.id = 0;
     91   configuration.audio = false;
     92   configuration.clock = system_clock_;
     93   configuration.remote_bitrate_estimator = remote_bitrate_estimator_.get();
     94   dummy_rtp_rtcp_impl_ = new ModuleRtpRtcpImpl(configuration);
     95   rtcp_sender_ =
     96       new RTCPSender(0, false, system_clock_, receive_statistics_.get());
     97   rtcp_receiver_ = new RTCPReceiver(0, system_clock_, dummy_rtp_rtcp_impl_);
     98   test_transport_ = new TestTransport(rtcp_receiver_);
     99 
    100   EXPECT_EQ(0, rtcp_sender_->RegisterSendTransport(test_transport_));
    101 }
    102 
    103 void RtcpFormatRembTest::TearDown() {
    104   delete rtcp_sender_;
    105   delete rtcp_receiver_;
    106   delete dummy_rtp_rtcp_impl_;
    107   delete test_transport_;
    108 }
    109 
    110 TEST_F(RtcpFormatRembTest, TestBasicAPI) {
    111   EXPECT_FALSE(rtcp_sender_->REMB());
    112   EXPECT_EQ(0, rtcp_sender_->SetREMBStatus(true));
    113   EXPECT_TRUE(rtcp_sender_->REMB());
    114   EXPECT_EQ(0, rtcp_sender_->SetREMBStatus(false));
    115   EXPECT_FALSE(rtcp_sender_->REMB());
    116 
    117   EXPECT_EQ(0, rtcp_sender_->SetREMBData(1234, 0, NULL));
    118 }
    119 
    120 TEST_F(RtcpFormatRembTest, TestNonCompund) {
    121   uint32_t SSRC = 456789;
    122   EXPECT_EQ(0, rtcp_sender_->SetRTCPStatus(kRtcpNonCompound));
    123   EXPECT_EQ(0, rtcp_sender_->SetREMBData(1234, 1, &SSRC));
    124   RTCPSender::FeedbackState feedback_state =
    125       dummy_rtp_rtcp_impl_->GetFeedbackState();
    126   EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state, kRtcpRemb));
    127 }
    128 
    129 TEST_F(RtcpFormatRembTest, TestCompund) {
    130   uint32_t SSRCs[2] = {456789, 98765};
    131   EXPECT_EQ(0, rtcp_sender_->SetRTCPStatus(kRtcpCompound));
    132   EXPECT_EQ(0, rtcp_sender_->SetREMBData(1234, 2, SSRCs));
    133   RTCPSender::FeedbackState feedback_state =
    134       dummy_rtp_rtcp_impl_->GetFeedbackState();
    135   EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state, kRtcpRemb));
    136 }
    137 }  // namespace
    138