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

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

Issue 1772353002: Adds a test for an one-way media PeerConnection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Refactoring P2PTestConductor frame cheks Created 4 years, 9 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 | « no previous file | no next file » | 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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 &source_constraints); 408 &source_constraints);
409 std::string label = stream_label + kVideoTrackLabelBase; 409 std::string label = stream_label + kVideoTrackLabelBase;
410 return peer_connection_factory_->CreateVideoTrack(label, source); 410 return peer_connection_factory_->CreateVideoTrack(label, source);
411 } 411 }
412 412
413 DataChannelInterface* data_channel() { return data_channel_; } 413 DataChannelInterface* data_channel() { return data_channel_; }
414 const MockDataChannelObserver* data_observer() const { 414 const MockDataChannelObserver* data_observer() const {
415 return data_observer_.get(); 415 return data_observer_.get();
416 } 416 }
417 417
418 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); } 418 webrtc::PeerConnectionInterface* pc() const { return peer_connection_.get(); }
419 419
420 void StopVideoCapturers() { 420 void StopVideoCapturers() {
421 for (std::vector<cricket::VideoCapturer*>::iterator it = 421 for (std::vector<cricket::VideoCapturer*>::iterator it =
422 video_capturers_.begin(); 422 video_capturers_.begin();
423 it != video_capturers_.end(); ++it) { 423 it != video_capturers_.end(); ++it) {
424 (*it)->Stop(); 424 (*it)->Stop();
425 } 425 }
426 } 426 }
427 427
428 bool AudioFramesReceivedCheck(int number_of_frames) const { 428 bool AudioFramesReceivedCheck(int number_of_frames) const {
429 return number_of_frames <= fake_audio_capture_module_->frames_received(); 429 return number_of_frames <= fake_audio_capture_module_->frames_received();
430 } 430 }
431 431
432 int audio_frames_received() const { 432 int audio_frames_received() const {
433 return fake_audio_capture_module_->frames_received(); 433 return fake_audio_capture_module_->frames_received();
434 } 434 }
435 435
436 bool VideoFramesReceivedCheck(int number_of_frames) { 436 bool VideoFramesReceivedCheck(int number_of_frames) {
437 if (video_decoder_factory_enabled_) { 437 if (video_decoder_factory_enabled_) {
438 const std::vector<FakeWebRtcVideoDecoder*>& decoders 438 const std::vector<FakeWebRtcVideoDecoder*>& decoders
439 = fake_video_decoder_factory_->decoders(); 439 = fake_video_decoder_factory_->decoders();
440 if (decoders.empty()) { 440 if (decoders.empty()) {
441 return number_of_frames <= 0; 441 return number_of_frames <= 0;
442 } 442 }
443 443 // Note - this checks that EACH decoder has the requisite number
444 // of frames. The video_frames_received() function sums them.
444 for (FakeWebRtcVideoDecoder* decoder : decoders) { 445 for (FakeWebRtcVideoDecoder* decoder : decoders) {
445 if (number_of_frames > decoder->GetNumFramesReceived()) { 446 if (number_of_frames > decoder->GetNumFramesReceived()) {
446 return false; 447 return false;
447 } 448 }
448 } 449 }
449 return true; 450 return true;
450 } else { 451 } else {
451 if (fake_video_renderers_.empty()) { 452 if (fake_video_renderers_.empty()) {
452 return number_of_frames <= 0; 453 return number_of_frames <= 0;
453 } 454 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 return fake_video_renderers_.empty() ? 1 : 654 return fake_video_renderers_.empty() ? 1 :
654 fake_video_renderers_.begin()->second->height(); 655 fake_video_renderers_.begin()->second->height();
655 } 656 }
656 657
657 size_t number_of_remote_streams() { 658 size_t number_of_remote_streams() {
658 if (!pc()) 659 if (!pc())
659 return 0; 660 return 0;
660 return pc()->remote_streams()->count(); 661 return pc()->remote_streams()->count();
661 } 662 }
662 663
663 StreamCollectionInterface* remote_streams() { 664 StreamCollectionInterface* remote_streams() const {
664 if (!pc()) { 665 if (!pc()) {
665 ADD_FAILURE(); 666 ADD_FAILURE();
666 return nullptr; 667 return nullptr;
667 } 668 }
668 return pc()->remote_streams(); 669 return pc()->remote_streams();
669 } 670 }
670 671
671 StreamCollectionInterface* local_streams() { 672 StreamCollectionInterface* local_streams() {
672 if (!pc()) { 673 if (!pc()) {
673 ADD_FAILURE(); 674 ADD_FAILURE();
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 P2PTestConductor() 913 P2PTestConductor()
913 : pss_(new rtc::PhysicalSocketServer), 914 : pss_(new rtc::PhysicalSocketServer),
914 ss_(new rtc::VirtualSocketServer(pss_.get())), 915 ss_(new rtc::VirtualSocketServer(pss_.get())),
915 ss_scope_(ss_.get()) {} 916 ss_scope_(ss_.get()) {}
916 917
917 bool SessionActive() { 918 bool SessionActive() {
918 return initiating_client_->SessionActive() && 919 return initiating_client_->SessionActive() &&
919 receiving_client_->SessionActive(); 920 receiving_client_->SessionActive();
920 } 921 }
921 922
922 // Return true if the number of frames provided have been received or it is 923 // Return true if the number of frames provided have been received
923 // known that that will never occur (e.g. no frames will be sent or 924 // on the video and audio tracks provided.
924 // captured). 925 bool FramesHaveArrived(int audio_frames_to_receive,
925 bool FramesNotPending(int audio_frames_to_receive, 926 int video_frames_to_receive) {
926 int video_frames_to_receive) { 927 bool all_good = true;
927 return VideoFramesReceivedCheck(video_frames_to_receive) && 928 // Note: We assume that all tracks contain audio and video,
928 AudioFramesReceivedCheck(audio_frames_to_receive); 929 // unless one of the parties has can_receive_video() = false.
930 if (initiating_client_->local_streams()->count() > 0) {
931 if (receiving_client_->can_receive_audio()) {
932 all_good &= receiving_client_->AudioFramesReceivedCheck(
933 audio_frames_to_receive);
934 }
935 if (receiving_client_->can_receive_video() &&
936 initiating_client_->can_receive_video()) {
937 all_good &= receiving_client_->VideoFramesReceivedCheck(
938 audio_frames_to_receive);
939 }
940 }
941 if (receiving_client_->local_streams()->count() > 0) {
942 if (initiating_client_->can_receive_audio()) {
943 all_good &= initiating_client_->AudioFramesReceivedCheck(
944 audio_frames_to_receive);
945 }
946 if (initiating_client_->can_receive_video() &&
947 receiving_client_->can_receive_video()) {
948 all_good &= initiating_client_->VideoFramesReceivedCheck(
949 audio_frames_to_receive);
950 }
951 }
952 return all_good;
929 } 953 }
930 bool AudioFramesReceivedCheck(int frames_received) { 954
931 return initiating_client_->AudioFramesReceivedCheck(frames_received) &&
932 receiving_client_->AudioFramesReceivedCheck(frames_received);
933 }
934 bool VideoFramesReceivedCheck(int frames_received) {
935 return initiating_client_->VideoFramesReceivedCheck(frames_received) &&
936 receiving_client_->VideoFramesReceivedCheck(frames_received);
937 }
938 void VerifyDtmf() { 955 void VerifyDtmf() {
939 initiating_client_->VerifyDtmf(); 956 initiating_client_->VerifyDtmf();
940 receiving_client_->VerifyDtmf(); 957 receiving_client_->VerifyDtmf();
941 } 958 }
942 959
943 void TestUpdateOfferWithRejectedContent() { 960 void TestUpdateOfferWithRejectedContent() {
944 // Renegotiate, rejecting the video m-line. 961 // Renegotiate, rejecting the video m-line.
945 initiating_client_->Negotiate(true, false); 962 initiating_client_->Negotiate(true, false);
946 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); 963 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
947 964
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 if (initiating_client_->NumberOfLocalMediaStreams() == 0) { 1049 if (initiating_client_->NumberOfLocalMediaStreams() == 0) {
1033 initiating_client_->AddMediaStream(true, true); 1050 initiating_client_->AddMediaStream(true, true);
1034 } 1051 }
1035 initiating_client_->Negotiate(); 1052 initiating_client_->Negotiate();
1036 // Assert true is used here since next tests are guaranteed to fail and 1053 // Assert true is used here since next tests are guaranteed to fail and
1037 // would eat up 5 seconds. 1054 // would eat up 5 seconds.
1038 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); 1055 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
1039 VerifySessionDescriptions(); 1056 VerifySessionDescriptions();
1040 1057
1041 int audio_frame_count = kEndAudioFrameCount; 1058 int audio_frame_count = kEndAudioFrameCount;
1059 int video_frame_count = kEndVideoFrameCount;
1042 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. 1060 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly.
1043 if (!initiating_client_->can_receive_audio() || 1061 if (!initiating_client_->can_receive_audio() ||
perkj_webrtc 2016/03/09 14:44:41 these can be removed now?
hta-webrtc 2016/03/09 16:37:52 With one more tweak, yes.
1044 !receiving_client_->can_receive_audio()) { 1062 !receiving_client_->can_receive_audio()) {
1045 audio_frame_count = -1; 1063 audio_frame_count = -1;
1046 } 1064 }
1047 int video_frame_count = kEndVideoFrameCount;
1048 if (!initiating_client_->can_receive_video() || 1065 if (!initiating_client_->can_receive_video() ||
perkj_webrtc 2016/03/09 14:44:41 dito?
hta-webrtc 2016/03/09 16:37:52 Done.
1049 !receiving_client_->can_receive_video()) { 1066 !receiving_client_->can_receive_video()) {
1050 video_frame_count = -1; 1067 video_frame_count = -1;
1051 } 1068 }
1052 1069
1053 if (audio_frame_count != -1 || video_frame_count != -1) { 1070 if ((!initiating_client_->can_receive_audio() &&
1054 // Audio or video is expected to flow, so both clients should reach the 1071 !initiating_client_->can_receive_video()) ||
1055 // Connected state, and the offerer (ICE controller) should proceed to 1072 (!receiving_client_->can_receive_audio() &&
1056 // Completed. 1073 !receiving_client_->can_receive_video())) {
1057 // Note: These tests have been observed to fail under heavy load at 1074 // Neither audio nor video will flow, so connections won't be
1058 // shorter timeouts, so they may be flaky. 1075 // established. There's nothing more to check.
perkj_webrtc 2016/03/09 14:17:17 Is this really true? What about data channels only
hta-webrtc 2016/03/09 14:31:28 Datachannels will cause transports to be establish
perkj_webrtc 2016/03/09 14:44:41 I mean- should the below checks now work even if y
hta-webrtc 2016/03/09 16:37:52 The checks that wait for ICE to complete won't wor
1059 EXPECT_EQ_WAIT( 1076 return;
1060 webrtc::PeerConnectionInterface::kIceConnectionCompleted,
1061 initiating_client_->ice_connection_state(),
1062 kMaxWaitForFramesMs);
1063 EXPECT_EQ_WAIT(
1064 webrtc::PeerConnectionInterface::kIceConnectionConnected,
1065 receiving_client_->ice_connection_state(),
1066 kMaxWaitForFramesMs);
1067 } 1077 }
1068 1078
1069 if (initiating_client_->can_receive_audio() || 1079 // Audio or video is expected to flow, so both clients should reach the
1070 initiating_client_->can_receive_video()) { 1080 // Connected state, and the offerer (ICE controller) should proceed to
1071 // The initiating client can receive media, so it must produce candidates 1081 // Completed.
1072 // that will serve as destinations for that media. 1082 // Note: These tests have been observed to fail under heavy load at
1073 // TODO(bemasc): Understand why the state is not already Complete here, as 1083 // shorter timeouts, so they may be flaky.
1074 // seems to be the case for the receiving client. This may indicate a bug 1084 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
1075 // in the ICE gathering system. 1085 initiating_client_->ice_connection_state(),
1076 EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew, 1086 kMaxWaitForFramesMs);
1077 initiating_client_->ice_gathering_state()); 1087 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
1078 } 1088 receiving_client_->ice_connection_state(),
1079 if (receiving_client_->can_receive_audio() || 1089 kMaxWaitForFramesMs);
1080 receiving_client_->can_receive_video()) {
1081 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
1082 receiving_client_->ice_gathering_state(),
1083 kMaxWaitForFramesMs);
1084 }
1085 1090
1086 EXPECT_TRUE_WAIT(FramesNotPending(audio_frame_count, video_frame_count), 1091 EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew,
perkj_webrtc 2016/03/09 14:17:17 Should you leave the todo here unless you know tha
hta-webrtc 2016/03/09 14:31:28 I know it's not correct behavior according to curr
hta-webrtc 2016/03/09 16:37:52 Added a TODO and explanatory text.
1092 initiating_client_->ice_gathering_state());
1093 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
1094 receiving_client_->ice_gathering_state(),
1095 kMaxWaitForFramesMs);
1096
1097 // Check that the expected number of frames have arrived.
1098 EXPECT_TRUE_WAIT(FramesHaveArrived(audio_frame_count, video_frame_count),
1087 kMaxWaitForFramesMs); 1099 kMaxWaitForFramesMs);
1088 } 1100 }
1089 1101
1090 void SetupAndVerifyDtlsCall() { 1102 void SetupAndVerifyDtlsCall() {
1091 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); 1103 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1092 FakeConstraints setup_constraints; 1104 FakeConstraints setup_constraints;
1093 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, 1105 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1094 true); 1106 true);
1095 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); 1107 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1096 LocalP2PTest(); 1108 LocalP2PTest();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 LocalP2PTest(); 1218 LocalP2PTest();
1207 VerifyRenderedSize(1280, 720); 1219 VerifyRenderedSize(1280, 720);
1208 } 1220 }
1209 1221
1210 // This test sets up a call between two endpoints that are configured to use 1222 // This test sets up a call between two endpoints that are configured to use
1211 // DTLS key agreement. As a result, DTLS is negotiated and used for transport. 1223 // DTLS key agreement. As a result, DTLS is negotiated and used for transport.
1212 TEST_F(P2PTestConductor, LocalP2PTestDtls) { 1224 TEST_F(P2PTestConductor, LocalP2PTestDtls) {
1213 SetupAndVerifyDtlsCall(); 1225 SetupAndVerifyDtlsCall();
1214 } 1226 }
1215 1227
1228 // This test sets up an one-way call, with media only from initiator to
1229 // responder.
1230 TEST_F(P2PTestConductor, OneWayMediaCall) {
1231 ASSERT_TRUE(CreateTestClients());
1232 receiving_client()->set_auto_add_stream(false);
1233 LocalP2PTest();
1234 }
1235
1216 // This test sets up a audio call initially and then upgrades to audio/video, 1236 // This test sets up a audio call initially and then upgrades to audio/video,
1217 // using DTLS. 1237 // using DTLS.
1218 TEST_F(P2PTestConductor, LocalP2PTestDtlsRenegotiate) { 1238 TEST_F(P2PTestConductor, LocalP2PTestDtlsRenegotiate) {
1219 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); 1239 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1220 FakeConstraints setup_constraints; 1240 FakeConstraints setup_constraints;
1221 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, 1241 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1222 true); 1242 true);
1223 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); 1243 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1224 receiving_client()->SetReceiveAudioVideo(true, false); 1244 receiving_client()->SetReceiveAudioVideo(true, false);
1225 LocalP2PTest(); 1245 LocalP2PTest();
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1812 initializing_client()->ice_connection_state(), 1832 initializing_client()->ice_connection_state(),
1813 kMaxWaitForFramesMs); 1833 kMaxWaitForFramesMs);
1814 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, 1834 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
1815 receiving_client()->ice_connection_state(), 1835 receiving_client()->ice_connection_state(),
1816 kMaxWaitForFramesMs); 1836 kMaxWaitForFramesMs);
1817 // Now set the tracks, and expect frames to immediately start flowing. 1837 // Now set the tracks, and expect frames to immediately start flowing.
1818 EXPECT_TRUE( 1838 EXPECT_TRUE(
1819 audio_sender->SetTrack(initializing_client()->CreateLocalAudioTrack(""))); 1839 audio_sender->SetTrack(initializing_client()->CreateLocalAudioTrack("")));
1820 EXPECT_TRUE( 1840 EXPECT_TRUE(
1821 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack(""))); 1841 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack("")));
1822 EXPECT_TRUE_WAIT(FramesNotPending(kEndAudioFrameCount, kEndVideoFrameCount), 1842 EXPECT_TRUE_WAIT(FramesHaveArrived(kEndAudioFrameCount, kEndVideoFrameCount),
1823 kMaxWaitForFramesMs); 1843 kMaxWaitForFramesMs);
1824 } 1844 }
1825 1845
1826 class IceServerParsingTest : public testing::Test { 1846 class IceServerParsingTest : public testing::Test {
1827 public: 1847 public:
1828 // Convenience for parsing a single URL. 1848 // Convenience for parsing a single URL.
1829 bool ParseUrl(const std::string& url) { 1849 bool ParseUrl(const std::string& url) {
1830 return ParseUrl(url, std::string(), std::string()); 1850 return ParseUrl(url, std::string(), std::string());
1831 } 1851 }
1832 1852
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 PeerConnectionInterface::IceServer server; 2026 PeerConnectionInterface::IceServer server;
2007 server.urls.push_back("turn:hostname"); 2027 server.urls.push_back("turn:hostname");
2008 server.urls.push_back("turn:hostname2"); 2028 server.urls.push_back("turn:hostname2");
2009 servers.push_back(server); 2029 servers.push_back(server);
2010 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); 2030 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2011 EXPECT_EQ(2U, turn_servers_.size()); 2031 EXPECT_EQ(2U, turn_servers_.size());
2012 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); 2032 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority);
2013 } 2033 }
2014 2034
2015 #endif // if !defined(THREAD_SANITIZER) 2035 #endif // if !defined(THREAD_SANITIZER)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698