From 27ab0e5ee56bdfe4dfe2291107e753e38bba4603 Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Mon, 23 Jul 2018 15:11:53 -0700 Subject: [PATCH] Add CreateIceCandidate overload which takes a cricket::Candidate This gives clients a clear way to create an IceCandidateInterface instance for use with PeerConnection from a parsed cricket::Candidate structure. Previously, the only way was with the JsepIceCandidate constructor, but this CL will allow us to move that class out of the API. Bug: webrtc:9544 Change-Id: Idfc1f1e0f5ee4c68d94599aae3fb824b23189a7c Reviewed-on: https://webrtc-review.googlesource.com/90121 Reviewed-by: Seth Hampson Cr-Commit-Position: refs/heads/master@{#24074} --- api/jsep.h | 6 ++++++ pc/jsepicecandidate.cc | 8 +++++++ pc/peerconnection_bundle_unittest.cc | 5 +++-- pc/peerconnection_ice_unittest.cc | 32 +++++++++++++++++----------- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/api/jsep.h b/api/jsep.h index b07f8581eb..cbc0a6c6bf 100644 --- a/api/jsep.h +++ b/api/jsep.h @@ -78,6 +78,12 @@ IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid, const std::string& sdp, SdpParseError* error); +// Creates an IceCandidateInterface based on a parsed candidate structure. +std::unique_ptr CreateIceCandidate( + const std::string& sdp_mid, + int sdp_mline_index, + const cricket::Candidate& candidate); + // This class represents a collection of candidates for a specific m= section. // Used in SessionDescriptionInterface. class IceCandidateCollection { diff --git a/pc/jsepicecandidate.cc b/pc/jsepicecandidate.cc index 22139c8de5..84a002c165 100644 --- a/pc/jsepicecandidate.cc +++ b/pc/jsepicecandidate.cc @@ -29,6 +29,14 @@ IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid, return jsep_ice; } +std::unique_ptr CreateIceCandidate( + const std::string& sdp_mid, + int sdp_mline_index, + const cricket::Candidate& candidate) { + return absl::make_unique(sdp_mid, sdp_mline_index, + candidate); +} + JsepIceCandidate::JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index) : sdp_mid_(sdp_mid), sdp_mline_index_(sdp_mline_index) {} diff --git a/pc/peerconnection_bundle_unittest.cc b/pc/peerconnection_bundle_unittest.cc index 3211f269ea..907669b5ad 100644 --- a/pc/peerconnection_bundle_unittest.cc +++ b/pc/peerconnection_bundle_unittest.cc @@ -61,8 +61,9 @@ class PeerConnectionWrapperForBundleTest : public PeerConnectionWrapper { const auto& content = desc->contents()[i]; if (content.media_description()->type() == media_type) { candidate->set_transport_name(content.name); - JsepIceCandidate jsep_candidate(content.name, i, *candidate); - return pc()->AddIceCandidate(&jsep_candidate); + std::unique_ptr jsep_candidate = + CreateIceCandidate(content.name, i, *candidate); + return pc()->AddIceCandidate(jsep_candidate.get()); } } RTC_NOTREACHED(); diff --git a/pc/peerconnection_ice_unittest.cc b/pc/peerconnection_ice_unittest.cc index 656ff22497..36e0a098dd 100644 --- a/pc/peerconnection_ice_unittest.cc +++ b/pc/peerconnection_ice_unittest.cc @@ -51,8 +51,9 @@ class PeerConnectionWrapperForIceTest : public PeerConnectionWrapper { RTC_DCHECK(desc->contents().size() > 0); const auto& first_content = desc->contents()[0]; candidate->set_transport_name(first_content.name); - JsepIceCandidate jsep_candidate(first_content.name, 0, *candidate); - return pc()->AddIceCandidate(&jsep_candidate); + std::unique_ptr jsep_candidate = + CreateIceCandidate(first_content.name, 0, *candidate); + return pc()->AddIceCandidate(jsep_candidate.get()); } // Returns ICE candidates from the remote session description. @@ -221,8 +222,9 @@ class PeerConnectionIceBaseTest : public ::testing::Test { RTC_DCHECK(desc->contents().size() > 0); const auto& first_content = desc->contents()[0]; candidate->set_transport_name(first_content.name); - JsepIceCandidate jsep_candidate(first_content.name, 0, *candidate); - return sdesc->AddCandidate(&jsep_candidate); + std::unique_ptr jsep_candidate = + CreateIceCandidate(first_content.name, 0, *candidate); + return sdesc->AddCandidate(jsep_candidate.get()); } rtc::FakeNetworkManager* NewFakeNetwork() { @@ -411,13 +413,14 @@ TEST_P(PeerConnectionIceTest, CannotAddCandidateWhenRemoteDescriptionNotSet) { auto caller = CreatePeerConnectionWithAudioVideo(); cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress); - JsepIceCandidate jsep_candidate(cricket::CN_AUDIO, 0, candidate); + std::unique_ptr jsep_candidate = + CreateIceCandidate(cricket::CN_AUDIO, 0, candidate); - EXPECT_FALSE(caller->pc()->AddIceCandidate(&jsep_candidate)); + EXPECT_FALSE(caller->pc()->AddIceCandidate(jsep_candidate.get())); caller->CreateOfferAndSetAsLocal(); - EXPECT_FALSE(caller->pc()->AddIceCandidate(&jsep_candidate)); + EXPECT_FALSE(caller->pc()->AddIceCandidate(jsep_candidate.get())); EXPECT_EQ( 2, webrtc::metrics::NumSamples("WebRTC.PeerConnection.AddIceCandidate")); EXPECT_EQ( @@ -436,11 +439,12 @@ TEST_P(PeerConnectionIceTest, CannotAddCandidateWhenPeerConnectionClosed) { cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress); auto* audio_content = cricket::GetFirstAudioContent( caller->pc()->local_description()->description()); - JsepIceCandidate jsep_candidate(audio_content->name, 0, candidate); + std::unique_ptr jsep_candidate = + CreateIceCandidate(audio_content->name, 0, candidate); caller->pc()->Close(); - EXPECT_FALSE(caller->pc()->AddIceCandidate(&jsep_candidate)); + EXPECT_FALSE(caller->pc()->AddIceCandidate(jsep_candidate.get())); } TEST_P(PeerConnectionIceTest, DuplicateIceCandidateIgnoredWhenAdded) { @@ -471,9 +475,10 @@ TEST_P(PeerConnectionIceTest, cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress); auto* audio_content = cricket::GetFirstAudioContent( caller->pc()->local_description()->description()); - JsepIceCandidate ice_candidate(audio_content->name, 0, candidate); + std::unique_ptr ice_candidate = + CreateIceCandidate(audio_content->name, 0, candidate); - ASSERT_TRUE(caller->pc()->AddIceCandidate(&ice_candidate)); + ASSERT_TRUE(caller->pc()->AddIceCandidate(ice_candidate.get())); caller->pc()->Close(); @@ -495,8 +500,9 @@ TEST_P(PeerConnectionIceTest, cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress); auto* audio_content = cricket::GetFirstAudioContent( caller->pc()->local_description()->description()); - JsepIceCandidate ice_candidate(audio_content->name, 0, candidate); - EXPECT_TRUE(caller->pc()->AddIceCandidate(&ice_candidate)); + std::unique_ptr ice_candidate = + CreateIceCandidate(audio_content->name, 0, candidate); + EXPECT_TRUE(caller->pc()->AddIceCandidate(ice_candidate.get())); EXPECT_TRUE(caller->pc()->RemoveIceCandidates({candidate})); }