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 // Sets the per-stream maximum bitrate limit for the specified SSRC. |
| 218 bool SetMaxBitrateForStream(int32_t ssrc, int bitrate) { |
| 219 webrtc::RtpParameters parameters = channel_->GetRtpParameters(ssrc); |
| 220 EXPECT_EQ(1UL, parameters.encodings.size()); |
| 221 |
| 222 parameters.encodings[0].max_bitrate_bps = bitrate; |
| 223 return channel_->SetRtpParameters(ssrc, parameters); |
| 224 } |
| 225 |
| 226 bool SetGlobalMaxBitrate(const cricket::AudioCodec& codec, int bitrate) { |
| 227 cricket::AudioSendParameters send_parameters; |
| 228 send_parameters.codecs.push_back(codec); |
| 229 send_parameters.max_bandwidth_bps = bitrate; |
| 230 return channel_->SetSendParameters(send_parameters); |
| 231 } |
| 232 |
| 233 int GetCodecBitrate(int32_t ssrc) { |
| 234 cricket::WebRtcVoiceMediaChannel* media_channel = |
| 235 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); |
| 236 int channel = media_channel->GetSendChannelId(ssrc); |
| 237 EXPECT_NE(-1, channel); |
| 238 webrtc::CodecInst codec; |
| 239 EXPECT_FALSE(voe_.GetSendCodec(channel, codec)); |
| 240 return codec.rate; |
| 241 } |
| 242 |
| 243 void SetAndExpectMaxBitrate(const cricket::AudioCodec& codec, |
| 244 int global_max, |
| 245 int stream_max, |
| 246 bool expected_result, |
| 247 int expected_codec_bitrate) { |
| 248 // Clear the bitrate limit from the previous test case. |
| 249 EXPECT_TRUE(SetMaxBitrateForStream(kSsrc1, -1)); |
| 250 |
| 251 // Attempt to set the requested bitrate limits. |
| 252 EXPECT_TRUE(SetGlobalMaxBitrate(codec, global_max)); |
| 253 EXPECT_EQ(expected_result, SetMaxBitrateForStream(kSsrc1, stream_max)); |
| 254 |
| 255 // Verify that reading back the parameters gives results |
| 256 // consistent with the Set() result. |
| 257 webrtc::RtpParameters resulting_parameters = |
| 258 channel_->GetRtpParameters(kSsrc1); |
| 259 EXPECT_EQ(1UL, resulting_parameters.encodings.size()); |
| 260 EXPECT_EQ(expected_result ? stream_max : -1, |
| 261 resulting_parameters.encodings[0].max_bitrate_bps); |
| 262 |
| 263 // Verify that the codec settings have the expected bitrate. |
| 264 EXPECT_EQ(expected_codec_bitrate, GetCodecBitrate(kSsrc1)); |
| 265 } |
| 266 |
217 void TestSetSendRtpHeaderExtensions(const std::string& ext) { | 267 void TestSetSendRtpHeaderExtensions(const std::string& ext) { |
218 EXPECT_TRUE(SetupSendStream()); | 268 EXPECT_TRUE(SetupSendStream()); |
219 | 269 |
220 // Ensure extensions are off by default. | 270 // Ensure extensions are off by default. |
221 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc1).rtp.extensions.size()); | 271 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc1).rtp.extensions.size()); |
222 | 272 |
223 // Ensure unknown extensions won't cause an error. | 273 // Ensure unknown extensions won't cause an error. |
224 send_parameters_.extensions.push_back(cricket::RtpHeaderExtension( | 274 send_parameters_.extensions.push_back(cricket::RtpHeaderExtension( |
225 "urn:ietf:params:unknownextention", 1)); | 275 "urn:ietf:params:unknownextention", 1)); |
226 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); | 276 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_)); | 815 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
766 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); | 816 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); |
767 EXPECT_EQ(64000, codec.rate); | 817 EXPECT_EQ(64000, codec.rate); |
768 | 818 |
769 send_parameters_.max_bandwidth_bps = 128; | 819 send_parameters_.max_bandwidth_bps = 128; |
770 EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); | 820 EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); |
771 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); | 821 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); |
772 EXPECT_EQ(64000, codec.rate); | 822 EXPECT_EQ(64000, codec.rate); |
773 } | 823 } |
774 | 824 |
| 825 // Test that the per-stream bitrate limit and the global |
| 826 // bitrate limit both apply. |
| 827 TEST_F(WebRtcVoiceEngineTestFake, SetMaxBitratePerStream) { |
| 828 EXPECT_TRUE(SetupSendStream()); |
| 829 |
| 830 // opus, default bitrate == 64000. |
| 831 SetAndExpectMaxBitrate(kOpusCodec, 0, 0, true, 64000); |
| 832 SetAndExpectMaxBitrate(kOpusCodec, 48000, 0, true, 48000); |
| 833 SetAndExpectMaxBitrate(kOpusCodec, 48000, 64000, true, 48000); |
| 834 SetAndExpectMaxBitrate(kOpusCodec, 64000, 48000, true, 48000); |
| 835 |
| 836 // CBR codecs allow both maximums to exceed the bitrate. |
| 837 SetAndExpectMaxBitrate(kPcmuCodec, 0, 0, true, 64000); |
| 838 SetAndExpectMaxBitrate(kPcmuCodec, 64001, 0, true, 64000); |
| 839 SetAndExpectMaxBitrate(kPcmuCodec, 0, 64001, true, 64000); |
| 840 SetAndExpectMaxBitrate(kPcmuCodec, 64001, 64001, true, 64000); |
| 841 |
| 842 // CBR codecs don't allow per stream maximums to be too low. |
| 843 SetAndExpectMaxBitrate(kPcmuCodec, 0, 63999, false, 64000); |
| 844 SetAndExpectMaxBitrate(kPcmuCodec, 64001, 63999, false, 64000); |
| 845 } |
| 846 |
| 847 // Test that an attempt to set RtpParameters for a stream that does not exist |
| 848 // fails. |
| 849 TEST_F(WebRtcVoiceEngineTestFake, CannotSetMaxBitrateForNonexistentStream) { |
| 850 EXPECT_TRUE(SetupChannel()); |
| 851 webrtc::RtpParameters nonexistent_parameters = |
| 852 channel_->GetRtpParameters(kSsrc1); |
| 853 EXPECT_EQ(0, nonexistent_parameters.encodings.size()); |
| 854 |
| 855 nonexistent_parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
| 856 EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, nonexistent_parameters)); |
| 857 } |
| 858 |
| 859 TEST_F(WebRtcVoiceEngineTestFake, |
| 860 CannotSetRtpParametersWithIncorrectNumberOfEncodings) { |
| 861 // This test verifies that setting RtpParameters succeeds only if |
| 862 // the structure contains exactly one encoding. |
| 863 // TODO(skvlad): Update this test when we start supporting setting parameters |
| 864 // for each encoding individually. |
| 865 |
| 866 EXPECT_TRUE(SetupSendStream()); |
| 867 // Setting RtpParameters with no encoding is expected to fail. |
| 868 webrtc::RtpParameters parameters; |
| 869 EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, parameters)); |
| 870 // Setting RtpParameters with exactly one encoding should succeed. |
| 871 parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
| 872 EXPECT_TRUE(channel_->SetRtpParameters(kSsrc1, parameters)); |
| 873 // Two or more encodings should result in failure. |
| 874 parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
| 875 EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, parameters)); |
| 876 } |
| 877 |
| 878 // Test that SetRtpParameters configures the correct encoding channel for each |
| 879 // SSRC. |
| 880 TEST_F(WebRtcVoiceEngineTestFake, RtpParametersArePerStream) { |
| 881 SetupForMultiSendStream(); |
| 882 // Create send streams. |
| 883 for (uint32_t ssrc : kSsrcs4) { |
| 884 EXPECT_TRUE( |
| 885 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(ssrc))); |
| 886 } |
| 887 // Configure one stream to be limited by the stream config, another to be |
| 888 // limited by the global max, and the third one with no per-stream limit |
| 889 // (still subject to the global limit). |
| 890 EXPECT_TRUE(SetGlobalMaxBitrate(kOpusCodec, 64000)); |
| 891 EXPECT_TRUE(SetMaxBitrateForStream(kSsrcs4[0], 48000)); |
| 892 EXPECT_TRUE(SetMaxBitrateForStream(kSsrcs4[1], 96000)); |
| 893 EXPECT_TRUE(SetMaxBitrateForStream(kSsrcs4[2], -1)); |
| 894 |
| 895 EXPECT_EQ(48000, GetCodecBitrate(kSsrcs4[0])); |
| 896 EXPECT_EQ(64000, GetCodecBitrate(kSsrcs4[1])); |
| 897 EXPECT_EQ(64000, GetCodecBitrate(kSsrcs4[2])); |
| 898 |
| 899 // Remove the global cap; the streams should switch to their respective |
| 900 // maximums (or remain unchanged if there was no other limit on them.) |
| 901 EXPECT_TRUE(SetGlobalMaxBitrate(kOpusCodec, -1)); |
| 902 EXPECT_EQ(48000, GetCodecBitrate(kSsrcs4[0])); |
| 903 EXPECT_EQ(96000, GetCodecBitrate(kSsrcs4[1])); |
| 904 EXPECT_EQ(64000, GetCodecBitrate(kSsrcs4[2])); |
| 905 } |
| 906 |
775 // Test that we apply codecs properly. | 907 // Test that we apply codecs properly. |
776 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) { | 908 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) { |
777 EXPECT_TRUE(SetupSendStream()); | 909 EXPECT_TRUE(SetupSendStream()); |
778 cricket::AudioSendParameters parameters; | 910 cricket::AudioSendParameters parameters; |
779 parameters.codecs.push_back(kIsacCodec); | 911 parameters.codecs.push_back(kIsacCodec); |
780 parameters.codecs.push_back(kPcmuCodec); | 912 parameters.codecs.push_back(kPcmuCodec); |
781 parameters.codecs.push_back(kRedCodec); | 913 parameters.codecs.push_back(kRedCodec); |
782 parameters.codecs[0].id = 96; | 914 parameters.codecs[0].id = 96; |
783 parameters.codecs[0].bitrate = 48000; | 915 parameters.codecs[0].bitrate = 48000; |
784 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 916 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
(...skipping 2560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3345 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { | 3477 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { |
3346 cricket::WebRtcVoiceEngine engine(nullptr); | 3478 cricket::WebRtcVoiceEngine engine(nullptr); |
3347 std::unique_ptr<webrtc::Call> call( | 3479 std::unique_ptr<webrtc::Call> call( |
3348 webrtc::Call::Create(webrtc::Call::Config())); | 3480 webrtc::Call::Create(webrtc::Call::Config())); |
3349 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), | 3481 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), |
3350 cricket::AudioOptions(), call.get()); | 3482 cricket::AudioOptions(), call.get()); |
3351 cricket::AudioRecvParameters parameters; | 3483 cricket::AudioRecvParameters parameters; |
3352 parameters.codecs = engine.codecs(); | 3484 parameters.codecs = engine.codecs(); |
3353 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3485 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3354 } | 3486 } |
OLD | NEW |