Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / rtp_rtcp / source / rtcp_format_remb_unittest.cc
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                 kRemoteBitrateEstimatorMinBitrateBps)) {}
73   virtual void SetUp();
74   virtual void TearDown();
75
76   OverUseDetectorOptions over_use_detector_options_;
77   Clock* system_clock_;
78   ModuleRtpRtcpImpl* dummy_rtp_rtcp_impl_;
79   scoped_ptr<ReceiveStatistics> receive_statistics_;
80   RTCPSender* rtcp_sender_;
81   RTCPReceiver* rtcp_receiver_;
82   TestTransport* test_transport_;
83   MockRemoteBitrateObserver remote_bitrate_observer_;
84   scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
85 };
86
87 void RtcpFormatRembTest::SetUp() {
88   RtpRtcp::Configuration configuration;
89   configuration.id = 0;
90   configuration.audio = false;
91   configuration.clock = system_clock_;
92   configuration.remote_bitrate_estimator = remote_bitrate_estimator_.get();
93   dummy_rtp_rtcp_impl_ = new ModuleRtpRtcpImpl(configuration);
94   rtcp_sender_ =
95       new RTCPSender(0, false, system_clock_, receive_statistics_.get());
96   rtcp_receiver_ = new RTCPReceiver(0, system_clock_, dummy_rtp_rtcp_impl_);
97   test_transport_ = new TestTransport(rtcp_receiver_);
98
99   EXPECT_EQ(0, rtcp_sender_->Init());
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(dummy_rtp_rtcp_impl_);
125   EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state, kRtcpRemb));
126 }
127
128 TEST_F(RtcpFormatRembTest, TestCompund) {
129   uint32_t SSRCs[2] = {456789, 98765};
130   EXPECT_EQ(0, rtcp_sender_->SetRTCPStatus(kRtcpCompound));
131   EXPECT_EQ(0, rtcp_sender_->SetREMBData(1234, 2, SSRCs));
132   RTCPSender::FeedbackState feedback_state(dummy_rtp_rtcp_impl_);
133   EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state, kRtcpRemb));
134 }
135 }  // namespace