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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 std::string& msg) = 0; | 139 std::string& msg) = 0; |
140 virtual void ReceiveIceMessage(const std::string& sdp_mid, | 140 virtual void ReceiveIceMessage(const std::string& sdp_mid, |
141 int sdp_mline_index, | 141 int sdp_mline_index, |
142 const std::string& msg) = 0; | 142 const std::string& msg) = 0; |
143 | 143 |
144 protected: | 144 protected: |
145 SignalingMessageReceiver() {} | 145 SignalingMessageReceiver() {} |
146 virtual ~SignalingMessageReceiver() {} | 146 virtual ~SignalingMessageReceiver() {} |
147 }; | 147 }; |
148 | 148 |
149 class MockRtpReceiverObserver : public webrtc::RtpReceiverObserverInterface { | |
150 public: | |
151 MockRtpReceiverObserver(cricket::MediaType media_type) | |
152 : expected_media_type_(media_type) {} | |
153 | |
154 void OnFirstPacketReceived(cricket::MediaType media_type) override { | |
155 ASSERT_EQ(expected_media_type_, media_type); | |
156 first_packet_received_ = true; | |
157 } | |
158 | |
159 bool first_packet_received() { return first_packet_received_; } | |
160 | |
161 virtual ~MockRtpReceiverObserver() {} | |
162 | |
163 private: | |
164 bool first_packet_received_ = false; | |
165 cricket::MediaType expected_media_type_; | |
166 }; | |
167 | |
149 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, | 168 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, |
150 public SignalingMessageReceiver, | 169 public SignalingMessageReceiver, |
151 public ObserverInterface { | 170 public ObserverInterface { |
152 public: | 171 public: |
153 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore( | 172 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore( |
154 const std::string& id, | 173 const std::string& id, |
155 const MediaConstraintsInterface* constraints, | 174 const MediaConstraintsInterface* constraints, |
156 const PeerConnectionFactory::Options* options, | 175 const PeerConnectionFactory::Options* options, |
157 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, | 176 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
158 bool prefer_constraint_apis, | 177 bool prefer_constraint_apis, |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 } | 792 } |
774 | 793 |
775 webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() { | 794 webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() { |
776 return pc()->ice_connection_state(); | 795 return pc()->ice_connection_state(); |
777 } | 796 } |
778 | 797 |
779 webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() { | 798 webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() { |
780 return pc()->ice_gathering_state(); | 799 return pc()->ice_gathering_state(); |
781 } | 800 } |
782 | 801 |
802 std::vector<std::unique_ptr<MockRtpReceiverObserver>> const& | |
803 rtp_receiver_observers() { | |
804 return rtp_receiver_observers_; | |
805 } | |
806 | |
807 void SetRtpReceiverObservers() { | |
808 rtp_receiver_observers_.clear(); | |
809 for (auto receiver : pc()->GetReceivers()) { | |
810 std::unique_ptr<MockRtpReceiverObserver> observer( | |
811 new MockRtpReceiverObserver(receiver->media_type())); | |
812 receiver->SetObserver(observer.get()); | |
813 rtp_receiver_observers_.push_back(std::move(observer)); | |
814 } | |
815 } | |
816 | |
783 private: | 817 private: |
784 class DummyDtmfObserver : public DtmfSenderObserverInterface { | 818 class DummyDtmfObserver : public DtmfSenderObserverInterface { |
785 public: | 819 public: |
786 DummyDtmfObserver() : completed_(false) {} | 820 DummyDtmfObserver() : completed_(false) {} |
787 | 821 |
788 // Implements DtmfSenderObserverInterface. | 822 // Implements DtmfSenderObserverInterface. |
789 void OnToneChange(const std::string& tone) override { | 823 void OnToneChange(const std::string& tone) override { |
790 tones_.push_back(tone); | 824 tones_.push_back(tone); |
791 if (tone.empty()) { | 825 if (tone.empty()) { |
792 completed_ = true; | 826 completed_ = true; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
863 | 897 |
864 void HandleIncomingOffer(const std::string& msg) { | 898 void HandleIncomingOffer(const std::string& msg) { |
865 LOG(INFO) << id_ << "HandleIncomingOffer "; | 899 LOG(INFO) << id_ << "HandleIncomingOffer "; |
866 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { | 900 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { |
867 // If we are not sending any streams ourselves it is time to add some. | 901 // If we are not sending any streams ourselves it is time to add some. |
868 AddMediaStream(true, true); | 902 AddMediaStream(true, true); |
869 } | 903 } |
870 std::unique_ptr<SessionDescriptionInterface> desc( | 904 std::unique_ptr<SessionDescriptionInterface> desc( |
871 webrtc::CreateSessionDescription("offer", msg, nullptr)); | 905 webrtc::CreateSessionDescription("offer", msg, nullptr)); |
872 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); | 906 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); |
907 // Set the RtpReceiverObserver after receivers are created. | |
908 SetRtpReceiverObservers(); | |
873 std::unique_ptr<SessionDescriptionInterface> answer; | 909 std::unique_ptr<SessionDescriptionInterface> answer; |
874 EXPECT_TRUE(DoCreateAnswer(&answer)); | 910 EXPECT_TRUE(DoCreateAnswer(&answer)); |
875 std::string sdp; | 911 std::string sdp; |
876 EXPECT_TRUE(answer->ToString(&sdp)); | 912 EXPECT_TRUE(answer->ToString(&sdp)); |
877 EXPECT_TRUE(DoSetLocalDescription(answer.release())); | 913 EXPECT_TRUE(DoSetLocalDescription(answer.release())); |
878 if (signaling_message_receiver_) { | 914 if (signaling_message_receiver_) { |
879 signaling_message_receiver_->ReceiveSdpMessage( | 915 signaling_message_receiver_->ReceiveSdpMessage( |
880 webrtc::SessionDescriptionInterface::kAnswer, sdp); | 916 webrtc::SessionDescriptionInterface::kAnswer, sdp); |
881 } | 917 } |
882 } | 918 } |
883 | 919 |
884 void HandleIncomingAnswer(const std::string& msg) { | 920 void HandleIncomingAnswer(const std::string& msg) { |
885 LOG(INFO) << id_ << "HandleIncomingAnswer"; | 921 LOG(INFO) << id_ << "HandleIncomingAnswer"; |
886 std::unique_ptr<SessionDescriptionInterface> desc( | 922 std::unique_ptr<SessionDescriptionInterface> desc( |
887 webrtc::CreateSessionDescription("answer", msg, nullptr)); | 923 webrtc::CreateSessionDescription("answer", msg, nullptr)); |
888 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); | 924 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); |
925 // Set the RtpReceiverObserver after receivers are created. | |
926 SetRtpReceiverObservers(); | |
889 } | 927 } |
890 | 928 |
891 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, | 929 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, |
892 bool offer) { | 930 bool offer) { |
893 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> | 931 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> |
894 observer(new rtc::RefCountedObject< | 932 observer(new rtc::RefCountedObject< |
895 MockCreateSessionDescriptionObserver>()); | 933 MockCreateSessionDescriptionObserver>()); |
896 if (prefer_constraint_apis_) { | 934 if (prefer_constraint_apis_) { |
897 if (offer) { | 935 if (offer) { |
898 pc()->CreateOffer(observer, &offer_answer_constraints_); | 936 pc()->CreateOffer(observer, &offer_answer_constraints_); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1019 bool remove_bundle_ = | 1057 bool remove_bundle_ = |
1020 false; // True if bundle should be removed in received SDP. | 1058 false; // True if bundle should be removed in received SDP. |
1021 bool remove_sdes_ = | 1059 bool remove_sdes_ = |
1022 false; // True if a=crypto should be removed in received SDP. | 1060 false; // True if a=crypto should be removed in received SDP. |
1023 // |remove_cvo_| is true if extension urn:3gpp:video-orientation should be | 1061 // |remove_cvo_| is true if extension urn:3gpp:video-orientation should be |
1024 // removed in the received SDP. | 1062 // removed in the received SDP. |
1025 bool remove_cvo_ = false; | 1063 bool remove_cvo_ = false; |
1026 | 1064 |
1027 rtc::scoped_refptr<DataChannelInterface> data_channel_; | 1065 rtc::scoped_refptr<DataChannelInterface> data_channel_; |
1028 std::unique_ptr<MockDataChannelObserver> data_observer_; | 1066 std::unique_ptr<MockDataChannelObserver> data_observer_; |
1067 | |
1068 std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_; | |
1029 }; | 1069 }; |
1030 | 1070 |
1031 class P2PTestConductor : public testing::Test { | 1071 class P2PTestConductor : public testing::Test { |
1032 public: | 1072 public: |
1033 P2PTestConductor() | 1073 P2PTestConductor() |
1034 : pss_(new rtc::PhysicalSocketServer), | 1074 : pss_(new rtc::PhysicalSocketServer), |
1035 ss_(new rtc::VirtualSocketServer(pss_.get())), | 1075 ss_(new rtc::VirtualSocketServer(pss_.get())), |
1036 network_thread_(new rtc::Thread(ss_.get())), | 1076 network_thread_(new rtc::Thread(ss_.get())), |
1037 worker_thread_(rtc::Thread::Create()) { | 1077 worker_thread_(rtc::Thread::Create()) { |
1038 RTC_CHECK(network_thread_->Start()); | 1078 RTC_CHECK(network_thread_->Start()); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1307 | 1347 |
1308 // Set the |receiving_client_| to the |client| passed in and return the | 1348 // Set the |receiving_client_| to the |client| passed in and return the |
1309 // original |receiving_client_|. | 1349 // original |receiving_client_|. |
1310 PeerConnectionTestClient* set_receiving_client( | 1350 PeerConnectionTestClient* set_receiving_client( |
1311 PeerConnectionTestClient* client) { | 1351 PeerConnectionTestClient* client) { |
1312 PeerConnectionTestClient* old = receiving_client_.release(); | 1352 PeerConnectionTestClient* old = receiving_client_.release(); |
1313 receiving_client_.reset(client); | 1353 receiving_client_.reset(client); |
1314 return old; | 1354 return old; |
1315 } | 1355 } |
1316 | 1356 |
1357 void CheckRtpReceiverObserverAreCalled(PeerConnectionTestClient* client) { | |
pthatcher1
2016/06/13 23:27:27
This should probably be:
EXPECT_TRUE_WAIT(std::al
| |
1358 for (auto const& observer : client->rtp_receiver_observers()) { | |
1359 EXPECT_TRUE_WAIT(observer->first_packet_received(), kMaxWaitForFramesMs); | |
1360 } | |
1361 } | |
1362 | |
1317 private: | 1363 private: |
1318 // |ss_| is used by |network_thread_| so it must be destroyed later. | 1364 // |ss_| is used by |network_thread_| so it must be destroyed later. |
1319 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 1365 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
1320 std::unique_ptr<rtc::VirtualSocketServer> ss_; | 1366 std::unique_ptr<rtc::VirtualSocketServer> ss_; |
1321 // |network_thread_| and |worker_thread_| are used by both | 1367 // |network_thread_| and |worker_thread_| are used by both |
1322 // |initiating_client_| and |receiving_client_| so they must be destroyed | 1368 // |initiating_client_| and |receiving_client_| so they must be destroyed |
1323 // later. | 1369 // later. |
1324 std::unique_ptr<rtc::Thread> network_thread_; | 1370 std::unique_ptr<rtc::Thread> network_thread_; |
1325 std::unique_ptr<rtc::Thread> worker_thread_; | 1371 std::unique_ptr<rtc::Thread> worker_thread_; |
1326 std::unique_ptr<PeerConnectionTestClient> initiating_client_; | 1372 std::unique_ptr<PeerConnectionTestClient> initiating_client_; |
1327 std::unique_ptr<PeerConnectionTestClient> receiving_client_; | 1373 std::unique_ptr<PeerConnectionTestClient> receiving_client_; |
1328 bool prefer_constraint_apis_ = true; | 1374 bool prefer_constraint_apis_ = true; |
1329 }; | 1375 }; |
1330 | 1376 |
1331 // Disable for TSan v2, see | 1377 // Disable for TSan v2, see |
1332 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. | 1378 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
1333 #if !defined(THREAD_SANITIZER) | 1379 #if !defined(THREAD_SANITIZER) |
1334 | 1380 |
1381 TEST_F(P2PTestConductor, TestRtpReceiverObserverCallbackFunction) { | |
1382 ASSERT_TRUE(CreateTestClients()); | |
1383 LocalP2PTest(); | |
1384 CheckRtpReceiverObserverAreCalled(initializing_client()); | |
1385 CheckRtpReceiverObserverAreCalled(receiving_client()); | |
1386 } | |
1387 | |
1388 // The observers are expected to fire the signal even if they are set after the | |
1389 // first packet is received. | |
1390 TEST_F(P2PTestConductor, TestSetRtpReceiverObserverAfterFirstPacketIsReceived) { | |
1391 ASSERT_TRUE(CreateTestClients()); | |
1392 LocalP2PTest(); | |
1393 // Reset the RtpReceiverObservers. | |
1394 initializing_client()->SetRtpReceiverObservers(); | |
1395 receiving_client()->SetRtpReceiverObservers(); | |
1396 CheckRtpReceiverObserverAreCalled(initializing_client()); | |
1397 CheckRtpReceiverObserverAreCalled(receiving_client()); | |
1398 } | |
1399 | |
1335 // This test sets up a Jsep call between two parties and test Dtmf. | 1400 // This test sets up a Jsep call between two parties and test Dtmf. |
1336 // TODO(holmer): Disabled due to sometimes crashing on buildbots. | 1401 // TODO(holmer): Disabled due to sometimes crashing on buildbots. |
1337 // See issue webrtc/2378. | 1402 // See issue webrtc/2378. |
1338 TEST_F(P2PTestConductor, DISABLED_LocalP2PTestDtmf) { | 1403 TEST_F(P2PTestConductor, DISABLED_LocalP2PTestDtmf) { |
1339 ASSERT_TRUE(CreateTestClients()); | 1404 ASSERT_TRUE(CreateTestClients()); |
1340 LocalP2PTest(); | 1405 LocalP2PTest(); |
1341 VerifyDtmf(); | 1406 VerifyDtmf(); |
1342 } | 1407 } |
1343 | 1408 |
1344 // This test sets up a Jsep call between two parties and test that we can get a | 1409 // This test sets up a Jsep call between two parties and test that we can get a |
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2214 server.urls.push_back("turn:hostname2"); | 2279 server.urls.push_back("turn:hostname2"); |
2215 servers.push_back(server); | 2280 servers.push_back(server); |
2216 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); | 2281 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); |
2217 EXPECT_EQ(2U, turn_servers_.size()); | 2282 EXPECT_EQ(2U, turn_servers_.size()); |
2218 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); | 2283 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); |
2219 } | 2284 } |
2220 | 2285 |
2221 #endif // if !defined(THREAD_SANITIZER) | 2286 #endif // if !defined(THREAD_SANITIZER) |
2222 | 2287 |
2223 } // namespace | 2288 } // namespace |
OLD | NEW |