| 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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 452     // Add kTelephoneEventCodec for dtmf test. | 452     // Add kTelephoneEventCodec for dtmf test. | 
| 453     const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000, | 453     const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000, | 
| 454                                                    0, 1); | 454                                                    0, 1); | 
| 455     std::vector<cricket::AudioCodec> codecs; | 455     std::vector<cricket::AudioCodec> codecs; | 
| 456     codecs.push_back(kTelephoneEventCodec); | 456     codecs.push_back(kTelephoneEventCodec); | 
| 457     media_engine_->SetAudioCodecs(codecs); | 457     media_engine_->SetAudioCodecs(codecs); | 
| 458     desc_factory_->set_audio_codecs(codecs); | 458     desc_factory_->set_audio_codecs(codecs); | 
| 459     Init(); | 459     Init(); | 
| 460   } | 460   } | 
| 461 | 461 | 
|  | 462   void InitWithGcm() { | 
|  | 463     rtc::CryptoOptions crypto_options; | 
|  | 464     crypto_options.enable_gcm_crypto_suites = true; | 
|  | 465     channel_manager_->SetCryptoOptions(crypto_options); | 
|  | 466     with_gcm_ = true; | 
|  | 467     Init(); | 
|  | 468   } | 
|  | 469 | 
| 462   void SendAudioVideoStream1() { | 470   void SendAudioVideoStream1() { | 
| 463     send_stream_1_ = true; | 471     send_stream_1_ = true; | 
| 464     send_stream_2_ = false; | 472     send_stream_2_ = false; | 
| 465     send_audio_ = true; | 473     send_audio_ = true; | 
| 466     send_video_ = true; | 474     send_video_ = true; | 
| 467   } | 475   } | 
| 468 | 476 | 
| 469   void SendAudioVideoStream2() { | 477   void SendAudioVideoStream2() { | 
| 470     send_stream_1_ = false; | 478     send_stream_1_ = false; | 
| 471     send_stream_2_ = true; | 479     send_stream_2_ = true; | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 542           session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO); | 550           session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO); | 
| 543     } | 551     } | 
| 544     session_options->bundle_enabled = | 552     session_options->bundle_enabled = | 
| 545         session_options->bundle_enabled && | 553         session_options->bundle_enabled && | 
| 546         (session_options->has_audio() || session_options->has_video() || | 554         (session_options->has_audio() || session_options->has_video() || | 
| 547          session_options->has_data()); | 555          session_options->has_data()); | 
| 548 | 556 | 
| 549     if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) { | 557     if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) { | 
| 550       session_options->data_channel_type = cricket::DCT_SCTP; | 558       session_options->data_channel_type = cricket::DCT_SCTP; | 
| 551     } | 559     } | 
|  | 560 | 
|  | 561     if (with_gcm_) { | 
|  | 562       session_options->crypto_options.enable_gcm_crypto_suites = true; | 
|  | 563     } | 
| 552   } | 564   } | 
| 553 | 565 | 
| 554   void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) { | 566   void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) { | 
| 555     // ParseConstraintsForAnswer is used to set some defaults. | 567     // ParseConstraintsForAnswer is used to set some defaults. | 
| 556     ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options)); | 568     ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options)); | 
| 557 | 569 | 
| 558     AddStreamsToOptions(session_options); | 570     AddStreamsToOptions(session_options); | 
| 559     session_options->bundle_enabled = | 571     session_options->bundle_enabled = | 
| 560         session_options->bundle_enabled && | 572         session_options->bundle_enabled && | 
| 561         (session_options->has_audio() || session_options->has_video() || | 573         (session_options->has_audio() || session_options->has_video() || | 
| 562          session_options->has_data()); | 574          session_options->has_data()); | 
| 563 | 575 | 
| 564     if (session_->data_channel_type() == cricket::DCT_SCTP) { | 576     if (session_->data_channel_type() == cricket::DCT_SCTP) { | 
| 565       session_options->data_channel_type = cricket::DCT_SCTP; | 577       session_options->data_channel_type = cricket::DCT_SCTP; | 
| 566     } | 578     } | 
|  | 579 | 
|  | 580     if (with_gcm_) { | 
|  | 581       session_options->crypto_options.enable_gcm_crypto_suites = true; | 
|  | 582     } | 
| 567   } | 583   } | 
| 568 | 584 | 
| 569   // Creates a local offer and applies it. Starts ICE. | 585   // Creates a local offer and applies it. Starts ICE. | 
| 570   // Call SendAudioVideoStreamX() before this function | 586   // Call SendAudioVideoStreamX() before this function | 
| 571   // to decide which streams to create. | 587   // to decide which streams to create. | 
| 572   void InitiateCall() { | 588   void InitiateCall() { | 
| 573     SessionDescriptionInterface* offer = CreateOffer(); | 589     SessionDescriptionInterface* offer = CreateOffer(); | 
| 574     SetLocalDescriptionWithoutError(offer); | 590     SetLocalDescriptionWithoutError(offer); | 
| 575     EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != | 591     EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != | 
| 576         observer_.ice_gathering_state_, | 592         observer_.ice_gathering_state_, | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 619     options.recv_video = true; | 635     options.recv_video = true; | 
| 620     options.recv_audio = true; | 636     options.recv_audio = true; | 
| 621     return CreateAnswer(options); | 637     return CreateAnswer(options); | 
| 622   } | 638   } | 
| 623 | 639 | 
| 624   bool ChannelsExist() const { | 640   bool ChannelsExist() const { | 
| 625     return (session_->voice_channel() != NULL && | 641     return (session_->voice_channel() != NULL && | 
| 626             session_->video_channel() != NULL); | 642             session_->video_channel() != NULL); | 
| 627   } | 643   } | 
| 628 | 644 | 
| 629   void VerifyCryptoParams(const cricket::SessionDescription* sdp) { | 645   void VerifyCryptoParams(const cricket::SessionDescription* sdp, | 
|  | 646       bool gcm_enabled = false) { | 
| 630     ASSERT_TRUE(session_.get() != NULL); | 647     ASSERT_TRUE(session_.get() != NULL); | 
| 631     const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); | 648     const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); | 
| 632     ASSERT_TRUE(content != NULL); | 649     ASSERT_TRUE(content != NULL); | 
| 633     const cricket::AudioContentDescription* audio_content = | 650     const cricket::AudioContentDescription* audio_content = | 
| 634         static_cast<const cricket::AudioContentDescription*>( | 651         static_cast<const cricket::AudioContentDescription*>( | 
| 635             content->description); | 652             content->description); | 
| 636     ASSERT_TRUE(audio_content != NULL); | 653     ASSERT_TRUE(audio_content != NULL); | 
| 637     ASSERT_EQ(1U, audio_content->cryptos().size()); | 654     if (!gcm_enabled) { | 
| 638     ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size()); | 655       ASSERT_EQ(1U, audio_content->cryptos().size()); | 
| 639     ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", | 656       ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size()); | 
| 640               audio_content->cryptos()[0].cipher_suite); | 657       ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", | 
| 641     EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), | 658                 audio_content->cryptos()[0].cipher_suite); | 
| 642               audio_content->protocol()); | 659       EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), | 
|  | 660                 audio_content->protocol()); | 
|  | 661     } else { | 
|  | 662       // The offer contains 3 possible crypto suites, the answer 1. | 
|  | 663       EXPECT_LE(1U, audio_content->cryptos().size()); | 
|  | 664       EXPECT_NE(2U, audio_content->cryptos().size()); | 
|  | 665       EXPECT_GE(3U, audio_content->cryptos().size()); | 
|  | 666       ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size()); | 
|  | 667       ASSERT_EQ("AEAD_AES_256_GCM", | 
|  | 668                 audio_content->cryptos()[0].cipher_suite); | 
|  | 669       EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), | 
|  | 670                 audio_content->protocol()); | 
|  | 671     } | 
| 643 | 672 | 
| 644     content = cricket::GetFirstVideoContent(sdp); | 673     content = cricket::GetFirstVideoContent(sdp); | 
| 645     ASSERT_TRUE(content != NULL); | 674     ASSERT_TRUE(content != NULL); | 
| 646     const cricket::VideoContentDescription* video_content = | 675     const cricket::VideoContentDescription* video_content = | 
| 647         static_cast<const cricket::VideoContentDescription*>( | 676         static_cast<const cricket::VideoContentDescription*>( | 
| 648             content->description); | 677             content->description); | 
| 649     ASSERT_TRUE(video_content != NULL); | 678     ASSERT_TRUE(video_content != NULL); | 
| 650     ASSERT_EQ(1U, video_content->cryptos().size()); | 679     if (!gcm_enabled) { | 
| 651     ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", | 680       ASSERT_EQ(1U, video_content->cryptos().size()); | 
| 652               video_content->cryptos()[0].cipher_suite); | 681       ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", | 
| 653     ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size()); | 682                 video_content->cryptos()[0].cipher_suite); | 
| 654     EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), | 683       ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size()); | 
| 655               video_content->protocol()); | 684       EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), | 
|  | 685                 video_content->protocol()); | 
|  | 686     } else { | 
|  | 687       // The offer contains 3 possible crypto suites, the answer 1. | 
|  | 688       EXPECT_LE(1U, video_content->cryptos().size()); | 
|  | 689       EXPECT_NE(2U, video_content->cryptos().size()); | 
|  | 690       EXPECT_GE(3U, video_content->cryptos().size()); | 
|  | 691       ASSERT_EQ("AEAD_AES_256_GCM", | 
|  | 692                 video_content->cryptos()[0].cipher_suite); | 
|  | 693       ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size()); | 
|  | 694       EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), | 
|  | 695                 video_content->protocol()); | 
|  | 696     } | 
| 656   } | 697   } | 
| 657 | 698 | 
| 658   void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) { | 699   void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) { | 
| 659     const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); | 700     const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); | 
| 660     ASSERT_TRUE(content != NULL); | 701     ASSERT_TRUE(content != NULL); | 
| 661     const cricket::AudioContentDescription* audio_content = | 702     const cricket::AudioContentDescription* audio_content = | 
| 662         static_cast<const cricket::AudioContentDescription*>( | 703         static_cast<const cricket::AudioContentDescription*>( | 
| 663             content->description); | 704             content->description); | 
| 664     ASSERT_TRUE(audio_content != NULL); | 705     ASSERT_TRUE(audio_content != NULL); | 
| 665     ASSERT_EQ(0U, audio_content->cryptos().size()); | 706     ASSERT_EQ(0U, audio_content->cryptos().size()); | 
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1441   // The following flags affect options created for CreateOffer/CreateAnswer. | 1482   // The following flags affect options created for CreateOffer/CreateAnswer. | 
| 1442   bool send_stream_1_ = false; | 1483   bool send_stream_1_ = false; | 
| 1443   bool send_stream_2_ = false; | 1484   bool send_stream_2_ = false; | 
| 1444   bool send_audio_ = false; | 1485   bool send_audio_ = false; | 
| 1445   bool send_video_ = false; | 1486   bool send_video_ = false; | 
| 1446   rtc::scoped_refptr<DataChannel> data_channel_; | 1487   rtc::scoped_refptr<DataChannel> data_channel_; | 
| 1447   // Last values received from data channel creation signal. | 1488   // Last values received from data channel creation signal. | 
| 1448   std::string last_data_channel_label_; | 1489   std::string last_data_channel_label_; | 
| 1449   InternalDataChannelInit last_data_channel_config_; | 1490   InternalDataChannelInit last_data_channel_config_; | 
| 1450   bool session_destroyed_ = false; | 1491   bool session_destroyed_ = false; | 
|  | 1492   bool with_gcm_ = false; | 
| 1451 }; | 1493 }; | 
| 1452 | 1494 | 
| 1453 TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { | 1495 TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { | 
| 1454   InitWithDtls(GetParam()); | 1496   InitWithDtls(GetParam()); | 
| 1455   // SDES is disabled when DTLS is on. | 1497   // SDES is disabled when DTLS is on. | 
| 1456   EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); | 1498   EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); | 
| 1457 } | 1499 } | 
| 1458 | 1500 | 
| 1459 TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { | 1501 TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { | 
| 1460   Init(); | 1502   Init(); | 
| (...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2783 TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) { | 2825 TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) { | 
| 2784   Init(); | 2826   Init(); | 
| 2785   SendAudioVideoStream1(); | 2827   SendAudioVideoStream1(); | 
| 2786   std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); | 2828   std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); | 
| 2787   VerifyCryptoParams(offer->description()); | 2829   VerifyCryptoParams(offer->description()); | 
| 2788   SetRemoteDescriptionWithoutError(offer.release()); | 2830   SetRemoteDescriptionWithoutError(offer.release()); | 
| 2789   std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); | 2831   std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); | 
| 2790   VerifyCryptoParams(answer->description()); | 2832   VerifyCryptoParams(answer->description()); | 
| 2791 } | 2833 } | 
| 2792 | 2834 | 
|  | 2835 TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) { | 
|  | 2836   InitWithGcm(); | 
|  | 2837   SendAudioVideoStream1(); | 
|  | 2838   std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); | 
|  | 2839   VerifyCryptoParams(offer->description(), true); | 
|  | 2840   SetRemoteDescriptionWithoutError(offer.release()); | 
|  | 2841   std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); | 
|  | 2842   VerifyCryptoParams(answer->description(), true); | 
|  | 2843 } | 
|  | 2844 | 
| 2793 TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) { | 2845 TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) { | 
| 2794   options_.disable_encryption = true; | 2846   options_.disable_encryption = true; | 
| 2795   Init(); | 2847   Init(); | 
| 2796   SendAudioVideoStream1(); | 2848   SendAudioVideoStream1(); | 
| 2797   std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); | 2849   std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); | 
| 2798   VerifyNoCryptoParams(offer->description(), false); | 2850   VerifyNoCryptoParams(offer->description(), false); | 
| 2799 } | 2851 } | 
| 2800 | 2852 | 
| 2801 TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) { | 2853 TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) { | 
| 2802   Init(); | 2854   Init(); | 
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3354   EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL)); | 3406   EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL)); | 
| 3355   SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer); | 3407   SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer); | 
| 3356   JsepSessionDescription* remote_offer = | 3408   JsepSessionDescription* remote_offer = | 
| 3357       new JsepSessionDescription(JsepSessionDescription::kOffer); | 3409       new JsepSessionDescription(JsepSessionDescription::kOffer); | 
| 3358   EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL)); | 3410   EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL)); | 
| 3359   SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer); | 3411   SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer); | 
| 3360   // Trying unmodified SDP. | 3412   // Trying unmodified SDP. | 
| 3361   SetLocalDescriptionWithoutError(offer); | 3413   SetLocalDescriptionWithoutError(offer); | 
| 3362 } | 3414 } | 
| 3363 | 3415 | 
|  | 3416 TEST_F(WebRtcSessionTest, SetSetupGcm) { | 
|  | 3417   InitWithGcm(); | 
|  | 3418   SendAudioVideoStream1(); | 
|  | 3419   CreateAndSetRemoteOfferAndLocalAnswer(); | 
|  | 3420 } | 
|  | 3421 | 
| 3364 TEST_F(WebRtcSessionTest, SetAudioPlayout) { | 3422 TEST_F(WebRtcSessionTest, SetAudioPlayout) { | 
| 3365   Init(); | 3423   Init(); | 
| 3366   SendAudioVideoStream1(); | 3424   SendAudioVideoStream1(); | 
| 3367   CreateAndSetRemoteOfferAndLocalAnswer(); | 3425   CreateAndSetRemoteOfferAndLocalAnswer(); | 
| 3368   cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); | 3426   cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); | 
| 3369   ASSERT_TRUE(channel != NULL); | 3427   ASSERT_TRUE(channel != NULL); | 
| 3370   ASSERT_EQ(1u, channel->recv_streams().size()); | 3428   ASSERT_EQ(1u, channel->recv_streams().size()); | 
| 3371   uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc(); | 3429   uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc(); | 
| 3372   double volume; | 3430   double volume; | 
| 3373   EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume)); | 3431   EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume)); | 
| (...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4396 } | 4454 } | 
| 4397 | 4455 | 
| 4398 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled.  That test | 4456 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled.  That test | 
| 4399 // currently fails because upon disconnection and reconnection OnIceComplete is | 4457 // currently fails because upon disconnection and reconnection OnIceComplete is | 
| 4400 // called more than once without returning to IceGatheringGathering. | 4458 // called more than once without returning to IceGatheringGathering. | 
| 4401 | 4459 | 
| 4402 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, | 4460 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, | 
| 4403                         WebRtcSessionTest, | 4461                         WebRtcSessionTest, | 
| 4404                         testing::Values(ALREADY_GENERATED, | 4462                         testing::Values(ALREADY_GENERATED, | 
| 4405                                         DTLS_IDENTITY_STORE)); | 4463                                         DTLS_IDENTITY_STORE)); | 
| OLD | NEW | 
|---|