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

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: More review cleanups 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);
perkj_webrtc 2016/03/09 16:56:25 video_frames_to_receive
hta-webrtc 2016/03/09 17:50:56 Done.
939 }
940 }
941 if (receiving_client_->local_streams()->count() > 0) {
942 if (initiating_client_->can_receive_audio() &&
943 receiving_client_->can_receive_audio()) {
perkj_webrtc 2016/03/09 16:56:25 please change to if (receiving_client_->local_str
hta-webrtc 2016/03/09 17:50:56 Restructured.
944 all_good &= initiating_client_->AudioFramesReceivedCheck(
945 audio_frames_to_receive);
946 }
947 if (initiating_client_->can_receive_video() &&
948 receiving_client_->can_receive_video()) {
949 all_good &= initiating_client_->VideoFramesReceivedCheck(
950 audio_frames_to_receive);
perkj_webrtc 2016/03/09 16:56:25 video_frames_to_receive
hta-webrtc 2016/03/09 17:50:56 Done.
951 }
952 }
953 return all_good;
929 } 954 }
930 bool AudioFramesReceivedCheck(int frames_received) { 955
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() { 956 void VerifyDtmf() {
939 initiating_client_->VerifyDtmf(); 957 initiating_client_->VerifyDtmf();
940 receiving_client_->VerifyDtmf(); 958 receiving_client_->VerifyDtmf();
941 } 959 }
942 960
943 void TestUpdateOfferWithRejectedContent() { 961 void TestUpdateOfferWithRejectedContent() {
944 // Renegotiate, rejecting the video m-line. 962 // Renegotiate, rejecting the video m-line.
945 initiating_client_->Negotiate(true, false); 963 initiating_client_->Negotiate(true, false);
946 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); 964 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
947 965
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 if (initiating_client_->NumberOfLocalMediaStreams() == 0) { 1050 if (initiating_client_->NumberOfLocalMediaStreams() == 0) {
1033 initiating_client_->AddMediaStream(true, true); 1051 initiating_client_->AddMediaStream(true, true);
1034 } 1052 }
1035 initiating_client_->Negotiate(); 1053 initiating_client_->Negotiate();
1036 // Assert true is used here since next tests are guaranteed to fail and 1054 // Assert true is used here since next tests are guaranteed to fail and
1037 // would eat up 5 seconds. 1055 // would eat up 5 seconds.
1038 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); 1056 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
1039 VerifySessionDescriptions(); 1057 VerifySessionDescriptions();
1040 1058
1041 int audio_frame_count = kEndAudioFrameCount; 1059 int audio_frame_count = kEndAudioFrameCount;
1060 int video_frame_count = kEndVideoFrameCount;
1042 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. 1061 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly.
perkj_webrtc 2016/03/09 16:56:25 please remove this todo
hta-webrtc 2016/03/09 17:50:56 Don't think it's right to remove. We still have no
1043 if (!initiating_client_->can_receive_audio() || 1062
1044 !receiving_client_->can_receive_audio()) { 1063 if ((!initiating_client_->can_receive_audio() &&
1045 audio_frame_count = -1; 1064 !initiating_client_->can_receive_video()) ||
1046 } 1065 (!receiving_client_->can_receive_audio() &&
1047 int video_frame_count = kEndVideoFrameCount; 1066 !receiving_client_->can_receive_video())) {
1048 if (!initiating_client_->can_receive_video() || 1067 // Neither audio nor video will flow, so connections won't be
1049 !receiving_client_->can_receive_video()) { 1068 // established. There's nothing more to check.
1050 video_frame_count = -1; 1069 // TODO(hta): Check connection if there's a data channel.
1070 return;
1051 } 1071 }
1052 1072
1053 if (audio_frame_count != -1 || video_frame_count != -1) { 1073 // Audio or video is expected to flow, so both clients should reach the
1054 // Audio or video is expected to flow, so both clients should reach the 1074 // Connected state, and the offerer (ICE controller) should proceed to
1055 // Connected state, and the offerer (ICE controller) should proceed to 1075 // Completed.
1056 // Completed. 1076 // Note: These tests have been observed to fail under heavy load at
1057 // Note: These tests have been observed to fail under heavy load at 1077 // shorter timeouts, so they may be flaky.
1058 // shorter timeouts, so they may be flaky. 1078 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
1059 EXPECT_EQ_WAIT( 1079 initiating_client_->ice_connection_state(),
1060 webrtc::PeerConnectionInterface::kIceConnectionCompleted, 1080 kMaxWaitForFramesMs);
1061 initiating_client_->ice_connection_state(), 1081 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
1062 kMaxWaitForFramesMs); 1082 receiving_client_->ice_connection_state(),
1063 EXPECT_EQ_WAIT( 1083 kMaxWaitForFramesMs);
1064 webrtc::PeerConnectionInterface::kIceConnectionConnected,
1065 receiving_client_->ice_connection_state(),
1066 kMaxWaitForFramesMs);
1067 }
1068 1084
1069 if (initiating_client_->can_receive_audio() || 1085 // The ICE gathering state should end up in kIceGatheringComplete,
1070 initiating_client_->can_receive_video()) { 1086 // but there's a bug that prevents this at the moment, and the state
1071 // The initiating client can receive media, so it must produce candidates 1087 // machine is being updated by the WEBRTC WG.
1072 // that will serve as destinations for that media. 1088 // TODO(hta): Update this check when spec revisions finish.
1073 // TODO(bemasc): Understand why the state is not already Complete here, as 1089 EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew,
1074 // seems to be the case for the receiving client. This may indicate a bug 1090 initiating_client_->ice_gathering_state());
1075 // in the ICE gathering system. 1091 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
1076 EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew, 1092 receiving_client_->ice_gathering_state(),
1077 initiating_client_->ice_gathering_state()); 1093 kMaxWaitForFramesMs);
1078 }
1079 if (receiving_client_->can_receive_audio() ||
1080 receiving_client_->can_receive_video()) {
1081 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
1082 receiving_client_->ice_gathering_state(),
1083 kMaxWaitForFramesMs);
1084 }
1085 1094
1086 EXPECT_TRUE_WAIT(FramesNotPending(audio_frame_count, video_frame_count), 1095 // Check that the expected number of frames have arrived.
1096 EXPECT_TRUE_WAIT(FramesHaveArrived(audio_frame_count, video_frame_count),
1087 kMaxWaitForFramesMs); 1097 kMaxWaitForFramesMs);
1088 } 1098 }
1089 1099
1090 void SetupAndVerifyDtlsCall() { 1100 void SetupAndVerifyDtlsCall() {
1091 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); 1101 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1092 FakeConstraints setup_constraints; 1102 FakeConstraints setup_constraints;
1093 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, 1103 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1094 true); 1104 true);
1095 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); 1105 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1096 LocalP2PTest(); 1106 LocalP2PTest();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 LocalP2PTest(); 1216 LocalP2PTest();
1207 VerifyRenderedSize(1280, 720); 1217 VerifyRenderedSize(1280, 720);
1208 } 1218 }
1209 1219
1210 // This test sets up a call between two endpoints that are configured to use 1220 // 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. 1221 // DTLS key agreement. As a result, DTLS is negotiated and used for transport.
1212 TEST_F(P2PTestConductor, LocalP2PTestDtls) { 1222 TEST_F(P2PTestConductor, LocalP2PTestDtls) {
1213 SetupAndVerifyDtlsCall(); 1223 SetupAndVerifyDtlsCall();
1214 } 1224 }
1215 1225
1226 // This test sets up an one-way call, with media only from initiator to
1227 // responder.
1228 TEST_F(P2PTestConductor, OneWayMediaCall) {
1229 ASSERT_TRUE(CreateTestClients());
1230 receiving_client()->set_auto_add_stream(false);
1231 LocalP2PTest();
1232 }
1233
1216 // This test sets up a audio call initially and then upgrades to audio/video, 1234 // This test sets up a audio call initially and then upgrades to audio/video,
1217 // using DTLS. 1235 // using DTLS.
1218 TEST_F(P2PTestConductor, LocalP2PTestDtlsRenegotiate) { 1236 TEST_F(P2PTestConductor, LocalP2PTestDtlsRenegotiate) {
1219 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); 1237 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
1220 FakeConstraints setup_constraints; 1238 FakeConstraints setup_constraints;
1221 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, 1239 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1222 true); 1240 true);
1223 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); 1241 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1224 receiving_client()->SetReceiveAudioVideo(true, false); 1242 receiving_client()->SetReceiveAudioVideo(true, false);
1225 LocalP2PTest(); 1243 LocalP2PTest();
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1812 initializing_client()->ice_connection_state(), 1830 initializing_client()->ice_connection_state(),
1813 kMaxWaitForFramesMs); 1831 kMaxWaitForFramesMs);
1814 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected, 1832 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
1815 receiving_client()->ice_connection_state(), 1833 receiving_client()->ice_connection_state(),
1816 kMaxWaitForFramesMs); 1834 kMaxWaitForFramesMs);
1817 // Now set the tracks, and expect frames to immediately start flowing. 1835 // Now set the tracks, and expect frames to immediately start flowing.
1818 EXPECT_TRUE( 1836 EXPECT_TRUE(
1819 audio_sender->SetTrack(initializing_client()->CreateLocalAudioTrack(""))); 1837 audio_sender->SetTrack(initializing_client()->CreateLocalAudioTrack("")));
1820 EXPECT_TRUE( 1838 EXPECT_TRUE(
1821 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack(""))); 1839 video_sender->SetTrack(initializing_client()->CreateLocalVideoTrack("")));
1822 EXPECT_TRUE_WAIT(FramesNotPending(kEndAudioFrameCount, kEndVideoFrameCount), 1840 EXPECT_TRUE_WAIT(FramesHaveArrived(kEndAudioFrameCount, kEndVideoFrameCount),
1823 kMaxWaitForFramesMs); 1841 kMaxWaitForFramesMs);
1824 } 1842 }
1825 1843
1826 class IceServerParsingTest : public testing::Test { 1844 class IceServerParsingTest : public testing::Test {
1827 public: 1845 public:
1828 // Convenience for parsing a single URL. 1846 // Convenience for parsing a single URL.
1829 bool ParseUrl(const std::string& url) { 1847 bool ParseUrl(const std::string& url) {
1830 return ParseUrl(url, std::string(), std::string()); 1848 return ParseUrl(url, std::string(), std::string());
1831 } 1849 }
1832 1850
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 PeerConnectionInterface::IceServer server; 2024 PeerConnectionInterface::IceServer server;
2007 server.urls.push_back("turn:hostname"); 2025 server.urls.push_back("turn:hostname");
2008 server.urls.push_back("turn:hostname2"); 2026 server.urls.push_back("turn:hostname2");
2009 servers.push_back(server); 2027 servers.push_back(server);
2010 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); 2028 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2011 EXPECT_EQ(2U, turn_servers_.size()); 2029 EXPECT_EQ(2U, turn_servers_.size());
2012 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); 2030 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority);
2013 } 2031 }
2014 2032
2015 #endif // if !defined(THREAD_SANITIZER) 2033 #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