Index: webrtc/media/engine/webrtcvoiceengine_unittest.cc |
diff --git a/webrtc/media/engine/webrtcvoiceengine_unittest.cc b/webrtc/media/engine/webrtcvoiceengine_unittest.cc |
index 1e23d381cd1ca7298c3ed9d21da840910f418d6f..610b7dbbbe1ea020ff2dc7e94d5eafb0907b0659 100644 |
--- a/webrtc/media/engine/webrtcvoiceengine_unittest.cc |
+++ b/webrtc/media/engine/webrtcvoiceengine_unittest.cc |
@@ -200,6 +200,43 @@ class WebRtcVoiceEngineTestFake : public testing::Test { |
EXPECT_EQ(expected_bitrate, temp_codec.rate); |
} |
+ void TestSendStreamBitrate(const cricket::AudioCodec& codec, |
+ int max_bitrate_global, |
+ int max_bitrate_ssrc, |
+ bool expected_result, |
+ int expected_bitrate) { |
+ // clear the bitrate limit from the previous test case |
+ webrtc::RTCRtpParameters rtp_parameters = |
+ channel_->GetRtpParameters(kSsrc1); |
+ EXPECT_EQ(1UL, rtp_parameters.encodings.size()); |
+ rtp_parameters.encodings[0].max_bitrate_bps = -1; |
+ EXPECT_TRUE(channel_->SetRtpParameters(kSsrc1, rtp_parameters)); |
+ |
+ // Attempt to set the requested bitrate limits |
+ cricket::AudioSendParameters send_parameters; |
+ send_parameters.codecs.push_back(codec); |
+ send_parameters.max_bandwidth_bps = max_bitrate_global; |
+ EXPECT_TRUE(channel_->SetSendParameters(send_parameters)); |
+ |
+ rtp_parameters.encodings[0].max_bitrate_bps = max_bitrate_ssrc; |
+ EXPECT_EQ(expected_result, |
+ channel_->SetRtpParameters(kSsrc1, rtp_parameters)); |
+ |
+ // Verify that reading back the parameters gives results |
+ // consistent with the Set() result |
+ webrtc::RTCRtpParameters resulting_parameters = |
+ channel_->GetRtpParameters(kSsrc1); |
+ EXPECT_EQ(1UL, resulting_parameters.encodings.size()); |
+ EXPECT_EQ(expected_result ? max_bitrate_ssrc : -1, |
+ resulting_parameters.encodings[0].max_bitrate_bps); |
+ |
+ // Verify that the codec settings have the expected bitrate |
+ int channel_num = voe_.GetLastChannel(); |
+ webrtc::CodecInst temp_codec; |
+ EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec)); |
+ EXPECT_EQ(expected_bitrate, temp_codec.rate); |
+ } |
+ |
void TestSetSendRtpHeaderExtensions(const std::string& ext) { |
EXPECT_TRUE(SetupEngineWithSendStream()); |
@@ -769,6 +806,53 @@ TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) { |
EXPECT_EQ(64000, codec.rate); |
} |
+// Test that the per-stream bitrate limit and the global |
+// bitrate limit both apply |
+TEST_F(WebRtcVoiceEngineTestFake, SetMaxBitratePerStream) { |
+ EXPECT_TRUE(SetupEngineWithSendStream()); |
+ |
+ // opus, default bitrate == 64000. |
+ TestSendStreamBitrate(kOpusCodec, 0, 0, true, 64000); |
+ TestSendStreamBitrate(kOpusCodec, 48000, 0, true, 48000); |
+ TestSendStreamBitrate(kOpusCodec, 48000, 64000, true, 48000); |
+ TestSendStreamBitrate(kOpusCodec, 64000, 48000, true, 48000); |
+ |
+ // CBR codecs allow both maximums to exceed the bitrate |
+ TestSendStreamBitrate(kPcmuCodec, 0, 0, true, 64000); |
+ TestSendStreamBitrate(kPcmuCodec, 64001, 0, true, 64000); |
+ TestSendStreamBitrate(kPcmuCodec, 0, 64001, true, 64000); |
+ TestSendStreamBitrate(kPcmuCodec, 64001, 64001, true, 64000); |
+ |
+ // CBR codecs don't allow per stream maximums to be too low |
+ TestSendStreamBitrate(kPcmuCodec, 0, 63999, false, 64000); |
+ TestSendStreamBitrate(kPcmuCodec, 64001, 63999, false, 64000); |
+} |
+ |
+TEST_F(WebRtcVoiceEngineTestFake, CannotSetMaxBitrateForNonexistentStream) { |
+ EXPECT_TRUE(SetupEngine()); |
+ webrtc::RTCRtpParameters nonexistent_parameters = |
+ channel_->GetRtpParameters(kSsrc1); |
+ EXPECT_EQ(0, nonexistent_parameters.encodings.size()); |
+ |
+ nonexistent_parameters.encodings.push_back( |
+ webrtc::RTCRtpEncodingParameters()); |
+ EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, nonexistent_parameters)); |
+} |
+ |
+TEST_F(WebRtcVoiceEngineTestFake, |
+ CannotSetRtpParametersWithIncorrectNumberOfEncodings) { |
Taylor Brandstetter
2016/03/12 01:57:06
If you add a TODO comment for the other "Incorrect
skvlad
2016/03/15 21:18:18
Done.
|
+ EXPECT_TRUE(SetupEngineWithSendStream()); |
+ // no encodings - should fail |
+ webrtc::RTCRtpParameters parameters; |
+ EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, parameters)); |
+ // one encoding - expected to succeed |
+ parameters.encodings.push_back(webrtc::RTCRtpEncodingParameters()); |
+ EXPECT_TRUE(channel_->SetRtpParameters(kSsrc1, parameters)); |
+ // two encodings - too many |
+ parameters.encodings.push_back(webrtc::RTCRtpEncodingParameters()); |
+ EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, parameters)); |
+} |
+ |
// Test that we apply codecs properly. |
TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) { |
EXPECT_TRUE(SetupEngineWithSendStream()); |