blob: 2a7902fadf289a16731df32e900df2f7350150c6 [file] [log] [blame]
pwestin@webrtc.org741da942011-09-20 13:52:041/*
phoglund@webrtc.org78088c22012-02-07 14:56:452 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
pwestin@webrtc.org741da942011-09-20 13:52:043 *
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
pbos@webrtc.orga048d7c2013-05-29 14:27:3811#include "testing/gtest/include/gtest/gtest.h"
pwestin@webrtc.org741da942011-09-20 13:52:0412
pbos@webrtc.orga048d7c2013-05-29 14:27:3813#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"
pwestin@webrtc.org741da942011-09-20 13:52:0421
22namespace {
23
24using namespace webrtc;
25
26
27class 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) {
pbos@webrtc.org2f446732013-04-08 11:08:4139 RTCPUtility::RTCPParserV2 rtcpParser((uint8_t*)packet,
40 (int32_t)packetLength,
pwestin@webrtc.org741da942011-09-20 13:52:0441 true); // Allow non-compound RTCP
42
phoglund@webrtc.org78088c22012-02-07 14:56:4543 EXPECT_TRUE(rtcpParser.IsValid());
pwestin@webrtc.org741da942011-09-20 13:52:0444 RTCPHelp::RTCPPacketInformation rtcpPacketInformation;
45 EXPECT_EQ(0, rtcp_receiver_->IncomingRTCPPacket(rtcpPacketInformation,
46 &rtcpParser));
47
pbos@webrtc.org2f446732013-04-08 11:08:4148 EXPECT_EQ((uint32_t)kRtcpRemb,
pwestin@webrtc.org741da942011-09-20 13:52:0449 rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRemb);
pbos@webrtc.org2f446732013-04-08 11:08:4150 EXPECT_EQ((uint32_t)1234,
pwestin@webrtc.org741da942011-09-20 13:52:0451 rtcpPacketInformation.receiverEstimatedMaxBitrate);
52 return packetLength;
53 }
54 private:
55 RTCPReceiver* rtcp_receiver_;
56};
57
58
59class RtcpFormatRembTest : public ::testing::Test {
60 protected:
stefan@webrtc.org9354cc92012-06-07 08:10:1461 RtcpFormatRembTest()
astor@webrtc.orgbd7aeba2012-06-26 10:47:0462 : over_use_detector_options_(),
stefan@webrtc.orgb5865072013-02-01 14:33:4263 system_clock_(Clock::GetRealTimeClock()),
stefan@webrtc.org717d1472013-07-10 13:39:2764 receive_statistics_(ReceiveStatistics::Create(system_clock_)),
astor@webrtc.orgbd7aeba2012-06-26 10:47:0465 remote_bitrate_observer_(),
andresp@webrtc.org29b22192013-05-14 12:10:5866 remote_bitrate_estimator_(
67 RemoteBitrateEstimatorFactory().Create(
68 &remote_bitrate_observer_,
69 system_clock_)) {}
pwestin@webrtc.org741da942011-09-20 13:52:0470 virtual void SetUp();
71 virtual void TearDown();
72
astor@webrtc.orgbd7aeba2012-06-26 10:47:0473 OverUseDetectorOptions over_use_detector_options_;
stefan@webrtc.org20ed36d2013-01-17 14:01:2074 Clock* system_clock_;
pwestin@webrtc.org741da942011-09-20 13:52:0475 ModuleRtpRtcpImpl* dummy_rtp_rtcp_impl_;
stefan@webrtc.org717d1472013-07-10 13:39:2776 scoped_ptr<ReceiveStatistics> receive_statistics_;
pwestin@webrtc.org741da942011-09-20 13:52:0477 RTCPSender* rtcp_sender_;
78 RTCPReceiver* rtcp_receiver_;
79 TestTransport* test_transport_;
stefan@webrtc.org9354cc92012-06-07 08:10:1480 MockRemoteBitrateObserver remote_bitrate_observer_;
stefan@webrtc.org976a7e62012-09-21 13:20:2181 scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
pwestin@webrtc.org741da942011-09-20 13:52:0482};
83
84void RtcpFormatRembTest::SetUp() {
pwestin@webrtc.org2853dde2012-05-11 11:08:5485 RtpRtcp::Configuration configuration;
86 configuration.id = 0;
87 configuration.audio = false;
88 configuration.clock = system_clock_;
stefan@webrtc.org976a7e62012-09-21 13:20:2189 configuration.remote_bitrate_estimator = remote_bitrate_estimator_.get();
pwestin@webrtc.org2853dde2012-05-11 11:08:5490 dummy_rtp_rtcp_impl_ = new ModuleRtpRtcpImpl(configuration);
stefan@webrtc.org717d1472013-07-10 13:39:2791 rtcp_sender_ = new RTCPSender(0, false, system_clock_, dummy_rtp_rtcp_impl_,
92 receive_statistics_.get());
henrike@webrtc.orgd6d014f2012-02-16 02:18:0993 rtcp_receiver_ = new RTCPReceiver(0, system_clock_, dummy_rtp_rtcp_impl_);
pwestin@webrtc.org741da942011-09-20 13:52:0494 test_transport_ = new TestTransport(rtcp_receiver_);
95
96 EXPECT_EQ(0, rtcp_sender_->Init());
97 EXPECT_EQ(0, rtcp_sender_->RegisterSendTransport(test_transport_));
98}
99
100void RtcpFormatRembTest::TearDown() {
101 delete rtcp_sender_;
102 delete rtcp_receiver_;
103 delete dummy_rtp_rtcp_impl_;
104 delete test_transport_;
105}
106
107TEST_F(RtcpFormatRembTest, TestBasicAPI) {
phoglund@webrtc.orgd1a860b2012-01-26 14:49:28108 EXPECT_FALSE(rtcp_sender_->REMB());
pwestin@webrtc.org741da942011-09-20 13:52:04109 EXPECT_EQ(0, rtcp_sender_->SetREMBStatus(true));
phoglund@webrtc.orgd1a860b2012-01-26 14:49:28110 EXPECT_TRUE(rtcp_sender_->REMB());
pwestin@webrtc.org741da942011-09-20 13:52:04111 EXPECT_EQ(0, rtcp_sender_->SetREMBStatus(false));
phoglund@webrtc.orgd1a860b2012-01-26 14:49:28112 EXPECT_FALSE(rtcp_sender_->REMB());
pwestin@webrtc.org741da942011-09-20 13:52:04113
114 EXPECT_EQ(0, rtcp_sender_->SetREMBData(1234, 0, NULL));
115}
116
117TEST_F(RtcpFormatRembTest, TestNonCompund) {
pbos@webrtc.org2f446732013-04-08 11:08:41118 uint32_t SSRC = 456789;
pwestin@webrtc.org741da942011-09-20 13:52:04119 EXPECT_EQ(0, rtcp_sender_->SetRTCPStatus(kRtcpNonCompound));
120 EXPECT_EQ(0, rtcp_sender_->SetREMBData(1234, 1, &SSRC));
stefan@webrtc.org717d1472013-07-10 13:39:27121 EXPECT_EQ(0, rtcp_sender_->SendRTCP(kRtcpRemb));
pwestin@webrtc.org741da942011-09-20 13:52:04122}
123
124TEST_F(RtcpFormatRembTest, TestCompund) {
pbos@webrtc.org2f446732013-04-08 11:08:41125 uint32_t SSRCs[2] = {456789, 98765};
pwestin@webrtc.org741da942011-09-20 13:52:04126 EXPECT_EQ(0, rtcp_sender_->SetRTCPStatus(kRtcpCompound));
127 EXPECT_EQ(0, rtcp_sender_->SetREMBData(1234, 2, SSRCs));
stefan@webrtc.org717d1472013-07-10 13:39:27128 EXPECT_EQ(0, rtcp_sender_->SendRTCP(kRtcpRemb));
pwestin@webrtc.org741da942011-09-20 13:52:04129}
pbos@webrtc.orgd900e8b2013-07-03 15:12:26130} // namespace