OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1164 const std::string& GetFirstAudioStreamCname( | 1164 const std::string& GetFirstAudioStreamCname( |
1165 const SessionDescriptionInterface* desc) { | 1165 const SessionDescriptionInterface* desc) { |
1166 const cricket::ContentInfo* audio_content = | 1166 const cricket::ContentInfo* audio_content = |
1167 cricket::GetFirstAudioContent(desc->description()); | 1167 cricket::GetFirstAudioContent(desc->description()); |
1168 const cricket::AudioContentDescription* audio_desc = | 1168 const cricket::AudioContentDescription* audio_desc = |
1169 static_cast<const cricket::AudioContentDescription*>( | 1169 static_cast<const cricket::AudioContentDescription*>( |
1170 audio_content->description); | 1170 audio_content->description); |
1171 return audio_desc->streams()[0].cname; | 1171 return audio_desc->streams()[0].cname; |
1172 } | 1172 } |
1173 | 1173 |
1174 bool CreateOfferWithOptions( | |
1175 std::unique_ptr<SessionDescriptionInterface>* desc, | |
1176 const RTCOfferAnswerOptions& offer_answer_options) { | |
Taylor Brandstetter
2017/07/28 19:00:25
Can this just return the unique_ptr, returning nul
Zhi Huang
2017/08/02 04:38:36
Done.
| |
1177 RTC_DCHECK(pc_); | |
1178 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer( | |
1179 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>()); | |
1180 pc_->CreateOffer(observer, offer_answer_options); | |
1181 EXPECT_EQ_WAIT(true, observer->called(), kTimeout); | |
1182 *desc = observer->MoveDescription(); | |
1183 return observer->result(); | |
1184 } | |
1185 | |
1186 void CreateOfferWithOptionsAsRemoteDescription( | |
1187 std::unique_ptr<SessionDescriptionInterface>* desc, | |
1188 const RTCOfferAnswerOptions& offer_answer_options) { | |
1189 ASSERT_TRUE(CreateOfferWithOptions(desc, offer_answer_options)); | |
1190 std::string sdp; | |
1191 EXPECT_TRUE((*desc)->ToString(&sdp)); | |
1192 SessionDescriptionInterface* remote_offer = | |
1193 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
1194 sdp, NULL); | |
1195 EXPECT_TRUE(DoSetRemoteDescription(remote_offer)); | |
1196 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); | |
1197 } | |
1198 | |
1199 void CreateOfferWithOptionsAsLocalDescription( | |
1200 std::unique_ptr<SessionDescriptionInterface>* desc, | |
1201 const RTCOfferAnswerOptions& offer_answer_options) { | |
1202 ASSERT_TRUE(CreateOfferWithOptions(desc, offer_answer_options)); | |
1203 std::string sdp; | |
1204 EXPECT_TRUE((*desc)->ToString(&sdp)); | |
1205 SessionDescriptionInterface* new_offer = webrtc::CreateSessionDescription( | |
1206 SessionDescriptionInterface::kOffer, sdp, NULL); | |
1207 | |
1208 EXPECT_TRUE(DoSetLocalDescription(new_offer)); | |
1209 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_); | |
1210 } | |
1211 | |
1212 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { | |
Taylor Brandstetter
2017/07/28 19:00:25
I think it would make more sense to call this "Has
Zhi Huang
2017/08/02 04:38:36
Done.
| |
1213 const cricket::ContentDescription* description = content->description; | |
1214 RTC_DCHECK(description); | |
1215 const cricket::AudioContentDescription* audio_content_desc = | |
1216 static_cast<const cricket::AudioContentDescription*>(description); | |
1217 RTC_DCHECK(audio_content_desc); | |
1218 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { | |
1219 if (audio_content_desc->codecs()[i].name == "CN") | |
1220 return false; | |
1221 } | |
1222 return true; | |
1223 } | |
1224 | |
1174 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 1225 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
1175 rtc::AutoSocketServerThread main_; | 1226 rtc::AutoSocketServerThread main_; |
1176 cricket::FakePortAllocator* port_allocator_ = nullptr; | 1227 cricket::FakePortAllocator* port_allocator_ = nullptr; |
1177 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr; | 1228 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr; |
1178 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; | 1229 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; |
1179 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_; | 1230 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_; |
1180 rtc::scoped_refptr<PeerConnectionInterface> pc_; | 1231 rtc::scoped_refptr<PeerConnectionInterface> pc_; |
1181 MockPeerConnectionObserver observer_; | 1232 MockPeerConnectionObserver observer_; |
1182 rtc::scoped_refptr<StreamCollection> reference_collection_; | 1233 rtc::scoped_refptr<StreamCollection> reference_collection_; |
1183 }; | 1234 }; |
(...skipping 2219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3403 // Call's BitrateConfig, which comes from the SDP or a default value. This test | 3454 // Call's BitrateConfig, which comes from the SDP or a default value. This test |
3404 // checks that a call to SetBitrate with a current bitrate that will be clamped | 3455 // checks that a call to SetBitrate with a current bitrate that will be clamped |
3405 // succeeds. | 3456 // succeeds. |
3406 TEST_F(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) { | 3457 TEST_F(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) { |
3407 CreatePeerConnection(); | 3458 CreatePeerConnection(); |
3408 PeerConnectionInterface::BitrateParameters bitrate; | 3459 PeerConnectionInterface::BitrateParameters bitrate; |
3409 bitrate.current_bitrate_bps = rtc::Optional<int>(1); | 3460 bitrate.current_bitrate_bps = rtc::Optional<int>(1); |
3410 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok()); | 3461 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok()); |
3411 } | 3462 } |
3412 | 3463 |
3464 // The following tests verify that session options and offers are created | |
3465 // correctly. | |
3466 TEST_F(PeerConnectionInterfaceTest, GetOptionsForOfferWithInvalidAudioOption) { | |
Taylor Brandstetter
2017/07/28 19:00:25
Since these tests are no longer calling "GetOption
Zhi Huang
2017/08/02 04:38:36
Done.
| |
3467 RTCOfferAnswerOptions rtc_options; | |
3468 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1; | |
3469 | |
3470 std::unique_ptr<SessionDescriptionInterface> offer; | |
3471 CreatePeerConnection(); | |
3472 EXPECT_FALSE(CreateOfferWithOptions(&offer, rtc_options)); | |
Taylor Brandstetter
2017/07/28 19:00:25
These tests could use some comments. For example:
Zhi Huang
2017/08/02 04:38:36
Done.
| |
3473 rtc_options.offer_to_receive_audio = | |
3474 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; | |
3475 EXPECT_FALSE(CreateOfferWithOptions(&offer, rtc_options)); | |
3476 } | |
3477 | |
3478 TEST_F(PeerConnectionInterfaceTest, GetOptionsForOfferWithInvalidVideoOption) { | |
3479 RTCOfferAnswerOptions rtc_options; | |
3480 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1; | |
3481 | |
3482 std::unique_ptr<SessionDescriptionInterface> offer; | |
3483 CreatePeerConnection(); | |
3484 EXPECT_FALSE(CreateOfferWithOptions(&offer, rtc_options)); | |
3485 | |
3486 rtc_options.offer_to_receive_video = | |
3487 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; | |
3488 EXPECT_FALSE(CreateOfferWithOptions(&offer, rtc_options)); | |
3489 } | |
3490 | |
3491 // Test that the audio and video section will be added to an offer if | |
3492 // OfferToReceiveAudio and OfferToReceiveVideo options are set. | |
3493 TEST_F(PeerConnectionInterfaceTest, | |
3494 GetMediaSessionOptionsForOfferWithAudioVideo) { | |
3495 RTCOfferAnswerOptions rtc_options; | |
3496 rtc_options.offer_to_receive_audio = 1; | |
3497 rtc_options.offer_to_receive_video = 1; | |
3498 | |
3499 std::unique_ptr<SessionDescriptionInterface> offer; | |
3500 CreatePeerConnection(); | |
3501 EXPECT_TRUE(CreateOfferWithOptions(&offer, rtc_options)); | |
3502 EXPECT_TRUE(ValidateOfferAnswerOptions(rtc_options)); | |
3503 EXPECT_NE(nullptr, offer->description()->GetContentByName(cricket::CN_AUDIO)); | |
3504 EXPECT_NE(nullptr, offer->description()->GetContentByName(cricket::CN_VIDEO)); | |
Taylor Brandstetter
2017/07/28 19:00:25
nit: To be foolproof, we shouldn't rely on "GetCon
Zhi Huang
2017/08/02 04:38:36
Done.
| |
3505 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE)); | |
Taylor Brandstetter
2017/07/28 19:00:26
I don't think the BUNDLE group assertion is releva
Zhi Huang
2017/08/02 04:38:36
Done.
| |
3506 } | |
3507 | |
3508 // Test that only audio section will be added if only OfferToReceiveAudio | |
3509 // options is set. | |
3510 TEST_F(PeerConnectionInterfaceTest, GetMediaSessionOptionsForOfferWithAudio) { | |
3511 RTCOfferAnswerOptions rtc_options; | |
3512 rtc_options.offer_to_receive_audio = 1; | |
3513 rtc_options.offer_to_receive_video = 0; | |
3514 | |
3515 std::unique_ptr<SessionDescriptionInterface> offer; | |
3516 CreatePeerConnection(); | |
3517 EXPECT_TRUE(CreateOfferWithOptions(&offer, rtc_options)); | |
3518 EXPECT_NE(nullptr, offer->description()->GetContentByName(cricket::CN_AUDIO)); | |
3519 EXPECT_EQ(nullptr, offer->description()->GetContentByName(cricket::CN_VIDEO)); | |
3520 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE)); | |
3521 } | |
3522 | |
3523 // Test that the |vad_enabled| can be set correctly in MediaSessionOptions. | |
Taylor Brandstetter
2017/07/28 19:00:26
This comment should be updated since this test doe
Zhi Huang
2017/08/02 04:38:36
Done.
| |
3524 TEST_F(PeerConnectionInterfaceTest, GetMediaSessionOptionsWithVAD) { | |
3525 RTCOfferAnswerOptions rtc_options; | |
3526 rtc_options.offer_to_receive_audio = 1; | |
3527 rtc_options.offer_to_receive_video = 0; | |
3528 | |
3529 std::unique_ptr<SessionDescriptionInterface> offer; | |
3530 CreatePeerConnection(); | |
3531 EXPECT_TRUE(CreateOfferWithOptions(&offer, rtc_options)); | |
3532 const cricket::ContentInfo* audio_content = | |
3533 offer->description()->GetContentByName(cricket::CN_AUDIO); | |
3534 ASSERT_TRUE(audio_content); | |
3535 EXPECT_FALSE(VerifyNoCNCodecs(audio_content)); | |
3536 | |
3537 rtc_options.voice_activity_detection = false; | |
3538 EXPECT_TRUE(CreateOfferWithOptions(&offer, rtc_options)); | |
3539 audio_content = offer->description()->GetContentByName(cricket::CN_AUDIO); | |
3540 ASSERT_TRUE(audio_content); | |
3541 EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); | |
3542 } | |
3543 | |
3544 // Test that no media section will be added if using default | |
3545 // RTCOfferAnswerOptions. | |
3546 TEST_F(PeerConnectionInterfaceTest, GetDefaultMediaSessionOptionsForOffer) { | |
3547 RTCOfferAnswerOptions rtc_options; | |
3548 | |
3549 std::unique_ptr<SessionDescriptionInterface> offer; | |
3550 CreatePeerConnection(); | |
3551 EXPECT_TRUE(CreateOfferWithOptions(&offer, rtc_options)); | |
3552 // No media sections should be created. | |
3553 EXPECT_EQ(nullptr, offer->description()->GetContentByName(cricket::CN_AUDIO)); | |
3554 EXPECT_EQ(nullptr, offer->description()->GetContentByName(cricket::CN_VIDEO)); | |
3555 } | |
3556 | |
3557 // Test that only video section will be added if only OfferToReceiveVideo | |
3558 // options is set. | |
3559 TEST_F(PeerConnectionInterfaceTest, GetMediaSessionOptionsForOfferWithVideo) { | |
3560 RTCOfferAnswerOptions rtc_options; | |
3561 rtc_options.offer_to_receive_audio = 0; | |
3562 rtc_options.offer_to_receive_video = 1; | |
3563 | |
3564 std::unique_ptr<SessionDescriptionInterface> offer; | |
3565 CreatePeerConnection(); | |
3566 EXPECT_TRUE(CreateOfferWithOptions(&offer, rtc_options)); | |
3567 EXPECT_EQ(nullptr, offer->description()->GetContentByName(cricket::CN_AUDIO)); | |
3568 EXPECT_NE(nullptr, offer->description()->GetContentByName(cricket::CN_VIDEO)); | |
3569 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE)); | |
3570 } | |
3571 | |
3572 // Test that a correct MediaSessionOptions is created to restart ice if | |
3573 // IceRestart is set. | |
3574 TEST_F(PeerConnectionInterfaceTest, | |
3575 GetMediaSessionOptionsForOfferWithIceRestart) { | |
3576 RTCOfferAnswerOptions rtc_options; | |
3577 rtc_options.ice_restart = false; | |
3578 rtc_options.offer_to_receive_audio = 1; | |
3579 | |
3580 std::unique_ptr<SessionDescriptionInterface> offer; | |
3581 CreatePeerConnection(); | |
3582 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options); | |
3583 auto ufrag1 = offer->description() | |
3584 ->GetTransportInfoByName(cricket::CN_AUDIO) | |
3585 ->description.ice_ufrag; | |
3586 auto pwd1 = offer->description() | |
3587 ->GetTransportInfoByName(cricket::CN_AUDIO) | |
3588 ->description.ice_pwd; | |
3589 | |
3590 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options); | |
Taylor Brandstetter
2017/07/28 19:00:26
So this is also testing that if ice_restart is fal
Zhi Huang
2017/08/02 04:38:36
Done.
| |
3591 auto ufrag2 = offer->description() | |
3592 ->GetTransportInfoByName(cricket::CN_AUDIO) | |
3593 ->description.ice_ufrag; | |
3594 auto pwd2 = offer->description() | |
3595 ->GetTransportInfoByName(cricket::CN_AUDIO) | |
3596 ->description.ice_pwd; | |
3597 | |
3598 rtc_options.ice_restart = true; | |
3599 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options); | |
3600 auto ufrag3 = offer->description() | |
3601 ->GetTransportInfoByName(cricket::CN_AUDIO) | |
3602 ->description.ice_ufrag; | |
3603 auto pwd3 = offer->description() | |
3604 ->GetTransportInfoByName(cricket::CN_AUDIO) | |
3605 ->description.ice_pwd; | |
3606 | |
3607 EXPECT_EQ(ufrag1, ufrag2); | |
3608 EXPECT_EQ(pwd1, pwd2); | |
3609 EXPECT_NE(ufrag2, ufrag3); | |
3610 EXPECT_NE(pwd2, pwd3); | |
3611 } | |
3612 | |
3613 // Test that the MediaConstraints can be correctly translated to | |
3614 // RTCOfferAnswerOptions when creating an answer and the MediaConstraints don't | |
3615 // affect whether audio and video sections are created if they are offered from | |
3616 // the remote side. | |
3617 TEST_F(PeerConnectionInterfaceTest, MediaConstraintsInAnswer) { | |
Taylor Brandstetter
2017/07/28 19:00:26
I think this test could be written in terms of Pee
Zhi Huang
2017/08/02 04:38:36
Done.
| |
3618 FakeConstraints answer_c; | |
3619 answer_c.SetMandatoryReceiveAudio(true); | |
3620 answer_c.SetMandatoryReceiveVideo(true); | |
3621 | |
3622 RTCOfferAnswerOptions rtc_answer_options; | |
3623 EXPECT_TRUE( | |
3624 ConvertConstraintsToOfferAnswerOptions(&answer_c, &rtc_answer_options)); | |
3625 EXPECT_EQ(1, rtc_answer_options.offer_to_receive_audio); | |
3626 EXPECT_EQ(1, rtc_answer_options.offer_to_receive_video); | |
3627 | |
3628 RTCOfferAnswerOptions rtc_offer_options; | |
3629 rtc_offer_options.offer_to_receive_audio = 1; | |
3630 rtc_offer_options.offer_to_receive_video = 1; | |
3631 | |
3632 CreatePeerConnection(); | |
3633 | |
3634 std::unique_ptr<SessionDescriptionInterface> offer; | |
3635 CreateOfferWithOptionsAsRemoteDescription(&offer, rtc_offer_options); | |
3636 EXPECT_NE(nullptr, offer->description()->GetContentByName(cricket::CN_AUDIO)); | |
3637 EXPECT_NE(nullptr, offer->description()->GetContentByName(cricket::CN_VIDEO)); | |
3638 | |
3639 // Since an offer has been created with both audio and video, subsequent | |
3640 // offers and answers should contain both audio and video. | |
3641 // Answers will only contain the media types that exist in the offer | |
3642 // regardless of the value of |updated_answer_options.has_audio| and | |
3643 // |updated_answer_options.has_video|. | |
3644 FakeConstraints updated_answer_c; | |
3645 updated_answer_c.SetMandatoryReceiveAudio(false); | |
3646 updated_answer_c.SetMandatoryReceiveVideo(false); | |
3647 | |
3648 std::unique_ptr<SessionDescriptionInterface> answer; | |
3649 ASSERT_TRUE(DoCreateAnswer(&answer, &updated_answer_c)); | |
3650 EXPECT_NE(nullptr, | |
3651 answer->description()->GetContentByName(cricket::CN_AUDIO)); | |
3652 EXPECT_NE(nullptr, | |
3653 answer->description()->GetContentByName(cricket::CN_VIDEO)); | |
3654 } | |
3655 | |
3413 class PeerConnectionMediaConfigTest : public testing::Test { | 3656 class PeerConnectionMediaConfigTest : public testing::Test { |
3414 protected: | 3657 protected: |
3415 void SetUp() override { | 3658 void SetUp() override { |
3416 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest(); | 3659 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest(); |
3417 pcf_->Initialize(); | 3660 pcf_->Initialize(); |
3418 } | 3661 } |
3419 const cricket::MediaConfig TestCreatePeerConnection( | 3662 const cricket::MediaConfig TestCreatePeerConnection( |
3420 const PeerConnectionInterface::RTCConfiguration& config, | 3663 const PeerConnectionInterface::RTCConfiguration& config, |
3421 const MediaConstraintsInterface *constraints) { | 3664 const MediaConstraintsInterface* constraints) { |
3422 | |
3423 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection( | 3665 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection( |
3424 config, constraints, nullptr, nullptr, &observer_)); | 3666 config, constraints, nullptr, nullptr, &observer_)); |
3425 EXPECT_TRUE(pc.get()); | 3667 EXPECT_TRUE(pc.get()); |
3426 return pc->GetConfiguration().media_config; | 3668 return pc->GetConfiguration().media_config; |
3427 } | 3669 } |
3428 | 3670 |
3429 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_; | 3671 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_; |
3430 MockPeerConnectionObserver observer_; | 3672 MockPeerConnectionObserver observer_; |
3431 }; | 3673 }; |
3432 | 3674 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3494 | 3736 |
3495 constraints.AddOptional( | 3737 constraints.AddOptional( |
3496 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, | 3738 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, |
3497 true); | 3739 true); |
3498 const cricket::MediaConfig media_config = | 3740 const cricket::MediaConfig media_config = |
3499 TestCreatePeerConnection(config, &constraints); | 3741 TestCreatePeerConnection(config, &constraints); |
3500 | 3742 |
3501 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate); | 3743 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate); |
3502 } | 3744 } |
3503 | 3745 |
3504 // The following tests verify that session options are created correctly. | |
3505 // TODO(deadbeef): Convert these tests to be more end-to-end. Instead of | |
3506 // "verify options are converted correctly", should be "pass options into | |
3507 // CreateOffer and verify the correct offer is produced." | |
3508 | |
3509 TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) { | |
3510 RTCOfferAnswerOptions rtc_options; | |
3511 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1; | |
3512 | |
3513 cricket::MediaSessionOptions options; | |
3514 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
3515 | |
3516 rtc_options.offer_to_receive_audio = | |
3517 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; | |
3518 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
3519 } | |
3520 | |
3521 TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) { | |
3522 RTCOfferAnswerOptions rtc_options; | |
3523 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1; | |
3524 | |
3525 cricket::MediaSessionOptions options; | |
3526 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
3527 | |
3528 rtc_options.offer_to_receive_video = | |
3529 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; | |
3530 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
3531 } | |
3532 | |
3533 // Test that a MediaSessionOptions is created for an offer if | |
3534 // OfferToReceiveAudio and OfferToReceiveVideo options are set. | |
3535 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) { | |
3536 RTCOfferAnswerOptions rtc_options; | |
3537 rtc_options.offer_to_receive_audio = 1; | |
3538 rtc_options.offer_to_receive_video = 1; | |
3539 | |
3540 cricket::MediaSessionOptions options; | |
3541 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
3542 EXPECT_TRUE(options.has_audio()); | |
3543 EXPECT_TRUE(options.has_video()); | |
3544 EXPECT_TRUE(options.bundle_enabled); | |
3545 } | |
3546 | |
3547 // Test that a correct MediaSessionOptions is created for an offer if | |
3548 // OfferToReceiveAudio is set. | |
3549 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) { | |
3550 RTCOfferAnswerOptions rtc_options; | |
3551 rtc_options.offer_to_receive_audio = 1; | |
3552 | |
3553 cricket::MediaSessionOptions options; | |
3554 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
3555 EXPECT_TRUE(options.has_audio()); | |
3556 EXPECT_FALSE(options.has_video()); | |
3557 EXPECT_TRUE(options.bundle_enabled); | |
3558 } | |
3559 | |
3560 // Test that a correct MediaSessionOptions is created for an offer if | |
3561 // the default OfferOptions are used. | |
3562 TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) { | |
3563 RTCOfferAnswerOptions rtc_options; | |
3564 | |
3565 cricket::MediaSessionOptions options; | |
3566 options.transport_options["audio"] = cricket::TransportOptions(); | |
3567 options.transport_options["video"] = cricket::TransportOptions(); | |
3568 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
3569 EXPECT_TRUE(options.has_audio()); | |
3570 EXPECT_FALSE(options.has_video()); | |
3571 EXPECT_TRUE(options.bundle_enabled); | |
3572 EXPECT_TRUE(options.vad_enabled); | |
3573 EXPECT_FALSE(options.transport_options["audio"].ice_restart); | |
3574 EXPECT_FALSE(options.transport_options["video"].ice_restart); | |
3575 } | |
3576 | |
3577 // Test that a correct MediaSessionOptions is created for an offer if | |
3578 // OfferToReceiveVideo is set. | |
3579 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) { | |
3580 RTCOfferAnswerOptions rtc_options; | |
3581 rtc_options.offer_to_receive_audio = 0; | |
3582 rtc_options.offer_to_receive_video = 1; | |
3583 | |
3584 cricket::MediaSessionOptions options; | |
3585 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
3586 EXPECT_FALSE(options.has_audio()); | |
3587 EXPECT_TRUE(options.has_video()); | |
3588 EXPECT_TRUE(options.bundle_enabled); | |
3589 } | |
3590 | |
3591 // Test that a correct MediaSessionOptions is created for an offer if | |
3592 // UseRtpMux is set to false. | |
3593 TEST(CreateSessionOptionsTest, | |
3594 GetMediaSessionOptionsForOfferWithBundleDisabled) { | |
3595 RTCOfferAnswerOptions rtc_options; | |
3596 rtc_options.offer_to_receive_audio = 1; | |
3597 rtc_options.offer_to_receive_video = 1; | |
3598 rtc_options.use_rtp_mux = false; | |
3599 | |
3600 cricket::MediaSessionOptions options; | |
3601 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
3602 EXPECT_TRUE(options.has_audio()); | |
3603 EXPECT_TRUE(options.has_video()); | |
3604 EXPECT_FALSE(options.bundle_enabled); | |
3605 } | |
3606 | |
3607 // Test that a correct MediaSessionOptions is created to restart ice if | |
3608 // IceRestart is set. It also tests that subsequent MediaSessionOptions don't | |
3609 // have |audio_transport_options.ice_restart| etc. set. | |
3610 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) { | |
3611 RTCOfferAnswerOptions rtc_options; | |
3612 rtc_options.ice_restart = true; | |
3613 | |
3614 cricket::MediaSessionOptions options; | |
3615 options.transport_options["audio"] = cricket::TransportOptions(); | |
3616 options.transport_options["video"] = cricket::TransportOptions(); | |
3617 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
3618 EXPECT_TRUE(options.transport_options["audio"].ice_restart); | |
3619 EXPECT_TRUE(options.transport_options["video"].ice_restart); | |
3620 | |
3621 rtc_options = RTCOfferAnswerOptions(); | |
3622 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
3623 EXPECT_FALSE(options.transport_options["audio"].ice_restart); | |
3624 EXPECT_FALSE(options.transport_options["video"].ice_restart); | |
3625 } | |
3626 | |
3627 // Test that the MediaConstraints in an answer don't affect if audio and video | |
3628 // is offered in an offer but that if kOfferToReceiveAudio or | |
3629 // kOfferToReceiveVideo constraints are true in an offer, the media type will be | |
3630 // included in subsequent answers. | |
3631 TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) { | |
3632 FakeConstraints answer_c; | |
3633 answer_c.SetMandatoryReceiveAudio(true); | |
3634 answer_c.SetMandatoryReceiveVideo(true); | |
3635 | |
3636 cricket::MediaSessionOptions answer_options; | |
3637 EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options)); | |
3638 EXPECT_TRUE(answer_options.has_audio()); | |
3639 EXPECT_TRUE(answer_options.has_video()); | |
3640 | |
3641 RTCOfferAnswerOptions rtc_offer_options; | |
3642 | |
3643 cricket::MediaSessionOptions offer_options; | |
3644 EXPECT_TRUE( | |
3645 ExtractMediaSessionOptions(rtc_offer_options, false, &offer_options)); | |
3646 EXPECT_TRUE(offer_options.has_audio()); | |
3647 EXPECT_TRUE(offer_options.has_video()); | |
3648 | |
3649 RTCOfferAnswerOptions updated_rtc_offer_options; | |
3650 updated_rtc_offer_options.offer_to_receive_audio = 1; | |
3651 updated_rtc_offer_options.offer_to_receive_video = 1; | |
3652 | |
3653 cricket::MediaSessionOptions updated_offer_options; | |
3654 EXPECT_TRUE(ExtractMediaSessionOptions(updated_rtc_offer_options, false, | |
3655 &updated_offer_options)); | |
3656 EXPECT_TRUE(updated_offer_options.has_audio()); | |
3657 EXPECT_TRUE(updated_offer_options.has_video()); | |
3658 | |
3659 // Since an offer has been created with both audio and video, subsequent | |
3660 // offers and answers should contain both audio and video. | |
3661 // Answers will only contain the media types that exist in the offer | |
3662 // regardless of the value of |updated_answer_options.has_audio| and | |
3663 // |updated_answer_options.has_video|. | |
3664 FakeConstraints updated_answer_c; | |
3665 answer_c.SetMandatoryReceiveAudio(false); | |
3666 answer_c.SetMandatoryReceiveVideo(false); | |
3667 | |
3668 cricket::MediaSessionOptions updated_answer_options; | |
3669 EXPECT_TRUE( | |
3670 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); | |
3671 EXPECT_TRUE(updated_answer_options.has_audio()); | |
3672 EXPECT_TRUE(updated_answer_options.has_video()); | |
3673 } | |
3674 | |
3675 // Tests a few random fields being different. | 3746 // Tests a few random fields being different. |
3676 TEST(RTCConfigurationTest, ComparisonOperators) { | 3747 TEST(RTCConfigurationTest, ComparisonOperators) { |
3677 PeerConnectionInterface::RTCConfiguration a; | 3748 PeerConnectionInterface::RTCConfiguration a; |
3678 PeerConnectionInterface::RTCConfiguration b; | 3749 PeerConnectionInterface::RTCConfiguration b; |
3679 EXPECT_EQ(a, b); | 3750 EXPECT_EQ(a, b); |
3680 | 3751 |
3681 PeerConnectionInterface::RTCConfiguration c; | 3752 PeerConnectionInterface::RTCConfiguration c; |
3682 c.servers.push_back(PeerConnectionInterface::IceServer()); | 3753 c.servers.push_back(PeerConnectionInterface::IceServer()); |
3683 EXPECT_NE(a, c); | 3754 EXPECT_NE(a, c); |
3684 | 3755 |
(...skipping 10 matching lines...) Expand all Loading... | |
3695 EXPECT_NE(a, f); | 3766 EXPECT_NE(a, f); |
3696 | 3767 |
3697 PeerConnectionInterface::RTCConfiguration g; | 3768 PeerConnectionInterface::RTCConfiguration g; |
3698 g.disable_ipv6 = true; | 3769 g.disable_ipv6 = true; |
3699 EXPECT_NE(a, g); | 3770 EXPECT_NE(a, g); |
3700 | 3771 |
3701 PeerConnectionInterface::RTCConfiguration h( | 3772 PeerConnectionInterface::RTCConfiguration h( |
3702 PeerConnectionInterface::RTCConfigurationType::kAggressive); | 3773 PeerConnectionInterface::RTCConfigurationType::kAggressive); |
3703 EXPECT_NE(a, h); | 3774 EXPECT_NE(a, h); |
3704 } | 3775 } |
OLD | NEW |