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

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: Make the destructor of RtpReceiverObserverInterface virtual. Created 4 years, 7 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
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()
152 : is_first_audio_packet_recevied_(false),
153 is_first_video_packet_recevied_(false),
154 kind_("unset") {}
155
156 void onFirstPacketReceived(cricket::MediaType media_type) override {
pthatcher2 2016/05/20 20:23:13 OnFirstPacketReceived
157 if (media_type == cricket::MEDIA_TYPE_AUDIO) {
158 is_first_audio_packet_recevied_ = true;
159 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) {
160 is_first_video_packet_recevied_ = true;
161 }
162 }
163
164 void SetKind(std::string kind) { kind_ = kind; }
165
166 std::string kind() { return kind_; }
167
168 bool IsFirstAudioPacketReceived() { return is_first_audio_packet_recevied_; }
169
170 bool IsFirstVideoPacketReceived() { return is_first_video_packet_recevied_; }
171
172 virtual ~MockRtpReceiverObserver() {}
173
174 private:
175 bool is_first_audio_packet_recevied_;
176 bool is_first_video_packet_recevied_;
177 std::string kind_;
178 };
179
149 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, 180 class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
150 public SignalingMessageReceiver, 181 public SignalingMessageReceiver,
151 public ObserverInterface { 182 public ObserverInterface {
152 public: 183 public:
153 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore( 184 static PeerConnectionTestClient* CreateClientWithDtlsIdentityStore(
154 const std::string& id, 185 const std::string& id,
155 const MediaConstraintsInterface* constraints, 186 const MediaConstraintsInterface* constraints,
156 const PeerConnectionFactory::Options* options, 187 const PeerConnectionFactory::Options* options,
157 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, 188 std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
158 bool prefer_constraint_apis, 189 bool prefer_constraint_apis,
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 } 801 }
771 802
772 webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() { 803 webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() {
773 return pc()->ice_connection_state(); 804 return pc()->ice_connection_state();
774 } 805 }
775 806
776 webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() { 807 webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() {
777 return pc()->ice_gathering_state(); 808 return pc()->ice_gathering_state();
778 } 809 }
779 810
811 std::vector<rtc::scoped_refptr<MockRtpReceiverObserver>>
812 RtpReceiverObservers() {
pthatcher2 2016/05/20 20:23:13 rtp_receiver_observers()
zhihuang1 2016/05/24 01:01:44 Done.
813 return rtp_receiver_observers_;
814 }
815
780 private: 816 private:
781 class DummyDtmfObserver : public DtmfSenderObserverInterface { 817 class DummyDtmfObserver : public DtmfSenderObserverInterface {
782 public: 818 public:
783 DummyDtmfObserver() : completed_(false) {} 819 DummyDtmfObserver() : completed_(false) {}
784 820
785 // Implements DtmfSenderObserverInterface. 821 // Implements DtmfSenderObserverInterface.
786 void OnToneChange(const std::string& tone) override { 822 void OnToneChange(const std::string& tone) override {
787 tones_.push_back(tone); 823 tones_.push_back(tone);
788 if (tone.empty()) { 824 if (tone.empty()) {
789 completed_ = true; 825 completed_ = true;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 896
861 void HandleIncomingOffer(const std::string& msg) { 897 void HandleIncomingOffer(const std::string& msg) {
862 LOG(INFO) << id_ << "HandleIncomingOffer "; 898 LOG(INFO) << id_ << "HandleIncomingOffer ";
863 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) { 899 if (NumberOfLocalMediaStreams() == 0 && auto_add_stream_) {
864 // If we are not sending any streams ourselves it is time to add some. 900 // If we are not sending any streams ourselves it is time to add some.
865 AddMediaStream(true, true); 901 AddMediaStream(true, true);
866 } 902 }
867 std::unique_ptr<SessionDescriptionInterface> desc( 903 std::unique_ptr<SessionDescriptionInterface> desc(
868 webrtc::CreateSessionDescription("offer", msg, nullptr)); 904 webrtc::CreateSessionDescription("offer", msg, nullptr));
869 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); 905 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
906 // Register the RtpReceiverObserver after receivers are created.
907 DoRegisterRtpReceiverObservers();
pthatcher2 2016/05/20 20:23:13 Why not just RegisterRtpReceiverObservers()?
zhihuang1 2016/05/24 01:01:44 Done.
870 std::unique_ptr<SessionDescriptionInterface> answer; 908 std::unique_ptr<SessionDescriptionInterface> answer;
871 EXPECT_TRUE(DoCreateAnswer(&answer)); 909 EXPECT_TRUE(DoCreateAnswer(&answer));
872 std::string sdp; 910 std::string sdp;
873 EXPECT_TRUE(answer->ToString(&sdp)); 911 EXPECT_TRUE(answer->ToString(&sdp));
874 EXPECT_TRUE(DoSetLocalDescription(answer.release())); 912 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
875 if (signaling_message_receiver_) { 913 if (signaling_message_receiver_) {
876 signaling_message_receiver_->ReceiveSdpMessage( 914 signaling_message_receiver_->ReceiveSdpMessage(
877 webrtc::SessionDescriptionInterface::kAnswer, sdp); 915 webrtc::SessionDescriptionInterface::kAnswer, sdp);
878 } 916 }
879 } 917 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 // ProcessMessages waits at least 1ms but processes all messages before 971 // ProcessMessages waits at least 1ms but processes all messages before
934 // returning. Since this test is synchronous and send messages to the remote 972 // returning. Since this test is synchronous and send messages to the remote
935 // peer whenever a callback is invoked, this can lead to messages being 973 // peer whenever a callback is invoked, this can lead to messages being
936 // sent to the remote peer in the wrong order. 974 // sent to the remote peer in the wrong order.
937 // TODO(perkj): Find a way to check the result without risking that the 975 // TODO(perkj): Find a way to check the result without risking that the
938 // order of sent messages are changed. Ex- by posting all messages that are 976 // order of sent messages are changed. Ex- by posting all messages that are
939 // sent to the remote peer. 977 // sent to the remote peer.
940 return true; 978 return true;
941 } 979 }
942 980
981 void DoRegisterRtpReceiverObservers() {
982 for (auto receiver : pc()->GetReceivers()) {
983 rtc::scoped_refptr<MockRtpReceiverObserver> observer(
984 new rtc::RefCountedObject<MockRtpReceiverObserver>());
985 observer->SetKind(receiver->track()->kind());
986 receiver->RegisterRtpReceiverObserver(observer);
987 rtp_receiver_observers_.push_back(observer);
988 }
989 }
990
943 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { 991 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
944 rtc::scoped_refptr<MockSetSessionDescriptionObserver> 992 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
945 observer(new rtc::RefCountedObject< 993 observer(new rtc::RefCountedObject<
946 MockSetSessionDescriptionObserver>()); 994 MockSetSessionDescriptionObserver>());
947 LOG(INFO) << id_ << "SetRemoteDescription "; 995 LOG(INFO) << id_ << "SetRemoteDescription ";
948 pc()->SetRemoteDescription(observer, desc); 996 pc()->SetRemoteDescription(observer, desc);
949 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); 997 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
950 return observer->result(); 998 return observer->result();
951 } 999 }
952 1000
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 bool remove_bundle_ = 1064 bool remove_bundle_ =
1017 false; // True if bundle should be removed in received SDP. 1065 false; // True if bundle should be removed in received SDP.
1018 bool remove_sdes_ = 1066 bool remove_sdes_ =
1019 false; // True if a=crypto should be removed in received SDP. 1067 false; // True if a=crypto should be removed in received SDP.
1020 // |remove_cvo_| is true if extension urn:3gpp:video-orientation should be 1068 // |remove_cvo_| is true if extension urn:3gpp:video-orientation should be
1021 // removed in the received SDP. 1069 // removed in the received SDP.
1022 bool remove_cvo_ = false; 1070 bool remove_cvo_ = false;
1023 1071
1024 rtc::scoped_refptr<DataChannelInterface> data_channel_; 1072 rtc::scoped_refptr<DataChannelInterface> data_channel_;
1025 std::unique_ptr<MockDataChannelObserver> data_observer_; 1073 std::unique_ptr<MockDataChannelObserver> data_observer_;
1074
1075 std::vector<rtc::scoped_refptr<MockRtpReceiverObserver>>
1076 rtp_receiver_observers_;
1026 }; 1077 };
1027 1078
1028 class P2PTestConductor : public testing::Test { 1079 class P2PTestConductor : public testing::Test {
1029 public: 1080 public:
1030 P2PTestConductor() 1081 P2PTestConductor()
1031 : network_thread_(rtc::Thread::CreateWithSocketServer()), 1082 : network_thread_(rtc::Thread::CreateWithSocketServer()),
1032 worker_thread_(rtc::Thread::Create()), 1083 worker_thread_(rtc::Thread::Create()),
1033 pss_(new rtc::PhysicalSocketServer), 1084 pss_(new rtc::PhysicalSocketServer),
1034 ss_(new rtc::VirtualSocketServer(pss_.get())), 1085 ss_(new rtc::VirtualSocketServer(pss_.get())),
1035 ss_scope_(ss_.get()) { 1086 ss_scope_(ss_.get()) {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 1356
1306 // Set the |receiving_client_| to the |client| passed in and return the 1357 // Set the |receiving_client_| to the |client| passed in and return the
1307 // original |receiving_client_|. 1358 // original |receiving_client_|.
1308 PeerConnectionTestClient* set_receiving_client( 1359 PeerConnectionTestClient* set_receiving_client(
1309 PeerConnectionTestClient* client) { 1360 PeerConnectionTestClient* client) {
1310 PeerConnectionTestClient* old = receiving_client_.release(); 1361 PeerConnectionTestClient* old = receiving_client_.release();
1311 receiving_client_.reset(client); 1362 receiving_client_.reset(client);
1312 return old; 1363 return old;
1313 } 1364 }
1314 1365
1366 // Only check the callee side because only callee can guarantee to register
1367 // the observer before sending the data.
pthatcher2 2016/05/20 20:23:13 Here's a simple solution: whenever an observer is
zhihuang1 2016/05/24 01:01:44 This is a nice and easy solution.
1368 void CheckRtpReceiverObserverAreCalled() {
1369 for (auto observer : receiving_client_->RtpReceiverObservers()) {
1370 if (observer->kind() == webrtc::MediaStreamTrackInterface::kAudioKind) {
1371 EXPECT_TRUE_WAIT(observer->IsFirstAudioPacketReceived(),
1372 kMaxWaitForFramesMs);
1373 EXPECT_FALSE(observer->IsFirstVideoPacketReceived());
1374 } else if (observer->kind() ==
1375 webrtc::MediaStreamTrackInterface::kVideoKind) {
1376 EXPECT_FALSE(observer->IsFirstAudioPacketReceived());
1377 EXPECT_TRUE_WAIT(observer->IsFirstVideoPacketReceived(),
1378 kMaxWaitForFramesMs);
1379 } else {
1380 EXPECT_TRUE(false);
pthatcher2 2016/05/20 20:23:13 I think you can add a message to the EXPECT, like
zhihuang1 2016/05/24 01:01:44 Done.
1381 }
1382 }
1383 }
1384
1315 private: 1385 private:
1316 // |worker_thread_| is used by both |initiating_client_| and 1386 // |worker_thread_| is used by both |initiating_client_| and
1317 // |receiving_client_|. Must be destroyed last. 1387 // |receiving_client_|. Must be destroyed last.
1318 std::unique_ptr<rtc::Thread> network_thread_; 1388 std::unique_ptr<rtc::Thread> network_thread_;
1319 std::unique_ptr<rtc::Thread> worker_thread_; 1389 std::unique_ptr<rtc::Thread> worker_thread_;
1320 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 1390 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1321 std::unique_ptr<rtc::VirtualSocketServer> ss_; 1391 std::unique_ptr<rtc::VirtualSocketServer> ss_;
1322 rtc::SocketServerScope ss_scope_; 1392 rtc::SocketServerScope ss_scope_;
1323 std::unique_ptr<PeerConnectionTestClient> initiating_client_; 1393 std::unique_ptr<PeerConnectionTestClient> initiating_client_;
1324 std::unique_ptr<PeerConnectionTestClient> receiving_client_; 1394 std::unique_ptr<PeerConnectionTestClient> receiving_client_;
1325 bool prefer_constraint_apis_ = true; 1395 bool prefer_constraint_apis_ = true;
1326 }; 1396 };
1327 1397
1328 // Disable for TSan v2, see 1398 // Disable for TSan v2, see
1329 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. 1399 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
1330 #if !defined(THREAD_SANITIZER) 1400 #if !defined(THREAD_SANITIZER)
1331 1401
1402 TEST_F(P2PTestConductor, TestRtpReceiverObserverCallbackFunction) {
1403 ASSERT_TRUE(CreateTestClients());
1404 LocalP2PTest();
1405 CheckRtpReceiverObserverAreCalled();
pthatcher2 2016/05/20 20:23:13 If it's only called once, just put the code inline
zhihuang1 2016/05/24 01:01:44 I will make it a helper function to check both the
1406 }
1407
1332 // This test sets up a Jsep call between two parties and test Dtmf. 1408 // This test sets up a Jsep call between two parties and test Dtmf.
1333 // TODO(holmer): Disabled due to sometimes crashing on buildbots. 1409 // TODO(holmer): Disabled due to sometimes crashing on buildbots.
1334 // See issue webrtc/2378. 1410 // See issue webrtc/2378.
1335 TEST_F(P2PTestConductor, DISABLED_LocalP2PTestDtmf) { 1411 TEST_F(P2PTestConductor, DISABLED_LocalP2PTestDtmf) {
1336 ASSERT_TRUE(CreateTestClients()); 1412 ASSERT_TRUE(CreateTestClients());
1337 LocalP2PTest(); 1413 LocalP2PTest();
1338 VerifyDtmf(); 1414 VerifyDtmf();
1339 } 1415 }
1340 1416
1341 // This test sets up a Jsep call between two parties and test that we can get a 1417 // 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
2211 server.urls.push_back("turn:hostname2"); 2287 server.urls.push_back("turn:hostname2");
2212 servers.push_back(server); 2288 servers.push_back(server);
2213 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); 2289 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2214 EXPECT_EQ(2U, turn_servers_.size()); 2290 EXPECT_EQ(2U, turn_servers_.size());
2215 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); 2291 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority);
2216 } 2292 }
2217 2293
2218 #endif // if !defined(THREAD_SANITIZER) 2294 #endif // if !defined(THREAD_SANITIZER)
2219 2295
2220 } // namespace 2296 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698