| Index: webrtc/media/engine/webrtcvoiceengine_unittest.cc
|
| diff --git a/webrtc/media/engine/webrtcvoiceengine_unittest.cc b/webrtc/media/engine/webrtcvoiceengine_unittest.cc
|
| index 78b6a207903e86cb2c64b088de5ed89412b2f184..d69e6d171f767f8fdbfca7cb79b3de09697a845f 100644
|
| --- a/webrtc/media/engine/webrtcvoiceengine_unittest.cc
|
| +++ b/webrtc/media/engine/webrtcvoiceengine_unittest.cc
|
| @@ -214,6 +214,42 @@ class WebRtcVoiceEngineTestFake : public testing::Test {
|
| EXPECT_EQ(expected_bitrate, temp_codec.rate);
|
| }
|
|
|
| + void SetAndExpectMaxBitrate(const cricket::AudioCodec& codec,
|
| + int global_max,
|
| + int stream_max,
|
| + bool expected_result,
|
| + int expected_codec_bitrate) {
|
| + // Clear the bitrate limit from the previous test case.
|
| + webrtc::RtpParameters 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 = global_max;
|
| + EXPECT_TRUE(channel_->SetSendParameters(send_parameters));
|
| +
|
| + rtp_parameters.encodings[0].max_bitrate_bps = stream_max;
|
| + EXPECT_EQ(expected_result,
|
| + channel_->SetRtpParameters(kSsrc1, rtp_parameters));
|
| +
|
| + // Verify that reading back the parameters gives results
|
| + // consistent with the Set() result.
|
| + webrtc::RtpParameters resulting_parameters =
|
| + channel_->GetRtpParameters(kSsrc1);
|
| + EXPECT_EQ(1UL, resulting_parameters.encodings.size());
|
| + EXPECT_EQ(expected_result ? stream_max : -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_codec_bitrate, temp_codec.rate);
|
| + }
|
| +
|
| void TestSetSendRtpHeaderExtensions(const std::string& ext) {
|
| EXPECT_TRUE(SetupSendStream());
|
|
|
| @@ -772,6 +808,59 @@ 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(SetupSendStream());
|
| +
|
| + // opus, default bitrate == 64000.
|
| + SetAndExpectMaxBitrate(kOpusCodec, 0, 0, true, 64000);
|
| + SetAndExpectMaxBitrate(kOpusCodec, 48000, 0, true, 48000);
|
| + SetAndExpectMaxBitrate(kOpusCodec, 48000, 64000, true, 48000);
|
| + SetAndExpectMaxBitrate(kOpusCodec, 64000, 48000, true, 48000);
|
| +
|
| + // CBR codecs allow both maximums to exceed the bitrate.
|
| + SetAndExpectMaxBitrate(kPcmuCodec, 0, 0, true, 64000);
|
| + SetAndExpectMaxBitrate(kPcmuCodec, 64001, 0, true, 64000);
|
| + SetAndExpectMaxBitrate(kPcmuCodec, 0, 64001, true, 64000);
|
| + SetAndExpectMaxBitrate(kPcmuCodec, 64001, 64001, true, 64000);
|
| +
|
| + // CBR codecs don't allow per stream maximums to be too low.
|
| + SetAndExpectMaxBitrate(kPcmuCodec, 0, 63999, false, 64000);
|
| + SetAndExpectMaxBitrate(kPcmuCodec, 64001, 63999, false, 64000);
|
| +}
|
| +
|
| +// Test that an attempt to set RtpParameters for a stream that does not exist
|
| +// fails.
|
| +TEST_F(WebRtcVoiceEngineTestFake, CannotSetMaxBitrateForNonexistentStream) {
|
| + EXPECT_TRUE(SetupChannel());
|
| + webrtc::RtpParameters nonexistent_parameters =
|
| + channel_->GetRtpParameters(kSsrc1);
|
| + EXPECT_EQ(0, nonexistent_parameters.encodings.size());
|
| +
|
| + nonexistent_parameters.encodings.push_back(webrtc::RtpEncodingParameters());
|
| + EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, nonexistent_parameters));
|
| +}
|
| +
|
| +TEST_F(WebRtcVoiceEngineTestFake,
|
| + CannotSetRtpParametersWithIncorrectNumberOfEncodings) {
|
| + // This test verifies that setting RtpParameters succeeds only if
|
| + // the structure contains exactly one encoding.
|
| + // TODO(skvlad): Update this test when we start supporting setting parameters
|
| + // for each encoding individually.
|
| +
|
| + EXPECT_TRUE(SetupSendStream());
|
| + // Setting RtpParameters with no encoding is expected to fail.
|
| + webrtc::RtpParameters parameters;
|
| + EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, parameters));
|
| + // Setting RtpParameters with exactly one encoding should succeed.
|
| + parameters.encodings.push_back(webrtc::RtpEncodingParameters());
|
| + EXPECT_TRUE(channel_->SetRtpParameters(kSsrc1, parameters));
|
| + // Two or more encodings should result in failure.
|
| + parameters.encodings.push_back(webrtc::RtpEncodingParameters());
|
| + EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, parameters));
|
| +}
|
| +
|
| // Test that we apply codecs properly.
|
| TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) {
|
| EXPECT_TRUE(SetupSendStream());
|
|
|