Chromium Code Reviews| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 "a=ssrc:1 mslabel:stream1\r\n" | 84 "a=ssrc:1 mslabel:stream1\r\n" |
| 85 "a=ssrc:1 label:audiotrack0\r\n" | 85 "a=ssrc:1 label:audiotrack0\r\n" |
| 86 "m=video 1 RTP/AVPF 120\r\n" | 86 "m=video 1 RTP/AVPF 120\r\n" |
| 87 "a=mid:video\r\n" | 87 "a=mid:video\r\n" |
| 88 "a=sendrecv\r\n" | 88 "a=sendrecv\r\n" |
| 89 "a=rtpmap:120 VP8/90000\r\n" | 89 "a=rtpmap:120 VP8/90000\r\n" |
| 90 "a=ssrc:2 cname:stream1\r\n" | 90 "a=ssrc:2 cname:stream1\r\n" |
| 91 "a=ssrc:2 mslabel:stream1\r\n" | 91 "a=ssrc:2 mslabel:stream1\r\n" |
| 92 "a=ssrc:2 label:videotrack0\r\n"; | 92 "a=ssrc:2 label:videotrack0\r\n"; |
| 93 | 93 |
| 94 // Reference SDP with a MediaStream with label "stream1" and audio track with | |
| 95 // id "audio_1"; | |
| 96 static const char kSdpStringWithStream1AudioTrackOnly[] = | |
| 97 "v=0\r\n" | |
| 98 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 99 "s=-\r\n" | |
| 100 "t=0 0\r\n" | |
| 101 "a=ice-ufrag:e5785931\r\n" | |
| 102 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 103 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 104 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 105 "m=audio 1 RTP/AVPF 103\r\n" | |
| 106 "a=mid:audio\r\n" | |
| 107 "a=sendrecv\r\n" | |
| 108 "a=rtpmap:103 ISAC/16000\r\n" | |
| 109 "a=ssrc:1 cname:stream1\r\n" | |
| 110 "a=ssrc:1 mslabel:stream1\r\n" | |
| 111 "a=ssrc:1 label:audiotrack0\r\n"; | |
| 112 | |
| 94 // Reference SDP with two MediaStreams with label "stream1" and "stream2. Each | 113 // Reference SDP with two MediaStreams with label "stream1" and "stream2. Each |
| 95 // MediaStreams have one audio track and one video track. | 114 // MediaStreams have one audio track and one video track. |
| 96 // This uses MSID. | 115 // This uses MSID. |
| 97 static const char kSdpStringWithStream1And2[] = | 116 static const char kSdpStringWithStream1And2[] = |
| 98 "v=0\r\n" | 117 "v=0\r\n" |
| 99 "o=- 0 0 IN IP4 127.0.0.1\r\n" | 118 "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 100 "s=-\r\n" | 119 "s=-\r\n" |
| 101 "t=0 0\r\n" | 120 "t=0 0\r\n" |
| 102 "a=ice-ufrag:e5785931\r\n" | 121 "a=ice-ufrag:e5785931\r\n" |
| 103 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | 122 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 } | 511 } |
| 493 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; } | 512 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; } |
| 494 void OnDataChannel( | 513 void OnDataChannel( |
| 495 rtc::scoped_refptr<DataChannelInterface> data_channel) override { | 514 rtc::scoped_refptr<DataChannelInterface> data_channel) override { |
| 496 last_datachannel_ = data_channel; | 515 last_datachannel_ = data_channel; |
| 497 } | 516 } |
| 498 | 517 |
| 499 void OnIceConnectionChange( | 518 void OnIceConnectionChange( |
| 500 PeerConnectionInterface::IceConnectionState new_state) override { | 519 PeerConnectionInterface::IceConnectionState new_state) override { |
| 501 EXPECT_EQ(pc_->ice_connection_state(), new_state); | 520 EXPECT_EQ(pc_->ice_connection_state(), new_state); |
| 502 callback_triggered = true; | 521 callback_triggered_ = true; |
| 503 } | 522 } |
| 504 void OnIceGatheringChange( | 523 void OnIceGatheringChange( |
| 505 PeerConnectionInterface::IceGatheringState new_state) override { | 524 PeerConnectionInterface::IceGatheringState new_state) override { |
| 506 EXPECT_EQ(pc_->ice_gathering_state(), new_state); | 525 EXPECT_EQ(pc_->ice_gathering_state(), new_state); |
| 507 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete; | 526 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete; |
| 508 callback_triggered = true; | 527 callback_triggered_ = true; |
| 509 } | 528 } |
| 510 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { | 529 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { |
| 511 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, | 530 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, |
| 512 pc_->ice_gathering_state()); | 531 pc_->ice_gathering_state()); |
| 513 | 532 |
| 514 std::string sdp; | 533 std::string sdp; |
| 515 EXPECT_TRUE(candidate->ToString(&sdp)); | 534 EXPECT_TRUE(candidate->ToString(&sdp)); |
| 516 EXPECT_LT(0u, sdp.size()); | 535 EXPECT_LT(0u, sdp.size()); |
| 517 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(), | 536 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(), |
| 518 candidate->sdp_mline_index(), sdp, NULL)); | 537 candidate->sdp_mline_index(), sdp, NULL)); |
| 519 EXPECT_TRUE(last_candidate_.get() != NULL); | 538 EXPECT_TRUE(last_candidate_.get() != NULL); |
| 520 callback_triggered = true; | 539 callback_triggered_ = true; |
| 521 } | 540 } |
| 522 | 541 |
| 523 void OnIceCandidatesRemoved( | 542 void OnIceCandidatesRemoved( |
| 524 const std::vector<cricket::Candidate>& candidates) override { | 543 const std::vector<cricket::Candidate>& candidates) override { |
| 525 callback_triggered = true; | 544 callback_triggered_ = true; |
| 526 } | 545 } |
| 527 | 546 |
| 528 void OnIceConnectionReceivingChange(bool receiving) override { | 547 void OnIceConnectionReceivingChange(bool receiving) override { |
| 529 callback_triggered = true; | 548 callback_triggered_ = true; |
| 549 } | |
| 550 | |
| 551 void OnAddTrack(rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver, | |
| 552 std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>> | |
| 553 streams) override { | |
| 554 EXPECT_TRUE(receiver != nullptr); | |
| 555 num_added_track_++; | |
| 556 last_added_track_label_ = receiver->id(); | |
| 530 } | 557 } |
| 531 | 558 |
| 532 // Returns the label of the last added stream. | 559 // Returns the label of the last added stream. |
| 533 // Empty string if no stream have been added. | 560 // Empty string if no stream have been added. |
| 534 std::string GetLastAddedStreamLabel() { | 561 std::string GetLastAddedStreamLabel() { |
| 535 if (last_added_stream_.get()) | 562 if (last_added_stream_.get()) |
| 536 return last_added_stream_->label(); | 563 return last_added_stream_->label(); |
| 537 return ""; | 564 return ""; |
| 538 } | 565 } |
| 539 std::string GetLastRemovedStreamLabel() { | 566 std::string GetLastRemovedStreamLabel() { |
| 540 if (last_removed_stream_.get()) | 567 if (last_removed_stream_.get()) |
| 541 return last_removed_stream_->label(); | 568 return last_removed_stream_->label(); |
| 542 return ""; | 569 return ""; |
| 543 } | 570 } |
| 544 | 571 |
| 545 rtc::scoped_refptr<PeerConnectionInterface> pc_; | 572 rtc::scoped_refptr<PeerConnectionInterface> pc_; |
| 546 PeerConnectionInterface::SignalingState state_; | 573 PeerConnectionInterface::SignalingState state_; |
| 547 std::unique_ptr<IceCandidateInterface> last_candidate_; | 574 std::unique_ptr<IceCandidateInterface> last_candidate_; |
| 548 rtc::scoped_refptr<DataChannelInterface> last_datachannel_; | 575 rtc::scoped_refptr<DataChannelInterface> last_datachannel_; |
| 549 rtc::scoped_refptr<StreamCollection> remote_streams_; | 576 rtc::scoped_refptr<StreamCollection> remote_streams_; |
| 550 bool renegotiation_needed_ = false; | 577 bool renegotiation_needed_ = false; |
| 551 bool ice_complete_ = false; | 578 bool ice_complete_ = false; |
| 552 bool callback_triggered = false; | 579 bool callback_triggered_ = false; |
| 580 int num_added_track_ = 0; | |
|
Taylor Brandstetter
2016/11/17 00:34:23
nit: I'd change this to "num_added_tracks_", plura
Zhi Huang
2016/11/17 01:42:06
Done.
I also removed the initialization of last_a
| |
| 581 std::string last_added_track_label_ = ""; | |
| 553 | 582 |
| 554 private: | 583 private: |
| 555 rtc::scoped_refptr<MediaStreamInterface> last_added_stream_; | 584 rtc::scoped_refptr<MediaStreamInterface> last_added_stream_; |
| 556 rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_; | 585 rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_; |
| 557 }; | 586 }; |
| 558 | 587 |
| 559 } // namespace | 588 } // namespace |
| 560 | 589 |
| 561 // The PeerConnectionMediaConfig tests below verify that configuration | 590 // The PeerConnectionMediaConfig tests below verify that configuration |
| 562 // and constraints are propagated into the MediaConfig passed to | 591 // and constraints are propagated into the MediaConfig passed to |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1063 // PeerConnection is closed. | 1092 // PeerConnection is closed. |
| 1064 TEST_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) { | 1093 TEST_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) { |
| 1065 rtc::scoped_refptr<PeerConnectionInterface> pc( | 1094 rtc::scoped_refptr<PeerConnectionInterface> pc( |
| 1066 pc_factory_for_test_->CreatePeerConnection( | 1095 pc_factory_for_test_->CreatePeerConnection( |
| 1067 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr, | 1096 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr, |
| 1068 nullptr, &observer_)); | 1097 nullptr, &observer_)); |
| 1069 observer_.SetPeerConnectionInterface(pc.get()); | 1098 observer_.SetPeerConnectionInterface(pc.get()); |
| 1070 pc->Close(); | 1099 pc->Close(); |
| 1071 | 1100 |
| 1072 // No callbacks is expected to be called. | 1101 // No callbacks is expected to be called. |
| 1073 observer_.callback_triggered = false; | 1102 observer_.callback_triggered_ = false; |
| 1074 std::vector<cricket::Candidate> candidates; | 1103 std::vector<cricket::Candidate> candidates; |
| 1075 pc_factory_for_test_->transport_controller->SignalGatheringState( | 1104 pc_factory_for_test_->transport_controller->SignalGatheringState( |
| 1076 cricket::IceGatheringState{}); | 1105 cricket::IceGatheringState{}); |
| 1077 pc_factory_for_test_->transport_controller->SignalCandidatesGathered( | 1106 pc_factory_for_test_->transport_controller->SignalCandidatesGathered( |
| 1078 "", candidates); | 1107 "", candidates); |
| 1079 pc_factory_for_test_->transport_controller->SignalConnectionState( | 1108 pc_factory_for_test_->transport_controller->SignalConnectionState( |
| 1080 cricket::IceConnectionState{}); | 1109 cricket::IceConnectionState{}); |
| 1081 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved( | 1110 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved( |
| 1082 candidates); | 1111 candidates); |
| 1083 pc_factory_for_test_->transport_controller->SignalReceiving(false); | 1112 pc_factory_for_test_->transport_controller->SignalReceiving(false); |
| 1084 EXPECT_FALSE(observer_.callback_triggered); | 1113 EXPECT_FALSE(observer_.callback_triggered_); |
| 1085 } | 1114 } |
| 1086 | 1115 |
| 1087 // Generate different CNAMEs when PeerConnections are created. | 1116 // Generate different CNAMEs when PeerConnections are created. |
| 1088 // The CNAMEs are expected to be generated randomly. It is possible | 1117 // The CNAMEs are expected to be generated randomly. It is possible |
| 1089 // that the test fails, though the possibility is very low. | 1118 // that the test fails, though the possibility is very low. |
| 1090 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) { | 1119 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) { |
| 1091 std::unique_ptr<SessionDescriptionInterface> offer1 = | 1120 std::unique_ptr<SessionDescriptionInterface> offer1 = |
| 1092 CreateOfferWithOneAudioStream(); | 1121 CreateOfferWithOneAudioStream(); |
| 1093 std::unique_ptr<SessionDescriptionInterface> offer2 = | 1122 std::unique_ptr<SessionDescriptionInterface> offer2 = |
| 1094 CreateOfferWithOneAudioStream(); | 1123 CreateOfferWithOneAudioStream(); |
| (...skipping 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2633 | 2662 |
| 2634 auto new_senders = pc_->GetSenders(); | 2663 auto new_senders = pc_->GetSenders(); |
| 2635 // Should be the same senders as before, but with updated stream id. | 2664 // Should be the same senders as before, but with updated stream id. |
| 2636 // Note that this behavior is subject to change in the future. | 2665 // Note that this behavior is subject to change in the future. |
| 2637 // We may decide the PC should ignore existing tracks in AddStream. | 2666 // We may decide the PC should ignore existing tracks in AddStream. |
| 2638 EXPECT_EQ(senders, new_senders); | 2667 EXPECT_EQ(senders, new_senders); |
| 2639 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); | 2668 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); |
| 2640 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); | 2669 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); |
| 2641 } | 2670 } |
| 2642 | 2671 |
| 2672 // This tests the PeerConnectionObserver::OnAddTrack are correctly called. | |
|
Taylor Brandstetter
2016/11/17 00:34:23
nit: "the" -> "that", "are" -> "is"
Zhi Huang
2016/11/17 01:42:06
Done.
| |
| 2673 TEST_F(PeerConnectionInterfaceTest, OnAddTrackCallback) { | |
| 2674 FakeConstraints constraints; | |
| 2675 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2676 true); | |
| 2677 CreatePeerConnection(&constraints); | |
| 2678 observer_.num_added_track_ = 0; | |
| 2679 observer_.last_added_track_label_ = ""; | |
|
Taylor Brandstetter
2016/11/17 00:34:23
These don't need to be initialized here since they
Zhi Huang
2016/11/17 01:42:06
Done.
| |
| 2680 | |
| 2681 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly); | |
| 2682 EXPECT_EQ(observer_.num_added_track_, 1); | |
| 2683 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]); | |
| 2684 // Create and set the updated remote SDP. | |
| 2685 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2686 EXPECT_EQ(observer_.num_added_track_, 2); | |
| 2687 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]); | |
| 2688 | |
| 2689 // Clear the observer stats. | |
| 2690 observer_.num_added_track_ = 0; | |
| 2691 observer_.last_added_track_label_ = ""; | |
|
Taylor Brandstetter
2016/11/17 00:34:23
This isn't needed, since each test case completely
Zhi Huang
2016/11/17 01:42:06
Good to know. Thanks for the link!
| |
| 2692 } | |
| 2693 | |
| 2643 class PeerConnectionMediaConfigTest : public testing::Test { | 2694 class PeerConnectionMediaConfigTest : public testing::Test { |
| 2644 protected: | 2695 protected: |
| 2645 void SetUp() override { | 2696 void SetUp() override { |
| 2646 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); | 2697 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); |
| 2647 pcf_->Initialize(); | 2698 pcf_->Initialize(); |
| 2648 } | 2699 } |
| 2649 const cricket::MediaConfig& TestCreatePeerConnection( | 2700 const cricket::MediaConfig& TestCreatePeerConnection( |
| 2650 const PeerConnectionInterface::RTCConfiguration& config, | 2701 const PeerConnectionInterface::RTCConfiguration& config, |
| 2651 const MediaConstraintsInterface *constraints) { | 2702 const MediaConstraintsInterface *constraints) { |
| 2652 pcf_->create_media_controller_called_ = false; | 2703 pcf_->create_media_controller_called_ = false; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2896 FakeConstraints updated_answer_c; | 2947 FakeConstraints updated_answer_c; |
| 2897 answer_c.SetMandatoryReceiveAudio(false); | 2948 answer_c.SetMandatoryReceiveAudio(false); |
| 2898 answer_c.SetMandatoryReceiveVideo(false); | 2949 answer_c.SetMandatoryReceiveVideo(false); |
| 2899 | 2950 |
| 2900 cricket::MediaSessionOptions updated_answer_options; | 2951 cricket::MediaSessionOptions updated_answer_options; |
| 2901 EXPECT_TRUE( | 2952 EXPECT_TRUE( |
| 2902 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); | 2953 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); |
| 2903 EXPECT_TRUE(updated_answer_options.has_audio()); | 2954 EXPECT_TRUE(updated_answer_options.has_audio()); |
| 2904 EXPECT_TRUE(updated_answer_options.has_video()); | 2955 EXPECT_TRUE(updated_answer_options.has_video()); |
| 2905 } | 2956 } |
| OLD | NEW |