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

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: Add media type to BaseChannel. 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()
pthatcher1 2016/06/08 17:35:55 I'd suggest just passing the kind (or expected cri
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 {
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 }
pthatcher1 2016/06/08 17:35:55 Given the unlikelyhood of getting the wrong media
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_; }
pthatcher1 2016/06/08 17:35:55 Using lowercase first_x_packet_received() is proba
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_;
pthatcher1 2016/06/08 17:35:55 You can use "= false" here and avoid needing to se
pthatcher1 2016/06/08 17:35:55 Just "first_x_packet_received_" would be enough.
177 std::string kind_;
pthatcher1 2016/06/08 17:35:55 I think it might make more sense to store the expe
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<std::unique_ptr<MockRtpReceiverObserver>> const&
812 rtp_receiver_observers() {
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 SetRtpReceiverObservers();
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 }
880 918
881 void HandleIncomingAnswer(const std::string& msg) { 919 void HandleIncomingAnswer(const std::string& msg) {
882 LOG(INFO) << id_ << "HandleIncomingAnswer"; 920 LOG(INFO) << id_ << "HandleIncomingAnswer";
883 std::unique_ptr<SessionDescriptionInterface> desc( 921 std::unique_ptr<SessionDescriptionInterface> desc(
884 webrtc::CreateSessionDescription("answer", msg, nullptr)); 922 webrtc::CreateSessionDescription("answer", msg, nullptr));
885 EXPECT_TRUE(DoSetRemoteDescription(desc.release())); 923 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
924 // Register the RtpReceiverObserver after receivers are created.
925 SetRtpReceiverObservers();
886 } 926 }
887 927
888 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, 928 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
889 bool offer) { 929 bool offer) {
890 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> 930 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
891 observer(new rtc::RefCountedObject< 931 observer(new rtc::RefCountedObject<
892 MockCreateSessionDescriptionObserver>()); 932 MockCreateSessionDescriptionObserver>());
893 if (prefer_constraint_apis_) { 933 if (prefer_constraint_apis_) {
894 if (offer) { 934 if (offer) {
895 pc()->CreateOffer(observer, &offer_answer_constraints_); 935 pc()->CreateOffer(observer, &offer_answer_constraints_);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 // ProcessMessages waits at least 1ms but processes all messages before 973 // ProcessMessages waits at least 1ms but processes all messages before
934 // returning. Since this test is synchronous and send messages to the remote 974 // 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 975 // peer whenever a callback is invoked, this can lead to messages being
936 // sent to the remote peer in the wrong order. 976 // sent to the remote peer in the wrong order.
937 // TODO(perkj): Find a way to check the result without risking that the 977 // 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 978 // order of sent messages are changed. Ex- by posting all messages that are
939 // sent to the remote peer. 979 // sent to the remote peer.
940 return true; 980 return true;
941 } 981 }
942 982
983 void SetRtpReceiverObservers() {
984 for (auto receiver : pc()->GetReceivers()) {
985 std::unique_ptr<MockRtpReceiverObserver> observer(
986 new MockRtpReceiverObserver());
987 observer->SetKind(receiver->track()->kind());
988 receiver->SetObserver(observer.get());
989 rtp_receiver_observers_.push_back(std::move(observer));
990 }
991 }
992
943 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { 993 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
944 rtc::scoped_refptr<MockSetSessionDescriptionObserver> 994 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
945 observer(new rtc::RefCountedObject< 995 observer(new rtc::RefCountedObject<
946 MockSetSessionDescriptionObserver>()); 996 MockSetSessionDescriptionObserver>());
947 LOG(INFO) << id_ << "SetRemoteDescription "; 997 LOG(INFO) << id_ << "SetRemoteDescription ";
948 pc()->SetRemoteDescription(observer, desc); 998 pc()->SetRemoteDescription(observer, desc);
949 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); 999 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
950 return observer->result(); 1000 return observer->result();
951 } 1001 }
952 1002
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 bool remove_bundle_ = 1066 bool remove_bundle_ =
1017 false; // True if bundle should be removed in received SDP. 1067 false; // True if bundle should be removed in received SDP.
1018 bool remove_sdes_ = 1068 bool remove_sdes_ =
1019 false; // True if a=crypto should be removed in received SDP. 1069 false; // True if a=crypto should be removed in received SDP.
1020 // |remove_cvo_| is true if extension urn:3gpp:video-orientation should be 1070 // |remove_cvo_| is true if extension urn:3gpp:video-orientation should be
1021 // removed in the received SDP. 1071 // removed in the received SDP.
1022 bool remove_cvo_ = false; 1072 bool remove_cvo_ = false;
1023 1073
1024 rtc::scoped_refptr<DataChannelInterface> data_channel_; 1074 rtc::scoped_refptr<DataChannelInterface> data_channel_;
1025 std::unique_ptr<MockDataChannelObserver> data_observer_; 1075 std::unique_ptr<MockDataChannelObserver> data_observer_;
1076
1077 std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_;
1026 }; 1078 };
1027 1079
1028 class P2PTestConductor : public testing::Test { 1080 class P2PTestConductor : public testing::Test {
1029 public: 1081 public:
1030 P2PTestConductor() 1082 P2PTestConductor()
1031 : network_thread_(rtc::Thread::CreateWithSocketServer()), 1083 : network_thread_(rtc::Thread::CreateWithSocketServer()),
1032 worker_thread_(rtc::Thread::Create()), 1084 worker_thread_(rtc::Thread::Create()),
1033 pss_(new rtc::PhysicalSocketServer), 1085 pss_(new rtc::PhysicalSocketServer),
1034 ss_(new rtc::VirtualSocketServer(pss_.get())), 1086 ss_(new rtc::VirtualSocketServer(pss_.get())),
1035 ss_scope_(ss_.get()) { 1087 ss_scope_(ss_.get()) {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 1357
1306 // Set the |receiving_client_| to the |client| passed in and return the 1358 // Set the |receiving_client_| to the |client| passed in and return the
1307 // original |receiving_client_|. 1359 // original |receiving_client_|.
1308 PeerConnectionTestClient* set_receiving_client( 1360 PeerConnectionTestClient* set_receiving_client(
1309 PeerConnectionTestClient* client) { 1361 PeerConnectionTestClient* client) {
1310 PeerConnectionTestClient* old = receiving_client_.release(); 1362 PeerConnectionTestClient* old = receiving_client_.release();
1311 receiving_client_.reset(client); 1363 receiving_client_.reset(client);
1312 return old; 1364 return old;
1313 } 1365 }
1314 1366
1367 void CheckRtpReceiverObserverAreCalled(PeerConnectionTestClient* client) {
1368 for (auto const& observer : client->rtp_receiver_observers()) {
1369 if (observer->kind() == webrtc::MediaStreamTrackInterface::kAudioKind) {
1370 EXPECT_TRUE_WAIT(observer->IsFirstAudioPacketReceived(),
1371 kMaxWaitForFramesMs);
1372 EXPECT_FALSE(observer->IsFirstVideoPacketReceived());
1373 } else if (observer->kind() ==
1374 webrtc::MediaStreamTrackInterface::kVideoKind) {
1375 EXPECT_FALSE(observer->IsFirstAudioPacketReceived());
1376 EXPECT_TRUE_WAIT(observer->IsFirstVideoPacketReceived(),
1377 kMaxWaitForFramesMs);
1378 } else {
1379 EXPECT_TRUE(false) << "Unknown RtpReceiver kind.";
1380 }
pthatcher1 2016/06/08 17:35:55 With my other suggestion about ASSERT_EQ(media_typ
Zhi Huang 2016/06/09 00:37:36 This make the code much cleaner.
1381 }
1382 }
1383
1315 private: 1384 private:
1316 // |worker_thread_| is used by both |initiating_client_| and 1385 // |worker_thread_| is used by both |initiating_client_| and
1317 // |receiving_client_|. Must be destroyed last. 1386 // |receiving_client_|. Must be destroyed last.
1318 std::unique_ptr<rtc::Thread> network_thread_; 1387 std::unique_ptr<rtc::Thread> network_thread_;
1319 std::unique_ptr<rtc::Thread> worker_thread_; 1388 std::unique_ptr<rtc::Thread> worker_thread_;
1320 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 1389 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1321 std::unique_ptr<rtc::VirtualSocketServer> ss_; 1390 std::unique_ptr<rtc::VirtualSocketServer> ss_;
1322 rtc::SocketServerScope ss_scope_; 1391 rtc::SocketServerScope ss_scope_;
1323 std::unique_ptr<PeerConnectionTestClient> initiating_client_; 1392 std::unique_ptr<PeerConnectionTestClient> initiating_client_;
1324 std::unique_ptr<PeerConnectionTestClient> receiving_client_; 1393 std::unique_ptr<PeerConnectionTestClient> receiving_client_;
1325 bool prefer_constraint_apis_ = true; 1394 bool prefer_constraint_apis_ = true;
1326 }; 1395 };
1327 1396
1328 // Disable for TSan v2, see 1397 // Disable for TSan v2, see
1329 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. 1398 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
1330 #if !defined(THREAD_SANITIZER) 1399 #if !defined(THREAD_SANITIZER)
1331 1400
1401 TEST_F(P2PTestConductor, TestRtpReceiverObserverCallbackFunction) {
1402 ASSERT_TRUE(CreateTestClients());
1403 LocalP2PTest();
1404 CheckRtpReceiverObserverAreCalled(initializing_client());
1405 CheckRtpReceiverObserverAreCalled(receiving_client());
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