Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: webrtc/call/call_unittest.cc

Issue 2838233002: Add PeerConnectionInterface::UpdateCallBitrate with call tests. (Closed)
Patch Set: Only update start from SetBitrateConfig when it changes; some comments and logging. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/call/call_unittest.cc
diff --git a/webrtc/call/call_unittest.cc b/webrtc/call/call_unittest.cc
index 564f6bd0323e014771266f9ec432b099758ef18b..8a304d8e9667729876481e3d62ec0ebf4de2c823 100644
--- a/webrtc/call/call_unittest.cc
+++ b/webrtc/call/call_unittest.cc
@@ -309,28 +309,239 @@ TEST(CallTest, MultipleFlexfecReceiveStreamsProtectingSingleVideoStream) {
}
}
-// TODO(zstein): This is just a motivating example for
-// MockSendSideCongestionController. It should be deleted once we have more
-// meaningful tests.
-TEST(CallTest, MockSendSideCongestionControllerExample) {
- RtcEventLogNullImpl event_log;
- Call::Config config(&event_log);
-
- SimulatedClock clock(123456);
- PacketRouter packet_router;
- testing::NiceMock<test::MockSendSideCongestionController> mock_cc(
- &clock, &event_log, &packet_router);
- auto transport_send =
- rtc::MakeUnique<FakeRtpTransportControllerSend>(&mock_cc);
- std::unique_ptr<Call> call(Call::Create(config, std::move(transport_send)));
-
- Call::Config::BitrateConfig bitrate_config;
- bitrate_config.min_bitrate_bps = 1;
- bitrate_config.start_bitrate_bps = 2;
- bitrate_config.max_bitrate_bps = 3;
-
- EXPECT_CALL(mock_cc, SetBweBitrates(1, 2, 3));
- call->SetBitrateConfig(bitrate_config);
+class CallBitrateTest : public testing::Test {
+ public:
+ void SetUp() {
+ Clock* clock = Clock::GetRealTimeClock();
+ mock_cc_ = rtc::MakeUnique<
+ testing::NiceMock<test::MockSendSideCongestionController>>(
+ clock, &event_log_, &packet_router_);
+ }
+
+ void CreateCall() {
+ Call::Config config(&event_log_);
+ CreateCall(config);
+ }
+
+ void CreateCall(const Call::Config& config) {
+ std::unique_ptr<RtpTransportControllerSendInterface> fake_controller =
+ rtc::MakeUnique<FakeRtpTransportControllerSend>(&packet_router_,
+ mock_cc_.get());
+ call_.reset(Call::Create(config, std::move(fake_controller)));
+ }
+
+ std::unique_ptr<testing::NiceMock<test::MockSendSideCongestionController>>
+ mock_cc_;
+ std::unique_ptr<Call> call_;
+
+ webrtc::RtcEventLogNullImpl event_log_;
+
+ private:
+ PacketRouter packet_router_;
+};
+
+TEST_F(CallBitrateTest, BiggerMaskMinUsed) {
+ CreateCall();
+ Call::Config::BitrateConfigMask mask;
+ mask.min_bitrate_bps = rtc::Optional<int>(1234);
+
+ EXPECT_CALL(*mock_cc_,
+ SetBweBitrates(*mask.min_bitrate_bps, testing::_, testing::_));
+ call_->SetBitrateConfigMask(mask);
+}
+
+TEST_F(CallBitrateTest, BiggerConfigMinUsed) {
+ CreateCall();
+
+ Call::Config::BitrateConfigMask mask;
+ mask.min_bitrate_bps = rtc::Optional<int>(1000);
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(1000, testing::_, testing::_));
+ call_->SetBitrateConfigMask(mask);
+
+ Call::Config::BitrateConfig config;
+ config.min_bitrate_bps = 1234;
+
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(1234, testing::_, testing::_));
+ call_->SetBitrateConfig(config);
+}
+
+// The last call to set start should be used.
+TEST_F(CallBitrateTest, LatestStartMaskPreferred) {
+ CreateCall();
+ Call::Config::BitrateConfigMask mask;
+ mask.start_bitrate_bps = rtc::Optional<int>(1300);
+
+ EXPECT_CALL(*mock_cc_,
+ SetBweBitrates(testing::_, *mask.start_bitrate_bps, testing::_));
+ call_->SetBitrateConfigMask(mask);
+
+ Call::Config::BitrateConfig config;
+ config.start_bitrate_bps = 1200;
+
+ EXPECT_CALL(*mock_cc_,
+ SetBweBitrates(testing::_, config.start_bitrate_bps, testing::_));
+ call_->SetBitrateConfig(config);
+}
+
+TEST_F(CallBitrateTest, SmallerMaskMaxUsed) {
+ Call::Config config(&event_log_);
+ config.bitrate_config.max_bitrate_bps =
+ config.bitrate_config.start_bitrate_bps + 2000;
+ CreateCall(config);
+
+ Call::Config::BitrateConfigMask mask;
+ mask.max_bitrate_bps =
+ rtc::Optional<int>(config.bitrate_config.start_bitrate_bps + 1000);
+
+ EXPECT_CALL(*mock_cc_,
+ SetBweBitrates(testing::_, testing::_, *mask.max_bitrate_bps));
+ call_->SetBitrateConfigMask(mask);
+}
+
+TEST_F(CallBitrateTest, SmallerConfigMaxUsed) {
+ Call::Config config(&event_log_);
+ config.bitrate_config.max_bitrate_bps =
+ config.bitrate_config.start_bitrate_bps + 1000;
+ CreateCall(config);
+
+ Call::Config::BitrateConfigMask mask;
+ mask.max_bitrate_bps =
+ rtc::Optional<int>(config.bitrate_config.start_bitrate_bps + 2000);
+
+ // Expect no calls because nothing changes
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(testing::_, testing::_, testing::_))
+ .Times(0);
+ call_->SetBitrateConfigMask(mask);
+}
+
+TEST_F(CallBitrateTest, MaskStartLessThanConfigMinClamped) {
+ Call::Config config(&event_log_);
+ config.bitrate_config.min_bitrate_bps = 2000;
+ CreateCall(config);
+
+ Call::Config::BitrateConfigMask mask;
+ mask.start_bitrate_bps = rtc::Optional<int>(1000);
+
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(2000, 2000, testing::_));
+ call_->SetBitrateConfigMask(mask);
+}
+
+TEST_F(CallBitrateTest, MaskStartGreaterThanConfigMaxClamped) {
+ Call::Config config(&event_log_);
+ config.bitrate_config.start_bitrate_bps = 2000;
+ CreateCall(config);
+
+ Call::Config::BitrateConfigMask mask;
+ mask.max_bitrate_bps = rtc::Optional<int>(1000);
+
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(testing::_, -1, 1000));
+ call_->SetBitrateConfigMask(mask);
+}
+
+TEST_F(CallBitrateTest, MaskMinGreaterThanConfigMaxClamped) {
+ Call::Config config(&event_log_);
+ config.bitrate_config.min_bitrate_bps = 2000;
+ CreateCall(config);
+
+ Call::Config::BitrateConfigMask mask;
+ mask.max_bitrate_bps = rtc::Optional<int>(1000);
+
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(1000, testing::_, 1000));
+ call_->SetBitrateConfigMask(mask);
+}
+
+TEST_F(CallBitrateTest, SettingMaskStartForcesUpdate) {
+ CreateCall();
+
+ Call::Config::BitrateConfigMask mask;
+ mask.start_bitrate_bps = rtc::Optional<int>(1000);
+
+ // SetBweBitrates should be called twice with the same params since
+ // start_bitrate_bps is set.
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(testing::_, 1000, testing::_)).Times(2);
+ call_->SetBitrateConfigMask(mask);
+ call_->SetBitrateConfigMask(mask);
+}
+
+TEST_F(CallBitrateTest,
+ SetBitrateConfigWithNoChangesDoesNotCallSetBweBitrates) {
+ CreateCall();
+
+ Call::Config::BitrateConfig config1;
+ config1.min_bitrate_bps = 0;
+ config1.start_bitrate_bps = 1000;
+ config1.max_bitrate_bps = -1;
+
+ Call::Config::BitrateConfig config2;
+ config2.min_bitrate_bps = 0;
+ config2.start_bitrate_bps = -1;
+ config2.max_bitrate_bps = -1;
+
+ // The second call should not call SetBweBitrates because it doesn't
+ // change any values.
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(0, 1000, -1));
+ call_->SetBitrateConfig(config1);
+ call_->SetBitrateConfig(config2);
+}
+
+// If SetBitrateConfig changes the max, but not the effective max,
+// SetBweBitrates shouldn't be called, to avoid unnecessary encoder
+// reconfigurations.
+TEST_F(CallBitrateTest, SetBweBitratesNotCalledWhenEffectiveMaxUnchanged) {
+ CreateCall();
+
+ Call::Config::BitrateConfig config;
+ config.min_bitrate_bps = 0;
+ config.start_bitrate_bps = -1;
+ config.max_bitrate_bps = 2000;
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(0, -1, 2000));
+ call_->SetBitrateConfig(config);
+
+ // Reduce effective max to 1000 with the mask.
+ Call::Config::BitrateConfigMask mask;
+ mask.max_bitrate_bps = rtc::Optional<int>(1000);
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(0, -1, 1000));
+ call_->SetBitrateConfigMask(mask);
+
+ // This leaves the effective max unchanged, so SetBweBitrates shouldn't be
+ // called again.
+ config.max_bitrate_bps = 1000;
+ call_->SetBitrateConfig(config);
+}
+
+// When the "start bitrate" mask is removed, SetBweBitrates shouldn't be called
+// again, since nothing's changing.
+TEST_F(CallBitrateTest, SetBweBitratesNotCalledWhenStartMaskRemoved) {
+ CreateCall();
+
+ Call::Config::BitrateConfigMask mask;
+ mask.start_bitrate_bps = rtc::Optional<int>(1000);
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(0, 1000, -1));
+ call_->SetBitrateConfigMask(mask);
+
+ mask.start_bitrate_bps.reset();
+ call_->SetBitrateConfigMask(mask);
+}
+
+// Test that if SetBitrateConfig is called after SetBitrateConfigMask applies a
+// "start" value, the SetBitrateConfig call won't apply that start value a
+// second time.
+TEST_F(CallBitrateTest, SetBitrateConfigAfterSetBitrateConfigMaskWithStart) {
+ CreateCall();
+
+ Call::Config::BitrateConfigMask mask;
+ mask.start_bitrate_bps = rtc::Optional<int>(1000);
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(0, 1000, -1));
+ call_->SetBitrateConfigMask(mask);
+
+ Call::Config::BitrateConfig config;
+ config.min_bitrate_bps = 0;
+ config.start_bitrate_bps = -1;
+ config.max_bitrate_bps = 5000;
+ // The start value isn't changing, so SetBweBitrates should be called with
+ // -1.
+ EXPECT_CALL(*mock_cc_, SetBweBitrates(0, -1, 5000));
+ call_->SetBitrateConfig(config);
}
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698