Index: webrtc/media/engine/webrtcvideoengine2_unittest.cc |
diff --git a/webrtc/media/engine/webrtcvideoengine2_unittest.cc b/webrtc/media/engine/webrtcvideoengine2_unittest.cc |
index e8800ba66f3cc7e171b008765247b0b624a74365..20feef65f541b4a8347c9c448d4427376c6b055f 100644 |
--- a/webrtc/media/engine/webrtcvideoengine2_unittest.cc |
+++ b/webrtc/media/engine/webrtcvideoengine2_unittest.cc |
@@ -915,12 +915,13 @@ class WebRtcVideoChannel2Test : public WebRtcVideoEngine2Test { |
return streams[streams.size() - 1]; |
} |
- void SetSendCodecsShouldWorkForBitrates(const char* min_bitrate_kbps, |
- int expected_min_bitrate_bps, |
- const char* start_bitrate_kbps, |
- int expected_start_bitrate_bps, |
- const char* max_bitrate_kbps, |
- int expected_max_bitrate_bps) { |
+ void SetSendCodecsShouldWorkForBitrates( |
+ const char* min_bitrate_kbps, |
+ int expected_min_bitrate_bps, |
+ const char* start_bitrate_kbps, |
+ int expected_start_bitrate_bps, |
+ const char* max_bitrate_kbps, |
+ rtc::Optional<int> expected_max_bitrate_bps) { |
auto& codecs = send_parameters_.codecs; |
codecs.clear(); |
codecs.push_back(kVp8Codec); |
@@ -1090,11 +1091,11 @@ class WebRtcVideoChannel2Test : public WebRtcVideoEngine2Test { |
} |
void SetAndExpectMaxBitrate(cricket::FakeVideoCapturer& capturer, |
- int global_max, |
- int stream_max, |
+ rtc::Optional<int> global_max, |
+ rtc::Optional<int> stream_max, |
int expected_encoder_bitrate) { |
VideoSendParameters limited_send_params = send_parameters_; |
- limited_send_params.max_bandwidth_bps = global_max; |
+ limited_send_params.max_bitrate_bps = global_max; |
EXPECT_TRUE(channel_->SetSendParameters(limited_send_params)); |
webrtc::RtpParameters parameters = channel_->GetRtpParameters(last_ssrc_); |
EXPECT_EQ(1UL, parameters.encodings.size()); |
@@ -2257,11 +2258,12 @@ TEST_F(WebRtcVideoChannel2Test, SetSendCodecsChangesExistingStreams) { |
TEST_F(WebRtcVideoChannel2Test, SetSendCodecsWithBitrates) { |
SetSendCodecsShouldWorkForBitrates("100", 100000, "150", 150000, "200", |
- 200000); |
+ rtc::Optional<int>(200000)); |
} |
TEST_F(WebRtcVideoChannel2Test, SetSendCodecsWithHighMaxBitrate) { |
- SetSendCodecsShouldWorkForBitrates("", 0, "", -1, "10000", 10000000); |
+ SetSendCodecsShouldWorkForBitrates("", 0, "", -1, "10000", |
+ rtc::Optional<int>(10000000)); |
std::vector<webrtc::VideoStream> streams = AddSendStream()->GetVideoStreams(); |
ASSERT_EQ(1u, streams.size()); |
EXPECT_EQ(10000000, streams[0].max_bitrate_bps); |
@@ -2269,12 +2271,12 @@ TEST_F(WebRtcVideoChannel2Test, SetSendCodecsWithHighMaxBitrate) { |
TEST_F(WebRtcVideoChannel2Test, |
SetSendCodecsWithoutBitratesUsesCorrectDefaults) { |
- SetSendCodecsShouldWorkForBitrates( |
- "", 0, "", -1, "", -1); |
+ SetSendCodecsShouldWorkForBitrates("", 0, "", -1, "", rtc::Optional<int>()); |
} |
TEST_F(WebRtcVideoChannel2Test, SetSendCodecsCapsMinAndStartBitrate) { |
- SetSendCodecsShouldWorkForBitrates("-1", 0, "-100", -1, "", -1); |
+ SetSendCodecsShouldWorkForBitrates("-1", 0, "-100", -1, "", |
+ rtc::Optional<int>()); |
} |
TEST_F(WebRtcVideoChannel2Test, SetSendCodecsRejectsMaxLessThanMinBitrate) { |
@@ -2286,24 +2288,27 @@ TEST_F(WebRtcVideoChannel2Test, SetSendCodecsRejectsMaxLessThanMinBitrate) { |
TEST_F(WebRtcVideoChannel2Test, |
SetMaxSendBandwidthShouldPreserveOtherBitrates) { |
SetSendCodecsShouldWorkForBitrates("100", 100000, "150", 150000, "200", |
- 200000); |
- send_parameters_.max_bandwidth_bps = 300000; |
+ rtc::Optional<int>(200000)); |
+ send_parameters_.max_bitrate_bps = rtc::Optional<int>(300000); |
EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
EXPECT_EQ(100000, fake_call_->GetConfig().bitrate_config.min_bitrate_bps) |
<< "Setting max bitrate should keep previous min bitrate."; |
EXPECT_EQ(-1, fake_call_->GetConfig().bitrate_config.start_bitrate_bps) |
<< "Setting max bitrate should not reset start bitrate."; |
- EXPECT_EQ(300000, fake_call_->GetConfig().bitrate_config.max_bitrate_bps); |
+ EXPECT_EQ(rtc::Optional<int>(300000), |
+ fake_call_->GetConfig().bitrate_config.max_bitrate_bps); |
} |
TEST_F(WebRtcVideoChannel2Test, SetMaxSendBandwidthShouldBeRemovable) { |
- send_parameters_.max_bandwidth_bps = 300000; |
+ send_parameters_.max_bitrate_bps = rtc::Optional<int>(300000); |
EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
- EXPECT_EQ(300000, fake_call_->GetConfig().bitrate_config.max_bitrate_bps); |
- // <= 0 means disable (infinite) max bitrate. |
- send_parameters_.max_bandwidth_bps = 0; |
+ EXPECT_EQ(rtc::Optional<int>(300000), |
+ fake_call_->GetConfig().bitrate_config.max_bitrate_bps); |
+ // <not set> means disable (infinite) max bitrate. |
+ send_parameters_.max_bitrate_bps = rtc::Optional<int>(); |
EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
- EXPECT_EQ(-1, fake_call_->GetConfig().bitrate_config.max_bitrate_bps) |
+ EXPECT_EQ(rtc::Optional<int>(), |
+ fake_call_->GetConfig().bitrate_config.max_bitrate_bps) |
<< "Setting zero max bitrate did not reset start bitrate."; |
} |
@@ -2324,7 +2329,7 @@ TEST_F(WebRtcVideoChannel2Test, SetMaxSendBitrateCanIncreaseSenderBitrate) { |
int initial_max_bitrate_bps = streams[0].max_bitrate_bps; |
EXPECT_GT(initial_max_bitrate_bps, 0); |
- parameters.max_bandwidth_bps = initial_max_bitrate_bps * 2; |
+ parameters.max_bitrate_bps = rtc::Optional<int>(initial_max_bitrate_bps * 2); |
EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
// Insert a frame to update the encoder config. |
EXPECT_TRUE(capturer.CaptureFrame()); |
@@ -2356,7 +2361,7 @@ TEST_F(WebRtcVideoChannel2Test, |
int initial_max_bitrate_bps = GetTotalMaxBitrateBps(streams); |
EXPECT_GT(initial_max_bitrate_bps, 0); |
- parameters.max_bandwidth_bps = initial_max_bitrate_bps * 2; |
+ parameters.max_bitrate_bps = rtc::Optional<int>(initial_max_bitrate_bps * 2); |
EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
// Insert a frame to update the encoder config. |
EXPECT_TRUE(capturer.CaptureFrame()); |
@@ -3220,7 +3225,7 @@ TEST_F(WebRtcVideoChannel2Test, RedRtxPacketDoesntCreateUnsignalledStream) { |
TestReceiveUnsignalledSsrcPacket(kRedRtxPayloadType, false); |
} |
-TEST_F(WebRtcVideoChannel2Test, CanSentMaxBitrateForExistingStream) { |
+TEST_F(WebRtcVideoChannel2Test, CanSetMaxBitrateForExistingStream) { |
AddSendStream(); |
cricket::FakeVideoCapturer capturer; |
@@ -3235,23 +3240,31 @@ TEST_F(WebRtcVideoChannel2Test, CanSentMaxBitrateForExistingStream) { |
int default_encoder_bitrate = GetMaxEncoderBitrate(capturer); |
EXPECT_TRUE(default_encoder_bitrate > 1000); |
- // TODO(skvlad): Resolve the inconsistency between the interpretation |
- // of the global bitrate limit for audio and video: |
- // - Audio: max_bandwidth_bps = 0 - fail the operation, |
- // max_bandwidth_bps = -1 - remove the bandwidth limit |
- // - Video: max_bandwidth_bps = 0 - remove the bandwidth limit, |
- // max_bandwidth_bps = -1 - do not change the previously set |
- // limit. |
- |
- SetAndExpectMaxBitrate(capturer, 1000, 0, 1000); |
- SetAndExpectMaxBitrate(capturer, 1000, 800, 800); |
- SetAndExpectMaxBitrate(capturer, 600, 800, 600); |
- SetAndExpectMaxBitrate(capturer, 0, 800, 800); |
- SetAndExpectMaxBitrate(capturer, 0, 0, default_encoder_bitrate); |
+ SetAndExpectMaxBitrate(capturer, rtc::Optional<int>(1000), |
+ rtc::Optional<int>(), 1000); |
+ SetAndExpectMaxBitrate(capturer, rtc::Optional<int>(1000), |
+ rtc::Optional<int>(800), 800); |
+ SetAndExpectMaxBitrate(capturer, rtc::Optional<int>(600), |
+ rtc::Optional<int>(800), 600); |
+ SetAndExpectMaxBitrate(capturer, rtc::Optional<int>(), |
+ rtc::Optional<int>(800), 800); |
+ SetAndExpectMaxBitrate(capturer, rtc::Optional<int>(), rtc::Optional<int>(), |
+ default_encoder_bitrate); |
EXPECT_TRUE(channel_->SetCapturer(last_ssrc_, NULL)); |
} |
+TEST_F(WebRtcVideoChannel2Test, CannotSetNegativeOrZeroMaxBitrate) { |
+ AddSendStream(); |
+ webrtc::RtpParameters bad_parameters; |
+ bad_parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
+ |
+ bad_parameters.encodings[0].max_bitrate_bps = rtc::Optional<int>(0); |
+ EXPECT_FALSE(channel_->SetRtpParameters(last_ssrc_, bad_parameters)); |
+ bad_parameters.encodings[0].max_bitrate_bps = rtc::Optional<int>(-1); |
+ EXPECT_FALSE(channel_->SetRtpParameters(last_ssrc_, bad_parameters)); |
+} |
+ |
TEST_F(WebRtcVideoChannel2Test, CannotSetMaxBitrateForNonexistentStream) { |
webrtc::RtpParameters nonexistent_parameters = |
channel_->GetRtpParameters(last_ssrc_); |
@@ -3395,7 +3408,8 @@ class WebRtcVideoChannel2SimulcastTest : public testing::Test { |
ASSERT_EQ(expected_num_streams, video_streams.size()); |
std::vector<webrtc::VideoStream> expected_streams = GetSimulcastConfig( |
- num_configured_streams, codec.width, codec.height, 0, kDefaultQpMax, |
+ num_configured_streams, codec.width, codec.height, rtc::Optional<int>(), |
+ kDefaultQpMax, |
codec.framerate != 0 ? codec.framerate : kDefaultFramerate); |
ASSERT_EQ(expected_streams.size(), video_streams.size()); |