2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #include "testing/gtest/include/gtest/gtest.h"
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"
24 using namespace webrtc;
27 class TestTransport : public Transport {
29 TestTransport(RTCPReceiver* rtcp_receiver) :
30 rtcp_receiver_(rtcp_receiver) {
33 virtual int SendPacket(int /*channel*/, const void* /*data*/, int /*len*/) {
36 virtual int SendRTCPPacket(int /*channel*/,
39 RTCPUtility::RTCPParserV2 rtcpParser((uint8_t*)packet,
40 (int32_t)packetLength,
41 true); // Allow non-compound RTCP
43 EXPECT_TRUE(rtcpParser.IsValid());
44 RTCPHelp::RTCPPacketInformation rtcpPacketInformation;
45 EXPECT_EQ(0, rtcp_receiver_->IncomingRTCPPacket(rtcpPacketInformation,
48 EXPECT_EQ((uint32_t)kRtcpRemb,
49 rtcpPacketInformation.rtcpPacketTypeFlags & kRtcpRemb);
50 EXPECT_EQ((uint32_t)1234,
51 rtcpPacketInformation.receiverEstimatedMaxBitrate);
55 RTCPReceiver* rtcp_receiver_;
59 class RtcpFormatRembTest : public ::testing::Test {
61 static const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000;
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_,
72 kRemoteBitrateEstimatorMinBitrateBps)) {}
74 virtual void TearDown();
76 OverUseDetectorOptions over_use_detector_options_;
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_;
87 void RtcpFormatRembTest::SetUp() {
88 RtpRtcp::Configuration configuration;
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);
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_);
99 EXPECT_EQ(0, rtcp_sender_->Init());
100 EXPECT_EQ(0, rtcp_sender_->RegisterSendTransport(test_transport_));
103 void RtcpFormatRembTest::TearDown() {
105 delete rtcp_receiver_;
106 delete dummy_rtp_rtcp_impl_;
107 delete test_transport_;
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());
117 EXPECT_EQ(0, rtcp_sender_->SetREMBData(1234, 0, NULL));
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));
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));