Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: webrtc/api/peerconnection_unittest.cc

Issue 1999853002: Forward the SignalFirstPacketReceived to RtpReceiver. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Modified the unit test. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/mediastreamprovider.h ('k') | webrtc/api/rtpreceiver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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
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 bool AllObserversReceived(
1358 const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& observers) {
1359 for (auto& observer : observers) {
1360 if (!observer->first_packet_received()) {
1361 return false;
1362 }
1363 }
1364 return true;
1365 }
1366
1317 private: 1367 private:
1318 // |ss_| is used by |network_thread_| so it must be destroyed later. 1368 // |ss_| is used by |network_thread_| so it must be destroyed later.
1319 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 1369 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1320 std::unique_ptr<rtc::VirtualSocketServer> ss_; 1370 std::unique_ptr<rtc::VirtualSocketServer> ss_;
1321 // |network_thread_| and |worker_thread_| are used by both 1371 // |network_thread_| and |worker_thread_| are used by both
1322 // |initiating_client_| and |receiving_client_| so they must be destroyed 1372 // |initiating_client_| and |receiving_client_| so they must be destroyed
1323 // later. 1373 // later.
1324 std::unique_ptr<rtc::Thread> network_thread_; 1374 std::unique_ptr<rtc::Thread> network_thread_;
1325 std::unique_ptr<rtc::Thread> worker_thread_; 1375 std::unique_ptr<rtc::Thread> worker_thread_;
1326 std::unique_ptr<PeerConnectionTestClient> initiating_client_; 1376 std::unique_ptr<PeerConnectionTestClient> initiating_client_;
1327 std::unique_ptr<PeerConnectionTestClient> receiving_client_; 1377 std::unique_ptr<PeerConnectionTestClient> receiving_client_;
1328 bool prefer_constraint_apis_ = true; 1378 bool prefer_constraint_apis_ = true;
1329 }; 1379 };
1330 1380
1331 // Disable for TSan v2, see 1381 // Disable for TSan v2, see
1332 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. 1382 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
1333 #if !defined(THREAD_SANITIZER) 1383 #if !defined(THREAD_SANITIZER)
1334 1384
1385 TEST_F(P2PTestConductor, TestRtpReceiverObserverCallbackFunction) {
1386 ASSERT_TRUE(CreateTestClients());
1387 LocalP2PTest();
1388 EXPECT_TRUE_WAIT(
1389 AllObserversReceived(initializing_client()->rtp_receiver_observers()),
1390 kMaxWaitForFramesMs);
1391 EXPECT_TRUE_WAIT(
1392 AllObserversReceived(receiving_client()->rtp_receiver_observers()),
1393 kMaxWaitForFramesMs);
1394 }
1395
1396 // The observers are expected to fire the signal even if they are set after the
1397 // first packet is received.
1398 TEST_F(P2PTestConductor, TestSetRtpReceiverObserverAfterFirstPacketIsReceived) {
1399 ASSERT_TRUE(CreateTestClients());
1400 LocalP2PTest();
1401 // Reset the RtpReceiverObservers.
1402 initializing_client()->SetRtpReceiverObservers();
1403 receiving_client()->SetRtpReceiverObservers();
1404 EXPECT_TRUE_WAIT(
1405 AllObserversReceived(initializing_client()->rtp_receiver_observers()),
1406 kMaxWaitForFramesMs);
1407 EXPECT_TRUE_WAIT(
1408 AllObserversReceived(receiving_client()->rtp_receiver_observers()),
1409 kMaxWaitForFramesMs);
1410 }
1411
1335 // This test sets up a Jsep call between two parties and test Dtmf. 1412 // This test sets up a Jsep call between two parties and test Dtmf.
1336 // TODO(holmer): Disabled due to sometimes crashing on buildbots. 1413 // TODO(holmer): Disabled due to sometimes crashing on buildbots.
1337 // See issue webrtc/2378. 1414 // See issue webrtc/2378.
1338 TEST_F(P2PTestConductor, DISABLED_LocalP2PTestDtmf) { 1415 TEST_F(P2PTestConductor, DISABLED_LocalP2PTestDtmf) {
1339 ASSERT_TRUE(CreateTestClients()); 1416 ASSERT_TRUE(CreateTestClients());
1340 LocalP2PTest(); 1417 LocalP2PTest();
1341 VerifyDtmf(); 1418 VerifyDtmf();
1342 } 1419 }
1343 1420
1344 // This test sets up a Jsep call between two parties and test that we can get a 1421 // 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
2214 server.urls.push_back("turn:hostname2"); 2291 server.urls.push_back("turn:hostname2");
2215 servers.push_back(server); 2292 servers.push_back(server);
2216 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); 2293 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2217 EXPECT_EQ(2U, turn_servers_.size()); 2294 EXPECT_EQ(2U, turn_servers_.size());
2218 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); 2295 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority);
2219 } 2296 }
2220 2297
2221 #endif // if !defined(THREAD_SANITIZER) 2298 #endif // if !defined(THREAD_SANITIZER)
2222 2299
2223 } // namespace 2300 } // namespace
OLDNEW
« no previous file with comments | « webrtc/api/mediastreamprovider.h ('k') | webrtc/api/rtpreceiver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698