| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 EXPECT_EQ(2, telephone_event.event_code); | 182 EXPECT_EQ(2, telephone_event.event_code); |
| 183 EXPECT_EQ(123, telephone_event.duration_ms); | 183 EXPECT_EQ(123, telephone_event.duration_ms); |
| 184 } | 184 } |
| 185 | 185 |
| 186 // Test that send bandwidth is set correctly. | 186 // Test that send bandwidth is set correctly. |
| 187 // |codec| is the codec under test. | 187 // |codec| is the codec under test. |
| 188 // |max_bitrate| is a parameter to set to SetMaxSendBandwidth(). | 188 // |max_bitrate| is a parameter to set to SetMaxSendBandwidth(). |
| 189 // |expected_result| is the expected result from SetMaxSendBandwidth(). | 189 // |expected_result| is the expected result from SetMaxSendBandwidth(). |
| 190 // |expected_bitrate| is the expected audio bitrate afterward. | 190 // |expected_bitrate| is the expected audio bitrate afterward. |
| 191 void TestSendBandwidth(const cricket::AudioCodec& codec, | 191 void TestSendBandwidth(const cricket::AudioCodec& codec, |
| 192 int max_bitrate, | 192 rtc::Optional<int> max_bitrate, |
| 193 bool expected_result, | 193 bool expected_result, |
| 194 int expected_bitrate) { | 194 int expected_bitrate) { |
| 195 cricket::AudioSendParameters parameters; | 195 cricket::AudioSendParameters parameters; |
| 196 parameters.codecs.push_back(codec); | 196 parameters.codecs.push_back(codec); |
| 197 parameters.max_bandwidth_bps = max_bitrate; | 197 parameters.max_bitrate_bps = max_bitrate; |
| 198 EXPECT_EQ(expected_result, channel_->SetSendParameters(parameters)); | 198 EXPECT_EQ(expected_result, channel_->SetSendParameters(parameters)); |
| 199 | 199 |
| 200 int channel_num = voe_.GetLastChannel(); | 200 int channel_num = voe_.GetLastChannel(); |
| 201 webrtc::CodecInst temp_codec; | 201 webrtc::CodecInst temp_codec; |
| 202 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec)); | 202 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec)); |
| 203 EXPECT_EQ(expected_bitrate, temp_codec.rate); | 203 EXPECT_EQ(expected_bitrate, temp_codec.rate); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void TestSetSendRtpHeaderExtensions(const std::string& ext) { | 206 void TestSetSendRtpHeaderExtensions(const std::string& ext) { |
| 207 EXPECT_TRUE(SetupEngineWithSendStream()); | 207 EXPECT_TRUE(SetupEngineWithSendStream()); |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 } | 686 } |
| 687 | 687 |
| 688 TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) { | 688 TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) { |
| 689 EXPECT_TRUE(SetupEngineWithSendStream()); | 689 EXPECT_TRUE(SetupEngineWithSendStream()); |
| 690 | 690 |
| 691 // Test that when autobw is enabled, bitrate is kept as the default | 691 // Test that when autobw is enabled, bitrate is kept as the default |
| 692 // value. autobw is enabled for the following tests because the target | 692 // value. autobw is enabled for the following tests because the target |
| 693 // bitrate is <= 0. | 693 // bitrate is <= 0. |
| 694 | 694 |
| 695 // ISAC, default bitrate == 32000. | 695 // ISAC, default bitrate == 32000. |
| 696 TestSendBandwidth(kIsacCodec, 0, true, 32000); | 696 TestSendBandwidth(kIsacCodec, rtc::Optional<int>(), true, 32000); |
| 697 | 697 |
| 698 // PCMU, default bitrate == 64000. | 698 // PCMU, default bitrate == 64000. |
| 699 TestSendBandwidth(kPcmuCodec, -1, true, 64000); | 699 TestSendBandwidth(kPcmuCodec, rtc::Optional<int>(), true, 64000); |
| 700 | 700 |
| 701 // opus, default bitrate == 64000. | 701 // opus, default bitrate == 64000. |
| 702 TestSendBandwidth(kOpusCodec, -1, true, 64000); | 702 TestSendBandwidth(kOpusCodec, rtc::Optional<int>(), true, 64000); |
| 703 } | 703 } |
| 704 | 704 |
| 705 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) { | 705 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) { |
| 706 EXPECT_TRUE(SetupEngineWithSendStream()); | 706 EXPECT_TRUE(SetupEngineWithSendStream()); |
| 707 | 707 |
| 708 // Test that the bitrate of a multi-rate codec is always the maximum. | 708 // Test that the bitrate of a multi-rate codec is always the maximum. |
| 709 | 709 |
| 710 // ISAC, default bitrate == 32000. | 710 // ISAC, default bitrate == 32000. |
| 711 TestSendBandwidth(kIsacCodec, 128000, true, 128000); | 711 TestSendBandwidth(kIsacCodec, rtc::Optional<int>(128000), true, 128000); |
| 712 TestSendBandwidth(kIsacCodec, 16000, true, 16000); | 712 TestSendBandwidth(kIsacCodec, rtc::Optional<int>(16000), true, 16000); |
| 713 | 713 |
| 714 // opus, default bitrate == 64000. | 714 // opus, default bitrate == 64000. |
| 715 TestSendBandwidth(kOpusCodec, 96000, true, 96000); | 715 TestSendBandwidth(kOpusCodec, rtc::Optional<int>(96000), true, 96000); |
| 716 TestSendBandwidth(kOpusCodec, 48000, true, 48000); | 716 TestSendBandwidth(kOpusCodec, rtc::Optional<int>(48000), true, 48000); |
| 717 } | 717 } |
| 718 | 718 |
| 719 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) { | 719 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) { |
| 720 EXPECT_TRUE(SetupEngineWithSendStream()); | 720 EXPECT_TRUE(SetupEngineWithSendStream()); |
| 721 | 721 |
| 722 // Test that we can only set a maximum bitrate for a fixed-rate codec | 722 // Test that we can only set a maximum bitrate for a fixed-rate codec |
| 723 // if it's bigger than the fixed rate. | 723 // if it's bigger than the fixed rate. |
| 724 | 724 |
| 725 // PCMU, fixed bitrate == 64000. | 725 // PCMU, fixed bitrate == 64000. |
| 726 TestSendBandwidth(kPcmuCodec, 0, true, 64000); | 726 TestSendBandwidth(kPcmuCodec, rtc::Optional<int>(), true, 64000); |
| 727 TestSendBandwidth(kPcmuCodec, 1, false, 64000); | 727 TestSendBandwidth(kPcmuCodec, rtc::Optional<int>(1), false, 64000); |
| 728 TestSendBandwidth(kPcmuCodec, 128000, true, 64000); | 728 TestSendBandwidth(kPcmuCodec, rtc::Optional<int>(128000), true, 64000); |
| 729 TestSendBandwidth(kPcmuCodec, 32000, false, 64000); | 729 TestSendBandwidth(kPcmuCodec, rtc::Optional<int>(32000), false, 64000); |
| 730 TestSendBandwidth(kPcmuCodec, 64000, true, 64000); | 730 TestSendBandwidth(kPcmuCodec, rtc::Optional<int>(64000), true, 64000); |
| 731 TestSendBandwidth(kPcmuCodec, 63999, false, 64000); | 731 TestSendBandwidth(kPcmuCodec, rtc::Optional<int>(63999), false, 64000); |
| 732 TestSendBandwidth(kPcmuCodec, 64001, true, 64000); | 732 TestSendBandwidth(kPcmuCodec, rtc::Optional<int>(64001), true, 64000); |
| 733 } | 733 } |
| 734 | 734 |
| 735 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) { | 735 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) { |
| 736 EXPECT_TRUE(SetupEngine()); | 736 EXPECT_TRUE(SetupEngine()); |
| 737 const int kDesiredBitrate = 128000; | 737 const int kDesiredBitrate = 128000; |
| 738 cricket::AudioSendParameters parameters; | 738 cricket::AudioSendParameters parameters; |
| 739 parameters.codecs = engine_.codecs(); | 739 parameters.codecs = engine_.codecs(); |
| 740 parameters.max_bandwidth_bps = kDesiredBitrate; | 740 parameters.max_bitrate_bps = rtc::Optional<int>(kDesiredBitrate); |
| 741 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 741 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 742 | 742 |
| 743 EXPECT_TRUE(channel_->AddSendStream( | 743 EXPECT_TRUE(channel_->AddSendStream( |
| 744 cricket::StreamParams::CreateLegacy(kSsrc1))); | 744 cricket::StreamParams::CreateLegacy(kSsrc1))); |
| 745 | 745 |
| 746 int channel_num = voe_.GetLastChannel(); | 746 int channel_num = voe_.GetLastChannel(); |
| 747 webrtc::CodecInst codec; | 747 webrtc::CodecInst codec; |
| 748 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); | 748 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); |
| 749 EXPECT_EQ(kDesiredBitrate, codec.rate); | 749 EXPECT_EQ(kDesiredBitrate, codec.rate); |
| 750 } | 750 } |
| 751 | 751 |
| 752 // Test that bitrate cannot be set for CBR codecs. | 752 // Test that bitrate cannot be set for CBR codecs. |
| 753 // Bitrate is ignored if it is higher than the fixed bitrate. | 753 // Bitrate is ignored if it is higher than the fixed bitrate. |
| 754 // Bitrate less then the fixed bitrate is an error. | 754 // Bitrate less then the fixed bitrate is an error. |
| 755 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) { | 755 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) { |
| 756 EXPECT_TRUE(SetupEngineWithSendStream()); | 756 EXPECT_TRUE(SetupEngineWithSendStream()); |
| 757 | 757 |
| 758 // PCMU, default bitrate == 64000. | 758 // PCMU, default bitrate == 64000. |
| 759 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); | 759 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 760 int channel_num = voe_.GetLastChannel(); | 760 int channel_num = voe_.GetLastChannel(); |
| 761 webrtc::CodecInst codec; | 761 webrtc::CodecInst codec; |
| 762 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); | 762 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); |
| 763 EXPECT_EQ(64000, codec.rate); | 763 EXPECT_EQ(64000, codec.rate); |
| 764 | 764 |
| 765 send_parameters_.max_bandwidth_bps = 128000; | 765 send_parameters_.max_bitrate_bps = rtc::Optional<int>(128000); |
| 766 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); | 766 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 767 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); | 767 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); |
| 768 EXPECT_EQ(64000, codec.rate); | 768 EXPECT_EQ(64000, codec.rate); |
| 769 | 769 |
| 770 send_parameters_.max_bandwidth_bps = 128; | 770 send_parameters_.max_bitrate_bps = rtc::Optional<int>(128); |
| 771 EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); | 771 EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); |
| 772 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); | 772 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); |
| 773 EXPECT_EQ(64000, codec.rate); | 773 EXPECT_EQ(64000, codec.rate); |
| 774 } | 774 } |
| 775 | 775 |
| 776 // Test that we apply codecs properly. | 776 // Test that we apply codecs properly. |
| 777 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) { | 777 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) { |
| 778 EXPECT_TRUE(SetupEngineWithSendStream()); | 778 EXPECT_TRUE(SetupEngineWithSendStream()); |
| 779 cricket::AudioSendParameters parameters; | 779 cricket::AudioSendParameters parameters; |
| 780 parameters.codecs.push_back(kIsacCodec); | 780 parameters.codecs.push_back(kIsacCodec); |
| (...skipping 2568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3349 cricket::WebRtcVoiceEngine engine; | 3349 cricket::WebRtcVoiceEngine engine; |
| 3350 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); | 3350 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
| 3351 std::unique_ptr<webrtc::Call> call( | 3351 std::unique_ptr<webrtc::Call> call( |
| 3352 webrtc::Call::Create(webrtc::Call::Config())); | 3352 webrtc::Call::Create(webrtc::Call::Config())); |
| 3353 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), | 3353 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), |
| 3354 cricket::AudioOptions(), call.get()); | 3354 cricket::AudioOptions(), call.get()); |
| 3355 cricket::AudioRecvParameters parameters; | 3355 cricket::AudioRecvParameters parameters; |
| 3356 parameters.codecs = engine.codecs(); | 3356 parameters.codecs = engine.codecs(); |
| 3357 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3357 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
| 3358 } | 3358 } |
| OLD | NEW |