OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 parameters.codecs.push_back(codec); | 207 parameters.codecs.push_back(codec); |
208 parameters.max_bandwidth_bps = max_bitrate; | 208 parameters.max_bandwidth_bps = max_bitrate; |
209 EXPECT_EQ(expected_result, channel_->SetSendParameters(parameters)); | 209 EXPECT_EQ(expected_result, channel_->SetSendParameters(parameters)); |
210 | 210 |
211 int channel_num = voe_.GetLastChannel(); | 211 int channel_num = voe_.GetLastChannel(); |
212 webrtc::CodecInst temp_codec; | 212 webrtc::CodecInst temp_codec; |
213 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec)); | 213 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec)); |
214 EXPECT_EQ(expected_bitrate, temp_codec.rate); | 214 EXPECT_EQ(expected_bitrate, temp_codec.rate); |
215 } | 215 } |
216 | 216 |
| 217 void SetAndExpectMaxBitrate(const cricket::AudioCodec& codec, |
| 218 int global_max, |
| 219 int stream_max, |
| 220 bool expected_result, |
| 221 int expected_codec_bitrate) { |
| 222 // Clear the bitrate limit from the previous test case. |
| 223 webrtc::RtpParameters rtp_parameters = channel_->GetRtpParameters(kSsrc1); |
| 224 EXPECT_EQ(1UL, rtp_parameters.encodings.size()); |
| 225 rtp_parameters.encodings[0].max_bitrate_bps = -1; |
| 226 EXPECT_TRUE(channel_->SetRtpParameters(kSsrc1, rtp_parameters)); |
| 227 |
| 228 // Attempt to set the requested bitrate limits. |
| 229 cricket::AudioSendParameters send_parameters; |
| 230 send_parameters.codecs.push_back(codec); |
| 231 send_parameters.max_bandwidth_bps = global_max; |
| 232 EXPECT_TRUE(channel_->SetSendParameters(send_parameters)); |
| 233 |
| 234 rtp_parameters.encodings[0].max_bitrate_bps = stream_max; |
| 235 EXPECT_EQ(expected_result, |
| 236 channel_->SetRtpParameters(kSsrc1, rtp_parameters)); |
| 237 |
| 238 // Verify that reading back the parameters gives results |
| 239 // consistent with the Set() result. |
| 240 webrtc::RtpParameters resulting_parameters = |
| 241 channel_->GetRtpParameters(kSsrc1); |
| 242 EXPECT_EQ(1UL, resulting_parameters.encodings.size()); |
| 243 EXPECT_EQ(expected_result ? stream_max : -1, |
| 244 resulting_parameters.encodings[0].max_bitrate_bps); |
| 245 |
| 246 // Verify that the codec settings have the expected bitrate. |
| 247 int channel_num = voe_.GetLastChannel(); |
| 248 webrtc::CodecInst temp_codec; |
| 249 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec)); |
| 250 EXPECT_EQ(expected_codec_bitrate, temp_codec.rate); |
| 251 } |
| 252 |
217 void TestSetSendRtpHeaderExtensions(const std::string& ext) { | 253 void TestSetSendRtpHeaderExtensions(const std::string& ext) { |
218 EXPECT_TRUE(SetupSendStream()); | 254 EXPECT_TRUE(SetupSendStream()); |
219 | 255 |
220 // Ensure extensions are off by default. | 256 // Ensure extensions are off by default. |
221 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc1).rtp.extensions.size()); | 257 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc1).rtp.extensions.size()); |
222 | 258 |
223 // Ensure unknown extensions won't cause an error. | 259 // Ensure unknown extensions won't cause an error. |
224 send_parameters_.extensions.push_back(cricket::RtpHeaderExtension( | 260 send_parameters_.extensions.push_back(cricket::RtpHeaderExtension( |
225 "urn:ietf:params:unknownextention", 1)); | 261 "urn:ietf:params:unknownextention", 1)); |
226 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); | 262 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); | 801 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
766 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); | 802 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); |
767 EXPECT_EQ(64000, codec.rate); | 803 EXPECT_EQ(64000, codec.rate); |
768 | 804 |
769 send_parameters_.max_bandwidth_bps = 128; | 805 send_parameters_.max_bandwidth_bps = 128; |
770 EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); | 806 EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); |
771 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); | 807 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); |
772 EXPECT_EQ(64000, codec.rate); | 808 EXPECT_EQ(64000, codec.rate); |
773 } | 809 } |
774 | 810 |
| 811 // Test that the per-stream bitrate limit and the global |
| 812 // bitrate limit both apply. |
| 813 TEST_F(WebRtcVoiceEngineTestFake, SetMaxBitratePerStream) { |
| 814 EXPECT_TRUE(SetupSendStream()); |
| 815 |
| 816 // opus, default bitrate == 64000. |
| 817 SetAndExpectMaxBitrate(kOpusCodec, 0, 0, true, 64000); |
| 818 SetAndExpectMaxBitrate(kOpusCodec, 48000, 0, true, 48000); |
| 819 SetAndExpectMaxBitrate(kOpusCodec, 48000, 64000, true, 48000); |
| 820 SetAndExpectMaxBitrate(kOpusCodec, 64000, 48000, true, 48000); |
| 821 |
| 822 // CBR codecs allow both maximums to exceed the bitrate. |
| 823 SetAndExpectMaxBitrate(kPcmuCodec, 0, 0, true, 64000); |
| 824 SetAndExpectMaxBitrate(kPcmuCodec, 64001, 0, true, 64000); |
| 825 SetAndExpectMaxBitrate(kPcmuCodec, 0, 64001, true, 64000); |
| 826 SetAndExpectMaxBitrate(kPcmuCodec, 64001, 64001, true, 64000); |
| 827 |
| 828 // CBR codecs don't allow per stream maximums to be too low. |
| 829 SetAndExpectMaxBitrate(kPcmuCodec, 0, 63999, false, 64000); |
| 830 SetAndExpectMaxBitrate(kPcmuCodec, 64001, 63999, false, 64000); |
| 831 } |
| 832 |
| 833 // Test that an attempt to set RtpParameters for a stream that does not exist |
| 834 // fails. |
| 835 TEST_F(WebRtcVoiceEngineTestFake, CannotSetMaxBitrateForNonexistentStream) { |
| 836 EXPECT_TRUE(SetupChannel()); |
| 837 webrtc::RtpParameters nonexistent_parameters = |
| 838 channel_->GetRtpParameters(kSsrc1); |
| 839 EXPECT_EQ(0, nonexistent_parameters.encodings.size()); |
| 840 |
| 841 nonexistent_parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
| 842 EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, nonexistent_parameters)); |
| 843 } |
| 844 |
| 845 TEST_F(WebRtcVoiceEngineTestFake, |
| 846 CannotSetRtpParametersWithIncorrectNumberOfEncodings) { |
| 847 // This test verifies that setting RtpParameters succeeds only if |
| 848 // the structure contains exactly one encoding. |
| 849 // TODO(skvlad): Update this test when we start supporting setting parameters |
| 850 // for each encoding individually. |
| 851 |
| 852 EXPECT_TRUE(SetupSendStream()); |
| 853 // Setting RtpParameters with no encoding is expected to fail. |
| 854 webrtc::RtpParameters parameters; |
| 855 EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, parameters)); |
| 856 // Setting RtpParameters with exactly one encoding should succeed. |
| 857 parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
| 858 EXPECT_TRUE(channel_->SetRtpParameters(kSsrc1, parameters)); |
| 859 // Two or more encodings should result in failure. |
| 860 parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
| 861 EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, parameters)); |
| 862 } |
| 863 |
775 // Test that we apply codecs properly. | 864 // Test that we apply codecs properly. |
776 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) { | 865 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) { |
777 EXPECT_TRUE(SetupSendStream()); | 866 EXPECT_TRUE(SetupSendStream()); |
778 cricket::AudioSendParameters parameters; | 867 cricket::AudioSendParameters parameters; |
779 parameters.codecs.push_back(kIsacCodec); | 868 parameters.codecs.push_back(kIsacCodec); |
780 parameters.codecs.push_back(kPcmuCodec); | 869 parameters.codecs.push_back(kPcmuCodec); |
781 parameters.codecs.push_back(kRedCodec); | 870 parameters.codecs.push_back(kRedCodec); |
782 parameters.codecs[0].id = 96; | 871 parameters.codecs[0].id = 96; |
783 parameters.codecs[0].bitrate = 48000; | 872 parameters.codecs[0].bitrate = 48000; |
784 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 873 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
(...skipping 2560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3345 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { | 3434 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { |
3346 cricket::WebRtcVoiceEngine engine(nullptr); | 3435 cricket::WebRtcVoiceEngine engine(nullptr); |
3347 std::unique_ptr<webrtc::Call> call( | 3436 std::unique_ptr<webrtc::Call> call( |
3348 webrtc::Call::Create(webrtc::Call::Config())); | 3437 webrtc::Call::Create(webrtc::Call::Config())); |
3349 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), | 3438 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), |
3350 cricket::AudioOptions(), call.get()); | 3439 cricket::AudioOptions(), call.get()); |
3351 cricket::AudioRecvParameters parameters; | 3440 cricket::AudioRecvParameters parameters; |
3352 parameters.codecs = engine.codecs(); | 3441 parameters.codecs = engine.codecs(); |
3353 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3442 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3354 } | 3443 } |
OLD | NEW |