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 <shampson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24074}
diff --git a/api/jsep.h b/api/jsep.h
index b07f858..cbc0a6c 100644
--- a/api/jsep.h
+++ b/api/jsep.h
@@ -78,6 +78,12 @@
const std::string& sdp,
SdpParseError* error);
+// Creates an IceCandidateInterface based on a parsed candidate structure.
+std::unique_ptr<IceCandidateInterface> 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 22139c8..84a002c 100644
--- a/pc/jsepicecandidate.cc
+++ b/pc/jsepicecandidate.cc
@@ -29,6 +29,14 @@
return jsep_ice;
}
+std::unique_ptr<IceCandidateInterface> CreateIceCandidate(
+ const std::string& sdp_mid,
+ int sdp_mline_index,
+ const cricket::Candidate& candidate) {
+ return absl::make_unique<JsepIceCandidate>(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 3211f26..907669b 100644
--- a/pc/peerconnection_bundle_unittest.cc
+++ b/pc/peerconnection_bundle_unittest.cc
@@ -61,8 +61,9 @@
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<IceCandidateInterface> 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 656ff22..36e0a09 100644
--- a/pc/peerconnection_ice_unittest.cc
+++ b/pc/peerconnection_ice_unittest.cc
@@ -51,8 +51,9 @@
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<IceCandidateInterface> 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 @@
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<IceCandidateInterface> jsep_candidate =
+ CreateIceCandidate(first_content.name, 0, *candidate);
+ return sdesc->AddCandidate(jsep_candidate.get());
}
rtc::FakeNetworkManager* NewFakeNetwork() {
@@ -411,13 +413,14 @@
auto caller = CreatePeerConnectionWithAudioVideo();
cricket::Candidate candidate = CreateLocalUdpCandidate(kCalleeAddress);
- JsepIceCandidate jsep_candidate(cricket::CN_AUDIO, 0, candidate);
+ std::unique_ptr<IceCandidateInterface> 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 @@
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<IceCandidateInterface> 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 @@
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<IceCandidateInterface> 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 @@
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<IceCandidateInterface> ice_candidate =
+ CreateIceCandidate(audio_content->name, 0, candidate);
+ EXPECT_TRUE(caller->pc()->AddIceCandidate(ice_candidate.get()));
EXPECT_TRUE(caller->pc()->RemoveIceCandidates({candidate}));
}