2016-05-11 06:01:13 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "testing/gmock/include/gmock/gmock.h"
|
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
#include "webrtc/modules/pacing/mock/mock_paced_sender.h"
|
|
|
|
|
#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
|
|
|
|
|
#include "webrtc/modules/congestion_controller/include/mock/mock_congestion_controller.h"
|
|
|
|
|
#include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitrate_observer.h"
|
|
|
|
|
#include "webrtc/system_wrappers/include/clock.h"
|
|
|
|
|
|
|
|
|
|
using testing::_;
|
|
|
|
|
using testing::NiceMock;
|
|
|
|
|
using testing::Return;
|
|
|
|
|
using testing::SaveArg;
|
|
|
|
|
using testing::StrictMock;
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
|
|
class CongestionControllerTest : public ::testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
CongestionControllerTest() : clock_(123456) {}
|
|
|
|
|
~CongestionControllerTest() override {}
|
|
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
|
pacer_ = new NiceMock<MockPacedSender>();
|
|
|
|
|
std::unique_ptr<PacedSender> pacer(pacer_); // Passes ownership.
|
|
|
|
|
std::unique_ptr<PacketRouter> packet_router(new PacketRouter());
|
Revert of Move RtcEventLog object from inside VoiceEngine to Call. (patchset #16 id:420001 of https://codereview.webrtc.org/1748403002/ )
Reason for revert:
Reverting all CLs related to moving the eventlog, as they break Chromium tests.
Original issue's description:
> Move RtcEventLog object from inside VoiceEngine to Call.
>
> In addition to moving the logging object itself, this also moves the interface from PeerConnectionFactory to PeerConnection, which makes more sense for this functionality. An API parameter to set an upper limit to the size of the logfile is introduced.
> The old interface on PeerConnectionFactory is not removed in this CL, because it is called from Chrome, it will be removed after Chrome is updated to use the PeerConnection interface.
>
> BUG=webrtc:4741,webrtc:5603,chromium:609749
> R=solenberg@webrtc.org, stefan@webrtc.org, terelius@webrtc.org, tommi@webrtc.org
>
> Committed: https://crrev.com/1895526c6130e3d0e9b154f95079b8eda7567016
> Cr-Commit-Position: refs/heads/master@{#13321}
TBR=solenberg@webrtc.org,tommi@webrtc.org,stefan@webrtc.org,terelius@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:4741,webrtc:5603,chromium:609749
Review-Url: https://codereview.webrtc.org/2111813002
Cr-Commit-Position: refs/heads/master@{#13340}
2016-06-30 00:59:43 -07:00
|
|
|
controller_.reset(
|
|
|
|
|
new CongestionController(&clock_, &observer_, &remote_bitrate_observer_,
|
|
|
|
|
std::move(packet_router), std::move(pacer)));
|
2016-05-11 06:01:13 -07:00
|
|
|
bandwidth_observer_.reset(
|
|
|
|
|
controller_->GetBitrateController()->CreateRtcpBandwidthObserver());
|
|
|
|
|
|
|
|
|
|
// Set the initial bitrate estimate and expect the |observer| and |pacer_|
|
|
|
|
|
// to be updated.
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _));
|
|
|
|
|
EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps));
|
|
|
|
|
controller_->SetBweBitrates(0, kInitialBitrateBps, 5 * kInitialBitrateBps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SimulatedClock clock_;
|
|
|
|
|
StrictMock<MockCongestionObserver> observer_;
|
|
|
|
|
NiceMock<MockPacedSender>* pacer_;
|
|
|
|
|
NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_;
|
|
|
|
|
std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_;
|
|
|
|
|
std::unique_ptr<CongestionController> controller_;
|
|
|
|
|
const uint32_t kInitialBitrateBps = 60000;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(CongestionControllerTest, OnNetworkChanged) {
|
|
|
|
|
// Test no change.
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(25);
|
|
|
|
|
controller_->Process();
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _));
|
|
|
|
|
EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2));
|
|
|
|
|
bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2);
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(25);
|
|
|
|
|
controller_->Process();
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _));
|
|
|
|
|
EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps));
|
|
|
|
|
bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps);
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(25);
|
|
|
|
|
controller_->Process();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CongestionControllerTest, OnSendQueueFull) {
|
|
|
|
|
EXPECT_CALL(*pacer_, ExpectedQueueTimeMs())
|
|
|
|
|
.WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1));
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(0, _, _));
|
|
|
|
|
controller_->Process();
|
|
|
|
|
|
|
|
|
|
// Let the pacer not be full next time the controller checks.
|
|
|
|
|
EXPECT_CALL(*pacer_, ExpectedQueueTimeMs())
|
|
|
|
|
.WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1));
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _));
|
|
|
|
|
controller_->Process();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CongestionControllerTest, OnSendQueueFullAndEstimateChange) {
|
|
|
|
|
EXPECT_CALL(*pacer_, ExpectedQueueTimeMs())
|
|
|
|
|
.WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1));
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(0, _, _));
|
|
|
|
|
controller_->Process();
|
|
|
|
|
|
|
|
|
|
// Receive new estimate but let the queue still be full.
|
|
|
|
|
bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2);
|
|
|
|
|
EXPECT_CALL(*pacer_, ExpectedQueueTimeMs())
|
|
|
|
|
.WillOnce(Return(PacedSender::kMaxQueueLengthMs + 1));
|
|
|
|
|
// The send pacer should get the new estimate though.
|
|
|
|
|
EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2));
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(25);
|
|
|
|
|
controller_->Process();
|
|
|
|
|
|
|
|
|
|
// Let the pacer not be full next time the controller checks.
|
|
|
|
|
// |OnNetworkChanged| should be called with the new estimate.
|
|
|
|
|
EXPECT_CALL(*pacer_, ExpectedQueueTimeMs())
|
|
|
|
|
.WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1));
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _));
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(25);
|
|
|
|
|
controller_->Process();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-14 00:58:48 -07:00
|
|
|
TEST_F(CongestionControllerTest, SignalNetworkState) {
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(0, _, _));
|
|
|
|
|
controller_->SignalNetworkState(kNetworkDown);
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps, _, _));
|
|
|
|
|
controller_->SignalNetworkState(kNetworkUp);
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(0, _, _));
|
|
|
|
|
controller_->SignalNetworkState(kNetworkDown);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-24 11:03:55 -07:00
|
|
|
TEST_F(CongestionControllerTest, ResetBweAndBitrates) {
|
|
|
|
|
int new_bitrate = 200000;
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(new_bitrate, _, _));
|
|
|
|
|
EXPECT_CALL(*pacer_, SetEstimatedBitrate(new_bitrate));
|
|
|
|
|
controller_->ResetBweAndBitrates(new_bitrate, -1, -1);
|
|
|
|
|
|
|
|
|
|
// If the bitrate is reset to -1, the new starting bitrate will be
|
|
|
|
|
// the minimum default bitrate 10000bps.
|
|
|
|
|
int min_default_bitrate = 10000;
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(min_default_bitrate, _, _));
|
|
|
|
|
EXPECT_CALL(*pacer_, SetEstimatedBitrate(min_default_bitrate));
|
|
|
|
|
controller_->ResetBweAndBitrates(-1, -1, -1);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-14 00:58:48 -07:00
|
|
|
TEST_F(CongestionControllerTest,
|
|
|
|
|
SignalNetworkStateAndQueueIsFullAndEstimateChange) {
|
|
|
|
|
// Send queue is full
|
|
|
|
|
EXPECT_CALL(*pacer_, ExpectedQueueTimeMs())
|
|
|
|
|
.WillRepeatedly(Return(PacedSender::kMaxQueueLengthMs + 1));
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(0, _, _));
|
|
|
|
|
controller_->Process();
|
|
|
|
|
|
|
|
|
|
// Queue is full and network is down. Expect no bitrate change.
|
|
|
|
|
controller_->SignalNetworkState(kNetworkDown);
|
|
|
|
|
controller_->Process();
|
|
|
|
|
|
|
|
|
|
// Queue is full but network is up. Expect no bitrate change.
|
|
|
|
|
controller_->SignalNetworkState(kNetworkUp);
|
|
|
|
|
controller_->Process();
|
|
|
|
|
|
|
|
|
|
// Receive new estimate but let the queue still be full.
|
|
|
|
|
EXPECT_CALL(*pacer_, SetEstimatedBitrate(kInitialBitrateBps * 2));
|
|
|
|
|
bandwidth_observer_->OnReceivedEstimatedBitrate(kInitialBitrateBps * 2);
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(25);
|
|
|
|
|
controller_->Process();
|
|
|
|
|
|
|
|
|
|
// Let the pacer not be full next time the controller checks.
|
|
|
|
|
EXPECT_CALL(*pacer_, ExpectedQueueTimeMs())
|
|
|
|
|
.WillOnce(Return(PacedSender::kMaxQueueLengthMs - 1));
|
|
|
|
|
EXPECT_CALL(observer_, OnNetworkChanged(kInitialBitrateBps * 2, _, _));
|
|
|
|
|
controller_->Process();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 06:01:13 -07:00
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|